2021-01-15 07:29:18 +00:00
|
|
|
{ lib, stdenv, fetchurl, nss, python3
|
2016-09-01 21:40:05 +00:00
|
|
|
, blacklist ? []
|
2020-12-01 09:49:47 +00:00
|
|
|
|
|
|
|
# Used for tests only
|
|
|
|
, runCommand
|
|
|
|
, cacert
|
|
|
|
, openssl
|
2016-09-01 21:40:05 +00:00
|
|
|
}:
|
|
|
|
|
2021-01-15 07:29:18 +00:00
|
|
|
with lib;
|
2016-09-01 21:40:05 +00:00
|
|
|
|
|
|
|
let
|
2020-12-11 16:26:00 +00:00
|
|
|
version = "3.60";
|
2020-11-18 14:51:51 +00:00
|
|
|
underscoreVersion = builtins.replaceStrings ["."] ["_"] version;
|
2016-09-01 21:40:05 +00:00
|
|
|
in
|
2010-01-20 14:10:26 +00:00
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
stdenv.mkDerivation {
|
2020-11-18 14:51:51 +00:00
|
|
|
name = "nss-cacert-${version}";
|
2010-01-20 14:10:26 +00:00
|
|
|
|
2020-11-18 14:51:51 +00:00
|
|
|
src = fetchurl {
|
|
|
|
url = "mirror://mozilla/security/nss/releases/NSS_${underscoreVersion}_RTM/src/nss-${version}.tar.gz";
|
2020-12-11 16:26:00 +00:00
|
|
|
sha256 = "hKvVV1q4dMU65RG9Rh5dCGjRobOE7kB1MVTN0dWQ/j0=";
|
2020-11-18 14:51:51 +00:00
|
|
|
};
|
2015-05-29 20:51:55 +00:00
|
|
|
|
2021-03-18 20:44:09 +00:00
|
|
|
certdata2pem = fetchurl {
|
|
|
|
name = "certdata2pem.py";
|
2021-03-18 20:57:21 +00:00
|
|
|
url = [
|
|
|
|
"https://salsa.debian.org/debian/ca-certificates/raw/debian/20170717/mozilla/certdata2pem.py"
|
|
|
|
"https://git.launchpad.net/ubuntu/+source/ca-certificates/plain/mozilla/certdata2pem.py?id=47e49e1e0a8a1ca74deda27f88fe181191562957"
|
|
|
|
];
|
2021-03-18 20:44:09 +00:00
|
|
|
sha256 = "1d4q27j1gss0186a5m8bs5dk786w07ccyq0qi6xmd2zr1a8q16wy";
|
|
|
|
};
|
|
|
|
|
2018-02-25 22:23:59 +00:00
|
|
|
outputs = [ "out" "unbundled" ];
|
|
|
|
|
2019-12-14 16:15:33 +00:00
|
|
|
nativeBuildInputs = [ python3 ];
|
2016-05-11 20:50:49 +00:00
|
|
|
|
2016-09-01 21:40:05 +00:00
|
|
|
configurePhase = ''
|
|
|
|
ln -s nss/lib/ckfw/builtins/certdata.txt
|
|
|
|
|
|
|
|
cat << EOF > blacklist.txt
|
|
|
|
${concatStringsSep "\n" (map (c: ''"${c}"'') blacklist)}
|
|
|
|
EOF
|
2015-05-29 20:51:55 +00:00
|
|
|
|
2021-03-18 20:44:09 +00:00
|
|
|
# copy from the store, otherwise python will scan it for imports
|
|
|
|
cat "$certdata2pem" > certdata2pem.py
|
2016-09-01 21:40:05 +00:00
|
|
|
'';
|
2010-01-20 14:10:26 +00:00
|
|
|
|
2015-05-29 20:51:55 +00:00
|
|
|
buildPhase = ''
|
2016-09-01 21:40:05 +00:00
|
|
|
python certdata2pem.py | grep -vE '^(!|UNTRUSTED)'
|
|
|
|
|
|
|
|
for cert in *.crt; do
|
|
|
|
echo $cert | cut -d. -f1 | sed -e 's,_, ,g' >> ca-bundle.crt
|
|
|
|
cat $cert >> ca-bundle.crt
|
|
|
|
echo >> ca-bundle.crt
|
|
|
|
done
|
2015-05-29 20:51:55 +00:00
|
|
|
'';
|
2010-01-20 14:10:26 +00:00
|
|
|
|
2015-05-29 20:51:55 +00:00
|
|
|
installPhase = ''
|
2015-06-05 20:00:52 +00:00
|
|
|
mkdir -pv $out/etc/ssl/certs
|
|
|
|
cp -v ca-bundle.crt $out/etc/ssl/certs
|
2018-02-25 22:23:59 +00:00
|
|
|
# install individual certs in unbundled output
|
|
|
|
mkdir -pv $unbundled/etc/ssl/certs
|
|
|
|
cp -v *.crt $unbundled/etc/ssl/certs
|
|
|
|
rm -f $unbundled/etc/ssl/certs/ca-bundle.crt # not wanted in unbundled
|
2015-05-29 20:51:55 +00:00
|
|
|
'';
|
2010-01-20 14:10:26 +00:00
|
|
|
|
2017-12-23 14:13:29 +00:00
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
2020-11-18 14:51:51 +00:00
|
|
|
passthru.updateScript = ./update.sh;
|
2020-12-01 09:49:47 +00:00
|
|
|
passthru.tests = {
|
|
|
|
# Test that building this derivation with a blacklist works, and that UTF-8 is supported.
|
|
|
|
blacklist-utf8 = let
|
|
|
|
blacklistCAToFingerprint = {
|
|
|
|
# "blacklist" uses the CA name from the NSS bundle, but we check for presence using the SHA256 fingerprint.
|
|
|
|
"CFCA EV ROOT" = "5C:C3:D7:8E:4E:1D:5E:45:54:7A:04:E6:87:3E:64:F9:0C:F9:53:6D:1C:CC:2E:F8:00:F3:55:C4:C5:FD:70:FD";
|
|
|
|
"NetLock Arany (Class Gold) Főtanúsítvány" = "6C:61:DA:C3:A2:DE:F0:31:50:6B:E0:36:D2:A6:FE:40:19:94:FB:D1:3D:F9:C8:D4:66:59:92:74:C4:46:EC:98";
|
|
|
|
};
|
|
|
|
mapBlacklist = f: concatStringsSep "\n" (mapAttrsToList f blacklistCAToFingerprint);
|
|
|
|
in runCommand "verify-the-cacert-filter-output" {
|
|
|
|
cacert = cacert.unbundled;
|
|
|
|
cacertWithExcludes = (cacert.override {
|
|
|
|
blacklist = builtins.attrNames blacklistCAToFingerprint;
|
|
|
|
}).unbundled;
|
|
|
|
|
|
|
|
nativeBuildInputs = [ openssl ];
|
|
|
|
} ''
|
|
|
|
isPresent() {
|
|
|
|
# isPresent <unbundled-dir> <ca name> <ca sha256 fingerprint>
|
|
|
|
for f in $1/etc/ssl/certs/*.crt; do
|
|
|
|
fingerprint="$(openssl x509 -in "$f" -noout -fingerprint -sha256 | cut -f2 -d=)"
|
|
|
|
if [[ "x$fingerprint" == "x$3" ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ensure that each certificate is in the main "cacert".
|
|
|
|
${mapBlacklist (caName: caFingerprint: ''
|
|
|
|
isPresent "$cacert" "${caName}" "${caFingerprint}" || ({
|
|
|
|
echo "CA fingerprint ${caFingerprint} (${caName}) is missing from the CA bundle. Consider picking a different CA for the blacklist test." >&2
|
|
|
|
exit 1
|
|
|
|
})
|
|
|
|
'')}
|
|
|
|
|
|
|
|
# Ensure that each certificate is NOT in the "cacertWithExcludes".
|
|
|
|
${mapBlacklist (caName: caFingerprint: ''
|
|
|
|
isPresent "$cacertWithExcludes" "${caName}" "${caFingerprint}" && ({
|
|
|
|
echo "CA fingerprint ${caFingerprint} (${caName}) is present in the cacertWithExcludes bundle." >&2
|
|
|
|
exit 1
|
|
|
|
})
|
|
|
|
'')}
|
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
};
|
2020-11-18 14:51:51 +00:00
|
|
|
|
2016-09-01 21:40:05 +00:00
|
|
|
meta = {
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "https://curl.haxx.se/docs/caextract.html";
|
2010-01-20 14:10:26 +00:00
|
|
|
description = "A bundle of X.509 certificates of public Certificate Authorities (CA)";
|
2015-05-29 20:51:55 +00:00
|
|
|
platforms = platforms.all;
|
2020-12-01 17:55:59 +00:00
|
|
|
maintainers = with maintainers; [ andir fpletz lukegb ];
|
2020-06-26 22:53:42 +00:00
|
|
|
license = licenses.mpl20;
|
2010-01-20 14:10:26 +00:00
|
|
|
};
|
|
|
|
}
|