|
IAIK TSP version 2.32 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object iaik.tsp.TimeStampResp
public class TimeStampResp
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 |
---|
public TimeStampResp()
public TimeStampResp(PKIStatusInfo status) throws java.lang.NullPointerException
TimeStampResp
object with a
PKIStatusInfo
object.
status
- The status of the response.
java.lang.NullPointerException
- Thrown if the given argument is null
.public TimeStampResp(ASN1Object component) throws CodingException
TimeStampResp
object
from the given ASN.1 structure.
component
- The ASN.1 structure.
CodingException
- Thrown if the given ASN1Object
is not a
TimeStampResp
ASN.1 object.public TimeStampResp(byte[] timeStampResp) throws CodingException
TimeStampResp
object from an
encoded ASN.1 object.
timeStampResp
- The encoded ASN.1 object.
CodingException
- Thrown if the given ASN1Object
is not a
TimeStampResp
.Method Detail |
---|
public byte[] getEncoded()
TimeStampResp
object.
TimeStampResp
object.public ASN1Object toASN1Object()
TimeStampResp
object.
ASN1Object
of the TimeStampResp
object.public void setPKIStatusInfo(PKIStatusInfo status) throws java.lang.NullPointerException
PKIStatusInfo
object.
status
- The PKIStatusInfo
object.
java.lang.NullPointerException
- Thrown if the argument is null
.public void setTimeStampToken(TimeStampToken time_stamp_token) throws java.lang.NullPointerException
TimeStampToken
object.
time_stamp_token
- The TimeStampToken
object.
java.lang.NullPointerException
- Thrown if the argument is null
.public PKIStatusInfo getPKIStatusInfo()
PKIStatusInfo
object.
PKIStatusInfo
object.public TimeStampToken getTimeStampToken()
TimeStampToken
object.
TimeStampToken
object.public java.lang.String toString()
toString
in class java.lang.Object
TimeStampResp
object.
|
This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |