|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.x509.ocsp.utils.ResponseGenerator
A simple utility for generating OCSP responses (of type BasicOCSPResponse).
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 Summary | |
ResponseGenerator(PKCS12 pkcs12,
char[] password)
Creates a ResponseGenerator from the given PCSK#12 object. |
|
ResponseGenerator(PrivateKey responderKey,
X509Certificate[] responderCerts)
Creates a ResponseGenerator from responder private key and responder certs. |
Method Summary | |
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,
Date thisUpdate,
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(InputStream requestStream,
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. |
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. |
Enumeration |
getSingleResponses()
Returns all single responses produced by this response generator. |
void |
init(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(OutputStream out)
Sets the stream to which debug information shall be printed. |
String |
toString()
Returns a string representation of this resposne generator. |
void |
writeTo(OutputStream os)
Writes the contents of this response generator to the given output stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ResponseGenerator(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.Method Detail |
public PrivateKey getResponderKey()
public X509Certificate[] getResponderCertificates()
public void addResponseEntry(ReqCert reqCert, CertStatus certStatus, Date thisUpdate, 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, 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 aboveSignatureException
- if the crl cannot be verified with the given crl issuer certpublic void addResponseEntries(X509CRL crl, X509Certificate crlIssuer, int reqCertType, CrlID crlID) throws OCSPException, 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 aboveSignatureException
- if the crl cannot be verified with the given crl issuer certpublic 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):
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(InputStream requestStream, 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(InputStream is) throws 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 possibiltiy 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 authenticy 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 generatorIOException
- if an initialization, verification error,...
occurs or the contents read in has does not belong to
the owner of this generatorpublic void writeTo(OutputStream os) throws 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 possibiltiy 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 authenticy 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 generatorIOException
- if some I/O, signing, ... error occurspublic void printDebug(boolean debug)
debug
- whether to write debug messages to System.out or notpublic void setDebugStream(OutputStream out)
out
- the stream to which debug information shall be written;
maybe null
for disabling debug outputpublic String toString()
toString
in class Object
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |