Skip to content

Commit

Permalink
Remove comment about EC PKCS #8 not working on Firefox, and add tests (
Browse files Browse the repository at this point in the history
…#117)

* Remove comment about EC PKCS #8 not working on Firefox, and add tests

* Disable `flutter test --platform chrome`
  • Loading branch information
jonasfj authored May 22, 2024
1 parent e0c1734 commit b8f6aeb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- run: flutter pub get
- run: flutter pub run webcrypto:setup
- run: flutter test
- run: flutter test --platform chrome
#- run: flutter test --platform chrome
- run: flutter test integration_test/webcrypto_test.dart -d windows
working-directory: ./example
- uses: nanasess/setup-chromedriver@v2
Expand Down
15 changes: 4 additions & 11 deletions lib/src/testing/webcrypto/ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ final runner = TestRunner.asymmetric<EcdhPrivateKey, EcdhPublicKey>(
algorithm: 'ECDH',
importPrivateRawKey: null, // not supported
exportPrivateRawKey: null,
// HACK: PKCS8 is not support for ECDH / ECDSA on firefox:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1133698
//
// So filter away PKCS8 test data and functions when running on gecko.
importPrivatePkcs8Key: nullOnFirefox((keyData, keyImportParams) =>
EcdhPrivateKey.importPkcs8Key(keyData, curveFromJson(keyImportParams))),
exportPrivatePkcs8Key: nullOnFirefox((key) => key.exportPkcs8Key()),
importPrivatePkcs8Key: (keyData, keyImportParams) =>
EcdhPrivateKey.importPkcs8Key(keyData, curveFromJson(keyImportParams)),
exportPrivatePkcs8Key: (key) => key.exportPkcs8Key(),
importPrivateJsonWebKey: (jsonWebKeyData, keyImportParams) =>
EcdhPrivateKey.importJsonWebKey(
jsonWebKeyData, curveFromJson(keyImportParams)),
Expand Down Expand Up @@ -70,10 +66,7 @@ final runner = TestRunner.asymmetric<EcdhPrivateKey, EcdhPublicKey>(
length,
keys.publicKey,
),
testData: _testData.map((c) => {
...c,
'privatePkcs8KeyData': nullOnFirefox(c['privatePkcs8KeyData']),
}),
testData: _testData,
);

void main() async {
Expand Down
16 changes: 4 additions & 12 deletions lib/src/testing/webcrypto/ecdsa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@
import 'package:webcrypto/webcrypto.dart';
import '../utils/utils.dart';
import '../utils/testrunner.dart';
import '../utils/detected_runtime.dart';

final runner = TestRunner.asymmetric<EcdsaPrivateKey, EcdsaPublicKey>(
algorithm: 'ECDSA',
importPrivateRawKey: null, // not supported
exportPrivateRawKey: null,
// HACK: PKCS8 is not support for ECDH / ECDSA on firefox:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1133698
//
// So filter away PKCS8 test data and functions when running on gecko.
importPrivatePkcs8Key: nullOnFirefox((keyData, keyImportParams) =>
EcdsaPrivateKey.importPkcs8Key(keyData, curveFromJson(keyImportParams))),
exportPrivatePkcs8Key: nullOnFirefox((key) => key.exportPkcs8Key()),
importPrivatePkcs8Key: (keyData, keyImportParams) =>
EcdsaPrivateKey.importPkcs8Key(keyData, curveFromJson(keyImportParams)),
exportPrivatePkcs8Key: (key) => key.exportPkcs8Key(),
importPrivateJsonWebKey: (jsonWebKeyData, keyImportParams) =>
EcdsaPrivateKey.importJsonWebKey(
jsonWebKeyData, curveFromJson(keyImportParams)),
Expand All @@ -53,10 +48,7 @@ final runner = TestRunner.asymmetric<EcdsaPrivateKey, EcdsaPublicKey>(
key.verifyBytes(signature, data, hashFromJson(verifyParams)),
verifyStream: (key, signature, data, verifyParams) =>
key.verifyStream(signature, data, hashFromJson(verifyParams)),
testData: _testData.map((c) => {
...c,
'privatePkcs8KeyData': nullOnFirefox(c['privatePkcs8KeyData']),
}),
testData: _testData,
);

void main() async {
Expand Down
2 changes: 0 additions & 2 deletions lib/src/webcrypto/webcrypto.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ part of 'webcrypto.dart';
abstract class EcdhPrivateKey {
EcdhPrivateKey._(); // keep the constructor private.

// Note. unsupported on Firefox, see EcdsaPrivateKey.importPkcs8Key
static Future<EcdhPrivateKey> importPkcs8Key(
List<int> keyData,
EllipticCurve curve,
Expand Down Expand Up @@ -48,7 +47,6 @@ abstract class EcdhPrivateKey {
// https://tools.ietf.org/html/rfc6090#appendix-B
Future<Uint8List> deriveBits(int length, EcdhPublicKey publicKey);

// Note. unsupported on Firefox, see EcdsaPrivateKey.importPkcs8Key
Future<Uint8List> exportPkcs8Key();

Future<Map<String, dynamic>> exportJsonWebKey();
Expand Down
4 changes: 0 additions & 4 deletions lib/src/webcrypto/webcrypto.ecdsa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ part of 'webcrypto.dart';
abstract class EcdsaPrivateKey {
EcdsaPrivateKey._(); // keep the constructor private.

// TODO: document or workaround pkcs8 being unsupported on Firefox:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1133698
// See: https://github.com/callstats-io/pem-to-jwk/blob/master/index.js#L126
static Future<EcdsaPrivateKey> importPkcs8Key(
List<int> keyData,
EllipticCurve curve,
Expand Down Expand Up @@ -48,7 +45,6 @@ abstract class EcdsaPrivateKey {
Future<Uint8List> signBytes(List<int> data, Hash hash);
Future<Uint8List> signStream(Stream<List<int>> data, Hash hash);

// Note. unsupported on Firefox, see EcdsaPrivateKey.importPkcs8Key
Future<Uint8List> exportPkcs8Key();

Future<Map<String, dynamic>> exportJsonWebKey();
Expand Down

0 comments on commit b8f6aeb

Please sign in to comment.