---
schema_version: "1"
id: bcbd301066294e4fc972f92607473e31dda0352fd122bddb4ad6c06b4c7478fe
title: TLS Configuration
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-sdk/latest/tls.md
canonical_url: https://docs.mulesoft.com/mule-sdk/latest/tls
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 8ef1d222638c90d1305e95448ff74df834914d6ffc36d839a8a50f8616ab5440
description: MuleSoft Documentation Site
release: "1.13"
latest: true
---
---
product: Mule SDK
version: 1.13
is-latest-version: true
keywords: mule, sdk, security, tls
---

# TLS Configuration

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Adding support for TLS configuration in your module is as simple as declaring a
[parameter](https://docs.mulesoft.com/mule-sdk/latest/parameters) of type `TlsContextFactory`, for example:

```java
@Parameter
@Optional
private TlsContextFactory tlsContextFactory;
```

The example above will automatically generate support for this XML setting:

```xml
<tls:context enabledProtocols="TLSv1.2,SSLv3">
    <tls:trust-store path="my-trust-store.jks" password="myPassword"/>
    <tls:key-store path="my-key-store.jks" keyPassword="myPassword" password="myPassword"/>
</tls:context>
```

Note that a TLS context can also be defined as a global element of your app, so you can reference it
by its name anywhere you need to use it.

If TLS needs are hidden from the user (for example, if you need to connect safely to a service
internally), you can create your own `TlsContextFactory` using its builder:

```java
private final TlsContextFactory tlsContextFactory = TlsContextFactory.builder()
                                                        .trustStorePath("tls/trustStore")
                                                        .trustStorePassword("mulepassword")
                                                        .build()
```

This builder also allows creating default instances of `TlsContextFactory`:

```java
private final TlsContextFactory defaultTlsContextFactory = TlsContextFactory.builder().buildDefault();
```

Once a `TlsContextFactory` is available (whether as a parameter or obtained through its builder), it
should be initialized, for example:

```java
if (tlsContextFactory instanceof Initialisable) {
  ((Initialisable) tlsContextFactory).initialise();
}
```

It can then be used to obtain an `SSLContext`, a `SSLSocketFactory` or a `SSLServerSocketFactory`.
It can also obtain enabled TLS protocols and cipher suites, allowing you to set up most Java
components that use TLS/SSL as shown in the examples below.

You could set up a
[FTPSClient](https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPSClient.html)
by obtaining an
[SSLContext](https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html) and then
configure the protocols and cipher suites for it:

```java
SSLContext sslContext = tlsContextFactory.createSslContext();
String[] enabledProtocols = tlsContextFactory.getEnabledProtocols();
String[] enabledCiphers = tlsContextFactory.getEnabledCipherSuites();

FTPSClient client = new FTPSClient(sslContext);
client.setEnabledProtocols(enabledProtocols);
client.setEnabledCipherSuites(enabledCiphers);
```

You could obtain an
[SSLSocketFactory](https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLSocketFactory.html) to
create your own [Socket](https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html):

```java
SSLSocketFactory sslSocketFactory = tlsContextFactory.createSocketFactory();
Socket socket = sslSocketFactory.create();
```

To create a
[ServerSocket](https://docs.oracle.com/javase/8/docs/api/java/net/ServerSocket.html)instead, you can
obtain an
[SSLServerSocketFactory](https://docs.oracle.com/javase/8/docs/api/index.html?javax/net/ssl/SSLServerSocketFactory.html):

```java
SSLServerSocketFactory sslServerSocketFactory = tlsContextFactory.createServerSocketFactory();
ServerSocket socket = sslServerSocketFactory.createServerSocket();
```

To correctly configure TLS context and all the available parameters that you can set, see
[Configure TLS with Keystores and Truststores](https://docs.mulesoft.com/mule-runtime/latest/tls-configuration).
