mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-31 11:43:31 +00:00
crypt32: Add tests for CertCreateCTLContext.
This commit is contained in:
parent
854d35e1a0
commit
e6bcb4581f
2 changed files with 188 additions and 0 deletions
|
@ -10,6 +10,7 @@ CTESTS = \
|
|||
cert.c \
|
||||
chain.c \
|
||||
crl.c \
|
||||
ctl.c \
|
||||
encode.c \
|
||||
main.c \
|
||||
message.c \
|
||||
|
|
187
dlls/crypt32/tests/ctl.c
Normal file
187
dlls/crypt32/tests/ctl.c
Normal file
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* crypt32 CTL functions tests
|
||||
*
|
||||
* Copyright 2008 Juan Lang
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winerror.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
#include "wine/test.h"
|
||||
|
||||
static const BYTE emptyCTL[] = {
|
||||
0x30,0x17,0x30,0x00,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,
|
||||
0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x02,0x06,0x00 };
|
||||
static const BYTE ctlWithOneEntry[] = {
|
||||
0x30,0x2a,0x30,0x00,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,
|
||||
0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x02,0x06,0x00,0x30,0x11,0x30,0x0f,0x04,
|
||||
0x01,0x01,0x31,0x0a,0x30,0x08,0x06,0x02,0x2a,0x03,0x31,0x02,0x30,0x00 };
|
||||
static const BYTE signedCTL[] = {
|
||||
0x30,0x81,0xc7,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0,
|
||||
0x81,0xb9,0x30,0x81,0xb6,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a,
|
||||
0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x28,0x06,0x09,0x2a,0x86,
|
||||
0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x1b,0x04,0x19,0x30,0x17,0x30,0x00,
|
||||
0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
|
||||
0x30,0x5a,0x30,0x02,0x06,0x00,0x31,0x77,0x30,0x75,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,0x30,0x04,0x06,0x00,0x05,
|
||||
0x00,0x04,0x40,0xca,0xd8,0x32,0xd1,0xbd,0x97,0x61,0x54,0xd6,0x80,0xcf,0x0d,
|
||||
0xbd,0xa2,0x42,0xc7,0xca,0x37,0x91,0x7d,0x9d,0xac,0x8c,0xdf,0x05,0x8a,0x39,
|
||||
0xc6,0x07,0xc1,0x37,0xe6,0xb9,0xd1,0x0d,0x26,0xec,0xa5,0xb0,0x8a,0x51,0x26,
|
||||
0x2b,0x4f,0x73,0x44,0x86,0x83,0x5e,0x2b,0x6e,0xcc,0xf8,0x1b,0x85,0x53,0xe9,
|
||||
0x7a,0x80,0x8f,0x6b,0x42,0x19,0x93 };
|
||||
static const BYTE signedCTLWithSubjectAlgorithm[] = {
|
||||
0x30,0x81,0xd1,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0,
|
||||
0x81,0xc3,0x30,0x81,0xc0,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a,
|
||||
0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x32,0x06,0x09,0x2a,0x86,
|
||||
0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x25,0x04,0x23,0x30,0x21,0x30,0x00,
|
||||
0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
|
||||
0x30,0x5a,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,
|
||||
0x00,0x31,0x77,0x30,0x75,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,0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x40,0xca,0x7a,
|
||||
0xfa,0xbf,0x44,0x36,0xfd,0xb2,0x84,0x70,0x0f,0xf5,0x66,0xcb,0x68,0xdb,0x45,
|
||||
0x74,0xa1,0xed,0xe3,0x30,0x4a,0x11,0xd2,0x7b,0xf5,0xa9,0x68,0x8d,0x36,0xe8,
|
||||
0x79,0xff,0xa2,0xf2,0x4c,0x8a,0xa9,0x65,0x03,0xf8,0x77,0xa5,0x01,0xd3,0x46,
|
||||
0x8a,0xcc,0x93,0x36,0x30,0xe1,0xa4,0x47,0x70,0x3d,0xb3,0x97,0xfc,0x6d,0x24,
|
||||
0xe9,0xf9 };
|
||||
static const BYTE signedCTLWithCTLInnerContent[] = {
|
||||
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,0x00,
|
||||
0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
|
||||
0x30,0x5a,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,
|
||||
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,0x54,0x71,0xbc,0xe1,0x56,0x31,0xa2,0xf9,
|
||||
0x65,0x70,0x34,0xf8,0xe2,0xe9,0xb4,0xf4,0x30,0x04,0x06,0x00,0x05,0x00,0x04,
|
||||
0x40,0x2f,0x1b,0x9f,0x5a,0x4a,0x15,0x73,0xfa,0xb1,0x93,0x3d,0x09,0x52,0xdf,
|
||||
0x6b,0x98,0x4b,0x13,0x5e,0xe7,0xbf,0x65,0xf4,0x9c,0xc2,0xb1,0x77,0x09,0xb1,
|
||||
0x66,0x4d,0x72,0x0d,0xb1,0x1a,0x50,0x20,0xe0,0x57,0xa2,0x39,0xc7,0xcd,0x7f,
|
||||
0x8e,0xe7,0x5f,0x76,0x2b,0xd1,0x6a,0x82,0xb3,0x30,0x25,0x61,0xf6,0x25,0x23,
|
||||
0x57,0x6c,0x0b,0x47,0xb8 };
|
||||
static const BYTE signedCTLWithCTLInnerContentAndBadSig[] = {
|
||||
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,0x00,
|
||||
0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,
|
||||
0x30,0x5a,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,
|
||||
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,0x54,0x71,0xbc,0xe1,0x56,0x31,0xa2,0xf9,
|
||||
0x65,0x70,0x34,0xf8,0xe2,0xe9,0xb4,0xf4,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 testCreateCTL(void)
|
||||
{
|
||||
PCCTL_CONTEXT ctl;
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ctl = CertCreateCTLContext(0, NULL, 0);
|
||||
todo_wine
|
||||
ok(!ctl && GetLastError() == E_INVALIDARG,
|
||||
"expected E_INVALIDARG, got %08x\n", GetLastError());
|
||||
SetLastError(0xdeadbeef);
|
||||
ctl = CertCreateCTLContext(X509_ASN_ENCODING, NULL, 0);
|
||||
todo_wine
|
||||
ok(!ctl && GetLastError() == ERROR_INVALID_DATA,
|
||||
"expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
||||
GetLastError());
|
||||
/* An empty CTL can't be created.. */
|
||||
SetLastError(0xdeadbeef);
|
||||
ctl = CertCreateCTLContext(X509_ASN_ENCODING, emptyCTL, sizeof(emptyCTL));
|
||||
todo_wine
|
||||
ok(!ctl && GetLastError() == ERROR_INVALID_DATA,
|
||||
"expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
||||
GetLastError());
|
||||
/* Nor can any of these "signed" CTLs whose inner content OID isn't
|
||||
* szOID_CTL.
|
||||
*/
|
||||
SetLastError(0xdeadbeef);
|
||||
ctl = CertCreateCTLContext(X509_ASN_ENCODING, signedCTL, sizeof(signedCTL));
|
||||
todo_wine
|
||||
ok(!ctl && GetLastError() == ERROR_INVALID_DATA,
|
||||
"expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
||||
GetLastError());
|
||||
SetLastError(0xdeadbeef);
|
||||
ctl = CertCreateCTLContext(X509_ASN_ENCODING, ctlWithOneEntry,
|
||||
sizeof(ctlWithOneEntry));
|
||||
todo_wine
|
||||
ok(!ctl && GetLastError() == ERROR_INVALID_DATA,
|
||||
"expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
||||
GetLastError());
|
||||
SetLastError(0xdeadbeef);
|
||||
ctl = CertCreateCTLContext(X509_ASN_ENCODING,
|
||||
signedCTLWithSubjectAlgorithm, sizeof(signedCTLWithSubjectAlgorithm));
|
||||
todo_wine
|
||||
ok(!ctl && GetLastError() == ERROR_INVALID_DATA,
|
||||
"expected ERROR_INVALID_DATA, got %d (0x%08x)\n", GetLastError(),
|
||||
GetLastError());
|
||||
/* This signed CTL with the appropriate inner content type can be decoded.
|
||||
*/
|
||||
ctl = CertCreateCTLContext(X509_ASN_ENCODING,
|
||||
signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent));
|
||||
todo_wine
|
||||
ok(ctl != NULL, "CertCreateCTLContext failed: %08x\n", GetLastError());
|
||||
if (ctl)
|
||||
{
|
||||
/* Even though the CTL was decoded with X509_ASN_ENCODING, the
|
||||
* message encoding type is included in the CTL's encoding type.
|
||||
*/
|
||||
ok(ctl->dwMsgAndCertEncodingType ==
|
||||
(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING),
|
||||
"expected X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, got %08x\n",
|
||||
ctl->dwMsgAndCertEncodingType);
|
||||
CertFreeCTLContext(ctl);
|
||||
}
|
||||
/* This CTL with a bad signature can also be decoded, so the sig isn't
|
||||
* checked when loading the CTL.
|
||||
*/
|
||||
ctl = CertCreateCTLContext(X509_ASN_ENCODING,
|
||||
signedCTLWithCTLInnerContentAndBadSig,
|
||||
sizeof(signedCTLWithCTLInnerContentAndBadSig));
|
||||
todo_wine
|
||||
ok(ctl != NULL, "CertCreateCTLContext failed: %08x\n", GetLastError());
|
||||
if (ctl)
|
||||
CertFreeCTLContext(ctl);
|
||||
}
|
||||
|
||||
START_TEST(ctl)
|
||||
{
|
||||
testCreateCTL();
|
||||
}
|
Loading…
Reference in a new issue