directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r944873 - in /directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl: ReloadableSSLSocketFactory.java StartTlsConfidentialityIT.java StartTlsIT.java
Date Sun, 16 May 2010 16:01:24 GMT
Author: seelmann
Date: Sun May 16 16:01:24 2010
New Revision: 944873

URL: http://svn.apache.org/viewvc?rev=944873&view=rev
Log:
Added SSLContextFactory that reloads the trust store each time it is used. Use this factory
for TLS tests

Added:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/ReloadableSSLSocketFactory.java
Modified:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsConfidentialityIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsIT.java

Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/ReloadableSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/ReloadableSSLSocketFactory.java?rev=944873&view=auto
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/ReloadableSSLSocketFactory.java
(added)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/ReloadableSSLSocketFactory.java
Sun May 16 16:01:24 2010
@@ -0,0 +1,189 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.server.ssl;
+
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.security.KeyStore;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+
+
+/**
+ * A {@link SSLSocketFactory} that initializes the {@link TrustManager} each time it is used.

+ * The standard factory only loads the underlying key store and trust store files once, 
+ * changes to the files are not reflected while the JVM is running. This implementation 
+ * initializes the trust manager factory each time it is used.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ReloadableSSLSocketFactory extends SSLSocketFactory
+{
+
+    private SSLSocketFactory delegate;
+
+
+    public static SSLSocketFactory getDefault()
+    {
+        return new ReloadableSSLSocketFactory();
+    }
+
+
+    public ReloadableSSLSocketFactory()
+    {
+        try
+        {
+            // always load default trust managers
+            TrustManagerFactory factory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm()
);
+            factory.init( ( KeyStore ) null );
+            TrustManager[] trustManagers = factory.getTrustManagers();
+
+            // create the real socket factory
+            SSLContext sc = SSLContext.getInstance( "TLS" ); //$NON-NLS-1$
+            sc.init( null, trustManagers, null );
+            delegate = sc.getSocketFactory();
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    private SSLSocketFactory getDelegate()
+    {
+        return delegate;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String[] getDefaultCipherSuites()
+    {
+        return getDelegate().getDefaultCipherSuites();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String[] getSupportedCipherSuites()
+    {
+        return getDelegate().getSupportedCipherSuites();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Socket createSocket( Socket s, String host, int port, boolean autoClose ) throws
IOException
+    {
+        try
+        {
+            return getDelegate().createSocket( s, host, port, autoClose );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Socket createSocket( String host, int port ) throws IOException, UnknownHostException
+    {
+        try
+        {
+            return getDelegate().createSocket( host, port );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Socket createSocket( InetAddress host, int port ) throws IOException
+    {
+        try
+        {
+            return getDelegate().createSocket( host, port );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Socket createSocket( String host, int port, InetAddress localHost, int localPort
) throws IOException,
+        UnknownHostException
+    {
+        try
+        {
+            return getDelegate().createSocket( host, port, localHost, localPort );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Socket createSocket( InetAddress address, int port, InetAddress localAddress,
int localPort )
+        throws IOException
+    {
+        try
+        {
+            return getDelegate().createSocket( address, port, localAddress, localPort );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+}

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsConfidentialityIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsConfidentialityIT.java?rev=944873&r1=944872&r2=944873&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsConfidentialityIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsConfidentialityIT.java
Sun May 16 16:01:24 2010
@@ -183,7 +183,7 @@ public class StartTlsConfidentialityIT e
             } 
         } );
         LOG.debug( "TLS negotion about to begin" );
-        tls.negotiate();
+        tls.negotiate( ReloadableSSLSocketFactory.getDefault() );
         return ctx;
     }
     

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsIT.java?rev=944873&r1=944872&r2=944873&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ssl/StartTlsIT.java
Sun May 16 16:01:24 2010
@@ -235,7 +235,7 @@ public class StartTlsIT extends Abstract
                 } 
             } );
             LOG.debug( "TLS negotion about to begin" );
-            tls.negotiate();
+            tls.negotiate( ReloadableSSLSocketFactory.getDefault() );
 
             search( ii, ctx );
             



Mime
View raw message