Truststore and Keystore in MuleSoft: A Beginner's Guide to SSL/TLS Certificates and Handshakes
Secure communication is key in modern integrations, and MuleSoft heavily relies on SSL/TLS protocols for this purpose. Truststores and keystores play a significant role in ensuring secure communication. This guide will help you understand what truststores and keystores are, why they're important, and what happens before and during the SSL/TLS handshake in MuleSoft.
A truststore is a collection of trusted certificates that a client uses
to validate a server's identity during secure communication. In the context of
MuleSoft, the truststore ensures that the server's certificate is from a
reputable source, has not expired, and forms a valid chain back to a trusted
root certificate authority (CA).
What Is a Keystore?
A keystore, on the other hand, is a secure storage for certificates and private keys. In MuleSoft, keystores are typically used on the server side to present the server's certificate during SSL/TLS handshakes, ensuring secure communication.
In a nutshell
During communication between a client and a server, the server presents its certificate (Keystore, commonly in .pfx format) to the client. The client verifies this certificate against its truststore (often a .jks file). If the certificate is valid, the client and server complete an SSL/TLS handshake, establishing a secure connection.
For example, When Mulesoft connect to a server (say amazon.in for simplicity) over HTTPS the server presents a certificate that validates its identity and Mulesoft will verify the same using the truststore configured.
However, the certificate presented by the server (amazon.in) isn't isolated—it is part of a chain of certificates that leads to a trusted authority. The typical certificate chain includes:
Root
certificate
Intermediate certificate
End-Entity Certificate
This is the server certificate issued to the website itself. It represents the identity of the website
This certificate typically contains:
1. The domain name it is issued for.
2. The public key used for encryption and digital signature verification.
3. Information about the certificate's issuer.
4. The validity period.
5. Other metadata like key usage and digital signature.
Intermediate certificate
This is an intermediate certificate issued by a Certificate Authority (CA).
This certificate typically
1. Acts as a bridge between the end-entity certificate and the root certificate.
2. Is signed by the root certificate, establishing a chain of trust.
3. Contains the public key, validity period, and issuer information (the root certificate).
Root Certificate
Is the ultimate source of trust in the certificate chain and is issued by a well-known Certificate Authority.
Root certificates are at the top of the certificate hierarchy and are self-signed.
They are trusted because they are part of the system's or application’s list of trusted CAs.
How?
open the target endpoint in a web browser like Chrome or Edge.
Step 2: View Certificate Details
In Google chrome/Microsoft Edge
Click the padlock
icon in the address bar.
Select
"Certificate" or "Certificate (Valid)".
In the Certificate
window, click the "Details" tab.
Step 3: Export Certificates
Step 4: Create a Truststore with
Keytool
Once you've exported the necessary certificates,
you can create a Java KeyStore (JKS), the format often used in MuleSoft, using
a tool like keytool:
keytool -importcert
-file <exported_certificate_path> -keystore <truststore_name>.jks
-alias <certificate_alias>
Replace <exported_certificate_path>, <truststore_name>, <certificate_alias> with
appropriate values for your setup.
Enter a password
for truststore and verify it again.
Step 5: Configure the Truststore in MuleSoft
- 1-Way SSL/TLS: Only the server presents a certificate to the client, which verifies it for a secure connection. Common for public-facing endpoints.
- 2-Way SSL/TLS: Both the client and server exchange certificates for mutual verification, providing a higher level of security and trust. Often used in more sensitive or secure communications.
Now lets take few example to understand the handshake over HTTPS using keystore and truststore
As client is hitting Mulesoft endpoint, we will be using a “listener“
In general-> TLS configurations, you will find “truststore configuration” and “keystore configuration”
In one way validation, only the server has to validate itself (In our case - Mulesoft) and client verify it using the trustore configured
1.Initiation of Connection: Client initiates a connection to a target system using Request connector via HTTPS, indicating that SSL/TLS is in use.
2.Mulesoft Sends Its Certificate: During the handshake, Mulesoft sends its certificate to client.
3.Client side Validation: Client verifies Mulesoft certificate by validating the digital signature, checking the certificate chain to ensure it leads back to a trusted root certificate, confirming the certificate's validity period, and verifying that the certificate hasn't been revoked.
4.Secure Communication Established: If the certificate passes validation, the client and server complete the SSL/TLS handshake, establishing a secure, encrypted communication channel.
Assumptions – Target is exposing an endpoint
Mulesoft is hitting it to post some data,
expected validation – one way
Here, In Mulesoft we will be using “request” connector to connect with the target
In general-> TLS configurations, you will find “truststore configuration” and “keystore configuration”
In one way validation, only the target(server) has to validate itself and Mulesoft will verify it using the trustore configured
2.Server(Target system) Sends Its Certificate: During the handshake, server sends its certificate to mulesoft.
3.Validation in Mulesoft: MuleSoft verifies a server certificate using the truststore by validating the digital signature, checking the certificate chain to ensure it leads back to a trusted root certificate, confirming the certificate's validity period, and verifying that the certificate hasn't been revoked.
4.Secure Communication Established: If the certificate passes validation, the client and server complete the SSL/TLS handshake, establishing a secure, encrypted communication channel.
### Did you noticed
something?? ###
But in scenario 2, Did the Client explicitly made a truststore out of mulesoft certificate?? Probably Not. Also, while you hit Mulesoft endpoint via postman/browser you do not have to explicitly make a truststore certificate
Why?
*** What
if a service/client other than Postman or web browser doesn’t have built-in
truststore?
In
that case, we have to convert mulesoft’s .pfx certicate either .pem or .crt or
.cer and passon this public certificate to the client and ask them to make a
truststore out of it and configure it at their end
As the client is hitting the mulesoft endpoint, we will be using a “listener“
In general-> TLS configurations, you will find “truststore configuration” and “keystore configuration”
As it is two way validation, we will have to configure both “truststore configuration” and “keystore configuration”
1.Initiation of Connection: Client initiates a connection to a target system using Request connector via HTTPS, indicating that SSL/TLS is in use.
2.Mulesoft Sends Its Certificate: During the handshake, Mulesoft sends its certificate to client.
3.Client side Validation: Client verifies Mulesoft certificate by validating the digital signature, checking the certificate chain to ensure it leads back to a trusted root certificate, confirming the certificate's validity period, and verifying that the certificate hasn't been revoked.
4.Client Sends Its Certificate: During the handshake, Mulesoft sends its certificate to client.
5.Mulesoft side validation: Mulesoft verifies client certificate by validating the digital signature, checking the certificate chain to ensure it leads back to a trusted root certificate, confirming the certificate's validity period, and verifying that the certificate hasn't been revoked.
6.Secure Communication Established: If the certificate passes validation, the client and server complete the SSL/TLS handshake, establishing a secure, encrypted communication channel.
Comments
Post a Comment