Skip to main content

TLS in Java for JSON DB API

Use TLS in Java for JSON DB API

Abstract

Use TLS in Java for JSON DB API

This document shows how to configure TLS in the FairCom JSON DB API tutorial. The source code is in

<faircom>\drivers\java.json.db\tutorials\src\main\java\org\example\JsonActionExample.java

The tutorial can be run without modification, but will not be secure.  This document describes how to load a certificate from the file system at runtime which will enable secure TLS communications.

Prerequisites:
Steps:
  1. Copy the CA certificate to the machine running the tutorial, and note the directory it is saved to.

  2. Locate the ServerConnection serverConnection = new ServerConnection() code block in the source code.

  3. Change the endpoint to a secure endpoint:

    endpoint: https://127.0.0.1:8443/api

  4. Between .endpoint and .configure, designate the location of the CA certificate file you saved:

    .caCertificatePath( "/path/to/my/ca.crt" )

    The final code block looks like this:

    ServerConnection serverConnection = new ServerConnection()
       .endpoint( "https://127.0.0.1:8443/api" )
       .caCertificatePath( "/path/to/my/ca.crt" )
       .configure();
  5. Run the tutorial.

Note

  • The CA certificate must sign the server certificate.  A self-signed certificate will not work.

  • The Java client library for the FairCom JSON Action APIs provides additional methods to configure a secure connection, such as using a Java keystore or trustManagers.