code: private boolean verifyHostname(String hostname, X509Certificate certificate) {
          hostname = hostname.toLowerCase(Locale.US);
          boolean hasDns = false;
          List<String> altNames = getSubjectAltNames(certificate, ALT_DNS_NAME);
          for (int i = 0, size = altNames.size(); i < size; i++) {
              hasDns = true;
              if (verifyHostname(hostname, altNames.get(i))) {
                  return true;
              }
          }
  
          if (!hasDns) {
              X500Principal principal = certificate.getSubjectX500Principal();
              // RFC 2818 advises using the most specific name for matching.
              String cn = new DistinguishedNameParser(principal).findMostSpecific("cn");
              if (cn != null) {
                  return verifyHostname(hostname, cn);
              }
              else {
                  // NOTE: In case of empty Common Name (CN), not checking
                  return true;
              }
          }
  
          return false;
      }
docs: Returns true if {@code certificate} matches {@code hostname}.