public class OCSPRequest
extends java.lang.Object
OCSPRequest
.
The X.509 Online Certificate Status Protocol ( RFC 2560), RFC 6960) specifies the OCSPRequest type for giving the format of a request message that may be send to a OCSP server for getting status information of one or more certificates:
OCSPRequest ::= SEQUENCE { tbsRequest TBSRequest, optionalSignature [0] EXPLICIT Signature OPTIONAL } TBSRequest ::= SEQUENCE { version [0] EXPLICIT Version DEFAULT v1, requestorName [1] EXPLICIT GeneralName OPTIONAL, requestList SEQUENCE OF Request, requestExtensions [2] EXPLICIT Extensions OPTIONAL } Signature ::= SEQUENCE { signatureAlgorithm AlgorithmIdentifier, signature BIT STRING, certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL}An OCSPRequest may include any number of single
Requests
, each of them identifying one
particular certificate for which revocation information shall be obtained.
Single Requests may be set by calling method
setRequestList
, e.g.:
Request request1 = ...; Request request2 = ...; OCSPRequest ocspRequest = new OCSPRequest(); Request[] requestList = { request1, request2 }; ocspRequest.setRequestList(requestList);An OCSP request may be
signed
by the
requestor or may be unsigned. If signed, the
requestorName
shall be present and the
certificates
of the signer may be
included to help the OCSP responder to verify
the
signature, e.g.:
// the certificates of the requestor X509Certificate[] requestorCerts = ...; // the private key of the requestor, used for signing: PrivateKey requestorKey = ...; // the name of the requestor: GeneralName requestorName = new GeneralName(GeneralName.directoryName, requestorCerts[0].getSubjectDN())); ocspRequest.setRequestorName(requestorName); // set the certificates: ocspRequest.setCertificates(requestorCerts); // sign the request: ocspRequest.sign(AlgorithmID.sha1WithRSAEncryption, requestorKey);Please note that, when signing an OCSP request, any information that shall be included in the request has to be set before calling the
sign
method. In this way, also any extension has to be
added
before calling the sign
method. Finally you may call method writeTo
or
getEncoded
for DER encoding the OCSP request:
OutputStream os = ...; ocspRequest.writeTo(os);
Request
,
OCSPResponse
,
ReqCert
Constructor and Description |
---|
OCSPRequest()
Default constructor for creating a new empty OCSPRequest.
|
OCSPRequest(byte[] array)
Creates an OCSPRequest from a PEM or DER byte array.
|
OCSPRequest(java.io.InputStream is)
Creates an OCSPRequest from an input stream.
|
Modifier and Type | Method and Description |
---|---|
void |
addExtension(V3Extension e)
Adds the given extension.
|
boolean |
containsCertificates()
Checks if certificates are included.
|
boolean |
containsSignature()
Checks if this OCSPRequest has been signed.
|
int |
countExtensions()
Returns the number of extensions included in this ocsp request.
|
int |
countRequests()
Returns the number of requests included.
|
void |
decode(ASN1Object obj)
Decodes a OCSPRequest from an ASN1Object.
|
void |
decode(byte[] enc)
Decodes a OCSPRequest from a byte array.
|
void |
decode(java.io.InputStream is)
Decodes an OCSPRequest from an InputStream.
|
ObjectID[] |
getAccepatableResponseTypes()
A convenience method for getting the response type list of the
AcceptableResponses extension, if included in this request.
|
X509Certificate[] |
getCertifcates()
Returns the signer certificates that may be included in this request.
|
byte[] |
getEncoded()
Returns this OCSPRequest as DER encoded ASN.1 data structure
|
V3Extension |
getExtension(ObjectID oid)
Returns a specific extension, identified by its object identifier.
|
byte[] |
getNonce()
A convenience method for getting the value of the Nonce extension, if
included in this request.
|
Request[] |
getRequestList()
Returns all single requests included in this OCSPRequest.
|
GeneralName |
getRequestorName()
Returns the requestorName, if included.
|
byte[] |
getSignature()
Returns the signature of this OCSPRequest, if included.
|
AlgorithmID |
getSignatureAlgorithm()
Returns the signature algorithm of this OCSPRequest.
|
byte[] |
getTBSRequest()
Returns the DER encoded
TBSRequest ASN.1 data structure
specifying request data to be signed. |
int |
getVersion()
Returns the version number of this OCSPRequest as
int . |
boolean |
hasExtensions()
Checks, if there are any extensions included in this ocsp request.
|
boolean |
hasUnsupportedCriticalExtension()
Returns true if there are unsupported critical extensions.
|
java.util.Enumeration |
listExtensions()
Returns an enumeration of all extensions included in this ocsp request.
|
void |
removeAllExtensions()
Removes all extensions from this ocsp request.
|
boolean |
removeExtension(ObjectID oid)
Removes the extension specified by its object identifier.
|
void |
setAcceptableResponseTypes(ObjectID[] acceptableResponseTypes)
A convenience method for setting the response Types of the
AcceptableResponses extension.
|
void |
setCertificates(X509Certificate[] signerCerts)
Sets the certificates to be included into this OCSPRequest.
|
void |
setNonce(byte[] nonce)
A convenience method for setting the value of the Nonce extension.
|
void |
setRequestList(Request[] requestList)
Sets the request list of this OCSPRequest.
|
void |
setRequestorName(GeneralName requestorName)
Sets the requestorName.
|
void |
setSignature(AlgorithmID signatureAlg,
byte[] signature)
Sets the signature value of this OCSP request.
|
void |
sign(AlgorithmID signatureAlg,
java.security.PrivateKey privateKey)
Signs the OCSPRequest with the private key of the requestor.
|
void |
sign(AlgorithmID signatureAlg,
java.security.PrivateKey privateKey,
java.security.spec.AlgorithmParameterSpec signatureParams,
java.security.Provider provider)
Signs the OCSPRequest with the private key of the requestor.
|
void |
sign(AlgorithmID signatureAlg,
java.security.PrivateKey privateKey,
java.security.spec.AlgorithmParameterSpec signatureParams,
java.lang.String providerName)
Signs the OCSPRequest with the private key of the requestor.
|
void |
sign(AlgorithmID signatureAlg,
java.security.PrivateKey privateKey,
java.security.Provider provider)
Signs the OCSPRequest with the private key of the requestor.
|
void |
sign(AlgorithmID signatureAlg,
java.security.PrivateKey privateKey,
java.lang.String providerName)
Signs the OCSPRequest with the private key of the requestor.
|
ASN1Object |
toASN1Object()
Returns the OCSPRequest as an ASN1Object.
|
java.lang.String |
toString()
Returns a string that represents the contents of this OCSPRequest.
|
java.lang.String |
toString(boolean detailed)
Returns a string that represents the contents of this OCSPRequest.
|
X509Certificate |
verify()
Verifies this request using the included signer certificates.
|
void |
verify(java.security.PublicKey key)
Uses the given public key to verify this OCSPRequest.
|
void |
verify(java.security.PublicKey key,
java.security.Provider provider)
Uses the given public key to verify this OCSPRequest.
|
void |
verify(java.security.PublicKey key,
java.lang.String providerName)
Uses the given public key to verify this OCSPRequest.
|
void |
writeTo(java.io.OutputStream os)
Writes this OCSPRequest DER encoded to the given output stream.
|
public OCSPRequest()
Any value may be set using the corrseponding set<Value>
method. The version number per default is set to 0
indicating
a v1
response.
public OCSPRequest(java.io.InputStream is) throws java.io.IOException
The supplied OCSPRequest can be in PEM or DER format. This constructor
reads a OCSPRequest previously written with method
writeTo(OutputStream)
.
For instance:
InputStream is = ...; OCSPRequest request = new OCSPRequest(is); is.close();
is
- InputStream from which to create the OCSPRequestjava.io.IOException
- if the request could not be readpublic OCSPRequest(byte[] array) throws CodingException
This constructor may be used for parsing an already existing
OCSPRequest
ASN.1 object, supplied as DER encoded byte array,
which may have been created by calling method getEncoded
.
array
- the byte array containing the DER encoded requestCodingException
- if the request cannot be decodedpublic void decode(ASN1Object obj) throws CodingException
The given ASN1Object represents an already existing OCSPRequest which may
have been created by calling the toASN1Object
method.
obj
- the ASN1Object which representing the requestCodingException
- if there is a problem when parsing the requestpublic void decode(byte[] enc) throws CodingException
enc
- is the byte array from where the request should be readCodingException
- if an decoding/parsing error occurspublic void decode(java.io.InputStream is) throws java.io.IOException
is
- the InputStream from where the request should be readjava.io.IOException
- if an the resquest cannot be decodedpublic void sign(AlgorithmID signatureAlg, java.security.PrivateKey privateKey) throws OCSPException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException
signatureAlg
- the AlgorithmID of the signature algorithmprivateKey
- the private key of the requestorOCSPException
- if the request could not be signedjava.security.InvalidKeyException
- if the format of the key is wrongjava.security.NoSuchAlgorithmException
- if there is no implementation for the specified algorithmpublic void sign(AlgorithmID signatureAlg, java.security.PrivateKey privateKey, java.lang.String providerName) throws OCSPException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException
signatureAlg
- the AlgorithmID of the signature algorithmprivateKey
- the private key of the requestorproviderName
- the name of the provider supplying the Signature engine to be used;
if null
the first available provider will be used
the supports the signature algorithmOCSPException
- if the request could not be signedjava.security.InvalidKeyException
- if the format of the key is wrongjava.security.NoSuchAlgorithmException
- if there is no implementation for the specified algorithmpublic void sign(AlgorithmID signatureAlg, java.security.PrivateKey privateKey, java.security.spec.AlgorithmParameterSpec signatureParams, java.lang.String providerName) throws OCSPException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
signatureAlg
- the AlgorithmID of the signature algorithmprivateKey
- the private key of the requestorsignatureParams
- any signature parameters to -- if not null
-- be
used for initializing the Signature engine; if applicable the parameters
are also set for the signatureAlg
AlgorithmID (if it
does not contain any parameters yet)providerName
- the name of the provider supplying the Signature engine to be used;
if null
the first available provider will be used
the supports the signature algorithmOCSPException
- if the request could not be signedjava.security.InvalidKeyException
- if the format of the key is wrongjava.security.NoSuchAlgorithmException
- if there is no implementation for the specified algorithmjava.security.InvalidAlgorithmParameterException
- if an error occurs when trying to set the signature parameters *public void sign(AlgorithmID signatureAlg, java.security.PrivateKey privateKey, java.security.Provider provider) throws OCSPException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException
Signature
engine from the given provider
for signing the request.
Signature.getInstance(algorithm,provider)
is not available method Signature.getInstance(algorithm,provider.getName())
is tried.signatureAlg
- the AlgorithmID of the signature algorithmprivateKey
- the private key of the requestorprovider
- the provider supplying the Signature engine to be used;
if null
the first available provider will be used
the supports the signature algorithmOCSPException
- if the request could not be signedjava.security.InvalidKeyException
- if the format of the key is wrongjava.security.NoSuchAlgorithmException
- if there is no implementation for the specified algorithmpublic void sign(AlgorithmID signatureAlg, java.security.PrivateKey privateKey, java.security.spec.AlgorithmParameterSpec signatureParams, java.security.Provider provider) throws OCSPException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
Signature
engine from the given provider
for signing the request.
Signature.getInstance(algorithm,provider)
is not available method Signature.getInstance(algorithm,provider.getName())
is tried.signatureAlg
- the AlgorithmID of the signature algorithmprivateKey
- the private key of the requestorsignatureParams
- any signature parameters to -- if not null
-- be
used for initializing the Signature engine; if applicable the parameters
are also set for the signatureAlg
AlgorithmID (if it
does not contain any parameters yet)provider
- the provider supplying the Signature engine to be used;
if null
the first available provider will be used
the supports the signature algorithmOCSPException
- if the request could not be signedjava.security.InvalidKeyException
- if the format of the key is wrongjava.security.NoSuchAlgorithmException
- if there is no implementation for the specified algorithmjava.security.InvalidAlgorithmParameterException
- if an error occurs when trying to set the signature parameterspublic void setSignature(AlgorithmID signatureAlg, byte[] signature) throws OCSPException
This method provides an alternative way to method
sign
for "signing" this basic OCSP
requst with a precalculated signature value. If using this method please
make sure that the signature value provided actually has beeb calculated
over the TBS request.
signatureAlg
- the AlgorithmID of the signature algorithmsignature
- the (precalculated) signature valueOCSPException
- if the request could not be signedpublic byte[] getEncoded() throws CodingException
CodingException
- if the response cannot be encoded correctlypublic int getVersion()
int
. Default
version: v1.
ASN.1 definition:
Version ::= INTEGER { v1(0), v2(1) }
int
, 1 for v1, 2 for
v2.public GeneralName getRequestorName()
null
if not includedpublic Request[] getRequestList()
public int countRequests()
public byte[] getTBSRequest() throws CodingException
TBSRequest
ASN.1 data structure
specifying request data to be signed.
TBSRequest ::= SEQUENCE { version [0] EXPLICIT Version DEFAULT v1, requestorName [1] EXPLICIT GeneralName OPTIONAL, requestList SEQUENCE OF Request, requestExtensions [2] EXPLICIT Extensions OPTIONAL }
TBSRequest
as DER encoded ASN.1 structureCodingException
- if an encoding error occurspublic byte[] getSignature()
null
if request
has not be signedpublic boolean containsSignature()
true
if this OCSPRequest has been signed,
false
if notpublic AlgorithmID getSignatureAlgorithm()
AlgorithmID
public void verify(java.security.PublicKey key) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.SignatureException
key
- the public key (of the issuer) to verify the responsejava.security.NoSuchAlgorithmException
- if there is no implementation for the algorithm that has been
used to sign this responsejava.security.InvalidKeyException
- if the format of the public key is wrongjava.security.SignatureException
- if the signature does not verifypublic void verify(java.security.PublicKey key, java.lang.String providerName) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.SignatureException
key
- the public key (of the issuer) to verify the responseproviderName
- the name of the crypto provider supplying the Signature engine to be used;
if null
the first available provider will be used
the supports the signature algorithmjava.security.NoSuchAlgorithmException
- if there is no implementation for the algorithm that has been
used to sign this responsejava.security.InvalidKeyException
- if the format of the public key is wrongjava.security.SignatureException
- if the signature does not verifypublic void verify(java.security.PublicKey key, java.security.Provider provider) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.SignatureException
This method uses a Signature
engine from the given provider
for verifying the request.
If Provider object based JCA/JCE Signature engine instantiation
is not available the Java VM in use (<1.4), this method tries to get an implementation
based on the provider name (if the Provider is installed within the Security Provider
framework). I.e. if method Signature.getInstance(algorithm,provider)
is not available method Signature.getInstance(algorithm,provider.getName())
is tried.
key
- the public key (of the issuer) to verify the responseprovider
- the crypto provider supplying the Signature engine to be used;
if null
the first available provider will be used
the supports the signature algorithmjava.security.NoSuchAlgorithmException
- if there is no implementation for the algorithm that has been
used to sign this responsejava.security.InvalidKeyException
- if the format of the public key is wrongjava.security.SignatureException
- if the signature does not verifypublic X509Certificate verify() throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, java.security.SignatureException, OCSPException
This method only can be used for verifying this request if signer
certificates are included. If so, this method assumes that all certificates
included belong to same chain. It tries to sort the chain to get the signer
certificate public key for verifying the request. If no certificates are
included or the chain cannot be sorted, an OCSPException is thrown. In this
case you may use method verify
for verifying the
request with the right public key supplied by other means.
java.security.NoSuchAlgorithmException
- if there is no implementation for the algorithm that has been
used to sign this responsejava.security.InvalidKeyException
- if the format of the public key is wrongjava.security.SignatureException
- if the signature does not verifyOCSPException
- if no certs are included or the signer cert cannot be found in
the certificate list includedpublic boolean containsCertificates()
true
if certificates are included, false
otherwisepublic ASN1Object toASN1Object() throws CodingException
CodingException
public void writeTo(java.io.OutputStream os) throws java.io.IOException
os
- the output stream where the response shall be written tojava.io.IOException
- if an I/O error occurspublic void setRequestorName(GeneralName requestorName)
requestorName
- the name of the requestorpublic void setNonce(byte[] nonce) throws X509ExtensionException
This method provides an convenient alternative to method
addExtension
for including the
Nonce
extension in this
OCSPRequest. From the given nonce value a Nonce extension object is created
an added to the list of request extensions as not critical extension.
The Nonce extension can be used for cryptographically binding a request and a response to prevent replay attacks.
nonce
- the nonce valueX509ExtensionException
- if the Nonce extension cannot be createdpublic byte[] getNonce() throws X509ExtensionInitException
This method provides an convenient alternative to method
getExtension
for getting the value of the
Nonce
extension, if included in
this OCSPRequest.
The Nonce extension can be used for cryptographically binding a request and a response to prevent replay attacks.
null
X509ExtensionInitException
- if the Nonce extension cannot be initialized from its encodingpublic void setAcceptableResponseTypes(ObjectID[] acceptableResponseTypes) throws X509ExtensionException
This method provides an convenient alternative to method
addExtension
for including the
AcceptableResponses
extension in this OCSPRequest. From the given response type list a
AcceptableResponses extension object is created an added to the list of
request extensions.
The AcceptableResponses extension can be used by an OCSP client to specify the kinds of response types it understands. The OIDs included in AcceptableResponses are the OIDs of the various response types this client can accept (e.g., id-pkix-ocsp-basic), e.g.:
ObjectID[] acceptedResponseTypes = { BasicOCSPResponse.responseType }; ocspRequest.setAcceptableResponseTypes(acceptedResponseTypes);
acceptableResponseTypes
- the list of acceptable response typesX509ExtensionException
- if the AcceptableResponses extension cannot be createdpublic ObjectID[] getAccepatableResponseTypes() throws X509ExtensionInitException
This method provides an convenient alternative to method
getExtension
for getting the value of the
AcceptableResponses
extension, if included in this OCSPRequest.
The AcceptableResponses extension can be used by an OCSP client to specify the kinds of response types it understands. The OIDs included in AcceptableResponses are the OIDs of the various response types this client can accept (e.g., id-pkix-ocsp-basic).
null
X509ExtensionInitException
- if the AcceptableResponses extension cannot be initialized
from its encodingpublic void setRequestList(Request[] requestList)
requestList
- the request list to be setpublic void setCertificates(X509Certificate[] signerCerts)
signerCerts
- the certificates of the signer to be includedpublic X509Certificate[] getCertifcates()
null
otherwisepublic void addExtension(V3Extension e) throws X509ExtensionException
The extension to be added shall be an implemented
V3Extension
. If an extension with the same
object ID already exists, it is replaced.
For reading back some extension use the getExtension(ObjectID)
method.
e
- the extension to be addedX509ExtensionException
- if the extension cannot be addedpublic boolean removeExtension(ObjectID oid)
oid
- the object ID of the extension to removetrue
if the extension has been successfully removed,
false
otherwisepublic void removeAllExtensions()
public java.util.Enumeration listExtensions()
The returned enumeration may contain unknown extensions (instances
of UnknownExtension
if there are any
extensions included in request, for which there exists no registered
implementation, and it may contain error extensions (instances of
ErrorExtension
) indicating
extensions which cannot be parsed properly because of some kind of error.
null
if there are
no extensions present at allpublic boolean hasExtensions()
true
if there are extensions, false
if
notpublic boolean hasUnsupportedCriticalExtension()
public int countExtensions()
public V3Extension getExtension(ObjectID oid) throws X509ExtensionInitException
If the extension cannot be initialized for some reason, an
X509ExtensionInitException is thrown. If the requested extension is an
unknown extension, which is not supported by a registered
implementation, this method creates and returns an
UnknownExtension
which may be queried
for obtaining as much information as possible about the unknown extension.
oid
- the object ID of the extensionnull
if the requested
extension is not presentX509ExtensionInitException
- if the extension can not be initializedpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean detailed)
detailed
- whether or not to give detailed information about the included
single responses and extensions