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

implemented basic API improvemt for auth callbacks

parent 3ac50c3a
Branches
Tags
2 merge requests!510Release,!252Auth callbacks change
...@@ -26,20 +26,18 @@ import ( ...@@ -26,20 +26,18 @@ import (
type authCallbacks struct { type authCallbacks struct {
autoConfirm bool autoConfirm bool
confCh chan *id.ID confCh chan *id.ID
client *xxdk.E2e
} }
func makeAuthCallbacks(client *xxdk.E2e, autoConfirm bool) *authCallbacks { func makeAuthCallbacks(autoConfirm bool) *authCallbacks {
return &authCallbacks{ return &authCallbacks{
autoConfirm: autoConfirm, autoConfirm: autoConfirm,
confCh: make(chan *id.ID, 10), confCh: make(chan *id.ID, 10),
client: client,
} }
} }
func (a *authCallbacks) Request(requestor contact.Contact, func (a *authCallbacks) Request(requestor contact.Contact,
receptionID receptionID.EphemeralIdentity, receptionID receptionID.EphemeralIdentity,
round rounds.Round) { round rounds.Round, client *xxdk.E2e) {
msg := fmt.Sprintf("Authentication channel request from: %s\n", msg := fmt.Sprintf("Authentication channel request from: %s\n",
requestor.ID) requestor.ID)
jww.INFO.Printf(msg) jww.INFO.Printf(msg)
...@@ -48,9 +46,9 @@ func (a *authCallbacks) Request(requestor contact.Contact, ...@@ -48,9 +46,9 @@ func (a *authCallbacks) Request(requestor contact.Contact,
jww.INFO.Printf("Channel Request: %s", jww.INFO.Printf("Channel Request: %s",
requestor.ID) requestor.ID)
if viper.GetBool("verify-sends") { // Verify message sends were successful if viper.GetBool("verify-sends") { // Verify message sends were successful
acceptChannelVerified(a.client, requestor.ID) acceptChannelVerified(client, requestor.ID)
} else { } else {
acceptChannel(a.client, requestor.ID) acceptChannel(client, requestor.ID)
} }
a.confCh <- requestor.ID a.confCh <- requestor.ID
...@@ -60,14 +58,14 @@ func (a *authCallbacks) Request(requestor contact.Contact, ...@@ -60,14 +58,14 @@ func (a *authCallbacks) Request(requestor contact.Contact,
func (a *authCallbacks) Confirm(requestor contact.Contact, func (a *authCallbacks) Confirm(requestor contact.Contact,
receptionID receptionID.EphemeralIdentity, receptionID receptionID.EphemeralIdentity,
round rounds.Round) { round rounds.Round, client *xxdk.E2e) {
jww.INFO.Printf("Channel Confirmed: %s", requestor.ID) jww.INFO.Printf("Channel Confirmed: %s", requestor.ID)
a.confCh <- requestor.ID a.confCh <- requestor.ID
} }
func (a *authCallbacks) Reset(requestor contact.Contact, func (a *authCallbacks) Reset(requestor contact.Contact,
receptionID receptionID.EphemeralIdentity, receptionID receptionID.EphemeralIdentity,
round rounds.Round) { round rounds.Round, client *xxdk.E2e) {
msg := fmt.Sprintf("Authentication channel reset from: %s\n", msg := fmt.Sprintf("Authentication channel reset from: %s\n",
requestor.ID) requestor.ID)
jww.INFO.Printf(msg) jww.INFO.Printf(msg)
......
...@@ -670,7 +670,7 @@ func initClient() *xxdk.E2e { ...@@ -670,7 +670,7 @@ func initClient() *xxdk.E2e {
jww.FATAL.Panicf("%+v", err) jww.FATAL.Panicf("%+v", err)
} }
authCbs = makeAuthCallbacks(nil, authCbs = makeAuthCallbacks(
viper.GetBool("unsafe-channel-creation")) viper.GetBool("unsafe-channel-creation"))
client, err := xxdk.LoginLegacy(baseclient, authCbs) client, err := xxdk.LoginLegacy(baseclient, authCbs)
...@@ -678,8 +678,6 @@ func initClient() *xxdk.E2e { ...@@ -678,8 +678,6 @@ func initClient() *xxdk.E2e {
jww.FATAL.Panicf("%+v", err) jww.FATAL.Panicf("%+v", err)
} }
authCbs.client = client
if protoUser := viper.GetString("protoUserOut"); protoUser != "" { if protoUser := viper.GetString("protoUserOut"); protoUser != "" {
jsonBytes, err := client.ConstructProtoUserFile() jsonBytes, err := client.ConstructProtoUserFile()
......
...@@ -12,10 +12,13 @@ import ( ...@@ -12,10 +12,13 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/auth" "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"
"gitlab.com/elixxir/client/e2e/rekey" "gitlab.com/elixxir/client/e2e/rekey"
"gitlab.com/elixxir/client/storage/user" "gitlab.com/elixxir/client/storage/user"
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/ekv" "gitlab.com/elixxir/ekv"
...@@ -34,16 +37,25 @@ type E2e struct { ...@@ -34,16 +37,25 @@ type E2e struct {
e2eIdentity ReceptionIdentity e2eIdentity ReceptionIdentity
} }
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 // Login creates a new E2e backed by the xxdk.Cmix persistent versioned.KV
// It bundles a Cmix object with a ReceptionIdentity object // It bundles a Cmix object with a ReceptionIdentity object
// and initializes the auth.State and e2e.Handler objects // 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) { identity ReceptionIdentity) (m *E2e, err error) {
return login(client, callbacks, identity, client.GetStorage().GetKV()) return login(client, callbacks, identity, client.GetStorage().GetKV())
} }
// LoginEphemeral creates a new E2e backed by a totally ephemeral versioned.KV // 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) { identity ReceptionIdentity) (m *E2e, err error) {
return login(client, callbacks, identity, versioned.NewKV(ekv.MakeMemstore())) return login(client, callbacks, identity, versioned.NewKV(ekv.MakeMemstore()))
} }
...@@ -52,7 +64,7 @@ func LoginEphemeral(client *Cmix, callbacks auth.Callbacks, ...@@ -52,7 +64,7 @@ func LoginEphemeral(client *Cmix, callbacks auth.Callbacks,
// Uses the pre-generated transmission ID used by xxdk.Cmix. // Uses the pre-generated transmission ID used by xxdk.Cmix.
// This function is designed to maintain backwards compatibility with previous // This function is designed to maintain backwards compatibility with previous
// xx messenger designs and should not be used for other purposes. // 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{ m = &E2e{
Cmix: client, Cmix: client,
backup: &Container{}, backup: &Container{},
...@@ -70,9 +82,14 @@ func LoginLegacy(client *Cmix, callbacks auth.Callbacks) (m *E2e, err error) { ...@@ -70,9 +82,14 @@ func LoginLegacy(client *Cmix, callbacks auth.Callbacks) (m *E2e, err error) {
"the e2e processies") "the e2e processies")
} }
acw := &authCallbacksAdapter{
ac: callbacks,
e2e: m,
}
m.auth, err = auth.NewState(client.GetStorage().GetKV(), client.GetCmix(), m.auth, err = auth.NewState(client.GetStorage().GetKV(), client.GetCmix(),
m.e2e, client.GetRng(), client.GetEventReporter(), m.e2e, client.GetRng(), client.GetEventReporter(),
auth.GetDefaultParams(), callbacks, m.backup.TriggerBackup) auth.GetDefaultParams(), acw, m.backup.TriggerBackup)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -131,7 +148,7 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte, ...@@ -131,7 +148,7 @@ func LoginWithNewBaseNDF_UNSAFE(storageDir string, password []byte,
// JSON containing the cryptographic primitives. This is designed for // JSON containing the cryptographic primitives. This is designed for
// some specific deployment procedures and is generally unsafe. // some specific deployment procedures and is generally unsafe.
func LoginWithProtoClient(storageDir string, password []byte, func LoginWithProtoClient(storageDir string, password []byte,
protoClientJSON []byte, newBaseNdf string, protoClientJSON []byte, newBaseNdf string, callbacks AuthCallbacks,
params Params) (*E2e, error) { params Params) (*E2e, error) {
jww.INFO.Printf("LoginWithProtoClient()") jww.INFO.Printf("LoginWithProtoClient()")
...@@ -166,18 +183,12 @@ func LoginWithProtoClient(storageDir string, password []byte, ...@@ -166,18 +183,12 @@ func LoginWithProtoClient(storageDir string, password []byte,
c.network.AddIdentity(c.GetUser().ReceptionID, time.Time{}, true) c.network.AddIdentity(c.GetUser().ReceptionID, time.Time{}, true)
// 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() err = c.registerFollower()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return Login(c, nil, ReceptionIdentity{ return Login(c, callbacks, ReceptionIdentity{
ID: protoUser.ReceptionID, ID: protoUser.ReceptionID,
RSAPrivatePem: protoUser.ReceptionRSA, RSAPrivatePem: protoUser.ReceptionRSA,
Salt: protoUser.ReceptionSalt, Salt: protoUser.ReceptionSalt,
...@@ -186,7 +197,7 @@ func LoginWithProtoClient(storageDir string, password []byte, ...@@ -186,7 +197,7 @@ func LoginWithProtoClient(storageDir string, password []byte,
} }
// login creates a new xxdk.E2e backed by the given versioned.KV // 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) { identity ReceptionIdentity, kv *versioned.KV) (m *E2e, err error) {
// Verify the passed-in ReceptionIdentity matches its properties // Verify the passed-in ReceptionIdentity matches its properties
...@@ -228,9 +239,14 @@ func login(client *Cmix, callbacks auth.Callbacks, ...@@ -228,9 +239,14 @@ func login(client *Cmix, callbacks auth.Callbacks,
"the e2e processies") "the e2e processies")
} }
acw := &authCallbacksAdapter{
ac: callbacks,
e2e: m,
}
m.auth, err = auth.NewState(kv, client.GetCmix(), m.auth, err = auth.NewState(kv, client.GetCmix(),
m.e2e, client.GetRng(), client.GetEventReporter(), m.e2e, client.GetRng(), client.GetEventReporter(),
auth.GetDefaultTemporaryParams(), callbacks, m.backup.TriggerBackup) auth.GetDefaultTemporaryParams(), acw, m.backup.TriggerBackup)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -396,3 +412,25 @@ func (m *E2e) DeleteContact(partnerId *id.ID) error { ...@@ -396,3 +412,25 @@ func (m *E2e) DeleteContact(partnerId *id.ID) error {
return nil return nil
} }
// Adapter type to make the xxdk auth callbacks type compatible with the
// auth.callbacks
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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment