Examples of HostnameChecker


Examples of sun.security.util.HostnameChecker

            host = host.substring(1, host.length()-1);
        }

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

            Principal principal = getPeerPrincipal();
            if (principal instanceof KerberosPrincipal) {
                if (!HostnameChecker.match(host, (KerberosPrincipal)principal)) {
                    throw new SSLPeerUnverifiedException("Hostname checker" +
                                " failed for Kerberos");
                }
            } else {
                // 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;
View Full Code Here

Examples of sun.security.util.HostnameChecker

        if (hostname != null && hostname.startsWith("[") &&
                hostname.endsWith("]")) {
            hostname = hostname.substring(1, hostname.length() - 1);
        }
        try {
            HostnameChecker checker = HostnameChecker.getInstance(
                                                HostnameChecker.TYPE_LDAP);
            Principal principal = getPeerPrincipal(session);
            if (principal instanceof KerberosPrincipal) {
                if (!checker.match(hostname, (KerberosPrincipal) principal)) {
                    throw new SSLPeerUnverifiedException(
                        "hostname of the kerberos principal:" + principal +
                        " does not match the hostname:" + hostname);
                }
            } else {

                // get the subject's certificate
                certs = session.getPeerCertificates();
                X509Certificate peerCert;
                if (certs[0] instanceof java.security.cert.X509Certificate) {
                    peerCert = (java.security.cert.X509Certificate) certs[0];
                } else {
                    throw new SSLPeerUnverifiedException(
                            "Received a non X509Certificate from the server");
                }
                checker.match(hostname, peerCert);
            }

            // no exception means verification passed
            return true;
        } catch (SSLPeerUnverifiedException e) {
View Full Code Here

Examples of sun.security.util.HostnameChecker

      // TODO This hostname verifier is the default in Smack 4.1 when
      // smack-java7 is used, remove the code once Smack 4.1 is used
      cfg.setHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
          HostnameChecker checker = HostnameChecker
              .getInstance(HostnameChecker.TYPE_TLS);

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

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

              try {
                checker.match(hostname, peerCertificate);
                // Certificate matches hostname
                validCertificate = true;
              } catch (CertificateException ex) {
                // Certificate does not match hostname
              }
View Full Code Here

Examples of sun.security.util.HostnameChecker

        if (hostname != null && hostname.startsWith("[") &&
                hostname.endsWith("]")) {
            hostname = hostname.substring(1, hostname.length() - 1);
        }
        try {
            HostnameChecker checker = HostnameChecker.getInstance(
                                                HostnameChecker.TYPE_LDAP);
            // Use ciphersuite to determine whether Kerberos is active.
            if (session.getCipherSuite().startsWith("TLS_KRB5")) {
                Principal principal = getPeerPrincipal(session);
                if (!checker.match(hostname, principal)) {
                    throw new SSLPeerUnverifiedException(
                        "hostname of the kerberos principal:" + principal +
                        " does not match the hostname:" + hostname);
                }
            } else { // X.509

                // get the subject's certificate
                certs = session.getPeerCertificates();
                X509Certificate peerCert;
                if (certs[0] instanceof java.security.cert.X509Certificate) {
                    peerCert = (java.security.cert.X509Certificate) certs[0];
                } else {
                    throw new SSLPeerUnverifiedException(
                            "Received a non X509Certificate from the server");
                }
                checker.match(hostname, peerCert);
            }

            // no exception means verification passed
            return true;
        } catch (SSLPeerUnverifiedException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.