From 3628e8c9f8d926b7e587d06b0767825fadabd7a1 Mon Sep 17 00:00:00 2001 From: Jake Taylor <jake@elixxir.io> Date: Thu, 30 Jun 2022 12:12:12 -0500 Subject: [PATCH] added identity storage bindings calls --- bindings/{contact.go => identity.go} | 29 +++++++++++++++++++ .../{contact_test.go => identity_test.go} | 0 connect/authenticated.go | 6 +++- 3 files changed, 34 insertions(+), 1 deletion(-) rename bindings/{contact.go => identity.go} (85%) rename bindings/{contact_test.go => identity_test.go} (100%) diff --git a/bindings/contact.go b/bindings/identity.go similarity index 85% rename from bindings/contact.go rename to bindings/identity.go index 82631bf6e..2718672f5 100644 --- a/bindings/contact.go +++ b/bindings/identity.go @@ -110,3 +110,32 @@ func GetFactsFromContact(marshaled []byte) ([]byte, error) { } return factsListMarshaled, nil } + +// StoreReceptionIdentity stores the given identity in Cmix storage with the given key +// This is the ideal way to securely store identities, as the caller of this function +// is only required to store the given key separately rather than the keying material +func StoreReceptionIdentity(key string, identity []byte, cmixId int) error { + cmix, err := cmixTrackerSingleton.get(cmixId) + if err != nil { + return err + } + receptionIdentity, err := xxdk.UnmarshalReceptionIdentity(identity) + if err != nil { + return err + } + return xxdk.StoreReceptionIdentity(key, receptionIdentity, cmix.api) +} + +// LoadReceptionIdentity loads the given identity in Cmix storage with the given key +func LoadReceptionIdentity(key string, cmixId int) ([]byte, error) { + cmix, err := cmixTrackerSingleton.get(cmixId) + if err != nil { + return nil, err + } + storageObj, err := cmix.api.GetStorage().Get(key) + if err != nil { + return nil, err + } + + return storageObj.Data, nil +} diff --git a/bindings/contact_test.go b/bindings/identity_test.go similarity index 100% rename from bindings/contact_test.go rename to bindings/identity_test.go diff --git a/connect/authenticated.go b/connect/authenticated.go index 89311eff3..5e5d91107 100644 --- a/connect/authenticated.go +++ b/connect/authenticated.go @@ -66,7 +66,11 @@ func ConnectWithAuthentication(recipient contact.Contact, e2eClient *xxdk.E2e, // Build the authenticated connection and return identity := e2eClient.GetReceptionIdentity() - return connectWithAuthentication(conn, timeStart, recipient, identity.Salt, identity.RSAPrivatePem, + privKey, err := identity.GetRSAPrivatePem() + if err != nil { + return nil, err + } + return connectWithAuthentication(conn, timeStart, recipient, identity.Salt, privKey, e2eClient.GetRng(), e2eClient.GetCmix(), p) } -- GitLab