aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.32k stars 248 forks source link

java.io.FileNotFoundException: can't read keyset while initializing Amplify #4432

Closed danielgomezrico closed 8 months ago

danielgomezrico commented 9 months ago

Description

Issue

A FileNotFoundException and stack trace is logged while initializing Amplify. The full log looks like:

It was reported on https://github.com/aws-amplify/amplify-flutter/issues/2640 as fixed but it is still happening on:

W/AndroidKeysetManager( 1231): keyset not found, will generate a new one
W/AndroidKeysetManager( 1231): java.io.FileNotFoundException: can't read keyset; the pref value __androidx_security_crypto_encrypted_prefs_key_keyset__ does not exist
W/AndroidKeysetManager( 1231):  at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readPref(SharedPrefKeysetReader.java:71)
W/AndroidKeysetManager( 1231):  at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readEncrypted(SharedPrefKeysetReader.java:89)
W/AndroidKeysetManager( 1231):  at com.google.crypto.tink.KeysetHandle.read(KeysetHandle.java:105)
W/AndroidKeysetManager( 1231):  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:311)
W/AndroidKeysetManager( 1231):  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:287)
W/AndroidKeysetManager( 1231):  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:238)
W/AndroidKeysetManager( 1231):  at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:123)
W/AndroidKeysetManager( 1231):  at com.amazonaws.amplify.amplify_secure_storage.amplify_secure_storage.EncryptedKeyValueRepository$sharedPreferences$2.invoke(EncryptedKeyValueRepository.kt:31)
W/AndroidKeysetManager( 1231):  at com.amazonaws.amplify.amplify_secure_storage.amplify_secure_storage.EncryptedKeyValueRepository$sharedPreferences$2.invoke(EncryptedKeyValueRepository.kt:21)
W/AndroidKeysetManager( 1231):  at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
W/AndroidKeysetManager( 1231):  at com.amazonaws.amplify.amplify_secure_storage.amplify_secure_storage.EncryptedKeyValueRepository.getSharedPreferences(EncryptedKeyValueRepository.kt:21)
W/AndroidKeysetManager( 1231):  at com.amazonaws.amplify.amplify_secure_storage.amplify_secure_storage.EncryptedKeyValueRepository.get(EncryptedKeyValueRepository.kt:73)
W/AndroidKeysetManager( 1231):  at com.amazonaws.amplify.amplify_secure_storage.amplify_secure_storage.AmplifySecureStoragePlugin.read(AmplifySecureStoragePlugin.kt:33)
W/AndroidKeysetManager( 1231):  at com.amazonaws.amplify.amplify_secure_storage.amplify_secure_storage.Messages$AmplifySecureStorageApi.lambda$setup$0(Messages.java:77)
W/AndroidKeysetManager( 1231):  at com.amazonaws.amplify.amplify_secure_storage.amplify_secure_storage.Messages$AmplifySecureStorageApi$$ExternalSyntheticLambda0.onMessage(Unknown Source:2)
W/AndroidKeysetManager( 1231):  at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:217)
W/AndroidKeysetManager( 1231):  at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
W/AndroidKeysetManager( 1231):  at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
W/AndroidKeysetManager( 1231):  at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
W/AndroidKeysetManager( 1231):  at io.flutter.embedding.engine.dart.DartMessenger$SerialTaskQueue.flush(DartMessenger.java:173)
W/AndroidKeysetManager( 1231):  at io.flutter.embedding.engine.dart.DartMessenger$SerialTaskQueue.lambda$dispatch$0$io-flutter-embedding-engine-dart-DartMessenger$SerialTaskQueue(DartMessenger.java:163)

Cause

The log message is coming from Android Security (androidx.security:security-crypto:1.0.0) which is used for storing sensitive data in Amplify when targeting Android.

Categories

Steps to Reproduce

Add the dependency and run the app

Screenshots

No response

Platforms

Flutter Version

3.2.3

Amplify Flutter Version

1.6.1

Deployment Method

Custom Pipeline

Schema

No response

Jordan-Nelson commented 9 months ago

Hello @danielgomezrico - Thanks for reporting this issue. This was supposed to be resolved by upgrading to a newer version of tink-crypto, which Android Security depends on. I am not sure what would have caused this to reoccur but we will look into it.

When this issue surfaced before it did not impact the functionality of the app. The message does clutter logs though, which can be disruptive. Is this the case? Are you seeing any impact on functionality or is the issue that this is cluttering logs?

danielgomezrico commented 9 months ago

thanks for answering, it works, I can access the user pool but I see a big log input every time and I was wondering why so I reopened the issue

Jordan-Nelson commented 9 months ago

Got it. Thanks. The log does look alarming, but should be harmless. I do understand it is not ideal though as it causes confusion and clutters logs.

I was able to reproduce this on a fresh install of an app using the latest versions of amplify flutter.

The version constraint for google tink was updated in https://github.com/aws-amplify/amplify-flutter/pull/3220. I think the syntax is not correct and is therefore being ignored. I will investigate.

danielgomezrico commented 9 months ago

Sound good to me! thanks for the fast feedback

Jordan-Nelson commented 9 months ago

I have a PR open to resolve this. It will likely be included in the next release. Thanks for bringing this to our attention.

Equartey commented 8 months ago

Hi @danielgomezrico, closing this as it has been resolved in Amplify Flutter 1.7.0.