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
10 # This patch set is based on the following files from Fedora 31,
11 # see https://src.fedoraproject.org/rpms/openssl/blob/f31/f/openssl.spec
13 # - hobble-openssl (SOURCE1)
14 # - ec_curve.c (SOURCE12) -- MODIFIED
15 # - ectest.c (SOURCE13)
16 # - openssl-1.1.1-ec-curves.patch (PATCH37) -- MODIFIED
17 BINDIST_PATCH_SET="openssl-1.1.1e-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
23 mirror://gentoo/${BINDIST_PATCH_SET}
24 https://dev.gentoo.org/~whissi/dist/openssl/${BINDIST_PATCH_SET}
28 SLOT="0/1.1" # .so version of libssl/libcrypto
29 [[ "${PV}" = *_pre* ]] || \
30 KEYWORDS="~alpha amd64 arm arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv s390 sparc ~x86 ~x86-linux"
31 IUSE="+asm bindist elibc_musl rfc3779 sctp cpu_flags_x86_sse2 sslv3 static-libs test tls-heartbeat vanilla zlib"
32 RESTRICT="!bindist? ( bindist )
35 RDEPEND=">=app-misc/c_rehash-1.7-r1
36 zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )"
40 sctp? ( >=net-misc/lksctp-tools-1.0.12 )
46 PDEPEND="app-misc/ca-certificates"
49 "${FILESDIR}"/${PN}-1.1.0j-parallel_install_fix.patch #671602
52 S="${WORKDIR}/${MY_P}"
54 # force upgrade to prevent broken login, bug 696950
55 RDEPEND+=" !<net-misc/openssh-8.0_p1-r3"
57 MULTILIB_WRAPPED_HEADERS=(
58 usr/include/openssl/opensslconf.h
62 [[ ${MERGE_TYPE} == binary ]] && return
64 # must check in pkg_setup; sysctl don't work with userpriv!
65 if has test ${FEATURES} && use sctp; then
66 # test_ssl_new will fail with "Ensure SCTP AUTH chunks are enabled in kernel"
67 # if sctp.auth_enable is not enabled.
68 local sctp_auth_status=$(sysctl -n net.sctp.auth_enable 2>/dev/null)
69 if [[ -z "${sctp_auth_status}" ]] || [[ ${sctp_auth_status} != 1 ]]; then
70 die "FEATURES=test with USE=sctp requires net.sctp.auth_enable=1!"
76 # allow openssl to be cross-compiled
77 cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
78 chmod a+rx gentoo.config || die
81 mv "${WORKDIR}"/bindist-patches/hobble-openssl "${WORKDIR}" || die
82 bash "${WORKDIR}"/hobble-openssl || die
84 cp -f "${WORKDIR}"/bindist-patches/ec_curve.c "${S}"/crypto/ec/ || die
85 cp -f "${WORKDIR}"/bindist-patches/ectest.c "${S}"/test/ || die
87 eapply "${WORKDIR}"/bindist-patches/ec-curves.patch
89 local known_failing_test
90 for known_failing_test in \
94 ebegin "Disabling test '${known_failing_test}' which is known to fail with USE=bindist"
95 rm test/recipes/${known_failing_test} || die
99 # Also see the configure parts below:
101 # $(use_ssl !bindist ec2m) \
104 # keep this in sync with app-misc/c_rehash
105 SSL_CNF_DIR="/etc/ssl"
107 # Make sure we only ever touch Makefile.org and avoid patching a file
108 # that gets blown away anyways by the Configure script in src_configure
111 if ! use vanilla ; then
112 if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]] ; then
113 [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"
119 if has test ${FEATURES} && use sctp && has network-sandbox ${FEATURES}; then
120 ebegin "Disabling test '80-test_ssl_new.t' which is known to fail with FEATURES=network-sandbox"
121 rm test/recipes/80-test_ssl_new.t || die
125 # make sure the man pages are suffixed #302165
126 # don't bother building man pages if they're disabled
127 # Make DOCDIR Gentoo compliant
129 -e '/^MANSUFFIX/s:=.*:=ssl:' \
130 -e '/^MAKEDEPPROG/s:=.*:=$(CC):' \
131 -e $(has noman FEATURES \
132 && echo '/^install:/s:install_docs::' \
133 || echo '/^MANDIR=/s:=.*:='${EPREFIX}'/usr/share/man:') \
134 -e "/^DOCDIR/s@\$(BASENAME)@&-${PVR}@" \
135 Configurations/unix-Makefile.tmpl \
138 # quiet out unknown driver argument warnings since openssl
139 # doesn't have well-split CFLAGS and we're making it even worse
140 # and 'make depend' uses -Werror for added fun (#417795 again)
141 [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
143 append-flags -fno-strict-aliasing
144 append-flags $(test-flags-CC -Wa,--noexecstack)
145 append-cppflags -DOPENSSL_NO_BUF_FREELISTS
147 # Prefixify Configure shebang (#141906)
149 -e "1s,/usr/bin/env,${EPREFIX}&," \
151 # Remove test target when FEATURES=test isn't set
154 -e '/^$config{dirs}/s@ "test",@@' \
157 # The config script does stupid stuff to prompt the user. Kill it.
158 sed -i '/stty -icanon min 0 time 50; read waste/d' config || die
159 ./config --test-sanity || die "I AM NOT SANE"
161 multilib_copy_sources
164 multilib_src_configure() {
166 unset SCRIPTS #312551
167 unset CROSS_COMPILE #311473
169 tc-export CC AR RANLIB RC
171 # Clean out patent-or-otherwise-encumbered code
172 # Camellia: Royalty Free https://en.wikipedia.org/wiki/Camellia_(cipher)
173 # IDEA: Expired https://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
174 # EC: ????????? ??/??/2015 https://en.wikipedia.org/wiki/Elliptic_Curve_Cryptography
175 # MDC2: Expired https://en.wikipedia.org/wiki/MDC-2
176 # RC5: Expired https://en.wikipedia.org/wiki/RC5
178 use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
179 echoit() { echo "$@" ; "$@" ; }
181 local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
183 # See if our toolchain supports __uint128_t. If so, it's 64bit
184 # friendly and can use the nicely optimized code paths. #460790
185 local ec_nistp_64_gcc_128
186 # Disable it for now though #469976
187 #if ! use bindist ; then
188 # echo "__uint128_t i;" > "${T}"/128.c
189 # if ${CC} ${CFLAGS} -c "${T}"/128.c -o /dev/null >&/dev/null ; then
190 # ec_nistp_64_gcc_128="enable-ec_nistp_64_gcc_128"
194 local sslout=$(./gentoo.config)
195 einfo "Use configuration ${sslout:-(openssl knows best)}"
196 local config="Configure"
197 [[ -z ${sslout} ]] && config="config"
199 # Fedora hobbled-EC needs 'no-ec2m'
200 # 'srp' was restricted until early 2017 as well.
201 # "disable-deprecated" option breaks too many consumers.
202 # Don't set it without thorough revdeps testing.
203 # Make sure user flags don't get added *yet* to avoid duplicated
205 CFLAGS= LDFLAGS= echoit \
208 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
211 $(use_ssl !bindist ec2m) \
213 $(use elibc_musl && echo "no-async") \
214 ${ec_nistp_64_gcc_128} \
218 $(use_ssl sslv3 ssl3) \
219 $(use_ssl sslv3 ssl3-method) \
223 $(use_ssl tls-heartbeat heartbeats) \
225 --prefix="${EPREFIX}"/usr \
226 --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
227 --libdir=$(get_libdir) \
231 # Clean out hardcoded flags that openssl uses
232 local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \
234 -e 's:\(^\| \)-fomit-frame-pointer::g' \
235 -e 's:\(^\| \)-O[^ ]*::g' \
236 -e 's:\(^\| \)-march=[^ ]*::g' \
237 -e 's:\(^\| \)-mcpu=[^ ]*::g' \
238 -e 's:\(^\| \)-m[^ ]*::g' \
245 # Now insert clean default flags with user flags
247 -e "/^CFLAGS=/s|=.*|=${DEFAULT_CFLAGS} ${CFLAGS}|" \
248 -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" \
252 multilib_src_compile() {
253 # depend is needed to use $confopts; it also doesn't matter
254 # that it's -j1 as the code itself serializes subdirs
259 multilib_src_test() {
263 multilib_src_install() {
264 # We need to create $ED/usr on our own to avoid a race condition #665130
265 if [[ ! -d "${ED}/usr" ]]; then
266 # We can only create this directory once
267 mkdir "${ED}"/usr || die
270 emake DESTDIR="${D}" install
273 multilib_src_install_all() {
274 # openssl installs perl version of c_rehash by default, but
275 # we provide a shell version via app-misc/c_rehash
276 rm "${ED}"/usr/bin/c_rehash || die
278 dodoc CHANGES* FAQ NEWS README doc/*.txt doc/${PN}-c-indent.el
280 # This is crappy in that the static archives are still built even
281 # when USE=static-libs. But this is due to a failing in the openssl
282 # build system: the static archives are built as PIC all the time.
283 # Only way around this would be to manually configure+compile openssl
284 # twice; once with shared lib support enabled and once without.
285 use static-libs || rm -f "${ED}"/usr/lib*/lib*.a
287 # create the certs directory
288 keepdir ${SSL_CNF_DIR}/certs
290 # Namespace openssl programs to prevent conflicts with other man pages
291 cd "${ED}"/usr/share/man || die
293 for m in $(find . -type f | xargs grep -L '#include') ; do
294 d=${m%/*} ; d=${d#./} ; m=${m##*/}
295 [[ ${m} == openssl.1* ]] && continue
296 [[ -n $(find -L ${d} -type l) ]] && die "erp, broken links already!"
298 # fix up references to renamed man pages
299 sed -i '/^[.]SH "SEE ALSO"/,/^[.]/s:\([^(, ]*(1)\):ssl-\1:g' ${d}/ssl-${m}
300 ln -s ssl-${m} ${d}/openssl-${m}
301 # locate any symlinks that point to this man page ... we assume
302 # that any broken links are due to the above renaming
303 for s in $(find -L ${d} -type l) ; do
306 # We don't want to "|| die" here
307 ln -s ssl-${m} ${d}/ssl-${s}
308 ln -s ssl-${s} ${d}/openssl-${s}
311 [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
313 dodir /etc/sandbox.d #254521
314 echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED}"/etc/sandbox.d/10openssl
317 keepdir ${SSL_CNF_DIR}/private
321 ebegin "Running 'c_rehash ${EROOT}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
322 c_rehash "${EROOT}${SSL_CNF_DIR}/certs" >/dev/null