Skip to content
Snippets Groups Projects
Commit 6eadfdef authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

added autneticated channel APIs

parent 61a36abd
No related branches found
No related tags found
No related merge requests found
...@@ -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
......
...@@ -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
......
...@@ -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)
......
...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment