Files
CloudWebRTC 26947e96d6 e2ee. (#226)
* 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>
2023-04-27 17:54:32 +08:00

95 lines
2.0 KiB
Dart

import 'dart:async';
import 'dart:typed_data';
import 'dart:js_util' as jsutil;
import 'dart:html' as html;
import 'package:js/js.dart';
@JS('Promise')
class Promise<T> {
external factory Promise._();
}
@JS('Algorithm')
class Algorithm {
external String get name;
}
@JS('crypto.subtle.encrypt')
external Promise<ByteBuffer> encrypt(
dynamic algorithm,
html.CryptoKey key,
ByteBuffer data,
);
@JS('crypto.subtle.decrypt')
external Promise<ByteBuffer> decrypt(
dynamic algorithm,
html.CryptoKey key,
ByteBuffer data,
);
@JS()
@anonymous
class AesGcmParams {
external factory AesGcmParams({
required String name,
required ByteBuffer iv,
ByteBuffer? additionalData,
int tagLength = 128,
});
}
ByteBuffer jsArrayBufferFrom(List<int> data) {
// Avoid copying if possible
if (data is Uint8List &&
data.offsetInBytes == 0 &&
data.lengthInBytes == data.buffer.lengthInBytes) {
return data.buffer;
}
// Copy
return Uint8List.fromList(data).buffer;
}
@JS('crypto.subtle.importKey')
external Promise<html.CryptoKey> importKey(
String format,
ByteBuffer keyData,
dynamic algorithm,
bool extractable,
List<String> keyUsages,
);
@JS('crypto.subtle.exportKey')
external Promise<ByteBuffer> exportKey(
String format,
html.CryptoKey key,
);
@JS('crypto.subtle.deriveKey')
external Promise<html.CryptoKey> deriveKey(
dynamic algorithm,
html.CryptoKey baseKey,
dynamic derivedKeyAlgorithm,
bool extractable,
List<String> keyUsages);
@JS('crypto.subtle.deriveBits')
external Promise<ByteBuffer> deriveBits(
dynamic algorithm,
html.CryptoKey baseKey,
int length,
);
Future<html.CryptoKey> impportKeyFromRawData(List<int> secretKeyData,
{required String webCryptoAlgorithm,
required List<String> keyUsages}) async {
return jsutil.promiseToFuture<html.CryptoKey>(importKey(
'raw',
jsArrayBufferFrom(secretKeyData),
jsutil.jsify({'name': webCryptoAlgorithm}),
false,
keyUsages,
));
}