-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSmppTlsClient.java
More file actions
48 lines (39 loc) · 1.87 KB
/
SmppTlsClient.java
File metadata and controls
48 lines (39 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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();
}
}
}