dev-libs/openssl: synchronize v1.1.0x with v1.1.1x
[gentoo.git] / dev-libs / openssl / openssl-1.1.1b-r2.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5
6 inherit flag-o-matic toolchain-funcs multilib multilib-minimal
7
8 MY_P=${P/_/-}
9 DESCRIPTION="full-strength general purpose cryptography library (including SSL and TLS)"
10 HOMEPAGE="https://www.openssl.org/"
11 SRC_URI="mirror://openssl/source/${MY_P}.tar.gz"
12
13 LICENSE="openssl"
14 SLOT="0/1.1" # .so version of libssl/libcrypto
15 [[ "${PV}" = *_pre* ]] || \
16 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~x86-linux"
17 IUSE="+asm bindist elibc_musl rfc3779 sctp cpu_flags_x86_sse2 sslv3 static-libs test tls-heartbeat vanilla zlib"
18 RESTRICT="!bindist? ( bindist )"
19
20 RDEPEND=">=app-misc/c_rehash-1.7-r1
21         zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )"
22 DEPEND="${RDEPEND}
23         >=dev-lang/perl-5
24         sctp? ( >=net-misc/lksctp-tools-1.0.12 )
25         test? (
26                 sys-apps/diffutils
27                 sys-devel/bc
28         )"
29 PDEPEND="app-misc/ca-certificates"
30
31 PATCHES=(
32         "${FILESDIR}"/${PN}-1.1.0j-parallel_install_fix.patch #671602
33         "${FILESDIR}"/${P}-CVE-2019-1543.patch
34 )
35
36 # This does not copy the entire Fedora patchset, but JUST the parts that
37 # are needed to make it safe to use EC with RESTRICT=bindist.
38 # See openssl.spec for the matching numbering of SourceNNN, PatchNNN
39 SOURCE1=hobble-openssl
40 SOURCE12=ec_curve.c
41 SOURCE13=ectest.c
42 PATCH37=openssl-1.1.1-ec-curves.patch
43 FEDORA_GIT_BASE='https://src.fedoraproject.org/cgit/rpms/openssl.git/plain/'
44 FEDORA_GIT_BRANCH='f29'
45 FEDORA_SRC_URI=()
46 FEDORA_SOURCE=( ${SOURCE1} ${SOURCE12} ${SOURCE13} )
47 FEDORA_PATCH=( ${PATCH37} )
48 for i in "${FEDORA_SOURCE[@]}" ; do
49         FEDORA_SRC_URI+=( "${FEDORA_GIT_BASE}/${i}?h=${FEDORA_GIT_BRANCH} -> ${P}_${i}" )
50 done
51 for i in "${FEDORA_PATCH[@]}" ; do # Already have a version prefix
52         FEDORA_SRC_URI+=( "${FEDORA_GIT_BASE}/${i}?h=${FEDORA_GIT_BRANCH} -> ${i}" )
53 done
54 SRC_URI+=" bindist? ( ${FEDORA_SRC_URI[@]} )"
55
56 S="${WORKDIR}/${MY_P}"
57
58 MULTILIB_WRAPPED_HEADERS=(
59         usr/include/openssl/opensslconf.h
60 )
61
62 src_prepare() {
63         if use bindist; then
64                 # This just removes the prefix, and puts it into WORKDIR like the RPM.
65                 for i in "${FEDORA_SOURCE[@]}" ; do
66                         cp -f "${DISTDIR}"/"${P}_${i}" "${WORKDIR}"/"${i}" || die
67                 done
68
69                 # .spec %prep
70                 bash "${WORKDIR}"/"${SOURCE1}" || die
71                 cp -f "${WORKDIR}"/"${SOURCE12}" "${S}"/crypto/ec/ || die
72                 cp -f "${WORKDIR}"/"${SOURCE13}" "${S}"/test/ || die
73                 for i in "${FEDORA_PATCH[@]}" ; do
74                         if [[ "${i}" == "${PATCH37}" ]] ; then
75                                 # apply our own for OpenSSL 1.1.1b adjusted version of this patch
76                                 eapply "${FILESDIR}"/openssl-1.1.1b-ec-curves-patch.patch
77                         else
78                                 eapply "${DISTDIR}"/"${i}"
79                         fi
80                 done
81                 # Also see the configure parts below:
82                 # enable-ec \
83                 # $(use_ssl !bindist ec2m) \
84
85         fi
86
87         # keep this in sync with app-misc/c_rehash
88         SSL_CNF_DIR="/etc/ssl"
89
90         # Make sure we only ever touch Makefile.org and avoid patching a file
91         # that gets blown away anyways by the Configure script in src_configure
92         rm -f Makefile
93
94         if ! use vanilla ; then
95                 if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]] ; then
96                         [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"
97                 fi
98         fi
99
100         eapply_user #332661
101
102         # make sure the man pages are suffixed #302165
103         # don't bother building man pages if they're disabled
104         # Make DOCDIR Gentoo compliant
105         sed -i \
106                 -e '/^MANSUFFIX/s:=.*:=ssl:' \
107                 -e '/^MAKEDEPPROG/s:=.*:=$(CC):' \
108                 -e $(has noman FEATURES \
109                         && echo '/^install:/s:install_docs::' \
110                         || echo '/^MANDIR=/s:=.*:='${EPREFIX%/}'/usr/share/man:') \
111                 -e "/^DOCDIR/s@\$(BASENAME)@&-${PVR}@" \
112                 Configurations/unix-Makefile.tmpl \
113                 || die
114
115         # quiet out unknown driver argument warnings since openssl
116         # doesn't have well-split CFLAGS and we're making it even worse
117         # and 'make depend' uses -Werror for added fun (#417795 again)
118         [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
119
120         # allow openssl to be cross-compiled
121         cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
122         chmod a+rx gentoo.config || die
123
124         append-flags -fno-strict-aliasing
125         append-flags $(test-flags-CC -Wa,--noexecstack)
126         append-cppflags -DOPENSSL_NO_BUF_FREELISTS
127
128         # Prefixify Configure shebang (#141906)
129         sed \
130                 -e "1s,/usr/bin/env,${EPREFIX%/}&," \
131                 -i Configure || die
132         # Remove test target when FEATURES=test isn't set
133         if ! use test ; then
134                 sed \
135                         -e '/^$config{dirs}/s@ "test",@@' \
136                         -i Configure || die
137         fi
138         # The config script does stupid stuff to prompt the user.  Kill it.
139         sed -i '/stty -icanon min 0 time 50; read waste/d' config || die
140         ./config --test-sanity || die "I AM NOT SANE"
141
142         multilib_copy_sources
143 }
144
145 multilib_src_configure() {
146         unset APPS #197996
147         unset SCRIPTS #312551
148         unset CROSS_COMPILE #311473
149
150         tc-export CC AR RANLIB RC
151
152         # Clean out patent-or-otherwise-encumbered code
153         # Camellia: Royalty Free            https://en.wikipedia.org/wiki/Camellia_(cipher)
154         # IDEA:     Expired                 https://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
155         # EC:       ????????? ??/??/2015    https://en.wikipedia.org/wiki/Elliptic_Curve_Cryptography
156         # MDC2:     Expired                 https://en.wikipedia.org/wiki/MDC-2
157         # RC5:      Expired                 https://en.wikipedia.org/wiki/RC5
158
159         use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
160         echoit() { echo "$@" ; "$@" ; }
161
162         local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
163
164         # See if our toolchain supports __uint128_t.  If so, it's 64bit
165         # friendly and can use the nicely optimized code paths. #460790
166         local ec_nistp_64_gcc_128
167         # Disable it for now though #469976
168         #if ! use bindist ; then
169         #       echo "__uint128_t i;" > "${T}"/128.c
170         #       if ${CC} ${CFLAGS} -c "${T}"/128.c -o /dev/null >&/dev/null ; then
171         #               ec_nistp_64_gcc_128="enable-ec_nistp_64_gcc_128"
172         #       fi
173         #fi
174
175         local sslout=$(./gentoo.config)
176         einfo "Use configuration ${sslout:-(openssl knows best)}"
177         local config="Configure"
178         [[ -z ${sslout} ]] && config="config"
179
180         # Fedora hobbled-EC needs 'no-ec2m'
181         # 'srp' was restricted until early 2017 as well.
182         # "disable-deprecated" option breaks too many consumers.
183         # Don't set it without thorough revdeps testing.
184         echoit \
185         ./${config} \
186                 ${sslout} \
187                 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
188                 enable-camellia \
189                 enable-ec \
190                 $(use_ssl !bindist ec2m) \
191                 enable-srp \
192                 $(use elibc_musl && echo "no-async") \
193                 ${ec_nistp_64_gcc_128} \
194                 enable-idea \
195                 enable-mdc2 \
196                 enable-rc5 \
197                 $(use_ssl sslv3 ssl3) \
198                 $(use_ssl sslv3 ssl3-method) \
199                 $(use_ssl asm) \
200                 $(use_ssl rfc3779) \
201                 $(use_ssl sctp) \
202                 $(use_ssl tls-heartbeat heartbeats) \
203                 $(use_ssl zlib) \
204                 --prefix="${EPREFIX%/}"/usr \
205                 --openssldir="${EPREFIX%/}"${SSL_CNF_DIR} \
206                 --libdir=$(get_libdir) \
207                 shared threads \
208                 || die
209
210         # Clean out hardcoded flags that openssl uses
211         # Fix quoting for sed
212         local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \
213                 -e 's:^CFLAGS=::' \
214                 -e 's:-fomit-frame-pointer ::g' \
215                 -e 's:-O[0-9] ::g' \
216                 -e 's:-march=[-a-z0-9]* ::g' \
217                 -e 's:-mcpu=[-a-z0-9]* ::g' \
218                 -e 's:-m[a-z0-9]* ::g' \
219                 -e 's:\\:\\\\:g' \
220         )
221         sed -i \
222                 -e "/^CFLAGS=/s|=.*|=${DEFAULT_CFLAGS} ${CFLAGS}|" \
223                 -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" \
224                 Makefile || die
225 }
226
227 multilib_src_compile() {
228         # depend is needed to use $confopts; it also doesn't matter
229         # that it's -j1 as the code itself serializes subdirs
230         emake -j1 depend
231         emake all
232 }
233
234 multilib_src_test() {
235         emake -j1 test
236 }
237
238 multilib_src_install() {
239         # We need to create $ED/usr on our own to avoid a race condition #665130
240         if [[ ! -d "${ED%/}/usr" ]]; then
241                 # We can only create this directory once
242                 mkdir "${ED%/}"/usr || die
243         fi
244
245         emake DESTDIR="${D%/}" install
246 }
247
248 multilib_src_install_all() {
249         # openssl installs perl version of c_rehash by default, but
250         # we provide a shell version via app-misc/c_rehash
251         rm "${ED%/}"/usr/bin/c_rehash || die
252
253         dodoc CHANGES* FAQ NEWS README doc/*.txt doc/${PN}-c-indent.el
254
255         # This is crappy in that the static archives are still built even
256         # when USE=static-libs.  But this is due to a failing in the openssl
257         # build system: the static archives are built as PIC all the time.
258         # Only way around this would be to manually configure+compile openssl
259         # twice; once with shared lib support enabled and once without.
260         use static-libs || rm -f "${ED%/}"/usr/lib*/lib*.a
261
262         # create the certs directory
263         keepdir ${SSL_CNF_DIR}/certs
264
265         # Namespace openssl programs to prevent conflicts with other man pages
266         cd "${ED%/}"/usr/share/man || die
267         local m d s
268         for m in $(find . -type f | xargs grep -L '#include') ; do
269                 d=${m%/*} ; d=${d#./} ; m=${m##*/}
270                 [[ ${m} == openssl.1* ]] && continue
271                 [[ -n $(find -L ${d} -type l) ]] && die "erp, broken links already!"
272                 mv ${d}/{,ssl-}${m}
273                 # fix up references to renamed man pages
274                 sed -i '/^[.]SH "SEE ALSO"/,/^[.]/s:\([^(, ]*(1)\):ssl-\1:g' ${d}/ssl-${m}
275                 ln -s ssl-${m} ${d}/openssl-${m}
276                 # locate any symlinks that point to this man page ... we assume
277                 # that any broken links are due to the above renaming
278                 for s in $(find -L ${d} -type l) ; do
279                         s=${s##*/}
280                         rm -f ${d}/${s}
281                         # We don't want to "|| die" here
282                         ln -s ssl-${m} ${d}/ssl-${s}
283                         ln -s ssl-${s} ${d}/openssl-${s}
284                 done
285         done
286         [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
287
288         dodir /etc/sandbox.d #254521
289         echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED%/}"/etc/sandbox.d/10openssl
290
291         diropts -m0700
292         keepdir ${SSL_CNF_DIR}/private
293 }
294
295 pkg_postinst() {
296         ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
297         c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null
298         eend $?
299 }