Top Description Inners Fields Constructors Methods
org.bouncycastle.tsp

public Class TimeStampResponseGenerator

extends Object
Class Inheritance
Imports
java.io.IOException, java.math.BigInteger, java.util.Date, .HashSet, .Iterator, .Set, org.bouncycastle.asn1.ASN1Encodable, .ASN1EncodableVector, .ASN1Integer, .ASN1ObjectIdentifier, .DERBitString, .DERSequence, .DERUTF8String, .DLSequence, org.bouncycastle.asn1.cmp.PKIFailureInfo, .PKIFreeText, .PKIStatus, .PKIStatusInfo, org.bouncycastle.asn1.cms.ContentInfo, org.bouncycastle.asn1.tsp.TimeStampResp, org.bouncycastle.asn1.x509.Extensions

Generator for RFC 3161 Time Stamp Responses.

New generate methods have been introduced to give people more control over what ends up in the message. Unfortunately it turns out that in some cases fields like statusString must be left out otherwise a an otherwise valid timestamp will be rejected.

If you're after the most control with generating a response use:
   TimeStampResponse tsResp;

   try
   {
      tsResp = tsRespGen.generateGrantedResponse(request, new BigInteger("23"), new Date());
   }
   catch (Exception e)
   {
       tsResp = tsRespGen.generateRejectedResponse(e);
   }
The generate method does this, but provides a status string of "Operation Okay".

It should be pointed out that generateRejectedResponse() may also, on very rare occasions throw a TSPException. In the event that happens, there's a serious internal problem with your responder.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private Set<E>
private Set<E>
private Set<E>
pack-priv int
pack-priv int
pack-priv ASN1EncodableVector
private TimeStampTokenGenerator

Constructor Summary

AccessConstructor and Description
public
TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, Set<E>
a set of OIDs giving accepted algorithms.
acceptedAlgorithms
)

public
TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, Set<E>
a set of OIDs giving accepted algorithms.
acceptedAlgorithms
,
Set<E>
if non-null a set of policies OIDs we are willing to sign under.
acceptedPolicies
)

public
TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, Set<E>
a set of OIDs giving accepted algorithms.
acceptedAlgorithms
,
Set<E>
if non-null a set of policies OIDs we are willing to sign under.
acceptedPolicies
,
Set<E>
if non-null a set of extensions OIDs we are willing to accept.
acceptedExtensions
)

Method Summary

Modifier and TypeMethod and Description
private void
addStatusString(String statusString)

private Set<E>
convert(Set<E> orig)

public TimeStampResponse

Returns:

a TimeStampResponse.
generate
(TimeStampRequest
the request this response is for.
request
,
BigInteger
serial number for the response token.
serialNumber
,
Date
generation time for the response token.
genTime
)

Return an appropriate TimeStampResponse.

public TimeStampResponse

Returns:

a TimeStampResponse with a failInfoField and optional statusString
generateFailResponse
(int
the PKIStatus to set.
status
,
int
the FailInfoField to set.
failInfoField
,
String
an optional string describing the failure.
statusString
)

Generate a non-granted TimeStampResponse with chosen status and FailInfoField.

public TimeStampResponse

Returns:

the TimeStampResponse with a status of PKIStatus.GRANTED
generateGrantedResponse
(TimeStampRequest
the request this response is for.
request
,
BigInteger
serial number for the response token.
serialNumber
,
Date
generation time for the response token.
genTime
)

Return a granted response, if the passed in request passes validation.

public TimeStampResponse

Returns:

the TimeStampResponse with a status of PKIStatus.GRANTED
generateGrantedResponse
(TimeStampRequest
the request this response is for.
request
,
BigInteger
serial number for the response token.
serialNumber
,
Date
generation time for the response token.
genTime
,
String statusString)

Return a granted response, if the passed in request passes validation with the passed in status string.

public TimeStampResponse

Returns:

the TimeStampResponse with a status of PKIStatus.GRANTED
generateGrantedResponse
(TimeStampRequest
the request this response is for.
request
,
BigInteger
serial number for the response token.
serialNumber
,
Date
generation time for the response token.
genTime
,
String statusString, Extensions
extra extensions to be added to the response token.
additionalExtensions
)

Return a granted response, if the passed in request passes validation with the passed in status string and extra extensions.

public TimeStampResponse

Returns:

a TimeStampResponse.
generateRejectedResponse
(Exception
the exception thrown on validating the request.
exception
)

Generate a generic rejection response based on a TSPValidationException or an Exception.

private PKIStatusInfo
private void
setFailInfoField(int field)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

acceptedAlgorithmsback to summary
private Set<E> acceptedAlgorithms
acceptedExtensionsback to summary
private Set<E> acceptedExtensions
acceptedPoliciesback to summary
private Set<E> acceptedPolicies
failInfoback to summary
pack-priv int failInfo
statusback to summary
pack-priv int status
statusStringsback to summary
pack-priv ASN1EncodableVector statusStrings
tokenGeneratorback to summary
private TimeStampTokenGenerator tokenGenerator

Constructor Detail

TimeStampResponseGeneratorback to summary
public TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, Set<E> acceptedAlgorithms)
Parameters
acceptedAlgorithms:Set<E>

a set of OIDs giving accepted algorithms.

TimeStampResponseGeneratorback to summary
public TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, Set<E> acceptedAlgorithms, Set<E> acceptedPolicies)
Parameters
acceptedAlgorithms:Set<E>

a set of OIDs giving accepted algorithms.

acceptedPolicies:Set<E>

if non-null a set of policies OIDs we are willing to sign under.

TimeStampResponseGeneratorback to summary
public TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, Set<E> acceptedAlgorithms, Set<E> acceptedPolicies, Set<E> acceptedExtensions)
Parameters
acceptedAlgorithms:Set<E>

a set of OIDs giving accepted algorithms.

acceptedPolicies:Set<E>

if non-null a set of policies OIDs we are willing to sign under.

acceptedExtensions:Set<E>

if non-null a set of extensions OIDs we are willing to accept.

Method Detail

addStatusStringback to summary
private void addStatusString(String statusString)
convertback to summary
private Set<E> convert(Set<E> orig)
generateback to summary
public TimeStampResponse generate(TimeStampRequest request, BigInteger serialNumber, Date genTime) throws TSPException

Return an appropriate TimeStampResponse.

If genTime is null a timeNotAvailable error response will be returned. Calling generate() is the equivalent of:

   TimeStampResponse tsResp;

   try
   {
      tsResp = tsRespGen.generateGrantedResponse(request, serialNumber, genTime, "Operation Okay");
   }
   catch (Exception e)
   {
       tsResp = tsRespGen.generateRejectedResponse(e);
   }
Parameters
request:TimeStampRequest

the request this response is for.

serialNumber:BigInteger

serial number for the response token.

genTime:Date

generation time for the response token.

Returns:TimeStampResponse

a TimeStampResponse.

generateFailResponseback to summary
public TimeStampResponse generateFailResponse(int status, int failInfoField, String statusString) throws TSPException

Generate a non-granted TimeStampResponse with chosen status and FailInfoField.

Parameters
status:int

the PKIStatus to set.

failInfoField:int

the FailInfoField to set.

statusString:String

an optional string describing the failure.

Returns:TimeStampResponse

a TimeStampResponse with a failInfoField and optional statusString

Exceptions
TSPException:
in case the response could not be created
generateGrantedResponseback to summary
public TimeStampResponse generateGrantedResponse(TimeStampRequest request, BigInteger serialNumber, Date genTime) throws TSPException

Return a granted response, if the passed in request passes validation.

If genTime is null a timeNotAvailable or a validation exception occurs a TSPValidationException will be thrown. The parent TSPException will only occur on some sort of system failure.

Parameters
request:TimeStampRequest

the request this response is for.

serialNumber:BigInteger

serial number for the response token.

genTime:Date

generation time for the response token.

Returns:TimeStampResponse

the TimeStampResponse with a status of PKIStatus.GRANTED

Exceptions
TSPException:
on validation exception or internal error.
generateGrantedResponseback to summary
public TimeStampResponse generateGrantedResponse(TimeStampRequest request, BigInteger serialNumber, Date genTime, String statusString) throws TSPException

Return a granted response, if the passed in request passes validation with the passed in status string.

If genTime is null a timeNotAvailable or a validation exception occurs a TSPValidationException will be thrown. The parent TSPException will only occur on some sort of system failure.

Parameters
request:TimeStampRequest

the request this response is for.

serialNumber:BigInteger

serial number for the response token.

genTime:Date

generation time for the response token.

Returns:TimeStampResponse

the TimeStampResponse with a status of PKIStatus.GRANTED

Exceptions
TSPException:
on validation exception or internal error.
generateGrantedResponseback to summary
public TimeStampResponse generateGrantedResponse(TimeStampRequest request, BigInteger serialNumber, Date genTime, String statusString, Extensions additionalExtensions) throws TSPException

Return a granted response, if the passed in request passes validation with the passed in status string and extra extensions.

If genTime is null a timeNotAvailable or a validation exception occurs a TSPValidationException will be thrown. The parent TSPException will only occur on some sort of system failure.

Parameters
request:TimeStampRequest

the request this response is for.

serialNumber:BigInteger

serial number for the response token.

genTime:Date

generation time for the response token.

additionalExtensions:Extensions

extra extensions to be added to the response token.

Returns:TimeStampResponse

the TimeStampResponse with a status of PKIStatus.GRANTED

Exceptions
TSPException:
on validation exception or internal error.
generateRejectedResponseback to summary
public TimeStampResponse generateRejectedResponse(Exception exception) throws TSPException

Generate a generic rejection response based on a TSPValidationException or an Exception. Exceptions which are not an instance of TSPValidationException will be treated as systemFailure. The return value of exception.getMessage() will be used as the status string for the response.

Parameters
exception:Exception

the exception thrown on validating the request.

Returns:TimeStampResponse

a TimeStampResponse.

Exceptions
TSPException:
if a failure response cannot be generated.
getPKIStatusInfoback to summary
private PKIStatusInfo getPKIStatusInfo()
setFailInfoFieldback to summary
private void setFailInfoField(int field)
org.bouncycastle.tsp back to summary

pack-priv Class TimeStampResponseGenerator.FailInfo

extends DERBitString
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv
FailInfo(int failInfoValue)

Method Summary

Inherited from org.bouncycastle.asn1.DERBitString:
convert

Constructor Detail

FailInfoback to summary
pack-priv FailInfo(int failInfoValue)