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.

lpFullBuffer = lpNewBuffer;<br />

lpBuffer = (LPVOID)((LPBYTE)lpFullBuffer + dwContentLength);<br />

}<br />

if ((lpNewBuffer = LocalReAlloc(lpFullBuffer, dwContentLength, 0)) != 0)<br />

lpFullBuffer = lpNewBuffer;<br />

InternetCloseHandle(hRequest);<br />

InternetCloseHandle(hSession);<br />

*lpdwDataLength = dwContentLength;<br />

return (BYTE *)lpFullBuffer;<br />

}<br />

The primary function used in this recipe is SpcRetrieveCRL( ). It ties all of the other<br />

functions together in a neat little package, returning a CRL_CONTEXT object to the caller<br />

if a CRLcan be successfully obtained using the information from the subject and<br />

issuer certificates that are required as arguments. SpcRetrieveCRL( ) uses the URL<br />

information from cRLDistributionPoints extensions in either certificate before consulting<br />

the internal table of CA fingerprints and CRLURLs. Unfortunately, the<br />

cRLDistributionPoints extension often contains a URLthat is invalid, so this case is<br />

handled by falling back on the table lookup if the data cannot be retrieved from the<br />

cRLDistributionPoints information.<br />

If the function is successful, it returns a CRL_CONTEXT object created using CryptoAPI.<br />

When the object is no longer needed, it should be destroyed using<br />

CertFreeCRLContext( ). If a CRLcannot be created for some reason, NULL is returned,<br />

and the Win32 function GetLastError( ) can be used to determine what went wrong.<br />

PCCRL_CONTEXT SpcRetrieveCRL(PCCERT_CONTEXT pSubject, PCCERT_CONTEXT pIssuer) {<br />

BYTE *pbData;<br />

DWORD cbData;<br />

LPSTR lpszURL, lpszSecondURL;<br />

PCCRL_CONTEXT pCRL;<br />

if (!(lpszURL = SpcGetCertCRLURL(pSubject, pIssuer, FALSE))) return 0;<br />

if (!(pbData = RetrieveWebData(lpszURL, &cbData))) {<br />

lpszSecondURL = SpcGetCertCRLURL(pSubject, pIssuer, TRUE);<br />

if (!lpszSecondURL || !lstrcmpA(lpszURL, lpszSecondURL)) {<br />

if (lpszSecondURL) LocalFree(lpszSecondURL);<br />

LocalFree(lpszURL);<br />

return 0;<br />

}<br />

pbData = RetrieveWebData(lpszSecondURL, &cbData);<br />

LocalFree(lpszSecondURL);<br />

}<br />

if (pbData) {<br />

pCRL = CertCreateCRLContext(X509_ASN_ENCODING, pbData, cbData);<br />

LocalFree(pbData);<br />

}<br />

LocalFree(lpszURL);<br />

return pCRL;<br />

}<br />

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