-
Notifications
You must be signed in to change notification settings - Fork 665
feat: Add option to let InitiatorSslFilter bypass InetSocketAddress' reverse DNS lookup
#1271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
t-fitchie-meur
wants to merge
7
commits into
quickfix-j:master
Choose a base branch
from
t-fitchie-meur:reverse-proxy-bypass
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d492e2
Add reverse DNS lookup bypass
t-fitchie-meur b1c14fc
Update configuration
t-fitchie-meur e3f4826
document that initiatorSslFilter and ioSessionInitiator are internal …
t-fitchie-meur 70da966
Tidy up comments, remove config html change
t-fitchie-meur 4389903
Merge branch 'master' into reverse-proxy-bypass
chrjohn 539b9a3
Merge branch 'master' into reverse-proxy-bypass
chrjohn fa1d094
Reduced visibility of IoSessionInitiator constructor
chrjohn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
quickfixj-core/src/main/java/quickfix/mina/HostResolutionStrategy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package quickfix.mina; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
|
|
||
| @FunctionalInterface | ||
| public interface HostResolutionStrategy { | ||
| String getHost(InetSocketAddress address); | ||
|
|
||
| HostResolutionStrategy WITH_REVERSE_DNS = InetSocketAddress::getHostName; | ||
|
|
||
| HostResolutionStrategy WITHOUT_REVERSE_DNS = InetSocketAddress::getHostString; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
quickfixj-core/src/test/java/quickfix/mina/ssl/InitiatorSslFilterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package quickfix.mina.ssl; | ||
|
|
||
| import org.apache.mina.core.session.IoSession; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import quickfix.mina.HostResolutionStrategy; | ||
|
|
||
| import javax.net.ssl.SSLContext; | ||
| import javax.net.ssl.SSLEngine; | ||
| import java.net.InetAddress; | ||
| import java.net.InetSocketAddress; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Tests that {@link InitiatorSslFilter} resolves the SSL engine peer host | ||
| * according to the configured {@link HostResolutionStrategy}. | ||
| */ | ||
| public class InitiatorSslFilterTest { | ||
|
|
||
| private static final String LITERAL_IP = "1.2.3.4"; | ||
| private static final byte[] IP_BYTES = {1, 2, 3, 4}; | ||
| private static final String HOST_NAME = "example.quickfixj.org"; | ||
| private static final int PORT = 5001; | ||
|
|
||
| private SSLContext sslContext; | ||
| private IoSession session; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| sslContext = buildSslContext(); | ||
| session = mock(IoSession.class); | ||
| when(session.isServer()).thenReturn(false); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldUseHostStringWhenReverseDnsDisabled() throws Exception { | ||
| InitiatorSslFilter filter = new InitiatorSslFilter(sslContext, null, | ||
| HostResolutionStrategy.WITHOUT_REVERSE_DNS); | ||
|
|
||
| // Address built from raw bytes has no stored host name, so getHostString() | ||
| // returns the literal IP without performing a reverse DNS lookup. | ||
| InetSocketAddress address = new InetSocketAddress(InetAddress.getByAddress(IP_BYTES), PORT); | ||
|
|
||
| SSLEngine engine = filter.createEngine(session, address); | ||
|
|
||
| assertEquals(LITERAL_IP, engine.getPeerHost()); | ||
| assertTrue(engine.getUseClientMode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldUseHostNameWhenReverseDnsEnabled() throws Exception { | ||
| InitiatorSslFilter filter = new InitiatorSslFilter(sslContext, null, | ||
| HostResolutionStrategy.WITH_REVERSE_DNS); | ||
|
|
||
| // Address built with an explicit host name resolves to that name via | ||
| // getHostName() without performing a DNS lookup. | ||
| InetSocketAddress address = new InetSocketAddress( | ||
| InetAddress.getByAddress(HOST_NAME, IP_BYTES), PORT); | ||
|
|
||
| SSLEngine engine = filter.createEngine(session, address); | ||
|
|
||
| assertEquals(HOST_NAME, engine.getPeerHost()); | ||
| assertTrue(engine.getUseClientMode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldCreateClientEngineWhenAddressIsNull() { | ||
| InitiatorSslFilter filter = new InitiatorSslFilter(sslContext, null, | ||
| HostResolutionStrategy.WITHOUT_REVERSE_DNS); | ||
|
|
||
| SSLEngine engine = filter.createEngine(session, null); | ||
|
|
||
| assertNotNull(engine); | ||
| assertTrue(engine.getUseClientMode()); | ||
| } | ||
|
|
||
| private static SSLContext buildSslContext() throws Exception { | ||
| SSLConfig sslConfig = new SSLConfig(); | ||
| sslConfig.setKeyStoreName(SSLSupport.QUICKFIXJ_KEY_STORE); | ||
| sslConfig.setKeyStorePassword(SSLSupport.QUICKFIXJ_KEY_STORE_PWD.toCharArray()); | ||
| sslConfig.setKeyStoreType("JKS"); | ||
| sslConfig.setKeyManagerFactoryAlgorithm("SunX509"); | ||
| sslConfig.setTrustStoreType("JKS"); | ||
| sslConfig.setTrustManagerFactoryAlgorithm("PKIX"); | ||
| return SSLContextFactory.getInstance(sslConfig); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.