当前位置: 首页>>代码示例>>Java>>正文


Java HostnameChecker.match方法代码示例

本文整理汇总了Java中sun.security.util.HostnameChecker.match方法的典型用法代码示例。如果您正苦于以下问题:Java HostnameChecker.match方法的具体用法?Java HostnameChecker.match怎么用?Java HostnameChecker.match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.security.util.HostnameChecker的用法示例。


在下文中一共展示了HostnameChecker.match方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hostnameMatches

import sun.security.util.HostnameChecker; //导入方法依赖的package包/类
/**
 * Checks if a given hostname matches the certificate of a given session.
 */
private boolean hostnameMatches(String hostname, SSLSession session) {
	HostnameChecker checker = HostnameChecker.getInstance(HostnameChecker.TYPE_TLS);

	boolean validCertificate = false;
	
	try {
		Certificate[] peerCertificates = session.getPeerCertificates();

		if ((peerCertificates.length > 0)
						&& (peerCertificates[0] instanceof X509Certificate)) {
			X509Certificate peerCertificate = (X509Certificate) peerCertificates[0];

			checker.match(hostname, peerCertificate);
			validCertificate = true;
		}
	} catch (CertificateException ex) {
		validCertificate = false;
	} catch (SSLPeerUnverifiedException e) {
		validCertificate = false;
	}
	
	return validCertificate;
}
 
开发者ID:MercadoBitcoin,项目名称:mb-api-client-java,代码行数:27,代码来源:HostnameVerifierBag.java

示例2: checkURLSpoofing

import sun.security.util.HostnameChecker; //导入方法依赖的package包/类
private void checkURLSpoofing(HostnameVerifier hostnameVerifier) throws IOException {
	String theHost = super.url.getHost();
	if (theHost != null && theHost.startsWith("[") && theHost.endsWith("]")) {
		theHost = theHost.substring(1, theHost.length() - 1);
	}
	try {
		Certificate peerCerts[] = _sslSession.getPeerCertificates();
		X509Certificate peerCert;
		if (peerCerts[0] instanceof X509Certificate) {
			peerCert = (X509Certificate) peerCerts[0];
		} else {
			throw new SSLPeerUnverifiedException("");
		}
		HostnameChecker checker = HostnameChecker.getInstance((byte) 1);
		checker.match(theHost, peerCert);
		return;
	} catch (SSLPeerUnverifiedException sslpeerunverifiedexception) {
		/* ignore */
	} catch (CertificateException certificateexception) {
		/* ignore */
	}
	String cipher = _sslSession.getCipherSuite();
	if (cipher != null && cipher.indexOf("_anon_") != -1) {
		return;
	}
	if (hostnameVerifier != null && hostnameVerifier.verify(theHost, _sslSession)) return;

	super.serverSocket.close();
	_sslSession.invalidate();
	throw new IOException("HTTPS hostname wrong:  should be <" + super.url.getHost() + ">");
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:32,代码来源:HttpsClient.java

示例3: checkURLSpoofing

import sun.security.util.HostnameChecker; //导入方法依赖的package包/类
private void checkURLSpoofing(HostnameVerifier hostnameVerifier)
        throws IOException {
    //
    // Get authenticated server name, if any
    //
    String host = url.getHost();

    // if IPv6 strip off the "[]"
    if (host != null && host.startsWith("[") && host.endsWith("]")) {
        host = host.substring(1, host.length()-1);
    }

    Certificate[] peerCerts = null;
    String cipher = session.getCipherSuite();
    try {
        HostnameChecker checker = HostnameChecker.getInstance(
                                            HostnameChecker.TYPE_TLS);

        // Use ciphersuite to determine whether Kerberos is present.
        if (cipher.startsWith("TLS_KRB5")) {
            if (!HostnameChecker.match(host, getPeerPrincipal())) {
                throw new SSLPeerUnverifiedException("Hostname checker" +
                            " failed for Kerberos");
            }
        } else { // X.509

            // get the subject's certificate
            peerCerts = session.getPeerCertificates();

            X509Certificate peerCert;
            if (peerCerts[0] instanceof
                    java.security.cert.X509Certificate) {
                peerCert = (java.security.cert.X509Certificate)peerCerts[0];
            } else {
                throw new SSLPeerUnverifiedException("");
            }
            checker.match(host, peerCert);
        }

        // if it doesn't throw an exception, we passed. Return.
        return;

    } catch (SSLPeerUnverifiedException e) {

        //
        // client explicitly changed default policy and enabled
        // anonymous ciphers; we can't check the standard policy
        //
        // ignore
    } catch (java.security.cert.CertificateException cpe) {
        // ignore
    }

    if ((cipher != null) && (cipher.indexOf("_anon_") != -1)) {
        return;
    } else if ((hostnameVerifier != null) &&
               (hostnameVerifier.verify(host, session))) {
        return;
    }

    serverSocket.close();
    session.invalidate();

    throw new IOException("HTTPS hostname wrong:  should be <"
                          + url.getHost() + ">");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:67,代码来源:HttpsClient.java


注:本文中的sun.security.util.HostnameChecker.match方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。