Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

SSL client connection

  Asked By: Adella    Date: Jan 31    Category: Java    Views: 964
  

I am trying to launch a ssl page through a servlet .
my code snipet is:


try {
int port = 443;
String hostname = "hostname";
SocketFactory socketFactory = SSLSocketFactory.getDefault();
Socket socket = socketFactory.createSocket(hostname, port);

// Create streams to securely send and receive data to the server
InputStream in = soc ket.getInputStream();

***** while( readLine=in.readln() ) { // Read from in and write to out...
out.write(readLine) ;
}
// Close the socket
in.close();
out.close();
} catch(IOException e) {
}

it gives me validator exception: trusted certificate not found

how can I fix it ? considering this servlet is as a client for ssl

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Abana Cohen     Answered On: Jan 31

You obviously are connecting to a server, whose ssl
certificate does not lead to a root in the default
trust collection delivered with the JRE.

To persuade the ssl  connection with another
certificate or a set of them first you should provide
your own trust manager; aka an implementation of

javax.net.ssl.X509TrustManager

Let's say it is called MyTrustManager. There you put
all your own customized business logic to check and
control ssl certificates.

Then before your acquiring the ssl factory you forge
that trust manager to ssl context using


SSLContext sslContext =
SLContext.getInstance("SSLv3");
MyTrustManager tm = new MyTrustManager(...[whatever
param makes sense to you e.g. set of certificates you
will accept or a file including them]),
TrustManager tms[] = {tm};
sslContext.init(null, tms, null);
SocketFactory socketFactory =
sslContxt.getSocketFactory();

And then you go ahead establishing a connection  to
servers as you entitled before.

 
Didn't find what you were looking for? Find more on SSL client connection Or get search suggestion and latest updates.




Tagged: