2005-06-14 13:38:36 +02:00
|
|
|
/*
|
|
|
|
* Miscellaneous crypt32 tests
|
|
|
|
*
|
|
|
|
* Copyright 2005 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-06-14 13:38:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winerror.h>
|
|
|
|
#include <wincrypt.h>
|
2006-08-09 23:45:34 +02:00
|
|
|
#include <winreg.h>
|
2005-06-14 13:38:36 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2010-10-01 13:36:03 +02:00
|
|
|
static HMODULE hCrypt;
|
2006-08-11 16:23:05 +02:00
|
|
|
|
2005-07-07 22:27:55 +02:00
|
|
|
static void test_findAttribute(void)
|
|
|
|
{
|
|
|
|
PCRYPT_ATTRIBUTE ret;
|
2005-08-29 11:38:19 +02:00
|
|
|
BYTE blobbin[] = {0x02,0x01,0x01};
|
2006-07-18 22:48:44 +02:00
|
|
|
static CHAR oid[] = "1.2.3";
|
2005-08-29 11:38:19 +02:00
|
|
|
CRYPT_ATTR_BLOB blobs[] = { { sizeof blobbin, blobbin }, };
|
2018-06-22 19:50:40 +02:00
|
|
|
CRYPT_ATTRIBUTE attr = { oid, ARRAY_SIZE(blobs), blobs };
|
2005-07-07 22:27:55 +02:00
|
|
|
|
|
|
|
/* returns NULL, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindAttribute(NULL, 0, NULL);
|
|
|
|
ok(ret == NULL, "Expected failure\n");
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Last error was set to %08x\n",
|
2005-07-07 22:27:55 +02:00
|
|
|
GetLastError());
|
2007-06-15 16:55:21 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* crashes */
|
2011-02-10 22:27:09 +01:00
|
|
|
CertFindAttribute(NULL, 1, NULL);
|
2007-06-15 16:55:21 +02:00
|
|
|
/* returns NULL, last error is ERROR_INVALID_PARAMETER
|
|
|
|
* crashes on Vista
|
|
|
|
*/
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindAttribute(NULL, 1, &attr);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d (%08x)\n", GetLastError(),
|
|
|
|
GetLastError());
|
|
|
|
}
|
2005-07-07 22:27:55 +02:00
|
|
|
/* returns NULL, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindAttribute("bogus", 1, &attr);
|
|
|
|
ok(ret == NULL, "Expected failure\n");
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Last error was set to %08x\n",
|
2005-07-07 22:27:55 +02:00
|
|
|
GetLastError());
|
|
|
|
/* returns NULL, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindAttribute("1.2.4", 1, &attr);
|
|
|
|
ok(ret == NULL, "Expected failure\n");
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Last error was set to %08x\n",
|
2005-07-07 22:27:55 +02:00
|
|
|
GetLastError());
|
|
|
|
/* succeeds, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindAttribute("1.2.3", 1, &attr);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret != NULL, "CertFindAttribute failed: %08x\n", GetLastError());
|
2005-07-07 22:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_findExtension(void)
|
|
|
|
{
|
|
|
|
PCERT_EXTENSION ret;
|
2006-07-18 22:48:44 +02:00
|
|
|
static CHAR oid[] = "1.2.3";
|
2005-08-29 11:38:19 +02:00
|
|
|
BYTE blobbin[] = {0x02,0x01,0x01};
|
2006-07-18 22:48:44 +02:00
|
|
|
CERT_EXTENSION ext = { oid, TRUE, { sizeof blobbin, blobbin } };
|
2005-07-07 22:27:55 +02:00
|
|
|
|
|
|
|
/* returns NULL, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindExtension(NULL, 0, NULL);
|
|
|
|
ok(ret == NULL, "Expected failure\n");
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Last error was set to %08x\n",
|
2005-07-07 22:27:55 +02:00
|
|
|
GetLastError());
|
2007-06-15 16:55:21 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* crashes */
|
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-31 17:12:20 +01:00
|
|
|
CertFindExtension(NULL, 1, NULL);
|
2007-06-15 16:55:21 +02:00
|
|
|
/* returns NULL, last error is ERROR_INVALID_PARAMETER
|
|
|
|
* crashes on Vista
|
|
|
|
*/
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindExtension(NULL, 1, &ext);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d (%08x)\n", GetLastError(),
|
|
|
|
GetLastError());
|
|
|
|
}
|
2005-07-07 22:27:55 +02:00
|
|
|
/* returns NULL, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindExtension("bogus", 1, &ext);
|
|
|
|
ok(ret == NULL, "Expected failure\n");
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Last error was set to %08x\n",
|
2005-07-07 22:27:55 +02:00
|
|
|
GetLastError());
|
|
|
|
/* returns NULL, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindExtension("1.2.4", 1, &ext);
|
|
|
|
ok(ret == NULL, "Expected failure\n");
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Last error was set to %08x\n",
|
2005-07-07 22:27:55 +02:00
|
|
|
GetLastError());
|
|
|
|
/* succeeds, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindExtension("1.2.3", 1, &ext);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret != NULL, "CertFindExtension failed: %08x\n", GetLastError());
|
2005-07-07 22:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_findRDNAttr(void)
|
|
|
|
{
|
|
|
|
PCERT_RDN_ATTR ret;
|
2006-07-18 22:48:44 +02:00
|
|
|
static CHAR oid[] = "1.2.3";
|
2005-08-29 11:38:19 +02:00
|
|
|
BYTE bin[] = { 0x16,0x09,'J','u','a','n',' ','L','a','n','g' };
|
2005-07-07 22:27:55 +02:00
|
|
|
CERT_RDN_ATTR attrs[] = {
|
2006-07-18 22:48:44 +02:00
|
|
|
{ oid, CERT_RDN_IA5_STRING, { sizeof bin, bin } },
|
2005-07-07 22:27:55 +02:00
|
|
|
};
|
2018-06-22 19:50:40 +02:00
|
|
|
CERT_RDN rdns[] = { { ARRAY_SIZE(attrs), attrs } };
|
|
|
|
CERT_NAME_INFO nameInfo = { ARRAY_SIZE(rdns), rdns };
|
2005-07-07 22:27:55 +02:00
|
|
|
|
2007-06-15 16:55:21 +02:00
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* crashes */
|
|
|
|
SetLastError(0xdeadbeef);
|
2011-02-10 22:27:09 +01:00
|
|
|
CertFindRDNAttr(NULL, NULL);
|
2007-06-15 16:55:21 +02:00
|
|
|
/* returns NULL, last error is ERROR_INVALID_PARAMETER
|
|
|
|
* crashes on Vista
|
|
|
|
*/
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindRDNAttr(NULL, &nameInfo);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d (%08x)\n", GetLastError(),
|
|
|
|
GetLastError());
|
|
|
|
}
|
2005-07-07 22:27:55 +02:00
|
|
|
/* returns NULL, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindRDNAttr("bogus", &nameInfo);
|
|
|
|
ok(ret == NULL, "Expected failure\n");
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Last error was set to %08x\n",
|
2005-07-07 22:27:55 +02:00
|
|
|
GetLastError());
|
|
|
|
/* returns NULL, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindRDNAttr("1.2.4", &nameInfo);
|
|
|
|
ok(ret == NULL, "Expected failure\n");
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "Last error was set to %08x\n",
|
2005-07-07 22:27:55 +02:00
|
|
|
GetLastError());
|
|
|
|
/* succeeds, last error not set */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CertFindRDNAttr("1.2.3", &nameInfo);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret != NULL, "CertFindRDNAttr failed: %08x\n", GetLastError());
|
2005-07-07 22:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_verifyTimeValidity(void)
|
|
|
|
{
|
|
|
|
SYSTEMTIME sysTime;
|
|
|
|
FILETIME fileTime;
|
|
|
|
CERT_INFO info = { 0 };
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
GetSystemTime(&sysTime);
|
|
|
|
SystemTimeToFileTime(&sysTime, &fileTime);
|
|
|
|
/* crashes
|
|
|
|
ret = CertVerifyTimeValidity(NULL, NULL);
|
|
|
|
ret = CertVerifyTimeValidity(&fileTime, NULL);
|
|
|
|
*/
|
|
|
|
/* Check with 0 NotBefore and NotAfter */
|
|
|
|
ret = CertVerifyTimeValidity(&fileTime, &info);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret == 1, "Expected 1, got %d\n", ret);
|
2013-02-05 13:22:27 +01:00
|
|
|
info.NotAfter = fileTime;
|
2005-07-07 22:27:55 +02:00
|
|
|
/* Check with NotAfter equal to comparison time */
|
|
|
|
ret = CertVerifyTimeValidity(&fileTime, &info);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret == 0, "Expected 0, got %d\n", ret);
|
2005-07-07 22:27:55 +02:00
|
|
|
/* Check with NotBefore after comparison time */
|
2013-02-05 13:22:27 +01:00
|
|
|
info.NotBefore = fileTime;
|
2005-07-07 22:27:55 +02:00
|
|
|
info.NotBefore.dwLowDateTime += 5000;
|
|
|
|
ret = CertVerifyTimeValidity(&fileTime, &info);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret == -1, "Expected -1, got %d\n", ret);
|
2005-07-07 22:27:55 +02:00
|
|
|
}
|
|
|
|
|
2005-10-27 12:24:20 +02:00
|
|
|
static void test_cryptAllocate(void)
|
|
|
|
{
|
|
|
|
LPVOID buf;
|
|
|
|
|
|
|
|
buf = CryptMemAlloc(0);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(buf != NULL, "CryptMemAlloc failed: %08x\n", GetLastError());
|
2005-10-27 12:24:20 +02:00
|
|
|
CryptMemFree(buf);
|
2008-09-02 07:54:48 +02:00
|
|
|
/* CryptMemRealloc(NULL, 0) fails pre-Vista */
|
2005-10-27 12:24:20 +02:00
|
|
|
buf = CryptMemAlloc(0);
|
|
|
|
buf = CryptMemRealloc(buf, 1);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(buf != NULL, "CryptMemRealloc failed: %08x\n", GetLastError());
|
2005-10-27 12:24:20 +02:00
|
|
|
CryptMemFree(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void test_cryptTls(void)
|
|
|
|
{
|
2012-06-15 15:19:50 +02:00
|
|
|
DWORD (WINAPI *pI_CryptAllocTls)(void);
|
|
|
|
LPVOID (WINAPI *pI_CryptDetachTls)(DWORD dwTlsIndex);
|
|
|
|
LPVOID (WINAPI *pI_CryptGetTls)(DWORD dwTlsIndex);
|
|
|
|
BOOL (WINAPI *pI_CryptSetTls)(DWORD dwTlsIndex, LPVOID lpTlsValue);
|
|
|
|
BOOL (WINAPI *pI_CryptFreeTls)(DWORD dwTlsIndex, DWORD unknown);
|
2006-08-11 16:23:05 +02:00
|
|
|
DWORD index;
|
|
|
|
BOOL ret;
|
2005-10-27 12:24:20 +02:00
|
|
|
|
2012-06-15 15:19:50 +02:00
|
|
|
pI_CryptAllocTls = (void *)GetProcAddress(hCrypt, "I_CryptAllocTls");
|
|
|
|
pI_CryptDetachTls = (void *)GetProcAddress(hCrypt, "I_CryptDetachTls");
|
|
|
|
pI_CryptGetTls = (void *)GetProcAddress(hCrypt, "I_CryptGetTls");
|
|
|
|
pI_CryptSetTls = (void *)GetProcAddress(hCrypt, "I_CryptSetTls");
|
|
|
|
pI_CryptFreeTls = (void *)GetProcAddress(hCrypt, "I_CryptFreeTls");
|
2005-10-27 12:24:20 +02:00
|
|
|
|
2006-08-11 16:23:05 +02:00
|
|
|
/* One normal pass */
|
|
|
|
index = pI_CryptAllocTls();
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(index, "I_CryptAllocTls failed: %08x\n", GetLastError());
|
2006-08-11 16:23:05 +02:00
|
|
|
if (index)
|
|
|
|
{
|
|
|
|
LPVOID ptr;
|
2005-10-27 12:24:20 +02:00
|
|
|
|
2006-08-11 16:23:05 +02:00
|
|
|
ptr = pI_CryptGetTls(index);
|
|
|
|
ok(!ptr, "Expected NULL\n");
|
|
|
|
ret = pI_CryptSetTls(index, (LPVOID)0xdeadbeef);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret, "I_CryptSetTls failed: %08x\n", GetLastError());
|
2006-08-11 16:23:05 +02:00
|
|
|
ptr = pI_CryptGetTls(index);
|
|
|
|
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
|
|
|
|
/* This crashes
|
|
|
|
ret = pI_CryptFreeTls(index, 1);
|
|
|
|
*/
|
|
|
|
ret = pI_CryptFreeTls(index, 0);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret, "I_CryptFreeTls failed: %08x\n", GetLastError());
|
2006-08-11 16:23:05 +02:00
|
|
|
ret = pI_CryptFreeTls(index, 0);
|
2010-03-02 22:31:46 +01:00
|
|
|
ok(!ret, "I_CryptFreeTls succeeded\n");
|
|
|
|
ok(GetLastError() == E_INVALIDARG,
|
2006-09-29 23:36:26 +02:00
|
|
|
"Expected E_INVALIDARG, got %08x\n", GetLastError());
|
2006-08-11 16:23:05 +02:00
|
|
|
}
|
|
|
|
/* Similar pass, check I_CryptDetachTls */
|
|
|
|
index = pI_CryptAllocTls();
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(index, "I_CryptAllocTls failed: %08x\n", GetLastError());
|
2006-08-11 16:23:05 +02:00
|
|
|
if (index)
|
|
|
|
{
|
|
|
|
LPVOID ptr;
|
2005-10-27 12:24:20 +02:00
|
|
|
|
2006-08-11 16:23:05 +02:00
|
|
|
ptr = pI_CryptGetTls(index);
|
|
|
|
ok(!ptr, "Expected NULL\n");
|
|
|
|
ret = pI_CryptSetTls(index, (LPVOID)0xdeadbeef);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(ret, "I_CryptSetTls failed: %08x\n", GetLastError());
|
2006-08-11 16:23:05 +02:00
|
|
|
ptr = pI_CryptGetTls(index);
|
|
|
|
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
|
|
|
|
ptr = pI_CryptDetachTls(index);
|
|
|
|
ok(ptr == (LPVOID)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", ptr);
|
|
|
|
ptr = pI_CryptGetTls(index);
|
|
|
|
ok(!ptr, "Expected NULL\n");
|
2005-10-27 12:24:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:45:34 +02:00
|
|
|
static void test_readTrustedPublisherDWORD(void)
|
|
|
|
{
|
|
|
|
|
2012-06-15 15:19:50 +02:00
|
|
|
BOOL (WINAPI *pReadDWORD)(LPCWSTR, DWORD *);
|
|
|
|
|
|
|
|
pReadDWORD = (void *)GetProcAddress(hCrypt, "I_CryptReadTrustedPublisherDWORDValueFromRegistry");
|
2006-08-11 16:23:05 +02:00
|
|
|
if (pReadDWORD)
|
2006-08-09 23:45:34 +02:00
|
|
|
{
|
2006-08-11 16:23:05 +02:00
|
|
|
static const WCHAR safer[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'P','o','l','i','c','i','e','s','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
|
|
|
|
'C','e','r','t','i','f','i','c','a','t','e','s','\\',
|
|
|
|
'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r',
|
|
|
|
'\\','S','a','f','e','r',0 };
|
|
|
|
static const WCHAR authenticodeFlags[] = { 'A','u','t','h','e','n',
|
|
|
|
't','i','c','o','d','e','F','l','a','g','s',0 };
|
|
|
|
BOOL ret, exists = FALSE;
|
2006-08-12 05:37:04 +02:00
|
|
|
DWORD size, readFlags = 0, returnedFlags;
|
2006-08-11 16:23:05 +02:00
|
|
|
HKEY key;
|
|
|
|
LONG rc;
|
2006-08-09 23:45:34 +02:00
|
|
|
|
2006-08-11 16:23:05 +02:00
|
|
|
rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, safer, &key);
|
|
|
|
if (rc == ERROR_SUCCESS)
|
2006-08-09 23:45:34 +02:00
|
|
|
{
|
2006-08-11 16:23:05 +02:00
|
|
|
size = sizeof(readFlags);
|
|
|
|
rc = RegQueryValueExW(key, authenticodeFlags, NULL, NULL,
|
|
|
|
(LPBYTE)&readFlags, &size);
|
2006-08-09 23:45:34 +02:00
|
|
|
if (rc == ERROR_SUCCESS)
|
2006-08-11 16:23:05 +02:00
|
|
|
exists = TRUE;
|
2006-08-09 23:45:34 +02:00
|
|
|
}
|
2006-08-12 05:37:04 +02:00
|
|
|
returnedFlags = 0xdeadbeef;
|
2006-08-11 16:23:05 +02:00
|
|
|
ret = pReadDWORD(authenticodeFlags, &returnedFlags);
|
|
|
|
ok(ret == exists, "Unexpected return value\n");
|
2006-08-12 05:37:04 +02:00
|
|
|
ok(readFlags == returnedFlags,
|
2006-09-29 23:36:26 +02:00
|
|
|
"Expected flags %08x, got %08x\n", readFlags, returnedFlags);
|
2006-08-09 23:45:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-12 05:37:04 +02:00
|
|
|
static void test_getDefaultCryptProv(void)
|
|
|
|
{
|
2018-11-06 11:40:53 +01:00
|
|
|
#define ALG(id) id, #id
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
ALG_ID algid;
|
|
|
|
const char *name;
|
|
|
|
BOOL optional;
|
|
|
|
} test_prov[] =
|
|
|
|
{
|
|
|
|
{ ALG(CALG_MD2), TRUE },
|
|
|
|
{ ALG(CALG_MD4), TRUE },
|
|
|
|
{ ALG(CALG_MD5), TRUE },
|
|
|
|
{ ALG(CALG_SHA), TRUE },
|
|
|
|
{ ALG(CALG_RSA_SIGN) },
|
|
|
|
{ ALG(CALG_DSS_SIGN) },
|
|
|
|
{ ALG(CALG_NO_SIGN) },
|
|
|
|
{ ALG(CALG_ECDSA), TRUE },
|
|
|
|
{ ALG(CALG_ECDH), TRUE },
|
|
|
|
{ ALG(CALG_RSA_KEYX) },
|
|
|
|
{ ALG(CALG_RSA_KEYX) },
|
|
|
|
};
|
|
|
|
#undef ALG
|
2012-06-15 15:19:50 +02:00
|
|
|
HCRYPTPROV (WINAPI *pI_CryptGetDefaultCryptProv)(DWORD w);
|
2006-08-12 05:37:04 +02:00
|
|
|
HCRYPTPROV prov;
|
2018-11-06 11:40:53 +01:00
|
|
|
BOOL ret;
|
|
|
|
DWORD size, i;
|
|
|
|
LPSTR name;
|
2006-08-12 05:37:04 +02:00
|
|
|
|
2012-06-15 15:19:50 +02:00
|
|
|
pI_CryptGetDefaultCryptProv = (void *)GetProcAddress(hCrypt, "I_CryptGetDefaultCryptProv");
|
2006-08-12 05:37:04 +02:00
|
|
|
if (!pI_CryptGetDefaultCryptProv) return;
|
|
|
|
|
|
|
|
prov = pI_CryptGetDefaultCryptProv(0xdeadbeef);
|
|
|
|
ok(prov == 0 && GetLastError() == E_INVALIDARG,
|
2006-09-29 23:36:26 +02:00
|
|
|
"Expected E_INVALIDARG, got %08x\n", GetLastError());
|
2006-08-12 05:37:04 +02:00
|
|
|
prov = pI_CryptGetDefaultCryptProv(PROV_RSA_FULL);
|
|
|
|
ok(prov == 0 && GetLastError() == E_INVALIDARG,
|
2006-09-29 23:36:26 +02:00
|
|
|
"Expected E_INVALIDARG, got %08x\n", GetLastError());
|
2006-08-12 05:37:04 +02:00
|
|
|
prov = pI_CryptGetDefaultCryptProv(1);
|
|
|
|
ok(prov == 0 && GetLastError() == E_INVALIDARG,
|
2006-09-29 23:36:26 +02:00
|
|
|
"Expected E_INVALIDARG, got %08x\n", GetLastError());
|
2006-08-12 05:37:04 +02:00
|
|
|
prov = pI_CryptGetDefaultCryptProv(0);
|
2006-09-29 23:36:26 +02:00
|
|
|
ok(prov != 0, "I_CryptGetDefaultCryptProv failed: %08x\n", GetLastError());
|
2006-08-12 05:37:04 +02:00
|
|
|
CryptReleaseContext(prov, 0);
|
2018-11-06 11:40:53 +01:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(test_prov); i++)
|
|
|
|
{
|
|
|
|
if (winetest_debug > 1)
|
|
|
|
trace("%u: algid %#x (%s): class %u, type %u, sid %u\n", i, test_prov[i].algid, test_prov[i].name,
|
|
|
|
GET_ALG_CLASS(test_prov[i].algid) >> 13, GET_ALG_TYPE(test_prov[i].algid) >> 9, GET_ALG_SID(test_prov[i].algid));
|
|
|
|
|
|
|
|
prov = pI_CryptGetDefaultCryptProv(test_prov[i].algid);
|
|
|
|
if (!prov)
|
|
|
|
{
|
2018-11-06 11:40:59 +01:00
|
|
|
todo_wine_if(test_prov[i].algid == CALG_DSS_SIGN || test_prov[i].algid == CALG_NO_SIGN)
|
2018-11-06 11:40:53 +01:00
|
|
|
ok(test_prov[i].optional, "%u: I_CryptGetDefaultCryptProv(%#x) failed\n", i, test_prov[i].algid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = CryptGetProvParam(prov, PP_NAME, NULL, &size, 0);
|
|
|
|
if (ret) /* some provders don't support PP_NAME */
|
|
|
|
{
|
|
|
|
name = CryptMemAlloc(size);
|
|
|
|
ret = CryptGetProvParam(prov, PP_NAME, (BYTE *)name, &size, 0);
|
|
|
|
ok(ret, "%u: CryptGetProvParam failed %#x\n", i, GetLastError());
|
|
|
|
if (winetest_debug > 1)
|
|
|
|
trace("%u: algid %#x, name %s\n", i, test_prov[i].algid, name);
|
|
|
|
CryptMemFree(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
CryptReleaseContext(prov, 0);
|
|
|
|
}
|
2006-08-12 05:37:04 +02:00
|
|
|
}
|
|
|
|
|
2006-11-24 20:25:20 +01:00
|
|
|
static void test_CryptInstallOssGlobal(void)
|
|
|
|
{
|
2012-06-15 15:19:50 +02:00
|
|
|
int (WINAPI *pI_CryptInstallOssGlobal)(DWORD,DWORD,DWORD);
|
2006-11-24 20:25:20 +01:00
|
|
|
int ret,i;
|
|
|
|
|
2012-06-15 15:19:50 +02:00
|
|
|
pI_CryptInstallOssGlobal = (void *)GetProcAddress(hCrypt,"I_CryptInstallOssGlobal");
|
2006-11-24 20:25:20 +01:00
|
|
|
/* passing in some random values to I_CryptInstallOssGlobal, it always returns 9 the first time, then 10, 11 etc.*/
|
|
|
|
for(i=0;i<30;i++)
|
|
|
|
{
|
|
|
|
ret = pI_CryptInstallOssGlobal(rand(),rand(),rand());
|
2008-09-02 07:53:56 +02:00
|
|
|
ok((9+i) == ret ||
|
|
|
|
ret == 0, /* Vista */
|
|
|
|
"Expected %d or 0, got %d\n",(9+i),ret);
|
2006-11-24 20:25:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-30 22:39:36 +01:00
|
|
|
static void test_format_object(void)
|
|
|
|
{
|
2019-10-26 00:28:31 +02:00
|
|
|
static const BYTE encodedInt[] = {0x02,0x01,0x01};
|
|
|
|
static const BYTE encodedBigInt[] = {0x02,0x1f,0x01,0x02,0x03,0x04,0x05,
|
|
|
|
0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,
|
|
|
|
0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f};
|
|
|
|
static const WCHAR encodedBigIntStr[] = L"02 1f 01 02 03 04 05 06 07 08 09 "
|
|
|
|
"0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f";
|
|
|
|
|
2008-10-30 22:39:36 +01:00
|
|
|
BOOL ret;
|
|
|
|
DWORD size;
|
2019-10-26 00:28:31 +02:00
|
|
|
WCHAR str[100];
|
2008-10-30 22:39:36 +01:00
|
|
|
|
|
|
|
/* Crash */
|
|
|
|
if (0)
|
|
|
|
{
|
2019-10-26 00:28:31 +02:00
|
|
|
CryptFormatObject(0, 0, 0, NULL, NULL, NULL, 0, NULL, NULL);
|
2008-10-30 22:39:36 +01:00
|
|
|
}
|
|
|
|
/* When called with any but the default encoding, it fails to find a
|
|
|
|
* formatting function.
|
|
|
|
*/
|
|
|
|
SetLastError(0xdeadbeef);
|
2019-10-26 00:28:31 +02:00
|
|
|
ret = CryptFormatObject(0, 0, 0, NULL, NULL, NULL, 0, NULL, &size);
|
|
|
|
ok(!ret, "expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
|
|
|
|
|
2008-10-30 22:39:36 +01:00
|
|
|
/* When called with the default encoding type for any undefined struct type
|
|
|
|
* (including none), it succeeds: the default encoding is a hex string
|
|
|
|
* encoding.
|
|
|
|
*/
|
|
|
|
SetLastError(0xdeadbeef);
|
2019-10-26 00:28:31 +02:00
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL, 0, NULL, &size);
|
2008-10-30 22:39:36 +01:00
|
|
|
ok(ret, "CryptFormatObject failed: %d\n", GetLastError());
|
2019-10-26 00:28:31 +02:00
|
|
|
ok(size == sizeof(WCHAR) || broken(!size) /* Win10 1709+ */, "wrong size %d\n", size);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = 0;
|
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL, 0, str, &size);
|
|
|
|
ok(!ret, "expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_MORE_DATA, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
size = sizeof(WCHAR);
|
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL, 0, str, &size);
|
|
|
|
ok(ret, "CryptFormatObject failed, error %u\n", GetLastError());
|
|
|
|
ok(!str[0], "expected empty string\n");
|
|
|
|
|
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedInt,
|
|
|
|
sizeof(encodedInt), NULL, &size);
|
|
|
|
ok(ret, "CryptFormatObject failed, error %u\n", GetLastError());
|
|
|
|
ok(size >= sizeof(L"02 01 01"), "wrong size %u\n", size);
|
|
|
|
|
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedInt,
|
|
|
|
sizeof(encodedInt), str, &size);
|
|
|
|
ok(ret, "CryptFormatObject failed, error %u\n", GetLastError());
|
|
|
|
ok(!wcscmp(str, L"02 01 01"), "wrong string %s\n", wine_dbgstr_w(str));
|
|
|
|
|
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedBigInt,
|
|
|
|
sizeof(encodedBigInt), NULL, &size);
|
|
|
|
ok(ret, "CryptFormatObject failed, error %u\n", GetLastError());
|
|
|
|
ok(size >= sizeof(encodedBigIntStr), "wrong size %u\n", size);
|
|
|
|
|
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL,
|
|
|
|
encodedBigInt, sizeof(encodedBigInt), str, &size);
|
2008-10-30 22:39:36 +01:00
|
|
|
ok(ret, "CryptFormatObject failed: %d\n", GetLastError());
|
2019-10-26 00:28:31 +02:00
|
|
|
ok(!wcsicmp(str, encodedBigIntStr), "wrong string %s\n", wine_dbgstr_w(str));
|
|
|
|
|
2008-10-30 22:39:36 +01:00
|
|
|
/* When called with the default encoding type for any undefined struct
|
|
|
|
* type but CRYPT_FORMAT_STR_NO_HEX specified, it fails to find a
|
|
|
|
* formatting function.
|
|
|
|
*/
|
|
|
|
SetLastError(0xdeadbeef);
|
2019-10-26 00:28:31 +02:00
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, CRYPT_FORMAT_STR_NO_HEX,
|
|
|
|
NULL, NULL, NULL, 0, NULL, &size);
|
2008-11-12 17:35:12 +01:00
|
|
|
ok(!ret, "CryptFormatObject succeeded\n");
|
2019-10-26 00:28:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND
|
|
|
|
|| GetLastError() == 0xdeadbeef, /* Vista, W2K8 */
|
|
|
|
"wrong error %u\n", GetLastError());
|
|
|
|
|
2008-10-30 22:39:36 +01:00
|
|
|
/* When called to format an AUTHORITY_KEY_ID2_INFO, it fails when no
|
|
|
|
* data are given.
|
|
|
|
*/
|
|
|
|
SetLastError(0xdeadbeef);
|
2019-10-26 00:28:31 +02:00
|
|
|
ret = CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL,
|
|
|
|
szOID_AUTHORITY_KEY_IDENTIFIER2, NULL, 0, NULL, &size);
|
|
|
|
ok(!ret, "expected failure\n");
|
|
|
|
ok(GetLastError() == E_INVALIDARG, "wrong error %u\n", GetLastError());
|
2008-10-30 22:39:36 +01:00
|
|
|
}
|
|
|
|
|
2005-06-14 13:38:36 +02:00
|
|
|
START_TEST(main)
|
|
|
|
{
|
2007-08-14 20:38:51 +02:00
|
|
|
hCrypt = GetModuleHandleA("crypt32.dll");
|
|
|
|
|
2005-07-07 22:27:55 +02:00
|
|
|
test_findAttribute();
|
|
|
|
test_findExtension();
|
|
|
|
test_findRDNAttr();
|
|
|
|
test_verifyTimeValidity();
|
2005-10-27 12:24:20 +02:00
|
|
|
test_cryptAllocate();
|
|
|
|
test_cryptTls();
|
2006-08-09 23:45:34 +02:00
|
|
|
test_readTrustedPublisherDWORD();
|
2006-08-12 05:37:04 +02:00
|
|
|
test_getDefaultCryptProv();
|
2006-11-24 20:25:20 +01:00
|
|
|
test_CryptInstallOssGlobal();
|
2008-10-30 22:39:36 +01:00
|
|
|
test_format_object();
|
2005-06-14 13:38:36 +02:00
|
|
|
}
|