/** * Per-participant context holding the cryptographic keys and * encode/decode functions */ export class Context { /** * @param {Object} options */ constructor({ sharedKey }?: any); _cryptoKeyRing: any[]; _currentKeyIndex: number; _sendCounts: Map; _sharedKey: any; /** * Derives the different subkeys and starts using them for encryption or * decryption. * @param {Uint8Array|false} key bytes. Pass false to disable. * @param {Number} keyIndex */ setKey(key: Uint8Array | false, keyIndex?: number): Promise; /** * Sets a set of keys and resets the sendCount. * decryption. * @param {Object} keys set of keys. * @param {Number} keyIndex optional * @private */ private _setKeys; _sendCount: bigint; /** * Function that will be injected in a stream and will encrypt the given encoded frames. * * @param {RTCEncodedVideoFrame|RTCEncodedAudioFrame} encodedFrame - Encoded video frame. * @param {TransformStreamDefaultController} controller - TransportStreamController. * * The VP8 payload descriptor described in * https://tools.ietf.org/html/rfc7741#section-4.2 * is part of the RTP packet and not part of the frame and is not controllable by us. * This is fine as the SFU keeps having access to it for routing. * * The encrypted frame is formed as follows: * 1) Leave the first (10, 3, 1) bytes unencrypted, depending on the frame type and kind. * 2) Form the GCM IV for the frame as described above. * 3) Encrypt the rest of the frame using AES-GCM. * 4) Allocate space for the encrypted frame. * 5) Copy the unencrypted bytes to the start of the encrypted frame. * 6) Append the ciphertext to the encrypted frame. * 7) Append the IV. * 8) Append a single byte for the key identifier. * 9) Enqueue the encrypted frame for sending. */ encodeFunction(encodedFrame: any | any, controller: TransformStreamDefaultController): Promise; /** * Function that will be injected in a stream and will decrypt the given encoded frames. * * @param {RTCEncodedVideoFrame|RTCEncodedAudioFrame} encodedFrame - Encoded video frame. * @param {TransformStreamDefaultController} controller - TransportStreamController. */ decodeFunction(encodedFrame: any | any, controller: TransformStreamDefaultController): Promise; /** * Function that will decrypt the given encoded frame. If the decryption fails, it will * ratchet the key for up to RATCHET_WINDOW_SIZE times. * * @param {RTCEncodedVideoFrame|RTCEncodedAudioFrame} encodedFrame - Encoded video frame. * @param {number} keyIndex - the index of the decryption data in _cryptoKeyRing array. * @param {number} ratchetCount - the number of retries after ratcheting the key. * @returns {Promise} - The decrypted frame. * @private */ private _decryptFrame; /** * Construct the IV used for AES-GCM and sent (in plain) with the packet similar to * https://tools.ietf.org/html/rfc7714#section-8.1 * It concatenates * - the 32 bit synchronization source (SSRC) given on the encoded frame, * - the 32 bit rtp timestamp given on the encoded frame, * - a send counter that is specific to the SSRC. Starts at a random number. * The send counter is essentially the pictureId but we currently have to implement this ourselves. * There is no XOR with a salt. Note that this IV leaks the SSRC to the receiver but since this is * randomly generated and SFUs may not rewrite this is considered acceptable. * The SSRC is used to allow demultiplexing multiple streams with the same key, as described in * https://tools.ietf.org/html/rfc3711#section-4.1.1 * The RTP timestamp is 32 bits and advances by the codec clock rate (90khz for video, 48khz for * opus audio) every second. For video it rolls over roughly every 13 hours. * The send counter will advance at the frame rate (30fps for video, 50fps for 20ms opus audio) * every second. It will take a long time to roll over. * * See also https://developer.mozilla.org/en-US/docs/Web/API/AesGcmParams */ _makeIV(synchronizationSource: any, timestamp: any): ArrayBuffer; }