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