@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 = verify(name, (X509Certificate) session.getPeerCertificates()[0]); } catch (SSLPeerUnverifiedException e) { logger.warn("Could not get certificate from the SSL session", e); } return b; }
/** * @param hostname to match against the cert * @param cert to extract hostname from * @param pass whether the verify should succeed * * @throws Exception On test failure. */ @Test(groups = {"ssl"}, dataProvider = "certificates") public void verifyDefault(final String hostname, final X509Certificate cert, final boolean pass) throws Exception { Assert.assertEquals(DEFAULT_VERIFIER.verify(hostname, cert), pass); }