-
Notifications
You must be signed in to change notification settings - Fork 111
feat(e2ee): support e2ee #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
71f66c9
e327a1d
14e95f6
d448aa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ import { | |
| import { FfiClient } from './ffi_client.js'; | ||
|
|
||
| const DEFAULT_RATCHET_SALT = new TextEncoder().encode('LKFrameEncryptionKey'); | ||
| const DEFAULT_RATCHET_WINDOW_SIZE = 16; | ||
| const DEFAULT_RATCHET_WINDOW_SIZE = 10; | ||
| const DEFAULT_FAILURE_TOLERANCE = -1; | ||
|
|
||
| export interface KeyProviderOptions { | ||
|
|
@@ -123,14 +123,15 @@ export class KeyProvider { | |
| return (res.message.value as RatchetSharedKeyResponse).newKey!; | ||
| } | ||
|
|
||
| setKey(participantIdentity: string, keyIndex: number) { | ||
| setKey(participantIdentity: string, key: Uint8Array, keyIndex: number) { | ||
| const req = new E2eeRequest({ | ||
| roomHandle: this.roomHandle, | ||
| message: { | ||
| case: 'setKey', | ||
| value: new SetKeyRequest({ | ||
| keyIndex: keyIndex, | ||
| participantIdentity: participantIdentity, | ||
| key, | ||
| }), | ||
| }, | ||
| }); | ||
|
|
@@ -191,12 +192,20 @@ export class KeyProvider { | |
| export class FrameCryptor { | ||
| private roomHandle = BigInt(0); | ||
| participantIdentity: string; | ||
| trackSid: string; | ||
| keyIndex: number; | ||
| enabled: boolean; | ||
|
|
||
| constructor(roomHandle: bigint, participantIdentity: string, keyIndex: number, enabled: boolean) { | ||
| constructor( | ||
| roomHandle: bigint, | ||
| participantIdentity: string, | ||
| trackSid: string, | ||
| keyIndex: number, | ||
| enabled: boolean, | ||
| ) { | ||
| this.roomHandle = roomHandle; | ||
| this.participantIdentity = participantIdentity; | ||
| this.trackSid = trackSid; | ||
| this.keyIndex = keyIndex; | ||
| this.enabled = enabled; | ||
| } | ||
|
|
@@ -209,6 +218,7 @@ export class FrameCryptor { | |
| case: 'cryptorSetEnabled', | ||
| value: new FrameCryptorSetEnabledRequest({ | ||
| participantIdentity: this.participantIdentity, | ||
| trackSid: this.trackSid, | ||
| enabled: this.enabled, | ||
| }), | ||
| }, | ||
|
|
@@ -230,6 +240,7 @@ export class FrameCryptor { | |
| case: 'cryptorSetKeyIndex', | ||
| value: new FrameCryptorSetKeyIndexRequest({ | ||
| participantIdentity: this.participantIdentity, | ||
| trackSid: this.trackSid, | ||
| keyIndex: this.keyIndex, | ||
| }), | ||
| }, | ||
|
Comment on lines
+213
to
246
|
||
|
|
@@ -262,6 +273,22 @@ export class E2EEManager { | |
| this.keyProvider = new KeyProvider(roomHandle, options.keyProviderOptions); | ||
| } | ||
|
|
||
| setKey(participantIdentity: string, key: Uint8Array, keyIndex: number) { | ||
| this.keyProvider.setKey(participantIdentity, key, keyIndex); | ||
| } | ||
|
|
||
| setSharedKey(sharedKey: Uint8Array, keyIndex: number) { | ||
| this.keyProvider.setSharedKey(sharedKey, keyIndex); | ||
| } | ||
|
|
||
| exportKey(participantIdentity: string, keyIndex: number): Uint8Array { | ||
| return this.keyProvider.exportKey(participantIdentity, keyIndex); | ||
| } | ||
|
|
||
| exportSharedKey(keyIndex: number): Uint8Array { | ||
| return this.keyProvider.exportSharedKey(keyIndex); | ||
| } | ||
|
|
||
| setEnabled(enabled: boolean) { | ||
| this.enabled = enabled; | ||
| const req = new E2eeRequest({ | ||
|
|
@@ -305,6 +332,7 @@ export class E2EEManager { | |
| new FrameCryptor( | ||
| this.roomHandle, | ||
| cryptor.participantIdentity!, | ||
| cryptor.trackSid!, | ||
| cryptor.keyIndex!, | ||
| cryptor.enabled!, | ||
| ), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeyProvider.setKeyis a breaking change for consumers (this class is exported fromsrc/index.ts), since it now requires aUint8Arraykey parameter and changes the method signature/semantics. Consider providing an overload/backwards-compatible alternative (or a new method name) and/or documenting the migration path so downstream users don’t unexpectedly break on upgrade.