flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

[Linux] Warning "libsecret_error: Failed to unlock the keyring"

Open PureTryOut opened this issue 1 year ago • 12 comments

I have an application that uses flutter_secure_storage to locally store credentials. Although I've ran this application successfully before it's been a while since I launched it and now it fails to unlock the keyring for some reason. I'm using KDE Plasma and it's kwallet is used as the keyring provider, with kwalletmanager I can still see the entry from last time I've used flutter_secure_storage so the keyring itself works just fine. I tried wiping the stored credentials and starting anew but it made no difference.

When reading any entry from the storage the console logs the following:

** (<appname>19565): WARNING **: 09:53:45.713: libsecret_error: Failed to unlock the keyring

It gives me no explanation on what exactly is failing so I have no way to figure out what's going wrong.

PureTryOut avatar Aug 27 '24 07:08 PureTryOut

When calling .deleteAll() it actually even errors out badly:

** (<appname>:27723): WARNING **: 15:41:52.952: libsecret_error: \xb2\xfe\u001d!
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Unexpected extension byte (at offset 1)
#0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1760:7)
#1      Utf8Decoder.convert (dart:convert/utf.dart:349:37)
#2      StandardMessageCodec.readValueOfType (package:flutter/src/services/message_codecs.dart:502:29)
#3      StandardMessageCodec.readValue (package:flutter/src/services/message_codecs.dart:477:12)
#4      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:644:47)
#5      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
<asynchronous suspension>
#6      FlutterSecureStorage.deleteAll (package:flutter_secure_storage/flutter_secure_storage.dart:285:5)

PureTryOut avatar Aug 27 '24 13:08 PureTryOut

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar Oct 27 '24 02:10 github-actions[bot]

This is still very much relevant and still breaks the whole functionality of this package on Linux!

PureTryOut avatar Oct 27 '24 07:10 PureTryOut

Sorry for the late response. Can you please check if this still an issue with version 10.0.0-beta.1? If so, I will try to setup a linux environment to check how i can solve this issue.

juliansteenbakker avatar Jan 06 '25 17:01 juliansteenbakker

It still doesn't work in 10.0.0-beta.4. I have a fresh Ubuntu installation, so it can't be me.

SuricateTrading avatar Feb 08 '25 21:02 SuricateTrading

⚠️ This issue has been marked as stale because it has been open for 60 days with no activity.

If this issue is still relevant, please comment to keep it active. Otherwise, it will be closed in 60 days.

github-actions[bot] avatar Apr 10 '25 02:04 github-actions[bot]

Still relevant

gepbird avatar Apr 10 '25 04:04 gepbird

Can you guys provide what's your exact OS version and flutter_secure_storage version?

It seems that this issue was initially reported in August 2024, yet flutter_secure_storage had its latest version, 9.2.4 released on Jan 9, 2025

tomekit avatar Apr 10 '25 09:04 tomekit

Can you guys provide what's your exact OS version and flutter_secure_storage version?

It seems that this issue was initially reported in August 2024, yet flutter_secure_storage had its latest version, 9.2.4 released on Jan 9, 2025

I use Ubuntu 24.04.2 LTS and flutter_secure_storage 9.2.4 So both versions are up to date.

SuricateTrading avatar Apr 14 '25 08:04 SuricateTrading

I use EndeavourOS (no version here because it's based on Arch) and flutter_secure_storage 9.2.4. I get the exact same problem.

I have a suggestion of how we could fix the issue though. There is a packaged called dbus_secrets that works really well on Linux as it uses Canonical's dbus package to communicate directly with the org.freedesktop.secrets service. I've replaced my usage of flutter_secure_storage with dbus_secrets on Linux. However, the main package (as of writing this) has some issues on various desktops due to not following the standard completely. I forked it and created a pull request that makes it work in more places. After this, it at least works using gnome-keyring (default on Gnome) and kwallet (default on KDE), the only things I've tested it with so far.

If wanted, we could implement a new version of flutter_secure_storage_linux that uses dbus instead of the current approach with libsecret requiring native code.

Unbreathable avatar May 06 '25 14:05 Unbreathable

A few weeks ago, it suddenly started working on Linux. However, today I suddenly got the same error message again. I fixed the problem by updating everything (operating system, packages, Dart, Flutter), and now it's working perfectly again. This is really strange because when I first got the error message, I had a brand new Ubuntu installed, and everything was just installed and up to date.

SuricateTrading avatar May 06 '25 16:05 SuricateTrading

I arrived here after attempting to add Linux support to my application (which already runs on both Android and Windows).

I use Fedora Silverblue, but I think my findings will be of general interest.

I managed to get my app running without issue (including flutter_secure_storage usage) when building and running from within a Toolbox. I then moved onto solving the "IDE problem", by which I mean how can I connect my Flatpak-installed Code instance to the project-specific toolbox that contains the correct version of Flutter and other tooling?

I decided to set up SSH in the toolbox and use Code's remote development tooling, along with the X-forwarding capabilities of SSH, to build and debug my app. I got that working but hit this issue (Failed to unlock the keyring). So it's interesting that it triggers when running the app within an SSH session, but not when running directly from the toolbox.

Anyway, I tried the suggestion from @Unbreathable (thanks!) and swapped out flutter_secure_storage for dbus_secrets and sure enough it worked. Of course, now I will need to introduce an abstraction in my app that either uses dbus_secrets on Linux or flutter_secure_storage for other platforms. It would be wonderful if this could be addressed in this library so I don't need this hoop-jumping.

johnnyggalt avatar May 29 '25 03:05 johnnyggalt

⚠️ This issue has been marked as stale because it has been open for 60 days with no activity.

If this issue is still relevant, please comment to keep it active. Otherwise, it will be closed in 60 days.

github-actions[bot] avatar Jul 29 '25 03:07 github-actions[bot]

Still relevant OS :Ubuntu 24.04.3 LTS on WSL2 flutter_secure_storage: both 9.2.4 and ^10.0.0-beta.4 would fail hope that helps

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(Libsecret error, Failed to unlock the keyring, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:367:18)
<asynchronous suspension>
#2      _SecureTokenStorage.load (package:personal_finance/services/token_storage_io.dart:18:16)
<asynchronous suspension>
#3      Session.loadFromStorage (package:personal_finance/services/session.dart:13:16)
<asynchronous suspension>
#4      _MyAppState.initState.<anonymous closure> (package:personal_finance/app.dart:23:7)
<asynchronous suspension>

rangermix avatar Aug 25 '25 13:08 rangermix

Hopefully this helps someone. For me the plugin was working fine on my Ubuntu desktop, but failing on my Debian CI machine (I run the integration test suite for my Flutter app as a Linux app in CI). The reason for this was that my code was running in a Docker container, it needed to unlock the keyring.

I fixed it by installing GNOME keyring in the Docker container:

  • apt install gnome-keyring in the Dockerfile
  • Launching the Docker container with --cap-add ipc_lock
  • In the CI config that runs the tests:
dbus-run-session --bash -c "
  printf '\n' | gnome-keyring-daemon --unlock
  <command to run tests>
"

For those of you not running in Docker and are running the app on bare metal, perhaps you need to run gnome-keyring-daemon --unlock as part of your app startup in Linux.

robbrit avatar Aug 27 '25 19:08 robbrit

Your issue is different then, as I already had a working keyring installed, kwallet. I mentioned this in the original post. Please don't pollute the issue thread.

PureTryOut avatar Aug 28 '25 05:08 PureTryOut

Your issue is different then, as I already had a working keyring installed, kwallet. I mentioned this in the original post.

The thing is that you not only need to have keyring installed, but also unlocked. Thanks to @robbrit taking time to write his comment we now know how to unlock GNOME keyring and how flutter_secure_storage fails if you don't.

Apparently similar procedure is required for KDE Wallet, by calling: /usr/lib/pam_kwallet_init as mentioned here: https://wiki.archlinux.org/title/KDE_Wallet#Unlocking_KWallet_automatically_in_a_window_manager

Please don't pollute the issue thread.

There is a possibility that you're experiencing a different problem, but given that other commenters are also experiencing this issue in other Linux distros and not just KDE I wouldn't even think about calling helpful comment a pollution.

tomekit avatar Aug 28 '25 18:08 tomekit

I've identified the cause and solution of this issue.

Ubuntu has a feature called “Automatic Login”, which lets you skip entering your user password each time you start your computer. However, when this feature is enabled, the Keyring is not unlocked automatically at login.

Because of that, flutter_secure_storage (and any other library that relies on libsecret) cannot access the keyring — it remains locked, and the app itself has no way to unlock it since that requires the user’s Ubuntu password.

So, this isn’t actually a bug in flutter_secure_storage, but rather a side effect of Ubuntu’s login configuration. That said, the error message could definitely be clearer and more helpful.

There are a few ways for users to fix this on their systems:

  1. Disable automatic login and restart (recommended) Go to Settings, search for "Users" and turn off “Automatic Login”

  2. Manually unlock the keyring (inconvenient)

  3. Use a keyring without a password (insecure)

In short, the issue is caused by the system configuration, not the app. This can be problematic because many Ubuntu users have Automatic Login enabled by default, so they might all encounter the same confusing error message without understanding its cause.

SuricateTrading avatar Oct 26 '25 14:10 SuricateTrading

I don't use sutomatic login and my keyring is automatically unlocked on login. I'm happy it works for you but it's not "the" cause or "the" solution.

PureTryOut avatar Oct 27 '25 05:10 PureTryOut

What's the name of your keyrings? You should have a "login" keyring and I think it has to be set to default.

SuricateTrading avatar Oct 27 '25 08:10 SuricateTrading

I've identified the cause and solution of this issue.

Ubuntu has a feature called “Automatic Login”, which lets you skip entering your user password each time you start your computer. However, when this feature is enabled, the Keyring is not unlocked automatically at login.

Because of that, flutter_secure_storage (and any other library that relies on libsecret) cannot access the keyring — it remains locked, and the app itself has no way to unlock it since that requires the user’s Ubuntu password.

So, this isn’t actually a bug in flutter_secure_storage, but rather a side effect of Ubuntu’s login configuration. That said, the error message could definitely be clearer and more helpful.

There are a few ways for users to fix this on their systems:

  1. Disable automatic login and restart (recommended) Go to Settings, search for "Users" and turn off “Automatic Login”
  2. Manually unlock the keyring (inconvenient)
  3. Use a keyring without a password (insecure)

In short, the issue is caused by the system configuration, not the app. This can be problematic because many Ubuntu users have Automatic Login enabled by default, so they might all encounter the same confusing error message without understanding its cause.

Hi, I use Gnome Keyring with a "Login" entry without a password and the problem continues.

Nieto2018 avatar Oct 30 '25 12:10 Nieto2018