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 this requires that HTTP is enabled on the server, and will not be secure. This document describes how to load a certificate from the file system at runtime to enable secure TLS communication.
Prerequisites:
-
Ensure you have properly enabled TLS and created and configured TLS certificates on the server.
- See create a server certificate and configure TLS for a server.
-
You must create a separate server certificate for each computer that runs a FairCom server.
- Each FairCom server must be configured to use the appropriate server certificate for the computer on which it runs.
Steps:
- Copy the CA certificate to the machine running the tutorial, and note the directory it is saved to.
- Locate the
ServerConnection serverConnection = new ServerConnection()code block in the source code. - Change the endpoint to a secure endpoint:
endpoint: https://127.0.0.1:8443/api - Between
.endpointand.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();
- Run the tutorial.
- 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.