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.

10.5 Performing X.509 Certificate Verification<br />

with OpenSSL<br />

<strong>Problem</strong><br />

You have an X.509 certificate and you want to verify its validity using OpenSSL.<br />

Solution<br />

OpenSSLrepresents an X.509 certificate using an X509 object. Another object, an<br />

X509_STORE, must be combined with the X509 object to be verified into an X509_STORE_<br />

CTX object. An X509_STORE object contains the certificates that OpenSSLwill use to<br />

verify the certificate under scrutiny, as well as an optional CRL. The X509_STORE_CTX<br />

object simply combines the X509_STORE and X509 objects. The actual certificate verification<br />

is performed by calling X509_verify_cert( ) and passing it the X509_STORE_CTX<br />

object.<br />

Discussion<br />

Actually performing the certificate verification requires a significant amount of setup<br />

work. Much of the work should not really be necessary, but there are some issues<br />

with the current version of OpenSSLthat need to be addressed. The OpenSSLteam<br />

is aware of the problems we have encountered, and we anticipate that they will be<br />

fixed at some point in the future, but unfortunately, we do not know when that<br />

might be.<br />

OpenSSLprovides a set of functions for manipulating X509_STORE objects, and we<br />

will be using them, but in versions of OpenSSLup to and including the initial release<br />

of 0.9.7, no X.509 objects are reference counted while other OpenSSLobjects<br />

(including EVP_PKEY, SSL_CTX, and many others) are. This presents a problem for us<br />

because much of the code that we will be presenting needs to have only a single<br />

X509_STORE object used for different purposes. If we attach the X509_STORE object to<br />

an SSL_CTX, for example, when the SSL_CTX is destroyed, so is the X509_STORE object.<br />

When trying to build a higher-level API on top of OpenSSL’s API, things quickly get<br />

ugly.<br />

The situation is complicated by the fact that OpenSSLprovides no APIs to duplicate<br />

objects. Our solution to this problem as a whole is to create a new structure that contains<br />

everything we might need, then to create X509_STORE objects from that structure<br />

as we need them. It is obviously not optimal, and it is also not a perfect solution,<br />

but it is difficult to do any better. The proper solution is OpenSSL’s to implement,<br />

but it’s not a small task. Reference counting is often difficult to get right, and adding<br />

that kind of memory management into a large body of existing code is even harder.<br />

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