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.

goto end;<br />

}<br />

if (!(req = OCSP_REQUEST_new( ))) {<br />

result = SPC_OCSPRESULT_ERROR_OUTOFMEMORY;<br />

goto end;<br />

}<br />

id = OCSP_cert_to_id(0, data->cert, data->issuer);<br />

if (!id || !OCSP_request_add0_id(req, id)) goto end;<br />

OCSP_request_add1_nonce(req, 0, -1);<br />

/* sign the request */<br />

if (data->sign_cert && data->sign_key &&<br />

!OCSP_request_sign(req, data->sign_cert, data->sign_key, EVP_sha1( ), 0, 0)) {<br />

result = SPC_OCSPRESULT_ERROR_SIGNFAILURE;<br />

goto end;<br />

}<br />

/* establish a connection to the OCSP responder */<br />

if (!(bio = spc_connect(host, atoi(port), ssl, data->store, &ctx))) {<br />

result = SPC_OCSPRESULT_ERROR_CONNECTFAILURE;<br />

goto end;<br />

}<br />

/* send the request and get a response */<br />

resp = OCSP_sendreq_bio(bio, path, req);<br />

if ((rc = OCSP_response_status(resp)) != OCSP_RESPONSE_STATUS_SUCCESSFUL) {<br />

switch (rc) {<br />

case OCSP_RESPONSE_STATUS_MALFORMEDREQUEST:<br />

result = SPC_OCSPRESULT_ERROR_MALFORMEDREQUEST; break;<br />

case OCSP_RESPONSE_STATUS_INTERNALERROR:<br />

result = SPC_OCSPRESULT_ERROR_INTERNALERROR; break;<br />

case OCSP_RESPONSE_STATUS_TRYLATER:<br />

result = SPC_OCSPRESULT_ERROR_TRYLATER; break;<br />

case OCSP_RESPONSE_STATUS_SIGREQUIRED:<br />

result = SPC_OCSPRESULT_ERROR_SIGREQUIRED; break;<br />

case OCSP_RESPONSE_STATUS_UNAUTHORIZED:<br />

result = SPC_OCSPRESULT_ERROR_UNAUTHORIZED; break;<br />

}<br />

goto end;<br />

}<br />

/* verify the response */<br />

result = SPC_OCSPRESULT_ERROR_INVALIDRESPONSE;<br />

if (!(basic = OCSP_response_get1_basic(resp))) goto end;<br />

if (OCSP_check_nonce(req, basic) store && !(store = spc_create_x509store(data->store))) goto end;<br />

if ((rc = OCSP_basic_verify(basic, 0, store, 0)) skew, data->maxage))<br />

goto end;<br />

566 | Chapter 10: Public Key Infrastructure<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!