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


Java HostnameChecker类代码示例

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


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

示例1: checkIdentity

import sun.security.util.HostnameChecker; //导入依赖的package包/类
static void checkIdentity(String hostname, X509Certificate cert,
        String algorithm) throws CertificateException {
    if (algorithm != null && algorithm.length() != 0) {
        // if IPv6 strip off the "[]"
        if ((hostname != null) && hostname.startsWith("[") &&
                hostname.endsWith("]")) {
            hostname = hostname.substring(1, hostname.length() - 1);
        }

        if (algorithm.equalsIgnoreCase("HTTPS")) {
            HostnameChecker.getInstance(HostnameChecker.TYPE_TLS).match(
                    hostname, cert);
        } else if (algorithm.equalsIgnoreCase("LDAP") ||
                algorithm.equalsIgnoreCase("LDAPS")) {
            HostnameChecker.getInstance(HostnameChecker.TYPE_LDAP).match(
                    hostname, cert);
        } else {
            throw new CertificateException(
                    "Unknown identification algorithm: " + algorithm);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:X509TrustManagerImpl.java

示例2: checkIdentity

import sun.security.util.HostnameChecker; //导入依赖的package包/类
private static void checkIdentity(String hostname, X509Certificate cert,
        String algorithm, boolean chainsToPublicCA)
        throws CertificateException {
    if (algorithm != null && algorithm.length() != 0) {
        // if IPv6 strip off the "[]"
        if ((hostname != null) && hostname.startsWith("[") &&
                hostname.endsWith("]")) {
            hostname = hostname.substring(1, hostname.length() - 1);
        }

        if (algorithm.equalsIgnoreCase("HTTPS")) {
            HostnameChecker.getInstance(HostnameChecker.TYPE_TLS).match(
                    hostname, cert, chainsToPublicCA);
        } else if (algorithm.equalsIgnoreCase("LDAP") ||
                algorithm.equalsIgnoreCase("LDAPS")) {
            HostnameChecker.getInstance(HostnameChecker.TYPE_LDAP).match(
                    hostname, cert, chainsToPublicCA);
        } else {
            throw new CertificateException(
                    "Unknown identification algorithm: " + algorithm);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:X509TrustManagerImpl.java

示例3: 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

示例4: checkIdentity

import sun.security.util.HostnameChecker; //导入依赖的package包/类
private void checkIdentity(String hostname, X509Certificate cert,
    String algorithm) throws CertificateException {
    if (algorithm != null && algorithm.length() != 0) {
        // if IPv6 strip off the "[]"
        if (hostname != null && hostname.startsWith("[") &&
            hostname.endsWith("]")) {
            hostname = hostname.substring(1, hostname.length()-1);
        }

        if (algorithm.equalsIgnoreCase("HTTPS")) {
            HostnameChecker.getInstance(HostnameChecker.TYPE_TLS).match(
                    hostname, cert);
        } else if (algorithm.equalsIgnoreCase("LDAP")) {
            HostnameChecker.getInstance(HostnameChecker.TYPE_LDAP).match(
                    hostname, cert);
        } else {
            throw new CertificateException(
                    "Unknown identification algorithm: " + algorithm);
        }
    }
}
 
开发者ID:coova,项目名称:jradius,代码行数:22,代码来源:X509TrustManagerImpl.java

示例5: verify

import sun.security.util.HostnameChecker; //导入依赖的package包/类
public boolean verify(String hostname, javax.net.ssl.SSLSession session) {
    try {
        String serverName;
        // Use ciphersuite to determine whether Kerberos is active.
        if (session.getCipherSuite().startsWith("TLS_KRB5")) {
            serverName =
                HostnameChecker.getServerName(getPeerPrincipal(session));

        } else { // X.509
            Certificate[] serverChain = session.getPeerCertificates();
            if ((serverChain == null) || (serverChain.length == 0)) {
                return false;
            }
            if (serverChain[0] instanceof X509Certificate == false) {
                return false;
            }
            X509Certificate serverCert = (X509Certificate)serverChain[0];
            serverName = getServername(serverCert);
        }
        if (serverName == null) {
            return false;
        }
        return verifier.verify(hostname, serverName);
    } catch (javax.net.ssl.SSLPeerUnverifiedException e) {
        return false;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:DelegateHttpsURLConnection.java

示例6: getNamesForCert

import sun.security.util.HostnameChecker; //导入依赖的package包/类
private String getNamesForCert(X509Certificate c) {

        String names = "";

        // We use the specification from
        // http://java.sun.com/j2se/1.5.0/docs/api/java/security/cert/X509Certificate.html#getSubjectAlternativeNames()
        // to determine the type of address
        int ALTNAME_DNS = 2;
        int ALTNAME_IP = 7;

        try {
            Collection<List<?>> subjAltNames = c.getSubjectAlternativeNames();
            X500Name subjectName = HostnameChecker.getSubjectX500Name(c);
            DerValue derValue = subjectName.findMostSpecificAttribute
                                                        (X500Name.commonName_oid);
            names += derValue.getAsString();

            if (subjAltNames != null) {
                for (List<?> next : subjAltNames) {
                    if (((Integer) next.get(0)).intValue() == ALTNAME_IP ||
                            ((Integer) next.get(0)).intValue() == ALTNAME_DNS) {
                        names += ", " + (String) next.get(1);
                    }
                }
            }

            if (subjAltNames != null)
                names = names.substring(2); // remove proceeding ", "

        } catch (CertificateParsingException cpe) {
            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, cpe);
        } catch (IOException ioe) {
            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ioe);
        }

        return names;
    }
 
开发者ID:GITNE,项目名称:icedtea-web,代码行数:38,代码来源:HttpsCertVerifier.java

示例7: 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

示例8: 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

示例9: main

import sun.security.util.HostnameChecker; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
    HostnameChecker hc = HostnameChecker.getInstance(HostnameChecker.TYPE_LDAP);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:Bar.java

示例10: main

import sun.security.util.HostnameChecker; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
     HostnameChecker hc = HostnameChecker.getInstance(HostnameChecker.TYPE_LDAP);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:WithRepl.java


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