From 788439a955471d9b4a09cf35edb04adf0a83bdfa Mon Sep 17 00:00:00 2001 From: Sydney Anne Erickson <sydney@elixxir.io> Date: Fri, 20 Nov 2020 09:44:10 -0800 Subject: [PATCH] Do the hashing of adding a fact properly --- go.mod | 2 +- go.sum | 2 ++ ud/addFact.go | 26 ++++++++++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 320f87836..9caa51bf9 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/spf13/viper v1.7.1 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 gitlab.com/elixxir/comms v0.0.4-0.20201116233755-b476dea10095 - gitlab.com/elixxir/crypto v0.0.5-0.20201110193609-6b5e881867b4 + gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6 gitlab.com/elixxir/ekv v0.1.3 gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704 gitlab.com/xx_network/comms v0.0.4-0.20201110022115-4a6171cad07d diff --git a/go.sum b/go.sum index fdfcad501..e29eb17e5 100644 --- a/go.sum +++ b/go.sum @@ -260,6 +260,8 @@ gitlab.com/elixxir/crypto v0.0.3 h1:znCt/x2bL4y8czTPaaFkwzdgSgW3BJc/1+dxyf1jqVw= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.5-0.20201110193609-6b5e881867b4 h1:1a1zZDuqZ56qU1EPgpc+Sqny1YFl0kAKJgQbsVc0WJQ= gitlab.com/elixxir/crypto v0.0.5-0.20201110193609-6b5e881867b4/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= +gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6 h1:HEJHC6gyVMdCZ1PSJkFDScHnsrWAMF+PFxyL2zpNrgU= +gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6/go.mod h1:BqvmtLM4eW+3NNOVK7U3COnnxqhJZxdCv4yziCuYhlA= gitlab.com/elixxir/ekv v0.1.3 h1:OE+LBMIhjGUMwc6hHJzYvEPNJQV7t1vMnJyIgxUMUo8= gitlab.com/elixxir/ekv v0.1.3/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= diff --git a/ud/addFact.go b/ud/addFact.go index 28bf676b2..1d7372eac 100644 --- a/ud/addFact.go +++ b/ud/addFact.go @@ -3,6 +3,7 @@ package ud import ( "crypto/rand" pb "gitlab.com/elixxir/comms/mixmessages" + "gitlab.com/elixxir/crypto/factID" "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/comms/connect" @@ -17,24 +18,29 @@ func (m *Manager) SendRegisterFact(fact fact.Fact) (*pb.FactRegisterResponse, er return m.addFact(fact, m.comms) } -func (m *Manager) addFact(fact fact.Fact, aFC addFactComms) (*pb.FactRegisterResponse, error) { - // Construct the message to send - // Convert our Fact to a mixmessages Fact for sending - mmFact := pb.Fact{ - Fact: fact.Fact, - FactType: uint32(fact.T), +func (m *Manager) addFact(inFact fact.Fact, aFC addFactComms) (*pb.FactRegisterResponse, error) { + // Create a primitives Fact so we can hash it + f, err := fact.NewFact(inFact.T, inFact.Fact) + if err != nil { + return &pb.FactRegisterResponse{}, err } - // Sign our fact for putting into the request - fsig, err := rsa.Sign(rand.Reader, m.privKey, hash.CMixHash, mmFact.Digest(), nil) + // Create a hash of our fact + fhash := factID.Fingerprint(f) + + // Sign our inFact for putting into the request + fsig, err := rsa.Sign(rand.Reader, m.privKey, hash.CMixHash, fhash, nil) if err != nil { return &pb.FactRegisterResponse{}, err } // Create our Fact Removal Request message data remFactMsg := pb.FactRegisterRequest{ - UID: m.host.GetId().Marshal(), - Fact: &mmFact, + UID: m.host.GetId().Marshal(), + Fact: &pb.Fact{ + Fact: inFact.Fact, + FactType: uint32(inFact.T), + }, FactSig: fsig, } -- GitLab