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.

for (i = 0; !bResult && i < pNameInfo->cAltEntry; i++) {<br />

if (pNameInfo->rgAltEntry[i].dwAltNameChoice = = CERT_ALT_NAME_DNS_NAME) {<br />

if (!(lpszDNSName = fold_wide(pNameInfo->rgAltEntry[i].pwszDNSName)))<br />

break;<br />

if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, lpszDNSName,<br />

-1, lpszHostName, -1) = = CSTR_EQUAL)<br />

bResult = TRUE;<br />

LocalFree(lpszDNSName);<br />

}<br />

}<br />

LocalFree(pvStructInfo);<br />

LocalFree(lpszHostName);<br />

return bResult;<br />

}<br />

}<br />

/* No subjectAltName extension -- check commonName */<br />

dwCommonNameLength = CertGetNameStringW(pCertContext, CERT_NAME_ATTR_TYPE, 0,<br />

szOID_COMMON_NAME, 0, 0);<br />

if (!dwCommonNameLength) {<br />

LocalFree(lpszHostName);<br />

return FALSE;<br />

}<br />

lpszTemp = (LPWSTR)LocalAlloc(LMEM_FIXED, dwCommonNameLength * sizeof(WCHAR));<br />

if (lpszTemp) {<br />

CertGetNameStringW(pCertContext, CERT_NAME_ATTR_TYPE, 0, szOID_COMMON_NAME,<br />

lpszTemp, dwCommonNameLength);<br />

if ((lpszCommonName = fold_wide(lpszTemp)) != 0) {<br />

if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, lpszCommonName,<br />

-1, lpszHostName, -1) = = CSTR_EQUAL)<br />

bResult = TRUE;<br />

LocalFree(lpszCommonName);<br />

}<br />

LocalFree(lpszTemp);<br />

}<br />

LocalFree(lpszHostName);<br />

return bResult;<br />

}<br />

Unfortunately, if you are using a version of the Microsoft Windows Platform SDK<br />

older than the .NET version, you will experience difficulties compiling and linking<br />

this code into your program. The older wincrypt.h header file and crypt32.lib import<br />

library are missing the definitions required to use CertGetNameStringW( ), even<br />

though they are documented to be available in versions prior to .NET. The definitions<br />

required for your code are:<br />

#ifndef CERT_NAME_ATTR_TYPE<br />

WINCRYPT32API<br />

DWORD<br />

WINAPI<br />

CertGetNameStringW(<br />

IN PCCERT_CONTEXT pCertIntext,<br />

Adding Hostname Checking to Certificate Verification | 543<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!