Skip to content

Commit

Permalink
Add keyring size to key provider options (#1085)
Browse files Browse the repository at this point in the history
* Add keyringSize to keyprovider options

* Create serious-buses-travel.md
  • Loading branch information
lukasIO authored Mar 20, 2024
1 parent 9f89e52 commit df5c375
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-buses-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Add keyring size to keyprovider options
6 changes: 1 addition & 5 deletions src/e2ee/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import type { KeyProviderOptions } from './types';

export const ENCRYPTION_ALGORITHM = 'AES-GCM';

// We use a ringbuffer of keys so we can change them and still decode packets that were
// encrypted with an old key. We use a size of 16 which corresponds to the four bits
// in the frame trailer.
export const KEYRING_SIZE = 16;

// How many consecutive frames can fail decrypting before a particular key gets marked as invalid
export const DECRYPTION_FAILURE_TOLERANCE = 10;

Expand Down Expand Up @@ -41,6 +36,7 @@ export const KEY_PROVIDER_DEFAULTS: KeyProviderOptions = {
ratchetSalt: SALT,
ratchetWindowSize: 8,
failureTolerance: DECRYPTION_FAILURE_TOLERANCE,
keyringSize: 16,
} as const;

export const MAX_SIF_COUNT = 100;
Expand Down
1 change: 1 addition & 0 deletions src/e2ee/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export type KeyProviderOptions = {
ratchetSalt: string;
ratchetWindowSize: number;
failureTolerance: number;
keyringSize: number;
};

export type KeyInfo = {
Expand Down
6 changes: 4 additions & 2 deletions src/e2ee/worker/ParticipantKeyHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EventEmitter } from 'events';
import type TypedEventEmitter from 'typed-emitter';
import { workerLogger } from '../../logger';
import { KEYRING_SIZE } from '../constants';
import { KeyHandlerEvent, type ParticipantKeyHandlerCallbacks } from '../events';
import type { KeyProviderOptions, KeySet } from '../types';
import { deriveKeys, importKey, ratchet } from '../utils';
Expand Down Expand Up @@ -39,7 +38,10 @@ export class ParticipantKeyHandler extends (EventEmitter as new () => TypedEvent
constructor(participantIdentity: string, keyProviderOptions: KeyProviderOptions) {
super();
this.currentKeyIndex = 0;
this.cryptoKeyRing = new Array(KEYRING_SIZE).fill(undefined);
if (keyProviderOptions.keyringSize < 1 || keyProviderOptions.keyringSize > 255) {
throw new TypeError('Keyring size needs to be between 1 and 256');
}
this.cryptoKeyRing = new Array(keyProviderOptions.keyringSize).fill(undefined);
this.keyProviderOptions = keyProviderOptions;
this.ratchetPromiseMap = new Map();
this.participantIdentity = participantIdentity;
Expand Down

0 comments on commit df5c375

Please sign in to comment.