Connecting to a Server with SSL

To connect to a server with SSL, you need to setup 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 setup 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 key store 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. Then, 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);