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
33 import org.apache.hc.core5.http.ssl.TLS;
34 import org.apache.hc.core5.ssl.SSLContexts;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 @Deprecated
63 public class SSLConnectionSocketFactoryBuilder {
64
65 public static SSLConnectionSocketFactoryBuilder create() {
66 return new SSLConnectionSocketFactoryBuilder();
67 }
68
69 private SSLContext sslContext;
70 private String[] tlsVersions;
71 private String[] ciphers;
72 private HostnameVerifier hostnameVerifier;
73 private boolean systemProperties;
74
75
76
77
78
79
80 public SSLConnectionSocketFactoryBuilder setSslContext(final SSLContext sslContext) {
81 this.sslContext = sslContext;
82 return this;
83 }
84
85
86
87
88
89
90 public final SSLConnectionSocketFactoryBuilder setTlsVersions(final String... tlslVersions) {
91 this.tlsVersions = tlslVersions;
92 return this;
93 }
94
95
96
97
98
99
100 public final SSLConnectionSocketFactoryBuilder setTlsVersions(final TLS... tlslVersions) {
101 this.tlsVersions = new String[tlslVersions.length];
102 for (int i = 0; i < tlslVersions.length; i++) {
103 this.tlsVersions[i] = tlslVersions[i].id;
104 }
105 return this;
106 }
107
108
109
110
111
112
113 public final SSLConnectionSocketFactoryBuilder setCiphers(final String... ciphers) {
114 this.ciphers = ciphers;
115 return this;
116 }
117
118
119
120
121
122
123
124 public SSLConnectionSocketFactoryBuilder setHostnameVerifier(final HostnameVerifier hostnameVerifier) {
125 this.hostnameVerifier = hostnameVerifier;
126 return this;
127 }
128
129
130
131
132
133
134
135 public final SSLConnectionSocketFactoryBuilder useSystemProperties() {
136 this.systemProperties = true;
137 return this;
138 }
139
140 public SSLConnectionSocketFactory build() {
141 final javax.net.ssl.SSLSocketFactory socketFactory;
142 if (sslContext != null) {
143 socketFactory = sslContext.getSocketFactory();
144 } else {
145 if (systemProperties) {
146 socketFactory = (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault();
147 } else {
148 socketFactory = SSLContexts.createDefault().getSocketFactory();
149 }
150 }
151 final String[] tlsVersionsCopy;
152 if (tlsVersions != null) {
153 tlsVersionsCopy = tlsVersions;
154 } else {
155 tlsVersionsCopy = systemProperties ? HttpsSupport.getSystemProtocols() : null;
156 }
157 final String[] ciphersCopy;
158 if (ciphers != null) {
159 ciphersCopy = ciphers;
160 } else {
161 ciphersCopy = systemProperties ? HttpsSupport.getSystemCipherSuits() : null;
162 }
163 return new SSLConnectionSocketFactory(
164 socketFactory,
165 tlsVersionsCopy,
166 ciphersCopy,
167 hostnameVerifier != null ? hostnameVerifier : HttpsSupport.getDefaultHostnameVerifier());
168 }
169
170 }