IAIK TSP
version 2.32

iaik.tsp
Class TimeStampResp

java.lang.Object
  extended by iaik.tsp.TimeStampResp

public class TimeStampResp
extends java.lang.Object

This class implements the TSP ASN.1 type TimeStampResp as it is specified in RFC 3161.

 TimeStampResp ::= SEQUENCE {
     status         PKIStatusInfo,
     timeStampToken TimeStampToken OPTIONAL
 }
 
 PKIStatusInfo ::= SEQUENCE {
     status               PKIStatus,
     statusString   PKIFreeText    OPTIONAL,
     failInfo     PKIFailureInfo OPTIONAL
 }
 

This class handles the ASN.1 structure and the DER encoding and decoding of this structure.

If the status is zero a TimeStampToken is present. If the Time Stamp Token is not present, the failInfo indicates the reason why the time stamp request was rejected. The statusString field of PKIStatusInfo MAY be used to include reason text such as "messageImprint field is not correctly formatted". If the status returned is different from zero or one, then no TimeStampToken is returned. Example code for creating a TimeStampResp:

 
 TimeStampReq request = null;
 try {
   //data = received time stamp request from client
   request = new TimeStampReq(data);
 } catch (CodingException ex) {
   ex.printStackTrace();
   return;
 }

 //create TSTInfo
 TSTInfo tstInfo = new TSTInfo();
 
 //the time at which the time stamp is generated
 Date genTime = ...;
 tstInfo.setGenTime(genTime);
 
 //set the imprint
 tstInfo.setMessageImprint(request.getMessageImprint());
 
 //set the accuracy (optional)
 Accuracy acc = new Accuracy();
 acc.setMicros(1);
 acc.setMillis(1);
 acc.setSeconds(1);
 tstInfo.setAccuracy(acc);
 
 //if the request contains a nonce the response must have the same (optional)
 if (request.getNonce() != null) {
   tstInfo.setNonce(request.getNonce());
 }
 
 //set the serial number  
 tstInfo.setSerialNumber(generateSerialNumber());
 
 ObjectID oid = request.getTSAPolicyID();
 
 //if the server supports the requested oid set the tsa policy id
 //if the requested oid is not supported send a PKIFailureInfo with unacceptedPolicy value
 //if the request does not contain a policy id you can set it or not
 tstInfo.setTSAPolicyID(oid);

 //create TimeStampToken
 TimeStampToken token = new TimeStampToken(tstInfo);
 
 //if requested by the client include the TSA certificate chain in the response
 if (request.getCertReq()) {
   //set the certificate chain of the response signing TSA
   X509Certificate[] tsaCerts = ...;
   token.setCertificates(tsaCerts);
 }
 
 //set the signing certificate
 X509Certificate signingCert = ...;
 token.setSigningCertificate(signingCert);

 //set the hash algorithm to be used for signing
 AlgorithmID hashAlgorithm = ...;
 token.setHashAlgorithm(hashAlgorithm);

 //set the private key for signing
 PrivateKey signingKey = ...;
 token.setPrivateKey(signingKey);
 
 //sign the token
 try {
   token.signTimeStampToken();
 } catch (TspSigningException ex) {
   ex.printStackTrace();  
   return;
  }
 
 //create a new time stamp response
 TimeStampResp response = new TimeStampResp();
 
 //set the token
 response.setTimeStampToken(token);
 
 //create a new status
 PKIStatus status = new PKIStatus(PKIStatus.GRANTED);
 
 //create a new info
 PKIStatusInfo info = new PKIStatusInfo(status);
 
 //set the info
 response.setPKIStatusInfo(info);
 
 byte[] resp = response.getEncoded();
 
 //now the response is ready to be send back
 
 


Constructor Summary
TimeStampResp()
           
TimeStampResp(ASN1Object component)
          This constructor tries to reconstruct a TimeStampResp object from the given ASN.1 structure.
TimeStampResp(byte[] timeStampResp)
          This constructor generates a TimeStampResp object from an encoded ASN.1 object.
TimeStampResp(PKIStatusInfo status)
          To construct a new TimeStampResp object with a PKIStatusInfo object.
 
Method Summary
 byte[] getEncoded()
          This method DER encodes the ASN.1 TimeStampResp object.
 PKIStatusInfo getPKIStatusInfo()
          Returns the PKIStatusInfo object.
 TimeStampToken getTimeStampToken()
          Returns the TimeStampToken object.
 void setPKIStatusInfo(PKIStatusInfo status)
          This method sets a new PKIStatusInfo object.
 void setTimeStampToken(TimeStampToken time_stamp_token)
          This method sets a new TimeStampToken object.
 ASN1Object toASN1Object()
          Returns the ASN.1 structure of the TimeStampResp object.
 java.lang.String toString()
          This method returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeStampResp

public TimeStampResp()

TimeStampResp

public TimeStampResp(PKIStatusInfo status)
              throws java.lang.NullPointerException
To construct a new TimeStampResp object with a PKIStatusInfo object.

Parameters:
status - The status of the response.
Throws:
java.lang.NullPointerException - Thrown if the given argument is null.

TimeStampResp

public TimeStampResp(ASN1Object component)
              throws CodingException
This constructor tries to reconstruct a TimeStampResp object from the given ASN.1 structure.

Parameters:
component - The ASN.1 structure.
Throws:
CodingException - Thrown if the given ASN1Object is not a TimeStampResp ASN.1 object.

TimeStampResp

public TimeStampResp(byte[] timeStampResp)
              throws CodingException
This constructor generates a TimeStampResp object from an encoded ASN.1 object.

Parameters:
timeStampResp - The encoded ASN.1 object.
Throws:
CodingException - Thrown if the given ASN1Object is not a TimeStampResp.
Method Detail

getEncoded

public byte[] getEncoded()
This method DER encodes the ASN.1 TimeStampResp object.

Returns:
DER encoded TimeStampResp object.

toASN1Object

public ASN1Object toASN1Object()
Returns the ASN.1 structure of the TimeStampResp object.

Returns:
The ASN1Object of the TimeStampResp object.

setPKIStatusInfo

public void setPKIStatusInfo(PKIStatusInfo status)
                      throws java.lang.NullPointerException
This method sets a new PKIStatusInfo object.

Parameters:
status - The PKIStatusInfo object.
Throws:
java.lang.NullPointerException - Thrown if the argument is null.

setTimeStampToken

public void setTimeStampToken(TimeStampToken time_stamp_token)
                       throws java.lang.NullPointerException
This method sets a new TimeStampToken object.

Parameters:
time_stamp_token - The TimeStampToken object.
Throws:
java.lang.NullPointerException - Thrown if the argument is null.

getPKIStatusInfo

public PKIStatusInfo getPKIStatusInfo()
Returns the PKIStatusInfo object.

Returns:
The PKIStatusInfo object.

getTimeStampToken

public TimeStampToken getTimeStampToken()
Returns the TimeStampToken object.

Returns:
The TimeStampToken object.

toString

public java.lang.String toString()
This method returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
A String representing the TimeStampResp object.

This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note).

IAIK TSP, © 2002 IAIK, © 2003 - 2014 Stiftung SIC