|
23 | 23 | import static org.junit.jupiter.api.Assertions.assertFalse; |
24 | 24 | import static org.junit.jupiter.api.Assertions.assertThrows; |
25 | 25 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 26 | +import io.netty.buffer.UnpooledByteBufAllocator; |
| 27 | +import io.netty.handler.ssl.SslContext; |
26 | 28 | import java.io.IOException; |
27 | 29 | import java.net.InetAddress; |
28 | 30 | import java.net.InetSocketAddress; |
|
45 | 47 | import javax.net.ssl.HandshakeCompletedEvent; |
46 | 48 | import javax.net.ssl.HandshakeCompletedListener; |
47 | 49 | import javax.net.ssl.SSLContext; |
| 50 | +import javax.net.ssl.SSLEngine; |
48 | 51 | import javax.net.ssl.SSLHandshakeException; |
49 | 52 | import javax.net.ssl.SSLServerSocket; |
50 | 53 | import javax.net.ssl.SSLSocket; |
|
58 | 61 | import org.junit.jupiter.params.ParameterizedTest; |
59 | 62 | import org.junit.jupiter.params.provider.MethodSource; |
60 | 63 |
|
| 64 | + |
61 | 65 | public class X509UtilTest extends BaseX509ParameterizedTestCase { |
62 | 66 |
|
63 | 67 | private X509Util x509Util; |
@@ -754,6 +758,28 @@ public void testCreateSSLContext_ocspWithJreProvider( |
754 | 758 | } |
755 | 759 | } |
756 | 760 |
|
| 761 | + @ParameterizedTest |
| 762 | + @MethodSource("data") |
| 763 | + public void testCreateSSLContext_hostnameVerificationNoCustomTrustStore(X509KeyType caKeyType, |
| 764 | + X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception { |
| 765 | + init(caKeyType, certKeyType, keyPassword, paramIndex); |
| 766 | + // No truststore |
| 767 | + System.clearProperty(x509Util.getSslTruststoreLocationProperty()); |
| 768 | + // Verify client hostname too |
| 769 | + System.setProperty(x509Util.getSslClientHostnameVerificationEnabledProperty(), "true"); |
| 770 | + ZKConfig zkConfig = new ZKConfig(); |
| 771 | + try (ClientX509Util clientX509Util = new ClientX509Util();) { |
| 772 | + UnpooledByteBufAllocator byteBufAllocator = new UnpooledByteBufAllocator(false); |
| 773 | + SslContext clientContext = clientX509Util.createNettySslContextForClient(zkConfig); |
| 774 | + SSLEngine clientEngine = clientContext.newEngine(byteBufAllocator); |
| 775 | + assertEquals(clientEngine.getSSLParameters().getEndpointIdentificationAlgorithm(), "HTTPS"); |
| 776 | + |
| 777 | + SslContext serverContext = clientX509Util.createNettySslContextForServer(zkConfig); |
| 778 | + SSLEngine serverEngine = serverContext.newEngine(byteBufAllocator); |
| 779 | + assertEquals(serverEngine.getSSLParameters().getEndpointIdentificationAlgorithm(), "HTTPS"); |
| 780 | + } |
| 781 | + } |
| 782 | + |
757 | 783 | private static void forceClose(Socket s) { |
758 | 784 | if (s == null || s.isClosed()) { |
759 | 785 | return; |
|
0 commit comments