[21311] | 1 | /*
|
---|
| 2 | * Unit test suite for crypt32.dll's OID support functions.
|
---|
| 3 | *
|
---|
| 4 | * Copyright 2005 Juan Lang
|
---|
| 5 | *
|
---|
| 6 | * This library is free software; you can redistribute it and/or
|
---|
| 7 | * modify it under the terms of the GNU Lesser General Public
|
---|
| 8 | * License as published by the Free Software Foundation; either
|
---|
| 9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
| 10 | *
|
---|
| 11 | * This library is distributed in the hope that it will be useful,
|
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 14 | * Lesser General Public License for more details.
|
---|
| 15 | *
|
---|
| 16 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 17 | * License along with this library; if not, write to the Free Software
|
---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
| 19 | */
|
---|
| 20 | #include <stdio.h>
|
---|
| 21 | #include <stdarg.h>
|
---|
| 22 | #include <windef.h>
|
---|
| 23 | #include <winbase.h>
|
---|
| 24 | #include <winerror.h>
|
---|
| 25 | #include <wincrypt.h>
|
---|
| 26 | #include <winreg.h>
|
---|
| 27 |
|
---|
| 28 | #include "wine/test.h"
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | static BOOL (WINAPI *pCryptEnumOIDInfo)(DWORD,DWORD,void*,PFN_CRYPT_ENUM_OID_INFO);
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | struct OIDToAlgID
|
---|
| 35 | {
|
---|
| 36 | LPCSTR oid;
|
---|
| 37 | DWORD algID;
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | static const struct OIDToAlgID oidToAlgID[] = {
|
---|
| 41 | { szOID_RSA_RSA, CALG_RSA_KEYX },
|
---|
| 42 | { szOID_RSA_MD2RSA, CALG_MD2 },
|
---|
| 43 | { szOID_RSA_MD4RSA, CALG_MD4 },
|
---|
| 44 | { szOID_RSA_MD5RSA, CALG_MD5 },
|
---|
| 45 | { szOID_RSA_SHA1RSA, CALG_SHA },
|
---|
| 46 | { szOID_RSA_DH, CALG_DH_SF },
|
---|
| 47 | { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM },
|
---|
| 48 | { szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES },
|
---|
| 49 | { szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2 },
|
---|
| 50 | { szOID_RSA_MD2, CALG_MD2 },
|
---|
| 51 | { szOID_RSA_MD4, CALG_MD4 },
|
---|
| 52 | { szOID_RSA_MD5, CALG_MD5 },
|
---|
| 53 | { szOID_RSA_RC2CBC, CALG_RC2 },
|
---|
| 54 | { szOID_RSA_RC4, CALG_RC4 },
|
---|
| 55 | { szOID_RSA_DES_EDE3_CBC, CALG_3DES },
|
---|
| 56 | { szOID_ANSI_X942_DH, CALG_DH_SF },
|
---|
| 57 | { szOID_X957_DSA, CALG_DSS_SIGN },
|
---|
| 58 | { szOID_X957_SHA1DSA, CALG_SHA },
|
---|
| 59 | { szOID_OIWSEC_md4RSA, CALG_MD4 },
|
---|
| 60 | { szOID_OIWSEC_md5RSA, CALG_MD5 },
|
---|
| 61 | { szOID_OIWSEC_md4RSA2, CALG_MD4 },
|
---|
| 62 | { szOID_OIWSEC_desCBC, CALG_DES },
|
---|
| 63 | { szOID_OIWSEC_dsa, CALG_DSS_SIGN },
|
---|
| 64 | { szOID_OIWSEC_shaDSA, CALG_SHA },
|
---|
| 65 | { szOID_OIWSEC_shaRSA, CALG_SHA },
|
---|
| 66 | { szOID_OIWSEC_sha, CALG_SHA },
|
---|
| 67 | { szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX },
|
---|
| 68 | { szOID_OIWSEC_sha1, CALG_SHA },
|
---|
| 69 | { szOID_OIWSEC_dsaSHA1, CALG_SHA },
|
---|
| 70 | { szOID_OIWSEC_sha1RSASign, CALG_SHA },
|
---|
| 71 | { szOID_OIWDIR_md2RSA, CALG_MD2 },
|
---|
| 72 | { szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA },
|
---|
| 73 | { szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN },
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | static const struct OIDToAlgID algIDToOID[] = {
|
---|
| 77 | { szOID_RSA_RSA, CALG_RSA_KEYX },
|
---|
| 78 | { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM },
|
---|
| 79 | { szOID_RSA_MD2, CALG_MD2 },
|
---|
| 80 | { szOID_RSA_MD4, CALG_MD4 },
|
---|
| 81 | { szOID_RSA_MD5, CALG_MD5 },
|
---|
| 82 | { szOID_RSA_RC2CBC, CALG_RC2 },
|
---|
| 83 | { szOID_RSA_RC4, CALG_RC4 },
|
---|
| 84 | { szOID_RSA_DES_EDE3_CBC, CALG_3DES },
|
---|
| 85 | { szOID_ANSI_X942_DH, CALG_DH_SF },
|
---|
| 86 | { szOID_X957_DSA, CALG_DSS_SIGN },
|
---|
| 87 | { szOID_OIWSEC_desCBC, CALG_DES },
|
---|
| 88 | { szOID_OIWSEC_sha1, CALG_SHA },
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | static const WCHAR bogusDll[] = { 'b','o','g','u','s','.','d','l','l',0 };
|
---|
| 92 | static const WCHAR bogus2Dll[] = { 'b','o','g','u','s','2','.','d','l','l',0 };
|
---|
| 93 |
|
---|
| 94 | static void testOIDToAlgID(void)
|
---|
| 95 | {
|
---|
| 96 | int i;
|
---|
| 97 | DWORD alg;
|
---|
| 98 |
|
---|
| 99 | /* Test with a bogus one */
|
---|
| 100 | SetLastError(0xdeadbeef);
|
---|
| 101 | alg = CertOIDToAlgId("1.2.3");
|
---|
| 102 | ok(!alg, "Expected failure, got %d\n", alg);
|
---|
| 103 | ok(GetLastError() == 0xdeadbeef ||
|
---|
| 104 | GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND ||
|
---|
| 105 | GetLastError() == ERROR_INVALID_PARAMETER || /* Vista */
|
---|
| 106 | GetLastError() == ERROR_SUCCESS || /* win2k */
|
---|
| 107 | GetLastError() == ERROR_FILE_INVALID, /* another Vista */
|
---|
| 108 | "Expected ERROR_RESOURCE_NAME_NOT_FOUND, ERROR_INVALID_PARAMETER, "
|
---|
| 109 | "ERROR_SUCCESS or no error set, got %08x\n", GetLastError());
|
---|
| 110 |
|
---|
| 111 | for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++)
|
---|
| 112 | {
|
---|
| 113 | alg = CertOIDToAlgId(oidToAlgID[i].oid);
|
---|
| 114 | /* Not all Windows installations support all these, so make sure it's
|
---|
| 115 | * at least not the wrong one.
|
---|
| 116 | */
|
---|
| 117 | ok(alg == 0 || alg == oidToAlgID[i].algID,
|
---|
| 118 | "Expected %d, got %d\n", oidToAlgID[i].algID, alg);
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | static void testAlgIDToOID(void)
|
---|
| 123 | {
|
---|
| 124 | int i;
|
---|
| 125 | LPCSTR oid;
|
---|
| 126 |
|
---|
| 127 | /* Test with a bogus one */
|
---|
| 128 | SetLastError(0xdeadbeef);
|
---|
| 129 | oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80);
|
---|
| 130 | ok(!oid && GetLastError() == 0xdeadbeef,
|
---|
| 131 | "Didn't expect last error (%08x) to be set\n", GetLastError());
|
---|
| 132 | for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++)
|
---|
| 133 | {
|
---|
| 134 | oid = CertAlgIdToOID(algIDToOID[i].algID);
|
---|
| 135 | /* Allow failure, not every version of Windows supports every algo */
|
---|
| 136 | if (oid)
|
---|
| 137 | ok(!strcmp(oid, algIDToOID[i].oid),
|
---|
| 138 | "Expected %s, got %s\n", algIDToOID[i].oid, oid);
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | static void test_oidFunctionSet(void)
|
---|
| 143 | {
|
---|
| 144 | HCRYPTOIDFUNCSET set1, set2;
|
---|
| 145 | BOOL ret;
|
---|
| 146 | LPWSTR buf = NULL;
|
---|
| 147 | DWORD size;
|
---|
| 148 |
|
---|
| 149 | /* This crashes
|
---|
| 150 | set = CryptInitOIDFunctionSet(NULL, 0);
|
---|
| 151 | */
|
---|
| 152 |
|
---|
| 153 | /* The name doesn't mean much */
|
---|
| 154 | set1 = CryptInitOIDFunctionSet("funky", 0);
|
---|
| 155 | ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
|
---|
| 156 | if (set1)
|
---|
| 157 | {
|
---|
| 158 | /* These crash
|
---|
| 159 | ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
|
---|
| 160 | ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
|
---|
| 161 | */
|
---|
| 162 | size = 0;
|
---|
| 163 | ret = CryptGetDefaultOIDDllList(set1, 0, NULL, &size);
|
---|
| 164 | ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
|
---|
| 165 | if (ret)
|
---|
| 166 | {
|
---|
| 167 | buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
---|
| 168 | if (buf)
|
---|
| 169 | {
|
---|
| 170 | ret = CryptGetDefaultOIDDllList(set1, 0, buf, &size);
|
---|
| 171 | ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n",
|
---|
| 172 | GetLastError());
|
---|
| 173 | ok(!*buf, "Expected empty DLL list\n");
|
---|
| 174 | HeapFree(GetProcessHeap(), 0, buf);
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /* MSDN says flags must be 0, but it's not checked */
|
---|
| 180 | set1 = CryptInitOIDFunctionSet("", 1);
|
---|
| 181 | ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
|
---|
| 182 | set2 = CryptInitOIDFunctionSet("", 0);
|
---|
| 183 | ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
|
---|
| 184 | /* There isn't a free function, so there must be only one set per name to
|
---|
| 185 | * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
|
---|
| 186 | */
|
---|
| 187 | ok(set1 == set2, "Expected identical sets\n");
|
---|
| 188 | if (set1)
|
---|
| 189 | {
|
---|
| 190 | /* The empty name function set used here seems to correspond to
|
---|
| 191 | * DEFAULT.
|
---|
| 192 | */
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | /* There's no installed function for a built-in encoding. */
|
---|
| 196 | set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
|
---|
| 197 | ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
|
---|
| 198 | if (set1)
|
---|
| 199 | {
|
---|
| 200 | void *funcAddr;
|
---|
| 201 | HCRYPTOIDFUNCADDR hFuncAddr;
|
---|
| 202 |
|
---|
| 203 | ret = CryptGetOIDFunctionAddress(set1, X509_ASN_ENCODING, X509_CERT, 0,
|
---|
| 204 | &funcAddr, &hFuncAddr);
|
---|
| 205 | ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 206 | "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | typedef int (*funcY)(int);
|
---|
| 211 |
|
---|
| 212 | static int funky(int x)
|
---|
| 213 | {
|
---|
| 214 | return x;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | static void test_installOIDFunctionAddress(void)
|
---|
| 218 | {
|
---|
| 219 | BOOL ret;
|
---|
| 220 | CRYPT_OID_FUNC_ENTRY entry = { CRYPT_DEFAULT_OID, funky };
|
---|
| 221 | HCRYPTOIDFUNCSET set;
|
---|
| 222 |
|
---|
| 223 | /* This crashes
|
---|
| 224 | ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
|
---|
| 225 | */
|
---|
| 226 |
|
---|
| 227 | /* Installing zero functions should work */
|
---|
| 228 | SetLastError(0xdeadbeef);
|
---|
| 229 | ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
|
---|
| 230 | NULL, 0);
|
---|
| 231 | ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
|
---|
| 232 | GetLastError());
|
---|
| 233 |
|
---|
| 234 | /* The function name doesn't much matter */
|
---|
| 235 | SetLastError(0xdeadbeef);
|
---|
| 236 | ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
|
---|
| 237 | ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
|
---|
| 238 | GetLastError());
|
---|
| 239 | SetLastError(0xdeadbeef);
|
---|
| 240 | entry.pszOID = X509_CERT;
|
---|
| 241 | ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
|
---|
| 242 | ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
|
---|
| 243 | GetLastError());
|
---|
| 244 | set = CryptInitOIDFunctionSet("OhSoFunky", 0);
|
---|
| 245 | ok(set != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
|
---|
| 246 | if (set)
|
---|
| 247 | {
|
---|
| 248 | funcY funcAddr = NULL;
|
---|
| 249 | HCRYPTOIDFUNCADDR hFuncAddr = NULL;
|
---|
| 250 |
|
---|
| 251 | /* This crashes
|
---|
| 252 | ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
|
---|
| 253 | NULL);
|
---|
| 254 | */
|
---|
| 255 | ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0,
|
---|
| 256 | (void **)&funcAddr, &hFuncAddr);
|
---|
| 257 | ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 258 | "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
---|
| 259 | ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, X509_CERT, 0,
|
---|
| 260 | (void **)&funcAddr, &hFuncAddr);
|
---|
| 261 | ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 262 | "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
---|
| 263 | ret = CryptGetOIDFunctionAddress(set, 0, X509_CERT, 0,
|
---|
| 264 | (void **)&funcAddr, &hFuncAddr);
|
---|
| 265 | ok(ret, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
|
---|
| 266 | if (funcAddr)
|
---|
| 267 | {
|
---|
| 268 | int y = funcAddr(0xabadc0da);
|
---|
| 269 |
|
---|
| 270 | ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
|
---|
| 271 | CryptFreeOIDFunctionAddress(hFuncAddr, 0);
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | static void test_registerOIDFunction(void)
|
---|
| 277 | {
|
---|
| 278 | BOOL ret;
|
---|
| 279 |
|
---|
| 280 | /* oddly, this succeeds under WinXP; the function name key is merely
|
---|
| 281 | * omitted. This may be a side effect of the registry code, I don't know.
|
---|
| 282 | * I don't check it because I doubt anyone would depend on it.
|
---|
| 283 | ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
|
---|
| 284 | "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
|
---|
| 285 | */
|
---|
| 286 | /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
|
---|
| 287 | * E_INVALIDARG
|
---|
| 288 | */
|
---|
| 289 | ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo", NULL, bogusDll,
|
---|
| 290 | NULL);
|
---|
| 291 | ok(!ret && GetLastError() == E_INVALIDARG,
|
---|
| 292 | "Expected E_INVALIDARG: %d\n", GetLastError());
|
---|
| 293 | /* This has no effect, but "succeeds" on XP */
|
---|
| 294 | ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo",
|
---|
| 295 | "1.2.3.4.5.6.7.8.9.10", NULL, NULL);
|
---|
| 296 | ok(ret, "Expected pseudo-success, got %d\n", GetLastError());
|
---|
| 297 | SetLastError(0xdeadbeef);
|
---|
| 298 | ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
|
---|
| 299 | "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
|
---|
| 300 | if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
---|
| 301 | {
|
---|
| 302 | skip("Need admin rights\n");
|
---|
| 303 | return;
|
---|
| 304 | }
|
---|
| 305 | ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 306 | ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
|
---|
| 307 | "1.2.3.4.5.6.7.8.9.10");
|
---|
| 308 | ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 309 | ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "bogus",
|
---|
| 310 | "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
|
---|
| 311 | ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 312 | ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "bogus",
|
---|
| 313 | "1.2.3.4.5.6.7.8.9.10");
|
---|
| 314 | ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 315 | /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
|
---|
| 316 | ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
|
---|
| 317 | "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
|
---|
| 318 | "Could not delete bogus key\n");
|
---|
| 319 | /* Shouldn't have effect but registry keys are created */
|
---|
| 320 | ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
|
---|
| 321 | "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
|
---|
| 322 | ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 323 | ret = CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
|
---|
| 324 | "1.2.3.4.5.6.7.8.9.10");
|
---|
| 325 | ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 326 | /* Check with bogus encoding type. Registry keys are still created */
|
---|
| 327 | ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
|
---|
| 328 | "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
|
---|
| 329 | ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 330 | ret = CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
|
---|
| 331 | "1.2.3.4.5.6.7.8.9.10");
|
---|
| 332 | ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 333 | /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
|
---|
| 334 | * will still be there
|
---|
| 335 | */
|
---|
| 336 | ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
|
---|
| 337 | "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
|
---|
| 338 | "Could not delete CryptDllEncodeObject key\n");
|
---|
| 339 | /* This is written with value 3 verbatim. Thus, the encoding type isn't
|
---|
| 340 | * (for now) treated as a mask. Registry keys are created.
|
---|
| 341 | */
|
---|
| 342 | ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
|
---|
| 343 | "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
|
---|
| 344 | ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 345 | ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
|
---|
| 346 | "1.2.3.4.5.6.7.8.9.10");
|
---|
| 347 | ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
|
---|
| 348 | /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
|
---|
| 349 | * will still be there.
|
---|
| 350 | */
|
---|
| 351 | ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
|
---|
| 352 | "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
|
---|
| 353 | "Could not delete CryptDllEncodeObject key\n");
|
---|
| 354 | ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE,
|
---|
| 355 | "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
|
---|
| 356 | "Could not delete 'EncodingType 3' key\n");
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | static void test_registerDefaultOIDFunction(void)
|
---|
| 360 | {
|
---|
| 361 | static const char fmt[] =
|
---|
| 362 | "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
|
---|
| 363 | static const char func[] = "CertDllOpenStoreProv";
|
---|
| 364 | char buf[MAX_PATH];
|
---|
| 365 | BOOL ret;
|
---|
| 366 | long rc;
|
---|
| 367 | HKEY key;
|
---|
| 368 |
|
---|
| 369 | ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, NULL);
|
---|
| 370 | ok(!ret && GetLastError() == E_INVALIDARG,
|
---|
| 371 | "Expected E_INVALIDARG, got %08x\n", GetLastError());
|
---|
| 372 | /* This succeeds on WinXP, although the bogus entry is unusable.
|
---|
| 373 | ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
|
---|
| 374 | */
|
---|
| 375 | /* Register one at index 0 */
|
---|
| 376 | SetLastError(0xdeadbeef);
|
---|
| 377 | ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
|
---|
| 378 | bogusDll);
|
---|
| 379 | if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
---|
| 380 | {
|
---|
| 381 | skip("Need admin rights\n");
|
---|
| 382 | return;
|
---|
| 383 | }
|
---|
| 384 | ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
|
---|
| 385 | /* Reregistering should fail */
|
---|
| 386 | ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
|
---|
| 387 | bogusDll);
|
---|
| 388 | ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
|
---|
| 389 | "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
|
---|
| 390 | /* Registering the same one at index 1 should also fail */
|
---|
| 391 | ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
|
---|
| 392 | bogusDll);
|
---|
| 393 | ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
|
---|
| 394 | "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
|
---|
| 395 | /* Registering a different one at index 1 succeeds */
|
---|
| 396 | ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
|
---|
| 397 | bogus2Dll);
|
---|
| 398 | ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
|
---|
| 399 | sprintf(buf, fmt, 0, func);
|
---|
| 400 | rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, buf, &key);
|
---|
| 401 | ok(rc == 0, "Expected key to exist, RegOpenKeyA failed: %ld\n", rc);
|
---|
| 402 | if (rc == 0)
|
---|
| 403 | {
|
---|
| 404 | static const CHAR dllA[] = "Dll";
|
---|
| 405 | static const CHAR bogusDll_A[] = "bogus.dll";
|
---|
| 406 | static const CHAR bogus2Dll_A[] = "bogus2.dll";
|
---|
| 407 | CHAR dllBuf[MAX_PATH];
|
---|
| 408 | DWORD type, size;
|
---|
| 409 | LPSTR ptr;
|
---|
| 410 |
|
---|
| 411 | size = sizeof(dllBuf) / sizeof(dllBuf[0]);
|
---|
| 412 | rc = RegQueryValueExA(key, dllA, NULL, &type, (LPBYTE)dllBuf, &size);
|
---|
| 413 | ok(rc == 0,
|
---|
| 414 | "Expected Dll value to exist, RegQueryValueExA failed: %ld\n", rc);
|
---|
| 415 | ok(type == REG_MULTI_SZ, "Expected type REG_MULTI_SZ, got %d\n", type);
|
---|
| 416 | /* bogusDll was registered first, so that should be first */
|
---|
| 417 | ptr = dllBuf;
|
---|
| 418 | ok(!lstrcmpiA(ptr, bogusDll_A), "Unexpected dll\n");
|
---|
| 419 | ptr += lstrlenA(ptr) + 1;
|
---|
| 420 | ok(!lstrcmpiA(ptr, bogus2Dll_A), "Unexpected dll\n");
|
---|
| 421 | RegCloseKey(key);
|
---|
| 422 | }
|
---|
| 423 | /* Unregister both of them */
|
---|
| 424 | ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
|
---|
| 425 | bogusDll);
|
---|
| 426 | ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
|
---|
| 427 | GetLastError());
|
---|
| 428 | ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
|
---|
| 429 | bogus2Dll);
|
---|
| 430 | ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
|
---|
| 431 | GetLastError());
|
---|
| 432 | /* Now that they're both unregistered, unregistering should fail */
|
---|
| 433 | ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
|
---|
| 434 | bogusDll);
|
---|
| 435 | ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 436 | "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
---|
| 437 |
|
---|
| 438 | /* Repeat a few tests on the normal encoding type */
|
---|
| 439 | ret = CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING,
|
---|
| 440 | "CertDllOpenStoreProv", 0, bogusDll);
|
---|
| 441 | ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
|
---|
| 442 | "CertDllOpenStoreProv", bogusDll);
|
---|
| 443 | ok(ret, "CryptUnregisterDefaultOIDFunction failed\n");
|
---|
| 444 | ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
|
---|
| 445 | "CertDllOpenStoreProv", bogusDll);
|
---|
| 446 | ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 447 | "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | static void test_getDefaultOIDFunctionAddress(void)
|
---|
| 451 | {
|
---|
| 452 | BOOL ret;
|
---|
| 453 | HCRYPTOIDFUNCSET set;
|
---|
| 454 | void *funcAddr;
|
---|
| 455 | HCRYPTOIDFUNCADDR hFuncAddr;
|
---|
| 456 |
|
---|
| 457 | /* Crash
|
---|
| 458 | ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
|
---|
| 459 | ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
|
---|
| 460 | ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
|
---|
| 461 | ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
|
---|
| 462 | &hFuncAddr);
|
---|
| 463 | */
|
---|
| 464 | set = CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
|
---|
| 465 | ok(set != 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
|
---|
| 466 | /* This crashes if hFuncAddr is not 0 to begin with */
|
---|
| 467 | hFuncAddr = 0;
|
---|
| 468 | ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
|
---|
| 469 | &hFuncAddr);
|
---|
| 470 | ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 471 | "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
---|
| 472 | /* This fails with the normal encoding too, so built-in functions aren't
|
---|
| 473 | * returned.
|
---|
| 474 | */
|
---|
| 475 | ret = CryptGetDefaultOIDFunctionAddress(set, X509_ASN_ENCODING, NULL, 0,
|
---|
| 476 | &funcAddr, &hFuncAddr);
|
---|
| 477 | ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 478 | "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
---|
| 479 |
|
---|
| 480 | /* Even with a registered dll, this fails (since the dll doesn't exist) */
|
---|
| 481 | SetLastError(0xdeadbeef);
|
---|
| 482 | ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
|
---|
| 483 | bogusDll);
|
---|
| 484 | if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
|
---|
| 485 | skip("Need admin rights\n");
|
---|
| 486 | else
|
---|
| 487 | ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
|
---|
| 488 | ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
|
---|
| 489 | &hFuncAddr);
|
---|
| 490 | ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
---|
| 491 | "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
---|
| 492 | CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll);
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | static BOOL WINAPI countOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
|
---|
| 496 | {
|
---|
| 497 | (*(DWORD *)pvArg)++;
|
---|
| 498 | return TRUE;
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
|
---|
| 502 | {
|
---|
| 503 | return FALSE;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | static void test_enumOIDInfo(void)
|
---|
| 507 | {
|
---|
| 508 | BOOL ret;
|
---|
| 509 | DWORD count = 0;
|
---|
| 510 |
|
---|
| 511 | if (!pCryptEnumOIDInfo)
|
---|
| 512 | {
|
---|
| 513 | skip("CryptEnumOIDInfo() is not available\n");
|
---|
| 514 | return;
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | /* This crashes
|
---|
| 518 | ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
|
---|
| 519 | */
|
---|
| 520 |
|
---|
| 521 | /* Silly tests, check that more than one thing is enumerated */
|
---|
| 522 | ret = pCryptEnumOIDInfo(0, 0, &count, countOidInfo);
|
---|
| 523 | ok(ret && count > 0, "Expected more than item enumerated\n");
|
---|
| 524 | ret = pCryptEnumOIDInfo(0, 0, NULL, noOidInfo);
|
---|
| 525 | ok(!ret, "Expected FALSE\n");
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 | static void test_findOIDInfo(void)
|
---|
| 529 | {
|
---|
| 530 | static WCHAR sha1[] = { 's','h','a','1',0 };
|
---|
| 531 | static CHAR oid_rsa_md5[] = szOID_RSA_MD5;
|
---|
| 532 | ALG_ID alg = CALG_SHA1;
|
---|
| 533 | ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
|
---|
| 534 | PCCRYPT_OID_INFO info;
|
---|
| 535 |
|
---|
| 536 | info = CryptFindOIDInfo(0, NULL, 0);
|
---|
| 537 | ok(info == NULL, "Expected NULL\n");
|
---|
| 538 | info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_rsa_md5, 0);
|
---|
| 539 | ok(info != NULL, "Expected to find szOID_RSA_MD5\n");
|
---|
| 540 | if (info)
|
---|
| 541 | {
|
---|
| 542 | ok(!strcmp(info->pszOID, szOID_RSA_MD5), "Expected %s, got %s\n",
|
---|
| 543 | szOID_RSA_MD5, info->pszOID);
|
---|
| 544 | ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
|
---|
| 545 | U(*info).Algid);
|
---|
| 546 | }
|
---|
| 547 | info = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, sha1, 0);
|
---|
| 548 | ok(info != NULL, "Expected to find sha1\n");
|
---|
| 549 | if (info)
|
---|
| 550 | {
|
---|
| 551 | ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
|
---|
| 552 | szOID_OIWSEC_sha1, info->pszOID);
|
---|
| 553 | ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
|
---|
| 554 | U(*info).Algid);
|
---|
| 555 | }
|
---|
| 556 | info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY, &alg, 0);
|
---|
| 557 | ok(info != NULL, "Expected to find sha1\n");
|
---|
| 558 | if (info)
|
---|
| 559 | {
|
---|
| 560 | ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
|
---|
| 561 | szOID_OIWSEC_sha1, info->pszOID);
|
---|
| 562 | ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
|
---|
| 563 | U(*info).Algid);
|
---|
| 564 | }
|
---|
| 565 | info = CryptFindOIDInfo(CRYPT_OID_INFO_SIGN_KEY, algs, 0);
|
---|
| 566 | ok(info != NULL, "Expected to find md5RSA\n");
|
---|
| 567 | if (info)
|
---|
| 568 | {
|
---|
| 569 | ok(!strcmp(info->pszOID, szOID_RSA_MD5RSA), "Expected %s, got %s\n",
|
---|
| 570 | szOID_RSA_MD5RSA, info->pszOID);
|
---|
| 571 | ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
|
---|
| 572 | U(*info).Algid);
|
---|
| 573 | }
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | START_TEST(oid)
|
---|
| 577 | {
|
---|
| 578 | HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
|
---|
| 579 | pCryptEnumOIDInfo = (void*)GetProcAddress(hCrypt32, "CryptEnumOIDInfo");
|
---|
| 580 |
|
---|
| 581 | testOIDToAlgID();
|
---|
| 582 | testAlgIDToOID();
|
---|
| 583 | test_enumOIDInfo();
|
---|
| 584 | test_findOIDInfo();
|
---|
| 585 | test_oidFunctionSet();
|
---|
| 586 | test_installOIDFunctionAddress();
|
---|
| 587 | test_registerOIDFunction();
|
---|
| 588 | test_registerDefaultOIDFunction();
|
---|
| 589 | test_getDefaultOIDFunctionAddress();
|
---|
| 590 | }
|
---|