Class CAdESSignatureTimestampUtil
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:
computeSignatureImprint(SignerInformation, AlgorithmIdentifier, DigestCalculatorProvider)returns the bytes to put in the TSPMessageImprint.- The caller submits a
TimeStampRequestto a TSA (over HTTP or any other transport — BC deliberately does not embed an HTTP client) and receives aTimeStampToken. applySignatureTimestamp(CMSSignedData, SignerId, TimeStampToken)returns a newCMSSignedDatawith the token attached to the specified signer.
CMSSignedData is unchanged.-
Method Summary
Modifier and TypeMethodDescriptionstatic CMSSignedDataapplySignatureTimestamp(CMSSignedData signedData, SignerId signerId, TimeStampToken token) Return a newCMSSignedDatawhoseSignerInformationmatchingsignerIdhas anid-aa-signatureTimeStampTokenunsigned attribute appended carryingtoken.static byte[]computeSignatureImprint(SignerInformation signer, org.bouncycastle.asn1.x509.AlgorithmIdentifier digestAlg, DigestCalculatorProvider digCalcProv) Compute theMessageImprintinput for a CAdES signature time-stamp request — the digest ofSignerInfo.signatureunder the supplied algorithm.static List<TimeStampToken> Return the RFC 3161 tokens carried by the signer'sid-aa-signatureTimeStampTokenunsigned attribute, in attribute-value order.static voidvalidateSignatureTimestamps(SignerInformation signer, SignerInformationVerifier verifier) 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.static voidvalidateSignatureTimestamps(SignerInformation signer, DigestCalculatorProvider digCalcProv) Self-consistency check on B-T material: for everyid-aa-signatureTimeStampTokenattached to the signer, verify the token'sMessageImprintequalscomputeSignatureImprintrun under the token's own hash algorithm.
-
Method Details
-
computeSignatureImprint
public static byte[] computeSignatureImprint(SignerInformation signer, org.bouncycastle.asn1.x509.AlgorithmIdentifier digestAlg, DigestCalculatorProvider digCalcProv) throws OperatorCreationException, IOException Compute theMessageImprintinput for a CAdES signature time-stamp request — the digest ofSignerInfo.signatureunder 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:
OperatorCreationExceptionIOException
-
applySignatureTimestamp
public static CMSSignedData applySignatureTimestamp(CMSSignedData signedData, SignerId signerId, TimeStampToken token) throws CAdESException Return a newCMSSignedDatawhoseSignerInformationmatchingsignerIdhas anid-aa-signatureTimeStampTokenunsigned attribute appended carryingtoken.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 matchessignerId.
-
getSignatureTimestamps
public static List<TimeStampToken> getSignatureTimestamps(SignerInformation signer) throws CAdESException Return the RFC 3161 tokens carried by the signer'sid-aa-signatureTimeStampTokenunsigned 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 aTimeStampToken.
-
validateSignatureTimestamps
public static void validateSignatureTimestamps(SignerInformation signer, DigestCalculatorProvider digCalcProv) throws CAdESException, OperatorCreationException, IOException Self-consistency check on B-T material: for everyid-aa-signatureTimeStampTokenattached to the signer, verify the token'sMessageImprintequalscomputeSignatureImprintrun 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 thetspmodule'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 oneid-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.OperatorCreationExceptionIOException
-
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 bySigningCertificateVerifier.verifySigningCertificate(SignerInformation, X509CertificateHolder, DigestCalculatorProvider)), and everyid-aa-signatureTimeStampTokenmust carry the imprint of this signature value, asvalidateSignatureTimestamps(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 oneid-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.OperatorCreationExceptionIOException
-