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

nss: add option to use p11-kit #96763

Merged
merged 2 commits into from Jan 24, 2021
Merged

nss: add option to use p11-kit #96763

merged 2 commits into from Jan 24, 2021

Conversation

rnhmjoj
Copy link
Contributor

@rnhmjoj rnhmjoj commented Aug 31, 2020

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.

@ajs124
Copy link
Member

ajs124 commented Sep 2, 2020

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
Copy link
Contributor Author

rnhmjoj commented Sep 2, 2020

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

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Sep 2, 2020

Done. I removed the (duplicated) part.

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Oct 8, 2020

ping

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Oct 14, 2020

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
Copy link
Member

ajs124 commented Oct 14, 2020

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

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 tfc and andir October 29, 2020 08:08
@@ -126,6 +133,11 @@ in stdenv.mkDerivation rec {
chmod 0755 $out/bin/nss-config
'';

postInstall = stdenv.lib.optionalString useP11kit ''
# Replace built-in trust with p11-kit connection
ln -sf ${p11-kit}/lib/pkcs11/p11-kit-trust.so $out/lib/libnssckbi.so
Copy link
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
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
Copy link
Member

andir commented Nov 19, 2020

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
Copy link
Contributor Author

rnhmjoj commented Nov 19, 2020

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
Copy link
Member

SuperSandro2000 commented Nov 23, 2020

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

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jan 10, 2021

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
Copy link
Contributor Author

rnhmjoj commented Jan 11, 2021

@GrahamcOfBorg eval

@SuperSandro2000
Copy link
Member

Staging is broken right now.

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jan 11, 2021

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

@FRidh
Copy link
Member

FRidh commented Jan 11, 2021

yes another fix in e3961ff

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jan 11, 2021

@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
Copy link
Contributor Author

rnhmjoj commented Jan 13, 2021

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
Copy link
Contributor

tfc commented Jan 18, 2021

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
Copy link
Contributor Author

rnhmjoj commented Jan 24, 2021

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
Copy link
Contributor

flokli commented May 7, 2022

@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants