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