Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
49cfab25
Commit
49cfab25
authored
3 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Clean up documentation
parent
11364b03
No related branches found
No related tags found
3 merge requests
!510
Release
,
!216
Xx 3895/authenticated connection
,
!207
WIP: Client Restructure
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
connect/authenticated.go
+2
-2
2 additions, 2 deletions
connect/authenticated.go
connect/authenticated_test.go
+21
-9
21 additions, 9 deletions
connect/authenticated_test.go
connect/utils_test.go
+4
-122
4 additions, 122 deletions
connect/utils_test.go
with
27 additions
and
133 deletions
connect/authenticated.go
+
2
−
2
View file @
49cfab25
...
...
@@ -204,8 +204,8 @@ func buildAuthenticatedConnection(conn Connection) *authenticatedHandler {
}
}
// IsAuthenticated returns whether the AuthenticatedConnection has completed
the
// authentication process.
// IsAuthenticated returns whether the AuthenticatedConnection has completed
//
the
authentication process.
func
(
h
*
authenticatedHandler
)
IsAuthenticated
()
bool
{
return
h
.
isAuthenticated
}
...
...
This diff is collapsed.
Click to expand it.
connect/authenticated_test.go
+
21
−
9
View file @
49cfab25
...
...
@@ -20,16 +20,19 @@ import (
"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
)
{
grp
:=
getGroup
()
numPrimeByte
:=
len
(
grp
.
GetPBytes
())
cmixHandler
:=
newMockCmixHandler
()
mockNet
,
err
:=
newMockCmix
(
cmixHandler
,
t
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to initialize mock network: %+v"
,
err
)
}
// Set up cmix handler
mockNet
:=
newMockCmix
()
// Set up connect arguments
prng
:=
rand
.
New
(
rand
.
NewSource
(
42
))
dhPrivKey
:=
diffieHellman
.
GeneratePrivateKey
(
numPrimeByte
,
grp
,
prng
)
...
...
@@ -42,12 +45,17 @@ func TestConnectWithAuthentication(t *testing.T) {
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
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to generate client's id: %+v"
,
err
)
}
// Generate server ID using testing interface
serverID
:=
id
.
NewIdFromString
(
"server"
,
id
.
User
,
t
)
// Construct recipient
recipient
:=
contact
.
Contact
{
ID
:
serverID
,
DhPubKey
:
dhPubKey
,
...
...
@@ -56,17 +64,19 @@ func TestConnectWithAuthentication(t *testing.T) {
rng
:=
fastRNG
.
NewStreamGenerator
(
1
,
1
,
csprng
.
NewSystemRNG
)
// Create the mock connection, which will be shared by the client and
server.
// This will send the client's request to the server internally
// Create the mock connection, which will be shared by the client and
//
server.
This will send the client's request to the server internally
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
)
serverCb
:=
AuthenticatedCallback
(
func
(
connection
AuthenticatedConnection
)
{
authConnChan
<-
connection
})
// Initialize params with a shorter timeout to hasten test results
customParams
:=
GetDefaultParams
()
customParams
.
Timeout
=
3
*
time
.
Second
...
...
@@ -85,9 +95,11 @@ func TestConnectWithAuthentication(t *testing.T) {
t
.
Fatalf
(
"ConnectWithAuthentication error: %+v"
,
err
)
}
// Wait for the server to establish it's connection via the callback
timeout
:=
time
.
NewTimer
(
customParams
.
Timeout
)
select
{
case
<-
authConnChan
:
return
case
<-
timeout
.
C
:
t
.
Fatalf
(
"Timed out waiting for server's authenticated connection "
+
"to be established"
)
...
...
This diff is collapsed.
Click to expand it.
connect/utils_test.go
+
4
−
122
View file @
49cfab25
package
connect
import
(
"fmt"
"github.com/cloudflare/circl/dh/sidh"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/gateway"
"gitlab.com/elixxir/client/cmix/identity"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/e2e"
...
...
@@ -15,20 +13,17 @@ import (
"gitlab.com/elixxir/client/e2e/ratchet/partner/session"
"gitlab.com/elixxir/client/e2e/receive"
"gitlab.com/elixxir/client/stoppable"
pb
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic"
cryptoE2e
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/ndf"
"gitlab.com/xx_network/primitives/netTime"
"sync"
"time"
)
...
...
@@ -179,42 +174,13 @@ func (m mockConnection) Unregister(listenerID receive.ListenerID) {
// 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
{
numPrimeBytes
int
health
bool
handler
*
mockCmixHandler
instance
*
network
.
Instance
}
func
newMockCmix
(
handler
*
mockCmixHandler
,
face
interface
{}
)
(
*
mockCmix
,
error
)
{
func
newMockCmix
()
*
mockCmix
{
instanceComms
:=
&
connect
.
ProtoComms
{
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
return
&
mockCmix
{}
}
func
(
m
mockCmix
)
Connect
(
ndf
*
ndf
.
NetworkDefinition
)
error
{
...
...
@@ -226,37 +192,12 @@ func (m *mockCmix) Follow(report cmix.ClientErrorReport) (stoppable.Stoppable, e
}
func
(
m
*
mockCmix
)
GetMaxMessageLength
()
int
{
return
format
.
NewMessage
(
m
.
numPrimeBytes
)
.
ContentsSize
()
return
4096
}
func
(
m
*
mockCmix
)
Send
(
recipient
*
id
.
ID
,
fingerprint
format
.
Fingerprint
,
service
message
.
Service
,
payload
,
mac
[]
byte
,
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
}
...
...
@@ -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
)
{
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
)
{
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
)
{
m
.
handler
.
RLock
()
defer
m
.
handler
.
RUnlock
()
return
identity
.
TrackedID
{
Creation
:
netTime
.
Now
()
.
Add
(
-
time
.
Minute
),
},
nil
}
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
}
...
...
@@ -324,25 +231,6 @@ func (m *mockCmix) DeleteClientFingerprints(identity *id.ID) {
}
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
}
...
...
@@ -351,12 +239,6 @@ func (m *mockCmix) DeleteService(clientID *id.ID, toDelete message.Service, proc
}
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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment