Hi all,
I've asked something similar before, so apologies if you feel its doubled.
I have a https- Server that I need to connect to using HTTPS and digest
authentication. This works perfect with plain HTTP.
Now for SSL, I implemented a TrustManager with its methods as empty ones
and connected it to the SSLFactory. But the methods
are not even called during the httpclient.execute() call.
Then I switched to TrustStrategy and connected this to the SSLFactory.
Again no way. The isTrusted()- method of TrustStrategy is not even called.
Instead both implementation just abort with
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated.
This is the essential code for TrustManager (X509TrustManager did not
work either)
==============================================================================================
public class ClientTrustManager {
public final static void main(String[] args) throws Exception{
SSLContext ctx = SSLContext.getInstance("TLS");
MyTrustManager tm = new MyTrustManager();
ctx.init (null, new TrustManager []{tm}, null);
SSLSocketFactory socketFactory = new SSLSocketFactory(ctx);
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getConnectionManager().getSchemeRegistry().register(new
Scheme("https", 443, socketFactory));
httpclient.getCredentialsProvider() .setCredentials(new
AuthScope(null, -1, null),
new
UsernamePasswordCredentials("...", "..."));
HttpGet httpget = new HttpGet("https://192.168.111.56/...");
HttpResponse response = httpclient.execute(httpget);
}
}
class MyTrustManager implements TrustManager {
public void checkClientTrusted(java.security.cert.X509Certificate[] xcs,
String string) throws CertificateException {
System.out.println("checkClientTrusted");
}
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
System.out.println("getAcceptedIssuers");
return null;
}
public void checkServerTrusted(java.security.cert.X509Certificate[]
arg0, String arg1) throws CertificateException {
System.out.println("checkServerTrusted");
}
}
And this is the essential code for TrustStrategy:
====================================================================================
public class ClientTrustStrategy {
public final static void main(String[] args) throws Exception{
MyTrustStrategy ts = new MyTrustStrategy();
SSLSocketFactory socketFactory = new SSLSocketFactory(ts);
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getConnectionManager().getSchemeRegistry().register(new
Scheme("https", 443, socketFactory));
httpclient.getCredentialsProvider().setCredentials(new AuthScope(null,
-1, null),
new
UsernamePasswordCredentials("...", "..."));
HttpResponse response = httpclient.execute(httpget);
}
}
class MyTrustStrategy implements TrustStrategy {
public boolean isTrusted(X509Certificate[] arg0, String authString)
throws CertificateException {
System.out.println("MyTrustStrategy.isTrusted:" + authString);
return true;
}
}
====================================================================================
Can somebody sched a light on this ?
Thx for any help
Gerd
The information included in this e-mail and any files transmitted with it is
strictly confidential and may be privileged or otherwise protected from
disclosure. If you are not the intended recipient, please notify the sender
immediately by e-mail and delete this e-mail as well as any attachment from
your system. If you are not the intended recipient you are not authorized to
use and/or copy this message and/or attachment and/or disclose the contents to
any other person.