21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

void spc_x509store_addcrl(spc_x509store_t *spc_store, X509_CRL *crl) {<br />

sk_X509_CRL_push(spc_store->crls, crl);<br />

}<br />

The last set of functions for manipulating spc_x509store_t objects is used for setting<br />

up a certificate verification callback function and for defining flags that control various<br />

aspects of the X509_STORE and certificate verification behavior. If no verification<br />

callback function is defined, spc_verify_callback( ) is the default; it simply prints<br />

any errors encountered out to stderr.<br />

void spc_x509store_setcallback(spc_x509store_t *spc_store,<br />

spc_x509verifycallback_t callback) {<br />

spc_store->callback = callback;<br />

}<br />

#define SPC_X509STORE_NO_DEFAULT_CAFILE 0x01<br />

#define SPC_X509STORE_NO_DEFAULT_CAPATH 0x02<br />

void spc_x509store_setflags(spc_x509store_t *spc_store, int flags) {<br />

spc_store->flags |= flags;<br />

}<br />

void spc_x509store_clearflags(spc_x509store_t *spc_store, int flags) {<br />

spc_store->flags &= ~flags;<br />

}<br />

int spc_verify_callback(int ok, X509_STORE_CTX *store) {<br />

if (!ok)<br />

fprintf(stderr, "Error: %s\n", X509_verify_cert_error_string(store->error));<br />

return ok;<br />

}<br />

Only two flags are defined here, leaving plenty of room to expand the implementation<br />

and add additional flags as needed:<br />

SPC_X509STORE_NO_DEFAULT_CAFILE<br />

If this flag is set and no file of trusted certificates has been specified, the systemwide<br />

default is used. This flag is checked when creating an X509_STORE object via<br />

spc_create_x509store( ).<br />

SPC_X509STORE_NO_DEFAULT_CAPATH<br />

If this flag is set and no path of trusted certificates has been specified, the system-wide<br />

default is not used. This flag is checked when creating an X509_STORE<br />

object via spc_create_x509store( ).<br />

The last function, spc_create_x509store( ), creates a new X509_STORE object from the<br />

information contained in the spc_x509store_t object that it accepts as its only argument.<br />

Attentive readers will notice at this point that we have omitted discussion of<br />

several fields in the spc_x509store_t structure. We will address them in Recipe 10.7.<br />

X509_STORE *spc_create_x509store(spc_x509store_t *spc_store) {<br />

int i;<br />

X509_STORE *store;<br />

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