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.

We begin our solution by defining two data types. One is merely a convenience for a<br />

function pointer. The other is the core of our X509_STORE wrapper:<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

typedef int (*spc_x509verifycallback_t)(int, X509_STORE_CTX *);<br />

typedef struct {<br />

char *cafile;<br />

char *capath;<br />

char *crlfile;<br />

spc_x509verifycallback_t callback;<br />

STACK_OF(X509) *certs;<br />

STACK_OF(X509_CRL) *crls;<br />

char *use_certfile;<br />

STACK_OF(X509) *use_certs;<br />

char *use_keyfile;<br />

EVP_PKEY *use_key;<br />

int flags;<br />

} spc_x509store_t;<br />

We will not get into any detailed explanation of this structure here. Instead, we will<br />

provide a complete set of functions to manipulate the structure and explain as we go<br />

along. The first two functions are used to initialize and clean up an spc_x509store_t<br />

object. The caller is responsible for allocating memory for the object as necessary.<br />

Our API will only manage the object’s contents.<br />

void spc_init_x509store(spc_x509store_t *spc_store) {<br />

spc_store->cafile = 0;<br />

spc_store->capath = 0;<br />

spc_store->crlfile = 0;<br />

spc_store->callback = 0;<br />

spc_store->certs = sk_X509_new_null( );<br />

spc_store->crls = sk_X509_CRL_new_null( );<br />

spc_store->use_certfile = 0;<br />

spc_store->use_certs = sk_X509_new_null( );<br />

spc_store->use_keyfile = 0;<br />

spc_store->use_key = 0;<br />

spc_store->flags = 0;<br />

}<br />

void spc_cleanup_x509store(spc_x509store_t *spc_store) {<br />

if (spc_store->cafile) free(spc_store->cafile);<br />

if (spc_store->capath) free(spc_store->capath);<br />

if (spc_store->crlfile) free(spc_store->crlfile);<br />

if (spc_store->use_certfile) free(spc_store->use_certfile);<br />

if (spc_store->use_keyfile) free(spc_store->use_keyfile);<br />

if (spc_store->use_key) EVP_PKEY_free(spc_store->use_key);<br />

sk_X509_free(spc_store->certs);<br />

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