push 9eb9af089d68d39110a91889d3a673043db63c4b
[wine/hacks.git] / dlls / crypt32 / store.c
blob1519c968ee0812c861ad5c5f676db3bcc9c51d71
1 /*
2 * Copyright 2002 Mike McCormack for CodeWeavers
3 * Copyright 2004-2006 Juan Lang
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * FIXME:
20 * - The concept of physical stores and locations isn't implemented. (This
21 * doesn't mean registry stores et al aren't implemented. See the PSDK for
22 * registering and enumerating physical stores and locations.)
23 * - Many flags, options and whatnot are unimplemented.
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdarg.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winnls.h"
34 #include "winreg.h"
35 #include "winuser.h"
36 #include "wincrypt.h"
37 #include "wine/debug.h"
38 #include "wine/list.h"
39 #include "wine/exception.h"
40 #include "crypt32_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
44 static const WINE_CONTEXT_INTERFACE gCertInterface = {
45 (CreateContextFunc)CertCreateCertificateContext,
46 (AddContextToStoreFunc)CertAddCertificateContextToStore,
47 (AddEncodedContextToStoreFunc)CertAddEncodedCertificateToStore,
48 (DuplicateContextFunc)CertDuplicateCertificateContext,
49 (EnumContextsInStoreFunc)CertEnumCertificatesInStore,
50 (EnumPropertiesFunc)CertEnumCertificateContextProperties,
51 (GetContextPropertyFunc)CertGetCertificateContextProperty,
52 (SetContextPropertyFunc)CertSetCertificateContextProperty,
53 (SerializeElementFunc)CertSerializeCertificateStoreElement,
54 (FreeContextFunc)CertFreeCertificateContext,
55 (DeleteContextFunc)CertDeleteCertificateFromStore,
57 PCWINE_CONTEXT_INTERFACE pCertInterface = &gCertInterface;
59 static const WINE_CONTEXT_INTERFACE gCRLInterface = {
60 (CreateContextFunc)CertCreateCRLContext,
61 (AddContextToStoreFunc)CertAddCRLContextToStore,
62 (AddEncodedContextToStoreFunc)CertAddEncodedCRLToStore,
63 (DuplicateContextFunc)CertDuplicateCRLContext,
64 (EnumContextsInStoreFunc)CertEnumCRLsInStore,
65 (EnumPropertiesFunc)CertEnumCRLContextProperties,
66 (GetContextPropertyFunc)CertGetCRLContextProperty,
67 (SetContextPropertyFunc)CertSetCRLContextProperty,
68 (SerializeElementFunc)CertSerializeCRLStoreElement,
69 (FreeContextFunc)CertFreeCRLContext,
70 (DeleteContextFunc)CertDeleteCRLFromStore,
72 PCWINE_CONTEXT_INTERFACE pCRLInterface = &gCRLInterface;
74 static const WINE_CONTEXT_INTERFACE gCTLInterface = {
75 (CreateContextFunc)CertCreateCTLContext,
76 (AddContextToStoreFunc)CertAddCTLContextToStore,
77 (AddEncodedContextToStoreFunc)CertAddEncodedCTLToStore,
78 (DuplicateContextFunc)CertDuplicateCTLContext,
79 (EnumContextsInStoreFunc)CertEnumCTLsInStore,
80 (EnumPropertiesFunc)CertEnumCTLContextProperties,
81 (GetContextPropertyFunc)CertGetCTLContextProperty,
82 (SetContextPropertyFunc)CertSetCTLContextProperty,
83 (SerializeElementFunc)CertSerializeCTLStoreElement,
84 (FreeContextFunc)CertFreeCTLContext,
85 (DeleteContextFunc)CertDeleteCTLFromStore,
87 PCWINE_CONTEXT_INTERFACE pCTLInterface = &gCTLInterface;
89 typedef struct _WINE_MEMSTORE
91 WINECRYPT_CERTSTORE hdr;
92 struct ContextList *certs;
93 struct ContextList *crls;
94 struct ContextList *ctls;
95 } WINE_MEMSTORE, *PWINE_MEMSTORE;
97 void CRYPT_InitStore(WINECRYPT_CERTSTORE *store, DWORD dwFlags,
98 CertStoreType type)
100 store->ref = 1;
101 store->dwMagic = WINE_CRYPTCERTSTORE_MAGIC;
102 store->type = type;
103 store->dwOpenFlags = dwFlags;
104 store->properties = NULL;
107 void CRYPT_FreeStore(PWINECRYPT_CERTSTORE store)
109 if (store->properties)
110 ContextPropertyList_Free(store->properties);
111 CryptMemFree(store);
114 BOOL WINAPI I_CertUpdateStore(HCERTSTORE store1, HCERTSTORE store2, DWORD unk0,
115 DWORD unk1)
117 static BOOL warned = FALSE;
118 const WINE_CONTEXT_INTERFACE * const interfaces[] = { pCertInterface,
119 pCRLInterface, pCTLInterface };
120 DWORD i;
122 TRACE("(%p, %p, %08x, %08x)\n", store1, store2, unk0, unk1);
123 if (!warned)
125 FIXME("semi-stub\n");
126 warned = TRUE;
129 /* Poor-man's resync: empty first store, then add everything from second
130 * store to it.
132 for (i = 0; i < sizeof(interfaces) / sizeof(interfaces[0]); i++)
134 const void *context;
136 do {
137 context = interfaces[i]->enumContextsInStore(store1, NULL);
138 if (context)
139 interfaces[i]->deleteFromStore(context);
140 } while (context);
141 do {
142 context = interfaces[i]->enumContextsInStore(store2, context);
143 if (context)
144 interfaces[i]->addContextToStore(store1, context,
145 CERT_STORE_ADD_ALWAYS, NULL);
146 } while (context);
148 return TRUE;
151 static BOOL CRYPT_MemAddCert(PWINECRYPT_CERTSTORE store, void *cert,
152 void *toReplace, const void **ppStoreContext)
154 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
155 PCERT_CONTEXT context;
157 TRACE("(%p, %p, %p, %p)\n", store, cert, toReplace, ppStoreContext);
159 context = ContextList_Add(ms->certs, cert, toReplace);
160 if (context)
162 context->hCertStore = store;
163 if (ppStoreContext)
164 *ppStoreContext = CertDuplicateCertificateContext(context);
166 return context ? TRUE : FALSE;
169 static void *CRYPT_MemEnumCert(PWINECRYPT_CERTSTORE store, void *pPrev)
171 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
172 void *ret;
174 TRACE("(%p, %p)\n", store, pPrev);
176 ret = ContextList_Enum(ms->certs, pPrev);
177 if (!ret)
178 SetLastError(CRYPT_E_NOT_FOUND);
180 TRACE("returning %p\n", ret);
181 return ret;
184 static BOOL CRYPT_MemDeleteCert(PWINECRYPT_CERTSTORE store, void *pCertContext)
186 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
188 ContextList_Delete(ms->certs, pCertContext);
189 return TRUE;
192 static BOOL CRYPT_MemAddCrl(PWINECRYPT_CERTSTORE store, void *crl,
193 void *toReplace, const void **ppStoreContext)
195 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
196 PCRL_CONTEXT context;
198 TRACE("(%p, %p, %p, %p)\n", store, crl, toReplace, ppStoreContext);
200 context = ContextList_Add(ms->crls, crl, toReplace);
201 if (context)
203 context->hCertStore = store;
204 if (ppStoreContext)
205 *ppStoreContext = CertDuplicateCRLContext(context);
207 return context ? TRUE : FALSE;
210 static void *CRYPT_MemEnumCrl(PWINECRYPT_CERTSTORE store, void *pPrev)
212 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
213 void *ret;
215 TRACE("(%p, %p)\n", store, pPrev);
217 ret = ContextList_Enum(ms->crls, pPrev);
218 if (!ret)
219 SetLastError(CRYPT_E_NOT_FOUND);
221 TRACE("returning %p\n", ret);
222 return ret;
225 static BOOL CRYPT_MemDeleteCrl(PWINECRYPT_CERTSTORE store, void *pCrlContext)
227 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
229 ContextList_Delete(ms->crls, pCrlContext);
230 return TRUE;
233 static BOOL CRYPT_MemAddCtl(PWINECRYPT_CERTSTORE store, void *ctl,
234 void *toReplace, const void **ppStoreContext)
236 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
237 PCTL_CONTEXT context;
239 TRACE("(%p, %p, %p, %p)\n", store, ctl, toReplace, ppStoreContext);
241 context = ContextList_Add(ms->ctls, ctl, toReplace);
242 if (context)
244 context->hCertStore = store;
245 if (ppStoreContext)
246 *ppStoreContext = CertDuplicateCTLContext(context);
248 return context ? TRUE : FALSE;
251 static void *CRYPT_MemEnumCtl(PWINECRYPT_CERTSTORE store, void *pPrev)
253 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
254 void *ret;
256 TRACE("(%p, %p)\n", store, pPrev);
258 ret = ContextList_Enum(ms->ctls, pPrev);
259 if (!ret)
260 SetLastError(CRYPT_E_NOT_FOUND);
262 TRACE("returning %p\n", ret);
263 return ret;
266 static BOOL CRYPT_MemDeleteCtl(PWINECRYPT_CERTSTORE store, void *pCtlContext)
268 WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store;
270 ContextList_Delete(ms->ctls, pCtlContext);
271 return TRUE;
274 static void WINAPI CRYPT_MemCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
276 WINE_MEMSTORE *store = (WINE_MEMSTORE *)hCertStore;
278 TRACE("(%p, %08x)\n", store, dwFlags);
279 if (dwFlags)
280 FIXME("Unimplemented flags: %08x\n", dwFlags);
282 ContextList_Free(store->certs);
283 ContextList_Free(store->crls);
284 ContextList_Free(store->ctls);
285 CRYPT_FreeStore((PWINECRYPT_CERTSTORE)store);
288 static WINECRYPT_CERTSTORE *CRYPT_MemOpenStore(HCRYPTPROV hCryptProv,
289 DWORD dwFlags, const void *pvPara)
291 PWINE_MEMSTORE store;
293 TRACE("(%ld, %08x, %p)\n", hCryptProv, dwFlags, pvPara);
295 if (dwFlags & CERT_STORE_DELETE_FLAG)
297 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
298 store = NULL;
300 else
302 store = CryptMemAlloc(sizeof(WINE_MEMSTORE));
303 if (store)
305 memset(store, 0, sizeof(WINE_MEMSTORE));
306 CRYPT_InitStore(&store->hdr, dwFlags, StoreTypeMem);
307 store->hdr.closeStore = CRYPT_MemCloseStore;
308 store->hdr.certs.addContext = CRYPT_MemAddCert;
309 store->hdr.certs.enumContext = CRYPT_MemEnumCert;
310 store->hdr.certs.deleteContext = CRYPT_MemDeleteCert;
311 store->hdr.crls.addContext = CRYPT_MemAddCrl;
312 store->hdr.crls.enumContext = CRYPT_MemEnumCrl;
313 store->hdr.crls.deleteContext = CRYPT_MemDeleteCrl;
314 store->hdr.ctls.addContext = CRYPT_MemAddCtl;
315 store->hdr.ctls.enumContext = CRYPT_MemEnumCtl;
316 store->hdr.ctls.deleteContext = CRYPT_MemDeleteCtl;
317 store->hdr.control = NULL;
318 store->certs = ContextList_Create(pCertInterface,
319 sizeof(CERT_CONTEXT));
320 store->crls = ContextList_Create(pCRLInterface,
321 sizeof(CRL_CONTEXT));
322 store->ctls = ContextList_Create(pCTLInterface,
323 sizeof(CTL_CONTEXT));
324 /* Mem store doesn't need crypto provider, so close it */
325 if (hCryptProv && !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG))
326 CryptReleaseContext(hCryptProv, 0);
329 return (PWINECRYPT_CERTSTORE)store;
332 static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreW(HCRYPTPROV hCryptProv,
333 DWORD dwFlags, const void *pvPara)
335 static const WCHAR rootW[] = { 'R','o','o','t',0 };
336 static const WCHAR fmt[] = { '%','s','\\','%','s',0 };
337 LPCWSTR storeName = (LPCWSTR)pvPara;
338 LPWSTR storePath;
339 PWINECRYPT_CERTSTORE store = NULL;
340 HKEY root;
341 LPCWSTR base;
343 TRACE("(%ld, %08x, %s)\n", hCryptProv, dwFlags,
344 debugstr_w((LPCWSTR)pvPara));
346 if (!pvPara)
348 SetLastError(E_INVALIDARG);
349 return NULL;
351 if (!lstrcmpiW(storeName, rootW))
352 return CRYPT_RootOpenStore(hCryptProv, dwFlags);
354 switch (dwFlags & CERT_SYSTEM_STORE_LOCATION_MASK)
356 case CERT_SYSTEM_STORE_LOCAL_MACHINE:
357 root = HKEY_LOCAL_MACHINE;
358 base = CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH;
359 break;
360 case CERT_SYSTEM_STORE_CURRENT_USER:
361 root = HKEY_CURRENT_USER;
362 base = CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH;
363 break;
364 case CERT_SYSTEM_STORE_CURRENT_SERVICE:
365 /* hklm\Software\Microsoft\Cryptography\Services\servicename\
366 * SystemCertificates
368 FIXME("CERT_SYSTEM_STORE_CURRENT_SERVICE, %s: stub\n",
369 debugstr_w(storeName));
370 return NULL;
371 case CERT_SYSTEM_STORE_SERVICES:
372 /* hklm\Software\Microsoft\Cryptography\Services\servicename\
373 * SystemCertificates
375 FIXME("CERT_SYSTEM_STORE_SERVICES, %s: stub\n",
376 debugstr_w(storeName));
377 return NULL;
378 case CERT_SYSTEM_STORE_USERS:
379 /* hku\user sid\Software\Microsoft\SystemCertificates */
380 FIXME("CERT_SYSTEM_STORE_USERS, %s: stub\n",
381 debugstr_w(storeName));
382 return NULL;
383 case CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY:
384 root = HKEY_CURRENT_USER;
385 base = CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH;
386 break;
387 case CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY:
388 root = HKEY_LOCAL_MACHINE;
389 base = CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH;
390 break;
391 case CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE:
392 /* hklm\Software\Microsoft\EnterpriseCertificates */
393 FIXME("CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, %s: stub\n",
394 debugstr_w(storeName));
395 return NULL;
396 default:
397 SetLastError(E_INVALIDARG);
398 return NULL;
401 storePath = CryptMemAlloc((lstrlenW(base) + lstrlenW(storeName) + 2) *
402 sizeof(WCHAR));
403 if (storePath)
405 LONG rc;
406 HKEY key;
407 REGSAM sam = dwFlags & CERT_STORE_READONLY_FLAG ? KEY_READ :
408 KEY_ALL_ACCESS;
410 wsprintfW(storePath, fmt, base, storeName);
411 if (dwFlags & CERT_STORE_OPEN_EXISTING_FLAG)
412 rc = RegOpenKeyExW(root, storePath, 0, sam, &key);
413 else
415 DWORD disp;
417 rc = RegCreateKeyExW(root, storePath, 0, NULL, 0, sam, NULL,
418 &key, &disp);
419 if (!rc && dwFlags & CERT_STORE_CREATE_NEW_FLAG &&
420 disp == REG_OPENED_EXISTING_KEY)
422 RegCloseKey(key);
423 rc = ERROR_FILE_EXISTS;
426 if (!rc)
428 store = CRYPT_RegOpenStore(hCryptProv, dwFlags, key);
429 RegCloseKey(key);
431 else
432 SetLastError(rc);
433 CryptMemFree(storePath);
435 return store;
438 static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreA(HCRYPTPROV hCryptProv,
439 DWORD dwFlags, const void *pvPara)
441 int len;
442 PWINECRYPT_CERTSTORE ret = NULL;
444 TRACE("(%ld, %08x, %s)\n", hCryptProv, dwFlags,
445 debugstr_a((LPCSTR)pvPara));
447 if (!pvPara)
449 SetLastError(ERROR_FILE_NOT_FOUND);
450 return NULL;
452 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, NULL, 0);
453 if (len)
455 LPWSTR storeName = CryptMemAlloc(len * sizeof(WCHAR));
457 if (storeName)
459 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, storeName, len);
460 ret = CRYPT_SysRegOpenStoreW(hCryptProv, dwFlags, storeName);
461 CryptMemFree(storeName);
464 return ret;
467 static PWINECRYPT_CERTSTORE CRYPT_SysOpenStoreW(HCRYPTPROV hCryptProv,
468 DWORD dwFlags, const void *pvPara)
470 HCERTSTORE store = 0;
471 BOOL ret;
473 TRACE("(%ld, %08x, %s)\n", hCryptProv, dwFlags,
474 debugstr_w((LPCWSTR)pvPara));
476 if (!pvPara)
478 SetLastError(ERROR_FILE_NOT_FOUND);
479 return NULL;
481 /* This returns a different error than system registry stores if the
482 * location is invalid.
484 switch (dwFlags & CERT_SYSTEM_STORE_LOCATION_MASK)
486 case CERT_SYSTEM_STORE_LOCAL_MACHINE:
487 case CERT_SYSTEM_STORE_CURRENT_USER:
488 case CERT_SYSTEM_STORE_CURRENT_SERVICE:
489 case CERT_SYSTEM_STORE_SERVICES:
490 case CERT_SYSTEM_STORE_USERS:
491 case CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY:
492 case CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY:
493 case CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE:
494 ret = TRUE;
495 break;
496 default:
497 SetLastError(ERROR_FILE_NOT_FOUND);
498 ret = FALSE;
500 if (ret)
502 HCERTSTORE regStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_W,
503 0, 0, dwFlags, pvPara);
505 if (regStore)
507 store = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
508 CERT_STORE_CREATE_NEW_FLAG, NULL);
509 CertAddStoreToCollection(store, regStore,
510 dwFlags & CERT_STORE_READONLY_FLAG ? 0 :
511 CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
512 CertCloseStore(regStore, 0);
513 /* CERT_SYSTEM_STORE_CURRENT_USER returns both the HKCU and HKLM
514 * stores.
516 if ((dwFlags & CERT_SYSTEM_STORE_LOCATION_MASK) ==
517 CERT_SYSTEM_STORE_CURRENT_USER)
519 dwFlags &= ~CERT_SYSTEM_STORE_CURRENT_USER;
520 dwFlags |= CERT_SYSTEM_STORE_LOCAL_MACHINE;
521 regStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_W, 0,
522 0, dwFlags, pvPara);
523 if (regStore)
525 CertAddStoreToCollection(store, regStore,
526 dwFlags & CERT_STORE_READONLY_FLAG ? 0 :
527 CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
528 CertCloseStore(regStore, 0);
531 /* System store doesn't need crypto provider, so close it */
532 if (hCryptProv && !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG))
533 CryptReleaseContext(hCryptProv, 0);
536 return (PWINECRYPT_CERTSTORE)store;
539 static PWINECRYPT_CERTSTORE CRYPT_SysOpenStoreA(HCRYPTPROV hCryptProv,
540 DWORD dwFlags, const void *pvPara)
542 int len;
543 PWINECRYPT_CERTSTORE ret = NULL;
545 TRACE("(%ld, %08x, %s)\n", hCryptProv, dwFlags,
546 debugstr_a((LPCSTR)pvPara));
548 if (!pvPara)
550 SetLastError(ERROR_FILE_NOT_FOUND);
551 return NULL;
553 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, NULL, 0);
554 if (len)
556 LPWSTR storeName = CryptMemAlloc(len * sizeof(WCHAR));
558 if (storeName)
560 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, storeName, len);
561 ret = CRYPT_SysOpenStoreW(hCryptProv, dwFlags, storeName);
562 CryptMemFree(storeName);
565 return ret;
568 static void WINAPI CRYPT_MsgCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
570 HCRYPTMSG msg = hCertStore;
572 TRACE("(%p, %08x)\n", msg, dwFlags);
573 CryptMsgClose(msg);
576 static void *msgProvFuncs[] = {
577 CRYPT_MsgCloseStore,
580 static PWINECRYPT_CERTSTORE CRYPT_MsgOpenStore(HCRYPTPROV hCryptProv,
581 DWORD dwFlags, const void *pvPara)
583 PWINECRYPT_CERTSTORE store = NULL;
584 HCRYPTMSG msg = (HCRYPTMSG)pvPara;
585 PWINECRYPT_CERTSTORE memStore;
587 TRACE("(%ld, %08x, %p)\n", hCryptProv, dwFlags, pvPara);
589 memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
590 CERT_STORE_CREATE_NEW_FLAG, NULL);
591 if (memStore)
593 BOOL ret;
594 DWORD size, count, i;
596 size = sizeof(count);
597 ret = CryptMsgGetParam(msg, CMSG_CERT_COUNT_PARAM, 0, &count, &size);
598 for (i = 0; ret && i < count; i++)
600 size = 0;
601 ret = CryptMsgGetParam(msg, CMSG_CERT_PARAM, i, NULL, &size);
602 if (ret)
604 LPBYTE buf = CryptMemAlloc(size);
606 if (buf)
608 ret = CryptMsgGetParam(msg, CMSG_CERT_PARAM, i, buf, &size);
609 if (ret)
610 ret = CertAddEncodedCertificateToStore(memStore,
611 X509_ASN_ENCODING, buf, size, CERT_STORE_ADD_ALWAYS,
612 NULL);
613 CryptMemFree(buf);
617 size = sizeof(count);
618 ret = CryptMsgGetParam(msg, CMSG_CRL_COUNT_PARAM, 0, &count, &size);
619 for (i = 0; ret && i < count; i++)
621 size = 0;
622 ret = CryptMsgGetParam(msg, CMSG_CRL_PARAM, i, NULL, &size);
623 if (ret)
625 LPBYTE buf = CryptMemAlloc(size);
627 if (buf)
629 ret = CryptMsgGetParam(msg, CMSG_CRL_PARAM, i, buf, &size);
630 if (ret)
631 ret = CertAddEncodedCRLToStore(memStore,
632 X509_ASN_ENCODING, buf, size, CERT_STORE_ADD_ALWAYS,
633 NULL);
634 CryptMemFree(buf);
638 if (ret)
640 CERT_STORE_PROV_INFO provInfo = { 0 };
642 provInfo.cbSize = sizeof(provInfo);
643 provInfo.cStoreProvFunc = sizeof(msgProvFuncs) /
644 sizeof(msgProvFuncs[0]);
645 provInfo.rgpvStoreProvFunc = msgProvFuncs;
646 provInfo.hStoreProv = CryptMsgDuplicate(msg);
647 store = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo);
648 /* Msg store doesn't need crypto provider, so close it */
649 if (hCryptProv && !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG))
650 CryptReleaseContext(hCryptProv, 0);
652 else
653 CertCloseStore(memStore, 0);
655 TRACE("returning %p\n", store);
656 return store;
659 static PWINECRYPT_CERTSTORE CRYPT_PKCSOpenStore(HCRYPTPROV hCryptProv,
660 DWORD dwFlags, const void *pvPara)
662 HCRYPTMSG msg;
663 PWINECRYPT_CERTSTORE store = NULL;
664 const CRYPT_DATA_BLOB *data = (const CRYPT_DATA_BLOB *)pvPara;
665 BOOL ret;
666 DWORD msgOpenFlags = dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG ? 0 :
667 CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
669 TRACE("(%ld, %08x, %p)\n", hCryptProv, dwFlags, pvPara);
671 msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, msgOpenFlags, CMSG_SIGNED,
672 hCryptProv, NULL, NULL);
673 ret = CryptMsgUpdate(msg, data->pbData, data->cbData, TRUE);
674 if (!ret)
676 CryptMsgClose(msg);
677 msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, msgOpenFlags, 0,
678 hCryptProv, NULL, NULL);
679 ret = CryptMsgUpdate(msg, data->pbData, data->cbData, TRUE);
680 if (ret)
682 DWORD type, size = sizeof(type);
684 /* Only signed messages are allowed, check type */
685 ret = CryptMsgGetParam(msg, CMSG_TYPE_PARAM, 0, &type, &size);
686 if (ret && type != CMSG_SIGNED)
688 SetLastError(CRYPT_E_INVALID_MSG_TYPE);
689 ret = FALSE;
693 if (ret)
694 store = CRYPT_MsgOpenStore(0, dwFlags, msg);
695 CryptMsgClose(msg);
696 TRACE("returning %p\n", store);
697 return store;
700 static PWINECRYPT_CERTSTORE CRYPT_PhysOpenStoreW(HCRYPTPROV hCryptProv,
701 DWORD dwFlags, const void *pvPara)
703 if (dwFlags & CERT_SYSTEM_STORE_RELOCATE_FLAG)
704 FIXME("(%ld, %08x, %p): stub\n", hCryptProv, dwFlags, pvPara);
705 else
706 FIXME("(%ld, %08x, %s): stub\n", hCryptProv, dwFlags,
707 debugstr_w((LPCWSTR)pvPara));
708 return NULL;
711 HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider,
712 DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags,
713 const void* pvPara)
715 WINECRYPT_CERTSTORE *hcs;
716 StoreOpenFunc openFunc = NULL;
718 TRACE("(%s, %08x, %08lx, %08x, %p)\n", debugstr_a(lpszStoreProvider),
719 dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara);
721 if (!HIWORD(lpszStoreProvider))
723 switch (LOWORD(lpszStoreProvider))
725 case LOWORD(CERT_STORE_PROV_MSG):
726 openFunc = CRYPT_MsgOpenStore;
727 break;
728 case LOWORD(CERT_STORE_PROV_MEMORY):
729 openFunc = CRYPT_MemOpenStore;
730 break;
731 case LOWORD(CERT_STORE_PROV_FILE):
732 openFunc = CRYPT_FileOpenStore;
733 break;
734 case LOWORD(CERT_STORE_PROV_PKCS7):
735 openFunc = CRYPT_PKCSOpenStore;
736 break;
737 case LOWORD(CERT_STORE_PROV_REG):
738 openFunc = CRYPT_RegOpenStore;
739 break;
740 case LOWORD(CERT_STORE_PROV_FILENAME_A):
741 openFunc = CRYPT_FileNameOpenStoreA;
742 break;
743 case LOWORD(CERT_STORE_PROV_FILENAME_W):
744 openFunc = CRYPT_FileNameOpenStoreW;
745 break;
746 case LOWORD(CERT_STORE_PROV_COLLECTION):
747 openFunc = CRYPT_CollectionOpenStore;
748 break;
749 case LOWORD(CERT_STORE_PROV_SYSTEM_A):
750 openFunc = CRYPT_SysOpenStoreA;
751 break;
752 case LOWORD(CERT_STORE_PROV_SYSTEM_W):
753 openFunc = CRYPT_SysOpenStoreW;
754 break;
755 case LOWORD(CERT_STORE_PROV_SYSTEM_REGISTRY_A):
756 openFunc = CRYPT_SysRegOpenStoreA;
757 break;
758 case LOWORD(CERT_STORE_PROV_SYSTEM_REGISTRY_W):
759 openFunc = CRYPT_SysRegOpenStoreW;
760 break;
761 case LOWORD(CERT_STORE_PROV_PHYSICAL_W):
762 openFunc = CRYPT_PhysOpenStoreW;
763 break;
764 default:
765 if (LOWORD(lpszStoreProvider))
766 FIXME("unimplemented type %d\n", LOWORD(lpszStoreProvider));
769 else if (!strcasecmp(lpszStoreProvider, sz_CERT_STORE_PROV_MEMORY))
770 openFunc = CRYPT_MemOpenStore;
771 else if (!strcasecmp(lpszStoreProvider, sz_CERT_STORE_PROV_FILENAME_W))
772 openFunc = CRYPT_FileOpenStore;
773 else if (!strcasecmp(lpszStoreProvider, sz_CERT_STORE_PROV_SYSTEM))
774 openFunc = CRYPT_SysOpenStoreW;
775 else if (!strcasecmp(lpszStoreProvider, sz_CERT_STORE_PROV_COLLECTION))
776 openFunc = CRYPT_CollectionOpenStore;
777 else if (!strcasecmp(lpszStoreProvider, sz_CERT_STORE_PROV_SYSTEM_REGISTRY))
778 openFunc = CRYPT_SysRegOpenStoreW;
779 else
781 FIXME("unimplemented type %s\n", lpszStoreProvider);
782 openFunc = NULL;
785 if (!openFunc)
786 hcs = CRYPT_ProvOpenStore(lpszStoreProvider, dwMsgAndCertEncodingType,
787 hCryptProv, dwFlags, pvPara);
788 else
789 hcs = openFunc(hCryptProv, dwFlags, pvPara);
790 return (HCERTSTORE)hcs;
793 HCERTSTORE WINAPI CertOpenSystemStoreA(HCRYPTPROV_LEGACY hProv,
794 LPCSTR szSubSystemProtocol)
796 if (!szSubSystemProtocol)
798 SetLastError(E_INVALIDARG);
799 return 0;
801 return CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, hProv,
802 CERT_SYSTEM_STORE_CURRENT_USER, szSubSystemProtocol);
805 HCERTSTORE WINAPI CertOpenSystemStoreW(HCRYPTPROV_LEGACY hProv,
806 LPCWSTR szSubSystemProtocol)
808 if (!szSubSystemProtocol)
810 SetLastError(E_INVALIDARG);
811 return 0;
813 return CertOpenStore(CERT_STORE_PROV_SYSTEM_W, 0, hProv,
814 CERT_SYSTEM_STORE_CURRENT_USER, szSubSystemProtocol);
817 #define CertContext_CopyProperties(to, from) \
818 Context_CopyProperties((to), (from), sizeof(CERT_CONTEXT))
820 BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore,
821 PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition,
822 PCCERT_CONTEXT *ppStoreContext)
824 PWINECRYPT_CERTSTORE store = (PWINECRYPT_CERTSTORE)hCertStore;
825 BOOL ret = TRUE;
826 PCCERT_CONTEXT toAdd = NULL, existing = NULL;
828 TRACE("(%p, %p, %08x, %p)\n", hCertStore, pCertContext,
829 dwAddDisposition, ppStoreContext);
831 if (dwAddDisposition != CERT_STORE_ADD_ALWAYS)
833 BYTE hashToAdd[20];
834 DWORD size = sizeof(hashToAdd);
836 ret = CertGetCertificateContextProperty(pCertContext, CERT_HASH_PROP_ID,
837 hashToAdd, &size);
838 if (ret)
840 CRYPT_HASH_BLOB blob = { sizeof(hashToAdd), hashToAdd };
842 existing = CertFindCertificateInStore(hCertStore,
843 pCertContext->dwCertEncodingType, 0, CERT_FIND_SHA1_HASH, &blob,
844 NULL);
848 switch (dwAddDisposition)
850 case CERT_STORE_ADD_ALWAYS:
851 toAdd = CertDuplicateCertificateContext(pCertContext);
852 break;
853 case CERT_STORE_ADD_NEW:
854 if (existing)
856 TRACE("found matching certificate, not adding\n");
857 SetLastError(CRYPT_E_EXISTS);
858 ret = FALSE;
860 else
861 toAdd = CertDuplicateCertificateContext(pCertContext);
862 break;
863 case CERT_STORE_ADD_REPLACE_EXISTING:
864 toAdd = CertDuplicateCertificateContext(pCertContext);
865 break;
866 case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES:
867 toAdd = CertDuplicateCertificateContext(pCertContext);
868 if (existing)
869 CertContext_CopyProperties(toAdd, existing);
870 break;
871 case CERT_STORE_ADD_USE_EXISTING:
872 if (existing)
874 CertContext_CopyProperties(existing, pCertContext);
875 *ppStoreContext = CertDuplicateCertificateContext(existing);
877 else
878 toAdd = CertDuplicateCertificateContext(pCertContext);
879 break;
880 case CERT_STORE_ADD_NEWER:
881 if (existing)
883 if (CompareFileTime(&existing->pCertInfo->NotBefore,
884 &pCertContext->pCertInfo->NotBefore) >= 0)
886 TRACE("existing certificate is newer, not adding\n");
887 SetLastError(CRYPT_E_EXISTS);
888 ret = FALSE;
890 else
891 toAdd = CertDuplicateCertificateContext(pCertContext);
893 else
894 toAdd = CertDuplicateCertificateContext(pCertContext);
895 break;
896 default:
897 FIXME("Unimplemented add disposition %d\n", dwAddDisposition);
898 SetLastError(E_INVALIDARG);
899 ret = FALSE;
902 if (toAdd)
904 if (store)
905 ret = store->certs.addContext(store, (void *)toAdd,
906 (void *)existing, (const void **)ppStoreContext);
907 else if (ppStoreContext)
908 *ppStoreContext = CertDuplicateCertificateContext(toAdd);
909 CertFreeCertificateContext(toAdd);
911 CertFreeCertificateContext(existing);
913 TRACE("returning %d\n", ret);
914 return ret;
917 PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore,
918 PCCERT_CONTEXT pPrev)
920 WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *)hCertStore;
921 PCCERT_CONTEXT ret;
923 TRACE("(%p, %p)\n", hCertStore, pPrev);
924 if (!hCertStore)
925 ret = NULL;
926 else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
927 ret = NULL;
928 else
929 ret = (PCCERT_CONTEXT)hcs->certs.enumContext(hcs, (void *)pPrev);
930 return ret;
933 BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
935 BOOL ret;
937 TRACE("(%p)\n", pCertContext);
939 if (!pCertContext)
940 ret = TRUE;
941 else if (!pCertContext->hCertStore)
943 ret = TRUE;
944 CertFreeCertificateContext(pCertContext);
946 else
948 PWINECRYPT_CERTSTORE hcs =
949 (PWINECRYPT_CERTSTORE)pCertContext->hCertStore;
951 if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
952 ret = FALSE;
953 else
954 ret = hcs->certs.deleteContext(hcs, (void *)pCertContext);
955 CertFreeCertificateContext(pCertContext);
957 return ret;
960 #define CrlContext_CopyProperties(to, from) \
961 Context_CopyProperties((to), (from), sizeof(CRL_CONTEXT))
963 BOOL WINAPI CertAddCRLContextToStore(HCERTSTORE hCertStore,
964 PCCRL_CONTEXT pCrlContext, DWORD dwAddDisposition,
965 PCCRL_CONTEXT* ppStoreContext)
967 PWINECRYPT_CERTSTORE store = (PWINECRYPT_CERTSTORE)hCertStore;
968 BOOL ret = TRUE;
969 PCCRL_CONTEXT toAdd = NULL, existing = NULL;
971 TRACE("(%p, %p, %08x, %p)\n", hCertStore, pCrlContext,
972 dwAddDisposition, ppStoreContext);
974 /* Weird case to pass a test */
975 if (dwAddDisposition == 0)
977 SetLastError(STATUS_ACCESS_VIOLATION);
978 return FALSE;
980 if (dwAddDisposition != CERT_STORE_ADD_ALWAYS)
982 existing = CertFindCRLInStore(hCertStore, 0, 0, CRL_FIND_EXISTING,
983 pCrlContext, NULL);
986 switch (dwAddDisposition)
988 case CERT_STORE_ADD_ALWAYS:
989 toAdd = CertDuplicateCRLContext(pCrlContext);
990 break;
991 case CERT_STORE_ADD_NEW:
992 if (existing)
994 TRACE("found matching CRL, not adding\n");
995 SetLastError(CRYPT_E_EXISTS);
996 ret = FALSE;
998 else
999 toAdd = CertDuplicateCRLContext(pCrlContext);
1000 break;
1001 case CERT_STORE_ADD_NEWER:
1002 if (existing)
1004 LONG newer = CompareFileTime(&existing->pCrlInfo->ThisUpdate,
1005 &pCrlContext->pCrlInfo->ThisUpdate);
1007 if (newer < 0)
1008 toAdd = CertDuplicateCRLContext(pCrlContext);
1009 else
1011 TRACE("existing CRL is newer, not adding\n");
1012 SetLastError(CRYPT_E_EXISTS);
1013 ret = FALSE;
1016 else
1017 toAdd = CertDuplicateCRLContext(pCrlContext);
1018 break;
1019 case CERT_STORE_ADD_REPLACE_EXISTING:
1020 toAdd = CertDuplicateCRLContext(pCrlContext);
1021 break;
1022 case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES:
1023 toAdd = CertDuplicateCRLContext(pCrlContext);
1024 if (existing)
1025 CrlContext_CopyProperties(toAdd, existing);
1026 break;
1027 case CERT_STORE_ADD_USE_EXISTING:
1028 if (existing)
1029 CrlContext_CopyProperties(existing, pCrlContext);
1030 break;
1031 default:
1032 FIXME("Unimplemented add disposition %d\n", dwAddDisposition);
1033 ret = FALSE;
1036 if (toAdd)
1038 if (store)
1039 ret = store->crls.addContext(store, (void *)toAdd,
1040 (void *)existing, (const void **)ppStoreContext);
1041 else if (ppStoreContext)
1042 *ppStoreContext = CertDuplicateCRLContext(toAdd);
1043 CertFreeCRLContext(toAdd);
1045 CertFreeCRLContext(existing);
1047 TRACE("returning %d\n", ret);
1048 return ret;
1051 BOOL WINAPI CertDeleteCRLFromStore(PCCRL_CONTEXT pCrlContext)
1053 BOOL ret;
1055 TRACE("(%p)\n", pCrlContext);
1057 if (!pCrlContext)
1058 ret = TRUE;
1059 else if (!pCrlContext->hCertStore)
1061 ret = TRUE;
1062 CertFreeCRLContext(pCrlContext);
1064 else
1066 PWINECRYPT_CERTSTORE hcs =
1067 (PWINECRYPT_CERTSTORE)pCrlContext->hCertStore;
1069 if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
1070 ret = FALSE;
1071 else
1072 ret = hcs->crls.deleteContext(hcs, (void *)pCrlContext);
1073 CertFreeCRLContext(pCrlContext);
1075 return ret;
1078 PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(HCERTSTORE hCertStore,
1079 PCCRL_CONTEXT pPrev)
1081 WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *)hCertStore;
1082 PCCRL_CONTEXT ret;
1084 TRACE("(%p, %p)\n", hCertStore, pPrev);
1085 if (!hCertStore)
1086 ret = NULL;
1087 else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
1088 ret = NULL;
1089 else
1090 ret = (PCCRL_CONTEXT)hcs->crls.enumContext(hcs, (void *)pPrev);
1091 return ret;
1094 HCERTSTORE WINAPI CertDuplicateStore(HCERTSTORE hCertStore)
1096 WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *)hCertStore;
1098 TRACE("(%p)\n", hCertStore);
1100 if (hcs && hcs->dwMagic == WINE_CRYPTCERTSTORE_MAGIC)
1101 InterlockedIncrement(&hcs->ref);
1102 return hCertStore;
1105 BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
1107 WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *) hCertStore;
1109 TRACE("(%p, %08x)\n", hCertStore, dwFlags);
1111 if( ! hCertStore )
1112 return TRUE;
1114 if ( hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC )
1115 return FALSE;
1117 if (InterlockedDecrement(&hcs->ref) == 0)
1119 TRACE("%p's ref count is 0, freeing\n", hcs);
1120 hcs->dwMagic = 0;
1121 hcs->closeStore(hcs, dwFlags);
1123 else
1124 TRACE("%p's ref count is %d\n", hcs, hcs->ref);
1125 return TRUE;
1128 BOOL WINAPI CertControlStore(HCERTSTORE hCertStore, DWORD dwFlags,
1129 DWORD dwCtrlType, void const *pvCtrlPara)
1131 WINECRYPT_CERTSTORE *hcs = (WINECRYPT_CERTSTORE *)hCertStore;
1132 BOOL ret;
1134 TRACE("(%p, %08x, %d, %p)\n", hCertStore, dwFlags, dwCtrlType,
1135 pvCtrlPara);
1137 if (!hcs)
1138 ret = FALSE;
1139 else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
1140 ret = FALSE;
1141 else
1143 if (hcs->control)
1144 ret = hcs->control(hCertStore, dwFlags, dwCtrlType, pvCtrlPara);
1145 else
1146 ret = TRUE;
1148 return ret;
1151 BOOL WINAPI CertGetStoreProperty(HCERTSTORE hCertStore, DWORD dwPropId,
1152 void *pvData, DWORD *pcbData)
1154 PWINECRYPT_CERTSTORE store = (PWINECRYPT_CERTSTORE)hCertStore;
1155 BOOL ret = FALSE;
1157 TRACE("(%p, %d, %p, %p)\n", hCertStore, dwPropId, pvData, pcbData);
1159 switch (dwPropId)
1161 case CERT_ACCESS_STATE_PROP_ID:
1162 if (!pvData)
1164 *pcbData = sizeof(DWORD);
1165 ret = TRUE;
1167 else if (*pcbData < sizeof(DWORD))
1169 SetLastError(ERROR_MORE_DATA);
1170 *pcbData = sizeof(DWORD);
1172 else
1174 DWORD state = 0;
1176 if (store->type != StoreTypeMem &&
1177 !(store->dwOpenFlags & CERT_STORE_READONLY_FLAG))
1178 state |= CERT_ACCESS_STATE_WRITE_PERSIST_FLAG;
1179 *(DWORD *)pvData = state;
1180 ret = TRUE;
1182 break;
1183 default:
1184 if (store->properties)
1186 CRYPT_DATA_BLOB blob;
1188 ret = ContextPropertyList_FindProperty(store->properties, dwPropId,
1189 &blob);
1190 if (ret)
1192 if (!pvData)
1193 *pcbData = blob.cbData;
1194 else if (*pcbData < blob.cbData)
1196 SetLastError(ERROR_MORE_DATA);
1197 *pcbData = blob.cbData;
1198 ret = FALSE;
1200 else
1202 memcpy(pvData, blob.pbData, blob.cbData);
1203 *pcbData = blob.cbData;
1206 else
1207 SetLastError(CRYPT_E_NOT_FOUND);
1209 else
1210 SetLastError(CRYPT_E_NOT_FOUND);
1212 return ret;
1215 BOOL WINAPI CertSetStoreProperty(HCERTSTORE hCertStore, DWORD dwPropId,
1216 DWORD dwFlags, const void *pvData)
1218 PWINECRYPT_CERTSTORE store = (PWINECRYPT_CERTSTORE)hCertStore;
1219 BOOL ret = FALSE;
1221 TRACE("(%p, %d, %08x, %p)\n", hCertStore, dwPropId, dwFlags, pvData);
1223 if (!store->properties)
1224 store->properties = ContextPropertyList_Create();
1225 switch (dwPropId)
1227 case CERT_ACCESS_STATE_PROP_ID:
1228 SetLastError(E_INVALIDARG);
1229 break;
1230 default:
1231 if (pvData)
1233 const CRYPT_DATA_BLOB *blob = (const CRYPT_DATA_BLOB *)pvData;
1235 ret = ContextPropertyList_SetProperty(store->properties, dwPropId,
1236 blob->pbData, blob->cbData);
1238 else
1240 ContextPropertyList_RemoveProperty(store->properties, dwPropId);
1241 ret = TRUE;
1244 return ret;
1247 static LONG CRYPT_OpenParentStore(DWORD dwFlags,
1248 void *pvSystemStoreLocationPara, HKEY *key)
1250 HKEY root;
1251 LPCWSTR base;
1253 TRACE("(%08x, %p)\n", dwFlags, pvSystemStoreLocationPara);
1255 switch (dwFlags & CERT_SYSTEM_STORE_LOCATION_MASK)
1257 case CERT_SYSTEM_STORE_LOCAL_MACHINE:
1258 root = HKEY_LOCAL_MACHINE;
1259 base = CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH;
1260 break;
1261 case CERT_SYSTEM_STORE_CURRENT_USER:
1262 root = HKEY_CURRENT_USER;
1263 base = CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH;
1264 break;
1265 case CERT_SYSTEM_STORE_CURRENT_SERVICE:
1266 /* hklm\Software\Microsoft\Cryptography\Services\servicename\
1267 * SystemCertificates
1269 FIXME("CERT_SYSTEM_STORE_CURRENT_SERVICE\n");
1270 return ERROR_FILE_NOT_FOUND;
1271 case CERT_SYSTEM_STORE_SERVICES:
1272 /* hklm\Software\Microsoft\Cryptography\Services\servicename\
1273 * SystemCertificates
1275 FIXME("CERT_SYSTEM_STORE_SERVICES\n");
1276 return ERROR_FILE_NOT_FOUND;
1277 case CERT_SYSTEM_STORE_USERS:
1278 /* hku\user sid\Software\Microsoft\SystemCertificates */
1279 FIXME("CERT_SYSTEM_STORE_USERS\n");
1280 return ERROR_FILE_NOT_FOUND;
1281 case CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY:
1282 root = HKEY_CURRENT_USER;
1283 base = CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH;
1284 break;
1285 case CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY:
1286 root = HKEY_LOCAL_MACHINE;
1287 base = CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH;
1288 break;
1289 case CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE:
1290 /* hklm\Software\Microsoft\EnterpriseCertificates */
1291 FIXME("CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE\n");
1292 return ERROR_FILE_NOT_FOUND;
1293 default:
1294 return ERROR_FILE_NOT_FOUND;
1297 return RegOpenKeyExW(root, base, 0, KEY_READ, key);
1300 BOOL WINAPI CertEnumSystemStore(DWORD dwFlags, void *pvSystemStoreLocationPara,
1301 void *pvArg, PFN_CERT_ENUM_SYSTEM_STORE pfnEnum)
1303 BOOL ret = FALSE;
1304 LONG rc;
1305 HKEY key;
1307 TRACE("(%08x, %p, %p, %p)\n", dwFlags, pvSystemStoreLocationPara, pvArg,
1308 pfnEnum);
1310 rc = CRYPT_OpenParentStore(dwFlags, pvArg, &key);
1311 if (!rc)
1313 DWORD index = 0;
1314 CERT_SYSTEM_STORE_INFO info = { sizeof(info) };
1316 ret = TRUE;
1317 do {
1318 WCHAR name[MAX_PATH];
1319 DWORD size = sizeof(name) / sizeof(name[0]);
1321 rc = RegEnumKeyExW(key, index++, name, &size, NULL, NULL, NULL,
1322 NULL);
1323 if (!rc)
1324 ret = pfnEnum(name, dwFlags, &info, NULL, pvArg);
1325 } while (ret && !rc);
1326 if (ret && rc != ERROR_NO_MORE_ITEMS)
1327 SetLastError(rc);
1329 else
1330 SetLastError(rc);
1331 return ret;
1334 BOOL WINAPI CertEnumPhysicalStore(const void *pvSystemStore, DWORD dwFlags,
1335 void *pvArg, PFN_CERT_ENUM_PHYSICAL_STORE pfnEnum)
1337 if (dwFlags & CERT_SYSTEM_STORE_RELOCATE_FLAG)
1338 FIXME("(%p, %08x, %p, %p): stub\n", pvSystemStore, dwFlags, pvArg,
1339 pfnEnum);
1340 else
1341 FIXME("(%s, %08x, %p, %p): stub\n", debugstr_w((LPCWSTR)pvSystemStore),
1342 dwFlags, pvArg,
1343 pfnEnum);
1344 return FALSE;