Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PKCS#11 / p11-kit verifier for Linux #157

Open
zecakeh opened this issue Feb 5, 2025 · 4 comments
Open

Add PKCS#11 / p11-kit verifier for Linux #157

zecakeh opened this issue Feb 5, 2025 · 4 comments

Comments

@zecakeh
Copy link

zecakeh commented Feb 5, 2025

As mentioned in several places, the current problems with Linux are that the certificates are loaded only once and there are no trust decisions available.

Several distributions use p11-kit as a way to list certificates on the system and to list other PKCS#11 modules, and expose them via its API or a PKCS#11 proxy module. By interacting with it, we get an up-to-date list of certificates, and each certificate has a trust decision.

There is support for this in other TLS libraries:

@djc
Copy link
Member

djc commented Feb 5, 2025

What are you trying to achieve exactly? What is the problem motivating your suggestion? Concretely, which (popular) distributions rely on p11-kit by default?

@zecakeh
Copy link
Author

zecakeh commented Feb 5, 2025

My use case is that we have a Linux desktop application that uses reqwest to make HTTP requests. With the current choice of TLS connectors, we cannot access user-provided certs in some environments. Particularly when the application is bundled with Flatpak, the only way to access user-provided certs on the system is to use p11-kit (although it is poorly documented). So for example users have a difficult time using proxies.

The distributions that I know use p11-kit by default (there might be others):

  • Fedora, Red Hat, CentOS
  • Arch Linux and derivatives

@djc
Copy link
Member

djc commented Feb 7, 2025

@complexspaces have you run into issues with this kind of isolation at your employer?

Personally I'm not excited about doing FFI with a bunch of GLib-encumbered C code, but I agree that this might be a half way reasonable thing to do for these environments.

It doesn't inspire confidence that the link to PKCS #11 from the p11-kit homepage is broken (ends up at the rsa.com homepage) -- apparently it now lives at OASIS.

I'd be more interested in ways to have Rust versions of the code dealing with JSON/filesystem interfaces, but I guess that might mean we'd miss out on the C modules people are already using and installing? Do we know what kind of default installed modules one might encounter on Fedora, Red Hat or Arch Linux systems?

@ctz
Copy link
Member

ctz commented Feb 7, 2025

Since PKCS#11 can't do trust decisions1 this would be more along the lines of rustls-native-certs (which hooks up assorted sources of root certs suitable for server authentication) than rustls-platform-verifier (which hooks up the platform's verifier API).

I think if we want to do something with PKCS#11, my strong preference would be to divest that interaction into a subprocess to keep them in their own resource and memory space. Arbitrary PKCS#11 providers are obviously of varying quality, and resource management in a dynamic library is notoriously fraught.

However, p11-kit provides some such programs that we could use as subprocesses, eg this:

$ trust extract --format pem-bundle --filter=ca-anchors --purpose=server-auth certs.pem
$ export SSL_CERT_FILE=certs.pem

Means rustls-native-certs will pick up those certs.

Footnotes

  1. in other words, it cannot tell you if a certificate chain is valid for a particular purpose/name, only which certificates exist and what their properties are, and also let you verify signatures with them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants