Add fix from upstream for CVE-2015-0209 #541502 by Agostino Sarubbo and CVE-2015...
authorMike Frysinger <vapier@gentoo.org>
Wed, 4 Mar 2015 07:34:39 +0000 (07:34 +0000)
committerMike Frysinger <vapier@gentoo.org>
Wed, 4 Mar 2015 07:34:39 +0000 (07:34 +0000)
Package-Manager: portage-2.2.17/cvs/Linux x86_64
Manifest-Sign-Key: 0xD2E96200

dev-libs/openssl/ChangeLog
dev-libs/openssl/Manifest
dev-libs/openssl/files/openssl-1.0.2-CVE-2015-0209.patch [new file with mode: 0644]
dev-libs/openssl/files/openssl-1.0.2-CVE-2015-0288.patch [new file with mode: 0644]
dev-libs/openssl/openssl-1.0.2-r2.ebuild [new file with mode: 0644]

index 2943af69215dc8a8b4b0dbc70fc5f67d912fe28a..c3465c9db4576de9e41a4a991a14d33ede7a7b5d 100644 (file)
@@ -1,6 +1,14 @@
 # ChangeLog for dev-libs/openssl
 # Copyright 1999-2015 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/dev-libs/openssl/ChangeLog,v 1.629 2015/01/28 19:35:28 mgorny Exp $
+# $Header: /var/cvsroot/gentoo-x86/dev-libs/openssl/ChangeLog,v 1.630 2015/03/04 07:34:28 vapier Exp $
+
+*openssl-1.0.2-r2 (04 Mar 2015)
+
+  04 Mar 2015; Mike Frysinger <vapier@gentoo.org>
+  +files/openssl-1.0.2-CVE-2015-0209.patch,
+  +files/openssl-1.0.2-CVE-2015-0288.patch, +openssl-1.0.2-r2.ebuild:
+  Add fix from upstream for CVE-2015-0209 #541502 by Agostino Sarubbo and
+  CVE-2015-0288 #542038 by Kristian Fiskerstrand.
 
   28 Jan 2015; Michał Górny <mgorny@gentoo.org> openssl-0.9.8z_p1-r2.ebuild,
   openssl-0.9.8z_p2.ebuild, openssl-0.9.8z_p3.ebuild, openssl-0.9.8z_p4.ebuild,
index 805807fb6d22659433f8dc2c593f61955a2bdf78..9d19916db50615280e918b3fe7bc025537dddcb1 100644 (file)
@@ -17,6 +17,8 @@ AUX openssl-1.0.1-x32.patch 3273 SHA256 a4f05b8757e225a05a9c5a3ea485159066760d87
 AUX openssl-1.0.1e-s_client-verify.patch 592 SHA256 6f540fce663eefbe68cee16ad7d8d561d6c898eeb4180c2f4a4caa7e43c6d0c9 SHA512 117b1017e1259667078d3ccdcd9fd46357c6f85cf2702794f49c612b37acdc044fe88f871dbe46fcad9ed4cd8aaaaee800dddb5286203322802efd7549a43b68 WHIRLPOOL 70a4cc36b1dcb24d7e9bcef016684fb2394977f7f20aa332ebd0aa15e3f4c16c74563d2fc0ba8d70669f6cc9a13bf8a30cdb28ebafe2d102cd2859a4e32c38d7
 AUX openssl-1.0.1f-revert-alpha-perl-generation.patch 3102 SHA256 6e502275b32ac0eca80f28448ae1bb88506f9135258f420fd857ea0b9b485778 SHA512 c80439da3d268e70fd492d0ca73c0a17ddb088b9330610794a338d1921ee13dad9caca4c81ca103b82a7541c8712f77e51f352ec1b1b02789d9aed291acb0cdc WHIRLPOOL cb760366c8759b1c78c5307134bb48c4fc12b1556276c2ef55455ea54725d20cb433ade966a7453f512d2feb5ae89a9798078ab535e4605366633a8e003c7ac6
 AUX openssl-1.0.1h-ipv6.patch 17788 SHA256 7adeeb88cc544f8b210efbe2baff48fccf5029b582dff7010ae70e0e1f097d7b SHA512 0f0990d4294abcb5f3e51c84080883046a054c710b57a23f99b3323727d5e9aeb5ddeb6b6c2565b4be364f7c21419c90ce5288154e404cd663678f87e0d1c259 WHIRLPOOL cfe7a2e141a4a6252ffcfe215b16dd1082bc14a757dad7eb01bb9819de41ef0ee51a4b2dbf110c27b52e483341c337bf4d1f77f4f9f3172d2fee9e348c30af7e
+AUX openssl-1.0.2-CVE-2015-0209.patch 1282 SHA256 6be2b1fa0d440bc1c1b15da4a9d32811a04c3e7c701678eb8ee72454bbf87401 SHA512 db5b73c815582453d3231d49c9c24d60824e56f67a74f815818d0f90bccd485e98a98b449386aa297fa055b5fc27e2a058c03bc410478fb98051a729ac75b4db WHIRLPOOL 46ddfaff115622e2426c544e757bf882fc5069f35d169189cf277d90a5ad36c274beaf1ff89cdc593e2e5cd1593588c389262dce3bb6a166c5fd7eb908458fec
+AUX openssl-1.0.2-CVE-2015-0288.patch 800 SHA256 613acdc06a22ec5cbc274cc39022b1fa1fd73e409551493bcab6d4a273983484 SHA512 4785d9c4620492c4997cbe7c83a42a9804a9e8c3d94e35dd7d3e6bd16f607a9b294b77123686f24c953e6330f96907008dccf1379648d806fa85bbdd20b81ca0 WHIRLPOOL 738831379e3c117f260306e2f39aacd51b895ed4bcb7dd0189f14a7301c09ffd4fbd882fbd05d7e71cd6c9524fc289124909e5fd2dcc23607fa4ce71ba3a0df7
 AUX openssl-1.0.2-ipv6.patch 18811 SHA256 9ff3150c75f3f3e6a9773ffe54d90994cbf68cc919134aea68e09e7ed921763d SHA512 58e293f8f19a3fad08729b842dd977b73fedb0c49208d87a056bfea857c0e2b79a310d7d098c04429b65564fce64defeda6d1dcc3068ad5a80ef276db6421e54 WHIRLPOOL 36a0fffc7238011b93077bed94c9507f2ffc1cf199e6c06e94d01589cdc84a6568b9122e1a120b8262bd0a1c43f25169a29796c92a78338dd9f03b4cc2cdf0b8
 AUX openssl-1.0.2-parallel-build.patch 10661 SHA256 bc5622150a964dc2d9909f41557140b696ce1bdfa4e2b12cc3e0e51029ead32b SHA512 a4957304a4424016cd8a1c6552c422cd042d737e12f96235ec54d1e601ccbe8cb79d931ac8777d1a599bd4a70eac4e6700a24362f14fb04eb273df82f2de0d01 WHIRLPOOL 5b34e45dcb0db6649e26d275925ca008f5201afbc22184e15c5324513bc0ed40ee271a70686e10a20bb219b3c4bd2148323b317ead97cdc27a3c897c0a07d228
 AUX openssl-1.0.2-s_client-verify.patch 648 SHA256 b6ca2278dd9833f87a1d0037cb3cac8aee0f8326ff13ece1f08a536b8545eb77 SHA512 78b09ae700096205582785584a268776af46fc5bc94a0faa1ce6087ffcc945649e69269ff7fa88dedd5df1a5cdecc53e885de1e39506470f23b02028ca962104 WHIRLPOOL 8e7c90d37c1736b4b2f2c38d1c12dcfee4996a50a2a7dd07645a0c0b6616006d11232dd0f88ab735833e1c46aa171ceb5e1288c3d57296010bdda59295de7599
@@ -41,24 +43,23 @@ EBUILD openssl-1.0.1j.ebuild 8781 SHA256 d95067eb3e8a17a63af329b7fe90dbf1f8f1725
 EBUILD openssl-1.0.1k.ebuild 8785 SHA256 15a9925bac0ded537ef3f17292d8c76fa921fc6149d9a41c9f9c25a8dac8fdb1 SHA512 182fdaeff959ec9227241af5c6ae5559f3faf821c71150404bdea4b88657b8d01fa3ff54d700e118a16b0459d8c9d8235e8d337fa4f94038f12e170665ff0546 WHIRLPOOL 23fd4b7c4f4905403cb13588093740f4ab3617ec2a7ee043e8b50e6a6db9898630f0937bfa28ffa48eb98bc84ce0e1eb31b81df2dbdef294074dcad3e23f6498
 EBUILD openssl-1.0.1l.ebuild 8793 SHA256 f745217205fdb90496bcb3ce539b0d856b915623d17514c238a9e52ef6f1addd SHA512 145f809f24f0ec6707f0dc79d9c7ae52b5d35c69eed5e622fbb377c77e80c6f97dbb80ded3e142cac3646e3845a6cdf94f445968620b8f8924754dfea41b3cde WHIRLPOOL d08368fcab1a6d933424c6d67905b72bbe2d418320ea5fa1312fcd7e476d3c69fd085892242efb57548743b092a964a4bea75ad6e1f62b1b394a08670992e05d
 EBUILD openssl-1.0.2-r1.ebuild 8731 SHA256 648eb0511e4ddaf96bdfd9743d10a49e3be0068b6b2d6e88f2b83c58db0fb478 SHA512 e588f7fd3953e744ea1e1c03de718a5910390e47eb5692a66e14949ef4475a13aa871eb3c76c5a32a5e2e632e96104ddc872ea605abffe2ea37517ca1ee0f6f3 WHIRLPOOL e38e904d6580f83f12096a27d1906bfa722b8002c509cc242e7225568f99bb0dbde1cadcb3bbc2aed8e0de9da818199fb664c759b1d45d1c061a2e9dec5633a3
-MISC ChangeLog 96358 SHA256 bdbfa11580e29918ccdb302253799ea8f64506d6133f3419f31db19579dad7d0 SHA512 bc2b65e7a09e5ca119ddb1214b56832eb67dcb3efe026b6119da32abe2c6f3e75a93aa5f8045214a1db7de6f7484dda6a4fd80ddd151a2afea7e1dc149c4a3a9 WHIRLPOOL 1029d4ce2afd4eed876594deae15a2d3502e3180d85b6ae7e784a6909d7412c011b987aaae5924eaafff8e4741de0bac60934baa4b960bd34ccccd35e5c2e021
+EBUILD openssl-1.0.2-r2.ebuild 8828 SHA256 c6afb206f0db5ed9f820e5f149570582dbe445cda75eb93d5a2f6718d67527b0 SHA512 46068f4662039afd9ba24d6427ea8029fe12de17d234b1a4dc39298898f904e5a5d1e3f3ee40603bb15788cc55e6bbba61cd899d663df5eb82c465d42e00a5ba WHIRLPOOL 98dbfddc3337eda7976f7c5e1c4c9e22133b6f707146bb86075353b8c11702c582756aaf9d12867c3d41dc214e49cc870b29975282b8800521a86a8e3398d794
+MISC ChangeLog 96680 SHA256 386a10696cc9cb35834ed2199f93b7d90768d819b1cbdade110c1ce19b4d07d9 SHA512 11cd87a4c63154b5f0915daa1554565ee0070a990732337ffe41b839fc378e57225e05dc416ef857fca621f7f97aa6bbecb02447104546acc8574b39c2712cf6 WHIRLPOOL a000e30a0d5d18b3787408410fd69230b2d5258a868ae197a92f87798d82577d7c8b9ce6b973f753f563f10ed59ddad85c26d6553e82fe86830060a0c9f1b130
 MISC metadata.xml 637 SHA256 7b96f0e49fc5ab28bf914be847a89300bf3c7e65f652d748a48721a40c444b8d SHA512 a92ca59f6fc42237f7d30c4b0cd7339a7e82455ef31e155fb09d61012b3e3892d235d09a8c535f1db73b1468d483bb697575167cfe0d1ab45ef184bb95dc37db WHIRLPOOL f6fe48fc5b7a3a94eff327c5a8d6930efe2a7c92e7fb8a3366d8af0133b466420e68e168883742f993e89e45db12dab8c5a11e665242e368f012b0dc26d3c9ef
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
-iQJ8BAEBCABmBQJUyToEXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w
-ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQ2REJCMDdDQzRGMERBRDA2RUEwQUZFNDFC
-MDdBMUFFQUVGQjQ0NjRFAAoJELB6GurvtEZO31cP/0CiAR4M5PdaOPMNpZ/udTSJ
-mIPyi+j+ApeTFuuBcpq3yZDb0buJsmeu8IO4x4iERVUhnGWEVLbrycx5eK6aha+J
-lzuBr+kbIuEkNrAHk1FH3a0hf9fktudpCXFopBN9/wKOFcOlWegRYMK8od20Y8My
-SCdtnt6NcJ/A9L0j6wBwL7vpBGMQY9bX+ouGQwBlPTrERbcWI2CQysfm93gYiAI1
-tbYDUH52VzPsYtsPuqZ47D1Zmp8Sqq/CnXjosedGK2i9zhGnPNMccNy6dFvSQWy1
-TtwUuShE9Sbn0hshunQBfacMfeDM8uz0Pc0+tFLbP0877eRji+jhw9UkZtIhvqGt
-GQZ9ngW/enxu4rF+mMOvxHOLa8hrGKTCVa4tILqBOCh8FIFyDLaouJk+AtgH01IT
-eAqqVle9jGBdbLN4i8IbBT1gIvuxhac0C9eS8iB63DUU+WkFfu7zsPvnEyX6PH2K
-VQknHi5drdFZPIZDjHmoM0+7s5CPTKUvkH8WtEnE8wtD7dec95T3e3C/AtvKZyh9
-xPwacu1piFp/LrWk3fMSGRMuliEdyjY8mwNYw/MEjH9+9ltQFSef+eUv7fm3Ulx7
-bQoVjnKHkzNDOxb1C10YCT1Wg+W1qS+W5CxXec7tu+Az/eA82kwayxXn7sggj43N
-GK1hZIvPZIE3oEXSGPVc
-=hhLb
+iQIcBAEBCAAGBQJU9rWNAAoJEPGu1DbS6WIAPV8P/jGaHILU5d1ky4Ck8Zv2hEgY
+UU8gGhVzL7xTw7zpsiP4wbEzqEeVowhqLipqZnL2VCadswEaDMyh49crlPZMMUnC
+reLoTlDFbP8rcToe8ImjMKmFSk92uRqhRnY8GqfVqvOl6LR/NokpY5u8DEsbsHox
+QDofNq1V7WoP4MhZ1G7JLp1Z0sRpJ49FJbbjPcWUq2cjsq5LJc9RfmWFyphYUSr7
+WKgYT+g/HCb1vIKnX65jYqwF1hDK+z7hEn3e9ak5b4BK9zkIi5gXkOdkez538HeC
+xqktgqdtSxESgpoUvVW0rZghWZTkL/4POxaEyEgDkV/ww+Vefug73CWTfpRzxqaP
+6K808RqjBJ5wYILmX0bm+VxglFMR0VXgkge3zdv7eADVgrh1no3x3Fa9xUIBea9d
+d8xTr3D/aL6AwK9IXPRo3HDVi8kl8W8zAkTPKDUY0Bpw9MAQGSw/nYsMRdrBToe/
+Ukayb0+gBuLLCrKVZjVmOuDjyV0nDMkTNDlt4OfA25Je2Dyq1CRCVb9oncVuuG/g
+Al1dwTxofboTrMU79bhXvhnKwFSIObtF/3pHefEJCYhwTA3WnMX0KfiJG/4XjLgu
+8sKeRA4FuSHxaiuQtyUvj+a8z35JrljSS+pTByoooO9HOTYoheWD51LhiDVm6j1N
+gfC74/JECpUlzLqkIMfm
+=aT3y
 -----END PGP SIGNATURE-----
diff --git a/dev-libs/openssl/files/openssl-1.0.2-CVE-2015-0209.patch b/dev-libs/openssl/files/openssl-1.0.2-CVE-2015-0209.patch
new file mode 100644 (file)
index 0000000..6d396b4
--- /dev/null
@@ -0,0 +1,49 @@
+https://bugs.gentoo.org/541502
+
+From 1b4a8df38fc9ab3c089ca5765075ee53ec5bd66a Mon Sep 17 00:00:00 2001
+From: Matt Caswell <matt@openssl.org>
+Date: Mon, 9 Feb 2015 11:38:41 +0000
+Subject: [PATCH] Fix a failure to NULL a pointer freed on error.
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Inspired by BoringSSL commit 517073cd4b by Eric Roman <eroman@chromium.org>
+
+CVE-2015-0209
+
+Reviewed-by: Emilia Käsper <emilia@openssl.org>
+---
+ crypto/ec/ec_asn1.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c
+index 30b7df4..d3e8316 100644
+--- a/crypto/ec/ec_asn1.c
++++ b/crypto/ec/ec_asn1.c
+@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
+             ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
+             goto err;
+         }
+-        if (a)
+-            *a = ret;
+     } else
+         ret = *a;
+ 
+@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
+         }
+     }
+ 
++    if (a)
++        *a = ret;
+     ok = 1;
+  err:
+     if (!ok) {
+-        if (ret)
++        if (ret && (a == NULL || *a != ret))
+             EC_KEY_free(ret);
+         ret = NULL;
+     }
+-- 
+2.3.1
+
diff --git a/dev-libs/openssl/files/openssl-1.0.2-CVE-2015-0288.patch b/dev-libs/openssl/files/openssl-1.0.2-CVE-2015-0288.patch
new file mode 100644 (file)
index 0000000..a6a10b0
--- /dev/null
@@ -0,0 +1,31 @@
+https://bugs.gentoo.org/542038
+
+From 28a00bcd8e318da18031b2ac8778c64147cd54f9 Mon Sep 17 00:00:00 2001
+From: "Dr. Stephen Henson" <steve@openssl.org>
+Date: Wed, 18 Feb 2015 00:34:59 +0000
+Subject: [PATCH] Check public key is not NULL.
+
+CVE-2015-0288
+PR#3708
+
+Reviewed-by: Matt Caswell <matt@openssl.org>
+---
+ crypto/x509/x509_req.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/crypto/x509/x509_req.c b/crypto/x509/x509_req.c
+index bc6e566..01795f4 100644
+--- a/crypto/x509/x509_req.c
++++ b/crypto/x509/x509_req.c
+@@ -92,6 +92,8 @@ X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
+         goto err;
+ 
+     pktmp = X509_get_pubkey(x);
++    if (pktmp == NULL)
++        goto err;
+     i = X509_REQ_set_pubkey(ret, pktmp);
+     EVP_PKEY_free(pktmp);
+     if (!i)
+-- 
+2.3.1
+
diff --git a/dev-libs/openssl/openssl-1.0.2-r2.ebuild b/dev-libs/openssl/openssl-1.0.2-r2.ebuild
new file mode 100644 (file)
index 0000000..0b1a2a7
--- /dev/null
@@ -0,0 +1,261 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-libs/openssl/openssl-1.0.2-r2.ebuild,v 1.1 2015/03/04 07:34:28 vapier Exp $
+
+EAPI="4"
+
+inherit eutils flag-o-matic toolchain-funcs multilib multilib-minimal
+
+REV="1.7"
+MY_P=${P/_/-}
+DESCRIPTION="full-strength general purpose cryptography library (including SSL and TLS)"
+HOMEPAGE="http://www.openssl.org/"
+SRC_URI="mirror://openssl/source/${MY_P}.tar.gz
+       http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/${PN}/${PN}-c_rehash.sh?rev=${REV} -> ${PN}-c_rehash.sh.${REV}"
+
+LICENSE="openssl"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~arm-linux ~x86-linux"
+IUSE="bindist gmp kerberos rfc3779 sctp cpu_flags_x86_sse2 static-libs test +tls-heartbeat vanilla zlib"
+
+# The blocks are temporary just to make sure people upgrade to a
+# version that lack runtime version checking.  We'll drop them in
+# the future.
+RDEPEND="gmp? ( >=dev-libs/gmp-5.1.3-r1[static-libs(+)?,${MULTILIB_USEDEP}] )
+       zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )
+       kerberos? ( >=app-crypt/mit-krb5-1.11.4[${MULTILIB_USEDEP}] )
+       abi_x86_32? (
+               !<=app-emulation/emul-linux-x86-baselibs-20140508
+               !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)]
+       )
+       !<net-misc/openssh-5.9_p1-r4
+       !<net-libs/neon-0.29.6-r1"
+DEPEND="${RDEPEND}
+       sys-apps/diffutils
+       >=dev-lang/perl-5
+       sctp? ( net-misc/lksctp-tools )
+       test? ( sys-devel/bc )"
+PDEPEND="app-misc/ca-certificates"
+
+S="${WORKDIR}/${MY_P}"
+
+MULTILIB_WRAPPED_HEADERS=(
+       usr/include/openssl/opensslconf.h
+)
+
+src_prepare() {
+       SSL_CNF_DIR="/etc/ssl"
+       sed \
+               -e "/^DIR=/s:=.*:=${EPREFIX}${SSL_CNF_DIR}:" \
+               -e "s:SSL_CMD=/usr:SSL_CMD=${EPREFIX}/usr:" \
+               "${DISTDIR}"/${PN}-c_rehash.sh.${REV} \
+               > "${WORKDIR}"/c_rehash || die #416717
+
+       # Make sure we only ever touch Makefile.org and avoid patching a file
+       # that gets blown away anyways by the Configure script in src_configure
+       rm -f Makefile
+
+       epatch "${FILESDIR}"/${P}-CVE-2015-0209.patch #541502
+       epatch "${FILESDIR}"/${P}-CVE-2015-0288.patch #542038
+       if ! use vanilla ; then
+               epatch "${FILESDIR}"/${PN}-1.0.0a-ldflags.patch #327421
+               epatch "${FILESDIR}"/${PN}-1.0.0d-windres.patch #373743
+               epatch "${FILESDIR}"/${PN}-1.0.2-parallel-build.patch
+               epatch "${FILESDIR}"/${PN}-1.0.2-ipv6.patch
+               epatch "${FILESDIR}"/${PN}-1.0.2-s_client-verify.patch #472584
+
+               epatch_user #332661
+       fi
+
+       # disable fips in the build
+       # make sure the man pages are suffixed #302165
+       # don't bother building man pages if they're disabled
+       sed -i \
+               -e '/DIRS/s: fips : :g' \
+               -e '/^MANSUFFIX/s:=.*:=ssl:' \
+               -e '/^MAKEDEPPROG/s:=.*:=$(CC):' \
+               -e $(has noman FEATURES \
+                       && echo '/^install:/s:install_docs::' \
+                       || echo '/^MANDIR=/s:=.*:='${EPREFIX}'/usr/share/man:') \
+               Makefile.org \
+               || die
+       # show the actual commands in the log
+       sed -i '/^SET_X/s:=.*:=set -x:' Makefile.shared
+
+       # since we're forcing $(CC) as makedep anyway, just fix
+       # the conditional as always-on
+       # helps clang (#417795), and versioned gcc (#499818)
+       sed -i 's/expr.*MAKEDEPEND.*;/true;/' util/domd || die
+
+       # quiet out unknown driver argument warnings since openssl
+       # doesn't have well-split CFLAGS and we're making it even worse
+       # and 'make depend' uses -Werror for added fun (#417795 again)
+       [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
+
+       # allow openssl to be cross-compiled
+       cp "${FILESDIR}"/gentoo.config-1.0.1 gentoo.config || die
+       chmod a+rx gentoo.config
+
+       append-flags -fno-strict-aliasing
+       append-flags $(test-flags-CC -Wa,--noexecstack)
+       append-cppflags -DOPENSSL_NO_BUF_FREELISTS
+
+       sed -i '1s,^:$,#!'${EPREFIX}'/usr/bin/perl,' Configure #141906
+       # The config script does stupid stuff to prompt the user.  Kill it.
+       sed -i '/stty -icanon min 0 time 50; read waste/d' config || die
+       ./config --test-sanity || die "I AM NOT SANE"
+
+       multilib_copy_sources
+}
+
+multilib_src_configure() {
+       unset APPS #197996
+       unset SCRIPTS #312551
+       unset CROSS_COMPILE #311473
+
+       tc-export CC AR RANLIB RC
+
+       # Clean out patent-or-otherwise-encumbered code
+       # Camellia: Royalty Free            http://en.wikipedia.org/wiki/Camellia_(cipher)
+       # IDEA:     Expired                 http://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
+       # EC:       ????????? ??/??/2015    http://en.wikipedia.org/wiki/Elliptic_Curve_Cryptography
+       # MDC2:     Expired                 http://en.wikipedia.org/wiki/MDC-2
+       # RC5:      Expirted                http://en.wikipedia.org/wiki/RC5
+
+       use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
+       echoit() { echo "$@" ; "$@" ; }
+
+       local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
+
+       # See if our toolchain supports __uint128_t.  If so, it's 64bit
+       # friendly and can use the nicely optimized code paths. #460790
+       local ec_nistp_64_gcc_128
+       # Disable it for now though #469976
+       #if ! use bindist ; then
+       #       echo "__uint128_t i;" > "${T}"/128.c
+       #       if ${CC} ${CFLAGS} -c "${T}"/128.c -o /dev/null >&/dev/null ; then
+       #               ec_nistp_64_gcc_128="enable-ec_nistp_64_gcc_128"
+       #       fi
+       #fi
+
+       local sslout=$(./gentoo.config)
+       einfo "Use configuration ${sslout:-(openssl knows best)}"
+       local config="Configure"
+       [[ -z ${sslout} ]] && config="config"
+
+       echoit \
+       ./${config} \
+               ${sslout} \
+               $(use sctp && echo "sctp") \
+               $(use cpu_flags_x86_sse2 || echo "no-sse2") \
+               enable-camellia \
+               $(use_ssl !bindist ec) \
+               ${ec_nistp_64_gcc_128} \
+               enable-idea \
+               enable-mdc2 \
+               enable-rc5 \
+               enable-tlsext \
+               $(use_ssl gmp gmp -lgmp) \
+               $(use_ssl kerberos krb5 --with-krb5-flavor=${krb5}) \
+               $(use_ssl rfc3779) \
+               $(use_ssl tls-heartbeat heartbeats) \
+               $(use_ssl zlib) \
+               --prefix="${EPREFIX}"/usr \
+               --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
+               --libdir=$(get_libdir) \
+               shared threads \
+               || die
+
+       # Clean out hardcoded flags that openssl uses
+       local CFLAG=$(grep ^CFLAG= Makefile | LC_ALL=C sed \
+               -e 's:^CFLAG=::' \
+               -e 's:-fomit-frame-pointer ::g' \
+               -e 's:-O[0-9] ::g' \
+               -e 's:-march=[-a-z0-9]* ::g' \
+               -e 's:-mcpu=[-a-z0-9]* ::g' \
+               -e 's:-m[a-z0-9]* ::g' \
+       )
+       sed -i \
+               -e "/^CFLAG/s|=.*|=${CFLAG} ${CFLAGS}|" \
+               -e "/^SHARED_LDFLAGS=/s|$| ${LDFLAGS}|" \
+               Makefile || die
+}
+
+multilib_src_compile() {
+       # depend is needed to use $confopts; it also doesn't matter
+       # that it's -j1 as the code itself serializes subdirs
+       emake -j1 depend
+       emake all
+       # rehash is needed to prep the certs/ dir; do this
+       # separately to avoid parallel build issues.
+       emake rehash
+}
+
+multilib_src_test() {
+       emake -j1 test
+}
+
+multilib_src_install() {
+       emake INSTALL_PREFIX="${D}" install
+}
+
+multilib_src_install_all() {
+       dobin "${WORKDIR}"/c_rehash #333117
+       dodoc CHANGES* FAQ NEWS README doc/*.txt doc/c-indentation.el
+       dohtml -r doc/*
+       use rfc3779 && dodoc engines/ccgost/README.gost
+
+       # This is crappy in that the static archives are still built even
+       # when USE=static-libs.  But this is due to a failing in the openssl
+       # build system: the static archives are built as PIC all the time.
+       # Only way around this would be to manually configure+compile openssl
+       # twice; once with shared lib support enabled and once without.
+       use static-libs || rm -f "${ED}"/usr/lib*/lib*.a
+
+       # create the certs directory
+       dodir ${SSL_CNF_DIR}/certs
+       cp -RP certs/* "${ED}"${SSL_CNF_DIR}/certs/ || die
+       rm -r "${ED}"${SSL_CNF_DIR}/certs/{demo,expired}
+
+       # Namespace openssl programs to prevent conflicts with other man pages
+       cd "${ED}"/usr/share/man
+       local m d s
+       for m in $(find . -type f | xargs grep -L '#include') ; do
+               d=${m%/*} ; d=${d#./} ; m=${m##*/}
+               [[ ${m} == openssl.1* ]] && continue
+               [[ -n $(find -L ${d} -type l) ]] && die "erp, broken links already!"
+               mv ${d}/{,ssl-}${m}
+               # fix up references to renamed man pages
+               sed -i '/^[.]SH "SEE ALSO"/,/^[.]/s:\([^(, ]*(1)\):ssl-\1:g' ${d}/ssl-${m}
+               ln -s ssl-${m} ${d}/openssl-${m}
+               # locate any symlinks that point to this man page ... we assume
+               # that any broken links are due to the above renaming
+               for s in $(find -L ${d} -type l) ; do
+                       s=${s##*/}
+                       rm -f ${d}/${s}
+                       ln -s ssl-${m} ${d}/ssl-${s}
+                       ln -s ssl-${s} ${d}/openssl-${s}
+               done
+       done
+       [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
+
+       dodir /etc/sandbox.d #254521
+       echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED}"/etc/sandbox.d/10openssl
+
+       diropts -m0700
+       keepdir ${SSL_CNF_DIR}/private
+}
+
+pkg_preinst() {
+       has_version ${CATEGORY}/${PN}:0.9.8 && return 0
+       preserve_old_lib /usr/$(get_libdir)/lib{crypto,ssl}.so.0.9.8
+}
+
+pkg_postinst() {
+       ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
+       c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null
+       eend $?
+
+       has_version ${CATEGORY}/${PN}:0.9.8 && return 0
+       preserve_old_lib_notify /usr/$(get_libdir)/lib{crypto,ssl}.so.0.9.8
+}