[Schmitzm-commits] r2401 - trunk/schmitzm-core/src/main/java/de/schmitzm/io
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Mon May 19 18:56:07 CEST 2014
Author: mojays
Date: 2014-05-19 18:56:07 +0200 (Mon, 19 May 2014)
New Revision: 2401
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
Log:
IOUtil: new TRUST_ALL_HOSTNAME_VERIFIER; ignoring hostname verify during downloadUrlToFile(..)
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java 2014-03-29 01:33:55 UTC (rev 2400)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java 2014-05-19 16:56:07 UTC (rev 2401)
@@ -77,9 +77,11 @@
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
+import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
@@ -155,8 +157,19 @@
}
} };
-
+
/**
+ * Hostename verifier that does not validate any hostname in certificate.<br>
+ * @see http://stackoverflow.com/questions/19540289/how-to-fix-the-java-security-cert-certificateexception-no-subject-alternative
+ */
+ public static final HostnameVerifier TRUST_ALL_HOSTNAME_VERIFIER = new HostnameVerifier() {
+ @Override
+ public boolean verify(String hostname, SSLSession session) {
+ return true;
+ }
+ };
+
+ /**
* Liefert den Index des Dateinames, an der die Dateinamen-Erweiterung
* (inkl. Punkt) beginnt.
*
@@ -855,6 +868,9 @@
// opening the InputStream
connection = openConnection(url, user, password, proxy, connTimeout, readTimeout);
((HttpsURLConnection)connection).setSSLSocketFactory(sslSocketFactory);
+ // Install the all-trusting hostname verifier
+ ((HttpsURLConnection)connection).setHostnameVerifier(TRUST_ALL_HOSTNAME_VERIFIER);
+
input = connection.getInputStream();
LOGGER.warn("SSL connecion established ignoring any certificate!");
} catch (Exception e) {
More information about the Schmitzm-commits
mailing list