diff --git a/.gitignore b/.gitignore index 30f29f0e733db9a0ae86702d463517e7be394e29..62d17d343d1b27f52c143eea6eab0920bc7619ab 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,8 @@ localdev_* *.class *.aar *.jar +# Ignore test output related to ekv +.ekv* +.*test* +*.1 +*.2 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 939c429d956d80ba7afb9d650f9b4cacf6d4df3d..c56744a67dec1aea996233813306d47f405a54e8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ variables: REPO_DIR: gitlab.com/elixxir REPO_NAME: client DOCKER_IMAGE: elixxirlabs/cuda-go:latest - MIN_CODE_COVERAGE: "74" + MIN_CODE_COVERAGE: "73.5" before_script: ## diff --git a/Makefile b/Makefile index b8d85b2d4b167ff0347162df66cc69dda12755e3..9c16bd45cb615fabfce834ad0a8e2cdf5518218d 100644 --- a/Makefile +++ b/Makefile @@ -24,12 +24,14 @@ update_release: GOFLAGS="" go get -u gitlab.com/elixxir/crypto@release GOFLAGS="" go get -u gitlab.com/elixxir/comms@release GOFLAGS="" go get -u gitlab.com/xx_network/comms@release + GOFLAGS="" go get -u gitlab.com/xx_network/primitives@release update_master: GOFLAGS="" go get -u gitlab.com/elixxir/primitives@master GOFLAGS="" go get -u gitlab.com/elixxir/crypto@master GOFLAGS="" go get -u gitlab.com/elixxir/comms@master GOFLAGS="" go get -u gitlab.com/xx_network/comms@master + GOFLAGS="" go get -u gitlab.com/xx_network/primitives@master master: clean update_master build version diff --git a/api/client.go b/api/client.go index c9f2bf336194b5cf4dd7169bbc6ca43b5a05bfa0..58697ae0f86e1b9f9c1d3ecb560e4be94af82b6a 100644 --- a/api/client.go +++ b/api/client.go @@ -28,11 +28,12 @@ import ( "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/tls" - "gitlab.com/elixxir/primitives/id" - "gitlab.com/elixxir/primitives/ndf" "gitlab.com/elixxir/primitives/switchboard" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/ndf" goio "io" + "os" "path/filepath" "strings" "testing" @@ -155,10 +156,6 @@ func (cl *Client) Login(password string) (*id.ID, error) { if session == nil { return nil, errors.New("Unable to load session, no error reported") } - if session.GetRegState() < user.KeyGenComplete { - return nil, errors.New("Cannot log a user in which has not " + - "completed registration ") - } cl.session = session @@ -172,6 +169,21 @@ func (cl *Client) Login(password string) (*id.ID, error) { } cl.sessionV2 = io.SessionV2 + regState, err := io.SessionV2.GetRegState() + // fixme ! + if err != nil && os.IsNotExist(err) { + io.SessionV2.SetRegState(user.KeyGenComplete) + regState, _ = io.SessionV2.GetRegState() + + } else if err != nil { + return nil, errors.Wrap(err, "Login: Could not login: Could not get regState") + } + + if regState < user.KeyGenComplete { + return nil, errors.New("Cannot log a user in which has not " + + "completed registration ") + } + newRm, err := io.NewReceptionManager(cl.rekeyChan, cl.session.GetCurrentUser().User, rsa.CreatePrivateKeyPem(cl.session.GetRSAPrivateKey()), rsa.CreatePublicKeyPem(cl.session.GetRSAPublicKey()), @@ -441,30 +453,28 @@ type SearchCallback interface { func (cl *Client) SearchForUser(emailAddress string, cb SearchCallback, timeout time.Duration) { //see if the user has been searched before, if it has, return it - uid, pk := cl.session.GetContactByValue(emailAddress) + contact, err := cl.sessionV2.GetContact(emailAddress) - if uid != nil { - cb.Callback(uid.Bytes(), pk, nil) + // if we successfully got the contact, return it. + // errors can include the email address not existing, + // so errors from the GetContact call are ignored + if contact != nil && err == nil { + cb.Callback(contact.Id.Bytes(), contact.PublicKey, nil) + return } valueType := "EMAIL" go func() { - uid, pubKey, err := bots.Search(valueType, emailAddress, cl.opStatus, timeout) - if err == nil && uid != nil && pubKey != nil { + contact, err := bots.Search(valueType, emailAddress, cl.opStatus, timeout) + if err == nil && contact.Id != nil && contact.PublicKey != nil { cl.opStatus(globals.UDB_SEARCH_BUILD_CREDS) - err = cl.registerUserE2E(uid, pubKey) + err = cl.registerUserE2E(contact) if err != nil { - cb.Callback(uid[:], pubKey, err) + cb.Callback(contact.Id.Bytes(), contact.PublicKey, err) return } //store the user so future lookups can find it - cl.session.StoreContactByValue(emailAddress, uid, pubKey) - - err = cl.session.StoreSession() - if err != nil { - cb.Callback(uid[:], pubKey, err) - return - } + err = cl.sessionV2.SetContact(emailAddress, contact) // If there is something in the channel then send it; otherwise, // skip over it @@ -473,7 +483,7 @@ func (cl *Client) SearchForUser(emailAddress string, default: } - cb.Callback(uid[:], pubKey, err) + cb.Callback(contact.Id.Bytes(), contact.PublicKey, err) } else { if err == nil { @@ -598,6 +608,12 @@ func (cl *Client) GetSession() user.Session { return cl.session } +// GetSession returns the session object for external access. Access at yourx +// own risk +func (cl *Client) GetSessionV2() *storage.Session { + return cl.sessionV2 +} + // ReceptionManager returns the comm manager object for external access. Access // at your own risk func (cl *Client) GetCommManager() *io.ReceptionManager { diff --git a/api/client_test.go b/api/client_test.go index 190efcefc6096cd7dbf4b7e3085418a0eb546a0a..fcd302c1e629d82a474f5a7ec59010be557f9618 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -13,6 +13,7 @@ import ( "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/keyStore" "gitlab.com/elixxir/client/parse" + "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/crypto/csprng" "gitlab.com/elixxir/crypto/cyclic" @@ -22,7 +23,7 @@ import ( "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "reflect" "testing" "time" @@ -177,7 +178,13 @@ func TestRegisterUserE2E(t *testing.T) { testClient.session = session - testClient.registerUserE2E(partner, partnerPubKeyCyclic.Bytes()) + err = testClient.registerUserE2E(&storage.Contact{ + Id: partner, + PublicKey: partnerPubKeyCyclic.Bytes(), + }) + if err != nil { + t.Fatal(err) + } // Confirm we can get all types of keys km := session.GetKeyStore().GetSendManager(partner) @@ -243,7 +250,7 @@ func TestRegisterUserE2E(t *testing.T) { func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { testClient, err := NewClient(&globals.RamStorage{}, ".ekv-testrege2e-allkeys", "", def) if err != nil { - t.Error(err) + t.Fatal(err) } cmixGrp, e2eGrp := getGroups() @@ -268,7 +275,13 @@ func TestRegisterUserE2E_CheckAllKeys(t *testing.T) { testClient.session = session - testClient.registerUserE2E(partner, partnerPubKeyCyclic.Bytes()) + err = testClient.registerUserE2E(&storage.Contact{ + Id: partner, + PublicKey: partnerPubKeyCyclic.Bytes(), + }) + if err != nil { + t.Fatal(err) + } // Generate all keys and confirm they all match keyParams := testClient.GetKeyParams() @@ -712,8 +725,8 @@ func TestClient_LogoutTimeout(t *testing.T) { // Test that if we logout we can logback in. func TestClient_LogoutAndLoginAgain(t *testing.T) { //Initialize a client - storage := &DummyStorage{LocationA: ".ekv-logoutlogin", StoreA: []byte{'a', 'b', 'c'}} - tc, err := NewClient(storage, ".ekv-logoutlogin", "", def) + dummyStorage := &DummyStorage{LocationA: ".ekv-logoutlogin", StoreA: []byte{'a', 'b', 'c'}} + tc, err := NewClient(dummyStorage, ".ekv-logoutlogin", "", def) if err != nil { t.Errorf("Failed to create new client: %+v", err) } @@ -750,7 +763,7 @@ func TestClient_LogoutAndLoginAgain(t *testing.T) { } //Redefine client with old session files and attempt to login. - tc, err = NewClient(storage, ".ekv-logoutlogin", "", def) + tc, err = NewClient(dummyStorage, ".ekv-logoutlogin", "", def) if err != nil { t.Errorf("Failed second client initialization: %+v", err) } @@ -759,6 +772,8 @@ func TestClient_LogoutAndLoginAgain(t *testing.T) { t.Fatalf("InitNetwork should have succeeded when creating second client %v", err) } + io.SessionV2.SetRegState(user.PermissioningComplete) + _, err = tc.Login("password") if err != nil { t.Logf("Login failed %+v", err) diff --git a/api/connect.go b/api/connect.go index 928e47f63b522974a51d4fd6b9f1744482b8fb81..212df62a74048e8f40279a75b64653f37a7a7207 100644 --- a/api/connect.go +++ b/api/connect.go @@ -11,10 +11,10 @@ import ( "github.com/pkg/errors" "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/io" - "gitlab.com/elixxir/primitives/id" - "gitlab.com/elixxir/primitives/ndf" "gitlab.com/elixxir/primitives/version" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/ndf" ) var ErrNoPermissioning = errors.New("No Permissioning In NDF") diff --git a/api/mockserver.go b/api/mockserver.go index a0ac4fc9dddb8f5dcfd48d6b7ef51fe5446ec8d5..2d363d7f3d333cc4db983f4ec2380fe053668fee 100644 --- a/api/mockserver.go +++ b/api/mockserver.go @@ -19,10 +19,10 @@ import ( "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" - "gitlab.com/elixxir/primitives/ndf" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/messages" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/ndf" "sync" "time" ) @@ -353,7 +353,6 @@ func (m *GatewayHandlerMultipleMessages) CheckMessages(userId *id.ID, // PutMessage adds a message to the outgoing queue and // calls SendBatch when it's size is the batch size func (m *GatewayHandlerMultipleMessages) PutMessage(msg *pb.GatewaySlot, ipaddr string) (*pb.GatewaySlotResponse, error) { - fmt.Printf("multiMessages\n\n\n") for i := 0; i < BatchSize; i++ { msg.Message.Index = uint32(i) m.LastReceivedMessage = append(m.LastReceivedMessage, *msg.Message) diff --git a/api/mockserver_test.go b/api/mockserver_test.go index 8be4e116dbbbb69eb87a2472e208d957c2aff9e7..ac3f9919dbc48b6cb99ec111bdf0345896a3dbbe 100644 --- a/api/mockserver_test.go +++ b/api/mockserver_test.go @@ -11,15 +11,15 @@ import ( "fmt" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/io" - "gitlab.com/elixxir/client/storage" + clientStorage "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/comms/gateway" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/notificationBot" "gitlab.com/elixxir/comms/registration" - "gitlab.com/elixxir/primitives/id" - "gitlab.com/elixxir/primitives/ndf" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/ndf" "os" "strings" "testing" @@ -60,7 +60,7 @@ func TestMain(m *testing.M) { // Set logging params jww.SetLogThreshold(jww.LevelTrace) jww.SetStdoutThreshold(jww.LevelTrace) - io.SessionV2, _ = storage.Init(".ekvapi", "test") + io.SessionV2, _ = clientStorage.Init(".ekvapi", "test") os.Exit(testMainWrapper(m)) } @@ -81,8 +81,8 @@ func TestClient_StartMessageReceiver_MultipleMessages(t *testing.T) { } testDef.Nodes = def.Nodes - - storage := DummyStorage{LocationA: ".ekv-messagereceiver-multiple", StoreA: []byte{'a', 'b', 'c'}} + locA := ".ekv-messagereceiver-multiple" + storage := DummyStorage{LocationA: locA, StoreA: []byte{'a', 'b', 'c'}} client, err := NewClient(&storage, ".ekv-messagereceiver-multiple", "", testDef) if err != nil { t.Errorf("Failed to initialize dummy client: %s", err.Error()) @@ -100,6 +100,8 @@ func TestClient_StartMessageReceiver_MultipleMessages(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) + // Register with a valid registration code _, err = client.RegisterWithPermissioning(true, ValidRegCode) @@ -158,7 +160,7 @@ func TestRegister_ValidPrecannedRegCodeReturnsZeroID(t *testing.T) { if err != nil { t.Errorf("Could not generate Keys: %+v", err) } - + io.SessionV2.SetRegState(user.KeyGenComplete) // Register precanned user with all gateways regRes, err := client.RegisterWithPermissioning(true, ValidRegCode) @@ -293,7 +295,7 @@ func TestSend(t *testing.T) { } err = client.GenerateKeys(nil, "password") - + io.SessionV2.SetRegState(user.KeyGenComplete) // Register with a valid registration code userID, err := client.RegisterWithPermissioning(true, ValidRegCode) @@ -394,6 +396,8 @@ func TestLogout(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) + // Register with a valid registration code _, err = client.RegisterWithPermissioning(true, ValidRegCode) diff --git a/api/ndf_test.go b/api/ndf_test.go index 3a113b52c6cc323f4e478fc3fdf3c24991281823..22b3f3c2d55c6449a782c833c830d6075d7f1252 100644 --- a/api/ndf_test.go +++ b/api/ndf_test.go @@ -12,7 +12,7 @@ import ( "encoding/base64" "fmt" "gitlab.com/elixxir/crypto/signature/rsa" - "gitlab.com/elixxir/primitives/ndf" + "gitlab.com/xx_network/primitives/ndf" "reflect" "testing" ) diff --git a/api/notifications.go b/api/notifications.go index 5d27bf73d22387c378b66f738478dfb927c6ba0f..a7587f4f80c632995dd0cb4c885a5a6189bc7d2e 100644 --- a/api/notifications.go +++ b/api/notifications.go @@ -3,7 +3,7 @@ package api import ( "github.com/pkg/errors" "gitlab.com/elixxir/comms/mixmessages" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" ) // RegisterForNotifications sends a message to notification bot indicating it diff --git a/api/private.go b/api/private.go index bc76f0f36d6f02080c16698ceab5c73a6f6b7caa..8a9bf7b9c368f182af14ae7ce74e96dd530d0e31 100644 --- a/api/private.go +++ b/api/private.go @@ -13,6 +13,7 @@ import ( "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/keyStore" + "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/user" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/crypto/csprng" @@ -22,9 +23,9 @@ import ( "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/xx" - "gitlab.com/elixxir/primitives/id" - "gitlab.com/elixxir/primitives/ndf" "gitlab.com/xx_network/comms/messages" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/ndf" ) const PermissioningAddrID = "Permissioning" @@ -208,16 +209,15 @@ func (cl *Client) confirmNonce(UID, nonce []byte, return nil } -func (cl *Client) registerUserE2E(partnerID *id.ID, - partnerPubKey []byte) error { +func (cl *Client) registerUserE2E(partner *storage.Contact) error { // Check that the returned user is valid - if partnerKeyStore := cl.session.GetKeyStore().GetSendManager(partnerID); partnerKeyStore != nil { + if partnerKeyStore := cl.session.GetKeyStore().GetSendManager(partner.Id); partnerKeyStore != nil { return errors.New(fmt.Sprintf("UDB searched failed for %v because user has "+ - "been searched for before", partnerID)) + "been searched for before", partner.Id)) } - if cl.session.GetCurrentUser().User.Cmp(partnerID) { + if cl.session.GetCurrentUser().User.Cmp(partner.Id) { return errors.New("cannot search for yourself on UDB") } @@ -228,11 +228,11 @@ func (cl *Client) registerUserE2E(partnerID *id.ID, // Create user private key and partner public key // in the group privKeyCyclic := cl.session.GetE2EDHPrivateKey() - partnerPubKeyCyclic := grp.NewIntFromBytes(partnerPubKey) + publicKeyCyclic := grp.NewIntFromBytes(partner.PublicKey) // Generate baseKey baseKey, _ := diffieHellman.CreateDHSessionKey( - partnerPubKeyCyclic, + publicKeyCyclic, privKeyCyclic, grp) @@ -243,7 +243,7 @@ func (cl *Client) registerUserE2E(partnerID *id.ID, // Create Send KeyManager km := keyStore.NewManager(baseKey, privKeyCyclic, - partnerPubKeyCyclic, partnerID, true, + publicKeyCyclic, partner.Id, true, numKeys, keysTTL, params.NumRekeys) // Generate Send Keys @@ -252,7 +252,7 @@ func (cl *Client) registerUserE2E(partnerID *id.ID, // Create Receive KeyManager km = keyStore.NewManager(baseKey, privKeyCyclic, - partnerPubKeyCyclic, partnerID, false, + publicKeyCyclic, partner.Id, false, numKeys, keysTTL, params.NumRekeys) // Generate Receive Keys @@ -265,10 +265,10 @@ func (cl *Client) registerUserE2E(partnerID *id.ID, keys := &keyStore.RekeyKeys{ CurrPrivKey: privKeyCyclic, - CurrPubKey: partnerPubKeyCyclic, + CurrPubKey: publicKeyCyclic, } - rkm.AddKeys(partnerID, keys) + rkm.AddKeys(partner.Id, keys) return nil } diff --git a/api/register.go b/api/register.go index 921738be22150f4fa06a187a0f375a622ce2aaa7..7dd5c28a76c5664167c60bcaf4c904d7c80f8aa4 100644 --- a/api/register.go +++ b/api/register.go @@ -12,14 +12,16 @@ import ( "github.com/pkg/errors" "gitlab.com/elixxir/client/bots" "gitlab.com/elixxir/client/globals" + "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/registration" "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/tls" - "gitlab.com/elixxir/primitives/id" - "gitlab.com/elixxir/primitives/ndf" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/ndf" + "os" "sync" "time" ) @@ -30,12 +32,16 @@ const SaltSize = 32 // Returns an error if registration fails. func (cl *Client) RegisterWithPermissioning(preCan bool, registrationCode string) (*id.ID, error) { //Check the regState is in proper state for registration - if cl.session.GetRegState() != user.KeyGenComplete { + regState, err := io.SessionV2.GetRegState() + if err != nil { + return nil, err + } + + if regState != user.KeyGenComplete { return nil, errors.Errorf("Attempting to register before key generation!") } usr := cl.session.GetCurrentUser() UID := usr.User - var err error //Initialized response from Registration Server regValidationSignature := make([]byte, 0) @@ -59,10 +65,11 @@ func (cl *Client) RegisterWithPermissioning(preCan bool, registrationCode string for n, k := range nodeKeyMap { cl.session.PushNodeKey(&n, k) } + //update the state - err := cl.session.SetRegState(user.PermissioningComplete) + err = io.SessionV2.SetRegState(user.PermissioningComplete) if err != nil { - return nil, errors.Wrap(err, "Could not do precanned registration") + return &id.ZeroUser, err } } else { @@ -73,11 +80,16 @@ func (cl *Client) RegisterWithPermissioning(preCan bool, registrationCode string return &id.ZeroUser, err } //update the session with the registration - err = cl.session.RegisterPermissioningSignature(regValidationSignature) + err = io.SessionV2.SetRegState(user.PermissioningComplete) + if err != nil { + return nil, err + } + err = io.SessionV2.SetRegValidationSig(regValidationSignature) if err != nil { return nil, err } + } //Set the registration secure state @@ -97,16 +109,16 @@ func (cl *Client) RegisterWithPermissioning(preCan bool, registrationCode string // User discovery. Must be called after Register and InitNetwork. // It will fail if the user has already registered with UDB func (cl *Client) RegisterWithUDB(username string, timeout time.Duration) error { - - regState := cl.GetSession().GetRegState() + regState, err := io.SessionV2.GetRegState() + if err != nil { + return err + } if regState != user.PermissioningComplete { return errors.New("Cannot register with UDB when registration " + "state is not PermissioningComplete") } - var err error - if username != "" { err := cl.session.ChangeUsername(username) if err != nil { @@ -129,8 +141,7 @@ func (cl *Client) RegisterWithUDB(username string, timeout time.Duration) error } //set the registration state - err = cl.session.SetRegState(user.UDBComplete) - + err = io.SessionV2.SetRegState(user.UDBComplete) if err != nil { return errors.Wrap(err, "UDB Registration Failed") } @@ -169,7 +180,10 @@ func (cl *Client) RegisterWithNodes() error { UID := session.GetCurrentUser().User usr := session.GetCurrentUser() //Load the registration signature - regSignature := session.GetRegistrationValidationSignature() + regSignature, err := io.SessionV2.GetRegValidationSig() + if err != nil && !os.IsNotExist(err) { + return errors.Errorf("Failed to get registration signature: %v", err) + } // Storage of the registration signature was broken in previous releases. // get the signature again from permissioning if it is absent @@ -194,7 +208,11 @@ func (cl *Client) RegisterWithNodes() error { //update the session with the registration //HACK HACK HACK sesObj := cl.session.(*user.SessionObj) - sesObj.RegValidationSignature = regSignature + err = io.SessionV2.SetRegValidationSig(regSignature) + if err != nil { + return err + } + err = sesObj.StoreSession() if err != nil { diff --git a/api/register_test.go b/api/register_test.go index 291c655ba337e403603cce19de94268e12272a3e..055c9a8a222d2cdb3f405815c396c62963d143af 100644 --- a/api/register_test.go +++ b/api/register_test.go @@ -8,9 +8,10 @@ package api import ( "crypto/sha256" "gitlab.com/elixxir/client/globals" + "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/user" - "gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "testing" ) @@ -31,6 +32,8 @@ func TestRegistrationGob(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) + // populate a gob in the store _, err = testClient.RegisterWithPermissioning(true, "WTROXJ33") if err != nil { @@ -74,6 +77,8 @@ func TestClient_Register(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + // fixme please (and all other places where this call is above RegisterWithPermissioning in tests) + io.SessionV2.SetRegState(user.KeyGenComplete) // populate a gob in the store _, err = testClient.RegisterWithPermissioning(true, "WTROXJ33") if err != nil { @@ -146,6 +151,7 @@ func TestRegister_ValidRegParams___(t *testing.T) { t.Errorf("%+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) // Register precanned user with all gateways regRes, err := client.RegisterWithPermissioning(false, ValidRegCode) if err != nil { diff --git a/bindings/client.go b/bindings/client.go index 480a55fe8ec810be1e112cb91265b90f8e99d13f..834bbfd3bd750259edd1313b99005efb69a18c0a 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -9,12 +9,15 @@ package bindings import ( "crypto/rand" "errors" + "fmt" "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/globals" + clientIo "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/parse" + "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/crypto/csprng" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "io" "math/big" "strings" @@ -254,6 +257,14 @@ func (cl *Client) backoff(backoffCount int) { func (cl *Client) ChangeUsername(un string) error { globals.Log.INFO.Printf("Binding call: ChangeUsername()\n"+ " username: %s", un) + regState, err := clientIo.SessionV2.GetRegState() + if err != nil { + return errors.New(fmt.Sprintf("Could not get reg state: %v", err)) + } + if regState != user.PermissioningComplete { + return errors.New("Can only change username during " + + "PermissioningComplete registration state") + } return cl.client.GetSession().ChangeUsername(un) } diff --git a/bindings/client_test.go b/bindings/client_test.go index cddfb41381e04481f5e9fbca3deae8a47b761dee..a0fbf4ba73d9b795aa670e53e2d7c987407a5900 100644 --- a/bindings/client_test.go +++ b/bindings/client_test.go @@ -25,10 +25,10 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/signature/rsa" - "gitlab.com/elixxir/primitives/id" - "gitlab.com/elixxir/primitives/ndf" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/messages" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/ndf" "math/rand" "os" "reflect" @@ -141,6 +141,8 @@ func TestRegister(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) + regRes, err := client.RegisterWithPermissioning(true, ValidRegCode) if err != nil { t.Errorf("Registration failed: %s", err.Error()) @@ -303,6 +305,7 @@ func TestClient_GetRegState(t *testing.T) { if err != nil { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) // Register with a valid registration code _, err = testClient.RegisterWithPermissioning(true, ValidRegCode) @@ -311,11 +314,14 @@ func TestClient_GetRegState(t *testing.T) { t.Errorf("Register with permissioning failed: %s", err.Error()) } - if testClient.GetRegState() != int64(user.PermissioningComplete) { + regState, _ := io.SessionV2.GetRegState() + if regState != int64(user.PermissioningComplete) { t.Errorf("Unexpected reg state: Expected PermissioningComplete (%d), recieved: %d", user.PermissioningComplete, testClient.GetRegState()) } + io.SessionV2.SetRegValidationSig([]byte("test")) + err = testClient.RegisterWithNodes() if err != nil { t.Errorf("Register with nodes failed: %v", err.Error()) @@ -343,6 +349,8 @@ func TestClient_Send(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) + // Register with a valid registration code userID, err := testClient.RegisterWithPermissioning(true, ValidRegCode) @@ -424,6 +432,7 @@ func TestLoginLogout(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) regRes, err := client.RegisterWithPermissioning(true, ValidRegCode) loginRes, err2 := client.Login(regRes, "password") if err2 != nil { @@ -472,6 +481,7 @@ func TestListen(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) regRes, _ := client.RegisterWithPermissioning(true, ValidRegCode) _, err = client.Login(regRes, "password") @@ -519,6 +529,7 @@ func TestStopListening(t *testing.T) { t.Errorf("Could not generate Keys: %+v", err) } + io.SessionV2.SetRegState(user.KeyGenComplete) regRes, _ := client.RegisterWithPermissioning(true, ValidRegCode) _, err = client.Login(regRes, "password") diff --git a/bots/bots.go b/bots/bots.go index 6cf0bdc3cee88b91aa0bc11a279cf0789a3a39ce..815e183370da872d587fb893445d0824326b43a9 100644 --- a/bots/bots.go +++ b/bots/bots.go @@ -6,9 +6,9 @@ import ( "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/user" - "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/switchboard" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" ) var session user.Session diff --git a/bots/bots_test.go b/bots/bots_test.go index 6f0c7edba4e04504b780cf8039028940a7e25986..1efab52c84adcedf5b2a4b28b9e839734f736e39 100644 --- a/bots/bots_test.go +++ b/bots/bots_test.go @@ -20,8 +20,8 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "os" "strings" "testing" @@ -126,11 +126,6 @@ func TestRegister(t *testing.T) { // TestSearch smoke tests the search function func TestSearch(t *testing.T) { publicKeyString := base64.StdEncoding.EncodeToString(pubKey) - //uid := id.NewIdFromUInt(26, id.User, t) - //serRetUid := base64.StdEncoding.EncodeToString(uid[:]) - //result, _ := base64.StdEncoding.DecodeString(serRetUid) - //t.Fatal(serRetUid) - //t.Fatal(len(result)) // Send response messages from fake UDB in advance searchResponseListener <- "blah@elixxir.io FOUND UR69db14ZyicpZVqJ1HFC5rk9UZ8817aV6+VHmrJpGc= AAAAAAAAABoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD 8oKh7TYG4KxQcBAymoXPBHSD/uga9pX3Mn/jKhvcD8M=" @@ -141,16 +136,19 @@ func TestSearch(t *testing.T) { return } - searchedUser, _, err := Search("EMAIL", "blah@elixxir.io", + searchedUser, err := Search("EMAIL", "blah@elixxir.io", dummySearchState, 30*time.Second) if err != nil { - t.Errorf("Error on Search: %s", err.Error()) + t.Fatalf("Error on Search: %s", err.Error()) } - if !searchedUser.Cmp(id.NewIdFromUInt(26, id.User, t)) { + if !searchedUser.Id.Cmp(id.NewIdFromUInt(26, id.User, t)) { t.Errorf("Search did not return user ID 26! returned %s", searchedUser) } //Test the timeout capabilities - searchedUser, _, err = Search("EMAIL", "blah@elixxir.io", dummySearchState, 1*time.Millisecond) + searchedUser, err = Search("EMAIL", "blah@elixxir.io", dummySearchState, 1*time.Millisecond) + if err == nil { + t.Fatal("udb search timeout should have caused error") + } if strings.Compare(err.Error(), "UDB search timeout exceeded on user lookup") != 0 { t.Errorf("error: %v", err) } diff --git a/bots/userDiscovery.go b/bots/userDiscovery.go index d84976c955d24e3814939419a7d3c8541dae07fc..5d3404d9e56a620185eee74f657fd5bef768fade 100644 --- a/bots/userDiscovery.go +++ b/bots/userDiscovery.go @@ -16,8 +16,9 @@ import ( "gitlab.com/elixxir/client/cmixproto" "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/parse" + "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/crypto/hash" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "strings" "time" ) @@ -38,7 +39,7 @@ func Register(valueType, value string, publicKey []byte, regStatus func(int), ti if valueType == "EMAIL" { value, err = hashAndEncode(strings.ToLower(value)) if err != nil { - return fmt.Errorf("Could not hash and encode email %s: %+v", value, err) + return fmt.Errorf("could not hash and encode email %s: %+v", value, err) } } @@ -114,7 +115,7 @@ func Register(valueType, value string, publicKey []byte, regStatus func(int), ti // Search returns a userID and public key based on the search criteria // it accepts a valueType of EMAIL and value of an e-mail address, and // returns a map of userid -> public key -func Search(valueType, value string, searchStatus func(int), timeout time.Duration) (*id.ID, []byte, error) { +func Search(valueType, value string, searchStatus func(int), timeout time.Duration) (*storage.Contact, error) { globals.Log.DEBUG.Printf("Running search for %v, %v", valueType, value) searchTimeout := time.NewTimer(timeout) @@ -123,7 +124,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati if valueType == "EMAIL" { value, err = hashAndEncode(strings.ToLower(value)) if err != nil { - return nil, nil, fmt.Errorf("Could not hash and encode email %s: %+v", value, err) + return nil, fmt.Errorf("could not hash and encode email %s: %+v", value, err) } } @@ -135,7 +136,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati }) err = sendCommand(&id.UDB, msgBody) if err != nil { - return nil, nil, err + return nil, err } var response string @@ -149,20 +150,20 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati case response = <-searchResponseListener: empty := fmt.Sprintf("SEARCH %s NOTFOUND", value) if response == empty { - return nil, nil, nil + return nil, nil } if strings.Contains(response, value) { found = true } case <-searchTimeout.C: - return nil, nil, errors.New("UDB search timeout exceeded on user lookup") + return nil, errors.New("UDB search timeout exceeded on user lookup") } } // While search returns more than 1 result, we only process the first cMixUID, keyFP, err := parseSearch(response) if err != nil { - return nil, nil, err + return nil, err } searchStatus(globals.UDB_SEARCH_GETKEY) @@ -174,7 +175,7 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati }) err = sendCommand(&id.UDB, msgBody) if err != nil { - return nil, nil, err + return nil, err } // wait for the response to searching for the key against the timeout. @@ -187,13 +188,16 @@ func Search(valueType, value string, searchStatus func(int), timeout time.Durati found = true } case <-searchTimeout.C: - return nil, nil, errors.New("UDB search timeout exceeded on key lookup") + return nil, errors.New("UDB search timeout exceeded on key lookup") } } publicKey := parseGetKey(response) - return cMixUID, publicKey, nil + return &storage.Contact{ + Id: cMixUID, + PublicKey: publicKey, + }, nil } func hashAndEncode(s string) (string, error) { diff --git a/cmd/root.go b/cmd/root.go index 825cb3218ef90899680dff436a6f9d2f6478a3d5..ed8473d5521f96dbd7ec8afe1f8aae18268645f3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,12 +18,13 @@ import ( "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/cmixproto" "gitlab.com/elixxir/client/globals" + "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/crypto/signature/rsa" - "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/switchboard" "gitlab.com/elixxir/primitives/utils" + "gitlab.com/xx_network/primitives/id" "io/ioutil" "os" "strconv" @@ -441,7 +442,12 @@ var rootCmd = &cobra.Command{ // todo: since this is in the root cmd, would checking the regstate directly really be bad? // It's correct that it should be an error state for RegisterWithUDB, however for this, it's start up code - if username != "" && client.GetSession().GetRegState() == user.PermissioningComplete { + regState, err := io.SessionV2.GetRegState() + if err != nil { + globals.Log.FATAL.Panicf("Could not retrieve registration state: %v", err) + } + + if username != "" && regState == user.PermissioningComplete { err := client.RegisterWithUDB(username, 2*time.Minute) if err != nil { globals.Log.ERROR.Printf("%+v", err) diff --git a/cmd/udb.go b/cmd/udb.go index ed39e5d8be21880cc3b3540c64d214c8f6e87b12..9935a5382ce96f36434576c641a4a18f25aa11de 100644 --- a/cmd/udb.go +++ b/cmd/udb.go @@ -9,7 +9,7 @@ package cmd import ( "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/globals" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "strings" "time" ) diff --git a/crypto/encryptdecrypt_test.go b/crypto/encryptdecrypt_test.go index 7cc9ad2c852126e10e63b560486946d7864f3066..3e7d30506a5504abee1f285806fb9eda01d7192b 100644 --- a/crypto/encryptdecrypt_test.go +++ b/crypto/encryptdecrypt_test.go @@ -16,8 +16,8 @@ import ( "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "golang.org/x/crypto/blake2b" "os" "testing" diff --git a/globals/version_vars.go b/globals/version_vars.go index 1172fd30b4685ba23b945d5de6cf4efe61a5a96a..e20266b2b707fe9641e8453e67a725a58429912b 100644 --- a/globals/version_vars.go +++ b/globals/version_vars.go @@ -1,15 +1,9 @@ -//////////////////////////////////////////////////////////////////////////////// -// Copyright © 2020 Privategrity Corporation / -// / -// All rights reserved. / -//////////////////////////////////////////////////////////////////////////////// - // Code generated by go generate; DO NOT EDIT. // This file was generated by robots at -// 2020-08-04 14:03:41.019893 -0700 PDT m=+0.029153253 +// 2020-08-06 10:52:35.96635741 -0700 PDT m=+0.008615574 package globals -const GITVERSION = `dc3e415 re-enable session smoke test` +const GITVERSION = `d97700f Merge branch 'XX-2418/ClientStorage-Registration' of gitlab.com:elixxir/client into XX-2418/ClientStorage-Registration` const SEMVER = "1.4.0" const DEPENDENCIES = `module gitlab.com/elixxir/client @@ -28,17 +22,16 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.6.2 - gitlab.com/elixxir/comms v0.0.0-20200803223713-26b69d6adff9 - gitlab.com/elixxir/crypto v0.0.0-20200803223738-661ca14b6470 - gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842 - gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d - gitlab.com/xx_network/comms v0.0.0-20200803203304-a7a1c5e4239d - golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 + gitlab.com/elixxir/comms v0.0.0-20200805174832-240bba97beaa + gitlab.com/elixxir/crypto v0.0.0-20200805174804-bdf909f2a16d + gitlab.com/elixxir/ekv v0.1.1 + gitlab.com/elixxir/primitives v0.0.0-20200805174810-86b366d1dd2d + gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023 + gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da + golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de + golang.org/x/sys v0.0.0-20200806125547-5acd03effb82 // indirect gopkg.in/ini.v1 v1.52.0 // indirect ) -replace ( - gitlab.com/xx_network/collections/ring => gitlab.com/xx_network/collections/ring.git v0.0.1 - google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1 -) +replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1 ` diff --git a/go.mod b/go.mod index 02a7a34737a3d0ef3fa7cd400f9e46016bebd9a7..dd4027a2473bb8aef8db64504fa537c4d9fc5c4b 100644 --- a/go.mod +++ b/go.mod @@ -15,17 +15,15 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.6.2 - gitlab.com/elixxir/comms v0.0.0-20200803223713-26b69d6adff9 - gitlab.com/elixxir/crypto v0.0.0-20200803223738-661ca14b6470 - gitlab.com/elixxir/ekv v0.1.0 - gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d - gitlab.com/xx_network/comms v0.0.0-20200803203304-a7a1c5e4239d + gitlab.com/elixxir/comms v0.0.0-20200805174832-240bba97beaa + gitlab.com/elixxir/crypto v0.0.0-20200805174804-bdf909f2a16d + gitlab.com/elixxir/ekv v0.1.1 + gitlab.com/elixxir/primitives v0.0.0-20200805174810-86b366d1dd2d + gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023 + gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de - golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 // indirect + golang.org/x/sys v0.0.0-20200806125547-5acd03effb82 // indirect gopkg.in/ini.v1 v1.52.0 // indirect ) -replace ( - gitlab.com/xx_network/collections/ring => gitlab.com/xx_network/collections/ring.git v0.0.1 - google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1 -) +replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1 diff --git a/go.sum b/go.sum index c9189bcbdf590bdc80400c5ba85e43cc3e3d1eba..6daefd75f3b24c3ed997c6c6a0ac1ae451d6a170 100644 --- a/go.sum +++ b/go.sum @@ -161,29 +161,32 @@ github.com/zeebo/assert v0.0.0-20181109011804-10f827ce2ed6/go.mod h1:yssERNPivll github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= github.com/zeebo/blake3 v0.0.4/go.mod h1:YOZo8A49yNqM0X/Y+JmDUZshJWLt1laHsNSn5ny2i34= github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm//LBaEvBiaXY7hXJ6KGe2V32X2F6E= -gitlab.com/elixxir/comms v0.0.0-20200707210150-b8ebd0951d23/go.mod h1:OsWMZ1O/R9fOkm+PoHnR3rkXfFtipGoPs73FuKuurHY= -gitlab.com/elixxir/comms v0.0.0-20200803223713-26b69d6adff9 h1:CqlisVYRzrOnGcGy0ER8dfRT7qIKUeD7vPQ8Jl3W08g= -gitlab.com/elixxir/comms v0.0.0-20200803223713-26b69d6adff9/go.mod h1:JLUr1981dSoxSDgOKCDPrf9d+SSYexGm6iKFoZiRZ/M= -gitlab.com/elixxir/crypto v0.0.0-20200707005343-97f868cbd930 h1:9qzfwyR12OYgn3j30qcHZHHVfWshWnH54lcAHppEROQ= -gitlab.com/elixxir/crypto v0.0.0-20200707005343-97f868cbd930/go.mod h1:LHBAaEf48a0/AjU118rjoworH0LgXifhAqmNX3ZRvME= -gitlab.com/elixxir/crypto v0.0.0-20200721213839-b026955c55c0 h1:bXpAX607nE2edN7ei8CIAcHuD0kJxDdGFusK51qlxN4= -gitlab.com/elixxir/crypto v0.0.0-20200721213839-b026955c55c0/go.mod h1:LHBAaEf48a0/AjU118rjoworH0LgXifhAqmNX3ZRvME= -gitlab.com/elixxir/crypto v0.0.0-20200803223738-661ca14b6470 h1:WGECBA9PtyUk9RfkpHjcbySoXfByEBTaD5IUHmjGem4= -gitlab.com/elixxir/crypto v0.0.0-20200803223738-661ca14b6470/go.mod h1:LHBAaEf48a0/AjU118rjoworH0LgXifhAqmNX3ZRvME= -gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842 h1:m1zDQ6UadpuMnV7nvnyR+DUXE3AisRnVjajTb1xZE4c= -gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842/go.mod h1:bXY0kgbV5BHYda4YY5/hiG5bjimGK+R3PYub5yM9C/s= -gitlab.com/elixxir/ekv v0.1.0 h1:CXYdlWzR2MmT54WaVw3REdWayuSxYuGOQoAHL2YTWTA= -gitlab.com/elixxir/ekv v0.1.0/go.mod h1:bXY0kgbV5BHYda4YY5/hiG5bjimGK+R3PYub5yM9C/s= -gitlab.com/elixxir/primitives v0.0.0-20200706165052-9fe7a4fb99a3 h1:GTfflZBNLeBq3UApYog0J3+hytdkoRsDduGQji2wyEU= -gitlab.com/elixxir/primitives v0.0.0-20200706165052-9fe7a4fb99a3/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= +gitlab.com/elixxir/comms v0.0.0-20200805174832-240bba97beaa h1:yn5FW/zPPKb0DYbN1HvhudYkCrXhpBK4CrZGeUKCGu4= +gitlab.com/elixxir/comms v0.0.0-20200805174832-240bba97beaa/go.mod h1:Wc6fZyP/M4sBjnzb9pRScLeqwMOCv6DRXoTOd07bO3g= +gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4 h1:28ftZDeYEko7xptCZzeFWS1Iam95dj46TWFVVlKmw6A= +gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= +gitlab.com/elixxir/crypto v0.0.0-20200805174804-bdf909f2a16d h1:3+o6r8a0o9/HIpBzlGCCiwuPN8OdEX3cHzdnCNqKDAw= +gitlab.com/elixxir/crypto v0.0.0-20200805174804-bdf909f2a16d/go.mod h1:cu6uNoANVLV0J6HyTL6KqVtVyh9SHU1RjJhytYlsbVQ= +gitlab.com/elixxir/ekv v0.1.1 h1:Em3rF8sv+tNbQGXbcpYzAS2blWRAP708JGhYlkN74Kg= +gitlab.com/elixxir/ekv v0.1.1/go.mod h1:bXY0kgbV5BHYda4YY5/hiG5bjimGK+R3PYub5yM9C/s= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d h1:OKWTmYN5q8XVHo8JXThIH0TCuvl/fLXR7MGVacpqfRg= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= -gitlab.com/xx_network/collections/ring.git v0.0.1 h1:3JLw2pgaOm57WWtjw6dvqvbud4DtoKxwYjEA95hNwgE= -gitlab.com/xx_network/collections/ring.git v0.0.1/go.mod h1:M61MlPiyB23ni0L1DJ8QErcUjOcnKEfbCpl75vE7Ej0= -gitlab.com/xx_network/comms v0.0.0-20200731231107-9e020daf0013 h1:sis9BdA5VNXUAamga/tpr4qHcJ01qugbMt6wBmaGyJ4= -gitlab.com/xx_network/comms v0.0.0-20200731231107-9e020daf0013/go.mod h1:ECW83bFGaOzZMM8axIWX6BsYpXakiM0Zf4Snp7H9+yI= -gitlab.com/xx_network/comms v0.0.0-20200803203304-a7a1c5e4239d h1:mU4Gk9IivWABbzAuibA4887yANHYOohlWq4Y4BvzR+8= -gitlab.com/xx_network/comms v0.0.0-20200803203304-a7a1c5e4239d/go.mod h1:Qg7dyO6DHgHzjUM1IQ5nbFoRyzx5wVZAjf4FOTeu8mA= +gitlab.com/elixxir/primitives v0.0.0-20200804170709-a1896d262cd9 h1:o0P00afLOlI3/98DR3G5IfGSTAO1ab/uzhPYzxE/Kcg= +gitlab.com/elixxir/primitives v0.0.0-20200804170709-a1896d262cd9/go.mod h1:p0VelQda72OzoUckr1O+vPW0AiFe0nyKQ6gYcmFSuF8= +gitlab.com/elixxir/primitives v0.0.0-20200804182913-788f47bded40 h1:S1cyRivF4MywQX10K8cGXux6Pbwy5dbWhsxs56G+8hs= +gitlab.com/elixxir/primitives v0.0.0-20200804182913-788f47bded40/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc= +gitlab.com/elixxir/primitives v0.0.0-20200804231232-ad79a9e8f113/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc= +gitlab.com/elixxir/primitives v0.0.0-20200805174810-86b366d1dd2d h1:ky5oz0D2EmOzk2n/A6Ugwj7S1B6rftxMJwc19sjGkz8= +gitlab.com/elixxir/primitives v0.0.0-20200805174810-86b366d1dd2d/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc= +gitlab.com/xx_network/comms v0.0.0-20200804225654-09a9af23d699 h1:e9rzUjMxt/4iQ5AVXVgwANvbgxxXgWEbvApgd6P72jU= +gitlab.com/xx_network/comms v0.0.0-20200804225654-09a9af23d699/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw= +gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023 h1:fQPaxyuXyH3vl8qFlFDBEx8rlEzBnXBNy74K8ItFRM4= +gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw= +gitlab.com/xx_network/primitives v0.0.0-20200803231956-9b192c57ea7c/go.mod h1:wtdCMr7DPePz9qwctNoAUzZtbOSHSedcK++3Df3psjA= +gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da h1:CCVslUwNC7Ul7NG5nu3ThGTSVUt1TxNRX+47f5TUwnk= +gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da/go.mod h1:OK9xevzWCaPO7b1wiluVJGk7R5ZsuC7pHY5hteZFQug= +gitlab.com/xx_network/ring v0.0.2 h1:TlPjlbFdhtJrwvRgIg4ScdngMTaynx/ByHBRZiXCoL0= +gitlab.com/xx_network/ring v0.0.2/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= @@ -209,8 +212,6 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120 h1:EZ3cVSzKOlJxAd8e8YAJ7no8nNypTxexh/YE/xW3ZEY= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -229,11 +230,9 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7 golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 h1:B6caxRw+hozq68X2MY7jEpZh/cr4/aHLv9xU8Kkadrw= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200806125547-5acd03effb82 h1:6cBnXxYO+CiRVrChvCosSv7magqTPbyAgz1M8iOv5wM= +golang.org/x/sys v0.0.0-20200806125547-5acd03effb82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -248,8 +247,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200514193133-8feb7f20f2a2 h1:RwW6+LxyOQJ7oeoZ76GIJlwt/O0J5cN2fk+q/jK27kQ= -google.golang.org/genproto v0.0.0-20200514193133-8feb7f20f2a2/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20200709005830-7a2ca40e9dc3 h1:JwLN1jVnmIsfE4HkDVe2AblFAbo0Z+4cjteDSOnv6oE= google.golang.org/genproto v0.0.0-20200709005830-7a2ca40e9dc3/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= diff --git a/io/collate.go b/io/collate.go index c2d74635ed915576f807767f4f17d065e5b928aa..ae8edda7b2897d4b2563de0d089021581377570f 100644 --- a/io/collate.go +++ b/io/collate.go @@ -13,7 +13,7 @@ import ( "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "sync" "time" ) diff --git a/io/collate_test.go b/io/collate_test.go index 274497f2519a478511de3c8f24ceffd1d2bb5195..31d78c3f1627d47d5a8035acd2e026686d99ef4e 100644 --- a/io/collate_test.go +++ b/io/collate_test.go @@ -11,7 +11,7 @@ import ( "encoding/hex" "gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "math/rand" "testing" "time" diff --git a/io/interface.go b/io/interface.go index 3352147ee359249751df963abe00487a6fd579e1..57e9cc9897c084a3413e11cd88875377632c4c4d 100644 --- a/io/interface.go +++ b/io/interface.go @@ -9,8 +9,8 @@ package io import ( "gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/user" - "gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "time" ) diff --git a/io/receive.go b/io/receive.go index b371bf1da05783320dcecd19545bbd8a258df54c..43737aff93f3b365da658e2e0f58c3445f35240b 100644 --- a/io/receive.go +++ b/io/receive.go @@ -18,9 +18,9 @@ import ( pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/switchboard" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "strings" "time" ) diff --git a/io/receptionManager.go b/io/receptionManager.go index 467ab0ebd069c22dcad1600d90e5e9967afd1205..4386a28cc10613d6d4050175b5a1dd1b07ff4845 100644 --- a/io/receptionManager.go +++ b/io/receptionManager.go @@ -13,7 +13,7 @@ import ( "github.com/pkg/errors" "gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/comms/client" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "sync" "time" ) diff --git a/io/send.go b/io/send.go index 48da90e9d56036d7e9c180f874a8022f920368ef..74d008e18a969bc58603c1aa3247fada8749d6e4 100644 --- a/io/send.go +++ b/io/send.go @@ -22,8 +22,8 @@ import ( "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "time" ) diff --git a/keyStore/keyManager.go b/keyStore/keyManager.go index a6938702fa624f69145c159f74a883ae46da1e7e..eedcd5702ca5a21d4dace16a9b4e46a40d2ec696 100644 --- a/keyStore/keyManager.go +++ b/keyStore/keyManager.go @@ -9,7 +9,7 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "sync/atomic" ) diff --git a/keyStore/keyManager_test.go b/keyStore/keyManager_test.go index 3851e03e3e978539768f1d759ada70c3017b5ca0..1163b9185333e980f035c7b4497f2bcf7a5cfe9c 100644 --- a/keyStore/keyManager_test.go +++ b/keyStore/keyManager_test.go @@ -8,7 +8,7 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/large" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "testing" ) diff --git a/keyStore/keyStore.go b/keyStore/keyStore.go index 8256cbde527b7025ea1842974b6c62df2b9de427..8efba3a8ad03fd2ea32005d82318fdd7b1481ee4 100644 --- a/keyStore/keyStore.go +++ b/keyStore/keyStore.go @@ -8,7 +8,7 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "sync" ) diff --git a/keyStore/keyStore_test.go b/keyStore/keyStore_test.go index ee334ff3ad7147cb1d6ba2f02423f4f5f1705b4a..53891da174ab1d284892c676f166e591e96a6b08 100644 --- a/keyStore/keyStore_test.go +++ b/keyStore/keyStore_test.go @@ -5,7 +5,7 @@ import ( "encoding/gob" "github.com/pkg/errors" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "testing" ) diff --git a/keyStore/recieveKeyManagerBuffer_test.go b/keyStore/recieveKeyManagerBuffer_test.go index a9caec7d1dba38af6a53253a26b64b518df0688b..e4680eeb8a451b31ea42950a094eb78e5754b578 100644 --- a/keyStore/recieveKeyManagerBuffer_test.go +++ b/keyStore/recieveKeyManagerBuffer_test.go @@ -3,7 +3,7 @@ package keyStore import ( "bytes" "encoding/gob" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "testing" ) diff --git a/keyStore/rekeyManager.go b/keyStore/rekeyManager.go index cfb0442141a2ac3f93c871d1d35decb953e4afb0..64e87ef466dfde92e449a94b1a152d9c1d78f5b5 100644 --- a/keyStore/rekeyManager.go +++ b/keyStore/rekeyManager.go @@ -2,7 +2,7 @@ package keyStore import ( "gitlab.com/elixxir/crypto/cyclic" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "sync" ) diff --git a/keyStore/rekeyManager_test.go b/keyStore/rekeyManager_test.go index 87072da6f788bbc5c7e6aae38fea5e7e0c8d6b96..a41a5ed5a2289b9ee3e80d817a76f298c6e29922 100644 --- a/keyStore/rekeyManager_test.go +++ b/keyStore/rekeyManager_test.go @@ -3,7 +3,7 @@ package keyStore import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/large" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "testing" ) diff --git a/parse/message.go b/parse/message.go index 9e626dc2c524e9660275ee74854769b0852cd689..c6f01dba8d011050f79b69da5c235ba7bfc26faa 100644 --- a/parse/message.go +++ b/parse/message.go @@ -8,7 +8,7 @@ package parse import ( "crypto/sha256" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "time" ) diff --git a/parse/message_test.go b/parse/message_test.go index 15933f84cfa7c526a2b4cf1dd33af1c63eca751f..6f4ddc224bc4b1b79ba435c1697107de934f99dc 100644 --- a/parse/message_test.go +++ b/parse/message_test.go @@ -7,7 +7,7 @@ package parse import ( - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "reflect" "testing" "time" diff --git a/rekey/rekey.go b/rekey/rekey.go index b013ad245f9b5d53994e4466756d81eb525ef831..737c94656efde87f3a7a2b16755e211b5545428f 100644 --- a/rekey/rekey.go +++ b/rekey/rekey.go @@ -14,9 +14,9 @@ import ( "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/switchboard" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" ) var session user.Session diff --git a/rekey/rekey_test.go b/rekey/rekey_test.go index cd9019f5f82024a89e7fb1da845745effdbfd892..43d430ec0ef9307c757b37ca737b622bcba876f5 100644 --- a/rekey/rekey_test.go +++ b/rekey/rekey_test.go @@ -16,8 +16,8 @@ import ( "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/signature/rsa" - "gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "os" "testing" "time" diff --git a/storage/contact.go b/storage/contact.go new file mode 100644 index 0000000000000000000000000000000000000000..7c49e5f1884c4044b61878aaecebd256f6cf99ff --- /dev/null +++ b/storage/contact.go @@ -0,0 +1,55 @@ +package storage + +import ( + "encoding/json" + "gitlab.com/elixxir/client/globals" + "gitlab.com/xx_network/primitives/id" + "time" +) + +const currentContactVersion = 0 + +func (s *Session) GetContact(name string) (*Contact, error) { + // Make key + // If upgrading version, may need to add logic to update version number in key prefix + key := MakeKeyPrefix("Contact", currentContactVersion) + name + + obj, err := s.Get(key) + if err != nil { + return nil, err + } + // Correctly implemented upgrade should always change the version number to what's current + if obj.Version != currentContactVersion { + globals.Log.WARN.Printf("Session.GetContact: got unexpected version %v, expected version %v", obj.Version, currentContactVersion) + } + + // deserialize + var contact Contact + err = json.Unmarshal(obj.Data, &contact) + return &contact, err +} + +func (s *Session) SetContact(name string, record *Contact) error { + now, err := time.Now().MarshalText() + if err != nil { + return err + } + + key := MakeKeyPrefix("Contact", currentContactVersion) + name + var data []byte + data, err = json.Marshal(record) + if err != nil { + return err + } + obj := VersionedObject{ + Version: currentContactVersion, + Timestamp: now, + Data: data, + } + return s.Set(key, &obj) +} + +type Contact struct { + Id *id.ID + PublicKey []byte +} diff --git a/storage/contact_test.go b/storage/contact_test.go new file mode 100644 index 0000000000000000000000000000000000000000..b4fb5e370a399a9674f438f7ebcfb3f04cfa07eb --- /dev/null +++ b/storage/contact_test.go @@ -0,0 +1,33 @@ +package storage + +import ( + "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/primitives/id" + "reflect" + "testing" +) + +// Show that all fields of a searched user record get stored +func TestSession_Contact(t *testing.T) { + store := make(ekv.Memstore) + session := &Session{NewVersionedKV(store)} + + expectedRecord := &Contact{ + Id: id.NewIdFromUInt(24601, id.User, t), + PublicKey: []byte("not a real public key"), + } + + name := "niamh@elixxir.io" + err := session.SetContact(name, expectedRecord) + if err != nil { + t.Fatal(err) + } + retrievedRecord, err := session.GetContact(name) + if err != nil { + t.Fatal(err) + } + + if !reflect.DeepEqual(expectedRecord, retrievedRecord) { + t.Error("Expected and retrieved records were different") + } +} diff --git a/storage/registration.go b/storage/registration.go new file mode 100644 index 0000000000000000000000000000000000000000..338dbd7f052bb44b7e57314c3b40ec4f4ffefe92 --- /dev/null +++ b/storage/registration.go @@ -0,0 +1,108 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 Privategrity Corporation / +// / +// All rights reserved. / +//////////////////////////////////////////////////////////////////////////////// +package storage + +import ( + "encoding/json" + "gitlab.com/elixxir/client/globals" + "time" +) + +var currentRegistrationVersion = uint64(0) + +// SetRegValidationSig builds the versioned object and sets it in the key-value store +func (s *Session) SetRegValidationSig(newVal []byte) error { + // Get the time for the versioned object + now := time.Now() + nowText, err := now.MarshalText() + if err != nil { + //Should never happen + return err + } + + // Construct the versioned object + vo := &VersionedObject{ + Version: currentRegistrationVersion, + Timestamp: nowText, + Data: newVal, + } + + // Construct the key and place in the key-value store + key := MakeKeyPrefix("RegValidationSig", currentRegistrationVersion) + + return s.kv.Set(key, vo) +} + +// GetRegValidationSig pulls the versioned object by the key and parses +// it into the requested registration signature +func (s *Session) GetRegValidationSig() ([]byte, error) { + key := MakeKeyPrefix("RegValidationSig", currentRegistrationVersion) + + // Pull the object from the key-value store + voData, err := s.kv.Get(key) + if err != nil { + return nil, err + } + + if voData.Version != currentRegistrationVersion { + globals.Log.WARN.Printf("Session.GetRegValidationSig: got unexpected version %v, expected version %v", + voData.Version, currentRegistrationVersion) + } + + return voData.Data, nil +} + +// SetRegState uses the SetInterface method to place the regstate into +// the key-value store +func (s *Session) SetRegState(newVal int64) error { + now, err := time.Now().MarshalText() + if err != nil { + return err + } + + key := MakeKeyPrefix("RegState", currentRegistrationVersion) + + var data []byte + data, err = json.Marshal(newVal) + if err != nil { + return err + } + + obj := VersionedObject{ + Version: currentRegistrationVersion, + Timestamp: now, + Data: data, + } + + return s.kv.Set(key, &obj) +} + +// GetRegValidationSig pulls the versioned object by the key and parses +// it into the requested registration signature +func (s *Session) GetRegState() (int64, error) { + // Construct the key from the + key := MakeKeyPrefix("RegState", currentRegistrationVersion) + + // Pull the object from the key-value store + voData, err := s.kv.Get(key) + if err != nil { + return 0, err + } + + if voData.Version != currentRegistrationVersion { + globals.Log.WARN.Printf("Session.GetRegState: got unexpected version %v, expected version %v", + voData.Version, currentRegistrationVersion) + } + + var data int64 + err = json.Unmarshal(voData.Data, &data) + if err != nil { + return 0, err + } + + return data, nil + +} diff --git a/storage/registration_test.go b/storage/registration_test.go new file mode 100644 index 0000000000000000000000000000000000000000..db6fdc447b645bf77092ae80aaa58364fb999d9e --- /dev/null +++ b/storage/registration_test.go @@ -0,0 +1,55 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 Privategrity Corporation / +// / +// All rights reserved. / +//////////////////////////////////////////////////////////////////////////////// +package storage + +import ( + "bytes" + "testing" +) + +func TestSession_RegState(t *testing.T) { + testSession := InitTestingSession(t) + + expectedVal := int64(42) + err := testSession.SetRegState(expectedVal) + if err != nil { + t.Errorf("Failed to place value in session: %v", err) + } + + retrievedVal, err := testSession.GetRegState() + if err != nil { + t.Errorf("Faield to get value from session: %v", err) + } + + if retrievedVal != expectedVal { + t.Errorf("Expected value not retrieved from file store!"+ + "\n\tExpected: %v"+ + "\n\tRecieved: %v", expectedVal, retrievedVal) + } + +} + +func TestSession_RegValidation(t *testing.T) { + testSession := InitTestingSession(t) + + expectedVal := []byte("testData") + + err := testSession.SetRegValidationSig(expectedVal) + if err != nil { + t.Errorf("Failed to place value in session: %v", err) + } + + retrievedVal, err := testSession.GetRegValidationSig() + if err != nil { + t.Errorf("Faield to get value from session: %v", err) + } + + if !bytes.Equal(retrievedVal, expectedVal) { + t.Errorf("Expected value not retrieved from file store!"+ + "\n\tExpected: %v"+ + "\n\tRecieved: %v", expectedVal, retrievedVal) + } +} diff --git a/storage/session.go b/storage/session.go index 35ec1722881edb985f19fa2460144aa6aa0afdd3..b164743c2c8dce89ad857ce817982e20f7616f22 100644 --- a/storage/session.go +++ b/storage/session.go @@ -11,9 +11,11 @@ package storage import ( "encoding/json" "gitlab.com/elixxir/client/user" + "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/ekv" "gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/comms/connect" + "testing" "time" ) @@ -122,3 +124,22 @@ func (s *Session) PushNodeKey(id *id.ID, key user.NodeKeys) error { } return s.kv.Set("NodeKeys", vo) } + +// Initializes a Session object wrapped around a MemStore object. +// FOR TESTING ONLY +func InitTestingSession(i interface{}) *Session { + switch i.(type) { + case *testing.T: + break + case *testing.M: + break + case *testing.B: + break + default: + globals.Log.FATAL.Panicf("InitTestingSession is restricted to testing only. Got %T", i) + } + + store := make(ekv.Memstore) + return &Session{NewVersionedKV(store)} + +} diff --git a/user/regCode.go b/user/regCode.go index 65094ad616ef680f8ea7a193d505c45e00cc1dc8..1914d03a26a27b36f6574c5a3b806b7d6b07d7e4 100644 --- a/user/regCode.go +++ b/user/regCode.go @@ -2,7 +2,7 @@ package user import ( "encoding/base32" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "golang.org/x/crypto/blake2b" ) diff --git a/user/session.go b/user/session.go index 04665d6579c272144b08d222d7d7e911c882881b..948208bf39ca9a6360a238daa180512d6f43c814 100644 --- a/user/session.go +++ b/user/session.go @@ -20,9 +20,9 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/switchboard" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "io" "sync" "sync/atomic" @@ -394,15 +394,17 @@ func (s *SessionObj) PushNodeKey(id *id.ID, key NodeKeys) { func (s *SessionObj) RegisterPermissioningSignature(sig []byte) error { s.LockStorage() defer s.UnlockStorage() - err := s.SetRegState(PermissioningComplete) - if err != nil { - return errors.Wrap(err, "Could not store permissioning signature") - } - s.RegValidationSignature = sig + // fixme remove the below + //err := s.SetRegState(PermissioningComplete) + //if err != nil { + // return errors.Wrap(err, "Could not store permissioning signature") + //} + // + //s.RegValidationSignature = sig //storing to ensure we never loose the signature - err = s.storeSession() + err := s.storeSession() return err } @@ -491,11 +493,7 @@ func (s *SessionObj) SetRegState(rs uint32) error { } func (s *SessionObj) ChangeUsername(username string) error { - b := s.GetRegState() - if b != PermissioningComplete { - return errors.New("Can only change username during " + - "PermissioningComplete registration state") - } + s.CurrentUser.Username = username return nil } diff --git a/user/session_test.go b/user/session_test.go index ddf7201574ec3eb66bd06c5bb87c8932d4ccd5e5..d0a2805a25d8e8bb9b3ff08c05057cf57f80f972 100644 --- a/user/session_test.go +++ b/user/session_test.go @@ -15,8 +15,8 @@ import ( "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/primitives/id" "math/rand" "reflect" "testing" diff --git a/user/sessionv1.go b/user/sessionv1.go index 3f470aa558447c8edf0aad156db45e6a23d52d21..e6bfcf41666fae2067a9adabfe2beb433108c09f 100644 --- a/user/sessionv1.go +++ b/user/sessionv1.go @@ -10,8 +10,8 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/switchboard" + "gitlab.com/xx_network/primitives/id" "sync" ) diff --git a/user/user.go b/user/user.go index 45e0bc65cf265247df30e08c830ee87d958f006c..e0fd215fafe43556ccdad059dba92d9391ce24b5 100644 --- a/user/user.go +++ b/user/user.go @@ -11,7 +11,7 @@ import ( "encoding/binary" "gitlab.com/elixxir/client/globals" "gitlab.com/elixxir/crypto/cyclic" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" ) // Globally instantiated Registry diff --git a/user/user_test.go b/user/user_test.go index 52d303e432c7c0a686b30406db2b130a7b46ce73..6f20a4b8c7e823e27ccbecf79145878e56de73bd 100644 --- a/user/user_test.go +++ b/user/user_test.go @@ -10,7 +10,7 @@ import ( "crypto/sha256" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/large" - "gitlab.com/elixxir/primitives/id" + "gitlab.com/xx_network/primitives/id" "testing" ) diff --git a/version_vars.go.bak b/version_vars.go.bak new file mode 100644 index 0000000000000000000000000000000000000000..5167c98b946d126f46e21e7101072cd04cc44376 --- /dev/null +++ b/version_vars.go.bak @@ -0,0 +1,37 @@ +// Code generated by go generate; DO NOT EDIT. +// This file was generated by robots at +// 2020-08-06 10:52:35.96635741 -0700 PDT m=+0.008615574 +package cmd + +const GITVERSION = `d97700f Merge branch 'XX-2418/ClientStorage-Registration' of gitlab.com:elixxir/client into XX-2418/ClientStorage-Registration` +const SEMVER = "1.4.0" +const DEPENDENCIES = `module gitlab.com/elixxir/client + +go 1.13 + +require ( + github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 + github.com/golang/protobuf v1.4.2 + github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect + github.com/pelletier/go-toml v1.6.0 // indirect + github.com/pkg/errors v0.9.1 + github.com/smartystreets/assertions v1.0.1 // indirect + github.com/spf13/afero v1.2.2 // indirect + github.com/spf13/cast v1.3.1 // indirect + github.com/spf13/cobra v1.0.0 + github.com/spf13/jwalterweatherman v1.1.0 + github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/viper v1.6.2 + gitlab.com/elixxir/comms v0.0.0-20200805174832-240bba97beaa + gitlab.com/elixxir/crypto v0.0.0-20200805174804-bdf909f2a16d + gitlab.com/elixxir/ekv v0.1.1 + gitlab.com/elixxir/primitives v0.0.0-20200805174810-86b366d1dd2d + gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023 + gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da + golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de + golang.org/x/sys v0.0.0-20200806125547-5acd03effb82 // indirect + gopkg.in/ini.v1 v1.52.0 // indirect +) + +replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1 +`