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

Storage sometimes returns random data #164

Closed
Sorunome opened this issue Oct 7, 2020 · 3 comments
Closed

Storage sometimes returns random data #164

Sorunome opened this issue Oct 7, 2020 · 3 comments

Comments

@Sorunome
Copy link

Sorunome commented Oct 7, 2020

Using android, Xperia 10 w/ LOS 10

Sometimes the storage returns random junk data instead of the actual data stored by the key. Interestingly this random data is the same every single time.

Some other times a platform exception is thrown:

I/flutter (13224): PlatformException(Exception encountered, read, javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
I/flutter (13224): 	at com.android.org.conscrypt.NativeCrypto.EVP_CipherFinal_ex(Native Method)
I/flutter (13224): 	at com.android.org.conscrypt.OpenSSLCipher$EVP_CIPHER.doFinalInternal(OpenSSLCipher.java:602)
I/flutter (13224): 	at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:365)
I/flutter (13224): 	at javax.crypto.Cipher.doFinal(Cipher.java:2055)
I/flutter (13224): 	at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.decrypt(StorageCipher18Implementation.java:91)
I/flutter (13224): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.decodeRawValue(FlutterSecureStoragePlugin.java:163)
I/flutter (13224): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.read(FlutterSecureStoragePlugin.java:144)
I/flutter (13224): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.access$300(FlutterSecureStoragePlugin.java:29)
I/flutter (13224): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java
I/flutter (13224): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
I/flutter (13224): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
I/flutter (13224): <asynchronous suspension>
I/flutter (13224): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
I/flutter (13224): #3      FlutterSecureStorage.read (package:flutter_secure_storage/flutter_secure_storage.dart:33:41)
I/flutter (13224): #4      Store.getItem (package:fluffychat/utils/famedlysdk_store.dart:225:40)
I/flutter (13224): <asynchronous suspension>
I/flutter (13224): #5      ThemeSwitcherWidgetState.loadSelection (package:fluffychat/components/theme_switcher.dart:178:38)
I/flutter (13224): #6      ThemeSwitcherWidgetState.setup (package:fluffychat/components/theme_switcher.dart:241:11)
I/flutter (13224): #7      ThemeSwitcherWidgetState.initState.<anonymous closure> (package:fluffychat/components/theme_switcher.dart:248:9)
I/flutter (13224): #8      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
I/flutter (13224): #9      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/bindi

The following code seems to be able to fetch a value from the store significantly more reliably:

    try {
      final val1 = await secureStorage.read(key: key);
      final val2 = await secureStorage.read(key: key);
      if (val1 == val2) {
        return val1;
      }
      // else read a third time
      return await secureStorage.read(key: key);
    } catch (e, s) {
      try {
        final val1 = await secureStorage.read(key: key);
        final val2 = await secureStorage.read(key: key);
        if (val1 == val2) {
          return val1;
        }
        // else read a third time
        return await secureStorage.read(key: key);
      } catch (_) {
        return null;
      }
    }

Perhaps the library should adapt better re-trying on errors or thelike?

@Sorunome
Copy link
Author

Sorunome commented Oct 7, 2020

It might be important to point out that these reads happen very early in the apps startup cycle

@dukemike
Copy link

dukemike commented Oct 7, 2020

@Sorunome refer to #161 for a likely work around

@Sorunome
Copy link
Author

Sorunome commented Oct 8, 2020

Ah, thank you. Closing this issue as a duplicate of that one.

@Sorunome Sorunome closed this as completed Oct 8, 2020
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