Hi,

I brought this up on the commons dev thread and forgot
to post the idea here.

You'll need to write your own implementation of the
SecureProtocolSocketFactory to replace the
SSLProtocolSocketFactory implementation.  Add a
socketFactory argument to the constructor of this
class and use the socket factory instead of the calls
to SSLSocketFactory.getDefault() used in
SSLProtocolSocketFactory.

I think this idea ought to replace
SSLProtocolSocketFactory FWIW.  I just hadn't had time
to send it in or type up the code for it yet.

Eric Johnson (not the one that regularly contributes,
but one that might like to in the near future.)

:)

--- Carlos_Cort�s_del_Valle_de_la_Lastra
<[EMAIL PROTECTED]> wrote:
> I have a problem using httpclient classes. I need
> connect through https protocol with PostMethod. But,
> when I execute the method, an Exception ocurred
> because it doesn't find the certificate i've created
> for this
> 
> public class RobotImpl{
> 
>     //Init server...    
>     public void iniciar() throws ExceptionGlobal{
>         try{
>                 URL u = new
> URL("https://localhost:8443/Jsp2.jsp";);
>                 org.apache.commons.httpclient.URI
> uri=new org.apache.commons.httpclient.URI(u);
>                 HttpClient client = new
> HttpClient();
>                 HostConfiguration hc = new
> HostConfiguration();
>                 hc.setHost(uri);
>                 client.setHostConfiguration(hc);
>                 client.setTimeout(30000);
> 
> 
>                 PostMethod post = new
> PostMethod("https://localhost:8443/Jsp2.jsp";);
> 
>                 int iResultCode =
> client.executeMethod(post);
>         }
>         catch................
> ...
> }//end code
> 
> 
> 
> Exception Message
> 
> javax.net.ssl.SSLHandshakeException:
> java.security.cert.CertificateException: Couldn't
> find trusted certificate
>  at
>
com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
>  at
>
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
>  at
>
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
>  at
>
com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
>  at
>
com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
>  at
>
com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)...........
> ....
> 
> 
> I tried to create a trust manager that does not
> validate certificate chains, but it doesn't works...
> this is the code
> 
> TrustManager[] trustAllCerts = new TrustManager[]{
>     new X509TrustManager() {
>     public java.security.cert.X509Certificate[]
> getAcceptedIssuers() {
>         return null;
>     }
>     public void checkClientTrusted(
>             java.security.cert.X509Certificate[]
> certs, String authType) {
>     }
>     public void checkServerTrusted(
>             java.security.cert.X509Certificate[]
> certs, String authType) {
>     }
>     }
> };
> // Install the all-trusting trust manager
> try {
>     SSLContext sc = SSLContext.getInstance("SSL");
>     sc.init(null, trustAllCerts, new
> java.security.SecureRandom());
>    
>
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
> } catch (Exception e) {
> }
> 
> 
> thanks for advance,
> Carlos


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to