Skip to content

[linux] support XDG Desktop Secret Portal (org.freedesktop.portal.Secret) #16

Open

Description

@EchoEllet

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

See also: https://pub.dev/packages/freedesktop_secret#portal-security-model

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

  1. added
    enhancement
    on Jul 21, 2026
  2. EchoEllet commented on Jul 21, 2026

    @EchoEllet
    ContributorAuthor

    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.

  3. Skyost commented on Jul 22, 2026

    @Skyost
    Owner

    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_store as an implementation detail.

    I only have one side question regarding its cryptography dependency : is there a particular reason why it uses cryptography rather than cipherlib? cipherlib is part of a broader family of packages alongside convertlib and hashlib, and it does not introduce additional dependencies (eg. Dart's crypto, ffi, ...). Using it would also keep this implementation consistent with the cryptography library already used by the web implementation of simple_secure_storage.
    This is not necessarily a blocker, but I would be interested in understanding the reasoning behind the current choice before moving forward.

  4. EchoEllet commented on Jul 22, 2026

    @EchoEllet
    ContributorAuthor

    Thank you for the response and for considering this!

    I only have one side question regarding its cryptography dependency : is there a particular reason why it uses cryptography rather than cipherlib?

    Not that I can think of. It is mainly for convenience, but the default implementation can be overridden.

    I do agree that forcing package:cryptography as 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, or xdg_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_store is still useful because it provides a unified model, convenient API that integrates well xdg_desktop_portal without 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 with xdg_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 .keyring format, but even then we would need to retain compatibility and track their changes and migrations.

    and it does not introduce additional dependencies (eg. Dart's crypto, ffi, ...)

    I agree that it is a bit inconsistent that it depends on Dart's crypto while in the readme it states the 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):

    import 'package:crypto/crypto.dart' as other;
    import 'package:cryptography/cryptography.dart';
     
    /// [Sha1] implemented with [package:crypto](https://pub.dev/packages/crypto)
    /// (a package by Google).

    Because package:crypto is a pure Dart package, unused or dead code will be automatically eliminated
    assuming 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 adding package:crypto (from dart.dev) as a transitive dependency.

    hashlib

    Many packages end up adding package:crypto as a transitive dependency even if they do not use it directly: https://pub.dev/packages?q=dependency%3Acrypto
    This includes uuid, dio, google_fonts, hydrated_bloc, postgres, web_socket_channel and even hashlib.

    ffi

    I think the primary purpose for package:ffi is 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 of material_ui or cupertino_ui.

    Many Flutter plugins (from flutter.dev) have been updated to use ffi (directly or indirectly), and even jni / objective_c (from dart.dev) depend on it. For example, path_provider_android depends on jni, path_provider_foundation depends on objective_c. So adding any of them pulls ffi as a transitive dependency.

    I don't think package:ffi is 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.08M
    • package:ffi: 9.6M
    • package:meta: 10M

    Tip

    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 for freedesktop_secret and xdg_secret_portal_store.

    Using pure Dart code for integration tests and avoiding method channels is valuable.

    But even then, both freedesktop_secret and xdg_desktop_portal depend on dbus and dbus depends on ffi.

    So I think it is reasonable for cryptography to adapt ffi. 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_flutter does 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 cryptography is 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:

    dependencies:
      flutter_secure_storage_platform_interface: ^2.0.1
      xdg_secret_portal_store: ^0.1.0
      xdg_desktop_portal: ^0.1.13
      xdg_directories: ^1.1.0
      linux_application_id: ^1.0.0

    We can technically replace xdg_directories and linux_application_id with path_provider but path_provider is Flutter-specific and will bring additional transitive dependencies implicitly, such as flutter (for method channels), path_provider_platform_interface, path and ffi (the package, not just dart:ffi).

    linux_application_id is similar to the current internal Flutter implementation of path_provider_linux: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider_linux/lib/src/get_application_id_real.dart

    So even though the above pubspec.yaml of flutter_secure_storage_linux_portal seems like a lot of dependencies compared to just using path_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_store doesn't use xdg_desktop_portal directly, 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_portal so they have the flexibility to move to something different or even their own portal implementation.

    If xdg_secret_portal_store opens a portal client internally, now it has to provide close and force xdg_desktop_portal as a transitive dependency. But if you provided it with a portal client in the constructor, what should close() now do? It has nothing to close (it should not take ownership of the provided instance, which is how avahi and xdg_desktop_portal are designed). That makes it a less clean API and a bit misleading.

    The tradeoff is a more complex setup, but simple_secure_storage_linux_portal will handle this once, and all consumers of simple_secure_storage do 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_store to remove package:cryptography entirely 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 since cryptography does not use native code or method channels directly (it leaves this for cryptography_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 cryptography releases 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 removing simple_secure_storage_linux_portal, which removes cryptography.

    And because simple_secure_storage will not force simple_secure_storage_linux_portal as a transitive dependency, this does not impact non-Linux users in practice who do not want to maintain a Linux app and its dependencies.

    Using it would also keep this implementation consistent with the cryptography library already used by the web implementation of simple_secure_storage.

    If the primary concern is behavior implementation, then we can already implement this:

    import 'package:xdg_secret_portal_store/xdg_secret_portal_store.dart';
    
    class SecretStoreCryptoCustom implements SecretStoreCrypto {
      // ...
    }

    And then pass it:

    final store = XdgSecretPortalStore(
      // ...
      crypto: SecretStoreCryptoCustom(),
    );

    My only concern is package:cryptography may 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/cryptography

    Note

    Off-topic Example: I used package:serverpod in 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_store if a transitive dependency of xdg_secret_portal_store made a similar change. Hopefully it will be a rare case, not something I would expect with package:cryptography.

  5. EchoEllet commented on Jul 22, 2026

    @EchoEllet
    ContributorAuthor

    I only have one side question regarding its cryptography dependency : is there a particular reason why it uses cryptography

    I have updated package:xdg_secret_portal_store so that it does not include any cryptographic implementation on its own, and therefore no longer adds package:cryptography as 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_store without being forced into a specific crypto library or any algorithm implementation detail.
    That means xdg_secret_portal_store_default can no longer assume and maintain breaking changes across different implementations.

  6. Skyost commented on Jul 22, 2026

    @Skyost
    Owner

    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_store implementation-agnostic to me.

  7. EchoEllet commented on Jul 22, 2026

    @EchoEllet
    ContributorAuthor

    Glad the design update was useful! So, should we use package:cipherlib or package:cryptography?

    It seems cryptography depends on crypto to implement some interfaces for compatibility reasons (dint-dev/cryptography#228). As for package:ffi, it is already required by xdg_desktop_portal, dbus, feeedesktop, and linux_application_id.

    Using a different cryptographic library is totally fine, though. You may want to read this section.

  8. Skyost commented on Jul 23, 2026

    @Skyost
    Owner

    Glad the design update was useful! So, should we use package:cipherlib or package:cryptography?

    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 prefer cryptography.

  9. EchoEllet commented on Jul 23, 2026

    @EchoEllet
    ContributorAuthor

    Personally, I prefer cipherlib

    Sure, I will go with cipherlib (the maintenance situation of cryptography is concerning).

    Regarding the cryptographic design, is this sufficient?

    I think compatibility across different libraries is beneficial. That's one of package:freedesktop_secret strengths, 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_store is opinionated. For libraries that store the secrets as Map<String, String>, it is usually sufficient.

  10. Skyost commented on Jul 25, 2026

    @Skyost
    Owner

    Regarding the cryptographic design, is this sufficient?

    Sure !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions