Package org.bouncycastle.tsp
Class TimeStampTokenGenerator
- java.lang.Object
-
- org.bouncycastle.tsp.TimeStampTokenGenerator
-
public class TimeStampTokenGenerator extends java.lang.ObjectGenerator for the RFC 3161 time-stamp token (theSignedDatacarried as thetimeStampTokenof a time-stamp response) over aTimeStampRequest.The signing certificate is bound into the token through a signing-certificate signed attribute. If a digest calculator based on SHA-1 is passed in the class supports the original
id-aa-signingCertificateattribute (carrying an ESSCertID), otherwise it uses theid-aa-signingCertificateV2attribute (carrying an ESSCertIDv2) introduced for RFC 3161 by RFC 5816. In the event you need to pass both types, you will need to override the SignedAttributeGenerator for the SignerInfoGeneratorBuilder you are using. For the default for ESSCertIDv2 the code will look something like the following:final ESSCertID essCertid = new ESSCertID(certHashSha1, issuerSerial); final ESSCertIDv2 essCertidV2 = new ESSCertIDv2(certHashSha256, issuerSerial); signerInfoGenBuilder.setSignedAttributeGenerator(new CMSAttributeTableGenerator() { public AttributeTable getAttributes(Map parameters) throws CMSAttributeTableGenerationException { CMSAttributeTableGenerator attrGen = new DefaultSignedAttributeTableGenerator(); AttributeTable table = attrGen.getAttributes(parameters); table = table.add(PKCSObjectIdentifiers.id_aa_signingCertificate, new SigningCertificate(essCertid)); table = table.add(PKCSObjectIdentifiers.id_aa_signingCertificateV2, new SigningCertificateV2(essCertidV2)); return table; } });
-
-
Field Summary
Fields Modifier and Type Field Description static intR_HUNDREDTHS_OF_SECONDSCreate time-stamps with a resolution of 1 hundredth of a second.static intR_MICROSECONDSDeprecated.use R_HUNDREDTHS_OF_SECONDS - this field will be deleted!!static intR_MILLISECONDSCreate time-stamps with a resolution of 1 millisecond.static intR_SECONDSCreate time-stamps with a resolution of 1 second (the default).static intR_TENTHS_OF_SECONDSCreate time-stamps with a resolution of 1 tenth of a second.
-
Constructor Summary
Constructors Constructor Description TimeStampTokenGenerator(SignerInfoGenerator signerInfoGen, DigestCalculator digestCalculator, org.bouncycastle.asn1.ASN1ObjectIdentifier tsaPolicy)Basic Constructor - set up a calculator based on signerInfoGen with a ESSCertID calculated from the signer's associated certificate using the sha1DigestCalculator.TimeStampTokenGenerator(SignerInfoGenerator signerInfoGen, DigestCalculator digestCalculator, org.bouncycastle.asn1.ASN1ObjectIdentifier tsaPolicy, boolean isIssuerSerialIncluded)Basic Constructor - set up a calculator based on signerInfoGen with a ESSCertID calculated from the signer's associated certificate using the sha1DigestCalculator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttributeCertificates(org.bouncycastle.util.Store attrStore)Add the store of attribute certificates to be included with the generated TimeStampToken.voidaddCertificates(org.bouncycastle.util.Store certStore)Add the store of X509 Certificates to the generator.voidaddCRLs(org.bouncycastle.util.Store crlStore)Add the store of CRLs to be included with the generated TimeStampToken.voidaddOtherRevocationInfo(org.bouncycastle.asn1.ASN1ObjectIdentifier otherRevocationInfoFormat, org.bouncycastle.util.Store otherRevocationInfos)Add a Store of otherRevocationData to the CRL set to be included with the generated TimeStampToken.TimeStampTokengenerate(TimeStampRequest request, java.math.BigInteger serialNumber, java.util.Date genTime)Generate a TimeStampToken for the passed in request and serialNumber marking it with the passed in genTime.TimeStampTokengenerate(TimeStampRequest request, java.math.BigInteger serialNumber, java.util.Date genTime, org.bouncycastle.asn1.x509.Extensions additionalExtensions)Generate a TimeStampToken for the passed in request and serialNumber marking it with the passed in genTime.voidsetAccuracyMicros(int accuracyMicros)Set the microseconds component of the accuracy with which the genTime is reported (RFC 3161 Accuracy).voidsetAccuracyMillis(int accuracyMillis)Set the milliseconds component of the accuracy with which the genTime is reported (RFC 3161 Accuracy).voidsetAccuracySeconds(int accuracySeconds)Set the seconds component of the accuracy with which the genTime is reported (RFC 3161 Accuracy).voidsetLocale(java.util.Locale locale)Set a Locale for time creation - you may need to use this if the default locale doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.voidsetOrdering(boolean ordering)Set the ordering field of the generated TSTInfo.voidsetResolution(int resolution)Set the resolution of the time stamp - R_SECONDS (the default), R_TENTH_OF_SECONDS, R_MICROSECONDS, R_MILLISECONDSvoidsetTSA(org.bouncycastle.asn1.x509.GeneralName tsa)Set the optional tsa field naming the authority producing the token (RFC 3161 TSTInfo).
-
-
-
Field Detail
-
R_SECONDS
public static final int R_SECONDS
Create time-stamps with a resolution of 1 second (the default).- See Also:
- Constant Field Values
-
R_TENTHS_OF_SECONDS
public static final int R_TENTHS_OF_SECONDS
Create time-stamps with a resolution of 1 tenth of a second.- See Also:
- Constant Field Values
-
R_HUNDREDTHS_OF_SECONDS
public static final int R_HUNDREDTHS_OF_SECONDS
Create time-stamps with a resolution of 1 hundredth of a second.- See Also:
- Constant Field Values
-
R_MICROSECONDS
public static final int R_MICROSECONDS
Deprecated.use R_HUNDREDTHS_OF_SECONDS - this field will be deleted!!- See Also:
- Constant Field Values
-
R_MILLISECONDS
public static final int R_MILLISECONDS
Create time-stamps with a resolution of 1 millisecond.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TimeStampTokenGenerator
public TimeStampTokenGenerator(SignerInfoGenerator signerInfoGen, DigestCalculator digestCalculator, org.bouncycastle.asn1.ASN1ObjectIdentifier tsaPolicy) throws java.lang.IllegalArgumentException, TSPException
Basic Constructor - set up a calculator based on signerInfoGen with a ESSCertID calculated from the signer's associated certificate using the sha1DigestCalculator. If alternate values are required for id-aa-signingCertificate they should be added to the signerInfoGen object before it is passed in, otherwise a standard digest based value will be added.- Parameters:
signerInfoGen- the generator for the signer we are using.digestCalculator- calculator for to use for digest of certificate.tsaPolicy- tasPolicy to send.- Throws:
java.lang.IllegalArgumentException- if calculator is not SHA-1 or there is no associated certificate for the signer,TSPException- if the signer certificate cannot be processed.
-
TimeStampTokenGenerator
public TimeStampTokenGenerator(SignerInfoGenerator signerInfoGen, DigestCalculator digestCalculator, org.bouncycastle.asn1.ASN1ObjectIdentifier tsaPolicy, boolean isIssuerSerialIncluded) throws java.lang.IllegalArgumentException, TSPException
Basic Constructor - set up a calculator based on signerInfoGen with a ESSCertID calculated from the signer's associated certificate using the sha1DigestCalculator. If alternate values are required for id-aa-signingCertificate they should be added to the signerInfoGen object before it is passed in, otherwise a standard digest based value will be added.- Parameters:
signerInfoGen- the generator for the signer we are using.digestCalculator- calculator for to use for digest of certificate.tsaPolicy- tasPolicy to send.isIssuerSerialIncluded- should issuerSerial be included in the ESSCertIDs, true if yes, by default false.- Throws:
java.lang.IllegalArgumentException- if calculator is not SHA-1 or there is no associated certificate for the signer,TSPException- if the signer certificate cannot be processed.
-
-
Method Detail
-
addCertificates
public void addCertificates(org.bouncycastle.util.Store certStore)
Add the store of X509 Certificates to the generator.- Parameters:
certStore- a Store containing X509CertificateHolder objects
-
addCRLs
public void addCRLs(org.bouncycastle.util.Store crlStore)
Add the store of CRLs to be included with the generated TimeStampToken.- Parameters:
crlStore- a Store containing X509CRLHolder objects.
-
addAttributeCertificates
public void addAttributeCertificates(org.bouncycastle.util.Store attrStore)
Add the store of attribute certificates to be included with the generated TimeStampToken.- Parameters:
attrStore- a Store containing X509AttributeCertificate objects.
-
addOtherRevocationInfo
public void addOtherRevocationInfo(org.bouncycastle.asn1.ASN1ObjectIdentifier otherRevocationInfoFormat, org.bouncycastle.util.Store otherRevocationInfos)Add a Store of otherRevocationData to the CRL set to be included with the generated TimeStampToken.- Parameters:
otherRevocationInfoFormat- the OID specifying the format of the otherRevocationInfo data.otherRevocationInfos- a Store of otherRevocationInfo data to add.
-
setResolution
public void setResolution(int resolution)
Set the resolution of the time stamp - R_SECONDS (the default), R_TENTH_OF_SECONDS, R_MICROSECONDS, R_MILLISECONDS- Parameters:
resolution- resolution of timestamps to be produced.
-
setLocale
public void setLocale(java.util.Locale locale)
Set a Locale for time creation - you may need to use this if the default locale doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.- Parameters:
locale- a locale to use for converting system time into a GeneralizedTime.
-
setAccuracySeconds
public void setAccuracySeconds(int accuracySeconds)
Set the seconds component of the accuracy with which the genTime is reported (RFC 3161 Accuracy).- Parameters:
accuracySeconds- whole-seconds accuracy, ignored if not greater than zero.
-
setAccuracyMillis
public void setAccuracyMillis(int accuracyMillis)
Set the milliseconds component of the accuracy with which the genTime is reported (RFC 3161 Accuracy).- Parameters:
accuracyMillis- milliseconds accuracy (1..999), ignored if not greater than zero.
-
setAccuracyMicros
public void setAccuracyMicros(int accuracyMicros)
Set the microseconds component of the accuracy with which the genTime is reported (RFC 3161 Accuracy).- Parameters:
accuracyMicros- microseconds accuracy (1..999), ignored if not greater than zero.
-
setOrdering
public void setOrdering(boolean ordering)
Set the ordering field of the generated TSTInfo. When true the genTime can always be ordered with respect to the genTime of other tokens from the same TSA regardless of accuracy (RFC 3161 2.4.2).- Parameters:
ordering- true if every token from this TSA is orderable, false (the default) otherwise.
-
setTSA
public void setTSA(org.bouncycastle.asn1.x509.GeneralName tsa)
Set the optional tsa field naming the authority producing the token (RFC 3161 TSTInfo).- Parameters:
tsa- a GeneralName identifying the TSA.
-
generate
public TimeStampToken generate(TimeStampRequest request, java.math.BigInteger serialNumber, java.util.Date genTime) throws TSPException
Generate a TimeStampToken for the passed in request and serialNumber marking it with the passed in genTime.- Parameters:
request- the originating request.serialNumber- serial number for the TimeStampTokengenTime- token generation time.- Returns:
- a TimeStampToken
- Throws:
TSPException
-
generate
public TimeStampToken generate(TimeStampRequest request, java.math.BigInteger serialNumber, java.util.Date genTime, org.bouncycastle.asn1.x509.Extensions additionalExtensions) throws TSPException
Generate a TimeStampToken for the passed in request and serialNumber marking it with the passed in genTime.- Parameters:
request- the originating request.serialNumber- serial number for the TimeStampTokengenTime- token generation time.additionalExtensions- extra extensions to be added to the response token.- Returns:
- a TimeStampToken
- Throws:
TSPException
-
-