本文整理汇总了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);
}
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
}
示例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;
}
示例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() + ">");
}
示例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() + ">");
}
示例9: main
import sun.security.util.HostnameChecker; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
HostnameChecker hc = HostnameChecker.getInstance(HostnameChecker.TYPE_LDAP);
}
示例10: main
import sun.security.util.HostnameChecker; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
HostnameChecker hc = HostnameChecker.getInstance(HostnameChecker.TYPE_LDAP);
}