diff --git a/api/authenticatedChannel.go b/api/authenticatedChannel.go index 786b0cc98703d7fdf7dd013daf3d4c76fafe420a..84fd751178f710482c49c24df38449ef731f0779 100644 --- a/api/authenticatedChannel.go +++ b/api/authenticatedChannel.go @@ -8,19 +8,19 @@ package api import ( + "encoding/binary" + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/auth" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/preimage" "gitlab.com/elixxir/client/storage/edge" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/primitives/id" - "encoding/binary" "math/rand" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) // RequestAuthenticatedChannel sends a request to another party to establish an diff --git a/auth/callback.go b/auth/callback.go index 594c4fa9a37c4e6e20f9fd1514d233a26b0e669f..5925c7a4d21f705e861b55c51740744562071b62 100644 --- a/auth/callback.go +++ b/auth/callback.go @@ -8,8 +8,8 @@ package auth import ( - "github.com/cloudflare/circl/dh/sidh" "fmt" + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces" @@ -22,11 +22,11 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/diffieHellman" cAuth "gitlab.com/elixxir/crypto/e2e/auth" + "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/format" - "strings" - "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/xx_network/crypto/csprng" + "strings" ) func (m *Manager) StartProcesses() (stoppable.Stoppable, error) { @@ -190,8 +190,8 @@ func (m *Manager) handleRequest(cmixMsg format.Message, if !cAuth.VerifyOwnershipProof( myHistoricalPrivKey, partnerPubKey, grp, ownership) { - jww.WARN.Printf("Invalid ownership proof from %s received, discarding msdDigest: %s", - partnerID, cmixMsg.Digest()) + jww.WARN.Printf("Invalid ownership proof from %s received, discarding msdDigest: %s", + partnerID, cmixMsg.Digest()) } // Check if I need to resend by comparing the @@ -224,11 +224,11 @@ func (m *Manager) handleRequest(cmixMsg format.Message, // add a confirmation to disk if err = m.storage.Auth().AddReceived(partnerContact, partnerSIDHPubKey); err != nil { - em := fmt.Sprintf("failed to store contact Auth "+ - "Request: %s", err) - jww.WARN.Print(em) - events.Report(10, "Auth", "RequestError", em) - } + em := fmt.Sprintf("failed to store contact Auth "+ + "Request: %s", err) + jww.WARN.Print(em) + events.Report(10, "Auth", "RequestError", em) + } // Call ConfirmRequestAuth to send confirmation rngGen := fastRNG.NewStreamGenerator(1, 1, @@ -249,7 +249,6 @@ func (m *Manager) handleRequest(cmixMsg format.Message, } } - //process the inner payload facts, _, err := fact.UnstringifyFactList( string(requestFmt.msgPayload)) @@ -356,8 +355,6 @@ func (m *Manager) handleConfirm(cmixMsg format.Message, sr *auth.SentRequest, jww.TRACE.Printf("handleConfirm PARTNERSIDHPUBKEY: %v", partnerSIDHPubKey) - - // finalize the confirmation if err := m.doConfirm(sr, grp, partnerPubKey, sr.GetMyPrivKey(), sr.GetPartnerHistoricalPubKey(), diff --git a/auth/confirm.go b/auth/confirm.go index 546d1372a9dacd61d5010def3b2fd3a4cbbe6379..2a8169d21eb5be5f80ccbe5519aeb6a5a1e0d783 100644 --- a/auth/confirm.go +++ b/auth/confirm.go @@ -16,13 +16,13 @@ import ( "gitlab.com/elixxir/client/interfaces/preimage" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/edge" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/diffieHellman" cAuth "gitlab.com/elixxir/crypto/e2e/auth" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" "io" - util "gitlab.com/elixxir/client/storage/utility" ) func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, diff --git a/auth/fmt.go b/auth/fmt.go index 48a7cf55194168ab8927e22ad9ac3aef1ecb9a80..335867f41044eb65a5b5c3db27af669c72e60cb8 100644 --- a/auth/fmt.go +++ b/auth/fmt.go @@ -9,12 +9,12 @@ package auth import ( "github.com/cloudflare/circl/dh/sidh" - util "gitlab.com/elixxir/client/storage/utility" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" + sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/xx_network/primitives/id" - sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" ) //Basic Format////////////////////////////////////////////////////////////////// @@ -27,10 +27,10 @@ type baseFormat struct { func newBaseFormat(payloadSize, pubkeySize int) baseFormat { total := pubkeySize + sidhinterface.PubKeyByteSize + 1 if payloadSize < total { - jww.FATAL.Panicf("Size of baseFormat is too small (%d), must be big " + - "enough to contain public key (%d) and sidh key (%d)" + + jww.FATAL.Panicf("Size of baseFormat is too small (%d), must be big "+ + "enough to contain public key (%d) and sidh key (%d)"+ "which totals to %d", payloadSize, pubkeySize, - sidhinterface.PubKeyByteSize + 1, total) + sidhinterface.PubKeyByteSize+1, total) } jww.INFO.Printf("Empty Space RequestAuth: %d", payloadSize-total) @@ -97,10 +97,10 @@ func (f baseFormat) SetEcrPayload(ecr []byte) { const ownershipSize = 32 type ecrFormat struct { - data []byte - ownership []byte + data []byte + ownership []byte sidHpubkey []byte - payload []byte + payload []byte } func newEcrFormat(size int) ecrFormat { diff --git a/auth/fmt_test.go b/auth/fmt_test.go index af990942d713f4e7b13659eefe6ae4fd753ee2e9..1178fc0b705b3c6dc3ee57bacfe6ada38de54933 100644 --- a/auth/fmt_test.go +++ b/auth/fmt_test.go @@ -9,11 +9,11 @@ package auth import ( "bytes" + sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" "gitlab.com/xx_network/primitives/id" "math/rand" "reflect" "testing" - sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" ) // Tests newBaseFormat @@ -39,7 +39,7 @@ func TestNewBaseFormat(t *testing.T) { "\n\tReceived: %v", make([]byte, expectedEcrPayloadSize), baseMsg.ecrPayload) } - // Error case, where payload size is less than the public key + // Error case, where payload size is less than the public key defer func() { if r := recover(); r == nil { t.Error("newBaseFormat() did not panic when the size of " + @@ -80,7 +80,6 @@ func TestBaseFormat_SetGetPubKey(t *testing.T) { } - // Set/Get EcrPayload tests func TestBaseFormat_SetGetEcrPayload(t *testing.T) { // Construct message @@ -164,7 +163,7 @@ func TestBaseFormat_MarshalUnmarshal(t *testing.T) { // Tests newEcrFormat func TestNewEcrFormat(t *testing.T) { // Construct message - payloadSize := ownershipSize * 2 + sidhinterface.PubKeyByteSize + 1 + payloadSize := ownershipSize*2 + sidhinterface.PubKeyByteSize + 1 ecrMsg := newEcrFormat(payloadSize) // Check that the ecrFormat was constructed properly @@ -199,7 +198,7 @@ func TestNewEcrFormat(t *testing.T) { // Set/Get ownership tests func TestEcrFormat_SetGetOwnership(t *testing.T) { // Construct message - payloadSize := ownershipSize * 2 + sidhinterface.PubKeyByteSize + 1 + payloadSize := ownershipSize*2 + sidhinterface.PubKeyByteSize + 1 ecrMsg := newEcrFormat(payloadSize) // Test setter @@ -235,7 +234,7 @@ func TestEcrFormat_SetGetOwnership(t *testing.T) { // Set/Get payload tests func TestEcrFormat_SetGetPayload(t *testing.T) { // Construct message - payloadSize := ownershipSize * 2 + sidhinterface.PubKeyByteSize + 1 + payloadSize := ownershipSize*2 + sidhinterface.PubKeyByteSize + 1 ecrMsg := newEcrFormat(payloadSize) // Test set @@ -273,10 +272,10 @@ func TestEcrFormat_SetGetPayload(t *testing.T) { // Marshal/ unmarshal tests func TestEcrFormat_MarshalUnmarshal(t *testing.T) { // Construct message - payloadSize := ownershipSize * 2 + sidhinterface.PubKeyByteSize + 1 + payloadSize := ownershipSize*2 + sidhinterface.PubKeyByteSize + 1 ecrMsg := newEcrFormat(payloadSize) expectedPayload := newPayload( - payloadSize-ownershipSize - sidhinterface.PubKeyByteSize - 1, + payloadSize-ownershipSize-sidhinterface.PubKeyByteSize-1, "ownership") ecrMsg.SetPayload(expectedPayload) ownership := newOwnership("owner") @@ -342,7 +341,7 @@ func TestNewRequestFormat(t *testing.T) { // "\n\tReceived: %v", make([]byte, 0), reqMsg.GetPayload()) // } - payloadSize = ownershipSize * 2 + sidhinterface.PubKeyByteSize + 1 + payloadSize = ownershipSize*2 + sidhinterface.PubKeyByteSize + 1 ecrMsg = newEcrFormat(payloadSize) reqMsg, err = newRequestFormat(ecrMsg) if err == nil { diff --git a/auth/request.go b/auth/request.go index e7bb8945073057906d1bf5ed9efed1b3ed5ea0d3..1f63d7e157caa9cb360d66f0fd3ec82c51ab7d69 100644 --- a/auth/request.go +++ b/auth/request.go @@ -16,10 +16,10 @@ import ( "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/interfaces/preimage" "gitlab.com/elixxir/client/storage" - util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/auth" "gitlab.com/elixxir/client/storage/e2e" "gitlab.com/elixxir/client/storage/edge" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/diffieHellman" @@ -108,8 +108,8 @@ func RequestAuth(partner, me contact.Contact, rng io.Reader, sidHPrivKeyA = util.NewSIDHPrivateKey(sidh.KeyVariantSidhA) sidHPubKeyA = util.NewSIDHPublicKey(sidh.KeyVariantSidhA) - if err = sidHPrivKeyA.Generate(rng); err!=nil{ - return 0, errors.WithMessagef(err, "RequestAuth: " + + if err = sidHPrivKeyA.Generate(rng); err != nil { + return 0, errors.WithMessagef(err, "RequestAuth: "+ "could not generate SIDH private key") } sidHPrivKeyA.GeneratePublicKey(sidHPubKeyA) @@ -122,7 +122,6 @@ func RequestAuth(partner, me contact.Contact, rng io.Reader, requestFmt.MsgPayloadLen(), len(msgPayloadBytes)) } - //generate ownership proof ownership := cAuth.MakeOwnershipProof(storage.E2e().GetDHPrivateKey(), partner.DhPubKey, storage.E2e().GetGroup()) diff --git a/bindings/client.go b/bindings/client.go index 7d18a1f4339a6fbd81a72e57e5d827a1deb5f5f7..9f2c1b3005211e9b6996fcbb14dac9909e2a7870 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -534,7 +534,7 @@ func (c *Client) getSingle() (*single.Manager, error) { func DumpStack() (string, error) { buf := new(bytes.Buffer) err := pprof.Lookup("goroutine").WriteTo(buf, 2) - if err!=nil{ + if err != nil { return "", err } return buf.String(), nil diff --git a/bindings/notifications.go b/bindings/notifications.go index 27d927deef0011750635556d3c0008b247df56c0..7c7bc07754d662cfa3b5a3993dcbde27152712f9 100644 --- a/bindings/notifications.go +++ b/bindings/notifications.go @@ -38,7 +38,7 @@ type ManyNotificationForMeReport struct { } func (mnfmr *ManyNotificationForMeReport) Get(i int) (*NotificationForMeReport, error) { - if i>=len(mnfmr.many){ + if i >= len(mnfmr.many) { return nil, errors.New("Cannot get, too long") } return mnfmr.many[i], nil @@ -48,8 +48,6 @@ func (mnfmr *ManyNotificationForMeReport) Len() int { return len(mnfmr.many) } - - // NotificationsForMe Check if a notification received is for me // It returns a NotificationForMeReport which contains a ForMe bool stating if it is for the caller, // a Type, and a source. These are as follows: @@ -74,7 +72,7 @@ func NotificationsForMe(notifCSV, preimages string) (*ManyNotificationForMeRepor return nil, err } - notifList := make( []*NotificationForMeReport, 0, len(list)) + notifList := make([]*NotificationForMeReport, 0, len(list)) for _, notifData := range list { n := &NotificationForMeReport{ @@ -99,7 +97,6 @@ func NotificationsForMe(notifCSV, preimages string) (*ManyNotificationForMeRepor return &ManyNotificationForMeReport{many: notifList}, nil } - // RegisterForNotifications accepts firebase messaging token func (c *Client) RegisterForNotifications(token string) error { return c.api.RegisterForNotifications(token) @@ -109,5 +106,3 @@ func (c *Client) RegisterForNotifications(token string) error { func (c *Client) UnregisterForNotifications() error { return c.api.UnregisterForNotifications() } - - diff --git a/bindings/notifications_test.go b/bindings/notifications_test.go index 53e5c911071ea1029aa4a7dfa729802d6e95acc0..b180d09d78f5acedfdd1a1eacd0a2356ede18106 100644 --- a/bindings/notifications_test.go +++ b/bindings/notifications_test.go @@ -38,22 +38,22 @@ func TestNotificationForMe(t *testing.T) { dataSources := []int{0, 1, -1, 2, 3, 4, -1, 0, 1, 2, 3, 4, -1, 2, 2, 2} - notifData := make([]*mixmessages.NotificationData,0,len(dataSources)) + notifData := make([]*mixmessages.NotificationData, 0, len(dataSources)) - for _, index := range dataSources{ + for _, index := range dataSources { var preimage []byte - if index==-1{ - preimage = make([]byte,32) + if index == -1 { + preimage = make([]byte, 32) rng.Read(preimage) - }else{ + } else { preimage = preimageList[index].Data } - msg := make([]byte,32) + msg := make([]byte, 32) rng.Read(msg) msgHash := fingerprint.GetMessageHash(msg) - identityFP := fingerprint.IdentityFP(msg,preimage) + identityFP := fingerprint.IdentityFP(msg, preimage) n := &mixmessages.NotificationData{ EphemeralID: 0, @@ -61,46 +61,45 @@ func TestNotificationForMe(t *testing.T) { MessageHash: msgHash, } - notifData = append(notifData,n) + notifData = append(notifData, n) } notfsCSV := mixmessages.MakeNotificationsCSV(notifData) - - notifsForMe, err := NotificationsForMe(notfsCSV,string(preimagesJson)) - if err!=nil{ + notifsForMe, err := NotificationsForMe(notfsCSV, string(preimagesJson)) + if err != nil { t.Errorf("Got error from NotificationsForMe: %+v", err) } - for i:=0;i<notifsForMe.Len();i++{ + for i := 0; i < notifsForMe.Len(); i++ { nfm, err := notifsForMe.Get(i) - if err!=nil{ + if err != nil { t.Errorf("Got error in getting notif: %+v", err) } - if dataSources[i]==-1{ - if nfm.ForMe(){ + if dataSources[i] == -1 { + if nfm.ForMe() { t.Errorf("Notification %d should not be for me", i) } - if nfm.Type()!=""{ - t.Errorf("Notification %d shoudl not have a type, " + + if nfm.Type() != "" { + t.Errorf("Notification %d shoudl not have a type, "+ "has: %s", i, nfm.Type()) } - if nfm.Source()!=nil{ - t.Errorf("Notification %d shoudl not have a source, " + + if nfm.Source() != nil { + t.Errorf("Notification %d shoudl not have a source, "+ "has: %v", i, nfm.Source()) } - }else{ - if !nfm.ForMe(){ + } else { + if !nfm.ForMe() { t.Errorf("Notification %d should be for me", i) - }else{ + } else { expectedType := types[dataSources[i]] - if nfm.Type()!=expectedType{ - t.Errorf("Notification %d has the wrong type, " + + if nfm.Type() != expectedType { + t.Errorf("Notification %d has the wrong type, "+ "Expected: %s, Received: %s", i, nfm.Type(), expectedType) } expectedSource := sourceList[dataSources[i]] - if !bytes.Equal(nfm.Source(),expectedSource){ - t.Errorf("Notification %d source does not match: " + + if !bytes.Equal(nfm.Source(), expectedSource) { + t.Errorf("Notification %d source does not match: "+ "Expected: %v, Received: %v", i, expectedSource, nfm.Source()) } @@ -114,13 +113,13 @@ func TestManyNotificationForMeReport_Get(t *testing.T) { //not too long _, err := ManyNotificationForMeReport.Get(2) - if err!=nil{ + if err != nil { t.Errorf("Got error when not too long: %+v", err) } //too long _, err = ManyNotificationForMeReport.Get(69) - if err==nil{ + if err == nil { t.Errorf("Didnt get error when too long") } } diff --git a/fileTransfer/manager_test.go b/fileTransfer/manager_test.go index e908eea35841fcb11bc4cd2de799f02fc2dbc71b..8d556d07f644c0a7cd7da408b2c6533eff2383ba 100644 --- a/fileTransfer/manager_test.go +++ b/fileTransfer/manager_test.go @@ -11,27 +11,26 @@ import ( "bytes" "errors" "fmt" + "github.com/cloudflare/circl/dh/sidh" "github.com/golang/protobuf/proto" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" ftStorage "gitlab.com/elixxir/client/storage/fileTransfer" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/diffieHellman" ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" "reflect" "strings" "sync" "testing" "time" - util "gitlab.com/elixxir/client/storage/utility" - "gitlab.com/xx_network/crypto/csprng" - "github.com/cloudflare/circl/dh/sidh" ) - // Tests that newManager does not return errors, that the sent and received // transfer lists are new, and that the callback works. func Test_newManager(t *testing.T) { diff --git a/fileTransfer/send_test.go b/fileTransfer/send_test.go index 49556db3b621a1e460fc671952b2ddd2e4073027..94897c3a2de7ed141c29c0b379101c9ee7904929 100644 --- a/fileTransfer/send_test.go +++ b/fileTransfer/send_test.go @@ -11,12 +11,14 @@ import ( "bytes" "errors" "fmt" + "github.com/cloudflare/circl/dh/sidh" "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/stoppable" ftStorage "gitlab.com/elixxir/client/storage/fileTransfer" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/diffieHellman" ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" @@ -31,8 +33,6 @@ import ( "sync" "testing" "time" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) // Tests that Manager.sendThread successfully sends the parts and reports their @@ -734,7 +734,6 @@ func TestManager_makeRoundEventCallback(t *testing.T) { } }() - prng := NewPrng(42) key, _ := ftCrypto.NewTransferKey(prng) _, parts := newFile(4, 64, prng, t) diff --git a/fileTransfer/utils_test.go b/fileTransfer/utils_test.go index 7d9d84553ff0c09b1e2eec6089a477c3de1f0675..85bd6f9e040be6298429ee72a13cf78233192e84 100644 --- a/fileTransfer/utils_test.go +++ b/fileTransfer/utils_test.go @@ -10,6 +10,7 @@ package fileTransfer import ( "bytes" "encoding/binary" + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/interfaces" @@ -19,6 +20,7 @@ import ( "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" ftStorage "gitlab.com/elixxir/client/storage/fileTransfer" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/switchboard" "gitlab.com/elixxir/comms/network" @@ -39,8 +41,6 @@ import ( "sync" "testing" "time" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) // newFile generates a file with random data of size numParts * partSize. diff --git a/groupChat/makeGroup_test.go b/groupChat/makeGroup_test.go index b8a30199ad53555ca42295cae77d20c74314a859..056355d31a0dbe49fa0189f3314d39edd76827c9 100644 --- a/groupChat/makeGroup_test.go +++ b/groupChat/makeGroup_test.go @@ -10,8 +10,10 @@ package groupChat import ( "bytes" "fmt" + "github.com/cloudflare/circl/dh/sidh" gs "gitlab.com/elixxir/client/groupChat/groupStore" "gitlab.com/elixxir/client/interfaces/params" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/crypto/group" "gitlab.com/xx_network/crypto/csprng" @@ -21,8 +23,6 @@ import ( "strconv" "strings" "testing" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) // Tests that Manager.MakeGroup adds a group and returns the expected status. @@ -293,7 +293,7 @@ func addPartners(m *Manager, t *testing.T) ([]*id.ID, group.Membership, dhKey := m.store.E2e().GetGroup().NewInt(int64(i + 42)) myVariant := sidh.KeyVariantSidhA - prng := rand.New(rand.NewSource(int64(i+42))) + prng := rand.New(rand.NewSource(int64(i + 42))) mySIDHPrivKey := util.NewSIDHPrivateKey(myVariant) mySIDHPubKey := util.NewSIDHPublicKey(myVariant) mySIDHPrivKey.Generate(prng) diff --git a/groupChat/receiveRequest_test.go b/groupChat/receiveRequest_test.go index 760e7685ecbdd8dd14a424836563736fe6a4047b..0e51cfdc8f78889241dee5696a198e1643f058af 100644 --- a/groupChat/receiveRequest_test.go +++ b/groupChat/receiveRequest_test.go @@ -8,18 +8,18 @@ package groupChat import ( + "github.com/cloudflare/circl/dh/sidh" "github.com/golang/protobuf/proto" gs "gitlab.com/elixxir/client/groupChat/groupStore" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/stoppable" + util "gitlab.com/elixxir/client/storage/utility" "math/rand" "reflect" "strings" "testing" "time" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) // Tests that the correct group is received from the request. @@ -62,7 +62,6 @@ func TestManager_receiveRequest(t *testing.T) { theirSIDHPrivKey.Generate(prng) theirSIDHPrivKey.GeneratePublicKey(theirSIDHPubKey) - _ = m.store.E2e().AddPartner( g.Members[0].ID, g.Members[0].DhKey, diff --git a/interfaces/params/E2E.go b/interfaces/params/E2E.go index a33ae9fc2d9513b69b8d50fee260ff3284dd928f..9d473c429b17414c34ca4bf7cc6672637d9160b5 100644 --- a/interfaces/params/E2E.go +++ b/interfaces/params/E2E.go @@ -14,18 +14,18 @@ import ( ) type E2E struct { - Type SendType - RetryCount int + Type SendType + RetryCount int OnlyNotifyOnLastSend bool CMIX } func GetDefaultE2E() E2E { return E2E{ - Type: Standard, - CMIX: GetDefaultCMIX(), + Type: Standard, + CMIX: GetDefaultCMIX(), OnlyNotifyOnLastSend: true, - RetryCount: 10, + RetryCount: 10, } } func (e E2E) Marshal() ([]byte, error) { diff --git a/interfaces/params/E2E_test.go b/interfaces/params/E2E_test.go index 1f88dba4cbf3252f27d62c28961f29301622d041..aa383c42f4404745dea429c2f93fdd5d98b74415 100644 --- a/interfaces/params/E2E_test.go +++ b/interfaces/params/E2E_test.go @@ -13,7 +13,7 @@ func TestGetDefaultE2E(t *testing.T) { if GetDefaultE2E().Type != Standard { t.Errorf("GetDefaultE2E did not return Standard") } - if !GetDefaultE2E().OnlyNotifyOnLastSend { + if !GetDefaultE2E().OnlyNotifyOnLastSend { t.Errorf("GetDefaultE2E did not return OnlyNotifyOnLastSend == true") } } diff --git a/interfaces/sidh/sidh.go b/interfaces/sidh/sidh.go index ca10626fb46d89129cb64a3341037ca95360d973..81468e4be1f4e48ee50cd20713cd08eab5be3f0a 100644 --- a/interfaces/sidh/sidh.go +++ b/interfaces/sidh/sidh.go @@ -3,6 +3,7 @@ package interfaces import "github.com/cloudflare/circl/dh/sidh" const KeyId = sidh.Fp503 + var PubKeyByteSize = sidh.NewPublicKey(sidh.Fp503, sidh.KeyVariantSidhA).Size() var PubKeyBitSize = PubKeyByteSize * 8 diff --git a/keyExchange/confirm.go b/keyExchange/confirm.go index df5b2bdb7c431b606e99a4c29f59e98e5f0cf71c..d754acc1da040efed8e55227d623c0cc5c414342 100644 --- a/keyExchange/confirm.go +++ b/keyExchange/confirm.go @@ -36,7 +36,7 @@ func handleConfirm(sess *storage.Session, confirmation message.Receive) { if confirmation.Encryption != message.E2E { jww.ERROR.Printf( "[REKEY] Received non-e2e encrypted Key Exchange "+ - "confirm from partner %s", confirmation.Sender) + "confirm from partner %s", confirmation.Sender) return } @@ -45,7 +45,7 @@ func handleConfirm(sess *storage.Session, confirmation message.Receive) { if err != nil { jww.ERROR.Printf( "[REKEY] Received Key Exchange Confirmation with unknown "+ - "partner %s", confirmation.Sender) + "partner %s", confirmation.Sender) return } @@ -76,7 +76,7 @@ func handleConfirm(sess *storage.Session, confirmation message.Receive) { confirmedSession, partner.GetPartnerID(), err) } - jww.DEBUG.Printf("[REKEY] handled confirmation for session " + + jww.DEBUG.Printf("[REKEY] handled confirmation for session "+ "%s from partner %s.", confirmedSession, partner.GetPartnerID()) } diff --git a/keyExchange/confirm_test.go b/keyExchange/confirm_test.go index fcded99324d34defbc6e0bd4769c4bd62fd40352..08b539a059b6de7c5d1c6251a03febe430992333 100644 --- a/keyExchange/confirm_test.go +++ b/keyExchange/confirm_test.go @@ -8,16 +8,16 @@ package keyExchange import ( + "github.com/cloudflare/circl/dh/sidh" "github.com/golang/protobuf/proto" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/e2e" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" - "testing" "math/rand" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" + "testing" ) // Smoke test for handleTrigger diff --git a/keyExchange/exchange_test.go b/keyExchange/exchange_test.go index 4da104231d8e3bced478a719380d0c8f0884d31e..7bf6cbad9404705246738f207e3a613a7a81f7af 100644 --- a/keyExchange/exchange_test.go +++ b/keyExchange/exchange_test.go @@ -9,22 +9,22 @@ package keyExchange import ( "fmt" + "github.com/cloudflare/circl/dh/sidh" "github.com/golang/protobuf/proto" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/e2e" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/switchboard" dh "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" + "math/rand" "testing" "time" - "math/rand" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) var exchangeAliceId, exchangeBobId *id.ID @@ -69,7 +69,7 @@ func TestFullExchange(t *testing.T) { newBobSIDHPubKey := util.NewSIDHPublicKey(bobVariant) newBobSIDHPrivKey.Generate(prng2) newBobSIDHPrivKey.GeneratePublicKey(newBobSIDHPubKey) - newBobSIDHPubKeyBytes := make([]byte, newBobSIDHPubKey.Size() + 1) + newBobSIDHPubKeyBytes := make([]byte, newBobSIDHPubKey.Size()+1) newBobSIDHPubKeyBytes[0] = byte(bobVariant) newBobSIDHPubKey.Export(newBobSIDHPubKeyBytes[1:]) diff --git a/keyExchange/rekey.go b/keyExchange/rekey.go index 03dfcde068889b636a481c989d11debe643ee8c2..9acbae9930e384b0c06140a8408c78b721797d92 100644 --- a/keyExchange/rekey.go +++ b/keyExchange/rekey.go @@ -18,11 +18,11 @@ import ( "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/e2e" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/comms/network" ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/primitives/states" - util "gitlab.com/elixxir/client/storage/utility" "time" ) @@ -123,7 +123,7 @@ func negotiate(instance *network.Instance, sendE2E interfaces.SendE2E, if err != nil { return errors.Errorf( "[REKEY] Failed to send the key negotiation message "+ - "for %s: %s", session, err) + "for %s: %s", session, err) } //create the runner which will handle the result of sending the messages diff --git a/keyExchange/trigger.go b/keyExchange/trigger.go index bf29c1a18305c7befb8c1bd780275d590c6e52ca..9e3bf66a3a7b596478f35be48cb3e88415c184c6 100644 --- a/keyExchange/trigger.go +++ b/keyExchange/trigger.go @@ -9,6 +9,7 @@ package keyExchange import ( "fmt" + "github.com/cloudflare/circl/dh/sidh" "github.com/golang/protobuf/proto" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" @@ -19,11 +20,10 @@ import ( "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/e2e" + util "gitlab.com/elixxir/client/storage/utility" ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/primitives/states" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) const ( @@ -69,8 +69,7 @@ func handleTrigger(sess *storage.Session, net interfaces.NetworkManager, } //unmarshal the message - oldSessionID, PartnerPublicKey, PartnerSIDHPublicKey, err := ( - unmarshalSource(sess.E2e().GetGroup(), request.Payload)) + oldSessionID, PartnerPublicKey, PartnerSIDHPublicKey, err := (unmarshalSource(sess.E2e().GetGroup(), request.Payload)) if err != nil { jww.ERROR.Printf("[REKEY] could not unmarshal partner %s: %s", request.Sender, err) diff --git a/keyExchange/trigger_test.go b/keyExchange/trigger_test.go index 448a3477a7b6c6876aa84453a5d683fc82bb2d2b..6bfdb41e7ef44f22f9b34e46bd68b11e528f47e5 100644 --- a/keyExchange/trigger_test.go +++ b/keyExchange/trigger_test.go @@ -8,20 +8,20 @@ package keyExchange import ( + "github.com/cloudflare/circl/dh/sidh" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage/e2e" + util "gitlab.com/elixxir/client/storage/utility" dh "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" "google.golang.org/protobuf/proto" + "math/rand" "testing" "time" - "math/rand" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) // Smoke test for handleTrigger @@ -61,7 +61,7 @@ func TestHandleTrigger(t *testing.T) { newBobSIDHPubKey := util.NewSIDHPublicKey(bobVariant) newBobSIDHPrivKey.Generate(prng2) newBobSIDHPrivKey.GeneratePublicKey(newBobSIDHPubKey) - newBobSIDHPubKeyBytes := make([]byte, newBobSIDHPubKey.Size() + 1) + newBobSIDHPubKeyBytes := make([]byte, newBobSIDHPubKey.Size()+1) newBobSIDHPubKeyBytes[0] = byte(bobVariant) newBobSIDHPubKey.Export(newBobSIDHPubKeyBytes[1:]) diff --git a/keyExchange/utils_test.go b/keyExchange/utils_test.go index bcb0321b65f13afa7f46347cdfc87d1984e4e747..a6b5afeadb04344c5550281e97ff4ca63c26e3c1 100644 --- a/keyExchange/utils_test.go +++ b/keyExchange/utils_test.go @@ -8,6 +8,7 @@ package keyExchange import ( + "github.com/cloudflare/circl/dh/sidh" "github.com/golang/protobuf/proto" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces" @@ -17,6 +18,7 @@ import ( "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/e2e" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/switchboard" "gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/crypto/cyclic" @@ -29,11 +31,9 @@ import ( "gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/ndf" "gitlab.com/xx_network/primitives/netTime" + "math/rand" "testing" "time" - "github.com/cloudflare/circl/dh/sidh" - "math/rand" - util "gitlab.com/elixxir/client/storage/utility" ) // Generate partner ID for two people, used for smoke tests diff --git a/network/message/garbled_test.go b/network/message/garbled_test.go index 3dcf059aea3a8f6cf959b0ecdf64dee2a18e1fbd..8656eda570f80f0a7f9333cbaa6f82b6ea80594e 100644 --- a/network/message/garbled_test.go +++ b/network/message/garbled_test.go @@ -2,6 +2,7 @@ package message import ( "encoding/binary" + "github.com/cloudflare/circl/dh/sidh" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" @@ -10,6 +11,7 @@ import ( "gitlab.com/elixxir/client/network/message/parse" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/switchboard" "gitlab.com/elixxir/comms/client" "gitlab.com/elixxir/crypto/fastRNG" @@ -21,8 +23,6 @@ import ( "os" "testing" "time" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) func TestMain(m *testing.M) { diff --git a/network/message/sendCmix.go b/network/message/sendCmix.go index 7e1e72620a014e2008c3317de5ff380976b19ac1..99010f1577df92aa2bcce967f2e84889a1fcaa7e 100644 --- a/network/message/sendCmix.go +++ b/network/message/sendCmix.go @@ -88,7 +88,7 @@ func sendCmixHelper(sender *gateway.Sender, msg format.Message, // flip leading bits randomly to thwart a tagging attack. // See SetGroupBits for more info - cmix.SetGroupBits(msg,grp,stream) + cmix.SetGroupBits(msg, grp, stream) for numRoundTries := uint(0); numRoundTries < cmixParams.RoundTries; numRoundTries++ { elapsed := netTime.Since(timeStart) @@ -142,14 +142,12 @@ func sendCmixHelper(sender *gateway.Sender, msg format.Message, // Build the messages to send - wrappedMsg, encMsg, ephID, err := buildSlotMessage(msg, recipient, firstGateway, stream, senderId, bestRound, roundKeys, cmixParams) if err != nil { return 0, ephemeral.Id{}, err } - jww.INFO.Printf("Sending to EphID %d (%s) on round %d, "+ "(msgDigest: %s, ecrMsgDigest: %s) via gateway %s", ephID.Int64(), recipient, bestRound.ID, msg.Digest(), diff --git a/network/message/sendE2E.go b/network/message/sendE2E.go index 3d32c6f6baa2504d548f3d6c4d300743bb99c66c..fba278fbaac11c5344d774d9d81c9156118273c0 100644 --- a/network/message/sendE2E.go +++ b/network/message/sendE2E.go @@ -101,10 +101,10 @@ func (m *Manager) SendE2E(msg message.Send, param params.E2E, // set all non last partitions to the silent type so they // dont cause notificatons if OnlyNotifyOnLastSend is true - lastPartition:= len(partitions)-1 + lastPartition := len(partitions) - 1 if localParam.OnlyNotifyOnLastSend && i != lastPartition { localParam.IdentityPreimage = partner.GetSilentPreimage() - }else if localParam.IdentityPreimage == nil { + } else if localParam.IdentityPreimage == nil { //set the preimage to the default e2e one if it is not already set localParam.IdentityPreimage = partner.GetE2EPreimage() } diff --git a/network/rounds/retrieve.go b/network/rounds/retrieve.go index a6b7b85c263b3612a0e6f2ade7f93d1b2b7bb21b..b5fdc8e52e766166384668f47fdfd27ba854b4c8 100644 --- a/network/rounds/retrieve.go +++ b/network/rounds/retrieve.go @@ -1,4 +1,3 @@ - /////////////////////////////////////////////////////////////////////////////// // Copyright © 2020 xx network SEZC // // // diff --git a/storage/auth/sentRequest.go b/storage/auth/sentRequest.go index 2b42df4727b99f58448ce3de2ca888ec217a34d8..1ab1cb8e80c4bc4f3246b989279aeddd36c2d8d7 100644 --- a/storage/auth/sentRequest.go +++ b/storage/auth/sentRequest.go @@ -39,8 +39,8 @@ type sentRequestDisk struct { PartnerHistoricalPubKey []byte MyPrivKey []byte MyPubKey []byte - MySidHPrivKeyA []byte - MySidHPubKeyA []byte + MySidHPrivKeyA []byte + MySidHPubKeyA []byte Fingerprint []byte } @@ -81,19 +81,18 @@ func loadSentRequest(kv *versioned.KV, partner *id.ID, grp *cyclic.Group) (*Sent sidh.KeyVariantSidhA) if err = mySidHPrivKeyA.Import(srd.MySidHPrivKeyA); err != nil { return nil, errors.WithMessagef(err, - "Failed to decode sidh private key " + - "with %s for SentRequest Auth", partner) + "Failed to decode sidh private key "+ + "with %s for SentRequest Auth", partner) } mySidHPubKeyA := sidh.NewPublicKey(sidhinterface.KeyId, sidh.KeyVariantSidhA) if err = mySidHPubKeyA.Import(srd.MySidHPubKeyA); err != nil { return nil, errors.WithMessagef(err, - "Failed to decode sidh public " + - "key with %s for SentRequest Auth", partner) + "Failed to decode sidh public "+ + "key with %s for SentRequest Auth", partner) } - fp := format.Fingerprint{} copy(fp[:], srd.Fingerprint) @@ -156,7 +155,7 @@ func (sr *SentRequest) save() error { PartnerHistoricalPubKey: historicalPubKey, MyPrivKey: privKey, MyPubKey: pubKey, - MySidHPrivKeyA: sidHPriv, + MySidHPrivKeyA: sidHPriv, MySidHPubKeyA: sidHPub, Fingerprint: sr.fingerprint[:], } diff --git a/storage/auth/store.go b/storage/auth/store.go index 0cfdbdb22c240a3714a30abe7a48c3aed6a4476c..addd3d138499ae09cfc5e9dc5d221d79d95d060a 100644 --- a/storage/auth/store.go +++ b/storage/auth/store.go @@ -331,7 +331,7 @@ func (s *Store) GetReceivedRequest(partner *id.ID) (contact.Contact, *sidh.Publi "found: %s", partner) } - return *r.receive,r.theirSidHPubKeyA, nil + return *r.receive, r.theirSidHPubKeyA, nil } // GetReceivedRequestData returns the contact representing the receive request diff --git a/storage/auth/store_test.go b/storage/auth/store_test.go index e84e125cfa8138eef16c4dcdd81a9f00b93eb927..b1c4bb92b95c98eadc23db6e66d1ab5e353efc51 100644 --- a/storage/auth/store_test.go +++ b/storage/auth/store_test.go @@ -8,23 +8,23 @@ package auth import ( + "github.com/cloudflare/circl/dh/sidh" + sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/e2e/auth" "gitlab.com/elixxir/ekv" "gitlab.com/elixxir/primitives/format" + "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/primitives/id" + "io" "math/rand" "reflect" "sync" "testing" - "io" - sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" - "github.com/cloudflare/circl/dh/sidh" - "gitlab.com/xx_network/crypto/csprng" - util "gitlab.com/elixxir/client/storage/utility" ) // Happy path. @@ -121,7 +121,7 @@ func TestLoadStore(t *testing.T) { partner := sr.partner if s.requests[*partner] == nil { - t.Errorf("AddSent() failed to add request to map for " + + t.Errorf("AddSent() failed to add request to map for "+ "partner ID %s.", partner) } else if !reflect.DeepEqual(sr, s.requests[*partner].sent) { t.Errorf("AddSent() failed store the correct SentRequest."+ @@ -134,7 +134,7 @@ func TestLoadStore(t *testing.T) { Request: &request{Sent, sr, nil, nil, sync.Mutex{}}, } if _, exists := s.fingerprints[sr.fingerprint]; !exists { - t.Errorf("AddSent() failed to add fingerprint to map for " + + t.Errorf("AddSent() failed to add fingerprint to map for "+ "fingerprint %s.", sr.fingerprint) } else if !reflect.DeepEqual(expectedFP, s.fingerprints[sr.fingerprint]) { @@ -183,7 +183,7 @@ func TestStore_AddSent(t *testing.T) { } if s.requests[*partner] == nil { - t.Errorf("AddSent() failed to add request to map for " + + t.Errorf("AddSent() failed to add request to map for "+ "partner ID %s.", partner) } else if !reflect.DeepEqual(sr, s.requests[*partner].sent) { t.Errorf("AddSent() failed store the correct SentRequest."+ @@ -192,7 +192,7 @@ func TestStore_AddSent(t *testing.T) { } if _, exists := s.fingerprints[sr.fingerprint]; !exists { - t.Errorf("AddSent() failed to add fingerprint to map for " + + t.Errorf("AddSent() failed to add fingerprint to map for "+ "fingerprint %s.", sr.fingerprint) } else if !reflect.DeepEqual(expectedFP, s.fingerprints[sr.fingerprint]) { @@ -242,10 +242,10 @@ func TestStore_AddReceived(t *testing.T) { } if s.requests[*c.ID] == nil { - t.Errorf("AddReceived() failed to add request to map for " + + t.Errorf("AddReceived() failed to add request to map for "+ "partner ID %s.", c.ID) } else if !reflect.DeepEqual(c, *s.requests[*c.ID].receive) { - t.Errorf("AddReceived() failed store the correct Contact." + + t.Errorf("AddReceived() failed store the correct Contact."+ "\n\texpected: %+v\n\treceived: %+v", c, *s.requests[*c.ID].receive) } @@ -377,16 +377,16 @@ func TestStore_GetFingerprint_InvalidFingerprintType(t *testing.T) { "FingerprintType is invalid.") } if fpType != 0 { - t.Errorf("GetFingerprint() returned incorrect " + + t.Errorf("GetFingerprint() returned incorrect "+ "FingerprintType.\n\texpected: %d\n\treceived: %d", 0, fpType) } if request != nil { - t.Errorf("GetFingerprint() returned incorrect request." + + t.Errorf("GetFingerprint() returned incorrect request."+ "\n\texpected: %+v\n\treceived: %+v", nil, request) } if key != nil { - t.Errorf("GetFingerprint() returned incorrect key." + + t.Errorf("GetFingerprint() returned incorrect key."+ "\n\texpected: %v\n\treceived: %v", nil, key) } } @@ -469,7 +469,7 @@ func TestStore_GetReceivedRequest_RequestNotInMap(t *testing.T) { testC, testPubKeyA, err := s.GetReceivedRequest( id.NewIdFromUInt(rand.Uint64(), - id.User, t)) + id.User, t)) if err == nil { t.Errorf("GetReceivedRequest() did not return an error " + "when the request should not exist.") @@ -784,7 +784,7 @@ func genSidhAKeys(rng io.Reader) (*sidh.PrivateKey, *sidh.PublicKey) { sidHPrivKeyA := util.NewSIDHPrivateKey(sidh.KeyVariantSidhA) sidHPubKeyA := util.NewSIDHPublicKey(sidh.KeyVariantSidhA) - if err := sidHPrivKeyA.Generate(rng); err!=nil{ + if err := sidHPrivKeyA.Generate(rng); err != nil { panic("failure to generate SidH A private key") } sidHPrivKeyA.GeneratePublicKey(sidHPubKeyA) @@ -796,7 +796,7 @@ func genSidhBKeys(rng io.Reader) (*sidh.PrivateKey, *sidh.PublicKey) { sidHPrivKeyB := util.NewSIDHPrivateKey(sidh.KeyVariantSidhB) sidHPubKeyB := util.NewSIDHPublicKey(sidh.KeyVariantSidhB) - if err := sidHPrivKeyB.Generate(rng); err!=nil{ + if err := sidHPrivKeyB.Generate(rng); err != nil { panic("failure to generate SidH A private key") } sidHPrivKeyB.GeneratePublicKey(sidHPubKeyB) diff --git a/storage/e2e/key.go b/storage/e2e/key.go index 8f49aa3db19f1f14327d46a570f72551bee1ce48..bd203c88e9c16d21224feda8181c77adaa8be0de 100644 --- a/storage/e2e/key.go +++ b/storage/e2e/key.go @@ -8,14 +8,14 @@ package e2e import ( + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" + jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/crypto/cyclic" + dh "gitlab.com/elixxir/crypto/diffieHellman" e2eCrypto "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/primitives/format" - "github.com/cloudflare/circl/dh/sidh" - "gitlab.com/elixxir/crypto/cyclic" - dh "gitlab.com/elixxir/crypto/diffieHellman" - jww "github.com/spf13/jwalterweatherman" ) // GenerateE2ESessionBaseKey returns the baseKey symmetric encryption key root. diff --git a/storage/e2e/key_test.go b/storage/e2e/key_test.go index 8ab67500dc5c70517d76e67eef2a525bae6dec38..acf235b0ed7ddba596faaf27d6109a1273c29d6c 100644 --- a/storage/e2e/key_test.go +++ b/storage/e2e/key_test.go @@ -9,11 +9,13 @@ package e2e import ( "bytes" + "github.com/cloudflare/circl/dh/sidh" "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" dh "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/crypto/e2e" + "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/ekv" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/crypto/csprng" @@ -22,11 +24,8 @@ import ( "math/rand" "reflect" "testing" - "gitlab.com/elixxir/crypto/fastRNG" - "github.com/cloudflare/circl/dh/sidh" ) - // TestGenerateE2ESessionBaseKey smoke tests the GenerateE2ESessionBaseKey // function to ensure that it produces the correct key on both sides of the // connection. diff --git a/storage/e2e/manager.go b/storage/e2e/manager.go index 08a9953c6bf2ae62549c0aa8984c937d3816b492..d8ec60e65209a217e45bcc28d2387ce6eadd1d9d 100644 --- a/storage/e2e/manager.go +++ b/storage/e2e/manager.go @@ -11,6 +11,7 @@ import ( "bytes" "encoding/base64" "fmt" + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces/params" @@ -20,7 +21,6 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/xx_network/primitives/id" "golang.org/x/crypto/blake2b" - "github.com/cloudflare/circl/dh/sidh" ) const managerPrefix = "Manager{partner:%s}" @@ -36,7 +36,7 @@ type Manager struct { originMyPrivKey *cyclic.Int originPartnerPubKey *cyclic.Int - originMySIDHPrivKey *sidh.PrivateKey + originMySIDHPrivKey *sidh.PrivateKey originPartnerSIDHPubKey *sidh.PublicKey receive *relationship diff --git a/storage/e2e/manager_test.go b/storage/e2e/manager_test.go index 1866baccf435b2a7f96dddf41957477642c6a68e..24c0f9ab85fbca4bd0e3d0166c8ae6a1ab7382cd 100644 --- a/storage/e2e/manager_test.go +++ b/storage/e2e/manager_test.go @@ -106,13 +106,13 @@ func TestManager_NewReceiveSession(t *testing.T) { se, exists := m.NewReceiveSession(s.partnerPubKey, s.partnerSIDHPubKey, s.e2eParams, s) if exists { - t.Errorf("NewReceiveSession() incorrect return value." + + t.Errorf("NewReceiveSession() incorrect return value."+ "\n\texpected: %v\n\treceived: %v", false, exists) } if !m.partner.Cmp(se.GetPartner()) || !bytes.Equal(s.GetID().Marshal(), se.GetID().Marshal()) { - t.Errorf("NewReceiveSession() incorrect session." + - "\n\texpected partner: %v\n\treceived partner: %v" + + t.Errorf("NewReceiveSession() incorrect session."+ + "\n\texpected partner: %v\n\treceived partner: %v"+ "\n\texpected ID: %v\n\treceived ID: %v", m.partner, se.GetPartner(), s.GetID(), se.GetID()) } @@ -125,8 +125,8 @@ func TestManager_NewReceiveSession(t *testing.T) { } if !m.partner.Cmp(se.GetPartner()) || !bytes.Equal(s.GetID().Marshal(), se.GetID().Marshal()) { - t.Errorf("NewReceiveSession() incorrect session." + - "\n\texpected partner: %v\n\treceived partner: %v" + + t.Errorf("NewReceiveSession() incorrect session."+ + "\n\texpected partner: %v\n\treceived partner: %v"+ "\n\texpected ID: %v\n\treceived ID: %v", m.partner, se.GetPartner(), s.GetID(), se.GetID()) } diff --git a/storage/e2e/relationship.go b/storage/e2e/relationship.go index 72342e54bf677c765680a492ce399fc26813477b..c545841761492ba43b854620b0b6724b67ee7c90 100644 --- a/storage/e2e/relationship.go +++ b/storage/e2e/relationship.go @@ -9,6 +9,7 @@ package e2e import ( "encoding/json" + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces/params" @@ -16,7 +17,6 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/xx_network/primitives/netTime" "sync" - "github.com/cloudflare/circl/dh/sidh" ) const maxUnconfirmed uint = 3 diff --git a/storage/e2e/relationship_test.go b/storage/e2e/relationship_test.go index 504c4d22496f7bf60d519f7e39a3610c7f643b81..bd21292259eae2cce4b1e82401bd4d002032a236 100644 --- a/storage/e2e/relationship_test.go +++ b/storage/e2e/relationship_test.go @@ -9,15 +9,15 @@ package e2e import ( "bytes" + "github.com/cloudflare/circl/dh/sidh" "gitlab.com/elixxir/client/interfaces/params" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" "reflect" "testing" - "gitlab.com/xx_network/crypto/csprng" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) // Subtest: unmarshal/marshal with one session in the buff @@ -586,11 +586,11 @@ func makeTestRelationshipManager(t *testing.T) *Manager { grp: g, myID: &id.ID{}, }, - kv: versioned.NewKV(make(ekv.Memstore)), - partner: id.NewIdFromUInt(8, id.User, t), - originMyPrivKey: g.NewInt(2), - originPartnerPubKey: g.NewInt(3), - originMySIDHPrivKey: mySIDHPrivKey, + kv: versioned.NewKV(make(ekv.Memstore)), + partner: id.NewIdFromUInt(8, id.User, t), + originMyPrivKey: g.NewInt(2), + originPartnerPubKey: g.NewInt(3), + originMySIDHPrivKey: mySIDHPrivKey, originPartnerSIDHPubKey: partnerSIDHPubKey, } } diff --git a/storage/e2e/session.go b/storage/e2e/session.go index 96185b32ddea3f1991a734cee28f6291faadbe4e..5f05d882b572a9f6bd9a36caaa1d18252a85d5e0 100644 --- a/storage/e2e/session.go +++ b/storage/e2e/session.go @@ -10,6 +10,7 @@ package e2e import ( "encoding/json" "fmt" + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces/params" @@ -24,7 +25,6 @@ import ( "math/big" "sync" "testing" - "github.com/cloudflare/circl/dh/sidh" ) const currentSessionVersion = 0 @@ -52,7 +52,7 @@ type Session struct { partnerPubKey *cyclic.Int // SIDH Keys of the same - mySIDHPrivKey *sidh.PrivateKey + mySIDHPrivKey *sidh.PrivateKey partnerSIDHPubKey *sidh.PublicKey // ID of the session which teh partner public key comes from for this @@ -123,7 +123,7 @@ func newSession(ship *relationship, t RelationshipType, myPrivKey, partnerPubKey e2eParams params.E2ESessionParams) *Session { if e2eParams.MinKeys < 10 { - jww.FATAL.Panicf("Cannot create a session with a minimum " + + jww.FATAL.Panicf("Cannot create a session with a minimum "+ "number of keys (%d) less than 10", e2eParams.MinKeys) } @@ -149,7 +149,7 @@ func newSession(ship *relationship, t RelationshipType, myPrivKey, partnerPubKey jww.INFO.Printf("New Session with Partner %s:\n\tType: %s"+ "\n\tBaseKey: %s\n\tRelationship Fingerprint: %v\n\tNumKeys: %d"+ - "\n\tMy Public Key: %s\n\tPartner Public Key: %s" + + "\n\tMy Public Key: %s\n\tPartner Public Key: %s"+ "\n\tMy Public SIDH: %s\n\tPartner Public SIDH: %s", ship.manager.partner, t, @@ -274,7 +274,6 @@ func (s *Session) GetPartnerSIDHPubKey() *sidh.PublicKey { return s.partnerSIDHPubKey } - func (s *Session) GetSource() SessionID { // no lock is needed because this cannot be edited return s.partnerSource diff --git a/storage/e2e/session_test.go b/storage/e2e/session_test.go index 3063cc41422241f6480e78f7dd18fa9ff6dd073e..58b2ed87b525963863bbf9c4d8b066fd2d8a533f 100644 --- a/storage/e2e/session_test.go +++ b/storage/e2e/session_test.go @@ -9,8 +9,10 @@ package e2e import ( "errors" + "github.com/cloudflare/circl/dh/sidh" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/utility" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/versioned" dh "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/crypto/fastRNG" @@ -21,8 +23,6 @@ import ( "reflect" "testing" "time" - util "gitlab.com/elixxir/client/storage/utility" - "github.com/cloudflare/circl/dh/sidh" ) func TestSession_generate_noPrivateKeyReceive(t *testing.T) { @@ -47,9 +47,9 @@ func TestSession_generate_noPrivateKeyReceive(t *testing.T) { // build the session s := &Session{ - partnerPubKey: partnerPubKey, + partnerPubKey: partnerPubKey, partnerSIDHPubKey: partnerSIDHPubKey, - e2eParams: params.GetDefaultE2ESessionParams(), + e2eParams: params.GetDefaultE2ESessionParams(), relationship: &relationship{ manager: &Manager{ctx: ctx}, }, @@ -118,11 +118,11 @@ func TestSession_generate_PrivateKeySend(t *testing.T) { // build the session s := &Session{ - myPrivKey: myPrivKey, - partnerPubKey: partnerPubKey, - mySIDHPrivKey: mySIDHPrivKey, + myPrivKey: myPrivKey, + partnerPubKey: partnerPubKey, + mySIDHPrivKey: mySIDHPrivKey, partnerSIDHPubKey: partnerSIDHPubKey, - e2eParams: params.GetDefaultE2ESessionParams(), + e2eParams: params.GetDefaultE2ESessionParams(), relationship: &relationship{ manager: &Manager{ctx: ctx}, }, @@ -633,12 +633,12 @@ func makeTestSession() (*Session, *context) { kv := versioned.NewKV(make(ekv.Memstore)) s := &Session{ - baseKey: baseKey, - myPrivKey: myPrivKey, - partnerPubKey: partnerPubKey, - mySIDHPrivKey: mySIDHPrivKey, + baseKey: baseKey, + myPrivKey: myPrivKey, + partnerPubKey: partnerPubKey, + mySIDHPrivKey: mySIDHPrivKey, partnerSIDHPubKey: partnerSIDHPubKey, - e2eParams: params.GetDefaultE2ESessionParams(), + e2eParams: params.GetDefaultE2ESessionParams(), relationship: &relationship{ manager: &Manager{ ctx: ctx, diff --git a/storage/e2e/store.go b/storage/e2e/store.go index 5650c1025727fc9f59b35e5d26d0e08a26359aa5..9be32c5c490e715dfa424e8b788dfb21f68b47a9 100644 --- a/storage/e2e/store.go +++ b/storage/e2e/store.go @@ -9,6 +9,7 @@ package e2e import ( "encoding/json" + "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces/params" @@ -22,7 +23,6 @@ import ( "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" "sync" - "github.com/cloudflare/circl/dh/sidh" ) const ( @@ -67,24 +67,24 @@ func NewStore(grp *cyclic.Group, kv *versioned.KV, privKey *cyclic.Int, fingerprints := newFingerprints() s := &Store{ - managers: make(map[id.ID]*Manager), + managers: make(map[id.ID]*Manager), - dhPrivateKey: privKey, - dhPublicKey: pubKey, - grp: grp, + dhPrivateKey: privKey, + dhPublicKey: pubKey, + grp: grp, - fingerprints: &fingerprints, + fingerprints: &fingerprints, - kv: kv, + kv: kv, - context: &context{ - fa: &fingerprints, - grp: grp, - rng: rng, - myID: myID, - }, + context: &context{ + fa: &fingerprints, + grp: grp, + rng: rng, + myID: myID, + }, - e2eParams: params.GetDefaultE2ESessionParams(), + e2eParams: params.GetDefaultE2ESessionParams(), } err := util.StoreCyclicKey(kv, pubKey, pubKeyKey) diff --git a/storage/e2e/store_test.go b/storage/e2e/store_test.go index d6e112840dd4defe527bde7e4bcac4f053977fa5..229799b57de2b453b75e6c00fad35c539dd12401 100644 --- a/storage/e2e/store_test.go +++ b/storage/e2e/store_test.go @@ -9,7 +9,9 @@ package e2e import ( "bytes" + "github.com/cloudflare/circl/dh/sidh" "gitlab.com/elixxir/client/interfaces/params" + util "gitlab.com/elixxir/client/storage/utility" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/cyclic" @@ -20,12 +22,10 @@ import ( "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/primitives/id" + "io" "math/rand" "reflect" "testing" - "github.com/cloudflare/circl/dh/sidh" - "io" - util "gitlab.com/elixxir/client/storage/utility" ) // Tests happy path of NewStore. @@ -125,7 +125,7 @@ func TestStore_AddPartner(t *testing.T) { } if !reflect.DeepEqual(expectedManager, m) { - t.Errorf("Added Manager not expected.\n\texpected: " + + t.Errorf("Added Manager not expected.\n\texpected: "+ "%v\n\treceived: %v", expectedManager, m) } } @@ -395,7 +395,7 @@ func genSidhKeys(rng io.Reader, variant sidh.KeyVariant) (*sidh.PrivateKey, *sid sidHPrivKey := util.NewSIDHPrivateKey(variant) sidHPubKey := util.NewSIDHPublicKey(variant) - if err := sidHPrivKey.Generate(rng); err!=nil{ + if err := sidHPrivKey.Generate(rng); err != nil { panic("failure to generate SidH A private key") } sidHPrivKey.GeneratePublicKey(sidHPubKey) diff --git a/storage/reception/fake_test.go b/storage/reception/fake_test.go index 3e9ab209cd7279aeb97ade25a2227a82b1c42940..af2cae004403c353c65b38a0499c594399f6ed1b 100644 --- a/storage/reception/fake_test.go +++ b/storage/reception/fake_test.go @@ -19,8 +19,7 @@ func Test_generateFakeIdentity(t *testing.T) { startValid, _ := json.Marshal(time.Unix(0, 1258407803759765625)) endValid, _ := json.Marshal(time.Unix(0, 1258494203759765625)) expected := "{\"EphId\":[0,0,0,0,0,0,46,197]," + - "\"Source\":[83,140,127,150,177,100,191,27,151,187,159,75,180,114," + - "232,159,91,20,132,242,82,9,201,217,52,62,146,186,9,221,157,82,3]," + + "\"Source\":\"U4x/lrFkvxuXu59LtHLon1sUhPJSCcnZND6SugndnVID\"," + "\"AddressSize\":" + strconv.Itoa(int(addressSize)) + "," + "\"End\":" + string(end) + ",\"ExtraChecks\":0," + "\"StartValid\":" + string(startValid) + "," + diff --git a/storage/utility/sidh.go b/storage/utility/sidh.go index d4bef091fd349871c3d287326e006fff3c9a0b76..d8082d872944fa2a24e9f04142e53aff8944f0e7 100644 --- a/storage/utility/sidh.go +++ b/storage/utility/sidh.go @@ -8,14 +8,14 @@ package utility import ( - "gitlab.com/elixxir/client/storage/versioned" - "gitlab.com/xx_network/primitives/netTime" - "github.com/cloudflare/circl/dh/sidh" "encoding/base64" - sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" - "gitlab.com/xx_network/primitives/id" "fmt" + "github.com/cloudflare/circl/dh/sidh" jww "github.com/spf13/jwalterweatherman" + sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" + "gitlab.com/elixxir/client/storage/versioned" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "io" ) @@ -48,7 +48,7 @@ func GenerateSIDHKeyPair(variant sidh.KeyVariant, rng io.Reader) ( priv := NewSIDHPrivateKey(variant) pub := NewSIDHPublicKey(variant) - if err := priv.Generate(rng); err!=nil { + if err := priv.Generate(rng); err != nil { jww.FATAL.Panicf("Unable to generate SIDH private key: %+v", err) } @@ -72,8 +72,6 @@ func StringSIDHPrivKey(k *sidh.PrivateKey) string { return StringSIDHPubKey(pubK) } - - //// // Public Key Storage utility functions //// diff --git a/storage/utility/sidh_test.go b/storage/utility/sidh_test.go index f2245cd86edd75ead64344c1e495cc04159933c3..13b557c493c277a7f292d99e8cf293ad8f3d6583 100644 --- a/storage/utility/sidh_test.go +++ b/storage/utility/sidh_test.go @@ -8,12 +8,12 @@ package utility import ( + "github.com/cloudflare/circl/dh/sidh" "gitlab.com/elixxir/client/storage/versioned" - "gitlab.com/xx_network/crypto/csprng" "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/crypto/csprng" "testing" - "github.com/cloudflare/circl/dh/sidh" ) // TestStoreLoadDeleteSIDHPublicKey tests the load/store/delete functions @@ -82,7 +82,6 @@ func TestStoreLoadDeleteSIDHPublicKey(t *testing.T) { myRng.Close() } - // TestStoreLoadDeleteSIDHPublicKey tests the load/store/delete functions // for SIDH Private Keys func TestStoreLoadDeleteSIDHPrivateKey(t *testing.T) {