commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From teknokrat <teknok...@yahoo.com>
Subject httpclient and ssl
Date Thu, 19 May 2005 16:17:34 GMT
I am trying to set up httpclient to replace another ad hoc class we 
have. It uses https. HttpClient fails the ssl handshake. The current 
class has the following in a static initializer

    static {
         SSLContext context;
         SSLSocketFactory ssf;
         try {
              X509TrustManager trustManager = new X509TrustManager() {
                 public X509Certificate[] getAcceptedIssuers() {
                     return null;
                 }

                 public void checkClientTrusted(X509Certificate[] arg0, 
tring arg1)
                     throws CertificateException {
                 }

                 public void checkServerTrusted(X509Certificate[] arg0, 
String arg1)
                     throws CertificateException {
                 }
             };

             HostnameVerifier verifier = new HostnameVerifier() {
                 public boolean verify(String arg0, SSLSession arg2) {
                     return true;
                 }
             };

             TrustManager[] tma = {trustManager};
             context = SSLContext.getInstance("SSLv3");
             context.init(null, tma, null);

             ssf = context.getSocketFactory();
             HttpsURLConnection.setDefaultHostnameVerifier(verifier);
             HttpsURLConnection.setDefaultSSLSocketFactory(ssf);
         }
         catch (GeneralSecurityException e) {
             // if this has failed, we wont allow https connections
             failedToInitialize = true;
         }
     }

It works fine. Does anyone understand why this works and why HttpClient 
fails?

thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message