diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index eb3ff6dc..e916e2d9 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -28,7 +28,7 @@ jobs: export HOMESERVER_IMPLEMENTATION=${{matrix.homeserver}} export HOMESERVER="localhost:80" scripts/integration-server-${{matrix.homeserver}}.sh 2>&1 > /dev/null & - sudo apt-get update && sudo apt-get install --no-install-recommends --no-install-suggests -y libolm3 libssl3 sqlite3 libsqlite3-dev + sudo apt-get update && sudo apt-get install --no-install-recommends --no-install-suggests -y libssl3 sqlite3 libsqlite3-dev source scripts/integration-create-environment-variables.sh scripts/integration-prepare-homeserver.sh scripts/prepare.sh @@ -75,7 +75,7 @@ jobs: gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}} - name: Run tests run: | - sudo apt-get update && sudo apt-get install --no-install-recommends --no-install-suggests -y lcov libsqlite3-0 libsqlite3-dev libolm3 libssl3 + sudo apt-get update && sudo apt-get install --no-install-recommends --no-install-suggests -y lcov libsqlite3-0 libsqlite3-dev libssl3 ./scripts/prepare_vodozemac.sh ./scripts/test.sh - uses: actions/upload-artifact@v4 diff --git a/README.md b/README.md index 14c01c9e..59b84879 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,17 @@ Matrix (matrix.org) SDK written in dart. ## Native libraries -For E2EE, libolm must be provided. +For E2EE, vodozemac must be provided. Additionally, OpenSSL (libcrypto) must be provided on native platforms for E2EE. -For flutter apps you can easily import it with the [flutter_olm](https://pub.dev/packages/flutter_olm) and the [flutter_openssl_crypto](https://pub.dev/packages/flutter_openssl_crypto) packages. +For flutter apps you can easily import it with the [flutter_vodozemac](https://pub.dev/packages/flutter_vodozemac) and the [flutter_openssl_crypto](https://pub.dev/packages/flutter_openssl_crypto) packages. ```sh flutter pub add matrix -flutter pub add flutter_olm + +# Optional: For end to end encryption: +flutter pub add flutter_vodozemac flutter pub add flutter_openssl_crypto ``` diff --git a/doc/end-to-end-encryption.md b/doc/end-to-end-encryption.md new file mode 100644 index 00000000..ac848cd3 --- /dev/null +++ b/doc/end-to-end-encryption.md @@ -0,0 +1,29 @@ +To enable end to end encryption you need to setup [Vodozemac](https://pub.dev/packages/vodozemac). For this you need Rust installed locally: [rust-lang.org/tools/install](https://www.rust-lang.org/tools/install) + +For Flutter you can use [flutter_vodozemac](https://pub.dev/packages/flutter_vodozemac). + +```sh +flutter pub add flutter_vodozemac +``` + +You also need [flutter_openssl_crypto](https://pub.dev/packages/flutter_openssl_crypto). + +```sh +flutter pub add flutter_openssl_crypto +``` + +Now before you create your `Client`, init vodozemac: + +```dart +import 'package:flutter_vodozemac/flutter_vodozemac' as vod; + +// ... + +await vod.init(); + +final client = Client(/*...*/); +``` + +This should work on Android, iOS, macOS, Linux and Windows. + +For web you need to compile vodozemac to wasm. [Please refer to the Vodozemac bindings documentation](https://pub.dev/packages/vodozemac#build-for-web). \ No newline at end of file diff --git a/doc/get-started.md b/doc/get-started.md index fa3d1267..f1113728 100644 --- a/doc/get-started.md +++ b/doc/get-started.md @@ -6,10 +6,12 @@ In your `pubspec.yaml` file add the following dependencies: ```yaml matrix: - # If you plan to use the SDK in a Flutter application on IO: + # (Optional) If you plan to use the SDK in a Flutter application on IO + # you need sqflite or sqflite_ffi: sqflite: - # For end to end encryption: - flutter_olm: + # (Optional) For end to end encryption, please head on the + # encryption guide and add these dependencies: + flutter_vodozemac: flutter_openssl_crypto: ``` diff --git a/doc/web.md b/doc/web.md deleted file mode 100644 index fd9f6f20..00000000 --- a/doc/web.md +++ /dev/null @@ -1,25 +0,0 @@ -To use end to end encryption in web you have to download the olm javascript/wasm library: - -```sh -#!/bin/sh -ve -rm -r assets/js/package - -OLM_VERSION=$(cat pubspec.yaml | yq .dependencies.flutter_olm) -DOWNLOAD_PATH="https://github.com/famedly/olm/releases/download/v$OLM_VERSION/olm.zip" - -curl -L $DOWNLOAD_PATH > olm.zip -unzip olm.zip -rm olm.zip -``` - -...and import it in your `index.html`: - -```html - - - ... - - - ... - -``` \ No newline at end of file diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index 13c81b63..090cfb63 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -19,8 +19,6 @@ import 'dart:async'; import 'dart:convert'; -import 'package:vodozemac/vodozemac.dart' as vod; - import 'package:matrix/encryption/cross_signing.dart'; import 'package:matrix/encryption/key_manager.dart'; import 'package:matrix/encryption/key_verification_manager.dart'; @@ -166,7 +164,7 @@ class Encryption { return await olmManager.decryptToDeviceEvent(event); } catch (e, s) { Logs().w( - '[LibOlm] Could not decrypt to device event from ${event.sender} with content: ${event.content}', + '[Vodozemac] Could not decrypt to device event from ${event.sender} with content: ${event.content}', e, s, ); @@ -243,8 +241,8 @@ class Encryption { .onError((e, _) => Logs().e('Ignoring error for updating indexes')); } decryptedPayload = json.decode(decryptResult.plaintext); - } catch (exception, stackTrace) { - Logs().w('Could not decrypt event', exception, stackTrace); + } catch (exception) { + Logs().d('Could not decrypt event', exception); // alright, if this was actually by our own outbound group session, we might as well clear it if (exception.toString() != DecryptException.unknownSession && (keyManager diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index 0b3064ed..49dd8639 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -127,7 +127,7 @@ class KeyManager { inboundGroupSession = vod.InboundGroupSession(content['session_key']); } } catch (e, s) { - Logs().e('[LibOlm] Could not create new InboundGroupSession', e, s); + Logs().e('[Vodozemac] Could not create new InboundGroupSession', e, s); return Future.value(); } final newSession = SessionKey( @@ -465,7 +465,7 @@ class KeyManager { } } catch (e, s) { Logs().e( - '[LibOlm] Unable to re-send the session key at later index to new devices', + '[Vodozemac] Unable to re-send the session key at later index to new devices', e, s, ); @@ -589,7 +589,7 @@ class KeyManager { _outboundGroupSessions[roomId] = sess; } catch (e, s) { Logs().e( - '[LibOlm] Unable to send the session key to the participating devices', + '[Vodozemac] Unable to send the session key to the participating devices', e, s, ); @@ -679,17 +679,15 @@ class KeyManager { try { decrypted = json.decode( decryption.decrypt( - vod.PkMessage( - base64decodeUnpadded(sessionData['ciphertext'] as String), - base64decodeUnpadded(sessionData['mac'] as String), - vod.Curve25519PublicKey.fromBase64( - sessionData['ephemeral'] as String, - ), + vod.PkMessage.fromBase64( + ciphertext: sessionData['ciphertext'] as String, + mac: sessionData['mac'] as String, + ephemeralKey: sessionData['ephemeral'] as String, ), ), ); } catch (e, s) { - Logs().e('[LibOlm] Error decrypting room key', e, s); + Logs().e('[Vodozemac] Error decrypting room key', e, s); } final senderKey = decrypted?.tryGet('sender_key'); if (decrypted != null && senderKey != null) { @@ -1256,14 +1254,15 @@ RoomKeys generateUploadKeysImplementation(GenerateUploadKeysArgs args) { // fetch the device, if available... //final device = args.client.getUserDeviceKeysByCurve25519Key(sess.senderKey); // aaaand finally add the session key to our payload + final (ciphertext, mac, ephemeral) = encrypted.toBase64(); roomKeyBackup.sessions[sess.sessionId] = KeyBackupData( firstMessageIndex: sess.inboundGroupSession!.firstKnownIndex, forwardedCount: sess.forwardingCurve25519KeyChain.length, isVerified: dbSession.verified, //device?.verified ?? false, sessionData: { - 'ephemeral': encrypted.ephemeralKey.toBase64(), - 'ciphertext': base64Encode(encrypted.ciphertext), - 'mac': base64Encode(encrypted.mac), + 'ephemeral': ephemeral, + 'ciphertext': ciphertext, + 'mac': mac, }, ); } diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index c445755c..9b41d3c7 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -296,15 +296,9 @@ class OlmManager { exception.error == MatrixError.M_UNKNOWN) { Logs().w('Rotating otks because upload failed', exception); for (final otk in signedOneTimeKeys.values) { - // Keys can only be removed by creating a session... - - final identity = olmAccount.identityKeys.curve25519.toBase64(); final key = otk.tryGet('key'); if (key != null) { - olmAccount.createOutboundSession( - identityKey: vod.Curve25519PublicKey.fromBase64(identity), - oneTimeKey: vod.Curve25519PublicKey.fromBase64(key), - ); + olmAccount.removeOneTimeKey(key); } } @@ -440,32 +434,16 @@ class OlmManager { if (session.session == null) { continue; } - if (type == 0) { - try { - plaintext = session.session!.decrypt( - messageType: type, - ciphertext: body, - ); - } catch (e) { - // The message was encrypted during this session, but is unable to decrypt - throw DecryptException( - DecryptException.decryptionFailed, - e.toString(), - ); - } + + try { + plaintext = session.session!.decrypt( + messageType: type, + ciphertext: body, + ); await updateSessionUsage(session); break; - } else if (type == 1) { - try { - plaintext = session.session!.decrypt( - messageType: type, - ciphertext: body, - ); - await updateSessionUsage(session); - break; - } catch (_) { - plaintext = null; - } + } catch (_) { + plaintext = null; } } } @@ -677,8 +655,11 @@ class OlmManager { ), ); } catch (e, s) { - Logs() - .e('[LibOlm] Could not create new outbound olm session', e, s); + Logs().e( + '[Vodozemac] Could not create new outbound olm session', + e, + s, + ); } } } @@ -767,10 +748,10 @@ class OlmManager { getFromDb: false, ); } on NoOlmSessionFoundException catch (e) { - Logs().d('[LibOlm] Error encrypting to-device event', e); + Logs().d('[Vodozemac] Error encrypting to-device event', e); continue; } catch (e, s) { - Logs().wtf('[LibOlm] Error encrypting to-device event', e, s); + Logs().wtf('[Vodozemac] Error encrypting to-device event', e, s); continue; } } diff --git a/lib/encryption/utils/json_signature_check_extension.dart b/lib/encryption/utils/json_signature_check_extension.dart index e691d415..e0d0be37 100644 --- a/lib/encryption/utils/json_signature_check_extension.dart +++ b/lib/encryption/utils/json_signature_check_extension.dart @@ -45,7 +45,7 @@ extension JsonSignatureCheckExtension on Map { isValid = true; } catch (e, s) { isValid = false; - Logs().w('[LibOlm] Signature check failed', e, s); + Logs().w('[Vodozemac] Signature check failed', e, s); } return isValid; } diff --git a/lib/encryption/utils/key_verification.dart b/lib/encryption/utils/key_verification.dart index 467b0cde..35cc121f 100644 --- a/lib/encryption/utils/key_verification.dart +++ b/lib/encryption/utils/key_verification.dart @@ -1460,7 +1460,11 @@ class _KeyVerificationMethodSas extends _KeyVerificationMethod { void _handleKey(Map payload) { theirPublicKey = payload['key']; - establishedSas = sas!.establishSasSecret(payload['key']); + final sas = this.sas; + if (sas == null || sas.disposed) { + throw Exception('SAS object is disposed'); + } + establishedSas = sas.establishSasSecret(payload['key']); } Future _validateCommitment() async { @@ -1553,9 +1557,9 @@ class _KeyVerificationMethodSas extends _KeyVerificationMethod { Future _makeCommitment(String pubKey, String canonicalJson) async { if (hash == 'sha256') { - final bytes = utf8.encode(pubKey + canonicalJson); + final bytes = utf8.encoder.convert(pubKey + canonicalJson); final digest = crypto.sha256.convert(bytes); - return base64.encode(digest.bytes); + return encodeBase64Unpadded(digest.bytes); } throw Exception('Unknown hash method'); } diff --git a/lib/encryption/utils/olm_session.dart b/lib/encryption/utils/olm_session.dart index 6f44b606..6c5a385c 100644 --- a/lib/encryption/utils/olm_session.dart +++ b/lib/encryption/utils/olm_session.dart @@ -50,6 +50,7 @@ class OlmSession { pickle: dbEntry['pickle'], ); } catch (_) { + Logs().d('Unable to unpickle Olm session. Try LibOlm format.'); session = vod.Session.fromOlmPickleEncrypted( pickleKey: utf8.encode(key), pickle: dbEntry['pickle'], @@ -60,7 +61,7 @@ class OlmSession { DateTime.fromMillisecondsSinceEpoch(dbEntry['last_received'] ?? 0); assert(sessionId == session!.sessionId); } catch (e, s) { - Logs().e('[LibOlm] Could not unpickle olm session', e, s); + Logs().e('[Vodozemac] Could not unpickle olm session', e, s); } } } diff --git a/lib/encryption/utils/outbound_group_session.dart b/lib/encryption/utils/outbound_group_session.dart index 0d5bb9e7..94219026 100644 --- a/lib/encryption/utils/outbound_group_session.dart +++ b/lib/encryption/utils/outbound_group_session.dart @@ -71,7 +71,7 @@ class OutboundGroupSession { pickle: dbEntry['pickle'], ); } catch (_) { - Logs().e('[LibOlm] Unable to unpickle outboundGroupSession', e, s); + Logs().e('[Vodozemac] Unable to unpickle outboundGroupSession', e, s); } } } diff --git a/lib/encryption/utils/session_key.dart b/lib/encryption/utils/session_key.dart index dd2f487b..77d83fd8 100644 --- a/lib/encryption/utils/session_key.dart +++ b/lib/encryption/utils/session_key.dart @@ -107,12 +107,13 @@ class SessionKey { ); } catch (e, s) { try { + Logs().d('Unable to unpickle inboundGroupSession. Try LibOlm format.'); inboundGroupSession = vod.InboundGroupSession.fromOlmPickleEncrypted( pickle: dbEntry.pickle, pickleKey: utf8.encode(key), ); } catch (_) { - Logs().e('[LibOlm] Unable to unpickle inboundGroupSession', e, s); + Logs().e('[Vodozemac] Unable to unpickle inboundGroupSession', e, s); rethrow; } } diff --git a/lib/matrix_api_lite/generated/api.dart b/lib/matrix_api_lite/generated/api.dart index bcf02678..c571cf34 100644 --- a/lib/matrix_api_lite/generated/api.dart +++ b/lib/matrix_api_lite/generated/api.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:developer'; import 'dart:typed_data'; import 'package:http/http.dart'; diff --git a/lib/src/client.dart b/lib/src/client.dart index af32a013..dff72e3a 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -27,6 +27,7 @@ import 'package:collection/collection.dart' show IterableExtension; import 'package:http/http.dart' as http; import 'package:mime/mime.dart'; import 'package:random_string/random_string.dart'; +import 'package:vodozemac/vodozemac.dart' as vod; import 'package:matrix/encryption.dart'; import 'package:matrix/matrix.dart'; @@ -35,7 +36,6 @@ import 'package:matrix/msc_extensions/msc_unpublished_custom_refresh_token_lifet import 'package:matrix/src/models/timeline_chunk.dart'; import 'package:matrix/src/utils/cached_stream_controller.dart'; import 'package:matrix/src/utils/client_init_exception.dart'; -import 'package:matrix/src/utils/compute_callback.dart'; import 'package:matrix/src/utils/multilock.dart'; import 'package:matrix/src/utils/run_benchmarked.dart'; import 'package:matrix/src/utils/run_in_root.dart'; @@ -106,20 +106,6 @@ class Client extends MatrixApi { final bool convertLinebreaksInFormatting; - final ComputeCallback? compute; - - @Deprecated('Use [nativeImplementations] instead') - Future runInBackground( - FutureOr Function(U arg) function, - U arg, - ) async { - final compute = this.compute; - if (compute != null) { - return await compute(function, arg); - } - return await function(arg); - } - final Duration sendTimelineEventTimeout; /// The timeout until a typing indicator gets removed automatically. @@ -208,8 +194,7 @@ class Client extends MatrixApi { Set? supportedLoginTypes, this.mxidLocalPartFallback = true, this.formatLocalpart = true, - @Deprecated('Use [nativeImplementations] instead') this.compute, - NativeImplementations nativeImplementations = NativeImplementations.dummy, + this.nativeImplementations = NativeImplementations.dummy, Level? logLevel, Filter? syncFilter, Duration defaultNetworkRequestTimeout = const Duration(seconds: 35), @@ -247,9 +232,6 @@ class Client extends MatrixApi { supportedLoginTypes = supportedLoginTypes ?? {AuthenticationTypes.password}, verificationMethods = verificationMethods ?? {}, - nativeImplementations = compute != null - ? NativeImplementationsIsolate(compute) - : nativeImplementations, super( httpClient: FixedTimeoutHttpClient( httpClient ?? http.Client(), @@ -2100,12 +2082,14 @@ class Client extends MatrixApi { } await encryption?.dispose(); - try { - _encryption = Encryption(client: this); - } catch (e) { - Logs().e('Error initializing encryption $e'); - await encryption?.dispose(); - _encryption = null; + if (vod.isInitialized()) { + try { + _encryption = Encryption(client: this); + } catch (e) { + Logs().e('Error initializing encryption $e'); + await encryption?.dispose(); + _encryption = null; + } } onInitStateChanged?.call(InitState.settingUpEncryption); await encryption?.init(olmAccount); @@ -3427,7 +3411,7 @@ class Client extends MatrixApi { }); } } catch (e, s) { - Logs().e('[LibOlm] Unable to update user device keys', e, s); + Logs().e('[Vodozemac] Unable to update user device keys', e, s); } } diff --git a/lib/src/utils/compute_callback.dart b/lib/src/utils/compute_callback.dart index d81f4083..f15d9f7a 100644 --- a/lib/src/utils/compute_callback.dart +++ b/lib/src/utils/compute_callback.dart @@ -11,12 +11,3 @@ typedef ComputeRunner = Future Function( FutureOr Function(U arg) function, U arg, ); - -ComputeCallback computeCallbackFromRunInBackground(ComputeRunner runner) { - return ( - FutureOr Function(U arg) callback, - U arg, { - String? debugLabel, - }) => - runner.call(callback, arg); -} diff --git a/lib/src/utils/matrix_file.dart b/lib/src/utils/matrix_file.dart index b82adbbd..cce8e82f 100644 --- a/lib/src/utils/matrix_file.dart +++ b/lib/src/utils/matrix_file.dart @@ -27,7 +27,6 @@ import 'package:image/image.dart'; import 'package:mime/mime.dart'; import 'package:matrix/matrix.dart'; -import 'package:matrix/src/utils/compute_callback.dart'; class MatrixFile { final Uint8List bytes; @@ -112,13 +111,8 @@ class MatrixImageFile extends MatrixFile { required Uint8List bytes, required String name, String? mimeType, - @Deprecated('Use [nativeImplementations] instead') ComputeRunner? compute, NativeImplementations nativeImplementations = NativeImplementations.dummy, }) async { - if (compute != null) { - nativeImplementations = - NativeImplementationsIsolate.fromRunInBackground(compute); - } final metaData = await nativeImplementations.calcImageMetadata(bytes); return MatrixImageFile( @@ -142,13 +136,8 @@ class MatrixImageFile extends MatrixFile { Future Function( MatrixImageFileResizeArguments, )? customImageResizer, - @Deprecated('Use [nativeImplementations] instead') ComputeRunner? compute, NativeImplementations nativeImplementations = NativeImplementations.dummy, }) async { - if (compute != null) { - nativeImplementations = - NativeImplementationsIsolate.fromRunInBackground(compute); - } final image = MatrixImageFile(name: name, mimeType: mimeType, bytes: bytes); return await image.generateThumbnail( @@ -196,13 +185,8 @@ class MatrixImageFile extends MatrixFile { Future Function( MatrixImageFileResizeArguments, )? customImageResizer, - @Deprecated('Use [nativeImplementations] instead') ComputeRunner? compute, NativeImplementations nativeImplementations = NativeImplementations.dummy, }) async { - if (compute != null) { - nativeImplementations = - NativeImplementationsIsolate.fromRunInBackground(compute); - } final arguments = MatrixImageFileResizeArguments( bytes: bytes, maxDimension: dimension, diff --git a/lib/src/utils/native_implementations.dart b/lib/src/utils/native_implementations.dart index eab0426d..367909d3 100644 --- a/lib/src/utils/native_implementations.dart +++ b/lib/src/utils/native_implementations.dart @@ -133,19 +133,13 @@ class NativeImplementationsDummy extends NativeImplementations { class NativeImplementationsIsolate extends NativeImplementations { /// pass by Flutter's compute function here final ComputeCallback compute; + final Future Function()? vodozemacInit; - NativeImplementationsIsolate(this.compute); - - /// creates a [NativeImplementationsIsolate] based on a [ComputeRunner] as - // ignore: deprecated_member_use_from_same_package - /// known from [Client.runInBackground] - factory NativeImplementationsIsolate.fromRunInBackground( - ComputeRunner runInBackground, - ) { - return NativeImplementationsIsolate( - computeCallbackFromRunInBackground(runInBackground), - ); - } + NativeImplementationsIsolate( + this.compute, { + /// To generate upload keys, vodozemac needs to be initialized in the isolate. + this.vodozemacInit, + }); Future runInBackground( FutureOr Function(U arg) function, @@ -172,7 +166,10 @@ class NativeImplementationsIsolate extends NativeImplementations { bool retryInDummy = true, }) async { return runInBackground( - NativeImplementations.dummy.generateUploadKeys, + (GenerateUploadKeysArgs args) async { + await vodozemacInit?.call(); + return NativeImplementations.dummy.generateUploadKeys(args); + }, args, ); } diff --git a/pubspec.yaml b/pubspec.yaml index a1333227..8f8ee085 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,18 +24,13 @@ dependencies: js: ^0.6.3 markdown: ^7.1.1 mime: ">=1.0.0 <3.0.0" - olm: ^3.1.0 random_string: ^2.3.1 sdp_transform: ^0.3.2 slugify: ^2.0.0 sqflite_common: ^2.4.5 sqlite3: ^2.1.0 typed_data: ^1.3.2 - vodozemac: - git: - url: https://github.com/famedly/dart-vodozemac.git - path: dart - ref: main + vodozemac: ^0.2.0 webrtc_interface: ^1.2.0 dev_dependencies: diff --git a/scripts/prepare.sh b/scripts/prepare.sh index 5826a474..b0c72655 100755 --- a/scripts/prepare.sh +++ b/scripts/prepare.sh @@ -1,35 +1,5 @@ #!/usr/bin/env bash -ENTRYPOINT="$(pwd)" - -mkdir js -cd js - -curl -O 'https://packages.matrix.org/npm/olm/olm-3.1.4.tgz' -tar xaf olm-3.1.4.tgz - -cd .. - -if [ -f /usr/lib/x86_64-linux-gnu/libolm.so.3 ]; then - mkdir -p ffi/olm/ - ln -sf /usr/lib/x86_64-linux-gnu/libolm.so.3 ffi/olm/libolm.so -# alpine specific location -elif [ -f /usr/lib/libolm.so.3 ]; then - mkdir -p ffi/olm - ln -sf /usr/lib/libolm.so.3 ffi/olm/libolm.so -else - mkdir ffi - cd ffi - cd .. - git clone --depth 1 https://gitlab.matrix.org/matrix-org/olm.git - cd olm - cmake -DCMAKE_BUILD_TYPE=Release . - cmake --build . - cd .. -fi - -cd "$ENTRYPOINT" - if which flutter >/dev/null; then flutter pub get else diff --git a/scripts/prepare_vodozemac.sh b/scripts/prepare_vodozemac.sh index d1b2b725..47f65044 100755 --- a/scripts/prepare_vodozemac.sh +++ b/scripts/prepare_vodozemac.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +rm -rf rust git clone https://github.com/famedly/dart-vodozemac.git mv ./dart-vodozemac/rust ./ rm -rf dart-vodozemac diff --git a/test/client_test.dart b/test/client_test.dart index 628343a7..015c73f0 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -23,9 +23,9 @@ import 'dart:typed_data'; import 'package:canonical_json/canonical_json.dart'; import 'package:collection/collection.dart'; -import 'package:olm/olm.dart' as olm; import 'package:path/path.dart' show join; import 'package:test/test.dart'; +import 'package:vodozemac/vodozemac.dart' as vod; import 'package:matrix/matrix.dart'; import 'package:matrix/src/utils/client_init_exception.dart'; @@ -1069,9 +1069,8 @@ void main() { final deviceKeys = []; for (var i = 0; i < 30; i++) { - final account = olm.Account(); - account.create(); - final keys = json.decode(account.identity_keys()); + final account = vod.Account(); + final keys = account.identityKeys; final userId = '@testuser:example.org'; final deviceId = 'DEVICE$i'; final keyObj = { @@ -1082,18 +1081,17 @@ void main() { 'm.megolm.v1.aes-sha2', ], 'keys': { - 'curve25519:$deviceId': keys['curve25519'], - 'ed25519:$deviceId': keys['ed25519'], + 'curve25519:$deviceId': keys.curve25519.toBase64(), + 'ed25519:$deviceId': keys.ed25519.toBase64(), }, }; final signature = account.sign(String.fromCharCodes(canonicalJson.encode(keyObj))); keyObj['signatures'] = { userId: { - 'ed25519:$deviceId': signature, + 'ed25519:$deviceId': signature.toBase64(), }, }; - account.free(); deviceKeys.add(DeviceKeys.fromJson(keyObj, matrix)); } FakeMatrixApi.calledEndpoints.clear(); diff --git a/test/encryption/bootstrap_test.dart b/test/encryption/bootstrap_test.dart index 363e49bb..61106b9d 100644 --- a/test/encryption/bootstrap_test.dart +++ b/test/encryption/bootstrap_test.dart @@ -19,7 +19,6 @@ import 'dart:async'; import 'dart:convert'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -40,8 +39,7 @@ void main() { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); + client = await getClient(); }); diff --git a/test/encryption/cross_signing_test.dart b/test/encryption/cross_signing_test.dart index d1c4ec04..dc78db98 100644 --- a/test/encryption/cross_signing_test.dart +++ b/test/encryption/cross_signing_test.dart @@ -18,7 +18,6 @@ import 'dart:convert'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -36,8 +35,7 @@ void main() { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); + client = await getClient(); await client.abortSync(); }); diff --git a/test/encryption/encrypt_decrypt_room_message_test.dart b/test/encryption/encrypt_decrypt_room_message_test.dart index 18226297..047e1ee8 100644 --- a/test/encryption/encrypt_decrypt_room_message_test.dart +++ b/test/encryption/encrypt_decrypt_room_message_test.dart @@ -16,7 +16,6 @@ * along with this program. If not, see . */ -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -38,8 +37,7 @@ void main() { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); + client = await getClient(); room = client.getRoomById(roomId)!; }); diff --git a/test/encryption/encrypt_decrypt_to_device_test.dart b/test/encryption/encrypt_decrypt_to_device_test.dart index 1ba5ce6d..67a21533 100644 --- a/test/encryption/encrypt_decrypt_to_device_test.dart +++ b/test/encryption/encrypt_decrypt_to_device_test.dart @@ -16,7 +16,6 @@ * along with this program. If not, see . */ -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -44,8 +43,7 @@ void main() async { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); + client = await getClient(); }); diff --git a/test/encryption/key_manager_test.dart b/test/encryption/key_manager_test.dart index 044b0ef7..bfbec9e7 100644 --- a/test/encryption/key_manager_test.dart +++ b/test/encryption/key_manager_test.dart @@ -18,7 +18,6 @@ import 'dart:convert'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -35,8 +34,7 @@ void main() { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); + client = await getClient(); }); diff --git a/test/encryption/key_request_test.dart b/test/encryption/key_request_test.dart index 19a64388..d107697d 100644 --- a/test/encryption/key_request_test.dart +++ b/test/encryption/key_request_test.dart @@ -18,7 +18,6 @@ import 'dart:convert'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -47,8 +46,6 @@ void main() { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); }); final validSessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU'; diff --git a/test/encryption/key_verification_test.dart b/test/encryption/key_verification_test.dart index aa191488..8c71f7e3 100644 --- a/test/encryption/key_verification_test.dart +++ b/test/encryption/key_verification_test.dart @@ -20,7 +20,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:typed_data'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -63,8 +62,6 @@ void main() async { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); }); setUp(() async { diff --git a/test/encryption/olm_manager_test.dart b/test/encryption/olm_manager_test.dart index 2d0e4004..8f013d64 100644 --- a/test/encryption/olm_manager_test.dart +++ b/test/encryption/olm_manager_test.dart @@ -18,7 +18,6 @@ import 'dart:convert'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -37,8 +36,7 @@ void main() { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); + client = await getClient(); }); diff --git a/test/encryption/online_key_backup_test.dart b/test/encryption/online_key_backup_test.dart index 0930ad3b..f7d68751 100644 --- a/test/encryption/online_key_backup_test.dart +++ b/test/encryption/online_key_backup_test.dart @@ -18,7 +18,6 @@ import 'dart:convert'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -40,8 +39,7 @@ void main() { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); + client = await getClient(); }); @@ -91,20 +89,19 @@ void main() { }); test('upload key', () async { - final session = olm.OutboundGroupSession(); - session.create(); - final inbound = olm.InboundGroupSession(); - inbound.create(session.session_key()); + final session = vod.GroupSession(); + final inbound = vod.InboundGroupSession(session.sessionKey); + final senderKey = client.identityKey; final roomId = '!someroom:example.org'; - final sessionId = inbound.session_id(); + final sessionId = inbound.sessionId; // set a payload... final sessionPayload = { 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': roomId, 'forwarding_curve25519_key_chain': [client.identityKey], 'session_id': sessionId, - 'session_key': inbound.export_session(1), + 'session_key': inbound.exportAt(1), 'sender_key': senderKey, 'sender_claimed_ed25519_key': client.fingerprintKey, }; diff --git a/test/encryption/ssss_test.dart b/test/encryption/ssss_test.dart index 4d5136ec..96726d76 100644 --- a/test/encryption/ssss_test.dart +++ b/test/encryption/ssss_test.dart @@ -20,7 +20,6 @@ import 'dart:convert'; import 'dart:math'; import 'dart:typed_data'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -59,8 +58,7 @@ void main() { wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.get_library_version(); + client = await getClient(); }); diff --git a/test_driver/matrixsdk_test.dart b/test_driver/matrixsdk_test.dart index 965fdd1d..4aa6b414 100644 --- a/test_driver/matrixsdk_test.dart +++ b/test_driver/matrixsdk_test.dart @@ -18,7 +18,6 @@ import 'dart:io'; -import 'package:olm/olm.dart' as olm; import 'package:test/test.dart'; import 'package:vodozemac/vodozemac.dart' as vod; @@ -44,9 +43,6 @@ void main() => group( wasmPath: './pkg/', libraryPath: './rust/target/debug/', ); - await olm.init(); - olm.Account(); - Logs().i('[LibOlm] Enabled'); final homeserverUri = Uri.parse(homeserver); Logs().i('++++ Using homeserver $homeserverUri ++++'); @@ -490,10 +486,6 @@ void main() => group( Client? testClientA, testClientB; try { - await olm.init(); - olm.Account(); - Logs().i('[LibOlm] Enabled'); - final homeserverUri = Uri.parse(homeserver); Logs().i('++++ Using homeserver $homeserverUri ++++');