Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EncryptedDrift + FirebaseMessaging on iOS = SQLCipher assertion fails #2255

Closed
wryczko opened this issue Jan 8, 2023 · 3 comments
Closed

Comments

@wryczko
Copy link

wryczko commented Jan 8, 2023

Hi,

I've created flutter app using Encrypted Drift using provided instruction and it worked like a charm, but...

Recently I've added a new package firebase_messaging to my app and everything worked on Android, but when I tried to open an app on iOS physical device, creating NativeDatabase instance failed following assertion:

bool _debugCheckHasCipher(Database database) {
  return database.select('PRAGMA cipher_version;').isNotEmpty;
}

with an error:

Unhandled Exception: '../DriftContext.dart': Failed assertion: line 156 pos 18: '_debugCheckHasCipher(rawDb)': is not true.
#0      DriftCommunication.request (package:drift/src/remote/communication.dart:116:66)
#1      _RemoteQueryExecutor.ensureOpen (package:drift/src/remote/client_impl.dart:158:10)

I've already tried a potential solution with adding -framework SQLCipher in "Other Linker Flags" in project's settings on Xcode described here, but this setting was already there.

Do you have any suggestions?

I am creating NativeDatabase instance (in separate Isolate) with following code:

bool _debugCheckHasCipher(Database database) {
  return database.select('PRAGMA cipher_version;').isNotEmpty;
}

void setupSqlCipher() {
  if (Platform.isAndroid) {
    open.overrideFor(OperatingSystem.android, () => DynamicLibrary.open('libsqlcipher.so'));
  }
}

void _startBackground(_IsolateStartRequest request) {
  final driftIsolate = DriftIsolate.inCurrent(() => DatabaseConnection(LazyDatabase(() async {
        setupSqlCipher();

        final file = File(request.targetPath);
        return NativeDatabase(file, logStatements: false, setup: (rawDb) {
          assert(_debugCheckHasCipher(rawDb));
          rawDb.execute("PRAGMA key = 'password';");
        });
      })));

  request.sendDriftIsolate.send(driftIsolate.connectPort);
}

class _IsolateStartRequest {
  final SendPort sendDriftIsolate;
  final String targetPath;

  _IsolateStartRequest(this.sendDriftIsolate, this.targetPath);
}

await Isolate.spawn(_startBackground, _IsolateStartRequest(receivePort.sendPort, path));
@simolus3
Copy link
Owner

simolus3 commented Jan 8, 2023

Could you try adding this to your podfile? #1810 (comment)

@wryczko
Copy link
Author

wryczko commented Jan 8, 2023

I've applied the fix you mentioned and my app has started working! Thank you @simolus3!

@simolus3
Copy link
Owner

simolus3 commented Jan 8, 2023

Nice, I've also added that information to sqlcipher_flutter_libs' README now.

@simolus3 simolus3 closed this as completed Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants