Comments (12)
Right, so it's not that easy. It seems that:
swift-sodium
doesn't support AES-GCM. https://github.com/jedisct1/swift-sodiumInvalid argument(s): Failed to lookup symbol 'crypto_aead_aes256gcm_abytes': dlsym(RTLD_DEFAULT, crypto_aead_aes256gcm_abytes): symbol not found
FYI: The 2.1.0 release of sodium_libs now does not depend on swift-sodium
anymore but instead directly include the native libsodium binaries. So at least on iOS/macOS, this problem might be fixed.
from libsodium_dart_bindings.
It's probably terrible way of doing it, but I've copied the XChaCha20 wrappers, renamed them accordingly and it just started to work. It's just amazing.
Very experimental and not tested.
main...tomekit:libsodium_dart_bindings:main
Example code:
test('libsodium', () async {
final libsodium = DynamicLibrary.open('/usr/lib/x86_64-linux-gnu/libsodium.so'); // dpkg -L libsodium-dev | grep "\.so"
final sodium = await SodiumInit.init(libsodium);
// final SecureKey key = sodium.crypto.secretBox.keygen();
final base64MasterKey = "+Hv/rT8HPG+Qmk3zhV2NDA==";
final encryptedKey = "8IK5l6NGSudK/b57goLjZ6ePvfHj+w29D7rle8ShLCLdl0Yy5irmtw==";
final cipherText = "CEs+CRiGBN/P9fANcqmHx4lnRd6wyj5ps2DoDDus9G7Cv+3FHqIy";
final iv = "T4jMtxyX/+s60T3r";
final unwrappedKey = AesKwRfc3394.unwrap(encryptedKey, base64MasterKey);
final secureKey = SecureKey.fromList(sodium, Uint8List.fromList(unwrappedKey));
final decryptedOutputBinary = sodium.crypto.aeadAes256Gcm.decrypt(cipherText: base64Decode(cipherText), nonce: base64Decode(iv), key: secureKey);
final decryptedOutput = utf8.decode(decryptedOutputBinary);
final expectedOutput = "encrypted_test_contents";
assert(decryptedOutput == expectedOutput);
});
from libsodium_dart_bindings.
Generally speaking: Yes, use the FFI-API directly is the way to go. You also do not have to extend the library for that. You can directly instanciate a LibSodiumFFI
simply by passing a DynamicLibrary
object with the loaded libsodium binary to it.
However, I have been planning on adding the AES APIs for quite a while now. So maybe, If you create a PR, I can check if the code is OK and add the missing JS implementation.
from libsodium_dart_bindings.
I will be playing with Dart libsodium and AES-GCM over the next few days, so I will validate if things work OK. I will then create PR.
from libsodium_dart_bindings.
I am trying to use stock: sodium_libs: ^2.0.0
, but would like to import custom sodium
(with experimental AES-GCM added), so I've added below override to dependency_overrides
:
sodium:
git:
url: https://github.com/tomekit/libsodium_dart_bindings.git
ref: main
path: packages/sodium
however when trying to run my unit test, I am getting pretty long list of errors, some of them related to freezed
and some annotation processing?
./../../.pub-cache/git/libsodium_dart_bindings-ad06e5f640970aa78adf8653b67245d958b07384/packages/sodium/lib/src/api/detached_cipher_result.dart:6:6: Error: Error when reading '../../../.pub-cache/git/libsodium_dart_bindings-ad06e5f640970aa78adf8653b67245d958b07384/packages/sodium/lib/src/api/detached_cipher_result.freezed.dart': No such file or directory
part 'detached_cipher_result.freezed.dart';
==
UPDATE: As a temporary solution I've built these files using: flutter pub run build_runner build --delete-conflicting-outputs
in sodium
, and then committed these to different branch and then loaded from the pubspec.yaml
from libsodium_dart_bindings.
Right, so it's not that easy. It seems that: swift-sodium
doesn't support AES-GCM.
https://github.com/jedisct1/swift-sodium
Invalid argument(s): Failed to lookup symbol 'crypto_aead_aes256gcm_abytes': dlsym(RTLD_DEFAULT, crypto_aead_aes256gcm_abytes): symbol not found
from libsodium_dart_bindings.
Oh okay, that is a problem. Maybe you should open an issue over there to see if they can enable it? I guess they leave it out by default for size optimizations.
from libsodium_dart_bindings.
And regarding the freezed files: Yes, that is correct. The generated files are not checked in on purpose, thus the package is not usabled directly from git. Creating a seperate branch is fine. The other option would have been to check it out locally, generate the files and then add it as path dependency.
from libsodium_dart_bindings.
I didn't have time to investigate the issue exactly however it seems that actually both: sodium.crypto.aeadAes256Gcm.decrypt
and sodium.crypto.aeadAes256Gcm.encrypt
functions are failing on a real Android device with: "A low-level libsodium operation has failed", however they work fine on an Android emulator (E.g. Nexus 5 - API 31), as well as Linux and Windows.
On Android I've replaced it with success using: https://github.com/hugo-pcl/native-crypto-flutter
Not an issue report really, but just a comment if someone would like to rely on this.
from libsodium_dart_bindings.
This might have to do with how the native binaries are compiled. Generally, libsodium only includes AES for compatibility reasons, but does not "actively" support it. So I guess you are probably better off using a different library for that usecase anyways...
from libsodium_dart_bindings.
That's really great to hear. Is it possible by any chance that this change also resolves the: "A low-level libsodium operation has failed" for AES on a real Android device?
from libsodium_dart_bindings.
No, I don't think so - the android build hasn't really changed. However, there problem there is not missing symbols, but some low level error. I already compile with all options enabled for android and use the official build scripts, so I don't think the issue is with the flutter bindings, but the C-library itself. You should open an issue at https://github.com/jedisct1/libsodium, maybe there you can find help with that problem.
from libsodium_dart_bindings.
Related Issues (20)
- How to set SecureKey manually? HOT 1
- Full build for Android version HOT 1
- Cannot read properties of undefined (reading 'then') HOT 2
- please update ffi HOT 2
- sodium.js - Cannot read properties of undefined (reading 'then') HOT 5
- Speed of sodium.crypto.secretBox.easy() etc... HOT 4
- Implement crypto_stream_xchacha20 HOT 1
- FFI failure or SodiumInit timing problem? HOT 9
- Flutter_test Failed to lookup symbol 'sodium_init' HOT 9
- Create `Sodium.runIsolated` method to easily run computation heavy cryptographic operations in an isolate HOT 12
- Request for SecretStream encryption/decryption example HOT 7
- Sodium.runIsolated breaking flutter run build HOT 2
- build failure: libsodium.so not found on latest update HOT 4
- Implement cryptoSignEd25519SkToSeed (crypto_sign_ed25519_sk_to_seed) HOT 8
- Use chacha20poly1305 instead of xchacha20poly1305_ietf HOT 2
- Secret stream state initialization; Continue interrupted upload of encrypted stream; HOT 3
- How update flutter_sodium 0.2.0 to sodium_libs? HOT 3
- How to create a shared secret using Scalarmult? HOT 6
- Fails to build on Fedora HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libsodium_dart_bindings.