Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,62 @@ This will also install the Telesign Self-service Java SDK since it is a dependen

If you use a Telesign SDK to make your request, authentication is handled behind-the-scenes for you. All you need to provide is your Customer ID and API Key. The SDKs apply Digest authentication whenever they make a request to a Telesign service where it is supported. When Digest authentication is not supported, the SDKs apply Basic authentication.

## SMPP TLSv1.2 Configuration

To configure SMPP TLSv1.2 in your Java application, follow these steps:

1. Ensure that your Java application is using Java 8 or later, as specified in the `build.gradle` file.
2. Use the `javax.net.ssl` package to configure the SSL/TLS settings in your Java application.
3. Set the desired encryption cipher by specifying it in the SSL/TLS configuration.

Here is an example of how to configure SSL/TLS settings and set the desired encryption cipher:

```java
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class SmppTlsClient extends RestClient {

public SmppTlsClient(String customerId, String apiKey, String restEndpoint) {
super(customerId, apiKey, restEndpoint);
configureSslSettings();
}

private void configureSslSettings() {
try {
// Load the certificate
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream caInput = getClass().getResourceAsStream("/path/to/your/certificate.crt");
X509Certificate ca = (X509Certificate) cf.generateCertificate(caInput);

// Create a KeyStore containing the trusted certificate
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);

// Create a TrustManager that trusts the certificate in the KeyStore
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
X509TrustManager trustManager = (X509TrustManager) tmf.getTrustManagers()[0];

// Create an SSLContext that uses the TrustManager
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, new javax.net.ssl.TrustManager[]{trustManager}, null);

// Set the SSLContext to be used by the RestClient
setSslSocketFactory(sslContext.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
}
```

## What's next

* Learn to send a request to Telesign with code with one of our [tutorials](https://developer.telesign.com/enterprise/docs/tutorials).
Expand Down
40 changes: 39 additions & 1 deletion src/main/java/com/telesign/enterprise/MessagingClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.telesign.enterprise;

import java.io.IOException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.InputStream;
import java.net.Proxy;
import java.security.KeyStore;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -15,10 +22,12 @@ public class MessagingClient extends com.telesign.RestClient {
public MessagingClient(String customerId, String apiKey) {

super(customerId, apiKey, "https://rest-ww.telesign.com");
configureSslSettings();
}

public MessagingClient(String customerId, String apiKey, String restEndpoint) {
super(customerId, apiKey, restEndpoint);
configureSslSettings();
}

public MessagingClient(String customerId,
Expand All @@ -31,6 +40,35 @@ public MessagingClient(String customerId,
final String proxyUsername,
final String proxyPassword) {
super(customerId, apiKey, restEndpoint, connectTimeout, readTimeout, writeTimeout, proxy, proxyUsername, proxyPassword);
configureSslSettings();
}

private void configureSslSettings() {
try {
// Load the certificate
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream caInput = getClass().getResourceAsStream("/path/to/your/certificate.crt");
X509Certificate ca = (X509Certificate) cf.generateCertificate(caInput);

// Create a KeyStore containing the trusted certificate
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);

// Create a TrustManager that trusts the certificate in the KeyStore
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
X509TrustManager trustManager = (X509TrustManager) tmf.getTrustManagers()[0];

// Create an SSLContext that uses the TrustManager
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, new javax.net.ssl.TrustManager[]{trustManager}, null);

// Set the SSLContext to be used by the RestClient
setSslSocketFactory(sslContext.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}

/**
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/telesign/enterprise/SmppTlsClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.telesign.enterprise;

import com.telesign.RestClient;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.InputStream;
import java.net.Proxy;
import java.security.KeyStore;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class SmppTlsClient extends RestClient {

public SmppTlsClient(String customerId, String apiKey, String restEndpoint) {
super(customerId, apiKey, restEndpoint);
configureSslSettings();
}

private void configureSslSettings() {
try {
// Load the certificate
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream caInput = getClass().getResourceAsStream("/path/to/your/certificate.crt");
X509Certificate ca = (X509Certificate) cf.generateCertificate(caInput);

// Create a KeyStore containing the trusted certificate
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);

// Create a TrustManager that trusts the certificate in the KeyStore
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
X509TrustManager trustManager = (X509TrustManager) tmf.getTrustManagers()[0];

// Create an SSLContext that uses the TrustManager
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, new javax.net.ssl.TrustManager[]{trustManager}, null);

// Set the SSLContext to be used by the RestClient
setSslSocketFactory(sslContext.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Loading