View Javadoc

1   /*
2    * $Id: SslConnector.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.ssl;
12  
13  import org.mule.providers.tcp.TcpConnector;
14  import org.mule.umo.lifecycle.InitialisationException;
15  import org.mule.umo.security.TlsDirectKeyStore;
16  import org.mule.umo.security.TlsDirectTrustStore;
17  import org.mule.umo.security.TlsIndirectKeyStore;
18  import org.mule.umo.security.provider.SecurityProviderFactory;
19  import org.mule.umo.security.tls.TlsConfiguration;
20  
21  import java.io.IOException;
22  import java.net.ServerSocket;
23  import java.net.URI;
24  import java.security.Provider;
25  
26  import javax.net.ssl.KeyManagerFactory;
27  import javax.net.ssl.SSLServerSocket;
28  import javax.net.ssl.TrustManagerFactory;
29  
30  /**
31   * <code>SslConnector</code> provides a connector for SSL connections.
32   * Note that the *only* function of the code in this package is to configure and
33   * provide SSL enabled sockets.  All other logic is identical to TCP.
34   */
35  public class SslConnector extends TcpConnector
36  implements TlsDirectKeyStore, TlsIndirectKeyStore, TlsDirectTrustStore
37  {
38  
39      // null initial keystore - see below
40      private TlsConfiguration tls = new TlsConfiguration(null);
41  
42      public SslConnector()
43      {
44          setSocketFactory(new SslSocketFactory(tls));
45          setServerSocketFactory(new SslServerSocketFactory(tls));
46          // setting this true causes problems as socket closes before handshake finishes
47          setValidateConnections(false);
48      }
49  
50      // @Override
51      protected void doInitialise() throws InitialisationException
52      {
53          super.doInitialise();
54          // the original logic here was slightly different to other uses of the TlsSupport code -
55          // it appeared to be equivalent to switching anon by whether or not a keyStore was defined
56          // (which seems to make sense), so that is used here.
57          tls.initialise(null == getKeyStore(), TlsConfiguration.JSSE_NAMESPACE);
58      }
59  
60      // @Override
61      protected ServerSocket getServerSocket(URI uri) throws IOException
62      {
63          SSLServerSocket serverSocket = (SSLServerSocket) super.getServerSocket(uri);
64          serverSocket.setNeedClientAuth(isRequireClientAuthentication());
65          return serverSocket;
66      }
67  
68      // @Override
69      public String getProtocol()
70      {
71          return "SSL";
72      }
73  
74      public String getClientKeyStore()
75      {
76          return tls.getClientKeyStore();
77      }
78  
79      public String getClientKeyStorePassword()
80      {
81          return tls.getClientKeyStorePassword();
82      }
83  
84      public String getClientKeyStoreType()
85      {
86          return this.tls.getClientKeyStoreType();
87      }
88  
89      public String getKeyManagerAlgorithm()
90      {
91          return tls.getKeyManagerAlgorithm();
92      }
93  
94      public KeyManagerFactory getKeyManagerFactory()
95      {
96          return tls.getKeyManagerFactory();
97      }
98  
99      public String getKeyPassword()
100     {
101         return tls.getKeyPassword();
102     }
103 
104     public String getKeyStore()
105     {
106         return tls.getKeyStore();
107     }
108 
109     public String getKeystoreType()
110     {
111         return tls.getKeystoreType();
112     }
113 
114     public String getProtocolHandler()
115     {
116         return tls.getProtocolHandler();
117     }
118 
119     public Provider getProvider()
120     {
121         return tls.getProvider();
122     }
123 
124     public SecurityProviderFactory getSecurityProviderFactory()
125     {
126         return tls.getSecurityProviderFactory();
127     }
128 
129     public String getSslType()
130     {
131         return tls.getSslType();
132     }
133 
134     public String getStorePassword()
135     {
136         return tls.getStorePassword();
137     }
138 
139     public String getTrustManagerAlgorithm()
140     {
141         return tls.getTrustManagerAlgorithm();
142     }
143 
144     public TrustManagerFactory getTrustManagerFactory()
145     {
146         return tls.getTrustManagerFactory();
147     }
148 
149     public String getTrustStore()
150     {
151         return tls.getTrustStore();
152     }
153 
154     public String getTrustStorePassword()
155     {
156         return tls.getTrustStorePassword();
157     }
158 
159     public String getTrustStoreType()
160     {
161         return tls.getTrustStoreType();
162     }
163 
164     public boolean isExplicitTrustStoreOnly()
165     {
166         return tls.isExplicitTrustStoreOnly();
167     }
168 
169     public boolean isRequireClientAuthentication()
170     {
171         return tls.isRequireClientAuthentication();
172     }
173 
174     public void setClientKeyStore(String clientKeyStore) throws IOException
175     {
176         tls.setClientKeyStore(clientKeyStore);
177     }
178 
179     public void setClientKeyStorePassword(String clientKeyStorePassword)
180     {
181         tls.setClientKeyStorePassword(clientKeyStorePassword);
182     }
183 
184     public void setClientKeyStoreType(String clientKeyStoreType)
185     {
186         this.tls.setClientKeyStoreType(clientKeyStoreType);
187     }
188 
189     public void setExplicitTrustStoreOnly(boolean explicitTrustStoreOnly)
190     {
191         tls.setExplicitTrustStoreOnly(explicitTrustStoreOnly);
192     }
193 
194     public void setKeyManagerAlgorithm(String keyManagerAlgorithm)
195     {
196         tls.setKeyManagerAlgorithm(keyManagerAlgorithm);
197     }
198 
199     public void setKeyPassword(String keyPassword)
200     {
201         tls.setKeyPassword(keyPassword);
202     }
203 
204     public void setKeyStore(String keyStore) throws IOException
205     {
206         tls.setKeyStore(keyStore);
207     }
208 
209     public void setKeystoreType(String keystoreType)
210     {
211         tls.setKeystoreType(keystoreType);
212     }
213 
214     public void setProtocolHandler(String protocolHandler)
215     {
216         tls.setProtocolHandler(protocolHandler);
217     }
218 
219     public void setProvider(Provider provider)
220     {
221         tls.setProvider(provider);
222     }
223 
224     public void setRequireClientAuthentication(boolean requireClientAuthentication)
225     {
226         tls.setRequireClientAuthentication(requireClientAuthentication);
227     }
228 
229     public void setSecurityProviderFactory(SecurityProviderFactory spFactory)
230     {
231         tls.setSecurityProviderFactory(spFactory);
232     }
233 
234     public void setSslType(String sslType)
235     {
236         tls.setSslType(sslType);
237     }
238 
239     public void setStorePassword(String storePassword)
240     {
241         tls.setStorePassword(storePassword);
242     }
243 
244     public void setTrustManagerAlgorithm(String trustManagerAlgorithm)
245     {
246         tls.setTrustManagerAlgorithm(trustManagerAlgorithm);
247     }
248 
249     public void setTrustManagerFactory(TrustManagerFactory trustManagerFactory)
250     {
251         tls.setTrustManagerFactory(trustManagerFactory);
252     }
253 
254     public void setTrustStore(String trustStore) throws IOException
255     {
256         tls.setTrustStore(trustStore);
257     }
258 
259     public void setTrustStorePassword(String trustStorePassword)
260     {
261         tls.setTrustStorePassword(trustStorePassword);
262     }
263 
264     public void setTrustStoreType(String trustStoreType)
265     {
266         tls.setTrustStoreType(trustStoreType);
267     }
268 
269 }