From f34cffdfc94293b43a4440c81ab8f9008edaebcf Mon Sep 17 00:00:00 2001 From: josh <josh@elixxir.io> Date: Mon, 27 Dec 2021 11:10:02 -0800 Subject: [PATCH] Fix tests and formatting --- api/authenticatedChannel.go | 6 ++-- auth/callback.go | 23 ++++++------- auth/confirm.go | 2 +- auth/fmt.go | 16 +++++----- auth/fmt_test.go | 17 +++++----- auth/request.go | 7 ++-- bindings/client.go | 2 +- bindings/notifications.go | 9 ++---- bindings/notifications_test.go | 55 ++++++++++++++++---------------- fileTransfer/manager_test.go | 7 ++-- fileTransfer/send_test.go | 5 ++- fileTransfer/utils_test.go | 4 +-- groupChat/makeGroup_test.go | 6 ++-- groupChat/receiveRequest_test.go | 5 ++- interfaces/params/E2E.go | 10 +++--- interfaces/params/E2E_test.go | 2 +- interfaces/sidh/sidh.go | 1 + keyExchange/confirm.go | 6 ++-- keyExchange/confirm_test.go | 6 ++-- keyExchange/exchange_test.go | 8 ++--- keyExchange/rekey.go | 4 +-- keyExchange/trigger.go | 7 ++-- keyExchange/trigger_test.go | 8 ++--- keyExchange/utils_test.go | 6 ++-- network/message/garbled_test.go | 4 +-- network/message/sendCmix.go | 4 +-- network/message/sendE2E.go | 4 +-- network/rounds/retrieve.go | 1 - storage/auth/sentRequest.go | 15 ++++----- storage/auth/store.go | 2 +- storage/auth/store_test.go | 34 ++++++++++---------- storage/e2e/key.go | 8 ++--- storage/e2e/key_test.go | 5 ++- storage/e2e/manager.go | 4 +-- storage/e2e/manager_test.go | 10 +++--- storage/e2e/relationship.go | 2 +- storage/e2e/relationship_test.go | 16 +++++----- storage/e2e/session.go | 9 +++--- storage/e2e/session_test.go | 26 +++++++-------- storage/e2e/store.go | 28 ++++++++-------- storage/e2e/store_test.go | 10 +++--- storage/reception/fake_test.go | 3 +- storage/utility/sidh.go | 14 ++++---- storage/utility/sidh_test.go | 5 ++- 44 files changed, 201 insertions(+), 225 deletions(-) diff --git a/api/authenticatedChannel.go b/api/authenticatedChannel.go index 786b0cc98..84fd75117 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 594c4fa9a..5925c7a4d 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 546d1372a..2a8169d21 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 48a7cf551..335867f41 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 af990942d..1178fc0b7 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 e7bb89450..1f63d7e15 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 7d18a1f43..9f2c1b300 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 27d927dee..7c7bc0775 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 53e5c9110..b180d09d7 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 e908eea35..8d556d07f 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 49556db3b..94897c3a2 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 7d9d84553..85bd6f9e0 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 b8a30199a..056355d31 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 760e7685e..0e51cfdc8 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 a33ae9fc2..9d473c429 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 1f88dba4c..aa383c42f 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 ca10626fb..81468e4be 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 df5b2bdb7..d754acc1d 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 fcded9932..08b539a05 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 4da104231..7bf6cbad9 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 03dfcde06..9acbae993 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 bf29c1a18..9e3bf66a3 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 448a3477a..6bfdb41e7 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 bcb0321b6..a6b5afead 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 3dcf059ae..8656eda57 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 7e1e72620..99010f157 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 3d32c6f6b..fba278fba 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 a6b7b85c2..b5fdc8e52 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 2b42df472..1ab1cb8e8 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 0cfdbdb22..addd3d138 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 e84e125cf..b1c4bb92b 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 8f49aa3db..bd203c88e 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 8ab67500d..acf235b0e 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 08a9953c6..d8ec60e65 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 1866baccf..24c0f9ab8 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 72342e54b..c54584176 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 504c4d224..bd2129225 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 96185b32d..5f05d882b 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 3063cc414..58b2ed87b 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 5650c1025..9be32c5c4 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 d6e112840..229799b57 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 3e9ab209c..af2cae004 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 d4bef091f..d8082d872 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 f2245cd86..13b557c49 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) { -- GitLab