Flutter Virgil E3 Kit not working in release mode but working in debug

Viewed 143

I am trying to implement Virgil e3 Kit into my flutter app for end to end encryption. When running the code and signing up in debug mode the EThree Kit is working perfectly however when I try and run in release mode I get an exception when registering the user with EThree Kit.

This is the package: https://github.com/cardoso/virgil-e3kit-flutter

This is the error: Failed to register user for encryption system: PlatformException(unknown_error, Http response: 400 : Bad Request Service response: 40200 : Identity search parameter cannot be empty., null, null)

I thought that this was something to do with cleartext traffic so I enabled that in my androidManifest but it still did not work

This is the code I am calling:

Signup

final firebaseUser = await _firebaseAuth.createUserWithEmailAndPassword(
      email: email, password: password);

  await EncryptionUtils.initialize(_firebaseAuth.currentUser.uid);
  await EncryptionUtils.register();
  await EncryptionUtils.backupPrivateKey(
      '${_firebaseAuth.currentUser.uid}...$password');

Initialize

static Future<void> initialize(String uid) async {
if (_eThree != null) return;

final tokenCallback = () async {
  final response = (await FirebaseFunctions.instance
          .httpsCallable('getVirgilJwt')
          .call())
      .data;

  final Map<String, dynamic> data = Map<String, dynamic>.from(response);
  print('[encryption tokenCallback] - ${data['token']}');
  return data['token'];
};

try {
  if (uid == null || uid.isEmpty) {
    throw Exception('user-id not valid');
  }

  _eThree = await EThree.init(uid, tokenCallback);
  print('[ENCRYPTION UTILS] - (initialize) initialized successfully');
} catch (err) {
  print('[ENCRYPTION UTILS] - Failed initializing: $err');
  throw Exception('Failed to intialize end to end encryption system');
}
}

Register

static Future<void> register() async {
try {
  await _eThree.cleanUp();
  print('[ENCRYPTION UTILS] - (Register) cleaned up successfully');
} catch (err) {
  print('[ENCRYPTION UTILS] - (Register) failed to cleanup');
}

try {
  print(
      '[encryption register] - trying to register ${await _eThree.identity}');
  
  await _eThree.register();
  print('[ENCRYPTION UTILS] - registered successfully');
} on PlatformException catch (err) {
  if (err.code == 'user_is_already_registered') {
    await _eThree.rotatePrivateKey();
    print('Rotated private key instead');
  }
  print('Failed to register user for encryption system: $err');
  throw Exception('Failed to register user for encryption system: $err');
}
}

Thank you in advance!

1 Answers

I know this is an old question, but I ran into the same problem and wanted to share my solution. I added the following lines in the Android app's build.gradle file to prevent bundle size optimization. You can find the same configuration in the Virgil Android SDK sample apps.

buildTypes {
    release {
        ...
        minifyEnabled false
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
Related