|
29 | 29 | import static org.mockito.Mockito.verify;
|
30 | 30 | import static org.mockito.Mockito.when;
|
31 | 31 |
|
| 32 | +import com.google.common.collect.ImmutableList; |
32 | 33 | import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
33 | 34 | import io.envoyproxy.envoy.type.matcher.v3.RegexMatcher;
|
34 | 35 | import io.envoyproxy.envoy.type.matcher.v3.StringMatcher;
|
|
37 | 38 | import java.security.cert.CertStoreException;
|
38 | 39 | import java.security.cert.CertificateException;
|
39 | 40 | import java.security.cert.X509Certificate;
|
| 41 | +import java.util.Collections; |
| 42 | +import java.util.List; |
40 | 43 | import javax.net.ssl.SSLEngine;
|
41 | 44 | import javax.net.ssl.SSLParameters;
|
42 | 45 | import javax.net.ssl.SSLSession;
|
@@ -551,6 +554,29 @@ public void checkServerTrustedSslSocket_untrustedServer_expectException()
|
551 | 554 | verify(sslSocket, times(1)).getHandshakeSession();
|
552 | 555 | }
|
553 | 556 |
|
| 557 | + @Test |
| 558 | + public void unsupportedAltNameType() throws CertificateException, IOException { |
| 559 | + StringMatcher stringMatcher = |
| 560 | + StringMatcher.newBuilder() |
| 561 | + .setExact("waterzooi.test.google.be") |
| 562 | + .setIgnoreCase(false) |
| 563 | + .build(); |
| 564 | + CertificateValidationContext certContext = |
| 565 | + CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); |
| 566 | + trustManager = new SdsX509TrustManager(certContext, mockDelegate); |
| 567 | + X509Certificate mockCert = mock(X509Certificate.class); |
| 568 | + |
| 569 | + when(mockCert.getSubjectAlternativeNames()) |
| 570 | + .thenReturn(Collections.<List<?>>singleton(ImmutableList.of(Integer.valueOf(1), "foo"))); |
| 571 | + X509Certificate[] certs = new X509Certificate[] {mockCert}; |
| 572 | + try { |
| 573 | + trustManager.verifySubjectAltNameInChain(certs); |
| 574 | + fail("no exception thrown"); |
| 575 | + } catch (CertificateException expected) { |
| 576 | + assertThat(expected).hasMessageThat().isEqualTo("Peer certificate SAN check failed"); |
| 577 | + } |
| 578 | + } |
| 579 | + |
554 | 580 | private TestSslEngine buildTrustManagerAndGetSslEngine()
|
555 | 581 | throws CertificateException, IOException, CertStoreException {
|
556 | 582 | SSLParameters sslParams = buildTrustManagerAndGetSslParameters();
|
|
0 commit comments