-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add TLS version mismatch tests to TestSSLHostConfigProtocol to verify… #973
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,18 @@ | |
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| import javax.net.ssl.HttpsURLConnection; | ||
| import javax.net.ssl.SSLContext; | ||
| import javax.net.ssl.SSLHandshakeException; | ||
| import javax.net.ssl.TrustManager; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
| import org.junit.runners.Parameterized.Parameter; | ||
|
|
||
| import org.apache.catalina.Context; | ||
| import org.apache.catalina.connector.Connector; | ||
| import org.apache.catalina.startup.Tomcat; | ||
| import org.apache.catalina.startup.TomcatBaseTest; | ||
|
|
@@ -95,6 +101,44 @@ private void doTestIgnoreProtocol(String protocol) throws Exception { | |
| Assert.assertEquals("TLSv1.2", enabledProtocols[0]); | ||
| } | ||
|
|
||
| @Test(expected = SSLHandshakeException.class) | ||
| public void testTlsVersionMismatchServerTls13ClientTls12() throws Exception { | ||
| SSLHostConfig sslHostConfig = getSSLHostConfig(); | ||
| sslHostConfig.setProtocols(Constants.SSL_PROTO_TLSv1_3); | ||
|
|
||
| Context ctx = getProgrammaticRootContext(); | ||
| Tomcat.addServlet(ctx, "hello", new HelloWorldServlet()); | ||
| ctx.addServletMappingDecoded("/", "hello"); | ||
|
|
||
| Tomcat tomcat = getTomcatInstance(); | ||
| tomcat.start(); | ||
|
|
||
| TesterSupport.configureClientSsl(true); | ||
|
|
||
| getUrl("https://localhost:" + getPort() + "/"); | ||
| } | ||
|
|
||
| @Test(expected = SSLHandshakeException.class) | ||
| public void testTlsVersionMismatchServerTls12ClientTls13() throws Exception { | ||
| SSLHostConfig sslHostConfig = getSSLHostConfig(); | ||
| sslHostConfig.setProtocols(Constants.SSL_PROTO_TLSv1_2); | ||
|
|
||
| Context ctx = getProgrammaticRootContext(); | ||
| Tomcat.addServlet(ctx, "hello", new HelloWorldServlet()); | ||
| ctx.addServletMappingDecoded("/", "hello"); | ||
|
|
||
| Tomcat tomcat = getTomcatInstance(); | ||
| tomcat.start(); | ||
|
|
||
| SSLContext sc = SSLContext.getInstance(Constants.SSL_PROTO_TLSv1_3); | ||
| sc.init(null, new TrustManager[] { new TesterSupport.TrustAllCerts() }, null); | ||
| TesterSupport.ClientSSLSocketFactory clientSSLSocketFactory = new TesterSupport.ClientSSLSocketFactory(sc.getSocketFactory()); | ||
| clientSSLSocketFactory.setProtocols(new String[] { Constants.SSL_PROTO_TLSv1_3 }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client and server have different style interfaces (SSLHostConfig String vs TesterSupport String[]). Is this intentional? If it good/okay, or should we align them?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's intentional in the test scenario because String[] is expected in SSLSocket.setEnabledProtocols(String[] protocols). SSLHostConfig.setProtocols(String input) on the other hand, delimits values from a single string. I suppose we are good as it is.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using an array in xml would not be ideal.. :/ |
||
| HttpsURLConnection.setDefaultSSLSocketFactory(clientSSLSocketFactory); | ||
|
|
||
| getUrl("https://localhost:" + getPort() + "/"); | ||
| } | ||
|
|
||
|
|
||
| private SSLHostConfig getSSLHostConfig() { | ||
| Tomcat tomcat = getTomcatInstance(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.