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.

      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