public class ResponseGenerator
extends java.lang.Object
This class provides an utility for caching pre-calculated single responses
(either immediately set or
computed
from a
crl) and creating a OCSPResponse
according to the single reponses cached.
When creating a ResponseGenerator object the certificates and private signing
key of the responder have to be supplied (either as PrivateKey and
X509Certificate chain) or as PKCS12
object:
// the responder certs: X509Certificate[] responderCerts = ...; // the private key of the responder: PrivateKey responderKey = ...; ResponseGenerator generator = new ResponseGenerator(responderKey, responderCerts);respectively:
// the PKCS12Object containing key and ceritifcates of the responder: PKCS12 pkcs12 = ...; // the password for decrypting the PKCS12 object: char[] password = ...; ResponseGenerator generator = new ResponseGenerator(pkcs12, password);After optionally
initializing
the generator with
the contents previously written
to a file,
adding single response entries (by using one of the
addResponseEntry
methods or
creating
them from
a CRL) and/or adding trusted certificate issuers
method
createOCSPResponse
may be called for creating an
OCSPResponse
in response to an
OCSPRequest
received, e.g.:
// add a single response generator.addResponseEntry(singleResponse); // create and add a second response generator.addResponseEntry(reqCert, certStatus, thisUpdate, nextUpdate); // create and add response entries from a crl X509CRL crl = ...; // the crl issuer cert X509Certificate crlIssuer = ...; generator.addResponseEntries(crl, crlIssuer, ReqCert.certID); // add a trusted certificate issuer Name issuer = ...; generator.addCertificateIssuer(issuer); // sign and create an OCSPResponse for an OCSPRequest read from a stream InputStream is = ...; AlgorithmID signingAlg = ...; OCSPResponse ocspResponse = createOCSPResponse(is, null, sigingAlg, null);The OCSPResponse will be created according to the following proceeding: First the OCSP request is read and decoded from the given input stream. For each of the included single
requests
a
SingleResponse
is created thereby
setting the CertStatus
according to the
following rules (in this order):
ServiceLocator
extension
indicating that the owner of this generator is not an accepted responder for
the request in mind, the CertStatus of the corresponding single response is
set to "unknown".
ReqCert
of the request in mind, this single
response is the one to be sent in response to the request.
CertID
, issuerSerial
, or
pKCert
) allowing to find the issuer of its
target certificate, and the owner of this generator itself is equal to the
target certificate issuer, the CertStatus of the corresponding single
response is set to "good".
CertID
, issuerSerial
, or
pKCert
) allowing to find the issuer of its
target certificate, and the owner of this generator has a certificate (with
ExtendedKeyUsage ocspSigning set) issued by the target certificate issuer,
the CertStatus of the corresponding single response is set to "good".
CertID
, issuerSerial
, or
pKCert
) allowing to find that any of the
certificate issuers cached
is the issuer
of the target certificate and also the issuer of the responder certificate,
the certStaus of the corresponding single response is set to "good" if the
responder certificate is allowed to sign OCSP responses (has to ocspSigning
ExtendedKeyUsage
set.
The OCSPResponse
created will indicate
another response status than "successful" if any of the following situations
occur:
request
supplied by the given
input stream cannot be read because of an decoding/parsing error ==> response
status "malformedRequest"
OCSPResponse
,
OCSPRequest
,
BasicOCSPResponse
,
SingleResponse
,
Request
,
ReqCert
Constructor and Description |
---|
ResponseGenerator(PKCS12 pkcs12,
char[] password)
Creates a ResponseGenerator from the given PCSK#12 object.
|
ResponseGenerator(java.security.PrivateKey responderKey,
X509Certificate[] responderCerts)
Creates a ResponseGenerator from responder private key and responder certs.
|
Modifier and Type | Method and Description |
---|---|
void |
addCertificateIssuer(Name issuer)
Adds a certificate issuers to this response generator.
|
void |
addResponseEntries(X509CRL crl,
X509Certificate crlIssuer,
int reqCertType)
Creates and adds SingleResponse entries for the given CRL.
|
void |
addResponseEntries(X509CRL crl,
X509Certificate crlIssuer,
int reqCertType,
CrlID crlID)
Creates and adds SingleResponse entries for the given CRL.
|
void |
addResponseEntry(ReqCert reqCert,
CertStatus certStatus,
java.util.Date thisUpdate,
java.util.Date nextUpdate)
Creates a SingleResponse for the given reqCert, certStatus and thisUpdate
(and optional nextUpdate) date and adds it to the list of single responses.
|
void |
addResponseEntry(SingleResponse singleResponse)
Adds the given SingleResponse.
|
OCSPResponse |
createOCSPResponse(java.io.InputStream requestStream,
java.security.PublicKey requestorKey,
AlgorithmID signatureAlgorithm,
V3Extension[] extensions)
Creates an OCSPResponse for the OCSPRequest read from the given input
stream.
|
X509Certificate[] |
getResponderCertificates()
Gets the certificates of the responder.
|
java.security.PrivateKey |
getResponderKey()
Gets the signing key of the responder.
|
SingleResponse |
getSingleResponse(ReqCert reqCert)
Returns the single response identified by the given ReqCert, if included.
|
SingleResponse |
getSingleResponse(Request request)
Creates a single response for the given single request.
|
java.util.Enumeration |
getSingleResponses()
Returns all single responses produced by this response generator.
|
void |
init(java.io.InputStream is)
Inits the single response repository from the from the given input stream.
|
void |
printDebug(boolean debug)
Turns debug printing to System.out on/off.
|
void |
removeAllCertIssuers()
Removes all certificate issuers included.
|
void |
removeAllSingleResponses()
Removes all single responses included.
|
boolean |
removeCertificateIssuer(Name issuer)
Removes the given certificate issuer.
|
SingleResponse |
removeSingleResponse(ReqCert reqCert)
Removes the single response identified by the given ReqCert.
|
void |
setDebugStream(java.io.OutputStream out)
Sets the stream to which debug information shall be printed.
|
java.lang.String |
toString()
Returns a string representation of this response generator.
|
void |
writeTo(java.io.OutputStream os)
Writes the contents of this response generator to the given output stream.
|
public ResponseGenerator(java.security.PrivateKey responderKey, X509Certificate[] responderCerts)
The certificate of the response signer (i.e. the certificate corresponding to the responder key) has to be at index 0 of the supplied array. No certificate chain verification or rearranging is performed. It is the responsibility of the calling application to supply valid certificates.
responderKey
- the key used for signing the responseresponderCerts
- the certificates of the responderpublic ResponseGenerator(PKCS12 pkcs12, char[] password) throws PKCSException
pkcs12
- the PKCS12
object supplying
responder key and certs.password
- the password for decrypting the PKCS12 object.PKCSException
public java.security.PrivateKey getResponderKey()
public X509Certificate[] getResponderCertificates()
public void addResponseEntry(ReqCert reqCert, CertStatus certStatus, java.util.Date thisUpdate, java.util.Date nextUpdate)
Any included SingleResponse with the same ReqCert is cleared.
Attention! This method does not check if the owner of this generator
is authorized to send the single response created from the given
information (such a check only might be possible if only ReqCert types
(CertID, issuerSerial, pKCert) were used allowing to find the issuer of the
corresponding target certificate. It is the responsibiltity of the calling
application to ensure that the given single responses matches to the OCSP
signing abilities of the owner of this generator (i.e. the responder).
reqCert
- the reqCert identifying the target cert for which revocation
information maybe requestedcertStatus
- the certStatus for the target certificate in mindthisUpdate
- the time at which the certStatus is known as being correctnextUpdate
- the time at or before newer information will be available about
the status of the certificate (maybe null
)public void addResponseEntry(SingleResponse singleResponse)
Any included SingleResponse with the same ReqCert is cleared.
Attention! This method does not check if the owner of this generator
is authorized to send the given single response (such a check only might be
possible if only ReqCert types (CertID, issuerSerial, pKCert) were used
allowing to find the issuer of the corresponding target certificate. It is
the responsibiltity of the calling application to ensure that the given
single responses matches to the OCSP signing abilities of the owner of this
generator (i.e. the responder).
singleResponse
- the SingleResponse to be addedpublic void addResponseEntries(X509CRL crl, X509Certificate crlIssuer, int reqCertType) throws OCSPException, java.security.SignatureException
This method tries to create single response entries for the revoked certificate of the given crl. This method throws an OCSPException if one of the following situations occur:
crl
- the crl from which to create single responsescrlIssuer
- the certificate of the CRL issuer (required for OCSPv1 CertID
creation)reqCertType
- the ReqCert type the single responses should have (either certID
or issuerSerialOCSPException
- if single response entries cannot be created because one of
the reasons stated abovejava.security.SignatureException
- if the crl cannot be verified with the given crl issuer certpublic void addResponseEntries(X509CRL crl, X509Certificate crlIssuer, int reqCertType, CrlID crlID) throws OCSPException, java.security.SignatureException
This method tries to create single response entries for the revoked certificate of the given crl. This method throws an OCSPException if one of the following situations occur:
crl
- the crl from which to create single responsescrlIssuer
- the certificate of the CRL issuer (required for OCSPv1 CertID
creation)reqCertType
- the ReqCert type the single responses should have (either certID
or issuerSerialcrlID
- the crlID extension, if to be included, otherwise
null
OCSPException
- if single response entries cannot be created because one of
the reasons stated abovejava.security.SignatureException
- if the crl cannot be verified with the given crl issuer certpublic java.util.Enumeration getSingleResponses()
public SingleResponse getSingleResponse(ReqCert reqCert)
null
if no single response for the given ReqCert is
includedpublic SingleResponse removeSingleResponse(ReqCert reqCert)
reqCert
- the reqCert ID for the single response to be removednull
if the
SingleResponse cannot be removed because it was not includedpublic void removeAllSingleResponses()
public void addCertificateIssuer(Name issuer)
When asking
for a single response for a
particular request
, but no SingleResponse
has been set for this request, a new SingleResponse has to be created for
this request using the following proceeding for determining the certStatus
of the single response:
If the ReqCert
of the request in mind has a
type (certID, issuerSerial or pKCert} allowing to find the issuer of its
target certificate, and if this issuer is the response signer itself or is
some of the issuers previously set by method
addCertificateIssuer
and has signed the
responder's OCSP signing certificate, the certStatus is set to "good". In
any other case the cert status is set to "unknown".
issuer
- the issuer name to be setpublic boolean removeCertificateIssuer(Name issuer)
Certificate issuer names can be added by calling method
addCertificateIssuer
to be used for
determining the certStatus of a SingleResponse for a request for which no
SingleResponse has been explicitly set: If the
ReqCert
of the request in mind has a type
(certID, issuerSerial or pKCert} allowing to find the issuer of its target
certificate, and if this issuer is the response signer itself or is some of
the issuers previously set by method addCertificateIssuer
and has signed the responder's OCSP signing
certificate, the certStatus is set to "good". In any other case the cert
status is set to "unknown".
issuer
- the issuer name to be removedtrue
, if removed, false
if the issuer
name cannot be removed because it was not includedpublic void removeAllCertIssuers()
Certificate issuer names can be added by calling method
addCertificateIssuer
to be used for
determining the certStatus of a SingleResponse for a request for which no
SingleResponse has been explicitly set: If the
ReqCert
of the request in mind has a type
(certID, issuerSerial or pKCert} allowing to find the issuer of its target
certificate, and if this issuer is the response signer itself or is some of
the issuers previously set by method addCertificateIssuer
and has signed the responder's OCSP signing
certificate, the certStatus is set to "good". In any other case the cert
status is set to "unknown".
public SingleResponse getSingleResponse(Request request)
For the given single request
a
SingleResponse
is created thereby
setting the CertStatus
according to the
following rules (in this order):
ServiceLocator ServiceLocator
extension indicating that the owner of this
generator is not an accepted responder for the request in mind, the
CertStatus of the corresponding single response is set to "unknown".
ReqCert
of the request in mind, this single
response is the one sent in response to the request.
CertID
,
issuerSerial
, or
pKCert
) allowing to find the issuer of
its target certificate, and the owner of this generator itself is equal to
the target certificate issuer, the CertStatus of the corresponding single
response is set to "good".
CertID
,
issuerSerial
, or
pKCert
) allowing to find the issuer of
its target certificate, and the owner of this generator has a certificate
(with ExtendedKeyUsage ocspSigning set) issued by the target certificate
issuer, the CertStatus of the corresponding single response is set to
"good".
CertID
,
issuerSerial
, or
pKCert
) allowing to find that any of the
certificate issuers cached
is the
issuer of the target certificate and also the issuer of the responder
certificate, the certStaus of the corresponding single response is set to
"good" if the responder certificate is allowed to sign OCSP responses (has
to ocspSigning ExtendedKeyUsage
set.
request
- the request for which to create a single responsepublic OCSPResponse createOCSPResponse(java.io.InputStream requestStream, java.security.PublicKey requestorKey, AlgorithmID signatureAlgorithm, V3Extension[] extensions)
This method first reads and decodes the request from the given input
stream. For each of the included single requests
a SingleResponse
is created
thereby setting the CertStatus
according
to the following rules (in this order):
ServiceLocator
extension
indicating that the owner of this generator is not an accepted responder
for the request in mind, the CertStatus of the corresponding single
response is set to "unknown".
ReqCert
of the request in mind, this single
response is the one sent in response to the request.
CertID
,
issuerSerial
, or
pKCert
) allowing to find the issuer of
its target certificate, and the owner of this generator itself is equal to
the target certificate issuer, the CertStatus of the corresponding single
response is set to "good".
CertID
,
issuerSerial
, or
pKCert
) allowing to find that any of the
certificate issuers cached
is the
issuer of the target certificate and also the issuer of the responder
certificate, the certStaus of the corresponding single response is set to
"good" if the responder certificate is allowed to sign OCSP responses (has
to ocspSigning ExtendedKeyUsage
set.
The OCSPResponse
returned by this
method will indicate another response status than "successful" if any of
the following situations occur:
request
supplied by the
given input stream cannot be read because of an decoding/parsing error ==>
response status "malformedRequest"
requestStream
- the input stream from where to read the DER encoded OCSP requestrequestorKey
- the public key of the requestor used to verify the request (may be
null
if the request is not signed or is signed and
has the requestor certificates includedsignatureAlgorithm
- the signature algorithm which will be used for signing the
OCSPResponseextensions
- any response extensions to be added to the OCSPResponse created by
this methodpublic void init(java.io.InputStream is) throws java.io.IOException
Attention! The data read in by this method does not represent the
OCSPResponse to be sent in response to a request. The final OCSPResponse is
created when calling method
createOCSPResponse
. This method only provides the possibilty to init the
generator from a file previously created by calling method
writeTo
.
This method reads in the (previously written) contents of the generator
thereby using a proprietary ASN.1 structure:
GeneratorContents ::= SEQUENCE { tbs Contents, signature BIT STRING } Contents ::= SEQUENCE { responderID ResponderID, certIssuers SEQUENCE OF Name OPTIONAL responses [0] SEQUENCE OF SingleResponse }For providing the integrity and authenticity of the generator the contents has been signed with the responder's private key and now is verified with its public key.
is
- the input stream supplying the contents of this generatorjava.io.IOException
- if an initialization, verification error,... occurs or the
contents read in has does not belong to the owner of this
generatorpublic void writeTo(java.io.OutputStream os) throws java.io.IOException
Attention! The output created and stored by this method is not the
the OCSPResponse to be sent in response to a request. The final
OCSPResponse is created when calling method
createOCSPResponse
. This method only provides the possibilty to store the
repository to a file from where it can be read back when calling method
init
.
This method uses a proprietary ASN.1 structure for writing the contents to
the given stream:
GeneratorContents ::= SEQUENCE { tbs Contents, signature BIT STRING } Contents ::= SEQUENCE { responderID ResponderID, certIssuers SEQUENCE OF Name OPTIONAL responses [0] SEQUENCE OF SingleResponse }For providing the integrity and authenticity of the generator the contents is signed with the responder's private key before writing it to the stream.
os
- the output stream to which to write the contents of this generatorjava.io.IOException
- if some I/O, signing, ... error occurspublic void printDebug(boolean debug)
debug
- whether to write debug messages to System.out or notpublic void setDebugStream(java.io.OutputStream out)
out
- the stream to which debug information shall be written; maybe
null
for disabling debug outputpublic java.lang.String toString()
toString
in class java.lang.Object