Ejemplo n.º 1
0
  /**
   * Sets the values of the certificate (body and signature).
   *
   * @param appSpe is a ASN1ApplicationSpecific object containing body and signature.
   * @throws IOException if tags or value are incorrect.
   */
  private void setPrivateData(ASN1ApplicationSpecific appSpe) throws IOException {
    valid = 0;
    if (appSpe.getApplicationTag() == EACTags.CARDHOLDER_CERTIFICATE) {
      ASN1InputStream content = new ASN1InputStream(appSpe.getContents());
      ASN1Primitive tmpObj;
      while ((tmpObj = content.readObject()) != null) {
        DERApplicationSpecific aSpe;
        if (tmpObj instanceof DERApplicationSpecific) {
          aSpe = (DERApplicationSpecific) tmpObj;
          switch (aSpe.getApplicationTag()) {
            case EACTags.CERTIFICATE_CONTENT_TEMPLATE:
              certificateBody = CertificateBody.getInstance(aSpe);
              valid |= bodyValid;
              break;
            case EACTags.STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP:
              signature = aSpe.getContents();
              valid |= signValid;
              break;
            default:
              throw new IOException(
                  "Invalid tag, not an Iso7816CertificateStructure :" + aSpe.getApplicationTag());
          }
        } else {
          throw new IOException("Invalid Object, not an Iso7816CertificateStructure");
        }
      }
      content.close();
    } else {
      throw new IOException("not a CARDHOLDER_CERTIFICATE :" + appSpe.getApplicationTag());
    }

    if (valid != (signValid | bodyValid)) {
      throw new IOException("invalid CARDHOLDER_CERTIFICATE :" + appSpe.getApplicationTag());
    }
  }
Ejemplo n.º 2
0
  public CVCertificate(byte[] in) throws IllegalArgumentException, IOException {
    ASN1StreamParser asn1Parser = new ASN1StreamParser(in);

    DERApplicationSpecific cvcert = (DERApplicationSpecific) asn1Parser.readObject();
    if (cvcert.getApplicationTag() != 0x21)
      throw new IllegalArgumentException("Can't find a CV Certificate");

    ASN1Sequence derCert =
        (ASN1Sequence) cvcert.getObject(BERTags.SEQUENCE); // Das CV Cerificate ist eine Sequence

    DERApplicationSpecific body =
        (DERApplicationSpecific)
            derCert.getObjectAt(0); // Das erste Objekt des Certificates ist der Cert-Body
    if (body.getApplicationTag() != 0x4E)
      throw new IllegalArgumentException("Can't find a Body in the CV Certificate");

    certBody = new CVCertBody(body);

    DERApplicationSpecific signature =
        (DERApplicationSpecific)
            derCert.getObjectAt(1); // Das zweite Objekt des Certificates ist die Signatur
    if (signature.getApplicationTag() != 0x37)
      throw new IllegalArgumentException("Can't find a Signature in the CV Certificate");

    certSignature = new CVCertSignature(signature.getContents());
  }
Ejemplo n.º 3
0
  /**
   * Create an iso7816Certificate structure from an object.
   *
   * @param obj the Object to extract the certificate from.
   * @return the Iso7816CertificateStructure represented by the byte stream.
   */
  public static CVCertificate getInstance(Object obj) {
    if (obj instanceof CVCertificate) {
      return (CVCertificate) obj;
    } else if (obj != null) {
      try {
        return new CVCertificate(DERApplicationSpecific.getInstance(obj));
      } catch (IOException e) {
        throw new ASN1ParsingException("unable to parse data: " + e.getMessage(), e);
      }
    }

    return null;
  }