Ejemplo n.º 1
0
  /**
   * Return a signer information object with passed in SignerInformationStore representing counter
   * signatures attached as an unsigned attribute.
   *
   * @param signerInformation the signerInfo to be used as the basis.
   * @param counterSigners signer info objects carrying counter signature.
   * @return a copy of the original SignerInformationObject with the changed attributes.
   */
  public static SignerInformation addCounterSigners(
      SignerInformation signerInformation, SignerInformationStore counterSigners) {
    // TODO Perform checks from RFC 3852 11.4

    SignerInfo sInfo = signerInformation.info;
    AttributeTable unsignedAttr = signerInformation.getUnsignedAttributes();
    ASN1EncodableVector v;

    if (unsignedAttr != null) {
      v = unsignedAttr.toASN1EncodableVector();
    } else {
      v = new ASN1EncodableVector();
    }

    ASN1EncodableVector sigs = new ASN1EncodableVector();

    for (Iterator it = counterSigners.getSigners().iterator(); it.hasNext(); ) {
      sigs.add(((SignerInformation) it.next()).toSignerInfo());
    }

    v.add(new Attribute(CMSAttributes.counterSignature, new DERSet(sigs)));

    return new SignerInformation(
        new SignerInfo(
            sInfo.getSID(),
            sInfo.getDigestAlgorithm(),
            sInfo.getAuthenticatedAttributes(),
            sInfo.getDigestEncryptionAlgorithm(),
            sInfo.getEncryptedDigest(),
            new DERSet(v)),
        signerInformation.contentType,
        signerInformation.content,
        null,
        new DefaultSignatureAlgorithmIdentifierFinder());
  }
 public List<TimestampToken> getSignatureTimestamps() {
   if (signatureTimeStamps == null) {
     try {
       signatureTimeStamps =
           UnsignedAttributesHelper.getSignatureTimestamps(
               firstSignerInfo.getUnsignedAttributes());
     } catch (Exception e) {
       ExceptionHandlerTyped.<SPISignatureException>handle(SPISignatureException.class, e);
     }
   }
   return signatureTimeStamps;
 }
 public void appendSignatureTimeStamp(byte[] timeStampTokenBytes) {
   try {
     AttributeTable at = firstSignerInfo.getUnsignedAttributes();
     firstSignerInfo =
         SignerInformation.replaceUnsignedAttributes(
             firstSignerInfo, appendTimestampAttribute(timeStampTokenBytes, at));
     Collection<SignerInformation> signers = new ArrayList<SignerInformation>(1);
     signers.add(firstSignerInfo);
     SignerInformationStore sis = new SignerInformationStore(signers);
     cmsSignedData = CMSSignedData.replaceSigners(cmsSignedData, sis);
   } catch (Exception e) {
     ExceptionHandlerTyped.<SPISignatureException>handle(SPISignatureException.class, e);
   }
 }