mirror of
https://github.com/reactos/reactos.git
synced 2025-04-19 04:07:16 +00:00
add wintrust winetest from wine 1.1.11
svn path=/trunk/; revision=38447
This commit is contained in:
parent
a2666bfc50
commit
789db79fc6
7 changed files with 2353 additions and 0 deletions
|
@ -136,6 +136,9 @@
|
|||
<directory name="wininet">
|
||||
<xi:include href="wininet/wininet.rbuild" />
|
||||
</directory>
|
||||
<directory name="wintrust">
|
||||
<xi:include href="wintrust/wintrust.rbuild" />
|
||||
</directory>
|
||||
<!--
|
||||
<directory name="winetest">
|
||||
<xi:include href="winetest/winetest.rbuild" />
|
||||
|
|
961
rostests/winetests/wintrust/asn.c
Normal file
961
rostests/winetests/wintrust/asn.c
Normal file
|
@ -0,0 +1,961 @@
|
|||
/* Unit test suite for wintrust asn functions
|
||||
*
|
||||
* Copyright 2007 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 <stdarg.h>
|
||||
#include "windef.h"
|
||||
#include "winbase.h"
|
||||
#include "winerror.h"
|
||||
#include "wincrypt.h"
|
||||
#include "wintrust.h"
|
||||
|
||||
#include "wine/test.h"
|
||||
|
||||
static BOOL (WINAPI *pCryptDecodeObjectEx)(DWORD,LPCSTR,const BYTE*,DWORD,DWORD,PCRYPT_DECODE_PARA,void*,DWORD*);
|
||||
static BOOL (WINAPI *pCryptEncodeObjectEx)(DWORD,LPCSTR,const void*,DWORD,PCRYPT_ENCODE_PARA,void*,DWORD*);
|
||||
|
||||
static const BYTE falseCriteria[] = { 0x30,0x06,0x01,0x01,0x00,0x01,0x01,0x00 };
|
||||
static const BYTE trueCriteria[] = { 0x30,0x06,0x01,0x01,0xff,0x01,0x01,0xff };
|
||||
|
||||
static void test_encodeSPCFinancialCriteria(void)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD size = 0;
|
||||
LPBYTE buf;
|
||||
SPC_FINANCIAL_CRITERIA criteria = { FALSE, FALSE };
|
||||
|
||||
if (!pCryptEncodeObjectEx)
|
||||
{
|
||||
skip("CryptEncodeObjectEx() is not available. Skipping the encodeFinancialCriteria tests\n");
|
||||
return;
|
||||
}
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_FINANCIAL_CRITERIA_STRUCT,
|
||||
&criteria, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(falseCriteria), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, falseCriteria, size), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
criteria.fFinancialInfoAvailable = criteria.fMeetsCriteria = TRUE;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_FINANCIAL_CRITERIA_STRUCT,
|
||||
&criteria, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(trueCriteria), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, trueCriteria, size), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_decodeSPCFinancialCriteria(void)
|
||||
{
|
||||
BOOL ret;
|
||||
SPC_FINANCIAL_CRITERIA criteria;
|
||||
DWORD size = sizeof(criteria);
|
||||
|
||||
if (!pCryptDecodeObjectEx)
|
||||
{
|
||||
skip("CryptDecodeObjectEx() is not available. Skipping the decodeSPCFinancialCriteria tests\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_FINANCIAL_CRITERIA_STRUCT,
|
||||
falseCriteria, sizeof(falseCriteria), 0, NULL, &criteria, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(!criteria.fFinancialInfoAvailable, "expected FALSE\n");
|
||||
ok(!criteria.fMeetsCriteria, "expected FALSE\n");
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_FINANCIAL_CRITERIA_STRUCT,
|
||||
trueCriteria, sizeof(trueCriteria), 0, NULL, &criteria, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(criteria.fFinancialInfoAvailable, "expected TRUE\n");
|
||||
ok(criteria.fMeetsCriteria, "expected TRUE\n");
|
||||
}
|
||||
}
|
||||
|
||||
static WCHAR url[] = { 'h','t','t','p',':','/','/','w','i','n','e','h','q','.',
|
||||
'o','r','g',0 };
|
||||
static const WCHAR nihongoURL[] = { 'h','t','t','p',':','/','/',0x226f,
|
||||
0x575b, 0 };
|
||||
static const BYTE emptyURLSPCLink[] = { 0x80,0x00 };
|
||||
static const BYTE urlSPCLink[] = {
|
||||
0x80,0x11,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,0x65,0x68,0x71,
|
||||
0x2e,0x6f,0x72,0x67};
|
||||
static const BYTE fileSPCLink[] = {
|
||||
0xa2,0x14,0x80,0x12,0x00,0x68,0x00,0x74,0x00,0x74,0x00,0x70,0x00,0x3a,0x00,
|
||||
0x2f,0x00,0x2f,0x22,0x6f,0x57,0x5b };
|
||||
static const BYTE emptyMonikerSPCLink[] = {
|
||||
0xa1,0x14,0x04,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x04,0x00 };
|
||||
static BYTE data[] = { 0xba, 0xad, 0xf0, 0x0d };
|
||||
static const BYTE monikerSPCLink[] = {
|
||||
0xa1,0x18,0x04,0x10,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,
|
||||
0xea,0xea,0xea,0xea,0xea,0x04,0x04,0xba,0xad,0xf0,0x0d };
|
||||
|
||||
static void test_encodeSPCLink(void)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD size = 0;
|
||||
LPBYTE buf;
|
||||
SPC_LINK link = { 0 };
|
||||
|
||||
if (!pCryptEncodeObjectEx)
|
||||
{
|
||||
skip("CryptEncodeObjectEx() is not available. Skipping the encodeSPCLink tests\n");
|
||||
return;
|
||||
}
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
|
||||
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(!ret && GetLastError() == E_INVALIDARG,
|
||||
"Expected E_INVALIDARG, got %08x\n", GetLastError());
|
||||
link.dwLinkChoice = SPC_URL_LINK_CHOICE;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
|
||||
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(emptyURLSPCLink), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, emptyURLSPCLink, size), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
/* With an invalid char: */
|
||||
U(link).pwszUrl = (LPWSTR)nihongoURL;
|
||||
size = 1;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
|
||||
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(!ret &&
|
||||
(GetLastError() == CRYPT_E_INVALID_IA5_STRING ||
|
||||
GetLastError() == OSS_BAD_PTR /* Win9x */),
|
||||
"Expected CRYPT_E_INVALID_IA5_STRING, got %08x\n", GetLastError());
|
||||
/* Unlike the crypt32 string encoding routines, size is not set to the
|
||||
* index of the first invalid character.
|
||||
*/
|
||||
ok(size == 0, "Expected size 0, got %d\n", size);
|
||||
U(link).pwszUrl = url;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
|
||||
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(urlSPCLink), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, urlSPCLink, size), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
link.dwLinkChoice = SPC_FILE_LINK_CHOICE;
|
||||
U(link).pwszFile = (LPWSTR)nihongoURL;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
|
||||
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(fileSPCLink), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, fileSPCLink, size), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
link.dwLinkChoice = SPC_MONIKER_LINK_CHOICE;
|
||||
memset(&U(link).Moniker, 0, sizeof(U(link).Moniker));
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
|
||||
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(emptyMonikerSPCLink), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, emptyMonikerSPCLink, size), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
memset(&U(link).Moniker.ClassId, 0xea, sizeof(U(link).Moniker.ClassId));
|
||||
U(link).Moniker.SerializedData.pbData = data;
|
||||
U(link).Moniker.SerializedData.cbData = sizeof(data);
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
|
||||
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(monikerSPCLink), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, monikerSPCLink, size), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static const BYTE badMonikerSPCLink[] = {
|
||||
0xa1,0x19,0x04,0x11,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,
|
||||
0xea,0xea,0xea,0xea,0xea,0xea,0x04,0x04,0xba,0xad,0xf0,0x0d };
|
||||
|
||||
static void test_decodeSPCLink(void)
|
||||
{
|
||||
BOOL ret;
|
||||
LPBYTE buf = NULL;
|
||||
DWORD size = 0;
|
||||
SPC_LINK *link;
|
||||
|
||||
if (!pCryptDecodeObjectEx)
|
||||
{
|
||||
skip("CryptDecodeObjectEx() is not available. Skipping the decodeSPCLink tests\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
|
||||
emptyURLSPCLink, sizeof(emptyURLSPCLink), CRYPT_DECODE_ALLOC_FLAG, NULL,
|
||||
(BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
link = (SPC_LINK *)buf;
|
||||
ok(link->dwLinkChoice == SPC_URL_LINK_CHOICE,
|
||||
"Expected SPC_URL_LINK_CHOICE, got %d\n", link->dwLinkChoice);
|
||||
ok(lstrlenW(U(*link).pwszUrl) == 0, "Expected empty string\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
|
||||
urlSPCLink, sizeof(urlSPCLink), CRYPT_DECODE_ALLOC_FLAG, NULL,
|
||||
(BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
link = (SPC_LINK *)buf;
|
||||
ok(link->dwLinkChoice == SPC_URL_LINK_CHOICE,
|
||||
"Expected SPC_URL_LINK_CHOICE, got %d\n", link->dwLinkChoice);
|
||||
ok(!lstrcmpW(U(*link).pwszUrl, url), "Unexpected URL\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
|
||||
fileSPCLink, sizeof(fileSPCLink), CRYPT_DECODE_ALLOC_FLAG, NULL,
|
||||
(BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
link = (SPC_LINK *)buf;
|
||||
ok(link->dwLinkChoice == SPC_FILE_LINK_CHOICE,
|
||||
"Expected SPC_FILE_LINK_CHOICE, got %d\n", link->dwLinkChoice);
|
||||
ok(!lstrcmpW(U(*link).pwszFile, nihongoURL), "Unexpected file\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
|
||||
emptyMonikerSPCLink, sizeof(emptyMonikerSPCLink), CRYPT_DECODE_ALLOC_FLAG,
|
||||
NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
SPC_SERIALIZED_OBJECT emptyMoniker = { { 0 } };
|
||||
|
||||
link = (SPC_LINK *)buf;
|
||||
ok(link->dwLinkChoice == SPC_MONIKER_LINK_CHOICE,
|
||||
"Expected SPC_MONIKER_LINK_CHOICE, got %d\n", link->dwLinkChoice);
|
||||
ok(!memcmp(&U(*link).Moniker.ClassId, &emptyMoniker.ClassId,
|
||||
sizeof(emptyMoniker.ClassId)), "Unexpected value\n");
|
||||
ok(U(*link).Moniker.SerializedData.cbData == 0,
|
||||
"Expected no serialized data\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
|
||||
monikerSPCLink, sizeof(monikerSPCLink), CRYPT_DECODE_ALLOC_FLAG, NULL,
|
||||
(BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
SPC_UUID id;
|
||||
|
||||
link = (SPC_LINK *)buf;
|
||||
ok(link->dwLinkChoice == SPC_MONIKER_LINK_CHOICE,
|
||||
"Expected SPC_MONIKER_LINK_CHOICE, got %d\n", link->dwLinkChoice);
|
||||
memset(&id, 0xea, sizeof(id));
|
||||
ok(!memcmp(&U(*link).Moniker.ClassId, &id, sizeof(id)),
|
||||
"Unexpected value\n");
|
||||
ok(U(*link).Moniker.SerializedData.cbData == sizeof(data),
|
||||
"Unexpected data size %d\n", U(*link).Moniker.SerializedData.cbData);
|
||||
ok(!memcmp(U(*link).Moniker.SerializedData.pbData, data, sizeof(data)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
|
||||
badMonikerSPCLink, sizeof(badMonikerSPCLink), CRYPT_DECODE_ALLOC_FLAG,
|
||||
NULL, (BYTE *)&buf, &size);
|
||||
ok(!ret &&
|
||||
(GetLastError() == CRYPT_E_BAD_ENCODE ||
|
||||
GetLastError() == OSS_DATA_ERROR /* Win9x */),
|
||||
"Expected CRYPT_E_BAD_ENCODE, got %08x\n", GetLastError());
|
||||
}
|
||||
|
||||
static const BYTE emptySequence[] = { 0x30,0x00 };
|
||||
static BYTE flags[] = { 1 };
|
||||
static const BYTE onlyFlagsPEImage[] = { 0x30,0x04,0x03,0x02,0x00,0x01 };
|
||||
static const BYTE moreFlagsPEImage[] = {
|
||||
0x30,0x06,0x03,0x04,0x04,0xff,0x80,0x10 };
|
||||
static const BYTE onlyEmptyFilePEImage[] = {
|
||||
0x30,0x06,0xa0,0x04,0xa2,0x02,0x80,0x00 };
|
||||
static const BYTE flagsAndEmptyFilePEImage[] = {
|
||||
0x30,0x0a,0x03,0x02,0x00,0x01,0xa0,0x04,0xa2,0x02,0x80,0x00 };
|
||||
static const BYTE flagsAndFilePEImage[] = {
|
||||
0x30,0x1c,0x03,0x02,0x00,0x01,0xa0,0x16,0xa2,0x14,0x80,0x12,0x00,0x68,0x00,
|
||||
0x74,0x00,0x74,0x00,0x70,0x00,0x3a,0x00,0x2f,0x00,0x2f,0x22,0x6f,0x57,0x5b };
|
||||
|
||||
static void test_encodeSPCPEImage(void)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD size = 0;
|
||||
LPBYTE buf;
|
||||
SPC_PE_IMAGE_DATA imageData = { { 0 } };
|
||||
SPC_LINK link = { 0 };
|
||||
|
||||
if (!pCryptEncodeObjectEx)
|
||||
{
|
||||
skip("CryptEncodeObjectEx() is not available. Skipping the encodeSPCPEImage tests\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
&imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(emptySequence), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, emptySequence, sizeof(emptySequence)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
/* With an invalid link: */
|
||||
imageData.pFile = &link;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
&imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(!ret && GetLastError () == E_INVALIDARG,
|
||||
"Expected E_INVALIDARG, got %08x\n", GetLastError());
|
||||
/* With just unused bits field set: */
|
||||
imageData.pFile = NULL;
|
||||
imageData.Flags.cUnusedBits = 1;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
&imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(emptySequence), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, emptySequence, sizeof(emptySequence)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
/* With flags set: */
|
||||
imageData.Flags.cUnusedBits = 0;
|
||||
imageData.Flags.pbData = flags;
|
||||
imageData.Flags.cbData = sizeof(flags);
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
&imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
if (!ret && GetLastError() == OSS_TOO_LONG)
|
||||
{
|
||||
skip("SPC_PE_IMAGE_DATA_STRUCT not supported\n");
|
||||
return;
|
||||
}
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(onlyFlagsPEImage), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, onlyFlagsPEImage, sizeof(onlyFlagsPEImage)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
/* With just an empty file: */
|
||||
imageData.Flags.cbData = 0;
|
||||
link.dwLinkChoice = SPC_FILE_LINK_CHOICE;
|
||||
imageData.pFile = &link;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
&imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(onlyEmptyFilePEImage), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, onlyEmptyFilePEImage, sizeof(onlyEmptyFilePEImage)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
/* With flags and an empty file: */
|
||||
imageData.Flags.pbData = flags;
|
||||
imageData.Flags.cbData = sizeof(flags);
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
&imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(flagsAndEmptyFilePEImage), "Unexpected size %d\n",
|
||||
size);
|
||||
ok(!memcmp(buf, flagsAndEmptyFilePEImage,
|
||||
sizeof(flagsAndEmptyFilePEImage)), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
/* Finally, a non-empty file: */
|
||||
U(link).pwszFile = (LPWSTR)nihongoURL;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
&imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(flagsAndFilePEImage), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, flagsAndFilePEImage, sizeof(flagsAndFilePEImage)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_decodeSPCPEImage(void)
|
||||
{
|
||||
static const WCHAR emptyString[] = { 0 };
|
||||
BOOL ret;
|
||||
LPBYTE buf = NULL;
|
||||
DWORD size = 0;
|
||||
SPC_PE_IMAGE_DATA *imageData;
|
||||
|
||||
if (!pCryptDecodeObjectEx)
|
||||
{
|
||||
skip("CryptDecodeObjectEx() is not available. Skipping the decodeSPCPEImage tests\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
emptySequence, sizeof(emptySequence),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
imageData = (SPC_PE_IMAGE_DATA *)buf;
|
||||
ok(imageData->Flags.cbData == 0, "Expected empty flags, got %d\n",
|
||||
imageData->Flags.cbData);
|
||||
ok(imageData->pFile == NULL, "Expected no file\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
onlyFlagsPEImage, sizeof(onlyFlagsPEImage),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
imageData = (SPC_PE_IMAGE_DATA *)buf;
|
||||
ok(imageData->Flags.cbData == sizeof(flags),
|
||||
"Unexpected flags size %d\n", imageData->Flags.cbData);
|
||||
if (imageData->Flags.cbData)
|
||||
ok(!memcmp(imageData->Flags.pbData, flags, sizeof(flags)),
|
||||
"Unexpected flags\n");
|
||||
ok(imageData->pFile == NULL, "Expected no file\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
onlyEmptyFilePEImage, sizeof(onlyEmptyFilePEImage),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
imageData = (SPC_PE_IMAGE_DATA *)buf;
|
||||
ok(imageData->Flags.cbData == 0, "Expected empty flags, got %d\n",
|
||||
imageData->Flags.cbData);
|
||||
ok(imageData->pFile != NULL, "Expected a file\n");
|
||||
if (imageData->pFile)
|
||||
{
|
||||
ok(imageData->pFile->dwLinkChoice == SPC_FILE_LINK_CHOICE,
|
||||
"Expected SPC_FILE_LINK_CHOICE, got %d\n",
|
||||
imageData->pFile->dwLinkChoice);
|
||||
ok(!lstrcmpW(U(*imageData->pFile).pwszFile, emptyString),
|
||||
"Unexpected file\n");
|
||||
}
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
flagsAndEmptyFilePEImage, sizeof(flagsAndEmptyFilePEImage),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
imageData = (SPC_PE_IMAGE_DATA *)buf;
|
||||
ok(imageData->Flags.cbData == sizeof(flags),
|
||||
"Unexpected flags size %d\n", imageData->Flags.cbData);
|
||||
if (imageData->Flags.cbData)
|
||||
ok(!memcmp(imageData->Flags.pbData, flags, sizeof(flags)),
|
||||
"Unexpected flags\n");
|
||||
ok(imageData->pFile != NULL, "Expected a file\n");
|
||||
if (imageData->pFile)
|
||||
{
|
||||
ok(imageData->pFile->dwLinkChoice == SPC_FILE_LINK_CHOICE,
|
||||
"Expected SPC_FILE_LINK_CHOICE, got %d\n",
|
||||
imageData->pFile->dwLinkChoice);
|
||||
ok(!lstrcmpW(U(*imageData->pFile).pwszFile, emptyString),
|
||||
"Unexpected file\n");
|
||||
}
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
|
||||
flagsAndFilePEImage, sizeof(flagsAndFilePEImage),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
imageData = (SPC_PE_IMAGE_DATA *)buf;
|
||||
ok(imageData->Flags.cbData == sizeof(flags),
|
||||
"Unexpected flags size %d\n", imageData->Flags.cbData);
|
||||
if (imageData->Flags.cbData)
|
||||
ok(!memcmp(imageData->Flags.pbData, flags, sizeof(flags)),
|
||||
"Unexpected flags\n");
|
||||
ok(imageData->pFile != NULL, "Expected a file\n");
|
||||
if (imageData->pFile)
|
||||
{
|
||||
ok(imageData->pFile->dwLinkChoice == SPC_FILE_LINK_CHOICE,
|
||||
"Expected SPC_FILE_LINK_CHOICE, got %d\n",
|
||||
imageData->pFile->dwLinkChoice);
|
||||
ok(!lstrcmpW(U(*imageData->pFile).pwszFile, nihongoURL),
|
||||
"Unexpected file\n");
|
||||
}
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static WCHAR foo[] = { 'f','o','o',0 };
|
||||
static WCHAR guidStr[] = { '{','8','b','c','9','6','b','0','0','-',
|
||||
'8','d','a','1','-','1','1','c','f','-','8','7','3','6','-','0','0',
|
||||
'a','a','0','0','a','4','8','5','e','b','}',0 };
|
||||
|
||||
static const BYTE emptyCatMemberInfo[] = { 0x30,0x05,0x1e,0x00,0x02,0x01,0x00 };
|
||||
static const BYTE catMemberInfoWithSillyGuid[] = {
|
||||
0x30,0x0b,0x1e,0x06,0x00,0x66,0x00,0x6f,0x00,0x6f,0x02,0x01,0x00 };
|
||||
static const BYTE catMemberInfoWithGuid[] = {
|
||||
0x30,0x51,0x1e,0x4c,0x00,0x7b,0x00,0x38,0x00,0x62,0x00,0x63,0x00,0x39,0x00,0x36,
|
||||
0x00,0x62,0x00,0x30,0x00,0x30,0x00,0x2d,0x00,0x38,0x00,0x64,0x00,0x61,0x00,0x31,
|
||||
0x00,0x2d,0x00,0x31,0x00,0x31,0x00,0x63,0x00,0x66,0x00,0x2d,0x00,0x38,0x00,0x37,
|
||||
0x00,0x33,0x00,0x36,0x00,0x2d,0x00,0x30,0x00,0x30,0x00,0x61,0x00,0x61,0x00,0x30,
|
||||
0x00,0x30,0x00,0x61,0x00,0x34,0x00,0x38,0x00,0x35,0x00,0x65,0x00,0x62,0x00,0x7d,
|
||||
0x02,0x01,0x00 };
|
||||
|
||||
static void test_encodeCatMemberInfo(void)
|
||||
{
|
||||
CAT_MEMBERINFO info;
|
||||
BOOL ret;
|
||||
DWORD size = 0;
|
||||
LPBYTE buf;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
|
||||
if (!pCryptEncodeObjectEx)
|
||||
{
|
||||
skip("CryptEncodeObjectEx() is not available. Skipping the encodeCatMemberInfo tests\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
|
||||
&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(emptyCatMemberInfo), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, emptyCatMemberInfo, sizeof(emptyCatMemberInfo)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
info.pwszSubjGuid = foo;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
|
||||
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(catMemberInfoWithSillyGuid), "Unexpected size %d\n",
|
||||
size);
|
||||
ok(!memcmp(buf, catMemberInfoWithSillyGuid,
|
||||
sizeof(catMemberInfoWithSillyGuid)), "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
info.pwszSubjGuid = guidStr;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
|
||||
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(catMemberInfoWithGuid), "Unexpected size %d\n",
|
||||
size);
|
||||
ok(!memcmp(buf, catMemberInfoWithGuid, sizeof(catMemberInfoWithGuid)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_decodeCatMemberInfo(void)
|
||||
{
|
||||
BOOL ret;
|
||||
LPBYTE buf;
|
||||
DWORD size;
|
||||
CAT_MEMBERINFO *info;
|
||||
|
||||
if (!pCryptDecodeObjectEx)
|
||||
{
|
||||
skip("CryptDecodeObjectEx() is not available. Skipping the decodeCatMemberInfo tests\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
|
||||
emptyCatMemberInfo, sizeof(emptyCatMemberInfo),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
info = (CAT_MEMBERINFO *)buf;
|
||||
ok(!info->pwszSubjGuid || !info->pwszSubjGuid[0],
|
||||
"expected empty pwszSubjGuid\n");
|
||||
ok(info->dwCertVersion == 0, "expected dwCertVersion == 0, got %d\n",
|
||||
info->dwCertVersion);
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
|
||||
catMemberInfoWithSillyGuid, sizeof(catMemberInfoWithSillyGuid),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
info = (CAT_MEMBERINFO *)buf;
|
||||
ok(info->pwszSubjGuid && !lstrcmpW(info->pwszSubjGuid, foo),
|
||||
"unexpected pwszSubjGuid\n");
|
||||
ok(info->dwCertVersion == 0, "expected dwCertVersion == 0, got %d\n",
|
||||
info->dwCertVersion);
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
|
||||
catMemberInfoWithGuid, sizeof(catMemberInfoWithGuid),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
info = (CAT_MEMBERINFO *)buf;
|
||||
ok(info->pwszSubjGuid && !lstrcmpW(info->pwszSubjGuid, guidStr),
|
||||
"unexpected pwszSubjGuid\n");
|
||||
ok(info->dwCertVersion == 0, "expected dwCertVersion == 0, got %d\n",
|
||||
info->dwCertVersion);
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static const BYTE emptyCatNameValue[] = {
|
||||
0x30,0x07,0x1e,0x00,0x02,0x01,0x00,0x04,0x00 };
|
||||
static const BYTE catNameValueWithTag[] = {
|
||||
0x30,0x0d,0x1e,0x06,0x00,0x66,0x00,0x6f,0x00,0x6f,0x02,0x01,0x00,0x04,0x00 };
|
||||
static const BYTE catNameValueWithFlags[] = {
|
||||
0x30,0x0a,0x1e,0x00,0x02,0x04,0xf0,0x0d,0xd0,0x0d,0x04,0x00 };
|
||||
static const BYTE catNameValueWithValue[] = {
|
||||
0x30,0x0b,0x1e,0x00,0x02,0x01,0x00,0x04,0x04,0x01,0x02,0x03,0x04 };
|
||||
|
||||
static BYTE aVal[] = { 1,2,3,4 };
|
||||
|
||||
static void test_encodeCatNameValue(void)
|
||||
{
|
||||
static WCHAR foo[] = { 'f','o','o',0 };
|
||||
BOOL ret;
|
||||
LPBYTE buf;
|
||||
DWORD size;
|
||||
CAT_NAMEVALUE value;
|
||||
|
||||
memset(&value, 0, sizeof(value));
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
|
||||
(LPBYTE)&value, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(emptyCatNameValue), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, emptyCatNameValue, sizeof(emptyCatNameValue)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
value.pwszTag = foo;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
|
||||
(LPBYTE)&value, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(catNameValueWithTag), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, catNameValueWithTag, sizeof(catNameValueWithTag)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
value.pwszTag = NULL;
|
||||
value.fdwFlags = 0xf00dd00d;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
|
||||
(LPBYTE)&value, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(catNameValueWithFlags), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, catNameValueWithFlags, sizeof(catNameValueWithFlags)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
value.fdwFlags = 0;
|
||||
value.Value.cbData = sizeof(aVal);
|
||||
value.Value.pbData = aVal;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
|
||||
(LPBYTE)&value, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(catNameValueWithValue), "Unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, catNameValueWithValue, sizeof(catNameValueWithValue)),
|
||||
"Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_decodeCatNameValue(void)
|
||||
{
|
||||
BOOL ret;
|
||||
LPBYTE buf;
|
||||
DWORD size;
|
||||
CAT_NAMEVALUE *value;
|
||||
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
|
||||
emptyCatNameValue, sizeof(emptyCatNameValue),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
value = (CAT_NAMEVALUE *)buf;
|
||||
ok(!value->pwszTag || !value->pwszTag[0], "expected empty pwszTag\n");
|
||||
ok(value->fdwFlags == 0, "expected fdwFlags == 0, got %08x\n",
|
||||
value->fdwFlags);
|
||||
ok(value->Value.cbData == 0, "expected 0-length value, got %d\n",
|
||||
value->Value.cbData);
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
|
||||
catNameValueWithTag, sizeof(catNameValueWithTag),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
value = (CAT_NAMEVALUE *)buf;
|
||||
ok(value->pwszTag && !lstrcmpW(value->pwszTag, foo),
|
||||
"unexpected pwszTag\n");
|
||||
ok(value->fdwFlags == 0, "expected fdwFlags == 0, got %08x\n",
|
||||
value->fdwFlags);
|
||||
ok(value->Value.cbData == 0, "expected 0-length value, got %d\n",
|
||||
value->Value.cbData);
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
|
||||
catNameValueWithFlags, sizeof(catNameValueWithFlags),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
value = (CAT_NAMEVALUE *)buf;
|
||||
ok(!value->pwszTag || !value->pwszTag[0], "expected empty pwszTag\n");
|
||||
ok(value->fdwFlags == 0xf00dd00d,
|
||||
"expected fdwFlags == 0xf00dd00d, got %08x\n", value->fdwFlags);
|
||||
ok(value->Value.cbData == 0, "expected 0-length value, got %d\n",
|
||||
value->Value.cbData);
|
||||
LocalFree(buf);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
|
||||
catNameValueWithValue, sizeof(catNameValueWithValue),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
value = (CAT_NAMEVALUE *)buf;
|
||||
ok(!value->pwszTag || !value->pwszTag[0], "expected empty pwszTag\n");
|
||||
ok(value->fdwFlags == 0, "expected fdwFlags == 0, got %08x\n",
|
||||
value->fdwFlags);
|
||||
ok(value->Value.cbData == sizeof(aVal), "unexpected size %d\n",
|
||||
value->Value.cbData);
|
||||
ok(!memcmp(value->Value.pbData, aVal, value->Value.cbData),
|
||||
"unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static const WCHAR progName[] = { 'A',' ','p','r','o','g','r','a','m',0 };
|
||||
static const BYTE spOpusInfoWithProgramName[] = {
|
||||
0x30,0x16,0xa0,0x14,0x80,0x12,0x00,0x41,0x00,0x20,0x00,0x70,0x00,0x72,0x00,0x6f,
|
||||
0x00,0x67,0x00,0x72,0x00,0x61,0x00,0x6d };
|
||||
static WCHAR winehq[] = { 'h','t','t','p',':','/','/','w','i','n','e','h','q',
|
||||
'.','o','r','g','/',0 };
|
||||
static const BYTE spOpusInfoWithMoreInfo[] = {
|
||||
0x30,0x16,0xa1,0x14,0x80,0x12,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,
|
||||
0x65,0x68,0x71,0x2e,0x6f,0x72,0x67,0x2f };
|
||||
static const BYTE spOpusInfoWithPublisherInfo[] = {
|
||||
0x30,0x16,0xa2,0x14,0x80,0x12,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,
|
||||
0x65,0x68,0x71,0x2e,0x6f,0x72,0x67,0x2f };
|
||||
|
||||
static void test_encodeSpOpusInfo(void)
|
||||
{
|
||||
BOOL ret;
|
||||
LPBYTE buf;
|
||||
DWORD size;
|
||||
SPC_SP_OPUS_INFO info;
|
||||
SPC_LINK moreInfo;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(emptySequence), "unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, emptySequence, size), "unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
info.pwszProgramName = progName;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(spOpusInfoWithProgramName), "unexpected size %d\n",
|
||||
size);
|
||||
ok(!memcmp(buf, spOpusInfoWithProgramName, size),
|
||||
"unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
info.pwszProgramName = NULL;
|
||||
memset(&moreInfo, 0, sizeof(moreInfo));
|
||||
info.pMoreInfo = &moreInfo;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(!ret && GetLastError() == E_INVALIDARG,
|
||||
"expected E_INVALIDARG, got %08x\n", GetLastError());
|
||||
moreInfo.dwLinkChoice = SPC_URL_LINK_CHOICE;
|
||||
moreInfo.pwszUrl = winehq;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(spOpusInfoWithMoreInfo),
|
||||
"unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, spOpusInfoWithMoreInfo, size),
|
||||
"unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
info.pMoreInfo = NULL;
|
||||
info.pPublisherInfo = &moreInfo;
|
||||
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
|
||||
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(size == sizeof(spOpusInfoWithPublisherInfo),
|
||||
"unexpected size %d\n", size);
|
||||
ok(!memcmp(buf, spOpusInfoWithPublisherInfo, size),
|
||||
"unexpected value\n");
|
||||
LocalFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_decodeSpOpusInfo(void)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD size;
|
||||
SPC_SP_OPUS_INFO *info;
|
||||
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
emptySequence, sizeof(emptySequence), CRYPT_DECODE_ALLOC_FLAG, NULL,
|
||||
&info, &size);
|
||||
todo_wine
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(!info->pwszProgramName, "expected NULL\n");
|
||||
ok(!info->pMoreInfo, "expected NULL\n");
|
||||
ok(!info->pPublisherInfo, "expected NULL\n");
|
||||
LocalFree(info);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
spOpusInfoWithProgramName, sizeof(spOpusInfoWithProgramName),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size);
|
||||
todo_wine
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(info->pwszProgramName && !lstrcmpW(info->pwszProgramName,
|
||||
progName), "unexpected program name\n");
|
||||
ok(!info->pMoreInfo, "expected NULL\n");
|
||||
ok(!info->pPublisherInfo, "expected NULL\n");
|
||||
LocalFree(info);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
spOpusInfoWithMoreInfo, sizeof(spOpusInfoWithMoreInfo),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size);
|
||||
todo_wine
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(!info->pwszProgramName, "expected NULL\n");
|
||||
ok(info->pMoreInfo != NULL, "expected a value for pMoreInfo\n");
|
||||
if (info->pMoreInfo)
|
||||
{
|
||||
ok(info->pMoreInfo->dwLinkChoice == SPC_URL_LINK_CHOICE,
|
||||
"unexpected link choice %d\n", info->pMoreInfo->dwLinkChoice);
|
||||
ok(!lstrcmpW(info->pMoreInfo->pwszUrl, winehq),
|
||||
"unexpected link value\n");
|
||||
}
|
||||
ok(!info->pPublisherInfo, "expected NULL\n");
|
||||
LocalFree(info);
|
||||
}
|
||||
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
|
||||
spOpusInfoWithPublisherInfo, sizeof(spOpusInfoWithPublisherInfo),
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size);
|
||||
todo_wine
|
||||
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
ok(!info->pwszProgramName, "expected NULL\n");
|
||||
ok(!info->pMoreInfo, "expected NULL\n");
|
||||
ok(info->pPublisherInfo != NULL,
|
||||
"expected a value for pPublisherInfo\n");
|
||||
if (info->pPublisherInfo)
|
||||
{
|
||||
ok(info->pPublisherInfo->dwLinkChoice == SPC_URL_LINK_CHOICE,
|
||||
"unexpected link choice %d\n",
|
||||
info->pPublisherInfo->dwLinkChoice);
|
||||
ok(!lstrcmpW(info->pPublisherInfo->pwszUrl, winehq),
|
||||
"unexpected link value\n");
|
||||
}
|
||||
LocalFree(info);
|
||||
}
|
||||
}
|
||||
|
||||
START_TEST(asn)
|
||||
{
|
||||
HMODULE hCrypt32 = LoadLibraryA("crypt32.dll");
|
||||
pCryptDecodeObjectEx = (void*)GetProcAddress(hCrypt32, "CryptDecodeObjectEx");
|
||||
pCryptEncodeObjectEx = (void*)GetProcAddress(hCrypt32, "CryptEncodeObjectEx");
|
||||
|
||||
test_encodeSPCFinancialCriteria();
|
||||
test_decodeSPCFinancialCriteria();
|
||||
test_encodeSPCLink();
|
||||
test_decodeSPCLink();
|
||||
test_encodeSPCPEImage();
|
||||
test_decodeSPCPEImage();
|
||||
test_encodeCatMemberInfo();
|
||||
test_decodeCatMemberInfo();
|
||||
test_encodeCatNameValue();
|
||||
test_decodeCatNameValue();
|
||||
test_encodeSpOpusInfo();
|
||||
test_decodeSpOpusInfo();
|
||||
|
||||
FreeLibrary(hCrypt32);
|
||||
}
|
450
rostests/winetests/wintrust/crypt.c
Normal file
450
rostests/winetests/wintrust/crypt.c
Normal file
|
@ -0,0 +1,450 @@
|
|||
/* Unit test suite for wintrust crypt functions
|
||||
*
|
||||
* Copyright 2007 Paul Vriens
|
||||
* Copyright 2008 Hans Leidekker for CodeWeavers
|
||||
*
|
||||
* 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 <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "windows.h"
|
||||
#include "mscat.h"
|
||||
|
||||
#include "wine/test.h"
|
||||
|
||||
static char selfname[MAX_PATH];
|
||||
static CHAR CURR_DIR[MAX_PATH];
|
||||
|
||||
/*
|
||||
* Minimalistic catalog file. To reconstruct, save text below as winetest.cdf,
|
||||
* convert to DOS line endings and run 'makecat /cat winetest.cdf'
|
||||
*/
|
||||
|
||||
/*
|
||||
[CatalogHeader]
|
||||
Name=winetest.cat
|
||||
ResultDir=.\
|
||||
PublicVersion=0x00000001
|
||||
EncodingType=
|
||||
CATATTR1=0x10010001:attr1:value1
|
||||
CATATTR2=0x10010001:attr2:value2
|
||||
|
||||
[CatalogFiles]
|
||||
hashme=.\winetest.cdf
|
||||
*/
|
||||
|
||||
const BYTE test_catalog[] = {
|
||||
0x30, 0x82, 0x01, 0xbc, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0,
|
||||
0x82, 0x01, 0xad, 0x30, 0x82, 0x01, 0xa9, 0x02, 0x01, 0x01, 0x31, 0x00, 0x30, 0x82, 0x01, 0x9e,
|
||||
0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0a, 0x01, 0xa0, 0x82, 0x01, 0x8f, 0x30,
|
||||
0x82, 0x01, 0x8b, 0x30, 0x0c, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01,
|
||||
0x01, 0x04, 0x10, 0xfa, 0x55, 0x2c, 0xc2, 0xf6, 0xcc, 0xdd, 0x11, 0x2a, 0x9c, 0x00, 0x14, 0x22,
|
||||
0xec, 0x8f, 0x3b, 0x17, 0x0d, 0x30, 0x38, 0x31, 0x32, 0x31, 0x38, 0x31, 0x31, 0x32, 0x36, 0x34,
|
||||
0x38, 0x5a, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x01, 0x02,
|
||||
0x05, 0x00, 0x30, 0x81, 0xdd, 0x30, 0x81, 0xda, 0x04, 0x0e, 0x68, 0x00, 0x61, 0x00, 0x73, 0x00,
|
||||
0x68, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x31, 0x81, 0xc7, 0x30, 0x61, 0x06, 0x0a, 0x2b,
|
||||
0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0x31, 0x53, 0x30, 0x51, 0x30, 0x2c, 0x06,
|
||||
0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x19, 0xa2, 0x1e, 0x80, 0x1c, 0x00,
|
||||
0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x4f, 0x00, 0x62, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x6c, 0x00,
|
||||
0x65, 0x00, 0x74, 0x00, 0x65, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x3e, 0x30, 0x21, 0x30, 0x09, 0x06,
|
||||
0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0xed, 0xd6, 0x9c, 0x9c, 0xb2, 0xfc,
|
||||
0xaa, 0x03, 0xe8, 0xd3, 0x20, 0xf6, 0xab, 0x28, 0xc3, 0xff, 0xbd, 0x07, 0x36, 0xf5, 0x30, 0x62,
|
||||
0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x02, 0x31, 0x54, 0x30, 0x52,
|
||||
0x1e, 0x4c, 0x00, 0x7b, 0x00, 0x44, 0x00, 0x45, 0x00, 0x33, 0x00, 0x35, 0x00, 0x31, 0x00, 0x41,
|
||||
0x00, 0x34, 0x00, 0x32, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x45, 0x00, 0x35, 0x00, 0x39, 0x00, 0x2d,
|
||||
0x00, 0x31, 0x00, 0x31, 0x00, 0x44, 0x00, 0x30, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x43, 0x00, 0x34,
|
||||
0x00, 0x37, 0x00, 0x2d, 0x00, 0x30, 0x00, 0x30, 0x00, 0x43, 0x00, 0x30, 0x00, 0x34, 0x00, 0x46,
|
||||
0x00, 0x43, 0x00, 0x32, 0x00, 0x39, 0x00, 0x35, 0x00, 0x45, 0x00, 0x45, 0x00, 0x7d, 0x02, 0x02,
|
||||
0x02, 0x00, 0xa0, 0x6a, 0x30, 0x68, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,
|
||||
0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61, 0x00, 0x74, 0x00, 0x74,
|
||||
0x00, 0x72, 0x00, 0x32, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e, 0x76, 0x00, 0x61, 0x00,
|
||||
0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x32, 0x00, 0x00, 0x00, 0x30, 0x32, 0x06, 0x0a, 0x2b, 0x06,
|
||||
0x01, 0x04, 0x01, 0x82, 0x37, 0x0c, 0x02, 0x01, 0x04, 0x24, 0x30, 0x22, 0x1e, 0x0a, 0x00, 0x61,
|
||||
0x00, 0x74, 0x00, 0x74, 0x00, 0x72, 0x00, 0x31, 0x02, 0x04, 0x10, 0x01, 0x00, 0x01, 0x04, 0x0e,
|
||||
0x76, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x65, 0x00, 0x31, 0x00, 0x00, 0x00, 0x31, 0x00,
|
||||
};
|
||||
|
||||
static BOOL (WINAPI * pCryptCATAdminAcquireContext)(HCATADMIN*, const GUID*, DWORD);
|
||||
static BOOL (WINAPI * pCryptCATAdminReleaseContext)(HCATADMIN, DWORD);
|
||||
static BOOL (WINAPI * pCryptCATAdminCalcHashFromFileHandle)(HANDLE hFile, DWORD*, BYTE*, DWORD);
|
||||
static HCATINFO (WINAPI * pCryptCATAdminAddCatalog)(HCATADMIN, PWSTR, PWSTR, DWORD);
|
||||
static BOOL (WINAPI * pCryptCATAdminRemoveCatalog)(HCATADMIN, LPCWSTR, DWORD);
|
||||
static BOOL (WINAPI * pCryptCATAdminReleaseCatalogContext)(HCATADMIN, HCATINFO, DWORD);
|
||||
|
||||
static void InitFunctionPtrs(void)
|
||||
{
|
||||
HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
|
||||
|
||||
#define WINTRUST_GET_PROC(func) \
|
||||
p ## func = (void*)GetProcAddress(hWintrust, #func); \
|
||||
if(!p ## func) { \
|
||||
trace("GetProcAddress(%s) failed\n", #func); \
|
||||
}
|
||||
|
||||
WINTRUST_GET_PROC(CryptCATAdminAcquireContext)
|
||||
WINTRUST_GET_PROC(CryptCATAdminReleaseContext)
|
||||
WINTRUST_GET_PROC(CryptCATAdminCalcHashFromFileHandle)
|
||||
WINTRUST_GET_PROC(CryptCATAdminAddCatalog)
|
||||
WINTRUST_GET_PROC(CryptCATAdminRemoveCatalog)
|
||||
WINTRUST_GET_PROC(CryptCATAdminReleaseCatalogContext)
|
||||
|
||||
#undef WINTRUST_GET_PROC
|
||||
}
|
||||
|
||||
static GUID dummy = {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
|
||||
|
||||
static void test_context(void)
|
||||
{
|
||||
BOOL ret;
|
||||
HCATADMIN hca;
|
||||
static GUID unknown = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */
|
||||
CHAR windir[MAX_PATH], catroot[MAX_PATH], catroot2[MAX_PATH], dummydir[MAX_PATH];
|
||||
DWORD attrs;
|
||||
|
||||
/* When CryptCATAdminAcquireContext is successful it will create
|
||||
* several directories if they don't exist:
|
||||
*
|
||||
* ...\system32\CatRoot\{GUID}, this directory holds the .cat files
|
||||
* ...\system32\CatRoot2\{GUID} (WinXP and up), here we find the catalog database for that GUID
|
||||
*
|
||||
* Windows Vista uses lowercase catroot and catroot2.
|
||||
*
|
||||
* When passed a NULL GUID it will create the following directories although on
|
||||
* WinXP and up these directories are already present when Windows is installed:
|
||||
*
|
||||
* ...\system32\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE}
|
||||
* ...\system32\CatRoot2\{127D0A1D-4EF2-11D1-8608-00C04FC295EE} (WinXP up)
|
||||
*
|
||||
* TODO: Find out what this GUID is/does.
|
||||
*
|
||||
* On WinXP and up there is also a TimeStamp file in some of directories that
|
||||
* seem to indicate the last change to the catalog database for that GUID.
|
||||
*
|
||||
* On Windows 2000 some files are created/updated:
|
||||
*
|
||||
* ...\system32\CatRoot\SYSMAST.cbk
|
||||
* ...\system32\CatRoot\SYSMAST.cbd
|
||||
* ...\system32\CatRoot\{GUID}\CATMAST.cbk
|
||||
* ...\system32\CatRoot\{GUID}\CATMAST.cbd
|
||||
*
|
||||
*/
|
||||
|
||||
/* All NULL */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminAcquireContext(NULL, NULL, 0);
|
||||
ok(!ret, "Expected failure\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
|
||||
/* NULL GUID */
|
||||
ret = pCryptCATAdminAcquireContext(&hca, NULL, 0);
|
||||
ok(ret, "Expected success\n");
|
||||
ok(hca != NULL, "Expected a context handle, got NULL\n");
|
||||
|
||||
/* All NULL */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminReleaseContext(NULL, 0);
|
||||
ok(!ret, "Expected failure\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
|
||||
/* Proper release */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminReleaseContext(hca, 0);
|
||||
ok(ret, "Expected success\n");
|
||||
ok(GetLastError() == 0xdeadbeef,
|
||||
"Expected no change in last error, got %d\n", GetLastError());
|
||||
|
||||
/* Try to release a second time */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminReleaseContext(hca, 0);
|
||||
ok(!ret, "Expected failure\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
|
||||
/* NULL context handle and dummy GUID */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminAcquireContext(NULL, &dummy, 0);
|
||||
ok(!ret, "Expected failure\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
|
||||
/* Correct context handle and dummy GUID
|
||||
*
|
||||
* The tests run in the past unfortunately made sure that some directories were created.
|
||||
*
|
||||
* FIXME:
|
||||
* We don't want to mess too much with these for now so we should delete only the ones
|
||||
* that shouldn't be there like the deadbeef ones. We first have to figure out if it's
|
||||
* save to remove files and directories from CatRoot/CatRoot2.
|
||||
*/
|
||||
|
||||
ret = pCryptCATAdminAcquireContext(&hca, &dummy, 0);
|
||||
ok(ret, "Expected success\n");
|
||||
ok(hca != NULL, "Expected a context handle, got NULL\n");
|
||||
|
||||
GetWindowsDirectoryA(windir, MAX_PATH);
|
||||
lstrcpyA(catroot, windir);
|
||||
lstrcatA(catroot, "\\system32\\CatRoot");
|
||||
lstrcpyA(catroot2, windir);
|
||||
lstrcatA(catroot2, "\\system32\\CatRoot2");
|
||||
|
||||
attrs = GetFileAttributes(catroot);
|
||||
ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected the CatRoot directory to exist\n");
|
||||
|
||||
/* Windows creates the GUID directory in capitals */
|
||||
lstrcpyA(dummydir, catroot);
|
||||
lstrcatA(dummydir, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}");
|
||||
attrs = GetFileAttributes(dummydir);
|
||||
ok(attrs != INVALID_FILE_ATTRIBUTES,
|
||||
"Expected CatRoot\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n");
|
||||
|
||||
/* Only present on XP or higher. */
|
||||
attrs = GetFileAttributes(catroot2);
|
||||
if (attrs != INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
lstrcpyA(dummydir, catroot2);
|
||||
lstrcatA(dummydir, "\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}");
|
||||
attrs = GetFileAttributes(dummydir);
|
||||
ok(attrs != INVALID_FILE_ATTRIBUTES,
|
||||
"Expected CatRoot2\\{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF} directory to exist\n");
|
||||
}
|
||||
|
||||
ret = pCryptCATAdminReleaseContext(hca, 0);
|
||||
ok(ret, "Expected success\n");
|
||||
|
||||
/* Correct context handle and GUID */
|
||||
ret = pCryptCATAdminAcquireContext(&hca, &unknown, 0);
|
||||
ok(ret, "Expected success\n");
|
||||
ok(hca != NULL, "Expected a context handle, got NULL\n");
|
||||
|
||||
ret = pCryptCATAdminReleaseContext(hca, 0);
|
||||
ok(ret, "Expected success\n");
|
||||
|
||||
/* Flags not equal to 0 */
|
||||
ret = pCryptCATAdminAcquireContext(&hca, &unknown, 1);
|
||||
ok(ret, "Expected success\n");
|
||||
ok(hca != NULL, "Expected a context handle, got NULL\n");
|
||||
|
||||
ret = pCryptCATAdminReleaseContext(hca, 0);
|
||||
ok(ret, "Expected success\n");
|
||||
}
|
||||
|
||||
/* TODO: Check whether SHA-1 is the algorithm that's always used */
|
||||
static void test_calchash(void)
|
||||
{
|
||||
BOOL ret;
|
||||
HANDLE file;
|
||||
DWORD hashsize = 0;
|
||||
BYTE* hash;
|
||||
BYTE expectedhash[20] = {0x3a,0xa1,0x19,0x08,0xec,0xa6,0x0d,0x2e,0x7e,0xcc,0x7a,0xca,0xf5,0xb8,0x2e,0x62,0x6a,0xda,0xf0,0x19};
|
||||
CHAR temp[MAX_PATH];
|
||||
DWORD written;
|
||||
|
||||
/* All NULL */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminCalcHashFromFileHandle(NULL, NULL, NULL, 0);
|
||||
ok(!ret, "Expected failure\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
|
||||
/* NULL filehandle, rest is legal */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminCalcHashFromFileHandle(NULL, &hashsize, NULL, 0);
|
||||
ok(!ret, "Expected failure\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
|
||||
/* Correct filehandle, rest is NULL */
|
||||
file = CreateFileA(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminCalcHashFromFileHandle(file, NULL, NULL, 0);
|
||||
ok(!ret, "Expected failure\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
CloseHandle(file);
|
||||
|
||||
/* All OK, but dwFlags set to 1 */
|
||||
file = CreateFileA(selfname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 1);
|
||||
ok(!ret, "Expected failure\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
CloseHandle(file);
|
||||
|
||||
/* All OK, requesting the size of the hash */
|
||||
file = CreateFileA(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
ok(file != INVALID_HANDLE_VALUE, "CreateFile failed %u\n", GetLastError());
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0);
|
||||
ok(ret, "Expected success %u\n", GetLastError());
|
||||
ok(hashsize == 20," Expected a hash size of 20, got %d\n", hashsize);
|
||||
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
||||
"Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
|
||||
CloseHandle(file);
|
||||
|
||||
/* All OK, retrieve the hash
|
||||
* Double the hash buffer to see what happens to the size parameter
|
||||
*/
|
||||
file = CreateFileA(selfname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
hashsize *= 2;
|
||||
hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, hash, 0);
|
||||
ok(ret, "Expected success %u\n", GetLastError());
|
||||
ok(hashsize == 20," Expected a hash size of 20, got %d\n", hashsize);
|
||||
ok(GetLastError() == ERROR_SUCCESS,
|
||||
"Expected ERROR_SUCCESS, got %d\n", GetLastError());
|
||||
CloseHandle(file);
|
||||
HeapFree(GetProcessHeap(), 0, hash);
|
||||
|
||||
/* Do the same test with a file created and filled by ourselves (and we thus
|
||||
* have a known hash for).
|
||||
*/
|
||||
GetTempFileNameA(CURR_DIR, "hsh", 0, temp);
|
||||
file = CreateFileA(temp, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
WriteFile(file, "Text in this file is needed to create a know hash", 49, &written, NULL);
|
||||
CloseHandle(file);
|
||||
|
||||
/* All OK, first request the size and then retrieve the hash */
|
||||
file = CreateFileA(temp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
hashsize = 0;
|
||||
pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, NULL, 0);
|
||||
hash = HeapAlloc(GetProcessHeap(), 0, hashsize);
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptCATAdminCalcHashFromFileHandle(file, &hashsize, hash, 0);
|
||||
ok(ret, "Expected success\n");
|
||||
ok(GetLastError() == ERROR_SUCCESS,
|
||||
"Expected ERROR_SUCCESS, got %d\n", GetLastError());
|
||||
ok(hashsize == sizeof(expectedhash) &&
|
||||
!memcmp(hash, expectedhash, sizeof(expectedhash)),
|
||||
"Hashes didn't match\n");
|
||||
CloseHandle(file);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, hash);
|
||||
DeleteFileA(temp);
|
||||
}
|
||||
|
||||
static void test_CryptCATAdminAddRemoveCatalog(void)
|
||||
{
|
||||
static WCHAR basenameW[] = {'w','i','n','e','t','e','s','t','.','c','a','t',0};
|
||||
HCATADMIN hcatadmin;
|
||||
HCATINFO hcatinfo;
|
||||
WCHAR tmpfileW[MAX_PATH];
|
||||
char tmpfile[MAX_PATH];
|
||||
HANDLE file;
|
||||
DWORD error, written;
|
||||
BOOL ret;
|
||||
|
||||
if (!pCryptCATAdminRemoveCatalog)
|
||||
{
|
||||
/* NT4 and W2K do have CryptCATAdminAddCatalog !! */
|
||||
win_skip("CryptCATAdminRemoveCatalog is not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GetTempFileNameA(CURR_DIR, "cat", 0, tmpfile)) return;
|
||||
DeleteFileA(tmpfile);
|
||||
file = CreateFileA(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
||||
ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError());
|
||||
CloseHandle(file);
|
||||
|
||||
ret = pCryptCATAdminAcquireContext(&hcatadmin, &dummy, 0);
|
||||
ok(ret, "CryptCATAdminAcquireContext failed %u\n", GetLastError());
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
hcatinfo = pCryptCATAdminAddCatalog(NULL, NULL, NULL, 0);
|
||||
error = GetLastError();
|
||||
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
|
||||
ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMTER\n", GetLastError());
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, NULL, NULL, 0);
|
||||
error = GetLastError();
|
||||
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
|
||||
ok(error == ERROR_INVALID_PARAMETER, "got %u expected INVALID_PARAMTER\n", GetLastError());
|
||||
|
||||
MultiByteToWideChar(0, 0, tmpfile, -1, tmpfileW, MAX_PATH);
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0);
|
||||
error = GetLastError();
|
||||
todo_wine {
|
||||
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
|
||||
ok(error == ERROR_BAD_FORMAT, "got %u expected ERROR_BAD_FORMAT\n", GetLastError());
|
||||
}
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 1);
|
||||
error = GetLastError();
|
||||
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
|
||||
ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMTER\n", GetLastError());
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0);
|
||||
error = GetLastError();
|
||||
ok(hcatinfo == NULL, "CryptCATAdminAddCatalog succeeded\n");
|
||||
todo_wine ok(error == ERROR_BAD_FORMAT, "got %u expected ERROR_BAD_FORMAT\n", GetLastError());
|
||||
|
||||
DeleteFileA(tmpfile);
|
||||
file = CreateFileA(tmpfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
||||
ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %u\n", GetLastError());
|
||||
WriteFile(file, test_catalog, sizeof(test_catalog), &written, NULL);
|
||||
CloseHandle(file);
|
||||
|
||||
hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, NULL, 0);
|
||||
todo_wine ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
|
||||
|
||||
hcatinfo = pCryptCATAdminAddCatalog(hcatadmin, tmpfileW, basenameW, 0);
|
||||
ok(hcatinfo != NULL, "CryptCATAdminAddCatalog failed %u\n", GetLastError());
|
||||
|
||||
ret = pCryptCATAdminReleaseCatalogContext(hcatadmin, hcatinfo, 0);
|
||||
ok(ret, "CryptCATAdminReleaseCatalogContext failed %u\n", GetLastError());
|
||||
|
||||
ret = pCryptCATAdminRemoveCatalog(hcatadmin, tmpfileW, 0);
|
||||
ok(ret, "CryptCATAdminRemoveCatalog failed %u\n", GetLastError());
|
||||
|
||||
ret = pCryptCATAdminReleaseContext(hcatadmin, 0);
|
||||
ok(ret, "CryptCATAdminReleaseContext failed %u\n", GetLastError());
|
||||
|
||||
DeleteFileA(tmpfile);
|
||||
}
|
||||
|
||||
START_TEST(crypt)
|
||||
{
|
||||
int myARGC;
|
||||
char** myARGV;
|
||||
|
||||
InitFunctionPtrs();
|
||||
|
||||
if (!pCryptCATAdminAcquireContext)
|
||||
{
|
||||
win_skip("CryptCATAdmin functions are not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
myARGC = winetest_get_mainargs(&myARGV);
|
||||
strcpy(selfname, myARGV[0]);
|
||||
|
||||
GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
|
||||
|
||||
test_context();
|
||||
test_calchash();
|
||||
test_CryptCATAdminAddRemoveCatalog();
|
||||
}
|
359
rostests/winetests/wintrust/register.c
Normal file
359
rostests/winetests/wintrust/register.c
Normal file
|
@ -0,0 +1,359 @@
|
|||
/* Unit test suite for wintrust API functions
|
||||
*
|
||||
* Copyright 2006 Paul Vriens
|
||||
*
|
||||
* 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 <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "windows.h"
|
||||
#include "softpub.h"
|
||||
#include "wintrust.h"
|
||||
#include "winreg.h"
|
||||
|
||||
#include "wine/test.h"
|
||||
|
||||
static BOOL (WINAPI * pWintrustAddActionID)(GUID*, DWORD, CRYPT_REGISTER_ACTIONID*);
|
||||
static BOOL (WINAPI * pWintrustAddDefaultForUsage)(const CHAR*,CRYPT_PROVIDER_REGDEFUSAGE*);
|
||||
static void (WINAPI * pWintrustGetRegPolicyFlags)(DWORD *);
|
||||
static BOOL (WINAPI * pWintrustLoadFunctionPointers)(GUID *, CRYPT_PROVIDER_FUNCTIONS *);
|
||||
static BOOL (WINAPI * pWintrustRemoveActionID)(GUID*);
|
||||
static BOOL (WINAPI * pWintrustSetRegPolicyFlags)(DWORD);
|
||||
|
||||
static void InitFunctionPtrs(void)
|
||||
{
|
||||
HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
|
||||
|
||||
#define WINTRUST_GET_PROC(func) \
|
||||
p ## func = (void*)GetProcAddress(hWintrust, #func); \
|
||||
if(!p ## func) \
|
||||
trace("GetProcAddress(%s) failed\n", #func);
|
||||
|
||||
WINTRUST_GET_PROC(WintrustAddActionID)
|
||||
WINTRUST_GET_PROC(WintrustAddDefaultForUsage)
|
||||
WINTRUST_GET_PROC(WintrustGetRegPolicyFlags)
|
||||
WINTRUST_GET_PROC(WintrustLoadFunctionPointers)
|
||||
WINTRUST_GET_PROC(WintrustRemoveActionID)
|
||||
WINTRUST_GET_PROC(WintrustSetRegPolicyFlags)
|
||||
|
||||
#undef WINTRUST_GET_PROC
|
||||
}
|
||||
|
||||
static void test_AddRem_ActionID(void)
|
||||
{
|
||||
static WCHAR DummyDllW[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
|
||||
static WCHAR DummyFunctionW[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
|
||||
GUID ActionID = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
|
||||
CRYPT_REGISTER_ACTIONID ActionIDFunctions;
|
||||
CRYPT_TRUST_REG_ENTRY EmptyProvider = { 0, NULL, NULL };
|
||||
CRYPT_TRUST_REG_ENTRY DummyProvider = { sizeof(CRYPT_TRUST_REG_ENTRY), DummyDllW, DummyFunctionW };
|
||||
BOOL ret;
|
||||
|
||||
if (!pWintrustAddActionID || !pWintrustRemoveActionID)
|
||||
{
|
||||
skip("WintrustAddActionID and/or WintrustRemoveActionID are not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* All NULL */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddActionID(NULL, 0, NULL);
|
||||
ok (!ret, "Expected WintrustAddActionID to fail.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
|
||||
GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
|
||||
"Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %u.\n", GetLastError());
|
||||
|
||||
/* NULL functions */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddActionID(&ActionID, 0, NULL);
|
||||
ok (!ret, "Expected WintrustAddActionID to fail.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
|
||||
GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
|
||||
"Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %u.\n", GetLastError());
|
||||
|
||||
/* All OK (although no functions defined), except cbStruct is not set in ActionIDFunctions */
|
||||
SetLastError(0xdeadbeef);
|
||||
memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
|
||||
ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
|
||||
ok (!ret, "Expected WintrustAddActionID to fail.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
|
||||
GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
|
||||
"Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %u.\n", GetLastError());
|
||||
|
||||
/* All OK (although no functions defined) and cbStruct is set now */
|
||||
SetLastError(0xdeadbeef);
|
||||
memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
|
||||
ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
|
||||
ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
|
||||
ok (ret, "Expected WintrustAddActionID to succeed.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
|
||||
|
||||
/* All OK and all (but 1) functions are correctly defined. The DLL and entrypoints
|
||||
* are not present.
|
||||
*/
|
||||
memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
|
||||
ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
|
||||
ActionIDFunctions.sInitProvider = DummyProvider;
|
||||
ActionIDFunctions.sObjectProvider = DummyProvider;
|
||||
ActionIDFunctions.sSignatureProvider = EmptyProvider;
|
||||
ActionIDFunctions.sCertificateProvider = DummyProvider;
|
||||
ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
|
||||
ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
|
||||
ActionIDFunctions.sTestPolicyProvider = DummyProvider;
|
||||
ActionIDFunctions.sCleanupProvider = DummyProvider;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
|
||||
ok (ret, "Expected WintrustAddActionID to succeed.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
|
||||
|
||||
/* All OK and all functions are correctly defined. The DLL and entrypoints
|
||||
* are not present.
|
||||
*/
|
||||
memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
|
||||
ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
|
||||
ActionIDFunctions.sInitProvider = DummyProvider;
|
||||
ActionIDFunctions.sObjectProvider = DummyProvider;
|
||||
ActionIDFunctions.sSignatureProvider = DummyProvider;
|
||||
ActionIDFunctions.sCertificateProvider = DummyProvider;
|
||||
ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
|
||||
ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
|
||||
ActionIDFunctions.sTestPolicyProvider = DummyProvider;
|
||||
ActionIDFunctions.sCleanupProvider = DummyProvider;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
|
||||
ok (ret, "Expected WintrustAddActionID to succeed.\n");
|
||||
ok (GetLastError() == 0xdeadbeef,
|
||||
"Expected 0xdeadbeef, got %u.\n", GetLastError());
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustRemoveActionID(&ActionID);
|
||||
ok ( ret, "WintrustRemoveActionID failed : %d\n", GetLastError());
|
||||
ok ( GetLastError() == 0xdeadbeef, "Last error should not have been changed: %u\n", GetLastError());
|
||||
|
||||
/* NULL input */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustRemoveActionID(NULL);
|
||||
ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
|
||||
|
||||
/* The passed GUID is removed by a previous call, so it's basically a test with a nonexistent Trust provider */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustRemoveActionID(&ActionID);
|
||||
ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
|
||||
ok (GetLastError() == 0xdeadbeef,
|
||||
"Expected 0xdeadbeef, got %u.\n", GetLastError());
|
||||
}
|
||||
|
||||
static void test_AddDefaultForUsage(void)
|
||||
{
|
||||
BOOL ret;
|
||||
LONG res;
|
||||
static GUID ActionID = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
|
||||
static WCHAR DummyDllW[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
|
||||
static CHAR DummyFunction[] = "dummyfunction";
|
||||
static const CHAR oid[] = "1.2.3.4.5.6.7.8.9.10";
|
||||
static const CHAR Usages[] = "SOFTWARE\\Microsoft\\Cryptography\\Providers\\Trust\\Usages\\1.2.3.4.5.6.7.8.9.10";
|
||||
static CRYPT_PROVIDER_REGDEFUSAGE DefUsage;
|
||||
|
||||
if (!pWintrustAddDefaultForUsage)
|
||||
{
|
||||
skip("WintrustAddDefaultForUsage is not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* All NULL */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddDefaultForUsage(NULL, NULL);
|
||||
ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
|
||||
|
||||
/* NULL defusage */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddDefaultForUsage(oid, NULL);
|
||||
ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
|
||||
|
||||
/* NULL oid and proper defusage */
|
||||
memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
|
||||
DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
|
||||
DefUsage.pgActionID = &ActionID;
|
||||
DefUsage.pwszDllName = DummyDllW;
|
||||
DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
|
||||
DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddDefaultForUsage(NULL, &DefUsage);
|
||||
ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
|
||||
|
||||
/* Just the ActionID */
|
||||
memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
|
||||
DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
|
||||
DefUsage.pgActionID = &ActionID;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
|
||||
ok ( ret, "Expected WintrustAddDefaultForUsage to succeed\n");
|
||||
ok (GetLastError() == 0xdeadbeef,
|
||||
"Last error should not have been changed: %u\n", GetLastError());
|
||||
|
||||
/* No ActionID */
|
||||
memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
|
||||
DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
|
||||
DefUsage.pwszDllName = DummyDllW;
|
||||
DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
|
||||
DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
|
||||
ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
|
||||
ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
|
||||
|
||||
/* cbStruct set to 0 */
|
||||
memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
|
||||
DefUsage.cbStruct = 0;
|
||||
DefUsage.pgActionID = &ActionID;
|
||||
DefUsage.pwszDllName = DummyDllW;
|
||||
DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
|
||||
DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
|
||||
ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
|
||||
ok (GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
|
||||
|
||||
/* All OK */
|
||||
memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
|
||||
DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
|
||||
DefUsage.pgActionID = &ActionID;
|
||||
DefUsage.pwszDllName = DummyDllW;
|
||||
DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
|
||||
DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
|
||||
ok ( ret, "Expected WintrustAddDefaultForUsage to succeed\n");
|
||||
ok (GetLastError() == 0xdeadbeef,
|
||||
"Last error should not have been changed: %u\n", GetLastError());
|
||||
|
||||
/* There is no corresponding remove for WintrustAddDefaultForUsage
|
||||
* so we delete the registry key manually.
|
||||
*/
|
||||
if (ret)
|
||||
{
|
||||
res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, Usages);
|
||||
ok (res == ERROR_SUCCESS, "Key delete failed : 0x%08x\n", res);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_LoadFunctionPointers(void)
|
||||
{
|
||||
BOOL ret;
|
||||
CRYPT_PROVIDER_FUNCTIONS funcs;
|
||||
GUID action = WINTRUST_ACTION_GENERIC_VERIFY_V2;
|
||||
|
||||
if (!pWintrustLoadFunctionPointers)
|
||||
{
|
||||
skip("WintrustLoadFunctionPointers is not available\n");
|
||||
return;
|
||||
}
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustLoadFunctionPointers(NULL, NULL);
|
||||
ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustLoadFunctionPointers(&action, NULL);
|
||||
ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWintrustLoadFunctionPointers(NULL, &funcs);
|
||||
ok(!ret, "WintrustLoadFunctionPointers succeeded\n");
|
||||
ok(GetLastError() == ERROR_INVALID_PARAMETER ||
|
||||
GetLastError() == 0xdeadbeef /* W2K and XP-SP1 */,
|
||||
"Expected ERROR_INVALID_PARAMETER or 0xdeadbeef, got %d\n", GetLastError());
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
funcs.cbStruct = 0;
|
||||
ret = pWintrustLoadFunctionPointers(&action, &funcs);
|
||||
ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
|
||||
SetLastError(0xdeadbeef);
|
||||
funcs.cbStruct = sizeof(funcs);
|
||||
ret = pWintrustLoadFunctionPointers(&action, &funcs);
|
||||
ok(ret, "WintrustLoadFunctionPointers failed: %d\n", GetLastError());
|
||||
ok(funcs.pfnAlloc != NULL, "Expected a pointer\n");
|
||||
ok(funcs.pfnFree != NULL, "Expected a pointer\n");
|
||||
}
|
||||
|
||||
static void test_RegPolicyFlags(void)
|
||||
{
|
||||
/* Default state value 0x00023c00, which is
|
||||
* WTPF_IGNOREREVOCATIONONTS |
|
||||
* WTPF_OFFLINEOKNBU_COM |
|
||||
* WTPF_OFFLINEOKNBU_IND |
|
||||
* WTPF_OFFLINEOK_COM |
|
||||
* WTPF_OFFLINEOK_IND
|
||||
*/
|
||||
static const CHAR Software_Publishing[] =
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Wintrust\\"
|
||||
"Trust Providers\\Software Publishing";
|
||||
static const CHAR State[] = "State";
|
||||
HKEY key;
|
||||
LONG r;
|
||||
DWORD flags1, flags2, flags3, size;
|
||||
BOOL ret;
|
||||
|
||||
if (!pWintrustGetRegPolicyFlags || !pWintrustSetRegPolicyFlags)
|
||||
{
|
||||
skip("Policy flags functions not present\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pWintrustGetRegPolicyFlags(&flags2);
|
||||
|
||||
r = RegOpenKeyExA(HKEY_CURRENT_USER, Software_Publishing, 0, KEY_ALL_ACCESS,
|
||||
&key);
|
||||
ok(!r, "RegOpenKeyEx failed: %d\n", r);
|
||||
|
||||
size = sizeof(flags1);
|
||||
r = RegQueryValueExA(key, State, NULL, NULL, (LPBYTE)&flags1, &size);
|
||||
ok(!r, "RegQueryValueEx failed: %d\n", r);
|
||||
|
||||
ok(flags1 == flags2, "Got %08x flags instead of %08x\n", flags1, flags2);
|
||||
|
||||
flags3 = flags2 | 1;
|
||||
ret = pWintrustSetRegPolicyFlags(flags3);
|
||||
ok(ret, "WintrustSetRegPolicyFlags failed: %d\n", GetLastError());
|
||||
size = sizeof(flags1);
|
||||
r = RegQueryValueExA(key, State, NULL, NULL, (LPBYTE)&flags1, &size);
|
||||
ok(flags1 == flags3, "Got %08x flags instead of %08x\n", flags1, flags3);
|
||||
|
||||
pWintrustSetRegPolicyFlags(flags2);
|
||||
|
||||
RegCloseKey(key);
|
||||
}
|
||||
|
||||
START_TEST(register)
|
||||
{
|
||||
InitFunctionPtrs();
|
||||
|
||||
test_AddRem_ActionID();
|
||||
test_AddDefaultForUsage();
|
||||
test_LoadFunctionPointers();
|
||||
test_RegPolicyFlags();
|
||||
}
|
540
rostests/winetests/wintrust/softpub.c
Normal file
540
rostests/winetests/wintrust/softpub.c
Normal file
|
@ -0,0 +1,540 @@
|
|||
/*
|
||||
* wintrust softpub functions tests
|
||||
*
|
||||
* Copyright 2007 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 <wintrust.h>
|
||||
#include <softpub.h>
|
||||
#include <mssip.h>
|
||||
#include <winuser.h>
|
||||
#include "winnls.h"
|
||||
|
||||
#include "wine/test.h"
|
||||
|
||||
/* Just in case we're being built with borked headers, redefine function
|
||||
* pointers to have the correct calling convention.
|
||||
*/
|
||||
typedef void *(WINAPI *SAFE_MEM_ALLOC)(DWORD);
|
||||
typedef void (WINAPI *SAFE_MEM_FREE)(void *);
|
||||
typedef BOOL (WINAPI *SAFE_ADD_STORE)(CRYPT_PROVIDER_DATA *,
|
||||
HCERTSTORE);
|
||||
typedef BOOL (WINAPI *SAFE_ADD_SGNR)(CRYPT_PROVIDER_DATA *,
|
||||
BOOL, DWORD, struct _CRYPT_PROVIDER_SGNR *);
|
||||
typedef BOOL (WINAPI *SAFE_ADD_CERT)(CRYPT_PROVIDER_DATA *,
|
||||
DWORD, BOOL, DWORD, PCCERT_CONTEXT);
|
||||
typedef BOOL (WINAPI *SAFE_ADD_PRIVDATA)(CRYPT_PROVIDER_DATA *,
|
||||
CRYPT_PROVIDER_PRIVDATA *);
|
||||
typedef HRESULT (WINAPI *SAFE_PROVIDER_INIT_CALL)(CRYPT_PROVIDER_DATA *);
|
||||
typedef HRESULT (WINAPI *SAFE_PROVIDER_OBJTRUST_CALL)(CRYPT_PROVIDER_DATA *);
|
||||
typedef HRESULT (WINAPI *SAFE_PROVIDER_SIGTRUST_CALL)(CRYPT_PROVIDER_DATA *);
|
||||
typedef HRESULT (WINAPI *SAFE_PROVIDER_CERTTRUST_CALL)(CRYPT_PROVIDER_DATA *);
|
||||
typedef HRESULT (WINAPI *SAFE_PROVIDER_FINALPOLICY_CALL)(CRYPT_PROVIDER_DATA *);
|
||||
typedef HRESULT (WINAPI *SAFE_PROVIDER_TESTFINALPOLICY_CALL)(
|
||||
CRYPT_PROVIDER_DATA *);
|
||||
typedef HRESULT (WINAPI *SAFE_PROVIDER_CLEANUP_CALL)(CRYPT_PROVIDER_DATA *);
|
||||
typedef BOOL (WINAPI *SAFE_PROVIDER_CERTCHKPOLICY_CALL)(
|
||||
CRYPT_PROVIDER_DATA *, DWORD, BOOL, DWORD);
|
||||
|
||||
typedef struct _SAFE_PROVIDER_FUNCTIONS
|
||||
{
|
||||
DWORD cbStruct;
|
||||
SAFE_MEM_ALLOC pfnAlloc;
|
||||
SAFE_MEM_FREE pfnFree;
|
||||
SAFE_ADD_STORE pfnAddStore2Chain;
|
||||
SAFE_ADD_SGNR pfnAddSgnr2Chain;
|
||||
SAFE_ADD_CERT pfnAddCert2Chain;
|
||||
SAFE_ADD_PRIVDATA pfnAddPrivData2Chain;
|
||||
SAFE_PROVIDER_INIT_CALL pfnInitialize;
|
||||
SAFE_PROVIDER_OBJTRUST_CALL pfnObjectTrust;
|
||||
SAFE_PROVIDER_SIGTRUST_CALL pfnSignatureTrust;
|
||||
SAFE_PROVIDER_CERTTRUST_CALL pfnCertificateTrust;
|
||||
SAFE_PROVIDER_FINALPOLICY_CALL pfnFinalPolicy;
|
||||
SAFE_PROVIDER_CERTCHKPOLICY_CALL pfnCertCheckPolicy;
|
||||
SAFE_PROVIDER_TESTFINALPOLICY_CALL pfnTestFinalPolicy;
|
||||
struct _CRYPT_PROVUI_FUNCS *psUIpfns;
|
||||
SAFE_PROVIDER_CLEANUP_CALL pfnCleanupPolicy;
|
||||
} SAFE_PROVIDER_FUNCTIONS;
|
||||
|
||||
static const BYTE v1CertWithPubKey[] = {
|
||||
0x30,0x81,0x95,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13,0x30,
|
||||
0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,
|
||||
0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
|
||||
0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
|
||||
0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30,0x11,
|
||||
0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
|
||||
0x67,0x00,0x30,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
|
||||
0x01,0x01,0x05,0x00,0x03,0x11,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
|
||||
0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xa3,0x16,0x30,0x14,0x30,0x12,0x06,
|
||||
0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02,
|
||||
0x01,0x01 };
|
||||
|
||||
static void test_utils(SAFE_PROVIDER_FUNCTIONS *funcs)
|
||||
{
|
||||
CRYPT_PROVIDER_DATA data = { 0 };
|
||||
HCERTSTORE store;
|
||||
CRYPT_PROVIDER_SGNR sgnr = { 0 };
|
||||
BOOL ret;
|
||||
|
||||
/* Crash
|
||||
ret = funcs->pfnAddStore2Chain(NULL, NULL);
|
||||
ret = funcs->pfnAddStore2Chain(&data, NULL);
|
||||
*/
|
||||
store = CertOpenStore(CERT_STORE_PROV_MEMORY, X509_ASN_ENCODING, 0,
|
||||
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
||||
if (store)
|
||||
{
|
||||
ret = funcs->pfnAddStore2Chain(&data, store);
|
||||
ok(ret, "pfnAddStore2Chain failed: %08x\n", GetLastError());
|
||||
ok(data.chStores == 1, "Expected 1 store, got %d\n", data.chStores);
|
||||
ok(data.pahStores != NULL, "Expected pahStores to be allocated\n");
|
||||
if (data.pahStores)
|
||||
{
|
||||
ok(data.pahStores[0] == store, "Unexpected store\n");
|
||||
CertCloseStore(data.pahStores[0], 0);
|
||||
funcs->pfnFree(data.pahStores);
|
||||
data.pahStores = NULL;
|
||||
data.chStores = 0;
|
||||
CertCloseStore(store, 0);
|
||||
store = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
skip("CertOpenStore failed: %08x\n", GetLastError());
|
||||
|
||||
/* Crash
|
||||
ret = funcs->pfnAddSgnr2Chain(NULL, FALSE, 0, NULL);
|
||||
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, NULL);
|
||||
*/
|
||||
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
|
||||
ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
|
||||
ok(data.csSigners == 1, "Expected 1 signer, got %d\n", data.csSigners);
|
||||
ok(data.pasSigners != NULL, "Expected pasSigners to be allocated\n");
|
||||
if (data.pasSigners)
|
||||
{
|
||||
PCCERT_CONTEXT cert;
|
||||
|
||||
ok(!memcmp(&data.pasSigners[0], &sgnr, sizeof(sgnr)),
|
||||
"Unexpected data in signer\n");
|
||||
/* Adds into the location specified by the index */
|
||||
sgnr.cbStruct = sizeof(CRYPT_PROVIDER_SGNR);
|
||||
sgnr.sftVerifyAsOf.dwLowDateTime = 0xdeadbeef;
|
||||
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 1, &sgnr);
|
||||
ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
|
||||
ok(data.csSigners == 2, "Expected 2 signers, got %d\n", data.csSigners);
|
||||
ok(!memcmp(&data.pasSigners[1], &sgnr, sizeof(sgnr)),
|
||||
"Unexpected data in signer\n");
|
||||
/* This also adds, but the data aren't copied */
|
||||
sgnr.cbStruct = sizeof(DWORD);
|
||||
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
|
||||
ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
|
||||
ok(data.csSigners == 3, "Expected 3 signers, got %d\n", data.csSigners);
|
||||
ok(data.pasSigners[0].cbStruct == 0, "Unexpected data size %d\n",
|
||||
data.pasSigners[0].cbStruct);
|
||||
ok(data.pasSigners[0].sftVerifyAsOf.dwLowDateTime == 0,
|
||||
"Unexpected verify time %d\n",
|
||||
data.pasSigners[0].sftVerifyAsOf.dwLowDateTime);
|
||||
/* But too large a thing isn't added */
|
||||
sgnr.cbStruct = sizeof(sgnr) + sizeof(DWORD);
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
|
||||
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
|
||||
/* Crash
|
||||
ret = funcs->pfnAddCert2Chain(NULL, 0, FALSE, 0, NULL);
|
||||
ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, NULL);
|
||||
*/
|
||||
cert = CertCreateCertificateContext(X509_ASN_ENCODING, v1CertWithPubKey,
|
||||
sizeof(v1CertWithPubKey));
|
||||
if (cert)
|
||||
{
|
||||
/* Notes on behavior that are hard to test:
|
||||
* 1. If pasSigners is invalid, pfnAddCert2Chain crashes
|
||||
* 2. An invalid signer index isn't checked.
|
||||
*/
|
||||
ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, cert);
|
||||
ok(ret, "pfnAddCert2Chain failed: %08x\n", GetLastError());
|
||||
ok(data.pasSigners[0].csCertChain == 1, "Expected 1 cert, got %d\n",
|
||||
data.pasSigners[0].csCertChain);
|
||||
ok(data.pasSigners[0].pasCertChain != NULL,
|
||||
"Expected pasCertChain to be allocated\n");
|
||||
if (data.pasSigners[0].pasCertChain)
|
||||
ok(data.pasSigners[0].pasCertChain[0].pCert == cert,
|
||||
"Unexpected cert\n");
|
||||
CertFreeCertificateContext(cert);
|
||||
}
|
||||
else
|
||||
skip("CertCreateCertificateContext failed: %08x\n", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
static void testInitialize(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
|
||||
{
|
||||
HRESULT ret;
|
||||
CRYPT_PROVIDER_DATA data = { 0 };
|
||||
WINTRUST_DATA wintrust_data = { 0 };
|
||||
|
||||
if (!funcs->pfnInitialize)
|
||||
{
|
||||
skip("missing pfnInitialize\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Crashes
|
||||
ret = funcs->pfnInitialize(NULL);
|
||||
*/
|
||||
memset(&data, 0, sizeof(data));
|
||||
ret = funcs->pfnInitialize(&data);
|
||||
ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
|
||||
data.padwTrustStepErrors =
|
||||
funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
|
||||
/* Without wintrust data set, crashes when padwTrustStepErrors is set */
|
||||
data.pWintrustData = &wintrust_data;
|
||||
if (data.padwTrustStepErrors)
|
||||
{
|
||||
/* Apparently, cdwTrustStepErrors does not need to be set. */
|
||||
ret = funcs->pfnInitialize(&data);
|
||||
ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
|
||||
data.cdwTrustStepErrors = 1;
|
||||
ret = funcs->pfnInitialize(&data);
|
||||
ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
|
||||
memset(data.padwTrustStepErrors, 0xba,
|
||||
TRUSTERROR_MAX_STEPS * sizeof(DWORD));
|
||||
ret = funcs->pfnInitialize(&data);
|
||||
ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
|
||||
data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] = 0;
|
||||
ret = funcs->pfnInitialize(&data);
|
||||
ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
|
||||
funcs->pfnFree(data.padwTrustStepErrors);
|
||||
}
|
||||
}
|
||||
|
||||
static void getNotepadPath(WCHAR *notepadPathW, DWORD size)
|
||||
{
|
||||
static const CHAR notepad[] = "\\notepad.exe";
|
||||
CHAR notepadPath[MAX_PATH];
|
||||
|
||||
/* Workaround missing W-functions for win9x */
|
||||
GetWindowsDirectoryA(notepadPath, MAX_PATH);
|
||||
lstrcatA(notepadPath, notepad);
|
||||
MultiByteToWideChar(0, 0, notepadPath, -1, notepadPathW, size);
|
||||
}
|
||||
|
||||
static void testObjTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
|
||||
{
|
||||
HRESULT ret;
|
||||
CRYPT_PROVIDER_DATA data = { 0 };
|
||||
WINTRUST_DATA wintrust_data = { 0 };
|
||||
WINTRUST_CERT_INFO certInfo = { sizeof(WINTRUST_CERT_INFO), 0 };
|
||||
WINTRUST_FILE_INFO fileInfo = { sizeof(WINTRUST_FILE_INFO), 0 };
|
||||
|
||||
if (!funcs->pfnObjectTrust)
|
||||
{
|
||||
skip("missing pfnObjectTrust\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Crashes
|
||||
ret = funcs->pfnObjectTrust(NULL);
|
||||
*/
|
||||
data.pWintrustData = &wintrust_data;
|
||||
data.padwTrustStepErrors =
|
||||
funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
|
||||
if (data.padwTrustStepErrors)
|
||||
{
|
||||
WCHAR notepadPathW[MAX_PATH];
|
||||
PROVDATA_SIP provDataSIP = { 0 };
|
||||
static const GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
|
||||
0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
|
||||
|
||||
ret = funcs->pfnObjectTrust(&data);
|
||||
ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
|
||||
ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
|
||||
ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %08x\n",
|
||||
data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
|
||||
U(wintrust_data).pCert = &certInfo;
|
||||
wintrust_data.dwUnionChoice = WTD_CHOICE_CERT;
|
||||
ret = funcs->pfnObjectTrust(&data);
|
||||
ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
|
||||
certInfo.psCertContext = (PCERT_CONTEXT)CertCreateCertificateContext(
|
||||
X509_ASN_ENCODING, v1CertWithPubKey, sizeof(v1CertWithPubKey));
|
||||
ret = funcs->pfnObjectTrust(&data);
|
||||
ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
|
||||
CertFreeCertificateContext(certInfo.psCertContext);
|
||||
certInfo.psCertContext = NULL;
|
||||
wintrust_data.dwUnionChoice = WTD_CHOICE_FILE;
|
||||
U(wintrust_data).pFile = NULL;
|
||||
ret = funcs->pfnObjectTrust(&data);
|
||||
ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
|
||||
ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
|
||||
ERROR_INVALID_PARAMETER,
|
||||
"Expected ERROR_INVALID_PARAMETER, got %08x\n",
|
||||
data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
|
||||
U(wintrust_data).pFile = &fileInfo;
|
||||
/* Crashes
|
||||
ret = funcs->pfnObjectTrust(&data);
|
||||
*/
|
||||
getNotepadPath(notepadPathW, MAX_PATH);
|
||||
fileInfo.pcwszFilePath = notepadPathW;
|
||||
/* pfnObjectTrust now crashes unless both pPDSip and psPfns are set */
|
||||
U(data).pPDSip = &provDataSIP;
|
||||
data.psPfns = (CRYPT_PROVIDER_FUNCTIONS *)funcs;
|
||||
ret = funcs->pfnObjectTrust(&data);
|
||||
ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
|
||||
ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
|
||||
TRUST_E_NOSIGNATURE, "Expected TRUST_E_NOSIGNATURE, got %08x\n",
|
||||
data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
|
||||
ok(!memcmp(&provDataSIP.gSubject, &unknown, sizeof(unknown)),
|
||||
"Unexpected subject GUID\n");
|
||||
ok(provDataSIP.pSip != NULL, "Expected a SIP\n");
|
||||
ok(provDataSIP.psSipSubjectInfo != NULL, "Expected a subject info\n");
|
||||
funcs->pfnFree(data.padwTrustStepErrors);
|
||||
}
|
||||
}
|
||||
|
||||
static const BYTE selfSignedCert[] = {
|
||||
0x30, 0x82, 0x01, 0x1f, 0x30, 0x81, 0xce, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02,
|
||||
0x10, 0xeb, 0x0d, 0x57, 0x2a, 0x9c, 0x09, 0xba, 0xa4, 0x4a, 0xb7, 0x25, 0x49,
|
||||
0xd9, 0x3e, 0xb5, 0x73, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1d,
|
||||
0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03,
|
||||
0x13, 0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30,
|
||||
0x1e, 0x17, 0x0d, 0x30, 0x36, 0x30, 0x36, 0x32, 0x39, 0x30, 0x35, 0x30, 0x30,
|
||||
0x34, 0x36, 0x5a, 0x17, 0x0d, 0x30, 0x37, 0x30, 0x36, 0x32, 0x39, 0x31, 0x31,
|
||||
0x30, 0x30, 0x34, 0x36, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
|
||||
0x55, 0x04, 0x03, 0x13, 0x0a, 0x4a, 0x75, 0x61, 0x6e, 0x20, 0x4c, 0x61, 0x6e,
|
||||
0x67, 0x00, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
|
||||
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41,
|
||||
0x00, 0xe2, 0x54, 0x3a, 0xa7, 0x83, 0xb1, 0x27, 0x14, 0x3e, 0x59, 0xbb, 0xb4,
|
||||
0x53, 0xe6, 0x1f, 0xe7, 0x5d, 0xf1, 0x21, 0x68, 0xad, 0x85, 0x53, 0xdb, 0x6b,
|
||||
0x1e, 0xeb, 0x65, 0x97, 0x03, 0x86, 0x60, 0xde, 0xf3, 0x6c, 0x38, 0x75, 0xe0,
|
||||
0x4c, 0x61, 0xbb, 0xbc, 0x62, 0x17, 0xa9, 0xcd, 0x79, 0x3f, 0x21, 0x4e, 0x96,
|
||||
0xcb, 0x0e, 0xdc, 0x61, 0x94, 0x30, 0x18, 0x10, 0x6b, 0xd0, 0x1c, 0x10, 0x79,
|
||||
0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02,
|
||||
0x1d, 0x05, 0x00, 0x03, 0x41, 0x00, 0x25, 0x90, 0x53, 0x34, 0xd9, 0x56, 0x41,
|
||||
0x5e, 0xdb, 0x7e, 0x01, 0x36, 0xec, 0x27, 0x61, 0x5e, 0xb7, 0x4d, 0x90, 0x66,
|
||||
0xa2, 0xe1, 0x9d, 0x58, 0x76, 0xd4, 0x9c, 0xba, 0x2c, 0x84, 0xc6, 0x83, 0x7a,
|
||||
0x22, 0x0d, 0x03, 0x69, 0x32, 0x1a, 0x6d, 0xcb, 0x0c, 0x15, 0xb3, 0x6b, 0xc7,
|
||||
0x0a, 0x8c, 0xb4, 0x5c, 0x34, 0x78, 0xe0, 0x3c, 0x9c, 0xe9, 0xf3, 0x30, 0x9f,
|
||||
0xa8, 0x76, 0x57, 0x92, 0x36 };
|
||||
|
||||
static void testCertTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
|
||||
{
|
||||
CRYPT_PROVIDER_DATA data = { 0 };
|
||||
CRYPT_PROVIDER_SGNR sgnr = { sizeof(sgnr), { 0 } };
|
||||
HRESULT ret;
|
||||
|
||||
data.padwTrustStepErrors =
|
||||
funcs->pfnAlloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
|
||||
if (!data.padwTrustStepErrors)
|
||||
{
|
||||
skip("pfnAlloc failed\n");
|
||||
return;
|
||||
}
|
||||
ret = funcs->pfnCertificateTrust(&data);
|
||||
ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
|
||||
ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV] ==
|
||||
TRUST_E_NOSIGNATURE, "Expected TRUST_E_NOSIGNATURE, got %08x\n",
|
||||
data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV]);
|
||||
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
|
||||
if (ret)
|
||||
{
|
||||
PCCERT_CONTEXT cert;
|
||||
|
||||
/* An empty signer "succeeds," even though there's no cert */
|
||||
ret = funcs->pfnCertificateTrust(&data);
|
||||
ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
|
||||
cert = CertCreateCertificateContext(X509_ASN_ENCODING, selfSignedCert,
|
||||
sizeof(selfSignedCert));
|
||||
if (cert)
|
||||
{
|
||||
WINTRUST_DATA wintrust_data = { 0 };
|
||||
|
||||
ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, cert);
|
||||
/* If pWintrustData isn't set, crashes attempting to access
|
||||
* pWintrustData->fdwRevocationChecks
|
||||
*/
|
||||
data.pWintrustData = &wintrust_data;
|
||||
/* If psPfns isn't set, crashes attempting to access
|
||||
* psPfns->pfnCertCheckPolicy
|
||||
*/
|
||||
data.psPfns = (CRYPT_PROVIDER_FUNCTIONS *)funcs;
|
||||
ret = funcs->pfnCertificateTrust(&data);
|
||||
ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
|
||||
ok(data.csSigners == 1, "Unexpected number of signers %d\n",
|
||||
data.csSigners);
|
||||
ok(data.pasSigners[0].pChainContext != NULL,
|
||||
"Expected a certificate chain\n");
|
||||
ok(data.pasSigners[0].csCertChain == 1,
|
||||
"Unexpected number of chain elements %d\n",
|
||||
data.pasSigners[0].csCertChain);
|
||||
/* pasSigners and pasSigners[0].pasCertChain are guaranteed to be
|
||||
* initialized, see tests for pfnAddSgnr2Chain and pfnAddCert2Chain
|
||||
*/
|
||||
ok(!data.pasSigners[0].pasCertChain[0].fTrustedRoot,
|
||||
"Didn't expect cert to be trusted\n");
|
||||
ok(data.pasSigners[0].pasCertChain[0].fSelfSigned,
|
||||
"Expected cert to be self-signed\n");
|
||||
ok(data.pasSigners[0].pasCertChain[0].dwConfidence ==
|
||||
(CERT_CONFIDENCE_SIG | CERT_CONFIDENCE_TIMENEST),
|
||||
"Expected CERT_CONFIDENCE_SIG | CERT_CONFIDENCE_TIMENEST, got %08x\n",
|
||||
data.pasSigners[0].pasCertChain[0].dwConfidence);
|
||||
CertFreeCertificateContext(cert);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_provider_funcs(void)
|
||||
{
|
||||
static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
|
||||
SAFE_PROVIDER_FUNCTIONS funcs = { sizeof(SAFE_PROVIDER_FUNCTIONS), 0 };
|
||||
BOOL ret;
|
||||
|
||||
ret = WintrustLoadFunctionPointers(&generic_verify_v2,
|
||||
(CRYPT_PROVIDER_FUNCTIONS *)&funcs);
|
||||
if (!ret)
|
||||
skip("WintrustLoadFunctionPointers failed\n");
|
||||
else
|
||||
{
|
||||
test_utils(&funcs);
|
||||
testInitialize(&funcs, &generic_verify_v2);
|
||||
testObjTrust(&funcs, &generic_verify_v2);
|
||||
testCertTrust(&funcs, &generic_verify_v2);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_wintrust(void)
|
||||
{
|
||||
static GUID generic_action_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
|
||||
WINTRUST_DATA wtd;
|
||||
WINTRUST_FILE_INFO file;
|
||||
LONG r;
|
||||
HRESULT hr;
|
||||
WCHAR notepadPathW[MAX_PATH];
|
||||
|
||||
memset(&wtd, 0, sizeof(wtd));
|
||||
wtd.cbStruct = sizeof(wtd);
|
||||
wtd.dwUIChoice = WTD_UI_NONE;
|
||||
wtd.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
|
||||
wtd.dwUnionChoice = WTD_CHOICE_FILE;
|
||||
U(wtd).pFile = &file;
|
||||
wtd.dwStateAction = WTD_STATEACTION_VERIFY;
|
||||
memset(&file, 0, sizeof(file));
|
||||
file.cbStruct = sizeof(file);
|
||||
getNotepadPath(notepadPathW, MAX_PATH);
|
||||
file.pcwszFilePath = notepadPathW;
|
||||
r = WinVerifyTrust(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
|
||||
ok(r == TRUST_E_NOSIGNATURE, "expected TRUST_E_NOSIGNATURE, got %08x\n", r);
|
||||
hr = WinVerifyTrustEx(INVALID_HANDLE_VALUE, &generic_action_v2, &wtd);
|
||||
ok(hr == TRUST_E_NOSIGNATURE, "expected TRUST_E_NOSIGNATURE, got %08x\n",
|
||||
hr);
|
||||
}
|
||||
|
||||
static BOOL (WINAPI * pWTHelperGetKnownUsages)(DWORD action, PCCRYPT_OID_INFO **usages);
|
||||
|
||||
static void InitFunctionPtrs(void)
|
||||
{
|
||||
HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
|
||||
|
||||
#define WINTRUST_GET_PROC(func) \
|
||||
p ## func = (void*)GetProcAddress(hWintrust, #func); \
|
||||
if(!p ## func) { \
|
||||
trace("GetProcAddress(%s) failed\n", #func); \
|
||||
}
|
||||
|
||||
WINTRUST_GET_PROC(WTHelperGetKnownUsages)
|
||||
|
||||
#undef WINTRUST_GET_PROC
|
||||
}
|
||||
|
||||
static void test_get_known_usages(void)
|
||||
{
|
||||
BOOL ret;
|
||||
PCCRYPT_OID_INFO *usages;
|
||||
|
||||
if (!pWTHelperGetKnownUsages)
|
||||
{
|
||||
skip("missing WTHelperGetKnownUsages\n");
|
||||
return;
|
||||
}
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWTHelperGetKnownUsages(0, NULL);
|
||||
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWTHelperGetKnownUsages(1, NULL);
|
||||
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWTHelperGetKnownUsages(0, &usages);
|
||||
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
/* A value of 1 for the first parameter seems to imply the value is
|
||||
* allocated
|
||||
*/
|
||||
SetLastError(0xdeadbeef);
|
||||
usages = NULL;
|
||||
ret = pWTHelperGetKnownUsages(1, &usages);
|
||||
ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
|
||||
ok(usages != NULL, "expected a pointer\n");
|
||||
if (ret && usages)
|
||||
{
|
||||
PCCRYPT_OID_INFO *ptr;
|
||||
|
||||
/* The returned usages are an array of PCCRYPT_OID_INFOs, terminated with a
|
||||
* NULL pointer.
|
||||
*/
|
||||
for (ptr = usages; *ptr; ptr++)
|
||||
{
|
||||
ok((*ptr)->cbSize == sizeof(CRYPT_OID_INFO) ||
|
||||
(*ptr)->cbSize == (sizeof(CRYPT_OID_INFO) + 2 * sizeof(LPCWSTR)), /* Vista */
|
||||
"unexpected size %d\n", (*ptr)->cbSize);
|
||||
/* Each returned usage is in the CRYPT_ENHKEY_USAGE_OID_GROUP_ID group */
|
||||
ok((*ptr)->dwGroupId == CRYPT_ENHKEY_USAGE_OID_GROUP_ID,
|
||||
"expected group CRYPT_ENHKEY_USAGE_OID_GROUP_ID, got %d\n",
|
||||
(*ptr)->dwGroupId);
|
||||
}
|
||||
}
|
||||
/* A value of 2 for the second parameter seems to imply the value is freed
|
||||
*/
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWTHelperGetKnownUsages(2, &usages);
|
||||
ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
|
||||
ok(usages == NULL, "expected pointer to be cleared\n");
|
||||
SetLastError(0xdeadbeef);
|
||||
usages = NULL;
|
||||
ret = pWTHelperGetKnownUsages(2, &usages);
|
||||
ok(ret, "WTHelperGetKnownUsages failed: %d\n", GetLastError());
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = pWTHelperGetKnownUsages(2, NULL);
|
||||
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
||||
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
||||
}
|
||||
|
||||
START_TEST(softpub)
|
||||
{
|
||||
InitFunctionPtrs();
|
||||
test_provider_funcs();
|
||||
test_wintrust();
|
||||
test_get_known_usages();
|
||||
}
|
21
rostests/winetests/wintrust/testlist.c
Normal file
21
rostests/winetests/wintrust/testlist.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* Automatically generated file; DO NOT EDIT!! */
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#define STANDALONE
|
||||
#include "wine/test.h"
|
||||
|
||||
extern void func_asn(void);
|
||||
extern void func_crypt(void);
|
||||
extern void func_register(void);
|
||||
extern void func_softpub(void);
|
||||
|
||||
const struct test winetest_testlist[] =
|
||||
{
|
||||
{ "asn", func_asn },
|
||||
{ "crypt", func_crypt },
|
||||
{ "register", func_register },
|
||||
{ "softpub", func_softpub },
|
||||
{ 0, 0 }
|
||||
};
|
19
rostests/winetests/wintrust/wintrust.rbuild
Normal file
19
rostests/winetests/wintrust/wintrust.rbuild
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
|
||||
<group>
|
||||
<module name="wintrust_winetest" type="win32cui" installbase="bin" installname="wintrust_winetest.exe" allowwarnings="true">
|
||||
<compilerflag compiler="cc">-Wno-format</compilerflag>
|
||||
<include base="wintrust_winetest">.</include>
|
||||
<file>asn.c</file>
|
||||
<file>crypt.c</file>
|
||||
<file>register.c</file>
|
||||
<file>softpub.c</file>
|
||||
<file>testlist.c</file>
|
||||
<library>wine</library>
|
||||
<library>wintrust</library>
|
||||
<library>crypt32</library>
|
||||
<library>advapi32</library>
|
||||
<library>kernel32</library>
|
||||
<library>ntdll</library>
|
||||
</module>
|
||||
</group>
|
Loading…
Reference in a new issue