1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit eutils 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 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
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
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 )"
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}] )"
35 sctp? ( >=net-misc/lksctp-tools-1.0.12 )
40 PDEPEND="app-misc/ca-certificates"
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
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'
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}" )
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}" )
62 SRC_URI+=" bindist? ( ${FEDORA_SRC_URI[@]} )"
64 S="${WORKDIR}/${MY_P}"
66 MULTILIB_WRAPPED_HEADERS=(
67 usr/include/openssl/opensslconf.h
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
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}"
83 eapply "${FILESDIR}"/openssl-1.0.2p-hobble-ecc.patch
84 # Also see the configure parts below:
86 # $(use_ssl !bindist ec2m) \
87 # $(use_ssl !bindist srp) \
90 # keep this in sync with app-misc/c_rehash
91 SSL_CNF_DIR="/etc/ssl"
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
97 if ! use vanilla ; then
98 eapply "${WORKDIR}"/patch/*.patch
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
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:') \
115 # show the actual commands in the log
116 sed -i '/^SET_X/s:=.*:=set -x:' Makefile.shared
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
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
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
133 append-flags -fno-strict-aliasing
134 append-flags $(test-flags-CC -Wa,--noexecstack)
135 append-cppflags -DOPENSSL_NO_BUF_FREELISTS
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"
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 # https://github.com/openssl/openssl/issues/2286
177 replace-flags -g3 -g2
178 replace-flags -ggdb3 -ggdb2
181 local sslout=$(./gentoo.config)
182 einfo "Use configuration ${sslout:-(openssl knows best)}"
183 local config="Configure"
184 [[ -z ${sslout} ]] && config="config"
186 # Fedora hobbled-EC needs 'no-ec2m', 'no-srp'
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 CFLAG=$(grep ^CFLAG= Makefile | LC_ALL=C sed \
218 -e 's:-fomit-frame-pointer ::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' \
225 -e "/^CFLAG/s|=.*|=${CFLAG} ${CFLAGS}|" \
226 -e "/^SHARED_LDFLAGS=/s|$| ${LDFLAGS}|" \
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
235 # rehash is needed to prep the certs/ dir; do this
236 # separately to avoid parallel build issues.
240 multilib_src_test() {
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
251 emake INSTALL_PREFIX="${D%/}" install
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
259 local -a DOCS=( CHANGES* FAQ NEWS README doc/*.txt doc/c-indentation.el )
262 use rfc3779 && dodoc engines/ccgost/README.gost
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
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}
276 # Namespace openssl programs to prevent conflicts with other man pages
277 cd "${ED}"/usr/share/man
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!"
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
292 ln -s ssl-${m} ${d}/ssl-${s}
293 ln -s ssl-${s} ${d}/openssl-${s}
296 [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
298 dodir /etc/sandbox.d #254521
299 echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED}"/etc/sandbox.d/10openssl
302 keepdir ${SSL_CNF_DIR}/private
306 ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
307 c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null