From ed09e1277c6d2855e329b9ec05b068b66d7ecacf Mon Sep 17 00:00:00 2001 From: Jake Taylor <jake@elixxir.io> Date: Thu, 7 Jul 2022 14:38:10 -0500 Subject: [PATCH] fix protouser cmd initialization path --- cmd/root.go | 2 +- xxdk/cmix.go | 16 +++++++++++----- xxdk/e2e.go | 10 +++------- xxdk/identity.go | 11 ++++++----- xxdk/precan.go | 7 ++++--- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index cca0887bc..587949a52 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -589,7 +589,7 @@ func initCmix() (*xxdk.Cmix, xxdk.ReceptionIdentity) { jww.FATAL.Panicf("%v", err) } - err = xxdk.NewProtoClient_Unsafe(string(ndfJSON), storeDir, + knownReception, err = xxdk.NewProtoClient_Unsafe(string(ndfJSON), storeDir, pass, protoUser) } else if userIDprefix != "" { err = xxdk.NewVanityClient(string(ndfJSON), storeDir, diff --git a/xxdk/cmix.go b/xxdk/cmix.go index 6bc1f0915..3e31d2859 100644 --- a/xxdk/cmix.go +++ b/xxdk/cmix.go @@ -163,14 +163,14 @@ func OpenCmix(storageDir string, password []byte, // predefined cryptographic which defines a user. This is designed for some // specific deployment procedures and is generally unsafe. func NewProtoClient_Unsafe(ndfJSON, storageDir string, password []byte, - protoUser *user.Proto) error { + protoUser *user.Proto) (ReceptionIdentity, error) { jww.INFO.Printf("NewProtoClient_Unsafe") usr := user.NewUserFromProto(protoUser) def, err := ParseNDF(ndfJSON) if err != nil { - return err + return ReceptionIdentity{}, err } cmixGrp, e2eGrp := DecodeGroups(def) @@ -178,7 +178,13 @@ func NewProtoClient_Unsafe(ndfJSON, storageDir string, password []byte, storageSess, err := CheckVersionAndSetupStorage(def, storageDir, password, usr, cmixGrp, e2eGrp, protoUser.RegCode) if err != nil { - return err + return ReceptionIdentity{}, err + } + + identity, err := buildReceptionIdentity(protoUser.ReceptionID, protoUser.ReceptionSalt, + protoUser.ReceptionRSA, e2eGrp, protoUser.E2eDhPrivateKey) + if err != nil { + return ReceptionIdentity{}, err } storageSess.SetReceptionRegistrationValidationSignature( @@ -192,10 +198,10 @@ func NewProtoClient_Unsafe(ndfJSON, storageDir string, password []byte, err = storageSess.ForwardRegistrationStatus( storage.PermissioningComplete) if err != nil { - return err + return ReceptionIdentity{}, err } - return nil + return identity, nil } // LoadCmix initializes a Cmix object from existing storage and starts the network diff --git a/xxdk/e2e.go b/xxdk/e2e.go index 69e1a463b..098657f9c 100644 --- a/xxdk/e2e.go +++ b/xxdk/e2e.go @@ -98,8 +98,8 @@ func LoginLegacy(client *Cmix, params E2EParams, callbacks AuthCallbacks) ( return nil, err } - m.e2eIdentity, err = buildReceptionIdentity(userInfo, m.e2e.GetGroup(), - m.e2e.GetHistoricalDHPrivkey()) + m.e2eIdentity, err = buildReceptionIdentity(userInfo.ReceptionID, userInfo.ReceptionSalt, + userInfo.ReceptionRSA, m.e2e.GetGroup(), m.e2e.GetHistoricalDHPrivkey()) return m, err } @@ -157,7 +157,7 @@ func LoginWithProtoClient(storageDir string, password []byte, return nil, err } - err = NewProtoClient_Unsafe(newBaseNdf, storageDir, password, + receptionIdentity, err := NewProtoClient_Unsafe(newBaseNdf, storageDir, password, protoUser) if err != nil { return nil, err @@ -174,10 +174,6 @@ func LoginWithProtoClient(storageDir string, password []byte, if err != nil { return nil, err } - - userInfo := user.NewUserFromProto(protoUser) - receptionIdentity, err := buildReceptionIdentity(userInfo, - c.GetStorage().GetE2EGroup(), protoUser.E2eDhPrivateKey) return Login(c, callbacks, receptionIdentity, e2eParams) } diff --git a/xxdk/identity.go b/xxdk/identity.go index 96100eddf..ba4706b34 100644 --- a/xxdk/identity.go +++ b/xxdk/identity.go @@ -176,9 +176,10 @@ func (r ReceptionIdentity) GetContact() contact.Contact { // buildReceptionIdentity creates a new ReceptionIdentity // from the given user.Info -func buildReceptionIdentity(userInfo user.Info, e2eGrp *cyclic.Group, dHPrivkey *cyclic.Int) (ReceptionIdentity, error) { - saltCopy := make([]byte, len(userInfo.ReceptionSalt)) - copy(saltCopy, userInfo.ReceptionSalt) +func buildReceptionIdentity(receptionId *id.ID, receptionSalt []byte, receptionRsa *rsa.PrivateKey, + e2eGrp *cyclic.Group, dHPrivkey *cyclic.Int) (ReceptionIdentity, error) { + saltCopy := make([]byte, len(receptionSalt)) + copy(saltCopy, receptionSalt) grp, err := e2eGrp.MarshalJSON() if err != nil { @@ -190,8 +191,8 @@ func buildReceptionIdentity(userInfo user.Info, e2eGrp *cyclic.Group, dHPrivkey } return ReceptionIdentity{ - ID: userInfo.ReceptionID.DeepCopy(), - RSAPrivatePem: rsa.CreatePrivateKeyPem(userInfo.ReceptionRSA), + ID: receptionId.DeepCopy(), + RSAPrivatePem: rsa.CreatePrivateKeyPem(receptionRsa), Salt: saltCopy, DHKeyPrivate: privKey, E2eGrp: grp, diff --git a/xxdk/precan.go b/xxdk/precan.go index 51ae566f3..e0e008e85 100644 --- a/xxdk/precan.go +++ b/xxdk/precan.go @@ -76,14 +76,15 @@ func NewPrecannedClient(precannedID uint, defJSON, storageDir string, dhPrivKey := generatePrecanDHKeypair(precannedID, e2eGrp) - protoUser := CreatePrecannedUser(precannedID, rngStream) - identity, err := buildReceptionIdentity(protoUser, e2eGrp, dhPrivKey) + userInfo := CreatePrecannedUser(precannedID, rngStream) + identity, err := buildReceptionIdentity(userInfo.ReceptionID, userInfo.ReceptionSalt, + userInfo.ReceptionRSA, e2eGrp, dhPrivKey) if err != nil { return ReceptionIdentity{}, err } store, err := CheckVersionAndSetupStorage(def, storageDir, password, - protoUser, cmixGrp, e2eGrp, "") + userInfo, cmixGrp, e2eGrp, "") if err != nil { return ReceptionIdentity{}, err } -- GitLab