Browse Source

always use Argon2FfiFlutter from base package, add windows support, etc.

remove-cryptography-dependency
Herbert Poul 4 years ago
parent
commit
7793e1fed4
  1. 12
      .github/workflows/dart.yml
  2. 18
      README.md
  3. BIN
      argon2_ffi_plugin.dll
  4. 24
      bin/_argon2.dart
  5. 10
      bin/kdbx.dart
  6. 9
      example/pubspec.lock
  7. 19
      test/internal/test_utils.dart
  8. 3
      test/kdbx4_test.dart

12
.github/workflows/dart.yml

@ -4,14 +4,18 @@ on: [push]
jobs:
build:
strategy:
matrix:
os: ['ubuntu-latest', 'windows-2019', 'macos-latest']
dart_channel: ['stable']
runs-on: ubuntu-latest
container:
image: google/dart:2.8
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: cedx/setup-dart@v2
with:
release-channel: ${{ matrix.dart_channel }}
- name: Install dependencies
run: pub get
- name: Run tests

18
README.md

@ -24,6 +24,24 @@ TODO
root directory contains shared libraris (libargon2*) which are built from
https://github.com/authpass/argon2_ffi
* MacOS:
* argon2_ffi/ios/Classes
* `cmake . && cmake --build .`
* `cp libargon2_ffi.dylib kdbx.dart/`
* Linux:
* argon2_ffi/ios/Classes
* `cmake . && cmake --build .`
* `cp libargon2_ffi.so kdbx.dart/`
* Windows:
* Install Visual Studio Commnity Edition with C++ Development environment
* Start "Developer Command Prompt for VS 2019"
* argon2_ffi/ios/Classes:
```
cmake .
cmake --build .
cp Debug\argon2_ffi.dll C:\kdbx.dart\argon2_ffi_plugin.dll
```
# OLD INFO:
# TODO

BIN
argon2_ffi_plugin.dll

Binary file not shown.

24
bin/_argon2.dart

@ -1,24 +0,0 @@
// ignore_for_file: non_constant_identifier_names
//typedef HashStuff = Pointer<Utf8> Function(Pointer<Utf8> str);
import 'dart:ffi';
import 'dart:io';
import 'package:argon2_ffi_base/argon2_ffi_base.dart';
// TODO: This should be somehow combined with the test variant
// which also loads the requierd dylib/so files.
class Argon2Test extends Argon2Base {
Argon2Test() {
final argon2lib = Platform.isMacOS
? DynamicLibrary.open('libargon2_ffi.dylib')
: DynamicLibrary.open('./libargon2_ffi.so');
argon2hash = argon2lib
.lookup<NativeFunction<Argon2HashNative>>('hp_argon2_hash')
.asFunction();
}
@override
Argon2Hash argon2hash;
}

10
bin/kdbx.dart

@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:ffi';
import 'dart:io';
import 'package:argon2_ffi_base/argon2_ffi_base.dart';
import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:kdbx/kdbx.dart';
@ -11,13 +13,13 @@ import 'package:logging/logging.dart';
import 'package:logging_appenders/logging_appenders.dart';
import 'package:prompts/prompts.dart' as prompts;
import '_argon2.dart';
final _logger = Logger('kdbx');
void main(List<String> arguments) {
exitCode = 0;
final path = Platform.script.resolve('../argon2_ffi_plugin.dll').toFilePath();
print('loading $path');
DynamicLibrary.open(path);
final runner = KdbxCommandRunner('kdbx', 'Kdbx Utility');
runner.run(arguments).catchError((dynamic error, StackTrace stackTrace) {
if (error is! UsageException) {
@ -92,7 +94,7 @@ abstract class KdbxFileCommand extends Command<void> {
final keyFileData =
keyFile == null ? null : await File(keyFile).readAsBytes();
final file = await KdbxFormat(Argon2Test()).read(
final file = await KdbxFormat(Argon2FfiFlutter()).read(
bytes,
Credentials.composite(ProtectedValue.fromString(password), keyFileData),
);

9
example/pubspec.lock

@ -1,6 +1,13 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
argon2_ffi_base:
dependency: transitive
description:
name: argon2_ffi_base
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
args:
dependency: transitive
description:
@ -231,6 +238,6 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.7.0"
version: "4.2.0"
sdks:
dart: ">=2.8.0 <3.0.0"

19
test/internal/test_utils.dart

@ -1,5 +1,4 @@
//typedef HashStuff = Pointer<Utf8> Function(Pointer<Utf8> str);
import 'dart:ffi';
import 'dart:io';
import 'dart:typed_data';
@ -8,26 +7,12 @@ import 'package:kdbx/kdbx.dart';
// ignore_for_file: non_constant_identifier_names
class Argon2Test extends Argon2Base {
Argon2Test() {
final argon2lib = Platform.isMacOS
? DynamicLibrary.open('libargon2_ffi.dylib')
: DynamicLibrary.open('./libargon2_ffi.so');
argon2hash = argon2lib
.lookup<NativeFunction<Argon2HashNative>>('hp_argon2_hash')
.asFunction();
}
@override
Argon2Hash argon2hash;
}
class TestUtil {
static Future<KdbxFile> readKdbxFile(
String filePath, {
String password = 'asdf',
}) async {
final kdbxFormat = KdbxFormat(Argon2Test());
final kdbxFormat = KdbxFormat(Argon2FfiFlutter());
final data = await File(filePath).readAsBytes();
final file = await kdbxFormat.read(
data, Credentials(ProtectedValue.fromString(password)));
@ -36,7 +21,7 @@ class TestUtil {
static Future<KdbxFile> readKdbxFileBytes(Uint8List data,
{String password = 'asdf'}) async {
final kdbxFormat = KdbxFormat(Argon2Test());
final kdbxFormat = KdbxFormat(Argon2FfiFlutter());
final file = await kdbxFormat.read(
data, Credentials(ProtectedValue.fromString(password)));
return file;

3
test/kdbx4_test.dart

@ -1,5 +1,6 @@
import 'dart:io';
import 'package:argon2_ffi_base/argon2_ffi_base.dart';
import 'package:kdbx/kdbx.dart';
import 'package:kdbx/src/kdbx_header.dart';
import 'package:logging/logging.dart';
@ -15,7 +16,7 @@ final _logger = Logger('kdbx4_test');
void main() {
Logger.root.level = Level.ALL;
PrintAppender().attachToLogger(Logger.root);
final kdbxFormat = KdbxFormat(Argon2Test());
final kdbxFormat = KdbxFormat(Argon2FfiFlutter());
group('Reading', () {
test('bubb', () async {
final data = await File('test/keepassxcpasswords.kdbx').readAsBytes();

Loading…
Cancel
Save