26947e96d6
* chore: e2ee. * update. * update. * update. * update. * chore: Use feat/frame-encryption branch of flutter-webrtc. * chore: Add E2EEKEY defines for dart environment, and e2ee switch. * Add encodedInsertableStreams to RTCConfiguration. * update. * feat: Add e2ee indicator for Participant. * feat: add e2ee worker js for flutter web. * dart format. * remove unused file. * fix flutter analyze . * update. * update. * add: indicate for decryption failure, and string key. * remove .lock files. * update. * update. * update e2ee.worker for web. * feat: support setCodecPreferences. * state TrackE2EEStateEvent. * fix wrong import interface from dart_webrtc. * update. * update. * update. * update. * update pubspec.lock. * chore: update protocol and add EncryptionType for Participant. * Update lib/src/e2ee/options.dart Co-authored-by: Théo Monnom <theo.monnom@outlook.com> * fix typo. * revert changes for internal import. * Add _cleanUp() for previous room. * Add e2ee supports detection method for native/web. * Remove redundant overriding methods. * dart format. * Add e2ee.worker code and deployment docs. * chore: remove duplicate words. * chore: using Pbkdf2 derive the key. * Update pubspec.yaml * fix e2ee for safari. * fix key length. * update e2ee.worker.dart.js. * fix. * update proto. * update. * chore: add simulate for rachetKey. * update. * chore: key ratchet for flutter web. * update. * update. * update. * chore: key ratchet export for web. * bump version for xframeworks. * update. * chore: some changes for key safety ratcheting. * update. * fix typo. * update. * rename. * magic bytes for web. * bump version for flutter-webrtc. * fix analyzer. --------- Co-authored-by: Théo Monnom <theo.monnom@outlook.com>
67 lines
1.8 KiB
Dart
67 lines
1.8 KiB
Dart
import 'dart:html';
|
|
import 'dart:js' as js;
|
|
import 'dart:js_util';
|
|
import 'dart:typed_data';
|
|
|
|
import 'crypto.dart' as crypto;
|
|
|
|
bool isE2EESupported() {
|
|
return isInsertableStreamSupported() || isScriptTransformSupported();
|
|
}
|
|
|
|
bool isScriptTransformSupported() {
|
|
return js.context['RTCRtpScriptTransform'] != null;
|
|
}
|
|
|
|
bool isInsertableStreamSupported() {
|
|
return js.context['RTCRtpSender'] != null &&
|
|
js.context['RTCRtpSender']['prototype']['createEncodedStreams'] != null;
|
|
}
|
|
|
|
Future<CryptoKey> importKey(
|
|
Uint8List keyBytes, String algorithm, String usage) {
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
|
|
return promiseToFuture<CryptoKey>(crypto.importKey(
|
|
'raw',
|
|
crypto.jsArrayBufferFrom(keyBytes),
|
|
js.JsObject.jsify({'name': algorithm}),
|
|
false,
|
|
usage == 'derive' ? ['deriveBits', 'deriveKey'] : ['encrypt', 'decrypt'],
|
|
));
|
|
}
|
|
|
|
Future<CryptoKey> createKeyMaterialFromString(
|
|
Uint8List keyBytes, String algorithm, String usage) {
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
|
|
return promiseToFuture<CryptoKey>(crypto.importKey(
|
|
'raw',
|
|
crypto.jsArrayBufferFrom(keyBytes),
|
|
js.JsObject.jsify({'name': 'PBKDF2'}),
|
|
false,
|
|
['deriveBits', 'deriveKey'],
|
|
));
|
|
}
|
|
|
|
dynamic getAlgoOptions(String algorithmName, Uint8List salt) {
|
|
switch (algorithmName) {
|
|
case 'HKDF':
|
|
return {
|
|
'name': 'HKDF',
|
|
'salt': crypto.jsArrayBufferFrom(salt),
|
|
'hash': 'SHA-256',
|
|
'info': crypto.jsArrayBufferFrom(Uint8List(128)),
|
|
};
|
|
case 'PBKDF2':
|
|
{
|
|
return {
|
|
'name': 'PBKDF2',
|
|
'salt': crypto.jsArrayBufferFrom(salt),
|
|
'hash': 'SHA-256',
|
|
'iterations': 100000,
|
|
};
|
|
}
|
|
default:
|
|
throw Exception('algorithm $algorithmName is currently unsupported');
|
|
}
|
|
}
|