21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SPC_OCSPRESULT_CERTIFICATE_VALID = 0,<br />

SPC_OCSPRESULT_CERTIFICATE_REVOKED = 1<br />

} spc_ocspresult_t;<br />

You will notice that any nonzero result code is an error of some kind—whether it is<br />

an error resulting in a failure to obtain the revocation status of the certificate in question,<br />

or one indicating that the certificate has been revoked. When checking the error<br />

codes, do not assume that zero means failure, as is the norm. You should always use<br />

these constants, instead of simple boolean tests, when checking the result of an<br />

OCSP operation.<br />

The following result codes have special meaning:<br />

SPC_OCSPRESULT_ERROR_MALFORMEDREQUEST through SPC_OCSPRESULT_ERROR_UNKNOWN<br />

Result codes starting with SPC_OCSPRESULT_ERROR_MALFORMEDREQUEST and ending<br />

with SPC_OCSPRESULT_ERROR_UNKNOWN come directly from the OCSP responder. If<br />

you receive any of these error codes, you can assume that communications with<br />

the OCSP responder were successfully established, but the responder was unable<br />

to satisfy the request for one of the reasons given.<br />

SPC_OCSPRESULT_ERROR_INVALIDRESPONSE<br />

Indicates that there was some failure in verifying the response received from the<br />

OCSP responder. In this case, it is a good idea not to trust the certificate for<br />

which you were attempting to discover the revocation status. It is safe to assume<br />

that communications with the OCSP responder were never established if you<br />

receive any of the other error codes.<br />

SPC_OCSPRESULT_CERTIFICATE_VALID or SPC_OCSPRESULT_CERTIFICATE_REVOKED<br />

If the request was successfully sent to the OCSP responder, and a valid response<br />

was received, the result code will be one of these codes.<br />

Once an spc_ocsprequest_t structure is created and appropriately initialized, communicating<br />

with the OCSP responder is a simple matter of calling spc_verify_via_<br />

ocsp( ) and checking the result code.<br />

spc_ocspresult_t spc_verify_via_ocsp(spc_ocsprequest_t *data) {<br />

BIO *bio = 0;<br />

int rc, reason, ssl, status;<br />

char *host = 0, *path = 0, *port = 0;<br />

SSL_CTX *ctx = 0;<br />

X509_STORE *store = 0;<br />

OCSP_CERTID *id;<br />

OCSP_REQUEST *req = 0;<br />

OCSP_RESPONSE *resp = 0;<br />

OCSP_BASICRESP *basic = 0;<br />

spc_ocspresult_t result;<br />

ASN1_GENERALIZEDTIME *producedAt, *thisUpdate, *nextUpdate;<br />

result = SPC_OCSPRESULT_ERROR_UNKNOWN;<br />

if (!OCSP_parse_url(data->url, &host, &port, &path, &ssl)) {<br />

result = SPC_OCSPRESULT_ERROR_BADOCSPADDRESS;<br />

Checking Revocation Status via OCSP with OpenSSL | 565<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!