@Override public boolean verify(final String hostname, final SSLSession session) { boolean b = false; try { String name = null; if (hostname != null) { // if IPv6 strip off the "[]" if (hostname.startsWith("[") && hostname.endsWith("]")) { name = hostname.substring(1, hostname.length() - 1).trim(); } else { name = hostname.trim(); } } b = hostnameVerifier.verify(name, (X509Certificate) session.getPeerCertificates()[0]); } catch (SSLPeerUnverifiedException e) { logger.warn("Could not get certificate from SSL session {} for hostname {}", session, hostname, e); } return b; }
@Override public boolean verify(final String hostname, final SSLSession session) { boolean b = false; try { String name = null; if (hostname != null) { // if IPv6 strip off the "[]" if (hostname.startsWith("[") && hostname.endsWith("]")) { name = hostname.substring(1, hostname.length() - 1).trim(); } else { name = hostname.trim(); } } b = hostnameVerifier.verify(name, (X509Certificate) session.getPeerCertificates()[0]); } catch (SSLPeerUnverifiedException e) { logger.warn("Could not get certificate from SSL session {} for hostname {}", session, hostname, e); } return b; }
/** * Verifies the supplied certificate using the hostname verifier with each hostname. * * @param cert to verify * * @throws CertificateException if none of the hostnames verify */ private void checkCertificateTrusted(final X509Certificate cert) throws CertificateException { for (String name : hostnames) { if (hostnameVerifier.verify(name, cert)) { logger.debug( "checkCertificateTrusted for {} succeeded against {}", hostnameVerifier, cert != null ? cert.getSubjectX500Principal() : null); return; } } throw new CertificateException( String.format( "Hostname '%s' does not match the hostname in the server's " + "certificate '%s'", Arrays.toString(hostnames), cert != null ? cert.getSubjectX500Principal() : null)); }
/** * Verifies the supplied certificate using the hostname verifier with each hostname. * * @param cert to verify * * @throws CertificateException if none of the hostnames verify */ private void checkCertificateTrusted(final X509Certificate cert) throws CertificateException { for (String name : hostnames) { if (hostnameVerifier.verify(name, cert)) { logger.debug( "checkCertificateTrusted for {} succeeded against {}", hostnameVerifier, cert != null ? cert.getSubjectX500Principal() : null); return; } } throw new CertificateException( String.format( "Hostname '%s' does not match the hostname in the server's " + "certificate '%s'", Arrays.toString(hostnames), cert != null ? cert.getSubjectX500Principal() : null)); }
/** * Verifies the supplied certificate using the hostname verifier with each hostname. * * @param cert to verify * * @throws CertificateException if none of the hostnames verify */ private void checkCertificateTrusted(final X509Certificate cert) throws CertificateException { for (String name : hostnames) { if (hostnameVerifier.verify(name, cert)) { logger.debug( "checkCertificateTrusted for {} succeeded against {}", hostnameVerifier, cert != null ? cert.getSubjectX500Principal() : null); return; } } throw new CertificateException( String.format( "Hostname '%s' does not match the hostname in the server's " + "certificate '%s'", Arrays.toString(hostnames), cert != null ? cert.getSubjectX500Principal() : null)); }