public class OCSPResponse
extends java.lang.Object
OCSPResponse
.
The X.509 Online Certificate Status Protocol ( RFC 2560), RFC 6960) specifies the OCSPResponse type for giving the format of a response message that may be send to a OCSP requestor in response to a certificate status information request:
OCSPResponse ::= SEQUENCE { responseStatus OCSPResponseStatus, responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }An OCSP response at a minimum consists of a responseStatus field indicating the processing status of the prior request. If the value of responseStatus is one of the error conditions, responseBytes are not set. Note that responseStatus type "noMoreData" has been introduced by OCSPv2 (see draft-ietf-pkix-ocspv2-01.txt).
OCSPResponseStatus ::= ENUMERATED { successful (0), --Response has valid confirmations malformedRequest (1), --Illegal confirmation request internalError (2), --Internal error in issuer tryLater (3), --Try again later --(4) is not used sigRequired (5), --Must sign the request unauthorized (6) --Request unauthorized }OCSP responses can be of various types. An OCSP response consists of a response type and the bytes of the actual response. There is one
basic type
of OCSP response
that MUST be supported by all OCSP servers and clients. This OCSP
implementation supports the BasicOCSPResponse
, but also provides an easy machanism allowing
application to implement any other response type
and register the corresponding class by its object
identifier (see class ResponseBytes
for more information.
When creating
an OCSPResponse you have to
set the response status information, e.g.:
OCSPResponse ocspResponse = new OCSPResponse(OCSPResponse.malformedRequest);In the case of an successful OCSPResponse you immediately may supply the response component to the
constructor
.
The response status is set to "successful" and ResponseBytes are created
automatically, e.g.:
BasicOCSPResponse basicOCSPResponse = ...; ... OCSPResponse ocspResponse = new OCSPResponse(basicOCSPResponse);For DER encoding the OCSP response you may call method
writeTo
or getEncoded
:
OutputStream os = ...; ocspResponse.writeTo(os);A requestor receiving an ocsp response,
checks
the
response status and -- if successful -- gets
the response included:
// the stream supplying the encoded OCSP response: InputStream is = ...; OCSPResponse ocspResponse = new OCSPResponse(is); // get the response status: int responseStatus = ocspResponse.getResponseStatus(); if (responseStatus != OCSPResponse.successful) { System.out.println("Not successful; got response status: " + ocspResponse.getResponseStatusName()); ... } else { // get the included response Response response = ocspResponse.getResponse(); ...
OCSPRequest
,
Request
,
BasicOCSPResponse
,
ResponseBytes
,
SingleResponse
,
ReqCert
,
CertStatus
Modifier and Type | Field and Description |
---|---|
static int |
internalError
Response status "internalError" (2) indicating an internal
responder error.
|
static int |
malformedRequest
Response status "malformedRequest" (1) indicating that the
request received is not OCSP-syntax-conform.
|
static int |
noMoreData
Response status "noMoreData" (7) indicating that the server has
previously returned the last positive response to a related sequence of
requests
|
static int |
sigRequired
Response status "sigRequired" (5) requiring a
request to be signed.
|
static int |
successful
Response status "successful" (0) indicating that the
response has valid confirmation.
|
static int |
tryLater
Response status "tryLater" (3) indicating that the
request should be resend at later because the server
temporarily cannot respond.
|
static int |
unauthorized
Response status "unauthorized" (6) indicating that the client is
not authorized to make this query to this server or the server is not
capable of responding authoritatively (for instance, does not have
access to authoritative records for a requested certificate).
|
Constructor and Description |
---|
OCSPResponse(ASN1Object obj)
Creates an OCSPResponse from its ASN.1 representation.
|
OCSPResponse(byte[] array)
Creates an OCSPResponse from its DER encoding.
|
OCSPResponse(java.io.InputStream is)
Creates an OCSPResponse from its DER encoding.
|
OCSPResponse(int responseStatus)
Creates an OCSPResponse for the given response status.
|
OCSPResponse(Response response)
Creates an OCSPResponse from the given response.
|
OCSPResponse(ResponseBytes responseBytes)
Creates an OCSPResponse for the given response bytes.
|
Modifier and Type | Method and Description |
---|---|
void |
decode(ASN1Object obj)
Decodes an OCSPResponse from its ASN.1 representation.
|
void |
decode(java.io.InputStream is)
Decodes an OCSPResponse from its DER encoding.
|
byte[] |
getEncoded()
DER encodes this OCSP response.
|
byte[] |
getFingerprint(java.lang.String digestAlgorithm)
Returns the fingerprint of this OCSPResponse calculated with the given
hash algorithm.
|
Response |
getResponse()
Returns the response component of the ResponseBytes, if included.
|
ResponseBytes |
getResponseBytes()
Returns the response bytes, if included.
|
int |
getResponseStatus()
Returns the response status.
|
java.lang.String |
getResponseStatusName()
Returns the response status as String.
|
ObjectID |
getResponseType()
Returns the response type oid of the ResponseBytes, if included.
|
void |
setResponse(Response response)
Sets the response of this OCSPResponse.
|
void |
setResponseBytes(ResponseBytes responseBytes)
Sets the response bytes of this OCSPResponse.
|
ASN1Object |
toASN1Object()
Returns this OCSP response as ASN1Object.
|
java.lang.String |
toString()
Returns a String representation of this OCSP response.
|
void |
writeTo(java.io.OutputStream os)
Writes this OCSPResponse DER encoded to the given output stream.
|
public static final int successful
public static final int malformedRequest
public static final int internalError
public static final int tryLater
public static final int sigRequired
public static final int unauthorized
public static final int noMoreData
public OCSPResponse(int responseStatus) throws java.lang.IllegalArgumentException
setResponseBytes
for setting
the response bytes.responseStatus
- the response statusjava.lang.IllegalArgumentException
- if the responseStatus is invalidpublic OCSPResponse(ResponseBytes responseBytes)
responseBytes
- the response bytespublic OCSPResponse(Response response)
response
- the responsepublic OCSPResponse(ASN1Object obj) throws CodingException, UnknownResponseException
If the response is a successful one, response bytes are present.
When parsing the response bytes, an unknown response type may
be included. In this case this constructor throws an UnknownResponseException
to be queried for information about the unknown response.
obj
- the OCSPResponse as ASN1ObjectCodingException
- if the ASN1Object cannot be parsed or the response status
is invalidUnknownResponseException
- if the response is a successful
response but the ResponseBytes included contain an response
of unknown (= unsupported) typepublic OCSPResponse(java.io.InputStream is) throws java.io.IOException, UnknownResponseException
If the response is a successful one, response bytes are present.
When parsing the response bytes, an unknown response type may
be included. In this case this constructor throws an UnknownResponseException
to be queried for information about the unknown response.
is
- the input stream supplying the DER encoded OCSPResponsejava.io.IOException
- if the ASN1Object cannot be parsed or the response status
is invalidUnknownResponseException
- if the response is a successful
response but the ResponseBytes included contain an response
of unknown (= unsupported) typepublic OCSPResponse(byte[] array) throws CodingException, UnknownResponseException
If the response is a successful one, response bytes are present.
When parsing the response bytes, an unknown response type may
be included. In this case this constructor throws an UnknownResponseException
to be queried for information about the unknown response.
array
- the DER encoded OCSPResponse as byte arrayCodingException
- if the ASN1Object cannot be parsed or the response status
is invalidUnknownResponseException
- if the response is a successful
response but the ResponseBytes included contain an response
of unknown (= unsupported) typepublic void setResponseBytes(ResponseBytes responseBytes)
responseBytes
- the response bytespublic void setResponse(Response response)
response
- the responsepublic ResponseBytes getResponseBytes()
public Response getResponse()
getResponseBytes().getResponse()
.
This method returns null
, if no response bytes are included.public ObjectID getResponseType()
getResponseBytes().getResponseType()
.
This method returns null
, if no response bytes are included.public int getResponseStatus()
public java.lang.String getResponseStatusName()
public void decode(ASN1Object obj) throws CodingException, UnknownResponseException
If the response is a successful one, response bytes are present.
When parsing the response bytes, an unknown response type may
be included. In this case this method throws an UnknownResponseException
to be queried for information about the unknown response.
obj
- the OCSPResponse as ASN1ObjectCodingException
- if the ASN1Object cannot be parsed or the response status
is invalidUnknownResponseException
- if ResponseBytes are included
containing an response of unknown (= unsupported) typepublic void decode(java.io.InputStream is) throws java.io.IOException, UnknownResponseException
If the response is a successful one, response bytes are present.
When parsing the response bytes, an unknown response type may
be included. In this case this method throws an UnknownResponseException
to be queried for information about the unknown response.
is
- the input stream supplying the DER encoded OCSPResponsejava.io.IOException
- if the ASN1Object cannot be parsed or the response status
is invalidUnknownResponseException
- if ResponseBytes are included
containing an response of unknown (= unsupported) typepublic ASN1Object toASN1Object()
public byte[] getEncoded()
public void writeTo(java.io.OutputStream os) throws java.io.IOException
os
- the output stream to which to write the responsejava.io.IOException
- if an error occurs while writing to the streampublic byte[] getFingerprint(java.lang.String digestAlgorithm) throws java.security.NoSuchAlgorithmException
digestAlgorithm
- the digest algorithm to be usedjava.security.NoSuchAlgorithmException
- if the requested algorithm is not supportedpublic java.lang.String toString()
toString
in class java.lang.Object