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

Crash SharedPrefKeysetReader #604

Closed
DmitriiBroli opened this issue Oct 6, 2022 · 9 comments
Closed

Crash SharedPrefKeysetReader #604

DmitriiBroli opened this issue Oct 6, 2022 · 9 comments

Comments

@DmitriiBroli
Copy link

General information

  • SDK/Library version: 4.16.0
  • Environment: Sandbox
  • Android Version and Device: Any
  • Compile SDK: 33
  • Targer SDK: 33
  • Braintree dependencies:
com.braintreepayments.api:card:4.16.0
com.braintreepayments.api:three-d-secure:4.16.0

Issue description

Crashlytics crash

java.io.FileNotFoundException: can't read keyset; the pref value __androidx_security_crypto_encrypted_prefs_value_keyset__ does not exist
        at xl6.b(SharedPrefKeysetReader.java:33)
        at xl6.a(SharedPrefKeysetReader.java:1)
        at ee3.j(KeysetHandle.java:1)
        at gd$b.e(AndroidKeysetManager.java:7)
        at gd$b.f(AndroidKeysetManager.java:1)
        at gd$b.d(AndroidKeysetManager.java:12)
        at gt1.b(EncryptedSharedPreferences.java:97)
        at gt1.a(EncryptedSharedPreferences.java:5)
        at e30.d(BraintreeSharedPreferences.java:22)
        at e30.a(BraintreeSharedPreferences.java:1)
        at pr0.b(ConfigurationCache.java:20)
        at pr0.a(ConfigurationCache.java:5)
        at tr0.c(ConfigurationLoader.java:7)
        at tr0.d(ConfigurationLoader.java:49)
        at n20$a.a(BraintreeClient.java:17)
        at qo$a.b(AuthorizationLoader.java:19)
        at kv.resumeWith(ContinuationImpl.kt:12)
        at sk1.run(DispatchedTask.kt:119)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
@scannillo
Copy link
Contributor

👋 Hello @DmitriiBroli - do you have steps to replicate?

@DmitriiBroli
Copy link
Author

@scannillo Hi, no steps unfortunately, this is a Crashlytics crash.

@sshropshire
Copy link
Contributor

Hi @DmitriiBroli we have an issue with our 3rd party MPI provider Cardinal that prevents us from providing explicit support for API version 33. I'm guessing this issue may be related, although it is hard to tell without steps. We appreciate the stack trace though that is helpful.

Is the crash frequent? Also you can follow along with #585 once this is resolved we'll release a new minor version update to include explicit support for Android 13.

@jaxdesmarais
Copy link
Contributor

Hello @DmitriiBroli -

We believe this has been fixed by our 3rd Party MPI Cardinal. The fix has been released in version 4.18.0. Are you able to test again as we were not able to reproduce this after updating and confirm if you are seeing this issue resolved?

@DmitriiBroli
Copy link
Author

Hi, the crash still persists. Additionally, we also noticed StrictMode violations from braintree side:

D/StrictMode: StrictMode policy violation; ~duration=113 ms: android.os.strictmode.DiskReadViolation
        at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1596)
        at android.app.SharedPreferencesImpl.awaitLoadedLocked(SharedPreferencesImpl.java:275)
        at android.app.SharedPreferencesImpl.edit(SharedPreferencesImpl.java:368)
        at com.google.crypto.tink.integration.android.SharedPrefKeysetWriter.<init>(SharedPrefKeysetWriter.java:56)
        at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.withSharedPref(AndroidKeysetManager.java:163)
        at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:153)
        at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:120)
        at com.braintreepayments.api.BraintreeSharedPreferences.getSharedPreferences(BraintreeSharedPreferences.java:34)
        at com.braintreepayments.api.BraintreeSharedPreferences.containsKey(BraintreeSharedPreferences.java:85)
        at com.braintreepayments.api.ConfigurationCache.getConfiguration(ConfigurationCache.java:40)
        at com.braintreepayments.api.ConfigurationCache.getConfiguration(ConfigurationCache.java:34)
        at com.braintreepayments.api.ConfigurationLoader.getCachedConfiguration(ConfigurationLoader.java:75)
        at com.braintreepayments.api.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:39)
        at com.braintreepayments.api.BraintreeClient$1.onAuthorizationResult(BraintreeClient.java:183)
        at com.braintreepayments.api.AuthorizationLoader$1.onSuccess(AuthorizationLoader.java:26)

@sshropshire
Copy link
Contributor

@DmitriiBroli thank you for your patience. We have a PR up. After looking at this stack overflow post, it looks like we may benefit from explicitly providing an encryption key alias. Once we have it merged it, it may help us if you could verify that our SNAPSHOT build fixes the issue and if so, we can add it to the next release.

@sshropshire
Copy link
Contributor

Hey @DmitriiBroli can you try version 4.19.0 to see if this resolves the issue? Also in regards to the StrictMode violations, we were notified that the Jetpack Security Crypto library has restarted active development recently. We will make updates to this dependency when possible.

@DmitriiBroli
Copy link
Author

@sshropshire Thank you for your time. We have updated to 4.19.0 and we will check out whether this helped after releasing to prod.

@jcnoriega
Copy link
Contributor

@DmitriiBroli issue has been fixed in latest version 4.20.0. In order to avoid a crash, you need to catch BraintreeSharedPreferencesException. Let me know if it works and i'll close this issue!

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

5 participants