[21311] | 1 | /*
|
---|
| 2 | * crypt32 CTL functions tests
|
---|
| 3 | *
|
---|
| 4 | * Copyright 2008 Juan Lang
|
---|
| 5 | *
|
---|
| 6 | * This library is free software; you can redistribute it and/or
|
---|
| 7 | * modify it under the terms of the GNU Lesser General Public
|
---|
| 8 | * License as published by the Free Software Foundation; either
|
---|
| 9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
| 10 | *
|
---|
| 11 | * This library is distributed in the hope that it will be useful,
|
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 14 | * Lesser General Public License for more details.
|
---|
| 15 | *
|
---|
| 16 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 17 | * License along with this library; if not, write to the Free Software
|
---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | #include <assert.h>
|
---|
| 22 | #include <stdio.h>
|
---|
| 23 | #include <stdarg.h>
|
---|
| 24 | #include <windef.h>
|
---|
| 25 | #include <winbase.h>
|
---|
| 26 | #include <winerror.h>
|
---|
| 27 | #include <wincrypt.h>
|
---|
| 28 |
|
---|
| 29 | #include "wine/test.h"
|
---|
| 30 |
|
---|
| 31 | static const BYTE emptyCTL[] = {
|
---|
| 32 | 0x30,0x17,0x30,0x00,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,
|
---|
| 33 | 0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x02,0x06,0x00 };
|
---|
| 34 | static const BYTE ctlWithOneEntry[] = {
|
---|
| 35 | 0x30,0x2a,0x30,0x00,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,
|
---|
| 36 | 0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x02,0x06,0x00,0x30,0x11,0x30,0x0f,0x04,
|
---|
| 37 | 0x01,0x01,0x31,0x0a,0x30,0x08,0x06,0x02,0x2a,0x03,0x31,0x02,0x30,0x00 };
|
---|
| 38 | static const BYTE signedCTL[] = {
|
---|
| 39 | 0x30,0x81,0xc7,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0,
|
---|
| 40 | 0x81,0xb9,0x30,0x81,0xb6,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a,
|
---|
| 41 | 0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x28,0x06,0x09,0x2a,0x86,
|
---|
| 42 | 0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x1b,0x04,0x19,0x30,0x17,0x30,0x00,
|
---|
| 43 | 0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
|
---|
| 44 | 0x30,0x5a,0x30,0x02,0x06,0x00,0x31,0x77,0x30,0x75,0x02,0x01,0x01,0x30,0x1a,
|
---|
| 45 | 0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,
|
---|
| 46 | 0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,
|
---|
| 47 | 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x04,0x06,0x00,0x05,
|
---|
| 48 | 0x00,0x04,0x40,0xca,0xd8,0x32,0xd1,0xbd,0x97,0x61,0x54,0xd6,0x80,0xcf,0x0d,
|
---|
| 49 | 0xbd,0xa2,0x42,0xc7,0xca,0x37,0x91,0x7d,0x9d,0xac,0x8c,0xdf,0x05,0x8a,0x39,
|
---|
| 50 | 0xc6,0x07,0xc1,0x37,0xe6,0xb9,0xd1,0x0d,0x26,0xec,0xa5,0xb0,0x8a,0x51,0x26,
|
---|
| 51 | 0x2b,0x4f,0x73,0x44,0x86,0x83,0x5e,0x2b,0x6e,0xcc,0xf8,0x1b,0x85,0x53,0xe9,
|
---|
| 52 | 0x7a,0x80,0x8f,0x6b,0x42,0x19,0x93 };
|
---|
| 53 | static const BYTE signedCTLWithSubjectAlgorithm[] = {
|
---|
| 54 | 0x30,0x81,0xd1,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0,
|
---|
| 55 | 0x81,0xc3,0x30,0x81,0xc0,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a,
|
---|
| 56 | 0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x32,0x06,0x09,0x2a,0x86,
|
---|
| 57 | 0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x25,0x04,0x23,0x30,0x21,0x30,0x00,
|
---|
| 58 | 0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
|
---|
| 59 | 0x30,0x5a,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,
|
---|
| 60 | 0x00,0x31,0x77,0x30,0x75,0x02,0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,
|
---|
| 61 | 0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,
|
---|
| 62 | 0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,
|
---|
| 63 | 0x0d,0x02,0x05,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x40,0xca,0x7a,
|
---|
| 64 | 0xfa,0xbf,0x44,0x36,0xfd,0xb2,0x84,0x70,0x0f,0xf5,0x66,0xcb,0x68,0xdb,0x45,
|
---|
| 65 | 0x74,0xa1,0xed,0xe3,0x30,0x4a,0x11,0xd2,0x7b,0xf5,0xa9,0x68,0x8d,0x36,0xe8,
|
---|
| 66 | 0x79,0xff,0xa2,0xf2,0x4c,0x8a,0xa9,0x65,0x03,0xf8,0x77,0xa5,0x01,0xd3,0x46,
|
---|
| 67 | 0x8a,0xcc,0x93,0x36,0x30,0xe1,0xa4,0x47,0x70,0x3d,0xb3,0x97,0xfc,0x6d,0x24,
|
---|
| 68 | 0xe9,0xf9 };
|
---|
| 69 | static const BYTE signedCTLWithCTLInnerContent[] = {
|
---|
| 70 | 0x30,0x82,0x01,0x0f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
|
---|
| 71 | 0xa0,0x82,0x01,0x00,0x30,0x81,0xfd,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,
|
---|
| 72 | 0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x30,0x06,0x09,
|
---|
| 73 | 0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0xa0,0x23,0x30,0x21,0x30,0x00,
|
---|
| 74 | 0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
|
---|
| 75 | 0x30,0x5a,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,
|
---|
| 76 | 0x00,0x31,0x81,0xb5,0x30,0x81,0xb2,0x02,0x01,0x01,0x30,0x1a,0x30,0x15,0x31,
|
---|
| 77 | 0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,
|
---|
| 78 | 0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,
|
---|
| 79 | 0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0xa0,0x3b,0x30,0x18,0x06,0x09,0x2a,0x86,
|
---|
| 80 | 0x48,0x86,0xf7,0x0d,0x01,0x09,0x03,0x31,0x0b,0x06,0x09,0x2b,0x06,0x01,0x04,
|
---|
| 81 | 0x01,0x82,0x37,0x0a,0x01,0x30,0x1f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
|
---|
| 82 | 0x01,0x09,0x04,0x31,0x12,0x04,0x10,0x54,0x71,0xbc,0xe1,0x56,0x31,0xa2,0xf9,
|
---|
| 83 | 0x65,0x70,0x34,0xf8,0xe2,0xe9,0xb4,0xf4,0x30,0x04,0x06,0x00,0x05,0x00,0x04,
|
---|
| 84 | 0x40,0x2f,0x1b,0x9f,0x5a,0x4a,0x15,0x73,0xfa,0xb1,0x93,0x3d,0x09,0x52,0xdf,
|
---|
| 85 | 0x6b,0x98,0x4b,0x13,0x5e,0xe7,0xbf,0x65,0xf4,0x9c,0xc2,0xb1,0x77,0x09,0xb1,
|
---|
| 86 | 0x66,0x4d,0x72,0x0d,0xb1,0x1a,0x50,0x20,0xe0,0x57,0xa2,0x39,0xc7,0xcd,0x7f,
|
---|
| 87 | 0x8e,0xe7,0x5f,0x76,0x2b,0xd1,0x6a,0x82,0xb3,0x30,0x25,0x61,0xf6,0x25,0x23,
|
---|
| 88 | 0x57,0x6c,0x0b,0x47,0xb8 };
|
---|
| 89 | static const BYTE signedCTLWithCTLInnerContentAndBadSig[] = {
|
---|
| 90 | 0x30,0x82,0x01,0x0f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
|
---|
| 91 | 0xa0,0x82,0x01,0x00,0x30,0x81,0xfd,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,
|
---|
| 92 | 0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x30,0x06,0x09,
|
---|
| 93 | 0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0xa0,0x23,0x30,0x21,0x30,0x00,
|
---|
| 94 | 0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
|
---|
| 95 | 0x30,0x5a,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,
|
---|
| 96 | 0x00,0x31,0x81,0xb5,0x30,0x81,0xb2,0x02,0x01,0x01,0x30,0x1a,0x30,0x15,0x31,
|
---|
| 97 | 0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,
|
---|
| 98 | 0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,
|
---|
| 99 | 0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0xa0,0x3b,0x30,0x18,0x06,0x09,0x2a,0x86,
|
---|
| 100 | 0x48,0x86,0xf7,0x0d,0x01,0x09,0x03,0x31,0x0b,0x06,0x09,0x2b,0x06,0x01,0x04,
|
---|
| 101 | 0x01,0x82,0x37,0x0a,0x01,0x30,0x1f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
|
---|
| 102 | 0x01,0x09,0x04,0x31,0x12,0x04,0x10,0x54,0x71,0xbc,0xe1,0x56,0x31,0xa2,0xf9,
|
---|
| 103 | 0x65,0x70,0x34,0xf8,0xe2,0xe9,0xb4,0xf4,0x30,0x04,0x06,0x00,0x05,0x00,0x04,
|
---|
| 104 | 0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 105 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 106 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 107 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 108 | 0xff,0xff,0xff,0xff,0xff };
|
---|
| 109 |
|
---|
| 110 | static void testCreateCTL(void)
|
---|
| 111 | {
|
---|
| 112 | PCCTL_CONTEXT ctl;
|
---|
| 113 |
|
---|
| 114 | SetLastError(0xdeadbeef);
|
---|
| 115 | ctl = CertCreateCTLContext(0, NULL, 0);
|
---|
| 116 | ok(!ctl && GetLastError() == E_INVALIDARG,
|
---|
| 117 | "expected E_INVALIDARG, got %08x\n", GetLastError());
|
---|
| 118 | SetLastError(0xdeadbeef);
|
---|
| 119 | ctl = CertCreateCTLContext(X509_ASN_ENCODING, NULL, 0);
|
---|
| 120 | ok(!ctl &&
|
---|
| 121 | (GetLastError() == ERROR_INVALID_DATA ||
|
---|
| 122 | GetLastError() == OSS_MORE_INPUT), /* win9x */
|
---|
| 123 | "expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
---|
| 124 | GetLastError());
|
---|
| 125 | /* An empty CTL can't be created.. */
|
---|
| 126 | SetLastError(0xdeadbeef);
|
---|
| 127 | ctl = CertCreateCTLContext(X509_ASN_ENCODING, emptyCTL, sizeof(emptyCTL));
|
---|
| 128 | ok(!ctl &&
|
---|
| 129 | (GetLastError() == ERROR_INVALID_DATA ||
|
---|
| 130 | GetLastError() == OSS_DATA_ERROR), /* win9x */
|
---|
| 131 | "expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
---|
| 132 | GetLastError());
|
---|
| 133 | /* Nor can any of these "signed" CTLs whose inner content OID isn't
|
---|
| 134 | * szOID_CTL.
|
---|
| 135 | */
|
---|
| 136 | SetLastError(0xdeadbeef);
|
---|
| 137 | ctl = CertCreateCTLContext(X509_ASN_ENCODING, signedCTL, sizeof(signedCTL));
|
---|
| 138 | ok(!ctl &&
|
---|
| 139 | (GetLastError() == ERROR_INVALID_DATA ||
|
---|
| 140 | GetLastError() == CRYPT_E_UNEXPECTED_MSG_TYPE), /* win9x */
|
---|
| 141 | "expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
---|
| 142 | GetLastError());
|
---|
| 143 | SetLastError(0xdeadbeef);
|
---|
| 144 | ctl = CertCreateCTLContext(X509_ASN_ENCODING, ctlWithOneEntry,
|
---|
| 145 | sizeof(ctlWithOneEntry));
|
---|
| 146 | ok(!ctl &&
|
---|
| 147 | (GetLastError() == ERROR_INVALID_DATA ||
|
---|
| 148 | GetLastError() == OSS_DATA_ERROR), /* win9x */
|
---|
| 149 | "expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
---|
| 150 | GetLastError());
|
---|
| 151 | SetLastError(0xdeadbeef);
|
---|
| 152 | ctl = CertCreateCTLContext(X509_ASN_ENCODING,
|
---|
| 153 | signedCTLWithSubjectAlgorithm, sizeof(signedCTLWithSubjectAlgorithm));
|
---|
| 154 | ok(!ctl &&
|
---|
| 155 | (GetLastError() == ERROR_INVALID_DATA ||
|
---|
| 156 | GetLastError() == CRYPT_E_UNEXPECTED_MSG_TYPE), /* win9x */
|
---|
| 157 | "expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
---|
| 158 | GetLastError());
|
---|
| 159 | /* This signed CTL with the appropriate inner content type can be decoded.
|
---|
| 160 | */
|
---|
| 161 | ctl = CertCreateCTLContext(X509_ASN_ENCODING,
|
---|
| 162 | signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent));
|
---|
| 163 | ok(ctl != NULL, "CertCreateCTLContext failed: %08x\n", GetLastError());
|
---|
| 164 | if (ctl)
|
---|
| 165 | {
|
---|
| 166 | /* Even though the CTL was decoded with X509_ASN_ENCODING, the
|
---|
| 167 | * message encoding type is included in the CTL's encoding type.
|
---|
| 168 | */
|
---|
| 169 | ok(ctl->dwMsgAndCertEncodingType ==
|
---|
| 170 | (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING),
|
---|
| 171 | "expected X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, got %08x\n",
|
---|
| 172 | ctl->dwMsgAndCertEncodingType);
|
---|
| 173 | CertFreeCTLContext(ctl);
|
---|
| 174 | }
|
---|
| 175 | /* This CTL with a bad signature can also be decoded, so the sig isn't
|
---|
| 176 | * checked when loading the CTL.
|
---|
| 177 | */
|
---|
| 178 | ctl = CertCreateCTLContext(X509_ASN_ENCODING,
|
---|
| 179 | signedCTLWithCTLInnerContentAndBadSig,
|
---|
| 180 | sizeof(signedCTLWithCTLInnerContentAndBadSig));
|
---|
| 181 | ok(ctl != NULL, "CertCreateCTLContext failed: %08x\n", GetLastError());
|
---|
| 182 | if (ctl)
|
---|
| 183 | CertFreeCTLContext(ctl);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | static void checkHash(const BYTE *data, DWORD dataLen, ALG_ID algID,
|
---|
| 187 | PCCTL_CONTEXT context, DWORD propID)
|
---|
| 188 | {
|
---|
| 189 | BYTE hash[20] = { 0 }, hashProperty[20];
|
---|
| 190 | BOOL ret;
|
---|
| 191 | DWORD size;
|
---|
| 192 |
|
---|
| 193 | memset(hash, 0, sizeof(hash));
|
---|
| 194 | memset(hashProperty, 0, sizeof(hashProperty));
|
---|
| 195 | size = sizeof(hash);
|
---|
| 196 | ret = CryptHashCertificate(0, algID, 0, data, dataLen, hash, &size);
|
---|
| 197 | ret = CertGetCTLContextProperty(context, propID, hashProperty, &size);
|
---|
| 198 | ok(ret, "CertGetCTLContextProperty failed: %08x\n", GetLastError());
|
---|
| 199 | if (ret)
|
---|
| 200 | ok(!memcmp(hash, hashProperty, size),
|
---|
| 201 | "Unexpected hash for property %d\n", propID);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | static void testCTLProperties(void)
|
---|
| 205 | {
|
---|
| 206 | PCCTL_CONTEXT ctl;
|
---|
| 207 | BOOL ret;
|
---|
| 208 | DWORD propID, numProps, access, size;
|
---|
| 209 |
|
---|
| 210 | ctl = CertCreateCTLContext(X509_ASN_ENCODING,
|
---|
| 211 | signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent));
|
---|
| 212 | if (!ctl)
|
---|
| 213 | {
|
---|
| 214 | skip("CertCreateCTLContext failed: %08x\n", GetLastError());
|
---|
| 215 | return;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | /* No properties as yet */
|
---|
| 219 | propID = 0;
|
---|
| 220 | numProps = 0;
|
---|
| 221 | do {
|
---|
| 222 | propID = CertEnumCTLContextProperties(ctl, propID);
|
---|
| 223 | if (propID)
|
---|
| 224 | numProps++;
|
---|
| 225 | } while (propID != 0);
|
---|
| 226 | ok(numProps == 0, "Expected 0 properties, got %d\n", numProps);
|
---|
| 227 |
|
---|
| 228 | /* An implicit property */
|
---|
| 229 | ret = CertGetCTLContextProperty(ctl, CERT_ACCESS_STATE_PROP_ID, NULL,
|
---|
| 230 | &size);
|
---|
| 231 | ok(ret, "CertGetCTLContextProperty failed: %08x\n", GetLastError());
|
---|
| 232 | ret = CertGetCTLContextProperty(ctl, CERT_ACCESS_STATE_PROP_ID, &access,
|
---|
| 233 | &size);
|
---|
| 234 | ok(ret, "CertGetCTLContextProperty failed: %08x\n", GetLastError());
|
---|
| 235 | ok(!(access & CERT_ACCESS_STATE_WRITE_PERSIST_FLAG),
|
---|
| 236 | "Didn't expect a persisted cert\n");
|
---|
| 237 |
|
---|
| 238 | checkHash(signedCTLWithCTLInnerContent,
|
---|
| 239 | sizeof(signedCTLWithCTLInnerContent), CALG_SHA1, ctl, CERT_HASH_PROP_ID);
|
---|
| 240 |
|
---|
| 241 | /* Now that the hash property is set, we should get one property when
|
---|
| 242 | * enumerating.
|
---|
| 243 | */
|
---|
| 244 | propID = 0;
|
---|
| 245 | numProps = 0;
|
---|
| 246 | do {
|
---|
| 247 | propID = CertEnumCTLContextProperties(ctl, propID);
|
---|
| 248 | if (propID)
|
---|
| 249 | numProps++;
|
---|
| 250 | } while (propID != 0);
|
---|
| 251 | ok(numProps == 1, "Expected 1 properties, got %d\n", numProps);
|
---|
| 252 |
|
---|
| 253 | checkHash(signedCTLWithCTLInnerContent,
|
---|
| 254 | sizeof(signedCTLWithCTLInnerContent), CALG_MD5, ctl,
|
---|
| 255 | CERT_MD5_HASH_PROP_ID);
|
---|
| 256 |
|
---|
| 257 | CertFreeCTLContext(ctl);
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | static const BYTE signedCTLWithUsage[] = {
|
---|
| 261 | 0x30,0x82,0x01,0x0f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
|
---|
| 262 | 0xa0,0x82,0x01,0x00,0x30,0x81,0xfd,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,
|
---|
| 263 | 0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x30,0x06,0x09,
|
---|
| 264 | 0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0xa0,0x23,0x30,0x21,0x30,0x0a,
|
---|
| 265 | 0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x18,0x0f,0x31,0x36,0x30,
|
---|
| 266 | 0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x02,0x06,
|
---|
| 267 | 0x00,0x31,0x81,0xb5,0x30,0x81,0xb2,0x02,0x01,0x01,0x30,0x1a,0x30,0x15,0x31,
|
---|
| 268 | 0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,
|
---|
| 269 | 0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,
|
---|
| 270 | 0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0xa0,0x3b,0x30,0x18,0x06,0x09,0x2a,0x86,
|
---|
| 271 | 0x48,0x86,0xf7,0x0d,0x01,0x09,0x03,0x31,0x0b,0x06,0x09,0x2b,0x06,0x01,0x04,
|
---|
| 272 | 0x01,0x82,0x37,0x0a,0x01,0x30,0x1f,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
|
---|
| 273 | 0x01,0x09,0x04,0x31,0x12,0x04,0x10,0xc4,0x3e,0x7e,0xc8,0xf9,0x85,0xf3,0x27,
|
---|
| 274 | 0x7d,0xc0,0x38,0xb2,0x7f,0xc7,0x76,0x85,0x30,0x04,0x06,0x00,0x05,0x00,0x04,
|
---|
| 275 | 0x40,0x90,0x33,0x1b,0xb4,0x88,0x35,0xe6,0xf7,0x7f,0x93,0x05,0xc9,0x1a,0x0e,
|
---|
| 276 | 0x8f,0x21,0xc0,0xaa,0xb3,0xab,0x3e,0x4a,0xa6,0x63,0x74,0xfd,0xef,0x11,0xbd,
|
---|
| 277 | 0x67,0x3a,0x1b,0x07,0x4b,0x88,0x59,0x31,0xd5,0x08,0xf9,0x09,0x2f,0x0b,0x85,
|
---|
| 278 | 0x62,0x5a,0x67,0x3b,0x62,0x7e,0x81,0x31,0xea,0xa4,0x36,0x5f,0x9a,0x92,0xb6,
|
---|
| 279 | 0x66,0xa5,0x00,0x60,0x96 };
|
---|
| 280 | static const BYTE signedCTLWithListID1[] = {
|
---|
| 281 | 0x30,0x82,0x01,0x07,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
|
---|
| 282 | 0xa0,0x81,0xf9,0x30,0x81,0xf6,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,
|
---|
| 283 | 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x29,0x06,0x09,0x2b,
|
---|
| 284 | 0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0xa0,0x1c,0x30,0x1a,0x30,0x00,0x04,
|
---|
| 285 | 0x01,0x01,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,
|
---|
| 286 | 0x30,0x30,0x30,0x5a,0x30,0x02,0x06,0x00,0x31,0x81,0xb5,0x30,0x81,0xb2,0x02,
|
---|
| 287 | 0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,
|
---|
| 288 | 0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,
|
---|
| 289 | 0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0xa0,
|
---|
| 290 | 0x3b,0x30,0x18,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x03,0x31,
|
---|
| 291 | 0x0b,0x06,0x09,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0x30,0x1f,0x06,
|
---|
| 292 | 0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x04,0x31,0x12,0x04,0x10,0xbc,
|
---|
| 293 | 0x13,0xde,0x17,0xc7,0x7c,0x67,0x5b,0xf9,0xa9,0x7c,0xb0,0xd9,0xf2,0x84,0xd5,
|
---|
| 294 | 0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 295 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 296 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 297 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 298 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
|
---|
| 299 | static const BYTE signedCTLWithListID2[] = {
|
---|
| 300 | 0x30,0x82,0x01,0x07,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
|
---|
| 301 | 0xa0,0x81,0xf9,0x30,0x81,0xf6,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,
|
---|
| 302 | 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x29,0x06,0x09,0x2b,
|
---|
| 303 | 0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0xa0,0x1c,0x30,0x1a,0x30,0x00,0x04,
|
---|
| 304 | 0x01,0x02,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,
|
---|
| 305 | 0x30,0x30,0x30,0x5a,0x30,0x02,0x06,0x00,0x31,0x81,0xb5,0x30,0x81,0xb2,0x02,
|
---|
| 306 | 0x01,0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,
|
---|
| 307 | 0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,
|
---|
| 308 | 0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0xa0,
|
---|
| 309 | 0x3b,0x30,0x18,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x03,0x31,
|
---|
| 310 | 0x0b,0x06,0x09,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x0a,0x01,0x30,0x1f,0x06,
|
---|
| 311 | 0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x04,0x31,0x12,0x04,0x10,0x60,
|
---|
| 312 | 0x6b,0x10,0xb6,0xb8,0x74,0xb8,0xf3,0x79,0xd5,0x42,0x15,0x4a,0x60,0x93,0x1f,
|
---|
| 313 | 0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x40,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 314 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 315 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 316 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
---|
| 317 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
|
---|
| 318 |
|
---|
| 319 | static void testAddCTLToStore(void)
|
---|
| 320 | {
|
---|
| 321 | HCERTSTORE store;
|
---|
| 322 | BOOL ret;
|
---|
| 323 | DWORD numCTLs;
|
---|
| 324 | PCCTL_CONTEXT ctl;
|
---|
| 325 |
|
---|
| 326 | store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
---|
| 327 | CERT_STORE_CREATE_NEW_FLAG, NULL);
|
---|
| 328 | /* Add two CTLs */
|
---|
| 329 | ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
|
---|
| 330 | signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent),
|
---|
| 331 | CERT_STORE_ADD_ALWAYS, NULL);
|
---|
| 332 | ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
|
---|
| 333 | ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
|
---|
| 334 | signedCTLWithCTLInnerContentAndBadSig,
|
---|
| 335 | sizeof(signedCTLWithCTLInnerContentAndBadSig), CERT_STORE_ADD_ALWAYS,
|
---|
| 336 | NULL);
|
---|
| 337 | ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
|
---|
| 338 | /* Check that two exist */
|
---|
| 339 | numCTLs = 0;
|
---|
| 340 | ctl = NULL;
|
---|
| 341 | do {
|
---|
| 342 | ctl = CertEnumCTLsInStore(store, ctl);
|
---|
| 343 | if (ctl)
|
---|
| 344 | numCTLs++;
|
---|
| 345 | } while (ctl);
|
---|
| 346 | ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
|
---|
| 347 | CertCloseStore(store, 0);
|
---|
| 348 |
|
---|
| 349 | store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
---|
| 350 | CERT_STORE_CREATE_NEW_FLAG, NULL);
|
---|
| 351 | /* Add the two CTLs again. They're identical except for the signature.. */
|
---|
| 352 | ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
|
---|
| 353 | signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent),
|
---|
| 354 | CERT_STORE_ADD_NEW, NULL);
|
---|
| 355 | ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
|
---|
| 356 | /* so adding the second CTL fails. */
|
---|
| 357 | SetLastError(0xdeadbeef);
|
---|
| 358 | ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
|
---|
| 359 | signedCTLWithCTLInnerContentAndBadSig,
|
---|
| 360 | sizeof(signedCTLWithCTLInnerContentAndBadSig), CERT_STORE_ADD_NEW,
|
---|
| 361 | NULL);
|
---|
| 362 | if (ret)
|
---|
| 363 | {
|
---|
| 364 | /* win9x */
|
---|
| 365 | ok(GetLastError() == CRYPT_E_NOT_FOUND,
|
---|
| 366 | "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
|
---|
| 367 | }
|
---|
| 368 | else
|
---|
| 369 | {
|
---|
| 370 | ok(!ret && GetLastError() == CRYPT_E_EXISTS,
|
---|
| 371 | "expected CRYPT_E_EXISTS, got %d %08x\n", ret, GetLastError());
|
---|
| 372 | }
|
---|
| 373 | CertCloseStore(store, 0);
|
---|
| 374 |
|
---|
| 375 | store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
---|
| 376 | CERT_STORE_CREATE_NEW_FLAG, NULL);
|
---|
| 377 | /* Add two CTLs. These two have different usages, so they're considered
|
---|
| 378 | * different.
|
---|
| 379 | */
|
---|
| 380 | ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
|
---|
| 381 | signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent),
|
---|
| 382 | CERT_STORE_ADD_NEW, NULL);
|
---|
| 383 | ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
|
---|
| 384 | ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
|
---|
| 385 | signedCTLWithUsage, sizeof(signedCTLWithUsage), CERT_STORE_ADD_NEW,
|
---|
| 386 | NULL);
|
---|
| 387 | ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
|
---|
| 388 | /* Check that two exist */
|
---|
| 389 | numCTLs = 0;
|
---|
| 390 | ctl = NULL;
|
---|
| 391 | do {
|
---|
| 392 | ctl = CertEnumCTLsInStore(store, ctl);
|
---|
| 393 | if (ctl)
|
---|
| 394 | numCTLs++;
|
---|
| 395 | } while (ctl);
|
---|
| 396 | ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
|
---|
| 397 | CertCloseStore(store, 0);
|
---|
| 398 |
|
---|
| 399 | store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
---|
| 400 | CERT_STORE_CREATE_NEW_FLAG, NULL);
|
---|
| 401 | /* Add two CTLs. Now they have the same (empty) usages and different list
|
---|
| 402 | * IDs, so they're different.
|
---|
| 403 | */
|
---|
| 404 | ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
|
---|
| 405 | signedCTLWithListID1, sizeof(signedCTLWithListID1), CERT_STORE_ADD_NEW,
|
---|
| 406 | NULL);
|
---|
| 407 | ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
|
---|
| 408 | ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING,
|
---|
| 409 | signedCTLWithListID2, sizeof(signedCTLWithListID2), CERT_STORE_ADD_NEW,
|
---|
| 410 | NULL);
|
---|
| 411 | ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError());
|
---|
| 412 | /* Check that two exist */
|
---|
| 413 | numCTLs = 0;
|
---|
| 414 | ctl = NULL;
|
---|
| 415 | do {
|
---|
| 416 | ctl = CertEnumCTLsInStore(store, ctl);
|
---|
| 417 | if (ctl)
|
---|
| 418 | numCTLs++;
|
---|
| 419 | } while (ctl);
|
---|
| 420 | ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs);
|
---|
| 421 | CertCloseStore(store, 0);
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | START_TEST(ctl)
|
---|
| 425 | {
|
---|
| 426 | testCreateCTL();
|
---|
| 427 | testCTLProperties();
|
---|
| 428 | testAddCTLToStore();
|
---|
| 429 | }
|
---|