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.

SPC_X509STORE_SSL_VERIFY_NONE<br />

This flag corresponds to OpenSSL’s SSL_VERIFY_NONE flag and is used to construct<br />

the flags that are passed in the call to SSL_CTX_set_verify( ) by spc_<br />

create_sslctx( ).<br />

SPC_X509STORE_SSL_VERIFY_PEER<br />

This flag corresponds to OpenSSL’s SSL_VERIFY_PEER flag and is used to construct<br />

the flags that are passed in the call to SSL_CTX_set_verify( ) by spc_<br />

create_sslctx( ).<br />

SPC_X509STORE_SSL_VERIFY_FAIL_IF_NO_PEER_CERT<br />

This flag corresponds to OpenSSL’s SSL_VERIFY_FAIL_IF_NO_PEER_CERT flag and is<br />

used to construct the flags that are passed in the call to SSL_CTX_set_verify( ) by<br />

spc_create_sslctx( ).<br />

SPC_X509STORE_SSL_VERIFY_CLIENT_ONCE<br />

This flag corresponds to OpenSSL’s SSL_VERIFY_CLIENT_ONCE flag and is used to<br />

construct the flags that are passed in the call to SSL_CTX_set_verify( ) by spc_<br />

create_sslctx( ).<br />

SPC_X509STORE_SSL_VERIFY_MASK<br />

This is simply a combination of all the SSLverification flags that is intended for<br />

internal use only.<br />

We will also need an additional set of functions to add certificate and key information<br />

into the context for presenting to a peer when it is requested. The information<br />

will be used by spc_create_sslctx( ) when creating an SSL_CTX object, but only if<br />

SPC_X509STORE_USE_CERTIFICATE is set in the spc_x509store_t’s flags.<br />

void spc_x509store_setusecertfile(spc_x509store_t *spc_store, char *file) {<br />

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

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

}<br />

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

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

}<br />

void spc_x509store_setusekeyfile(spc_x509store_t *spc_store, char *file) {<br />

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

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

}<br />

void spc_x509store_setusekey(spc_x509store_t *spc_store, EVP_PKEY *key) {<br />

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

spc_store->use_key = key;<br />

CRYPTO_add(&(key->references), 1, CRYPTO_LOCK_EVP_PKEY);<br />

}<br />

Both the certificates and the keys can be specified either as a file from which to load<br />

the information, or as preexisting OpenSSLobjects of the appropriate type (X509<br />

objects for certificates, and EVP_PKEY objects for keys). If a filename is specified, it will<br />

Verifying an SSL Peer’s Certificate | 537<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!