Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/e2ee-key-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"client-sdk-android": minor
---

Add a `keySize` option to `BaseKeyProvider` (`KeyProviderKeySize.BITS_128` by default, or `BITS_256`) to derive AES-256-GCM frame keys for E2EE. All participants in a room must use the same size. Matches `KeyProviderOptions.keySize` in the JS and Swift SDKs.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal const val defaultFailureTolerance = -1
internal const val defaultKeyRingSize = 16
internal const val defaultDiscardFrameWhenCryptorNotReady = false
internal val defaultKeyDerivationAlgorithm = FrameCryptorKeyDerivationAlgorithm.PBKDF2
internal val defaultKeySize = KeyProviderKeySize.BITS_128

data class E2EEOptions(
var keyProvider: KeyProvider = BaseKeyProvider(
Expand All @@ -37,6 +38,7 @@ data class E2EEOptions(
defaultKeyRingSize,
defaultDiscardFrameWhenCryptorNotReady,
defaultKeyDerivationAlgorithm,
defaultKeySize,
),
var encryptionType: Encryption.Type = Encryption.Type.GCM,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ internal class KeyInfo(var participantId: String, var keyIndex: Int, var key: St
}
}

/**
* The length of the AES-GCM key derived from the shared or per-participant key material.
*
* Every participant in a room must use the same size: a 256-bit client and a 128-bit client
* cannot decrypt each other's media or data. The default is [BITS_128], which matches the
* historical behavior of all SDKs.
*/
enum class KeyProviderKeySize(val bits: Int) {
BITS_128(128),
BITS_256(256),
}
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved

interface KeyProvider {
fun setSharedKey(key: String, keyIndex: Int? = 0): Boolean
fun ratchetSharedKey(keyIndex: Int? = 0): ByteArray
Expand All @@ -51,6 +63,7 @@ class BaseKeyProvider(
keyRingSize: Int = defaultKeyRingSize,
discardFrameWhenCryptorNotReady: Boolean = defaultDiscardFrameWhenCryptorNotReady,
keyDerivationAlgorithm: FrameCryptorKeyDerivationAlgorithm = defaultKeyDerivationAlgorithm,
keySize: KeyProviderKeySize = defaultKeySize,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Precompiled E2EE clients fail after upgrade

Precompiled clients using BaseKeyProvider constructor arguments hit NoSuchMethodError after this upgrade. Adding keySize removes the JVM constructor signatures those clients reference.

Learn more

Kotlin compiles calls with omitted constructor parameters against a synthetic JVM constructor containing every parameter and a default-value mask. Adding keySize replaces that signature, as well as the eight-argument constructor. An already-compiled Android module that calls the old constructor still links successfully during packaging but fails when the call runs. The no-argument constructor remains available, so this affects callers that supply any arguments.

Example: An existing compiled library calls BaseKeyProvider(enableSharedKey = false). An application upgrades this SDK without rebuilding that library; invoking its E2EE setup throws NoSuchMethodError instead of creating a provider.

Recommended fix: Preserve the old JVM constructor signatures, including the synthetic default-argument form, while exposing the new size configuration through a compatible additional API. Verify compatibility against a client compiled using the base SDK.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

) : KeyProvider {

private val latestSetIndex = mutableMapOf<String, Int>()
Expand All @@ -64,6 +77,7 @@ class BaseKeyProvider(
keyRingSize,
discardFrameWhenCryptorNotReady,
keyDerivationAlgorithm,
keySize.bits,
)

override fun setSharedKey(key: String, keyIndex: Int?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ constructor(
* Options for end-to-end encryption. Must be setup prior to [connect].
*
* If null, e2ee will be disabled.
*
* To use AES-256-GCM frame keys instead of the default AES-128-GCM, pass a key size to the
* key provider. All participants in the room must use the same key size.
* ```
* val keyProvider = BaseKeyProvider(keySize = KeyProviderKeySize.BITS_256)
* keyProvider.setSharedKey("my-shared-key")
* room.e2eeOptions = E2EEOptions(keyProvider = keyProvider)
* ```
*/
var e2eeOptions: E2EEOptions? = null

Expand Down