diff --git a/quickfixj-core/src/main/java/quickfix/mina/CustomSslFilter.java b/quickfixj-core/src/main/java/quickfix/mina/CustomSslFilter.java deleted file mode 100644 index 7092d6134d..0000000000 --- a/quickfixj-core/src/main/java/quickfix/mina/CustomSslFilter.java +++ /dev/null @@ -1,35 +0,0 @@ -package quickfix.mina; - -import org.apache.mina.core.filterchain.IoFilterChain; -import org.apache.mina.core.session.IoSession; -import org.apache.mina.filter.ssl.SslFilter; - -import javax.net.ssl.SSLContext; - -/** - * Temporary {@link SslFilter} wrapper that prevents auto connect for initiators. - */ -public class CustomSslFilter extends SslFilter { - - private static final boolean DEFAULT_AUTO_START = true; - - private final boolean autoStart; - - public CustomSslFilter(SSLContext sslContext) { - this(sslContext, DEFAULT_AUTO_START); - } - - public CustomSslFilter(SSLContext sslContext, boolean autoStart) { - super(sslContext); - this.autoStart = autoStart; - } - - @Override - public void onPostAdd(IoFilterChain parent, String name, NextFilter next) throws Exception { - IoSession session = parent.getSession(); - - if (session.isConnected() && autoStart) { - onConnected(next, session); - } - } -} diff --git a/quickfixj-core/src/main/java/quickfix/mina/acceptor/AbstractSocketAcceptor.java b/quickfixj-core/src/main/java/quickfix/mina/acceptor/AbstractSocketAcceptor.java index df0c18ff35..f9f418b5d6 100644 --- a/quickfixj-core/src/main/java/quickfix/mina/acceptor/AbstractSocketAcceptor.java +++ b/quickfixj-core/src/main/java/quickfix/mina/acceptor/AbstractSocketAcceptor.java @@ -40,7 +40,6 @@ import quickfix.SessionID; import quickfix.SessionSettings; import quickfix.mina.CompositeIoFilterChainBuilder; -import quickfix.mina.CustomSslFilter; import quickfix.mina.EventHandlingStrategy; import quickfix.mina.NetworkingOptions; import quickfix.mina.ProtocolFactory; @@ -135,7 +134,7 @@ private void installSSL(AcceptorSocketDescriptor descriptor, log.info("Installing SSL filter for {}", descriptor.getAddress()); SSLConfig sslConfig = descriptor.getSslConfig(); SSLContext sslContext = SSLContextFactory.getInstance(sslConfig); - SslFilter sslFilter = new CustomSslFilter(sslContext); + SslFilter sslFilter = new SslFilter(sslContext); sslFilter.setNeedClientAuth(sslConfig.isNeedClientAuth()); sslFilter.setEnabledCipherSuites(sslConfig.getEnabledCipherSuites() != null ? sslConfig.getEnabledCipherSuites() : SSLSupport.getDefaultCipherSuites(sslContext)); diff --git a/quickfixj-core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java b/quickfixj-core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java index 96436e0837..163a186ab5 100644 --- a/quickfixj-core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java +++ b/quickfixj-core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java @@ -34,7 +34,6 @@ import quickfix.SessionSettings; import quickfix.SystemTime; import quickfix.mina.CompositeIoFilterChainBuilder; -import quickfix.mina.CustomSslFilter; import quickfix.mina.EventHandlingStrategy; import quickfix.mina.NetworkingOptions; import quickfix.mina.ProtocolFactory; @@ -159,9 +158,8 @@ private void setupIoConnector() throws ConfigError, GeneralSecurityException { boolean hasProxy = proxyType != null && proxyPort > 0 && socketAddresses[nextSocketAddressIndex] instanceof InetSocketAddress; - SslFilter sslFilter = null; if (sslEnabled) { - sslFilter = installSslFilter(ioFilterChainBuilder); + installSslFilter(ioFilterChainBuilder); } ioFilterChainBuilder.addLast(FIXProtocolCodecFactory.FILTER_NAME, new ProtocolCodecFilter(new FIXProtocolCodecFactory())); @@ -192,17 +190,16 @@ private void setupIoConnector() throws ConfigError, GeneralSecurityException { ioConnector = newConnector; } - private SslFilter installSslFilter(CompositeIoFilterChainBuilder ioFilterChainBuilder) + private void installSslFilter(CompositeIoFilterChainBuilder ioFilterChainBuilder) throws GeneralSecurityException { final SSLContext sslContext = SSLContextFactory.getInstance(sslConfig); - final SslFilter sslFilter = new CustomSslFilter(sslContext, false); + final SslFilter sslFilter = new SslFilter(sslContext, false); sslFilter.setEnabledCipherSuites(sslConfig.getEnabledCipherSuites() != null ? sslConfig.getEnabledCipherSuites() : SSLSupport.getDefaultCipherSuites(sslContext)); sslFilter.setEnabledProtocols(sslConfig.getEnabledProtocols() != null ? sslConfig.getEnabledProtocols() : SSLSupport.getSupportedProtocols(sslContext)); sslFilter.setEndpointIdentificationAlgorithm(sslConfig.getEndpointIdentificationAlgorithm()); ioFilterChainBuilder.addLast(SSLSupport.FILTER_NAME, sslFilter); - return sslFilter; } @Override diff --git a/quickfixj-core/src/test/java/quickfix/mina/ssl/SecureSocketTest.java b/quickfixj-core/src/test/java/quickfix/mina/ssl/SecureSocketTest.java index f2012aea84..543a37fc96 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/ssl/SecureSocketTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/ssl/SecureSocketTest.java @@ -19,16 +19,16 @@ package quickfix.mina.ssl; -import junit.framework.TestCase; import org.apache.mina.core.filterchain.IoFilterAdapter; import org.apache.mina.core.session.IoSession; +import org.junit.Before; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import quickfix.ApplicationAdapter; import quickfix.ConfigError; import quickfix.DefaultMessageFactory; import quickfix.FixVersions; -import quickfix.Initiator; import quickfix.MemoryStoreFactory; import quickfix.Session; import quickfix.SessionID; @@ -43,14 +43,20 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -public class SecureSocketTest extends TestCase { +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class SecureSocketTest { + private final Logger log = LoggerFactory.getLogger(getClass()); private final int transportProtocol = ProtocolFactory.SOCKET; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { SystemTime.setTimeSource(null); } + @Test public void testLogonWithBadCertificate() throws Exception { ServerThread serverThread = new ServerThread("nonexistent", "pwd"); try { @@ -85,10 +91,12 @@ public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable } } + @Test public void testLogonWithDefaultCertificate() throws Exception { doLogonTest(null, null); } + @Test public void testLogonWithCustomCertificate() throws Exception { doLogonTest("test.keystore", "quickfixjtestpw"); } @@ -103,6 +111,7 @@ public void testLogonWithCustomCertificate() throws Exception { * so that it's not cached by another test so that there are no false failures. * The test-client.keystore key store is just a copy of test.keystore under a different name. */ + @Test public void testLogonWithBadCertificateOnInitiatorSide() throws Exception { SessionID clientSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "TW", "ISLD"); SessionSettings settings = getClientSessionSettings(clientSessionID); @@ -177,14 +186,8 @@ private void assertLoggedOn(ClientApplication clientApplication, Session clientS } private class ClientApplication extends ApplicationAdapter { - public CountDownLatch logonLatch; - private Initiator initiator; - private boolean stopAfterLogon; - //public void stopAfterLogon(Initiator initiator) { - // this.initiator = initiator; - // this.stopAfterLogon = true; - //} + public CountDownLatch logonLatch; public void setUpLogonExpectation() { logonLatch = new CountDownLatch(1); @@ -195,14 +198,11 @@ public void onLogon(SessionID sessionId) { log.info("Releasing logon latch"); logonLatch.countDown(); } - if (stopAfterLogon) { - log.info("Stopping after logon"); - initiator.stop(); - } } } private class ServerThread extends Thread { + private final ATServer server; public ServerThread(String keyStoreName, String keyStorePassword) { @@ -223,5 +223,4 @@ public void waitForInitialization() throws InterruptedException { server.waitForInitialization(); } } - }