[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.6 The ocsptool application
This is a program that can parse and print information about OCSP requests/responses, generate requests and verify responses.
Ocsptool help Usage : ocsptool [options] -e, --verify-response Verify response. -i, --request-info Print information on a OCSP request. -j, --response-info Print information on a OCSP response. -q, --generate-request Generate a OCSP request. --no-nonce don't add nonce to OCSP request. --load-issuer FILE read issuer certificate from FILE. --load-cert FILE read certificate to check from FILE. --load-trust FILE read trust anchors from FILE. --inder Use DER format for input certificates. -Q, --load-request FILE read DER encoded OCSP request from FILE. -S, --load-response FILE read DER encoded OCSP response from FILE. --outfile FILE Output file. --infile FILE Input file. -V, --verbose More verbose output. -d, --debug integer Enable debugging -v, --version prints the program's version number -h, --help shows this help text
Print information about an OCSP request
To parse an OCSP request and print information about the content, the
-i
or --request-info
parameter may be used as follows.
The -Q
parameter specify the name of the file containing the
OCSP request, and it should contain the OCSP request in binary DER
format.
$ ocsptool -i -Q ocsp-request.der
The input file may also be sent to standard input like this:
$ cat ocsp-request.der | ocsptool --request-info
Print information about an OCSP response
Similar to parsing OCSP requests, OCSP responses can be parsed using
the -j
or --response-info
as follows.
$ ocsptool -j -Q ocsp-response.der $ cat ocsp-response.der | ocsptool --response-info
Generate an OCSP request
The -q
or --generate-request
parameters are used to
generate an OCSP request. By default the OCSP request is written to
standard output in binary DER format, but can be stored in a file
using --outfile
. To generate an OCSP request the issuer of the
certificate to check needs to be specified with --load-issuer
and the certificate to check with --load-cert
. By default PEM
format is used for these files, although --inder
can be used to
specify that the input files are in DER format.
$ ocsptool -q --load-issuer issuer.pem --load-cert client.pem --outfile ocsp-request.der
When generating OCSP requests, the tool will add an OCSP extension
containing a nonce. This behaviour can be disabled by specifying
--no-nonce
.
Verify signature in OCSP response
To verify the signature in an OCSP response the -e
or
--verify-response
parameter is used. The tool will read an
OCSP response in DER format from standard input, or from the file
specified by --load-response
. The OCSP response is verified
against a set of trust anchors, which are specified using
--load-trust
. The trust anchors are concatenated certificates
in PEM format. The certificate that signed the OCSP response needs to
be in the set of trust anchors, or the issuer of the signer
certificate needs to be in the set of trust anchors and the OCSP
Extended Key Usage bit has to be asserted in the signer certificate.
$ ocsptool -e --load-trust issuer.pem --load-response ocsp-response.der
The tool will print status of verification.
Verify signature in OCSP response against given certificate
It is possible to override the normal trust logic if you know that a
certain certificate is supposed to have signed the OCSP response, and
you want to use it to check the signature. This is achieved using
--load-signer
instead of --load-trust
. This will load
one certificate and it will be used to verify the signature in the
OCSP response. It will not check the Extended Key Usage bit.
$ ocsptool -e --load-signer ocsp-signer.pem --load-response ocsp-response.der
This approach is normally only relevant in two situations. The first
is when the OCSP response does not contain a copy of the signer
certificate, so the --load-trust
code would fail. The second
is if you want to avoid the indirect mode where the OCSP response
signer certificate is signed by a trust anchor.
Real-world example
Here is an example of how to generate an OCSP request for a
certificate and to verify the response. For illustration we’ll use
the blog.josefsson.org
host, which (as of writing) uses a
certificate from CACert. First we’ll use gnutls-cli
to get a
copy of the server certificate chain. The server is not required to
send this information, but this particular one is configured to do so.
$ echo | gnutls-cli -p 443 blog.josefsson.org --print-cert > chain.pem
Use a text editor on chain.pem
to create three files for each
separate certificates, called cert.pem
for the first
certificate for the domain itself, secondly issuer.pem
for the
intermediate certificate and root.pem
for the final root
certificate.
The domain certificate normally contains a pointer to where the OCSP
responder is located, in the Authority Information Access Information
extension. For example, from certtool -i < cert.pem
there is
this information:
Authority Information Access Information (not critical): Access Method: 1.3.6.1.5.5.7.48.1 (id-ad-ocsp) Access Location URI: http://ocsp.CAcert.org/
This means the CA support OCSP queries over HTTP. We are now ready to create a OCSP request for the certificate.
$ ocsptool --generate-request --load-issuer issuer.pem --load-cert cert.pem --outfile ocsp-request.der
The request is sent base64 encoded via HTTP to the address indicated by the id-ad-ocsp extension, as follows.
$ wget -O ocsp-response.der http://ocsp.CAcert.org/$(base64 -w0 ocsp-request.der)
The OCSP response is now in the file ocsp-response.der
and you
can view it using ocsptool -j < ocsp-response.der
. To verify
the signature you need to load the issuer as the trust anchor.
$ ocsptool --verify-response --load-trust issuer.pem --load-response ocsp-response.der Verifying OCSP Response: Success. $
This particular OCSP responder includes its signer certificate in the
OCSP respnose, so you may extract it and use it together with
--load-signer
for verifying the signature directly against the
certificate.
$ ocsptool -j < ocsp-response.der > signer.pem $ ocsptool --verify-response --load-signer signer.pem --load-response ocsp-response.der Verifying OCSP Response: Success. $
You may experiment passing different certificates to
--load-trust
and --load-signer
to find common error
conditions for OCSP response verification failures.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on January 21, 2012 using texi2html 5.0.