Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<fix-orchestra.repository.version>1.7.3</fix-orchestra.repository.version>
<docgen.version>1.6.8</docgen.version>
<jaxb.version>4.0.5</jaxb.version>
<apache.mina.version>2.2.9</apache.mina.version>
<apache.mina.version>2.2.10</apache.mina.version>
<commons.io.version>2.22.0</commons.io.version>
<orchestra.file>OrchestraFIXLatest.xml</orchestra.file>
<org.quickfixj.orchestra.tools.version>1.0.3</org.quickfixj.orchestra.tools.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.ssl.SslFilter;
import org.apache.mina.filter.ssl.SslHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import quickfix.mina.HostResolutionStrategy;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLParameters;
import java.net.InetSocketAddress;

abstract class AbstractSslFilter extends SslFilter {

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSslFilter.class);

private final HostResolutionStrategy hostResolutionStrategy;
private boolean nonBlockingPipeline = true;

AbstractSslFilter(SSLContext sslContext, boolean autoStart,
HostResolutionStrategy hostResolutionStrategy) {
Expand All @@ -23,8 +31,18 @@ protected final SSLEngine createEngine(IoSession session, InetSocketAddress addr
SSLEngine sslEngine;

if (addr != null) {
sslEngine = sslContext.createSSLEngine(hostResolutionStrategy.getHost(addr), addr.getPort());
String resolvedHost = hostResolutionStrategy.getHost(addr);

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Creating SSL engine [session={},address={},resolvedHost={}]", session, addr, resolvedHost);
}

sslEngine = sslContext.createSSLEngine(resolvedHost, addr.getPort());
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Creating SSL engine [session={},address={}]", session, addr);
}

sslEngine = sslContext.createSSLEngine();
}

Expand Down Expand Up @@ -56,6 +74,25 @@ protected final SSLEngine createEngine(IoSession session, InetSocketAddress addr
return sslEngine;
}

synchronized protected void onConnected(NextFilter next, IoSession session) throws SSLException {
SslHandler sslHandler = SslHandler.class.cast(session.getAttribute(SSL_HANDLER));

if (sslHandler == null) {
InetSocketAddress s = InetSocketAddress.class.cast(session.getRemoteAddress());
SSLEngine sslEngine = createEngine(session, s);

if (nonBlockingPipeline) {
sslHandler = new QFSSLHandlerG1(sslEngine, EXECUTOR, session);
} else {
sslHandler = new QFSSLHandlerG0(sslEngine, EXECUTOR, session);
}

session.setAttribute(SSL_HANDLER, sslHandler);
}

sslHandler.open(next);
}

protected void configureEngine(SSLEngine sslEngine) {
}

Expand All @@ -68,4 +105,10 @@ public final void sessionClosed(NextFilter next, IoSession session) throws Excep
onClose(next, session, true);
next.sessionClosed(session);
}

@Override
public void setUseNonBlockingPipeline(boolean enable) {
super.setUseNonBlockingPipeline(enable);
this.nonBlockingPipeline = enable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 quickfix.mina.ssl;

import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.TrustManagerFactorySpi;
import javax.net.ssl.X509TrustManager;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.Provider;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

/**
* Bogus {@link TrustManagerFactory} which creates {@link X509TrustManager}
* accepting all certificates. Copied from Apache MINA (removed in MINA 2.2.x).
* Only used when no trust store is configured.
*/
class BogusTrustManagerFactory extends TrustManagerFactory {

private static final X509TrustManager X509 = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
// Do nothing
}

@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
// Do nothing
}

@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
};

private static final TrustManager[] X509_MANAGERS = new TrustManager[] { X509 };

BogusTrustManagerFactory() {
super(new BogusTrustManagerFactorySpi(), new Provider("MinaBogus", 1.0, "") {
private static final long serialVersionUID = -4024169055312053827L;
}, "MinaBogus");
}

private static class BogusTrustManagerFactorySpi extends TrustManagerFactorySpi {
@Override
protected TrustManager[] engineGetTrustManagers() {
return X509_MANAGERS;
}

@Override
protected void engineInit(KeyStore keystore) throws KeyStoreException {
// noop
}

@Override
protected void engineInit(ManagerFactoryParameters managerFactoryParameters)
throws InvalidAlgorithmParameterException {
// noop
}
}
}
Loading
Loading