Skip to content

nss: add option to use p11-kit - #96763

Merged
rnhmjoj merged 2 commits into
NixOS:stagingfrom
rnhmjoj:p11kit
Jan 24, 2021
Merged

rnhmjoj merged 2 commits into
NixOS:stagingfrom
rnhmjoj:p11kit

Conversation

@rnhmjoj

@rnhmjoj rnhmjoj commented Aug 31, 2020 •

Copy link
Copy Markdown
Contributor
Motivation for this change

The original motivation is #8247

After multiple attempts it seems I have finally understood how to use p11-kit-trust.
So far I've only built nss and tested the system trust store is used by qtwebengine.
Firefox and other Mozilla programs should be tested as well.

This commit adds an option to replace libnssckbi with the p11-kit-trust1 module. It makes all NSS application (like Firefox, Chromium, etc.) use the system trust store (/etc/ssl/certs/ in NixOS) and other PKCS#11 modules without ad-hoc configuration. Enabling the option will additionally generate a p11-kit compatible
module of the Mozilla CA bundle.

This approach was first implemented in Fedora2 and other distributions like Arch Linux, later. The certdata2pem.py script is in fact taken, and some of the build code adapted, from the ca-certificates Fedora package3.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS
    • firefox
    • chromium
  • Tested compilation of all pkgs that depend on this change (mass rebuild!)
  • Tested execution of all binary files (none)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@rnhmjoj
rnhmjoj requested a review from vcunat August 31, 2020 12:51
@ofborg ofborg Bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. labels Aug 31, 2020
@ajs124

ajs124 commented Sep 2, 2020

Copy link
Copy Markdown
Member

I might be mixing things up, but certdata2pem is already how nixpkgs/nixos is getting its ca certs. From nss. So why extract them here again?

@rnhmjoj

rnhmjoj commented Sep 2, 2020

Copy link
Copy Markdown
Contributor Author

Because I didn't know that: I thought cacert was a different CA bundle. I'll remove that part, thank you.

@rnhmjoj

rnhmjoj commented Sep 2, 2020

Copy link
Copy Markdown
Contributor Author

Done. I removed the (duplicated) part.

@rnhmjoj

rnhmjoj commented Oct 8, 2020

Copy link
Copy Markdown
Contributor Author

ping

@rnhmjoj

rnhmjoj commented Oct 14, 2020

Copy link
Copy Markdown
Contributor Author

So, do you have any objection?

I'd like for nss to use the system trust store in /etc/ssl/certs. That way is possibile to take control of the validation in chromium, firefox and basically all other browsers by setting security.pki in NixOS. I can't think of any unwanted side effects of this change.

@ajs124

ajs124 commented Oct 14, 2020

Copy link
Copy Markdown
Member

No objections, but I also don't feel comfortable approving/merging this, because I don't feel like I know enough about nss and/or p11-kit.

@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-in-distress/3604/35

@rnhmjoj
rnhmjoj requested review from andir and tfc October 29, 2020 08:08

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, how do we gurantee that the ABI between this "fake" output and the one defined in the header files matches? Is that defined in the PKCS#11 standard?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good question: the library is designed to be used like this, so I assume it's ABI compatible with nss, but I'm not sure.

Even if it is, this could be an issue if nss introduces an ABI incompatible change and Nixpkgs is updated before p11-kit. It should be noted p11-kit is maintained and used by red hat, so it should be update quickly enough.

@andir

andir commented Nov 19, 2020

Copy link
Copy Markdown
Member

This commit adds an option to replace libnssckbi with the p11-kit-trust1 module. It makes all NSS application (like Firefox, Chromium, etc.) use the system trust store (/etc/ssl/certs/ in NixOS) and other PKCS#11 modules without ad-hoc configuration. Enabling the option will additionally generate a p11-kit compatible
module of the Mozilla CA bundle.

What was the situation before that? Did all the applications linking to NSS use the bundled trust store that came with NSS? I still wonder if there wouldn't be a better way to deal with this but I fear NSS doesn't really care much about system wide certs.

@rnhmjoj

rnhmjoj commented Nov 19, 2020

Copy link
Copy Markdown
Contributor Author

Did all the applications linking to NSS use the bundled trust store that came with NSS?

I think so, certainly they aren't using the system wide store.

I still wonder if there wouldn't be a better way to deal with this but I fear NSS doesn't really care much about system wide certs.

Probably not, red hat/fedora was in the same situation and p11-kit is what they came up with.

@SuperSandro2000

SuperSandro2000 commented Nov 23, 2020 •

Copy link
Copy Markdown
Member

Can you please target staging with the mass rebuild and fix the merge conflict?

@ofborg ofborg Bot removed 6.topic: stdenv Standard environment 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` labels Dec 28, 2020
@rnhmjoj

rnhmjoj commented Jan 10, 2021 •

Copy link
Copy Markdown
Contributor Author

I added a test to check that the security.pki options are working in every major browser engine.
Programs based on openssl and gnutls should already be working, nss-based browsers needs this PR.

Building this on staging would probably take days, but you can avoid the rebuilds by running it from master and using replaceRuntimeDependencies as follows:

{ system.replaceRuntimeDependencies =
    let 
      nss-p11kit = pkgs.nss.overrideDerivation (old: {
        postInstall = ''
          # Replace built-in trust with p11-kit connection
          ln -sf ${pkgs.p11-kit}/lib/pkcs11/p11-kit-trust.so $out/lib/libnssckbi.so
        '';
      });
    in [{ original = pkgs.nss; replacement = nss-p11kit; }];
}

@rnhmjoj
rnhmjoj force-pushed the p11kit branch 3 times, most recently from 81c0389 to bef086f Compare January 11, 2021 11:13
@rnhmjoj

rnhmjoj commented Jan 11, 2021

Copy link
Copy Markdown
Contributor Author

@GrahamcOfBorg eval

@SuperSandro2000

Copy link
Copy Markdown
Member

Staging is broken right now.

@rnhmjoj

rnhmjoj commented Jan 11, 2021

Copy link
Copy Markdown
Contributor Author

I saw FRidh pushed a commit to fix the eval but it's still broken (differently).

@FRidh

FRidh commented Jan 11, 2021

Copy link
Copy Markdown
Member

yes another fix in e3961ff

@ofborg ofborg Bot added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Jan 11, 2021
@rnhmjoj

rnhmjoj commented Jan 11, 2021

Copy link
Copy Markdown
Contributor Author

@GrahamcOfBorg test custom-ca

@rnhmjoj
rnhmjoj force-pushed the p11kit branch 2 times, most recently from 9b2866b to 2a1c8c3 Compare January 13, 2021 08:50
@rnhmjoj

rnhmjoj commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

Thanks to the test, I'm now pretty confident this PR won't wreak havoc on Nixpkgs.
If you have no more changes to suggest I'd go on and try to merge it.

@tfc

tfc commented Jan 18, 2021

Copy link
Copy Markdown
Contributor

Wow, the integration test is awesome. Thanks for that!

This commit adds an option to replace libnssckbi with the
p11-kit-trust[1] module. It makes all NSS application (like Firefox,
Chromium, etc.) use the system trust store (/etc/ssl/certs/ in NixOS)
and other PKCS#11 modules without ad-hoc configuration.

This approach was first implemented in Fedora[2] and other distributions
like Arch Linux, later.
[1]: https://p11-glue.github.io/p11-glue/p11-kit/manual/trust-nss.html

[2]: https://fedoraproject.org/wiki/Features/SharedSystemCertificates
This is a NixOS test for the security.pki options.
@rnhmjoj

rnhmjoj commented Jan 24, 2021

Copy link
Copy Markdown
Contributor Author

Wow, the integration test is awesome. Thanks for that!

Thank you!

I have fixed the conflict (stdenv.lib -> lib change) and rebased. I tested again nixosTests.firefox, nixosTests.chromium and nixosTests.custom-ca and everything still looks ok. I'll try merge it now.

@flokli

flokli commented May 7, 2022

Copy link
Copy Markdown
Member

@rnhmjoj the commit message says:

This commit adds an option to replace libnssckbi with the
p11-kit-trust[1] module. It makes all NSS application (like Firefox,
Chromium, etc.) use the system trust store (/etc/ssl/certs/ in NixOS)
and other PKCS#11 modules without ad-hoc configuration.

It however seems p11-kit doesn't properly discover PKCS#11 modules on NixOS. I opened #171978.

@rnhmjoj
rnhmjoj deleted the p11kit branch July 10, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants