Commit 2c0e1fea authored by Matthieu Tanon's avatar Matthieu Tanon

Fix infinite IMDN loop by authorising clear IMDN and isComposing messages

parent 982f665d
......@@ -126,6 +126,9 @@ public:
void setEncryptionPrevented (bool value) { encryptionPrevented = value; }
void setAuthorisationWarning (bool value) { authorizationWarning = value; } // TODO find better name
bool getAuthorisationWarning () { return authorizationWarning; } // TODO find better name
// -----------------------------------------------------------------------------
// Deprecated methods only used for C wrapper, to be removed some day...
// -----------------------------------------------------------------------------
......@@ -213,6 +216,7 @@ private:
IdentityAddress fromAddress;
IdentityAddress authenticatedFromAddress;
bool senderAuthenticationEnabled = true;
bool authorizationWarning = false; // TODO find a better name
IdentityAddress toAddress;
ChatMessage::State state = ChatMessage::State::Idle;
......
......@@ -533,6 +533,23 @@ LinphoneReason ChatMessagePrivate::receive () {
currentRecvStep |= ChatMessagePrivate::Step::Cpim;
}
// Message Authorisation (could be done in CPIM modifier)
// If LIMEv2 enabled, check authorisation warning flag
// If warning flag is true, check if message is an isComposing or an IMDN
if (q->getSharedFromThis()->getPrivate()->getAuthorisationWarning()) {
if (q->getSharedFromThis()->getInternalContent().getContentType() != ContentType::Imdn && q->getSharedFromThis()->getInternalContent().getContentType() != ContentType::ImIsComposing) {
// TODO acknowledge message reception with errorCode = 0
// TODO return a "message refused because not encrypted" IMDN to the sender
errorCode = 415; // TODO 415 for example, maybe another one is better ? 488 ? 603 ?
reason = linphone_error_code_to_reason(errorCode);
if (getNegativeDeliveryNotificationRequired()) {
static_cast<ChatRoomPrivate *>(q->getChatRoom()->getPrivate())->sendDeliveryErrorNotification(
q->getSharedFromThis(),
reason
);
}
return reason;
}
if ((currentRecvStep &ChatMessagePrivate::Step::Multipart) == ChatMessagePrivate::Step::Multipart) {
lInfo() << "Multipart step already done, skipping";
} else {
......
......@@ -280,10 +280,18 @@ ChatMessageModifier::Result LimeV2::processIncomingMessage (const shared_ptr<Cha
internalContent = message->getInternalContent();
// Check if message if encrypted and unwrap the multipart
ContentType incomingContentType = message->getInternalContent().getContentType();
ContentType expectedContentType = ContentType::Encrypted;
expectedContentType.addParameter("boundary", MultipartBoundary);
if (internalContent.getContentType() != expectedContentType) {
lError() << "LIMEv2 unexpected content-type: " << internalContent.getContentType();
if (incomingContentType == ContentType::Cpim) {
lInfo() << "LIMEv2 incoming CPIM message";
message->getPrivate()->setAuthorisationWarning(true);
// Disable sender authentication otherwise the message will always get discarded because it doesn't have a sipfrag
message->getPrivate()->enableSenderAuthentication(false);
return ChatMessageModifier::Result::Skipped;
} else if (incomingContentType != expectedContentType) {
lError() << "LIMEv2 unexpected content-type: " << incomingContentType;
return ChatMessageModifier::Result::Error;
}
list<Content> contentList = ContentManager::multipartToContentList(internalContent);
......
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