Connecting to a Server with SSL

To connect to a server with SSL, you need to set up the trust store files and configure the client to use them through SslConfig. To continue from the example of authenticating the server found in "Enabling SSL for the Server", to set up the trust store files and connect to a server with SSL, do the following:
  1. Export the certificate containing the server's public key from the keystore on the server using the following command:
    keytool -export -alias certificatekey \
    -keystore keystore.jks -rfc -file cert.cer
    
  2. Create a trust store on the client machine and import the certificate to it using the following command:
    keytool -import -alias certificatekey \ 
    -file cert.cer -keystore truststore.jks
    
  3. Connect to the server by using BdbServerConnection.connectSsl and specifying the host name, port and a SslConfig:
    SslConfig sslConfig = new SslConfig() 
    .setTrustStore("truststore.jks", "password"); 
    BdbServerConnection conn = 
    BdbServerConnection.connectSsl("localhost", 8080, sslConfig);