ReactOS 0.4.16-dev-1948-gd260c1d
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 void test_OIDToAlgID (void)
 
static void test_AlgIDToOID (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 const struct OIDToAlgID oidToAlgID []
 
static const struct OIDToAlgID algIDToOID []
 

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 199 of file oid.c.

Function Documentation

◆ countOidInfo()

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

Definition at line 482 of file oid.c.

483{
484 (*(DWORD *)pvArg)++;
485 return TRUE;
486}
#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 201 of file oid.c.

202{
203 return x;
204}
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 488 of file oid.c.

489{
490 return FALSE;
491}
#define FALSE
Definition: types.h:117

Referenced by test_enumOIDInfo().

◆ START_TEST()

START_TEST ( oid  )

Definition at line 682 of file oid.c.

683{
687#ifdef __REACTOS__
688 if ((GetVersion() & 0xFF) > 5) // test_findOIDInfo() crashes on Server 2003
689#endif
697}
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
static void test_oidFunctionSet(void)
Definition: oid.c:131
static void test_findOIDInfo(void)
Definition: oid.c:509
static void test_registerOIDInfo(void)
Definition: oid.c:591
static void test_AlgIDToOID(void)
Definition: oid.c:111
static void test_installOIDFunctionAddress(void)
Definition: oid.c:206
static void test_registerOIDFunction(void)
Definition: oid.c:265
static void test_OIDToAlgID(void)
Definition: oid.c:94
static void test_getDefaultOIDFunctionAddress(void)
Definition: oid.c:437
static void test_registerDefaultOIDFunction(void)
Definition: oid.c:348
static void test_enumOIDInfo(void)
Definition: oid.c:493

◆ test_AlgIDToOID()

static void test_AlgIDToOID ( void  )
static

Definition at line 111 of file oid.c.

112{
113 int i;
114 LPCSTR oid;
115
116 /* Test with a bogus one */
117 SetLastError(0xdeadbeef);
119 ok(!oid && GetLastError() == 0xdeadbeef,
120 "Didn't expect last error (%08lx) to be set\n", GetLastError());
121 for (i = 0; i < ARRAY_SIZE(algIDToOID); i++)
122 {
123 oid = CertAlgIdToOID(algIDToOID[i].algID);
124 /* Allow failure, not every version of Windows supports every algo */
125 ok(oid != NULL, "CertAlgIdToOID failed, expected %s\n", algIDToOID[i].oid);
126 if (oid)
127 ok(!strcmp(oid, algIDToOID[i].oid), "Expected %s, got %s\n", algIDToOID[i].oid, oid);
128 }
129}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: atltest.h:57
#define ARRAY_SIZE(A)
Definition: main.h:20
#define NULL
Definition: types.h:112
LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
Definition: oid.c:1888
#define SetLastError(x)
Definition: compat.h:752
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
static const struct OIDToAlgID algIDToOID[]
Definition: oid.c:79
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ALG_CLASS_SIGNATURE
Definition: wincrypt.h:1968
#define ALG_TYPE_ANY
Definition: wincrypt.h:1975
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by START_TEST().

◆ test_enumOIDInfo()

static void test_enumOIDInfo ( void  )
static

Definition at line 493 of file oid.c.

494{
495 BOOL ret;
496 DWORD count = 0;
497
498 /* This crashes
499 ret = CryptEnumOIDInfo(7, 0, NULL, NULL);
500 */
501
502 /* Silly tests, check that more than one thing is enumerated */
504 ok(ret && count > 0, "Expected more than item enumerated\n");
506 ok(!ret, "Expected FALSE\n");
507}
BOOL WINAPI CryptEnumOIDInfo(DWORD dwGroupId, DWORD dwFlags, void *pvArg, PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo)
Definition: oid.c:1776
return ret
Definition: mutex.c:146
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:482
static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
Definition: oid.c:488

Referenced by START_TEST().

◆ test_findOIDInfo()

static void test_findOIDInfo ( void  )
static

Definition at line 509 of file oid.c.

510{
511 static CHAR oid_rsa_md5[] = szOID_RSA_MD5, oid_sha256[] = szOID_NIST_sha256;
512 static CHAR oid_ecdsa_sha256[] = szOID_ECDSA_SHA256;
513 static CHAR oid_ecc_public_key[] = szOID_ECC_PUBLIC_KEY;
514 ALG_ID alg = CALG_SHA1;
515 ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
516 const struct oid_info
517 {
518 DWORD key_type;
519 void *key;
520 const char *oid;
521 ALG_ID algid;
522 ALG_ID broken_algid;
523 } oid_test_info [] =
524 {
530 };
532 int i;
533
534 info = CryptFindOIDInfo(0, NULL, 0);
535 ok(info == NULL, "Expected NULL\n");
536
537 for (i = 0; i < ARRAY_SIZE(oid_test_info); i++)
538 {
539 const struct oid_info *test = &oid_test_info[i];
540
541 info = CryptFindOIDInfo(test->key_type, test->key, 0);
542 ok(info != NULL, "Failed to find %s.\n", test->oid);
543 if (info)
544 {
545 ok(!strcmp(info->pszOID, test->oid), "Unexpected OID %s, expected %s\n", info->pszOID, test->oid);
546 ok(info->Algid == test->algid || broken(info->Algid == test->broken_algid),
547 "Unexpected Algid %d, expected %d\n", info->Algid, test->algid);
548 }
549 }
550
551 info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_ecdsa_sha256, 0);
552 if (info)
553 {
554 DWORD *data;
555
556 ok(info->cbSize == sizeof(*info), "Unexpected structure size %ld.\n", info->cbSize);
557 ok(!strcmp(info->pszOID, oid_ecdsa_sha256), "Expected %s, got %s\n", oid_ecdsa_sha256, info->pszOID);
558 ok(!lstrcmpW(info->pwszName, L"sha256ECDSA"), "Expected %s, got %s\n",
559 wine_dbgstr_w(L"sha256ECDSA"), wine_dbgstr_w(info->pwszName));
560 ok(info->dwGroupId == CRYPT_SIGN_ALG_OID_GROUP_ID,
561 "Expected CRYPT_SIGN_ALG_OID_GROUP_ID, got %lu\n", info->dwGroupId);
563 "Expected CALG_OID_INFO_CNG_ONLY, got %d\n", info->Algid);
564
565 data = (DWORD *)info->ExtraInfo.pbData;
566 ok(info->ExtraInfo.cbData == 8, "Expected 8, got %ld\n", info->ExtraInfo.cbData);
567 ok(data[0] == CALG_OID_INFO_PARAMETERS, "Expected CALG_OID_INFO_PARAMETERS, got %lx\n", data[0]);
569 "Expected CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG, got %lx\n", data[1]);
570
571 ok(!lstrcmpW(info->pwszCNGAlgid, BCRYPT_SHA256_ALGORITHM), "Expected %s, got %s\n",
573 ok(!lstrcmpW(info->pwszCNGExtraAlgid, CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM), "Expected %s, got %s\n",
575 }
576 else
577 win_skip("Host does not support ECDSA_SHA256, skipping test\n");
578
579 info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_ecc_public_key, 0);
580 ok(!!info, "got error %#lx.\n", GetLastError());
581 ok(!strcmp(info->pszOID, oid_ecc_public_key), "got %s.\n", info->pszOID);
582 ok(!wcscmp(info->pwszName, L"ECC"), "got %s.\n", wine_dbgstr_w(info->pwszName));
583 ok(info->dwGroupId == CRYPT_PUBKEY_ALG_OID_GROUP_ID, "got %lu.\n", info->dwGroupId);
584 ok(info->Algid == CALG_OID_INFO_PARAMETERS, "got %d.\n", info->Algid);
585 ok(!info->ExtraInfo.cbData, "got %ld.\n", info->ExtraInfo.cbData);
586 ok(!wcscmp(info->pwszCNGAlgid, CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM), "got %s.\n", wine_dbgstr_w(info->pwszCNGAlgid));
587 ok(info->pwszCNGExtraAlgid && !wcscmp(info->pwszCNGExtraAlgid, L""), "got %s.\n",
588 wine_dbgstr_w(info->pwszCNGExtraAlgid));
589}
#define broken(x)
Definition: atltest.h:178
#define BCRYPT_SHA256_ALGORITHM
Definition: bcrypt.h:75
PCCRYPT_OID_INFO WINAPI CryptFindOIDInfo(DWORD dwKeyType, void *pvKey, DWORD dwGroupId)
Definition: oid.c:1799
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4246
#define L(x)
Definition: resources.c:13
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define wine_dbgstr_w
Definition: kernel32.h:34
#define win_skip
Definition: minitest.h:67
static char oid_rsa_md5[]
Definition: msg.c:32
#define test
Definition: rosglue.h:37
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: copy.c:22
static const WCHAR CRYPT_OID_INFO_ECC_PARAMETERS_ALGORITHM[]
Definition: wincrypt.h:1608
#define CRYPT_PUBKEY_ALG_OID_GROUP_ID
Definition: wincrypt.h:1939
#define CALG_SHA1
Definition: wincrypt.h:2060
#define CRYPT_OID_INFO_SIGN_KEY
Definition: wincrypt.h:1958
#define szOID_RSA_MD5RSA
Definition: wincrypt.h:3174
#define szOID_ECDSA_SHA256
Definition: wincrypt.h:3219
#define szOID_NIST_sha256
Definition: wincrypt.h:3287
#define CALG_RSA_SIGN
Definition: wincrypt.h:2069
#define CALG_MD5
Definition: wincrypt.h:2058
#define CALG_SHA_256
Definition: wincrypt.h:2066
#define CALG_OID_INFO_PARAMETERS
Definition: wincrypt.h:1596
#define CALG_OID_INFO_CNG_ONLY
Definition: wincrypt.h:1595
#define szOID_ECC_PUBLIC_KEY
Definition: wincrypt.h:3216
#define CRYPT_OID_INFO_NAME_KEY
Definition: wincrypt.h:1956
#define szOID_RSA_MD5
Definition: wincrypt.h:3206
#define szOID_OIWSEC_sha1
Definition: wincrypt.h:3253
#define CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG
Definition: wincrypt.h:1953
#define CRYPT_OID_INFO_OID_KEY
Definition: wincrypt.h:1955
#define CRYPT_OID_INFO_ALGID_KEY
Definition: wincrypt.h:1957
#define CRYPT_SIGN_ALG_OID_GROUP_ID
Definition: wincrypt.h:1940
unsigned int ALG_ID
Definition: wincrypt.h:54
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ test_getDefaultOIDFunctionAddress()

static void test_getDefaultOIDFunctionAddress ( void  )
static

Definition at line 437 of file oid.c.

438{
439 BOOL ret;
441 void *funcAddr;
442 HCRYPTOIDFUNCADDR hFuncAddr;
443
444 /* Crash
445 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
446 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
447 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
448 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
449 &hFuncAddr);
450 */
451 set = CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
452 ok(set != 0, "CryptInitOIDFunctionSet failed: %ld\n", GetLastError());
453 /* This crashes if hFuncAddr is not 0 to begin with */
454 hFuncAddr = 0;
455 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
456 &hFuncAddr);
458 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
459 /* This fails with the normal encoding too, so built-in functions aren't
460 * returned.
461 */
463 &funcAddr, &hFuncAddr);
465 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
466
467 /* Even with a registered dll, this fails (since the dll doesn't exist) */
468 SetLastError(0xdeadbeef);
469 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
470 L"bogus.dll");
472 skip("Need admin rights\n");
473 else
474 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08lx\n", GetLastError());
475 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
476 &hFuncAddr);
478 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
479 CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", L"bogus.dll");
480}
#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 ERROR_ACCESS_DENIED
Definition: compat.h:97
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define X509_ASN_ENCODING
Definition: wincrypt.h:2501

Referenced by START_TEST().

◆ test_installOIDFunctionAddress()

static void test_installOIDFunctionAddress ( void  )
static

Definition at line 206 of file oid.c.

207{
208 BOOL ret;
211
212 /* This crashes
213 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
214 */
215
216 /* Installing zero functions should work */
217 SetLastError(0xdeadbeef);
218 ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
219 NULL, 0);
220 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
221 GetLastError());
222
223 /* The function name doesn't much matter */
224 SetLastError(0xdeadbeef);
225 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
226 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
227 GetLastError());
228 SetLastError(0xdeadbeef);
229 entry.pszOID = X509_CERT;
230 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
231 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
232 GetLastError());
233 set = CryptInitOIDFunctionSet("OhSoFunky", 0);
234 ok(set != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
235 if (set)
236 {
237 funcY funcAddr = NULL;
238 HCRYPTOIDFUNCADDR hFuncAddr = NULL;
239
240 /* This crashes
241 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
242 NULL);
243 */
245 (void **)&funcAddr, &hFuncAddr);
247 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
249 (void **)&funcAddr, &hFuncAddr);
251 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
253 (void **)&funcAddr, &hFuncAddr);
254 ok(ret, "CryptGetOIDFunctionAddress failed: %ld\n", GetLastError());
255 if (funcAddr)
256 {
257 int y = funcAddr(0xabadc0da);
258
259 ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
260 CryptFreeOIDFunctionAddress(hFuncAddr, 0);
261 }
262 }
263}
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:199
static int funky(int x)
Definition: oid.c:201
Definition: wincrypt.h:1568
#define X509_CERT
Definition: wincrypt.h:3517
#define CRYPT_DEFAULT_OID
Definition: wincrypt.h:2698

Referenced by START_TEST().

◆ test_oidFunctionSet()

static void test_oidFunctionSet ( void  )
static

Definition at line 131 of file oid.c.

132{
134 BOOL ret;
135 LPWSTR buf = NULL;
136 DWORD size;
137
138 /* This crashes
139 set = CryptInitOIDFunctionSet(NULL, 0);
140 */
141
142 /* The name doesn't mean much */
143 set1 = CryptInitOIDFunctionSet("funky", 0);
144 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
145 if (set1)
146 {
147 /* These crash
148 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
149 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
150 */
151 size = 0;
153 ok(ret, "CryptGetDefaultOIDDllList failed: %08lx\n", GetLastError());
154 if (ret)
155 {
156 buf = malloc(size * sizeof(WCHAR));
157 if (buf)
158 {
160 ok(ret, "CryptGetDefaultOIDDllList failed: %08lx\n",
161 GetLastError());
162 ok(!*buf, "Expected empty DLL list\n");
163 free(buf);
164 }
165 }
166 }
167
168 /* MSDN says flags must be 0, but it's not checked */
170 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
171 set2 = CryptInitOIDFunctionSet("", 0);
172 ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
173 /* There isn't a free function, so there must be only one set per name to
174 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
175 */
176 ok(set1 == set2, "Expected identical sets\n");
177 if (set1)
178 {
179 /* The empty name function set used here seems to correspond to
180 * DEFAULT.
181 */
182 }
183
184 /* There's no installed function for a built-in encoding. */
185 set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
186 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
187 if (set1)
188 {
189 void *funcAddr;
190 HCRYPTOIDFUNCADDR hFuncAddr;
191
193 &funcAddr, &hFuncAddr);
195 "Expected ERROR_FILE_NOT_FOUND, got %08lx\n", GetLastError());
196 }
197}
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
BOOL WINAPI CryptGetDefaultOIDDllList(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
Definition: oid.c:193
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_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by START_TEST().

◆ test_OIDToAlgID()

static void test_OIDToAlgID ( void  )
static

Definition at line 94 of file oid.c.

95{
96 int i;
97 DWORD alg;
98
99 /* Test with a bogus one */
100 alg = CertOIDToAlgId("1.2.3");
101 ok(!alg, "Expected failure, got %ld\n", alg);
102
103 for (i = 0; i < ARRAY_SIZE(oidToAlgID); i++)
104 {
105 alg = CertOIDToAlgId(oidToAlgID[i].oid);
106 ok(alg == oidToAlgID[i].algID || (oidToAlgID[i].altAlgID && alg == oidToAlgID[i].altAlgID),
107 "Expected %ld, got %ld\n", oidToAlgID[i].algID, alg);
108 }
109}
DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
Definition: oid.c:1901
static const struct OIDToAlgID oidToAlgID[]
Definition: oid.c:39

Referenced by START_TEST().

◆ test_registerDefaultOIDFunction()

static void test_registerDefaultOIDFunction ( void  )
static

Definition at line 348 of file oid.c.

349{
350 static const char fmt[] =
351 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
352 static const char func[] = "CertDllOpenStoreProv";
353 char buf[MAX_PATH];
354 BOOL ret;
355 LSTATUS rc;
356 HKEY key;
357
360 "Expected E_INVALIDARG, got %08lx\n", GetLastError());
361 /* This succeeds on WinXP, although the bogus entry is unusable.
362 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, L"bogus.dll");
363 */
364 /* Register one at index 0 */
365 SetLastError(0xdeadbeef);
366 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
367 L"bogus.dll");
369 {
370 skip("Need admin rights\n");
371 return;
372 }
373 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08lx\n", GetLastError());
374 /* Reregistering should fail */
375 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
376 L"bogus.dll");
378 "Expected ERROR_FILE_EXISTS, got %08lx\n", GetLastError());
379 /* Registering the same one at index 1 should also fail */
380 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
381 L"bogus.dll");
383 "Expected ERROR_FILE_EXISTS, got %08lx\n", GetLastError());
384 /* Registering a different one at index 1 succeeds */
385 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
386 L"bogus2.dll");
387 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08lx\n", GetLastError());
388 sprintf(buf, fmt, 0, func);
390 ok(rc == 0, "Expected key to exist, RegOpenKeyA failed: %ld\n", rc);
391 if (rc == 0)
392 {
393 CHAR dllBuf[MAX_PATH];
394 DWORD type, size;
395 LPSTR ptr;
396
397 size = ARRAY_SIZE(dllBuf);
398 rc = RegQueryValueExA(key, "Dll", NULL, &type, (LPBYTE)dllBuf, &size);
399 ok(rc == 0,
400 "Expected Dll value to exist, RegQueryValueExA failed: %ld\n", rc);
401 ok(type == REG_MULTI_SZ, "Expected type REG_MULTI_SZ, got %ld\n", type);
402 /* bogus.dll was registered first, so that should be first */
403 ptr = dllBuf;
404 ok(!lstrcmpiA(ptr, "bogus.dll"), "Unexpected dll\n");
405 ptr += lstrlenA(ptr) + 1;
406 ok(!lstrcmpiA(ptr, "bogus2.dll"), "Unexpected dll\n");
408 }
409 /* Unregister both of them */
410 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
411 L"bogus.dll");
412 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08lx\n",
413 GetLastError());
414 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
415 L"bogus2.dll");
416 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08lx\n",
417 GetLastError());
418 /* Now that they're both unregistered, unregistering should fail */
419 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
420 L"bogus.dll");
422 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
423
424 /* Repeat a few tests on the normal encoding type */
426 "CertDllOpenStoreProv", 0, L"bogus.dll");
427 ok(ret, "CryptRegisterDefaultOIDFunction failed\n");
429 "CertDllOpenStoreProv", L"bogus.dll");
430 ok(ret, "CryptUnregisterDefaultOIDFunction failed\n");
432 "CertDllOpenStoreProv", L"bogus.dll");
434 "Expected ERROR_FILE_NOT_FOUND, got %08lx\n", GetLastError());
435}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define E_INVALIDARG
Definition: ddrawi.h:101
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:4227
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
Definition: sprintf.c:45
#define REG_MULTI_SZ
Definition: nt_native.h:1504
Definition: dsound.c:943
unsigned char * LPBYTE
Definition: typedefs.h:53
#define ERROR_FILE_EXISTS
Definition: winerror.h:287
#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 265 of file oid.c.

266{
267 BOOL ret;
268
269 /* oddly, this succeeds under WinXP; the function name key is merely
270 * omitted. This may be a side effect of the registry code, I don't know.
271 * I don't check it because I doubt anyone would depend on it.
272 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
273 "1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
274 */
275 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
276 * E_INVALIDARG
277 */
279 NULL);
281 "Expected E_INVALIDARG: %ld\n", GetLastError());
282 /* This has no effect, but "succeeds" on XP */
284 "1.2.3.4.5.6.7.8.9.10", NULL, NULL);
285 ok(ret, "Expected pseudo-success, got %ld\n", GetLastError());
286 SetLastError(0xdeadbeef);
287 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
288 "1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
290 {
291 skip("Need admin rights\n");
292 return;
293 }
294 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
295 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
296 "1.2.3.4.5.6.7.8.9.10");
297 ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
299 "1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
300 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
302 "1.2.3.4.5.6.7.8.9.10");
303 ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
304 /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
306 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
307 "Could not delete bogus key\n");
308 /* Shouldn't have effect but registry keys are created */
309 ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
310 "1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
311 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
312 ret = CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
313 "1.2.3.4.5.6.7.8.9.10");
314 ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
315 /* Check with bogus encoding type. Registry keys are still created */
316 ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
317 "1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
318 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
319 ret = CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
320 "1.2.3.4.5.6.7.8.9.10");
321 ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
322 /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
323 * will still be there
324 */
326 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
327 "Could not delete CryptDllEncodeObject key\n");
328 /* This is written with value 3 verbatim. Thus, the encoding type isn't
329 * (for now) treated as a mask. Registry keys are created.
330 */
331 ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
332 "1.2.3.4.5.6.7.8.9.10", L"bogus.dll", NULL);
333 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
334 ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
335 "1.2.3.4.5.6.7.8.9.10");
336 ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
337 /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
338 * will still be there.
339 */
341 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
342 "Could not delete CryptDllEncodeObject key\n");
344 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
345 "Could not delete 'EncodingType 3' key\n");
346}
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:2503

Referenced by START_TEST().

◆ test_registerOIDInfo()

static void test_registerOIDInfo ( void  )
static

Definition at line 591 of file oid.c.

592{
593 static char test_oid[] = "1.2.3.4.5.6.7.8.9.10";
594 CRYPT_OID_INFO info1;
595 const CRYPT_OID_INFO *info2;
596 HKEY key;
598 char buf[256];
599
600 SetLastError(0xdeadbeef);
602 ok(!ret, "should fail\n");
603 ok(GetLastError() == E_INVALIDARG, "got %#lx\n", GetLastError());
604
605 memset(&info1, 0, sizeof(info1));
606 SetLastError(0xdeadbeef);
607 ret = CryptUnregisterOIDInfo(&info1);
608 ok(!ret, "should fail\n");
609 ok(GetLastError() == E_INVALIDARG, "got %#lx\n", GetLastError());
610
611 info1.cbSize = sizeof(info1);
612 SetLastError(0xdeadbeef);
613 ret = CryptUnregisterOIDInfo(&info1);
614 ok(!ret, "should fail\n");
615 ok(GetLastError() == E_INVALIDARG, "got %#lx\n", GetLastError());
616
617 info1.pszOID = test_oid;
618 SetLastError(0xdeadbeef);
619 ret = CryptUnregisterOIDInfo(&info1);
620 ok(!ret, "should fail\n");
622 GetLastError() == ERROR_ACCESS_DENIED, "got %lu\n", GetLastError());
623
624 info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
625 ok(!info2, "should fail\n");
626
627 SetLastError(0xdeadbeef);
628 /* While it succeeds, the next call does not write anything to the
629 * registry on Windows because dwGroupId == 0.
630 */
631 ret = CryptRegisterOIDInfo(&info1, 0);
632 ok(ret, "got %lu\n", GetLastError());
633
634 ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
635 ok(ret == ERROR_FILE_NOT_FOUND, "got %lu\n", ret);
636
637 info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
638 ok(!info2, "should fail\n");
639
640 info1.pwszName = L"winetest";
642 SetLastError(0xdeadbeef);
645 {
646 skip("Need admin rights\n");
647 return;
648 }
649 ok(ret, "got %lu\n", GetLastError());
650
651 /* It looks like crypt32 reads the OID info from registry only on load,
652 * and CryptFindOIDInfo will find the registered OID on next run
653 */
654 info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0);
655 ok(!info2, "should fail\n");
656
657 ret = RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
658 ok(!ret, "got %lu\n", ret);
659
660 memset(buf, 0, sizeof(buf));
661 size = sizeof(buf);
662 ret = RegQueryValueExA(key, "Name", NULL, &type, (BYTE *)buf, &size);
663 ok(!ret, "got %lu\n", ret);
664 ok(type == REG_SZ, "got %lu\n", type);
665 ok(!strcmp(buf, "winetest"), "got %s\n", buf);
666
667 value = 0xdeadbeef;
668 size = sizeof(value);
669 ret = RegQueryValueExA(key, "Flags", NULL, &type, (BYTE *)&value, &size);
670 ok(!ret, "got %lu\n", ret);
671 ok(type == REG_DWORD, "got %lu\n", type);
672 ok(value == 1, "got %lu\n", value);
673
675
677
678 ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key);
679 ok(ret == ERROR_FILE_NOT_FOUND, "got %lu\n", ret);
680}
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:615
#define memset(x, y, z)
Definition: compat.h:39
LPCWSTR pwszName
Definition: wincrypt.h:1619
Definition: pdh_main.c:96
#define CRYPT_HASH_ALG_OID_GROUP_ID
Definition: wincrypt.h:1937
#define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG
Definition: wincrypt.h:2701
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

Variable Documentation

◆ algIDToOID

const struct OIDToAlgID algIDToOID[]
static
Initial value:
= {
}
#define CALG_RC2
Definition: wincrypt.h:2083
#define CALG_RC4
Definition: wincrypt.h:2091
#define szOID_RSA_DES_EDE3_CBC
Definition: wincrypt.h:3209
#define szOID_RSA_SMIMEalgESDH
Definition: wincrypt.h:3201
#define szOID_RSA_MD4
Definition: wincrypt.h:3205
#define szOID_RSA_MD2
Definition: wincrypt.h:3204
#define CALG_MD2
Definition: wincrypt.h:2056
#define szOID_OIWSEC_desCBC
Definition: wincrypt.h:3234
#define CALG_RSA_KEYX
Definition: wincrypt.h:2080
#define CALG_DH_SF
Definition: wincrypt.h:2073
#define CALG_3DES
Definition: wincrypt.h:2084
#define szOID_RSA_RC4
Definition: wincrypt.h:3208
#define CALG_MD4
Definition: wincrypt.h:2057
#define szOID_RSA_RC2CBC
Definition: wincrypt.h:3207
#define szOID_X957_DSA
Definition: wincrypt.h:3214
#define CALG_SHA
Definition: wincrypt.h:2059
#define CALG_DH_EPHEM
Definition: wincrypt.h:2074
#define CALG_DES
Definition: wincrypt.h:2082
#define szOID_RSA_RSA
Definition: wincrypt.h:3168
#define szOID_ANSI_X942_DH
Definition: wincrypt.h:3212
#define CALG_DSS_SIGN
Definition: wincrypt.h:2070

Definition at line 79 of file oid.c.

Referenced by test_AlgIDToOID().

◆ oidToAlgID

const struct OIDToAlgID oidToAlgID[]
static

Definition at line 39 of file oid.c.

Referenced by test_OIDToAlgID().