-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSSLConnConstructor.java
More file actions
35 lines (31 loc) · 1.08 KB
/
SSLConnConstructor.java
File metadata and controls
35 lines (31 loc) · 1.08 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
package com.genexus.internet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;
import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
public class SSLConnConstructor {
public static SSLConnectionSocketFactory getSSLSecureInstance(String[] supportedProtocols) {
try {
SSLContext sslContext = SSLContextBuilder
.create()
.loadTrustMaterial(new TrustSelfSignedStrategy())
.build();
return new SSLConnectionSocketFactory(
sslContext,
supportedProtocols,
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
e.printStackTrace();
}
return new SSLConnectionSocketFactory(
SSLContexts.createDefault(),
supportedProtocols,
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
}
}