Skip to content
Snippets Groups Projects
Commit 5c890337 authored by Josh Brooks's avatar Josh Brooks
Browse files

Merge branch 'xx-3003/update-id-creation' of gitlab.com:elixxir/client into...

Merge branch 'xx-3003/update-id-creation' of gitlab.com:elixxir/client into XX-3063/PersonalEphemeralTracking
parents 6ac606a5 c109c215
No related branches found
No related tags found
No related merge requests found
Showing
with 234 additions and 68 deletions
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
) )
//This holds all functions to send messages over the network //This holds all functions to send messages over the network
...@@ -45,23 +46,21 @@ func (c *Client) SendUnsafe(m message.Send, param params.Unsafe) ([]id.Round, ...@@ -45,23 +46,21 @@ func (c *Client) SendUnsafe(m message.Send, param params.Unsafe) ([]id.Round,
// recipient. Note that both SendE2E and SendUnsafe call SendCMIX. // recipient. Note that both SendE2E and SendUnsafe call SendCMIX.
// Returns the round ID of the round the payload was sent or an error // Returns the round ID of the round the payload was sent or an error
// if it fails. // if it fails.
func (c *Client) SendCMIX(msg format.Message, param params.CMIX) (id.Round, func (c *Client) SendCMIX(msg format.Message, recipientID *id.ID,
error) { param params.CMIX) (id.Round, ephemeral.Id, error) {
jww.INFO.Printf("SendCMIX(%s)", string(msg.GetContents())) jww.INFO.Printf("SendCMIX(%s)", string(msg.GetContents()))
return c.network.SendCMIX(msg, param) return c.network.SendCMIX(msg, recipientID, param)
} }
// NewCMIXMessage Creates a new cMix message with the right properties // NewCMIXMessage Creates a new cMix message with the right properties
// for the current cMix network. // for the current cMix network.
// FIXME: this is weird and shouldn't be necessary, but it is. // FIXME: this is weird and shouldn't be necessary, but it is.
func (c *Client) NewCMIXMessage(recipient *id.ID, func (c *Client) NewCMIXMessage(contents []byte) (format.Message, error) {
contents []byte) (format.Message, error) {
primeSize := len(c.storage.Cmix().GetGroup().GetPBytes()) primeSize := len(c.storage.Cmix().GetGroup().GetPBytes())
msg := format.NewMessage(primeSize) msg := format.NewMessage(primeSize)
if len(contents) > msg.ContentsSize() { if len(contents) > msg.ContentsSize() {
return format.Message{}, errors.New("Contents to long for cmix") return format.Message{}, errors.New("Contents to long for cmix")
} }
msg.SetContents(contents) msg.SetContents(contents)
msg.SetRecipientID(recipient)
return msg, nil return msg, nil
} }
...@@ -99,7 +99,6 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, ...@@ -99,7 +99,6 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader,
cmixMsg.SetKeyFP(fp) cmixMsg.SetKeyFP(fp)
cmixMsg.SetMac(mac) cmixMsg.SetMac(mac)
cmixMsg.SetContents(baseFmt.Marshal()) cmixMsg.SetContents(baseFmt.Marshal())
cmixMsg.SetRecipientID(partner.ID)
// fixme: channel can get into a bricked state if the first save occurs and // fixme: channel can get into a bricked state if the first save occurs and
// the second does not or the two occur and the storage into critical // the second does not or the two occur and the storage into critical
...@@ -127,7 +126,7 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader, ...@@ -127,7 +126,7 @@ func ConfirmRequestAuth(partner contact.Contact, rng io.Reader,
storage.GetCriticalRawMessages().AddProcessing(cmixMsg) storage.GetCriticalRawMessages().AddProcessing(cmixMsg)
/*send message*/ /*send message*/
round, err := net.SendCMIX(cmixMsg, params.GetDefaultCMIX()) round, _, err := net.SendCMIX(cmixMsg, partner.ID, params.GetDefaultCMIX())
if err != nil { if err != nil {
// if the send fails just set it to failed, it will but automatically // if the send fails just set it to failed, it will but automatically
// retried // retried
......
...@@ -132,7 +132,6 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader, ...@@ -132,7 +132,6 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader,
cmixMsg.SetKeyFP(requestfp) cmixMsg.SetKeyFP(requestfp)
cmixMsg.SetMac(mac) cmixMsg.SetMac(mac)
cmixMsg.SetContents(baseFmt.Marshal()) cmixMsg.SetContents(baseFmt.Marshal())
cmixMsg.SetRecipientID(partner.ID)
jww.INFO.Printf("PARTNER ID: %s", partner.ID) jww.INFO.Printf("PARTNER ID: %s", partner.ID)
/*store state*/ /*store state*/
...@@ -149,11 +148,11 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader, ...@@ -149,11 +148,11 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader,
//jww.INFO.Printf("CMIX MESSAGE 1: %s, %v, %v, %v", cmixMsg.GetRecipientID(), //jww.INFO.Printf("CMIX MESSAGE 1: %s, %v, %v, %v", cmixMsg.GetRecipientID(),
// cmixMsg.GetKeyFP(), cmixMsg.GetMac(), cmixMsg.GetContents()) // cmixMsg.GetKeyFP(), cmixMsg.GetMac(), cmixMsg.GetContents())
jww.INFO.Printf("CMIX MESSAGE FP: %s, %v", cmixMsg.GetRecipientID(), jww.INFO.Printf("CMIX MESSAGE FP: %s, %v", partner.ID,
cmixMsg.GetKeyFP()) cmixMsg.GetKeyFP())
/*send message*/ /*send message*/
round, err := net.SendCMIX(cmixMsg, params.GetDefaultCMIX()) round, _, err := net.SendCMIX(cmixMsg, partner.ID, params.GetDefaultCMIX())
if err != nil { if err != nil {
// if the send fails just set it to failed, it will but automatically // if the send fails just set it to failed, it will but automatically
// retried // retried
......
...@@ -30,26 +30,21 @@ import ( ...@@ -30,26 +30,21 @@ import (
// This will return the round the message was sent on if it is successfully sent // This will return the round the message was sent on if it is successfully sent
// This can be used to register a round event to learn about message delivery. // This can be used to register a round event to learn about message delivery.
// on failure a round id of -1 is returned // on failure a round id of -1 is returned
func (c *Client) SendCmix(recipient, contents []byte, parameters string) (int, error) { // todo- return the ephemeral ID
p, err := params.GetCMIXParameters(parameters) func (c *Client) SendCmix(recipient, contents []byte) (int, error) {
if err != nil {
return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v",
err))
}
u, err := id.Unmarshal(recipient) u, err := id.Unmarshal(recipient)
if err != nil { if err != nil {
return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v", return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v",
err)) err))
} }
msg, err := c.api.NewCMIXMessage(u, contents) msg, err := c.api.NewCMIXMessage(contents)
if err != nil { if err != nil {
return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v", return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v",
err)) err))
} }
rid, err := c.api.SendCMIX(msg, p) rid, _, err := c.api.SendCMIX(msg, u, params.GetDefaultCMIX())
if err != nil { if err != nil {
return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v", return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v",
err)) err))
...@@ -66,12 +61,7 @@ func (c *Client) SendCmix(recipient, contents []byte, parameters string) (int, e ...@@ -66,12 +61,7 @@ func (c *Client) SendCmix(recipient, contents []byte, parameters string) (int, e
// Message Types can be found in client/interfaces/message/type.go // Message Types can be found in client/interfaces/message/type.go
// Make sure to not conflict with ANY default message types with custom types // Make sure to not conflict with ANY default message types with custom types
func (c *Client) SendUnsafe(recipient, payload []byte, func (c *Client) SendUnsafe(recipient, payload []byte,
messageType int, parameters string) (*RoundList, error) { messageType int) (*RoundList, error) {
p, err := params.GetUnsafeParameters(parameters)
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v",
err))
}
u, err := id.Unmarshal(recipient) u, err := id.Unmarshal(recipient)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v", return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v",
...@@ -84,7 +74,7 @@ func (c *Client) SendUnsafe(recipient, payload []byte, ...@@ -84,7 +74,7 @@ func (c *Client) SendUnsafe(recipient, payload []byte,
MessageType: message.Type(messageType), MessageType: message.Type(messageType),
} }
rids, err := c.api.SendUnsafe(m, p) rids, err := c.api.SendUnsafe(m, params.GetDefaultUnsafe())
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v", return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v",
err)) err))
...@@ -99,12 +89,7 @@ func (c *Client) SendUnsafe(recipient, payload []byte, ...@@ -99,12 +89,7 @@ func (c *Client) SendUnsafe(recipient, payload []byte,
// //
// Message Types can be found in client/interfaces/message/type.go // Message Types can be found in client/interfaces/message/type.go
// Make sure to not conflict with ANY default message types // Make sure to not conflict with ANY default message types
func (c *Client) SendE2E(recipient, payload []byte, messageType int, parameters string) (*SendReport, error) { func (c *Client) SendE2E(recipient, payload []byte, messageType int) (*SendReport, error) {
p, err := params.GetE2EParameters(parameters)
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err))
}
u, err := id.Unmarshal(recipient) u, err := id.Unmarshal(recipient)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err)) return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err))
...@@ -116,7 +101,7 @@ func (c *Client) SendE2E(recipient, payload []byte, messageType int, parameters ...@@ -116,7 +101,7 @@ func (c *Client) SendE2E(recipient, payload []byte, messageType int, parameters
MessageType: message.Type(messageType), MessageType: message.Type(messageType),
} }
rids, mid, err := c.api.SendE2E(m, p) rids, mid, err := c.api.SendE2E(m, params.GetDefaultE2E())
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err)) return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err))
} }
......
...@@ -10,6 +10,7 @@ package message ...@@ -10,6 +10,7 @@ package message
import ( import (
"gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"time" "time"
) )
...@@ -18,6 +19,8 @@ type Receive struct { ...@@ -18,6 +19,8 @@ type Receive struct {
Payload []byte Payload []byte
MessageType Type MessageType Type
Sender *id.ID Sender *id.ID
RecipientID *id.ID
EphemeralID ephemeral.Id
Timestamp time.Time Timestamp time.Time
Encryption EncryptionType Encryption EncryptionType
} }
...@@ -15,12 +15,13 @@ import ( ...@@ -15,12 +15,13 @@ import (
"gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
) )
type NetworkManager interface { type NetworkManager interface {
SendE2E(m message.Send, p params.E2E) ([]id.Round, e2e.MessageID, error) SendE2E(m message.Send, p params.E2E) ([]id.Round, e2e.MessageID, error)
SendUnsafe(m message.Send, p params.Unsafe) ([]id.Round, error) SendUnsafe(m message.Send, p params.Unsafe) ([]id.Round, error)
SendCMIX(message format.Message, p params.CMIX) (id.Round, error) SendCMIX(message format.Message, recipient *id.ID, p params.CMIX) (id.Round, ephemeral.Id, error)
GetInstance() *network.Instance GetInstance() *network.Instance
GetHealthTracker() HealthTracker GetHealthTracker() HealthTracker
Follow() (stoppable.Stoppable, error) Follow() (stoppable.Stoppable, error)
......
...@@ -26,6 +26,7 @@ import ( ...@@ -26,6 +26,7 @@ import (
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"testing" "testing"
"time" "time"
...@@ -76,9 +77,9 @@ func (t *testNetworkManagerGeneric) SendUnsafe(m message.Send, p params.Unsafe) ...@@ -76,9 +77,9 @@ func (t *testNetworkManagerGeneric) SendUnsafe(m message.Send, p params.Unsafe)
return nil, nil return nil, nil
} }
func (t *testNetworkManagerGeneric) SendCMIX(message format.Message, p params.CMIX) (id.Round, error) { func (t *testNetworkManagerGeneric) SendCMIX(message format.Message, rid *id.ID, p params.CMIX) (id.Round, ephemeral.Id, error) {
return id.Round(0), nil return id.Round(0), ephemeral.Id{}, nil
} }
...@@ -183,9 +184,9 @@ func (t *testNetworkManagerFullExchange) SendUnsafe(m message.Send, p params.Uns ...@@ -183,9 +184,9 @@ func (t *testNetworkManagerFullExchange) SendUnsafe(m message.Send, p params.Uns
return nil, nil return nil, nil
} }
func (t *testNetworkManagerFullExchange) SendCMIX(message format.Message, p params.CMIX) (id.Round, error) { func (t *testNetworkManagerFullExchange) SendCMIX(message format.Message, eid *id.ID, p params.CMIX) (id.Round, ephemeral.Id, error) {
return id.Round(0), nil return id.Round(0), ephemeral.Id{}, nil
} }
......
...@@ -85,7 +85,7 @@ func (m *Manager) criticalMessages() { ...@@ -85,7 +85,7 @@ func (m *Manager) criticalMessages() {
for msg, has := critRawMsgs.Next(); has; msg, has = critRawMsgs.Next() { for msg, has := critRawMsgs.Next(); has; msg, has = critRawMsgs.Next() {
go func(msg format.Message) { go func(msg format.Message) {
//send the message //send the message
round, err := m.SendCMIX(msg, param) round, _, err := m.SendCMIX(msg, m.Uid, param)
//if the message fail to send, notify the buffer so it can be handled //if the message fail to send, notify the buffer so it can be handled
//in the future and exit //in the future and exit
if err != nil { if err != nil {
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"time" "time"
) )
...@@ -72,10 +73,16 @@ func (m *Manager) handleMessage(ecrMsg format.Message) { ...@@ -72,10 +73,16 @@ func (m *Manager) handleMessage(ecrMsg format.Message) {
// if it doesnt match any form of encrypted, hear it as a raw message // if it doesnt match any form of encrypted, hear it as a raw message
// and add it to garbled messages to be handled later // and add it to garbled messages to be handled later
msg = ecrMsg msg = ecrMsg
ephID, err := ephemeral.Marshal(msg.GetEphemeralRID())
if err!=nil{
jww.DEBUG.Printf("Failed to unmarshal ephemeral ID " +
"on unknown message: %+v", err)
}
raw := message.Receive{ raw := message.Receive{
Payload: msg.Marshal(), Payload: msg.Marshal(),
MessageType: message.Raw, MessageType: message.Raw,
Sender: msg.GetRecipientID(), Sender: nil,
EphemeralID: ephID,
Timestamp: time.Time{}, Timestamp: time.Time{},
Encryption: message.None, Encryption: message.None,
} }
......
...@@ -14,10 +14,12 @@ import ( ...@@ -14,10 +14,12 @@ import (
"gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/crypto/fingerprint"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/states" "gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"strings" "strings"
"time" "time"
) )
...@@ -33,7 +35,7 @@ const sendTimeBuffer = uint64(100 * time.Millisecond) ...@@ -33,7 +35,7 @@ const sendTimeBuffer = uint64(100 * time.Millisecond)
// If the message is successfully sent, the id of the round sent it is returned, // If the message is successfully sent, the id of the round sent it is returned,
// which can be registered with the network instance to get a callback on // which can be registered with the network instance to get a callback on
// its status // its status
func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, error) { func (m *Manager) SendCMIX(msg format.Message, recipient *id.ID, param params.CMIX) (id.Round, ephemeral.Id, error) {
timeStart := time.Now() timeStart := time.Now()
attempted := set.New() attempted := set.New()
...@@ -42,7 +44,7 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err ...@@ -42,7 +44,7 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err
elapsed := time.Now().Sub(timeStart) elapsed := time.Now().Sub(timeStart)
jww.DEBUG.Printf("SendCMIX Send Attempt %d", numRoundTries+1) jww.DEBUG.Printf("SendCMIX Send Attempt %d", numRoundTries+1)
if elapsed > param.Timeout { if elapsed > param.Timeout {
return 0, errors.New("Sending cmix message timed out") return 0, ephemeral.Id{}, errors.New("Sending cmix message timed out")
} }
remainingTime := param.Timeout - elapsed remainingTime := param.Timeout - elapsed
jww.TRACE.Printf("SendCMIX GetUpcommingRealtime") jww.TRACE.Printf("SendCMIX GetUpcommingRealtime")
...@@ -59,6 +61,22 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err ...@@ -59,6 +61,22 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err
continue continue
} }
//set the ephemeral ID
ephID, _, _, err := ephemeral.GetId(recipient,
uint(bestRound.AddressSpaceSize),
int64(bestRound.Timestamps[states.REALTIME]))
msg.SetEphemeralRID(ephID[:])
//set the identity fingerprint
ifp, err := fingerprint.IdentityFP(msg.GetContents(), recipient)
if err!=nil{
jww.FATAL.Panicf("failed to generate the Identity " +
"fingerprint due to unrecoverable error: %+v", err)
}
msg.SetIdentityFP(ifp)
//build the topology //build the topology
idList, err := id.NewIDListFromBytes(bestRound.Topology) idList, err := id.NewIDListFromBytes(bestRound.Topology)
if err != nil { if err != nil {
...@@ -94,10 +112,10 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err ...@@ -94,10 +112,10 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err
stream.Close() stream.Close()
if err != nil { if err != nil {
return 0, errors.WithMessage(err, "Failed to generate "+ return 0, ephemeral.Id{}, errors.WithMessage(err,
"salt, this should never happen") "Failed to generate salt, this should never happen")
} }
jww.INFO.Printf("RECIPIENTIDPRE_ENCRYPT: %s", msg.GetRecipientID())
encMsg, kmacs := roundKeys.Encrypt(msg, salt) encMsg, kmacs := roundKeys.Encrypt(msg, salt)
//build the message payload //build the message payload
...@@ -115,7 +133,8 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err ...@@ -115,7 +133,8 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err
RoundID: bestRound.ID, RoundID: bestRound.ID,
} }
//Add the mac proving ownership //Add the mac proving ownership
msg.MAC = roundKeys.MakeClientGatewayKey(salt, network.GenerateSlotDigest(msg)) msg.MAC = roundKeys.MakeClientGatewayKey(salt,
network.GenerateSlotDigest(msg))
//add the round on to the list of attempted so it is not tried again //add the round on to the list of attempted so it is not tried again
attempted.Insert(bestRound) attempted.Insert(bestRound)
...@@ -134,11 +153,11 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err ...@@ -134,11 +153,11 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err
jww.ERROR.Printf("Failed to send message to %s: %s", jww.ERROR.Printf("Failed to send message to %s: %s",
transmitGateway, err) transmitGateway, err)
} else if gwSlotResp.Accepted { } else if gwSlotResp.Accepted {
return id.Round(bestRound.ID), nil return id.Round(bestRound.ID), ephID, nil
} }
} }
return 0, errors.New("failed to send the message") return 0, ephemeral.Id{}, errors.New("failed to send the message")
} }
// Signals to the node registration thread to register a node if keys are // Signals to the node registration thread to register a node if keys are
......
...@@ -51,7 +51,6 @@ func (m *Manager) SendE2E(msg message.Send, param params.E2E) ([]id.Round, e2e.M ...@@ -51,7 +51,6 @@ func (m *Manager) SendE2E(msg message.Send, param params.E2E) ([]id.Round, e2e.M
//create the cmix message //create the cmix message
msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen()) msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen())
msgCmix.SetContents(p) msgCmix.SetContents(p)
msgCmix.SetRecipientID(msg.Recipient)
//get a key to end to end encrypt //get a key to end to end encrypt
key, err := partner.GetKeyForSending(param.Type) key, err := partner.GetKeyForSending(param.Type)
...@@ -67,7 +66,7 @@ func (m *Manager) SendE2E(msg message.Send, param params.E2E) ([]id.Round, e2e.M ...@@ -67,7 +66,7 @@ func (m *Manager) SendE2E(msg message.Send, param params.E2E) ([]id.Round, e2e.M
wg.Add(1) wg.Add(1)
go func(i int) { go func(i int) {
var err error var err error
roundIds[i], err = m.SendCMIX(msgEnc, param.CMIX) roundIds[i], _, err = m.SendCMIX(msgEnc, msg.Recipient, param.CMIX)
if err != nil { if err != nil {
errCh <- err errCh <- err
} }
......
...@@ -51,12 +51,11 @@ func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round, ...@@ -51,12 +51,11 @@ func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round,
for i, p := range partitions { for i, p := range partitions {
msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen()) msgCmix := format.NewMessage(m.Session.Cmix().GetGroup().GetP().ByteLen())
msgCmix.SetContents(p) msgCmix.SetContents(p)
msgCmix.SetRecipientID(msg.Recipient)
e2e.SetUnencrypted(msgCmix, m.Session.User().GetCryptographicIdentity().GetTransmissionID()) e2e.SetUnencrypted(msgCmix, m.Session.User().GetCryptographicIdentity().GetTransmissionID())
wg.Add(1) wg.Add(1)
go func(i int) { go func(i int) {
var err error var err error
roundIds[i], err = m.SendCMIX(msgCmix, param.CMIX) roundIds[i], _, err = m.SendCMIX(msgCmix, msg.Recipient, param.CMIX)
if err != nil { if err != nil {
errCh <- err errCh <- err
} }
......
...@@ -15,19 +15,20 @@ import ( ...@@ -15,19 +15,20 @@ import (
"gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
) )
// SendCMIX sends a "raw" CMIX message payload to the provided // SendCMIX sends a "raw" CMIX message payload to the provided
// recipient. Note that both SendE2E and SendUnsafe call SendCMIX. // recipient. Note that both SendE2E and SendUnsafe call SendCMIX.
// Returns the round ID of the round the payload was sent or an error // Returns the round ID of the round the payload was sent or an error
// if it fails. // if it fails.
func (m *manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, error) { func (m *manager) SendCMIX(msg format.Message, recipient *id.ID, param params.CMIX) (id.Round, ephemeral.Id, error) {
if !m.Health.IsHealthy() { if !m.Health.IsHealthy() {
return 0, errors.New("Cannot send cmix message when the " + return 0, ephemeral.Id{}, errors.New("Cannot send cmix message when the " +
"network is not healthy") "network is not healthy")
} }
return m.message.SendCMIX(msg, param) return m.message.SendCMIX(msg, recipient, param)
} }
// SendUnsafe sends an unencrypted payload to the provided recipient // SendUnsafe sends an unencrypted payload to the provided recipient
......
...@@ -26,7 +26,9 @@ type IdentityUse struct{ ...@@ -26,7 +26,9 @@ type IdentityUse struct{
KR KnownRounds KR KnownRounds
} }
func (iu IdentityUse)SetSamplingPeriod(rng io.Reader)(IdentityUse, error){ // setSamplingPeriod add the Request mask as a random buffer around the sampling
// time to obfuscate it
func (iu IdentityUse)setSamplingPeriod(rng io.Reader)(IdentityUse, error){
//generate the seed //generate the seed
seed := make([]byte,32) seed := make([]byte,32)
...@@ -36,18 +38,17 @@ func (iu IdentityUse)SetSamplingPeriod(rng io.Reader)(IdentityUse, error){ ...@@ -36,18 +38,17 @@ func (iu IdentityUse)SetSamplingPeriod(rng io.Reader)(IdentityUse, error){
} }
h, err := hash.NewCMixHash() h, err := hash.NewCMixHash()
if err==nil{ if err!=nil{
return IdentityUse{}, err return IdentityUse{}, err
} }
//calculate the period offset //calculate the period offset
periodOffset := periodOffset :=
randomness.RandInInterval(big.NewInt(iu.RequestMask.Nanoseconds()), randomness.RandInInterval(big.NewInt(iu.RequestMask.Nanoseconds()),
seed,h).Uint64() seed,h).Int64()
iu.StartRequest = iu.StartValid.Add(-time.Duration(periodOffset)* iu.StartRequest = iu.StartValid.Add(-time.Duration(periodOffset))
time.Nanosecond)
iu.EndRequest = iu.EndValid.Add(iu.RequestMask - iu.EndRequest = iu.EndValid.Add(iu.RequestMask -
time.Duration(periodOffset)*time.Nanosecond) time.Duration(periodOffset))
return iu, nil return iu, nil
} }
......
...@@ -8,7 +8,10 @@ import ( ...@@ -8,7 +8,10 @@ import (
"time" "time"
) )
func generateFakeIdentity(rng io.Reader, idSize uint)(IdentityUse, error){ // generateFakeIdentity generates a fake identity of the given size with the
// given random number generator
func generateFakeIdentity(rng io.Reader, idSize uint, now time.Time)(IdentityUse, error){
//randomly generate an identity
randIDbytes := make([]byte, id.ArrIDLen-1) randIDbytes := make([]byte, id.ArrIDLen-1)
if _, err := rng.Read(randIDbytes); err!=nil{ if _, err := rng.Read(randIDbytes); err!=nil{
return IdentityUse{}, errors.WithMessage(err, "failed to " + return IdentityUse{}, errors.WithMessage(err, "failed to " +
...@@ -19,8 +22,9 @@ func generateFakeIdentity(rng io.Reader, idSize uint)(IdentityUse, error){ ...@@ -19,8 +22,9 @@ func generateFakeIdentity(rng io.Reader, idSize uint)(IdentityUse, error){
copy(randID[:id.ArrIDLen-1], randIDbytes) copy(randID[:id.ArrIDLen-1], randIDbytes)
randID.SetType(id.User) randID.SetType(id.User)
//generate the current ephemeral ID from the random identity
ephID, start, end, err := ephemeral.GetId(randID, idSize, ephID, start, end, err := ephemeral.GetId(randID, idSize,
time.Now().UnixNano()) now.UnixNano())
if err!=nil{ if err!=nil{
return IdentityUse{}, errors.WithMessage(err, "failed to " + return IdentityUse{}, errors.WithMessage(err, "failed to " +
"generate an ephemral ID for random identity when none is " + "generate an ephemral ID for random identity when none is " +
......
package reception
import (
"encoding/json"
"math/rand"
"testing"
"time"
)
//tests Generate Fake identity is consistant and returns a correct result
func TestGenerateFakeIdentity(t *testing.T) {
rng := rand.New(rand.NewSource(42))
expected:= "{\"EphId\":[0,0,0,0,0,0,46,197],"+
"\"Source\":[83,140,127,150,177,100,191,27,151,187,159,75,180,114,"+
"232,159,91,20,132,242,82,9,201,217,52,62,146,186,9,221,157,82,3],"+
"\"End\":\"2009-11-17T13:43:23.759765625-08:00\",\"ExtraChecks\":0,"+
"\"StartValid\":\"2009-11-16T13:43:23.759765625-08:00\"," +
"\"EndValid\":\"2009-11-17T13:43:23.759765625-08:00\"," +
"\"RequestMask\":86400000000000,\"Ephemeral\":true,"+
"\"StartRequest\":\"0001-01-01T00:00:00Z\"," +
"\"EndRequest\":\"0001-01-01T00:00:00Z\",\"Fake\":true,\"KR\":null}"
timestamp := time.Date(2009, 11, 17, 20,
34, 58, 651387237, time.UTC)
received, err := generateFakeIdentity(rng, 15, timestamp)
if err!=nil{
t.Errorf("Generate fake identity returned an unexpected " +
"error: %+v", err )
}
receivedJson, _ := json.Marshal(received)
if expected!=string(receivedJson){
t.Errorf("The fake identity was generated incorrectly\n " +
"Expected: %s,\n Received: %s", expected, receivedJson)
}
}
\ No newline at end of file
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/id/ephemeral"
"strconv"
"time" "time"
) )
...@@ -80,6 +81,6 @@ func (i Identity)calculateKrSize()int{ ...@@ -80,6 +81,6 @@ func (i Identity)calculateKrSize()int{
} }
func (i *Identity)String()string{ func (i *Identity)String()string{
return string(i.EphId.Int64()) + " " + i.String() return strconv.FormatInt(i.EphId.Int64(), 16) + " " + i.Source.String()
} }
package reception
import (
"math/rand"
"testing"
"time"
)
func TestIdentityUse_SetSamplingPeriod(t *testing.T) {
rng := rand.New(rand.NewSource(42))
const numTests = 1000
for i:=0;i<numTests;i++{
//generate an identity use
start := randate()
end := start.Add(time.Duration(rand.Uint64()%uint64(92*time.Hour)))
mask := time.Duration(rand.Uint64()%uint64(92*time.Hour))
iu := IdentityUse{
Identity: Identity{
StartValid: start,
EndValid: end,
RequestMask: mask,
},
}
//generate the sampling period
var err error
iu, err = iu.setSamplingPeriod(rng)
if err!=nil{
t.Errorf("Errored in generatign sampling " +
"period on interation %v: %+v", i, err)
}
//test that the range between the periods is correct
resultRange := iu.EndRequest.Sub(iu.StartRequest)
expectedRange := iu.EndValid.Sub(iu.StartValid) + iu.RequestMask
if resultRange != expectedRange {
t.Errorf("The generated sampling period is of the wrong " +
"size: Expecterd: %s, Received: %s", expectedRange, resultRange)
}
//test the sampling range does not exceed a reasonable lower bound
lowerBound := iu.StartValid.Add(-iu.RequestMask)
if !iu.StartRequest.After(lowerBound){
t.Errorf("Start request exceeds the reasonable lower " +
"bound: \n\t Bound: %s\n\t Start: %s", lowerBound, iu.StartValid)
}
//test the sampling range does not exceed a reasonable upper bound
upperBound := iu.EndValid.Add(iu.RequestMask-time.Millisecond)
if iu.EndRequest.After(upperBound){
t.Errorf("End request exceeds the reasonable upper bound")
}
}
}
func randate() time.Time {
min := time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
max := time.Date(2070, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
delta := max - min
sec := rand.Int63n(delta) + min
return time.Unix(sec, 0)
}
\ No newline at end of file
...@@ -5,12 +5,13 @@ import ( ...@@ -5,12 +5,13 @@ import (
"gitlab.com/elixxir/ekv" "gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/id/ephemeral"
"math/rand"
"reflect" "reflect"
"testing" "testing"
"time" "time"
) )
func TestIdentityEncodeDecode(t *testing.T) { func TestIdentity_EncodeDecode(t *testing.T) {
kv := versioned.NewKV(make(ekv.Memstore)) kv := versioned.NewKV(make(ekv.Memstore))
r := Identity{ r := Identity{
...@@ -38,7 +39,7 @@ func TestIdentityEncodeDecode(t *testing.T) { ...@@ -38,7 +39,7 @@ func TestIdentityEncodeDecode(t *testing.T) {
} }
} }
func TestIdentityDelete(t *testing.T) { func TestIdentity_Delete(t *testing.T) {
kv := versioned.NewKV(make(ekv.Memstore)) kv := versioned.NewKV(make(ekv.Memstore))
r := Identity{ r := Identity{
...@@ -66,3 +67,40 @@ func TestIdentityDelete(t *testing.T) { ...@@ -66,3 +67,40 @@ func TestIdentityDelete(t *testing.T) {
t.Errorf("Load after delete succeded") t.Errorf("Load after delete succeded")
} }
} }
func TestIdentity_String(t *testing.T) {
rng := rand.New(rand.NewSource(42))
timestamp := time.Date(2009, 11, 17, 20,
34, 58, 651387237, time.UTC)
received, _ := generateFakeIdentity(rng, 15, timestamp)
expected := "-1763 U4x/lrFkvxuXu59LtHLon1sUhPJSCcnZND6SugndnVID"
s := received.String()
if s != expected{
t.Errorf("String did not return the correct value: " +
"\n\t Expected: %s\n\t Received: %s", expected, s)
}
}
func TestIdentity_CalculateKrSize(t *testing.T){
deltas := []time.Duration{0, 2*time.Second, 2*time.Hour, 36*time.Hour,
time.Duration(rand.Uint32())*time.Millisecond}
for _, d := range deltas {
expected := int(d.Seconds()+1)*maxRoundsPerSecond
now := time.Now()
id := Identity{
StartValid: now,
EndValid: now.Add(d),
}
krSize := id.calculateKrSize()
if krSize != expected{
t.Errorf("kr size not correct! expected: %v, recieved: %v",
expected, krSize)
}
}
}
\ No newline at end of file
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"gitlab.com/elixxir/primitives/knownRounds" "gitlab.com/elixxir/primitives/knownRounds"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/id/ephemeral"
"strconv"
"time" "time"
) )
...@@ -111,5 +112,6 @@ func (r registration)getKR()KnownRounds{ ...@@ -111,5 +112,6 @@ func (r registration)getKR()KnownRounds{
} }
func regPrefix(EphId ephemeral.Id, Source *id.ID)string{ func regPrefix(EphId ephemeral.Id, Source *id.ID)string{
return "receptionRegistration_" + string(EphId.Int64()) + Source.String() return "receptionRegistration_" +
strconv.FormatInt(EphId.Int64(), 16) + Source.String()
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment