Package codec.asn1

Examples of codec.asn1.ASN1OctetString


     */
    public Verifier(Signable sigdat, SignerInfo info, X509Certificate cert)
      throws GeneralSecurityException {
  AlgorithmParameterSpec spec;
  ASN1ObjectIdentifier oid;
  ASN1OctetString octets;
  Attributes attributes;
  Attribute attribute;
  String sigalg;
  String mdalg;

  /*
   * Either a certificate or a SignerInfo is needed. We might do without
   * one of'em but not without both. The SignedData is need in every case.
   */
  if (info == null && cert == null) {
      throw new IllegalArgumentException(
        "Need either a SignerInfo or a certificate!");
  }
  if (sigdat == null) {
      throw new NullPointerException("Need a SignedData!");
  }
  target_ = sigdat;

  /*
   * If the SignerInfo is null then we try to get it from the SignedData.
   */
  if (info == null) {
      info = target_.getSignerInfo(cert);

      if (info == null) {
    throw new NoSuchSignerException("No signer info found for: "
      + cert.getIssuerDN().getName() + ", "
      + cert.getSerialNumber());
      }
  }
  /*
   * If we have a SignerInfo but no certificate the we try and see if we
   * can get it from the SignedData.
   */
  else if (cert == null) {
      cert = target_.getCertificate(info.getIssuerDN(), info
        .getSerialNumber());

      if (cert == null) {
    throw new CertificateException("No certificate available for: "
      + info.getIssuerDN().getName() + ", "
      + info.getSerialNumber());
      }
  }
  /*
   * We have both a SignerInfo and a certificate, now let's see if they
   * have matching issuer and serial number.
   */
  else {
      if (!info.equivIssuerAndSerialNumber(cert)) {
    throw new IllegalArgumentException(
      "SignerInfo and certificate don't match!");
      }
  }
  /*
   * At this point we should have both a SignerInfo and a matching
   * certificate.
   */
  info_ = info;
  cert_ = cert;
  sigalg = info_.getAlgorithm();

  /*
   * We now check for a simple one-step verification or a two-step
   * verification. One-step occurs only in the degenerate case that the
   * content type of the SignedData instance is DATA and there are no
   * authenticated attributes in it.
   *
   * Otherwise we have to check painfully for the various details on
   * required attributes.
   */
  attributes = info_.authenticatedAttributes();
  oid = target_.getContentType();

  if (attributes.size() > 0 || !oid.equals(DATA)) {
      twostep_ = true;

      attribute = info_.authenticatedAttributes().getAttribute(
        CONTENT_TYPE);

      if (attribute == null) {
    throw new NoSuchAttributeException(
      "ContentType attribute missing!");
      }
      if (attribute.valueCount() == 0) {
    throw new InvalidAttributeException(
      "ContentType attribute has no OID!");
      }
      if (!oid.equals(attribute.valueAt(0))) {
    throw new InvalidAttributeException(
      "ContentType attribute mismatch!");
      }
      attribute = info_.authenticatedAttributes().getAttribute(
        MESSAGE_DIGEST);

      if (attribute == null) {
    throw new NoSuchAttributeException(
      "MessageDigest attribute missing!");
      }
      if (attribute.valueCount() == 0) {
    throw new InvalidAttributeException(
      "MessageDigest attribute has no data!");
      }
      octets = (ASN1OctetString) attribute.valueAt(0);
      md_ = octets.getByteArray();
      mdalg = JCA.getName(JCA.getDigestOID(sigalg));

      if (mdalg == null) {
    throw new NoSuchAlgorithmException(
      "Cannot determine digest algorithm for " + sigalg);
View Full Code Here


  /* Digest Encryption Algorithm Identifier */
  cAlg_ = new AlgorithmIdentifier();
  add(cAlg_);

  /* Encrypted Digest */
  edig_ = new ASN1OctetString();
  add(edig_);

  /* Unauthenticated Attributes */
  attr_ = new Attributes();
  add(new ASN1TaggedType(1, attr_, false, true));
View Full Code Here

  /* Digest Encryption Algorithm Identifier */
  cAlg_ = new AlgorithmIdentifier();
  add(cAlg_);

  /* Encrypted Digest */
  edig_ = new ASN1OctetString();
  add(edig_);

  /* Unauthenticated Attributes */
  attr_ = new Attributes(registry);
  add(new ASN1TaggedType(1, attr_, false, true));
View Full Code Here

  /* Digest Encryption Algorithm Identifier */
  add(cAlg_);

  /* Encrypted Digest */
  edig_ = new ASN1OctetString();
  add(edig_);

  /* Unauthenticated Attributes */
  attr_ = new Attributes();
  add(new ASN1TaggedType(1, attr_, false, true));
View Full Code Here

  /* Digest Encryption Algorithm Identifier */
  add(cAlg_);

  /* Encrypted Digest */
  edig_ = new ASN1OctetString();
  add(edig_);

  /* Unauthenticated Attributes */
  attr_ = new Attributes();
  add(new ASN1TaggedType(1, attr_, false, true));
View Full Code Here

  /* Digest Encryption Algorithm Identifier */
  add(cAlg_);

  /* Encrypted Digest */
  edig_ = new ASN1OctetString();
  add(edig_);

  /* Unauthenticated Attributes */
  attr_ = new Attributes();
  add(new ASN1TaggedType(1, attr_, false, true));
View Full Code Here

  /* Digest Encryption Algorithm Identifier */
  add(cAlg_);

  /* Encrypted Digest */
  edig_ = new ASN1OctetString();
  add(edig_);

  /* Unauthenticated Attributes */
  attr_ = new Attributes();
  add(new ASN1TaggedType(1, attr_, false, true));
View Full Code Here

     *
     * @param edig
     *                The encrypted digest.
     */
    public void setEncryptedDigest(byte[] edig) {
  edig_ = new ASN1OctetString(edig);
  set(5, edig_);
    }
View Full Code Here

  if (twostep_) {
      b = digest_.digest();

      attribute = new Attribute((ASN1ObjectIdentifier) MESSAGE_DIGEST
        .clone(), new ASN1OctetString(b));

      info_.addAuthenticatedAttribute(attribute);
      info_.update(sig_);
  }
  /*
 
View Full Code Here

  uniformResourceIdentifier_ = new ASN1TaggedType(
    TYPE_UNIFORM_RESOURCE_IDENTIFIER, uniformResourceId_, false,
    false);
  addType(uniformResourceIdentifier_);

  iPAdr_ = new ASN1OctetString();

  iPAddress_ = new ASN1TaggedType(TYPE_IP_ADDRESS, iPAdr_, false, false);
  addType(iPAddress_);

  regID_ = new ASN1ObjectIdentifier();
View Full Code Here

TOP

Related Classes of codec.asn1.ASN1OctetString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.