@Test public void testFailedToGenerateWhiteListFile() throws IOException, CertificateEncodingException { Path anotherFile = Paths.get(tmpDir.getRoot().getPath(),"parent", "anotherFile"); tmpDir.getRoot().setWritable(false); trustManager = new TrustOnFirstUseManager(anotherFile); when(certificate.getEncoded()).thenReturn("certificate".getBytes(UTF_8)); X500Principal cn = new X500Principal("CN=localhost"); when(certificate.getSubjectX500Principal()).thenReturn(cn); try { trustManager.checkServerTrusted(new X509Certificate[]{certificate}, "str"); failBecauseExceptionWasNotThrown(IOException.class); } catch (Exception ex) { assertThat(ex) .isInstanceOf(CertificateException.class) .hasMessageContaining("Failed to save address and certificate fingerprint to whitelist"); } verify(certificate).getEncoded(); verify(certificate).getSubjectX500Principal(); tmpDir.getRoot().setWritable(true); }
@Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { checkTrusted(serverCertificates); }
TrustOnFirstUseManager extends AbstractTrustManager { @Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { checkTrusted(serverCertificates); } }
TrustOnFirstUseManager extends AbstractTrustManager { @Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { checkTrusted(serverCertificates); } TrustOnFirstUseManager(Path knownHosts); }
TrustOnFirstUseManager extends AbstractTrustManager { @Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { checkTrusted(serverCertificates); } TrustOnFirstUseManager(Path knownHosts); @Override void checkClientTrusted(X509Certificate[] clientCertificates, String authType); @Override void checkServerTrusted(X509Certificate[] serverCertificates, String authType); @Override X509Certificate[] getAcceptedIssuers(); }
TrustOnFirstUseManager extends AbstractTrustManager { @Override public void checkServerTrusted(X509Certificate[] serverCertificates, String authType) throws CertificateException { checkTrusted(serverCertificates); } TrustOnFirstUseManager(Path knownHosts); @Override void checkClientTrusted(X509Certificate[] clientCertificates, String authType); @Override void checkServerTrusted(X509Certificate[] serverCertificates, String authType); @Override X509Certificate[] getAcceptedIssuers();  }