Class CAdESSignatureTimestampUtil
java.lang.Object
org.bouncycastle.cades.CAdESSignatureTimestampUtil
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:
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, 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.- 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
-