Skip to content

Commit

Permalink
Merge branch 'master' into refactor-rsaoaep
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfj authored Oct 17, 2024
2 parents 0a93df6 + cdf81ad commit 084db0d
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 25 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ jobs:
- run: flutter test --platform chrome
- run: flutter test integration_test/webcrypto_test.dart -d macos
working-directory: ./example
- uses: nanasess/setup-chromedriver@v2
- name: Run integration_test with chromedriver
working-directory: ./example
run: |
../tool/with-chromedriver.sh flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/webcrypto_test.dart \
-d chrome
# TODO: Enable chromdriver testing on MacOS when it works reliably
#- uses: nanasess/setup-chromedriver@v2
#- name: Run integration_test with chromedriver
# working-directory: ./example
# run: |
# ../tool/with-chromedriver.sh flutter drive \
# --driver=test_driver/integration_test.dart \
# --target=integration_test/webcrypto_test.dart \
# -d chrome
- run: flutter pub run test -p vm,chrome # TODO: Enable firefox if it works
windows:
name: webcrypto on Windows desktop / Chrome / Firefox
Expand Down
1 change: 0 additions & 1 deletion darwin/webcrypto.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Pod::Spec.new do |s|
s.compiler_flags = [
'-DOPENSSL_NO_ASM',
'-DDOPENSSL_SMALL',
'-GCC_WARN_INHIBIT_ALL_WARNINGS',
'-w',
]

Expand Down
3 changes: 3 additions & 0 deletions lib/src/impl_ffi/impl_ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {

@override
final rsaOaepPublicKey = const _StaticRsaOaepPublicKeyImpl();

@override
final pbkdf2SecretKey = const _StaticPbkdf2SecretKeyImpl();
}
17 changes: 13 additions & 4 deletions lib/src/impl_ffi/impl_ffi.pbkdf2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@

part of 'impl_ffi.dart';

Future<Pbkdf2SecretKey> pbkdf2SecretKey_importRawKey(List<int> keyData) async {
return _Pbkdf2SecretKey(Uint8List.fromList(keyData));
Future<Pbkdf2SecretKeyImpl> pbkdf2SecretKey_importRawKey(List<int> keyData) async {
return _Pbkdf2SecretKeyImpl(Uint8List.fromList(keyData));
}

class _Pbkdf2SecretKey implements Pbkdf2SecretKey {
final class _StaticPbkdf2SecretKeyImpl implements StaticPbkdf2SecretKeyImpl {
const _StaticPbkdf2SecretKeyImpl();

@override
Future<Pbkdf2SecretKeyImpl> importRawKey(List<int> keyData) {
return pbkdf2SecretKey_importRawKey(keyData);
}
}

final class _Pbkdf2SecretKeyImpl implements Pbkdf2SecretKeyImpl {
final Uint8List _key;

_Pbkdf2SecretKey(this._key);
_Pbkdf2SecretKeyImpl(this._key);

@override
String toString() {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/impl_interface/impl_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ part 'impl_interface.aescbc.dart';
part 'impl_interface.aesctr.dart';
part 'impl_interface.hmac.dart';
part 'impl_interface.rsaoaep.dart';
part 'impl_interface.pbkdf2.dart';
part 'impl_interface.aesgcm.dart';

/// Interface to be provided by platform implementations.
Expand All @@ -49,4 +50,5 @@ abstract interface class WebCryptoImpl {
StaticHmacSecretKeyImpl get hmacSecretKey;
StaticRsaOaepPrivateKeyImpl get rsaOaepPrivateKey;
StaticRsaOaepPublicKeyImpl get rsaOaepPublicKey;
StaticPbkdf2SecretKeyImpl get pbkdf2SecretKey;
}
23 changes: 23 additions & 0 deletions lib/src/impl_interface/impl_interface.pbkdf2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

part of 'impl_interface.dart';

abstract interface class StaticPbkdf2SecretKeyImpl {
Future<Pbkdf2SecretKeyImpl> importRawKey(List<int> keyData);
}

abstract interface class Pbkdf2SecretKeyImpl {
Future<Uint8List> deriveBits(int length, Hash hash, List<int> salt, int iterations);
}
3 changes: 3 additions & 0 deletions lib/src/impl_js/impl_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {

@override
final rsaOaepPublicKey = const _StaticRsaOaepPublicKeyImpl();

@override
final pbkdf2SecretKey = const _StaticPbkdf2SecretKeyImpl();
}
17 changes: 13 additions & 4 deletions lib/src/impl_js/impl_js.pbkdf2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ part of 'impl_js.dart';

const _pbkdf2AlgorithmName = 'PBKDF2';

Future<Pbkdf2SecretKey> pbkdf2SecretKey_importRawKey(List<int> keyData) async {
return _Pbkdf2SecretKey(await _importKey(
Future<Pbkdf2SecretKeyImpl> pbkdf2SecretKey_importRawKey(List<int> keyData) async {
return _Pbkdf2SecretKeyImpl(await _importKey(
'raw',
keyData,
const subtle.Algorithm(name: _pbkdf2AlgorithmName),
Expand All @@ -31,9 +31,18 @@ Future<Pbkdf2SecretKey> pbkdf2SecretKey_importRawKey(List<int> keyData) async {
));
}

class _Pbkdf2SecretKey implements Pbkdf2SecretKey {
final class _StaticPbkdf2SecretKeyImpl implements StaticPbkdf2SecretKeyImpl {
const _StaticPbkdf2SecretKeyImpl();

@override
Future<Pbkdf2SecretKeyImpl> importRawKey(List<int> keyData) {
return pbkdf2SecretKey_importRawKey(keyData);
}
}

final class _Pbkdf2SecretKeyImpl implements Pbkdf2SecretKeyImpl {
final subtle.JSCryptoKey _key;
_Pbkdf2SecretKey(this._key);
_Pbkdf2SecretKeyImpl(this._key);

@override
String toString() {
Expand Down
2 changes: 0 additions & 2 deletions lib/src/impl_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,3 @@ Future<HkdfSecretKey> hkdfSecretKey_importRawKey(List<int> keyData) =>

//---------------------- PBKDF2

Future<Pbkdf2SecretKey> pbkdf2SecretKey_importRawKey(List<int> keyData) =>
throw _notImplemented;
4 changes: 4 additions & 0 deletions lib/src/impl_stub/impl_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ part 'impl_stub.aesctr.dart';
part 'impl_stub.aesgcm.dart';
part 'impl_stub.hmac.dart';
part 'impl_stub.rsaoaep.dart';
part 'impl_stub.pbkdf2.dart';

const WebCryptoImpl webCryptImpl = _WebCryptoImpl();

Expand All @@ -45,4 +46,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {

@override
final rsaOaepPublicKey = const _StaticRsaOaepPublicKeyImpl();

@override
final pbkdf2SecretKey = const _StaticPbkdf2SecretKeyImpl();
}
24 changes: 24 additions & 0 deletions lib/src/impl_stub/impl_stub.pbkdf2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

part of 'impl_stub.dart';

final class _StaticPbkdf2SecretKeyImpl implements StaticPbkdf2SecretKeyImpl {
const _StaticPbkdf2SecretKeyImpl();

@override
Future<Pbkdf2SecretKeyImpl> importRawKey(List<int> keyData) {
throw UnimplementedError('Not implemented');
}
}
16 changes: 10 additions & 6 deletions lib/src/webcrypto/webcrypto.pbkdf2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ part of 'webcrypto.dart';
///
/// [1]: https://tools.ietf.org/html/rfc8018
// TODO: Rewrite all RFC links to use https://www.rfc-editor.org/rfc/rfcXXXX
@sealed
abstract class Pbkdf2SecretKey {
Pbkdf2SecretKey._(); // keep the constructor private.

final class Pbkdf2SecretKey {
final Pbkdf2SecretKeyImpl _impl;

Pbkdf2SecretKey._(this._impl); // keep the constructor private.

/// Import [Pbkdf2SecretKey] from raw [keyData].
///
/// Creates a [Pbkdf2SecretKey] for key derivation using [keyData].
///
/// {@macro Pbkdf2SecretKey:example}
static Future<Pbkdf2SecretKey> importRawKey(List<int> keyData) {
return impl.pbkdf2SecretKey_importRawKey(keyData);
static Future<Pbkdf2SecretKey> importRawKey(List<int> keyData) async {
final impl = await webCryptImpl.pbkdf2SecretKey.importRawKey(keyData);
return Pbkdf2SecretKey._(impl);
}

/// Derive key from [salt] and password specified as `keyData` in
Expand Down Expand Up @@ -90,5 +93,6 @@ abstract class Pbkdf2SecretKey {
Hash hash,
List<int> salt,
int iterations,
);
) =>
_impl.deriveBits(length, hash, salt, iterations);
}

0 comments on commit 084db0d

Please sign in to comment.