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.

LocalFree(pvStructInfo);<br />

return 0;<br />

}<br />

The SpcLookupCACert( ) function computes the fingerprint of the specified certificate<br />

and tries to match it with a fingerprint in the table of CA certificates and CRLURLs<br />

that we’ve already defined. If a match is found, the function returns a pointer to the<br />

matching entry. We will be using MD5 for computing the fingerprint, so we know<br />

that the size of the fingerprint will always be 16 bytes. (Note that we have essentially<br />

taken the SpcFingerPrintCert( ) and SpcFingerPrintEqual( ) functions from Recipe<br />

10.9, stripped them down a bit, and combined them here.)<br />

SPC_CACERT *SpcLookupCACert(PCCERT_CONTEXT pCertContext) {<br />

SPC_CACERT *pCACert;<br />

BYTE pbFingerPrint[16]; /* MD5 is 128 bits or 16 bytes */<br />

DWORD cbFingerPrint;<br />

/* Compute the fingerprint of the certificate */<br />

cbFingerPrint = sizeof(pbFingerPrint);<br />

CryptHashCertificate(0, CALG_MD5, 0, pCertContext->pbCertEncoded,<br />

pCertContext->cbCertEncoded, pbFingerPrint,<br />

&cbFingerPrint);<br />

/* Compare the computed certificate against those in our lookup table */<br />

for (pCACert = rgLookupTable; pCACert->pbFingerPrint; pCACert++) {<br />

if (!memcmp(pCACert->pbFingerPrint, pbFingerPrint, cbFingerPrint))<br />

return pCACert;<br />

}<br />

return 0;<br />

}<br />

SpcGetCertCRLURL( ) attempts to find the URLfor the CRLfor a certificate. It first<br />

checks the subject’s certificate for an RFC 3280 cRLDistributionPoints extension<br />

using the GetDistributionPoint( ) worker function. If the subject certificate does not<br />

have one, the function checks the issuer’s certificate. If neither certificate contains a<br />

cRLDistributionPoints extension, it checks the issuer certificate’s fingerprint against<br />

the table of CA fingerprints and CRLURLs using SpcLookupCACert( ). If a URLcannot<br />

be determined, SpcGetCertCRLURL( ) returns NULL.<br />

LPSTR SpcGetCertCRLURL(PCCERT_CONTEXT pSubject, PCCERT_CONTEXT pIssuer,<br />

BOOL bLookupOnly) {<br />

LPSTR lpszURL;<br />

SPC_CACERT *pCACert;<br />

if (!bLookupOnly) {<br />

if (pSubject && (lpszURL = GetDistributionPoint(pSubject)) != 0)<br />

return lpszURL;<br />

if (pIssuer && (lpszURL = GetDistributionPoint(pIssuer)) != 0)<br />

return lpszURL;<br />

}<br />

/* Get the fingerprint of the cert's issuer, and look it up in a table */<br />

Obtaining CRLs with CryptoAPI | 559<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!