Skip to content
Snippets Groups Projects
Commit e8c091dd authored by Josh Brooks's avatar Josh Brooks
Browse files

Make connect/authenticated.go more test-able

parent d374c03a
Branches
Tags
3 merge requests!510Release,!216Xx 3895/authenticated connection,!207WIP: Client Restructure
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"sync" "sync"
"time"
) )
// Constant error messages // Constant error messages
...@@ -62,11 +63,24 @@ func ConnectWithAuthentication(recipient contact.Contact, myId *id.ID, ...@@ -62,11 +63,24 @@ func ConnectWithAuthentication(recipient contact.Contact, myId *id.ID,
conn, err := Connect(recipient, myId, myDhPrivKey, rng, grp, net, p) conn, err := Connect(recipient, myId, myDhPrivKey, rng, grp, net, p)
if err != nil { if err != nil {
return nil, errors.Errorf("failed to establish connection "+ return nil, errors.Errorf("failed to establish connection "+
"with recipient %s: %v", recipient.ID, err) "with recipient %s: %+v", recipient.ID, err)
} }
// Build the authenticated connection and return
return connectWithAuthentication(conn, timeStart, recipient, salt, myRsaPrivKey,
rng, net, p)
}
// connectWithAuthentication builds and sends an IdentityAuthentication to
// the server. This will wait until the round it sends on completes or a
// timeout occurs.
func connectWithAuthentication(conn Connection, timeStart time.Time,
recipient contact.Contact, salt []byte, myRsaPrivKey *rsa.PrivateKey,
rng *fastRNG.StreamGenerator,
net cmix.Client, p Params) (AuthenticatedConnection, error) {
// Construct message to prove your identity to the server // Construct message to prove your identity to the server
payload, err := makeClientAuthRequest(conn.GetPartner(), rng, myRsaPrivKey, salt) payload, err := buildClientAuthRequest(conn.GetPartner(), rng,
myRsaPrivKey, salt)
if err != nil { if err != nil {
// Close connection on an error // Close connection on an error
errClose := conn.Close() errClose := conn.Close()
...@@ -164,9 +178,9 @@ func StartAuthenticatedServer(cb AuthenticatedCallback, ...@@ -164,9 +178,9 @@ func StartAuthenticatedServer(cb AuthenticatedCallback,
// Register the waiter for a connection establishment // Register the waiter for a connection establishment
connCb := Callback(func(connection Connection) { connCb := Callback(func(connection Connection) {
// Upon establishing a connection, register a listener for the // Upon establishing a connection, register a listener for the
// client's identity proof. If a identity authentication // client's identity proof. If an identity authentication
// message is received and validated, an authenticated connection will // message is received and validated, an authenticated connection will
// be passed along via the callback // be passed along via the AuthenticatedCallback
connection.RegisterListener(catalog.ConnectionAuthenticationRequest, connection.RegisterListener(catalog.ConnectionAuthenticationRequest,
buildAuthConfirmationHandler(cb, connection)) buildAuthConfirmationHandler(cb, connection))
}) })
...@@ -174,8 +188,8 @@ func StartAuthenticatedServer(cb AuthenticatedCallback, ...@@ -174,8 +188,8 @@ func StartAuthenticatedServer(cb AuthenticatedCallback,
net, p) net, p)
} }
// authenticatedHandler provides an implementation for the AuthenticatedConnection // authenticatedHandler provides an implementation for the
// interface. // AuthenticatedConnection interface.
type authenticatedHandler struct { type authenticatedHandler struct {
Connection Connection
isAuthenticated bool isAuthenticated bool
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment