private static int getServerCertificateFailures(X509Certificate cert, String realHostName) {
      int mask = 8;
      Date time = new Date(System.currentTimeMillis());
      if (time.before(cert.getNotBefore())) {
          mask |= 1;
      }
      if (time.after(cert.getNotAfter())) {
          mask |= 2;
      }
      String hostName = cert.getSubjectDN().getName();
      int index = hostName.indexOf("CN=") + 3;
      if (index >= 0) {
          hostName = hostName.substring(index);
          if (hostName.indexOf(' ') >= 0) {
              hostName = hostName.substring(0, hostName.indexOf(' '));
          }
          if (hostName.indexOf(',') >= 0) {
              hostName = hostName.substring(0, hostName.indexOf(','));
          }
      }
      if (realHostName != null && !realHostName.equals(hostName)) {
          mask |= 4;
      }
      return mask;
  }