Commit 386fd751 authored by Matthieu Tanon's avatar Matthieu Tanon
Browse files

Reject incoming message if decryption failed or if sender authentication failed

parent 7df2dbc9
......@@ -327,7 +327,10 @@ ChatMessageModifier::Result LimeV2::processIncomingMessage (const shared_ptr<Cha
lError() << e.what() << " while decrypting message";
}
if (peerDeviceStatus == lime::PeerDeviceStatus::fail) lError() << "Failed to decrypt message from " << senderDeviceId;
if (peerDeviceStatus == lime::PeerDeviceStatus::fail) {
lError() << "Failed to decrypt message from " << senderDeviceId;
return ChatMessageModifier::Result::Error;
}
// Prepare decrypted message for next modifier
string plainMessageString(plainMessage.begin(), plainMessage.end());
......
......@@ -169,6 +169,16 @@ ChatMessageModifier::Result CpimChatMessageModifier::decode (const shared_ptr<Ch
if (dateTimeHeader)
message->getPrivate()->setTime(dateTimeHeader->getTime());
if (cpimFromAddress.isValid() && (cpimFromAddress == message->getAuthenticatedFromAddress())) {
message->getPrivate()->forceFromAddress(cpimFromAddress);
lInfo() << "[CPIM] Sender authentication sucessful" << endl;
}
else {
lWarning() << "[CPIM] Sender authentication failed" << endl;
errorCode = 488;
return ChatMessageModifier::Result::Error;
}
auto messageIdHeader = cpimMessage->getMessageHeader("Message-ID"); // TODO: For compatibility, to remove
if (!imdnNamespace.empty()) {
if (!messageIdHeader)
......@@ -191,15 +201,6 @@ ChatMessageModifier::Result CpimChatMessageModifier::decode (const shared_ptr<Ch
// Modify the initial message since there was no error
message->setInternalContent(newContent);
if (cpimFromAddress.isValid() && (cpimFromAddress == message->getAuthenticatedFromAddress())) {
message->getPrivate()->forceFromAddress(cpimFromAddress);
lInfo() << "Sender authentication succeeded" << endl;
}
else {
lWarning() << "Sender authentication failed" << endl;
// TODO Reject message
}
return ChatMessageModifier::Result::Done;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment