ExtensibleTrustManagerImpl extends X509ExtendedTrustManager implements ExtensibleTrustManager { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { checkClientTrusted(chain, authType, (Socket) null); }  @Override void checkClientTrusted(X509Certificate[] chain, String authType); @Override void checkServerTrusted(X509Certificate[] chain, String authType); @Override X509Certificate[] getAcceptedIssuers(); @Override void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket); @Override void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine sslEngine); @Override void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket); @Override void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine sslEngine); @Override @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) void addTlsCertificateProvider(TlsCertificateProvider tlsCertificateProvider); @Override void removeTlsCertificateProvider(TlsCertificateProvider tlsCertificateProvider); @Override @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) void addTlsTrustManagerProvider(TlsTrustManagerProvider tlsTrustManagerProvider); @Override void removeTlsTrustManagerProvider(TlsTrustManagerProvider tlsTrustManagerProvider);  }
@Test public void shouldForwardCallsToMockForMatchingAlternativeNames() throws CertificateException { when(topOfChain.getSubjectX500Principal()) .thenReturn(new X500Principal("CN=example.com, OU=Smarthome, O=Eclipse, C=DE")); when(topOfChain.getSubjectAlternativeNames()) .thenReturn(constructAlternativeNames("example1.com", "example.org")); subject.checkClientTrusted(chain, "just"); verify(trustmanager).checkClientTrusted(chain, "just", (Socket) null); verifyNoMoreInteractions(trustmanager); }
@Test public void shouldBeResilientAgainstNullSubjectAlternativeNames() throws CertificateException, IllegalAccessException, NoSuchFieldException, SecurityException { writeField(subject, "defaultTrustManager", defaultTrustManager, true); when(topOfChain.getSubjectX500Principal()) .thenReturn(new X500Principal("CN=example.com, OU=Smarthome, O=Eclipse, C=DE")); when(topOfChain.getSubjectAlternativeNames()).thenReturn(null); subject.checkClientTrusted(chain, "just"); verify(defaultTrustManager).checkClientTrusted(chain, "just", (Socket) null); verifyNoMoreInteractions(trustmanager); }
@Test public void shouldBeResilientAgainstMissingCommonNames() throws CertificateException, IllegalAccessException, NoSuchFieldException, SecurityException, IllegalArgumentException { writeField(subject, "defaultTrustManager", defaultTrustManager, true); when(topOfChain.getSubjectX500Principal()).thenReturn(new X500Principal("OU=Smarthome, O=Eclipse, C=DE")); subject.checkClientTrusted(chain, "just"); verify(defaultTrustManager).checkClientTrusted(chain, "just", (Socket) null); verifyNoMoreInteractions(trustmanager); }
@Test public void shouldBeResilientAgainstInvalidCertificates() throws CertificateException, IllegalAccessException, NoSuchFieldException, SecurityException, IllegalArgumentException { writeField(subject, "defaultTrustManager", defaultTrustManager, true); when(topOfChain.getSubjectX500Principal()) .thenReturn(new X500Principal("CN=example.com, OU=Smarthome, O=Eclipse, C=DE")); when(topOfChain.getSubjectAlternativeNames()) .thenThrow(new CertificateParsingException("Invalid certificate!!!")); subject.checkClientTrusted(chain, "just"); verify(defaultTrustManager).checkClientTrusted(chain, "just", (Socket) null); verifyNoMoreInteractions(trustmanager); }