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
6eadfdef
Commit
6eadfdef
authored
Oct 20, 2020
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
added autneticated channel APIs
parent
61a36abd
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/authenticatedChannel.go
+47
-11
47 additions, 11 deletions
api/authenticatedChannel.go
api/client.go
+5
-0
5 additions, 0 deletions
api/client.go
auth/callback.go
+3
-4
3 additions, 4 deletions
auth/callback.go
bindings/client.go
+1
-1
1 addition, 1 deletion
bindings/client.go
with
56 additions
and
16 deletions
api/authenticatedChannel.go
+
47
−
11
View file @
6eadfdef
...
@@ -19,7 +19,7 @@ import (
...
@@ -19,7 +19,7 @@ import (
// will be called
// will be called
func
(
c
*
Client
)
RequestAuthenticatedChannel
(
recipient
,
me
contact
.
Contact
,
func
(
c
*
Client
)
RequestAuthenticatedChannel
(
recipient
,
me
contact
.
Contact
,
message
string
)
error
{
message
string
)
error
{
jww
.
INFO
.
Printf
(
"RequestAuthenticatedChannel(%
v
)"
,
recipient
)
jww
.
INFO
.
Printf
(
"RequestAuthenticatedChannel(%
s
)"
,
recipient
.
ID
)
if
!
c
.
network
.
GetHealthTracker
()
.
IsHealthy
()
{
if
!
c
.
network
.
GetHealthTracker
()
.
IsHealthy
()
{
return
errors
.
New
(
"Cannot request authenticated channel "
+
return
errors
.
New
(
"Cannot request authenticated channel "
+
...
@@ -30,18 +30,54 @@ func (c *Client) RequestAuthenticatedChannel(recipient, me contact.Contact,
...
@@ -30,18 +30,54 @@ func (c *Client) RequestAuthenticatedChannel(recipient, me contact.Contact,
c
.
storage
,
c
.
network
)
c
.
storage
,
c
.
network
)
}
}
// RegisterAuthConfirmationCb registers a callback for channel
// RegisterAuthCallbacks registers both callbacks for authenticated channels.
// authentication confirmation events.
// This can only be called once
func
(
c
*
Client
)
RegisterAuthConfirmationCb
(
cb
func
(
contact
contact
.
Contact
,
func
(
c
*
Client
)
RegisterAuthCallbacks
(
request
auth
.
RequestCallback
,
payload
[]
byte
))
{
confirm
auth
.
ConfirmCallback
)
error
{
jww
.
INFO
.
Printf
(
"RegisterAuthConfirmationCb(...)"
)
jww
.
INFO
.
Printf
(
"RegisterAuthCallbacks(...)"
)
exicuted
:=
false
c
.
authOnce
.
Do
(
func
()
{
stop
:=
auth
.
RegisterCallbacks
(
request
,
confirm
,
c
.
switchboard
,
c
.
storage
,
c
.
network
)
c
.
runner
.
Add
(
stop
)
exicuted
=
true
})
if
!
exicuted
{
return
errors
.
New
(
"Cannot register auth callbacks more than "
+
"once"
)
}
return
nil
}
}
// RegisterAuthRequestCb registers a callback for channel
// ConfirmAuthenticatedChannel creates an authenticated channel out of a valid
// authentication request events.
// received request and sends a message to the requestor that the request has
func
(
c
*
Client
)
RegisterAuthRequestCb
(
cb
func
(
contact
contact
.
Contact
,
// been confirmed
payload
[]
byte
))
{
// It will not run if the network status is not healthy
jww
.
INFO
.
Printf
(
"RegisterAuthRequestCb(...)"
)
// An error will be returned if a channel already exists, if a request doest
// exist, or if the passed in contact does not exactly match the received
// request
func
(
c
*
Client
)
ConfirmAuthenticatedChannel
(
recipient
,
me
contact
.
Contact
,
message
string
)
error
{
jww
.
INFO
.
Printf
(
"RequestAuthenticatedChannel(%s)"
,
recipient
.
ID
)
if
!
c
.
network
.
GetHealthTracker
()
.
IsHealthy
()
{
return
errors
.
New
(
"Cannot request authenticated channel "
+
"creation when the network is not healthy"
)
}
return
auth
.
ConfirmRequestAuth
(
recipient
,
c
.
rng
.
GetStream
(),
c
.
storage
,
c
.
network
)
}
// VerifyOwnership checks if the ownership proof on a passed contact matches the
// identity in a verified contact
func
(
c
*
Client
)
VerifyOwnership
(
received
,
verified
contact
.
Contact
)
bool
{
jww
.
INFO
.
Printf
(
"VerifyOwnership(%s)"
,
received
.
ID
)
return
auth
.
VerifyOwnership
(
received
,
verified
,
c
.
storage
)
}
}
// HasAuthenticatedChannel returns true if an authenticated channel exists for
// HasAuthenticatedChannel returns true if an authenticated channel exists for
...
...
This diff is collapsed.
Click to expand it.
api/client.go
+
5
−
0
View file @
6eadfdef
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
"gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/large"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/ndf"
"gitlab.com/xx_network/primitives/ndf"
"sync"
"time"
"time"
)
)
...
@@ -49,6 +50,10 @@ type Client struct {
...
@@ -49,6 +50,10 @@ type Client struct {
//contains stopables for all running threads
//contains stopables for all running threads
runner
*
stoppable
.
Multi
runner
*
stoppable
.
Multi
status
*
statusTracker
status
*
statusTracker
// contains the sync once used to ensure authenticated channel callbacks are
// only registered once
authOnce
sync
.
Once
}
}
// NewClient creates client storage, generates keys, connects, and registers
// NewClient creates client storage, generates keys, connects, and registers
...
...
This diff is collapsed.
Click to expand it.
auth/callback.go
+
3
−
4
View file @
6eadfdef
...
@@ -2,6 +2,7 @@ package auth
...
@@ -2,6 +2,7 @@ package auth
import
(
import
(
"github.com/pkg/errors"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/message"
...
@@ -10,11 +11,9 @@ import (
...
@@ -10,11 +11,9 @@ import (
"gitlab.com/elixxir/client/storage/auth"
"gitlab.com/elixxir/client/storage/auth"
"gitlab.com/elixxir/client/storage/e2e"
"gitlab.com/elixxir/client/storage/e2e"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/cyclic"
cAuth
"gitlab.com/elixxir/crypto/e2e/auth"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
cAuth
"gitlab.com/elixxir/crypto/e2e/auth"
jww
"github.com/spf13/jwalterweatherman"
"io"
"strings"
"strings"
)
)
...
@@ -23,7 +22,7 @@ type ConfirmCallback func(partner contact.Contact)
...
@@ -23,7 +22,7 @@ type ConfirmCallback func(partner contact.Contact)
func
RegisterCallbacks
(
rcb
RequestCallback
,
ccb
ConfirmCallback
,
func
RegisterCallbacks
(
rcb
RequestCallback
,
ccb
ConfirmCallback
,
sw
interfaces
.
Switchboard
,
storage
*
storage
.
Session
,
sw
interfaces
.
Switchboard
,
storage
*
storage
.
Session
,
net
interfaces
.
NetworkManager
,
rng
io
.
Reader
)
stoppable
.
Stoppable
{
net
interfaces
.
NetworkManager
)
stoppable
.
Stoppable
{
rawMessages
:=
make
(
chan
message
.
Receive
,
1000
)
rawMessages
:=
make
(
chan
message
.
Receive
,
1000
)
sw
.
RegisterChannel
(
"Auth"
,
&
id
.
ID
{},
message
.
Raw
,
rawMessages
)
sw
.
RegisterChannel
(
"Auth"
,
&
id
.
ID
{},
message
.
Raw
,
rawMessages
)
...
...
This diff is collapsed.
Click to expand it.
bindings/client.go
+
1
−
1
View file @
6eadfdef
...
@@ -16,7 +16,7 @@ import (
...
@@ -16,7 +16,7 @@ import (
"gitlab.com/elixxir/primitives/states"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"time"
"time"
jww
"github.com/spf13/jwalterweatherman"
//
jww "github.com/spf13/jwalterweatherman"
)
)
// BindingsClient wraps the api.Client, implementing additional functions
// BindingsClient wraps the api.Client, implementing additional functions
...
...
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