2005-12-02 11:28:09 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for crypt32.dll's OID support functions.
|
|
|
|
*
|
|
|
|
* Copyright 2005 Juan Lang
|
2018-10-05 10:41:51 +02:00
|
|
|
* Copyright 2018 Dmitry Timoshkov
|
2005-12-02 11:28:09 +01:00
|
|
|
*
|
|
|
|
* 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-12-02 11:28:09 +01:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winerror.h>
|
2018-06-22 15:26:54 +02:00
|
|
|
#define CRYPT_OID_INFO_HAS_EXTRA_FIELDS
|
2005-12-02 11:28:09 +01:00
|
|
|
#include <wincrypt.h>
|
2006-08-09 21:17:10 +02:00
|
|
|
#include <winreg.h>
|
2005-12-02 11:28:09 +01:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2006-02-23 01:26:52 +01:00
|
|
|
struct OIDToAlgID
|
|
|
|
{
|
|
|
|
LPCSTR oid;
|
|
|
|
DWORD algID;
|
2018-01-29 19:51:21 +01:00
|
|
|
DWORD altAlgID;
|
2006-02-23 01:26:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct OIDToAlgID oidToAlgID[] = {
|
2022-04-12 09:51:51 +02:00
|
|
|
{ szOID_RSA_RSA, CALG_RSA_KEYX },
|
|
|
|
{ szOID_RSA_MD2RSA, CALG_MD2 },
|
|
|
|
{ szOID_RSA_MD4RSA, CALG_MD4 },
|
|
|
|
{ szOID_RSA_MD5RSA, CALG_MD5 },
|
|
|
|
{ szOID_RSA_SHA1RSA, CALG_SHA },
|
|
|
|
{ szOID_RSA_DH, CALG_DH_SF },
|
|
|
|
{ szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM },
|
|
|
|
{ szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES },
|
|
|
|
{ szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2 },
|
|
|
|
{ szOID_RSA_MD2, CALG_MD2 },
|
|
|
|
{ szOID_RSA_MD4, CALG_MD4 },
|
|
|
|
{ szOID_RSA_MD5, CALG_MD5 },
|
|
|
|
{ szOID_RSA_RC2CBC, CALG_RC2 },
|
|
|
|
{ szOID_RSA_RC4, CALG_RC4 },
|
|
|
|
{ szOID_RSA_DES_EDE3_CBC, CALG_3DES },
|
|
|
|
{ szOID_ANSI_X942_DH, CALG_DH_SF },
|
|
|
|
{ szOID_X957_DSA, CALG_DSS_SIGN },
|
|
|
|
{ szOID_X957_SHA1DSA, CALG_SHA },
|
|
|
|
{ szOID_OIWSEC_md4RSA, CALG_MD4 },
|
|
|
|
{ szOID_OIWSEC_md5RSA, CALG_MD5 },
|
|
|
|
{ szOID_OIWSEC_md4RSA2, CALG_MD4 },
|
|
|
|
{ szOID_OIWSEC_desCBC, CALG_DES },
|
|
|
|
{ szOID_OIWSEC_dsa, CALG_DSS_SIGN },
|
|
|
|
{ szOID_OIWSEC_shaDSA, CALG_SHA },
|
|
|
|
{ szOID_OIWSEC_shaRSA, CALG_SHA },
|
|
|
|
{ szOID_OIWSEC_sha, CALG_SHA },
|
|
|
|
{ szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX },
|
|
|
|
{ szOID_OIWSEC_sha1, CALG_SHA },
|
|
|
|
{ szOID_OIWSEC_dsaSHA1, CALG_SHA },
|
|
|
|
{ szOID_OIWSEC_sha1RSASign, CALG_SHA },
|
|
|
|
{ szOID_OIWDIR_md2RSA, CALG_MD2 },
|
|
|
|
{ szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA },
|
|
|
|
{ szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN },
|
|
|
|
{ szOID_NIST_sha256, CALG_SHA_256, -1 },
|
|
|
|
{ szOID_NIST_sha384, CALG_SHA_384, -1 },
|
|
|
|
{ szOID_NIST_sha512, CALG_SHA_512, -1 }
|
2006-02-23 01:26:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct OIDToAlgID algIDToOID[] = {
|
2022-04-12 09:51:51 +02:00
|
|
|
{ szOID_RSA_RSA, CALG_RSA_KEYX },
|
|
|
|
{ szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM },
|
|
|
|
{ szOID_RSA_MD2, CALG_MD2 },
|
|
|
|
{ szOID_RSA_MD4, CALG_MD4 },
|
|
|
|
{ szOID_RSA_MD5, CALG_MD5 },
|
|
|
|
{ szOID_RSA_RC2CBC, CALG_RC2 },
|
|
|
|
{ szOID_RSA_RC4, CALG_RC4 },
|
|
|
|
{ szOID_RSA_DES_EDE3_CBC, CALG_3DES },
|
|
|
|
{ szOID_ANSI_X942_DH, CALG_DH_SF },
|
|
|
|
{ szOID_X957_DSA, CALG_DSS_SIGN },
|
|
|
|
{ szOID_OIWSEC_desCBC, CALG_DES },
|
|
|
|
{ szOID_OIWSEC_sha1, CALG_SHA },
|
2006-02-23 01:26:52 +01:00
|
|
|
};
|
|
|
|
|
2022-04-12 09:51:51 +02:00
|
|
|
static void test_OIDToAlgID(void)
|
2006-02-23 01:26:52 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
DWORD alg;
|
|
|
|
|
|
|
|
/* Test with a bogus one */
|
|
|
|
alg = CertOIDToAlgId("1.2.3");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(!alg, "Expected failure, got %ld\n", alg);
|
2006-02-23 01:26:52 +01:00
|
|
|
|
2018-06-22 19:50:40 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(oidToAlgID); i++)
|
2006-02-23 01:26:52 +01:00
|
|
|
{
|
|
|
|
alg = CertOIDToAlgId(oidToAlgID[i].oid);
|
2018-01-29 19:51:21 +01:00
|
|
|
ok(alg == oidToAlgID[i].algID || (oidToAlgID[i].altAlgID && alg == oidToAlgID[i].altAlgID),
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected %ld, got %ld\n", oidToAlgID[i].algID, alg);
|
2006-02-23 01:26:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 09:51:51 +02:00
|
|
|
static void test_AlgIDToOID(void)
|
2006-02-23 01:26:52 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
LPCSTR oid;
|
|
|
|
|
|
|
|
/* Test with a bogus one */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80);
|
|
|
|
ok(!oid && GetLastError() == 0xdeadbeef,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Didn't expect last error (%08lx) to be set\n", GetLastError());
|
2018-06-22 19:50:40 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(algIDToOID); i++)
|
2006-02-23 01:26:52 +01:00
|
|
|
{
|
|
|
|
oid = CertAlgIdToOID(algIDToOID[i].algID);
|
|
|
|
/* Allow failure, not every version of Windows supports every algo */
|
2022-04-12 09:51:51 +02:00
|
|
|
ok(oid != NULL, "CertAlgIdToOID failed, expected %s\n", algIDToOID[i].oid);
|
2006-02-23 01:26:52 +01:00
|
|
|
if (oid)
|
2022-04-12 09:51:51 +02:00
|
|
|
ok(!strcmp(oid, algIDToOID[i].oid), "Expected %s, got %s\n", algIDToOID[i].oid, oid);
|
2006-02-23 01:26:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:28:09 +01:00
|
|
|
static void test_oidFunctionSet(void)
|
|
|
|
{
|
|
|
|
HCRYPTOIDFUNCSET set1, set2;
|
|
|
|
BOOL ret;
|
|
|
|
LPWSTR buf = NULL;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
/* This crashes
|
|
|
|
set = CryptInitOIDFunctionSet(NULL, 0);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The name doesn't mean much */
|
|
|
|
set1 = CryptInitOIDFunctionSet("funky", 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
if (set1)
|
|
|
|
{
|
|
|
|
/* These crash
|
|
|
|
ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
|
|
|
|
ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
|
|
|
|
*/
|
|
|
|
size = 0;
|
|
|
|
ret = CryptGetDefaultOIDDllList(set1, 0, NULL, &size);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptGetDefaultOIDDllList failed: %08lx\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
ret = CryptGetDefaultOIDDllList(set1, 0, buf, &size);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptGetDefaultOIDDllList failed: %08lx\n",
|
2005-12-02 11:28:09 +01:00
|
|
|
GetLastError());
|
|
|
|
ok(!*buf, "Expected empty DLL list\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MSDN says flags must be 0, but it's not checked */
|
|
|
|
set1 = CryptInitOIDFunctionSet("", 1);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
set2 = CryptInitOIDFunctionSet("", 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
/* There isn't a free function, so there must be only one set per name to
|
|
|
|
* limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
|
|
|
|
*/
|
|
|
|
ok(set1 == set2, "Expected identical sets\n");
|
|
|
|
if (set1)
|
|
|
|
{
|
|
|
|
/* The empty name function set used here seems to correspond to
|
|
|
|
* DEFAULT.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There's no installed function for a built-in encoding. */
|
|
|
|
set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
if (set1)
|
|
|
|
{
|
|
|
|
void *funcAddr;
|
|
|
|
HCRYPTOIDFUNCADDR hFuncAddr;
|
|
|
|
|
|
|
|
ret = CryptGetOIDFunctionAddress(set1, X509_ASN_ENCODING, X509_CERT, 0,
|
|
|
|
&funcAddr, &hFuncAddr);
|
2022-04-12 09:51:51 +02:00
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %08lx\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int (*funcY)(int);
|
|
|
|
|
|
|
|
static int funky(int x)
|
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_installOIDFunctionAddress(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CRYPT_OID_FUNC_ENTRY entry = { CRYPT_DEFAULT_OID, funky };
|
|
|
|
HCRYPTOIDFUNCSET set;
|
|
|
|
|
|
|
|
/* This crashes
|
|
|
|
ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Installing zero functions should work */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
|
|
|
|
NULL, 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
|
2005-12-02 11:28:09 +01:00
|
|
|
GetLastError());
|
|
|
|
|
|
|
|
/* The function name doesn't much matter */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
|
2005-12-02 11:28:09 +01:00
|
|
|
GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
entry.pszOID = X509_CERT;
|
|
|
|
ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
|
2005-12-02 11:28:09 +01:00
|
|
|
GetLastError());
|
|
|
|
set = CryptInitOIDFunctionSet("OhSoFunky", 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(set != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
if (set)
|
|
|
|
{
|
|
|
|
funcY funcAddr = NULL;
|
|
|
|
HCRYPTOIDFUNCADDR hFuncAddr = NULL;
|
|
|
|
|
|
|
|
/* This crashes
|
|
|
|
ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
|
|
|
|
NULL);
|
|
|
|
*/
|
|
|
|
ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0,
|
|
|
|
(void **)&funcAddr, &hFuncAddr);
|
2022-04-12 09:51:51 +02:00
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, X509_CERT, 0,
|
|
|
|
(void **)&funcAddr, &hFuncAddr);
|
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptGetOIDFunctionAddress(set, 0, X509_CERT, 0,
|
|
|
|
(void **)&funcAddr, &hFuncAddr);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptGetOIDFunctionAddress failed: %ld\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
if (funcAddr)
|
|
|
|
{
|
|
|
|
int y = funcAddr(0xabadc0da);
|
|
|
|
|
|
|
|
ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
|
|
|
|
CryptFreeOIDFunctionAddress(hFuncAddr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_registerOIDFunction(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
/* oddly, this succeeds under WinXP; the function name key is merely
|
|
|
|
* omitted. This may be a side effect of the registry code, I don't know.
|
|
|
|
* I don't check it because I doubt anyone would depend on it.
|
|
|
|
ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
|
2022-03-31 11:06:03 +02:00
|
|
|
"1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
|
2005-12-02 11:28:09 +01:00
|
|
|
*/
|
|
|
|
/* On windows XP, GetLastError is incorrectly being set with an HRESULT,
|
2006-05-11 18:48:01 +02:00
|
|
|
* E_INVALIDARG
|
2005-12-02 11:28:09 +01:00
|
|
|
*/
|
2022-03-31 11:06:03 +02:00
|
|
|
ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo", NULL, L"bogus.dll",
|
2005-12-02 11:28:09 +01:00
|
|
|
NULL);
|
2006-05-11 18:48:01 +02:00
|
|
|
ok(!ret && GetLastError() == E_INVALIDARG,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected E_INVALIDARG: %ld\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
/* This has no effect, but "succeeds" on XP */
|
|
|
|
ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo",
|
|
|
|
"1.2.3.4.5.6.7.8.9.10", NULL, NULL);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "Expected pseudo-success, got %ld\n", GetLastError());
|
2007-06-13 12:17:06 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
|
2022-03-31 11:06:03 +02:00
|
|
|
"1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
|
2007-06-13 12:17:06 +02:00
|
|
|
if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
skip("Need admin rights\n");
|
|
|
|
return;
|
|
|
|
}
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
|
|
|
|
"1.2.3.4.5.6.7.8.9.10");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "bogus",
|
2022-03-31 11:06:03 +02:00
|
|
|
"1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "bogus",
|
|
|
|
"1.2.3.4.5.6.7.8.9.10");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
|
2008-05-08 15:06:53 +02:00
|
|
|
/* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
|
|
|
|
ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
|
|
|
|
"SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
|
|
|
|
"Could not delete bogus key\n");
|
|
|
|
/* Shouldn't have effect but registry keys are created */
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
|
2022-03-31 11:06:03 +02:00
|
|
|
"1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
|
2008-05-08 15:06:53 +02:00
|
|
|
ret = CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
|
|
|
|
"1.2.3.4.5.6.7.8.9.10");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
|
2008-05-08 15:06:53 +02:00
|
|
|
/* Check with bogus encoding type. Registry keys are still created */
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
|
2022-03-31 11:06:03 +02:00
|
|
|
"1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
|
2008-05-08 15:06:53 +02:00
|
|
|
ret = CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
|
|
|
|
"1.2.3.4.5.6.7.8.9.10");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
|
2008-05-08 15:06:53 +02:00
|
|
|
/* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
|
|
|
|
* will still be there
|
|
|
|
*/
|
|
|
|
ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
|
|
|
|
"SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
|
|
|
|
"Could not delete CryptDllEncodeObject key\n");
|
2005-12-02 11:28:09 +01:00
|
|
|
/* This is written with value 3 verbatim. Thus, the encoding type isn't
|
2008-05-08 15:06:53 +02:00
|
|
|
* (for now) treated as a mask. Registry keys are created.
|
2005-12-02 11:28:09 +01:00
|
|
|
*/
|
|
|
|
ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
|
2022-03-31 11:06:03 +02:00
|
|
|
"1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
|
2005-12-02 11:28:09 +01:00
|
|
|
ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
|
|
|
|
"1.2.3.4.5.6.7.8.9.10");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
|
2008-05-08 15:06:53 +02:00
|
|
|
/* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
|
|
|
|
* will still be there.
|
|
|
|
*/
|
|
|
|
ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
|
|
|
|
"SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
|
|
|
|
"Could not delete CryptDllEncodeObject key\n");
|
|
|
|
ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
|
|
|
|
"SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
|
|
|
|
"Could not delete 'EncodingType 3' key\n");
|
2005-12-02 11:28:09 +01:00
|
|
|
}
|
|
|
|
|
2006-08-09 21:17:10 +02:00
|
|
|
static void test_registerDefaultOIDFunction(void)
|
|
|
|
{
|
|
|
|
static const char fmt[] =
|
|
|
|
"Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
|
|
|
|
static const char func[] = "CertDllOpenStoreProv";
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
BOOL ret;
|
2009-06-03 09:44:55 +02:00
|
|
|
LSTATUS rc;
|
2006-08-09 21:17:10 +02:00
|
|
|
HKEY key;
|
|
|
|
|
|
|
|
ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, NULL);
|
|
|
|
ok(!ret && GetLastError() == E_INVALIDARG,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected E_INVALIDARG, got %08lx\n", GetLastError());
|
2006-08-09 21:17:10 +02:00
|
|
|
/* This succeeds on WinXP, although the bogus entry is unusable.
|
2022-03-31 11:06:03 +02:00
|
|
|
ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, L"bogus.dll");
|
2006-08-09 21:17:10 +02:00
|
|
|
*/
|
|
|
|
/* Register one at index 0 */
|
2007-06-13 12:17:06 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2006-08-09 21:17:10 +02:00
|
|
|
ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
|
2022-03-31 11:06:03 +02:00
|
|
|
L"bogus.dll");
|
2007-06-13 12:17:06 +02:00
|
|
|
if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
skip("Need admin rights\n");
|
|
|
|
return;
|
|
|
|
}
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptRegisterDefaultOIDFunction failed: %08lx\n", GetLastError());
|
2006-08-09 21:17:10 +02:00
|
|
|
/* Reregistering should fail */
|
|
|
|
ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
|
2022-03-31 11:06:03 +02:00
|
|
|
L"bogus.dll");
|
2006-08-09 21:17:10 +02:00
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_EXISTS, got %08lx\n", GetLastError());
|
2006-08-09 21:17:10 +02:00
|
|
|
/* Registering the same one at index 1 should also fail */
|
|
|
|
ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
|
2022-03-31 11:06:03 +02:00
|
|
|
L"bogus.dll");
|
2006-08-09 21:17:10 +02:00
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_EXISTS, got %08lx\n", GetLastError());
|
2006-08-09 21:17:10 +02:00
|
|
|
/* Registering a different one at index 1 succeeds */
|
|
|
|
ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
|
2022-03-31 11:06:03 +02:00
|
|
|
L"bogus2.dll");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptRegisterDefaultOIDFunction failed: %08lx\n", GetLastError());
|
2006-08-09 21:17:10 +02:00
|
|
|
sprintf(buf, fmt, 0, func);
|
|
|
|
rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, buf, &key);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(rc == 0, "Expected key to exist, RegOpenKeyA failed: %ld\n", rc);
|
2006-08-09 21:17:10 +02:00
|
|
|
if (rc == 0)
|
|
|
|
{
|
2007-04-24 09:11:44 +02:00
|
|
|
CHAR dllBuf[MAX_PATH];
|
2006-08-09 21:17:10 +02:00
|
|
|
DWORD type, size;
|
2007-04-24 09:11:44 +02:00
|
|
|
LPSTR ptr;
|
2006-08-09 21:17:10 +02:00
|
|
|
|
2018-06-22 19:50:40 +02:00
|
|
|
size = ARRAY_SIZE(dllBuf);
|
2022-03-31 11:06:03 +02:00
|
|
|
rc = RegQueryValueExA(key, "Dll", NULL, &type, (LPBYTE)dllBuf, &size);
|
2006-08-09 21:17:10 +02:00
|
|
|
ok(rc == 0,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected Dll value to exist, RegQueryValueExA failed: %ld\n", rc);
|
|
|
|
ok(type == REG_MULTI_SZ, "Expected type REG_MULTI_SZ, got %ld\n", type);
|
2022-03-31 11:06:03 +02:00
|
|
|
/* bogus.dll was registered first, so that should be first */
|
2006-08-09 21:17:10 +02:00
|
|
|
ptr = dllBuf;
|
2022-03-31 11:06:03 +02:00
|
|
|
ok(!lstrcmpiA(ptr, "bogus.dll"), "Unexpected dll\n");
|
2007-04-24 09:11:44 +02:00
|
|
|
ptr += lstrlenA(ptr) + 1;
|
2022-03-31 11:06:03 +02:00
|
|
|
ok(!lstrcmpiA(ptr, "bogus2.dll"), "Unexpected dll\n");
|
2006-08-09 21:17:10 +02:00
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
/* Unregister both of them */
|
|
|
|
ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
|
2022-03-31 11:06:03 +02:00
|
|
|
L"bogus.dll");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08lx\n",
|
2006-08-09 21:17:10 +02:00
|
|
|
GetLastError());
|
|
|
|
ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
|
2022-03-31 11:06:03 +02:00
|
|
|
L"bogus2.dll");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08lx\n",
|
2006-08-09 21:17:10 +02:00
|
|
|
GetLastError());
|
|
|
|
/* Now that they're both unregistered, unregistering should fail */
|
|
|
|
ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
|
2022-03-31 11:06:03 +02:00
|
|
|
L"bogus.dll");
|
2006-08-09 21:17:10 +02:00
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
|
2006-08-09 21:17:10 +02:00
|
|
|
|
|
|
|
/* Repeat a few tests on the normal encoding type */
|
|
|
|
ret = CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING,
|
2022-03-31 11:06:03 +02:00
|
|
|
"CertDllOpenStoreProv", 0, L"bogus.dll");
|
2011-02-10 22:27:16 +01:00
|
|
|
ok(ret, "CryptRegisterDefaultOIDFunction failed\n");
|
2006-08-09 21:17:10 +02:00
|
|
|
ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
|
2022-03-31 11:06:03 +02:00
|
|
|
"CertDllOpenStoreProv", L"bogus.dll");
|
2006-08-09 21:17:10 +02:00
|
|
|
ok(ret, "CryptUnregisterDefaultOIDFunction failed\n");
|
|
|
|
ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
|
2022-03-31 11:06:03 +02:00
|
|
|
"CertDllOpenStoreProv", L"bogus.dll");
|
2006-08-09 21:17:10 +02:00
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %08lx\n", GetLastError());
|
2006-08-09 21:17:10 +02:00
|
|
|
}
|
|
|
|
|
2007-10-17 18:31:18 +02:00
|
|
|
static void test_getDefaultOIDFunctionAddress(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
HCRYPTOIDFUNCSET set;
|
|
|
|
void *funcAddr;
|
|
|
|
HCRYPTOIDFUNCADDR hFuncAddr;
|
|
|
|
|
|
|
|
/* Crash
|
|
|
|
ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
|
|
|
|
ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
|
|
|
|
ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
|
|
|
|
ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
|
|
|
|
&hFuncAddr);
|
|
|
|
*/
|
|
|
|
set = CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(set != 0, "CryptInitOIDFunctionSet failed: %ld\n", GetLastError());
|
2007-10-17 18:31:18 +02:00
|
|
|
/* This crashes if hFuncAddr is not 0 to begin with */
|
|
|
|
hFuncAddr = 0;
|
|
|
|
ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
|
|
|
|
&hFuncAddr);
|
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
|
2007-10-17 18:31:18 +02:00
|
|
|
/* This fails with the normal encoding too, so built-in functions aren't
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
ret = CryptGetDefaultOIDFunctionAddress(set, X509_ASN_ENCODING, NULL, 0,
|
|
|
|
&funcAddr, &hFuncAddr);
|
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
|
2007-10-17 18:31:18 +02:00
|
|
|
|
|
|
|
/* Even with a registered dll, this fails (since the dll doesn't exist) */
|
2008-02-09 17:20:58 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2007-10-17 18:31:18 +02:00
|
|
|
ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
|
2022-03-31 11:06:03 +02:00
|
|
|
L"bogus.dll");
|
2008-02-09 17:20:58 +01:00
|
|
|
if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
|
|
|
skip("Need admin rights\n");
|
|
|
|
else
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "CryptRegisterDefaultOIDFunction failed: %08lx\n", GetLastError());
|
2007-10-17 18:31:18 +02:00
|
|
|
ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
|
|
|
|
&hFuncAddr);
|
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
|
2022-03-31 11:06:03 +02:00
|
|
|
CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", L"bogus.dll");
|
2007-10-17 18:31:18 +02:00
|
|
|
}
|
|
|
|
|
2006-02-23 22:18:13 +01:00
|
|
|
static BOOL WINAPI countOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
|
|
|
|
{
|
|
|
|
(*(DWORD *)pvArg)++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_enumOIDInfo(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD count = 0;
|
|
|
|
|
|
|
|
/* This crashes
|
2022-04-12 09:51:51 +02:00
|
|
|
ret = CryptEnumOIDInfo(7, 0, NULL, NULL);
|
2006-02-23 22:18:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Silly tests, check that more than one thing is enumerated */
|
2022-04-12 09:51:51 +02:00
|
|
|
ret = CryptEnumOIDInfo(0, 0, &count, countOidInfo);
|
2006-02-23 22:18:13 +01:00
|
|
|
ok(ret && count > 0, "Expected more than item enumerated\n");
|
2022-04-12 09:51:51 +02:00
|
|
|
ret = CryptEnumOIDInfo(0, 0, NULL, noOidInfo);
|
2006-02-23 22:18:13 +01:00
|
|
|
ok(!ret, "Expected FALSE\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_findOIDInfo(void)
|
|
|
|
{
|
2018-01-29 19:51:21 +01:00
|
|
|
static CHAR oid_rsa_md5[] = szOID_RSA_MD5, oid_sha256[] = szOID_NIST_sha256;
|
2018-06-22 15:26:54 +02:00
|
|
|
static CHAR oid_ecdsa_sha256[] = szOID_ECDSA_SHA256;
|
2006-02-23 22:18:13 +01:00
|
|
|
ALG_ID alg = CALG_SHA1;
|
|
|
|
ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
|
2018-06-22 15:26:53 +02:00
|
|
|
const struct oid_info
|
|
|
|
{
|
|
|
|
DWORD key_type;
|
|
|
|
void *key;
|
|
|
|
const char *oid;
|
|
|
|
ALG_ID algid;
|
|
|
|
ALG_ID broken_algid;
|
|
|
|
} oid_test_info [] =
|
|
|
|
{
|
|
|
|
{ CRYPT_OID_INFO_OID_KEY, oid_rsa_md5, szOID_RSA_MD5, CALG_MD5 },
|
2022-03-31 11:06:03 +02:00
|
|
|
{ CRYPT_OID_INFO_NAME_KEY, (void *)L"sha1", szOID_OIWSEC_sha1, CALG_SHA1 },
|
2018-06-22 15:26:53 +02:00
|
|
|
{ CRYPT_OID_INFO_ALGID_KEY, &alg, szOID_OIWSEC_sha1, CALG_SHA1 },
|
|
|
|
{ CRYPT_OID_INFO_SIGN_KEY, algs, szOID_RSA_MD5RSA, CALG_MD5 },
|
|
|
|
{ CRYPT_OID_INFO_OID_KEY, oid_sha256, szOID_NIST_sha256, CALG_SHA_256, -1 },
|
|
|
|
};
|
2006-02-23 22:18:13 +01:00
|
|
|
PCCRYPT_OID_INFO info;
|
2018-06-22 15:26:53 +02:00
|
|
|
int i;
|
2018-01-29 19:51:21 +01:00
|
|
|
|
2006-02-23 22:18:13 +01:00
|
|
|
info = CryptFindOIDInfo(0, NULL, 0);
|
|
|
|
ok(info == NULL, "Expected NULL\n");
|
2018-01-29 19:51:21 +01:00
|
|
|
|
2018-06-22 15:26:53 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(oid_test_info); i++)
|
2018-01-29 19:51:21 +01:00
|
|
|
{
|
2018-06-22 15:26:53 +02:00
|
|
|
const struct oid_info *test = &oid_test_info[i];
|
|
|
|
|
|
|
|
info = CryptFindOIDInfo(test->key_type, test->key, 0);
|
|
|
|
ok(info != NULL, "Failed to find %s.\n", test->oid);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
ok(!strcmp(info->pszOID, test->oid), "Unexpected OID %s, expected %s\n", info->pszOID, test->oid);
|
|
|
|
ok(U(*info).Algid == test->algid || broken(U(*info).Algid == test->broken_algid),
|
|
|
|
"Unexpected Algid %d, expected %d\n", U(*info).Algid, test->algid);
|
|
|
|
}
|
2018-01-29 19:51:21 +01:00
|
|
|
}
|
2018-06-22 15:26:54 +02:00
|
|
|
|
|
|
|
info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_ecdsa_sha256, 0);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
DWORD *data;
|
|
|
|
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(info->cbSize == sizeof(*info), "Unexpected structure size %ld.\n", info->cbSize);
|
2018-06-22 15:26:54 +02:00
|
|
|
ok(!strcmp(info->pszOID, oid_ecdsa_sha256), "Expected %s, got %s\n", oid_ecdsa_sha256, info->pszOID);
|
2022-03-31 11:06:03 +02:00
|
|
|
ok(!lstrcmpW(info->pwszName, L"sha256ECDSA"), "Expected %s, got %s\n",
|
|
|
|
wine_dbgstr_w(L"sha256ECDSA"), wine_dbgstr_w(info->pwszName));
|
2018-06-22 15:26:54 +02:00
|
|
|
ok(info->dwGroupId == CRYPT_SIGN_ALG_OID_GROUP_ID,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected CRYPT_SIGN_ALG_OID_GROUP_ID, got %lu\n", info->dwGroupId);
|
2018-06-22 15:26:54 +02:00
|
|
|
ok(U(*info).Algid == CALG_OID_INFO_CNG_ONLY,
|
|
|
|
"Expected CALG_OID_INFO_CNG_ONLY, got %d\n", U(*info).Algid);
|
|
|
|
|
|
|
|
data = (DWORD *)info->ExtraInfo.pbData;
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(info->ExtraInfo.cbData == 8, "Expected 8, got %ld\n", info->ExtraInfo.cbData);
|
|
|
|
ok(data[0] == CALG_OID_INFO_PARAMETERS, "Expected CALG_OID_INFO_PARAMETERS, got %lx\n", data[0]);
|
2018-06-22 15:26:54 +02:00
|
|
|
ok(data[1] == CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG,
|
2022-02-23 09:12:05 +01:00
|
|
|
"Expected CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG, got %lx\n", data[1]);
|
2018-06-22 15:26:54 +02:00
|
|
|
|
|
|
|
ok(!lstrcmpW(info->pwszCNGAlgid, BCRYPT_SHA256_ALGORITHM), "Expected %s, got %s\n",
|
|
|
|
wine_dbgstr_w(BCRYPT_SHA256_ALGORITHM), wine_dbgstr_w(info->pwszCNGAlgid));
|
|
|
|
ok(!lstrcmpW(info->pwszCNGExtraAlgid, CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM), "Expected %s, got %s\n",
|
|
|
|
wine_dbgstr_w(CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM), wine_dbgstr_w(info->pwszCNGExtraAlgid));
|
|
|
|
}
|
|
|
|
else
|
2018-06-22 15:26:55 +02:00
|
|
|
win_skip("Host does not support ECDSA_SHA256, skipping test\n");
|
2006-02-23 22:18:13 +01:00
|
|
|
}
|
|
|
|
|
2018-10-05 10:41:51 +02:00
|
|
|
static void test_registerOIDInfo(void)
|
|
|
|
{
|
|
|
|
static char test_oid[] = "1.2.3.4.5.6.7.8.9.10";
|
|
|
|
CRYPT_OID_INFO info1;
|
|
|
|
const CRYPT_OID_INFO *info2;
|
|
|
|
HKEY key;
|
|
|
|
DWORD ret, size, type, value;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CryptUnregisterOIDInfo(NULL);
|
|
|
|
ok(!ret, "should fail\n");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(GetLastError() == E_INVALIDARG, "got %#lx\n", GetLastError());
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
memset(&info1, 0, sizeof(info1));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CryptUnregisterOIDInfo(&info1);
|
|
|
|
ok(!ret, "should fail\n");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(GetLastError() == E_INVALIDARG, "got %#lx\n", GetLastError());
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
info1.cbSize = sizeof(info1);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CryptUnregisterOIDInfo(&info1);
|
|
|
|
ok(!ret, "should fail\n");
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(GetLastError() == E_INVALIDARG, "got %#lx\n", GetLastError());
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
info1.pszOID = test_oid;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CryptUnregisterOIDInfo(&info1);
|
|
|
|
ok(!ret, "should fail\n");
|
2020-12-17 10:29:57 +01:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
|
2022-02-23 09:12:05 +01:00
|
|
|
GetLastError() == ERROR_ACCESS_DENIED, "got %lu\n", GetLastError());
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
|
|
|
|
ok(!info2, "should fail\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-10-23 15:43:31 +02:00
|
|
|
/* While it succeeds, the next call does not write anything to the
|
|
|
|
* registry on Windows because dwGroupId == 0.
|
2018-10-05 10:41:51 +02:00
|
|
|
*/
|
|
|
|
ret = CryptRegisterOIDInfo(&info1, 0);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "got %lu\n", GetLastError());
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret == ERROR_FILE_NOT_FOUND, "got %lu\n", ret);
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
|
|
|
|
ok(!info2, "should fail\n");
|
|
|
|
|
2022-03-31 11:06:03 +02:00
|
|
|
info1.pwszName = L"winetest";
|
2018-10-05 10:41:51 +02:00
|
|
|
info1.dwGroupId = CRYPT_HASH_ALG_OID_GROUP_ID;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CryptRegisterOIDInfo(&info1, CRYPT_INSTALL_OID_INFO_BEFORE_FLAG);
|
|
|
|
if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
skip("Need admin rights\n");
|
|
|
|
return;
|
|
|
|
}
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret, "got %lu\n", GetLastError());
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
/* It looks like crypt32 reads the OID info from registry only on load,
|
|
|
|
* and CryptFindOIDInfo will find the registered OID on next run
|
|
|
|
*/
|
|
|
|
info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
|
|
|
|
ok(!info2, "should fail\n");
|
|
|
|
|
|
|
|
ret = RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(!ret, "got %lu\n", ret);
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
size = sizeof(buf);
|
|
|
|
ret = RegQueryValueExA(key, "Name", NULL, &type, (BYTE *)buf, &size);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(!ret, "got %lu\n", ret);
|
|
|
|
ok(type == REG_SZ, "got %lu\n", type);
|
2018-10-05 10:41:51 +02:00
|
|
|
ok(!strcmp(buf, "winetest"), "got %s\n", buf);
|
|
|
|
|
|
|
|
value = 0xdeadbeef;
|
|
|
|
size = sizeof(value);
|
|
|
|
ret = RegQueryValueExA(key, "Flags", NULL, &type, (BYTE *)&value, &size);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(!ret, "got %lu\n", ret);
|
|
|
|
ok(type == REG_DWORD, "got %lu\n", type);
|
|
|
|
ok(value == 1, "got %lu\n", value);
|
2018-10-05 10:41:51 +02:00
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
|
|
|
CryptUnregisterOIDInfo(&info1);
|
|
|
|
|
|
|
|
ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
|
2022-02-23 09:12:05 +01:00
|
|
|
ok(ret == ERROR_FILE_NOT_FOUND, "got %lu\n", ret);
|
2018-10-05 10:41:51 +02:00
|
|
|
}
|
|
|
|
|
2005-12-02 11:28:09 +01:00
|
|
|
START_TEST(oid)
|
|
|
|
{
|
2022-04-12 09:51:51 +02:00
|
|
|
test_OIDToAlgID();
|
|
|
|
test_AlgIDToOID();
|
2006-02-23 22:18:13 +01:00
|
|
|
test_enumOIDInfo();
|
|
|
|
test_findOIDInfo();
|
2018-10-05 10:41:51 +02:00
|
|
|
test_registerOIDInfo();
|
2005-12-02 11:28:09 +01:00
|
|
|
test_oidFunctionSet();
|
|
|
|
test_installOIDFunctionAddress();
|
|
|
|
test_registerOIDFunction();
|
2006-08-09 21:17:10 +02:00
|
|
|
test_registerDefaultOIDFunction();
|
2007-10-17 18:31:18 +02:00
|
|
|
test_getDefaultOIDFunctionAddress();
|
2005-12-02 11:28:09 +01:00
|
|
|
}
|