From 6aa03fc4c314671234975aecdb1afa81233d7427 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Thu, 6 Sep 2007 09:56:37 -0700 Subject: [PATCH] crypt32: Add more tests for getting issuer cert from store. Show that certificates are added to memory stores at the head rather than the tail. --- dlls/crypt32/context.c | 2 +- dlls/crypt32/tests/cert.c | 174 +++++++++++++++++++++++++++++++++++++- 2 files changed, 174 insertions(+), 2 deletions(-) diff --git a/dlls/crypt32/context.c b/dlls/crypt32/context.c index 977ea1d919e..50fec4d51d5 100644 --- a/dlls/crypt32/context.c +++ b/dlls/crypt32/context.c @@ -244,7 +244,7 @@ void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace) list->contextInterface->free(toReplace); } else - list_add_tail(&list->contexts, entry); + list_add_head(&list->contexts, entry); LeaveCriticalSection(&list->cs); } return context; diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c index 89b51e7cdbf..d0cac68b46d 100644 --- a/dlls/crypt32/tests/cert.c +++ b/dlls/crypt32/tests/cert.c @@ -1220,11 +1220,103 @@ static const BYTE childOfExpired[] = { 0x30, 0x81, 0xcc, 0x30, 0x78, 0xa0, 0x5f, 0x69, 0xfb, 0xbc, 0x5b, 0xf2, 0xa6, 0x2a, 0xbe, 0x91, 0x2c, 0xfc, 0x89, 0x69, 0x15, 0x18, 0x58, 0xe5, 0x02, 0x75, 0xf7, 0x2a, 0xb6, 0xa9, 0xfb, 0x47, 0x6a, 0x6e, 0x0a, 0x9b, 0xe9, 0xdc }; +/* chain10_0 -+ + * +-> chain7_1 + * chain10_1 -+ + * A chain with two issuers, only one of whose dates is valid. + */ +static const BYTE chain10_0[] = { +0x30,0x82,0x01,0x9b,0x30,0x82,0x01,0x08,0xa0,0x03,0x02,0x01,0x02,0x02,0x10, +0x4a,0x30,0x3a,0x42,0xa2,0x5a,0xb3,0x93,0x4d,0x94,0x06,0xad,0x6d,0x1c,0x34, +0xe6,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x30,0x10,0x31, +0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31, +0x30,0x1e,0x17,0x0d,0x30,0x36,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30, +0x30,0x5a,0x17,0x0d,0x30,0x36,0x31,0x32,0x33,0x31,0x32,0x33,0x35,0x39,0x35, +0x39,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05, +0x43,0x65,0x72,0x74,0x31,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,0xad,0x7e,0xca,0xf3,0xe5,0x99,0xc2,0x2a,0xca,0x50,0x82, +0x7c,0x2d,0xa4,0x81,0xcd,0x0d,0x0d,0x86,0xd7,0xd8,0xb2,0xde,0xc5,0xc3,0x34, +0x9e,0x07,0x78,0x08,0x11,0x12,0x2d,0x21,0x0a,0x09,0x07,0x14,0x03,0x7a,0xe7, +0x3b,0x58,0xf1,0xde,0x3e,0x01,0x25,0x93,0xab,0x8f,0xce,0x1f,0xc1,0x33,0x91, +0xfe,0x59,0xb9,0x3b,0x9e,0x95,0x12,0x89,0x8e,0xc3,0x4b,0x98,0x1b,0x99,0xc5, +0x07,0xe2,0xdf,0x15,0x4c,0x39,0x76,0x06,0xad,0xdb,0x16,0x06,0x49,0xba,0xcd, +0x0f,0x07,0xd6,0xea,0x27,0xa6,0xfe,0x3d,0x88,0xe5,0x97,0x45,0x72,0xb6,0x1c, +0xc0,0x1c,0xb1,0xa2,0x89,0xe8,0x37,0x9e,0xf6,0x2a,0xcf,0xd5,0x1f,0x2f,0x35, +0x5e,0x8f,0x3a,0x9c,0x61,0xb1,0xf1,0x6c,0xff,0x8c,0xb2,0x2f,0x02,0x03,0x01, +0x00,0x01,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x03,0x81, +0x81,0x00,0x85,0x6e,0x35,0x2f,0x2c,0x51,0x4f,0xd6,0x2a,0xe4,0x9e,0xd0,0x4b, +0xe6,0x90,0xfd,0xf7,0x20,0xad,0x76,0x3f,0x93,0xea,0x7f,0x0d,0x1f,0xb3,0x8e, +0xfd,0xe0,0xe1,0xd6,0xd7,0x9c,0x7d,0x46,0x6b,0x15,0x5c,0xe6,0xc9,0x62,0x3b, +0x70,0x4a,0x4b,0xb2,0x82,0xe3,0x55,0x0c,0xc4,0x90,0x44,0x06,0x6c,0x86,0x1c, +0x6d,0x47,0x12,0xda,0x33,0x95,0x5d,0x98,0x43,0xcb,0x7c,0xfa,0x2b,0xee,0xc4, +0x2d,0xc8,0x95,0x33,0x89,0x08,0x3f,0x9f,0x87,0xea,0x20,0x04,0xaf,0x58,0x4b, +0x9d,0xc0,0x7c,0x0a,0x1b,0x05,0x31,0x3b,0xbb,0x13,0x58,0x2e,0x3f,0x61,0x6b, +0x10,0xb4,0xeb,0xb9,0x1a,0x30,0xfd,0xea,0xca,0x29,0x99,0x5f,0x42,0x2b,0x00, +0xb0,0x08,0xc3,0xf0,0xb6,0xd6,0x6b,0xf9,0x35,0x95 }; +static const BYTE chain10_1[] = { +0x30,0x82,0x01,0x9b,0x30,0x82,0x01,0x08,0xa0,0x03,0x02,0x01,0x02,0x02,0x10, +0xbf,0x99,0x4f,0x14,0x03,0x77,0x44,0xb8,0x49,0x02,0x70,0xa1,0xb8,0x9c,0xa7, +0x24,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x30,0x10,0x31, +0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31, +0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30, +0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x32,0x33,0x31,0x32,0x33,0x35,0x39,0x35, +0x39,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05, +0x43,0x65,0x72,0x74,0x31,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,0xad,0x7e,0xca,0xf3,0xe5,0x99,0xc2,0x2a,0xca,0x50,0x82, +0x7c,0x2d,0xa4,0x81,0xcd,0x0d,0x0d,0x86,0xd7,0xd8,0xb2,0xde,0xc5,0xc3,0x34, +0x9e,0x07,0x78,0x08,0x11,0x12,0x2d,0x21,0x0a,0x09,0x07,0x14,0x03,0x7a,0xe7, +0x3b,0x58,0xf1,0xde,0x3e,0x01,0x25,0x93,0xab,0x8f,0xce,0x1f,0xc1,0x33,0x91, +0xfe,0x59,0xb9,0x3b,0x9e,0x95,0x12,0x89,0x8e,0xc3,0x4b,0x98,0x1b,0x99,0xc5, +0x07,0xe2,0xdf,0x15,0x4c,0x39,0x76,0x06,0xad,0xdb,0x16,0x06,0x49,0xba,0xcd, +0x0f,0x07,0xd6,0xea,0x27,0xa6,0xfe,0x3d,0x88,0xe5,0x97,0x45,0x72,0xb6,0x1c, +0xc0,0x1c,0xb1,0xa2,0x89,0xe8,0x37,0x9e,0xf6,0x2a,0xcf,0xd5,0x1f,0x2f,0x35, +0x5e,0x8f,0x3a,0x9c,0x61,0xb1,0xf1,0x6c,0xff,0x8c,0xb2,0x2f,0x02,0x03,0x01, +0x00,0x01,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x03,0x81, +0x81,0x00,0xa8,0xec,0x8c,0x34,0xe7,0x2c,0xdf,0x75,0x87,0xc4,0xf7,0xda,0x71, +0x72,0x29,0xb2,0x48,0xa8,0x2a,0xec,0x7b,0x7d,0x19,0xb9,0x5f,0x1d,0xd9,0x91, +0x2b,0xc4,0x28,0x7e,0xd6,0xb5,0x91,0x69,0xa5,0x8a,0x1a,0x1f,0x97,0x98,0x46, +0x9d,0xdf,0x12,0xf6,0x45,0x62,0xad,0x60,0xb6,0xba,0xb0,0xfd,0xf5,0x9f,0xc6, +0x98,0x05,0x4f,0x4d,0x48,0xdc,0xee,0x69,0xbe,0xb8,0xc4,0xc4,0xd7,0x1b,0xb1, +0x1f,0x64,0xd6,0x45,0xa7,0xdb,0xb3,0x87,0x63,0x0f,0x54,0xe1,0x3a,0x6b,0x57, +0x36,0xd7,0x68,0x65,0xcf,0xda,0x57,0x8d,0xcd,0x84,0x75,0x47,0x26,0x2c,0xef, +0x1e,0x8f,0xc7,0x3b,0xee,0x5d,0x03,0xa6,0xdf,0x3a,0x20,0xb2,0xcc,0xc9,0x09, +0x2c,0xfe,0x2b,0x79,0xb0,0xca,0x2c,0x9a,0x81,0x6b }; +static const BYTE chain7_1[] = { +0x30,0x82,0x01,0x93,0x30,0x81,0xfd,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x01, +0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00, +0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65, +0x72,0x74,0x31,0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x31,0x30,0x31,0x30,0x30, +0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x32,0x33,0x31,0x32,0x33, +0x35,0x39,0x35,0x39,0x5a,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04, +0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x32,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,0xb8,0x52,0xda,0xc5,0x4b,0x3f,0xe5,0x33, +0x0e,0x67,0x5f,0x48,0x21,0xdc,0x7e,0xef,0x37,0x33,0xba,0xff,0xb4,0xc6,0xdc, +0xb6,0x17,0x8e,0x20,0x55,0x07,0x12,0xd2,0x7b,0x3c,0xce,0x30,0xc5,0xa7,0x48, +0x9f,0x6e,0xfe,0xb8,0xbe,0xdb,0x9f,0x9b,0x17,0x60,0x16,0xde,0xc6,0x8b,0x47, +0xd1,0x57,0x71,0x3c,0x93,0xfc,0xbd,0xec,0x44,0x32,0x3b,0xb9,0xcf,0x6b,0x05, +0x72,0xa7,0x87,0x8e,0x7e,0xd4,0x9a,0x87,0x1c,0x2f,0xb7,0x82,0x40,0xfc,0x6a, +0x80,0x83,0x68,0x28,0xce,0x84,0xf4,0x0b,0x2e,0x44,0xcb,0x53,0xac,0x85,0x85, +0xb5,0x46,0x36,0x98,0x3c,0x10,0x02,0xaa,0x02,0xbc,0x8b,0xa2,0x23,0xb2,0xd3, +0x51,0x9a,0x22,0x4a,0xe3,0xaa,0x4e,0x7c,0xda,0x38,0xcf,0x49,0x98,0x72,0xa3, +0x02,0x03,0x01,0x00,0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d, +0x01,0x01,0x05,0x05,0x00,0x03,0x81,0x81,0x00,0x9f,0x69,0xfd,0x26,0xd5,0x4b, +0xe0,0xab,0x12,0x21,0xb9,0xfc,0xf7,0xe0,0x0c,0x09,0x94,0xad,0x27,0xd7,0x9d, +0xa3,0xcc,0x46,0x2a,0x25,0x9a,0x24,0xa7,0x31,0x58,0x78,0xf5,0xfc,0x30,0xe1, +0x6d,0xfd,0x59,0xab,0xbe,0x69,0xa0,0xea,0xe3,0x7d,0x7a,0x7b,0xe5,0x85,0xeb, +0x86,0x6a,0x84,0x3c,0x96,0x01,0x1a,0x70,0xa7,0xb8,0xcb,0xf2,0x11,0xe7,0x52, +0x9c,0x58,0x2d,0xac,0x63,0xce,0x72,0x4b,0xad,0x62,0xa8,0x1d,0x75,0x96,0xe2, +0x27,0xf5,0x6f,0xba,0x91,0xf8,0xf1,0xb0,0xbf,0x90,0x24,0x6d,0xba,0x5d,0xd7, +0x39,0x63,0x3b,0x7c,0x04,0x5d,0x89,0x9d,0x1c,0xf2,0xf7,0xcc,0xdf,0x6e,0x8a, +0x43,0xa9,0xdd,0x86,0x05,0xa2,0xf3,0x22,0x2d,0x1e,0x70,0xa1,0x59,0xd7,0xa5, +0x94,0x7d }; static void testGetIssuerCert(void) { BOOL ret; - PCCERT_CONTEXT parent, child; + PCCERT_CONTEXT parent, child, cert1, cert2; DWORD flags = 0xffffffff; HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); @@ -1296,6 +1388,86 @@ static void testGetIssuerCert(void) CertFreeCertificateContext(child); CertCloseStore(store, 0); + + flags = 0; + store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, + CERT_STORE_CREATE_NEW_FLAG, NULL); + /* With only the child certificate, no issuer will be found */ + ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, + chain7_1, sizeof(chain7_1), CERT_STORE_ADD_ALWAYS, &child); + parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags); + ok(parent == NULL, "Expected no issuer\n"); + /* Adding an issuer allows one (and only one) issuer to be found */ + ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, + chain10_1, sizeof(chain10_1), CERT_STORE_ADD_ALWAYS, &cert1); + parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags); + ok(parent == cert1, "Expected cert1 to be the issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); + ok(parent == NULL, "Expected only one issuer\n"); + /* Adding a second issuer allows two issuers to be found - and the second + * issuer is found before the first, implying certs are added to the head + * of a list. + */ + ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, + chain10_0, sizeof(chain10_0), CERT_STORE_ADD_ALWAYS, &cert2); + parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags); + ok(parent == cert2, "Expected cert2 to be the first issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); + ok(parent == cert1, "Expected cert1 to be the second issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); + ok(parent == NULL, "Expected no more than two issuers\n"); + /* It's possible to start enumerating from any certificate in the store */ + parent = CertGetIssuerCertificateFromStore(store, child, cert1, &flags); + ok(parent == NULL, "Expected no issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, cert2, &flags); + ok(parent == cert1, "Expected cert1 to be the second issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); + ok(parent == NULL, "Expected no more than two issuers\n"); + CertFreeCertificateContext(child); + CertFreeCertificateContext(cert1); + CertFreeCertificateContext(cert2); + CertCloseStore(store, 0); + + /* Repeat the test, reversing the order in which issuers are added, + * to show it's order-dependent. + */ + store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, + CERT_STORE_CREATE_NEW_FLAG, NULL); + /* With only the child certificate, no issuer will be found */ + ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, + chain7_1, sizeof(chain7_1), CERT_STORE_ADD_ALWAYS, &child); + parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags); + ok(parent == NULL, "Expected no issuer\n"); + /* Adding an issuer allows one (and only one) issuer to be found */ + ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, + chain10_0, sizeof(chain10_0), CERT_STORE_ADD_ALWAYS, &cert1); + parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags); + ok(parent == cert1, "Expected cert1 to be the issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); + ok(parent == NULL, "Expected only one issuer\n"); + /* Adding a second issuer allows two issuers to be found - and the second + * issuer is found before the first, implying certs are added to the head + * of a list. + */ + ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, + chain10_1, sizeof(chain10_1), CERT_STORE_ADD_ALWAYS, &cert2); + parent = CertGetIssuerCertificateFromStore(store, child, NULL, &flags); + ok(parent == cert2, "Expected cert2 to be the first issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); + ok(parent == cert1, "Expected cert1 to be the second issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); + ok(parent == NULL, "Expected no more than two issuers\n"); + /* It's possible to start enumerating from any certificate in the store */ + parent = CertGetIssuerCertificateFromStore(store, child, cert1, &flags); + ok(parent == NULL, "Expected no issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, cert2, &flags); + ok(parent == cert1, "Expected cert1 to be the second issuer\n"); + parent = CertGetIssuerCertificateFromStore(store, child, parent, &flags); + ok(parent == NULL, "Expected no more than two issuers\n"); + CertFreeCertificateContext(child); + CertFreeCertificateContext(cert1); + CertFreeCertificateContext(cert2); + CertCloseStore(store, 0); } static void testCryptHashCert(void)