@Test public void shouldReportPinIfNotPinned() { X509TrustManager tm = JavaPinning.trustManagerForPin("CERTPLAIN:" + TestUtilities.PLAIN_CERTIFICATE_2); try { tm.checkServerTrusted(DUMMY_CHAIN, ""); fail(); } catch (CertificateException e) { final String dummyCertPin = "CERTPLAIN:" + TestUtilities.PLAIN_CERTIFICATE_1; assertTrue(e.getMessage().contains(dummyCertPin)); } }
@Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { final X509Certificate leafCertificate = chain[0]; if (isPinned(leafCertificate)) { return; } final String pinHexString = HexUtilities.encodeToHex(leafCertificate.getEncoded()); throw new CertificateNotPinnedException("Certificate not pinned. Use 'CERTPLAIN:" + pinHexString + "' to pin this certificate. But only pin the certificate if you are sure this is the correct certificate!"); }
PinningTrustManager implements X509TrustManager { @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { final X509Certificate leafCertificate = chain[0]; if (isPinned(leafCertificate)) { return; } final String pinHexString = HexUtilities.encodeToHex(leafCertificate.getEncoded()); throw new CertificateNotPinnedException("Certificate not pinned. Use 'CERTPLAIN:" + pinHexString + "' to pin this certificate. But only pin the certificate if you are sure this is the correct certificate!"); } }
PinningTrustManager implements X509TrustManager { @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { final X509Certificate leafCertificate = chain[0]; if (isPinned(leafCertificate)) { return; } final String pinHexString = HexUtilities.encodeToHex(leafCertificate.getEncoded()); throw new CertificateNotPinnedException("Certificate not pinned. Use 'CERTPLAIN:" + pinHexString + "' to pin this certificate. But only pin the certificate if you are sure this is the correct certificate!"); } PinningTrustManager(Collection<Pin> pins); }
PinningTrustManager implements X509TrustManager { @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { final X509Certificate leafCertificate = chain[0]; if (isPinned(leafCertificate)) { return; } final String pinHexString = HexUtilities.encodeToHex(leafCertificate.getEncoded()); throw new CertificateNotPinnedException("Certificate not pinned. Use 'CERTPLAIN:" + pinHexString + "' to pin this certificate. But only pin the certificate if you are sure this is the correct certificate!"); } PinningTrustManager(Collection<Pin> pins); @Override void checkClientTrusted(X509Certificate[] chain, String authType); @Override void checkServerTrusted(X509Certificate[] chain, String authType); @Override X509Certificate[] getAcceptedIssuers(); }
PinningTrustManager implements X509TrustManager { @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { final X509Certificate leafCertificate = chain[0]; if (isPinned(leafCertificate)) { return; } final String pinHexString = HexUtilities.encodeToHex(leafCertificate.getEncoded()); throw new CertificateNotPinnedException("Certificate not pinned. Use 'CERTPLAIN:" + pinHexString + "' to pin this certificate. But only pin the certificate if you are sure this is the correct certificate!"); } PinningTrustManager(Collection<Pin> pins); @Override void checkClientTrusted(X509Certificate[] chain, String authType); @Override void checkServerTrusted(X509Certificate[] chain, String authType); @Override X509Certificate[] getAcceptedIssuers();  }