diff --git a/auth/callbacks.go b/auth/callbacks.go index 3c5862e7a13d901b874b12dc3c274852cf49b13c..273ff6b0b7af5b36ff53d44e265ebaeaab0183cd 100644 --- a/auth/callbacks.go +++ b/auth/callbacks.go @@ -7,10 +7,6 @@ package auth import ( - jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/cmix/identity/receptionID" - "gitlab.com/elixxir/client/cmix/rounds" - "gitlab.com/elixxir/crypto/contact" "gitlab.com/xx_network/primitives/id" "sync" ) @@ -47,25 +43,3 @@ func (p *partnerCallbacks) getPartnerCallback(partnerId *id.ID) Callbacks { return p.callbacks[*partnerId] } - -// DefaultAuthCallbacks is a simple structure for providing a default Callbacks implementation -// It should generally not be used. -type DefaultAuthCallbacks struct{} - -// Confirm will be called when an auth Confirm message is processed. -func (a DefaultAuthCallbacks) Confirm(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { - jww.ERROR.Printf("No valid auth callback assigned!") -} - -// Request will be called when an auth Request message is processed. -func (a DefaultAuthCallbacks) Request(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { - jww.ERROR.Printf("No valid auth callback assigned!") -} - -// Reset will be called when an auth Reset operation occurs. -func (a DefaultAuthCallbacks) Reset(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { - jww.ERROR.Printf("No valid auth callback assigned!") -} diff --git a/bindings/e2e.go b/bindings/e2e.go index 00509dad9dfaaba1e4c383c39c6d3d141a0791ae..dffc2560f4842e610a9eefe5f75f37d572776041 100644 --- a/bindings/e2e.go +++ b/bindings/e2e.go @@ -8,7 +8,7 @@ package bindings import ( "encoding/json" - "gitlab.com/elixxir/client/auth" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/xxdk" @@ -51,9 +51,9 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error return nil, err } - var authCallbacks auth.Callbacks + var authCallbacks xxdk.AuthCallbacks if callbacks == nil { - authCallbacks = auth.DefaultAuthCallbacks{} + authCallbacks = defaultAuthCallbacks{} } else { authCallbacks = &authCallback{bindingsCbs: callbacks} } @@ -80,9 +80,9 @@ func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E return nil, err } - var authCallbacks auth.Callbacks + var authCallbacks xxdk.AuthCallbacks if callbacks == nil { - authCallbacks = auth.DefaultAuthCallbacks{} + authCallbacks = defaultAuthCallbacks{} } else { authCallbacks = &authCallback{bindingsCbs: callbacks} } @@ -105,9 +105,9 @@ func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) { return nil, err } - var authCallbacks auth.Callbacks + var authCallbacks xxdk.AuthCallbacks if callbacks == nil { - authCallbacks = auth.DefaultAuthCallbacks{} + authCallbacks = defaultAuthCallbacks{} } else { authCallbacks = &authCallback{bindingsCbs: callbacks} } @@ -181,19 +181,41 @@ func convertAuthCallbacks(requestor contact.Contact, } // Confirm will be called when an auth Confirm message is processed. -func (a *authCallback) Confirm(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { - a.bindingsCbs.Confirm(convertAuthCallbacks(requestor, receptionID, round)) +func (a *authCallback) Confirm(partner contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round, _ *xxdk.E2e) { + a.bindingsCbs.Confirm(convertAuthCallbacks(partner, receptionID, round)) } // Request will be called when an auth Request message is processed. -func (a *authCallback) Request(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { - a.bindingsCbs.Request(convertAuthCallbacks(requestor, receptionID, round)) +func (a *authCallback) Request(partner contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round, _ *xxdk.E2e) { + a.bindingsCbs.Request(convertAuthCallbacks(partner, receptionID, round)) } // Reset will be called when an auth Reset operation occurs. -func (a *authCallback) Reset(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { - a.bindingsCbs.Reset(convertAuthCallbacks(requestor, receptionID, round)) +func (a *authCallback) Reset(partner contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round, _ *xxdk.E2e) { + a.bindingsCbs.Reset(convertAuthCallbacks(partner, receptionID, round)) +} + +// defaultAuthCallbacks is a simple structure for providing a default Callbacks implementation +// It should generally not be used. +type defaultAuthCallbacks struct{} + +// Confirm will be called when an auth Confirm message is processed. +func (a defaultAuthCallbacks) Confirm(contact.Contact, + receptionID.EphemeralIdentity, rounds.Round, *xxdk.E2e) { + jww.ERROR.Printf("No valid auth callback assigned!") +} + +// Request will be called when an auth Request message is processed. +func (a defaultAuthCallbacks) Request(contact.Contact, + receptionID.EphemeralIdentity, rounds.Round, *xxdk.E2e) { + jww.ERROR.Printf("No valid auth callback assigned!") +} + +// Reset will be called when an auth Reset operation occurs. +func (a defaultAuthCallbacks) Reset(contact.Contact, + receptionID.EphemeralIdentity, rounds.Round, *xxdk.E2e) { + jww.ERROR.Printf("No valid auth callback assigned!") } diff --git a/bindings/e2eAuth.go b/bindings/e2eAuth.go index b483671d90d3deb616bc0bd2e13018882e859ec1..77083daa290bfcd1dbd27ffe714e2d456624475d 100644 --- a/bindings/e2eAuth.go +++ b/bindings/e2eAuth.go @@ -8,6 +8,7 @@ package bindings import ( + "gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/primitives/id" @@ -215,7 +216,8 @@ func (e *E2e) AddPartnerCallback(partnerID []byte, cb AuthCallbacks) error { return err } - e.api.GetAuth().AddPartnerCallback(partnerId, &authCallback{bindingsCbs: cb}) + e.api.GetAuth().AddPartnerCallback(partnerId, + xxdk.MakeAuthCallbacksAdapter(&authCallback{bindingsCbs: cb}, e.api)) return nil } diff --git a/cmd/callbacks.go b/cmd/callbacks.go index 13900622395ed2e6b787df1b2d7d22c426cb8c61..d5d75a321f7e215062738184bbaab954812c29b6 100644 --- a/cmd/callbacks.go +++ b/cmd/callbacks.go @@ -26,20 +26,18 @@ import ( type authCallbacks struct { autoConfirm bool confCh chan *id.ID - client *xxdk.E2e } -func makeAuthCallbacks(client *xxdk.E2e, autoConfirm bool) *authCallbacks { +func makeAuthCallbacks(autoConfirm bool) *authCallbacks { return &authCallbacks{ autoConfirm: autoConfirm, confCh: make(chan *id.ID, 10), - client: client, } } func (a *authCallbacks) Request(requestor contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round) { + round rounds.Round, client *xxdk.E2e) { msg := fmt.Sprintf("Authentication channel request from: %s\n", requestor.ID) jww.INFO.Printf(msg) @@ -48,9 +46,9 @@ func (a *authCallbacks) Request(requestor contact.Contact, jww.INFO.Printf("Channel Request: %s", requestor.ID) if viper.GetBool("verify-sends") { // Verify message sends were successful - acceptChannelVerified(a.client, requestor.ID) + acceptChannelVerified(client, requestor.ID) } else { - acceptChannel(a.client, requestor.ID) + acceptChannel(client, requestor.ID) } a.confCh <- requestor.ID @@ -60,14 +58,14 @@ func (a *authCallbacks) Request(requestor contact.Contact, func (a *authCallbacks) Confirm(requestor contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round) { + round rounds.Round, client *xxdk.E2e) { jww.INFO.Printf("Channel Confirmed: %s", requestor.ID) a.confCh <- requestor.ID } func (a *authCallbacks) Reset(requestor contact.Contact, receptionID receptionID.EphemeralIdentity, - round rounds.Round) { + round rounds.Round, client *xxdk.E2e) { msg := fmt.Sprintf("Authentication channel reset from: %s\n", requestor.ID) jww.INFO.Printf(msg) diff --git a/cmd/root.go b/cmd/root.go index ac0e48756e933735e8fe9500a5d339439cffe86b..0f0a42ad98fddb2791e659930573a752f639e555 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -670,7 +670,7 @@ func initClient() *xxdk.E2e { jww.FATAL.Panicf("%+v", err) } - authCbs = makeAuthCallbacks(nil, + authCbs = makeAuthCallbacks( viper.GetBool("unsafe-channel-creation")) client, err := xxdk.LoginLegacy(baseclient, authCbs) @@ -678,8 +678,6 @@ func initClient() *xxdk.E2e { jww.FATAL.Panicf("%+v", err) } - authCbs.client = client - if protoUser := viper.GetString("protoUserOut"); protoUser != "" { jsonBytes, err := client.ConstructProtoUserFile() diff --git a/connect/authCallbacks.go b/connect/authCallbacks.go new file mode 100644 index 0000000000000000000000000000000000000000..3c4670bd3fce5be27d230e4b67d8fef43143d661 --- /dev/null +++ b/connect/authCallbacks.go @@ -0,0 +1,146 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2022 Privategrity Corporation / +// / +// All rights reserved. / +//////////////////////////////////////////////////////////////////////////////// + +package connect + +import ( + jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/auth" + "gitlab.com/elixxir/client/cmix/identity/receptionID" + "gitlab.com/elixxir/client/cmix/rounds" + clientE2e "gitlab.com/elixxir/client/e2e" + "gitlab.com/elixxir/client/xxdk" + "gitlab.com/elixxir/crypto/contact" +) + +// clientAuthCallback provides callback functionality for interfacing between +// auth.State and Connection. This is used both for blocking creation of a +// Connection object until the auth Request is confirmed and for dynamically +// building new Connection objects when an auth Request is received. +type clientAuthCallback struct { + // Used for signaling confirmation of E2E partnership + confirmCallback Callback + requestCallback Callback + + // Used for building new Connection objects + connectionE2e clientE2e.Handler + connectionParams Params + authState auth.State +} + +// getClientAuthCallback returns a callback interface to be passed into the creation +// of an auth.State object. +// it will accept requests only if a request callback is passed in +func getClientAuthCallback(confirm, request Callback, e2e clientE2e.Handler, + auth auth.State, params Params) *clientAuthCallback { + return &clientAuthCallback{ + confirmCallback: confirm, + requestCallback: request, + connectionE2e: e2e, + connectionParams: params, + authState: auth, + } +} + +// Confirm will be called when an auth Confirm message is processed. +func (a clientAuthCallback) Confirm(requestor contact.Contact, + _ receptionID.EphemeralIdentity, _ rounds.Round) { + jww.DEBUG.Printf("Connection auth request for %s confirmed", + requestor.ID.String()) + defer a.authState.DeletePartnerCallback(requestor.ID) + + // After confirmation, get the new partner + newPartner, err := a.connectionE2e.GetPartner(requestor.ID) + if err != nil { + jww.ERROR.Printf("Unable to build connection with "+ + "partner %s: %+v", requestor.ID, err) + // Send a nil connection to avoid hold-ups down the line + if a.confirmCallback != nil { + a.confirmCallback(nil) + } + return + } + + // Return the new Connection object + if a.confirmCallback != nil { + a.confirmCallback(BuildConnection(newPartner, a.connectionE2e, + a.authState, a.connectionParams)) + } +} + +// Request will be called when an auth Request message is processed. +func (a clientAuthCallback) Request(contact.Contact, + receptionID.EphemeralIdentity, rounds.Round) { +} + +// Reset will be called when an auth Reset operation occurs. +func (a clientAuthCallback) Reset(contact.Contact, + receptionID.EphemeralIdentity, rounds.Round) { +} + +// serverAuthCallback provides callback functionality for interfacing between +// auth.State and Connection. This is used both for blocking creation of a +// Connection object until the auth Request is confirmed and for dynamically +// building new Connection objects when an auth Request is received. +type serverAuthCallback struct { + // Used for signaling confirmation of E2E partnership + confirmCallback Callback + requestCallback Callback + + // Used for building new Connection objects + connectionParams Params +} + +// getServerAuthCallback returns a callback interface to be passed into the creation +// of a xxdk.E2e object. +// it will accept requests only if a request callback is passed in +func getServerAuthCallback(confirm, request Callback, params Params) *serverAuthCallback { + return &serverAuthCallback{ + confirmCallback: confirm, + requestCallback: request, + connectionParams: params, + } +} + +// Confirm will be called when an auth Confirm message is processed. +func (a serverAuthCallback) Confirm(contact.Contact, + receptionID.EphemeralIdentity, rounds.Round, *xxdk.E2e) { +} + +// Request will be called when an auth Request message is processed. +func (a serverAuthCallback) Request(requestor contact.Contact, + _ receptionID.EphemeralIdentity, _ rounds.Round, e2e *xxdk.E2e) { + if a.requestCallback == nil { + jww.ERROR.Printf("Received a request when requests are" + + "not enable, will not accept") + } + _, err := e2e.GetAuth().Confirm(requestor) + if err != nil { + jww.ERROR.Printf("Unable to build connection with "+ + "partner %s: %+v", requestor.ID, err) + // Send a nil connection to avoid hold-ups down the line + a.requestCallback(nil) + } + // After confirmation, get the new partner + newPartner, err := e2e.GetE2E().GetPartner(requestor.ID) + if err != nil { + jww.ERROR.Printf("Unable to build connection with "+ + "partner %s: %+v", requestor.ID, err) + // Send a nil connection to avoid hold-ups down the line + a.requestCallback(nil) + + return + } + + // Return the new Connection object + a.requestCallback(BuildConnection(newPartner, e2e.GetE2E(), + e2e.GetAuth(), a.connectionParams)) +} + +// Reset will be called when an auth Reset operation occurs. +func (a serverAuthCallback) Reset(contact.Contact, + receptionID.EphemeralIdentity, rounds.Round, *xxdk.E2e) { +} diff --git a/connect/connect.go b/connect/connect.go index b55d8ce96147fb91512db1563a12678354e08372..429f7331d4f1923cec27497f048fa9a3764567a0 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -16,8 +16,6 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/auth" "gitlab.com/elixxir/client/catalog" - "gitlab.com/elixxir/client/cmix/identity/receptionID" - "gitlab.com/elixxir/client/cmix/rounds" clientE2e "gitlab.com/elixxir/client/e2e" "gitlab.com/elixxir/client/e2e/ratchet/partner" "gitlab.com/elixxir/client/e2e/receive" @@ -121,7 +119,7 @@ func Connect(recipient contact.Contact, e2eClient *xxdk.E2e, cb := func(connection Connection) { signalChannel <- connection } - callback := getAuthCallback(cb, nil, e2eClient.GetE2E(), e2eClient.GetAuth(), p) + callback := getClientAuthCallback(cb, nil, e2eClient.GetE2E(), e2eClient.GetAuth(), p) e2eClient.GetAuth().AddPartnerCallback(recipient.ID, callback) // Perform the auth request @@ -163,16 +161,10 @@ func StartServer(identity xxdk.ReceptionIdentity, cb Callback, net *xxdk.Cmix, p Params) (*xxdk.E2e, error) { // Build callback for E2E negotiation - callback := getAuthCallback(nil, cb, nil, nil, p) + callback := getServerAuthCallback(nil, cb, p) - client, err := xxdk.LoginEphemeral(net, callback, identity) - if err != nil { - return nil, err - } - - callback.connectionE2e = client.GetE2E() - callback.authState = client.GetAuth() - return client, nil + // Return an ephemeral E2e object + return xxdk.LoginEphemeral(net, callback, identity) } // handler provides an implementation for the Connection interface. @@ -230,96 +222,6 @@ func (h *handler) Unregister(listenerID receive.ListenerID) { h.e2e.Unregister(listenerID) } -// authCallback provides callback functionality for interfacing between -// auth.State and Connection. This is used both for blocking creation of a -// Connection object until the auth Request is confirmed and for dynamically -// building new Connection objects when an auth Request is received. -type authCallback struct { - // Used for signaling confirmation of E2E partnership - confirmCallback Callback - requestCallback Callback - - // Used for building new Connection objects - connectionE2e clientE2e.Handler - connectionParams Params - authState auth.State -} - -// getAuthCallback returns a callback interface to be passed into the creation -// of an auth.State object. -// it will accept requests only if a request callback is passed in -func getAuthCallback(confirm, request Callback, e2e clientE2e.Handler, - auth auth.State, params Params) *authCallback { - return &authCallback{ - confirmCallback: confirm, - requestCallback: request, - connectionE2e: e2e, - connectionParams: params, - authState: auth, - } -} - -// Confirm will be called when an auth Confirm message is processed. -func (a authCallback) Confirm(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { - jww.DEBUG.Printf("Connection auth request for %s confirmed", - requestor.ID.String()) - defer a.authState.DeletePartnerCallback(requestor.ID) - - // After confirmation, get the new partner - newPartner, err := a.connectionE2e.GetPartner(requestor.ID) - if err != nil { - jww.ERROR.Printf("Unable to build connection with "+ - "partner %s: %+v", requestor.ID, err) - // Send a nil connection to avoid hold-ups down the line - if a.confirmCallback != nil { - a.confirmCallback(nil) - } - return - } - - // Return the new Connection object - if a.confirmCallback != nil { - a.confirmCallback(BuildConnection(newPartner, a.connectionE2e, - a.authState, a.connectionParams)) - } -} - -// Request will be called when an auth Request message is processed. -func (a authCallback) Request(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { - if a.requestCallback == nil { - jww.ERROR.Printf("Received a request when requests are" + - "not enable, will not accept") - } - _, err := a.authState.Confirm(requestor) - if err != nil { - jww.ERROR.Printf("Unable to build connection with "+ - "partner %s: %+v", requestor.ID, err) - // Send a nil connection to avoid hold-ups down the line - a.requestCallback(nil) - } - // After confirmation, get the new partner - newPartner, err := a.connectionE2e.GetPartner(requestor.ID) - if err != nil { - jww.ERROR.Printf("Unable to build connection with "+ - "partner %s: %+v", requestor.ID, err) - // Send a nil connection to avoid hold-ups down the line - a.requestCallback(nil) - - return - } - - // Return the new Connection object - a.requestCallback(BuildConnection(newPartner, a.connectionE2e, - a.authState, a.connectionParams)) -} - -// Reset will be called when an auth Reset operation occurs. -func (a authCallback) Reset(requestor contact.Contact, - receptionID receptionID.EphemeralIdentity, round rounds.Round) { -} - // FirstPartitionSize returns the max partition payload size for the // first payload func (h *handler) FirstPartitionSize() uint { diff --git a/xxdk/e2e.go b/xxdk/e2e.go index 157f0e6684426c276bd18144880d81958d175656..e528c63352d167cc5b90016b56ae7200b0b921b4 100644 --- a/xxdk/e2e.go +++ b/xxdk/e2e.go @@ -12,10 +12,13 @@ import ( "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/auth" + "gitlab.com/elixxir/client/cmix/identity/receptionID" + "gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/e2e" "gitlab.com/elixxir/client/e2e/rekey" "gitlab.com/elixxir/client/storage/user" "gitlab.com/elixxir/client/storage/versioned" + "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/ekv" @@ -34,16 +37,27 @@ type E2e struct { e2eIdentity ReceptionIdentity } +// AuthCallbacks is an adapter for the auth.Callbacks interface +// that allows for initializing an E2e object without an E2e-dependant auth.Callbacks +type AuthCallbacks interface { + Request(partner contact.Contact, receptionID receptionID.EphemeralIdentity, + round rounds.Round, e2e *E2e) + Confirm(partner contact.Contact, receptionID receptionID.EphemeralIdentity, + round rounds.Round, e2e *E2e) + Reset(partner contact.Contact, receptionID receptionID.EphemeralIdentity, + round rounds.Round, e2e *E2e) +} + // Login creates a new E2e backed by the xxdk.Cmix persistent versioned.KV // It bundles a Cmix object with a ReceptionIdentity object // and initializes the auth.State and e2e.Handler objects -func Login(client *Cmix, callbacks auth.Callbacks, +func Login(client *Cmix, callbacks AuthCallbacks, identity ReceptionIdentity) (m *E2e, err error) { return login(client, callbacks, identity, client.GetStorage().GetKV()) } // LoginEphemeral creates a new E2e backed by a totally ephemeral versioned.KV -func LoginEphemeral(client *Cmix, callbacks auth.Callbacks, +func LoginEphemeral(client *Cmix, callbacks AuthCallbacks, identity ReceptionIdentity) (m *E2e, err error) { return login(client, callbacks, identity, versioned.NewKV(ekv.MakeMemstore())) } @@ -52,7 +66,7 @@ func LoginEphemeral(client *Cmix, callbacks auth.Callbacks, // Uses the pre-generated transmission ID used by xxdk.Cmix. // This function is designed to maintain backwards compatibility with previous // xx messenger designs and should not be used for other purposes. -func LoginLegacy(client *Cmix, callbacks auth.Callbacks) (m *E2e, err error) { +func LoginLegacy(client *Cmix, callbacks AuthCallbacks) (m *E2e, err error) { m = &E2e{ Cmix: client, backup: &Container{}, @@ -72,7 +86,7 @@ func LoginLegacy(client *Cmix, callbacks auth.Callbacks) (m *E2e, err error) { m.auth, err = auth.NewState(client.GetStorage().GetKV(), client.GetCmix(), m.e2e, client.GetRng(), client.GetEventReporter(), - auth.GetDefaultParams(), callbacks, m.backup.TriggerBackup) + auth.GetDefaultParams(), MakeAuthCallbacksAdapter(callbacks, m), m.backup.TriggerBackup) if err != nil { return nil, err } @@ -131,7 +145,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, + protoClientJSON []byte, newBaseNdf string, callbacks AuthCallbacks, params Params) (*E2e, error) { jww.INFO.Printf("LoginWithProtoClient()") @@ -164,18 +178,12 @@ func LoginWithProtoClient(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? - if err != nil { - return nil, err - } err = c.registerFollower() if err != nil { return nil, err } - return Login(c, nil, ReceptionIdentity{ + return Login(c, callbacks, ReceptionIdentity{ ID: protoUser.ReceptionID, RSAPrivatePem: protoUser.ReceptionRSA, Salt: protoUser.ReceptionSalt, @@ -184,7 +192,7 @@ func LoginWithProtoClient(storageDir string, password []byte, } // login creates a new xxdk.E2e backed by the given versioned.KV -func login(client *Cmix, callbacks auth.Callbacks, +func login(client *Cmix, callbacks AuthCallbacks, identity ReceptionIdentity, kv *versioned.KV) (m *E2e, err error) { // Verify the passed-in ReceptionIdentity matches its properties @@ -230,7 +238,7 @@ func login(client *Cmix, callbacks auth.Callbacks, m.auth, err = auth.NewState(kv, client.GetCmix(), m.e2e, client.GetRng(), client.GetEventReporter(), - auth.GetDefaultTemporaryParams(), callbacks, m.backup.TriggerBackup) + auth.GetDefaultTemporaryParams(), MakeAuthCallbacksAdapter(callbacks, m), m.backup.TriggerBackup) if err != nil { return nil, err } @@ -396,3 +404,33 @@ func (m *E2e) DeleteContact(partnerId *id.ID) error { return nil } + +// MakeAuthCallbacksAdapter creates an authCallbacksAdapter +func MakeAuthCallbacksAdapter(ac AuthCallbacks, e2e *E2e) *authCallbacksAdapter { + return &authCallbacksAdapter{ + ac: ac, + e2e: e2e, + } +} + +// authCallbacksAdapter is an adapter type to make the AuthCallbacks type +// compatible with the auth.Callbacks type +type authCallbacksAdapter struct { + ac AuthCallbacks + e2e *E2e +} + +func (aca *authCallbacksAdapter) Request(partner contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round) { + aca.ac.Request(partner, receptionID, round, aca.e2e) +} + +func (aca *authCallbacksAdapter) Confirm(partner contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round) { + aca.ac.Confirm(partner, receptionID, round, aca.e2e) +} + +func (aca *authCallbacksAdapter) Reset(partner contact.Contact, + receptionID receptionID.EphemeralIdentity, round rounds.Round) { + aca.ac.Reset(partner, receptionID, round, aca.e2e) +}