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.

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

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

}<br />

The next three functions are used to set the locations from which trusted certificates<br />

and certificate revocation lists will be loaded:<br />

spc_x509store_setcafile( )<br />

Accepts a filename that specifies a single file containing any number of PEMencoded<br />

certificates. (See Recipe 7.17 for a discussion of PEM files.)<br />

spc_x509store_setcapath( )<br />

Accepts a pathname that specifies the location of trusted certificates. Each file in<br />

the directory should contain only a single PEM-encoded certificate and should<br />

be named with the hash value of the certificate it contains, suffixed with “.0”.<br />

The hash value of a certificate can be obtained by issuing the following command<br />

on the file containing the certificate:<br />

openssl x509 -noout -hash -in cert.pem<br />

spc_x509store_setcrlfile( )<br />

Accepts a filename that specifies a single file containing any number of PEMencoded<br />

CRLs.<br />

For any of the functions, NULL may be specified for the filename or pathname, in<br />

which case the system defaults will be used.<br />

void spc_x509store_setcafile(spc_x509store_t *spc_store, char *cafile) {<br />

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

spc_store->cafile = (cafile ? strdup(cafile) : 0);<br />

}<br />

void spc_x509store_setcapath(spc_x509store_t *spc_store, char *capath) {<br />

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

spc_store->capath = (capath ? strdup(capath) : 0);<br />

}<br />

void spc_x509store_setcrlfile(spc_x509store_t *spc_store, char *crlfile) {<br />

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

spc_store->crlfile = (crlfile ? strdup(crlfile) : 0);<br />

}<br />

Additional certificates and CRLs can be added to the store using one of the next two<br />

functions. Note that if duplicate certificates or CRLs are included in the spc_<br />

x509store_t object, spc_create_x509store( ) will not be able to successfully create an<br />

X509_STORE object. These two functions should only be used to add certificates and<br />

CRLs to the store that are not present in the certificate file, certificate path, or CRL<br />

file.<br />

void spc_x509store_addcert(spc_x509store_t *spc_store, X509 *cert) {<br />

sk_X509_push(spc_store->certs, cert);<br />

}<br />

Performing X.509 Certificate Verification with OpenSSL | 527<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!