1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit flag-o-matic toolchain-funcs multilib multilib-minimal
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"
13 MY_P=openssl-${PV/_/-}
15 # This patch set is based on the following files from Fedora 25,
16 # see https://src.fedoraproject.org/rpms/openssl/blob/25/f/openssl.spec
18 # - hobble-openssl (SOURCE1)
19 # - ec_curve.c (SOURCE12) -- MODIFIED
20 # - ectest.c (SOURCE13)
21 # - openssl-1.1.1-ec-curves.patch (PATCH37) -- MODIFIED
22 BINDIST_PATCH_SET="openssl-1.0.2t-bindist-1.0.tar.xz"
24 DESCRIPTION="full-strength general purpose cryptography library (including SSL and TLS)"
25 HOMEPAGE="https://www.openssl.org/"
26 SRC_URI="mirror://openssl/source/${MY_P}.tar.gz
28 mirror://gentoo/${BINDIST_PATCH_SET}
29 https://dev.gentoo.org/~whissi/dist/openssl/${BINDIST_PATCH_SET}
32 mirror://gentoo/${PATCH_SET}.tar.xz
33 https://dev.gentoo.org/~chutzpah/dist/openssl/${PATCH_SET}.tar.xz
34 https://dev.gentoo.org/~whissi/dist/openssl/${PATCH_SET}.tar.xz
35 https://dev.gentoo.org/~polynomial-c/dist/${PATCH_SET}.tar.xz
37 https://dev.gentoo.org/~whissi/dist/openssl/openssl-compat-1.0.2u-versioned-symbols.patch.gz"
41 KEYWORDS="~alpha amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc x86 ~x86-linux"
42 IUSE="+asm bindist gmp kerberos rfc3779 sctp cpu_flags_x86_sse2 sslv2 +sslv3 static-libs test +tls-heartbeat vanilla zlib"
44 RESTRICT="!bindist? ( bindist )
47 RDEPEND="gmp? ( >=dev-libs/gmp-5.1.3-r1[static-libs(+)?,${MULTILIB_USEDEP}] )
48 kerberos? ( >=app-crypt/mit-krb5-1.11.4[${MULTILIB_USEDEP}] )
49 zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )
50 !=dev-libs/openssl-1.0.2*:0
51 !dev-libs/openssl:1.0.0"
55 sctp? ( >=net-misc/lksctp-tools-1.0.12 )
61 # Do not install any docs
64 S="${WORKDIR}/${MY_P}"
66 MULTILIB_WRAPPED_HEADERS=(
67 usr/include/openssl/opensslconf.h
71 mv "${WORKDIR}"/openssl-compat-1.0.2u-versioned-symbols.patch "${WORKDIR}"/patch || die
74 mv "${WORKDIR}"/bindist-patches/hobble-openssl "${WORKDIR}" || die
75 bash "${WORKDIR}"/hobble-openssl || die
77 cp -f "${WORKDIR}"/bindist-patches/ec_curve.c "${S}"/crypto/ec/ || die
78 cp -f "${WORKDIR}"/bindist-patches/ectest.c "${S}"/crypto/ec/ || die
80 eapply "${WORKDIR}"/bindist-patches/ec-curves.patch
82 # Also see the configure parts below:
84 # $(use_ssl !bindist ec2m) \
85 # $(use_ssl !bindist srp) \
88 # keep this in sync with app-misc/c_rehash
89 SSL_CNF_DIR="/etc/ssl"
91 # Make sure we only ever touch Makefile.org and avoid patching a file
92 # that gets blown away anyways by the Configure script in src_configure
95 if ! use vanilla ; then
96 eapply "${WORKDIR}"/patch/*.patch
101 # disable fips in the build
102 # make sure the man pages are suffixed #302165
103 # don't bother building man pages if they're disabled
105 -e '/DIRS/s: fips : :g' \
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:') \
113 # show the actual commands in the log
114 sed -i '/^SET_X/s:=.*:=set -x:' Makefile.shared
116 # since we're forcing $(CC) as makedep anyway, just fix
117 # the conditional as always-on
118 # helps clang (#417795), and versioned gcc (#499818)
119 # this breaks build with 1.0.2p, not sure if it is needed anymore
120 #sed -i 's/expr.*MAKEDEPEND.*;/true;/' util/domd || die
122 # quiet out unknown driver argument warnings since openssl
123 # doesn't have well-split CFLAGS and we're making it even worse
124 # and 'make depend' uses -Werror for added fun (#417795 again)
125 [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
127 # allow openssl to be cross-compiled
128 cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
129 chmod a+rx gentoo.config || die
131 append-flags -fno-strict-aliasing
132 append-flags $(test-flags-CC -Wa,--noexecstack)
133 append-cppflags -DOPENSSL_NO_BUF_FREELISTS
135 sed -i '1s,^:$,#!'${EPREFIX}'/usr/bin/perl,' Configure #141906
136 # The config script does stupid stuff to prompt the user. Kill it.
137 sed -i '/stty -icanon min 0 time 50; read waste/d' config || die
138 ./config --test-sanity || die "I AM NOT SANE"
140 multilib_copy_sources
143 multilib_src_configure() {
145 unset SCRIPTS #312551
146 unset CROSS_COMPILE #311473
148 tc-export CC AR RANLIB RC
150 # Clean out patent-or-otherwise-encumbered code
151 # Camellia: Royalty Free https://en.wikipedia.org/wiki/Camellia_(cipher)
152 # IDEA: Expired https://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
153 # EC: ????????? ??/??/2015 https://en.wikipedia.org/wiki/Elliptic_Curve_Cryptography
154 # MDC2: Expired https://en.wikipedia.org/wiki/MDC-2
155 # RC5: Expired https://en.wikipedia.org/wiki/RC5
157 use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
158 echoit() { echo "$@" ; "$@" ; }
160 local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
162 # See if our toolchain supports __uint128_t. If so, it's 64bit
163 # friendly and can use the nicely optimized code paths. #460790
164 local ec_nistp_64_gcc_128
165 # Disable it for now though #469976
166 #if ! use bindist ; then
167 # echo "__uint128_t i;" > "${T}"/128.c
168 # if ${CC} ${CFLAGS} -c "${T}"/128.c -o /dev/null >&/dev/null ; then
169 # ec_nistp_64_gcc_128="enable-ec_nistp_64_gcc_128"
173 # https://github.com/openssl/openssl/issues/2286
175 replace-flags -g3 -g2
176 replace-flags -ggdb3 -ggdb2
179 local sslout=$(./gentoo.config)
180 einfo "Use configuration ${sslout:-(openssl knows best)}"
181 local config="Configure"
182 [[ -z ${sslout} ]] && config="config"
184 # Fedora hobbled-EC needs 'no-ec2m', 'no-srp'
185 # Make sure user flags don't get added *yet* to avoid duplicated
187 CFLAGS= LDFLAGS= echoit \
190 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
193 $(use_ssl !bindist ec2m) \
194 $(use_ssl !bindist srp) \
195 ${ec_nistp_64_gcc_128} \
201 $(use_ssl gmp gmp -lgmp) \
202 $(use_ssl kerberos krb5 --with-krb5-flavor=${krb5}) \
205 $(use_ssl sslv2 ssl2) \
206 $(use_ssl sslv3 ssl3) \
207 $(use_ssl tls-heartbeat heartbeats) \
209 --prefix="${EPREFIX}"/usr \
210 --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
211 --libdir=$(get_libdir) \
215 # Clean out hardcoded flags that openssl uses
216 local DEFAULT_CFLAGS=$(grep ^CFLAG= Makefile | LC_ALL=C sed \
218 -e 's:\(^\| \)-fomit-frame-pointer::g' \
219 -e 's:\(^\| \)-O[^ ]*::g' \
220 -e 's:\(^\| \)-march=[^ ]*::g' \
221 -e 's:\(^\| \)-mcpu=[^ ]*::g' \
222 -e 's:\(^\| \)-m[^ ]*::g' \
229 # Now insert clean default flags with user flags
231 -e "/^CFLAG/s|=.*|=${DEFAULT_CFLAGS} ${CFLAGS}|" \
232 -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" \
236 multilib_src_compile() {
237 # depend is needed to use $confopts; it also doesn't matter
238 # that it's -j1 as the code itself serializes subdirs
243 multilib_src_test() {
247 multilib_src_install() {
248 dolib.so lib{crypto,ssl}.so.${SLOT}