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.

IN DWORD dwType,<br />

IN DWORD dwFlags,<br />

IN void *pvTypePara,<br />

OUT OPTIONAL LPWSTR pszNameString,<br />

IN DWORD cchNameString<br />

);<br />

#define CERT_NAME_ATTR_TYPE 3<br />

#endif<br />

CertGetNameStringW( ) is exported from all versions of crypt32.dll that are included<br />

with Microsoft Internet Explorer 3.02 or later. You may run into problems linking,<br />

however, because the import is missing from crypt32.lib. In our testing, we have<br />

experienced no problems using the crypt32.lib distributed with the latest Microsoft<br />

Windows Platform SDK. Unfortunately, we have been unable to find an alternative<br />

method of obtaining the contents of the commonName field in a certificate other than<br />

using this function.<br />

See Also<br />

Recipe 10.4<br />

10.9 Using a Whitelist to Verify Certificates<br />

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

You have a certificate that you want to compare against a list of known good certificates.<br />

Solution<br />

The average certificate is generally small, often under 2 KB in size. Because a certificate<br />

is both reasonably small and cannot be undetectably modified once it has been<br />

signed by a CA, it might seem reasonable to do a byte-for-byte comparison of the<br />

certificate with a list of certificates. One problem with this approach is that if you are<br />

comparing a certificate against a sizable list, performing the comparisons can become<br />

a time-consuming operation. The other problem is that of storing all the certificates<br />

in the list against which the certificate to verify will be compared. A better way is to<br />

compute the fingerprint of each certificate and store the fingerprint instead of the<br />

entire certificate. Fingerprints are generally only 16 or 20 bytes in size, depending on<br />

the message digest algorithm used to compute them.<br />

Discussion<br />

In OpenSSL, computing the fingerprint of a certificate is as simple as a single call to<br />

X509_digest( ). Comparing fingerprints is done with a byte-for-byte comparison. The<br />

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