1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit flag-o-matic toolchain-funcs multilib multilib-minimal
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
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"
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} )"
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 )"
30 RDEPEND=">=app-misc/c_rehash-1.7-r1
31 zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )"
35 sctp? ( >=net-misc/lksctp-tools-1.0.12 )
40 PDEPEND="app-misc/ca-certificates"
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
48 S="${WORKDIR}/${MY_P}"
50 MULTILIB_WRAPPED_HEADERS=(
51 usr/include/openssl/opensslconf.h
56 mv "${WORKDIR}"/bindist-patches/hobble-openssl "${WORKDIR}" || die
57 bash "${WORKDIR}"/hobble-openssl || die
59 cp -f "${WORKDIR}"/bindist-patches/ec_curve.c "${S}"/crypto/ec/ || die
60 cp -f "${WORKDIR}"/bindist-patches/ectest.c "${S}"/test/ || die
62 eapply "${WORKDIR}"/bindist-patches/ec-curves.patch
64 local known_failing_test
65 for known_failing_test in \
69 ebegin "Disabling test '${known_failing_test}' which is known to fail with USE=bindist"
70 rm test/recipes/${known_failing_test} || die
74 # Also see the configure parts below:
76 # $(use_ssl !bindist ec2m) \
79 # keep this in sync with app-misc/c_rehash
80 SSL_CNF_DIR="/etc/ssl"
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
86 if ! use vanilla ; then
87 if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]] ; then
88 [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"
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
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 \
107 # show the actual commands in the log
108 sed -i '/^SET_X/s@=.*@=set -x@' Makefile.shared || die
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
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
119 append-flags -fno-strict-aliasing
120 append-flags $(test-flags-CC -Wa,--noexecstack)
121 append-cppflags -DOPENSSL_NO_BUF_FREELISTS
123 # Prefixify Configure shebang (#141906)
125 -e "1s,/usr/bin/env,${EPREFIX}&," \
127 # Remove test target when FEATURES=test isn't set
130 -e '/^$config{dirs}/s@ "test",@@' \
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"
137 multilib_copy_sources
140 multilib_src_configure() {
142 unset SCRIPTS #312551
143 unset CROSS_COMPILE #311473
145 tc-export CC AR RANLIB RC
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
154 use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
155 echoit() { echo "$@" ; "$@" ; }
157 local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
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"
170 local sslout=$(./gentoo.config)
171 einfo "Use configuration ${sslout:-(openssl knows best)}"
172 local config="Configure"
173 [[ -z ${sslout} ]] && config="config"
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.
182 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
185 $(use_ssl !bindist ec2m) \
187 $(use elibc_musl && echo "no-async") \
188 ${ec_nistp_64_gcc_128} \
192 $(use_ssl sslv3 ssl3) \
193 $(use_ssl sslv3 ssl3-method) \
197 $(use_ssl tls-heartbeat heartbeats) \
199 --prefix="${EPREFIX}"/usr \
200 --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
201 --libdir=$(get_libdir) \
205 # Clean out hardcoded flags that openssl uses
206 # Fix quoting for sed
207 local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \
209 -e 's:-fomit-frame-pointer ::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' \
217 -e "/^CFLAGS=/s|=.*|=${DEFAULT_CFLAGS} ${CFLAGS}|" \
218 -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" \
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
229 multilib_src_test() {
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
240 emake DESTDIR="${D}" install
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
248 dodoc CHANGES* FAQ NEWS README doc/*.txt doc/${PN}-c-indent.el
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
257 # create the certs directory
258 keepdir ${SSL_CNF_DIR}/certs
260 # Namespace openssl programs to prevent conflicts with other man pages
261 cd "${ED}"/usr/share/man || die
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!"
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
276 # We don't want to "|| die" here
277 ln -s ssl-${m} ${d}/ssl-${s}
278 ln -s ssl-${s} ${d}/openssl-${s}
281 [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
283 dodir /etc/sandbox.d #254521
284 echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED}"/etc/sandbox.d/10openssl
287 keepdir ${SSL_CNF_DIR}/private
291 ebegin "Running 'c_rehash ${EROOT}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
292 c_rehash "${EROOT}${SSL_CNF_DIR}/certs" >/dev/null