dev-libs/openssl: synchronize v1.1.0x with v1.1.1x
[gentoo.git] / dev-libs / openssl / openssl-1.0.2r.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 eutils flag-o-matic toolchain-funcs multilib multilib-minimal
7
8 # openssl-1.0.2-patches-1.6 contain additional CVE patches
9 # which got fixed with this release.
10 # Please use 1.7 version number when rolling a new tarball!
11 PATCH_SET="openssl-1.0.2-patches-1.5"
12 MY_P=${P/_/-}
13 DESCRIPTION="full-strength general purpose cryptography library (including SSL and TLS)"
14 HOMEPAGE="https://www.openssl.org/"
15 SRC_URI="mirror://openssl/source/${MY_P}.tar.gz
16         !vanilla? (
17                 mirror://gentoo/${PATCH_SET}.tar.xz
18                 https://dev.gentoo.org/~chutzpah/dist/${PN}/${PATCH_SET}.tar.xz
19                 https://dev.gentoo.org/~whissi/dist/${PN}/${PATCH_SET}.tar.xz
20                 https://dev.gentoo.org/~polynomial-c/dist/${PATCH_SET}.tar.xz
21         )"
22
23 LICENSE="openssl"
24 SLOT="0"
25 KEYWORDS="alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 ~riscv s390 sh sparc x86 ~amd64-fbsd ~x86-fbsd ~x86-linux"
26 IUSE="+asm bindist gmp kerberos rfc3779 sctp cpu_flags_x86_sse2 sslv2 +sslv3 static-libs test +tls-heartbeat vanilla zlib"
27 RESTRICT="!bindist? ( bindist )"
28
29 RDEPEND=">=app-misc/c_rehash-1.7-r1
30         gmp? ( >=dev-libs/gmp-5.1.3-r1[static-libs(+)?,${MULTILIB_USEDEP}] )
31         zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )
32         kerberos? ( >=app-crypt/mit-krb5-1.11.4[${MULTILIB_USEDEP}] )"
33 DEPEND="${RDEPEND}
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 # This does not copy the entire Fedora patchset, but JUST the parts that
43 # are needed to make it safe to use EC with RESTRICT=bindist.
44 # See openssl.spec for the matching numbering of SourceNNN, PatchNNN
45 SOURCE1=hobble-openssl
46 SOURCE12=ec_curve.c
47 SOURCE13=ectest.c
48 # These are ported instead
49 #PATCH1=openssl-1.1.0-build.patch # Fixes EVP testcase for EC
50 #PATCH37=openssl-1.1.0-ec-curves.patch
51 FEDORA_GIT_BASE='https://src.fedoraproject.org/cgit/rpms/openssl.git/plain/'
52 FEDORA_GIT_BRANCH='f25'
53 FEDORA_SRC_URI=()
54 FEDORA_SOURCE=( $SOURCE1 $SOURCE12 $SOURCE13 )
55 FEDORA_PATCH=( $PATCH1 $PATCH37 )
56 for i in "${FEDORA_SOURCE[@]}" ; do
57         FEDORA_SRC_URI+=( "${FEDORA_GIT_BASE}/${i}?h=${FEDORA_GIT_BRANCH} -> ${P}_${i}" )
58 done
59 for i in "${FEDORA_PATCH[@]}" ; do # Already have a version prefix
60         FEDORA_SRC_URI+=( "${FEDORA_GIT_BASE}/${i}?h=${FEDORA_GIT_BRANCH} -> ${i}" )
61 done
62 SRC_URI+=" bindist? ( ${FEDORA_SRC_URI[@]} )"
63
64 S="${WORKDIR}/${MY_P}"
65
66 MULTILIB_WRAPPED_HEADERS=(
67         usr/include/openssl/opensslconf.h
68 )
69
70 src_prepare() {
71         if use bindist; then
72                 # This just removes the prefix, and puts it into WORKDIR like the RPM.
73                 for i in "${FEDORA_SOURCE[@]}" ; do
74                         cp -f "${DISTDIR}"/"${P}_${i}" "${WORKDIR}"/"${i}" || die
75                 done
76                 # .spec %prep
77                 bash "${WORKDIR}"/"${SOURCE1}" || die
78                 cp -f "${WORKDIR}"/"${SOURCE12}" "${S}"/crypto/ec/ || die
79                 cp -f "${WORKDIR}"/"${SOURCE13}" "${S}"/crypto/ec/ || die # Moves to test/ in OpenSSL-1.1
80                 for i in "${FEDORA_PATCH[@]}" ; do
81                         eapply "${DISTDIR}"/"${i}"
82                 done
83                 eapply "${FILESDIR}"/openssl-1.0.2p-hobble-ecc.patch
84                 # Also see the configure parts below:
85                 # enable-ec \
86                 # $(use_ssl !bindist ec2m) \
87                 # $(use_ssl !bindist srp) \
88         fi
89
90         # keep this in sync with app-misc/c_rehash
91         SSL_CNF_DIR="/etc/ssl"
92
93         # Make sure we only ever touch Makefile.org and avoid patching a file
94         # that gets blown away anyways by the Configure script in src_configure
95         rm -f Makefile
96
97         if ! use vanilla ; then
98                 eapply "${WORKDIR}"/patch/*.patch
99         fi
100
101         eapply_user
102
103         # disable fips in the build
104         # make sure the man pages are suffixed #302165
105         # don't bother building man pages if they're disabled
106         sed -i \
107                 -e '/DIRS/s: fips : :g' \
108                 -e '/^MANSUFFIX/s:=.*:=ssl:' \
109                 -e '/^MAKEDEPPROG/s:=.*:=$(CC):' \
110                 -e $(has noman FEATURES \
111                         && echo '/^install:/s:install_docs::' \
112                         || echo '/^MANDIR=/s:=.*:='${EPREFIX%/}'/usr/share/man:') \
113                 Makefile.org \
114                 || die
115         # show the actual commands in the log
116         sed -i '/^SET_X/s:=.*:=set -x:' Makefile.shared
117
118         # since we're forcing $(CC) as makedep anyway, just fix
119         # the conditional as always-on
120         # helps clang (#417795), and versioned gcc (#499818)
121         # this breaks build with 1.0.2p, not sure if it is needed anymore
122         #sed -i 's/expr.*MAKEDEPEND.*;/true;/' util/domd || die
123
124         # quiet out unknown driver argument warnings since openssl
125         # doesn't have well-split CFLAGS and we're making it even worse
126         # and 'make depend' uses -Werror for added fun (#417795 again)
127         [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
128
129         # allow openssl to be cross-compiled
130         cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
131         chmod a+rx gentoo.config || die
132
133         append-flags -fno-strict-aliasing
134         append-flags $(test-flags-CC -Wa,--noexecstack)
135         append-cppflags -DOPENSSL_NO_BUF_FREELISTS
136
137         sed -i '1s,^:$,#!'${EPREFIX%/}'/usr/bin/perl,' Configure #141906
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         # https://github.com/openssl/openssl/issues/2286
176         if use ia64 ; then
177                 replace-flags -g3 -g2
178                 replace-flags -ggdb3 -ggdb2
179         fi
180
181         local sslout=$(./gentoo.config)
182         einfo "Use configuration ${sslout:-(openssl knows best)}"
183         local config="Configure"
184         [[ -z ${sslout} ]] && config="config"
185
186         # Fedora hobbled-EC needs 'no-ec2m', 'no-srp'
187         echoit \
188         ./${config} \
189                 ${sslout} \
190                 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
191                 enable-camellia \
192                 enable-ec \
193                 $(use_ssl !bindist ec2m) \
194                 $(use_ssl !bindist srp) \
195                 ${ec_nistp_64_gcc_128} \
196                 enable-idea \
197                 enable-mdc2 \
198                 enable-rc5 \
199                 enable-tlsext \
200                 $(use_ssl asm) \
201                 $(use_ssl gmp gmp -lgmp) \
202                 $(use_ssl kerberos krb5 --with-krb5-flavor=${krb5}) \
203                 $(use_ssl rfc3779) \
204                 $(use_ssl sctp) \
205                 $(use_ssl sslv2 ssl2) \
206                 $(use_ssl sslv3 ssl3) \
207                 $(use_ssl tls-heartbeat heartbeats) \
208                 $(use_ssl zlib) \
209                 --prefix="${EPREFIX%/}"/usr \
210                 --openssldir="${EPREFIX%/}"${SSL_CNF_DIR} \
211                 --libdir=$(get_libdir) \
212                 shared threads \
213                 || die
214
215         # Clean out hardcoded flags that openssl uses
216         local CFLAG=$(grep ^CFLAG= Makefile | LC_ALL=C sed \
217                 -e 's:^CFLAG=::' \
218                 -e 's:-fomit-frame-pointer ::g' \
219                 -e 's:-O[0-9] ::g' \
220                 -e 's:-march=[-a-z0-9]* ::g' \
221                 -e 's:-mcpu=[-a-z0-9]* ::g' \
222                 -e 's:-m[a-z0-9]* ::g' \
223         )
224         sed -i \
225                 -e "/^CFLAG/s|=.*|=${CFLAG} ${CFLAGS}|" \
226                 -e "/^SHARED_LDFLAGS=/s|$| ${LDFLAGS}|" \
227                 Makefile || die
228 }
229
230 multilib_src_compile() {
231         # depend is needed to use $confopts; it also doesn't matter
232         # that it's -j1 as the code itself serializes subdirs
233         emake -j1 V=1 depend
234         emake all
235         # rehash is needed to prep the certs/ dir; do this
236         # separately to avoid parallel build issues.
237         emake rehash
238 }
239
240 multilib_src_test() {
241         emake -j1 test
242 }
243
244 multilib_src_install() {
245         # We need to create $ED/usr on our own to avoid a race condition #665130
246         if [[ ! -d "${ED%/}/usr" ]]; then
247                 # We can only create this directory once
248                 mkdir "${ED%/}"/usr || die
249         fi
250
251         emake INSTALL_PREFIX="${D%/}" install
252 }
253
254 multilib_src_install_all() {
255         # openssl installs perl version of c_rehash by default, but
256         # we provide a shell version via app-misc/c_rehash
257         rm "${ED%/}"/usr/bin/c_rehash || die
258
259         local -a DOCS=( CHANGES* FAQ NEWS README doc/*.txt doc/c-indentation.el )
260         einstalldocs
261
262         use rfc3779 && dodoc engines/ccgost/README.gost
263
264         # This is crappy in that the static archives are still built even
265         # when USE=static-libs.  But this is due to a failing in the openssl
266         # build system: the static archives are built as PIC all the time.
267         # Only way around this would be to manually configure+compile openssl
268         # twice; once with shared lib support enabled and once without.
269         use static-libs || rm -f "${ED}"/usr/lib*/lib*.a
270
271         # create the certs directory
272         dodir ${SSL_CNF_DIR}/certs
273         cp -RP certs/* "${ED}"${SSL_CNF_DIR}/certs/ || die
274         rm -r "${ED}"${SSL_CNF_DIR}/certs/{demo,expired}
275
276         # Namespace openssl programs to prevent conflicts with other man pages
277         cd "${ED}"/usr/share/man
278         local m d s
279         for m in $(find . -type f | xargs grep -L '#include') ; do
280                 d=${m%/*} ; d=${d#./} ; m=${m##*/}
281                 [[ ${m} == openssl.1* ]] && continue
282                 [[ -n $(find -L ${d} -type l) ]] && die "erp, broken links already!"
283                 mv ${d}/{,ssl-}${m}
284                 # fix up references to renamed man pages
285                 sed -i '/^[.]SH "SEE ALSO"/,/^[.]/s:\([^(, ]*(1)\):ssl-\1:g' ${d}/ssl-${m}
286                 ln -s ssl-${m} ${d}/openssl-${m}
287                 # locate any symlinks that point to this man page ... we assume
288                 # that any broken links are due to the above renaming
289                 for s in $(find -L ${d} -type l) ; do
290                         s=${s##*/}
291                         rm -f ${d}/${s}
292                         ln -s ssl-${m} ${d}/ssl-${s}
293                         ln -s ssl-${s} ${d}/openssl-${s}
294                 done
295         done
296         [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
297
298         dodir /etc/sandbox.d #254521
299         echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED}"/etc/sandbox.d/10openssl
300
301         diropts -m0700
302         keepdir ${SSL_CNF_DIR}/private
303 }
304
305 pkg_postinst() {
306         ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
307         c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null
308         eend $?
309 }