1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.http; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.lifecycle.CreateException; |
11 | |
import org.mule.api.lifecycle.InitialisationException; |
12 | |
import org.mule.api.security.TlsDirectKeyStore; |
13 | |
import org.mule.api.security.TlsDirectTrustStore; |
14 | |
import org.mule.api.security.TlsIndirectKeyStore; |
15 | |
import org.mule.api.security.TlsProtocolHandler; |
16 | |
import org.mule.api.security.provider.SecurityProviderFactory; |
17 | |
import org.mule.api.security.tls.TlsConfiguration; |
18 | |
import org.mule.transport.ssl.SslServerSocketFactory; |
19 | |
import org.mule.transport.ssl.SslSocketFactory; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.net.ServerSocket; |
23 | |
import java.net.URI; |
24 | |
import java.security.GeneralSecurityException; |
25 | |
import java.security.Provider; |
26 | |
|
27 | |
import javax.net.ssl.KeyManagerFactory; |
28 | |
import javax.net.ssl.SSLServerSocket; |
29 | |
import javax.net.ssl.SSLSocketFactory; |
30 | |
import javax.net.ssl.TrustManagerFactory; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class HttpsConnector extends HttpConnector implements TlsDirectKeyStore, |
37 | |
TlsIndirectKeyStore, TlsDirectTrustStore, TlsProtocolHandler |
38 | |
{ |
39 | |
|
40 | |
public static final String HTTPS = "https"; |
41 | |
public static final String PEER_CERTIFICATES = "PEER_CERTIFICATES"; |
42 | |
public static final String LOCAL_CERTIFICATES = "LOCAL_CERTIFICATES"; |
43 | |
|
44 | |
|
45 | 0 | private TlsConfiguration tls = new TlsConfiguration(null); |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | private long sslHandshakeTimeout = 30000; |
51 | |
|
52 | |
public HttpsConnector(MuleContext context) |
53 | |
{ |
54 | 0 | super(context); |
55 | 0 | setSocketFactory(new SslSocketFactory(tls)); |
56 | 0 | setServerSocketFactory(new SslServerSocketFactory(tls)); |
57 | |
|
58 | 0 | setValidateConnections(false); |
59 | 0 | } |
60 | |
|
61 | |
@Override |
62 | |
protected ServerSocket getServerSocket(URI uri) throws IOException |
63 | |
{ |
64 | 0 | SSLServerSocket serverSocket = (SSLServerSocket) super.getServerSocket(uri); |
65 | 0 | serverSocket.setNeedClientAuth(isRequireClientAuthentication()); |
66 | 0 | return serverSocket; |
67 | |
} |
68 | |
|
69 | |
@Override |
70 | |
protected void doInitialise() throws InitialisationException |
71 | |
{ |
72 | |
|
73 | |
|
74 | |
try |
75 | |
{ |
76 | 0 | tls.initialise(null == getKeyStore(), TlsConfiguration.JSSE_NAMESPACE); |
77 | |
} |
78 | 0 | catch (CreateException e) |
79 | |
{ |
80 | 0 | throw new InitialisationException(e, this); |
81 | 0 | } |
82 | 0 | super.doInitialise(); |
83 | 0 | } |
84 | |
|
85 | |
@Override |
86 | |
public String getProtocol() |
87 | |
{ |
88 | 0 | return HTTPS; |
89 | |
} |
90 | |
|
91 | |
public String getClientKeyStore() |
92 | |
{ |
93 | 0 | return tls.getClientKeyStore(); |
94 | |
} |
95 | |
|
96 | |
public String getClientKeyStorePassword() |
97 | |
{ |
98 | 0 | return tls.getClientKeyStorePassword(); |
99 | |
} |
100 | |
|
101 | |
public String getClientKeyStoreType() |
102 | |
{ |
103 | 0 | return this.tls.getClientKeyStoreType(); |
104 | |
} |
105 | |
|
106 | |
public String getKeyManagerAlgorithm() |
107 | |
{ |
108 | 0 | return tls.getKeyManagerAlgorithm(); |
109 | |
} |
110 | |
|
111 | |
public KeyManagerFactory getKeyManagerFactory() |
112 | |
{ |
113 | 0 | return tls.getKeyManagerFactory(); |
114 | |
} |
115 | |
|
116 | |
public String getKeyPassword() |
117 | |
{ |
118 | 0 | return tls.getKeyPassword(); |
119 | |
} |
120 | |
|
121 | |
public String getKeyAlias() |
122 | |
{ |
123 | 0 | return tls.getKeyAlias(); |
124 | |
} |
125 | |
|
126 | |
public String getKeyStore() |
127 | |
{ |
128 | 0 | return tls.getKeyStore(); |
129 | |
} |
130 | |
|
131 | |
public String getKeyStoreType() |
132 | |
{ |
133 | 0 | return tls.getKeyStoreType(); |
134 | |
} |
135 | |
|
136 | |
public String getProtocolHandler() |
137 | |
{ |
138 | 0 | return tls.getProtocolHandler(); |
139 | |
} |
140 | |
|
141 | |
public Provider getProvider() |
142 | |
{ |
143 | 0 | return tls.getProvider(); |
144 | |
} |
145 | |
|
146 | |
public SecurityProviderFactory getSecurityProviderFactory() |
147 | |
{ |
148 | 0 | return tls.getSecurityProviderFactory(); |
149 | |
} |
150 | |
|
151 | |
public String getSslType() |
152 | |
{ |
153 | 0 | return tls.getSslType(); |
154 | |
} |
155 | |
|
156 | |
public String getKeyStorePassword() |
157 | |
{ |
158 | 0 | return tls.getKeyStorePassword(); |
159 | |
} |
160 | |
|
161 | |
public String getTrustManagerAlgorithm() |
162 | |
{ |
163 | 0 | return tls.getTrustManagerAlgorithm(); |
164 | |
} |
165 | |
|
166 | |
public TrustManagerFactory getTrustManagerFactory() |
167 | |
{ |
168 | 0 | return tls.getTrustManagerFactory(); |
169 | |
} |
170 | |
|
171 | |
public String getTrustStore() |
172 | |
{ |
173 | 0 | return tls.getTrustStore(); |
174 | |
} |
175 | |
|
176 | |
public String getTrustStorePassword() |
177 | |
{ |
178 | 0 | return tls.getTrustStorePassword(); |
179 | |
} |
180 | |
|
181 | |
public String getTrustStoreType() |
182 | |
{ |
183 | 0 | return tls.getTrustStoreType(); |
184 | |
} |
185 | |
|
186 | |
public boolean isExplicitTrustStoreOnly() |
187 | |
{ |
188 | 0 | return tls.isExplicitTrustStoreOnly(); |
189 | |
} |
190 | |
|
191 | |
public boolean isRequireClientAuthentication() |
192 | |
{ |
193 | 0 | return tls.isRequireClientAuthentication(); |
194 | |
} |
195 | |
|
196 | |
public void setClientKeyStore(String clientKeyStore) throws IOException |
197 | |
{ |
198 | 0 | tls.setClientKeyStore(clientKeyStore); |
199 | 0 | } |
200 | |
|
201 | |
public void setClientKeyStorePassword(String clientKeyStorePassword) |
202 | |
{ |
203 | 0 | tls.setClientKeyStorePassword(clientKeyStorePassword); |
204 | 0 | } |
205 | |
|
206 | |
public void setClientKeyStoreType(String clientKeyStoreType) |
207 | |
{ |
208 | 0 | this.tls.setClientKeyStoreType(clientKeyStoreType); |
209 | 0 | } |
210 | |
|
211 | |
public void setExplicitTrustStoreOnly(boolean explicitTrustStoreOnly) |
212 | |
{ |
213 | 0 | tls.setExplicitTrustStoreOnly(explicitTrustStoreOnly); |
214 | 0 | } |
215 | |
|
216 | |
public void setKeyManagerAlgorithm(String keyManagerAlgorithm) |
217 | |
{ |
218 | 0 | tls.setKeyManagerAlgorithm(keyManagerAlgorithm); |
219 | 0 | } |
220 | |
|
221 | |
public void setKeyPassword(String keyPassword) |
222 | |
{ |
223 | 0 | tls.setKeyPassword(keyPassword); |
224 | 0 | } |
225 | |
|
226 | |
public void setKeyAlias(String keyAlias) |
227 | |
{ |
228 | 0 | tls.setKeyAlias(keyAlias); |
229 | 0 | } |
230 | |
|
231 | |
public void setKeyStore(String keyStore) throws IOException |
232 | |
{ |
233 | 0 | tls.setKeyStore(keyStore); |
234 | 0 | } |
235 | |
|
236 | |
public void setKeyStoreType(String keystoreType) |
237 | |
{ |
238 | 0 | tls.setKeyStoreType(keystoreType); |
239 | 0 | } |
240 | |
|
241 | |
public void setProtocolHandler(String protocolHandler) |
242 | |
{ |
243 | 0 | tls.setProtocolHandler(protocolHandler); |
244 | 0 | } |
245 | |
|
246 | |
public void setProvider(Provider provider) |
247 | |
{ |
248 | 0 | tls.setProvider(provider); |
249 | 0 | } |
250 | |
|
251 | |
public void setRequireClientAuthentication(boolean requireClientAuthentication) |
252 | |
{ |
253 | 0 | tls.setRequireClientAuthentication(requireClientAuthentication); |
254 | 0 | } |
255 | |
|
256 | |
public void setSecurityProviderFactory(SecurityProviderFactory spFactory) |
257 | |
{ |
258 | 0 | tls.setSecurityProviderFactory(spFactory); |
259 | 0 | } |
260 | |
|
261 | |
public void setSslType(String sslType) |
262 | |
{ |
263 | 0 | tls.setSslType(sslType); |
264 | 0 | } |
265 | |
|
266 | |
public void setKeyStorePassword(String storePassword) |
267 | |
{ |
268 | 0 | tls.setKeyStorePassword(storePassword); |
269 | 0 | } |
270 | |
|
271 | |
public void setTrustManagerAlgorithm(String trustManagerAlgorithm) |
272 | |
{ |
273 | 0 | tls.setTrustManagerAlgorithm(trustManagerAlgorithm); |
274 | 0 | } |
275 | |
|
276 | |
public void setTrustManagerFactory(TrustManagerFactory trustManagerFactory) |
277 | |
{ |
278 | 0 | tls.setTrustManagerFactory(trustManagerFactory); |
279 | 0 | } |
280 | |
|
281 | |
public void setTrustStore(String trustStore) throws IOException |
282 | |
{ |
283 | 0 | tls.setTrustStore(trustStore); |
284 | 0 | } |
285 | |
|
286 | |
public void setTrustStorePassword(String trustStorePassword) |
287 | |
{ |
288 | 0 | tls.setTrustStorePassword(trustStorePassword); |
289 | 0 | } |
290 | |
|
291 | |
public void setTrustStoreType(String trustStoreType) |
292 | |
{ |
293 | 0 | tls.setTrustStoreType(trustStoreType); |
294 | 0 | } |
295 | |
|
296 | |
public long getSslHandshakeTimeout() |
297 | |
{ |
298 | 0 | return sslHandshakeTimeout; |
299 | |
} |
300 | |
|
301 | |
public void setSslHandshakeTimeout(long sslHandshakeTimeout) |
302 | |
{ |
303 | 0 | this.sslHandshakeTimeout = sslHandshakeTimeout; |
304 | 0 | } |
305 | |
|
306 | |
public SSLSocketFactory getSslSocketFactory() throws GeneralSecurityException |
307 | |
{ |
308 | 0 | return tls.getSocketFactory(); |
309 | |
} |
310 | |
|
311 | |
} |