From bbeb82a733965b8889661ef754b2cd235f1b179d Mon Sep 17 00:00:00 2001
From: josh <josh@elixxir.io>
Date: Thu, 9 Jan 2020 13:29:30 -0800
Subject: [PATCH] Fixed for noTLS pathway in local Environment

---
 api/connect.go  | 1 -
 api/private.go  | 5 ++---
 api/register.go | 7 +++----
 cmd/root.go     | 8 ++++++--
 io/updateNdf.go | 8 +++-----
 user/session.go | 1 -
 6 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/api/connect.go b/api/connect.go
index 1f0adecd0..7aa07f40a 100644
--- a/api/connect.go
+++ b/api/connect.go
@@ -27,7 +27,6 @@ func (cl *Client) InitNetwork() error {
 	}
 
 	runPermissioning := err != ErrNoPermissioning
-
 	if runPermissioning {
 		err = cl.setupPermissioning()
 
diff --git a/api/private.go b/api/private.go
index a4bd5bd0b..e2c7ace31 100644
--- a/api/private.go
+++ b/api/private.go
@@ -85,7 +85,7 @@ func (cl *Client) sendRegistrationMessage(registrationCode string,
 	if !ok {
 		return nil, errors.New("Failed to find permissioning host")
 	}
-	fmt.Println("in reg, pub key ", publicKeyRSA)
+
 	response, err := cl.receptionManager.Comms.
 		SendRegistrationMessage(host,
 			&pb.UserRegistration{
@@ -130,6 +130,7 @@ func (cl *Client) requestNonce(salt, regHash []byte,
 	if !ok {
 		return nil, nil, errors.Errorf("Failed to find host with ID %s", gwID.String())
 	}
+
 	nonceResponse, err := cl.receptionManager.Comms.
 		SendRequestNonceMessage(host,
 			&pb.NonceRequest{
@@ -152,7 +153,6 @@ func (cl *Client) requestNonce(salt, regHash []byte,
 		err := errors.New(fmt.Sprintf("requestNonce: nonceResponse error: %s", nonceResponse.Error))
 		return nil, nil, err
 	}
-
 	// Use Client keypair to sign Server nonce
 	return nonceResponse.Nonce, nonceResponse.DHPubKey, nil
 
@@ -301,7 +301,6 @@ func (cl *Client) GenerateKeys(rsaPrivKey *rsa.PrivateKey,
 
 	cl.session = user.NewSession(cl.storage, usr, pubKey, privKey, cmixPubKey,
 		cmixPrivKey, e2ePubKey, e2ePrivKey, salt, cmixGrp, e2eGrp, password)
-
 	//store the session
 	return cl.session.StoreSession()
 }
diff --git a/api/register.go b/api/register.go
index 6f9eaac45..183e48a5f 100644
--- a/api/register.go
+++ b/api/register.go
@@ -21,7 +21,6 @@ const SaltSize = 256
 //RegisterWithPermissioning registers the user and returns the User ID.
 // Returns an error if registration fails.
 func (cl *Client) RegisterWithPermissioning(preCan bool, registrationCode string) (*id.User, error) {
-
 	//Check the regState is in proper state for registration
 	if cl.session.GetRegState() != user.KeyGenComplete {
 		return nil, errors.Errorf("Attempting to register before key generation!")
@@ -52,7 +51,6 @@ func (cl *Client) RegisterWithPermissioning(preCan bool, registrationCode string
 		for n, k := range nodeKeyMap {
 			cl.session.PushNodeKey(&n, k)
 		}
-
 		//update the state
 		err := cl.session.SetRegState(user.PermissioningComplete)
 		if err != nil {
@@ -166,7 +164,6 @@ func (cl *Client) RegisterWithNodes() error {
 
 	//Load the registration signature
 	regSignature := session.GetRegistrationValidationSignature()
-
 	var wg sync.WaitGroup
 	errChan := make(chan error, len(cl.ndf.Gateways))
 
@@ -193,7 +190,6 @@ func (cl *Client) RegisterWithNodes() error {
 			}()
 		}
 	}
-
 	wg.Wait()
 	//See if the registration returned errors at all
 	var errs error
@@ -250,6 +246,7 @@ func (cl *Client) registerWithNode(index int, salt, registrationValidationSignat
 	if err != nil {
 		errMsg := fmt.Sprintf("Register: Failed requesting nonce from gateway: %+v", err)
 		errorChan <- errors.New(errMsg)
+		return
 	}
 
 	// Load server DH pubkey
@@ -261,6 +258,7 @@ func (cl *Client) registerWithNode(index int, salt, registrationValidationSignat
 	if err != nil {
 		errMsg := fmt.Sprintf("Register: Unable to confirm nonce: %v", err)
 		errorChan <- errors.New(errMsg)
+		return
 	}
 	nodeID := cl.topology.GetNodeAtIndex(index)
 	key := user.NodeKeys{
@@ -289,6 +287,7 @@ func (cl *Client) registerWithPermissioning(registrationCode string,
 			return nil, errors.Errorf("Register: Unable to send registration message: %+v", err)
 		}
 	}
+
 	globals.Log.INFO.Println("Register: successfully passed Registration message")
 
 	return regValidSig, nil
diff --git a/cmd/root.go b/cmd/root.go
index a6fa1266d..49cebec06 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -196,7 +196,7 @@ func sessionInitialization() (*id.User, string, *api.Client) {
 			regCode = id.NewUserFromUints(&[4]uint64{0, 0, 0, userId}).RegistrationCode()
 		}
 
-		globals.Log.INFO.Printf("Attempting to register with code %s...", regCode)
+		globals.Log.INFO.Printf("Building keys...")
 
 		var privKey *rsa.PrivateKey
 
@@ -220,8 +220,12 @@ func sessionInitialization() (*id.User, string, *api.Client) {
 			globals.Log.FATAL.Panicf("%+v", err)
 		}
 
+		globals.Log.INFO.Printf("Attempting to register with code %s...", regCode)
+
+		errRegister := fmt.Errorf("")
+		uid = client.GetCurrentUser()
 		//Attempt to register user with same keys until a success occurs
-		for errRegister := error(nil); errRegister != nil; {
+		for errRegister != nil {
 			_, errRegister = client.RegisterWithPermissioning(userId != 0, regCode)
 			if errRegister != nil {
 				globals.Log.FATAL.Panicf("Could Not Register User: %s",
diff --git a/io/updateNdf.go b/io/updateNdf.go
index 2e4304f1d..873578a42 100644
--- a/io/updateNdf.go
+++ b/io/updateNdf.go
@@ -23,13 +23,13 @@ func PollNdf(currentDef *ndf.NetworkDefinition, comms *client.Comms) (*ndf.Netwo
 	//Put the hash in a message
 	msg := &mixmessages.NDFHash{Hash: ndfHash}
 
-	host, ok := comms.GetHost(PermissioningAddrID)
+	regHost, ok := comms.GetHost(PermissioningAddrID)
 	if !ok {
 		return nil, errors.New("Failed to find permissioning host")
 	}
-
+	globals.Log.FATAL.Printf("about to request ndf")
 	//Send the hash to registration
-	response, err := comms.RequestNdf(host, msg)
+	response, err := comms.RequestNdf(regHost, msg)
 	if err != nil {
 		errMsg := fmt.Sprintf("Failed to get ndf from permissioning: %v", err)
 		if errMsg == noNDFErr.Error() {
@@ -45,8 +45,6 @@ func PollNdf(currentDef *ndf.NetworkDefinition, comms *client.Comms) (*ndf.Netwo
 		return nil, nil
 	}
 
-	//FixMe: use verify instead? Probs need to add a signature to ndf, like in registration's getupdate?
-
 	globals.Log.INFO.Printf("Remote NDF: %s", string(response.Ndf))
 
 	//Otherwise pull the ndf out of the response
diff --git a/user/session.go b/user/session.go
index 40fed35c8..76a57620c 100644
--- a/user/session.go
+++ b/user/session.go
@@ -392,7 +392,6 @@ func (s *SessionObj) PushNodeKey(id *id.Node, key NodeKeys) {
 func (s *SessionObj) RegisterPermissioningSignature(sig []byte) error {
 	s.LockStorage()
 	defer s.UnlockStorage()
-
 	err := s.SetRegState(PermissioningComplete)
 	if err != nil {
 		return errors.Wrap(err, "Could not store permissioning signature")
-- 
GitLab