1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # The Debian ca-certificates package merely takes the CA database as it exists
6 # in the nss package and repackages it for use by openssl.
8 # The issue with using the compiled debs directly is two fold:
9 # - they do not update frequently enough for us to rely on them
10 # - they pull the CA database from nss tip of tree rather than the release
12 # So we take the Debian source tools and combine them with the latest nss
13 # release to produce (largely) the same end result. The difference is that
14 # now we know our cert database is kept in sync with nss and, if need be,
15 # can be sync with nss tip of tree more frequently to respond to bugs.
17 # When triaging bugs from users, here's some handy tips:
18 # - To see what cert is hitting errors, use openssl:
19 # openssl s_client -port 443 -CApath /etc/ssl/certs/ -host $HOSTNAME
20 # Focus on the errors written to stderr.
22 # - Look at the upstream log as to why certs were added/removed:
23 # https://hg.mozilla.org/projects/nss/log/tip/lib/ckfw/builtins/certdata.txt
25 # - If people want to add/remove certs, tell them to file w/mozilla:
26 # https://bugzilla.mozilla.org/enter_bug.cgi?product=NSS&component=CA%20Certificates&version=trunk
29 PYTHON_COMPAT=( python{2_7,3_4,3_5} )
31 inherit eutils python-any-r1
33 if [[ ${PV} == *.* ]] ; then
34 # Compile from source ourselves.
38 DEB_VER=$(get_version_component_range 1)
39 NSS_VER=$(get_version_component_range 2-)
40 RTM_NAME="NSS_${NSS_VER//./_}_RTM"
42 # Debian precompiled version.
47 DESCRIPTION="Common CA Certificates PEM files"
48 HOMEPAGE="http://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
55 cacert? ( https://dev.gentoo.org/~anarchy/patches/nss-3.14.1-add_spi+cacerts_ca_certs.patch )"
60 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~x64-freebsd ~x86-freebsd ~hppa-hpux ~ia64-hpux ~x86-interix ~amd64-linux ~arm-linux ~ia64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris ~x86-winnt"
62 ${PRECOMPILED} || IUSE+=" +cacert"
65 if ${PRECOMPILED} ; then
66 DEPEND+=" !<sys-apps/portage-2.1.10.41"
68 # c_rehash: we run `c_rehash`
69 # debianutils: we run `run-parts`
74 if ! ${PRECOMPILED}; then
75 DEPEND+=" ${PYTHON_DEPS}"
81 # For the conversion to having it in CONFIG_PROTECT_MASK,
82 # we need to tell users about it once manually first.
83 [[ -f "${EPREFIX}"/etc/env.d/98ca-certificates ]] \
84 || ewarn "You should run update-ca-certificates manually after etc-update"
88 ${PRECOMPILED} || default
90 # Do all the work in the image subdir to avoid conflicting with source
91 # dirs in $WORKDIR. Need to perform everything in the offset #381937
92 mkdir -p "image/${EPREFIX}"
93 cd "image/${EPREFIX}" || die
95 ${PRECOMPILED} && unpacker_src_unpack
99 cd "image/${EPREFIX}" || die
100 if ! ${PRECOMPILED} ; then
102 cp -p "${S}"/${PN}/sbin/update-ca-certificates usr/sbin/ || die
105 pushd "${S}"/nss-${NSS_VER} >/dev/null
106 epatch "${DISTDIR}"/nss-3.14.1-add_spi+cacerts_ca_certs.patch
111 epatch "${FILESDIR}"/${PN}-20150426-root.patch
112 local relp=$(echo "${EPREFIX}" | sed -e 's:[^/]\+:..:g')
114 -e '/="$ROOT/s:ROOT:ROOT'"${EPREFIX}"':' \
115 -e '/RELPATH="\.\./s:"$:'"${relp}"'":' \
116 usr/sbin/update-ca-certificates || die
120 cd "image/${EPREFIX}" || die
121 if ! ${PRECOMPILED} ; then
123 local d="${S}/${PN}/mozilla"
124 # Grab the database from the nss sources.
125 cp "${S}"/nss-${NSS_VER}/nss/lib/ckfw/builtins/{certdata.txt,nssckbi.h} "${d}" || die
128 # Now move the files to the same places that the precompiled would.
129 mkdir -p etc/ssl/certs etc/ca-certificates/update.d usr/share/ca-certificates/mozilla
131 mkdir -p usr/share/ca-certificates/{cacert.org,spi-inc.org}
132 mv "${d}"/CAcert_Inc..crt usr/share/ca-certificates/cacert.org/cacert.org_root.crt || die
133 mv "${d}"/SPI_Inc..crt usr/share/ca-certificates/spi-inc.org/spi-cacert-2008.crt || die
135 mv "${d}"/*.crt usr/share/ca-certificates/mozilla/ || die
137 mv usr/share/doc/{ca-certificates,${PF}} || die
141 echo "# Automatically generated by ${CATEGORY}/${PF}"
143 echo "# Do not edit."
144 cd usr/share/ca-certificates
145 find * -name '*.crt' | LC_ALL=C sort
146 ) > etc/ca-certificates.conf
148 sh usr/sbin/update-ca-certificates --root "${S}/image" || die
152 cp -pPR image/* "${D}"/ || die
153 if ! ${PRECOMPILED} ; then
156 dodoc debian/README.* examples/ca-certificates-local/README
159 echo 'CONFIG_PROTECT_MASK="/etc/ca-certificates.conf"' > 98ca-certificates
160 doenvd 98ca-certificates
164 if [ -d "${EROOT}/usr/local/share/ca-certificates" ] ; then
165 # if the user has local certs, we need to rebuild again
166 # to include their stuff in the db.
167 # However it's too overzealous when the user has custom certs in place.
168 # --fresh is to clean up dangling symlinks
169 "${EROOT}"/usr/sbin/update-ca-certificates --root "${ROOT}"
172 if [ -n "$(find -L "${EROOT}"etc/ssl/certs/ -type l)" ] ; then
173 ewarn "Removing the following broken symlinks:"
174 ewarn "$(find -L "${EROOT}"/etc/ssl/certs/ -type l -printf '%p -> %l\n' -delete)"