Client-Side Authentication
Learn how to modify the FTP client to create a channel using two way authentication.
Our FTP server is now configured to run in two modes: IN-secure (without using any security credentials) and secure (using root, server, and client certificates). In this lesson, we will modify the FTP client project and add certificates as well as a mechanism to create the channel using two-way authentication.
Client configuration properties
For a secure connection, the client needs to verify its identity. The client needs the root CA certificate, client certificate and client key for this purpose. We will specify the paths of these files in a configuration file client.config.properties
in the resources directory src/main/resources/
in the ftp-service-client
project.
CLIENT_KEY_PATH=target/certs/clientKey.pexmCLIENT_CERT_PATH=target/certs/clientCert.pemCA_CERT_PATH=target/certs/rootCACert.pem
Loading client configuration
After defining the client.config.properties
configuration file, we will create a class called ClientConfiguration
in the io/datajek/ftpservice/utils
package. This class loads the contents of the configuration file. You can find the explanation of the code shown below in the Server and Client Configuration Properties lesson.
The ClientConfiguration
class is shown below:
/** Copyright 2023, DataJek.io* All Rights Reserved*/package io.datajek.ftpservice.utils;import java.io.IOException;import java.io.InputStream;import java.util.Properties;/*** This class manages the configuration settings for the client.*/public class ClientConfiguration {private Properties properties;public ClientConfiguration() {try (InputStream input =ClientConfiguration.class.getClassLoader().getResourceAsStream("client.config.properties")) {properties = new Properties();properties.load(input);} catch (IOException e) {// log.error("Cannot read in config file", e);}}public String getCAPath() {return properties.getProperty(ClientConstants.CA_CERT_PATH);}public String getClientCertPath() {return properties.getProperty(ClientConstants.CLIENT_CERT_PATH);}public String getClientKeyPath() {return properties.getProperty(ClientConstants.CLIENT_KEY_PATH);}}
Adding client constants
We have created a utility class named ClientConstants