Skip to content

Accessing Host Trusted Certificates #2721

Closed as not planned
Closed as not planned

Description

@LorbusChris

Linux distribution and version

Fedora Silverblue 29

Flatpak version

v1.2.3

Description of the problem

Flatpaks apps do not pick up PEM certificates placed in /etc/pki/ca-trust/source/anchors/ on the host.

Steps to reproduce

  • Place custom trusted cert in /etc/pki/ca-trust/source/anchors/
  • Install Riot.im or Firefox Nightly flatpak
  • In Riot.im: Try to log in to a Matrix server that uses that cert -> not possible
  • In Firefox Nightly: Navigate to an URL that uses that cert -> 'Warning: Potential Security Risk Ahead' page is shown

Activity

  1. changed the title [-]Accessing Trusted Certificates from Host[/-] [+]Accessing Host Trusted Certificates[/+] on Feb 24, 2019
  2. LorbusChris commented on Mar 27, 2019

    @LorbusChris
    Author

    Confirmed not to work on Fedora 29 standard as well.

  3. TingPing commented on Mar 27, 2019

    @TingPing
    Member

    Riot probably uses OpenSSL which doesn't respect PKI anyway AFIAK. Firefox should though.

  4. LorbusChris commented on Mar 27, 2019

    @LorbusChris
    Author

    Right, that could be, as I only reproduced it with Riot this time. Firefox Nightlies aren't up to date at the moment, so I didn't test that.

    Any idea how this could be made compatible with OpenSSL?

  5. TingPing commented on Mar 28, 2019

    @TingPing
    Member

    Hmm, it looks like Fedora builds openssl with --openssldir=/etc/pki/tls while freedesktop-sdk has the default /etc/ssl. So that is probably relevant.

    EDIT: Grepping around Flatpak doesn't seem to expose the pki dirs anyway. I thought there was some work on doing so though...

  6. matthiasclasen commented on Mar 28, 2019

    @matthiasclasen
    Collaborator

    @amigadave is this something you could look into for our fedora flatpak builds ?

  7. mcatanzaro commented on Aug 8, 2019

    @mcatanzaro
    Collaborator

    I think Firefox should be fixed nowadays, since https://gitlab.com/freedesktop-sdk/freedesktop-sdk/commit/a11bd7c94e163b34e4ac209361c47f914997932f, which is in 18.08. Can you confirm?

    Then Riot.im is an Electron app, right? So you would need to add p11-kit support to Chromium (CrNet) if you expect it to be able to access host certificates. I don't think it uses OpenSSL.

    Accessing host certificates requires use of the p11-kit server running on the host OS, so if your TLS library doesn't support using p11-kit as its trust store, this is simply not expected to work. So you should report a bug to Chrome (good luck with that) for Riot.im, not here.

    It's true that OpenSSL is not expected to work either, though I think neither of your example apps use OpenSSL. Eventually, OpenSSL will be improved to support p11-kit. Once that happens, we will need to change freedesktop-sdk to build OpenSSL with p11-kit configured as its default trust, like we already do for GnuTLS. freedesktop-sdk also has NSS patched to use p11-kit, like Fedora does, so NSS should work too. (I think OpenSSL is the last remaining significant holdout that doesn't support using p11-kit as its trust store; eventually it will get fixed.)

    So, expected to work:

    • Anything using GnuTLS, including all GNOME stuff and anything else that uses GLib sockets (glib-networking)
    • Anything using NSS, including Firefox
    • freedesktop-sdk only: libcurl (configured to use GnuTLS), and anything using libcurl

    Not expected to work and not our problem:

    • Chrome/Electron stuff
    • Anything using OpenSSL
    • Fedora runtime only: libcurl (configured to use OpenSSL), and anything using libcurl

    TL;DR: this bug should be closed, unless Firefox is still broken. (It should not be broken anymore.)

  8. mcatanzaro commented on Aug 8, 2019

    @mcatanzaro
    Collaborator
    • Chrome/Electron stuff

    Note: this will be using CrNet, and beneath that, BoringSSL. It's probably bundled in the Chromium source code under third_party/.

  9. mcatanzaro commented on Aug 8, 2019

    @mcatanzaro
    Collaborator

    OK one last tip. If you want a workaround, then instead of Riot.im you can use Revolt, which just uses WebKitGTK to display the Riot website instead of Electron. That means you get GLib sockets -> glib-networking -> GnuTLS -> p11-kit which should have access to the host certificates.

  10. AdrianVovk commented on Sep 2, 2019

    @AdrianVovk
    Collaborator

    There seem to be mechanisms to generate CA bundles for openssl & java & everything else in p11-kit: trust extract --format=openssl-bundle --filter=ca-anchors --overwrite /tmp/openssl-bundle.pem

    As a distributor, the fd.o sdk can override /usr/libexec/p11-kit/trust-extact-compat, and then just run trust extract-compat. p11-kit runs this automatically whenever trust anchor is run, but I'm not sure how it handles the daemon/client relationship used by Flatpak.

  11. mcatanzaro commented on Sep 2, 2019

    @mcatanzaro
    Collaborator

    Not sure I understand. How could that help?

  12. AdrianVovk commented on Sep 2, 2019

    @AdrianVovk
    Collaborator

    @mcatanzaro All the SDKs have to do is run trust extract [...] at some point and then OpenSSL will use the system's CA certs, right? Or am I missing something. Just extract it into the correct place for OpenSSL inside of the runtime will pick it up

    Edit: Or Flatpak can extract these on the host side and place them into, i.e. /run/flatpak/openssl-bundle.pem, and then bind-mount this into the runtime env

  13. mcatanzaro commented on Sep 2, 2019

    @mcatanzaro
    Collaborator

    Yes, that would work, but it would conflict with the certificates provided by the runtime itself. The runtime would have to stop shipping its own certificates. I'm not sure whether that would be desirable or not. There would be... implications. :)

    Proper fix is to finish and land openssl/openssl#8200 to bring openssl out of certificate dark ages and into modern times.

  14. AdrianVovk commented on Sep 3, 2019

    @AdrianVovk
    Collaborator

    @mcatanzaro That's fair

  15. dustymabe commented on Oct 27, 2019

    @dustymabe

    I think I hit this today. Trying to use firefox in a flatpak on f31 silverblue and I have system wide certs added to my host (to access websites hosted by my employer). These certs don't make it into the flatpak AFAICT.

  16. 33 remaining items

  17. j1mc commented on Sep 9, 2021

    @j1mc

    It looks like freedesktop-sdk release versions 21.08 and 21.08.1 were tagged within the last week.

    Can anyone verify if the issue is resolved or if it still persists?

  18. nanonyme commented on Dec 18, 2021

    @nanonyme
    Contributor

    Okay, so the thing is, OpenSSL clearly can access host certs as can GnuTLS. But curl appears to use both in a way that results in embedded CA certs being used. I don't understand why.

  19. nanonyme commented on Dec 18, 2021

    @nanonyme
    Contributor

    You can observe this by that currently with org.freedesktop.Platform//21.08

    curl -L https://mesa.freedesktop.org/archive/glu/glu-9.0.2.tar.xz fails

    CURL_SSL_BACKEND=gnutls curl -L https://mesa.freedesktop.org/archive/glu/glu-9.0.2.tar.xz fails

    gnutls-cli --ca-verification mesa.freedesktop.org succeeds

    openssl s_client -connect mesa.freedesktop.org:443 succeeds

    So remaining problem is clearly making curl not do something stupid. Crypto libraries work fine, curl does not.

  20. nanonyme commented on Dec 18, 2021

    @nanonyme
    Contributor

    @mcatanzaro looks like "causes me to worry that libcurl is not designed to do the right thing" was entirely correct.

  21. mcatanzaro commented on Dec 18, 2021

    @mcatanzaro
    Collaborator

    looks like "causes me to worry that libcurl is not designed to do the right thing" was entirely correct.

    To be clear: we must get rid of --with-ca-bundle from curl.bst if we want curl to have any chance at using host certificates (and we almost surely do want that). That does exactly what it says: it forces curl to use certs from the bundle installed in the runtime, rather than the host.

    That said, I see this warning in the buildstream element:

    # Curl must be configured --with-ca-bundle in order to find the
    # correct certificate bundle at runtime, which is later generated
    # by update-ca-certificates. Other applications such as git, rely
    # on curl knowing the default location of the certs.
    

    which indicates that libcurl defaults to using no certs at all? That doesn't sound right. If that's still true, it would be a curl bug IMO: it should default to using the system trust, not no trust at all.

    How this is supposed to work is flatpak drops a configuration fragment under /etc which makes p11kit under flatpak use host trust store. curl is already linked against p11kit. Curl is a bit weird since it builds against both nss and GnuTLS and builds a dependency on p11kit on both directions.
    Looks like for possibly historic reasons curl also links against OpenSSL and has OpenSSL backend which will not result in a working p11kit host cert usage if that ends up being used.

    For avoidance of doubt: curl lets you choose the TLS backend at build time. Normally you would pick just one. Don't expect any consistency between distros here. Debian builds all three and lets applications pick which one they want; only one of them gets used by default, but I don't remember which. Fedora used to use NSS (I think) but nowadays uses OpenSSL. I see freedesktop-sdk uses both NSS and GnuTLS, and I'm not sure why. My suggestion would be to drop the NSS support and see if anything breaks: my guess is probably not. Sorry, after discussing with @nanonyme I see freedesktop-sdk actually builds all three and lets applications pick, just like Debian, but OpenSSL is default.

    FWIW freedesktop-sdk 21.08 is going to carry libp11 to make OpenSSL hopefully play ball with p11kit. First beta is going to be done real soon.

    If you've got OpenSSL hooked up to p11-kit, then that's cool. p11-kit is the primary reason to prefer GnuTLS vs. OpenSSL.

    Of these three, NSS would be the least-preferred backend.

    P.S. It seems I've requested this bug be closed multiple times in prior comments, since its scope is too broad and it's obviously not a flatpak issue. The flatpak issue tracker would be more useful if misplaced issues were closed more aggressively.

  22. nanonyme commented on Dec 18, 2021

    @nanonyme
    Contributor

    Well, it defaults to trying to figure out where platform-specific CA bundle is. I'm currently trying to build curl with --without-ca-bundle to disable its bundle logic completely. Note that currently OpenSSL, GnuTLS and NSS should be using p11kit correctly. So backend shouldn't matter as long as curl doesn't try to tell crypto library to use the runtime CA bundle.

  23. nanonyme commented on Dec 18, 2021

    @nanonyme
    Contributor

    I would also note that currently curl does the wrong thing even with GnuTLS backend.

  24. mcatanzaro commented on Dec 18, 2021

    @mcatanzaro
    Collaborator

    So backend shouldn't matter as long as curl doesn't try to tell crypto library to use the runtime CA bundle.

    I believe so, yes. Certainly that is correct for GnuTLS.

  25. shmu26 commented on Aug 25, 2022

    @shmu26

    Just wanted to mention that I am having this certificate issue with the Zoom flatpak app.
    It is not honoring the certificate store of my system.
    Ubuntu 22.04.

  26. nanonyme commented on Aug 25, 2022

    @nanonyme
    Contributor

    For the record, --with-ca-fallback in combination with -without-ca-bundle was the right solution. Not all apps will ever work correctly if they have eg bundled curl.

  27. shmu26 commented on Aug 25, 2022

    @shmu26

    For the record, --with-ca-fallback in combination with -without-ca-bundle was the right solution. Not all apps will ever work correctly if they have eg bundled curl.

    As a home user without a technical background, is there anything I can do about this, on my side? I don't understand the terms you mentioned.

  28. nanonyme commented on Aug 25, 2022

    @nanonyme
    Contributor

    I mean, fix has been done. Runtime and flatpak work correctly. Remaining bugs are on app side and this should be closed.

  29. smcv commented on Aug 25, 2022

    @smcv
    Collaborator

    As a home user without a technical background, is there anything I can do about this, on my side?

    Not really, other than reporting it as a bug to the apps that are affected if nobody else has already done so.

    (The maintainers of the Flathub package for Zoom probably cannot fix it, because Zoom is proprietary software, but at least having a bug report would record that limitation.)

    It seems I've requested this bug be closed multiple times in prior comments, since its scope is too broad and it's obviously not a flatpak issue

    Closing this as not Flatpak's bug.

    What is now meant to happen is that apps (or the SSL/TLS libraries used by apps) should use p11-kit as their trust store. If they do that, then they will automatically pick up a socket forwarded by Flatpak from the host system, and trust whatever certificates the host trusts. If they do not do that, then that's a bug (or at least a limitation) in that app or the SSL/TLS library that it uses, and not a bug in Flatpak itself.

  30. merlinz01 commented on Mar 25, 2026

    @merlinz01

    For folks landing here trying to figure out how to get a Go or NodeJS program inside Flatpak to trust a custom root certificate, try this workaround:

    • Place the certificate file somewhere under your home folder, e.g. /home/yourusername/.local/share/root-ca.pem.
    • Run flatpak override --user --env=SSL_CERT_FILE=/home/yourusername/.local/share/root-ca.pem <flatpak-app-id>.
    • Run flatpak override --user --env=NODE_EXTRA_CA_CERTS=/home/yourusername/.local/share/root-ca.pem <flatpak-app-id>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions