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

Clean up documentation

parent 11364b03
Branches
Tags
3 merge requests!510Release,!216Xx 3895/authenticated connection,!207WIP: Client Restructure
...@@ -204,8 +204,8 @@ func buildAuthenticatedConnection(conn Connection) *authenticatedHandler { ...@@ -204,8 +204,8 @@ func buildAuthenticatedConnection(conn Connection) *authenticatedHandler {
} }
} }
// IsAuthenticated returns whether the AuthenticatedConnection has completed the // IsAuthenticated returns whether the AuthenticatedConnection has completed
// authentication process. // the authentication process.
func (h *authenticatedHandler) IsAuthenticated() bool { func (h *authenticatedHandler) IsAuthenticated() bool {
return h.isAuthenticated return h.isAuthenticated
} }
......
...@@ -20,16 +20,19 @@ import ( ...@@ -20,16 +20,19 @@ import (
"time" "time"
) )
// TestConnectWithAuthentication using the // TestConnectWithAuthentication will test the client/server relationship for
// an AuthenticatedConnection. This will construct a client which will send an
// IdentityAuthentication message to the server, who will hear it and verify
// the contents. This will use a mock connection interface and private
// production code helper functions for easier testing.
func TestConnectWithAuthentication(t *testing.T) { func TestConnectWithAuthentication(t *testing.T) {
grp := getGroup() grp := getGroup()
numPrimeByte := len(grp.GetPBytes()) numPrimeByte := len(grp.GetPBytes())
cmixHandler := newMockCmixHandler() // Set up cmix handler
mockNet, err := newMockCmix(cmixHandler, t) mockNet := newMockCmix()
if err != nil {
t.Fatalf("Failed to initialize mock network: %+v", err) // Set up connect arguments
}
prng := rand.New(rand.NewSource(42)) prng := rand.New(rand.NewSource(42))
dhPrivKey := diffieHellman.GeneratePrivateKey( dhPrivKey := diffieHellman.GeneratePrivateKey(
numPrimeByte, grp, prng) numPrimeByte, grp, prng)
...@@ -42,12 +45,17 @@ func TestConnectWithAuthentication(t *testing.T) { ...@@ -42,12 +45,17 @@ func TestConnectWithAuthentication(t *testing.T) {
t.Fatalf("Faled to load private key: %v", err) t.Fatalf("Faled to load private key: %v", err)
} }
// Construct client ID the proper way as server will need to verify it
// using the xx.NewID function call
myId, err := xx.NewID(myRsaPrivKey.GetPublic(), salt, id.User) myId, err := xx.NewID(myRsaPrivKey.GetPublic(), salt, id.User)
if err != nil { if err != nil {
t.Fatalf("Failed to generate client's id: %+v", err) t.Fatalf("Failed to generate client's id: %+v", err)
} }
// Generate server ID using testing interface
serverID := id.NewIdFromString("server", id.User, t) serverID := id.NewIdFromString("server", id.User, t)
// Construct recipient
recipient := contact.Contact{ recipient := contact.Contact{
ID: serverID, ID: serverID,
DhPubKey: dhPubKey, DhPubKey: dhPubKey,
...@@ -56,17 +64,19 @@ func TestConnectWithAuthentication(t *testing.T) { ...@@ -56,17 +64,19 @@ func TestConnectWithAuthentication(t *testing.T) {
rng := fastRNG.NewStreamGenerator(1, 1, rng := fastRNG.NewStreamGenerator(1, 1,
csprng.NewSystemRNG) csprng.NewSystemRNG)
// Create the mock connection, which will be shared by the client and server. // Create the mock connection, which will be shared by the client and
// This will send the client's request to the server internally // server. This will send the client's request to the server internally
mockConn := newMockConnection(myId, serverID, dhPrivKey, dhPubKey) mockConn := newMockConnection(myId, serverID, dhPrivKey, dhPubKey)
// Set up the server // Set up the server's callback, which will pass the authenticated
// connection through via a channel
authConnChan := make(chan AuthenticatedConnection, 1) authConnChan := make(chan AuthenticatedConnection, 1)
serverCb := AuthenticatedCallback( serverCb := AuthenticatedCallback(
func(connection AuthenticatedConnection) { func(connection AuthenticatedConnection) {
authConnChan <- connection authConnChan <- connection
}) })
// Initialize params with a shorter timeout to hasten test results
customParams := GetDefaultParams() customParams := GetDefaultParams()
customParams.Timeout = 3 * time.Second customParams.Timeout = 3 * time.Second
...@@ -85,9 +95,11 @@ func TestConnectWithAuthentication(t *testing.T) { ...@@ -85,9 +95,11 @@ func TestConnectWithAuthentication(t *testing.T) {
t.Fatalf("ConnectWithAuthentication error: %+v", err) t.Fatalf("ConnectWithAuthentication error: %+v", err)
} }
// Wait for the server to establish it's connection via the callback
timeout := time.NewTimer(customParams.Timeout) timeout := time.NewTimer(customParams.Timeout)
select { select {
case <-authConnChan: case <-authConnChan:
return
case <-timeout.C: case <-timeout.C:
t.Fatalf("Timed out waiting for server's authenticated connection " + t.Fatalf("Timed out waiting for server's authenticated connection " +
"to be established") "to be established")
......
package connect package connect
import ( import (
"fmt"
"github.com/cloudflare/circl/dh/sidh" "github.com/cloudflare/circl/dh/sidh"
"gitlab.com/elixxir/client/catalog" "gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/cmix" "gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/gateway" "gitlab.com/elixxir/client/cmix/gateway"
"gitlab.com/elixxir/client/cmix/identity" "gitlab.com/elixxir/client/cmix/identity"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/message" "gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/e2e" "gitlab.com/elixxir/client/e2e"
...@@ -15,20 +13,17 @@ import ( ...@@ -15,20 +13,17 @@ import (
"gitlab.com/elixxir/client/e2e/ratchet/partner/session" "gitlab.com/elixxir/client/e2e/ratchet/partner/session"
"gitlab.com/elixxir/client/e2e/receive" "gitlab.com/elixxir/client/e2e/receive"
"gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/stoppable"
pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
cryptoE2e "gitlab.com/elixxir/crypto/e2e" cryptoE2e "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"sync"
"time" "time"
) )
...@@ -179,42 +174,13 @@ func (m mockConnection) Unregister(listenerID receive.ListenerID) { ...@@ -179,42 +174,13 @@ func (m mockConnection) Unregister(listenerID receive.ListenerID) {
// Mock cMix Client // // Mock cMix Client //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
type mockCmixHandler struct {
processorMap map[id.ID]map[string][]message.Processor
sync.RWMutex
}
func newMockCmixHandler() *mockCmixHandler {
return &mockCmixHandler{
processorMap: make(map[id.ID]map[string][]message.Processor),
}
}
type mockCmix struct { type mockCmix struct {
numPrimeBytes int
health bool
handler *mockCmixHandler
instance *network.Instance instance *network.Instance
} }
func newMockCmix(handler *mockCmixHandler, face interface{}) (*mockCmix, error) { func newMockCmix() *mockCmix {
instanceComms := &connect.ProtoComms{ return &mockCmix{}
Manager: connect.NewManagerTesting(face),
}
thisInstance, err := network.NewInstanceTesting(instanceComms, getNDF(),
getNDF(), nil, nil, face)
if err != nil {
return nil, err
}
return &mockCmix{
numPrimeBytes: 4096,
health: true,
handler: handler,
instance: thisInstance,
}, nil
} }
func (m mockCmix) Connect(ndf *ndf.NetworkDefinition) error { func (m mockCmix) Connect(ndf *ndf.NetworkDefinition) error {
...@@ -226,37 +192,12 @@ func (m *mockCmix) Follow(report cmix.ClientErrorReport) (stoppable.Stoppable, e ...@@ -226,37 +192,12 @@ func (m *mockCmix) Follow(report cmix.ClientErrorReport) (stoppable.Stoppable, e
} }
func (m *mockCmix) GetMaxMessageLength() int { func (m *mockCmix) GetMaxMessageLength() int {
return format.NewMessage(m.numPrimeBytes).ContentsSize() return 4096
} }
func (m *mockCmix) Send(recipient *id.ID, fingerprint format.Fingerprint, func (m *mockCmix) Send(recipient *id.ID, fingerprint format.Fingerprint,
service message.Service, payload, mac []byte, service message.Service, payload, mac []byte,
cmixParams cmix.CMIXParams) (id.Round, ephemeral.Id, error) { cmixParams cmix.CMIXParams) (id.Round, ephemeral.Id, error) {
msg := format.NewMessage(m.numPrimeBytes)
msg.SetContents(payload)
msg.SetMac(mac)
msg.SetKeyFP(fingerprint)
mockRound := rounds.Round{
State: states.COMPLETED,
Timestamps: map[states.Round]time.Time{states.COMPLETED: netTime.Now().Add(5 * time.Second)},
Raw: &pb.RoundInfo{},
}
m.handler.RLock()
defer m.handler.RUnlock()
fmt.Printf("len procs: %v\n", len(m.handler.processorMap[*recipient][service.Tag]))
fmt.Printf("recipient: %s, tag: %s\n", recipient, service.Tag)
if service.Tag == catalog.E2e {
// todo need to activate the authenticated listener for the server here...
return 0, ephemeral.Id{}, nil
}
for _, p := range m.handler.processorMap[*recipient][service.Tag] {
fmt.Printf("running process with tag: %s\n", service.Tag)
p.Process(msg, receptionID.EphemeralIdentity{}, mockRound)
}
return 0, ephemeral.Id{}, nil return 0, ephemeral.Id{}, nil
} }
...@@ -266,52 +207,18 @@ func (m *mockCmix) SendMany(messages []cmix.TargetedCmixMessage, p cmix.CMIXPara ...@@ -266,52 +207,18 @@ func (m *mockCmix) SendMany(messages []cmix.TargetedCmixMessage, p cmix.CMIXPara
} }
func (m *mockCmix) AddIdentity(id *id.ID, validUntil time.Time, persistent bool) { func (m *mockCmix) AddIdentity(id *id.ID, validUntil time.Time, persistent bool) {
m.handler.Lock()
defer m.handler.Unlock()
if _, exists := m.handler.processorMap[*id]; exists {
return
}
fmt.Printf("AddIdentity recipient: %s\n", id)
m.handler.processorMap[*id] = make(map[string][]message.Processor)
} }
func (m *mockCmix) RemoveIdentity(id *id.ID) { func (m *mockCmix) RemoveIdentity(id *id.ID) {
m.handler.Lock()
defer m.handler.Unlock()
fmt.Printf("RemoveIdentity recipient: %s\n", id)
delete(m.handler.processorMap, *id)
} }
func (m *mockCmix) GetIdentity(get *id.ID) (identity.TrackedID, error) { func (m *mockCmix) GetIdentity(get *id.ID) (identity.TrackedID, error) {
m.handler.RLock()
defer m.handler.RUnlock()
return identity.TrackedID{ return identity.TrackedID{
Creation: netTime.Now().Add(-time.Minute), Creation: netTime.Now().Add(-time.Minute),
}, nil }, nil
} }
func (m *mockCmix) AddFingerprint(identity *id.ID, fp format.Fingerprint, mp message.Processor) error { func (m *mockCmix) AddFingerprint(identity *id.ID, fp format.Fingerprint, mp message.Processor) error {
if _, exists := m.handler.processorMap[*identity][fp.String()]; !exists {
if underMap := m.handler.processorMap[*identity]; underMap == nil {
underMap = make(map[string][]message.Processor)
underMap[fp.String()] = []message.Processor{mp}
m.handler.processorMap[*identity] = underMap
return nil
}
m.handler.processorMap[*identity][fp.String()] =
[]message.Processor{mp}
return nil
}
m.handler.processorMap[*identity][fp.String()] =
append(m.handler.processorMap[*identity][fp.String()], mp)
return nil return nil
} }
...@@ -324,25 +231,6 @@ func (m *mockCmix) DeleteClientFingerprints(identity *id.ID) { ...@@ -324,25 +231,6 @@ func (m *mockCmix) DeleteClientFingerprints(identity *id.ID) {
} }
func (m *mockCmix) AddService(clientID *id.ID, newService message.Service, response message.Processor) { func (m *mockCmix) AddService(clientID *id.ID, newService message.Service, response message.Processor) {
fmt.Printf("AddService recipient: %s, tag: %s, proc: %v\n", clientID, newService.Tag, response)
if _, exists := m.handler.processorMap[*clientID][newService.Tag]; !exists {
if underMap := m.handler.processorMap[*clientID]; underMap == nil {
underMap = make(map[string][]message.Processor)
underMap[newService.Tag] = []message.Processor{response}
m.handler.processorMap[*clientID] = underMap
return
}
m.handler.processorMap[*clientID][newService.Tag] =
[]message.Processor{response}
return
}
m.handler.processorMap[*clientID][newService.Tag] =
append(m.handler.processorMap[*clientID][newService.Tag], response)
return return
} }
...@@ -351,12 +239,6 @@ func (m *mockCmix) DeleteService(clientID *id.ID, toDelete message.Service, proc ...@@ -351,12 +239,6 @@ func (m *mockCmix) DeleteService(clientID *id.ID, toDelete message.Service, proc
} }
func (m *mockCmix) DeleteClientService(clientID *id.ID) { func (m *mockCmix) DeleteClientService(clientID *id.ID) {
m.handler.Lock()
defer m.handler.Unlock()
for tag := range m.handler.processorMap[*clientID] {
delete(m.handler.processorMap[*clientID], tag)
}
} }
func (m *mockCmix) TrackServices(tracker message.ServicesTracker) { func (m *mockCmix) TrackServices(tracker message.ServicesTracker) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment