Modern Apps git

← Modern-Apps.git

communicate: Signal - derive call SRTP keys from the stored identity key

Commit
249beafd0e3c94679bf64be2c9b08a2e9e6af559
Author
vayun-mathur <[email protected]>
When
2026-08-23 00:42 UTC (3 months ago)
Parents
af6ba8e

Diff

communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalClient.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalClient.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalClient.ktindex aa7a484e55..4d6cca9059 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalClient.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalClient.kt@@ -1247,10 +1247,15 @@ object SignalClient {                     // RingRTC binds the SRTP key derivation to both identity keys, so a call cannot be                     // set up before a session with this peer exists.                     val remote = e.storedIdentityKey(aci) ?: return null-                    return SignalCallManager.IdentityKeyPairBytes(-                        local = e.ownIdentityPublicKey,-                        remote = remote,+                    val local = e.ownIdentityPublicKey+                    // Logged because a size or encoding mismatch here yields SRTP keys that differ from the+                    // peer's, which looks like a connected call that never progresses.+                    Log.i(+                        TAG,+                        "call identity keys for $aci: local=${local.size}B(0x${"%02x".format(local.firstOrNull() ?: 0)}) " ++                            "remote=${remote.size}B(0x${"%02x".format(remote.firstOrNull() ?: 0)})",                     )+                    return SignalCallManager.IdentityKeyPairBytes(local = local, remote = remote)                 }                  override suspend fun iceServers(): List<PeerConnection.IceServer> =
communicate/src/main/java/com/vayunmathur/communicate/data/signal/e2e/SignalE2E.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/signal/e2e/SignalE2E.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/signal/e2e/SignalE2E.ktindex 871ee2af47..e84177d158 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/signal/e2e/SignalE2E.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/signal/e2e/SignalE2E.kt@@ -50,7 +50,20 @@ class SignalE2E(     /** See [PersistentSignalProtocolStore.onIdentityChanged]. */     private val onIdentityChanged: (String, ByteArray) -> Unit = { _, _ -> }, ) {-    val ownIdentityPublicKey: ByteArray = b64(auth.identityPublicKey)+    /**+     * Our own identity public key, taken from the protocol store rather than from preferences.+     *+     * These must be byte-identical to what the peer has for us: RingRTC derives the SRTP keys for a call+     * from both identity keys, so a different encoding — raw 32 bytes versus the 33-byte serialized form —+     * produces keys that do not match, ICE connects, and every RTP packet is then undecryptable. The store+     * is the authoritative copy because it is what messaging already uses successfully.+     */+    val ownIdentityPublicKey: ByteArray+        get() = try {+            protocolStore.identityKeyPair.publicKey.serialize()+        } catch (_: Throwable) {+            b64(auth.identityPublicKey)+        }     private val ownIdentityPrivate: ByteArray = b64(auth.identityPrivateKey)     private val ownAci: String = auth.aci.ifEmpty { auth.phoneNumber }     private val ownDeviceId: Int = auth.deviceId