The specified item could not be found in the keychain
Closed this issue · 51 comments
Hello,
after yesterday's update (9.1.1) we are encountering this error when trying to read secure storage only on ios:
Unhandled Exception: PlatformException(Unexpected security result code, Code: -25300, Message: The specified item could not be found in the keychain., -25300, null)
How can we solve that?
Thank you
Same here, data from the keychain can not be read.
Same here.
Same here, what's the solution?
Same here with the last version 9.1.1, and If I back to the previous version the problem is not solved, and now I can't run the app
and If I back to the previous version the problem is not solved, and now I can't run the app
Huh? Just revert your pubspec.lock
to the previous state. That will fix it.
Same here, what's the solution?
Don't upgrade.
Same here. Fixed my version to: flutter_secure_storage: 9.0.0
.
Submitted a fix for this in #710.
Looks like the platform function readAll
was updated to check for empty keys, but read
wasn't. Until my fix is tested and merged, the best bet would be to pin an earlier version.
For those who get here and need a temporary workaround for version 9.1.1, read
is the problem, readAll
works fine. You just need to do the key lookup yourself:
final secureStore = const FlutterSecureStorage();
// Not working in 9.1.1
final key = await secureStore.read(key: "some_key");
// Workaround -- `key` will be `null` if not present
final key = (await secureStore.readAll())["some_key"];
For those who get here and need a temporary workaround for version 9.1.1,
read
is the problem,readAll
works fine. You just need to do the key lookup yourself:final secureStore = const FlutterSecureStorage(); // Not working in 9.1.1 final key = await secureStore.read(key: "some_key"); // Workaround -- `key` will be `null` if not present final key = (await secureStore.readAll())["some_key"];
This works fine for now, Thank you
Same here, what's the solution?
Don't upgrade.
now i have flutter_secure_storage: ^9.0.0, but still showing same error
@dilshd specify the version: flutter_secure_storage: 9.0.0
How i can fix it?
For those who get here and need a temporary workaround for version 9.1.1,
read
is the problem,readAll
works fine. You just need to do the key lookup yourself:final secureStore = const FlutterSecureStorage(); // Not working in 9.1.1 final key = await secureStore.read(key: "some_key"); // Workaround -- `key` will be `null` if not present final key = (await secureStore.readAll())["some_key"];
what about secureStore.delete?
i got same problem when i delete.
@dilshd specify the version:
flutter_secure_storage: 9.0.0
i did, but still same.
You might need to do a flutter clean
and rebuild so the downgrade actually happens. As far as the delete
method, I am unsure. It's entirely possible that method is bugged as well, in which case the package maintainer can hopefully weigh in with a workaround and/or a fix.
@dilshd specify the version:
flutter_secure_storage: 9.0.0
i did, but still same.
You might need to do a
flutter clean
and rebuild so the downgrade actually happens. As far as thedelete
method, I am unsure. It's entirely possible that method is bugged as well, in which case the package maintainer can hopefully weigh in with a workaround and/or a fix.
is it possible like this ?
final key = (await secureStore.deleteAll())["some_key"];
@dilshd specify the version:
flutter_secure_storage: 9.0.0
i did, but still same.
You might need to do a
flutter clean
and rebuild so the downgrade actually happens. As far as thedelete
method, I am unsure. It's entirely possible that method is bugged as well, in which case the package maintainer can hopefully weigh in with a workaround and/or a fix.is it possible like this ? final key = (await secureStore.deleteAll())["some_key"];
Only if you are okay with deleting all keys. deleteAll
deletes all keys you have stored, and doesn't return anything, so you wouldn't need the ["some_key"]
part.
@dilshd specify the version:
flutter_secure_storage: 9.0.0
i did, but still same.
You might need to do a
flutter clean
and rebuild so the downgrade actually happens. As far as thedelete
method, I am unsure. It's entirely possible that method is bugged as well, in which case the package maintainer can hopefully weigh in with a workaround and/or a fix.is it possible like this ? final key = (await secureStore.deleteAll())["some_key"];
Only if you are okay with deleting all keys.
deleteAll
deletes all keys you have stored, and doesn't return anything, so you wouldn't need the["some_key"]
part.
But i need to delete the Keys separately.
@dilshd specify the version:
flutter_secure_storage: 9.0.0
i did, but still same.
You might need to do a
flutter clean
and rebuild so the downgrade actually happens. As far as thedelete
method, I am unsure. It's entirely possible that method is bugged as well, in which case the package maintainer can hopefully weigh in with a workaround and/or a fix.is it possible like this ? final key = (await secureStore.deleteAll())["some_key"];
Only if you are okay with deleting all keys.
deleteAll
deletes all keys you have stored, and doesn't return anything, so you wouldn't need the["some_key"]
part.But i need to delete separately.
Then I suggest pinning the version of this package to 9.0.0 or earlier, until it works for you without errors.
@dilshd specify the version:
flutter_secure_storage: 9.0.0
i did, but still same.
You might need to do a
flutter clean
and rebuild so the downgrade actually happens. As far as thedelete
method, I am unsure. It's entirely possible that method is bugged as well, in which case the package maintainer can hopefully weigh in with a workaround and/or a fix.is it possible like this ? final key = (await secureStore.deleteAll())["some_key"];
Only if you are okay with deleting all keys.
deleteAll
deletes all keys you have stored, and doesn't return anything, so you wouldn't need the["some_key"]
part.But i need to delete separately.
Then I suggest pinning the version of this package to 9.0.0 or earlier, until it works for you without errors.
i changed to 9.0.0 in pubspec.lock & pubspec.yaml, But the error still showing down.
@dilshd delete pubspec.lock
, run flutter clean
, then run flutter pub get
and then rebuild the project
@dilshd delete
pubspec.lock
, runflutter clean
, then runflutter pub get
and then rebuild the project
It works, thanks.
In macOS, I had to pin also the flutter_secure_storage_macos package in pubspec.yaml
dependency_overrides:
flutter_secure_storage: 9.1.1
flutter_secure_storage_macos: 3.0.1
In macOS, I had to pin also the flutter_secure_storage_macos package in pubspec.yaml
dependency_overrides: flutter_secure_storage: 9.1.1 flutter_secure_storage_macos: 3.0.1
More like
dependency_overrides:
# temporary fix for https://github.com/mogol/flutter_secure_storage/issues/709
flutter_secure_storage: 9.0.0
flutter_secure_storage_linux: 1.2.0
flutter_secure_storage_macos: 3.0.1
flutter_secure_storage_platform_interface: 1.0.2
flutter_secure_storage_windows: 3.0.0
flutter_secure_storage_web: 1.2.0
write도 마찬가지인데 해결 하려면 어떻게 해야돼??
The roll back to 9.0.0 worked great after flutter clean. Is there a way to follow the issue on Github so I can update the package once a fix is released?
Does the OS use cache internally when using Keychain? There is no problem when I access the Key value already in use before the package update, but when I read it again after calling the remove method, a problem occurs.
Hi all, i am reviewing #710 and will release a fix later today
Thanks @juliansteenbakker. Looking forward to the fix. Rolling back to 9.0.0 fixed the issue for me
I'm on 9.0.0 and getting the same error. I did this: delete pubspec.lock, run flutter clean, then run flutter pub get and then rebuild the project - still an issue.
Why would this all of a sudden become an issue, I did not upgrade to 9.1.1?
I had to use readAll() to get the app out.
Getting the same error, I'm already on version 9.0.0 and I did not upgrade to version 9.1.1
The roll back to 9.0.0 worked great after flutter clean. Is there a way to follow the issue on Github so I can update the package once a fix is released?
Top Right - Notifications - Subscribe
This is an odd problem. I'm in 9.0.0 since months and didn't do the upgrade and now I've the error only on the simulator.
I just changed my macbook yesterday so is it really this lib problem ?
ps : workaround seems to be working.
For those who get here and need a temporary workaround for version 9.1.1,
read
is the problem,readAll
works fine. You just need to do the key lookup yourself:final secureStore = const FlutterSecureStorage(); // Not working in 9.1.1 final key = await secureStore.read(key: "some_key"); // Workaround -- `key` will be `null` if not present final key = (await secureStore.readAll())["some_key"];what about secureStore.delete? i got same problem when i delete.
it works for me:
if (await _secureStorage.containsKey(key: _accessTokenKey)) {
await _secureStorage.delete(key: _accessTokenKey);
}
Seems like the issue is fixed with the latest version (9.2.0)
Seems like the issue is fixed with the latest version (9.2.0)
I still experience this error after upgrading to
flutter_secure_storage: 9.2.0
flutter_secure_storage_macos: 3.1.0
flutter_secure_storage_platform_interface: 1.1.2
After restarting the secure storage is empty.
await secureStorage.readAll();
returns an empty Map.
If I downgrade back to
flutter_secure_storage: 9.0.0
flutter_secure_storage_macos: 3.0.1
flutter_secure_storage_platform_interface: 1.0.2
await secureStorage.readAll();
returns a Map with all my data.
@techouse I am unable to reproduce this behavior, can you please provide more detail? It would also be a good idea to run a flutter clean
and fully rebuild.
@juliansteenbakker I did however notice in my testing that the macOS implementation crashes when the key does not exist, which can be fixed in the same manner as my PR for iOS.
It seems that the sub-dependencies are not updated (eg: for macOS).
The last version was 7 days ago.
It seems that the sub-dependencies are not updated (eg: for macOS). The last version was 7 days ago.
The macOS implementation was never updated to match the iOS behaviour. I have updated this just now and am releasing this asap.
I have released v9.2.1 with these fixes.
@techouse I am unable to reproduce this behavior, can you please provide more detail? It would also be a good idea to run a
flutter clean
and fully rebuild.
Hey @ztaylor54 I cleaned it and updated the pods. I'm still having the same problem with v9.2.1.
I did some tests and it looks like using v9.2.1 await secureStorage.readAll()
returns an empty Map {}
, however, await secureStorage.read(key: 'someKeyName')
returns that key's value.
My setup:
- OS: iOS v17.4.1
- Physical Device: iPhone 13 Pro
- Flutter ver: 3.19.6
The keychain was populated with:
flutter_secure_storage: 9.0.0
flutter_secure_storage_macos: 3.0.1
flutter_secure_storage_platform_interface: 1.0.2
I used this simple Dart test code.
final Map<String, String> secureData = await secureStorage.readAll();
print('is secureData empty: ${secureData.isEmpty}');
// call readAll again explicitly
print('stored username via readAll: ${(await secureStorage.readAll())['username']}');
print('stored username via read: ${await secureStorage.read(key: 'username')}');
Using v9.0.0
flutter_secure_storage: 9.0.0
flutter_secure_storage_macos: 3.0.1
flutter_secure_storage_platform_interface: 1.0.2
I get
flutter: is secureData empty: false
flutter: stored username via readAll: foo@bar.baz
flutter: stored username via read: foo@bar.baz
Using v9.2.1
flutter_secure_storage: 9.2.1
flutter_secure_storage_macos: 3.1.1
flutter_secure_storage_platform_interface: 1.1.2
I get
flutter: is secureData empty: true
flutter: stored username via readAll: null
flutter: stored username via read: foo@bar.baz
CC / @juliansteenbakker
@juliansteenbakker @ztaylor54 I submitted a PR #719 fixing the issue in the comment above
-
iOS
It seems that somehow the
accessibility
forreadAll
was explicitly (possibly deliberately?) set tonil
https://github.com/mogol/flutter_secure_storage/blob/eaccd9fb88effab9d3274c51cc91a3bc5886d8fd/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift#L75 which is not the case forread
https://github.com/mogol/flutter_secure_storage/blob/eaccd9fb88effab9d3274c51cc91a3bc5886d8fd/flutter_secure_storage/ios/Classes/FlutterSecureStorage.swift#L105 -
macOS
The same is true for the
macOS
package'sreadAll
https://github.com/mogol/flutter_secure_storage/blob/eaccd9fb88effab9d3274c51cc91a3bc5886d8fd/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift#L78 vsread
https://github.com/mogol/flutter_secure_storage/blob/eaccd9fb88effab9d3274c51cc91a3bc5886d8fd/flutter_secure_storage_macos/macos/Classes/FlutterSecureStorage.swift#L108
If anyone wants to play around with the PR directly you can reference it like this in your pubspec.yaml
dependencies:
flutter_secure_storage: ^9.2.1
dependency_overrides:
flutter_secure_storage:
git:
url: https://github.com/techouse/flutter_secure_storage.git
ref: fix/read-all
path: flutter_secure_storage
flutter_secure_storage_macos:
git:
url: https://github.com/techouse/flutter_secure_storage.git
ref: fix/read-all
path: flutter_secure_storage_macos
I noticed that this also happens when you first do the command:
await SecureStorage.cleanString();
It is not being executed within the function where the new token is captured.
Before my command was directly in OnPressed, when placing it directly in the login()
function on the first line this error disappeared.
Future<void> login(Map<String, dynamic> login) async { String url = '/auth/login'; isLoading = true.obs; await SecureStorage.cleanString(); try { dio.Response response = await _customDio.dio.post(url, data: login); (...)
I noticed that this also happens when you first do the command:
await SecureStorage.cleanString();
I must be blind, but I can't find any mention of a cleanString()
method anywhere in the codebase.
FYI, I've experienced this issue writing a string via _storage.write(key: key, value: value);
with the latest version 9.2.2
.
this issue still with the latest version 9.2.2 when writing secureStorage.write( key: key, value: value,
aOptions: AndroidOptions( encryptedSharedPreferences: true ),
iOptions: IOSOptions(accessibility: KeychainAccessibility.unlocked_this_device));
Yes we are hit by this issue too, version 9.2.2.
in our case issue occurred the first time FlutterSecureStorage.write
was called. We now must better debug, coz it could happen again.
[ERROR: flutter/runtime/dart_vm_initializer.ce(41)] Unhandled Exception: PlatformException(Unexpected security result code, Code: -25300, Message: The sp ecified item could not be found in the keychain., -25300, null)
#0
StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648)
#1
MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334)
‹asynchronous suspension>
#2 FlutterSecureStorage.write (package:flutter_secure_storage/flutter_secure_storage.dart:114)
‹asynchronous suspension>
I am also facing this for some of our users not all on 9.2.2. Anyone why it's happening? And also it is happening for some keys not all.
A workaround solution:
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:synchronized/synchronized.dart';
class AuthCache {
static const _accessTokenKey = "ACCESS_TOKEN_KEY";
final FlutterSecureStorage _secureStorage;
final _accessTokenLock = Lock();
AuthCache._()
: _secureStorage = const FlutterSecureStorage(
aOptions: AndroidOptions(
encryptedSharedPreferences: true,
),
);
Future<void> setAccessToken(String accessToken) async {
await _accessTokenLock.synchronized(() async {
await _secureStorage.write(key: _accessTokenKey, value: accessToken);
});
}
}