Code example for SSLSession

Methods: getPeerCertificates

					sslconn.setHostnameVerifier(new HostnameVerifier() { 
						public boolean verify(String hostname, SSLSession session) { 
							/* For each certificate, check */ 
							X509Certificate cert; 
							try { 
								cert = (X509Certificate)session.getPeerCertificates()[0]; 
							catch (SSLPeerUnverifiedException e) { 
								throw new RuntimeException(String.format( 
										"Failed to verify peer for url: %s (%s)", e, u.toString())); 
							Matcher m = DNPattern.matcher(cert.getSubjectDN().getName()); 
							if (!m.find()) { 
								throw new RuntimeException(String.format( 
										"Could not extract hostname from '%s' for url %s", cert.getSubjectDN(), u.toString())); 
							String sslname =; 
							if (sslname.equals(override_certname)) { 
								/* Matched the overridden certname, so allow this connection */ 
								return true;