mogol / flutter_secure_storage

A Flutter plugin to store data in secure storage
https://pub.dartlang.org/packages/flutter_secure_storage
BSD 3-Clause "New" or "Revised" License
1.09k stars 340 forks source link

The specified item could not be found in the keychain #709

Closed gianlucainnocente closed 1 month ago

gianlucainnocente commented 1 month ago

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

techouse commented 1 month ago

Same here, data from the keychain can not be read.

SpykeyRev commented 1 month ago

Same here.

dilshd commented 1 month ago

Same here, what's the solution?

JgomesAT commented 1 month ago

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

techouse commented 1 month ago

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.

techouse commented 1 month ago

Same here, what's the solution?

Don't upgrade.

nausharipov commented 1 month ago

Same here. Fixed my version to: flutter_secure_storage: 9.0.0.

ztaylor54 commented 1 month ago

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.

ztaylor54 commented 1 month ago

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"];
mNouh94 commented 1 month ago

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

dilshd commented 1 month ago

Same here, what's the solution?

Don't upgrade.

now i have flutter_secure_storage: ^9.0.0, but still showing same error

nausharipov commented 1 month ago

@dilshd specify the version: flutter_secure_storage: 9.0.0

dilshd commented 1 month ago

@dilshd specify the version: flutter_secure_storage: 9.0.0

i did, but still same.

dilshd commented 1 month ago

How i can fix it?

dilshd commented 1 month ago

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.

ztaylor54 commented 1 month ago

@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 commented 1 month ago

@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.

is it possible like this ? final key = (await secureStore.deleteAll())["some_key"];

ztaylor54 commented 1 month ago

@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.

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 commented 1 month ago

@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.

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.

ztaylor54 commented 1 month ago

@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.

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 commented 1 month ago

@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.

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.

ztaylor54 commented 1 month ago

@dilshd delete pubspec.lock, run flutter clean, then run flutter pub get and then rebuild the project

dilshd commented 1 month ago

@dilshd delete pubspec.lock, run flutter clean, then run flutter pub get and then rebuild the project

It works, thanks.

abibiano commented 1 month ago

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
techouse commented 1 month ago

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
earthManMan commented 1 month ago

write도 마찬가지인데 해결 하려면 어떻게 해야돼??

perdomon commented 1 month ago

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?

KOREAparksh commented 1 month ago

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.

juliansteenbakker commented 1 month ago

Hi all, i am reviewing #710 and will release a fix later today

sAtluna commented 1 month ago

Thanks @juliansteenbakker. Looking forward to the fix. Rolling back to 9.0.0 fixed the issue for me

mellowcello77 commented 1 month ago

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.

hasunperera commented 1 month ago

Getting the same error, I'm already on version 9.0.0 and I did not upgrade to version 9.1.1

byronweiss commented 1 month ago

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

EpiSayLaCata commented 1 month ago

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.

hantrungkien commented 1 month ago

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);
    }
ercantomac commented 1 month ago

Seems like the issue is fixed with the latest version (9.2.0)

techouse commented 1 month ago

Seems like the issue is fixed with the latest version (9.2.0)

I still experience this error after upgrading to

After restarting the secure storage is empty.

await secureStorage.readAll();

returns an empty Map.

If I downgrade back to

await secureStorage.readAll();

returns a Map with all my data.

CC / @juliansteenbakker @ztaylor54

ztaylor54 commented 1 month ago

@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.

g123k commented 1 month ago

It seems that the sub-dependencies are not updated (eg: for macOS). The last version was 7 days ago.

juliansteenbakker commented 1 month 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.

juliansteenbakker commented 1 month ago

I have released v9.2.1 with these fixes.

techouse commented 1 month ago

@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:

The keychain was populated with:

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

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

I get

flutter: is secureData empty: true
flutter: stored username via readAll: null
flutter: stored username via read: foo@bar.baz

CC / @juliansteenbakker

techouse commented 1 month ago

@juliansteenbakker @ztaylor54 I submitted a PR #719 fixing the issue in the comment above

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
CaioBonalume commented 1 month ago

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); (...)

techouse commented 1 month ago

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.

lance-mlabs commented 2 weeks ago

FYI, I've experienced this issue writing a string via _storage.write(key: key, value: value); with the latest version 9.2.2.

HoangDinhTho commented 1 week ago

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));