Skip to content

Commit 34996ec

Browse files
authored
Merge branch 'main' into td/unmodifiableMap
2 parents 0025e43 + f39b941 commit 34996ec

26 files changed

+980
-795
lines changed

.github/workflows/publish.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
- name: Checkout
1414
uses: actions/checkout@v1
1515
- name: Publish
16-
uses: sakebook/actions-flutter-pub-publisher@v1.3.1
16+
uses: k-paxian/dart-package-publisher@v1.5.1
1717
with:
18-
credential: ${{ secrets.CREDENTIAL_JSON }}
19-
flutter_package: true
20-
skip_test: true
21-
dry_run: false
18+
credentialJson: ${{ secrets.CREDENTIAL_JSON }}
19+
flutter: true
20+
skipTests: true
21+
force: true

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
# Changelog
22

33
--------------------------------------------
4+
[1.4.2] - 2024-04-15
5+
6+
* fix.
7+
8+
[1.4.1] - 2024-04-12
9+
10+
* remove RTCConfiguration convert.
11+
12+
[1.4.0] - 2024-04-09
13+
14+
* Fixed bug for RTCConfiguration convert.
15+
16+
[1.3.3] - 2024-04-09
17+
18+
* Fix DC data parse.
19+
20+
[1.3.2] - 2024-04-09
21+
22+
* Fix error when constructing RTCDataChannelInit.
23+
24+
[1.3.1] - 2024-04-08
25+
26+
* Add keyRingSize/discardFrameWhenCryptorNotReady to KeyProviderOptions.
27+
28+
[1.3.0] - 2024-04-08
29+
30+
* update to package:web by @jezell in #29.
31+
432
[1.2.1] - 2024-02-05
533

634
* Downgrade some dependencies make more compatible.

lib/src/e2ee.worker/crypto.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'dart:async';
2-
import 'dart:html' as html;
32
import 'dart:js_util' as jsutil;
43
import 'dart:typed_data';
54

65
import 'package:js/js.dart';
6+
import 'package:web/web.dart' as web;
77

88
@JS('Promise')
99
class Promise<T> {
@@ -18,14 +18,14 @@ class Algorithm {
1818
@JS('crypto.subtle.encrypt')
1919
external Promise<ByteBuffer> encrypt(
2020
dynamic algorithm,
21-
html.CryptoKey key,
21+
web.CryptoKey key,
2222
ByteBuffer data,
2323
);
2424

2525
@JS('crypto.subtle.decrypt')
2626
external Promise<ByteBuffer> decrypt(
2727
dynamic algorithm,
28-
html.CryptoKey key,
28+
web.CryptoKey key,
2929
ByteBuffer data,
3030
);
3131

@@ -52,7 +52,7 @@ ByteBuffer jsArrayBufferFrom(List<int> data) {
5252
}
5353

5454
@JS('crypto.subtle.importKey')
55-
external Promise<html.CryptoKey> importKey(
55+
external Promise<web.CryptoKey> importKey(
5656
String format,
5757
ByteBuffer keyData,
5858
dynamic algorithm,
@@ -63,28 +63,28 @@ external Promise<html.CryptoKey> importKey(
6363
@JS('crypto.subtle.exportKey')
6464
external Promise<ByteBuffer> exportKey(
6565
String format,
66-
html.CryptoKey key,
66+
web.CryptoKey key,
6767
);
6868

6969
@JS('crypto.subtle.deriveKey')
70-
external Promise<html.CryptoKey> deriveKey(
70+
external Promise<web.CryptoKey> deriveKey(
7171
dynamic algorithm,
72-
html.CryptoKey baseKey,
72+
web.CryptoKey baseKey,
7373
dynamic derivedKeyAlgorithm,
7474
bool extractable,
7575
List<String> keyUsages);
7676

7777
@JS('crypto.subtle.deriveBits')
7878
external Promise<ByteBuffer> deriveBits(
7979
dynamic algorithm,
80-
html.CryptoKey baseKey,
80+
web.CryptoKey baseKey,
8181
int length,
8282
);
8383

84-
Future<html.CryptoKey> impportKeyFromRawData(List<int> secretKeyData,
84+
Future<web.CryptoKey> impportKeyFromRawData(List<int> secretKeyData,
8585
{required String webCryptoAlgorithm,
8686
required List<String> keyUsages}) async {
87-
return jsutil.promiseToFuture<html.CryptoKey>(importKey(
87+
return jsutil.promiseToFuture<web.CryptoKey>(importKey(
8888
'raw',
8989
jsArrayBufferFrom(secretKeyData),
9090
jsutil.jsify({'name': webCryptoAlgorithm}),

lib/src/e2ee.worker/e2ee.cryptor.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import 'dart:async';
2-
import 'dart:html';
32
import 'dart:js';
3+
import 'dart:js_interop';
44
import 'dart:js_util' as jsutil;
55
import 'dart:math';
66
import 'dart:typed_data';
77

88
import 'package:dart_webrtc/src/rtc_transform_stream.dart';
9+
import 'package:web/web.dart' as web;
10+
911
import 'crypto.dart' as crypto;
1012
import 'e2ee.keyhandler.dart';
1113
import 'e2ee.logger.dart';
@@ -136,7 +138,7 @@ class FrameCryptor {
136138
bool _enabled = false;
137139
CryptorError lastError = CryptorError.kNew;
138140
int currentKeyIndex = 0;
139-
final DedicatedWorkerGlobalScope worker;
141+
final web.DedicatedWorkerGlobalScope worker;
140142
SifGuard sifGuard = SifGuard();
141143

142144
void setParticipant(String identity, ParticipantKeyHandler keys) {
@@ -219,7 +221,7 @@ class FrameCryptor {
219221
}
220222

221223
void postMessage(Object message) {
222-
worker.postMessage(message);
224+
worker.postMessage(message.jsify());
223225
}
224226

225227
Future<void> setupTransform({
@@ -299,6 +301,9 @@ class FrameCryptor {
299301
if (!enabled ||
300302
// skip for encryption for empty dtx frames
301303
buffer.isEmpty) {
304+
if (keyOptions.discardFrameWhenCryptorNotReady) {
305+
return;
306+
}
302307
controller.enqueue(frame);
303308
return;
304309
}
@@ -403,6 +408,9 @@ class FrameCryptor {
403408
// skip for encryption for empty dtx frames
404409
buffer.isEmpty) {
405410
sifGuard.recordUserFrame();
411+
if (keyOptions.discardFrameWhenCryptorNotReady) {
412+
return;
413+
}
406414
controller.enqueue(frame);
407415
return;
408416
}
@@ -480,7 +488,7 @@ class FrameCryptor {
480488
));
481489

482490
if (currentkeySet != initialKeySet) {
483-
logger.warning(
491+
logger.fine(
484492
'ratchetKey: decryption ok, reset state to kKeyRatcheted');
485493
await keyHandler.setKeySetFromMaterial(
486494
currentkeySet, initialKeyIndex);

lib/src/e2ee.worker/e2ee.keyhandler.dart

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
import 'dart:async';
2-
import 'dart:html';
32
import 'dart:js_util' as jsutil;
43
import 'dart:typed_data';
54

5+
import 'package:web/web.dart' as web;
6+
67
import 'crypto.dart' as crypto;
78
import 'e2ee.logger.dart';
89
import 'e2ee.utils.dart';
910

11+
const KEYRING_SIZE = 16;
12+
1013
class KeyOptions {
1114
KeyOptions({
1215
required this.sharedKey,
1316
required this.ratchetSalt,
1417
required this.ratchetWindowSize,
1518
this.uncryptedMagicBytes,
1619
this.failureTolerance = -1,
20+
this.keyRingSze = KEYRING_SIZE,
21+
this.discardFrameWhenCryptorNotReady = false,
1722
});
1823
bool sharedKey;
1924
Uint8List ratchetSalt;
2025
int ratchetWindowSize = 0;
2126
int failureTolerance;
2227
Uint8List? uncryptedMagicBytes;
28+
int keyRingSze;
29+
bool discardFrameWhenCryptorNotReady;
2330

2431
@override
2532
String toString() {
@@ -29,7 +36,7 @@ class KeyOptions {
2936

3037
class KeyProvider {
3138
KeyProvider(this.worker, this.id, this.keyProviderOptions);
32-
final DedicatedWorkerGlobalScope worker;
39+
final web.DedicatedWorkerGlobalScope worker;
3340
final String id;
3441
final KeyOptions keyProviderOptions;
3542
var participantKeys = <String, ParticipantKeyHandler>{};
@@ -76,31 +83,34 @@ class KeyProvider {
7683
}
7784
}
7885

79-
const KEYRING_SIZE = 16;
80-
8186
class KeySet {
8287
KeySet(this.material, this.encryptionKey);
83-
CryptoKey material;
84-
CryptoKey encryptionKey;
88+
web.CryptoKey material;
89+
web.CryptoKey encryptionKey;
8590
}
8691

8792
class ParticipantKeyHandler {
8893
ParticipantKeyHandler({
8994
required this.worker,
9095
required this.keyOptions,
9196
required this.participantIdentity,
92-
});
97+
}) {
98+
if (keyOptions.keyRingSze <= 0 || keyOptions.keyRingSze > 255) {
99+
throw Exception('Invalid key ring size');
100+
}
101+
cryptoKeyRing = List.filled(keyOptions.keyRingSze, null);
102+
}
93103
int currentKeyIndex = 0;
94104

95-
List<KeySet?> cryptoKeyRing = List.filled(KEYRING_SIZE, null);
105+
late List<KeySet?> cryptoKeyRing;
96106

97107
bool _hasValidKey = false;
98108

99109
bool get hasValidKey => _hasValidKey;
100110

101111
final KeyOptions keyOptions;
102112

103-
final DedicatedWorkerGlobalScope worker;
113+
final web.DedicatedWorkerGlobalScope worker;
104114

105115
final String participantIdentity;
106116

@@ -157,8 +167,8 @@ class ParticipantKeyHandler {
157167
return newKey;
158168
}
159169

160-
Future<CryptoKey> ratchetMaterial(
161-
CryptoKey currentMaterial, ByteBuffer newKeyBuffer) async {
170+
Future<web.CryptoKey> ratchetMaterial(
171+
web.CryptoKey currentMaterial, ByteBuffer newKeyBuffer) async {
162172
var newMaterial = await jsutil.promiseToFuture(crypto.importKey(
163173
'raw',
164174
newKeyBuffer,
@@ -194,14 +204,14 @@ class ParticipantKeyHandler {
194204

195205
/// Derives a set of keys from the master key.
196206
/// See https://tools.ietf.org/html/draft-omara-sframe-00#section-4.3.1
197-
Future<KeySet> deriveKeys(CryptoKey material, Uint8List salt) async {
207+
Future<KeySet> deriveKeys(web.CryptoKey material, Uint8List salt) async {
198208
var algorithmOptions =
199209
getAlgoOptions((material.algorithm as crypto.Algorithm).name, salt);
200210

201211
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveKey#HKDF
202212
// https://developer.mozilla.org/en-US/docs/Web/API/HkdfParams
203213
var encryptionKey =
204-
await jsutil.promiseToFuture<CryptoKey>(crypto.deriveKey(
214+
await jsutil.promiseToFuture<web.CryptoKey>(crypto.deriveKey(
205215
jsutil.jsify(algorithmOptions),
206216
material,
207217
jsutil.jsify({'name': 'AES-GCM', 'length': 128}),
@@ -215,7 +225,7 @@ class ParticipantKeyHandler {
215225
/// Ratchets a key. See
216226
/// https://tools.ietf.org/html/draft-omara-sframe-00#section-4.3.5.1
217227
218-
Future<Uint8List> ratchet(CryptoKey material, Uint8List salt) async {
228+
Future<Uint8List> ratchet(web.CryptoKey material, Uint8List salt) async {
219229
var algorithmOptions = getAlgoOptions('PBKDF2', salt);
220230

221231
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveBits

lib/src/e2ee.worker/e2ee.utils.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import 'dart:html';
21
import 'dart:js' as js;
32
import 'dart:typed_data';
43

4+
import 'package:js/js_util.dart';
5+
import 'package:web/web.dart' as web;
6+
57
import 'crypto.dart' as crypto;
68

79
bool isE2EESupported() {
@@ -17,10 +19,10 @@ bool isInsertableStreamSupported() {
1719
js.context['RTCRtpSender']['prototype']['createEncodedStreams'] != null;
1820
}
1921

20-
Future<CryptoKey> importKey(
22+
Future<web.CryptoKey> importKey(
2123
Uint8List keyBytes, String algorithm, String usage) {
2224
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
23-
return promiseToFuture<CryptoKey>(crypto.importKey(
25+
return promiseToFuture<web.CryptoKey>(crypto.importKey(
2426
'raw',
2527
crypto.jsArrayBufferFrom(keyBytes),
2628
js.JsObject.jsify({'name': algorithm}),
@@ -29,10 +31,10 @@ Future<CryptoKey> importKey(
2931
));
3032
}
3133

32-
Future<CryptoKey> createKeyMaterialFromString(
34+
Future<web.CryptoKey> createKeyMaterialFromString(
3335
Uint8List keyBytes, String algorithm, String usage) {
3436
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
35-
return promiseToFuture<CryptoKey>(crypto.importKey(
37+
return promiseToFuture<web.CryptoKey>(crypto.importKey(
3638
'raw',
3739
crypto.jsArrayBufferFrom(keyBytes),
3840
js.JsObject.jsify({'name': 'PBKDF2'}),

0 commit comments

Comments
 (0)