Skip to content
Snippets Groups Projects
Commit e8875de6 authored by Jonah Husson's avatar Jonah Husson
Browse files

Fix garbled message bug

parent 67f70846
No related branches found
No related tags found
2 merge requests!170Release,!120Add 0 byte to message contents
......@@ -57,65 +57,72 @@ func (m *Manager) handleGarbledMessages() {
var failedMsgs []format.Message
//try to decrypt every garbled message, excising those who's counts are too high
for grbldMsg, count, timestamp, has := garbledMsgs.Next(); has; grbldMsg, count, timestamp, has = garbledMsgs.Next() {
fingerprint := grbldMsg.GetKeyFP()
// Check if the key is there, process it if it is
if key, isE2E := e2eKv.PopKey(fingerprint); isE2E {
jww.INFO.Printf("[GARBLE] Check E2E for %s, KEYFP: %s",
grbldMsg.Digest(), grbldMsg.GetKeyFP())
// Decrypt encrypted message
msg, err := key.Decrypt(grbldMsg)
if err == nil {
// get the sender
sender := key.GetSession().GetPartner()
//remove from the buffer if decryption is successful
garbledMsgs.Remove(grbldMsg)
//if it exists, check against all in the list
modifiedContents := append([]byte{0}, grbldMsg.GetContents()...)
identity := m.Session.GetUser().GetContact().ID
_, forMe, _ := m.Session.GetEdge().Check(identity, grbldMsg.GetIdentityFP(), modifiedContents)
if forMe {
fingerprint := grbldMsg.GetKeyFP()
// Check if the key is there, process it if it is
if key, isE2E := e2eKv.PopKey(fingerprint); isE2E {
jww.INFO.Printf("[GARBLE] Check E2E for %s, KEYFP: %s",
grbldMsg.Digest(), grbldMsg.GetKeyFP())
// Decrypt encrypted message
msg, err := key.Decrypt(grbldMsg)
if err == nil {
// get the sender
sender := key.GetSession().GetPartner()
//remove from the buffer if decryption is successful
garbledMsgs.Remove(grbldMsg)
jww.INFO.Printf("[GARBLE] message decoded as E2E from "+
"%s, msgDigest: %s", sender, grbldMsg.Digest())
jww.INFO.Printf("[GARBLE] message decoded as E2E from "+
"%s, msgDigest: %s", sender, grbldMsg.Digest())
//handle the successfully decrypted message
xxMsg, ok := m.partitioner.HandlePartition(sender, message.E2E,
msg.GetContents(),
key.GetSession().GetRelationshipFingerprint())
if ok {
m.Switchboard.Speak(xxMsg)
continue
}
}
} else {
// todo: figure out how to get the ephermal reception id in here.
// we have the raw data, but do not know what address space was
// used int he round
// todo: figure out how to get the round id, the recipient id, and the round timestamp
/*
ephid, err := ephemeral.Marshal(garbledMsg.GetEphemeralRID())
if err!=nil{
jww.WARN.Printf("failed to get the ephemeral id for a garbled " +
"message, clearing the message: %+v", err)
garbledMsgs.Remove(garbledMsg)
continue
//handle the successfully decrypted message
xxMsg, ok := m.partitioner.HandlePartition(sender, message.E2E,
msg.GetContents(),
key.GetSession().GetRelationshipFingerprint())
if ok {
m.Switchboard.Speak(xxMsg)
continue
}
}
} else {
// todo: figure out how to get the ephermal reception id in here.
// we have the raw data, but do not know what address space was
// used int he round
// todo: figure out how to get the round id, the recipient id, and the round timestamp
/*
ephid, err := ephemeral.Marshal(garbledMsg.GetEphemeralRID())
if err!=nil{
jww.WARN.Printf("failed to get the ephemeral id for a garbled " +
"message, clearing the message: %+v", err)
garbledMsgs.Remove(garbledMsg)
continue
}
ephid.Clear(m.)*/
ephid.Clear(m.)*/
raw := message.Receive{
Payload: grbldMsg.Marshal(),
MessageType: message.Raw,
Sender: &id.ID{},
EphemeralID: ephemeral.Id{},
Timestamp: time.Time{},
Encryption: message.None,
RecipientID: &id.ID{},
RoundId: 0,
RoundTimestamp: time.Time{},
raw := message.Receive{
Payload: grbldMsg.Marshal(),
MessageType: message.Raw,
Sender: &id.ID{},
EphemeralID: ephemeral.Id{},
Timestamp: time.Time{},
Encryption: message.None,
RecipientID: &id.ID{},
RoundId: 0,
RoundTimestamp: time.Time{},
}
im := fmt.Sprintf("[GARBLE] RAW Message reprecessed: keyFP: %v, "+
"msgDigest: %s", grbldMsg.GetKeyFP(), grbldMsg.Digest())
jww.INFO.Print(im)
m.Internal.Events.Report(1, "MessageReception", "Garbled", im)
m.Session.GetGarbledMessages().Add(grbldMsg)
m.Switchboard.Speak(raw)
}
im := fmt.Sprintf("[GARBLE] RAW Message reprecessed: keyFP: %v, "+
"msgDigest: %s", grbldMsg.GetKeyFP(), grbldMsg.Digest())
jww.INFO.Print(im)
m.Internal.Events.Report(1, "MessageReception", "Garbled", im)
m.Session.GetGarbledMessages().Add(grbldMsg)
m.Switchboard.Speak(raw)
}
// fail the message if any part of the decryption fails,
// unless it is the last attempts and has been in the buffer long
// enough, in which case remove it
......
......@@ -71,7 +71,10 @@ func (m *Manager) handleMessage(ecrMsg format.Message, bundle Bundle, edge *edge
"check: %v (expected-default) vs %v (received)", identity.EphId,
identity.Source, expectedFP, ecrMsg.GetIdentityFP())
}
im := fmt.Sprintf("Garbled/RAW Message: keyFP: %v, round: %d"+
"msgDigest: %s, not determined to be for client", msg.GetKeyFP(), bundle.Round, msg.Digest())
m.Internal.Events.Report(1, "MessageReception", "Garbled", im)
m.Session.GetGarbledMessages().Add(msg)
return
}
......
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