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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
3e5388d8
Commit
3e5388d8
authored
Jul 11, 2019
by
Jono
Browse files
Options
Downloads
Patches
Plain Diff
Integrating output registration with input of cMix
parent
cb8b1c9b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/client.go
+40
-12
40 additions, 12 deletions
api/client.go
cmd/root.go
+14
-0
14 additions, 0 deletions
cmd/root.go
glide.yaml
+1
-1
1 addition, 1 deletion
glide.yaml
with
55 additions
and
13 deletions
api/client.go
+
40
−
12
View file @
3e5388d8
...
@@ -31,8 +31,10 @@ import (
...
@@ -31,8 +31,10 @@ import (
"gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/registration"
"gitlab.com/elixxir/crypto/registration"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/crypto/signature"
"gitlab.com/elixxir/crypto/signature/rsa"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/primitives/ndf"
"gitlab.com/elixxir/primitives/switchboard"
"gitlab.com/elixxir/primitives/switchboard"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials"
goio
"io"
goio
"io"
...
@@ -43,8 +45,7 @@ type Client struct {
...
@@ -43,8 +45,7 @@ type Client struct {
storage
globals
.
Storage
storage
globals
.
Storage
sess
user
.
Session
sess
user
.
Session
comm
io
.
Communications
comm
io
.
Communications
gwAddresses
[]
io
.
ConnAddr
ndf
*
ndf
.
NetworkDefinition
regAddress
io
.
ConnAddr
}
}
// Populates a text message and returns its wire representation
// Populates a text message and returns its wire representation
...
@@ -59,11 +60,38 @@ func FormatTextMessage(message string) []byte {
...
@@ -59,11 +60,38 @@ func FormatTextMessage(message string) []byte {
return
wireRepresentation
return
wireRepresentation
}
}
// VerifyNDF verifies the signature of the network definition file (NDF) and
// returns the structure.
func
VerifyNDF
(
ndfString
,
ndfPub
string
)
*
ndf
.
NetworkDefinition
{
// Decode NDF string to a NetworkDefinition and its signature
ndfJSON
,
ndfSignature
,
err
:=
ndf
.
DecodeNDF
(
ndfString
)
if
err
!=
nil
{
globals
.
Log
.
FATAL
.
Panicf
(
"Could not decode NDF: %+v"
,
err
)
}
// Get public key
pubKey
,
err
:=
rsa
.
LoadPublicKeyFromPem
([]
byte
(
ndfPub
))
// Hash NDF JSON
opts
:=
rsa
.
NewDefaultOptions
()
rsaHash
:=
opts
.
Hash
.
New
()
rsaHash
.
Write
(
ndfJSON
.
Serialize
())
// Verify signature
err
=
rsa
.
Verify
(
pubKey
,
opts
.
Hash
,
rsaHash
.
Sum
(
nil
),
ndfSignature
,
nil
)
if
err
!=
nil
{
globals
.
Log
.
FATAL
.
Panicf
(
"Could not verify NDF: %+v"
,
err
)
}
return
ndfJSON
}
// Creates a new Client using the storage mechanism provided.
// Creates a new Client using the storage mechanism provided.
// If none is provided, a default storage using OS file access
// If none is provided, a default storage using OS file access
// is created
// is created
// returns a new Client object, and an error if it fails
// returns a new Client object, and an error if it fails
func
NewClient
(
s
globals
.
Storage
,
loc
string
)
(
*
Client
,
error
)
{
func
NewClient
(
s
globals
.
Storage
,
loc
string
,
ndfJSON
*
ndf
.
NetworkDefinition
)
(
*
Client
,
error
)
{
var
store
globals
.
Storage
var
store
globals
.
Storage
if
s
==
nil
{
if
s
==
nil
{
globals
.
Log
.
INFO
.
Printf
(
"No storage provided,"
+
globals
.
Log
.
INFO
.
Printf
(
"No storage provided,"
+
...
@@ -84,21 +112,21 @@ func NewClient(s globals.Storage, loc string) (*Client, error) {
...
@@ -84,21 +112,21 @@ func NewClient(s globals.Storage, loc string) (*Client, error) {
cl
:=
new
(
Client
)
cl
:=
new
(
Client
)
cl
.
storage
=
store
cl
.
storage
=
store
cl
.
comm
=
io
.
NewMessenger
()
cl
.
comm
=
io
.
NewMessenger
()
cl
.
gwAddresses
=
make
([]
io
.
ConnAddr
,
0
)
cl
.
ndf
=
ndfJSON
return
cl
,
nil
return
cl
,
nil
}
}
// Connects to gateways and registration server (if needed)
// Connects to gateways and registration server (if needed)
// using TLS filepaths to create credential information
// using TLS filepaths to create credential information
// for connection establishment
// for connection establishment
func
(
cl
*
Client
)
Connect
(
gwAddresses
[]
string
,
gwCertPath
,
func
(
cl
*
Client
)
Connect
()
error
{
regAddr
,
regCertPath
string
)
error
{
if
len
(
cl
.
ndf
.
Gateways
)
<
1
{
if
len
(
gwAddresses
)
<
1
{
globals
.
Log
.
ERROR
.
Printf
(
"Connect: Invalid number of nodes"
)
globals
.
Log
.
ERROR
.
Printf
(
"Connect: Invalid number of nodes"
)
return
errors
.
New
(
"could not connect due to invalid number of nodes"
)
return
errors
.
New
(
"could not connect due to invalid number of nodes"
)
}
}
var
gwCreds
credentials
.
TransportCredentials
=
nil
var
gwCreds
credentials
.
TransportCredentials
if
gwCertPath
!=
""
{
if
gwCertPath
!=
""
{
gwCreds
=
connect
.
NewCredentialsFromFile
(
gwCertPath
,
""
)
gwCreds
=
connect
.
NewCredentialsFromFile
(
gwCertPath
,
""
)
}
}
...
@@ -110,7 +138,7 @@ func (cl *Client) Connect(gwAddresses []string, gwCertPath,
...
@@ -110,7 +138,7 @@ func (cl *Client) Connect(gwAddresses []string, gwCertPath,
}
}
if
regAddr
!=
""
{
if
regAddr
!=
""
{
var
regCreds
credentials
.
TransportCredentials
=
nil
var
regCreds
credentials
.
TransportCredentials
if
regCertPath
!=
""
{
if
regCertPath
!=
""
{
regCreds
=
connect
.
NewCredentialsFromFile
(
regCertPath
,
""
)
regCreds
=
connect
.
NewCredentialsFromFile
(
regCertPath
,
""
)
}
}
...
...
This diff is collapsed.
Click to expand it.
cmd/root.go
+
14
−
0
View file @
3e5388d8
...
@@ -52,6 +52,20 @@ var userEmail string
...
@@ -52,6 +52,20 @@ var userEmail string
var
end2end
bool
var
end2end
bool
var
keyParams
[]
string
var
keyParams
[]
string
var
client
*
api
.
Client
var
client
*
api
.
Client
var
ndfPubKey
=
`-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA1dn7rREgAU1PDHqczJAe
kQX1eJhrREnOAlKGu+bgpIxHOyzECtnFFnbX+XfZZATjPLuBKHPzlkxQvE6j8aAr
fOh7DZl56i492zDY/I+JmrSxpNw2NkB7KdRlWIeUNSdFrc/U3A3ot4FmPxIgy7Hi
5uW9L3RsY7vmTliD9hwGDWXrOCOWp+LhJjuT5hJwxMHj95vo12o2VPHXk6G3lomF
g0hy+3YN9vzaKFUV+38iGk/ytpDiYa0JD5TfWV/vFyLdNtajd/8llcTUnSIpCROG
NO9lUX4OViW7+9mylT6XQjOwb58qVaLGPXuEQBqj/m8t6c08X6apbgeRP1D5CL2o
dMgqB68SmxOFgmSroMGZBpb9F7XniwJc0+rgrzc31nu+l2dCTcU84QENFg96yRen
1CD+kJ8jtcazQQ79f72R32TDbXvgB2sQD8aBzOfGVlTHFh6IUkD8X9vOxbNRh48H
YF58Qhjc7TC3d9FLaDi3KhM/1NrCOtNVM9n+W8DTLN0ptmc442dKLMFEQ8Uw2pkM
VDWW3zrZeD6+Vsn1D9v57+0v+X01gqjUPgZBeeRUAsomeiL2Dn7/GA+/xuweX45m
NrzFlgTDOrJ0TLWPPstFBhyX4+6tY6/FGP/5Gwjt29Kr1EN72HcUuDCecSn6MUsS
/EiMyA55AI68m/Wx+kHnJN0CAwEAAQ==
-----END PUBLIC KEY-----`
// Execute adds all child commands to the root command and sets flags
// Execute adds all child commands to the root command and sets flags
// appropriately. This is called by main.main(). It only needs to
// appropriately. This is called by main.main(). It only needs to
...
...
This diff is collapsed.
Click to expand it.
glide.yaml
+
1
−
1
View file @
3e5388d8
...
@@ -12,7 +12,7 @@ import:
...
@@ -12,7 +12,7 @@ import:
repo
:
git@gitlab.com:elixxir/comms
repo
:
git@gitlab.com:elixxir/comms
vcs
:
git
vcs
:
git
-
package
:
gitlab.com/elixxir/primitives
-
package
:
gitlab.com/elixxir/primitives
version
:
master
version
:
newMessageFormat
repo
:
git@gitlab.com:elixxir/primitives
repo
:
git@gitlab.com:elixxir/primitives
vcs
:
git
vcs
:
git
-
package
:
github.com/mitchellh/go-homedir
-
package
:
github.com/mitchellh/go-homedir
...
...
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