google / webcrypto.dart

Cross-platform implementation of Web Cryptography APIs
https://pub.dev/packages/webcrypto
Apache License 2.0
81 stars 48 forks source link

Unsupported operation: package:webcrypto does not work with this version of the Dart DL API. #4

Closed mrcsh closed 3 years ago

mrcsh commented 3 years ago

With the latest flutter beta update my app started throwing the following exception:

I/flutter ( 6872): #1      lookupSymbol.<anonymous closure> (package:webcrypto/src/boringssl/lookup/lookup_symbol_flutter.dart:39:5)
I/flutter ( 6872): #2      lookupSymbol (package:webcrypto/src/boringssl/lookup/lookup_symbol_flutter.dart:54:2)
I/flutter ( 6872): #3      lookupSymbol (package:webcrypto/src/boringssl/lookup/lookup_symbol_flutter.dart)
I/flutter ( 6872): #4      SymbolResolver.lookupFunc (package:webcrypto/src/boringssl/lookup/lookup.dart:28:12)
I/flutter ( 6872): #5      RSA_new (package:webcrypto/src/boringssl/rsa.dart:31:6)
I/flutter ( 6872): #6      RSA_new (package:webcrypto/src/boringssl/rsa.dart)
I/flutter ( 6872): #7      _generateRsaKeyPair (package:webcrypto/src/impl_ffi/im
E/flutter ( 6872): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Exception: Unsupported operation: package:webcrypto does not work with this version of the Dart DL API.Please update to a newer version of package:webcrypto. And ensure thatyou have rebuilt the current version with `flutter pub run webcrypt:setup` if running locally.
E/flutter ( 6872): #0      initialize_dart_dl (package:webcrypto/src/boringssl/lookup/utils.dart:82:5)
E/flutter ( 6872): #1      lookupSymbol.<anonymous closure> (package:webcrypto/src/boringssl/lookup/lookup_symbol_flutter.dart:39:5)
E/flutter ( 6872): #2      lookupSymbol (package:webcrypto/src/boringssl/lookup/lookup_symbol_flutter.dart:54:2)
E/flutter ( 6872): #3      lookupSymbol (package:webcrypto/src/boringssl/lookup/lookup_symbol_flutter.dart)
E/flutter ( 6872): #4      SymbolResolver.lookupFunc (package:webcrypto/src/boringssl/lookup/lookup.dart:28:12)
E/flutter ( 6872): #5      RSA_new (package:webcrypto/src/boringssl/rsa.dart:31:6)
E/flutter ( 6872): #6      RSA_new (package:webcrypto/src/boringssl/rsa.dart)
E/flutter ( 6872): #7      _generateRsaKeyPair (package:webcrypto/src/impl_ffi/impl_ffi.rsa_common.dart:261:38)
E/flutter ( 6872): #8      rsaOaepPrivateKey_generateKey (package:webcrypto/src/impl_ffi/impl_ffi.rsaoaep.dart:68:16)
E/flutter ( 6872): #9      RsaOaepPrivateKey.generateKey (package:webcrypto/src/webcrypto/webcrypto.rsaoaep.dart:50:12)
 flutter doctor -v
[✓] Flutter (Channel beta, 1.24.0-10.2.pre, on Linux, locale en_US.UTF-8)
    • Flutter version 1.24.0-10.2.pre at /ssd/home/csh/lib/flutter
    • Framework revision 022b333a08 (13 days ago), 2020-11-18 11:35:09 -0800
    • Engine revision 07c1eed46b
    • Dart version 2.12.0 (build 2.12.0-29.10.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /ssd/home/csh/Android/Sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_272-b10)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] VS Code (version 1.51.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.16.0

[✓] Connected device (4 available)
    • moto x4 (mobile)                      • ZY224KQLWQ    • android-arm64  • Android 9 (API 28)
    • Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64    • Android 9 (API 28) (emulator)
    • Web Server (web)                      • web-server    • web-javascript • Flutter Tools
    • Chrome (web)                          • chrome        • web-javascript • Google Chrome 87.0.4280.66

! Doctor found issues in 1 category.

I am not sure why it thinks AS is not installed, it is installed and is running.

jonasfj commented 3 years ago

I edited formatting of your issue.

quick note: Please use code fences when posting logs, for large log files please use a gist.

jonasfj commented 3 years ago

Is it correct that you are on Linux and targeting Android?

mrcsh commented 3 years ago

Yes, I am on running tools on Linux (fedora32 if it matters) and building Android (and also web which is why I need to use the beta channel) The code runs fine on Android when built with stable channel tools. The code also ran fine on Android using the beta channel tools before the last flutter upgrade.

jonasfj commented 3 years ago

I've managed to reproduce :D

It seems the Dart SDK used in Flutter 1.24.0-10.2.pre includes https://github.com/dart-lang/sdk/commit/52783837369de45d3372cb6c6b7cdd63e71cd829 which bumps the dynamic library linking versioning in the Dart SDK. Hence, my code will refuse to run..

In this case I just need to update the files I've copied from Dart SDK into package:webcrypto, as these files include the version number allowed. Getting this to work doesn't seem to hard, but I'm having some orthogonal test issues I need to debug before I can publish a fix.


@dcharkes this an interesting case, because I was already using Dart_NewFinalizableHandle_DL it looks as if my code is entirely unaffected by the breaking change in DL API version 2.0, however, I'm unable to expression anywhere that I support both 2.0 and 1.1.

Worse, I can't update my already published package to say that it only supports Dart SDK <2.12.0 -- I'm not sure there is a possible solution to that short of only publishing with an SDK constraint <2.x, where 2.x is then next minor release -- so that I never promise compatibility with future Dart SDK verisons.

jonasfj commented 3 years ago

@mrcsh this should be fixed with webcrypto version 0.2.2 -- it might happen in the future again as the DL API is still early :D

But this package only uses a very small set of the surface and it's quick and easy to fix it.


@mrcsh, curious, what are you using this package for? (if I may inquire :smiley: )

mrcsh commented 3 years ago

Awesome, thanks for the quick resolution. We are using it for end-to-end message encryption. I was having a hard time finding any single crypto package that worked well on mobile and web and supported what we needed, anything that relied on the bouncy-castle stuff was so slow on the browser it was not usable. This package had everything we needed and is fast on the browser. (Fast enough to be only slightly annoying without web compute() actually being asynchronous)

jonasfj commented 3 years ago

(Fast enough to be only slightly annoying without web compute() actually being asynchronous)

This package should be fully asynchronous on the web... or well, I guess that depends on the web browser, but this package passes crypto off to the browser when running on the web, which is why it's fast and hopefully moved entirely off the main-thread.

So even if compute was off-the-mainthread on web I don't think it matters much for this package, it matters if you do other expensive operations yourself, but the actual crypto operations this package does is passed to the browser using an async API. I don't know any browser vendor that wouldn't move that off-the-mainthread.

On Android and iOS this package is async in API, but the actual computation isn't moved off-the-mainthread YET, so using compute will make a difference (for now). The reason the entire API is async is because I want to move all computation off-the-mainthread, so that wrapping calls with compute won't be necessary. I think it's mostly a matter of finding out how to create a thread-pool do some callbacks/ports and manage life-cycle of the thread-pool, or borrow the thread-pool Dart has if possible...

mrcsh commented 3 years ago

It does not appear to be async on the web as far as I can tell, as the UI freezes noticeably during longer crypto calls. (Using chrome). Good to know the truly async stuff is coming in the future, I was wondering why given the async interface it still appeared to behave like it was synchronous.

jonasfj commented 3 years ago

It does not appear to be async on the web as far as I can tell, as the UI freezes noticeably during longer crypto calls. (Using chrome).

@mrcsh, are you doing crypto on large streams? the interface on web will convert streams into byte buffers before doing crypto (on web, on Andorid/iOS streams are streaming), so that could add some main-thread overhead.

If you're interested you're most welcome to investigate it further, it could be things like buffer copying that adds overhead.

mrcsh commented 3 years ago

I am encrypting/decrypting Uint8List(s). It is most notable on images larger than a few hundred kilobytes, with over a couple of megabytes taking 10s of seconds.