コード例 #1
0
  public String toString() {
    StringBuffer buf = new StringBuffer();
    String nl = Strings.lineSeparator();

    buf.append("      userCertificate: ").append(this.getSerialNumber()).append(nl);
    buf.append("       revocationDate: ").append(this.getRevocationDate()).append(nl);
    buf.append("       certificateIssuer: ").append(this.getCertificateIssuer()).append(nl);

    Extensions extensions = c.getExtensions();

    if (extensions != null) {
      Enumeration e = extensions.oids();
      if (e.hasMoreElements()) {
        buf.append("   crlEntryExtensions:").append(nl);

        while (e.hasMoreElements()) {
          ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
          Extension ext = extensions.getExtension(oid);
          if (ext.getExtnValue() != null) {
            byte[] octs = ext.getExtnValue().getOctets();
            ASN1InputStream dIn = new ASN1InputStream(octs);
            buf.append("                       critical(").append(ext.isCritical()).append(") ");
            try {
              if (oid.equals(X509Extension.reasonCode)) {
                buf.append(CRLReason.getInstance(ASN1Enumerated.getInstance(dIn.readObject())))
                    .append(nl);
              } else if (oid.equals(X509Extension.certificateIssuer)) {
                buf.append("Certificate issuer: ")
                    .append(GeneralNames.getInstance(dIn.readObject()))
                    .append(nl);
              } else {
                buf.append(oid.getId());
                buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
              }
            } catch (Exception ex) {
              buf.append(oid.getId());
              buf.append(" value = ").append("*****").append(nl);
            }
          } else {
            buf.append(nl);
          }
        }
      }
    }

    return buf.toString();
  }
コード例 #2
0
  private Set getExtensionOIDs(boolean critical) {
    Extensions extensions = c.getExtensions();

    if (extensions != null) {
      Set set = new HashSet();
      Enumeration e = extensions.oids();

      while (e.hasMoreElements()) {
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
        Extension ext = extensions.getExtension(oid);

        if (critical == ext.isCritical()) {
          set.add(oid.getId());
        }
      }

      return set;
    }

    return null;
  }
コード例 #3
0
  private static Collection getAlternativeNames(byte[] extVal) throws CertificateParsingException {
    if (extVal == null) {
      return null;
    }
    try {
      Collection temp = new ArrayList();
      Enumeration it = ASN1Sequence.getInstance(extVal).getObjects();
      while (it.hasMoreElements()) {
        GeneralName genName = GeneralName.getInstance(it.nextElement());
        List list = new ArrayList();
        list.add(Integers.valueOf(genName.getTagNo()));
        switch (genName.getTagNo()) {
          case GeneralName.ediPartyName:
          case GeneralName.x400Address:
          case GeneralName.otherName:
            list.add(genName.getEncoded());
            break;
          case GeneralName.directoryName:
            list.add(X500Name.getInstance(RFC4519Style.INSTANCE, genName.getName()).toString());
            break;
          case GeneralName.dNSName:
          case GeneralName.rfc822Name:
          case GeneralName.uniformResourceIdentifier:
            list.add(((ASN1String) genName.getName()).getString());
            break;
          case GeneralName.registeredID:
            list.add(ASN1ObjectIdentifier.getInstance(genName.getName()).getId());
            break;
          case GeneralName.iPAddress:
            byte[] addrBytes = DEROctetString.getInstance(genName.getName()).getOctets();
            final String addr;
            try {
              addr = InetAddress.getByAddress(addrBytes).getHostAddress();
            } catch (UnknownHostException e) {
              continue;
            }
            list.add(addr);
            break;
          default:
            throw new IOException("Bad tag number: " + genName.getTagNo());
        }

        temp.add(Collections.unmodifiableList(list));
      }
      if (temp.size() == 0) {
        return null;
      }
      return Collections.unmodifiableCollection(temp);
    } catch (Exception e) {
      throw new CertificateParsingException(e.getMessage());
    }
  }
コード例 #4
0
  public Set getNonCriticalExtensionOIDs() {
    if (this.getVersion() == 3) {
      Set set = new HashSet();
      Extensions extensions = c.getTBSCertificate().getExtensions();

      if (extensions != null) {
        Enumeration e = extensions.oids();

        while (e.hasMoreElements()) {
          ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
          Extension ext = extensions.getExtension(oid);

          if (!ext.isCritical()) {
            set.add(oid.getId());
          }
        }

        return set;
      }
    }

    return null;
  }
コード例 #5
0
  public boolean hasUnsupportedCriticalExtension() {
    if (this.getVersion() == 3) {
      Extensions extensions = c.getTBSCertificate().getExtensions();

      if (extensions != null) {
        Enumeration e = extensions.oids();

        while (e.hasMoreElements()) {
          ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
          String oidId = oid.getId();

          if (oidId.equals(RFC3280CertPathUtilities.KEY_USAGE)
              || oidId.equals(RFC3280CertPathUtilities.CERTIFICATE_POLICIES)
              || oidId.equals(RFC3280CertPathUtilities.POLICY_MAPPINGS)
              || oidId.equals(RFC3280CertPathUtilities.INHIBIT_ANY_POLICY)
              || oidId.equals(RFC3280CertPathUtilities.CRL_DISTRIBUTION_POINTS)
              || oidId.equals(RFC3280CertPathUtilities.ISSUING_DISTRIBUTION_POINT)
              || oidId.equals(RFC3280CertPathUtilities.DELTA_CRL_INDICATOR)
              || oidId.equals(RFC3280CertPathUtilities.POLICY_CONSTRAINTS)
              || oidId.equals(RFC3280CertPathUtilities.BASIC_CONSTRAINTS)
              || oidId.equals(RFC3280CertPathUtilities.SUBJECT_ALTERNATIVE_NAME)
              || oidId.equals(RFC3280CertPathUtilities.NAME_CONSTRAINTS)) {
            continue;
          }

          Extension ext = extensions.getExtension(oid);

          if (ext.isCritical()) {
            return true;
          }
        }
      }
    }

    return false;
  }
コード例 #6
0
  public String toString() {
    StringBuffer buf = new StringBuffer();
    String nl = Strings.lineSeparator();

    buf.append("  [0]         Version: ").append(this.getVersion()).append(nl);
    buf.append("         SerialNumber: ").append(this.getSerialNumber()).append(nl);
    buf.append("             IssuerDN: ").append(this.getIssuerDN()).append(nl);
    buf.append("           Start Date: ").append(this.getNotBefore()).append(nl);
    buf.append("           Final Date: ").append(this.getNotAfter()).append(nl);
    buf.append("            SubjectDN: ").append(this.getSubjectDN()).append(nl);
    buf.append("           Public Key: ").append(this.getPublicKey()).append(nl);
    buf.append("  Signature Algorithm: ").append(this.getSigAlgName()).append(nl);

    byte[] sig = this.getSignature();

    buf.append("            Signature: ").append(new String(Hex.encode(sig, 0, 20))).append(nl);
    for (int i = 20; i < sig.length; i += 20) {
      if (i < sig.length - 20) {
        buf.append("                       ").append(new String(Hex.encode(sig, i, 20))).append(nl);
      } else {
        buf.append("                       ")
            .append(new String(Hex.encode(sig, i, sig.length - i)))
            .append(nl);
      }
    }

    Extensions extensions = c.getTBSCertificate().getExtensions();

    if (extensions != null) {
      Enumeration e = extensions.oids();

      if (e.hasMoreElements()) {
        buf.append("       Extensions: \n");
      }

      while (e.hasMoreElements()) {
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
        Extension ext = extensions.getExtension(oid);

        if (ext.getExtnValue() != null) {
          byte[] octs = ext.getExtnValue().getOctets();
          ASN1InputStream dIn = new ASN1InputStream(octs);
          buf.append("                       critical(").append(ext.isCritical()).append(") ");
          try {
            if (oid.equals(Extension.basicConstraints)) {
              buf.append(BasicConstraints.getInstance(dIn.readObject())).append(nl);
            } else if (oid.equals(Extension.keyUsage)) {
              buf.append(KeyUsage.getInstance(dIn.readObject())).append(nl);
            } else if (oid.equals(MiscObjectIdentifiers.netscapeCertType)) {
              buf.append(new NetscapeCertType((DERBitString) dIn.readObject())).append(nl);
            } else if (oid.equals(MiscObjectIdentifiers.netscapeRevocationURL)) {
              buf.append(new NetscapeRevocationURL((DERIA5String) dIn.readObject())).append(nl);
            } else if (oid.equals(MiscObjectIdentifiers.verisignCzagExtension)) {
              buf.append(new VerisignCzagExtension((DERIA5String) dIn.readObject())).append(nl);
            } else {
              buf.append(oid.getId());
              buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
              // buf.append(" value = ").append("*****").append(nl);
            }
          } catch (Exception ex) {
            buf.append(oid.getId());
            //     buf.append(" value = ").append(new
            // String(Hex.encode(ext.getExtnValue().getOctets()))).append(nl);
            buf.append(" value = ").append("*****").append(nl);
          }
        } else {
          buf.append(nl);
        }
      }
    }

    return buf.toString();
  }