From 2b55d3292ff92624aa251a9d2be8d5ddcaabc0a7 Mon Sep 17 00:00:00 2001 From: "Richard T. Carback III" <rick.carback@gmail.com> Date: Thu, 21 Apr 2022 23:24:21 +0000 Subject: [PATCH] Fix the contact information to make sure the user returned by api has the dh keys --- api/client.go | 13 ++++++++++--- cmd/utils.go | 2 ++ e2e/ratchet/storage.go | 25 ++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/api/client.go b/api/client.go index 685e7dca2..a8e641a49 100644 --- a/api/client.go +++ b/api/client.go @@ -290,7 +290,7 @@ func Login(storageDir string, password []byte, return nil, err } - u := c.GetUser() + u := c.userState.PortableUserInfo() jww.INFO.Printf("Client Logged in: \n\tTransmisstionID: %s "+ "\n\tReceptionID: %s", u.TransmissionID, u.ReceptionID) @@ -334,8 +334,10 @@ func Login(storageDir string, password []byte, return nil, err } + user := c.userState.PortableUserInfo() + c.e2e, err = e2e.Load(c.storage.GetKV(), c.network, - c.GetUser().ReceptionID, c.storage.GetE2EGroup(), + user.ReceptionID, c.storage.GetE2EGroup(), c.rng, c.events) if err != nil { return nil, err @@ -700,7 +702,12 @@ func (c *Client) AddService(sp Service) error { // can be serialized into a byte stream for out-of-band sharing. func (c *Client) GetUser() user.Info { jww.INFO.Printf("GetUser()") - return c.userState.PortableUserInfo() + cMixUser := c.userState.PortableUserInfo() + // Add e2e dh keys + e2e := c.GetE2EHandler() + cMixUser.E2eDhPrivateKey = e2e.GetHistoricalDHPrivkey().DeepCopy() + cMixUser.E2eDhPublicKey = e2e.GetHistoricalDHPubkey().DeepCopy() + return cMixUser } // GetComms returns the client comms object diff --git a/cmd/utils.go b/cmd/utils.go index 16bf5ea68..db747ab01 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -82,6 +82,7 @@ func writeContact(c contact.Contact) { if outfilePath == "" { return } + jww.INFO.Printf("PubKey WRITE: %s", c.DhPubKey.Text(10)) err := ioutil.WriteFile(outfilePath, c.Marshal(), 0644) if err != nil { jww.FATAL.Panicf("%+v", err) @@ -102,5 +103,6 @@ func readContact() contact.Contact { if err != nil { jww.FATAL.Panicf("Failed to unmarshal contact: %+v", err) } + jww.INFO.Printf("PubKey READ: %s", c.DhPubKey.Text(10)) return c } diff --git a/e2e/ratchet/storage.go b/e2e/ratchet/storage.go index cd285816f..146a51752 100644 --- a/e2e/ratchet/storage.go +++ b/e2e/ratchet/storage.go @@ -27,11 +27,25 @@ func Load(kv *versioned.KV, myID *id.ID, grp *cyclic.Group, *Ratchet, error) { kv = kv.Prefix(packagePrefix) + privKey, err := util.LoadCyclicKey(kv, privKeyKey) + if err != nil { + return nil, errors.WithMessage(err, + "Failed to load e2e DH private key") + } + + pubKey, err := util.LoadCyclicKey(kv, pubKeyKey) + if err != nil { + return nil, errors.WithMessage(err, + "Failed to load e2e DH public key") + } + r := &Ratchet{ managers: make(map[id.ID]partner.Manager), services: make(map[string]message.Processor), - myID: myID, + myID: myID, + advertisedDHPrivateKey: privKey, + advertisedDHPublicKey: pubKey, kv: kv, @@ -92,6 +106,15 @@ func (r *Ratchet) marshal() ([]byte, error) { index++ } + err := util.StoreCyclicKey(r.kv, r.advertisedDHPrivateKey, privKeyKey) + if err != nil { + return nil, err + } + err = util.StoreCyclicKey(r.kv, r.advertisedDHPublicKey, pubKeyKey) + if err != nil { + return nil, err + } + return json.Marshal(&contacts) } -- GitLab