1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # The Debian ca-certificates package merely takes the CA database as it exists
5 # in the nss package and repackages it for use by openssl.
7 # The issue with using the compiled debs directly is two fold:
8 # - they do not update frequently enough for us to rely on them
9 # - they pull the CA database from nss tip of tree rather than the release
11 # So we take the Debian source tools and combine them with the latest nss
12 # release to produce (largely) the same end result. The difference is that
13 # now we know our cert database is kept in sync with nss and, if need be,
14 # can be sync with nss tip of tree more frequently to respond to bugs.
16 # When triaging bugs from users, here's some handy tips:
17 # - To see what cert is hitting errors, use openssl:
18 # openssl s_client -port 443 -CApath /etc/ssl/certs/ -host $HOSTNAME
19 # Focus on the errors written to stderr.
21 # - Look at the upstream log as to why certs were added/removed:
22 # https://hg.mozilla.org/projects/nss/log/tip/lib/ckfw/builtins/certdata.txt
24 # - If people want to add/remove certs, tell them to file w/mozilla:
25 # https://bugzilla.mozilla.org/enter_bug.cgi?product=NSS&component=CA%20Certificates&version=trunk
29 PYTHON_COMPAT=( python3_{6,7,8} )
31 inherit eutils python-any-r1
33 if [[ ${PV} == *.* ]] ; then
34 # Compile from source ourselves.
40 RTM_NAME="NSS_${NSS_VER//./_}_RTM"
42 # Debian precompiled version.
47 DESCRIPTION="Common CA Certificates PEM files"
48 HOMEPAGE="https://packages.debian.org/sid/ca-certificates"
50 if ${PRECOMPILED} ; then
51 SRC_URI="mirror://debian/pool/main/c/${PN}/${PN}_${PV}${NMU_PR:++nmu}${NMU_PR}_all.deb"
53 SRC_URI="mirror://debian/pool/main/c/${PN}/${PN}_${DEB_VER}${NMU_PR:++nmu}${NMU_PR}.tar.xz
54 https://archive.mozilla.org/pub/security/nss/releases/${RTM_NAME}/src/nss-${NSS_VER}.tar.gz
56 https://dev.gentoo.org/~axs/distfiles/nss-cacert-class1-class3.patch
62 KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 m68k ~mips ppc ppc64 ~riscv s390 sparc x86 ~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris ~x86-winnt"
64 ${PRECOMPILED} || IUSE+=" cacert"
67 if ${PRECOMPILED} ; then
68 DEPEND+=" !<sys-apps/portage-2.1.10.41"
70 # c_rehash: we run `c_rehash`
71 # debianutils: we run `run-parts`
76 if ! ${PRECOMPILED}; then
77 DEPEND+=" ${PYTHON_DEPS}"
83 # For the conversion to having it in CONFIG_PROTECT_MASK,
84 # we need to tell users about it once manually first.
85 [[ -f "${EPREFIX}"/etc/env.d/98ca-certificates ]] \
86 || ewarn "You should run update-ca-certificates manually after etc-update"
90 ${PRECOMPILED} || default
92 # Do all the work in the image subdir to avoid conflicting with source
93 # dirs in ${WORKDIR}. Need to perform everything in the offset #381937
94 mkdir -p "image/${EPREFIX}" || die
95 cd "image/${EPREFIX}" || die
97 ${PRECOMPILED} && unpacker_src_unpack
101 cd "image/${EPREFIX}" || die
102 if ! ${PRECOMPILED} ; then
103 mkdir -p usr/sbin || die
104 cp -p "${S}"/${PN}-${DEB_VER}/sbin/update-ca-certificates \
108 pushd "${S}"/nss-${NSS_VER} >/dev/null || die
109 eapply -p0 "${DISTDIR}"/nss-cacert-class1-class3.patch
110 popd >/dev/null || die
115 eapply -p2 "${FILESDIR}"/${PN}-20150426-root.patch
116 local relp=$(echo "${EPREFIX}" | sed -e 's:[^/]\+:..:g')
118 -e '/="$ROOT/s:ROOT:ROOT'"${EPREFIX}"':' \
119 -e '/RELPATH="\.\./s:"$:'"${relp}"'":' \
120 -e 's/openssl rehash/c_rehash/' \
121 usr/sbin/update-ca-certificates || die
125 cd "image/${EPREFIX}" || die
126 if ! ${PRECOMPILED} ; then
128 local d="${S}/${PN}-${DEB_VER}/mozilla" c="usr/share/${PN}"
129 # Grab the database from the nss sources.
130 cp "${S}"/nss-${NSS_VER}/nss/lib/ckfw/builtins/{certdata.txt,nssckbi.h} "${d}" || die
133 # Now move the files to the same places that the precompiled would.
134 mkdir -p etc/ssl/certs \
135 etc/ca-certificates/update.d \
139 mkdir -p "${c}"/cacert.org || die
140 mv "${d}"/CAcert_Inc..crt \
141 "${c}"/cacert.org/cacert.org_root.crt || die
143 mv "${d}"/*.crt "${c}"/mozilla/ || die
145 mv usr/share/doc/{ca-certificates,${PF}} || die
149 echo "# Automatically generated by ${CATEGORY}/${PF}"
151 echo "# Do not edit."
153 find * -name '*.crt' | LC_ALL=C sort
154 ) > etc/ca-certificates.conf
156 sh usr/sbin/update-ca-certificates --root "${S}/image" || die
160 cp -pPR image/* "${D}"/ || die
161 if ! ${PRECOMPILED} ; then
162 cd ${PN}-${DEB_VER} || die
164 dodoc debian/README.* examples/ca-certificates-local/README
167 echo 'CONFIG_PROTECT_MASK="/etc/ca-certificates.conf"' > 98ca-certificates
168 doenvd 98ca-certificates
172 if [[ -d "${EROOT%/}/usr/local/share/ca-certificates" ]] ; then
173 # if the user has local certs, we need to rebuild again
174 # to include their stuff in the db.
175 # However it's too overzealous when the user has custom certs in place.
176 # --fresh is to clean up dangling symlinks
177 "${EROOT%/}"/usr/sbin/update-ca-certificates --root "${ROOT}"
180 if [[ -n "$(find -L "${EROOT%/}"/etc/ssl/certs/ -type l)" ]] ; then
181 ewarn "Removing the following broken symlinks:"
182 ewarn "$(find -L "${EROOT%/}"/etc/ssl/certs/ -type l -printf '%p -> %l\n' -delete)"