コード例 #1
0
  private byte[] getextensionbytes(string oid) {
    extensions exts = c.gettbscertificate().getextensions();

    if (exts != null) {
      extension ext = exts.getextension(new asn1objectidentifier(oid));
      if (ext != null) {
        return ext.getextnvalue().getoctets();
      }
    }

    return null;
  }
コード例 #2
0
  public byte[] getextensionvalue(string oid) {
    extensions exts = c.gettbscertificate().getextensions();

    if (exts != null) {
      extension ext = exts.getextension(new asn1objectidentifier(oid));

      if (ext != null) {
        try {
          return ext.getextnvalue().getencoded();
        } catch (exception e) {
          throw new illegalstateexception("error parsing " + e.tostring());
        }
      }
    }

    return null;
  }
コード例 #3
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;
  }
コード例 #4
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;
  }
コード例 #5
0
  public string tostring() {
    stringbuffer buf = new stringbuffer();
    string nl = system.getproperty("line.separator");

    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();
  }