Skip to content

Commit 37add8a

Browse files
chrjohnthe-thing
andauthored
Apply MINA 2.2.2 patch to QFJ 2.3.x branch (#661)
* Removing unused quickfix.mina.ssl.SSLFilter * Updating SSL configuration documentation * Changed to use MINA 2.2.2 * Update IoSessionInitiator.java Removed ctor parameter that is not present on 2.3.x * Added changes from #543, use `closeOnFlush()` --------- Co-authored-by: Marcin <marcin.lamparski@gmail.com>
1 parent 6026bd6 commit 37add8a

File tree

16 files changed

+207
-206
lines changed

16 files changed

+207
-206
lines changed

quickfixj-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<dependency>
6060
<groupId>org.apache.mina</groupId>
6161
<artifactId>mina-core</artifactId>
62-
<version>2.1.4</version>
62+
<version>2.2.2</version>
6363
</dependency>
6464
<dependency>
6565
<groupId>org.slf4j</groupId>

quickfixj-core/src/main/doc/usermanual/usage/configuration.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,12 @@ <H3>QuickFIX Settings</H3>
684684
<TD><a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html">Java default cipher suites</a></TD>
685685
</TR>
686686
<TR ALIGN="left" VALIGN="middle">
687-
<TD valign="top"> <I>UseSNI</I></TD>
688-
<TD>Configures the SSL engine to use Server Name Indication. This option is only useful to initiators.</TD>
689-
<TD>Y<BR>N</TD>
690-
<TD>N</TD>
687+
<TD valign="top"> <I>EndpointIdentificationAlgorithm</I></TD>
688+
<TD>Sets the endpoint identification algorithm. If the algorithm parameter is non-null, the endpoint identification/verification procedures must be handled during SSL/TLS handshaking. See
689+
<a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#jssenames">Endpoint Identification
690+
Algorithm Names</a></TD>
691+
<TD></TD>
692+
<TD></TD>
691693
</TR>
692694

693695
<TR ALIGN="center" VALIGN="middle">

quickfixj-core/src/main/java/quickfix/mina/AbstractIoHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void exceptionCaught(IoSession ioSession, Throwable cause) throws Excepti
8787
quickFixSession.disconnect(reason, true);
8888
} else {
8989
log.error(reason, cause);
90-
ioSession.closeNow();
90+
ioSession.closeOnFlush();
9191
}
9292
} finally {
9393
ioSession.setAttribute(SessionConnector.QFJ_RESET_IO_CONNECTOR, Boolean.TRUE);
@@ -112,7 +112,7 @@ public void sessionClosed(IoSession ioSession) {
112112
throw e;
113113
} finally {
114114
ioSession.removeAttribute(SessionConnector.QF_SESSION);
115-
ioSession.closeNow();
115+
ioSession.closeOnFlush();
116116
}
117117
}
118118

quickfixj-core/src/main/java/quickfix/mina/acceptor/AbstractSocketAcceptor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.mina.core.buffer.SimpleBufferAllocator;
2424
import org.apache.mina.core.service.IoAcceptor;
2525
import org.apache.mina.filter.codec.ProtocolCodecFilter;
26+
import org.apache.mina.filter.ssl.SslFilter;
2627
import quickfix.Acceptor;
2728
import quickfix.Application;
2829
import quickfix.ConfigError;
@@ -45,7 +46,6 @@
4546
import quickfix.mina.message.FIXProtocolCodecFactory;
4647
import quickfix.mina.ssl.SSLConfig;
4748
import quickfix.mina.ssl.SSLContextFactory;
48-
import quickfix.mina.ssl.SSLFilter;
4949
import quickfix.mina.ssl.SSLSupport;
5050

5151
import javax.net.ssl.SSLContext;
@@ -132,10 +132,9 @@ private void installSSL(AcceptorSocketDescriptor descriptor,
132132
log.info("Installing SSL filter for {}", descriptor.getAddress());
133133
SSLConfig sslConfig = descriptor.getSslConfig();
134134
SSLContext sslContext = SSLContextFactory.getInstance(sslConfig);
135-
SSLFilter sslFilter = new SSLFilter(sslContext);
136-
sslFilter.setUseClientMode(false);
135+
SslFilter sslFilter = new SslFilter(sslContext);
137136
sslFilter.setNeedClientAuth(sslConfig.isNeedClientAuth());
138-
sslFilter.setCipherSuites(sslConfig.getEnabledCipherSuites() != null ? sslConfig.getEnabledCipherSuites()
137+
sslFilter.setEnabledCipherSuites(sslConfig.getEnabledCipherSuites() != null ? sslConfig.getEnabledCipherSuites()
139138
: SSLSupport.getDefaultCipherSuites(sslContext));
140139
sslFilter.setEnabledProtocols(sslConfig.getEnabledProtocols() != null ? sslConfig.getEnabledProtocols()
141140
: SSLSupport.getSupportedProtocols(sslContext));

quickfixj-core/src/main/java/quickfix/mina/initiator/InitiatorProxyIoHandler.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@
2222
import org.apache.mina.core.session.IoSession;
2323
import org.apache.mina.proxy.AbstractProxyIoHandler;
2424

25-
import quickfix.mina.ssl.SSLFilter;
26-
2725
class InitiatorProxyIoHandler extends AbstractProxyIoHandler {
2826
private final InitiatorIoHandler initiatorIoHandler;
29-
private final SSLFilter sslFilter;
3027

31-
InitiatorProxyIoHandler(InitiatorIoHandler initiatorIoHandler, SSLFilter sslFilter) {
28+
InitiatorProxyIoHandler(InitiatorIoHandler initiatorIoHandler) {
3229
super();
3330
this.initiatorIoHandler = initiatorIoHandler;
34-
this.sslFilter = sslFilter;
3531
}
3632

3733
@Override
@@ -60,9 +56,6 @@ public void exceptionCaught(IoSession ioSession, Throwable cause) throws Excepti
6056
}
6157

6258
@Override
63-
public void proxySessionOpened(IoSession ioSession) throws Exception {
64-
if (this.sslFilter != null) {
65-
this.sslFilter.initiateHandshake(ioSession);
66-
}
59+
public void proxySessionOpened(IoSession ioSession) {
6760
}
6861
}

quickfixj-core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.mina.core.service.IoConnector;
2525
import org.apache.mina.core.session.IoSession;
2626
import org.apache.mina.filter.codec.ProtocolCodecFilter;
27+
import org.apache.mina.filter.ssl.SslFilter;
2728
import org.apache.mina.proxy.ProxyConnector;
2829
import org.apache.mina.transport.socket.SocketConnector;
2930
import quickfix.ConfigError;
@@ -39,7 +40,6 @@
3940
import quickfix.mina.message.FIXProtocolCodecFactory;
4041
import quickfix.mina.ssl.SSLConfig;
4142
import quickfix.mina.ssl.SSLContextFactory;
42-
import quickfix.mina.ssl.SSLFilter;
4343
import quickfix.mina.ssl.SSLSupport;
4444

4545
import javax.net.ssl.SSLContext;
@@ -150,9 +150,9 @@ private void setupIoConnector() throws ConfigError, GeneralSecurityException {
150150

151151
boolean hasProxy = proxyType != null && proxyPort > 0 && socketAddresses[nextSocketAddressIndex] instanceof InetSocketAddress;
152152

153-
SSLFilter sslFilter = null;
153+
SslFilter sslFilter = null;
154154
if (sslEnabled) {
155-
sslFilter = installSslFilter(ioFilterChainBuilder, !hasProxy);
155+
sslFilter = installSslFilter(ioFilterChainBuilder);
156156
}
157157

158158
ioFilterChainBuilder.addLast(FIXProtocolCodecFactory.FILTER_NAME, new ProtocolCodecFilter(new FIXProtocolCodecFactory()));
@@ -172,9 +172,7 @@ private void setupIoConnector() throws ConfigError, GeneralSecurityException {
172172
);
173173

174174
proxyConnector.setHandler(new InitiatorProxyIoHandler(
175-
new InitiatorIoHandler(fixSession, networkingOptions, eventHandlingStrategy),
176-
sslFilter
177-
));
175+
new InitiatorIoHandler(fixSession, networkingOptions, eventHandlingStrategy)));
178176

179177
newConnector = proxyConnector;
180178
}
@@ -185,16 +183,15 @@ private void setupIoConnector() throws ConfigError, GeneralSecurityException {
185183
ioConnector = newConnector;
186184
}
187185

188-
private SSLFilter installSslFilter(CompositeIoFilterChainBuilder ioFilterChainBuilder, boolean autoStart)
186+
private SslFilter installSslFilter(CompositeIoFilterChainBuilder ioFilterChainBuilder)
189187
throws GeneralSecurityException {
190188
final SSLContext sslContext = SSLContextFactory.getInstance(sslConfig);
191-
final SSLFilter sslFilter = new SSLFilter(sslContext, autoStart);
192-
sslFilter.setUseClientMode(true);
193-
sslFilter.setCipherSuites(sslConfig.getEnabledCipherSuites() != null ? sslConfig.getEnabledCipherSuites()
189+
final SslFilter sslFilter = new SslFilter(sslContext);
190+
sslFilter.setEnabledCipherSuites(sslConfig.getEnabledCipherSuites() != null ? sslConfig.getEnabledCipherSuites()
194191
: SSLSupport.getDefaultCipherSuites(sslContext));
195192
sslFilter.setEnabledProtocols(sslConfig.getEnabledProtocols() != null ? sslConfig.getEnabledProtocols()
196193
: SSLSupport.getSupportedProtocols(sslContext));
197-
sslFilter.setUseSNI(sslConfig.isUseSNI());
194+
sslFilter.setEndpointIdentificationAlgorithm(sslConfig.getEndpointIdentificationAlgorithm());
198195
ioFilterChainBuilder.addLast(SSLSupport.FILTER_NAME, sslFilter);
199196
return sslFilter;
200197
}

quickfixj-core/src/main/java/quickfix/mina/ssl/SSLConfig.java

Lines changed: 35 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package quickfix.mina.ssl;
2121

2222
import java.util.Arrays;
23+
import java.util.Objects;
2324

2425
/**
2526
* Groups together SSL related configuration.
@@ -36,58 +37,7 @@ public class SSLConfig {
3637
private String[] enabledProtocols;
3738
private String[] enabledCipherSuites;
3839
private boolean needClientAuth;
39-
private boolean useSNI;
40-
41-
@Override
42-
public boolean equals(Object obj) {
43-
if (this == obj)
44-
return true;
45-
if (obj == null)
46-
return false;
47-
if (getClass() != obj.getClass())
48-
return false;
49-
SSLConfig other = (SSLConfig) obj;
50-
if (!Arrays.equals(enabledCipherSuites, other.enabledCipherSuites))
51-
return false;
52-
if (!Arrays.equals(enabledProtocols, other.enabledProtocols))
53-
return false;
54-
if (keyManagerFactoryAlgorithm == null) {
55-
if (other.keyManagerFactoryAlgorithm != null)
56-
return false;
57-
} else if (!keyManagerFactoryAlgorithm.equals(other.keyManagerFactoryAlgorithm))
58-
return false;
59-
if (keyStoreName == null) {
60-
if (other.keyStoreName != null)
61-
return false;
62-
} else if (!keyStoreName.equals(other.keyStoreName))
63-
return false;
64-
if (!Arrays.equals(keyStorePassword, other.keyStorePassword))
65-
return false;
66-
if (keyStoreType == null) {
67-
if (other.keyStoreType != null)
68-
return false;
69-
} else if (!keyStoreType.equals(other.keyStoreType))
70-
return false;
71-
if (needClientAuth != other.needClientAuth)
72-
return false;
73-
if (trustManagerFactoryAlgorithm == null) {
74-
if (other.trustManagerFactoryAlgorithm != null)
75-
return false;
76-
} else if (!trustManagerFactoryAlgorithm.equals(other.trustManagerFactoryAlgorithm))
77-
return false;
78-
if (trustStoreName == null) {
79-
if (other.trustStoreName != null)
80-
return false;
81-
} else if (!trustStoreName.equals(other.trustStoreName))
82-
return false;
83-
if (!Arrays.equals(trustStorePassword, other.trustStorePassword))
84-
return false;
85-
if(useSNI != other.useSNI)
86-
return false;
87-
if (trustStoreType == null) {
88-
return other.trustStoreType == null;
89-
} else return trustStoreType.equals(other.trustStoreType);
90-
}
40+
private String endpointIdentificationAlgorithm;
9141

9242
public String[] getEnabledCipherSuites() {
9343
return enabledCipherSuites;
@@ -129,31 +79,12 @@ public String getTrustStoreType() {
12979
return trustStoreType;
13080
}
13181

132-
@Override
133-
public int hashCode() {
134-
final int prime = 31;
135-
int result = 1;
136-
result = prime * result + Arrays.hashCode(enabledCipherSuites);
137-
result = prime * result + Arrays.hashCode(enabledProtocols);
138-
result = prime * result + ((keyManagerFactoryAlgorithm == null) ? 0 : keyManagerFactoryAlgorithm.hashCode());
139-
result = prime * result + ((keyStoreName == null) ? 0 : keyStoreName.hashCode());
140-
result = prime * result + Arrays.hashCode(keyStorePassword);
141-
result = prime * result + ((keyStoreType == null) ? 0 : keyStoreType.hashCode());
142-
result = prime * result + (needClientAuth ? 1231 : 1237);
143-
result = prime * result
144-
+ ((trustManagerFactoryAlgorithm == null) ? 0 : trustManagerFactoryAlgorithm.hashCode());
145-
result = prime * result + ((trustStoreName == null) ? 0 : trustStoreName.hashCode());
146-
result = prime * result + Arrays.hashCode(trustStorePassword);
147-
result = prime * result + ((trustStoreType == null) ? 0 : trustStoreType.hashCode());
148-
return result;
149-
}
150-
15182
public boolean isNeedClientAuth() {
15283
return needClientAuth;
15384
}
15485

155-
public boolean isUseSNI() {
156-
return useSNI;
86+
public String getEndpointIdentificationAlgorithm() {
87+
return endpointIdentificationAlgorithm;
15788
}
15889

15990
public void setEnabledCipherSuites(String[] enabledCipherSuites) {
@@ -184,8 +115,8 @@ public void setNeedClientAuth(boolean needClientAuth) {
184115
this.needClientAuth = needClientAuth;
185116
}
186117

187-
public void setUseSNI(boolean useSNI) {
188-
this.useSNI = useSNI;
118+
public void setEndpointIdentificationAlgorithm(String endpointIdentificationAlgorithm) {
119+
this.endpointIdentificationAlgorithm = endpointIdentificationAlgorithm;
189120
}
190121

191122
public void setTrustManagerFactoryAlgorithm(String trustManagerFactoryAlgorithm) {
@@ -203,4 +134,33 @@ public void setTrustStorePassword(char[] trustStorePassword) {
203134
public void setTrustStoreType(String trustStoreType) {
204135
this.trustStoreType = trustStoreType;
205136
}
137+
138+
@Override
139+
public boolean equals(Object o) {
140+
if (this == o) return true;
141+
if (o == null || getClass() != o.getClass()) return false;
142+
SSLConfig sslConfig = (SSLConfig) o;
143+
return needClientAuth == sslConfig.needClientAuth &&
144+
Objects.equals(keyStoreName, sslConfig.keyStoreName) &&
145+
Arrays.equals(keyStorePassword, sslConfig.keyStorePassword) &&
146+
Objects.equals(keyManagerFactoryAlgorithm, sslConfig.keyManagerFactoryAlgorithm) &&
147+
Objects.equals(keyStoreType, sslConfig.keyStoreType) &&
148+
Objects.equals(trustStoreName, sslConfig.trustStoreName) &&
149+
Arrays.equals(trustStorePassword, sslConfig.trustStorePassword) &&
150+
Objects.equals(trustManagerFactoryAlgorithm, sslConfig.trustManagerFactoryAlgorithm) &&
151+
Objects.equals(trustStoreType, sslConfig.trustStoreType) &&
152+
Arrays.equals(enabledProtocols, sslConfig.enabledProtocols) &&
153+
Arrays.equals(enabledCipherSuites, sslConfig.enabledCipherSuites) &&
154+
Objects.equals(endpointIdentificationAlgorithm, sslConfig.endpointIdentificationAlgorithm);
155+
}
156+
157+
@Override
158+
public int hashCode() {
159+
int result = Objects.hash(keyStoreName, keyManagerFactoryAlgorithm, keyStoreType, trustStoreName, trustManagerFactoryAlgorithm, trustStoreType, needClientAuth, endpointIdentificationAlgorithm);
160+
result = 31 * result + Arrays.hashCode(keyStorePassword);
161+
result = 31 * result + Arrays.hashCode(trustStorePassword);
162+
result = 31 * result + Arrays.hashCode(enabledProtocols);
163+
result = 31 * result + Arrays.hashCode(enabledCipherSuites);
164+
return result;
165+
}
206166
}

quickfixj-core/src/main/java/quickfix/mina/ssl/SSLFilter.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)