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

split the API into 2 - a cmix part and a messenger part

parent 58a0cc8c
Branches
Tags
3 merge requests!510Release,!226WIP: Api2.0,!207WIP: Client Restructure
......@@ -7,7 +7,7 @@ version:
clean:
rm -rf vendor/
go mod vendor
go mod vendor -e
update:
-GOFLAGS="" go get all
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package api
import (
"gitlab.com/elixxir/client/e2e/ratchet/partner"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/xx_network/primitives/id"
)
// RequestAuthenticatedChannel sends a request to another party to establish an
// authenticated channel
// It will not run if the network state is not healthy
// An error will be returned if a channel already exists or if a request was
// already received
// When a confirmation occurs, the channel will be created and the callback
// will be called
// Can be retried.
func (c *Client) RequestAuthenticatedChannel(recipient, me contact.Contact,
message string) (id.Round, error) {
jww.INFO.Printf("RequestAuthenticatedChannel(%s)", recipient.ID)
if !c.network.IsHealthy() {
return 0, errors.New("Cannot request authenticated channel " +
"creation when the network is not healthy")
}
return c.auth.Request(recipient, c.GetUser().GetContact().Facts)
}
// ResetSession resets an authenticate channel that already exists
func (c *Client) ResetSession(recipient, me contact.Contact,
message string) (id.Round, error) {
jww.INFO.Printf("ResetSession(%s)", recipient.ID)
if !c.network.IsHealthy() {
return 0, errors.New("Cannot request authenticated channel " +
"creation when the network is not healthy")
}
return c.auth.Reset(recipient)
}
// GetAuthRegistrar gets the object which allows the registration of auth
// callbacks
func (c *Client) GetAuthRegistrar() auth.State {
jww.INFO.Printf("GetAuthRegistrar(...)")
return c.auth
}
// GetAuthenticatedChannelRequest returns the contact received in a request if
// one exists for the given userID. Returns an error if no contact is found.
func (c *Client) GetAuthenticatedChannelRequest(partner *id.ID) (contact.Contact, error) {
jww.INFO.Printf("GetAuthenticatedChannelRequest(%s)", partner)
return c.auth.GetReceivedRequest(partner)
}
// ConfirmAuthenticatedChannel creates an authenticated channel out of a valid
// received request and sends a message to the requestor that the request has
// been confirmed
// It will not run if the network state is not healthy
// 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
// Can be retried.
func (c *Client) ConfirmAuthenticatedChannel(recipient contact.Contact) (id.Round, error) {
jww.INFO.Printf("ConfirmAuthenticatedChannel(%s)", recipient.ID)
if !c.network.IsHealthy() {
return 0, errors.New("Cannot request authenticated channel " +
"creation when the network is not healthy")
}
return c.auth.Confirm(recipient)
}
// 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 c.auth.VerifyOwnership(received, verified, c.e2e)
}
// HasAuthenticatedChannel returns true if an authenticated channel exists for
// the partner
func (c *Client) HasAuthenticatedChannel(partner *id.ID) bool {
m, err := c.e2e.GetPartner(partner)
return m != nil && err == nil
}
// GetRelationshipFingerprint returns a unique 15 character fingerprint for an
// E2E relationship. An error is returned if no relationship with the partner
// is found.
func (c *Client) GetRelationshipFingerprint(p *id.ID) (string, error) {
m, err := c.e2e.GetPartner(p)
if err != nil {
return "", errors.Errorf("could not get partner %s: %+v",
partner.ConnectionFp{}, err)
} else if m == nil {
return "", errors.Errorf("manager for partner %s is nil.",
p)
}
return m.ConnectionFingerprint().String(), nil
}
......@@ -17,11 +17,8 @@ import (
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/backup"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/receive"
"gitlab.com/elixxir/client/e2e/rekey"
"gitlab.com/elixxir/client/event"
"gitlab.com/elixxir/client/interfaces"
......@@ -52,32 +49,21 @@ type Client struct {
// appropriate
storage storage.Session
// user state object
userState *user.User
//object used for communications
//Low level comms object
comms *client.Comms
// Network parameters, note e2e params wrap CMIXParams
parameters e2e.Params
//facilitates sane communications with cMix
network cmix.Client
//object used to register and communicate with permissioning
permissioning *registration.Registration
//object containing auth interactions
auth auth.State
e2e e2e.Handler
//services system to track running threads
followerServices *services
clientErrorChannel chan interfaces.ClientError
// Event reporting in event.go
events *event.Manager
// Handles the triggering and delivery of backups
backup *backup.Backup
}
// NewClient creates client storage, generates keys, connects, and registers
......@@ -97,13 +83,12 @@ func NewClient(ndfJSON, storageDir string, password []byte,
cmixGrp, e2eGrp := decodeGroups(def)
start := netTime.Now()
protoUser := createNewUser(rngStreamGen, cmixGrp, e2eGrp)
protoUser := createNewUser(rngStreamGen)
jww.DEBUG.Printf("PortableUserInfo generation took: %s",
netTime.Now().Sub(start))
_, err = checkVersionAndSetupStorage(def, storageDir, password,
protoUser, cmixGrp, e2eGrp, rngStreamGen,
registrationCode)
protoUser, cmixGrp, e2eGrp, registrationCode)
if err != nil {
return err
}
......@@ -134,8 +119,7 @@ func NewVanityClient(ndfJSON, storageDir string, password []byte,
userIdPrefix)
_, err = checkVersionAndSetupStorage(def, storageDir, password,
protoUser, cmixGrp, e2eGrp, rngStreamGen,
registrationCode)
protoUser, cmixGrp, e2eGrp, registrationCode)
if err != nil {
return err
}
......@@ -168,11 +152,9 @@ func NewClientFromBackup(ndfJSON, storageDir string, sessionPassword,
cmixGrp, e2eGrp := decodeGroups(def)
rngStreamGen := fastRNG.NewStreamGenerator(12, 3, csprng.NewSystemRNG)
// Note we do not need registration here
storageSess, err := checkVersionAndSetupStorage(def, storageDir,
[]byte(sessionPassword), usr, cmixGrp, e2eGrp, rngStreamGen,
[]byte(sessionPassword), usr, cmixGrp, e2eGrp,
backUp.RegistrationCode)
storageSess.SetReceptionRegistrationValidationSignature(
......@@ -213,22 +195,14 @@ func OpenClient(storageDir string, password []byte,
return nil, err
}
userState, err := user.LoadUser(storageSess.GetKV())
if err != nil {
return nil, err
}
c := &Client{
storage: storageSess,
rng: rngStreamGen,
comms: nil,
network: nil,
followerServices: newServices(),
parameters: parameters.E2E,
clientErrorChannel: make(chan interfaces.ClientError, 1000),
events: event.NewEventManager(),
backup: &backup.Backup{},
userState: userState,
}
err = c.initComms()
......@@ -242,15 +216,6 @@ func OpenClient(storageDir string, password []byte,
return nil, err
}
user := c.userState.PortableUserInfo()
c.e2e, err = e2e.Load(c.storage.GetKV(), c.network,
user.ReceptionID, c.storage.GetE2EGroup(),
c.rng, c.events)
if err != nil {
return nil, err
}
return c, nil
}
......@@ -261,8 +226,6 @@ func NewProtoClient_Unsafe(ndfJSON, storageDir string, password,
protoClientJSON []byte) error {
jww.INFO.Printf("NewProtoClient_Unsafe")
rngStreamGen := fastRNG.NewStreamGenerator(12, 3, csprng.NewSystemRNG)
def, err := parseNDF(ndfJSON)
if err != nil {
return err
......@@ -279,8 +242,7 @@ func NewProtoClient_Unsafe(ndfJSON, storageDir string, password,
usr := user.NewUserFromProto(protoUser)
storageSess, err := checkVersionAndSetupStorage(def, storageDir,
password, usr, cmixGrp, e2eGrp, rngStreamGen,
protoUser.RegCode)
password, usr, cmixGrp, e2eGrp, protoUser.RegCode)
if err != nil {
return err
}
......@@ -312,9 +274,8 @@ func Login(storageDir string, password []byte,
return nil, err
}
u := c.userState.PortableUserInfo()
jww.INFO.Printf("Client Logged in: \n\tTransmissionID: %s "+
"\n\tReceptionID: %s", u.TransmissionID, u.ReceptionID)
"\n\tReceptionID: %s", c.storage.GetTransmissionID(), c.storage.GetReceptionID())
def := c.storage.GetNDF()
......@@ -350,16 +311,6 @@ func Login(storageDir string, password []byte,
return nil, err
}
// FIXME: The callbacks need to be set, so I suppose we would need to
// either set them via a special type or add them
// to the login call?
authParams := auth.GetDefaultParams()
c.auth, err = auth.NewState(c.storage.GetKV(), c.network, c.e2e, c.rng,
c.events, authParams, authCallbacks, c.backup.TriggerBackup)
if err != nil {
return nil, err
}
err = c.registerFollower()
if err != nil {
return nil, err
......@@ -405,15 +356,6 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte,
return nil, err
}
// FIXME: The callbacks need to be set, so I suppose we would need to
// either set them via a special type or add them
// to the login call?
c.auth, err = auth.NewState(c.storage.GetKV(), c.network, c.e2e, c.rng,
c.events, params.Auth, authCallbacks, c.backup.TriggerBackup)
if err != nil {
return nil, err
}
err = c.registerFollower()
if err != nil {
return nil, err
......@@ -426,7 +368,7 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte,
// JSON containing the cryptographic primitives. This is designed for
// some specific deployment procedures and is generally unsafe.
func LoginWithProtoClient(storageDir string, password []byte,
protoClientJSON []byte, newBaseNdf string, authCallbacks auth.Callbacks,
protoClientJSON []byte, newBaseNdf string,
params Params) (*Client, error) {
jww.INFO.Printf("LoginWithProtoClient()")
......@@ -461,8 +403,6 @@ func LoginWithProtoClient(storageDir string, password []byte,
// FIXME: The callbacks need to be set, so I suppose we would need to
// either set them via a special type or add them
// to the login call?
c.auth, err = auth.NewState(c.storage.GetKV(), c.network, c.e2e, c.rng,
c.events, params.Auth, authCallbacks, c.backup.TriggerBackup)
if err != nil {
return nil, err
}
......@@ -478,16 +418,13 @@ func (c *Client) initComms() error {
var err error
//get the user from session
u := c.userState
cryptoUser := u.CryptographicIdentity
privKey := cryptoUser.GetTransmissionRSA()
privKey := c.storage.GetTransmissionRSA()
pubPEM := rsa.CreatePublicKeyPem(privKey.GetPublic())
privPEM := rsa.CreatePrivateKeyPem(privKey)
//start comms
c.comms, err = client.NewClientComms(cryptoUser.GetTransmissionID(),
pubPEM, privPEM, cryptoUser.GetTransmissionSalt())
c.comms, err = client.NewClientComms(c.storage.GetTransmissionID(),
pubPEM, privPEM, c.storage.GetTransmissionSalt())
if err != nil {
return errors.WithMessage(err, "failed to load client")
}
......@@ -598,9 +535,8 @@ func (c *Client) GetErrorsChannel() <-chan interfaces.ClientError {
// - Auth Callback (/auth/callback.go)
// Handles both auth confirm and requests
func (c *Client) StartNetworkFollower(timeout time.Duration) error {
u := c.GetUser()
jww.INFO.Printf("StartNetworkFollower() \n\tTransmissionID: %s "+
"\n\tReceptionID: %s", u.TransmissionID, u.ReceptionID)
"\n\tReceptionID: %s", c.storage.GetTransmissionID(), c.storage.GetReceptionID())
return c.followerServices.start(timeout)
}
......@@ -640,39 +576,6 @@ func (c *Client) GetRoundEvents() interfaces.RoundEvents {
return c.network.GetInstance().GetRoundEvents()
}
// RegisterListener registers a callback struct for message receive
// events.
func (c *Client) RegisterListener(senderID *id.ID,
messageType catalog.MessageType,
newListener receive.Listener) receive.ListenerID {
jww.INFO.Printf("GetRoundEvents()")
jww.WARN.Printf("GetRoundEvents does not handle Client Errors " +
"edge case!")
return c.e2e.RegisterListener(senderID, messageType, newListener)
}
// RegisterListenerFunc registers a callback func for message receive
// events.
func (c *Client) RegisterListenerFunc(name string, senderID *id.ID,
messageType catalog.MessageType,
newListener receive.ListenerFunc) receive.ListenerID {
jww.INFO.Printf("GetRoundEvents()")
jww.WARN.Printf("GetRoundEvents does not handle Client Errors " +
"edge case!")
return c.e2e.RegisterFunc(name, senderID, messageType, newListener)
}
// RegisterListenerChannel registers a channel for message receive
// events.
func (c *Client) RegisterListenerChannel(name string, senderID *id.ID,
messageType catalog.MessageType,
newListener chan receive.Message) receive.ListenerID {
jww.INFO.Printf("GetRoundEvents()")
jww.WARN.Printf("GetRoundEvents does not handle Client Errors " +
"edge case!")
return c.e2e.RegisterChannel(name, senderID, messageType, newListener)
}
// AddService adds a service ot be controlled by the client thread control,
// these will be started and stopped with the network follower
func (c *Client) AddService(sp Service) error {
......@@ -683,11 +586,7 @@ func (c *Client) AddService(sp Service) error {
// can be serialized into a byte stream for out-of-band sharing.
func (c *Client) GetUser() user.Info {
jww.INFO.Printf("GetUser()")
cMixUser := c.userState.PortableUserInfo()
// Add e2e dh keys
e2e := c.GetE2EHandler()
cMixUser.E2eDhPrivateKey = e2e.GetHistoricalDHPrivkey().DeepCopy()
cMixUser.E2eDhPublicKey = e2e.GetHistoricalDHPubkey().DeepCopy()
cMixUser := c.storage.PortableUserInfo()
return cMixUser
}
......@@ -706,41 +605,23 @@ func (c *Client) GetStorage() storage.Session {
return c.storage
}
// GetNetworkInterface returns the client Network Interface
func (c *Client) GetNetworkInterface() cmix.Client {
// GetCmix returns the client Network Interface
func (c *Client) GetCmix() cmix.Client {
return c.network
}
// GetE2EHandler returns the e2e handler
func (c *Client) GetE2EHandler() e2e.Handler {
return c.e2e
}
// GetEventReporter returns the event reporter
func (c *Client) GetEventReporter() event.Reporter {
return c.events
}
// GetBackup returns a pointer to the backup container so that the backup can be
// set and triggered.
func (c *Client) GetBackup() *backup.Backup {
return c.backup
}
func (c *Client) InitializeBackup(backupPass string,
updateBackupCb backup.UpdateBackupFn) (*backup.Backup, error) {
container := &backup.Container{}
return backup.InitializeBackup(backupPass, updateBackupCb, container,
c.e2e, c.storage, nil, c.storage.GetKV(), c.rng)
}
// GetNodeRegistrationStatus gets the current state of nodes registration. It
// returns the total number of nodes in the NDF and the number of those which
// are currently registers with. An error is returned if the network is not
// healthy.
func (c *Client) GetNodeRegistrationStatus() (int, int, error) {
// Return an error if the network is not healthy
if !c.GetNetworkInterface().IsHealthy() {
if !c.GetCmix().IsHealthy() {
return 0, 0, errors.New("Cannot get number of nodes " +
"registrations when network is not healthy")
}
......@@ -768,59 +649,6 @@ func (c *Client) GetNodeRegistrationStatus() (int, int, error) {
return numRegistered, len(nodes) - numStale, nil
}
// DeleteRequest will delete a request, agnostic of request type
// for the given partner ID. If no request exists for this
// partner ID an error will be returned.
func (c *Client) DeleteRequest(partnerId *id.ID) error {
jww.DEBUG.Printf("Deleting request for partner ID: %s", partnerId)
return c.auth.DeleteRequest(partnerId)
}
// DeleteAllRequests clears all requests from client's auth storage.
func (c *Client) DeleteAllRequests() error {
jww.DEBUG.Printf("Deleting all requests")
return c.auth.DeleteAllRequests()
}
// DeleteSentRequests clears sent requests from client's auth storage.
func (c *Client) DeleteSentRequests() error {
jww.DEBUG.Printf("Deleting all sent requests")
return c.auth.DeleteSentRequests()
}
// DeleteReceiveRequests clears receive requests from client's auth storage.
func (c *Client) DeleteReceiveRequests() error {
jww.DEBUG.Printf("Deleting all received requests")
return c.auth.DeleteReceiveRequests()
}
// DeleteContact is a function which removes a partner from Client's storage
func (c *Client) DeleteContact(partnerId *id.ID) error {
jww.DEBUG.Printf("Deleting contact with ID %s", partnerId)
_, err := c.e2e.GetPartner(partnerId)
if err != nil {
return errors.WithMessagef(err, "Could not delete %s because "+
"they could not be found", partnerId)
}
if err = c.e2e.DeletePartner(partnerId); err != nil {
return err
}
c.backup.TriggerBackup("contact deleted")
// FIXME: Do we need this?
// c.e2e.Conversations().Delete(partnerId)
// call delete requests to make sure nothing is lingering.
// this is for saftey to ensure the contact can be readded
// in the future
_ = c.auth.DeleteRequest(partnerId)
return nil
}
// GetPreferredBins returns the geographic bin or bins that the provided two
// character country code is a part of.
func (c *Client) GetPreferredBins(countryCode string) ([]string, error) {
......@@ -898,10 +726,9 @@ func decodeGroups(ndf *ndf.NetworkDefinition) (cmixGrp, e2eGrp *cyclic.Group) {
// NewPrecannedClient and NewVanityClient it checks client version and
// creates a new storage for user data
func checkVersionAndSetupStorage(def *ndf.NetworkDefinition,
storageDir string, password []byte,
protoUser user.Info,
cmixGrp, e2eGrp *cyclic.Group, rngStreamGen *fastRNG.StreamGenerator,
registrationCode string) (storage.Session, error) {
storageDir string, password []byte, protoUser user.Info,
cmixGrp, e2eGrp *cyclic.Group, registrationCode string) (
storage.Session, error) {
// get current client version
currentVersion, err := version.ParseVersion(SEMVER)
if err != nil {
......
......@@ -5,7 +5,7 @@
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
package backup
package messenger
import "sync"
......
package messenger
import (
"encoding/binary"
"encoding/json"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/rekey"
"gitlab.com/elixxir/client/storage/user"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/xx_network/primitives/id"
)
type Client struct {
*api.Client
auth auth.State
e2e e2e.Handler
backup *Container
}
func Login(client *api.Client, callbacks auth.Callbacks) (m *Client, err error) {
m = &Client{
Client: client,
backup: &Container{},
}
m.e2e, err = loadOrInitE2e(client)
if err != nil {
return nil, err
}
m.auth, err = auth.NewState(client.GetStorage().GetKV(), client.GetCmix(),
m.e2e, client.GetRng(), client.GetEventReporter(),
auth.GetDefaultParams(), callbacks, m.backup.TriggerBackup)
if err != nil {
return nil, err
}
return m, err
}
// loadOrInitE2e loads the e2e handler or makes a new one, generating a new
// e2e private key. It attempts to load via a legacy construction, then tries
// to load the modern one, creating a new modern ID if neither can be found
func loadOrInitE2e(client *api.Client) (e2e.Handler, error) {
usr := client.GetUser()
e2eGrp := client.GetStorage().GetE2EGroup()
kv := client.GetStorage().GetKV()
//try to load a legacy e2e hander
e2eHandler, err := e2e.LoadLegacy(kv,
client.GetCmix(), usr.ReceptionID, e2eGrp, client.GetRng(),
client.GetEventReporter(), rekey.GetDefaultParams())
if err != nil {
//if no legacy e2e handler exists, try to load a new one
e2eHandler, err = e2e.Load(kv,
client.GetCmix(), usr.ReceptionID, e2eGrp, client.GetRng(),
client.GetEventReporter())
//if no new e2e handler exists, initilize an e2e user
if err != nil {
jww.WARN.Printf("Failed to load e2e instance for %s, "+
"creating a new one", usr.ReceptionID)
//generate the key
var privkey *cyclic.Int
if client.GetStorage().IsPrecanned() {
precannedID := binary.BigEndian.Uint64(client.GetStorage().GetReceptionID()[:])
privkey = generatePrecanDHKeypair(uint(precannedID), client.GetStorage().GetE2EGroup())
} else {
rngStream := client.GetRng().GetStream()
privkey = diffieHellman.GeneratePrivateKey(len(e2eGrp.GetPBytes()),
e2eGrp, rngStream)
rngStream.Close()
}
//initialize the e2e storage
err = e2e.Init(kv, usr.ReceptionID, privkey, e2eGrp,
rekey.GetDefaultParams())
if err != nil {
return nil, err
}
//load the new e2e storage
e2eHandler, err = e2e.Load(kv,
client.GetCmix(), usr.ReceptionID, e2eGrp, client.GetRng(),
client.GetEventReporter())
if err != nil {
return nil, errors.WithMessage(err, "Failed to load a "+
"newly created e2e store")
}
} else {
jww.INFO.Printf("Loaded a modern e2e instance for %s",
usr.ReceptionID)
}
} else {
jww.INFO.Printf("Loaded a legacy e2e instance for %s",
usr.ReceptionID)
}
return e2eHandler, nil
}
// GetUser replaces api.Client's GetUser with one which includes the e2e dh
// private keys
func (m *Client) GetUser() user.Info {
u := m.Client.GetUser()
u.E2eDhPrivateKey = m.e2e.GetHistoricalDHPrivkey()
u.E2eDhPublicKey = m.e2e.GetHistoricalDHPrivkey()
return u
}
// ConstructProtoUserFile is a helper function which is used for proto
// client testing. This is used for development testing.
func (m *Client) ConstructProtoUserFile() ([]byte, error) {
//load the registration code
regCode, err := m.GetStorage().GetRegCode()
if err != nil {
return nil, errors.WithMessage(err, "failed to register with "+
"permissioning")
}
Usr := user.Proto{
TransmissionID: m.GetUser().TransmissionID,
TransmissionSalt: m.GetUser().TransmissionSalt,
TransmissionRSA: m.GetUser().TransmissionRSA,
ReceptionID: m.GetUser().ReceptionID,
ReceptionSalt: m.GetUser().ReceptionSalt,
ReceptionRSA: m.GetUser().ReceptionRSA,
Precanned: m.GetUser().Precanned,
RegistrationTimestamp: m.GetUser().RegistrationTimestamp,
RegCode: regCode,
TransmissionRegValidationSig: m.GetStorage().GetTransmissionRegistrationValidationSignature(),
ReceptionRegValidationSig: m.GetStorage().GetReceptionRegistrationValidationSignature(),
E2eDhPrivateKey: m.e2e.GetHistoricalDHPrivkey(),
E2eDhPublicKey: m.e2e.GetHistoricalDHPubkey(),
}
jsonBytes, err := json.Marshal(Usr)
if err != nil {
return nil, errors.WithMessage(err, "failed to register with "+
"permissioning")
}
return jsonBytes, nil
}
func (m *Client) GetAuth() auth.State {
return m.auth
}
func (m *Client) GetE2E() e2e.Handler {
return m.e2e
}
func (m *Client) GetBackupContainer() *Container {
return m.backup
}
// DeleteContact is a function which removes a partner from Client's storage
func (m *Client) DeleteContact(partnerId *id.ID) error {
jww.DEBUG.Printf("Deleting contact with ID %s", partnerId)
_, err := m.e2e.GetPartner(partnerId)
if err != nil {
return errors.WithMessagef(err, "Could not delete %s because "+
"they could not be found", partnerId)
}
if err = m.e2e.DeletePartner(partnerId); err != nil {
return err
}
m.backup.TriggerBackup("contact deleted")
// FIXME: Do we need this?
// c.e2e.Conversations().Delete(partnerId)
// call delete requests to make sure nothing is lingering.
// this is for saftey to ensure the contact can be readded
// in the future
_ = m.auth.DeleteRequest(partnerId)
return nil
}
......@@ -5,7 +5,7 @@
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package api
package messenger
import (
"github.com/pkg/errors"
......@@ -23,33 +23,33 @@ import (
// especially as these rely on third parties (i.e., Firebase *cough*
// *cough* google's palantir *cough*) that may represent a security
// risk to the user.
func (c *Client) RegisterForNotifications(token string) error {
func (m *Client) RegisterForNotifications(token string) error {
jww.INFO.Printf("RegisterForNotifications(%s)", token)
// Pull the host from the manage
notificationBotHost, ok := c.comms.GetHost(&id.NotificationBot)
notificationBotHost, ok := m.GetComms().GetHost(&id.NotificationBot)
if !ok {
return errors.New("RegisterForNotifications: Failed to retrieve host for notification bot")
}
intermediaryReceptionID, sig, err := c.getIidAndSig()
intermediaryReceptionID, sig, err := m.getIidAndSig()
if err != nil {
return err
}
privKey := c.userState.CryptographicIdentity.GetTransmissionRSA()
privKey := m.GetStorage().GetTransmissionRSA()
pubPEM := rsa.CreatePublicKeyPem(privKey.GetPublic())
regSig := c.userState.GetTransmissionRegistrationValidationSignature()
regTS := c.GetUser().RegistrationTimestamp
regSig := m.GetStorage().GetTransmissionRegistrationValidationSignature()
regTS := m.GetStorage().GetRegistrationTimestamp()
// Send the register message
_, err = c.comms.RegisterForNotifications(notificationBotHost,
_, err = m.GetComms().RegisterForNotifications(notificationBotHost,
&mixmessages.NotificationRegisterRequest{
Token: token,
IntermediaryId: intermediaryReceptionID,
TransmissionRsa: pubPEM,
TransmissionSalt: c.GetUser().TransmissionSalt,
TransmissionSalt: m.GetStorage().GetTransmissionSalt(),
TransmissionRsaSig: regSig,
IIDTransmissionRsaSig: sig,
RegistrationTimestamp: regTS,
RegistrationTimestamp: regTS.UnixNano(),
})
if err != nil {
err := errors.Errorf("RegisterForNotifications: Unable to "+
......@@ -61,19 +61,19 @@ func (c *Client) RegisterForNotifications(token string) error {
}
// UnregisterForNotifications turns of notifications for this client
func (c *Client) UnregisterForNotifications() error {
func (m *Client) UnregisterForNotifications() error {
jww.INFO.Printf("UnregisterForNotifications()")
// Pull the host from the manage
notificationBotHost, ok := c.comms.GetHost(&id.NotificationBot)
notificationBotHost, ok := m.GetComms().GetHost(&id.NotificationBot)
if !ok {
return errors.New("Failed to retrieve host for notification bot")
}
intermediaryReceptionID, sig, err := c.getIidAndSig()
intermediaryReceptionID, sig, err := m.getIidAndSig()
if err != nil {
return err
}
// Send the unregister message
_, err = c.comms.UnregisterForNotifications(notificationBotHost, &mixmessages.NotificationUnregisterRequest{
_, err = m.GetComms().UnregisterForNotifications(notificationBotHost, &mixmessages.NotificationUnregisterRequest{
IntermediaryId: intermediaryReceptionID,
IIDTransmissionRsaSig: sig,
})
......@@ -86,8 +86,8 @@ func (c *Client) UnregisterForNotifications() error {
return nil
}
func (c *Client) getIidAndSig() ([]byte, []byte, error) {
intermediaryReceptionID, err := ephemeral.GetIntermediaryId(c.GetUser().ReceptionID)
func (m *Client) getIidAndSig() ([]byte, []byte, error) {
intermediaryReceptionID, err := ephemeral.GetIntermediaryId(m.GetStorage().GetReceptionID())
if err != nil {
return nil, nil, errors.WithMessage(err, "RegisterForNotifications: Failed to form intermediary ID")
}
......@@ -100,10 +100,9 @@ func (c *Client) getIidAndSig() ([]byte, []byte, error) {
return nil, nil, errors.WithMessage(err, "RegisterForNotifications: Failed to write intermediary ID to hash")
}
stream := c.rng.GetStream()
c.GetUser()
stream := m.GetRng().GetStream()
sig, err := rsa.Sign(stream,
c.userState.GetTransmissionRSA(),
m.GetStorage().GetTransmissionRSA(),
hash.CMixHash, h.Sum(nil), nil)
if err != nil {
return nil, nil, errors.WithMessage(err, "RegisterForNotifications: Failed to sign intermediary ID")
......
package messenger
import (
"encoding/binary"
"github.com/cloudflare/circl/dh/sidh"
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/e2e/ratchet/partner/session"
util "gitlab.com/elixxir/client/storage/utility"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/primitives/fact"
"math/rand"
)
func generatePrecanDHKeypair(precannedID uint, e2eGrp *cyclic.Group) *cyclic.Int {
// DH Keygen
prng := rand.New(rand.NewSource(int64(precannedID)))
prime := e2eGrp.GetPBytes()
keyLen := len(prime)
priv := diffieHellman.GeneratePrivateKey(keyLen, e2eGrp, prng)
return priv
}
// Create an insecure e2e relationship with a precanned user
func (m *Client) MakePrecannedAuthenticatedChannel(precannedID uint) (
contact.Contact, error) {
precan := m.MakePrecannedContact(precannedID)
myID := binary.BigEndian.Uint64(m.GetStorage().GetReceptionID()[:])
// Pick a variant based on if their ID is bigger than mine.
myVariant := sidh.KeyVariantSidhA
theirVariant := sidh.KeyVariant(sidh.KeyVariantSidhB)
if myID > uint64(precannedID) {
myVariant = sidh.KeyVariantSidhB
theirVariant = sidh.KeyVariantSidhA
}
prng1 := rand.New(rand.NewSource(int64(precannedID)))
theirSIDHPrivKey := util.NewSIDHPrivateKey(theirVariant)
theirSIDHPubKey := util.NewSIDHPublicKey(theirVariant)
theirSIDHPrivKey.Generate(prng1)
theirSIDHPrivKey.GeneratePublicKey(theirSIDHPubKey)
prng2 := rand.New(rand.NewSource(int64(myID)))
mySIDHPrivKey := util.NewSIDHPrivateKey(myVariant)
mySIDHPubKey := util.NewSIDHPublicKey(myVariant)
mySIDHPrivKey.Generate(prng2)
mySIDHPrivKey.GeneratePublicKey(mySIDHPubKey)
// add the precanned user as a e2e contact
// FIXME: these params need to be threaded through...
sesParam := session.GetDefaultParams()
_, err := m.e2e.AddPartner(precan.ID, precan.DhPubKey,
m.e2e.GetHistoricalDHPrivkey(), theirSIDHPubKey,
mySIDHPrivKey, sesParam, sesParam)
// check garbled messages in case any messages arrived before creating
// the channel
m.GetCmix().CheckInProgressMessages()
return precan, err
}
// Create an insecure e2e contact object for a precanned user
func (m *Client) MakePrecannedContact(precannedID uint) contact.Contact {
e2eGrp := m.GetStorage().GetE2EGroup()
rng := m.GetRng().GetStream()
precanned := api.CreatePrecannedUser(precannedID, rng)
rng.Close()
precanned.E2eDhPrivateKey = generatePrecanDHKeypair(precannedID,
m.GetStorage().GetE2EGroup())
// compute their public e2e key
partnerPubKey := e2eGrp.ExpG(precanned.E2eDhPrivateKey,
e2eGrp.NewInt(1))
return contact.Contact{
ID: precanned.ReceptionID,
DhPubKey: partnerPubKey,
OwnershipProof: nil,
Facts: make([]fact.Fact, 0),
}
}
......@@ -6,7 +6,7 @@
// Provides various utility functions for access over the bindings
package api
package messenger
import (
"bytes"
......
......@@ -8,29 +8,18 @@
package api
import (
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/ratchet/partner/session"
"gitlab.com/elixxir/client/e2e/rekey"
)
type Params struct {
E2E e2e.Params
CMix cmix.Params
Network cmix.CMIXParams
Session session.Params
Auth auth.Param
Rekey rekey.Params
}
func GetDefaultParams() Params {
return Params{
E2E: e2e.GetDefaultParams(),
CMix: cmix.GetDefaultParams(),
Network: cmix.GetDefaultCMIXParams(),
Session: session.GetDefaultParams(),
Auth: auth.GetDefaultParams(),
Rekey: rekey.GetDefaultParams(),
}
}
......@@ -9,7 +9,6 @@ package api
import (
"encoding/json"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/storage/user"
......@@ -17,10 +16,9 @@ import (
// Returns an error if registration fails.
func (c *Client) registerWithPermissioning() error {
userData := c.userState.CryptographicIdentity
//get the users public key
transmissionPubKey := userData.GetTransmissionRSA().GetPublic()
receptionPubKey := userData.GetReceptionRSA().GetPublic()
transmissionPubKey := c.storage.GetTransmissionRSA().GetPublic()
receptionPubKey := c.storage.GetReceptionRSA().GetPublic()
//load the registration code
regCode, err := c.storage.GetRegCode()
......@@ -77,8 +75,8 @@ func (c *Client) ConstructProtoUserFile() ([]byte, error) {
RegCode: regCode,
TransmissionRegValidationSig: c.storage.GetTransmissionRegistrationValidationSignature(),
ReceptionRegValidationSig: c.storage.GetReceptionRegistrationValidationSignature(),
E2eDhPrivateKey: c.e2e.GetHistoricalDHPrivkey(),
E2eDhPublicKey: c.e2e.GetHistoricalDHPubkey(),
E2eDhPrivateKey: nil,
E2eDhPublicKey: nil,
}
jsonBytes, err := json.Marshal(Usr)
......
......@@ -9,32 +9,17 @@ package api
import (
"encoding/binary"
"gitlab.com/elixxir/crypto/diffieHellman"
"math/rand"
"github.com/cloudflare/circl/dh/sidh"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/e2e/ratchet/partner/session"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/storage/user"
util "gitlab.com/elixxir/client/storage/utility"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
)
// creates a precanned user
func createPrecannedUser(precannedID uint, rng csprng.Source, cmix,
e2e *cyclic.Group) user.Info {
// DH Keygen
prng := rand.New(rand.NewSource(int64(precannedID)))
prime := e2e.GetPBytes()
keyLen := len(prime)
e2eKey := diffieHellman.GeneratePrivateKey(keyLen, e2e, prng)
// CreatePrecannedUser creates a precanned user
func CreatePrecannedUser(precannedID uint, rng csprng.Source) user.Info {
// Salt, UID, etc gen
salt := make([]byte, SaltSize)
......@@ -55,8 +40,8 @@ func createPrecannedUser(precannedID uint, rng csprng.Source, cmix,
ReceptionID: &userID,
ReceptionSalt: salt,
Precanned: true,
E2eDhPrivateKey: e2eKey,
E2eDhPublicKey: diffieHellman.GeneratePublicKey(e2eKey, e2e),
E2eDhPrivateKey: nil,
E2eDhPublicKey: nil,
TransmissionRSA: rsaKey,
ReceptionRSA: rsaKey,
}
......@@ -80,11 +65,10 @@ func NewPrecannedClient(precannedID uint, defJSON, storageDir string,
}
cmixGrp, e2eGrp := decodeGroups(def)
protoUser := createPrecannedUser(precannedID, rngStream,
cmixGrp, e2eGrp)
protoUser := CreatePrecannedUser(precannedID, rngStream)
store, err := checkVersionAndSetupStorage(def, storageDir, password,
protoUser, cmixGrp, e2eGrp, rngStreamGen, "")
protoUser, cmixGrp, e2eGrp, "")
if err != nil {
return err
}
......@@ -98,63 +82,3 @@ func NewPrecannedClient(precannedID uint, defJSON, storageDir string,
return nil
}
\ No newline at end of file
// Create an insecure e2e relationship with a precanned user
func (c *Client) MakePrecannedAuthenticatedChannel(precannedID uint) (
contact.Contact, error) {
precan := c.MakePrecannedContact(precannedID)
myID := binary.BigEndian.Uint64(c.GetUser().GetContact().ID[:])
// Pick a variant based on if their ID is bigger than mine.
myVariant := sidh.KeyVariantSidhA
theirVariant := sidh.KeyVariant(sidh.KeyVariantSidhB)
if myID > uint64(precannedID) {
myVariant = sidh.KeyVariantSidhB
theirVariant = sidh.KeyVariantSidhA
}
prng1 := rand.New(rand.NewSource(int64(precannedID)))
theirSIDHPrivKey := util.NewSIDHPrivateKey(theirVariant)
theirSIDHPubKey := util.NewSIDHPublicKey(theirVariant)
theirSIDHPrivKey.Generate(prng1)
theirSIDHPrivKey.GeneratePublicKey(theirSIDHPubKey)
prng2 := rand.New(rand.NewSource(int64(myID)))
mySIDHPrivKey := util.NewSIDHPrivateKey(myVariant)
mySIDHPubKey := util.NewSIDHPublicKey(myVariant)
mySIDHPrivKey.Generate(prng2)
mySIDHPrivKey.GeneratePublicKey(mySIDHPubKey)
// add the precanned user as a e2e contact
// FIXME: these params need to be threaded through...
sesParam := session.GetDefaultParams()
_, err := c.e2e.AddPartner(precan.ID, precan.DhPubKey,
c.e2e.GetHistoricalDHPrivkey(), theirSIDHPubKey,
mySIDHPrivKey, sesParam, sesParam)
// check garbled messages in case any messages arrived before creating
// the channel
c.network.CheckInProgressMessages()
return precan, err
}
// Create an insecure e2e contact object for a precanned user
func (c *Client) MakePrecannedContact(precannedID uint) contact.Contact {
e2eGrp := c.storage.GetE2EGroup()
precanned := createPrecannedUser(precannedID, c.rng.GetStream(),
c.storage.GetCmixGroup(), e2eGrp)
// compute their public e2e key
partnerPubKey := e2eGrp.ExpG(precanned.E2eDhPrivateKey,
e2eGrp.NewInt(1))
return contact.Contact{
ID: precanned.ReceptionID,
DhPubKey: partnerPubKey,
OwnershipProof: nil,
Facts: make([]fact.Fact, 0),
}
}
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package api
import (
"time"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/e2e"
e2eCrypto "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
)
//This holds all functions to send messages over the network
// SendE2E sends an end-to-end payload to the provided recipient with
// the provided msgType. Returns the list of rounds in which parts of
// the message were sent or an error if it fails.
func (c *Client) SendE2E(mt catalog.MessageType, recipient *id.ID,
payload []byte, param e2e.Params) ([]id.Round,
e2eCrypto.MessageID, time.Time, error) {
jww.INFO.Printf("SendE2E(%s, %d. %v)", recipient,
mt, payload)
return c.e2e.SendE2E(mt, recipient, payload, param)
}
// SendUnsafe sends an unencrypted payload to the provided recipient
// with the provided msgType. Returns the list of rounds in which parts
// of the message were sent or an error if it fails.
// NOTE: Do not use this function unless you know what you are doing.
// This function always produces an error message in client logging.
func (c *Client) SendUnsafe(mt catalog.MessageType, recipient *id.ID,
payload []byte, param e2e.Params) ([]id.Round, time.Time,
error) {
jww.INFO.Printf("SendUnsafe(%s, %d. %v)", recipient,
mt, payload)
return c.e2e.SendUnsafe(mt, recipient, payload, param)
}
// SendCMIX sends a "raw" CMIX message payload to the provided
// recipient. Note that both SendE2E and SendUnsafe call SendCMIX.
// Returns the round ID of the round the payload was sent or an error
// if it fails.
func (c *Client) SendCMIX(msg format.Message, recipientID *id.ID,
param cmix.CMIXParams) (id.Round, ephemeral.Id, error) {
jww.INFO.Printf("Send(%s)", string(msg.GetContents()))
return c.network.Send(recipientID, msg.GetKeyFP(),
message.GetDefaultService(recipientID),
msg.GetContents(), msg.GetMac(), param)
}
// SendManyCMIX sends many "raw" CMIX message payloads to each of the
// provided recipients. Used for group chat functionality. Returns the
// round ID of the round the payload was sent or an error if it fails.
func (c *Client) SendManyCMIX(messages []cmix.TargetedCmixMessage,
params cmix.CMIXParams) (id.Round, []ephemeral.Id, error) {
return c.network.SendMany(messages, params)
}
// NewCMIXMessage Creates a new cMix message with the right properties
// for the current cMix network.
// FIXME: this is weird and shouldn't be necessary, but it is.
func (c *Client) NewCMIXMessage(contents []byte) (format.Message, error) {
primeSize := len(c.storage.GetCmixGroup().GetPBytes())
msg := format.NewMessage(primeSize)
if len(contents) > msg.ContentsSize() {
return format.Message{}, errors.New("Contents to long for cmix")
}
msg.SetContents(contents)
return msg, nil
}
......@@ -30,15 +30,13 @@ const (
)
// createNewUser generates an identity for cMix
func createNewUser(rng *fastRNG.StreamGenerator, cmix,
e2e *cyclic.Group) user.Info {
func createNewUser(rng *fastRNG.StreamGenerator) user.Info {
// CMIX Keygen
var transmissionRsaKey, receptionRsaKey *rsa.PrivateKey
var e2eKey *cyclic.Int
var transmissionSalt, receptionSalt []byte
transmissionSalt, receptionSalt, e2eKey,
transmissionRsaKey, receptionRsaKey = createKeys(rng, e2e)
transmissionSalt, receptionSalt,
transmissionRsaKey, receptionRsaKey = createKeys(rng)
// Salt, UID, etc gen
stream := rng.GetStream()
......@@ -86,30 +84,17 @@ func createNewUser(rng *fastRNG.StreamGenerator, cmix,
ReceptionSalt: receptionSalt,
ReceptionRSA: receptionRsaKey,
Precanned: false,
E2eDhPrivateKey: e2eKey,
E2eDhPublicKey: diffieHellman.GeneratePublicKey(e2eKey, e2e),
E2eDhPrivateKey: nil,
E2eDhPublicKey: nil,
}
}
func createKeys(rng *fastRNG.StreamGenerator,
e2e *cyclic.Group) (
transmissionSalt, receptionSalt []byte, e2eKey *cyclic.Int,
func createKeys(rng *fastRNG.StreamGenerator) (
transmissionSalt, receptionSalt []byte,
transmissionRsaKey, receptionRsaKey *rsa.PrivateKey) {
wg := sync.WaitGroup{}
wg.Add(3)
go func() {
defer wg.Done()
var err error
rngStream := rng.GetStream()
e2eKey = diffieHellman.GeneratePrivateKey(len(e2e.GetPBytes()), e2e,
rngStream)
rngStream.Close()
if err != nil {
jww.FATAL.Panicf(err.Error())
}
}()
wg.Add(1)
// RSA Keygen (4096 bit defaults)
go func() {
......
......@@ -7,6 +7,7 @@
package api
import (
"gitlab.com/xx_network/primitives/ndf"
"time"
"gitlab.com/elixxir/client/cmix"
......@@ -92,6 +93,9 @@ func (d *dummyEventMgr) EventService() (stoppable.Stoppable, error) {
}
/* Below methods built for interface adherence */
func (t *testNetworkManagerGeneric) Connect(ndf *ndf.NetworkDefinition) error {
return nil
}
func (t *testNetworkManagerGeneric) Follow(report cmix.ClientErrorReport) (stoppable.Stoppable, error) {
return nil, nil
}
......
This diff is collapsed.
......@@ -8,6 +8,7 @@
package backup
import (
"gitlab.com/elixxir/client/api/messenger"
"sync"
"time"
......@@ -43,7 +44,7 @@ type Backup struct {
// Callback that is called with the encrypted backup when triggered
updateBackupCb UpdateBackupFn
container *Container
container *messenger.Container
jsonParams string
......@@ -93,7 +94,7 @@ type UpdateBackupFn func(encryptedBackup []byte)
// Call this to turn on backups for the first time or to replace the user's
// password.
func InitializeBackup(password string, updateBackupCb UpdateBackupFn,
container *Container, e2e E2e, session Session, ud UserDiscovery,
container *messenger.Container, e2e E2e, session Session, ud UserDiscovery,
kv *versioned.KV, rng *fastRNG.StreamGenerator) (*Backup, error) {
b := &Backup{
updateBackupCb: updateBackupCb,
......@@ -143,7 +144,7 @@ func InitializeBackup(password string, updateBackupCb UpdateBackupFn,
// ResumeBackup resumes a backup by restoring the Backup object and registering
// a new callback. Call this to resume backups that have already been
// initialized. Returns an error if backups have not already been initialized.
func ResumeBackup(updateBackupCb UpdateBackupFn, container *Container,
func ResumeBackup(updateBackupCb UpdateBackupFn, container *messenger.Container,
e2e E2e, session Session, ud UserDiscovery, kv *versioned.KV,
rng *fastRNG.StreamGenerator) (*Backup, error) {
_, err := loadPassword(kv)
......
......@@ -8,16 +8,18 @@
package bindings
import "gitlab.com/elixxir/client/api"
import (
"gitlab.com/elixxir/client/api/messenger"
)
// CompressJpeg takes a JPEG image in byte format
// and compresses it based on desired output size
func CompressJpeg(imgBytes []byte) ([]byte, error) {
return api.CompressJpeg(imgBytes)
return messenger.CompressJpeg(imgBytes)
}
// CompressJpegForPreview takes a JPEG image in byte format
// and compresses it based on desired output size
func CompressJpegForPreview(imgBytes []byte) ([]byte, error) {
return api.CompressJpegForPreview(imgBytes)
return messenger.CompressJpegForPreview(imgBytes)
}
......@@ -10,9 +10,9 @@ package cmd
import (
"fmt"
"gitlab.com/elixxir/client/api/messenger"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/cmix/identity/receptionID"
"gitlab.com/elixxir/client/cmix/rounds"
......@@ -25,10 +25,10 @@ import (
type authCallbacks struct {
autoConfirm bool
confCh chan *id.ID
client *api.Client
client *messenger.Client
}
func makeAuthCallbacks(client *api.Client, autoConfirm bool) *authCallbacks {
func makeAuthCallbacks(client *messenger.Client, autoConfirm bool) *authCallbacks {
return &authCallbacks{
autoConfirm: autoConfirm,
confCh: make(chan *id.ID, 10),
......@@ -46,7 +46,7 @@ func (a *authCallbacks) Request(requestor contact.Contact,
if a.autoConfirm {
jww.INFO.Printf("Channel Request: %s",
requestor.ID)
_, err := a.client.ConfirmAuthenticatedChannel(requestor)
_, err := a.client.GetAuth().Confirm(requestor)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
......@@ -71,9 +71,9 @@ func (a *authCallbacks) Reset(requestor contact.Contact,
fmt.Printf(msg)
}
func registerMessageListener(client *api.Client) chan receive.Message {
func registerMessageListener(client *messenger.Client) chan receive.Message {
recvCh := make(chan receive.Message, 10000)
listenerID := client.RegisterListenerChannel("DefaultCLIReceiver",
listenerID := client.GetE2E().RegisterChannel("DefaultCLIReceiver",
receive.AnyUser(), catalog.NoType, recvCh)
jww.INFO.Printf("Message ListenerID: %v", listenerID)
return recvCh
......
......@@ -9,13 +9,13 @@ package cmd
import (
"fmt"
"gitlab.com/elixxir/client/api/messenger"
"io/ioutil"
"time"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"gitlab.com/elixxir/client/api"
ft "gitlab.com/elixxir/client/fileTransfer"
"gitlab.com/elixxir/crypto/contact"
ftCrypto "gitlab.com/elixxir/crypto/fileTransfer"
......@@ -54,7 +54,7 @@ var ftCmd = &cobra.Command{
// Wait until connected or crash on timeout
connected := make(chan bool, 10)
client.GetNetworkInterface().AddHealthCallback(
client.GetCmix().AddHealthCallback(
func(isconnected bool) {
connected <- isconnected
})
......@@ -131,7 +131,7 @@ type receivedFtResults struct {
// initFileTransferManager creates a new file transfer manager with a new
// reception callback. Returns the file transfer manager and the channel that
// will be triggered when the callback is called.
func initFileTransferManager(client *api.Client, maxThroughput int) (
func initFileTransferManager(client *messenger.Client, maxThroughput int) (
ft.FileTransfer, chan receivedFtResults) {
// Create interfaces.ReceiveCallback that returns the results on a channel
......
......@@ -12,13 +12,13 @@ package cmd
import (
"bufio"
"fmt"
"gitlab.com/elixxir/client/api/messenger"
"os"
"time"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/groupChat"
"gitlab.com/elixxir/client/groupChat/groupStore"
"gitlab.com/xx_network/primitives/id"
......@@ -47,7 +47,7 @@ var groupCmd = &cobra.Command{
// Wait until connected or crash on timeout
connected := make(chan bool, 10)
client.GetNetworkInterface().AddHealthCallback(
client.GetCmix().AddHealthCallback(
func(isconnected bool) {
connected <- isconnected
})
......@@ -112,7 +112,7 @@ var groupCmd = &cobra.Command{
// initGroupManager creates a new group chat manager and starts the process
// service.
func initGroupManager(client *api.Client) (*groupChat.Manager,
func initGroupManager(client *messenger.Client) (*groupChat.Manager,
chan groupChat.MessageReceive, chan groupStore.Group) {
recChan := make(chan groupChat.MessageReceive, 10)
receiveCb := func(msg groupChat.MessageReceive) {
......@@ -125,8 +125,8 @@ func initGroupManager(client *api.Client) (*groupChat.Manager,
}
jww.INFO.Print("Creating new group manager.")
manager, err := groupChat.NewManager(client.GetNetworkInterface(),
client.GetE2EHandler(), client.GetStorage().GetReceptionID(),
manager, err := groupChat.NewManager(client.GetCmix(),
client.GetE2E(), client.GetStorage().GetReceptionID(),
client.GetRng(), client.GetStorage().GetE2EGroup(),
client.GetStorage().GetKV(), requestCb, receiveCb)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment