Skip to content
Snippets Groups Projects
Select Git revision
  • 2e60cdc1d32b688bbb36ce7425c6680c284003f9
  • main default protected
  • development
  • integration
  • v1.1.5
  • v1.1.4
  • v1.1.3
  • v1.1.2
  • v1.1.1
  • v1.1.0
  • v1.0.0
11 results

README.md

Blame
  • client.go 1.76 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    package connect
    
    import (
    	"github.com/golang/protobuf/proto"
    	"github.com/pkg/errors"
    	"gitlab.com/elixxir/client/e2e/ratchet/partner"
    	"gitlab.com/elixxir/crypto/fastRNG"
    	"gitlab.com/xx_network/crypto/signature/rsa"
    )
    
    // buildClientAuthRequest is a helper function which constructs a marshalled
    // IdentityAuthentication message.
    func buildClientAuthRequest(newPartner partner.Manager,
    	rng *fastRNG.StreamGenerator, rsaPrivKey *rsa.PrivateKey,
    	salt []byte) ([]byte, error) {
    
    	// The connection fingerprint (hashed) will be used as a nonce
    	connectionFp := newPartner.ConnectionFingerprint().Bytes()
    	opts := rsa.NewDefaultOptions()
    	h := opts.Hash.New()
    	h.Write(connectionFp)
    	nonce := h.Sum(nil)
    
    	// Sign the connection fingerprint
    	stream := rng.GetStream()
    	defer stream.Close()
    	signature, err := rsa.Sign(stream, rsaPrivKey,
    		opts.Hash, nonce, opts)
    	if err != nil {
    		return nil, errors.Errorf("failed to sign nonce: %+v", err)
    	}
    
    	// Construct message
    	pemEncodedRsaPubKey := rsa.CreatePublicKeyPem(rsaPrivKey.GetPublic())
    	iar := &IdentityAuthentication{
    		Signature: signature,
    		RsaPubKey: pemEncodedRsaPubKey,
    		Salt:      salt,
    	}
    	payload, err := proto.Marshal(iar)
    	if err != nil {
    		return nil, errors.Errorf("failed to marshal identity request "+
    			"message: %+v", err)
    	}
    
    	return payload, nil
    }