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 the types of verification checks that failed. SpcVerifyCert( ) checks the set of flags<br />

after the successful return from CertGetIssuerCertificateFromStore( ) to see if CERT_<br />

STORE_NO_CRL_FLAG is set. If it is, this indicates that no CRLcould be found in the<br />

store against which the subject certificate could be compared. At this point, the flags<br />

indicating failure as a result of there being no CRLare cleared. If any flags remain<br />

set, this means that verification of the subject certificate failed; the loop is terminated,<br />

and failure is returned.<br />

CryptoAPI certificate stores<br />

Several special certificate stores are available for use. In addition, private stores can<br />

be created that reside in memory, in the registry, or in a disk file. To use one of the<br />

special certificate stores, use the CryptoAPI function CertOpenSystemStore( ). This<br />

function requires a handle to a Cryptographic Services Provider (CSP) and the name<br />

of the certificate store to open. In the majority of cases, the CSP handle can be passed<br />

as NULL, in which case the default CSP will be used. One of the names listed in<br />

Table 10-2 may be opened for use.<br />

Table 10-2. System certificate stores and their contents<br />

Certificate store name Types of certificates in the store<br />

MY Contains certificates that are owned by the current user. For each certificate in this store, the<br />

associated private key is also available.<br />

CA Contains CA certificates that are not self-signed root certificates. These certificates are capable<br />

of issuing certificates.<br />

ROOT Contains root CA certificates that are trusted. All of the certificates in this store should be selfsigned.<br />

SPC Contains trusted software publisher certificates. The certificates in this store are used by<br />

Microsoft’s Authenticode.<br />

For the purposes of verification using SpcVerifyCert( ) as presented, you’ll need to<br />

create a temporary certificate store that contains all the certificates that will be<br />

needed to verify a subject certificate. At a minimum, the certificate that you want to<br />

verify must be in the store, but verification will only succeed if the only certificate in<br />

the store is the subject certificate and is self-signed, which in the vast majority of<br />

cases isn’t all that useful.<br />

If you do not have all the certificates and need to use certificates from one of the system<br />

stores, a copy of the needed certificate from the system store can be made for<br />

insertion into the temporary store being used for verification. Otherwise, certificates<br />

in memory as CERT_CONTEXT objects can be added to the temporary store, or encoded<br />

certificates residing in memory as a blob (binary large object) can be added.<br />

#include <br />

#include <br />

static PCCERT_CONTEXT FindIssuerInSystemStore(LPCTSTR pszStoreName,<br />

PCCERT_CONTEXT pSubjectContext) {<br />

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