∟SslContextTest.java - javax.net.ssl.SSLContext Class Test
This section provides a tutorial example on how to write a simple program to test the java.net.ssl.SSLContext class.
SSL sockets created with the default SSL socket factories will not
have any certificates associated to authenticate them.
In order to associate certificates with SSL sockets, we need to use
the SSLContext class to create SSL socket factories. Here is a
sample program, SslContextTest.java:
Of course, to run this program, you need to have the key store file,
herong.jks, ready. It contains a self-signed pair of private and public
keys. Read my notes on "JCA - Certificates, 'keytool' and 'keystore'",
if you want to use "keytool" to create such a key store file.
If you run this program with JDK 1.5.0, you will get:
Testing socket factory with SSLContext:
SSLContext class: class javax.net.ssl.SSLContext
Protocol: SSLv3
Provider: SunJSSE version 1.5
KeyManagerFactory class: class javax.net.ssl.KeyManagerFactory
Algorithm: SunX509
Provider: SunJSSE version 1.5
KeyStore class: class java.security.KeyStore
Type: JKS
Provider: SUN version 1.5
Size: 1
KeyManager class:
class com.sun.net.ssl.internal.ssl.SunX509KeyManagerImpl
# of key manager: 1
SSLServerSocketFactory class:
class com.sun.net.ssl.internal.ssl.SSLServerSocketFactoryImpl
SSLServerSocket class:
class com.sun.net.ssl.internal.ssl.SSLServerSocketImpl
String: [SSL: ServerSocket[unbound]]
SSLSocketFactory class:
class com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl
SSLSocket class: class com.sun.net.ssl.internal.ssl.SSLSocketImpl
String: 1891d8f[SSL_NULL_WITH_NULL_NULL: Socket[unconnected]]