diff --git a/bindings/contact.go b/bindings/identity.go similarity index 85% rename from bindings/contact.go rename to bindings/identity.go index 82631bf6e64b1ecb87d55f17b833b76ea682f103..2718672f50b22b8017d84e9c1799eac4667905d6 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 89311eff3ee33dd957b790c06a98e3de7bd745b9..5e5d911070eb4f87111b591866ce296b06e1b6ea 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) }