Package com.itextpdf.signatures
Class TSAClientBouncyCastle
- java.lang.Object
-
- com.itextpdf.signatures.TSAClientBouncyCastle
-
- All Implemented Interfaces:
ITSAClient
public class TSAClientBouncyCastle extends java.lang.Object implements ITSAClient
Time Stamp Authority Client interface implementation using Bouncy Castle org.bouncycastle.tsp package.Created by Aiken Sam, 2006-11-15, refactored by Martin Brunecky, 07/15/2007 for ease of subclassing.
-
-
Field Summary
Fields Modifier and Type Field Description private static IBouncyCastleFactory
BOUNCY_CASTLE_FACTORY
private int
customTokenSizeEstimate
static java.lang.String
DEFAULTHASHALGORITHM
The default value for the hash algorithmstatic int
DEFAULTTOKENSIZE
The default value for token size estimation.protected java.lang.String
digestAlgorithm
Hash algorithmprivate static org.slf4j.Logger
LOGGER
The Logger instance.protected int
tokenSizeEstimate
Estimate of the received time stamp tokenprotected ITSAInfoBouncyCastle
tsaInfo
An interface that allows you to inspect the timestamp info.protected java.lang.String
tsaPassword
TSA passwordprivate java.lang.String
tsaReqPolicy
TSA request policyprotected java.lang.String
tsaURL
URL of the Time Stamp Authorityprotected java.lang.String
tsaUsername
TSA Username
-
Constructor Summary
Constructors Constructor Description TSAClientBouncyCastle(java.lang.String url)
Creates an instance of a TSAClient that will use BouncyCastle.TSAClientBouncyCastle(java.lang.String url, java.lang.String username, java.lang.String password)
Creates an instance of a TSAClient that will use BouncyCastle.TSAClientBouncyCastle(java.lang.String url, java.lang.String username, java.lang.String password, int tokSzEstimate, java.lang.String digestAlgorithm)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.security.MessageDigest
getMessageDigest()
Gets the MessageDigest to digest the data imprintbyte[]
getTimeStampToken(byte[] imprint)
Get RFC 3161 timeStampToken.int
getTokenSizeEstimate()
Get the token size estimate.java.lang.String
getTSAReqPolicy()
Gets the TSA request policy that will be used when retrieving timestamp token.protected byte[]
getTSAResponse(byte[] requestBytes)
Get timestamp token - communications layervoid
setTSAInfo(ITSAInfoBouncyCastle tsaInfo)
void
setTSAReqPolicy(java.lang.String tsaReqPolicy)
Sets the TSA request policy that will be used when retrieving timestamp token.
-
-
-
Field Detail
-
BOUNCY_CASTLE_FACTORY
private static final IBouncyCastleFactory BOUNCY_CASTLE_FACTORY
-
DEFAULTHASHALGORITHM
public static final java.lang.String DEFAULTHASHALGORITHM
The default value for the hash algorithm- See Also:
- Constant Field Values
-
DEFAULTTOKENSIZE
public static final int DEFAULTTOKENSIZE
The default value for token size estimation.- See Also:
- Constant Field Values
-
LOGGER
private static final org.slf4j.Logger LOGGER
The Logger instance.
-
tsaURL
protected java.lang.String tsaURL
URL of the Time Stamp Authority
-
tsaUsername
protected java.lang.String tsaUsername
TSA Username
-
tsaPassword
protected java.lang.String tsaPassword
TSA password
-
tsaInfo
protected ITSAInfoBouncyCastle tsaInfo
An interface that allows you to inspect the timestamp info.
-
tokenSizeEstimate
protected int tokenSizeEstimate
Estimate of the received time stamp token
-
digestAlgorithm
protected java.lang.String digestAlgorithm
Hash algorithm
-
tsaReqPolicy
private java.lang.String tsaReqPolicy
TSA request policy
-
customTokenSizeEstimate
private int customTokenSizeEstimate
-
-
Constructor Detail
-
TSAClientBouncyCastle
public TSAClientBouncyCastle(java.lang.String url)
Creates an instance of a TSAClient that will use BouncyCastle.- Parameters:
url
- String - Time Stamp Authority URL (i.e. "http://tsatest1.digistamp.com/TSA")
-
TSAClientBouncyCastle
public TSAClientBouncyCastle(java.lang.String url, java.lang.String username, java.lang.String password)
Creates an instance of a TSAClient that will use BouncyCastle.- Parameters:
url
- String - Time Stamp Authority URL (i.e. "http://tsatest1.digistamp.com/TSA")username
- String - user(account) namepassword
- String - password
-
TSAClientBouncyCastle
public TSAClientBouncyCastle(java.lang.String url, java.lang.String username, java.lang.String password, int tokSzEstimate, java.lang.String digestAlgorithm)
Constructor. Note the token size estimate is updated by each call, as the token size is not likely to change (as long as we call the same TSA using the same imprint length).- Parameters:
url
- Time Stamp Authority URL (i.e. "http://tsatest1.digistamp.com/TSA")username
- user(account) name, optionalpassword
- password, optional if used in combination with username, the credentials will be used in basic authentication. Use only in combination with a https url to ensure encryptiontokSzEstimate
- estimated size of received time stamp token (DER encoded)digestAlgorithm
- is a hash algorithm
-
-
Method Detail
-
setTSAInfo
public void setTSAInfo(ITSAInfoBouncyCastle tsaInfo)
- Parameters:
tsaInfo
- the tsaInfo to set
-
getTokenSizeEstimate
public int getTokenSizeEstimate()
Get the token size estimate. Returned value reflects the result of the last succesfull call, padded- Specified by:
getTokenSizeEstimate
in interfaceITSAClient
- Returns:
- an estimate of the token size
-
getTSAReqPolicy
public java.lang.String getTSAReqPolicy()
Gets the TSA request policy that will be used when retrieving timestamp token.- Returns:
- policy id, or
null
if not set
-
setTSAReqPolicy
public void setTSAReqPolicy(java.lang.String tsaReqPolicy)
Sets the TSA request policy that will be used when retrieving timestamp token.- Parameters:
tsaReqPolicy
- policy id
-
getMessageDigest
public java.security.MessageDigest getMessageDigest() throws java.security.GeneralSecurityException
Gets the MessageDigest to digest the data imprint- Specified by:
getMessageDigest
in interfaceITSAClient
- Returns:
- the digest algorithm name
- Throws:
java.security.GeneralSecurityException
- if digestAlgorithm doesn't match any known hash algorithm
-
getTimeStampToken
public byte[] getTimeStampToken(byte[] imprint) throws java.io.IOException, AbstractTSPException
Get RFC 3161 timeStampToken. Method may return null indicating that timestamp should be skipped.- Specified by:
getTimeStampToken
in interfaceITSAClient
- Parameters:
imprint
- data imprint to be time-stamped- Returns:
- encoded, TSA signed data of the timeStampToken
- Throws:
java.io.IOException
- if I/O error occursAbstractTSPException
- if the TSA response is malformed
-
getTSAResponse
protected byte[] getTSAResponse(byte[] requestBytes) throws java.io.IOException
Get timestamp token - communications layer- Parameters:
requestBytes
- is a byte representation of TSA request- Returns:
- - byte[] - TSA response, raw bytes (RFC 3161 encoded)
- Throws:
java.io.IOException
- if I/O issue occurs
-
-