Juan Lang : crypt32: Add tests for CertAddEncodedCTLToStore.

Alexandre Julliard julliard at winehq.org
Tue Sep 2 08:32:52 CDT 2008


Module: wine
Branch: master
Commit: 08f37c62be8f1940a0985451f9c575c937ef124c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=08f37c62be8f1940a0985451f9c575c937ef124c

Author: Juan Lang <juan.lang at gmail.com>
Date:   Fri Aug 29 07:58:43 2008 -0700

crypt32: Add tests for CertAddEncodedCTLToStore.

---

 dlls/crypt32/tests/ctl.c |  160 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 160 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/tests/ctl.c b/dlls/crypt32/tests/ctl.c
index cefca25..b6cccb2 100644
--- a/dlls/crypt32/tests/ctl.c
+++ b/dlls/crypt32/tests/ctl.c
@@ -247,8 +247,168 @@ static void testCTLProperties(void)
     CertFreeCTLContext(ctl);
 }
 
+static const BYTE signedCTLWithUsage[] = {
+0x30,0x82,0x01,0x0f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
+0xa0,0x82,0x01,0x00,0x30,0x81,0xfd,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,
+0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x30,0x06,0x09,
+0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0xa0,0x23,0x30,0x21,0x30,0x0a,
+0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x18,0x0f,0x31,0x36,0x30,
+0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x02,0x06,
+0x00,0x31,0x81,0xb5,0x30,0x81,0xb2,0x02,0x01,0x01,0x30,0x1a,0x30,0x15,0x31,
+0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,
+0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,
+0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0xa0,0x3b,0x30,0x18,0x06,0x09,0x2a,0x86,
+0x48,0x86,0xf7,0x0d,0x01,0x09,0x03,0x31,0x0b,0x06,0x09,0x2b,0x06,0x01,0x04,
+0x01,0x82,0x37,0x0a,0x01,0x30,0x1f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
+0x01,0x09,0x04,0x31,0x12,0x04,0x10,0xc4,0x3e,0x7e,0xc8,0xf9,0x85,0xf3,0x27,
+0x7d,0xc0,0x38,0xb2,0x7f,0xc7,0x76,0x85,0x30,0x04,0x06,0x00,0x05,0x00,0x04,
+0x40,0x90,0x33,0x1b,0xb4,0x88,0x35,0xe6,0xf7,0x7f,0x93,0x05,0xc9,0x1a,0x0e,
+0x8f,0x21,0xc0,0xaa,0xb3,0xab,0x3e,0x4a,0xa6,0x63,0x74,0xfd,0xef,0x11,0xbd,
+0x67,0x3a,0x1b,0x07,0x4b,0x88,0x59,0x31,0xd5,0x08,0xf9,0x09,0x2f,0x0b,0x85,
+0x62,0x5a,0x67,0x3b,0x62,0x7e,0x81,0x31,0xea,0xa4,0x36,0x5f,0x9a,0x92,0xb6,
+0x66,0xa5,0x00,0x60,0x96 };
+static const BYTE signedCTLWithListID1[] = {
+0x30,0x82,0x01,0x07,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
+0xa0,0x81,0xf9,0x30,0x81,0xf6,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,
+0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x29,0x06,0x09,0x2b,
+0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0xa0,0x1c,0x30,0x1a,0x30,0x00,0x04,
+0x01,0x01,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,
+0x30,0x30,0x30,0x5a,0x30,0x02,0x06,0x00,0x31,0x81,0xb5,0x30,0x81,0xb2,0x02,
+0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,
+0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,
+0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0xa0,
+0x3b,0x30,0x18,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x03,0x31,
+0x0b,0x06,0x09,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0x30,0x1f,0x06,
+0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x04,0x31,0x12,0x04,0x10,0xbc,
+0x13,0xde,0x17,0xc7,0x7c,0x67,0x5b,0xf9,0xa9,0x7c,0xb0,0xd9,0xf2,0x84,0xd5,
+0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
+static const BYTE signedCTLWithListID2[] = {
+0x30,0x82,0x01,0x07,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
+0xa0,0x81,0xf9,0x30,0x81,0xf6,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,
+0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x29,0x06,0x09,0x2b,
+0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0xa0,0x1c,0x30,0x1a,0x30,0x00,0x04,
+0x01,0x02,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,
+0x30,0x30,0x30,0x5a,0x30,0x02,0x06,0x00,0x31,0x81,0xb5,0x30,0x81,0xb2,0x02,
+0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,
+0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,
+0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0xa0,
+0x3b,0x30,0x18,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x03,0x31,
+0x0b,0x06,0x09,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0x30,0x1f,0x06,
+0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x04,0x31,0x12,0x04,0x10,0x60,
+0x6b,0x10,0xb6,0xb8,0x74,0xb8,0xf3,0x79,0xd5,0x42,0x15,0x4a,0x60,0x93,0x1f,
+0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
+
+static void testAddCTLToStore(void)
+{
+    HCERTSTORE store;
+    BOOL ret;
+    DWORD numCTLs;
+    PCCTL_CONTEXT ctl;
+
+    store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
+     CERT_STORE_CREATE_NEW_FLAG, NULL);
+    /* Add two CTLs */
+    ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
+     signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent),
+     CERT_STORE_ADD_ALWAYS, NULL);
+    ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
+    ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
+     signedCTLWithCTLInnerContentAndBadSig,
+     sizeof(signedCTLWithCTLInnerContentAndBadSig), CERT_STORE_ADD_ALWAYS,
+     NULL);
+    ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
+    /* Check that two exist */
+    numCTLs = 0;
+    ctl = NULL;
+    do {
+        ctl = CertEnumCTLsInStore(store, ctl);
+        if (ctl)
+            numCTLs++;
+    } while (ctl);
+    todo_wine
+    ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
+    CertCloseStore(store, 0);
+
+    store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
+     CERT_STORE_CREATE_NEW_FLAG, NULL);
+    /* Add the two CTLs again.  They're identical except for the signature.. */
+    ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
+     signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent),
+     CERT_STORE_ADD_NEW, NULL);
+    ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
+    /* so adding the second CTL fails. */
+    SetLastError(0xdeadbeef);
+    ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
+     signedCTLWithCTLInnerContentAndBadSig,
+     sizeof(signedCTLWithCTLInnerContentAndBadSig), CERT_STORE_ADD_NEW,
+     NULL);
+    todo_wine
+    ok(!ret && GetLastError() == CRYPT_E_EXISTS,
+     "expected CRYPT_E_EXISTS, got %08x\n", GetLastError());
+    CertCloseStore(store, 0);
+
+    store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
+     CERT_STORE_CREATE_NEW_FLAG, NULL);
+    /* Add two CTLs.  These two have different usages, so they're considered
+     * different.
+     */
+    ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
+     signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent),
+     CERT_STORE_ADD_NEW, NULL);
+    ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
+    ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
+     signedCTLWithUsage, sizeof(signedCTLWithUsage), CERT_STORE_ADD_NEW,
+     NULL);
+    ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
+    /* Check that two exist */
+    numCTLs = 0;
+    ctl = NULL;
+    do {
+        ctl = CertEnumCTLsInStore(store, ctl);
+        if (ctl)
+            numCTLs++;
+    } while (ctl);
+    todo_wine
+    ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
+    CertCloseStore(store, 0);
+
+    store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
+     CERT_STORE_CREATE_NEW_FLAG, NULL);
+    /* Add two CTLs.  Now they have the same (empty) usages and different list
+     * IDs, so they're different.
+     */
+    ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
+     signedCTLWithListID1, sizeof(signedCTLWithListID1), CERT_STORE_ADD_NEW,
+     NULL);
+    ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
+    ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
+     signedCTLWithListID2, sizeof(signedCTLWithListID2), CERT_STORE_ADD_NEW,
+     NULL);
+    ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
+    /* Check that two exist */
+    numCTLs = 0;
+    ctl = NULL;
+    do {
+        ctl = CertEnumCTLsInStore(store, ctl);
+        if (ctl)
+            numCTLs++;
+    } while (ctl);
+    todo_wine
+    ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
+    CertCloseStore(store, 0);
+}
+
 START_TEST(ctl)
 {
     testCreateCTL();
     testCTLProperties();
+    testAddCTLToStore();
 }




More information about the wine-cvs mailing list