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
9 DESCRIPTION="full-strength general purpose cryptography library (including SSL and TLS)"
10 HOMEPAGE="https://www.openssl.org/"
11 SRC_URI="mirror://openssl/source/${MY_P}.tar.gz"
14 SLOT="0/1.1" # .so version of libssl/libcrypto
15 [[ "${PV}" = *_pre* ]] || \
16 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~x86-linux"
17 IUSE="+asm bindist elibc_musl rfc3779 sctp cpu_flags_x86_sse2 sslv3 static-libs test tls-heartbeat vanilla zlib"
18 RESTRICT="!bindist? ( bindist )"
20 RDEPEND=">=app-misc/c_rehash-1.7-r1
21 zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )"
24 sctp? ( >=net-misc/lksctp-tools-1.0.12 )
29 PDEPEND="app-misc/ca-certificates"
32 "${FILESDIR}"/${PN}-1.1.0j-parallel_install_fix.patch #671602
33 "${FILESDIR}"/${P}-CVE-2019-1543.patch
36 # This does not copy the entire Fedora patchset, but JUST the parts that
37 # are needed to make it safe to use EC with RESTRICT=bindist.
38 # See openssl.spec for the matching numbering of SourceNNN, PatchNNN
39 SOURCE1=hobble-openssl
42 PATCH37=openssl-1.1.1-ec-curves.patch
43 FEDORA_GIT_BASE='https://src.fedoraproject.org/cgit/rpms/openssl.git/plain/'
44 FEDORA_GIT_BRANCH='f29'
46 FEDORA_SOURCE=( ${SOURCE1} ${SOURCE12} ${SOURCE13} )
47 FEDORA_PATCH=( ${PATCH37} )
48 for i in "${FEDORA_SOURCE[@]}" ; do
49 FEDORA_SRC_URI+=( "${FEDORA_GIT_BASE}/${i}?h=${FEDORA_GIT_BRANCH} -> ${P}_${i}" )
51 for i in "${FEDORA_PATCH[@]}" ; do # Already have a version prefix
52 FEDORA_SRC_URI+=( "${FEDORA_GIT_BASE}/${i}?h=${FEDORA_GIT_BRANCH} -> ${i}" )
54 SRC_URI+=" bindist? ( ${FEDORA_SRC_URI[@]} )"
56 S="${WORKDIR}/${MY_P}"
58 MULTILIB_WRAPPED_HEADERS=(
59 usr/include/openssl/opensslconf.h
64 # This just removes the prefix, and puts it into WORKDIR like the RPM.
65 for i in "${FEDORA_SOURCE[@]}" ; do
66 cp -f "${DISTDIR}"/"${P}_${i}" "${WORKDIR}"/"${i}" || die
70 bash "${WORKDIR}"/"${SOURCE1}" || die
71 cp -f "${WORKDIR}"/"${SOURCE12}" "${S}"/crypto/ec/ || die
72 cp -f "${WORKDIR}"/"${SOURCE13}" "${S}"/test/ || die
73 for i in "${FEDORA_PATCH[@]}" ; do
74 if [[ "${i}" == "${PATCH37}" ]] ; then
75 # apply our own for OpenSSL 1.1.1b adjusted version of this patch
76 eapply "${FILESDIR}"/openssl-1.1.1b-ec-curves-patch.patch
78 eapply "${DISTDIR}"/"${i}"
81 # Also see the configure parts below:
83 # $(use_ssl !bindist ec2m) \
87 # keep this in sync with app-misc/c_rehash
88 SSL_CNF_DIR="/etc/ssl"
90 # Make sure we only ever touch Makefile.org and avoid patching a file
91 # that gets blown away anyways by the Configure script in src_configure
94 if ! use vanilla ; then
95 if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]] ; then
96 [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"
102 # make sure the man pages are suffixed #302165
103 # don't bother building man pages if they're disabled
104 # Make DOCDIR Gentoo compliant
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:') \
111 -e "/^DOCDIR/s@\$(BASENAME)@&-${PVR}@" \
112 Configurations/unix-Makefile.tmpl \
115 # quiet out unknown driver argument warnings since openssl
116 # doesn't have well-split CFLAGS and we're making it even worse
117 # and 'make depend' uses -Werror for added fun (#417795 again)
118 [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
120 # allow openssl to be cross-compiled
121 cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
122 chmod a+rx gentoo.config || die
124 append-flags -fno-strict-aliasing
125 append-flags $(test-flags-CC -Wa,--noexecstack)
126 append-cppflags -DOPENSSL_NO_BUF_FREELISTS
128 # Prefixify Configure shebang (#141906)
130 -e "1s,/usr/bin/env,${EPREFIX%/}&," \
132 # Remove test target when FEATURES=test isn't set
135 -e '/^$config{dirs}/s@ "test",@@' \
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"
142 multilib_copy_sources
145 multilib_src_configure() {
147 unset SCRIPTS #312551
148 unset CROSS_COMPILE #311473
150 tc-export CC AR RANLIB RC
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
159 use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
160 echoit() { echo "$@" ; "$@" ; }
162 local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
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"
175 local sslout=$(./gentoo.config)
176 einfo "Use configuration ${sslout:-(openssl knows best)}"
177 local config="Configure"
178 [[ -z ${sslout} ]] && config="config"
180 # Fedora hobbled-EC needs 'no-ec2m'
181 # 'srp' was restricted until early 2017 as well.
182 # "disable-deprecated" option breaks too many consumers.
183 # Don't set it without thorough revdeps testing.
187 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
190 $(use_ssl !bindist ec2m) \
192 $(use elibc_musl && echo "no-async") \
193 ${ec_nistp_64_gcc_128} \
197 $(use_ssl sslv3 ssl3) \
198 $(use_ssl sslv3 ssl3-method) \
202 $(use_ssl tls-heartbeat heartbeats) \
204 --prefix="${EPREFIX%/}"/usr \
205 --openssldir="${EPREFIX%/}"${SSL_CNF_DIR} \
206 --libdir=$(get_libdir) \
210 # Clean out hardcoded flags that openssl uses
211 # Fix quoting for sed
212 local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \
214 -e 's:-fomit-frame-pointer ::g' \
216 -e 's:-march=[-a-z0-9]* ::g' \
217 -e 's:-mcpu=[-a-z0-9]* ::g' \
218 -e 's:-m[a-z0-9]* ::g' \
222 -e "/^CFLAGS=/s|=.*|=${DEFAULT_CFLAGS} ${CFLAGS}|" \
223 -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" \
227 multilib_src_compile() {
228 # depend is needed to use $confopts; it also doesn't matter
229 # that it's -j1 as the code itself serializes subdirs
234 multilib_src_test() {
238 multilib_src_install() {
239 # We need to create $ED/usr on our own to avoid a race condition #665130
240 if [[ ! -d "${ED%/}/usr" ]]; then
241 # We can only create this directory once
242 mkdir "${ED%/}"/usr || die
245 emake DESTDIR="${D%/}" install
248 multilib_src_install_all() {
249 # openssl installs perl version of c_rehash by default, but
250 # we provide a shell version via app-misc/c_rehash
251 rm "${ED%/}"/usr/bin/c_rehash || die
253 dodoc CHANGES* FAQ NEWS README doc/*.txt doc/${PN}-c-indent.el
255 # This is crappy in that the static archives are still built even
256 # when USE=static-libs. But this is due to a failing in the openssl
257 # build system: the static archives are built as PIC all the time.
258 # Only way around this would be to manually configure+compile openssl
259 # twice; once with shared lib support enabled and once without.
260 use static-libs || rm -f "${ED%/}"/usr/lib*/lib*.a
262 # create the certs directory
263 keepdir ${SSL_CNF_DIR}/certs
265 # Namespace openssl programs to prevent conflicts with other man pages
266 cd "${ED%/}"/usr/share/man || die
268 for m in $(find . -type f | xargs grep -L '#include') ; do
269 d=${m%/*} ; d=${d#./} ; m=${m##*/}
270 [[ ${m} == openssl.1* ]] && continue
271 [[ -n $(find -L ${d} -type l) ]] && die "erp, broken links already!"
273 # fix up references to renamed man pages
274 sed -i '/^[.]SH "SEE ALSO"/,/^[.]/s:\([^(, ]*(1)\):ssl-\1:g' ${d}/ssl-${m}
275 ln -s ssl-${m} ${d}/openssl-${m}
276 # locate any symlinks that point to this man page ... we assume
277 # that any broken links are due to the above renaming
278 for s in $(find -L ${d} -type l) ; do
281 # We don't want to "|| die" here
282 ln -s ssl-${m} ${d}/ssl-${s}
283 ln -s ssl-${s} ${d}/openssl-${s}
286 [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
288 dodir /etc/sandbox.d #254521
289 echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED%/}"/etc/sandbox.d/10openssl
292 keepdir ${SSL_CNF_DIR}/private
296 ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
297 c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null