Repository navigation
Description
Follow-up #15: supporting the secret portal.
Context
XDG portals are designed for sandboxing, security, and privacy (they are more than alternative APIs and are toolkit-agnostic), and are commonly used by Snap and Flatpak applications. Closer to Android/iOS/macOS security model than traditional desktop.
The secret portal (org.freedesktop.portal.Secret) is not a direct replacement for the secret service API (org.freedesktop.secrets) is designed to solve a different problem, which is application sandboxing.
The secret portal is not a secure storage itself; instead, it provides a unique master secret per application. It is created internally and does not change after app installation. The secret portal implementation may internally depend on the secret service to store a master secret for each application (but that's not part of the public contract).
The secret portal can also be used outside of sandbox applications, though do not seem to be widely adopted (source).
Secret portal support
package:freedesktop_secret is an org.freedesktop.secrets client; by design does not support the secret portal since it is fundamentally different.
package:xdg_desktop_portal is a portal client maintained by Canonical, and by design it only exposes the master secret.
For a complete secure storage, an application would need to store secrets encrypted in a file.
I have created a simple package (xdg_secret_portal_store) which provides convenient secure storage that depends on the portal client indirectly.
xdg_secret_portal_store is designed to complement package:xdg_desktop_portal so it is not a portal client but more of a helper library.
It stores secrets in a map Map<String, String> (JSON, UTF-8), which is suitable for simple_secure_storage. I have implemented integration tests and verified them against KDE CachyOS (KWallet).
It uses package:cryptography and by design does not depend on xdg_desktop_portal, xdg_directories or linux_application_id directly. It does not define a default file path either.
Note
Disclaimer: I'm not a security professional. The heavy lifting was done by package:cryptography. See also this README section and the implementation).
Simple secure storage can use package:xdg_secret_portal_store as an implementation detail so consumers of the plugin can use it in Flatpak/Snap without needing abstractions around simple_secure_storage.
xdg_secret_portal_store is significantly simpler than freedesktop_secret.
Design decisions
A new package or the same Linux package
The portal implementation can be part of simple_secure_storage_linux or part of simple_secure_storage_linux_portal (a new decoupled package).
I strongly vote for the latter, it is easier to implement integration tests and more flexible in terms of backend selection. The user only get the modules they need.
It also ensures that the selection between the portal and secret service API depends entirely on the app and its requirements. GNOME libsecret automatically detects Flatpak/Snap.
This also ensures that when package:cryptography or package:xdg_desktop_portal releases breaking changes, not all users will be affected (including non-Linux users).
However, it is yet another package to publish, which may slightly complicate Melos setup and CHANGELOG.
Use xdg_secret_portal_store or implement the portal secure storage directly
xdg_secret_portal_store is opinionated when it comes to the JSON schema and is designed to store the secrets locally on disk (the default implementation can be replaced).
Activity
EchoEllet commentedon Jul 21, 2026
I would be happy to send a PR. I need to know the preferred approach to handle it, or whether this is something under consideration.
Skyost commentedon Jul 22, 2026
Thanks for opening this issue and for the detailed explanation. I am definitely considering this feature, and I would be very happy to receive a PR for it.
I also agree that using a separate package, such as
simple_secure_storage_linux_portal, is the more reasonable approach. Your arguments in favor of keeping the portal implementation decoupled from the regular Linux backend are convincing, especially given how different the two security models are.You can absolutely use
xdg_secret_portal_storeas an implementation detail.I only have one side question regarding its cryptography dependency : is there a particular reason why it uses
cryptographyrather thancipherlib?cipherlibis part of a broader family of packages alongsideconvertlibandhashlib, and it does not introduce additional dependencies (eg. Dart'scrypto,ffi, ...). Using it would also keep this implementation consistent with the cryptography library already used by the web implementation ofsimple_secure_storage.This is not necessarily a blocker, but I would be interested in understanding the reasoning behind the current choice before moving forward.
EchoEllet commentedon Jul 22, 2026
Thank you for the response and for considering this!
Not that I can think of. It is mainly for convenience, but the default implementation can be overridden.
I do agree that forcing
package:cryptographyas a transitive dependency is a questionable decision. But the only alternative that I can think of is to move the default implementation to a separate package (xdg_secret_portal_store_default, orxdg_secret_portal_store_cryptography).Using a custom implementation is definitely possible, but then the consumer would be responsible for handling migrations and security decisions.
xdg_secret_portal_storeis still useful because it provides a unified model, convenient API that integrates wellxdg_desktop_portalwithout depending on it directly (it also intentionally does not re-implement the portal client, because it aims to adapt the ecosystem unless there is a reason or a design issue withxdg_desktop_portal).A unified JSON schema/model is still valuable.
The portal implementation is not interoperable with GNOME libsecret because libsecret uses a custom format that is specific to GNOME keyring (i.e., the old
libgnome-keyring, not part of the freedesktop/xdg specification) when running inside Flatpak/Snap. I could not find public documentation for.keyringformat, but even then we would need to retain compatibility and track their changes and migrations.I agree that it is a bit inconsistent that it depends on Dart's
cryptowhile in the readme it statesthe older "package:crypto"(I have filed an issue in their repo: dint-dev/cryptography#228).It seems to depend on it for compatibility reasons, so it only implements some interfaces or classes: https://github.com/search?q=repo%3Adint-dev%2Fcryptography%20package%3Acrypto&type=code
Example from its internal code (open the link above for all usages):
Because
package:cryptois a pure Dart package, unused or dead code will be automatically eliminatedassuming tree-shaking is enabled (which is the default). This is unlike Dart packages that depend on native dependencies (e.g.,
firebase_storage), which use native code and method channels. Only the Dart code will be tree-shaken.Still,
cryptography(from dint.dev) could explain the reason behind addingpackage:crypto(from dart.dev) as a transitive dependency.Many packages end up adding
package:cryptoas a transitive dependency even if they do not use it directly: https://pub.dev/packages?q=dependency%3AcryptoThis includes
uuid,dio,google_fonts,hydrated_bloc,postgres,web_socket_channeland evenhashlib.I think the primary purpose for
package:ffiis compatibility, so they separated the core part (dart:ffi) from the part that changes often. They could have made them both part of the Dart SDK, but that makes it harder to backport changes, support older versions, and it keeps changes more coupled to Dart/Flutter SDK version. This is also why Material UI and Cupertino are being slowly refactored to be outside of the Flutter framework. You may have heard ofmaterial_uiorcupertino_ui.Many Flutter plugins (from flutter.dev) have been updated to use
ffi(directly or indirectly), and evenjni/objective_c(from dart.dev) depend on it. For example,path_provider_androiddepends onjni,path_provider_foundationdepends onobjective_c. So adding any of them pullsffias a transitive dependency.I don't think
package:ffiis something we should abstract or avoid. If anything, more Flutter plugins may end up adapting it to migrate away from method channels (which depend on the Flutter engine).For comparison, the downloads of each package (at the time of this comment):
package:collection: 7.08Mpackage:ffi: 9.6Mpackage:meta: 10MTip
Using FFI in some cases makes it possible to not require a Flutter app, so you run your plugin's tests purely in Dart (
dart test integration_test/*), which is blazing fast (often takes less than 1 second to complete even with dozens of IO operations, without needing to build a native app on every run) and simpler (less CI YAML configuration). This is the case forfreedesktop_secretandxdg_secret_portal_store.Using pure Dart code for integration tests and avoiding method channels is valuable.
But even then, both
freedesktop_secretandxdg_desktop_portaldepend ondbusanddbusdepends onffi.So I think it is reasonable for
cryptographyto adaptffi. Maybe it is even more efficient or faster than a pure Dart implementation for such problems?For me it is enough that it does not force Flutter and method channels (separate package:
cryptography_flutter).cryptography_flutterdoes not have a Linux-specific implementation (unlike macOS/iOS/Android), so using it for a Linux-only implementation will not bring any value.I do, however, wonder whether I should move the default implementation to a separate package, so
cryptographyis no longer a required dependency.The tradeoff is that now we have to track migrations and compatibility across different implementations and complicate the implementation for
simple_secure_storage_linux_portal.When I was implementing
flutter_secure_storage_linux_portal(not published yet), the dependencies were:We can technically replace
xdg_directoriesandlinux_application_idwithpath_providerbutpath_provideris Flutter-specific and will bring additional transitive dependencies implicitly, such asflutter(for method channels),path_provider_platform_interface,pathandffi(the package, not justdart:ffi).linux_application_idis similar to the current internal Flutter implementation ofpath_provider_linux: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider_linux/lib/src/get_application_id_real.dartSo even though the above
pubspec.yamlofflutter_secure_storage_linux_portalseems like a lot of dependencies compared to just usingpath_provider, it is actually fewer dependencies, fewer breaking changes, with a similar behavior (but more independent of Flutter SDK).As for why
xdg_secret_portal_storedoesn't usexdg_desktop_portaldirectly, the reason is lifecycle.A portal client provides many functionalities, and opening one just for the secret portal is overkill. An application should consider opening one portal client for all portal-related functionalities. It also ensures users are independent of
xdg_desktop_portalso they have the flexibility to move to something different or even their own portal implementation.If
xdg_secret_portal_storeopens a portal client internally, now it has to providecloseand forcexdg_desktop_portalas a transitive dependency. But if you provided it with a portal client in the constructor, what shouldclose()now do? It has nothing to close (it should not take ownership of the provided instance, which is howavahiandxdg_desktop_portalare designed). That makes it a less clean API and a bit misleading.The tradeoff is a more complex setup, but
simple_secure_storage_linux_portalwill handle this once, and all consumers ofsimple_secure_storagedo not need to know these details or manually configure them.Given the current situation, do you think it would be valuable for
xdg_secret_portal_storeto removepackage:cryptographyentirely and require a default implementation? Note that we already abstract it, so you can supply a different implementation, and any unused/dead code typically gets removed in practice sincecryptographydoes not use native code or method channels directly (it leaves this forcryptography_flutter). So if the concern is bundle size or tree shaking, the current implementation already handles it.If the concern is that we need to update when
cryptographyreleases breaking changes, which affects every Flutter user even if they do not use it directly or do not build a Linux app, then that's a valid concern. But they still have the choice of removingsimple_secure_storage_linux_portal, which removescryptography.And because
simple_secure_storagewill not forcesimple_secure_storage_linux_portalas a transitive dependency, this does not impact non-Linux users in practice who do not want to maintain a Linux app and its dependencies.If the primary concern is behavior implementation, then we can already implement this:
And then pass it:
My only concern is
package:cryptographymay add build hooks in the future and bundle native dependencies, which does not seem to be currently the case: https://github.com/dint-dev/cryptography/tree/master/cryptographyNote
Off-topic Example: I used
package:serverpodin the past, and then suddenly, with a minor update, it added SQLite native dependencies (which is a new feature and is not always needed for an API server that depends on PostgreSQL), which added build hooks that broke my Dart tests and scripts. So I migrated to Dart Shelf (full reasons).This shows that some consumers may migrate from
xdg_secret_portal_storeif a transitive dependency ofxdg_secret_portal_storemade a similar change. Hopefully it will be a rare case, not something I would expect withpackage:cryptography.EchoEllet commentedon Jul 22, 2026
I have updated
package:xdg_secret_portal_storeso that it does not include any cryptographic implementation on its own, and therefore no longer addspackage:cryptographyas a transitive dependency.Instead, I have moved the default implementation to
package:xdg_secret_portal_store_default(a separate package).This only requires 3 additional lines of code from the consumer's perspective. In exchange for this complexity, we can now use
xdg_secret_portal_storewithout being forced into a specific crypto library or any algorithm implementation detail.That means
xdg_secret_portal_store_defaultcan no longer assume and maintain breaking changes across different implementations.Skyost commentedon Jul 22, 2026
Thanks a lot for this complete update and for your work. Your separation makes sense. The small amount of additional setup seems like a reasonable trade-off for keeping
xdg_secret_portal_storeimplementation-agnostic to me.EchoEllet commentedon Jul 22, 2026
Glad the design update was useful! So, should we use
package:cipherliborpackage:cryptography?It seems
cryptographydepends oncryptoto implement some interfaces for compatibility reasons (dint-dev/cryptography#228). As forpackage:ffi, it is already required byxdg_desktop_portal,dbus,feeedesktop, andlinux_application_id.Using a different cryptographic library is totally fine, though. You may want to read this section.
Skyost commentedon Jul 23, 2026
Personally, I prefer
cipherlib(because it's already used on web ; also because I use it in other projects and I find it well-maintained and well-designed). But, as I said, it's not a blocker for me if you prefercryptography.EchoEllet commentedon Jul 23, 2026
Sure, I will go with
cipherlib(the maintenance situation ofcryptographyis concerning).Regarding the cryptographic design, is this sufficient?
I think compatibility across different libraries is beneficial. That's one of
package:freedesktop_secretstrengths, but with the Secret Portal, it is a bit more fragmented.Maybe we should all agree on the same file path and algorithm unless there is a reason or a weakness with the design?
The JSON schema of
xdg_secret_portal_storeis opinionated. For libraries that store the secrets asMap<String, String>, it is usually sufficient.Skyost commentedon Jul 25, 2026
Sure !
feat(linux): add simple_secure_storage_linux_portal package for XDG D…