@Override
 public HttpDownloadResult postUrlUnsecure(
     final URL url,
     final Integer timeOut,
     final Map<String, String> data,
     final HttpHeader httpHeader)
     throws HttpDownloaderException {
   final TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManagerAllowAll()};
   final SSLSocketFactory orgSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
   final HostnameVerifier orgHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
   try {
     final SSLContext sc = SSLContext.getInstance("SSL");
     sc.init(null, trustAllCerts, new java.security.SecureRandom());
     final HostnameVerifier hv = new HostnameVerifierAllowAll();
     HttpsURLConnection.setDefaultHostnameVerifier(hv);
     HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
     return postUrlSecure(url, timeOut, data, httpHeader);
   } catch (final NoSuchAlgorithmException e) {
     logger.error("NoSuchAlgorithmException", e);
     throw new HttpDownloaderException("NoSuchAlgorithmException", e);
   } catch (final KeyManagementException e) {
     logger.error("KeyManagementException", e);
     throw new HttpDownloaderException("KeyManagementException", e);
   } finally {
     HttpsURLConnection.setDefaultHostnameVerifier(orgHostnameVerifier);
     HttpsURLConnection.setDefaultSSLSocketFactory(orgSSLSocketFactory);
   }
 }
Beispiel #2
0
  private void trustEveryone() {
    // TODO : this should actually not be everyone -- but only the one we accept
    try {
      if (defaultVerifier == null) {
        defaultVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
      }
      if (defaultSSLSocketFactory == null) {
        defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
      }
      HttpsURLConnection.setDefaultHostnameVerifier(
          new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
              return true;
            }
          });
      SSLContext context = SSLContext.getInstance("TLS");
      context.init(
          null,
          new X509TrustManager[] {
            new X509TrustManager() {
              public void checkClientTrusted(X509Certificate[] chain, String authType)
                  throws CertificateException {}

              public void checkServerTrusted(X509Certificate[] chain, String authType)
                  throws CertificateException {}

              public X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[0];
              }
            }
          },
          new SecureRandom());
      HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
    } catch (Exception e) { // should never happen
      e.printStackTrace();
    }
  }
 /**
  * Creates the default SSL socket factory. This constructor is used exclusively to instantiate the
  * factory for {@link #getSocketFactory getSocketFactory}.
  */
 private LMSSLSocketFactory() {
   super();
   this.sslcontext = null;
   this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
   this.nameResolver = null;
 }