borogove
created pr with
borogove/outgoing-e2ee-status.1
added borogove/outgoing-e2ee-status.2
1: 9b2b378 = 1: b641e78 Record if a send message was e2ee
-: ------- > 2: 9dbe688 review comments
commented
borogove/Chat.hx:284 — I think this would read better like:
return switch (e2eePreference) {
case OMEMO: EncryptionInfo.forSent(NS.OMEMO);
case NoE2EE: null;
case Default: defaultE2ee();
};
added borogove/outgoing-e2ee-status.3
1: b641e78 ! 1: a6d1b46 Record if a send message was e2ee
2: 9dbe688 = 2: 8565503 review comments
-: ------- > 3: 6b1d111 comments
cmds
checkout latest patchset:
ssh pr.pico.sh pull borogove:outgoing-e2ee-status | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull borogove:outgoing-e2ee-status [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh borogove:outgoing-e2ee-statusadd comment to patch request:
ssh pr.pico.sh comment borogove:outgoing-e2ee-status "lgtm!"
Patchset
borogove/outgoing-e2ee-status.2
Record if a send message was e2ee
Stephen Paul Weber
2026-11-11T22:02:49ZAnd also on re-send use the same e2ee originally intended. We store with the intended e2ee before attempting, then if it turns out we can't use e2ee and policy allows us to not, we update the DB with the fact that we didn't actually to be accurate.
Semantic diff summary
0 added,
1 modified,
0 signature changed,
0 removed
across 1 analyzed file
(7 files skipped: unsupported file type)
+47
-24
borogove/Chat.hx
#
| ... | ... | @@ -271,7 +271,24 @@ abstract class Chat extends EventEmitter { | |
| 271 | 271 | ||
| 272 | 272 | @:allow(borogove) | |
| 273 | 273 | // Not abstract to work around https://github.com/HaxeFoundation/haxe/issues/11666 | |
| 274 | - | private function sendMessageStanza(stanza: Stanza, ?outboxItem: OutboxItem, e2eePreference: OutgoingE2EEPreference = Default):Void { } | |
| 274 | + | private function sendMessageStanza(stanza: Stanza, ?outboxItem: OutboxItem, e2eePreference: OutgoingE2EEPreference = Default):Promise<Null<EncryptionInfo>> { throw "Not implemented"; } | |
| 275 | + | ||
| 276 | + | private function defaultE2ee():OutgoingE2EEPreference { | |
| 277 | + | return client.outgoingE2EEPreference[0]; | |
| 278 | + | } | |
| 279 | + | ||
| 280 | + | private function intendedEncryption(e2eePreference:OutgoingE2EEPreference):Null<EncryptionInfo> { | |
| 281 | + | #if NO_OMEMO | |
| 282 | + | return null; | |
| 283 | + | #else | |
| 284 | + | if (e2eePreference == Default) e2eePreference = defaultE2ee(); | |
| 285 | + | return switch (e2eePreference) { | |
| 286 | + | case OMEMO: EncryptionInfo.forSent(NS.OMEMO); | |
| 287 | + | case NoE2EE: null; | |
| 288 | + | case Default: throw "Impossible"; | |
| 289 | + | }; | |
| 290 | + | #end | |
| 291 | + | } | |
| 275 | 292 | ||
| 276 | 293 | /** | |
| 277 | 294 | Signals that all messages up to and including this one have probably |
| ... | ... | @@ -1270,7 +1287,7 @@ class DirectChat extends Chat { | |
| 1270 | 1287 | return message; | |
| 1271 | 1288 | } | |
| 1272 | 1289 | ||
| 1273 | - | private function prepareOutgoingMessage(message:ChatMessageBuilder) { | |
| 1290 | + | private function prepareOutgoingMessage(message:ChatMessageBuilder, e2eePreference:OutgoingE2EEPreference = Default) { | |
| 1274 | 1291 | message.timeSent = message.timeSent ?? Date.format(std.Date.now()); | |
| 1275 | 1292 | message.timeReceived = Date.format(std.Date.now()); | |
| 1276 | 1293 | message.direction = MessageSent; |
| ... | ... | @@ -1280,6 +1297,7 @@ class DirectChat extends Chat { | |
| 1280 | 1297 | message.recipients = counterparts().map((p) -> JID.parse(p)); | |
| 1281 | 1298 | message.to = message.recipients[0]; | |
| 1282 | 1299 | if (message.localId == null) message.localId = ID.unique(); | |
| 1300 | + | if (message.encryption == null) message.encryption = intendedEncryption(e2eePreference); | |
| 1283 | 1301 | return message; | |
| 1284 | 1302 | } | |
| 1285 | 1303 |
| ... | ... | @@ -1293,7 +1311,7 @@ class DirectChat extends Chat { | |
| 1293 | 1311 | client.storeMessageBuilder(message).then((corrected) -> { | |
| 1294 | 1312 | message.versions = corrected.versions[corrected.versions.length - 1]?.localId == correct.localId ? cast corrected.versions : [message.build()]; | |
| 1295 | 1313 | message.localId = toSendId; | |
| 1296 | - | sendMessageStanza(message.build().asStanza(), outboxItem); | |
| 1314 | + | sendMessageStanza(message.build().asStanza(), outboxItem).then((encryptionInfo) -> client.applySentEncryption(this, message, encryptionInfo)); | |
| 1297 | 1315 | if (lastMessage == null || corrected.canReplace(lastMessage)) { | |
| 1298 | 1316 | setLastMessage(corrected).then(_ -> | |
| 1299 | 1317 | client.trigger("chats/update", [this]) |
| ... | ... | @@ -1307,7 +1325,7 @@ class DirectChat extends Chat { | |
| 1307 | 1325 | if (uiState == Invited) uiState = Open; | |
| 1308 | 1326 | if (typingTimer != null) typingTimer.stop(); | |
| 1309 | 1327 | client.chatActivity(this); | |
| 1310 | - | message = prepareOutgoingMessage(message); | |
| 1328 | + | message = prepareOutgoingMessage(message, e2eePreference); | |
| 1311 | 1329 | message.to = message.recipients[0]; // Just pick one for the stanza we re-parse | |
| 1312 | 1330 | final fromStanza = Message.fromStanza(message.build().asStanza(), client.jid).parsed; | |
| 1313 | 1331 | switch (fromStanza) { |
| ... | ... | @@ -1320,7 +1338,7 @@ class DirectChat extends Chat { | |
| 1320 | 1338 | activeThread = message.threadId; | |
| 1321 | 1339 | stanza.tag("active", { xmlns: "http://jabber.org/protocol/chatstates" }).up(); | |
| 1322 | 1340 | } | |
| 1323 | - | sendMessageStanza(stanza, outboxItem, e2eePreference); | |
| 1341 | + | sendMessageStanza(stanza, outboxItem, e2eePreference).then((encryptionInfo) -> client.applySentEncryption(this, message, encryptionInfo)); | |
| 1324 | 1342 | setLastMessage(stored).then(_ -> { | |
| 1325 | 1343 | client.notifyMessageHandlers(stored, stored.versions.length > 1 ? CorrectionEvent : DeliveryEvent); | |
| 1326 | 1344 | client.trigger("chats/update", [this]); |
| ... | ... | @@ -1378,13 +1396,13 @@ class DirectChat extends Chat { | |
| 1378 | 1396 | }); | |
| 1379 | 1397 | } | |
| 1380 | 1398 | ||
| 1381 | - | override private function sendMessageStanza(stanza: Stanza, ?outboxItem: OutboxItem, e2eePreference: OutgoingE2EEPreference = Default) { | |
| 1399 | + | override private function sendMessageStanza(stanza: Stanza, ?outboxItem: OutboxItem, e2eePreference: OutgoingE2EEPreference = Default):Promise<Null<EncryptionInfo>> { | |
| 1382 | 1400 | if (stanza.name != "message") throw "Can only send message stanza this way"; | |
| 1383 | 1401 | ||
| 1384 | 1402 | if (outboxItem == null) outboxItem = outbox.newItem(); | |
| 1385 | 1403 | ||
| 1386 | 1404 | final counters = counterparts(); | |
| 1387 | - | thenshim.PromiseTools.all(counters.map(counterpart -> { | |
| 1405 | + | return thenshim.PromiseTools.all(counters.map(counterpart -> { | |
| 1388 | 1406 | final clone = stanza.clone(); | |
| 1389 | 1407 | clone.attr.set("to", counterpart); | |
| 1390 | 1408 | if (counters.length > 1 && stanza.getChild("addresses", "http://jabber.org/protocol/address") == null) { |
| ... | ... | @@ -1400,26 +1418,27 @@ class DirectChat extends Chat { | |
| 1400 | 1418 | if (e2eePreference == Default) e2eePreference = client.outgoingE2EEPreference[0]; | |
| 1401 | 1419 | #if NO_OMEMO | |
| 1402 | 1420 | if (e2eePreference != NoE2EE) throw "Selected E2EE preference unsupported"; | |
| 1403 | - | return Promise.resolve(stanza); | |
| 1421 | + | return Promise.resolve({ stanza: stanza, encryptionInfo: null }); | |
| 1404 | 1422 | #else | |
| 1405 | 1423 | switch (e2eePreference) { | |
| 1406 | 1424 | case OMEMO: | |
| 1407 | 1425 | // As written this falls back to NoE2EE if allowed | |
| 1408 | - | return client.omemo.encryptMessage([JID.parse(counterpart)], stanza).then((encryptedStanza) -> { | |
| 1409 | - | return Promise.resolve(encryptedStanza); | |
| 1426 | + | return client.omemo.encryptMessage([JID.parse(counterpart)], stanza).then((outcome) -> { | |
| 1427 | + | return Promise.resolve({ stanza: outcome.stanza, encryptionInfo: outcome.encryptionInfo }); | |
| 1410 | 1428 | }); | |
| 1411 | 1429 | case NoE2EE: | |
| 1412 | - | return Promise.resolve(stanza); | |
| 1430 | + | return Promise.resolve({ stanza: stanza, encryptionInfo: null }); | |
| 1413 | 1431 | case Default: | |
| 1414 | 1432 | throw "Impossible"; | |
| 1415 | 1433 | } | |
| 1416 | 1434 | #end | |
| 1417 | - | })).then(stanzas -> { | |
| 1435 | + | })).then(outcomes -> { | |
| 1418 | 1436 | outboxItem.handle(() -> { | |
| 1419 | - | for (stanza in stanzas) { | |
| 1420 | - | client.sendStanza(stanza); | |
| 1437 | + | for (outcome in outcomes) { | |
| 1438 | + | client.sendStanza(outcome.stanza); | |
| 1421 | 1439 | } | |
| 1422 | 1440 | }); | |
| 1441 | + | return Promise.resolve(outcomes.fold((x, y) -> x.encryptionInfo == null || y == null ? null : x.encryptionInfo, outcomes[0].encryptionInfo)); | |
| 1423 | 1442 | }); | |
| 1424 | 1443 | } | |
| 1425 | 1444 |
| ... | ... | @@ -2495,7 +2514,7 @@ class Channel extends Chat { | |
| 2495 | 2514 | return message; | |
| 2496 | 2515 | } | |
| 2497 | 2516 | ||
| 2498 | - | private function prepareOutgoingMessage(message:ChatMessageBuilder) { | |
| 2517 | + | private function prepareOutgoingMessage(message:ChatMessageBuilder, e2eePreference:OutgoingE2EEPreference = Default) { | |
| 2499 | 2518 | message.type = MessageChannel; | |
| 2500 | 2519 | message.timeSent = message.timeSent ?? Date.format(std.Date.now()); | |
| 2501 | 2520 | message.timeReceived = Date.format(std.Date.now()); |
| ... | ... | @@ -2529,7 +2549,7 @@ class Channel extends Chat { | |
| 2529 | 2549 | client.storeMessageBuilder(message).then((corrected) -> { | |
| 2530 | 2550 | message.versions = corrected.versions[0]?.localId == correct.localId ? cast corrected.versions : [message.build()]; | |
| 2531 | 2551 | message.localId = toSendId; | |
| 2532 | - | sendMessageStanza(message.build().asStanza(), outboxItem); | |
| 2552 | + | sendMessageStanza(message.build().asStanza(), outboxItem).then((encryptionInfo) -> client.applySentEncryption(this, message, encryptionInfo)); | |
| 2533 | 2553 | client.notifyMessageHandlers(corrected, CorrectionEvent); | |
| 2534 | 2554 | if (lastMessage == null || corrected.canReplace(lastMessage)) { | |
| 2535 | 2555 | setLastMessage(corrected).then(_ -> |
| ... | ... | @@ -2543,7 +2563,7 @@ class Channel extends Chat { | |
| 2543 | 2563 | if (uiState == Invited) uiState = Open; | |
| 2544 | 2564 | if (typingTimer != null) typingTimer.stop(); | |
| 2545 | 2565 | client.chatActivity(this); | |
| 2546 | - | message = prepareOutgoingMessage(message); | |
| 2566 | + | message = prepareOutgoingMessage(message, e2eePreference); | |
| 2547 | 2567 | final stanza = message.build().asStanza(); | |
| 2548 | 2568 | // Fake from as it will look on reflection for storage purposes | |
| 2549 | 2569 | stanza.attr.set("from", getFullJid().asString()); |
| ... | ... | @@ -2561,7 +2581,7 @@ class Channel extends Chat { | |
| 2561 | 2581 | } | |
| 2562 | 2582 | final outboxItem = outbox.newItem(); | |
| 2563 | 2583 | client.storeMessageBuilder(message).then((stored) -> { | |
| 2564 | - | sendMessageStanza(stanza, outboxItem); | |
| 2584 | + | sendMessageStanza(stanza, outboxItem, e2eePreference).then((encryptionInfo) -> client.applySentEncryption(this, message, encryptionInfo)); | |
| 2565 | 2585 | setLastMessage(stored).then(_ -> { | |
| 2566 | 2586 | client.notifyMessageHandlers(stored, stored.versions.length > 1 ? CorrectionEvent : DeliveryEvent); | |
| 2567 | 2587 | client.trigger("chats/update", [this]); |
| ... | ... | @@ -2615,7 +2635,7 @@ class Channel extends Chat { | |
| 2615 | 2635 | } | |
| 2616 | 2636 | ||
| 2617 | 2637 | // TODO: this is a gross heuristic. Large private groups that don't want e2ee are possible for example | |
| 2618 | - | private function defaultE2ee() { | |
| 2638 | + | override private function defaultE2ee() { | |
| 2619 | 2639 | if (!client.outgoingE2EEPreference.exists(p -> p == NoE2EE)) { | |
| 2620 | 2640 | // Must E2EE | |
| 2621 | 2641 | return client.outgoingE2EEPreference[0]; |
| ... | ... | @@ -2626,7 +2646,7 @@ class Channel extends Chat { | |
| 2626 | 2646 | return client.outgoingE2EEPreference[0]; | |
| 2627 | 2647 | } | |
| 2628 | 2648 | ||
| 2629 | - | override private function sendMessageStanza(stanza: Stanza, ?outboxItem: OutboxItem, e2eePreference: OutgoingE2EEPreference = Default) { | |
| 2649 | + | override private function sendMessageStanza(stanza: Stanza, ?outboxItem: OutboxItem, e2eePreference: OutgoingE2EEPreference = Default):Promise<Null<EncryptionInfo>> { | |
| 2630 | 2650 | if (stanza.name != "message") throw "Can only send message stanza this way"; | |
| 2631 | 2651 | ||
| 2632 | 2652 | if (outboxItem == null) outboxItem = outbox.newItem(); |
| ... | ... | @@ -2639,19 +2659,22 @@ class Channel extends Chat { | |
| 2639 | 2659 | #if NO_OMEMO | |
| 2640 | 2660 | if (e2eePreference != NoE2EE) throw "Selected E2EE preference unsupported"; | |
| 2641 | 2661 | outboxItem.handle(() -> client.sendStanza(stanza)); | |
| 2662 | + | return Promise.resolve(null); | |
| 2642 | 2663 | #else | |
| 2643 | 2664 | switch (e2eePreference) { | |
| 2644 | 2665 | case OMEMO: | |
| 2645 | 2666 | // As written this falls back to NoE2EE if allowed and no one has OMEMO | |
| 2646 | 2667 | // TODO: on some rooms, especially very large ones this may not be a full | |
| 2647 | 2668 | // list of members. In practise it is fine anywhere OMEMO could actually work | |
| 2648 | - | members().then(members -> | |
| 2669 | + | return members().then(members -> | |
| 2649 | 2670 | client.omemo.encryptMessage(members.map(member -> JID.parse(member.chat?.chatId)), stanza) | |
| 2650 | - | ).then((encryptedStanza) -> | |
| 2651 | - | outboxItem.handle(() -> client.sendStanza(encryptedStanza)) | |
| 2652 | - | ); | |
| 2671 | + | ).then((outcome) -> { | |
| 2672 | + | outboxItem.handle(() -> client.sendStanza(outcome.stanza)); | |
| 2673 | + | return Promise.resolve(outcome.encryptionInfo); | |
| 2674 | + | }); | |
| 2653 | 2675 | case NoE2EE: | |
| 2654 | 2676 | outboxItem.handle(() -> client.sendStanza(stanza)); | |
| 2677 | + | return Promise.resolve(null); | |
| 2655 | 2678 | case Default: | |
| 2656 | 2679 | throw "Impossible"; | |
| 2657 | 2680 | } |
+23
-2
borogove/Client.hx
#
| ... | ... | @@ -2188,6 +2188,23 @@ class Client extends EventEmitter { | |
| 2188 | 2188 | })).then(updatedMessages -> persistence.storeMessages(accountId(), updatedMessages)); | |
| 2189 | 2189 | } | |
| 2190 | 2190 | ||
| 2191 | + | @:allow(borogove) | |
| 2192 | + | private function applySentEncryption(chat: Chat, builder: ChatMessageBuilder, encryption: Null<EncryptionInfo>) { | |
| 2193 | + | final stored = builder.encryption; | |
| 2194 | + | if (stored == encryption || (stored != null && encryption != null && stored.status == encryption.status && stored.method == encryption.method)) { | |
| 2195 | + | return Promise.resolve(null); | |
| 2196 | + | } | |
| 2197 | + | ||
| 2198 | + | builder.encryption = encryption; | |
| 2199 | + | return storeMessageBuilder(builder).then(updated -> { | |
| 2200 | + | if (chat.lastMessage != null && chat.lastMessage.canReplace(updated)) { | |
| 2201 | + | chat.setLastMessage(updated).then(_ -> trigger("chats/update", [chat])); | |
| 2202 | + | } | |
| 2203 | + | notifyMessageHandlers(updated, StatusEvent); | |
| 2204 | + | return null; | |
| 2205 | + | }); | |
| 2206 | + | } | |
| 2207 | + | ||
| 2191 | 2208 | private function checkForResends() { | |
| 2192 | 2209 | var tooOld = Date.format( | |
| 2193 | 2210 | DateTools.delta(std.Date.now(), DateTools.hours(-3)) |
| ... | ... | @@ -2210,8 +2227,12 @@ class Client extends EventEmitter { | |
| 2210 | 2227 | from: accountId(), | |
| 2211 | 2228 | stamp: m.timeSent | |
| 2212 | 2229 | }); | |
| 2213 | - | // TODO: don't know if was originally send with OMEMO | |
| 2214 | - | chat.sendMessageStanza(stanza); | |
| 2230 | + | // Don't silently downgrade a message that was meant to be encrypted | |
| 2231 | + | var preference:OutgoingE2EEPreference = Default; | |
| 2232 | + | #if !NO_OMEMO | |
| 2233 | + | if (m.encryption != null) preference = OMEMO; | |
| 2234 | + | #end | |
| 2235 | + | chat.sendMessageStanza(stanza, null, preference).then((encryption) -> applySentEncryption(chat, ChatMessageBuilder.fromMessage(m), encryption)); | |
| 2215 | 2236 | } | |
| 2216 | 2237 | } | |
| 2217 | 2238 | } |
+8
-2
borogove/EncryptionInfo.hx
#
| ... | ... | @@ -8,7 +8,7 @@ import HaxeCBridge; | |
| 8 | 8 | Outcome of decrypting an incoming message. | |
| 9 | 9 | **/ | |
| 10 | 10 | enum abstract EncryptionStatus(Int) { | |
| 11 | - | var DecryptionSuccess; // Message was encrypted, and we decrypted it | |
| 11 | + | var EncryptionInfoSuccess; // Incoming: message was encrypted and we decrypted it. Outgoing: message was encrypted | |
| 12 | 12 | var DecryptionFailure; // Message is encrypted, and we failed to decrypt it | |
| 13 | 13 | } | |
| 14 | 14 |
| ... | ... | @@ -48,7 +48,7 @@ class EncryptionInfo { | |
| 48 | 48 | final el = new Stanza("decryption-status", { | |
| 49 | 49 | xmlns: "https://borogove.dev/protocol/sdk", | |
| 50 | 50 | encryption: this.method, | |
| 51 | - | result: status == DecryptionSuccess?"success":"failure", | |
| 51 | + | result: status == EncryptionInfoSuccess?"success":"failure", | |
| 52 | 52 | }); | |
| 53 | 53 | if(reason != null) { | |
| 54 | 54 | el.textTag("reason", reason); |
| ... | ... | @@ -59,6 +59,12 @@ class EncryptionInfo { | |
| 59 | 59 | return el; | |
| 60 | 60 | } | |
| 61 | 61 | ||
| 62 | + | // We encrypted an outgoing message with this method | |
| 63 | + | @:allow(borogove) | |
| 64 | + | static private function forSent(method:String):EncryptionInfo { | |
| 65 | + | return new EncryptionInfo(EncryptionInfoSuccess, method); | |
| 66 | + | } | |
| 67 | + | ||
| 62 | 68 | // Typically used to deduce an EncryptionInfo when none has been provided | |
| 63 | 69 | // May return null if the stanza is not recognizably encrypted. | |
| 64 | 70 | @:allow(borogove) |
+12
-6
borogove/OMEMO.hx
#
| ... | ... | @@ -311,6 +311,11 @@ class OMEMODecryptionResult { | |
| 311 | 311 | } | |
| 312 | 312 | } | |
| 313 | 313 | ||
| 314 | + | typedef OMEMOEncryptionOutcome = { | |
| 315 | + | final stanza:Stanza; | |
| 316 | + | final encryptionInfo:Null<EncryptionInfo>; | |
| 317 | + | }; | |
| 318 | + | ||
| 314 | 319 | @:expose | |
| 315 | 320 | class OMEMOSessionMetadata { | |
| 316 | 321 | // True when we have successfully received and decrypted any |
| ... | ... | @@ -959,7 +964,7 @@ class OMEMO { | |
| 959 | 964 | // No metadata in storage, so create a default | |
| 960 | 965 | metadata = new OMEMOSessionMetadata(false, false, false); | |
| 961 | 966 | } | |
| 962 | - | final decryptedOk = decryptionResult.encryptionInfo.status == DecryptionSuccess; | |
| 967 | + | final decryptedOk = decryptionResult.encryptionInfo.status == EncryptionInfoSuccess; | |
| 963 | 968 | var needUpdate = metadata.lastMessageDecryptedOk != decryptedOk; | |
| 964 | 969 | final receivedSessionMessage = deviceKey != null && !deviceKey.prekey; | |
| 965 | 970 | needUpdate = needUpdate || receivedSessionMessage != metadata.receivedSessionMessageOk; |
| ... | ... | @@ -1093,7 +1098,7 @@ class OMEMO { | |
| 1093 | 1098 | }); | |
| 1094 | 1099 | } | |
| 1095 | 1100 | ||
| 1096 | - | public function encryptMessage(recipients: Array<JID>, stanza:Stanza):Promise<Stanza> { | |
| 1101 | + | public function encryptMessage(recipients: Array<JID>, stanza:Stanza):Promise<OMEMOEncryptionOutcome> { | |
| 1097 | 1102 | final promHeader = thenshim.PromiseTools.all(recipients.map(getContactDevices)).then(raddresses -> { | |
| 1098 | 1103 | final raddrs = raddresses.flatMap(addrs -> addrs); | |
| 1099 | 1104 |
| ... | ... | @@ -1125,7 +1130,7 @@ class OMEMO { | |
| 1125 | 1130 | newStanza.addChild(header); | |
| 1126 | 1131 | newStanza.textTag("encryption", "", { xmlns: "urn:xmpp:eme:0", namespace: "eu.siacs.conversations.axolotl" }); | |
| 1127 | 1132 | newStanza.textTag("body", "I sent you an OMEMO encrypted message but your client doesn’t seem to support that. Find more information on https://conversations.im/omemo"); | |
| 1128 | - | return newStanza; | |
| 1133 | + | return { stanza: newStanza, encryptionInfo: EncryptionInfo.forSent(NS.OMEMO) }; | |
| 1129 | 1134 | }, (failureReason) -> { | |
| 1130 | 1135 | final noRecipientSupport = failureReason == "no-devices"; | |
| 1131 | 1136 | var allowUnencrypted:Bool = client.outgoingE2EEPreference.exists(p -> p == NoE2EE); |
| ... | ... | @@ -1152,9 +1157,10 @@ class OMEMO { | |
| 1152 | 1157 | ||
| 1153 | 1158 | trace("OMEMO: Skipping encryption (permitted by policy): " + errMsg); | |
| 1154 | 1159 | ||
| 1155 | - | // Encryption failed, but policy says this is ok. | |
| 1160 | + | // Encryption failed, but policy says this is ok. The message goes | |
| 1161 | + | // out unencrypted, so no EncryptionInfo is recorded for it. | |
| 1156 | 1162 | // Just pass through the original stanza to be sent. | |
| 1157 | - | return stanza; | |
| 1163 | + | return { stanza: stanza, encryptionInfo: null }; | |
| 1158 | 1164 | }); | |
| 1159 | 1165 | ||
| 1160 | 1166 | return promStanza; |
+5
-2
test/TestChat.hx
#
| ... | ... | @@ -1209,10 +1209,13 @@ class TestChat extends utest.Test { | |
| 1209 | 1209 | final chat = client.getDirectChat("friend@example.com"); | |
| 1210 | 1210 | ||
| 1211 | 1211 | Reflect.setField(client, "omemo", { | |
| 1212 | - | encryptMessage: function(jid: borogove.JID, stanza: Stanza) { | |
| 1212 | + | encryptMessage: function(jids: Array<borogove.JID>, stanza: Stanza) { | |
| 1213 | 1213 | final encrypted = stanza.clone(); | |
| 1214 | 1214 | encrypted.tag("encrypted", { xmlns: "eu.siacs.conversations.axolotl" }).up(); | |
| 1215 | - | return Promise.resolve(encrypted); | |
| 1215 | + | return Promise.resolve({ | |
| 1216 | + | stanza: encrypted, | |
| 1217 | + | encryptionInfo: new borogove.EncryptionInfo(EncryptionInfoSuccess, "eu.siacs.conversations.axolotl") | |
| 1218 | + | }); | |
| 1216 | 1219 | } | |
| 1217 | 1220 | }); | |
| 1218 | 1221 |
+64
-0
test/TestClient.hx
#
| ... | ... | @@ -23,6 +23,7 @@ import borogove.Stanza; | |
| 23 | 23 | import borogove.Status; | |
| 24 | 24 | import borogove.persistence.Dummy; | |
| 25 | 25 | import borogove.Chat.OutgoingE2EEPreference; | |
| 26 | + | import borogove.EncryptionInfo; | |
| 26 | 27 | import borogove.AttachmentUploadError; | |
| 27 | 28 | import borogove.AttachmentUploadErrorCode; | |
| 28 | 29 | #if !NO_OMEMO |
| ... | ... | @@ -663,6 +664,69 @@ class TestClient extends utest.Test { | |
| 663 | 664 | }); | |
| 664 | 665 | } | |
| 665 | 666 | ||
| 667 | + | #if !NO_OMEMO | |
| 668 | + | public function testSentMessageRecordsEncryption(async: Async) { | |
| 669 | + | final persistence = new MessageMockPersistence(); | |
| 670 | + | final client = new Client("test@example.com", persistence); | |
| 671 | + | final chat = client.getDirectChat("friend@example.com"); | |
| 672 | + | ||
| 673 | + | Reflect.setField(client, "omemo", { | |
| 674 | + | encryptMessage: function(jids: Array<JID>, stanza: Stanza) { | |
| 675 | + | final encrypted = stanza.clone(); | |
| 676 | + | encrypted.tag("encrypted", { xmlns: "eu.siacs.conversations.axolotl" }).up(); | |
| 677 | + | return Promise.resolve({ | |
| 678 | + | stanza: encrypted, | |
| 679 | + | encryptionInfo: new borogove.EncryptionInfo(EncryptionInfoSuccess, "eu.siacs.conversations.axolotl") | |
| 680 | + | }); | |
| 681 | + | } | |
| 682 | + | }); | |
| 683 | + | ||
| 684 | + | client.stream.on("sendStanza", (stanza: Stanza) -> { | |
| 685 | + | if (stanza.name != "message") return EventUnhandled; | |
| 686 | + | final stored = persistence.messages.get(stanza.attr.get("id")); | |
| 687 | + | Assert.notNull(stored); | |
| 688 | + | Assert.notNull(stored?.encryption); | |
| 689 | + | Assert.equals(EncryptionInfoSuccess, stored?.encryption?.status); | |
| 690 | + | Assert.equals("eu.siacs.conversations.axolotl", stored?.encryption?.method); | |
| 691 | + | Assert.equals("OMEMO", stored?.encryption?.methodName); | |
| 692 | + | async.done(); | |
| 693 | + | return EventHandled; | |
| 694 | + | }); | |
| 695 | + | ||
| 696 | + | final builder = new ChatMessageBuilder(); | |
| 697 | + | builder.text = "hello"; | |
| 698 | + | chat.sendMessage(builder, borogove.Chat.OutgoingE2EEPreference.OMEMO); | |
| 699 | + | } | |
| 700 | + | ||
| 701 | + | public function testSentMessageRecordsFallbackAsUnencrypted(async: Async) { | |
| 702 | + | final persistence = new MessageMockPersistence(); | |
| 703 | + | final client = new Client("test@example.com", persistence); | |
| 704 | + | final chat = client.getDirectChat("friend@example.com"); | |
| 705 | + | ||
| 706 | + | Reflect.setField(client, "omemo", { | |
| 707 | + | encryptMessage: function(jids: Array<JID>, stanza: Stanza) { | |
| 708 | + | return Promise.resolve({ stanza: stanza.clone(), encryptionInfo: null }); | |
| 709 | + | } | |
| 710 | + | }); | |
| 711 | + | ||
| 712 | + | var finished = false; | |
| 713 | + | client.on("message/new", (data: { message: ChatMessage, event: ChatMessageEvent }) -> { | |
| 714 | + | if (data.event != StatusEvent || finished) return EventUnhandled; | |
| 715 | + | Assert.isNull(data.message.encryption); | |
| 716 | + | Assert.isNull(persistence.messages.get(data.message.localId)?.encryption); | |
| 717 | + | Assert.equals(data.message.localId, chat.lastMessage?.localId); | |
| 718 | + | Assert.isNull(chat.lastMessage?.encryption); | |
| 719 | + | finished = true; | |
| 720 | + | async.done(); | |
| 721 | + | return EventHandled; | |
| 722 | + | }); | |
| 723 | + | ||
| 724 | + | final builder = new ChatMessageBuilder(); | |
| 725 | + | builder.text = "hello"; | |
| 726 | + | chat.sendMessage(builder, borogove.Chat.OutgoingE2EEPreference.OMEMO); | |
| 727 | + | } | |
| 728 | + | #end | |
| 729 | + | ||
| 666 | 730 | public function testDefaultDisplayName() { | |
| 667 | 731 | final persistence = new Dummy(); | |
| 668 | 732 | final client = new Client("test@example.com", persistence); |
+2
-2
test/TestSqlite.hx
#
| ... | ... | @@ -879,7 +879,7 @@ class TestSqlite extends utest.Test { | |
| 879 | 879 | final chatId = "encryption-correction-hatter@example.com"; | |
| 880 | 880 | final originalExpected = { | |
| 881 | 881 | text: "Original encrypted text", | |
| 882 | - | encryption: new EncryptionInfo(DecryptionSuccess, "urn:xmpp:omemo:1", null, null, "OMEMO 1") | |
| 882 | + | encryption: new EncryptionInfo(EncryptionInfoSuccess, "urn:xmpp:omemo:1", null, null, "OMEMO 1") | |
| 883 | 883 | }; | |
| 884 | 884 | final original = makeMessage({ | |
| 885 | 885 | timestamp: "2026-08-26T12:00:00Z", |
| ... | ... | @@ -1011,7 +1011,7 @@ class TestSqlite extends utest.Test { | |
| 1011 | 1011 | ||
| 1012 | 1012 | public function testUpdateMessageStatus(async: Async) { | |
| 1013 | 1013 | final account = "alice@example.com"; | |
| 1014 | - | final expectedEncryption = new EncryptionInfo(DecryptionSuccess, "eu.siacs.conversations.axolotl", null, null, "OMEMO"); | |
| 1014 | + | final expectedEncryption = new EncryptionInfo(EncryptionInfoSuccess, "eu.siacs.conversations.axolotl", null, null, "OMEMO"); | |
| 1015 | 1015 | final builder = new ChatMessageBuilder(); | |
| 1016 | 1016 | builder.localId = "loc1"; | |
| 1017 | 1017 | builder.senderId = "alice@example.com"; |
+2
-2
test/persistence-tests.ts
#
| ... | ... | @@ -455,7 +455,7 @@ export function sharedPersistenceTests(test) { | |
| 455 | 455 | builder.recipients = [builder.to]; | |
| 456 | 456 | builder.replyTo = [builder.from]; | |
| 457 | 457 | builder.encryption = { | |
| 458 | - | status: borogove.EncryptionStatus.DecryptionSuccess, | |
| 458 | + | status: borogove.EncryptionStatus.EncryptionInfoSuccess, | |
| 459 | 459 | method: "eu.siacs.conversations.axolotl", | |
| 460 | 460 | methodName: "OMEMO", | |
| 461 | 461 | reason: null, |
| ... | ... | @@ -503,7 +503,7 @@ export function sharedPersistenceTests(test) { | |
| 503 | 503 | originalBuilder.recipients = [originalBuilder.to]; | |
| 504 | 504 | originalBuilder.replyTo = [originalBuilder.from]; | |
| 505 | 505 | originalBuilder.encryption = { | |
| 506 | - | status: borogove.EncryptionStatus.DecryptionSuccess, | |
| 506 | + | status: borogove.EncryptionStatus.EncryptionInfoSuccess, | |
| 507 | 507 | method: "urn:xmpp:omemo:1", | |
| 508 | 508 | methodName: "OMEMO 1", | |
| 509 | 509 | reason: null, |