From 949f3492742f90e14fecabcb11593d8376c7de34 Mon Sep 17 00:00:00 2001
From: jbhusson <jonah@elixxir.io>
Date: Wed, 5 May 2021 16:11:50 -0400
Subject: [PATCH] Fix user copy & notification permissioning signature
 verification

---
 api/notifications.go      | 5 +++--
 cmd/root.go               | 2 +-
 go.mod                    | 2 +-
 go.sum                    | 2 ++
 permissioning/register.go | 4 ++--
 storage/user.go           | 2 +-
 6 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/api/notifications.go b/api/notifications.go
index 838d1e179..da7f6642a 100644
--- a/api/notifications.go
+++ b/api/notifications.go
@@ -40,7 +40,7 @@ func (c *Client) RegisterForNotifications(token string) error {
 		&mixmessages.NotificationRegisterRequest{
 			Token:                 token,
 			IntermediaryId:        intermediaryReceptionID,
-			TransmissionRsa:       rsa.CreatePublicKeyPem(c.GetUser().TransmissionRSA.GetPublic()),
+			TransmissionRsa:       rsa.CreatePublicKeyPem(c.GetStorage().User().GetCryptographicIdentity().GetTransmissionRSA().GetPublic()),
 			TransmissionSalt:      c.GetUser().TransmissionSalt,
 			TransmissionRsaSig:    c.GetStorage().User().GetTransmissionRegistrationValidationSignature(),
 			IIDTransmissionRsaSig: sig,
@@ -95,7 +95,8 @@ func (c *Client) getIidAndSig() ([]byte, []byte, error) {
 	}
 
 	stream := c.rng.GetStream()
-	sig, err := rsa.Sign(stream, c.GetUser().TransmissionRSA, hash.CMixHash, h.Sum(nil), nil)
+	c.GetUser()
+	sig, err := rsa.Sign(stream, c.storage.User().GetCryptographicIdentity().GetTransmissionRSA(), hash.CMixHash, h.Sum(nil), nil)
 	if err != nil {
 		return nil, nil, errors.WithMessage(err, "RegisterForNotifications: Failed to sign intermediary ID")
 	}
diff --git a/cmd/root.go b/cmd/root.go
index 01b245cec..ae852c8a1 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -116,7 +116,7 @@ var rootCmd = &cobra.Command{
 		client.GetHealth().AddChannel(connected)
 		waitUntilConnected(connected)
 
-		//err = client.RegisterForNotifications([]byte("dJwuGGX3KUyKldWK5PgQH8:APA91bFjuvimRc4LqOyMDiy124aLedifA8DhldtaB_b76ggphnFYQWJc_fq0hzQ-Jk4iYp2wPpkwlpE1fsOjs7XWBexWcNZoU-zgMiM0Mso9vTN53RhbXUferCbAiEylucEOacy9pniN"))
+		//err = client.RegisterForNotifications("dJwuGGX3KUyKldWK5PgQH8:APA91bFjuvimRc4LqOyMDiy124aLedifA8DhldtaB_b76ggphnFYQWJc_fq0hzQ-Jk4iYp2wPpkwlpE1fsOjs7XWBexWcNZoU-zgMiM0Mso9vTN53RhbXUferCbAiEylucEOacy9pniN")
 		//if err != nil {
 		//	jww.FATAL.Panicf("Failed to register for notifications: %+v", err)
 		//}
diff --git a/go.mod b/go.mod
index 13cf8b286..5adeb654f 100644
--- a/go.mod
+++ b/go.mod
@@ -23,7 +23,7 @@ require (
 	gitlab.com/elixxir/primitives v0.0.3-0.20210427004615-c68ecf15fcf3
 	gitlab.com/xx_network/comms v0.0.4-0.20210409202820-eb3dca6571d3
 	gitlab.com/xx_network/crypto v0.0.5-0.20210405224157-2b1f387b42c1
-	gitlab.com/xx_network/primitives v0.0.4-0.20210402222416-37c1c4d3fac4
+	gitlab.com/xx_network/primitives v0.0.4-0.20210419175212-11b843dd4791
 	golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
 	golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 // indirect
 	google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect
diff --git a/go.sum b/go.sum
index 87d34b61f..8dd7ece32 100644
--- a/go.sum
+++ b/go.sum
@@ -309,6 +309,8 @@ gitlab.com/xx_network/primitives v0.0.2 h1:r45yKenJ9e7PylI1ZXJ1Es09oYNaYXjxVy9+u
 gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc=
 gitlab.com/xx_network/primitives v0.0.4-0.20210402222416-37c1c4d3fac4 h1:YPYTKF0zQf08y0eQrjQP01C/EWQTypdqawjZPr5c6rc=
 gitlab.com/xx_network/primitives v0.0.4-0.20210402222416-37c1c4d3fac4/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE=
+gitlab.com/xx_network/primitives v0.0.4-0.20210419175212-11b843dd4791 h1:RSeT0tJiwRr1BuKsTCaulr+eJAxQHDl/r9ZMo4lN9mg=
+gitlab.com/xx_network/primitives v0.0.4-0.20210419175212-11b843dd4791/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE=
 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=
diff --git a/permissioning/register.go b/permissioning/register.go
index 1a64e5479..50f6c7ca6 100644
--- a/permissioning/register.go
+++ b/permissioning/register.go
@@ -27,7 +27,6 @@ type registrationMessageSender interface {
 // Returns an error if registration fails.
 func register(comms registrationMessageSender, host *connect.Host,
 	transmissionPublicKey, receptionPublicKey *rsa.PublicKey, registrationCode string) ([]byte, []byte, error) {
-
 	response, err := comms.
 		SendRegistrationMessage(host,
 			&pb.UserRegistration{
@@ -35,8 +34,9 @@ func register(comms registrationMessageSender, host *connect.Host,
 				ClientRSAPubKey:          string(rsa.CreatePublicKeyPem(transmissionPublicKey)),
 				ClientReceptionRSAPubKey: string(rsa.CreatePublicKeyPem(receptionPublicKey)),
 			})
+
 	if err != nil {
-		err = errors.Wrap(err, "sendRegistrationMessage: Unable to contact Identity Server!")
+		err = errors.WithMessage(err, "sendRegistrationMessage: Unable to contact Identity Server!")
 		return nil, nil, err
 	}
 	if response.Error != "" {
diff --git a/storage/user.go b/storage/user.go
index df1d9055e..a443d81cb 100644
--- a/storage/user.go
+++ b/storage/user.go
@@ -16,7 +16,7 @@ func (s *Session) GetUser() user.User {
 	return user.User{
 		TransmissionID:   ci.GetTransmissionID().DeepCopy(),
 		TransmissionSalt: copySlice(ci.GetTransmissionSalt()),
-		TransmissionRSA:  ci.GetReceptionRSA(),
+		TransmissionRSA:  ci.GetTransmissionRSA(),
 		ReceptionID:      ci.GetReceptionID().DeepCopy(),
 		ReceptionSalt:    copySlice(ci.GetReceptionSalt()),
 		ReceptionRSA:     ci.GetReceptionRSA(),
-- 
GitLab