git.iko.soy/typeable/nixpkgs
on master help sign in
cacerts: refactor, add blacklist option

Previously, the list of CA certificates was generated with a perl script which is included in curl. As this script is not very flexible, this commit refactors the expression to use the python script that Debian uses to generate their CA certificates from Mozilla's trust store in NSS. Additionally, an option was added to the cacerts derivation and the `security.pki` module to blacklist specific CAs.

commit0d59fc1169654fa1f77e17ad73099895af7bba4d authorFranz Pletz <fpletz@fnordicwalking.de> dateThu 1 Sep 2016, 23:40 (10 years ago) parentcefe4a8
2 files changed+63−17
nixos/modules/security/ca.nix+25−3 pkgs/data/misc/cacert/default.nix+38−14
nixos/modules/security/ca.nix+25−3
@@ -4,10 +4,16 @@ with lib;
44
55let
66
7+ cfg = config.security.pki;
8+
9+ cacertPackage = pkgs.cacert.override {
10+ blacklist = cfg.caCertificateBlacklist;
11+ };
12+
713 caCertificates = pkgs.runCommand "ca-certificates.crt"
814 { files =
9− config.security.pki.certificateFiles ++
10− [ (builtins.toFile "extra.crt" (concatStringsSep "\n" config.security.pki.certificates)) ];
15+ cfg.certificateFiles ++
16+ [ (builtins.toFile "extra.crt" (concatStringsSep "\n" cfg.certificates)) ];
1117 }
1218 ''
1319 cat $files > $out
@@ -52,11 +58,27 @@ in
5258 '';
5359 };
5460
61+ security.pki.caCertificateBlacklist = mkOption {
62+ type = types.listOf types.str;
63+ default = [];
64+ example = [
65+ "WoSign" "WoSign China"
66+ "CA WoSign ECC Root"
67+ "Certification Authority of WoSign G2"
68+ ];
69+ description = ''
70+ A list of blacklisted CA certificate names that won't be imported from
71+ the Mozilla Trust Store into
72+ <filename>/etc/ssl/certs/ca-certificates.crt</filename>. Use the
73+ names from that file.
74+ '';
75+ };
76+
5577 };
5678
5779 config = {
5880
59− security.pki.certificateFiles = [ "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ];
81+ security.pki.certificateFiles = [ "${cacertPackage}/etc/ssl/certs/ca-bundle.crt" ];
6082
6183 # NixOS canonical location + Debian/Ubuntu/Arch/Gentoo compatibility.
6284 environment.etc."ssl/certs/ca-certificates.crt".source = caCertificates;
pkgs/data/misc/cacert/default.nix+38−14
@@ -1,25 +1,49 @@
1−{ stdenv, nss, curl, perl }:
1+{ stdenv, fetchurl, writeText, nss, python
2+, blacklist ? []
3+, includeEmail ? false
4+}:
5+
6+with stdenv.lib;
7+
8+let
9+
10+ certdata2pem = fetchurl {
11+ name = "certdata2pem.py";
12+ url = "https://anonscm.debian.org/cgit/collab-maint/ca-certificates.git/plain/mozilla/certdata2pem.py?h=debian/20160104";
13+ sha256 = "0bw11mgfrf19qziyvdnq22kirp0nn54lfsanrg5h6djs6ig1c2im";
14+ };
15+
16+in
217
318stdenv.mkDerivation rec {
419 name = "nss-cacert-${nss.version}";
520
621 src = nss.src;
722
8− postPatch = ''
9− unpackFile ${curl.src};
23+ nativeBuildInputs = [ python ];
1024
11− # Remove dependency on LWP, curl is enough. Also, since curl here
12− # is working on a local file it will not actually get a 200 OK, so
13− # remove that expectation.
14− substituteInPlace curl-*/lib/mk-ca-bundle.pl \
15− --replace 'use LWP::UserAgent;' "" \
16− --replace ' && $out[0] == 200' ""
17− '';
25+ configurePhase = ''
26+ ln -s nss/lib/ckfw/builtins/certdata.txt
27+
28+ cat << EOF > blacklist.txt
29+ ${concatStringsSep "\n" (map (c: ''"${c}"'') blacklist)}
30+ EOF
1831
19− nativeBuildInputs = [ curl perl ];
32+ cp ${certdata2pem} certdata2pem.py
33+ ${optionalString includeEmail ''
34+ # Disable CAs used for mail signing
35+ substituteInPlace certdata2pem.py --replace \[\'CKA_TRUST_EMAIL_PROTECTION\'\] '''
36+ ''}
37+ '';
2038
2139 buildPhase = ''
22− perl curl-*/lib/mk-ca-bundle.pl -d "file://$(pwd)/nss/lib/ckfw/builtins/certdata.txt" ca-bundle.crt
40+ python certdata2pem.py | grep -vE '^(!|UNTRUSTED)'
41+
42+ for cert in *.crt; do
43+ echo $cert | cut -d. -f1 | sed -e 's,_, ,g' >> ca-bundle.crt
44+ cat $cert >> ca-bundle.crt
45+ echo >> ca-bundle.crt
46+ done
2347 '';
2448
2549 installPhase = ''
@@ -27,10 +51,10 @@ stdenv.mkDerivation rec {
2751 cp -v ca-bundle.crt $out/etc/ssl/certs
2852 '';
2953
30− meta = with stdenv.lib; {
54+ meta = {
3155 homepage = http://curl.haxx.se/docs/caextract.html;
3256 description = "A bundle of X.509 certificates of public Certificate Authorities (CA)";
3357 platforms = platforms.all;
34− maintainers = with maintainers; [ wkennington ];
58+ maintainers = with maintainers; [ wkennington fpletz ];
3559 };
3660}