Hey,
I have the following code:
System.setProperty("javax.net.ssl.trustStore","c:\keyStore.kst");
SSLContext sslContext = SSLContext.getInstance("SSLv3");
sslContext.init(new Keymanager[] { new Keymanager() }, new
X509TrustManager[] { new MyTrustManager() }, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
HttpsURLConnection.setDefaultHostnameVerifier(new MyHostnameVerifier());
What i would like is to avoid hardcoding the string ","c:\keyStore.kst", and
avoid creating this file with the keytool-program. Instead i would like to
import the file "something.crt" directly into the program. So the
"c:\keyStore.kst" is replaced with som kind of object. Is this possiable?
Brian
Chris Head - 20 Jun 2005 16:54 GMT
> Hey,
>
[quoted text clipped - 13 lines]
>
> Brian
Hi,
How about you use java.security.cert.CertificateFactory to load your
certificate file and get a java.security.cert.Certificate (which will be
an instance of java.security.cert.X509Certificate). You can then create
a new java.security.KeyStore, import your certificate into it, and then
use it as a parameter to javax.net.ssl.TrustManagerFactory.init(). Use
javax.net.ssl.TrustManagerFactory.getTrustManagers() to retrieve the
TrustManager objects to pass into javax.net.ssl.SSLContext.init(). You
don't need to write the KeyStore to a file this way. You can then use
javax.net.ssl.SSLContext.getSocketFactory() or
javax.net.ssl.SSLContext.getServerSocketFactory() to get the appropriate
Factory to create Sockets.
Chris