git » sdk » commit 6e109ac

OMEMO: Fix exception when receiving OMEMO key exchange messages

author Matthew Wild
2025-05-24 14:47:26 UTC
committer Stephen Paul Weber
2025-09-29 13:43:04 UTC
parent 9c644256265aabe1e8f38405cc56e8b80015462e

OMEMO: Fix exception when receiving OMEMO key exchange messages

This does not implement proper handling of them yet, but it fixes the
exception.

snikket/OMEMO.hx +10 -2

diff --git a/snikket/OMEMO.hx b/snikket/OMEMO.hx
index 6d67ba7..e4b7faf 100644
--- a/snikket/OMEMO.hx
+++ b/snikket/OMEMO.hx
@@ -213,7 +213,7 @@ class OMEMOPayload {
 	public final sid:Int;
 	public final keys:Array<OMEMOPayloadKey>;
 	public final encodedIv:String;
-	public final encodedPayload:String;
+	public final encodedPayload:Null<String>;
 
 	public function toXml():Stanza {
 		final el = new Stanza("encrypted", { xmlns: "eu.siacs.conversations.axolotl" });
@@ -265,7 +265,10 @@ class OMEMOPayload {
 		return Base64.decode(encodedIv).getData();
 	}
 
-	public function getRawPayload():BytesData {
+	public function getRawPayload():Null<BytesData> {
+		if(encodedPayload == null) {
+			return null;
+		}
 		return Base64.decode(encodedPayload).getData();
 	}
 
@@ -784,6 +787,11 @@ class OMEMO {
 
 	private function decryptPayload(deviceId:Int, deviceKey:OMEMOPayloadKey, fromBare:String, payload:OMEMOPayload):Promise<BytesData> {
 		var cipher:SessionCipher;
+		if(payload.getRawPayload() == null) {
+			// Probably a key transport message, which we don't
+			// currently handle.
+			return Promise.reject("no-payload");
+		}
 		final promCipher = new Promise<SessionCipher>((resolve, reject) -> {
 			if(deviceKey.prekey) {
 				// Incoming message used a prekey - build a new session between