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,
Comment thread
davidliu marked this conversation as resolved.
Resolved
) : 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
Loading