Class CAdESSignatureTimestampUtil

java.lang.Object
org.bouncycastle.cades.CAdESSignatureTimestampUtil

public final class CAdESSignatureTimestampUtil extends Object
Helpers for upgrading a CAdES B-B signature to B-T by attaching an id-aa-signatureTimeStampToken unsigned attribute carrying a caller-fetched RFC 3161 TSA token.

Per RFC 5126 sec. 6.1.1 / ETSI EN 319 122-1 sec. 5.3, the timestamp covers the value of the signature field within the SignerInfo being timestamped — not the whole CMS structure. A typical caller flow is:

  1. computeSignatureImprint(SignerInformation, AlgorithmIdentifier, DigestCalculatorProvider) returns the bytes to put in the TSP MessageImprint.
  2. The caller submits a TimeStampRequest to a TSA (over HTTP or any other transport — BC deliberately does not embed an HTTP client) and receives a TimeStampToken.
  3. applySignatureTimestamp(CMSSignedData, SignerId, TimeStampToken) returns a new CMSSignedData with the token attached to the specified signer.
The original CMSSignedData is unchanged.
  • Method Details

    • computeSignatureImprint

      public static byte[] computeSignatureImprint(SignerInformation signer, org.bouncycastle.asn1.x509.AlgorithmIdentifier digestAlg, DigestCalculatorProvider digCalcProv) throws OperatorCreationException, IOException
      Compute the MessageImprint input for a CAdES signature time-stamp request — the digest of SignerInfo.signature under the supplied algorithm.
      Parameters:
      signer - the signer whose signature value will be timestamped.
      digestAlg - the digest algorithm to use (typically matched to what the TSA supports / requires).
      digCalcProv - source of digest calculators.
      Returns:
      the digest bytes, suitable for use as the MessageImprint.hashedMessage.
      Throws:
      OperatorCreationException
      IOException
    • applySignatureTimestamp

      public static CMSSignedData applySignatureTimestamp(CMSSignedData signedData, SignerId signerId, TimeStampToken token) throws CAdESException
      Return a new CMSSignedData whose SignerInformation matching signerId has an id-aa-signatureTimeStampToken unsigned attribute appended carrying token.

      If the matched signer already has a signature-time-stamp attribute the new token is appended (the attribute is multi-valued per RFC 5126 sec. 6.1.1).

      Parameters:
      signedData - the source CMSSignedData (unchanged).
      signerId - selector identifying which signer to upgrade.
      token - the RFC 3161 token from the TSA.
      Returns:
      a new CMSSignedData with the timestamp attached.
      Throws:
      CAdESException - if no signer matches signerId.
    • getSignatureTimestamps

      public static List<TimeStampToken> getSignatureTimestamps(SignerInformation signer) throws CAdESException
      Return the RFC 3161 tokens carried by the signer's id-aa-signatureTimeStampToken unsigned attribute, in attribute-value order. The attribute is multi-valued (RFC 5126 sec. 6.1.1), so the list typically has one entry but may have more when multiple timestamps from different TSAs have been attached.
      Parameters:
      signer - the signer to inspect.
      Returns:
      an unmodifiable list of timestamp tokens, empty when the attribute is absent (signer has not been upgraded to B-T).
      Throws:
      CAdESException - if an attribute value cannot be parsed as a TimeStampToken.
    • validateSignatureTimestamps

      public static void validateSignatureTimestamps(SignerInformation signer, DigestCalculatorProvider digCalcProv) throws CAdESException, OperatorCreationException, IOException
      Self-consistency check on B-T material: for every id-aa-signatureTimeStampToken attached to the signer, verify the token's MessageImprint equals computeSignatureImprint run under the token's own hash algorithm.

      What this method does not do: validate the TSA's signature on the token, walk the TSA cert chain to a trust anchor, or check that the timestamp falls within the signer cert's validity window. Those steps are the caller's responsibility, built on getSignatureTimestamps(SignerInformation) plus the tsp module's token validators. Nor does it check that the signer's certificate is bound into the signed attributes, without which a time-stamped signature value says nothing about the key or content it is later presented with: validateSignatureTimestamps(SignerInformation, SignerInformationVerifier) does.

      Parameters:
      signer - the signer to validate. Must carry at least one id-aa-signatureTimeStampToken.
      digCalcProv - source of digest calculators.
      Throws:
      CAdESException - if the attribute is absent, a token cannot be parsed, or any token's imprint does not match the signer's signature value.
      OperatorCreationException
      IOException
    • validateSignatureTimestamps

      public static void validateSignatureTimestamps(SignerInformation signer, SignerInformationVerifier verifier) throws CAdESException, OperatorCreationException, IOException
      Validate a B-T signer against the certificate the verifier holds: the signature must verify under it, the signed attributes must identify it through an ESS signing-certificate attribute (RFC 5126 sec. 5.7.3, checked by SigningCertificateVerifier.verifySigningCertificate(SignerInformation, X509CertificateHolder, DigestCalculatorProvider)), and every id-aa-signatureTimeStampToken must carry the imprint of this signature value, as validateSignatureTimestamps(SignerInformation, DigestCalculatorProvider) checks. The second condition is what ties the time-stamped value to the certificate and the content; a signature value alone does not commit to the key that verifies it. The tokens' own signatures and TSA certificates remain the caller's to validate.
      Parameters:
      signer - the signer to validate. Must carry at least one id-aa-signatureTimeStampToken.
      verifier - verifier for the signer's signature, with its associated certificate; its digest calculators serve for the certificate hash and the imprints.
      Throws:
      CAdESException - if the signature does not verify, the certificate is not bound into the signed attributes, the time-stamp attribute is absent, a token cannot be parsed, or an imprint does not match.
      IllegalArgumentException - if the verifier has no associated certificate.
      OperatorCreationException
      IOException