2dba788ddc316f473c1c0b6a903ed9e642d5c890
[gentoo.git] / app-misc / ca-certificates / ca-certificates-20160104.3.23.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
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.
7 #
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
11 #
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.
16
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.
21 #
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
24 #
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
27
28 EAPI="5"
29 PYTHON_COMPAT=( python{2_7,3_4,3_5} )
30
31 inherit eutils python-any-r1
32
33 if [[ ${PV} == *.* ]] ; then
34         # Compile from source ourselves.
35         PRECOMPILED=false
36         inherit versionator
37
38         DEB_VER=$(get_version_component_range 1)
39         NSS_VER=$(get_version_component_range 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="http://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? ( https://dev.gentoo.org/~anarchy/patches/nss-3.14.1-add_spi+cacerts_ca_certs.patch )"
56 fi
57
58 LICENSE="MPL-1.1"
59 SLOT="0"
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"
61 IUSE=""
62 ${PRECOMPILED} || IUSE+=" +cacert"
63
64 DEPEND=""
65 if ${PRECOMPILED} ; then
66         DEPEND+=" !<sys-apps/portage-2.1.10.41"
67 fi
68 # c_rehash: we run `c_rehash`
69 # debianutils: we run `run-parts`
70 RDEPEND="${DEPEND}
71         app-misc/c_rehash
72         sys-apps/debianutils"
73
74 if ! ${PRECOMPILED}; then
75         DEPEND+=" ${PYTHON_DEPS}"
76 fi
77
78 S=${WORKDIR}
79
80 pkg_setup() {
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"
85 }
86
87 src_unpack() {
88         ${PRECOMPILED} || default
89
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
94
95         ${PRECOMPILED} && unpacker_src_unpack
96 }
97
98 src_prepare() {
99         cd "image/${EPREFIX}" || die
100         if ! ${PRECOMPILED} ; then
101                 mkdir -p usr/sbin
102                 cp -p "${S}"/${PN}/sbin/update-ca-certificates usr/sbin/ || die
103
104                 if use cacert ; then
105                         pushd "${S}"/nss-${NSS_VER} >/dev/null
106                         epatch "${DISTDIR}"/nss-3.14.1-add_spi+cacerts_ca_certs.patch
107                         popd >/dev/null
108                 fi
109         fi
110
111         epatch "${FILESDIR}"/${PN}-20150426-root.patch
112         local relp=$(echo "${EPREFIX}" | sed -e 's:[^/]\+:..:g')
113         sed -i \
114                 -e '/="$ROOT/s:ROOT:ROOT'"${EPREFIX}"':' \
115                 -e '/RELPATH="\.\./s:"$:'"${relp}"'":' \
116                 usr/sbin/update-ca-certificates || die
117 }
118
119 src_compile() {
120         cd "image/${EPREFIX}" || die
121         if ! ${PRECOMPILED} ; then
122                 python_setup
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
126                 emake -C "${d}"
127
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
130                 if use cacert ; then
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
134                 fi
135                 mv "${d}"/*.crt usr/share/ca-certificates/mozilla/ || die
136         else
137                 mv usr/share/doc/{ca-certificates,${PF}} || die
138         fi
139
140         (
141         echo "# Automatically generated by ${CATEGORY}/${PF}"
142         echo "# $(date -u)"
143         echo "# Do not edit."
144         cd usr/share/ca-certificates
145         find * -name '*.crt' | LC_ALL=C sort
146         ) > etc/ca-certificates.conf
147
148         sh usr/sbin/update-ca-certificates --root "${S}/image" || die
149 }
150
151 src_install() {
152         cp -pPR image/* "${D}"/ || die
153         if ! ${PRECOMPILED} ; then
154                 cd ca-certificates
155                 doman sbin/*.8
156                 dodoc debian/README.* examples/ca-certificates-local/README
157         fi
158
159         echo 'CONFIG_PROTECT_MASK="/etc/ca-certificates.conf"' > 98ca-certificates
160         doenvd 98ca-certificates
161 }
162
163 pkg_postinst() {
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}"
170         fi
171
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)"
175         fi
176 }