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

added unsafe sending to e2e

parent 9d949299
No related branches found
No related tags found
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
......@@ -28,6 +28,8 @@ type Handler interface {
// on, a unique ID for the message, and the timestamp sent on.
// the recipient must already have an e2e relationship, otherwise an error
// will be returned.
// Will return an error if the network is not healthy or in the event of
// a failed send
SendE2E(mt catalog.MessageType, recipient *id.ID, payload []byte,
params Params) ([]id.Round, e2e.MessageID, time.Time, error)
......@@ -120,4 +122,22 @@ type Handler interface {
// RemoveService removes all services for the given tag
RemoveService(tag string) error
/* === Unsafe =========================================================== */
// SendUnsafe sends a message without encryption. It breaks both privacy
// and security. It does partition the message. It should ONLY be used for
// debugging.
// It does not respect service tags in the parameters and sends all
// messages with "Silent" and "E2E" tags.
// It does not support critical messages.
// It does not check that an e2e relationship exists with the recipient
// Will return an error if the network is not healthy or in the event of
// a failed send
SendUnsafe(mt catalog.MessageType, recipient *id.ID,
payload []byte, params Params) ([]id.Round, time.Time, error)
// EnableUnsafeReception enables the reception of unsafe message by
// registering bespoke services for reception. For debugging only!
EnableUnsafeReception()
}
......@@ -8,6 +8,7 @@ import (
"gitlab.com/elixxir/client/e2e/rekey"
"gitlab.com/elixxir/client/event"
"gitlab.com/elixxir/client/network"
"gitlab.com/elixxir/client/network/message"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic"
......@@ -87,3 +88,22 @@ func (m *manager) StartProcesses() (stoppable.Stoppable, error) {
return multi, nil
}
// EnableUnsafeReception enables the reception of unsafe message by registering
// bespoke services for reception. For debugging only!
func (m *manager) EnableUnsafeReception() {
m.net.AddService(m.myID, message.Service{
Identifier: m.myID[:],
Tag: ratchet.Silent,
}, &UnsafeProcessor{
m: m,
tag: ratchet.Silent,
})
m.net.AddService(m.myID, message.Service{
Identifier: m.myID[:],
Tag: ratchet.E2e,
}, &UnsafeProcessor{
m: m,
tag: ratchet.E2e,
})
}
......@@ -71,12 +71,13 @@ func (m *manager) sendE2E(mt catalog.MessageType, recipient *id.ID,
"message, no relationship found with %s", recipient)
}
//return the rounds if everything send successfully
//Generate the message ID
msgID := e2e.NewMessageID(partner.GetSendRelationshipFingerprint(),
internalMsgId)
wg := sync.WaitGroup{}
//handle sending for each partition
for i, p := range partitions {
if mt != catalog.KeyExchangeTrigger {
// check if any rekeys need to happen and trigger them
......
package e2e
import (
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/e2e/ratchet"
"gitlab.com/elixxir/client/network/message"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime"
"sync"
"time"
)
func (m *manager) SendUnsafe(mt catalog.MessageType, recipient *id.ID,
payload []byte, params Params) ([]id.Round, time.Time, error) {
//check if the network is healthy
if !m.net.IsHealthy() {
return nil, time.Time{}, errors.New("cannot " +
"sendE2E when network is not healthy")
}
return m.sendUnsafe(mt, recipient, payload, params)
}
func (m *manager) sendUnsafe(mt catalog.MessageType, recipient *id.ID,
payload []byte, params Params) ([]id.Round, time.Time, error) {
//timestamp the message
ts := netTime.Now()
//partition the message
partitions, _, err := m.partitioner.Partition(recipient, mt, ts,
payload)
if err != nil {
return nil, time.Time{}, errors.WithMessage(err, "failed to send unsafe message")
}
jww.WARN.Printf("unsafe sending %d messages to %s. Unsafe sends "+
"are unencrypted, only use for debugging",
len(partitions), recipient)
//encrypt then send the partitions over cmix
roundIds := make([]id.Round, len(partitions))
errCh := make(chan error, len(partitions))
wg := sync.WaitGroup{}
//handle sending for each partition
for i, p := range partitions {
//set up the service tags
srvc := message.Service{
Identifier: recipient[:],
}
if i == len(partitions)-1 {
srvc.Tag = ratchet.Silent
} else {
srvc.Tag = ratchet.E2e
}
//send the cmix message, each partition in its own thread
wg.Add(1)
go func(i int, payload []byte) {
unencryptedMAC, fp := e2e.SetUnencrypted(payload, m.myID)
var err error
roundIds[i], _, err = m.net.SendCMIX(recipient, fp,
srvc, payload, unencryptedMAC, params.CMIX)
if err != nil {
errCh <- err
}
wg.Done()
}(i, p)
}
wg.Wait()
//see if any parts failed to send
numFail, errRtn := getSendErrors(errCh)
if numFail > 0 {
jww.INFO.Printf("Failed to unsafe send %d/%d to %s",
numFail, len(partitions), recipient)
return nil, time.Time{}, errors.Errorf("Failed to unsafe send %v/%v sub payloads:"+
" %s", numFail, len(partitions), errRtn)
} else {
jww.INFO.Printf("Successfully Unsafe Send %d/%d to %s",
len(partitions)-numFail, len(partitions), recipient)
}
//return the rounds if everything send successfully
jww.INFO.Printf("Successful Unsafe Send of %d messages to %s",
len(partitions), recipient)
return roundIds, ts, nil
}
package e2e
import (
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/network/historical"
"gitlab.com/elixxir/client/network/identity/receptionID"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/primitives/format"
)
type UnsafeProcessor struct {
m *manager
tag string
}
func (up *UnsafeProcessor) Process(ecrMsg format.Message, receptionID receptionID.EphemeralIdentity,
round historical.Round) {
//check if the message is unencrypted
unencrypted, sender := e2e.IsUnencrypted(ecrMsg)
if !unencrypted {
jww.ERROR.Printf("Received a non unencrypted message in e2e "+
"service %s, A message might have dropped!", up.tag)
}
//Parse
message, done := up.m.partitioner.HandlePartition(sender,
ecrMsg.GetContents(), nil)
if done {
message.RecipientID = receptionID.Source
message.EphemeralID = receptionID.EphId
message.Round = round
message.Encrypted = false
up.m.Switchboard.Speak(message)
}
}
......@@ -13,7 +13,7 @@ require (
github.com/spf13/viper v1.7.1
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20220308183624-c2183e687a03
gitlab.com/elixxir/crypto v0.0.7-0.20220328164108-c72388181116
gitlab.com/elixxir/crypto v0.0.7-0.20220331001626-1829e71edf56
gitlab.com/elixxir/ekv v0.1.6
gitlab.com/elixxir/primitives v0.0.3-0.20220330212736-cce83b5f948f
gitlab.com/xx_network/comms v0.0.4-0.20220311192415-d95fe8906580
......
......@@ -287,6 +287,10 @@ gitlab.com/elixxir/crypto v0.0.7-0.20220328163237-3bdc3e1369ca h1:jPhotwqZFJYHR4
gitlab.com/elixxir/crypto v0.0.7-0.20220328163237-3bdc3e1369ca/go.mod h1:tD6XjtQh87T2nKZL5I/pYPck5M2wLpkZ1Oz7H/LqO10=
gitlab.com/elixxir/crypto v0.0.7-0.20220328164108-c72388181116 h1:HvMO//NbadCiKGI10cdW98WimYf0YIudzQeUznYAgRQ=
gitlab.com/elixxir/crypto v0.0.7-0.20220328164108-c72388181116/go.mod h1:tD6XjtQh87T2nKZL5I/pYPck5M2wLpkZ1Oz7H/LqO10=
gitlab.com/elixxir/crypto v0.0.7-0.20220330235853-295c470e0e62 h1:t0cy5vu9m32Vq/pPAGjXLzMp9AceIlc+DSM4fyL1SLQ=
gitlab.com/elixxir/crypto v0.0.7-0.20220330235853-295c470e0e62/go.mod h1:JkByWX/TXCjdu6pRJsx+jwttbBGvlAljYSJMImDmt+4=
gitlab.com/elixxir/crypto v0.0.7-0.20220331001626-1829e71edf56 h1:1HJHlRwh3dDbvw3qIK17jK5R6W87S4tz/gkJT8aMLKQ=
gitlab.com/elixxir/crypto v0.0.7-0.20220331001626-1829e71edf56/go.mod h1:JkByWX/TXCjdu6pRJsx+jwttbBGvlAljYSJMImDmt+4=
gitlab.com/elixxir/ekv v0.1.6 h1:M2hUSNhH/ChxDd+s8xBqSEKgoPtmE6hOEBqQ73KbN6A=
gitlab.com/elixxir/ekv v0.1.6/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4=
gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg=
......
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