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.

end_error:<br />

if (data) { free(data); data = 0; *datalen = 0; }<br />

end:<br />

if (headers) free(headers);<br />

if (conn) BIO_free_all(conn);<br />

if (host) OPENSSL_free(host);<br />

if (port) OPENSSL_free(port);<br />

if (path) OPENSSL_free(path);<br />

if (ctx) SSL_CTX_free(ctx);<br />

return data;<br />

}<br />

With the data that has been retrieved from the server, we can create an OpenSSL X509_<br />

CRL object. We assume that the data retrieved from the server will be in DER format,<br />

which is the format returned by every server we have encountered (see Recipe 7.16).<br />

The DER format is more portable because not everyone supports PEM format. It is also<br />

a more compact format for transfer because it does not include any headers or base64<br />

encoding. The OpenSSLfunction d2i_X509_CRL_bio( ) is used to create the X509_CRL<br />

object using a memory base BIO object created with BIO_new_mem_buf( ).<br />

X509_CRL *spc_retrieve_crl(X509 *cert, X509 *issuer, spc_x509store_t *store) {<br />

BIO *bio = 0;<br />

int datalen, our_store;<br />

char *uri = 0, *uri2 = 0;<br />

void *data = 0;<br />

X509_CRL *crl = 0;<br />

if ((our_store = (!store)) != 0) {<br />

if (!(store = (spc_x509store_t *)malloc(sizeof(spc_x509store_t)))) return 0;<br />

spc_init_x509store(store);<br />

spc_x509store_addcert(store, issuer);<br />

}<br />

if (!(uri = spc_getcert_crlurl(cert, issuer, 0))) goto end;<br />

if (!(data = retrieve_webdata(uri, &datalen, store))) {<br />

uri2 = spc_getcert_crlurl(cert, issuer, 1);<br />

if (!uri2 || !strcmp(uri, uri2)) goto end;<br />

if (!(data = retrieve_webdata(uri2, &datalen, store))) goto end;<br />

}<br />

bio = BIO_new_mem_buf(data, datalen);<br />

crl = d2i_X509_CRL_bio(bio, 0);<br />

end:<br />

if (bio) BIO_free(bio);<br />

if (data) free(data);<br />

if (uri) free(uri);<br />

if (uri2) free(uri2);<br />

if (store && our_store) {<br />

spc_cleanup_x509store(store);<br />

free(store);<br />

}<br />

return crl;<br />

}<br />

554 | 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!