@Test public void testCheckServerFailedWhenBothTMFailed() throws CertificateException { doThrow(new CertificateException("TOFU FAILED")).when(trustOnFirstUseManager).checkServerTrusted(any(), any()); doThrow(new CertificateException("CA FAILED")).when(x509TrustManager).checkServerTrusted(any(), any()); try { trustManager.checkServerTrusted(new X509Certificate[]{certificate}, "s"); failBecauseExceptionWasNotThrown(Exception.class); } catch (Exception ex) { assertThat(ex).isInstanceOf(CertificateException.class); } }
@Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { for (TrustManager trustManager : trustManagers) { try { final X509TrustManager x509TrustManager = (X509TrustManager) trustManager; x509TrustManager.checkServerTrusted(serverCertificates, authType); return; } catch (CertificateException ex) { } } throw new CertificateException("Certificate is not trusted by any of the trust managers"); }
CompositeTrustManager extends AbstractTrustManager { @Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { for (TrustManager trustManager : trustManagers) { try { final X509TrustManager x509TrustManager = (X509TrustManager) trustManager; x509TrustManager.checkServerTrusted(serverCertificates, authType); return; } catch (CertificateException ex) { } } throw new CertificateException("Certificate is not trusted by any of the trust managers"); } }
CompositeTrustManager extends AbstractTrustManager { @Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { for (TrustManager trustManager : trustManagers) { try { final X509TrustManager x509TrustManager = (X509TrustManager) trustManager; x509TrustManager.checkServerTrusted(serverCertificates, authType); return; } catch (CertificateException ex) { } } throw new CertificateException("Certificate is not trusted by any of the trust managers"); } CompositeTrustManager(TrustManager[] trustManagers); }
CompositeTrustManager extends AbstractTrustManager { @Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { for (TrustManager trustManager : trustManagers) { try { final X509TrustManager x509TrustManager = (X509TrustManager) trustManager; x509TrustManager.checkServerTrusted(serverCertificates, authType); return; } catch (CertificateException ex) { } } throw new CertificateException("Certificate is not trusted by any of the trust managers"); } CompositeTrustManager(TrustManager[] trustManagers); @Override void checkClientTrusted(X509Certificate[] clientCertificates, String authType); @Override void checkServerTrusted(X509Certificate[] serverCertificates, String authType); @Override X509Certificate[] getAcceptedIssuers(); }
CompositeTrustManager extends AbstractTrustManager { @Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { for (TrustManager trustManager : trustManagers) { try { final X509TrustManager x509TrustManager = (X509TrustManager) trustManager; x509TrustManager.checkServerTrusted(serverCertificates, authType); return; } catch (CertificateException ex) { } } throw new CertificateException("Certificate is not trusted by any of the trust managers"); } CompositeTrustManager(TrustManager[] trustManagers); @Override void checkClientTrusted(X509Certificate[] clientCertificates, String authType); @Override void checkServerTrusted(X509Certificate[] serverCertificates, String authType); @Override X509Certificate[] getAcceptedIssuers();  }