diff options
author | Patrice Clement <monsieurp@gentoo.org> | 2015-06-13 21:24:49 +0000 |
---|---|---|
committer | Patrice Clement <monsieurp@gentoo.org> | 2015-06-13 21:24:49 +0000 |
commit | 52e37073cdac0f7cad9396f6c71888a797c04b36 (patch) | |
tree | 081339f5c28a22e22f97943a09304df581010a32 /www-servers | |
parent | Clean multilib_src_install_all() up. (diff) | |
download | historical-52e37073cdac0f7cad9396f6c71888a797c04b36.tar.gz historical-52e37073cdac0f7cad9396f6c71888a797c04b36.tar.bz2 historical-52e37073cdac0f7cad9396f6c71888a797c04b36.zip |
EAPI 5 bump. Add patch against CVE-2014-3596. Fix security bug 520304.
Signed-off-by: Patrice Clement <monsieurp@gentoo.org>
Package-Manager: portage-2.2.14/cvs/Linux x86_64
Manifest-Sign-Key: 0x93491BB8
Diffstat (limited to 'www-servers')
-rw-r--r-- | www-servers/axis/ChangeLog | 11 | ||||
-rw-r--r-- | www-servers/axis/Manifest | 36 | ||||
-rw-r--r-- | www-servers/axis/axis-1.4-r2.ebuild | 139 | ||||
-rw-r--r-- | www-servers/axis/files/axis-1.4-JSSESocketFactory.java.patch | 342 |
4 files changed, 515 insertions, 13 deletions
diff --git a/www-servers/axis/ChangeLog b/www-servers/axis/ChangeLog index 08f4718de6df..4bd5c3779530 100644 --- a/www-servers/axis/ChangeLog +++ b/www-servers/axis/ChangeLog @@ -1,6 +1,12 @@ # ChangeLog for www-servers/axis -# Copyright 1999-2010 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/www-servers/axis/ChangeLog,v 1.27 2010/01/22 11:32:51 caster Exp $ +# Copyright 1999-2015 Gentoo Foundation; Distributed under the GPL v2 +# $Header: /var/cvsroot/gentoo-x86/www-servers/axis/ChangeLog,v 1.28 2015/06/13 21:24:01 monsieurp Exp $ + +*axis-1.4-r2 (13 Jun 2015) + + 13 Jun 2015; Patrice Clement <monsieurp@gentoo.org> +axis-1.4-r2.ebuild, + +files/axis-1.4-JSSESocketFactory.java.patch: + EAPI 5 bump. Add patch against CVE-2014-3596. Fix security bug 520304. 22 Jan 2010; Vlastimil Babka <caster@gentoo.org> -axis-1.2_rc2-r3.ebuild, -files/axis-1.2-gentoo.patch, -axis-1.4.ebuild: @@ -109,4 +115,3 @@ 22 Jan 2005; Jan Brinkmann <luckyduck@gentoo.org> +metadata.xml, +files/axis-1.2-gentoo.patch, +axis-1.2_rc2.ebuild: Initial import. Ebuild contributions by various people, see #38899. - diff --git a/www-servers/axis/Manifest b/www-servers/axis/Manifest index 58e8a8ecbd35..162de0555244 100644 --- a/www-servers/axis/Manifest +++ b/www-servers/axis/Manifest @@ -1,10 +1,26 @@ -AUX axis-1.4-build.xml.patch 517 RMD160 831d8d2bbf65da81896b5f23127ae78e16beac4e SHA1 210117032afeaa3c4d82f6da38ba7b4586486d33 SHA256 30d1e9a91ee70113720833678b661554d99d89326a41927f1156e33d7712d952 -AUX axis-1.4-java6.patch 450 RMD160 c06a34617b41b611b57cf054b01ba3715d175de4 SHA1 9a3946e080bd56f43e171a00c28f79235f0a0ceb SHA256 5c00ac2e6944e56dcd428113d9a83fcb36e13c3ad9a9bcb9e4159747f384cd0b -AUX axis-1.4-path_refs.xml.patch 762 RMD160 3f6a8bb0288842adee09e75d977d1673f5380a22 SHA1 dea66dc8fb494fccbc4e56c29b4ad9891a87ca12 SHA256 940964f57376c042442c9cb2d6d6ca9ca06566abfa06770025cbbedfe0c1ea8a -AUX axis-1.4-targets.xml.patch 2780 RMD160 f8ecdf60f8285eff52e5946ff738ba305b15bdc9 SHA1 9c3c5693a42f60eddbb9f5aecab823e6ae8921bc SHA256 ea9f43d279ff90a9848cb17956430097533141ada147994d66018c808a66b0e2 -AUX axis-1.4-tools-build.xml.patch 756 RMD160 d62b5c3f7b86e416e52b025ad4527c27743a446b SHA1 3525ee11e6d08a12b588ef599c55b541e68f0b7b SHA256 90609f01b2ed4a598277ad0459fa27433644f8fc4c8ed6a9d22d0ccd6a84213a -AUX build.properties 282 RMD160 3bd03454c8cf97a39d72584bb52d1babfe86a030 SHA1 f2ca5bfdf973cd97295256213383be0246c50a00 SHA256 904c7615612013d7397a7d9580d1b7405f0fb9e3ec70f4a57c0f44b93ccfdfd2 -DIST axis-src-1_4.tar.gz 17041546 RMD160 5bf0a7b6c9708b2217ee06e226255766735ce323 SHA1 52b3703c8e807dc212e06b8c216685b4d18f32b5 SHA256 911b4467f3d6cfe2e50fb7baea7a754e6aa717902d6ed91cef78f8f52bef8572 -EBUILD axis-1.4-r1.ebuild 4053 RMD160 3c88a1138f85b0309c1713103f0a2315004f9d81 SHA1 c59b21be94bc822d7f480bf0aaca441e8bec6b12 SHA256 761e3c4aea8288fc6418d2121b9c12cc9c820e16b761a2ab31b07484fdf11bf9 -MISC ChangeLog 3872 RMD160 3ee605145cfad1fc4d2369c62281076715c9d0bf SHA1 3d8c0f88c0db5582cccb75ad957987a88fe5c961 SHA256 dde60dc08607969c8ea63ea1712990482a6199622c0d6451ef721c7bf0654853 -MISC metadata.xml 742 RMD160 8cdf22b8bb2f82933b9c42fb834d0284eab1a708 SHA1 6e907aeb23531d1390c708450bea8699819eaf1d SHA256 332e698c934cea8ec2bb1ad5600bb7edb69298af92ca92085e3bad370be820ff +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +AUX axis-1.4-JSSESocketFactory.java.patch 11617 SHA256 ede103731117686d4011ab4675f72018c3d39c52689d99a3ce771748af1454a0 SHA512 505ebe73b10e393cf95f925d6bd857f9934f90bd4cc451b8c2db900cdd318f484cf3d880568d4072966f60e2efd24307ce4170e623140c92ed300dff29c82f49 WHIRLPOOL 33f5a77272b79985106bc3304419adbe14e5e4d7ac9be6fb0a3e4628d9ccf9caf44230f7dc71fec5b2eec22edfc62bee68c64fa26c5e451c53da74e5c47e2133 +AUX axis-1.4-build.xml.patch 517 SHA256 30d1e9a91ee70113720833678b661554d99d89326a41927f1156e33d7712d952 SHA512 6df06dee44cd5c882f2afa236438d959e5dafe7134bf191f4a5ba421d3f82fbbc78c7f0ad71267cad356c3c02365b8b112fcea2ed07b0add6c8f41ab5702fc4d WHIRLPOOL 89ca5a32ae358592c1329ea2b3ca9226b43fbecb014f5a6daa138f83ec322fdfbe0a7fa269a943ada2e5495cb78028ab7d7c5ad193de4bcb0a8382217b901a31 +AUX axis-1.4-java6.patch 450 SHA256 5c00ac2e6944e56dcd428113d9a83fcb36e13c3ad9a9bcb9e4159747f384cd0b SHA512 b46ee3d72e00b311608a0dd4668a8324b16a7761944d36621634d2538214d1b9b6c8c41ca336aa702523485db5c65f1eae693052abe6b1e7598745b48e718049 WHIRLPOOL e777a380d9f4afed7c2c3e962b0403e457eeed4c99825dfea11a00e2ddd37331b491030066850d04dab5315990d1fb2e5d38e5de3d3a4ccd9b11553dbd8c51ad +AUX axis-1.4-path_refs.xml.patch 762 SHA256 940964f57376c042442c9cb2d6d6ca9ca06566abfa06770025cbbedfe0c1ea8a SHA512 7adf7c903873fc71953cbd5eea66bb2bba87b2bea0b87c55390eb8738434c7a7d84649c01fbef3c54220a5f878138546ec132ae73c64421fc30fd00138d019ee WHIRLPOOL 80d62d2fe7f8cca4db4bacb31357f10cccd9e52a1fd92b86426d639bc0d0b753f7b30505e0bcc47ebfafe8c4f086a620b5a29cff0c8fcde1ba30cc216d35ae9e +AUX axis-1.4-targets.xml.patch 2780 SHA256 ea9f43d279ff90a9848cb17956430097533141ada147994d66018c808a66b0e2 SHA512 e4b20e5c00814300e35c2ed8591811fe24590c8179763823b4c98440e93298c81ef473d29769bff51360e404d8d384f0edd860f37ef82c1fd40611ecfffc5850 WHIRLPOOL c34fd8e68bb83c17481cd256499324ccc3fc1cec3e1c93d0fd2f449cd1e4aab0f1a455b0111d13c3fd143b4d87f15087f2000e36cd2e0b515fda1faab3c05c02 +AUX axis-1.4-tools-build.xml.patch 756 SHA256 90609f01b2ed4a598277ad0459fa27433644f8fc4c8ed6a9d22d0ccd6a84213a SHA512 675e34a60090e7b3c37838caa6599ddbddaa072a6547b5582e69d49564d0daaead646b7cc0e7c51f3d013749745a5be21a195563d05e0736f011b8c9083cee8b WHIRLPOOL db8b5bd5b38653f65bfe24003610aebff3424a6a2867b3713bfa08961023777bda7747feb4329ed68395c1ac5dd526e3d55bdfeee2b7cc2c46e4494eb439b16e +AUX build.properties 282 SHA256 904c7615612013d7397a7d9580d1b7405f0fb9e3ec70f4a57c0f44b93ccfdfd2 SHA512 917a4c142eb44c630e4db9cfc3c884d3c9eb05e8529510c8ef9581e6b7a20565ea39abbf8aa1cc22b073abb4c600c1a987b148ba1f920f24a115c023e22fd2e5 WHIRLPOOL 48589f24f02d2fce890b9267ec0f3321822ae501cfc1e18e2fff739a8eb2e1bb9070aabeaec7290149b8d26b5e8ff727ed465ccfb344bfb7ec0baa4878467224 +DIST axis-src-1_4.tar.gz 17041546 SHA256 911b4467f3d6cfe2e50fb7baea7a754e6aa717902d6ed91cef78f8f52bef8572 SHA512 7d08212b04702e76c960ad772a475f5765fef7f9ebe0aea3d4b949c6ba28a62500e8a76a43c7364b7caf36b7f27aee8592744256154670c7a24d29c5c1518258 WHIRLPOOL cf359caa9e645bdefb7c2ff012673dc64af9d4cc4bbe2a082cb64bcb0211d3a844ef797738ae1a3e9f978d0bbd8dc42bac9ecbdf4c734dd30ff52da18bdd7a91 +EBUILD axis-1.4-r1.ebuild 4053 SHA256 761e3c4aea8288fc6418d2121b9c12cc9c820e16b761a2ab31b07484fdf11bf9 SHA512 a7355a179ef76f48b755cbf7af126e4238cd8f9487e356fc024897bd162d2396b0038eecc499ab08f14c94ef2af8946baf89b3c53d3a1054d7c6e3f0034b27bb WHIRLPOOL 9ae3eb80b54a5010f0495bf9d2c32344da10a1475f67b4649c9de48432f01a62fdb67d23e7c3279c456146f2023f46e27affcd9861b0a8b880dc97f0f6513068 +EBUILD axis-1.4-r2.ebuild 3985 SHA256 aca866165d123ff82596506892a79b644efba8a052182139f519cd81c156700c SHA512 c7c3e5ff40ed2f26cee8537dd4a86569362330fb8e72067dc17404c53e46469acdd3e23ed6c751769c9090c48f88b408736f84671bb52a29d0e2b3b78916c288 WHIRLPOOL 555a8abd936062b885c43294dc7131ea4bc241163efc15185cdbaba9c5420612db594ca935423d16467f1d76f9d81af3db57ce2ed58256b75356634385610084 +MISC ChangeLog 4099 SHA256 e1a5de791da016c8f9bdda2828c6144f59620c24f2fd906d08472f5e39ad2b88 SHA512 37a96e6c1e681bac1d6c070943565ab6756eaf6296f2f902e8d012729c2b7f8ee0f0e7d442605f8610a81770f01de8ca66d186eb22d77bd7c6dfc58932512447 WHIRLPOOL cb8a2048086ca64adbeb90f96751c212cf586472f9bc790b9f2a38f71ae38aac230480cf29cf01e54c22b114b2531803c0b11611f80ecdf3aef06fa64569510d +MISC metadata.xml 742 SHA256 332e698c934cea8ec2bb1ad5600bb7edb69298af92ca92085e3bad370be820ff SHA512 46ae800820ebe071b57a3fc5de573152413399a2db1401d2f9edded1a24f6ae316a019871bef70be04ce45a4103c045b063f59d87399f7f1c466ca3ecbdb1e2f WHIRLPOOL 8a8fb0b6bfbcd3003d3722538439e13d97368a6dd82b21d2cfc2483d8f02c1fabbdb9d7b6113b8f8b294d7d5c584faaf261047fe27244f547ac5025f520b7d61 +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v2 + +iQEcBAEBCAAGBQJVfJ8RAAoJEJGRpfGTSRu452gIAJ6TE0lyL/tyxfKI8OgV7/mU +vmvT/TwgLzzfFLhafm6JzY4v3+Dc5jUmSFrrXUsY4Et6ksBBhaNLqX8e5ndt+FLJ +alsSXgjTxrZNmfGFTO5GcwKG/OTp2nx1O4X+X13VA5plPZjt/flH+cVBFaj3QV+n +yQU+bGmKTZmjciZ8KUdLRBOCi/9ari3qXPmE3/rfEaVFfP/j6SnPucTiN/FXY+D5 +JwXj+KnLz36BeqEhjnKnEMXvBZQ6ZbiLbzkHzaLysFxPvY4FSbVoze0NcX0oiqnN +20dJrn7p7AbDWzpIOQZkzfBikM1rJpol/sn3EPr27QoWmb4isTHiXZX3hn/Xt9M= +=Qt+7 +-----END PGP SIGNATURE----- diff --git a/www-servers/axis/axis-1.4-r2.ebuild b/www-servers/axis/axis-1.4-r2.ebuild new file mode 100644 index 000000000000..3cb80392431c --- /dev/null +++ b/www-servers/axis/axis-1.4-r2.ebuild @@ -0,0 +1,139 @@ +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/www-servers/axis/axis-1.4-r2.ebuild,v 1.1 2015/06/13 21:24:01 monsieurp Exp $ + +EAPI=5 + +WANT_ANT_TASKS="ant-nodeps ant-trax" +JAVA_PKG_IUSE="doc source examples" + +inherit eutils java-pkg-2 java-ant-2 + +MY_PV="${PV//./_}" +MY_P="${PN}-${MY_PV}" + +DESCRIPTION="Apache's Axis1 implementation of the SOAP (Simple Object Access Protocol)" +HOMEPAGE="http://ws.apache.org/axis/index.html" +SRC_URI="mirror://apache/ws/${PN}/${MY_PV}/${PN}-src-${MY_PV}.tar.gz" + +LICENSE="Apache-2.0" +SLOT="1" +KEYWORDS="~amd64 ~x86" +IUSE="debug" + +CDEPEND="dev-java/commons-discovery:0 + dev-java/wsdl4j:0 + dev-java/sun-jaf:0 + dev-java/commons-logging:0 + java-virtuals/javamail:0 + dev-java/ant-core:0 + dev-java/bsf:2.3 + dev-java/castor:1.0 + dev-java/commons-httpclient:3 + dev-java/commons-net:0 + dev-java/sun-jimi:0 + dev-java/servletapi:2.4 + dev-java/saaj:0 + dev-java/jax-rpc:0 + dev-java/log4j:0 + dev-java/xml-commons:0 + dev-java/xml-xmlbeans:1" + +RDEPEND=">=virtual/jre-1.6 + ${CDEPEND}" + +DEPEND=">=virtual/jdk-1.6 + ${CDEPEND}" + +# uses enum as identifier +JAVA_PKG_WANT_SOURCE="1.4" +JAVA_PKG_WANT_TARGET="1.4" + +S="${WORKDIR}/${MY_P}" + +AXIS_NAME="${PN}-${SLOT}" + +# not declared mandatory but fails without it +# mailapi.jar would be enough but that's only in -bin, mail.jar superseedes +EANT_GENTOO_CLASSPATH="sun-jaf,javamail,log4j,xml-xmlbeans-1,servletapi-2.4,bsf-2.3,sun-jimi,commons-httpclient-3,castor-1.0,xml-commons,commons-net" +EANT_EXTRA_ARGS="-Ddeprecation=false -Dbase.path=/opt +-Dservlet.jar=servlet-api.jar -Dwsdl4j-1.5.1.jar=wsdl4j.jar +-Dcommons-logging-1.0.4.jar=commons-logging.jar" +EANT_BUILD_TARGET="compile" +EANT_DOC_TARGET="javadocs" +EANT_NEEDS_TOOLS="true" + +#TODO-tests require Atlassian clover, need to figure out which ones +RESTRICT="test" + +java_prepare() { + # remove some <copy> actions + epatch "${FILESDIR}/${P}-build.xml.patch" + # remove exact lib paths and global java.classpath from classpath + epatch "${FILESDIR}/${P}-path_refs.xml.patch" + # add missing target to javac, xml rewriting would break entities + epatch "${FILESDIR}/${P}-tools-build.xml.patch" + # remove most of <available> checks + epatch "${FILESDIR}/${P}-targets.xml.patch" + # this clashes with java6 method + epatch "${FILESDIR}/${P}-java6.patch" + + # fix CVE-2014-3596 and bug 520304 + epatch "${FILESDIR}/${P}-JSSESocketFactory.java.patch" + + # and replace them with predefined properties + cp "${FILESDIR}/build.properties" . \ + || die "failed to copy build.properties from ${FILESDIR}" + + rm -rf "${S}"/docs/apiDocs || die + + #Remove test till they are working + rm -rf "${S}"/test || die + #cd "${S}"/test + #mv build_ant.xml build.xml + cd "${S}"/webapps/axis/WEB-INF/lib + rm -v *.jar || die + + cd "${S}/lib" + mv saaj.jar endorsed/ || die + rm -v *.jar || die + java-pkg_jar-from --build-only ant-core + java-pkg_jar-from wsdl4j wsdl4j.jar + java-pkg_jar-from commons-logging commons-logging.jar + java-pkg_jar-from commons-discovery commons-discovery.jar + + if use debug; then + EANT_EXTRA_ARGS+=" -Ddebug=on" + else + EANT_EXTRA_ARGS+=" -Ddebug=off" + fi + + cd "${S}" + java-ant_rewrite-classpath + java-ant_rewrite-bootclasspath auto build.xml "lib/endorsed/xml-apis-2.6.2.jar:lib/endorsed/xercesImpl-2.6.2.jar:lib/endorsed/saaj.jar" + sed -i '/<bootclasspath refid="boot.classpath"/d' build.xml || die +} + +src_install() { + dodir /usr/share/${AXIS_NAME} + mv build/lib/axis-ant.jar build/lib/ant-axis.jar || die + java-pkg_dojar build/lib/axis.jar + java-pkg_dojar build/lib/ant-axis.jar + java-pkg_dojar build/lib/jaxrpc.jar + java-pkg_register-ant-task + dodir /usr/share/${AXIS_NAME}/webapps + + cp -pR "${S}"/webapps/axis "${D}"/usr/share/${AXIS_NAME}/webapps || die + + dodoc NOTICE README + dohtml release-notes.html changelog.html + + if use doc; then + java-pkg_dojavadoc build/javadocs/ + dohtml -r docs/* + dodoc xmls/* + fi + + use source && java-pkg_dosrc src + use examples && java-pkg_doexamples samples +} diff --git a/www-servers/axis/files/axis-1.4-JSSESocketFactory.java.patch b/www-servers/axis/files/axis-1.4-JSSESocketFactory.java.patch new file mode 100644 index 000000000000..1309115295d1 --- /dev/null +++ b/www-servers/axis/files/axis-1.4-JSSESocketFactory.java.patch @@ -0,0 +1,342 @@ +--- src/org/apache/axis/components/net/JSSESocketFactory.java (revision 1618775) ++++ src/org/apache/axis/components/net/JSSESocketFactory.java (working copy) +@@ -15,12 +15,6 @@ + */ + package org.apache.axis.components.net; + +-import org.apache.axis.utils.Messages; +-import org.apache.axis.utils.XMLUtils; +-import org.apache.axis.utils.StringUtils; +- +-import javax.net.ssl.SSLSocket; +-import javax.net.ssl.SSLSocketFactory; + import java.io.BufferedWriter; + import java.io.IOException; + import java.io.InputStream; +@@ -28,9 +22,35 @@ + import java.io.OutputStreamWriter; + import java.io.PrintWriter; + import java.net.Socket; ++import java.security.cert.Certificate; ++import java.security.cert.CertificateParsingException; ++import java.security.cert.X509Certificate; ++import java.util.ArrayList; ++import java.util.Arrays; ++import java.util.Collection; + import java.util.Hashtable; ++import java.util.Iterator; ++import java.util.LinkedList; ++import java.util.List; ++import java.util.Locale; ++import java.util.regex.Pattern; + ++import javax.naming.InvalidNameException; ++import javax.naming.NamingException; ++import javax.naming.directory.Attribute; ++import javax.naming.directory.Attributes; ++import javax.naming.ldap.LdapName; ++import javax.naming.ldap.Rdn; ++import javax.net.ssl.SSLException; ++import javax.net.ssl.SSLSession; ++import javax.net.ssl.SSLSocket; ++import javax.net.ssl.SSLSocketFactory; + ++import org.apache.axis.utils.Messages; ++import org.apache.axis.utils.StringUtils; ++import org.apache.axis.utils.XMLUtils; ++ ++ + /** + * SSL socket factory. It _requires_ a valid RSA key and + * JSSE. (borrowed code from tomcat) +@@ -41,6 +61,10 @@ + */ + public class JSSESocketFactory extends DefaultSocketFactory implements SecureSocketFactory { + ++ // This is a a sorted list, if you insert new elements do it orderdered. ++ private final static String[] BAD_COUNTRY_2LDS = ++ {"ac", "co", "com", "ed", "edu", "go", "gouv", "gov", "info", ++ "lg", "ne", "net", "or", "org"}; + /** Field sslFactory */ + protected SSLSocketFactory sslFactory = null; + +@@ -187,6 +211,279 @@ + if (log.isDebugEnabled()) { + log.debug(Messages.getMessage("createdSSL00")); + } ++ verifyHostName(host, (SSLSocket) sslSocket); + return sslSocket; + } ++ /** ++ * Verifies that the given hostname in certicifate is the hostname we are trying to connect to. ++ * This resolves CVE-2012-5784 and CVE-2014-3596 ++ * @param host ++ * @param ssl ++ * @throws IOException ++ */ ++ ++ private static void verifyHostName(String host, SSLSocket ssl) ++ throws IOException { ++ if (host == null) { ++ throw new IllegalArgumentException("host to verify was null"); ++ } ++ ++ SSLSession session = ssl.getSession(); ++ if (session == null) { ++ // In our experience this only happens under IBM 1.4.x when ++ // spurious (unrelated) certificates show up in the server's chain. ++ // Hopefully this will unearth the real problem: ++ InputStream in = ssl.getInputStream(); ++ in.available(); ++ /* ++ If you're looking at the 2 lines of code above because you're ++ running into a problem, you probably have two options: ++ ++ #1. Clean up the certificate chain that your server ++ is presenting (e.g. edit "/etc/apache2/server.crt" or ++ wherever it is your server's certificate chain is ++ defined). ++ ++ OR ++ ++ #2. Upgrade to an IBM 1.5.x or greater JVM, or switch to a ++ non-IBM JVM. ++ */ ++ ++ // If ssl.getInputStream().available() didn't cause an exception, ++ // maybe at least now the session is available? ++ session = ssl.getSession(); ++ if (session == null) { ++ // If it's still null, probably a startHandshake() will ++ // unearth the real problem. ++ ssl.startHandshake(); ++ ++ // Okay, if we still haven't managed to cause an exception, ++ // might as well go for the NPE. Or maybe we're okay now? ++ session = ssl.getSession(); ++ } ++ } ++ ++ Certificate[] certs = session.getPeerCertificates(); ++ verifyHostName(host.trim().toLowerCase(Locale.US), (X509Certificate) certs[0]); ++ } ++ /** ++ * Extract the names from the certificate and tests host matches one of them ++ * @param host ++ * @param cert ++ * @throws SSLException ++ */ ++ ++ private static void verifyHostName(final String host, X509Certificate cert) ++ throws SSLException { ++ // I'm okay with being case-insensitive when comparing the host we used ++ // to establish the socket to the hostname in the certificate. ++ // Don't trim the CN, though. ++ ++ String[] cns = getCNs(cert); ++ String[] subjectAlts = getDNSSubjectAlts(cert); ++ verifyHostName(host, cns, subjectAlts); ++ ++ } ++ ++ /** ++ * Extract all alternative names from a certificate. ++ * @param cert ++ * @return ++ */ ++ private static String[] getDNSSubjectAlts(X509Certificate cert) { ++ LinkedList subjectAltList = new LinkedList(); ++ Collection c = null; ++ try { ++ c = cert.getSubjectAlternativeNames(); ++ } catch (CertificateParsingException cpe) { ++ // Should probably log.debug() this? ++ cpe.printStackTrace(); ++ } ++ if (c != null) { ++ Iterator it = c.iterator(); ++ while (it.hasNext()) { ++ List list = (List) it.next(); ++ int type = ((Integer) list.get(0)).intValue(); ++ // If type is 2, then we've got a dNSName ++ if (type == 2) { ++ String s = (String) list.get(1); ++ subjectAltList.add(s); ++ } ++ } ++ } ++ if (!subjectAltList.isEmpty()) { ++ String[] subjectAlts = new String[subjectAltList.size()]; ++ subjectAltList.toArray(subjectAlts); ++ return subjectAlts; ++ } else { ++ return new String[0]; ++ } ++ ++ } ++ /** ++ * Verifies ++ * @param host ++ * @param cn ++ * @param subjectAlts ++ * @throws SSLException ++ */ ++ ++ private static void verifyHostName(final String host, String[] cns, String[] subjectAlts)throws SSLException{ ++ StringBuffer cnTested = new StringBuffer(); ++ ++ for (int i = 0; i < subjectAlts.length; i++){ ++ String name = subjectAlts[i]; ++ if (name != null) { ++ name = name.toLowerCase(Locale.US); ++ if (verifyHostName(host, name)){ ++ return; ++ } ++ cnTested.append("/").append(name); ++ } ++ } ++ for (int i = 0; i < cns.length; i++) { ++ String cn = cns[i]; ++ if (cn != null) { ++ cn = cn.toLowerCase(Locale.US); ++ if (verifyHostName(host, cn)) { ++ return; ++ } ++ cnTested.append("/").append(cn); ++ } ++ } ++ throw new SSLException("hostname in certificate didn't match: <" ++ + host + "> != <" + cnTested + ">"); ++ } ++ ++ private static boolean verifyHostName(final String host, final String cn){ ++ if (doWildCard(cn) && !isIPAddress(host)) { ++ return matchesWildCard(cn, host); ++ } ++ return host.equalsIgnoreCase(cn); ++ } ++ private static boolean doWildCard(String cn) { ++ // Contains a wildcard ++ // wildcard in the first block ++ // not an ipaddress (ip addres must explicitily be equal) ++ // not using 2nd level common tld : ex: not for *.co.uk ++ String parts[] = cn.split("\\."); ++ return parts.length >= 3 && ++ parts[0].endsWith("*") && ++ acceptableCountryWildcard(cn) && ++ !isIPAddress(cn); ++ } ++ ++ private static final Pattern IPV4_PATTERN = ++ Pattern.compile("^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$"); ++ ++ private static final Pattern IPV6_STD_PATTERN = ++ Pattern.compile("^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$"); ++ ++ private static final Pattern IPV6_HEX_COMPRESSED_PATTERN = ++ Pattern.compile("^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$"); ++ ++ ++ private static boolean isIPAddress(final String hostname) { ++ return hostname != null ++ && ( ++ IPV4_PATTERN.matcher(hostname).matches() ++ || IPV6_STD_PATTERN.matcher(hostname).matches() ++ || IPV6_HEX_COMPRESSED_PATTERN.matcher(hostname).matches() ++ ); ++ ++ } ++ ++ private static boolean acceptableCountryWildcard(final String cn) { ++ // The CN better have at least two dots if it wants wildcard action, ++ // but can't be [*.co.uk] or [*.co.jp] or [*.org.uk], etc... ++ // The [*.co.uk] problem is an interesting one. Should we just ++ // hope that CA's would never foolishly allow such a ++ // certificate to happen? ++ ++ String[] parts = cn.split("\\."); ++ // Only checks for 3 levels, with country code of 2 letters. ++ if (parts.length > 3 || parts[parts.length - 1].length() != 2) { ++ return true; ++ } ++ String countryCode = parts[parts.length - 2]; ++ return Arrays.binarySearch(BAD_COUNTRY_2LDS, countryCode) < 0; ++ } ++ ++ private static boolean matchesWildCard(final String cn, ++ final String hostName) { ++ String parts[] = cn.split("\\."); ++ boolean match = false; ++ String firstpart = parts[0]; ++ if (firstpart.length() > 1) { ++ // server∗ ++ // e.g. server ++ String prefix = firstpart.substring(0, firstpart.length() - 1); ++ // skipwildcard part from cn ++ String suffix = cn.substring(firstpart.length()); ++ // skip wildcard part from host ++ String hostSuffix = hostName.substring(prefix.length()); ++ match = hostName.startsWith(prefix) && hostSuffix.endsWith(suffix); ++ } else { ++ match = hostName.endsWith(cn.substring(1)); ++ } ++ if (match) { ++ // I f we ’ r e i n s t r i c t mode , ++ // [ ∗.foo.com] is not allowed to match [a.b.foo.com] ++ match = countDots(hostName) == countDots(cn); ++ } ++ return match; ++ } ++ ++ private static int countDots(final String data) { ++ int dots = 0; ++ for (int i = 0; i < data.length(); i++) { ++ if (data.charAt(i) == '.') { ++ dots += 1; ++ } ++ } ++ return dots; ++ } ++ ++ ++ private static String[] getCNs(X509Certificate cert) { ++ // Note: toString() seems to do a better job than getName() ++ // ++ // For example, getName() gives me this: ++ // 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d ++ // ++ // whereas toString() gives me this: ++ // EMAILADDRESS=juliusdavies@cucbc.com ++ String subjectPrincipal = cert.getSubjectX500Principal().toString(); ++ ++ return getCNs(subjectPrincipal); ++ ++ } ++ private static String[] getCNs(String subjectPrincipal) { ++ if (subjectPrincipal == null) { ++ return null; ++ } ++ final List cns = new ArrayList(); ++ try { ++ final LdapName subjectDN = new LdapName(subjectPrincipal); ++ final List rdns = subjectDN.getRdns(); ++ for (int i = rdns.size() - 1; i >= 0; i--) { ++ final Rdn rds = (Rdn) rdns.get(i); ++ final Attributes attributes = rds.toAttributes(); ++ final Attribute cn = attributes.get("cn"); ++ if (cn != null) { ++ try { ++ final Object value = cn.get(); ++ if (value != null) { ++ cns.add(value.toString()); ++ } ++ } ++ catch (NamingException ignore) {} ++ } ++ } ++ } ++ catch (InvalidNameException ignore) { } ++ return cns.isEmpty() ? null : (String[]) cns.toArray(new String[ cns.size() ]); ++ } ++ + } |