Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

573 lines
22 KiB

//+-------------------------------------------------------------------------
// Microsoft Windows
//
// Copyright (C) Microsoft Corporation, 2001 - 2001
//
// File: vercert.cpp
//
// Contents: Minimal Cryptographic functions to verify ASN.1 encoded
// X.509 certificates
//
//
// Functions: MinCryptVerifyCertificate
//
// History: 17-Jan-01 philh created
//--------------------------------------------------------------------------
#include "global.hxx"
#define MAX_CHAIN_DEPTH 10
// #define USE_TEST_ROOTS_FOR_TESTING 1
//+=========================================================================
// Microsoft Roots
//-=========================================================================
// Name:: <CN=Microsoft Authenticode(tm) Root Authority, O=MSFT, C=US>
const BYTE rgbMicrosoftRoot0_Name[] = {
0x30, 0x50, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03,
0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0A,
0x13, 0x04, 0x4D, 0x53, 0x46, 0x54, 0x31, 0x32,
0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
0x29, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F,
0x66, 0x74, 0x20, 0x41, 0x75, 0x74, 0x68, 0x65,
0x6E, 0x74, 0x69, 0x63, 0x6F, 0x64, 0x65, 0x28,
0x74, 0x6D, 0x29, 0x20, 0x52, 0x6F, 0x6F, 0x74,
0x20, 0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, 0x69,
0x74, 0x79
};
const BYTE rgbMicrosoftRoot0_PubKeyInfo[]= {
0x30, 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09,
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01,
0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00,
0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01,
0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0x05, 0x43, 0x7B,
0x2C, 0x05, 0x8D, 0xBD, 0x3D, 0x03, 0x8C, 0x93,
0x22, 0x7D, 0x63, 0xEA, 0x0A, 0x57, 0x05, 0x06,
0x0A, 0xDB, 0x61, 0x98, 0x65, 0x2D, 0x47, 0x49,
0xA8, 0xE7, 0xE6, 0x56, 0x75, 0x5C, 0xB8, 0x64,
0x08, 0x63, 0xA9, 0x30, 0x40, 0x66, 0xB2, 0xF9,
0xB6, 0xE3, 0x34, 0xE8, 0x67, 0x30, 0xE1, 0x43,
0x0B, 0x87, 0xFF, 0xC9, 0xBE, 0x72, 0x10, 0x5E,
0x23, 0xF0, 0x9B, 0xA7, 0x48, 0x65, 0xBF, 0x09,
0x88, 0x7B, 0xCD, 0x72, 0xBC, 0x2E, 0x79, 0x9B,
0x7B, 0x02, 0x03, 0x01, 0x00, 0x01
};
// Name:: <CN=Microsoft Root Authority, OU=Microsoft Corporation,
// OU=Copyright (c) 1997 Microsoft Corp.>
const BYTE rgbMicrosoftRoot1_Name[]= {
0x30, 0x70, 0x31, 0x2B, 0x30, 0x29, 0x06, 0x03,
0x55, 0x04, 0x0B, 0x13, 0x22, 0x43, 0x6F, 0x70,
0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28,
0x63, 0x29, 0x20, 0x31, 0x39, 0x39, 0x37, 0x20,
0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x2E, 0x31,
0x1E, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x04, 0x0B,
0x13, 0x15, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73,
0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70,
0x6F, 0x72, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x31,
0x21, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x04, 0x03,
0x13, 0x18, 0x4D, 0x69, 0x63, 0x72, 0x6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B4, 0x64, 0x3B, 0x9A, 0x50, 0x1C, 0x31, 0x08,
0x24, 0x14, 0x9F, 0xA9, 0xE7, 0x91, 0x2B, 0x18,
0xE6, 0x3D, 0x98, 0x63, 0x14, 0x60, 0x58, 0x05,
0x65, 0x9F, 0x1D, 0x37, 0x52, 0x87, 0xF7, 0xA7,
0xEF, 0x94, 0x02, 0xC6, 0x1B, 0xD3, 0xBF, 0x55,
0x45, 0xB3, 0x89, 0x80, 0xBF, 0x3A, 0xEC, 0x54,
0x94, 0x4E, 0xAE, 0xFD, 0xA7, 0x7A, 0x6D, 0x74,
0x4E, 0xAF, 0x18, 0xCC, 0x96, 0x09, 0x28, 0x21,
0x00, 0x57, 0x90, 0x60, 0x69, 0x37, 0xBB, 0x4B,
0x12, 0x07, 0x3C, 0x56, 0xFF, 0x5B, 0xFB, 0xA4,
0x66, 0x0A, 0x08, 0xA6, 0xD2, 0x81, 0x56, 0x57,
0xEF, 0xB6, 0x3B, 0x5E, 0x16, 0x81, 0x77, 0x04,
0xDA, 0xF6, 0xBE, 0xAE, 0x80, 0x95, 0xFE, 0xB0,
0xCD, 0x7F, 0xD6, 0xA7, 0x1A, 0x72, 0x5C, 0x3C,
0xCA, 0xBC, 0xF0, 0x08, 0xA3, 0x22, 0x30, 0xB3,
0x06, 0x85, 0xC9, 0xB3, 0x20, 0x77, 0x13, 0x85,
0xDF, 0x02, 0x03, 0x01, 0x00, 0x01
};
// 4096 bit key generated in 2001
//
// Name:: <CN=Microsoft Root Certificate Authority, DC=microsoft, DC=com>
const BYTE rgbMicrosoftRoot2_Name[]= {
0x30, 0x5F, 0x31, 0x13, 0x30, 0x11, 0x06, 0x0A,
0x09, 0x92, 0x26, 0x89, 0x93, 0xF2, 0x2C, 0x64,
0x01, 0x19, 0x16, 0x03, 0x63, 0x6F, 0x6D, 0x31,
0x19, 0x30, 0x17, 0x06, 0x0A, 0x09, 0x92, 0x26,
0x89, 0x93, 0xF2, 0x2C, 0x64, 0x01, 0x19, 0x16,
0x09, 0x6D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F,
0x66, 0x74, 0x31, 0x2D, 0x30, 0x2B, 0x06, 0x03,
0x55, 0x04, 0x03, 0x13, 0x24, 0x4D, 0x69, 0x63,
0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x52,
0x6F, 0x6F, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74,
0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20,
0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, 0x69, 0x74,
0x79
};
const BYTE rgbMicrosoftRoot2_PubKeyInfo[]= {
0x30, 0x82, 0x02, 0x22, 0x30, 0x0D, 0x06, 0x09,
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01,
0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0F, 0x00,
0x30, 0x82, 0x02, 0x0A, 0x02, 0x82, 0x02, 0x01,
0x00, 0xF3, 0x5D, 0xFA, 0x80, 0x67, 0xD4, 0x5A,
0xA7, 0xA9, 0x0C, 0x2C, 0x90, 0x20, 0xD0, 0x35,
0x08, 0x3C, 0x75, 0x84, 0xCD, 0xB7, 0x07, 0x89,
0x9C, 0x89, 0xDA, 0xDE, 0xCE, 0xC3, 0x60, 0xFA,
0x91, 0x68, 0x5A, 0x9E, 0x94, 0x71, 0x29, 0x18,
0x76, 0x7C, 0xC2, 0xE0, 0xC8, 0x25, 0x76, 0x94,
0x0E, 0x58, 0xFA, 0x04, 0x34, 0x36, 0xE6, 0xDF,
0xAF, 0xF7, 0x80, 0xBA, 0xE9, 0x58, 0x0B, 0x2B,
0x93, 0xE5, 0x9D, 0x05, 0xE3, 0x77, 0x22, 0x91,
0xF7, 0x34, 0x64, 0x3C, 0x22, 0x91, 0x1D, 0x5E,
0xE1, 0x09, 0x90, 0xBC, 0x14, 0xFE, 0xFC, 0x75,
0x58, 0x19, 0xE1, 0x79, 0xB7, 0x07, 0x92, 0xA3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B,
0x30, 0x99, 0x8F, 0x16, 0xAA, 0x23, 0xA8, 0x41,
0xD1, 0xB0, 0x6E, 0x11, 0x9B, 0x36, 0xC4, 0xDE,
0x40, 0x74, 0x9C, 0xE1, 0x58, 0x65, 0xC1, 0x60,
0x1E, 0x7A, 0x5B, 0x38, 0xC8, 0x8F, 0xBB, 0x04,
0x26, 0x7C, 0xD4, 0x16, 0x40, 0xE5, 0xB6, 0x6B,
0x6C, 0xAA, 0x86, 0xFD, 0x00, 0xBF, 0xCE, 0xC1,
0x35, 0x02, 0x03, 0x01, 0x00, 0x01
};
#ifdef USE_TEST_ROOTS_FOR_TESTING
//+=========================================================================
// Test Roots
//-=========================================================================
// Name:: <CN=Microsoft Test Root Authority, OU=Microsoft Corporation, OU=Copyright (c) 1999 Microsoft Corp.>
const BYTE rgbTestRoot0_Name[] = {
0x30, 0x75, 0x31, 0x2B, 0x30, 0x29, 0x06, 0x03,
0x55, 0x04, 0x0B, 0x13, 0x22, 0x43, 0x6F, 0x70,
0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28,
0x63, 0x29, 0x20, 0x31, 0x39, 0x39, 0x39, 0x20,
0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x2E, 0x31,
0x1E, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x04, 0x0B,
0x13, 0x15, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73,
0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70,
0x6F, 0x72, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x31,
0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03,
0x13, 0x1D, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73,
0x6F, 0x66, 0x74, 0x20, 0x54, 0x65, 0x73, 0x74,
0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x41, 0x75,
0x74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0, 0x32, 0xB0, 0x2A,
0x13, 0x21, 0xBE, 0xED, 0x24, 0xF4, 0x7D, 0x0D,
0xEA, 0xAA, 0x8A, 0x7A, 0xD2, 0x8B, 0x4D, 0x97,
0xB5, 0x4D, 0x64, 0xBA, 0xFB, 0x46, 0xDD, 0x69,
0x6F, 0x9A, 0x0E, 0xCC, 0x53, 0x77, 0xAA, 0x6E,
0xAE, 0x20, 0xD6, 0x21, 0x98, 0x69, 0xD9, 0x46,
0xB9, 0x64, 0x32, 0xD4, 0x17, 0x02, 0x03, 0x01,
0x00, 0x01
};
//+=========================================================================
// VeriSign Roots
//-=========================================================================
// Name:: <OU=VeriSign Commercial Software Publishers CA, O="VeriSign, Inc.", L=Internet>
const BYTE rgbVeriSignRoot0_Name[] = {
0x30, 0x61, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03,
0x55, 0x04, 0x07, 0x13, 0x08, 0x49, 0x6E, 0x74,
0x65, 0x72, 0x6E, 0x65, 0x74, 0x31, 0x17, 0x30,
0x15, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x0E,
0x56, 0x65, 0x72, 0x69, 0x53, 0x69, 0x67, 0x6E,
0x2C, 0x20, 0x49, 0x6E, 0x63, 0x2E, 0x31, 0x33,
0x30, 0x31, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13,
0x2A, 0x56, 0x65, 0x72, 0x69, 0x53, 0x69, 0x67,
0x6E, 0x20, 0x43, 0x6F, 0x6D, 0x6D, 0x65, 0x72,
0x63, 0x69, 0x61, 0x6C, 0x20, 0x53, 0x6F, 0x66,
0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x50, 0x75,
0x62, 0x6C, 0x69, 0x73, 0x68, 0x65, 0x72, 0x73,
0x20, 0x43, 0x41
};
const BYTE rgbVeriSignRoot0_PubKeyInfo[]= {
0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A,
0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81,
0x89, 0x02, 0x81, 0x81, 0x00, 0xC3, 0xD3, 0x69,
0x65, 0x52, 0x01, 0x94, 0x54, 0xAB, 0x28, 0xC6,
0x62, 0x18, 0xB3, 0x54, 0x55, 0xC5, 0x44, 0x87,
0x45, 0x4A, 0x3B, 0xC2, 0x7E, 0xD8, 0xD3, 0xD7,
0xC8, 0x80, 0x86, 0x8D, 0xD8, 0x0C, 0xF1, 0x16,
0x9C, 0xCC, 0x6B, 0xA9, 0x29, 0xB2, 0x8F, 0x76,
0x73, 0x92, 0xC8, 0xC5, 0x62, 0xA6, 0x3C, 0xED,
0x1E, 0x05, 0x75, 0xF0, 0x13, 0x00, 0x6C, 0x14,
0x4D, 0xD4, 0x98, 0x90, 0x07, 0xBE, 0x69, 0x73,
0x81, 0xB8, 0x62, 0x4E, 0x31, 0x1E, 0xD1, 0xFC,
0xC9, 0x0C, 0xEB, 0x7D, 0x90, 0xBF, 0xAE, 0xB4,
0x47, 0x51, 0xEC, 0x6F, 0xCE, 0x64, 0x35, 0x02,
0xD6, 0x7D, 0x67, 0x05, 0x77, 0xE2, 0x8F, 0xD9,
0x51, 0xD7, 0xFB, 0x97, 0x19, 0xBC, 0x3E, 0xD7,
0x77, 0x81, 0xC6, 0x43, 0xDD, 0xF2, 0xDD, 0xDF,
0xCA, 0xA3, 0x83, 0x8B, 0xCB, 0x41, 0xC1, 0x3D,
0x22, 0x48, 0x48, 0xA6, 0x19, 0x02, 0x03, 0x01,
0x00, 0x01
};
#endif
typedef struct _ROOT_INFO {
CRYPT_DER_BLOB EncodedName;
CRYPT_DER_BLOB EncodedPubKeyInfo;
} ROOT_INFO, *PROOT_INFO;
const ROOT_INFO RootTable[] = {
sizeof(rgbMicrosoftRoot0_Name), (BYTE *) rgbMicrosoftRoot0_Name,
sizeof(rgbMicrosoftRoot0_PubKeyInfo), (BYTE *) rgbMicrosoftRoot0_PubKeyInfo,
sizeof(rgbMicrosoftRoot1_Name), (BYTE *) rgbMicrosoftRoot1_Name,
sizeof(rgbMicrosoftRoot1_PubKeyInfo), (BYTE *) rgbMicrosoftRoot1_PubKeyInfo,
sizeof(rgbMicrosoftRoot2_Name), (BYTE *) rgbMicrosoftRoot2_Name,
sizeof(rgbMicrosoftRoot2_PubKeyInfo), (BYTE *) rgbMicrosoftRoot2_PubKeyInfo,
#ifdef USE_TEST_ROOTS_FOR_TESTING
sizeof(rgbTestRoot0_Name), (BYTE *) rgbTestRoot0_Name,
sizeof(rgbTestRoot0_PubKeyInfo), (BYTE *) rgbTestRoot0_PubKeyInfo,
sizeof(rgbVeriSignRoot0_Name), (BYTE *) rgbVeriSignRoot0_Name,
sizeof(rgbVeriSignRoot0_PubKeyInfo), (BYTE *) rgbVeriSignRoot0_PubKeyInfo,
#endif
};
#define ROOT_CNT (sizeof(RootTable) / sizeof(RootTable[0]))
// If found, returns pointer to the PubKeyInfo blob. Otherwise, returns NULL.
PCRYPT_DER_BLOB
WINAPI
I_MinCryptFindRootByName(
IN PCRYPT_DER_BLOB pIssuerNameValueBlob
)
{
DWORD i;
for (i = 0; i < ROOT_CNT; i++) {
if (pIssuerNameValueBlob->cbData == RootTable[i].EncodedName.cbData &&
0 == memcmp(pIssuerNameValueBlob->pbData,
RootTable[i].EncodedName.pbData,
pIssuerNameValueBlob->cbData))
return (PCRYPT_DER_BLOB) &RootTable[i].EncodedPubKeyInfo;
}
return NULL;
}
// If found, returns pointer to the PubKeyInfo blob. Otherwise, returns NULL.
PCRYPT_DER_BLOB
WINAPI
I_MinCryptFindRootByKey(
IN PCRYPT_DER_BLOB pSubjectPubKeyInfoBlob
)
{
DWORD i;
for (i = 0; i < ROOT_CNT; i++) {
if (pSubjectPubKeyInfoBlob->cbData ==
RootTable[i].EncodedPubKeyInfo.cbData
&&
0 == memcmp(pSubjectPubKeyInfoBlob->pbData,
RootTable[i].EncodedPubKeyInfo.pbData,
pSubjectPubKeyInfoBlob->cbData))
return (PCRYPT_DER_BLOB) &RootTable[i].EncodedPubKeyInfo;
}
return NULL;
}
// If found, returns pointer to rgCertBlob[MINASN1_CERT_BLOB_CNT].
// Otherwise, returns NULL.
PCRYPT_DER_BLOB
WINAPI
I_MinCryptFindIssuerCertificateByName(
IN PCRYPT_DER_BLOB pIssuerNameValueBlob,
IN DWORD cCert,
IN CRYPT_DER_BLOB rgrgCertBlob[][MINASN1_CERT_BLOB_CNT]
)
{
DWORD i;
DWORD cbName = pIssuerNameValueBlob->cbData;
const BYTE *pbName = pIssuerNameValueBlob->pbData;
if (0 == cbName)
return NULL;
for (i = 0; i < cCert; i++) {
if (cbName == rgrgCertBlob[i][MINASN1_CERT_SUBJECT_IDX].cbData &&
0 == memcmp(pbName,
rgrgCertBlob[i][MINASN1_CERT_SUBJECT_IDX].pbData,
cbName))
return rgrgCertBlob[i];
}
return NULL;
}
//+-------------------------------------------------------------------------
// Verifies a previously parsed X.509 Certificate.
//
// Assumes the ASN.1 encoded X.509 certificate was parsed via
// MinAsn1ParseCertificate() and the set of potential issuer certificates
// were parsed via one or more of:
// - MinAsn1ParseCertificate()
// - MinAsn1ParseSignedDataCertificates()
// - MinAsn1ExtractParsedCertificatesFromSignedData()
//
// Iteratively finds the issuer certificate via its encoded name. The
// public key in the issuer certificate is used to verify the subject
// certificate's signature. This is repeated until finding a self signed
// certificate or a baked in root identified by its encoded name.
// For a self signed certificate, compares against the baked in root
// public keys.
//
// If the certificate and its issuers were successfully verified to a
// baked in root, ERROR_SUCCESS is returned. Otherwise, a nonzero error
// code is returned.
//--------------------------------------------------------------------------
LONG
WINAPI
MinCryptVerifyCertificate(
IN CRYPT_DER_BLOB rgSubjectCertBlob[MINASN1_CERT_BLOB_CNT],
IN DWORD cIssuerCert,
IN CRYPT_DER_BLOB rgrgIssuerCertBlob[][MINASN1_CERT_BLOB_CNT]
)
{
LONG lErr;
DWORD dwChainDepth = 0;
PCRYPT_DER_BLOB rgSubject;
BOOL fRoot = FALSE;
rgSubject = rgSubjectCertBlob;
while (!fRoot) {
ALG_ID HashAlgId;
BYTE rgbHash[MINCRYPT_MAX_HASH_LEN];
DWORD cbHash;
PCRYPT_DER_BLOB rgIssuer = NULL;
PCRYPT_DER_BLOB pIssuerPubKeyInfo = NULL;
// Hash the Subject's ToBeSigned bytes
HashAlgId = MinCryptDecodeHashAlgorithmIdentifier(
&rgSubject[MINASN1_CERT_SIGN_ALGID_IDX]);
if (0 == HashAlgId)
goto UnknownHashAlgId;
lErr = MinCryptHashMemory(
HashAlgId,
1, // cBlob,
&rgSubject[MINASN1_CERT_TO_BE_SIGNED_IDX],
rgbHash,
&cbHash
);
if (ERROR_SUCCESS != lErr)
goto ErrorReturn;
// Get the public key to decrypt the signature
// Check if SelfSigned
if (rgSubject[MINASN1_CERT_ISSUER_IDX].cbData ==
rgSubject[MINASN1_CERT_SUBJECT_IDX].cbData
&&
0 == memcmp(rgSubject[MINASN1_CERT_ISSUER_IDX].pbData,
rgSubject[MINASN1_CERT_SUBJECT_IDX].pbData,
rgSubject[MINASN1_CERT_ISSUER_IDX].cbData)) {
pIssuerPubKeyInfo = I_MinCryptFindRootByKey(
&rgSubject[MINASN1_CERT_PUBKEY_INFO_IDX]);
if (NULL == pIssuerPubKeyInfo)
goto UntrustedRoot;
fRoot = TRUE;
} else {
// Check if the issuer is a root
pIssuerPubKeyInfo = I_MinCryptFindRootByName(
&rgSubject[MINASN1_CERT_ISSUER_IDX]);
if (pIssuerPubKeyInfo)
fRoot = TRUE;
else {
// Try to find the issuer from the input set of
// certificates
rgIssuer = I_MinCryptFindIssuerCertificateByName(
&rgSubject[MINASN1_CERT_ISSUER_IDX],
cIssuerCert,
rgrgIssuerCertBlob
);
if (NULL == rgIssuer)
goto PartialChain;
pIssuerPubKeyInfo = &rgIssuer[MINASN1_CERT_PUBKEY_INFO_IDX];
}
}
// Use the issuer or root's public key to decrypt and verify
// the signature.
lErr = MinCryptVerifySignedHash(
HashAlgId,
rgbHash,
cbHash,
&rgSubject[MINASN1_CERT_SIGNATURE_IDX],
pIssuerPubKeyInfo
);
if (ERROR_SUCCESS != lErr)
goto ErrorReturn;
if (!fRoot) {
assert(rgIssuer);
dwChainDepth++;
if (MAX_CHAIN_DEPTH < dwChainDepth)
goto CyclicChain;
rgSubject = rgIssuer;
}
}
lErr = ERROR_SUCCESS;
ErrorReturn:
CommonReturn:
return lErr;
UnknownHashAlgId:
lErr = CRYPT_E_UNKNOWN_ALGO;
goto CommonReturn;
UntrustedRoot:
lErr = CERT_E_UNTRUSTEDROOT;
goto CommonReturn;
CyclicChain:
PartialChain:
lErr = CERT_E_CHAINING;
goto CommonReturn;
}