Skip to content
Snippets Groups Projects
Commit 668afe6a authored by Jake Taylor's avatar Jake Taylor
Browse files

fix comments

parent 3894efe2
No related branches found
No related tags found
2 merge requests!510Release,!238Hotfix/e2e client
......@@ -107,6 +107,7 @@ type State interface {
}
// Callbacks is the interface for auth callback methods.
// TODO: Document this
type Callbacks interface {
Request(partner contact.Contact, receptionID receptionID.EphemeralIdentity,
round rounds.Round)
......
......@@ -68,30 +68,30 @@ func (c *Cmix) GetContactFromIdentity(identity []byte) ([]byte, error) {
return ct.Marshal(), nil
}
func (c *Cmix) unmarshalIdentity(marshaled []byte) (*xxdk.TransmissionIdentity, error) {
newIdentity := &xxdk.TransmissionIdentity{}
func (c *Cmix) unmarshalIdentity(marshaled []byte) (xxdk.TransmissionIdentity, error) {
newIdentity := xxdk.TransmissionIdentity{}
// Unmarshal given identity into TransmissionIdentity object
givenIdentity := TransmissionIdentity{}
err := json.Unmarshal(marshaled, &givenIdentity)
if err != nil {
return nil, err
return xxdk.TransmissionIdentity{}, err
}
newIdentity.ID, err = id.Unmarshal(givenIdentity.ID)
if err != nil {
return nil, err
return xxdk.TransmissionIdentity{}, err
}
newIdentity.DHKeyPrivate = c.api.GetStorage().GetE2EGroup().NewInt(1)
err = newIdentity.DHKeyPrivate.UnmarshalJSON(givenIdentity.DHKeyPrivate)
if err != nil {
return nil, err
return xxdk.TransmissionIdentity{}, err
}
newIdentity.RSAPrivatePem, err = rsa.LoadPrivateKeyFromPem(givenIdentity.RSAPrivatePem)
if err != nil {
return nil, err
return xxdk.TransmissionIdentity{}, err
}
newIdentity.Salt = givenIdentity.Salt
......
......@@ -29,49 +29,42 @@ type E2e struct {
}
// Login creates and returns a new E2e object and adds it to the e2eTrackerSingleton
// identity can be left nil such that a new TransmissionIdentity will be created automatically
// callbacks can be left nil and a default will be used
// identity should be created via MakeIdentity() and passed in here
// If callbacks is left nil, a default auth.Callbacks will be used
func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) {
cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil {
return nil, err
}
newIdentity := &xxdk.TransmissionIdentity{}
if identity == nil {
newIdentity = nil
} else {
newIdentity, err = cmix.unmarshalIdentity(identity)
if err != nil {
return nil, err
}
newIdentity, err := cmix.unmarshalIdentity(identity)
if err != nil {
return nil, err
}
var authCallbacks auth.Callbacks
if callbacks == nil {
authCallbacks := auth.DefaultAuthCallbacks{}
newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity)
if err != nil {
return nil, err
}
return e2eTrackerSingleton.make(newE2e), nil
authCallbacks = auth.DefaultAuthCallbacks{}
} else {
authCallbacks := &authCallback{bindingsCbs: callbacks}
newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity)
if err != nil {
return nil, err
}
return e2eTrackerSingleton.make(newE2e), nil
authCallbacks = &authCallback{bindingsCbs: callbacks}
}
newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity)
if err != nil {
return nil, err
}
return e2eTrackerSingleton.make(newE2e), nil
}
// AuthCallbacks is the bindings-specific interface for auth.Callbacks methods.
type AuthCallbacks interface {
Request(contact, receptionId []byte, ephemeralId, roundId uint64)
Confirm(contact, receptionId []byte, ephemeralId, roundId uint64)
Reset(contact, receptionId []byte, ephemeralId, roundId uint64)
Request(contact, receptionId []byte, ephemeralId, roundId int64)
Confirm(contact, receptionId []byte, ephemeralId, roundId int64)
Reset(contact, receptionId []byte, ephemeralId, roundId int64)
}
// authCallback implements AuthCallbacks
// authCallback implements AuthCallbacks as a way of obtaining
// an auth.Callbacks over the bindings
type authCallback struct {
bindingsCbs AuthCallbacks
}
......@@ -79,12 +72,12 @@ type authCallback struct {
// convertAuthCallbacks turns an auth.Callbacks into an AuthCallbacks
func convertAuthCallbacks(requestor contact.Contact,
receptionID receptionID.EphemeralIdentity,
round rounds.Round) (contact []byte, receptionId []byte, ephemeralId uint64, roundId uint64) {
round rounds.Round) (contact []byte, receptionId []byte, ephemeralId int64, roundId int64) {
contact = requestor.Marshal()
receptionId = receptionID.Source.Marshal()
ephemeralId = receptionID.EphId.UInt64()
roundId = uint64(round.ID)
ephemeralId = int64(receptionID.EphId.UInt64())
roundId = int64(round.ID)
return
}
......
......@@ -15,6 +15,7 @@ import (
// e2eTracker is a singleton used to keep track of extant E2e objects,
// preventing race conditions created by passing it over the bindings
type e2eTracker struct {
// TODO: Key on Identity.ID to prevent duplication
clients map[int]*E2e
count int
mux sync.RWMutex
......
......@@ -11,6 +11,7 @@ import (
"encoding/json"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/crypto/xx"
"time"
"github.com/pkg/errors"
......@@ -37,14 +38,14 @@ type E2e struct {
// Login creates a new E2e backed by the xxdk.Cmix persistent versioned.KV
// If identity == nil, a new TransmissionIdentity will be generated automagically
func Login(client *Cmix, callbacks auth.Callbacks,
identity *TransmissionIdentity) (m *E2e, err error) {
identity TransmissionIdentity) (m *E2e, err error) {
return login(client, callbacks, identity, client.GetStorage().GetKV())
}
// LoginEphemeral creates a new E2e backed by a totally ephemeral versioned.KV
// If identity == nil, a new TransmissionIdentity will be generated automagically
func LoginEphemeral(client *Cmix, callbacks auth.Callbacks,
identity *TransmissionIdentity) (m *E2e, err error) {
identity TransmissionIdentity) (m *E2e, err error) {
return login(client, callbacks, identity, versioned.NewKV(ekv.MakeMemstore()))
}
......@@ -83,25 +84,23 @@ func LoginLegacy(client *Cmix, callbacks auth.Callbacks) (m *E2e, err error) {
// login creates a new e2eApi.E2e backed by the given versioned.KV
func login(client *Cmix, callbacks auth.Callbacks,
identity *TransmissionIdentity, kv *versioned.KV) (m *E2e, err error) {
e2eGrp := client.GetStorage().GetE2EGroup()
identity TransmissionIdentity, kv *versioned.KV) (m *E2e, err error) {
// Create new identity automatically if one isn't specified
if identity == nil {
rng := client.GetRng().GetStream()
newIdentity, err := MakeTransmissionIdentity(rng, e2eGrp)
rng.Close()
if err != nil {
return nil, err
}
identity = &newIdentity
client.GetCmix().AddIdentity(identity.ID, time.Time{}, !kv.IsMemStore())
// Verify the passed-in TransmissionIdentity matches its properties
generatedId, err := xx.NewID(identity.RSAPrivatePem.GetPublic(), identity.Salt, id.User)
if err != nil {
return nil, err
}
if !generatedId.Cmp(identity.ID) {
return nil, errors.Errorf("Given identity %s is invalid, generated ID does not match",
identity.ID.String())
}
e2eGrp := client.GetStorage().GetE2EGroup()
m = &E2e{
Cmix: client,
backup: &Container{},
e2eIdentity: *identity,
e2eIdentity: identity,
}
//initialize the e2e storage
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment