Coverage Report - org.mule.transport.ssl.SslConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
SslConnector
0%
0/79
0%
0/2
0
 
 1  
 /*
 2  
  * $Id: SslConnector.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.ssl;
 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.tcp.TcpConnector;
 23  
 import org.mule.transport.tcp.protocols.DirectProtocol;
 24  
 
 25  
 import java.io.IOException;
 26  
 import java.net.ServerSocket;
 27  
 import java.net.URI;
 28  
 import java.security.Provider;
 29  
 
 30  
 import javax.net.ssl.KeyManagerFactory;
 31  
 import javax.net.ssl.SSLServerSocket;
 32  
 import javax.net.ssl.TrustManagerFactory;
 33  
 
 34  
 /**
 35  
  * <code>SslConnector</code> provides a connector for SSL connections.
 36  
  * Note that the *only* function of the code in this package is to configure and
 37  
  * provide SSL enabled sockets.  All other logic is identical to TCP.
 38  
  */
 39  
 public class SslConnector extends TcpConnector
 40  
         implements TlsDirectKeyStore, TlsIndirectKeyStore, TlsDirectTrustStore, TlsProtocolHandler
 41  
 {
 42  
 
 43  
     public static final String SSL = "ssl";
 44  
     public static final String PEER_CERTIFICATES = "PEER_CERTIFICATES";
 45  
     public static final String LOCAL_CERTIFICATES = "LOCAL_CERTIFICATES";
 46  
 
 47  
     // null initial keystore - see below
 48  0
     private TlsConfiguration tls = new TlsConfiguration(null);
 49  
 
 50  
     /**
 51  
      * Timeout for establishing the SSL connection with the client.
 52  
      */
 53  0
     private long sslHandshakeTimeout = 30000;
 54  
     
 55  
     public SslConnector(MuleContext context)
 56  
     {
 57  0
         super(context);
 58  0
         setSocketFactory(new SslSocketFactory(tls));
 59  0
         setServerSocketFactory(new SslServerSocketFactory(tls));
 60  0
         setTcpProtocol(new DirectProtocol());
 61  
         // setting this true causes problems as socket closes before handshake finishes
 62  0
         setValidateConnections(false);
 63  0
     }
 64  
 
 65  
     @Override
 66  
     protected void doInitialise() throws InitialisationException
 67  
     {
 68  0
         super.doInitialise();
 69  
         // the original logic here was slightly different to other uses of the TlsSupport code -
 70  
         // it appeared to be equivalent to switching anon by whether or not a keyStore was defined
 71  
         // (which seems to make sense), so that is used here.
 72  
         try
 73  
         {
 74  0
             tls.initialise(null == getKeyStore(), TlsConfiguration.JSSE_NAMESPACE);
 75  
         }
 76  0
         catch (CreateException e)
 77  
         {
 78  0
             throw new InitialisationException(e, this);
 79  0
         }
 80  0
     }
 81  
 
 82  
     @Override
 83  
     protected ServerSocket getServerSocket(URI uri) throws IOException
 84  
     {
 85  0
         SSLServerSocket serverSocket = (SSLServerSocket) super.getServerSocket(uri);
 86  0
         serverSocket.setNeedClientAuth(isRequireClientAuthentication());
 87  0
         return serverSocket;
 88  
     }
 89  
 
 90  
     @Override
 91  
     public String getProtocol()
 92  
     {
 93  0
         return SSL;
 94  
     }
 95  
 
 96  
     public String getClientKeyStore()
 97  
     {
 98  0
         return tls.getClientKeyStore();
 99  
     }
 100  
 
 101  
     public String getClientKeyStorePassword()
 102  
     {
 103  0
         return tls.getClientKeyStorePassword();
 104  
     }
 105  
 
 106  
     public String getClientKeyStoreType()
 107  
     {
 108  0
         return this.tls.getClientKeyStoreType();
 109  
     }
 110  
 
 111  
     public String getKeyManagerAlgorithm()
 112  
     {
 113  0
         return tls.getKeyManagerAlgorithm();
 114  
     }
 115  
 
 116  
     public KeyManagerFactory getKeyManagerFactory()
 117  
     {
 118  0
         return tls.getKeyManagerFactory();
 119  
     }
 120  
 
 121  
     public String getKeyPassword()
 122  
     {
 123  0
         return tls.getKeyPassword();
 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 setKeyStore(String keyStore) throws IOException
 227  
     {
 228  0
         tls.setKeyStore(keyStore);
 229  0
     }
 230  
 
 231  
     public void setKeyStoreType(String keystoreType)
 232  
     {
 233  0
         tls.setKeyStoreType(keystoreType);
 234  0
     }
 235  
 
 236  
     public void setProtocolHandler(String protocolHandler)
 237  
     {
 238  0
         tls.setProtocolHandler(protocolHandler);
 239  0
     }
 240  
 
 241  
     public void setProvider(Provider provider)
 242  
     {
 243  0
         tls.setProvider(provider);
 244  0
     }
 245  
 
 246  
     public void setRequireClientAuthentication(boolean requireClientAuthentication)
 247  
     {
 248  0
         tls.setRequireClientAuthentication(requireClientAuthentication);
 249  0
     }
 250  
 
 251  
     public void setSecurityProviderFactory(SecurityProviderFactory spFactory)
 252  
     {
 253  0
         tls.setSecurityProviderFactory(spFactory);
 254  0
     }
 255  
 
 256  
     public void setSslType(String sslType)
 257  
     {
 258  0
         tls.setSslType(sslType);
 259  0
     }
 260  
 
 261  
     public void setKeyStorePassword(String storePassword)
 262  
     {
 263  0
         tls.setKeyStorePassword(storePassword);
 264  0
     }
 265  
 
 266  
     public void setTrustManagerAlgorithm(String trustManagerAlgorithm)
 267  
     {
 268  0
         tls.setTrustManagerAlgorithm(trustManagerAlgorithm);
 269  0
     }
 270  
 
 271  
     public void setTrustManagerFactory(TrustManagerFactory trustManagerFactory)
 272  
     {
 273  0
         tls.setTrustManagerFactory(trustManagerFactory);
 274  0
     }
 275  
 
 276  
     public void setTrustStore(String trustStore) throws IOException
 277  
     {
 278  0
         tls.setTrustStore(trustStore);
 279  0
     }
 280  
 
 281  
     public void setTrustStorePassword(String trustStorePassword)
 282  
     {
 283  0
         tls.setTrustStorePassword(trustStorePassword);
 284  0
     }
 285  
 
 286  
     public void setTrustStoreType(String trustStoreType)
 287  
     {
 288  0
         tls.setTrustStoreType(trustStoreType);
 289  0
     }
 290  
 
 291  
     public long getSslHandshakeTimeout()
 292  
     {
 293  0
         return sslHandshakeTimeout;
 294  
     }
 295  
 
 296  
     public void setSslHandshakeTimeout(long sslHandshakeTimeout)
 297  
     {
 298  0
         this.sslHandshakeTimeout = sslHandshakeTimeout;
 299  0
     }
 300  
 
 301  
 }