Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comms
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
comms
Commits
ff981d6b
Commit
ff981d6b
authored
Aug 6, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Remove dynamic authentication
parent
ff226b00
No related branches found
No related tags found
1 merge request
!11
Release
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
connect/auth.go
+3
-50
3 additions, 50 deletions
connect/auth.go
connect/auth_test.go
+0
-82
0 additions, 82 deletions
connect/auth_test.go
connect/host.go
+0
-43
0 additions, 43 deletions
connect/host.go
connect/host_test.go
+0
-18
0 additions, 18 deletions
connect/host_test.go
with
3 additions
and
193 deletions
connect/auth.go
+
3
−
50
View file @
ff981d6b
...
...
@@ -10,7 +10,6 @@
package
connect
import
(
"bytes"
"context"
"crypto/rand"
"encoding/base64"
...
...
@@ -22,7 +21,6 @@ import (
"gitlab.com/xx_network/comms/connect/token"
pb
"gitlab.com/xx_network/comms/messages"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/crypto/xx"
"gitlab.com/xx_network/primitives/id"
"google.golang.org/grpc/metadata"
)
...
...
@@ -164,63 +162,18 @@ func (c *ProtoComms) GenerateToken() ([]byte, error) {
return
c
.
tokens
.
Generate
()
.
Marshal
(),
nil
}
// Performs the dynamic authentication process such that Hosts that were not
// already added to the Manager can establish authentication
func
(
c
*
ProtoComms
)
dynamicAuth
(
msg
*
pb
.
AuthenticatedMessage
)
(
host
*
Host
,
err
error
)
{
// Verify the client is attempting a dynamic authentication
if
msg
.
Client
==
nil
||
msg
.
Client
.
PublicKey
==
""
||
msg
.
Client
.
Salt
==
nil
{
return
nil
,
errors
.
New
(
"Invalid dynamic authentication attempt!"
)
}
// Process the public key
pubKey
,
err
:=
rsa
.
LoadPublicKeyFromPem
([]
byte
(
msg
.
Client
.
PublicKey
))
if
err
!=
nil
{
return
nil
,
errors
.
New
(
err
.
Error
())
}
// Generate the user's ID from supplied Client information
uid
,
err
:=
xx
.
NewID
(
pubKey
,
msg
.
Client
.
Salt
,
id
.
User
)
if
err
!=
nil
{
return
nil
,
err
}
// Verify the ID provided correctly matches the generated ID
if
!
bytes
.
Equal
(
msg
.
ID
,
uid
.
Marshal
())
{
return
nil
,
errors
.
Errorf
(
"Provided ID does not match. Expected: %s, Actual: %s"
,
uid
.
String
(),
msg
.
ID
)
}
// Create and add the new host to the manager
host
,
err
=
newDynamicHost
(
uid
,
[]
byte
(
msg
.
Client
.
PublicKey
))
if
err
!=
nil
{
return
}
c
.
addHost
(
host
)
return
}
// Validates a signed token using internal state
func
(
c
*
ProtoComms
)
ValidateToken
(
msg
*
pb
.
AuthenticatedMessage
)
(
err
error
)
{
// Convert EntityID to ID
msgID
,
err
:=
id
.
Unmarshal
(
msg
.
ID
)
senderId
,
err
:=
id
.
Unmarshal
(
msg
.
ID
)
if
err
!=
nil
{
return
err
}
// Verify the Host exists for the provided ID
host
,
ok
:=
c
.
GetHost
(
msgID
)
host
,
ok
:=
c
.
GetHost
(
senderId
)
if
!
ok
{
// If the host does not already exist, attempt dynamic authentication
jww
.
DEBUG
.
Printf
(
"Attempting dynamic authentication: %s"
,
msgID
.
String
())
host
,
err
=
c
.
dynamicAuth
(
msg
)
if
err
!=
nil
{
return
errors
.
Errorf
(
"Unable to complete dynamic authentication: %+v"
,
err
)
}
return
errors
.
Errorf
(
"No host set up with %s, refusing contact"
,
senderId
)
}
// Get the signed token
...
...
This diff is collapsed.
Click to expand it.
connect/auth_test.go
+
0
−
82
View file @
ff981d6b
...
...
@@ -14,9 +14,7 @@ import (
token
"gitlab.com/xx_network/comms/connect/token"
pb
"gitlab.com/xx_network/comms/messages"
"gitlab.com/xx_network/comms/testkeys"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/crypto/xx"
"gitlab.com/xx_network/primitives/id"
"google.golang.org/grpc/peer"
"net"
...
...
@@ -345,86 +343,6 @@ func TestProtoComms_ValidateToken_BadId(t *testing.T) {
}
// Dynamic authentication happy path (e.g. host not pre-added)
func
TestProtoComms_ValidateTokenDynamic
(
t
*
testing
.
T
)
{
// All of this is setup for UID ----
privKey
,
err
:=
rsa
.
GenerateKey
(
csprng
.
NewSystemRNG
(),
rsa
.
DefaultRSABitLen
)
if
err
!=
nil
{
t
.
Errorf
(
"Could not generate private key: %+v"
,
err
)
}
pubKey
:=
privKey
.
GetPublic
()
salt
:=
[]
byte
(
"0123456789ABCDEF0123456789ABCDEF"
)
uid
,
err
:=
xx
.
NewID
(
pubKey
,
salt
,
id
.
User
)
if
err
!=
nil
{
t
.
Errorf
(
"Could not generate user ID: %+v"
,
err
)
}
testId
:=
uid
.
String
()
// ------
// Now we set up the client comms object
comm
:=
ProtoComms
{
Id
:
uid
,
ListeningAddr
:
""
,
tokens
:
token
.
NewMap
(),
Manager
:
newManager
(),
}
err
=
comm
.
setPrivateKey
(
rsa
.
CreatePrivateKeyPem
(
privKey
))
if
err
!=
nil
{
t
.
Errorf
(
"Expected to set private key: %+v"
,
err
)
}
tokenBytes
,
err
:=
comm
.
GenerateToken
()
if
err
!=
nil
||
tokenBytes
==
nil
{
t
.
Errorf
(
"Unable to generate token: %+v"
,
err
)
}
tkn
:=
token
.
Token
{}
copy
(
tkn
[
:
],
tokenBytes
)
// For this test we won't addHost to Manager, we'll just create a host
// so we can compare to the dynamic one later
host
,
err
:=
newDynamicHost
(
uid
,
rsa
.
CreatePublicKeyPem
(
pubKey
))
if
err
!=
nil
{
t
.
Errorf
(
"Unable to create host: %+v"
,
err
)
}
host
.
transmissionToken
.
Set
(
tkn
)
tokenMsg
:=
&
pb
.
AssignToken
{
Token
:
tokenBytes
,
}
// Set up auth msg
msg
,
err
:=
comm
.
PackAuthenticatedMessage
(
tokenMsg
,
host
,
true
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected no error packing authenticated message: %+v"
,
err
)
}
msg
.
Client
=
&
pb
.
ClientID
{
Salt
:
salt
,
PublicKey
:
string
(
rsa
.
CreatePublicKeyPem
(
pubKey
)),
}
// Here's the method we're testing
err
=
comm
.
ValidateToken
(
msg
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected to validate token: %+v"
,
err
)
}
// Check the output values behaved as expected
host
,
ok
:=
comm
.
GetHost
(
uid
)
if
!
ok
{
t
.
Errorf
(
"Expected dynamic auth to add host %s!"
,
testId
)
}
if
!
host
.
IsDynamicHost
()
{
t
.
Errorf
(
"Expected host to be dynamic!"
)
}
if
!
bytes
.
Equal
(
msg
.
Token
,
host
.
receptionToken
.
GetBytes
())
{
t
.
Errorf
(
"Message token doesn't match message's token! "
+
"Expected: %+v"
+
"
\n\t
Received: %+v"
,
host
.
receptionToken
,
msg
.
Token
)
}
}
func
TestProtoComms_DisableAuth
(
t
*
testing
.
T
)
{
testId
:=
id
.
NewIdFromString
(
"test"
,
id
.
Node
,
t
)
comm
:=
ProtoComms
{
...
...
This diff is collapsed.
Click to expand it.
connect/host.go
+
0
−
43
View file @
ff981d6b
...
...
@@ -60,10 +60,6 @@ type Host struct {
// RSA Public Key corresponding to the TLS Certificate
rsaPublicKey
*
rsa
.
PublicKey
// Indicates whether dynamic authentication was used for this Host
// This is useful for determining whether a Host's key was hardcoded
dynamicHost
bool
// State tracking for host metric
metrics
*
Metric
...
...
@@ -121,32 +117,6 @@ func NewHost(id *id.ID, address string, cert []byte, params HostParams) (host *H
return
}
// Creates a new dynamic-authenticated Host object
func
newDynamicHost
(
id
*
id
.
ID
,
publicKey
[]
byte
)
(
host
*
Host
,
err
error
)
{
// Initialize the Host object
// IMPORTANT: This flag must be set to true for all dynamic Hosts
// because the security properties for these Hosts differ
host
=
&
Host
{
id
:
id
,
dynamicHost
:
true
,
transmissionToken
:
token
.
NewLive
(),
receptionToken
:
token
.
NewLive
(),
}
// Create the RSA Public Key object
host
.
rsaPublicKey
,
err
=
rsa
.
LoadPublicKeyFromPem
(
publicKey
)
if
err
!=
nil
{
err
=
errors
.
Errorf
(
"Error extracting PublicKey: %+v"
,
err
)
}
return
}
// Simple getter for the dynamicHost value
func
(
h
*
Host
)
IsDynamicHost
()
bool
{
return
h
.
dynamicHost
}
// the amount of data, when streaming, that a sender can send before receiving an ACK
// keep at zero to use the default GRPC algorithm to determine
func
(
h
*
Host
)
SetWindowSize
(
size
int32
)
{
...
...
@@ -476,16 +446,3 @@ func (h *Host) SetTestPublicKey(key *rsa.PublicKey, t interface{}) {
}
h
.
rsaPublicKey
=
key
}
// Set host to dynamic (for testing use)
func
(
h
*
Host
)
SetTestDynamic
(
t
interface
{})
{
switch
t
.
(
type
)
{
case
*
testing
.
T
:
break
case
*
testing
.
M
:
break
default
:
jww
.
FATAL
.
Panicf
(
"SetTestDynamic is restricted to testing only. Got %T"
,
t
)
}
h
.
dynamicHost
=
true
}
This diff is collapsed.
Click to expand it.
connect/host_test.go
+
0
−
18
View file @
ff981d6b
...
...
@@ -96,24 +96,6 @@ func TestHost_UpdateAddress(t *testing.T) {
}
}
// Validate that dynamic host defaults to false and can be set to true
func
TestHost_IsDynamicHost
(
t
*
testing
.
T
)
{
host
:=
Host
{}
if
host
.
IsDynamicHost
()
!=
false
{
t
.
Errorf
(
"Correct bool not returned. Expected false, got %v"
,
host
.
dynamicHost
)
}
host
.
dynamicHost
=
true
if
host
.
IsDynamicHost
()
!=
true
{
t
.
Errorf
(
"Correct bool not returned. Expected true, got %v"
,
host
.
dynamicHost
)
}
}
// Full test
func
TestHost_IsOnline
(
t
*
testing
.
T
)
{
addr
:=
"0.0.0.0:10234"
...
...
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