79af3785f2993d8a8b372e0dcf0c4e40b4221789
[gentoo.git] / app-misc / ca-certificates / ca-certificates-20190110.3.43.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
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.
6 #
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
10 #
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.
15
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.
20 #
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
23 #
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
26
27 EAPI=6
28
29 PYTHON_COMPAT=( python3_{6,7,8} )
30
31 inherit eutils python-any-r1
32
33 if [[ ${PV} == *.* ]] ; then
34         # Compile from source ourselves.
35         PRECOMPILED=false
36         inherit eapi7-ver
37
38         DEB_VER=$(ver_cut 1)
39         NSS_VER=$(ver_cut 2-)
40         RTM_NAME="NSS_${NSS_VER//./_}_RTM"
41 else
42         # Debian precompiled version.
43         PRECOMPILED=true
44         inherit unpacker
45 fi
46
47 DESCRIPTION="Common CA Certificates PEM files"
48 HOMEPAGE="https://packages.debian.org/sid/ca-certificates"
49 NMU_PR=""
50 if ${PRECOMPILED} ; then
51         SRC_URI="mirror://debian/pool/main/c/${PN}/${PN}_${PV}${NMU_PR:++nmu}${NMU_PR}_all.deb"
52 else
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? (
56                         https://dev.gentoo.org/~axs/distfiles/nss-cacert-class1-class3.patch
57                 )"
58 fi
59
60 LICENSE="MPL-1.1"
61 SLOT="0"
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"
63 IUSE=""
64 ${PRECOMPILED} || IUSE+=" cacert"
65
66 DEPEND=""
67 if ${PRECOMPILED} ; then
68         DEPEND+=" !<sys-apps/portage-2.1.10.41"
69 fi
70 # c_rehash: we run `c_rehash`
71 # debianutils: we run `run-parts`
72 RDEPEND="${DEPEND}
73         app-misc/c_rehash
74         sys-apps/debianutils"
75
76 if ! ${PRECOMPILED}; then
77         DEPEND+=" ${PYTHON_DEPS}"
78 fi
79
80 S=${WORKDIR}
81
82 pkg_setup() {
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"
87 }
88
89 src_unpack() {
90         ${PRECOMPILED} || default
91
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
96
97         ${PRECOMPILED} && unpacker_src_unpack
98 }
99
100 src_prepare() {
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 \
105                         usr/sbin/ || die
106
107                 if use cacert ; then
108                         pushd "${S}"/nss-${NSS_VER} >/dev/null || die
109                         eapply -p0 "${DISTDIR}"/nss-cacert-class1-class3.patch
110                         popd >/dev/null || die
111                 fi
112         fi
113
114         default
115         eapply -p2 "${FILESDIR}"/${PN}-20150426-root.patch
116         local relp=$(echo "${EPREFIX}" | sed -e 's:[^/]\+:..:g')
117         sed -i \
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
122 }
123
124 src_compile() {
125         cd "image/${EPREFIX}" || die
126         if ! ${PRECOMPILED} ; then
127                 python_setup
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
131                 emake -C "${d}"
132
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 \
136                         "${c}"/mozilla \
137                         || die
138                 if use cacert ; then
139                         mkdir -p "${c}"/cacert.org || die
140                         mv "${d}"/CAcert_Inc..crt \
141                                 "${c}"/cacert.org/cacert.org_root.crt || die
142                 fi
143                 mv "${d}"/*.crt "${c}"/mozilla/ || die
144         else
145                 mv usr/share/doc/{ca-certificates,${PF}} || die
146         fi
147
148         (
149                 echo "# Automatically generated by ${CATEGORY}/${PF}"
150                 echo "# $(date -u)"
151                 echo "# Do not edit."
152                 cd "${c}" || die
153                 find * -name '*.crt' | LC_ALL=C sort
154         ) > etc/ca-certificates.conf
155
156         sh usr/sbin/update-ca-certificates --root "${S}/image" || die
157 }
158
159 src_install() {
160         cp -pPR image/* "${D}"/ || die
161         if ! ${PRECOMPILED} ; then
162                 cd ${PN}-${DEB_VER} || die
163                 doman sbin/*.8
164                 dodoc debian/README.* examples/ca-certificates-local/README
165         fi
166
167         echo 'CONFIG_PROTECT_MASK="/etc/ca-certificates.conf"' > 98ca-certificates
168         doenvd 98ca-certificates
169 }
170
171 pkg_postinst() {
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}"
178         fi
179
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)"
183         fi
184 }