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 package org.apache.hc.client5.http.ssl;
29
30 import javax.net.ssl.HostnameVerifier;
31 import javax.net.ssl.SSLContext;
32 import javax.net.ssl.SSLEngine;
33 import javax.net.ssl.SSLParameters;
34
35 import org.apache.hc.core5.annotation.Contract;
36 import org.apache.hc.core5.annotation.ThreadingBehavior;
37 import org.apache.hc.core5.function.Factory;
38 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
39 import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
40 import org.apache.hc.core5.reactor.ssl.TlsDetails;
41 import org.apache.hc.core5.ssl.SSLContexts;
42
43
44
45
46
47
48 @Contract(threading = ThreadingBehavior.STATELESS)
49 public class DefaultClientTlsStrategy extends AbstractClientTlsStrategy {
50
51 public static TlsStrategy getDefault() {
52 return new DefaultClientTlsStrategy(
53 SSLContexts.createDefault(),
54 HttpsSupport.getDefaultHostnameVerifier());
55 }
56
57 public static TlsStrategy getSystemDefault() {
58 return new DefaultClientTlsStrategy(
59 SSLContexts.createSystemDefault(),
60 HttpsSupport.getSystemProtocols(),
61 HttpsSupport.getSystemCipherSuits(),
62 SSLBufferMode.STATIC,
63 HttpsSupport.getDefaultHostnameVerifier());
64 }
65
66
67
68
69 @Deprecated
70 private Factory<SSLEngine, TlsDetails> tlsDetailsFactory;
71
72
73
74
75 @Deprecated
76 public DefaultClientTlsStrategy(
77 final SSLContext sslContext,
78 final String[] supportedProtocols,
79 final String[] supportedCipherSuites,
80 final SSLBufferMode sslBufferManagement,
81 final HostnameVerifier hostnameVerifier,
82 final Factory<SSLEngine, TlsDetails> tlsDetailsFactory) {
83 super(sslContext, supportedProtocols, supportedCipherSuites, sslBufferManagement, hostnameVerifier);
84 this.tlsDetailsFactory = tlsDetailsFactory;
85 }
86
87 public DefaultClientTlsStrategy(
88 final SSLContext sslContext,
89 final String[] supportedProtocols,
90 final String[] supportedCipherSuites,
91 final SSLBufferMode sslBufferManagement,
92 final HostnameVerifier hostnameVerifier) {
93 super(sslContext, supportedProtocols, supportedCipherSuites, sslBufferManagement, hostnameVerifier);
94 }
95
96 public DefaultClientTlsStrategy(
97 final SSLContext sslContext,
98 final HostnameVerifier hostnameVerifier) {
99 this(sslContext, null, null, SSLBufferMode.STATIC, hostnameVerifier);
100 }
101
102 public DefaultClientTlsStrategy(final SSLContext sslContext) {
103 this(sslContext, HttpsSupport.getDefaultHostnameVerifier());
104 }
105
106 @Override
107 void applyParameters(final SSLEngine sslEngine, final SSLParameters sslParameters, final String[] appProtocols) {
108 sslParameters.setApplicationProtocols(appProtocols);
109 sslEngine.setSSLParameters(sslParameters);
110 }
111
112 @Override
113 @SuppressWarnings("deprecated")
114 TlsDetails createTlsDetails(final SSLEngine sslEngine) {
115 return tlsDetailsFactory != null ? tlsDetailsFactory.create(sslEngine) : null;
116 }
117
118 }