ReactOS 0.4.15-dev-8145-ga541a46
oid.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winerror.h>
#include <wincrypt.h>
#include <winreg.h>
#include "wine/test.h"
Include dependency graph for oid.c:

Go to the source code of this file.

Classes

struct  OIDToAlgID
 

Macros

#define CRYPT_OID_INFO_HAS_EXTRA_FIELDS
 

Typedefs

typedef int(* funcY) (int)
 

Functions

static BOOL (WINAPI *pCryptEnumOIDInfo)(DWORD
 
static void testOIDToAlgID (void)
 
static void testAlgIDToOID (void)
 
static void test_oidFunctionSet (void)
 
static int funky (int x)
 
static void test_installOIDFunctionAddress (void)
 
static void test_registerOIDFunction (void)
 
static void test_registerDefaultOIDFunction (void)
 
static void test_getDefaultOIDFunctionAddress (void)
 
static BOOL WINAPI countOidInfo (PCCRYPT_OID_INFO pInfo, void *pvArg)
 
static BOOL WINAPI noOidInfo (PCCRYPT_OID_INFO pInfo, void *pvArg)
 
static void test_enumOIDInfo (void)
 
static void test_findOIDInfo (void)
 
static void test_registerOIDInfo (void)
 
 START_TEST (oid)
 

Variables

static DWORD
 
static void PFN_CRYPT_ENUM_OID_INFO
 
static const struct OIDToAlgID oidToAlgID []
 
static const struct OIDToAlgID algIDToOID []
 
static const WCHAR bogusDll [] = { 'b','o','g','u','s','.','d','l','l',0 }
 
static const WCHAR bogus2Dll [] = { 'b','o','g','u','s','2','.','d','l','l',0 }
 

Macro Definition Documentation

◆ CRYPT_OID_INFO_HAS_EXTRA_FIELDS

#define CRYPT_OID_INFO_HAS_EXTRA_FIELDS

Definition at line 26 of file oid.c.

Typedef Documentation

◆ funcY

typedef int(* funcY) (int)

Definition at line 225 of file oid.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pCryptEnumOIDInfo)
static

◆ countOidInfo()

static BOOL WINAPI countOidInfo ( PCCRYPT_OID_INFO  pInfo,
void pvArg 
)
static

Definition at line 513 of file oid.c.

514{
515 (*(DWORD *)pvArg)++;
516 return TRUE;
517}
#define TRUE
Definition: types.h:120
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by test_enumOIDInfo().

◆ funky()

static int funky ( int  x)
static

Definition at line 227 of file oid.c.

228{
229 return x;
230}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Referenced by test_installOIDFunctionAddress().

◆ noOidInfo()

static BOOL WINAPI noOidInfo ( PCCRYPT_OID_INFO  pInfo,
void pvArg 
)
static

Definition at line 519 of file oid.c.

520{
521 return FALSE;
522}
#define FALSE
Definition: types.h:117

Referenced by test_enumOIDInfo().

◆ START_TEST()

START_TEST ( oid  )

Definition at line 709 of file oid.c.

710{
711 HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
712 pCryptEnumOIDInfo = (void*)GetProcAddress(hCrypt32, "CryptEnumOIDInfo");
713
724}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static void test_oidFunctionSet(void)
Definition: oid.c:156
static void testAlgIDToOID(void)
Definition: oid.c:118
static void test_findOIDInfo(void)
Definition: oid.c:546
static void testOIDToAlgID(void)
Definition: oid.c:101
static void test_registerOIDInfo(void)
Definition: oid.c:618
static void test_installOIDFunctionAddress(void)
Definition: oid.c:232
static void test_registerOIDFunction(void)
Definition: oid.c:293
static void test_getDefaultOIDFunctionAddress(void)
Definition: oid.c:468
static void test_registerDefaultOIDFunction(void)
Definition: oid.c:376
static void test_enumOIDInfo(void)
Definition: oid.c:524

◆ test_enumOIDInfo()

static void test_enumOIDInfo ( void  )
static

Definition at line 524 of file oid.c.

525{
526 BOOL ret;
527 DWORD count = 0;
528
529 if (!pCryptEnumOIDInfo)
530 {
531 win_skip("CryptEnumOIDInfo() is not available\n");
532 return;
533 }
534
535 /* This crashes
536 ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
537 */
538
539 /* Silly tests, check that more than one thing is enumerated */
540 ret = pCryptEnumOIDInfo(0, 0, &count, countOidInfo);
541 ok(ret && count > 0, "Expected more than item enumerated\n");
542 ret = pCryptEnumOIDInfo(0, 0, NULL, noOidInfo);
543 ok(!ret, "Expected FALSE\n");
544}
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint GLuint GLsizei count
Definition: gl.h:1545
static BOOL WINAPI countOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
Definition: oid.c:513
static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
Definition: oid.c:519
#define win_skip
Definition: test.h:163
int ret

Referenced by START_TEST().

◆ test_findOIDInfo()

static void test_findOIDInfo ( void  )
static

Definition at line 546 of file oid.c.

547{
548 static WCHAR sha256ECDSA[] = { 's','h','a','2','5','6','E','C','D','S','A',0 };
549 static WCHAR sha1[] = { 's','h','a','1',0 };
550 static CHAR oid_rsa_md5[] = szOID_RSA_MD5, oid_sha256[] = szOID_NIST_sha256;
551 static CHAR oid_ecdsa_sha256[] = szOID_ECDSA_SHA256;
552 ALG_ID alg = CALG_SHA1;
553 ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
554 const struct oid_info
555 {
556 DWORD key_type;
557 void *key;
558 const char *oid;
559 ALG_ID algid;
560 ALG_ID broken_algid;
561 } oid_test_info [] =
562 {
568 };
570 int i;
571
572 info = CryptFindOIDInfo(0, NULL, 0);
573 ok(info == NULL, "Expected NULL\n");
574
575 for (i = 0; i < ARRAY_SIZE(oid_test_info); i++)
576 {
577 const struct oid_info *test = &oid_test_info[i];
578
579 info = CryptFindOIDInfo(test->key_type, test->key, 0);
580 ok(info != NULL, "Failed to find %s.\n", test->oid);
581 if (info)
582 {
583 ok(!strcmp(info->pszOID, test->oid), "Unexpected OID %s, expected %s\n", info->pszOID, test->oid);
584 ok(U(*info).Algid == test->algid || broken(U(*info).Algid == test->broken_algid),
585 "Unexpected Algid %d, expected %d\n", U(*info).Algid, test->algid);
586 }
587 }
588
589 info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_ecdsa_sha256, 0);
590 if (info)
591 {
592 DWORD *data;
593
594 ok(info->cbSize == sizeof(*info), "Unexpected structure size %d.\n", info->cbSize);
595 ok(!strcmp(info->pszOID, oid_ecdsa_sha256), "Expected %s, got %s\n", oid_ecdsa_sha256, info->pszOID);
596 ok(!lstrcmpW(info->pwszName, sha256ECDSA), "Expected %s, got %s\n",
598 ok(info->dwGroupId == CRYPT_SIGN_ALG_OID_GROUP_ID,
599 "Expected CRYPT_SIGN_ALG_OID_GROUP_ID, got %u\n", info->dwGroupId);
600 ok(U(*info).Algid == CALG_OID_INFO_CNG_ONLY,
601 "Expected CALG_OID_INFO_CNG_ONLY, got %d\n", U(*info).Algid);
602
603 data = (DWORD *)info->ExtraInfo.pbData;
604 ok(info->ExtraInfo.cbData == 8, "Expected 8, got %d\n", info->ExtraInfo.cbData);
605 ok(data[0] == CALG_OID_INFO_PARAMETERS, "Expected CALG_OID_INFO_PARAMETERS, got %x\n", data[0]);
607 "Expected CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG, got %x\n", data[1]);
608
609 ok(!lstrcmpW(info->pwszCNGAlgid, BCRYPT_SHA256_ALGORITHM), "Expected %s, got %s\n",
611 ok(!lstrcmpW(info->pwszCNGExtraAlgid, CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM), "Expected %s, got %s\n",
613 }
614 else
615 win_skip("Host does not support ECDSA_SHA256, skipping test\n");
616}
#define broken(x)
Definition: _sntprintf.h:21
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ARRAY_SIZE(A)
Definition: main.h:33
#define U(x)
Definition: wordpad.c:45
#define BCRYPT_SHA256_ALGORITHM
Definition: bcrypt.h:75
#define sha1
Definition: compat-1.3.h:2261
PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey, DWORD dwGroupId)
Definition: oid.c:1799
static const WCHAR sha256ECDSA[]
Definition: oid.c:1247
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4242
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define wine_dbgstr_w
Definition: kernel32.h:34
static char oid_rsa_md5[]
Definition: msg.c:34
#define test
Definition: rosglue.h:37
Definition: copy.c:22
static const WCHAR CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM[]
Definition: wincrypt.h:1394
#define CALG_SHA1
Definition: wincrypt.h:1807
#define CRYPT_OID_INFO_SIGN_KEY
Definition: wincrypt.h:1705
#define szOID_RSA_MD5RSA
Definition: wincrypt.h:3021
#define szOID_ECDSA_SHA256
Definition: wincrypt.h:3066
#define szOID_NIST_sha256
Definition: wincrypt.h:3351
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define CALG_MD5
Definition: wincrypt.h:1805
#define CALG_SHA_256
Definition: wincrypt.h:1813
#define CALG_OID_INFO_PARAMETERS
Definition: wincrypt.h:1374
#define CALG_OID_INFO_CNG_ONLY
Definition: wincrypt.h:1373
#define CRYPT_OID_INFO_NAME_KEY
Definition: wincrypt.h:1703
#define szOID_RSA_MD5
Definition: wincrypt.h:3053
#define szOID_OIWSEC_sha1
Definition: wincrypt.h:3100
#define CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG
Definition: wincrypt.h:1700
#define CRYPT_OID_INFO_OID_KEY
Definition: wincrypt.h:1702
#define CRYPT_OID_INFO_ALGID_KEY
Definition: wincrypt.h:1704
#define CRYPT_SIGN_ALG_OID_GROUP_ID
Definition: wincrypt.h:1687
unsigned int ALG_ID
Definition: wincrypt.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ test_getDefaultOIDFunctionAddress()

static void test_getDefaultOIDFunctionAddress ( void  )
static

Definition at line 468 of file oid.c.

469{
470 BOOL ret;
472 void *funcAddr;
473 HCRYPTOIDFUNCADDR hFuncAddr;
474
475 /* Crash
476 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
477 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
478 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
479 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
480 &hFuncAddr);
481 */
482 set = CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
483 ok(set != 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
484 /* This crashes if hFuncAddr is not 0 to begin with */
485 hFuncAddr = 0;
486 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
487 &hFuncAddr);
489 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
490 /* This fails with the normal encoding too, so built-in functions aren't
491 * returned.
492 */
494 &funcAddr, &hFuncAddr);
496 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
497
498 /* Even with a registered dll, this fails (since the dll doesn't exist) */
499 SetLastError(0xdeadbeef);
500 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
501 bogusDll);
503 skip("Need admin rights\n");
504 else
505 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
506 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
507 &hFuncAddr);
509 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
510 CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll);
511}
#define skip(...)
Definition: atltest.h:64
Definition: _set.h:50
BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
Definition: oid.c:1109
BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, LPCWSTR pwszDll)
Definition: oid.c:1142
HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName, DWORD dwFlags)
Definition: oid.c:114
BOOL WINAPI CryptGetDefaultOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void **ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
Definition: oid.c:511
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static const WCHAR bogusDll[]
Definition: oid.c:98
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297

Referenced by START_TEST().

◆ test_installOIDFunctionAddress()

static void test_installOIDFunctionAddress ( void  )
static

Definition at line 232 of file oid.c.

233{
234 BOOL ret;
237
238 /* This crashes
239 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
240 */
241
242 /* Installing zero functions should work */
243 SetLastError(0xdeadbeef);
244 ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
245 NULL, 0);
246 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
247 GetLastError());
248
249 /* The function name doesn't much matter */
250 SetLastError(0xdeadbeef);
251 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
252 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
253 GetLastError());
254 SetLastError(0xdeadbeef);
255 entry.pszOID = X509_CERT;
256 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
257 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
258 GetLastError());
259 set = CryptInitOIDFunctionSet("OhSoFunky", 0);
260 ok(set != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
261 if (set)
262 {
263 funcY funcAddr = NULL;
264 HCRYPTOIDFUNCADDR hFuncAddr = NULL;
265
266 /* This crashes
267 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
268 NULL);
269 */
271 (void **)&funcAddr, &hFuncAddr);
273 GetLastError() == E_INVALIDARG /* some Win98 */),
274 "Expected ERROR_FILE_NOT_FOUND or E_INVALIDARG, got %d\n",
275 GetLastError());
277 (void **)&funcAddr, &hFuncAddr);
279 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
281 (void **)&funcAddr, &hFuncAddr);
282 ok(ret, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
283 if (funcAddr)
284 {
285 int y = funcAddr(0xabadc0da);
286
287 ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
288 CryptFreeOIDFunctionAddress(hFuncAddr, 0);
289 }
290 }
291}
#define E_INVALIDARG
Definition: ddrawi.h:101
BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
Definition: oid.c:387
BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule, DWORD dwEncodingType, LPCSTR pszFuncName, DWORD cFuncEntry, const CRYPT_OID_FUNC_ENTRY rgFuncEntry[], DWORD dwFlags)
Definition: oid.c:237
BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr, DWORD dwFlags)
Definition: oid.c:468
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
uint32_t entry
Definition: isohybrid.c:63
int(* funcY)(int)
Definition: oid.c:225
static int funky(int x)
Definition: oid.c:227
Definition: wincrypt.h:1354
#define X509_CERT
Definition: wincrypt.h:3365
#define CRYPT_DEFAULT_OID
Definition: wincrypt.h:2535

Referenced by START_TEST().

◆ test_oidFunctionSet()

static void test_oidFunctionSet ( void  )
static

Definition at line 156 of file oid.c.

157{
159 BOOL ret;
160 LPWSTR buf = NULL;
161 DWORD size;
162
163 /* This crashes
164 set = CryptInitOIDFunctionSet(NULL, 0);
165 */
166
167 /* The name doesn't mean much */
168 set1 = CryptInitOIDFunctionSet("funky", 0);
169 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
170 if (set1)
171 {
172 /* These crash
173 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
174 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
175 */
176 size = 0;
178 ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
179 if (ret)
180 {
181 buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
182 if (buf)
183 {
185 ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n",
186 GetLastError());
187 ok(!*buf, "Expected empty DLL list\n");
189 }
190 }
191 }
192
193 /* MSDN says flags must be 0, but it's not checked */
195 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
196 set2 = CryptInitOIDFunctionSet("", 0);
197 ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
198 /* There isn't a free function, so there must be only one set per name to
199 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
200 */
201 ok(set1 == set2, "Expected identical sets\n");
202 if (set1)
203 {
204 /* The empty name function set used here seems to correspond to
205 * DEFAULT.
206 */
207 }
208
209 /* There's no installed function for a built-in encoding. */
210 set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
211 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
212 if (set1)
213 {
214 void *funcAddr;
215 HCRYPTOIDFUNCADDR hFuncAddr;
216
218 &funcAddr, &hFuncAddr);
220 broken(ret) /* some Win98 */,
221 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
222 }
223}
BOOL WINAPI CryptGetDefaultOIDDllList(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
Definition: oid.c:193
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static void set1(uint8 *data, int x, int y)
Definition: nanoxwin.c:811
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by START_TEST().

◆ test_registerDefaultOIDFunction()

static void test_registerDefaultOIDFunction ( void  )
static

Definition at line 376 of file oid.c.

377{
378 static const char fmt[] =
379 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
380 static const char func[] = "CertDllOpenStoreProv";
381 char buf[MAX_PATH];
382 BOOL ret;
383 LSTATUS rc;
384 HKEY key;
385
388 "Expected E_INVALIDARG, got %08x\n", GetLastError());
389 /* This succeeds on WinXP, although the bogus entry is unusable.
390 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
391 */
392 /* Register one at index 0 */
393 SetLastError(0xdeadbeef);
394 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
395 bogusDll);
397 {
398 skip("Need admin rights\n");
399 return;
400 }
401 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
402 /* Reregistering should fail */
403 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
404 bogusDll);
406 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
407 /* Registering the same one at index 1 should also fail */
408 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
409 bogusDll);
411 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
412 /* Registering a different one at index 1 succeeds */
413 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
414 bogus2Dll);
415 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
416 sprintf(buf, fmt, 0, func);
418 ok(rc == 0, "Expected key to exist, RegOpenKeyA failed: %d\n", rc);
419 if (rc == 0)
420 {
421 static const CHAR dllA[] = "Dll";
422 static const CHAR bogusDll_A[] = "bogus.dll";
423 static const CHAR bogus2Dll_A[] = "bogus2.dll";
424 CHAR dllBuf[MAX_PATH];
425 DWORD type, size;
426 LPSTR ptr;
427
428 size = ARRAY_SIZE(dllBuf);
429 rc = RegQueryValueExA(key, dllA, NULL, &type, (LPBYTE)dllBuf, &size);
430 ok(rc == 0,
431 "Expected Dll value to exist, RegQueryValueExA failed: %d\n", rc);
432 ok(type == REG_MULTI_SZ, "Expected type REG_MULTI_SZ, got %d\n", type);
433 /* bogusDll was registered first, so that should be first */
434 ptr = dllBuf;
435 ok(!lstrcmpiA(ptr, bogusDll_A), "Unexpected dll\n");
436 ptr += lstrlenA(ptr) + 1;
437 ok(!lstrcmpiA(ptr, bogus2Dll_A), "Unexpected dll\n");
439 }
440 /* Unregister both of them */
441 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
442 bogusDll);
443 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
444 GetLastError());
445 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
446 bogus2Dll);
447 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
448 GetLastError());
449 /* Now that they're both unregistered, unregistering should fail */
450 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
451 bogusDll);
453 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
454
455 /* Repeat a few tests on the normal encoding type */
457 "CertDllOpenStoreProv", 0, bogusDll);
458 ok(ret, "CryptRegisterDefaultOIDFunction failed\n");
460 "CertDllOpenStoreProv", bogusDll);
461 ok(ret, "CryptUnregisterDefaultOIDFunction failed\n");
463 "CertDllOpenStoreProv", bogusDll);
465 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
466}
#define RegCloseKey(hKey)
Definition: registry.h:49
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3234
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
#define MAX_PATH
Definition: compat.h:34
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4223
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLenum func
Definition: glext.h:6028
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
static PVOID ptr
Definition: dispmode.c:27
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static const WCHAR bogus2Dll[]
Definition: oid.c:99
#define REG_MULTI_SZ
Definition: nt_native.h:1501
Definition: dsound.c:943
unsigned char * LPBYTE
Definition: typedefs.h:53
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
char * LPSTR
Definition: xmlstorage.h:182

Referenced by START_TEST().

◆ test_registerOIDFunction()

static void test_registerOIDFunction ( void  )
static

Definition at line 293 of file oid.c.

294{
295 BOOL ret;
296
297 /* oddly, this succeeds under WinXP; the function name key is merely
298 * omitted. This may be a side effect of the registry code, I don't know.
299 * I don't check it because I doubt anyone would depend on it.
300 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
301 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
302 */
303 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
304 * E_INVALIDARG
305 */
307 NULL);
309 "Expected E_INVALIDARG: %d\n", GetLastError());
310 /* This has no effect, but "succeeds" on XP */
312 "1.2.3.4.5.6.7.8.9.10", NULL, NULL);
313 ok(ret, "Expected pseudo-success, got %d\n", GetLastError());
314 SetLastError(0xdeadbeef);
315 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
316 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
318 {
319 skip("Need admin rights\n");
320 return;
321 }
322 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
323 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
324 "1.2.3.4.5.6.7.8.9.10");
325 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
327 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
328 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
330 "1.2.3.4.5.6.7.8.9.10");
331 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
332 /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
334 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
335 "Could not delete bogus key\n");
336 /* Shouldn't have effect but registry keys are created */
337 ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
338 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
339 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
340 ret = CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
341 "1.2.3.4.5.6.7.8.9.10");
342 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
343 /* Check with bogus encoding type. Registry keys are still created */
344 ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
345 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
346 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
347 ret = CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
348 "1.2.3.4.5.6.7.8.9.10");
349 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
350 /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
351 * will still be there
352 */
354 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
355 "Could not delete CryptDllEncodeObject key\n");
356 /* This is written with value 3 verbatim. Thus, the encoding type isn't
357 * (for now) treated as a mask. Registry keys are created.
358 */
359 ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
360 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
361 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
362 ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
363 "1.2.3.4.5.6.7.8.9.10");
364 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
365 /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
366 * will still be there.
367 */
369 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
370 "Could not delete CryptDllEncodeObject key\n");
372 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
373 "Could not delete 'EncodingType 3' key\n");
374}
LONG WINAPI RegDeleteKeyA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey)
Definition: reg.c:1224
BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
Definition: oid.c:647
BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, LPCSTR pszOID)
Definition: oid.c:831
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2299

Referenced by START_TEST().

◆ test_registerOIDInfo()

static void test_registerOIDInfo ( void  )
static

Definition at line 618 of file oid.c.

619{
620 static const WCHAR winetestW[] = { 'w','i','n','e','t','e','s','t',0 };
621 static char test_oid[] = "1.2.3.4.5.6.7.8.9.10";
622 CRYPT_OID_INFO info1;
623 const CRYPT_OID_INFO *info2;
624 HKEY key;
626 char buf[256];
627
628 SetLastError(0xdeadbeef);
630 ok(!ret, "should fail\n");
631 ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
632
633 memset(&info1, 0, sizeof(info1));
634 SetLastError(0xdeadbeef);
635 ret = CryptUnregisterOIDInfo(&info1);
636 ok(!ret, "should fail\n");
637 ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
638
639 info1.cbSize = sizeof(info1);
640 SetLastError(0xdeadbeef);
641 ret = CryptUnregisterOIDInfo(&info1);
642 ok(!ret, "should fail\n");
643 ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError());
644
645 info1.pszOID = test_oid;
646 SetLastError(0xdeadbeef);
647 ret = CryptUnregisterOIDInfo(&info1);
648 ok(!ret, "should fail\n");
650
651 info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
652 ok(!info2, "should fail\n");
653
654 SetLastError(0xdeadbeef);
655 /* While it succeeds, the next call does not write anything to the
656 * registry on Windows because dwGroupId == 0.
657 */
658 ret = CryptRegisterOIDInfo(&info1, 0);
659 ok(ret, "got %u\n", GetLastError());
660
661 ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
662 ok(ret == ERROR_FILE_NOT_FOUND, "got %u\n", ret);
663
664 info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
665 ok(!info2, "should fail\n");
666
667 info1.pwszName = winetestW;
669 SetLastError(0xdeadbeef);
672 {
673 skip("Need admin rights\n");
674 return;
675 }
676 ok(ret, "got %u\n", GetLastError());
677
678 /* It looks like crypt32 reads the OID info from registry only on load,
679 * and CryptFindOIDInfo will find the registered OID on next run
680 */
681 info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
682 ok(!info2, "should fail\n");
683
684 ret = RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
685 ok(!ret, "got %u\n", ret);
686
687 memset(buf, 0, sizeof(buf));
688 size = sizeof(buf);
689 ret = RegQueryValueExA(key, "Name", NULL, &type, (BYTE *)buf, &size);
690 ok(!ret, "got %u\n", ret);
691 ok(type == REG_SZ, "got %u\n", type);
692 ok(!strcmp(buf, "winetest"), "got %s\n", buf);
693
694 value = 0xdeadbeef;
695 size = sizeof(value);
696 ret = RegQueryValueExA(key, "Flags", NULL, &type, (BYTE *)&value, &size);
697 ok(!ret, "got %u\n", ret);
698 ok(type == REG_DWORD, "got %u\n", type);
699 ok(value == 1, "got %u\n", value);
700
702
704
705 ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
706 ok(ret == ERROR_FILE_NOT_FOUND, "got %u\n", ret);
707}
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1179
BOOL WINAPI CryptRegisterOIDInfo(PCCRYPT_OID_INFO info, DWORD flags)
Definition: oid.c:750
BOOL WINAPI CryptUnregisterOIDInfo(PCCRYPT_OID_INFO info)
Definition: oid.c:708
#define REG_SZ
Definition: layer.c:22
#define REG_DWORD
Definition: sdbapi.c:596
#define memset(x, y, z)
Definition: compat.h:39
static const WCHAR winetestW[]
Definition: shelldispatch.c:47
LPCWSTR pwszName
Definition: wincrypt.h:1405
Definition: pdh_main.c:94
#define CRYPT_HASH_ALG_OID_GROUP_ID
Definition: wincrypt.h:1684
#define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG
Definition: wincrypt.h:2538
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ testAlgIDToOID()

static void testAlgIDToOID ( void  )
static

Definition at line 118 of file oid.c.

119{
120 int i;
121 LPCSTR oid;
122
123 /* Test with a bogus one */
124 SetLastError(0xdeadbeef);
126 ok(!oid && GetLastError() == 0xdeadbeef,
127 "Didn't expect last error (%08x) to be set\n", GetLastError());
128 for (i = 0; i < ARRAY_SIZE(algIDToOID); i++)
129 {
130 oid = CertAlgIdToOID(algIDToOID[i].algID);
131 /* Allow failure, not every version of Windows supports every algo */
132 ok(oid != NULL || broken(!oid), "CertAlgIdToOID failed, expected %s\n", algIDToOID[i].oid);
133 if (oid)
134 {
135 if (strcmp(oid, algIDToOID[i].oid))
136 {
137 if (algIDToOID[i].altOid)
138 ok(!strcmp(oid, algIDToOID[i].altOid),
139 "Expected %s or %s, got %s\n", algIDToOID[i].oid,
140 algIDToOID[i].altOid, oid);
141 else
142 {
143 /* No need to rerun the test, we already know it failed. */
144 ok(0, "Expected %s, got %s\n", algIDToOID[i].oid, oid);
145 }
146 }
147 else
148 {
149 /* No need to rerun the test, we already know it succeeded. */
150 ok(1, "Expected %s, got %s\n", algIDToOID[i].oid, oid);
151 }
152 }
153 }
154}
LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
Definition: oid.c:1888
static const struct OIDToAlgID algIDToOID[]
Definition: oid.c:83
#define ALG_CLASS_SIGNATURE
Definition: wincrypt.h:1715
#define ALG_TYPE_ANY
Definition: wincrypt.h:1722
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by START_TEST().

◆ testOIDToAlgID()

static void testOIDToAlgID ( void  )
static

Definition at line 101 of file oid.c.

102{
103 int i;
104 DWORD alg;
105
106 /* Test with a bogus one */
107 alg = CertOIDToAlgId("1.2.3");
108 ok(!alg, "Expected failure, got %d\n", alg);
109
110 for (i = 0; i < ARRAY_SIZE(oidToAlgID); i++)
111 {
112 alg = CertOIDToAlgId(oidToAlgID[i].oid);
113 ok(alg == oidToAlgID[i].algID || (oidToAlgID[i].altAlgID && alg == oidToAlgID[i].altAlgID),
114 "Expected %d, got %d\n", oidToAlgID[i].algID, alg);
115 }
116}
DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
Definition: oid.c:1901
static const struct OIDToAlgID oidToAlgID[]
Definition: oid.c:44

Referenced by START_TEST().

Variable Documentation

◆ algIDToOID

const struct OIDToAlgID algIDToOID[]
static
Initial value:
= {
}
#define CALG_RC2
Definition: wincrypt.h:1829
#define CALG_RC4
Definition: wincrypt.h:1837
#define szOID_RSA_DES_EDE3_CBC
Definition: wincrypt.h:3056
#define szOID_RSA_SMIMEalgESDH
Definition: wincrypt.h:3048
#define szOID_RSA_MD4
Definition: wincrypt.h:3052
#define szOID_RSA_MD2
Definition: wincrypt.h:3051
#define CALG_MD2
Definition: wincrypt.h:1803
#define szOID_OIWSEC_desCBC
Definition: wincrypt.h:3081
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
#define CALG_DH_SF
Definition: wincrypt.h:1819
#define CALG_3DES
Definition: wincrypt.h:1830
#define szOID_RSA_RC4
Definition: wincrypt.h:3055
#define CALG_MD4
Definition: wincrypt.h:1804
#define szOID_RSA_RC2CBC
Definition: wincrypt.h:3054
#define szOID_X957_DSA
Definition: wincrypt.h:3061
#define CALG_SHA
Definition: wincrypt.h:1806
#define CALG_DH_EPHEM
Definition: wincrypt.h:1820
#define CALG_DES
Definition: wincrypt.h:1828
#define szOID_RSA_RSA
Definition: wincrypt.h:3015
#define szOID_OIWSEC_dsa
Definition: wincrypt.h:3086
#define szOID_ANSI_X942_DH
Definition: wincrypt.h:3059
#define CALG_DSS_SIGN
Definition: wincrypt.h:1817

Definition at line 83 of file oid.c.

Referenced by testAlgIDToOID().

◆ bogus2Dll

const WCHAR bogus2Dll[] = { 'b','o','g','u','s','2','.','d','l','l',0 }
static

Definition at line 99 of file oid.c.

Referenced by test_registerDefaultOIDFunction().

◆ bogusDll

const WCHAR bogusDll[] = { 'b','o','g','u','s','.','d','l','l',0 }
static

◆ DWORD

Definition at line 33 of file oid.c.

◆ oidToAlgID

const struct OIDToAlgID oidToAlgID[]
static

Definition at line 44 of file oid.c.

Referenced by testOIDToAlgID().

◆ PFN_CRYPT_ENUM_OID_INFO

void PFN_CRYPT_ENUM_OID_INFO

Definition at line 33 of file oid.c.