package HTTPClient;

import javax.security.cert.X509Certificate;
import javax.net.ssl.SSLSession;
import javax.net.ssl.HostnameVerifier;

/**
 * A simple implementation of HostnameVerifier.
 */
public final class HostnameVerifierImpl implements HostnameVerifier {
    public boolean verify(String hostname, SSLSession session) {
	String name;
	try
	{
            X509Certificate cert = session.getPeerCertificateChain()[0];
	    name = ((sun.security.x509.X500Name) cert.getSubjectDN()).
			getCommonName().toLowerCase();
	}
	catch (Throwable t)
	    { return true; } 	// Oh well, can't check the name in that case

	return Util.wildcardMatch(name, hostname);
    }
}


