diff --git a/auth/store/previousNegotiations.go b/auth/store/previousNegotiations.go index 6bc8931d78827ade1af9df355288ee761ca497d7..b631f1d5dd819c19524a1e52820dc624b9415704 100644 --- a/auth/store/previousNegotiations.go +++ b/auth/store/previousNegotiations.go @@ -9,6 +9,7 @@ package store import ( "bytes" + "crypto/hmac" "encoding/binary" "encoding/json" @@ -76,7 +77,7 @@ func (s *Store) CheckIfNegotiationIsNew(partner *id.ID, negotiationFingerprint [ // If the partner does exist and the fingerprint exists, then make no // changes to the list for i, fp := range fingerprints { - if bytes.Equal(fp, negotiationFingerprint) { + if hmac.Equal(fp, negotiationFingerprint) { newFingerprint = false // Latest = true if it is the last fingerprint in the list @@ -158,7 +159,7 @@ func marshalPreviousNegotiations(partners map[id.ID]bool) []byte { } // unmarshalPreviousNegotiations unmarshalls the marshalled json into a -//// list of partner IDs. +// // list of partner IDs. func unmarshalPreviousNegotiations(b []byte) (map[id.ID]bool, error) { unmarshal := make([]id.ID, 0) diff --git a/cmix/follow.go b/cmix/follow.go index ceda2004f11eb8a24a21fa8ed8233f6a73feb7cf..3ed80bc98c1ac51b774843fbc23dbbb6a897308a 100644 --- a/cmix/follow.go +++ b/cmix/follow.go @@ -23,15 +23,16 @@ package cmix // instance import ( - "bytes" + "crypto/hmac" "encoding/binary" "fmt" - "gitlab.com/elixxir/client/cmix/identity/receptionID" - "gitlab.com/xx_network/primitives/ndf" "sync" "sync/atomic" "time" + "gitlab.com/elixxir/client/cmix/identity/receptionID" + "gitlab.com/xx_network/primitives/ndf" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/cmix/identity/receptionID/store" "gitlab.com/elixxir/client/stoppable" @@ -294,7 +295,7 @@ func (c *client) follow(identity receptionID.IdentityUse, marshaledTid := c.session.GetTransmissionID().Marshal() for _, clientErr := range update.ClientErrors { // If this ClientId appears in the ClientError - if bytes.Equal(clientErr.ClientId, marshaledTid) { + if hmac.Equal(clientErr.ClientId, marshaledTid) { // Obtain relevant NodeGateway information nid, err := id.Unmarshal(clientErr.Source) diff --git a/cmix/message/services.go b/cmix/message/services.go index 665c4f858dfb2b0af472cd08a4fbdb436df000f0..64f3eed1f9a982854497cca038f08e42625c9eb8 100644 --- a/cmix/message/services.go +++ b/cmix/message/services.go @@ -8,7 +8,7 @@ package message import ( - "bytes" + "crypto/hmac" "sync" jww "github.com/spf13/jwalterweatherman" @@ -116,10 +116,12 @@ func (sm *ServicesManager) get(clientID *id.ID, receivedSIH, // AddService adds a service which can call a message handing function or be // used for notifications. In general a single service can only be registered // for the same identifier/tag pair. -// preimage - the preimage which is triggered on -// type - a descriptive string of the service. Generally used in notifications -// source - a byte buffer of related data. Mostly used in notifications. -// Example: Sender ID +// +// preimage - the preimage which is triggered on +// type - a descriptive string of the service. Generally used in notifications +// source - a byte buffer of related data. Mostly used in notifications. +// Example: Sender ID +// // There can be multiple "default" services, they must use the "default" tag // and the identifier must be the client reception ID. // A service may have a nil response unless it is default. @@ -140,7 +142,7 @@ func (sm *ServicesManager) AddService(clientID *id.ID, newService Service, respo // Handle default tag behavior if newService.Tag == sih.Default { - if !bytes.Equal(newService.Identifier, clientID[:]) { + if !hmac.Equal(newService.Identifier, clientID[:]) { jww.FATAL.Panicf("Cannot accept a malformed 'Default' " + "service, Identifier must match clientID") } diff --git a/e2e/manager.go b/e2e/manager.go index 72197eb40c645bbc4e55a5d7485fcab4240203f4..e9d03832b2227593cbe433200c84cc0e05a7cabd 100644 --- a/e2e/manager.go +++ b/e2e/manager.go @@ -8,12 +8,13 @@ package e2e import ( - "bytes" + "crypto/hmac" "encoding/base64" "encoding/json" + "sync" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/crypto/e2e" - "sync" "gitlab.com/xx_network/primitives/netTime" @@ -315,7 +316,7 @@ func (m *manager) closeE2eListener(item receive.Message) { // Check the connection fingerprint to verify that the message is // from the expected E2E relationship (refer to the comment in // DeletePartner for more details) - if !bytes.Equal(p.ConnectionFingerprint().Bytes(), item.Payload) { + if !hmac.Equal(p.ConnectionFingerprint().Bytes(), item.Payload) { jww.ERROR.Printf("Received %s message from %s with incorrect "+ "connection fingerprint %s.", catalog.E2eClose, item.Sender, base64.StdEncoding.EncodeToString(item.Payload)) diff --git a/e2e/parse/partition/store.go b/e2e/parse/partition/store.go index 713fc291a9bb530994c3598b26e595eea52a6b03..f8b9c72715b3769630750c3145fcf9908b04e0d4 100644 --- a/e2e/parse/partition/store.go +++ b/e2e/parse/partition/store.go @@ -8,9 +8,12 @@ package partition import ( - "bytes" + "crypto/hmac" "encoding/binary" "encoding/json" + "sync" + "time" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/e2e/receive" @@ -19,8 +22,6 @@ import ( "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" "golang.org/x/crypto/blake2b" - "sync" - "time" ) type multiPartID [16]byte @@ -60,7 +61,7 @@ func (s *Store) AddFirst(partner *id.ID, mt catalog.MessageType, mpm := s.load(partner, messageID) mpm.AddFirst(mt, partNum, numParts, senderTimestamp, storageTimestamp, part) - if bytes.Equal(residue.Marshal(), []byte{}) { + if hmac.Equal(residue.Marshal(), []byte{}) { // fixme: should this error or crash? jww.WARN.Printf("Key reside from first message " + "is empty, continuing...")