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
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.
27 #include "wine/port.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 #define WINE_CRYPTCERTSTORE_MAGIC 0x74726563
46 static const WINE_CONTEXT_INTERFACE gCertInterface
= {
47 (CreateContextFunc
)CertCreateCertificateContext
,
48 (AddContextToStoreFunc
)CertAddCertificateContextToStore
,
49 (AddEncodedContextToStoreFunc
)CertAddEncodedCertificateToStore
,
50 (DuplicateContextFunc
)CertDuplicateCertificateContext
,
51 (EnumContextsInStoreFunc
)CertEnumCertificatesInStore
,
52 (EnumPropertiesFunc
)CertEnumCertificateContextProperties
,
53 (GetContextPropertyFunc
)CertGetCertificateContextProperty
,
54 (SetContextPropertyFunc
)CertSetCertificateContextProperty
,
55 (SerializeElementFunc
)CertSerializeCertificateStoreElement
,
56 (FreeContextFunc
)CertFreeCertificateContext
,
57 (DeleteContextFunc
)CertDeleteCertificateFromStore
,
59 PCWINE_CONTEXT_INTERFACE pCertInterface
= &gCertInterface
;
61 static const WINE_CONTEXT_INTERFACE gCRLInterface
= {
62 (CreateContextFunc
)CertCreateCRLContext
,
63 (AddContextToStoreFunc
)CertAddCRLContextToStore
,
64 (AddEncodedContextToStoreFunc
)CertAddEncodedCRLToStore
,
65 (DuplicateContextFunc
)CertDuplicateCRLContext
,
66 (EnumContextsInStoreFunc
)CertEnumCRLsInStore
,
67 (EnumPropertiesFunc
)CertEnumCRLContextProperties
,
68 (GetContextPropertyFunc
)CertGetCRLContextProperty
,
69 (SetContextPropertyFunc
)CertSetCRLContextProperty
,
70 (SerializeElementFunc
)CertSerializeCRLStoreElement
,
71 (FreeContextFunc
)CertFreeCRLContext
,
72 (DeleteContextFunc
)CertDeleteCRLFromStore
,
74 PCWINE_CONTEXT_INTERFACE pCRLInterface
= &gCRLInterface
;
76 static const WINE_CONTEXT_INTERFACE gCTLInterface
= {
77 (CreateContextFunc
)CertCreateCTLContext
,
78 (AddContextToStoreFunc
)CertAddCTLContextToStore
,
79 (AddEncodedContextToStoreFunc
)CertAddEncodedCTLToStore
,
80 (DuplicateContextFunc
)CertDuplicateCTLContext
,
81 (EnumContextsInStoreFunc
)CertEnumCTLsInStore
,
82 (EnumPropertiesFunc
)CertEnumCTLContextProperties
,
83 (GetContextPropertyFunc
)CertGetCTLContextProperty
,
84 (SetContextPropertyFunc
)CertSetCTLContextProperty
,
85 (SerializeElementFunc
)CertSerializeCTLStoreElement
,
86 (FreeContextFunc
)CertFreeCTLContext
,
87 (DeleteContextFunc
)CertDeleteCTLFromStore
,
89 PCWINE_CONTEXT_INTERFACE pCTLInterface
= &gCTLInterface
;
91 struct WINE_CRYPTCERTSTORE
;
93 typedef struct WINE_CRYPTCERTSTORE
* (*StoreOpenFunc
)(HCRYPTPROV hCryptProv
,
94 DWORD dwFlags
, const void *pvPara
);
96 /* Called to enumerate the next context in a store. */
97 typedef void * (*EnumFunc
)(struct WINE_CRYPTCERTSTORE
*store
, void *pPrev
);
99 /* Called to add a context to a store. If toReplace is not NULL,
100 * context replaces toReplace in the store, and access checks should not be
101 * performed. Otherwise context is a new context, and it should only be
102 * added if the store allows it. If ppStoreContext is not NULL, the added
103 * context should be returned in *ppStoreContext.
105 typedef BOOL (*AddFunc
)(struct WINE_CRYPTCERTSTORE
*store
, void *context
,
106 void *toReplace
, const void **ppStoreContext
);
108 typedef BOOL (*DeleteFunc
)(struct WINE_CRYPTCERTSTORE
*store
, void *context
);
110 typedef struct _CONTEXT_FUNCS
113 EnumFunc enumContext
;
114 DeleteFunc deleteContext
;
115 } CONTEXT_FUNCS
, *PCONTEXT_FUNCS
;
117 typedef enum _CertStoreType
{
123 /* A cert store is polymorphic through the use of function pointers. A type
124 * is still needed to distinguish collection stores from other types.
125 * On the function pointers:
126 * - closeStore is called when the store's ref count becomes 0
127 * - control is optional, but should be implemented by any store that supports
130 typedef struct WINE_CRYPTCERTSTORE
135 HCRYPTPROV cryptProv
;
137 PFN_CERT_STORE_PROV_CLOSE closeStore
;
140 PFN_CERT_STORE_PROV_CONTROL control
; /* optional */
141 PCONTEXT_PROPERTY_LIST properties
;
142 } WINECRYPT_CERTSTORE
, *PWINECRYPT_CERTSTORE
;
144 typedef struct _WINE_MEMSTORE
146 WINECRYPT_CERTSTORE hdr
;
147 struct ContextList
*certs
;
148 struct ContextList
*crls
;
149 } WINE_MEMSTORE
, *PWINE_MEMSTORE
;
151 typedef struct _WINE_HASH_TO_DELETE
155 } WINE_HASH_TO_DELETE
, *PWINE_HASH_TO_DELETE
;
157 typedef struct _WINE_REGSTOREINFO
160 HCRYPTPROV cryptProv
;
161 PWINECRYPT_CERTSTORE memStore
;
165 struct list certsToDelete
;
166 struct list crlsToDelete
;
167 } WINE_REGSTOREINFO
, *PWINE_REGSTOREINFO
;
169 typedef struct _WINE_FILESTOREINFO
172 HCRYPTPROV cryptProv
;
173 PWINECRYPT_CERTSTORE memStore
;
176 } WINE_FILESTOREINFO
, *PWINE_FILESTOREINFO
;
178 typedef struct _WINE_MSGSTOREINFO
181 HCRYPTPROV cryptProv
;
182 PWINECRYPT_CERTSTORE memStore
;
184 } WINE_MSGSTOREINFO
, *PWINE_MSGSTOREINFO
;
186 typedef struct _WINE_STORE_LIST_ENTRY
188 PWINECRYPT_CERTSTORE store
;
192 } WINE_STORE_LIST_ENTRY
, *PWINE_STORE_LIST_ENTRY
;
194 typedef struct _WINE_COLLECTIONSTORE
196 WINECRYPT_CERTSTORE hdr
;
199 } WINE_COLLECTIONSTORE
, *PWINE_COLLECTIONSTORE
;
201 typedef struct _WINE_PROVIDERSTORE
203 WINECRYPT_CERTSTORE hdr
;
204 DWORD dwStoreProvFlags
;
205 PWINECRYPT_CERTSTORE memStore
;
206 HCERTSTOREPROV hStoreProv
;
207 PFN_CERT_STORE_PROV_CLOSE provCloseStore
;
208 PFN_CERT_STORE_PROV_WRITE_CERT provWriteCert
;
209 PFN_CERT_STORE_PROV_DELETE_CERT provDeleteCert
;
210 PFN_CERT_STORE_PROV_WRITE_CRL provWriteCrl
;
211 PFN_CERT_STORE_PROV_DELETE_CRL provDeleteCrl
;
212 PFN_CERT_STORE_PROV_CONTROL provControl
;
213 } WINE_PROVIDERSTORE
, *PWINE_PROVIDERSTORE
;
215 static void CRYPT_InitStore(WINECRYPT_CERTSTORE
*store
, HCRYPTPROV hCryptProv
,
216 DWORD dwFlags
, CertStoreType type
)
219 store
->dwMagic
= WINE_CRYPTCERTSTORE_MAGIC
;
223 hCryptProv
= CRYPT_GetDefaultProvider();
224 dwFlags
|= CERT_STORE_NO_CRYPT_RELEASE_FLAG
;
226 store
->cryptProv
= hCryptProv
;
227 store
->dwOpenFlags
= dwFlags
;
228 store
->properties
= NULL
;
231 static void CRYPT_FreeStore(PWINECRYPT_CERTSTORE store
)
233 if (store
->properties
)
234 ContextPropertyList_Free(store
->properties
);
238 static BOOL
CRYPT_MemAddCert(PWINECRYPT_CERTSTORE store
, void *cert
,
239 void *toReplace
, const void **ppStoreContext
)
241 WINE_MEMSTORE
*ms
= (WINE_MEMSTORE
*)store
;
242 PCERT_CONTEXT context
;
244 TRACE("(%p, %p, %p, %p)\n", store
, cert
, toReplace
, ppStoreContext
);
246 context
= (PCERT_CONTEXT
)ContextList_Add(ms
->certs
, cert
, toReplace
);
249 context
->hCertStore
= store
;
251 *ppStoreContext
= CertDuplicateCertificateContext(context
);
253 return context
? TRUE
: FALSE
;
256 static void *CRYPT_MemEnumCert(PWINECRYPT_CERTSTORE store
, void *pPrev
)
258 WINE_MEMSTORE
*ms
= (WINE_MEMSTORE
*)store
;
261 TRACE("(%p, %p)\n", store
, pPrev
);
263 ret
= ContextList_Enum(ms
->certs
, pPrev
);
265 SetLastError(CRYPT_E_NOT_FOUND
);
267 TRACE("returning %p\n", ret
);
271 static BOOL
CRYPT_MemDeleteCert(PWINECRYPT_CERTSTORE store
, void *pCertContext
)
273 WINE_MEMSTORE
*ms
= (WINE_MEMSTORE
*)store
;
275 ContextList_Delete(ms
->certs
, pCertContext
);
279 static BOOL
CRYPT_MemAddCrl(PWINECRYPT_CERTSTORE store
, void *crl
,
280 void *toReplace
, const void **ppStoreContext
)
282 WINE_MEMSTORE
*ms
= (WINE_MEMSTORE
*)store
;
283 PCRL_CONTEXT context
;
285 TRACE("(%p, %p, %p, %p)\n", store
, crl
, toReplace
, ppStoreContext
);
287 context
= (PCRL_CONTEXT
)ContextList_Add(ms
->crls
, crl
, toReplace
);
290 context
->hCertStore
= store
;
292 *ppStoreContext
= CertDuplicateCRLContext(context
);
294 return context
? TRUE
: FALSE
;
297 static void *CRYPT_MemEnumCrl(PWINECRYPT_CERTSTORE store
, void *pPrev
)
299 WINE_MEMSTORE
*ms
= (WINE_MEMSTORE
*)store
;
302 TRACE("(%p, %p)\n", store
, pPrev
);
304 ret
= ContextList_Enum(ms
->crls
, pPrev
);
306 SetLastError(CRYPT_E_NOT_FOUND
);
308 TRACE("returning %p\n", ret
);
312 static BOOL
CRYPT_MemDeleteCrl(PWINECRYPT_CERTSTORE store
, void *pCrlContext
)
314 WINE_MEMSTORE
*ms
= (WINE_MEMSTORE
*)store
;
316 ContextList_Delete(ms
->crls
, pCrlContext
);
320 static void CRYPT_MemEmptyStore(PWINE_MEMSTORE store
)
322 ContextList_Empty(store
->certs
);
323 ContextList_Empty(store
->crls
);
326 static void WINAPI
CRYPT_MemCloseStore(HCERTSTORE hCertStore
, DWORD dwFlags
)
328 WINE_MEMSTORE
*store
= (WINE_MEMSTORE
*)hCertStore
;
330 TRACE("(%p, %08x)\n", store
, dwFlags
);
332 FIXME("Unimplemented flags: %08x\n", dwFlags
);
334 ContextList_Free(store
->certs
);
335 ContextList_Free(store
->crls
);
336 CRYPT_FreeStore((PWINECRYPT_CERTSTORE
)store
);
339 static WINECRYPT_CERTSTORE
*CRYPT_MemOpenStore(HCRYPTPROV hCryptProv
,
340 DWORD dwFlags
, const void *pvPara
)
342 PWINE_MEMSTORE store
;
344 TRACE("(%ld, %08x, %p)\n", hCryptProv
, dwFlags
, pvPara
);
346 if (dwFlags
& CERT_STORE_DELETE_FLAG
)
348 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
353 store
= CryptMemAlloc(sizeof(WINE_MEMSTORE
));
356 memset(store
, 0, sizeof(WINE_MEMSTORE
));
357 CRYPT_InitStore(&store
->hdr
, hCryptProv
, dwFlags
, StoreTypeMem
);
358 store
->hdr
.closeStore
= CRYPT_MemCloseStore
;
359 store
->hdr
.certs
.addContext
= CRYPT_MemAddCert
;
360 store
->hdr
.certs
.enumContext
= CRYPT_MemEnumCert
;
361 store
->hdr
.certs
.deleteContext
= CRYPT_MemDeleteCert
;
362 store
->hdr
.crls
.addContext
= CRYPT_MemAddCrl
;
363 store
->hdr
.crls
.enumContext
= CRYPT_MemEnumCrl
;
364 store
->hdr
.crls
.deleteContext
= CRYPT_MemDeleteCrl
;
365 store
->hdr
.control
= NULL
;
366 store
->certs
= ContextList_Create(pCertInterface
,
367 sizeof(CERT_CONTEXT
));
368 store
->crls
= ContextList_Create(pCRLInterface
,
369 sizeof(CRL_CONTEXT
));
372 return (PWINECRYPT_CERTSTORE
)store
;
375 static void WINAPI
CRYPT_CollectionCloseStore(HCERTSTORE store
, DWORD dwFlags
)
377 PWINE_COLLECTIONSTORE cs
= (PWINE_COLLECTIONSTORE
)store
;
378 PWINE_STORE_LIST_ENTRY entry
, next
;
380 TRACE("(%p, %08x)\n", store
, dwFlags
);
382 LIST_FOR_EACH_ENTRY_SAFE(entry
, next
, &cs
->stores
, WINE_STORE_LIST_ENTRY
,
385 TRACE("closing %p\n", entry
);
386 CertCloseStore((HCERTSTORE
)entry
->store
, dwFlags
);
389 cs
->cs
.DebugInfo
->Spare
[0] = 0;
390 DeleteCriticalSection(&cs
->cs
);
391 CRYPT_FreeStore((PWINECRYPT_CERTSTORE
)store
);
394 static void *CRYPT_CollectionCreateContextFromChild(PWINE_COLLECTIONSTORE store
,
395 PWINE_STORE_LIST_ENTRY storeEntry
, void *child
, size_t contextSize
,
398 void *ret
= Context_CreateLinkContext(contextSize
, child
,
399 sizeof(PWINE_STORE_LIST_ENTRY
), addRef
);
402 *(PWINE_STORE_LIST_ENTRY
*)Context_GetExtra(ret
, contextSize
)
408 static BOOL
CRYPT_CollectionAddContext(PWINE_COLLECTIONSTORE store
,
409 unsigned int contextFuncsOffset
, void *context
, void *toReplace
, unsigned int contextSize
,
410 void **pChildContext
)
413 void *childContext
= NULL
;
414 PWINE_STORE_LIST_ENTRY storeEntry
= NULL
;
416 TRACE("(%p, %d, %p, %p, %d)\n", store
, contextFuncsOffset
, context
,
417 toReplace
, contextSize
);
422 void *existingLinked
= Context_GetLinkedContext(toReplace
, contextSize
);
423 PCONTEXT_FUNCS contextFuncs
;
425 storeEntry
= *(PWINE_STORE_LIST_ENTRY
*)Context_GetExtra(toReplace
,
427 contextFuncs
= (PCONTEXT_FUNCS
)((LPBYTE
)storeEntry
->store
+
429 ret
= contextFuncs
->addContext(storeEntry
->store
, context
,
430 existingLinked
, childContext
);
434 PWINE_STORE_LIST_ENTRY entry
, next
;
436 EnterCriticalSection(&store
->cs
);
437 LIST_FOR_EACH_ENTRY_SAFE(entry
, next
, &store
->stores
,
438 WINE_STORE_LIST_ENTRY
, entry
)
440 if (entry
->dwUpdateFlags
& CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG
)
442 PCONTEXT_FUNCS contextFuncs
= (PCONTEXT_FUNCS
)(
443 (LPBYTE
)entry
->store
+ contextFuncsOffset
);
446 ret
= contextFuncs
->addContext(entry
->store
, context
, NULL
,
447 (const void **)&childContext
);
451 LeaveCriticalSection(&store
->cs
);
453 SetLastError(E_ACCESSDENIED
);
455 *pChildContext
= childContext
;
459 /* Advances a collection enumeration by one context, if possible, where
461 * - calling the current store's enumeration function once, and returning
462 * the enumerated context if one is returned
463 * - moving to the next store if the current store has no more items, and
464 * recursively calling itself to get the next item.
465 * Returns NULL if the collection contains no more items or on error.
466 * Assumes the collection store's lock is held.
468 static void *CRYPT_CollectionAdvanceEnum(PWINE_COLLECTIONSTORE store
,
469 PWINE_STORE_LIST_ENTRY storeEntry
, size_t contextFuncsOffset
,
470 PCWINE_CONTEXT_INTERFACE contextInterface
, void *pPrev
, size_t contextSize
)
473 struct list
*storeNext
= list_next(&store
->stores
, &storeEntry
->entry
);
474 PCONTEXT_FUNCS contextFuncs
= (PCONTEXT_FUNCS
)((LPBYTE
)storeEntry
->store
+
477 TRACE("(%p, %p, %p)\n", store
, storeEntry
, pPrev
);
481 /* Ref-counting funny business: "duplicate" (addref) the child, because
482 * the free(pPrev) below can cause the ref count to become negative.
484 child
= Context_GetLinkedContext(pPrev
, contextSize
);
485 contextInterface
->duplicate(child
);
486 child
= contextFuncs
->enumContext(storeEntry
->store
, child
);
487 contextInterface
->free(pPrev
);
491 child
= contextFuncs
->enumContext(storeEntry
->store
, NULL
);
493 ret
= CRYPT_CollectionCreateContextFromChild(store
, storeEntry
, child
,
498 ret
= CRYPT_CollectionAdvanceEnum(store
, LIST_ENTRY(storeNext
,
499 WINE_STORE_LIST_ENTRY
, entry
), contextFuncsOffset
,
500 contextInterface
, NULL
, contextSize
);
503 SetLastError(CRYPT_E_NOT_FOUND
);
507 TRACE("returning %p\n", ret
);
511 static BOOL
CRYPT_CollectionAddCert(PWINECRYPT_CERTSTORE store
, void *cert
,
512 void *toReplace
, const void **ppStoreContext
)
515 void *childContext
= NULL
;
516 PWINE_COLLECTIONSTORE cs
= (PWINE_COLLECTIONSTORE
)store
;
518 ret
= CRYPT_CollectionAddContext(cs
, offsetof(WINECRYPT_CERTSTORE
, certs
),
519 cert
, toReplace
, sizeof(CERT_CONTEXT
), &childContext
);
520 if (ppStoreContext
&& childContext
)
522 PWINE_STORE_LIST_ENTRY storeEntry
= *(PWINE_STORE_LIST_ENTRY
*)
523 Context_GetExtra(childContext
, sizeof(CERT_CONTEXT
));
524 PCERT_CONTEXT context
=
525 CRYPT_CollectionCreateContextFromChild(cs
, storeEntry
, childContext
,
526 sizeof(CERT_CONTEXT
), TRUE
);
529 context
->hCertStore
= store
;
530 *ppStoreContext
= context
;
532 CertFreeCertificateContext((PCCERT_CONTEXT
)childContext
);
536 static void *CRYPT_CollectionEnumCert(PWINECRYPT_CERTSTORE store
, void *pPrev
)
538 PWINE_COLLECTIONSTORE cs
= (PWINE_COLLECTIONSTORE
)store
;
541 TRACE("(%p, %p)\n", store
, pPrev
);
543 EnterCriticalSection(&cs
->cs
);
546 PWINE_STORE_LIST_ENTRY storeEntry
=
547 *(PWINE_STORE_LIST_ENTRY
*)Context_GetExtra(pPrev
,
548 sizeof(CERT_CONTEXT
));
550 ret
= CRYPT_CollectionAdvanceEnum(cs
, storeEntry
,
551 offsetof(WINECRYPT_CERTSTORE
, certs
), pCertInterface
, pPrev
,
552 sizeof(CERT_CONTEXT
));
556 if (!list_empty(&cs
->stores
))
558 PWINE_STORE_LIST_ENTRY storeEntry
= LIST_ENTRY(cs
->stores
.next
,
559 WINE_STORE_LIST_ENTRY
, entry
);
561 ret
= CRYPT_CollectionAdvanceEnum(cs
, storeEntry
,
562 offsetof(WINECRYPT_CERTSTORE
, certs
), pCertInterface
, NULL
,
563 sizeof(CERT_CONTEXT
));
567 SetLastError(CRYPT_E_NOT_FOUND
);
571 LeaveCriticalSection(&cs
->cs
);
573 ((PCERT_CONTEXT
)ret
)->hCertStore
= store
;
574 TRACE("returning %p\n", ret
);
578 static BOOL
CRYPT_CollectionDeleteCert(PWINECRYPT_CERTSTORE store
,
583 TRACE("(%p, %p)\n", store
, pCertContext
);
585 ret
= CertDeleteCertificateFromStore((PCCERT_CONTEXT
)
586 Context_GetLinkedContext(pCertContext
, sizeof(CERT_CONTEXT
)));
590 static BOOL
CRYPT_CollectionAddCRL(PWINECRYPT_CERTSTORE store
, void *crl
,
591 void *toReplace
, const void **ppStoreContext
)
594 void *childContext
= NULL
;
595 PWINE_COLLECTIONSTORE cs
= (PWINE_COLLECTIONSTORE
)store
;
597 ret
= CRYPT_CollectionAddContext(cs
, offsetof(WINECRYPT_CERTSTORE
, crls
),
598 crl
, toReplace
, sizeof(CRL_CONTEXT
), &childContext
);
599 if (ppStoreContext
&& childContext
)
601 PWINE_STORE_LIST_ENTRY storeEntry
= *(PWINE_STORE_LIST_ENTRY
*)
602 Context_GetExtra(childContext
, sizeof(CRL_CONTEXT
));
603 PCRL_CONTEXT context
=
604 CRYPT_CollectionCreateContextFromChild(cs
, storeEntry
, childContext
,
605 sizeof(CRL_CONTEXT
), TRUE
);
608 context
->hCertStore
= store
;
609 *ppStoreContext
= context
;
611 CertFreeCRLContext((PCCRL_CONTEXT
)childContext
);
615 static void *CRYPT_CollectionEnumCRL(PWINECRYPT_CERTSTORE store
, void *pPrev
)
617 PWINE_COLLECTIONSTORE cs
= (PWINE_COLLECTIONSTORE
)store
;
620 TRACE("(%p, %p)\n", store
, pPrev
);
622 EnterCriticalSection(&cs
->cs
);
625 PWINE_STORE_LIST_ENTRY storeEntry
=
626 *(PWINE_STORE_LIST_ENTRY
*)Context_GetExtra(pPrev
,
627 sizeof(CRL_CONTEXT
));
629 ret
= CRYPT_CollectionAdvanceEnum(cs
, storeEntry
,
630 offsetof(WINECRYPT_CERTSTORE
, crls
), pCRLInterface
, pPrev
,
631 sizeof(CRL_CONTEXT
));
635 if (!list_empty(&cs
->stores
))
637 PWINE_STORE_LIST_ENTRY storeEntry
= LIST_ENTRY(cs
->stores
.next
,
638 WINE_STORE_LIST_ENTRY
, entry
);
640 ret
= CRYPT_CollectionAdvanceEnum(cs
, storeEntry
,
641 offsetof(WINECRYPT_CERTSTORE
, crls
), pCRLInterface
, NULL
,
642 sizeof(CRL_CONTEXT
));
646 SetLastError(CRYPT_E_NOT_FOUND
);
650 LeaveCriticalSection(&cs
->cs
);
652 ((PCRL_CONTEXT
)ret
)->hCertStore
= store
;
653 TRACE("returning %p\n", ret
);
657 static BOOL
CRYPT_CollectionDeleteCRL(PWINECRYPT_CERTSTORE store
,
662 TRACE("(%p, %p)\n", store
, pCrlContext
);
664 ret
= CertDeleteCRLFromStore((PCCRL_CONTEXT
)
665 Context_GetLinkedContext(pCrlContext
, sizeof(CRL_CONTEXT
)));
669 static WINECRYPT_CERTSTORE
*CRYPT_CollectionOpenStore(HCRYPTPROV hCryptProv
,
670 DWORD dwFlags
, const void *pvPara
)
672 PWINE_COLLECTIONSTORE store
;
674 if (dwFlags
& CERT_STORE_DELETE_FLAG
)
676 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
681 store
= CryptMemAlloc(sizeof(WINE_COLLECTIONSTORE
));
684 memset(store
, 0, sizeof(WINE_COLLECTIONSTORE
));
685 CRYPT_InitStore(&store
->hdr
, hCryptProv
, dwFlags
,
686 StoreTypeCollection
);
687 store
->hdr
.closeStore
= CRYPT_CollectionCloseStore
;
688 store
->hdr
.certs
.addContext
= CRYPT_CollectionAddCert
;
689 store
->hdr
.certs
.enumContext
= CRYPT_CollectionEnumCert
;
690 store
->hdr
.certs
.deleteContext
= CRYPT_CollectionDeleteCert
;
691 store
->hdr
.crls
.addContext
= CRYPT_CollectionAddCRL
;
692 store
->hdr
.crls
.enumContext
= CRYPT_CollectionEnumCRL
;
693 store
->hdr
.crls
.deleteContext
= CRYPT_CollectionDeleteCRL
;
694 InitializeCriticalSection(&store
->cs
);
695 store
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": PWINE_COLLECTIONSTORE->cs");
696 list_init(&store
->stores
);
699 return (PWINECRYPT_CERTSTORE
)store
;
702 static void WINAPI
CRYPT_ProvCloseStore(HCERTSTORE hCertStore
, DWORD dwFlags
)
704 PWINE_PROVIDERSTORE store
= (PWINE_PROVIDERSTORE
)hCertStore
;
706 TRACE("(%p, %08x)\n", store
, dwFlags
);
708 if (store
->provCloseStore
)
709 store
->provCloseStore(store
->hStoreProv
, dwFlags
);
710 if (!(store
->dwStoreProvFlags
& CERT_STORE_PROV_EXTERNAL_FLAG
))
711 CertCloseStore(store
->memStore
, dwFlags
);
712 CRYPT_FreeStore((PWINECRYPT_CERTSTORE
)store
);
715 static BOOL
CRYPT_ProvAddCert(PWINECRYPT_CERTSTORE store
, void *cert
,
716 void *toReplace
, const void **ppStoreContext
)
718 PWINE_PROVIDERSTORE ps
= (PWINE_PROVIDERSTORE
)store
;
721 TRACE("(%p, %p, %p, %p)\n", store
, cert
, toReplace
, ppStoreContext
);
724 ret
= ps
->memStore
->certs
.addContext(ps
->memStore
, cert
, toReplace
,
729 if (ps
->provWriteCert
)
730 ret
= ps
->provWriteCert(ps
->hStoreProv
, (PCCERT_CONTEXT
)cert
,
731 CERT_STORE_PROV_WRITE_ADD_FLAG
);
733 ret
= ps
->memStore
->certs
.addContext(ps
->memStore
, cert
, NULL
,
736 /* dirty trick: replace the returned context's hCertStore with
740 (*(PCERT_CONTEXT
*)ppStoreContext
)->hCertStore
= store
;
744 static void *CRYPT_ProvEnumCert(PWINECRYPT_CERTSTORE store
, void *pPrev
)
746 PWINE_PROVIDERSTORE ps
= (PWINE_PROVIDERSTORE
)store
;
749 ret
= ps
->memStore
->certs
.enumContext(ps
->memStore
, pPrev
);
752 /* same dirty trick: replace the returned context's hCertStore with
755 ((PCERT_CONTEXT
)ret
)->hCertStore
= store
;
760 static BOOL
CRYPT_ProvDeleteCert(PWINECRYPT_CERTSTORE store
, void *cert
)
762 PWINE_PROVIDERSTORE ps
= (PWINE_PROVIDERSTORE
)store
;
765 TRACE("(%p, %p)\n", store
, cert
);
767 if (ps
->provDeleteCert
)
768 ret
= ps
->provDeleteCert(ps
->hStoreProv
, cert
, 0);
770 ret
= ps
->memStore
->certs
.deleteContext(ps
->memStore
, cert
);
774 static BOOL
CRYPT_ProvAddCRL(PWINECRYPT_CERTSTORE store
, void *crl
,
775 void *toReplace
, const void **ppStoreContext
)
777 PWINE_PROVIDERSTORE ps
= (PWINE_PROVIDERSTORE
)store
;
780 TRACE("(%p, %p, %p, %p)\n", store
, crl
, toReplace
, ppStoreContext
);
783 ret
= ps
->memStore
->crls
.addContext(ps
->memStore
, crl
, toReplace
,
787 if (ps
->hdr
.dwOpenFlags
& CERT_STORE_READONLY_FLAG
)
789 SetLastError(ERROR_ACCESS_DENIED
);
795 if (ps
->provWriteCrl
)
796 ret
= ps
->provWriteCrl(ps
->hStoreProv
, (PCCRL_CONTEXT
)crl
,
797 CERT_STORE_PROV_WRITE_ADD_FLAG
);
799 ret
= ps
->memStore
->crls
.addContext(ps
->memStore
, crl
, NULL
,
803 /* dirty trick: replace the returned context's hCertStore with
807 (*(PCRL_CONTEXT
*)ppStoreContext
)->hCertStore
= store
;
811 static void *CRYPT_ProvEnumCRL(PWINECRYPT_CERTSTORE store
, void *pPrev
)
813 PWINE_PROVIDERSTORE ps
= (PWINE_PROVIDERSTORE
)store
;
816 ret
= ps
->memStore
->crls
.enumContext(ps
->memStore
, pPrev
);
819 /* same dirty trick: replace the returned context's hCertStore with
822 ((PCRL_CONTEXT
)ret
)->hCertStore
= store
;
827 static BOOL
CRYPT_ProvDeleteCRL(PWINECRYPT_CERTSTORE store
, void *crl
)
829 PWINE_PROVIDERSTORE ps
= (PWINE_PROVIDERSTORE
)store
;
832 TRACE("(%p, %p)\n", store
, crl
);
834 if (ps
->provDeleteCrl
)
835 ret
= ps
->provDeleteCrl(ps
->hStoreProv
, crl
, 0);
837 ret
= ps
->memStore
->crls
.deleteContext(ps
->memStore
, crl
);
841 static BOOL WINAPI
CRYPT_ProvControl(HCERTSTORE hCertStore
, DWORD dwFlags
,
842 DWORD dwCtrlType
, void const *pvCtrlPara
)
844 PWINE_PROVIDERSTORE store
= (PWINE_PROVIDERSTORE
)hCertStore
;
847 TRACE("(%p, %08x, %d, %p)\n", hCertStore
, dwFlags
, dwCtrlType
,
850 if (store
->provControl
)
851 ret
= store
->provControl(store
->hStoreProv
, dwFlags
, dwCtrlType
,
856 static PWINECRYPT_CERTSTORE
CRYPT_ProvCreateStore(HCRYPTPROV hCryptProv
,
857 DWORD dwFlags
, PWINECRYPT_CERTSTORE memStore
, const CERT_STORE_PROV_INFO
*pProvInfo
)
859 PWINE_PROVIDERSTORE ret
= CryptMemAlloc(sizeof(WINE_PROVIDERSTORE
));
863 CRYPT_InitStore(&ret
->hdr
, hCryptProv
, dwFlags
,
865 ret
->dwStoreProvFlags
= pProvInfo
->dwStoreProvFlags
;
866 if (ret
->dwStoreProvFlags
& CERT_STORE_PROV_EXTERNAL_FLAG
)
868 CertCloseStore(memStore
, 0);
869 ret
->memStore
= NULL
;
872 ret
->memStore
= memStore
;
873 ret
->hStoreProv
= pProvInfo
->hStoreProv
;
874 ret
->hdr
.closeStore
= CRYPT_ProvCloseStore
;
875 ret
->hdr
.certs
.addContext
= CRYPT_ProvAddCert
;
876 ret
->hdr
.certs
.enumContext
= CRYPT_ProvEnumCert
;
877 ret
->hdr
.certs
.deleteContext
= CRYPT_ProvDeleteCert
;
878 ret
->hdr
.crls
.addContext
= CRYPT_ProvAddCRL
;
879 ret
->hdr
.crls
.enumContext
= CRYPT_ProvEnumCRL
;
880 ret
->hdr
.crls
.deleteContext
= CRYPT_ProvDeleteCRL
;
881 ret
->hdr
.control
= CRYPT_ProvControl
;
882 if (pProvInfo
->cStoreProvFunc
> CERT_STORE_PROV_CLOSE_FUNC
)
883 ret
->provCloseStore
=
884 pProvInfo
->rgpvStoreProvFunc
[CERT_STORE_PROV_CLOSE_FUNC
];
886 ret
->provCloseStore
= NULL
;
887 if (pProvInfo
->cStoreProvFunc
>
888 CERT_STORE_PROV_WRITE_CERT_FUNC
)
889 ret
->provWriteCert
= pProvInfo
->rgpvStoreProvFunc
[
890 CERT_STORE_PROV_WRITE_CERT_FUNC
];
892 ret
->provWriteCert
= NULL
;
893 if (pProvInfo
->cStoreProvFunc
>
894 CERT_STORE_PROV_DELETE_CERT_FUNC
)
895 ret
->provDeleteCert
= pProvInfo
->rgpvStoreProvFunc
[
896 CERT_STORE_PROV_DELETE_CERT_FUNC
];
898 ret
->provDeleteCert
= NULL
;
899 if (pProvInfo
->cStoreProvFunc
>
900 CERT_STORE_PROV_WRITE_CRL_FUNC
)
901 ret
->provWriteCrl
= pProvInfo
->rgpvStoreProvFunc
[
902 CERT_STORE_PROV_WRITE_CRL_FUNC
];
904 ret
->provWriteCert
= NULL
;
905 if (pProvInfo
->cStoreProvFunc
>
906 CERT_STORE_PROV_DELETE_CRL_FUNC
)
907 ret
->provDeleteCrl
= pProvInfo
->rgpvStoreProvFunc
[
908 CERT_STORE_PROV_DELETE_CRL_FUNC
];
910 ret
->provDeleteCert
= NULL
;
911 if (pProvInfo
->cStoreProvFunc
>
912 CERT_STORE_PROV_CONTROL_FUNC
)
913 ret
->provControl
= pProvInfo
->rgpvStoreProvFunc
[
914 CERT_STORE_PROV_CONTROL_FUNC
];
916 ret
->provControl
= NULL
;
918 return (PWINECRYPT_CERTSTORE
)ret
;
921 static PWINECRYPT_CERTSTORE
CRYPT_ProvOpenStore(LPCSTR lpszStoreProvider
,
922 DWORD dwEncodingType
, HCRYPTPROV hCryptProv
, DWORD dwFlags
, const void *pvPara
)
924 static HCRYPTOIDFUNCSET set
= NULL
;
925 PFN_CERT_DLL_OPEN_STORE_PROV_FUNC provOpenFunc
;
926 HCRYPTOIDFUNCADDR hFunc
;
927 PWINECRYPT_CERTSTORE ret
= NULL
;
930 set
= CryptInitOIDFunctionSet(CRYPT_OID_OPEN_STORE_PROV_FUNC
, 0);
931 CryptGetOIDFunctionAddress(set
, dwEncodingType
, lpszStoreProvider
, 0,
932 (void **)&provOpenFunc
, &hFunc
);
935 CERT_STORE_PROV_INFO provInfo
= { 0 };
937 provInfo
.cbSize
= sizeof(provInfo
);
938 if (dwFlags
& CERT_STORE_DELETE_FLAG
)
939 provOpenFunc(lpszStoreProvider
, dwEncodingType
, hCryptProv
,
940 dwFlags
, pvPara
, NULL
, &provInfo
);
945 memStore
= CertOpenStore(CERT_STORE_PROV_MEMORY
, 0, 0,
946 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
949 if (provOpenFunc(lpszStoreProvider
, dwEncodingType
, hCryptProv
,
950 dwFlags
, pvPara
, memStore
, &provInfo
))
951 ret
= CRYPT_ProvCreateStore(hCryptProv
, dwFlags
, memStore
,
954 CertCloseStore(memStore
, 0);
957 CryptFreeOIDFunctionAddress(hFunc
, 0);
960 SetLastError(ERROR_FILE_NOT_FOUND
);
964 static void CRYPT_HashToStr(const BYTE
*hash
, LPWSTR asciiHash
)
966 static const WCHAR fmt
[] = { '%','0','2','X',0 };
972 for (i
= 0; i
< 20; i
++)
973 wsprintfW(asciiHash
+ i
* 2, fmt
, hash
[i
]);
976 static const WCHAR CertsW
[] = { 'C','e','r','t','i','f','i','c','a','t','e','s',
978 static const WCHAR CRLsW
[] = { 'C','R','L','s',0 };
979 static const WCHAR CTLsW
[] = { 'C','T','L','s',0 };
980 static const WCHAR BlobW
[] = { 'B','l','o','b',0 };
982 static void CRYPT_RegReadSerializedFromReg(const WINE_REGSTOREINFO
*store
, HKEY key
,
987 WCHAR subKeyName
[MAX_PATH
];
990 DWORD size
= sizeof(subKeyName
) / sizeof(WCHAR
);
992 rc
= RegEnumKeyExW(key
, index
++, subKeyName
, &size
, NULL
, NULL
, NULL
,
998 rc
= RegOpenKeyExW(key
, subKeyName
, 0, KEY_READ
, &subKey
);
1004 rc
= RegQueryValueExW(subKey
, BlobW
, NULL
, NULL
, NULL
, &size
);
1006 buf
= CryptMemAlloc(size
);
1009 rc
= RegQueryValueExW(subKey
, BlobW
, NULL
, NULL
, buf
,
1013 const void *context
;
1016 TRACE("Adding cert with hash %s\n",
1017 debugstr_w(subKeyName
));
1018 context
= CRYPT_ReadSerializedElement(buf
, size
,
1019 contextType
, &addedType
);
1022 const WINE_CONTEXT_INTERFACE
*contextInterface
;
1027 case CERT_STORE_CERTIFICATE_CONTEXT
:
1028 contextInterface
= &gCertInterface
;
1030 case CERT_STORE_CRL_CONTEXT
:
1031 contextInterface
= &gCRLInterface
;
1033 case CERT_STORE_CTL_CONTEXT
:
1034 contextInterface
= &gCTLInterface
;
1037 contextInterface
= NULL
;
1039 if (contextInterface
)
1041 size
= sizeof(hash
);
1042 if (contextInterface
->getProp(context
,
1043 CERT_HASH_PROP_ID
, hash
, &size
))
1045 WCHAR asciiHash
[20 * 2 + 1];
1047 CRYPT_HashToStr(hash
, asciiHash
);
1048 TRACE("comparing %s\n",
1049 debugstr_w(asciiHash
));
1050 TRACE("with %s\n", debugstr_w(subKeyName
));
1051 if (!lstrcmpW(asciiHash
, subKeyName
))
1053 TRACE("hash matches, adding\n");
1054 contextInterface
->addContextToStore(
1055 store
->memStore
, context
,
1056 CERT_STORE_ADD_REPLACE_EXISTING
, NULL
);
1059 TRACE("hash doesn't match, ignoring\n");
1061 contextInterface
->free(context
);
1067 RegCloseKey(subKey
);
1069 /* Ignore intermediate errors, continue enumerating */
1075 static void CRYPT_RegReadFromReg(const WINE_REGSTOREINFO
*store
)
1077 static const WCHAR
* const subKeys
[] = { CertsW
, CRLsW
, CTLsW
};
1078 static const DWORD contextFlags
[] = { CERT_STORE_CERTIFICATE_CONTEXT_FLAG
,
1079 CERT_STORE_CRL_CONTEXT_FLAG
, CERT_STORE_CTL_CONTEXT_FLAG
};
1082 for (i
= 0; i
< sizeof(subKeys
) / sizeof(subKeys
[0]); i
++)
1087 rc
= RegCreateKeyExW(store
->key
, subKeys
[i
], 0, NULL
, 0, KEY_READ
, NULL
,
1091 CRYPT_RegReadSerializedFromReg(store
, key
, contextFlags
[i
]);
1097 /* Hash is assumed to be 20 bytes in length (a SHA-1 hash) */
1098 static BOOL
CRYPT_WriteSerializedToReg(HKEY key
, const BYTE
*hash
, const BYTE
*buf
,
1101 WCHAR asciiHash
[20 * 2 + 1];
1106 CRYPT_HashToStr(hash
, asciiHash
);
1107 rc
= RegCreateKeyExW(key
, asciiHash
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
,
1111 rc
= RegSetValueExW(subKey
, BlobW
, 0, REG_BINARY
, buf
, len
);
1112 RegCloseKey(subKey
);
1124 static BOOL
CRYPT_SerializeContextsToReg(HKEY key
,
1125 const WINE_CONTEXT_INTERFACE
*contextInterface
, HCERTSTORE memStore
)
1127 const void *context
= NULL
;
1131 context
= contextInterface
->enumContextsInStore(memStore
, context
);
1135 DWORD hashSize
= sizeof(hash
);
1137 ret
= contextInterface
->getProp(context
, CERT_HASH_PROP_ID
, hash
,
1144 ret
= contextInterface
->serialize(context
, 0, NULL
, &size
);
1146 buf
= CryptMemAlloc(size
);
1149 ret
= contextInterface
->serialize(context
, 0, buf
, &size
);
1151 ret
= CRYPT_WriteSerializedToReg(key
, hash
, buf
, size
);
1158 } while (ret
&& context
!= NULL
);
1160 contextInterface
->free(context
);
1164 static BOOL
CRYPT_RegWriteToReg(PWINE_REGSTOREINFO store
)
1166 static const WCHAR
* const subKeys
[] = { CertsW
, CRLsW
, CTLsW
};
1167 static const WINE_CONTEXT_INTERFACE
* const interfaces
[] = { &gCertInterface
,
1168 &gCRLInterface
, &gCTLInterface
};
1169 struct list
*listToDelete
[] = { &store
->certsToDelete
, &store
->crlsToDelete
,
1174 for (i
= 0; ret
&& i
< sizeof(subKeys
) / sizeof(subKeys
[0]); i
++)
1177 LONG rc
= RegCreateKeyExW(store
->key
, subKeys
[i
], 0, NULL
, 0,
1178 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1182 if (listToDelete
[i
])
1184 PWINE_HASH_TO_DELETE toDelete
, next
;
1185 WCHAR asciiHash
[20 * 2 + 1];
1187 EnterCriticalSection(&store
->cs
);
1188 LIST_FOR_EACH_ENTRY_SAFE(toDelete
, next
, listToDelete
[i
],
1189 WINE_HASH_TO_DELETE
, entry
)
1193 CRYPT_HashToStr(toDelete
->hash
, asciiHash
);
1194 TRACE("Removing %s\n", debugstr_w(asciiHash
));
1195 rc
= RegDeleteKeyW(key
, asciiHash
);
1196 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_FILE_NOT_FOUND
)
1201 list_remove(&toDelete
->entry
);
1202 CryptMemFree(toDelete
);
1204 LeaveCriticalSection(&store
->cs
);
1206 ret
= CRYPT_SerializeContextsToReg(key
, interfaces
[i
],
1219 /* If force is true or the registry store is dirty, writes the contents of the
1220 * store to the registry.
1222 static BOOL
CRYPT_RegFlushStore(PWINE_REGSTOREINFO store
, BOOL force
)
1226 TRACE("(%p, %d)\n", store
, force
);
1228 if (store
->dirty
|| force
)
1229 ret
= CRYPT_RegWriteToReg(store
);
1235 static void WINAPI
CRYPT_RegCloseStore(HCERTSTORE hCertStore
, DWORD dwFlags
)
1237 PWINE_REGSTOREINFO store
= (PWINE_REGSTOREINFO
)hCertStore
;
1239 TRACE("(%p, %08x)\n", store
, dwFlags
);
1241 FIXME("Unimplemented flags: %08x\n", dwFlags
);
1243 CRYPT_RegFlushStore(store
, FALSE
);
1244 RegCloseKey(store
->key
);
1245 store
->cs
.DebugInfo
->Spare
[0] = 0;
1246 DeleteCriticalSection(&store
->cs
);
1247 CryptMemFree(store
);
1250 static BOOL WINAPI
CRYPT_RegWriteContext(PWINE_REGSTOREINFO store
,
1251 const void *context
, DWORD dwFlags
)
1255 if (dwFlags
& CERT_STORE_PROV_WRITE_ADD_FLAG
)
1257 store
->dirty
= TRUE
;
1265 static BOOL
CRYPT_RegDeleteContext(PWINE_REGSTOREINFO store
,
1266 struct list
*deleteList
, const void *context
,
1267 PCWINE_CONTEXT_INTERFACE contextInterface
)
1271 if (store
->dwOpenFlags
& CERT_STORE_READONLY_FLAG
)
1273 SetLastError(ERROR_ACCESS_DENIED
);
1278 PWINE_HASH_TO_DELETE toDelete
=
1279 CryptMemAlloc(sizeof(WINE_HASH_TO_DELETE
));
1283 DWORD size
= sizeof(toDelete
->hash
);
1285 ret
= contextInterface
->getProp(context
, CERT_HASH_PROP_ID
,
1286 toDelete
->hash
, &size
);
1289 EnterCriticalSection(&store
->cs
);
1290 list_add_tail(deleteList
, &toDelete
->entry
);
1291 LeaveCriticalSection(&store
->cs
);
1295 CryptMemFree(toDelete
);
1302 store
->dirty
= TRUE
;
1307 static BOOL WINAPI
CRYPT_RegWriteCert(HCERTSTORE hCertStore
,
1308 PCCERT_CONTEXT cert
, DWORD dwFlags
)
1310 PWINE_REGSTOREINFO store
= (PWINE_REGSTOREINFO
)hCertStore
;
1312 TRACE("(%p, %p, %d)\n", hCertStore
, cert
, dwFlags
);
1314 return CRYPT_RegWriteContext(store
, cert
, dwFlags
);
1317 static BOOL WINAPI
CRYPT_RegDeleteCert(HCERTSTORE hCertStore
,
1318 PCCERT_CONTEXT pCertContext
, DWORD dwFlags
)
1320 PWINE_REGSTOREINFO store
= (PWINE_REGSTOREINFO
)hCertStore
;
1322 TRACE("(%p, %p, %08x)\n", store
, pCertContext
, dwFlags
);
1324 return CRYPT_RegDeleteContext(store
, &store
->certsToDelete
, pCertContext
,
1328 static BOOL WINAPI
CRYPT_RegWriteCRL(HCERTSTORE hCertStore
,
1329 PCCRL_CONTEXT crl
, DWORD dwFlags
)
1331 PWINE_REGSTOREINFO store
= (PWINE_REGSTOREINFO
)hCertStore
;
1333 TRACE("(%p, %p, %d)\n", hCertStore
, crl
, dwFlags
);
1335 return CRYPT_RegWriteContext(store
, crl
, dwFlags
);
1338 static BOOL WINAPI
CRYPT_RegDeleteCRL(HCERTSTORE hCertStore
,
1339 PCCRL_CONTEXT pCrlContext
, DWORD dwFlags
)
1341 PWINE_REGSTOREINFO store
= (PWINE_REGSTOREINFO
)hCertStore
;
1343 TRACE("(%p, %p, %08x)\n", store
, pCrlContext
, dwFlags
);
1345 return CRYPT_RegDeleteContext(store
, &store
->crlsToDelete
, pCrlContext
,
1349 static BOOL WINAPI
CRYPT_RegControl(HCERTSTORE hCertStore
, DWORD dwFlags
,
1350 DWORD dwCtrlType
, void const *pvCtrlPara
)
1352 PWINE_REGSTOREINFO store
= (PWINE_REGSTOREINFO
)hCertStore
;
1355 TRACE("(%p, %08x, %d, %p)\n", hCertStore
, dwFlags
, dwCtrlType
,
1360 case CERT_STORE_CTRL_RESYNC
:
1361 CRYPT_RegFlushStore(store
, FALSE
);
1362 CRYPT_MemEmptyStore((PWINE_MEMSTORE
)store
->memStore
);
1363 CRYPT_RegReadFromReg(store
);
1366 case CERT_STORE_CTRL_COMMIT
:
1367 ret
= CRYPT_RegFlushStore(store
,
1368 dwFlags
& CERT_STORE_CTRL_COMMIT_FORCE_FLAG
);
1371 FIXME("%d: stub\n", dwCtrlType
);
1377 static void *regProvFuncs
[] = {
1378 CRYPT_RegCloseStore
,
1379 NULL
, /* CERT_STORE_PROV_READ_CERT_FUNC */
1381 CRYPT_RegDeleteCert
,
1382 NULL
, /* CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC */
1383 NULL
, /* CERT_STORE_PROV_READ_CRL_FUNC */
1386 NULL
, /* CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC */
1387 NULL
, /* CERT_STORE_PROV_READ_CTL_FUNC */
1388 NULL
, /* CERT_STORE_PROV_WRITE_CTL_FUNC */
1389 NULL
, /* CERT_STORE_PROV_DELETE_CTL_FUNC */
1390 NULL
, /* CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC */
1394 static WINECRYPT_CERTSTORE
*CRYPT_RegOpenStore(HCRYPTPROV hCryptProv
,
1395 DWORD dwFlags
, const void *pvPara
)
1397 PWINECRYPT_CERTSTORE store
= NULL
;
1399 TRACE("(%ld, %08x, %p)\n", hCryptProv
, dwFlags
, pvPara
);
1401 if (dwFlags
& CERT_STORE_DELETE_FLAG
)
1403 DWORD rc
= RegDeleteTreeW((HKEY
)pvPara
, CertsW
);
1405 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_NO_MORE_ITEMS
)
1406 rc
= RegDeleteTreeW((HKEY
)pvPara
, CRLsW
);
1407 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_NO_MORE_ITEMS
)
1408 rc
= RegDeleteTreeW((HKEY
)pvPara
, CTLsW
);
1409 if (rc
== ERROR_NO_MORE_ITEMS
)
1417 if (DuplicateHandle(GetCurrentProcess(), (HANDLE
)pvPara
,
1418 GetCurrentProcess(), (LPHANDLE
)&key
,
1419 dwFlags
& CERT_STORE_READONLY_FLAG
? KEY_READ
: KEY_ALL_ACCESS
,
1422 PWINECRYPT_CERTSTORE memStore
;
1424 memStore
= CRYPT_MemOpenStore(hCryptProv
, dwFlags
, NULL
);
1427 PWINE_REGSTOREINFO regInfo
= CryptMemAlloc(
1428 sizeof(WINE_REGSTOREINFO
));
1432 CERT_STORE_PROV_INFO provInfo
= { 0 };
1434 regInfo
->dwOpenFlags
= dwFlags
;
1435 regInfo
->cryptProv
= hCryptProv
;
1436 regInfo
->memStore
= memStore
;
1438 InitializeCriticalSection(®Info
->cs
);
1439 regInfo
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": PWINE_REGSTOREINFO->cs");
1440 list_init(®Info
->certsToDelete
);
1441 list_init(®Info
->crlsToDelete
);
1442 CRYPT_RegReadFromReg(regInfo
);
1443 regInfo
->dirty
= FALSE
;
1444 provInfo
.cbSize
= sizeof(provInfo
);
1445 provInfo
.cStoreProvFunc
= sizeof(regProvFuncs
) /
1446 sizeof(regProvFuncs
[0]);
1447 provInfo
.rgpvStoreProvFunc
= regProvFuncs
;
1448 provInfo
.hStoreProv
= regInfo
;
1449 store
= CRYPT_ProvCreateStore(hCryptProv
, dwFlags
, memStore
,
1455 TRACE("returning %p\n", store
);
1459 /* FIXME: this isn't complete for the Root store, in which the top-level
1460 * self-signed CA certs reside. Adding a cert to the Root store should present
1461 * the user with a dialog indicating the consequences of doing so, and asking
1462 * the user to confirm whether the cert should be added.
1464 static PWINECRYPT_CERTSTORE
CRYPT_SysRegOpenStoreW(HCRYPTPROV hCryptProv
,
1465 DWORD dwFlags
, const void *pvPara
)
1467 static const WCHAR fmt
[] = { '%','s','\\','%','s',0 };
1468 LPCWSTR storeName
= (LPCWSTR
)pvPara
;
1470 PWINECRYPT_CERTSTORE store
= NULL
;
1475 TRACE("(%ld, %08x, %s)\n", hCryptProv
, dwFlags
,
1476 debugstr_w((LPCWSTR
)pvPara
));
1480 SetLastError(E_INVALIDARG
);
1485 switch (dwFlags
& CERT_SYSTEM_STORE_LOCATION_MASK
)
1487 case CERT_SYSTEM_STORE_LOCAL_MACHINE
:
1488 root
= HKEY_LOCAL_MACHINE
;
1489 base
= CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH
;
1491 case CERT_SYSTEM_STORE_CURRENT_USER
:
1492 root
= HKEY_CURRENT_USER
;
1493 base
= CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH
;
1495 case CERT_SYSTEM_STORE_CURRENT_SERVICE
:
1496 /* hklm\Software\Microsoft\Cryptography\Services\servicename\
1497 * SystemCertificates
1499 FIXME("CERT_SYSTEM_STORE_CURRENT_SERVICE, %s: stub\n",
1500 debugstr_w(storeName
));
1502 case CERT_SYSTEM_STORE_SERVICES
:
1503 /* hklm\Software\Microsoft\Cryptography\Services\servicename\
1504 * SystemCertificates
1506 FIXME("CERT_SYSTEM_STORE_SERVICES, %s: stub\n",
1507 debugstr_w(storeName
));
1509 case CERT_SYSTEM_STORE_USERS
:
1510 /* hku\user sid\Software\Microsoft\SystemCertificates */
1511 FIXME("CERT_SYSTEM_STORE_USERS, %s: stub\n",
1512 debugstr_w(storeName
));
1514 case CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY
:
1515 root
= HKEY_CURRENT_USER
;
1516 base
= CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH
;
1518 case CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
:
1519 root
= HKEY_LOCAL_MACHINE
;
1520 base
= CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH
;
1522 case CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
:
1523 /* hklm\Software\Microsoft\EnterpriseCertificates */
1524 FIXME("CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, %s: stub\n",
1525 debugstr_w(storeName
));
1528 SetLastError(E_INVALIDARG
);
1532 storePath
= CryptMemAlloc((lstrlenW(base
) + lstrlenW(storeName
) + 2) *
1538 REGSAM sam
= dwFlags
& CERT_STORE_READONLY_FLAG
? KEY_READ
:
1541 wsprintfW(storePath
, fmt
, base
, storeName
);
1542 if (dwFlags
& CERT_STORE_OPEN_EXISTING_FLAG
)
1543 rc
= RegOpenKeyExW(root
, storePath
, 0, sam
, &key
);
1548 rc
= RegCreateKeyExW(root
, storePath
, 0, NULL
, 0, sam
, NULL
,
1550 if (!rc
&& dwFlags
& CERT_STORE_CREATE_NEW_FLAG
&&
1551 disp
== REG_OPENED_EXISTING_KEY
)
1554 rc
= ERROR_FILE_EXISTS
;
1559 store
= CRYPT_RegOpenStore(hCryptProv
, dwFlags
, key
);
1564 CryptMemFree(storePath
);
1569 static PWINECRYPT_CERTSTORE
CRYPT_SysRegOpenStoreA(HCRYPTPROV hCryptProv
,
1570 DWORD dwFlags
, const void *pvPara
)
1573 PWINECRYPT_CERTSTORE ret
= NULL
;
1575 TRACE("(%ld, %08x, %s)\n", hCryptProv
, dwFlags
,
1576 debugstr_a((LPCSTR
)pvPara
));
1580 SetLastError(ERROR_FILE_NOT_FOUND
);
1583 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pvPara
, -1, NULL
, 0);
1586 LPWSTR storeName
= CryptMemAlloc(len
* sizeof(WCHAR
));
1590 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pvPara
, -1, storeName
, len
);
1591 ret
= CRYPT_SysRegOpenStoreW(hCryptProv
, dwFlags
, storeName
);
1592 CryptMemFree(storeName
);
1598 static PWINECRYPT_CERTSTORE
CRYPT_SysOpenStoreW(HCRYPTPROV hCryptProv
,
1599 DWORD dwFlags
, const void *pvPara
)
1601 HCERTSTORE store
= 0;
1604 TRACE("(%ld, %08x, %s)\n", hCryptProv
, dwFlags
,
1605 debugstr_w((LPCWSTR
)pvPara
));
1609 SetLastError(ERROR_FILE_NOT_FOUND
);
1612 /* This returns a different error than system registry stores if the
1613 * location is invalid.
1615 switch (dwFlags
& CERT_SYSTEM_STORE_LOCATION_MASK
)
1617 case CERT_SYSTEM_STORE_LOCAL_MACHINE
:
1618 case CERT_SYSTEM_STORE_CURRENT_USER
:
1619 case CERT_SYSTEM_STORE_CURRENT_SERVICE
:
1620 case CERT_SYSTEM_STORE_SERVICES
:
1621 case CERT_SYSTEM_STORE_USERS
:
1622 case CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY
:
1623 case CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
:
1624 case CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
:
1628 SetLastError(ERROR_FILE_NOT_FOUND
);
1633 HCERTSTORE regStore
= CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_W
,
1634 0, hCryptProv
, dwFlags
, pvPara
);
1638 store
= CertOpenStore(CERT_STORE_PROV_COLLECTION
, 0, 0,
1639 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
1640 CertAddStoreToCollection(store
, regStore
,
1641 dwFlags
& CERT_STORE_READONLY_FLAG
? 0 :
1642 CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG
, 0);
1643 CertCloseStore(regStore
, 0);
1644 /* CERT_SYSTEM_STORE_CURRENT_USER returns both the HKCU and HKLM
1647 if ((dwFlags
& CERT_SYSTEM_STORE_LOCATION_MASK
) ==
1648 CERT_SYSTEM_STORE_CURRENT_USER
)
1650 dwFlags
&= ~CERT_SYSTEM_STORE_CURRENT_USER
;
1651 dwFlags
|= CERT_SYSTEM_STORE_LOCAL_MACHINE
;
1652 regStore
= CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_W
, 0,
1653 hCryptProv
, dwFlags
, pvPara
);
1656 CertAddStoreToCollection(store
, regStore
,
1657 dwFlags
& CERT_STORE_READONLY_FLAG
? 0 :
1658 CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG
, 0);
1659 CertCloseStore(regStore
, 0);
1664 return (PWINECRYPT_CERTSTORE
)store
;
1667 static PWINECRYPT_CERTSTORE
CRYPT_SysOpenStoreA(HCRYPTPROV hCryptProv
,
1668 DWORD dwFlags
, const void *pvPara
)
1671 PWINECRYPT_CERTSTORE ret
= NULL
;
1673 TRACE("(%ld, %08x, %s)\n", hCryptProv
, dwFlags
,
1674 debugstr_a((LPCSTR
)pvPara
));
1678 SetLastError(ERROR_FILE_NOT_FOUND
);
1681 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pvPara
, -1, NULL
, 0);
1684 LPWSTR storeName
= CryptMemAlloc(len
* sizeof(WCHAR
));
1688 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pvPara
, -1, storeName
, len
);
1689 ret
= CRYPT_SysOpenStoreW(hCryptProv
, dwFlags
, storeName
);
1690 CryptMemFree(storeName
);
1696 static void WINAPI
CRYPT_FileCloseStore(HCERTSTORE hCertStore
, DWORD dwFlags
)
1698 PWINE_FILESTOREINFO store
= (PWINE_FILESTOREINFO
)hCertStore
;
1700 TRACE("(%p, %08x)\n", store
, dwFlags
);
1702 CRYPT_WriteSerializedFile(store
->file
, store
->memStore
);
1703 CertCloseStore(store
->memStore
, dwFlags
);
1704 CloseHandle(store
->file
);
1705 CryptMemFree(store
);
1708 static BOOL WINAPI
CRYPT_FileWriteCert(HCERTSTORE hCertStore
,
1709 PCCERT_CONTEXT cert
, DWORD dwFlags
)
1711 PWINE_FILESTOREINFO store
= (PWINE_FILESTOREINFO
)hCertStore
;
1713 TRACE("(%p, %p, %d)\n", hCertStore
, cert
, dwFlags
);
1714 store
->dirty
= TRUE
;
1718 static BOOL WINAPI
CRYPT_FileDeleteCert(HCERTSTORE hCertStore
,
1719 PCCERT_CONTEXT pCertContext
, DWORD dwFlags
)
1721 PWINE_FILESTOREINFO store
= (PWINE_FILESTOREINFO
)hCertStore
;
1723 TRACE("(%p, %p, %08x)\n", hCertStore
, pCertContext
, dwFlags
);
1724 store
->dirty
= TRUE
;
1728 static BOOL WINAPI
CRYPT_FileWriteCRL(HCERTSTORE hCertStore
,
1729 PCCRL_CONTEXT crl
, DWORD dwFlags
)
1731 PWINE_FILESTOREINFO store
= (PWINE_FILESTOREINFO
)hCertStore
;
1733 TRACE("(%p, %p, %d)\n", hCertStore
, crl
, dwFlags
);
1734 store
->dirty
= TRUE
;
1738 static BOOL WINAPI
CRYPT_FileDeleteCRL(HCERTSTORE hCertStore
,
1739 PCCRL_CONTEXT pCrlContext
, DWORD dwFlags
)
1741 PWINE_FILESTOREINFO store
= (PWINE_FILESTOREINFO
)hCertStore
;
1743 TRACE("(%p, %p, %08x)\n", hCertStore
, pCrlContext
, dwFlags
);
1744 store
->dirty
= TRUE
;
1748 static BOOL WINAPI
CRYPT_FileControl(HCERTSTORE hCertStore
, DWORD dwFlags
,
1749 DWORD dwCtrlType
, void const *pvCtrlPara
)
1751 PWINE_FILESTOREINFO store
= (PWINE_FILESTOREINFO
)hCertStore
;
1754 TRACE("(%p, %08x, %d, %p)\n", hCertStore
, dwFlags
, dwCtrlType
,
1759 case CERT_STORE_CTRL_RESYNC
:
1760 CRYPT_MemEmptyStore((PWINE_MEMSTORE
)store
->memStore
);
1761 CRYPT_ReadSerializedFile(store
->file
, store
);
1764 case CERT_STORE_CTRL_COMMIT
:
1765 if (!(store
->dwOpenFlags
& CERT_FILE_STORE_COMMIT_ENABLE_FLAG
))
1767 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1770 else if (store
->dirty
)
1771 ret
= CRYPT_WriteSerializedFile(store
->file
, store
->memStore
);
1776 FIXME("%d: stub\n", dwCtrlType
);
1782 static void *fileProvFuncs
[] = {
1783 CRYPT_FileCloseStore
,
1784 NULL
, /* CERT_STORE_PROV_READ_CERT_FUNC */
1785 CRYPT_FileWriteCert
,
1786 CRYPT_FileDeleteCert
,
1787 NULL
, /* CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC */
1788 NULL
, /* CERT_STORE_PROV_READ_CRL_FUNC */
1790 CRYPT_FileDeleteCRL
,
1791 NULL
, /* CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC */
1792 NULL
, /* CERT_STORE_PROV_READ_CTL_FUNC */
1793 NULL
, /* CERT_STORE_PROV_WRITE_CTL_FUNC */
1794 NULL
, /* CERT_STORE_PROV_DELETE_CTL_FUNC */
1795 NULL
, /* CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC */
1799 static PWINECRYPT_CERTSTORE
CRYPT_FileOpenStore(HCRYPTPROV hCryptProv
,
1800 DWORD dwFlags
, const void *pvPara
)
1802 PWINECRYPT_CERTSTORE store
= NULL
;
1803 HANDLE file
= (HANDLE
)pvPara
;
1805 TRACE("(%ld, %08x, %p)\n", hCryptProv
, dwFlags
, pvPara
);
1809 SetLastError(ERROR_INVALID_HANDLE
);
1812 if (dwFlags
& CERT_STORE_DELETE_FLAG
)
1814 SetLastError(E_INVALIDARG
);
1817 if ((dwFlags
& CERT_STORE_READONLY_FLAG
) &&
1818 (dwFlags
& CERT_FILE_STORE_COMMIT_ENABLE_FLAG
))
1820 SetLastError(E_INVALIDARG
);
1824 if (DuplicateHandle(GetCurrentProcess(), (HANDLE
)pvPara
,
1825 GetCurrentProcess(), &file
, dwFlags
& CERT_STORE_READONLY_FLAG
?
1826 GENERIC_READ
: GENERIC_READ
| GENERIC_WRITE
, TRUE
, 0))
1828 PWINECRYPT_CERTSTORE memStore
;
1830 memStore
= CRYPT_MemOpenStore(hCryptProv
, dwFlags
, NULL
);
1833 if (CRYPT_ReadSerializedFile(file
, memStore
))
1835 PWINE_FILESTOREINFO info
= CryptMemAlloc(
1836 sizeof(WINE_FILESTOREINFO
));
1840 CERT_STORE_PROV_INFO provInfo
= { 0 };
1842 info
->dwOpenFlags
= dwFlags
;
1843 info
->cryptProv
= hCryptProv
;
1844 info
->memStore
= memStore
;
1846 info
->dirty
= FALSE
;
1847 provInfo
.cbSize
= sizeof(provInfo
);
1848 provInfo
.cStoreProvFunc
= sizeof(fileProvFuncs
) /
1849 sizeof(fileProvFuncs
[0]);
1850 provInfo
.rgpvStoreProvFunc
= fileProvFuncs
;
1851 provInfo
.hStoreProv
= info
;
1852 store
= CRYPT_ProvCreateStore(hCryptProv
, dwFlags
, memStore
,
1858 TRACE("returning %p\n", store
);
1862 static PWINECRYPT_CERTSTORE
CRYPT_FileNameOpenStoreW(HCRYPTPROV hCryptProv
,
1863 DWORD dwFlags
, const void *pvPara
)
1865 HCERTSTORE store
= 0;
1866 LPCWSTR fileName
= (LPCWSTR
)pvPara
;
1867 DWORD access
, create
;
1870 TRACE("(%ld, %08x, %s)\n", hCryptProv
, dwFlags
, debugstr_w(fileName
));
1874 SetLastError(ERROR_PATH_NOT_FOUND
);
1878 access
= GENERIC_READ
;
1879 if (dwFlags
& CERT_FILE_STORE_COMMIT_ENABLE_FLAG
)
1880 access
|= GENERIC_WRITE
;
1881 if (dwFlags
& CERT_STORE_CREATE_NEW_FLAG
)
1882 create
= CREATE_NEW
;
1883 else if (dwFlags
& CERT_STORE_OPEN_EXISTING_FLAG
)
1884 create
= OPEN_EXISTING
;
1886 create
= OPEN_ALWAYS
;
1887 file
= CreateFileW(fileName
, access
, FILE_SHARE_READ
, NULL
, create
,
1888 FILE_ATTRIBUTE_NORMAL
, NULL
);
1889 if (file
!= INVALID_HANDLE_VALUE
)
1891 /* FIXME: need to check whether it's a serialized store; if not, fall
1892 * back to a PKCS#7 signed message, then to a single serialized cert.
1894 store
= CertOpenStore(CERT_STORE_PROV_FILE
, 0, hCryptProv
, dwFlags
,
1898 return (PWINECRYPT_CERTSTORE
)store
;
1901 static PWINECRYPT_CERTSTORE
CRYPT_FileNameOpenStoreA(HCRYPTPROV hCryptProv
,
1902 DWORD dwFlags
, const void *pvPara
)
1905 PWINECRYPT_CERTSTORE ret
= NULL
;
1907 TRACE("(%ld, %08x, %s)\n", hCryptProv
, dwFlags
,
1908 debugstr_a((LPCSTR
)pvPara
));
1912 SetLastError(ERROR_FILE_NOT_FOUND
);
1915 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pvPara
, -1, NULL
, 0);
1918 LPWSTR storeName
= CryptMemAlloc(len
* sizeof(WCHAR
));
1922 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pvPara
, -1, storeName
, len
);
1923 ret
= CRYPT_FileNameOpenStoreW(hCryptProv
, dwFlags
, storeName
);
1924 CryptMemFree(storeName
);
1930 static void WINAPI
CRYPT_MsgCloseStore(HCERTSTORE hCertStore
, DWORD dwFlags
)
1932 PWINE_MSGSTOREINFO store
= (PWINE_MSGSTOREINFO
)hCertStore
;
1934 TRACE("(%p, %08x)\n", store
, dwFlags
);
1935 CertCloseStore(store
->memStore
, dwFlags
);
1936 CryptMsgClose(store
->msg
);
1937 CryptMemFree(store
);
1940 static void *msgProvFuncs
[] = {
1941 CRYPT_MsgCloseStore
,
1942 NULL
, /* CERT_STORE_PROV_READ_CERT_FUNC */
1943 NULL
, /* CERT_STORE_PROV_WRITE_CERT_FUNC */
1944 NULL
, /* CERT_STORE_PROV_DELETE_CERT_FUNC */
1945 NULL
, /* CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC */
1946 NULL
, /* CERT_STORE_PROV_READ_CRL_FUNC */
1947 NULL
, /* CERT_STORE_PROV_WRITE_CRL_FUNC */
1948 NULL
, /* CERT_STORE_PROV_DELETE_CRL_FUNC */
1949 NULL
, /* CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC */
1950 NULL
, /* CERT_STORE_PROV_READ_CTL_FUNC */
1951 NULL
, /* CERT_STORE_PROV_WRITE_CTL_FUNC */
1952 NULL
, /* CERT_STORE_PROV_DELETE_CTL_FUNC */
1953 NULL
, /* CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC */
1954 NULL
, /* CERT_STORE_PROV_CONTROL_FUNC */
1957 static PWINECRYPT_CERTSTORE
CRYPT_MsgOpenStore(HCRYPTPROV hCryptProv
,
1958 DWORD dwFlags
, const void *pvPara
)
1960 PWINECRYPT_CERTSTORE store
= NULL
;
1961 HCRYPTMSG msg
= (HCRYPTMSG
)pvPara
;
1962 PWINECRYPT_CERTSTORE memStore
;
1964 TRACE("(%ld, %08x, %p)\n", hCryptProv
, dwFlags
, pvPara
);
1966 memStore
= CRYPT_MemOpenStore(hCryptProv
, dwFlags
, NULL
);
1970 DWORD size
, count
, i
;
1972 size
= sizeof(count
);
1973 ret
= CryptMsgGetParam(msg
, CMSG_CERT_COUNT_PARAM
, 0, &count
, &size
);
1974 for (i
= 0; ret
&& i
< count
; i
++)
1977 ret
= CryptMsgGetParam(msg
, CMSG_CERT_PARAM
, i
, NULL
, &size
);
1980 LPBYTE buf
= CryptMemAlloc(size
);
1984 ret
= CryptMsgGetParam(msg
, CMSG_CERT_PARAM
, i
, buf
, &size
);
1986 ret
= CertAddEncodedCertificateToStore(memStore
,
1987 X509_ASN_ENCODING
, buf
, size
, CERT_STORE_ADD_ALWAYS
,
1993 size
= sizeof(count
);
1994 ret
= CryptMsgGetParam(msg
, CMSG_CRL_COUNT_PARAM
, 0, &count
, &size
);
1995 for (i
= 0; ret
&& i
< count
; i
++)
1998 ret
= CryptMsgGetParam(msg
, CMSG_CRL_PARAM
, i
, NULL
, &size
);
2001 LPBYTE buf
= CryptMemAlloc(size
);
2005 ret
= CryptMsgGetParam(msg
, CMSG_CRL_PARAM
, i
, buf
, &size
);
2007 ret
= CertAddEncodedCRLToStore(memStore
,
2008 X509_ASN_ENCODING
, buf
, size
, CERT_STORE_ADD_ALWAYS
,
2016 PWINE_MSGSTOREINFO info
= CryptMemAlloc(sizeof(WINE_MSGSTOREINFO
));
2020 CERT_STORE_PROV_INFO provInfo
= { 0 };
2022 info
->dwOpenFlags
= dwFlags
;
2023 info
->cryptProv
= hCryptProv
;
2024 info
->memStore
= memStore
;
2025 info
->msg
= CryptMsgDuplicate(msg
);
2026 provInfo
.cbSize
= sizeof(provInfo
);
2027 provInfo
.cStoreProvFunc
= sizeof(msgProvFuncs
) /
2028 sizeof(msgProvFuncs
[0]);
2029 provInfo
.rgpvStoreProvFunc
= msgProvFuncs
;
2030 provInfo
.hStoreProv
= info
;
2031 store
= CRYPT_ProvCreateStore(hCryptProv
, dwFlags
, memStore
,
2035 CertCloseStore(memStore
, 0);
2038 CertCloseStore(memStore
, 0);
2040 TRACE("returning %p\n", store
);
2044 static PWINECRYPT_CERTSTORE
CRYPT_PKCSOpenStore(HCRYPTPROV hCryptProv
,
2045 DWORD dwFlags
, const void *pvPara
)
2048 PWINECRYPT_CERTSTORE store
= NULL
;
2049 const CRYPT_DATA_BLOB
*data
= (const CRYPT_DATA_BLOB
*)pvPara
;
2052 TRACE("(%ld, %08x, %p)\n", hCryptProv
, dwFlags
, pvPara
);
2054 msg
= CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING
, 0, CMSG_SIGNED
, 0, NULL
,
2056 ret
= CryptMsgUpdate(msg
, data
->pbData
, data
->cbData
, TRUE
);
2060 msg
= CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING
, 0, 0, 0, NULL
, NULL
);
2061 ret
= CryptMsgUpdate(msg
, data
->pbData
, data
->cbData
, TRUE
);
2064 DWORD type
, size
= sizeof(type
);
2066 /* Only signed messages are allowed, check type */
2067 ret
= CryptMsgGetParam(msg
, CMSG_TYPE_PARAM
, 0, &type
, &size
);
2068 if (ret
&& type
!= CMSG_SIGNED
)
2070 SetLastError(CRYPT_E_INVALID_MSG_TYPE
);
2076 store
= CRYPT_MsgOpenStore(hCryptProv
, dwFlags
, msg
);
2078 TRACE("returning %p\n", store
);
2082 static PWINECRYPT_CERTSTORE
CRYPT_PhysOpenStoreW(HCRYPTPROV hCryptProv
,
2083 DWORD dwFlags
, const void *pvPara
)
2085 if (dwFlags
& CERT_SYSTEM_STORE_RELOCATE_FLAG
)
2086 FIXME("(%ld, %08x, %p): stub\n", hCryptProv
, dwFlags
, pvPara
);
2088 FIXME("(%ld, %08x, %s): stub\n", hCryptProv
, dwFlags
,
2089 debugstr_w((LPCWSTR
)pvPara
));
2093 HCERTSTORE WINAPI
CertOpenStore(LPCSTR lpszStoreProvider
,
2094 DWORD dwMsgAndCertEncodingType
, HCRYPTPROV_LEGACY hCryptProv
, DWORD dwFlags
,
2097 WINECRYPT_CERTSTORE
*hcs
;
2098 StoreOpenFunc openFunc
= NULL
;
2100 TRACE("(%s, %08x, %08lx, %08x, %p)\n", debugstr_a(lpszStoreProvider
),
2101 dwMsgAndCertEncodingType
, hCryptProv
, dwFlags
, pvPara
);
2103 if (!HIWORD(lpszStoreProvider
))
2105 switch (LOWORD(lpszStoreProvider
))
2107 case (int)CERT_STORE_PROV_MSG
:
2108 openFunc
= CRYPT_MsgOpenStore
;
2110 case (int)CERT_STORE_PROV_MEMORY
:
2111 openFunc
= CRYPT_MemOpenStore
;
2113 case (int)CERT_STORE_PROV_FILE
:
2114 openFunc
= CRYPT_FileOpenStore
;
2116 case (int)CERT_STORE_PROV_PKCS7
:
2117 openFunc
= CRYPT_PKCSOpenStore
;
2119 case (int)CERT_STORE_PROV_REG
:
2120 openFunc
= CRYPT_RegOpenStore
;
2122 case (int)CERT_STORE_PROV_FILENAME_A
:
2123 openFunc
= CRYPT_FileNameOpenStoreA
;
2125 case (int)CERT_STORE_PROV_FILENAME_W
:
2126 openFunc
= CRYPT_FileNameOpenStoreW
;
2128 case (int)CERT_STORE_PROV_COLLECTION
:
2129 openFunc
= CRYPT_CollectionOpenStore
;
2131 case (int)CERT_STORE_PROV_SYSTEM_A
:
2132 openFunc
= CRYPT_SysOpenStoreA
;
2134 case (int)CERT_STORE_PROV_SYSTEM_W
:
2135 openFunc
= CRYPT_SysOpenStoreW
;
2137 case (int)CERT_STORE_PROV_SYSTEM_REGISTRY_A
:
2138 openFunc
= CRYPT_SysRegOpenStoreA
;
2140 case (int)CERT_STORE_PROV_SYSTEM_REGISTRY_W
:
2141 openFunc
= CRYPT_SysRegOpenStoreW
;
2143 case (int)CERT_STORE_PROV_PHYSICAL_W
:
2144 openFunc
= CRYPT_PhysOpenStoreW
;
2147 if (LOWORD(lpszStoreProvider
))
2148 FIXME("unimplemented type %d\n", LOWORD(lpszStoreProvider
));
2151 else if (!strcasecmp(lpszStoreProvider
, sz_CERT_STORE_PROV_MEMORY
))
2152 openFunc
= CRYPT_MemOpenStore
;
2153 else if (!strcasecmp(lpszStoreProvider
, sz_CERT_STORE_PROV_FILENAME_W
))
2154 openFunc
= CRYPT_FileOpenStore
;
2155 else if (!strcasecmp(lpszStoreProvider
, sz_CERT_STORE_PROV_SYSTEM
))
2156 openFunc
= CRYPT_SysOpenStoreW
;
2157 else if (!strcasecmp(lpszStoreProvider
, sz_CERT_STORE_PROV_COLLECTION
))
2158 openFunc
= CRYPT_CollectionOpenStore
;
2159 else if (!strcasecmp(lpszStoreProvider
, sz_CERT_STORE_PROV_SYSTEM_REGISTRY
))
2160 openFunc
= CRYPT_SysRegOpenStoreW
;
2163 FIXME("unimplemented type %s\n", lpszStoreProvider
);
2168 hcs
= CRYPT_ProvOpenStore(lpszStoreProvider
, dwMsgAndCertEncodingType
,
2169 hCryptProv
, dwFlags
, pvPara
);
2171 hcs
= openFunc(hCryptProv
, dwFlags
, pvPara
);
2172 return (HCERTSTORE
)hcs
;
2175 HCERTSTORE WINAPI
CertOpenSystemStoreA(HCRYPTPROV_LEGACY hProv
,
2176 LPCSTR szSubSystemProtocol
)
2178 if (!szSubSystemProtocol
)
2180 SetLastError(E_INVALIDARG
);
2183 return CertOpenStore(CERT_STORE_PROV_SYSTEM_A
, 0, hProv
,
2184 CERT_SYSTEM_STORE_CURRENT_USER
, szSubSystemProtocol
);
2187 HCERTSTORE WINAPI
CertOpenSystemStoreW(HCRYPTPROV_LEGACY hProv
,
2188 LPCWSTR szSubSystemProtocol
)
2190 if (!szSubSystemProtocol
)
2192 SetLastError(E_INVALIDARG
);
2195 return CertOpenStore(CERT_STORE_PROV_SYSTEM_W
, 0, hProv
,
2196 CERT_SYSTEM_STORE_CURRENT_USER
, szSubSystemProtocol
);
2199 BOOL WINAPI
CertSaveStore(HCERTSTORE hCertStore
, DWORD dwMsgAndCertEncodingType
,
2200 DWORD dwSaveAs
, DWORD dwSaveTo
, void* pvSaveToPara
, DWORD dwFlags
)
2202 FIXME("(%p,%d,%d,%d,%p,%08x) stub!\n", hCertStore
,
2203 dwMsgAndCertEncodingType
, dwSaveAs
, dwSaveTo
, pvSaveToPara
, dwFlags
);
2207 #define CertContext_CopyProperties(to, from) \
2208 Context_CopyProperties((to), (from), sizeof(CERT_CONTEXT))
2210 BOOL WINAPI
CertAddCertificateContextToStore(HCERTSTORE hCertStore
,
2211 PCCERT_CONTEXT pCertContext
, DWORD dwAddDisposition
,
2212 PCCERT_CONTEXT
*ppStoreContext
)
2214 PWINECRYPT_CERTSTORE store
= (PWINECRYPT_CERTSTORE
)hCertStore
;
2216 PCCERT_CONTEXT toAdd
= NULL
, existing
= NULL
;
2218 TRACE("(%p, %p, %08x, %p)\n", hCertStore
, pCertContext
,
2219 dwAddDisposition
, ppStoreContext
);
2221 /* Weird case to pass a test */
2222 if (dwAddDisposition
== 0)
2224 SetLastError(STATUS_ACCESS_VIOLATION
);
2227 if (dwAddDisposition
!= CERT_STORE_ADD_ALWAYS
)
2230 DWORD size
= sizeof(hashToAdd
);
2232 ret
= CertGetCertificateContextProperty(pCertContext
, CERT_HASH_PROP_ID
,
2236 CRYPT_HASH_BLOB blob
= { sizeof(hashToAdd
), hashToAdd
};
2238 existing
= CertFindCertificateInStore(hCertStore
,
2239 pCertContext
->dwCertEncodingType
, 0, CERT_FIND_SHA1_HASH
, &blob
,
2244 switch (dwAddDisposition
)
2246 case CERT_STORE_ADD_ALWAYS
:
2247 toAdd
= CertDuplicateCertificateContext(pCertContext
);
2249 case CERT_STORE_ADD_NEW
:
2252 TRACE("found matching certificate, not adding\n");
2253 SetLastError(CRYPT_E_EXISTS
);
2257 toAdd
= CertDuplicateCertificateContext(pCertContext
);
2259 case CERT_STORE_ADD_REPLACE_EXISTING
:
2260 toAdd
= CertDuplicateCertificateContext(pCertContext
);
2262 case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
:
2263 toAdd
= CertDuplicateCertificateContext(pCertContext
);
2265 CertContext_CopyProperties(toAdd
, existing
);
2267 case CERT_STORE_ADD_USE_EXISTING
:
2270 CertContext_CopyProperties(existing
, pCertContext
);
2271 *ppStoreContext
= CertDuplicateCertificateContext(existing
);
2274 toAdd
= CertDuplicateCertificateContext(pCertContext
);
2277 FIXME("Unimplemented add disposition %d\n", dwAddDisposition
);
2284 ret
= store
->certs
.addContext(store
, (void *)toAdd
,
2285 (void *)existing
, (const void **)ppStoreContext
);
2286 else if (ppStoreContext
)
2287 *ppStoreContext
= CertDuplicateCertificateContext(toAdd
);
2288 CertFreeCertificateContext(toAdd
);
2290 CertFreeCertificateContext(existing
);
2292 TRACE("returning %d\n", ret
);
2296 PCCERT_CONTEXT WINAPI
CertEnumCertificatesInStore(HCERTSTORE hCertStore
,
2297 PCCERT_CONTEXT pPrev
)
2299 WINECRYPT_CERTSTORE
*hcs
= (WINECRYPT_CERTSTORE
*)hCertStore
;
2302 TRACE("(%p, %p)\n", hCertStore
, pPrev
);
2305 else if (hcs
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2308 ret
= (PCCERT_CONTEXT
)hcs
->certs
.enumContext(hcs
, (void *)pPrev
);
2312 BOOL WINAPI
CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext
)
2316 TRACE("(%p)\n", pCertContext
);
2320 else if (!pCertContext
->hCertStore
)
2323 CertFreeCertificateContext(pCertContext
);
2327 PWINECRYPT_CERTSTORE hcs
=
2328 (PWINECRYPT_CERTSTORE
)pCertContext
->hCertStore
;
2330 if (hcs
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2333 ret
= hcs
->certs
.deleteContext(hcs
, (void *)pCertContext
);
2334 CertFreeCertificateContext(pCertContext
);
2339 #define CrlContext_CopyProperties(to, from) \
2340 Context_CopyProperties((to), (from), sizeof(CRL_CONTEXT))
2342 BOOL WINAPI
CertAddCRLContextToStore(HCERTSTORE hCertStore
,
2343 PCCRL_CONTEXT pCrlContext
, DWORD dwAddDisposition
,
2344 PCCRL_CONTEXT
* ppStoreContext
)
2346 PWINECRYPT_CERTSTORE store
= (PWINECRYPT_CERTSTORE
)hCertStore
;
2348 PCCRL_CONTEXT toAdd
= NULL
, existing
= NULL
;
2350 TRACE("(%p, %p, %08x, %p)\n", hCertStore
, pCrlContext
,
2351 dwAddDisposition
, ppStoreContext
);
2353 /* Weird case to pass a test */
2354 if (dwAddDisposition
== 0)
2356 SetLastError(STATUS_ACCESS_VIOLATION
);
2359 if (dwAddDisposition
!= CERT_STORE_ADD_ALWAYS
)
2361 existing
= CertFindCRLInStore(hCertStore
, 0, 0, CRL_FIND_EXISTING
,
2365 switch (dwAddDisposition
)
2367 case CERT_STORE_ADD_ALWAYS
:
2368 toAdd
= CertDuplicateCRLContext(pCrlContext
);
2370 case CERT_STORE_ADD_NEW
:
2373 TRACE("found matching CRL, not adding\n");
2374 SetLastError(CRYPT_E_EXISTS
);
2378 toAdd
= CertDuplicateCRLContext(pCrlContext
);
2380 case CERT_STORE_ADD_NEWER
:
2383 LONG newer
= CompareFileTime(&existing
->pCrlInfo
->ThisUpdate
,
2384 &pCrlContext
->pCrlInfo
->ThisUpdate
);
2387 toAdd
= CertDuplicateCRLContext(pCrlContext
);
2390 TRACE("existing CRL is newer, not adding\n");
2391 SetLastError(CRYPT_E_EXISTS
);
2396 toAdd
= CertDuplicateCRLContext(pCrlContext
);
2398 case CERT_STORE_ADD_REPLACE_EXISTING
:
2399 toAdd
= CertDuplicateCRLContext(pCrlContext
);
2401 case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
:
2402 toAdd
= CertDuplicateCRLContext(pCrlContext
);
2404 CrlContext_CopyProperties(toAdd
, existing
);
2406 case CERT_STORE_ADD_USE_EXISTING
:
2408 CrlContext_CopyProperties(existing
, pCrlContext
);
2411 FIXME("Unimplemented add disposition %d\n", dwAddDisposition
);
2418 ret
= store
->crls
.addContext(store
, (void *)toAdd
,
2419 (void *)existing
, (const void **)ppStoreContext
);
2420 else if (ppStoreContext
)
2421 *ppStoreContext
= CertDuplicateCRLContext(toAdd
);
2422 CertFreeCRLContext(toAdd
);
2424 CertFreeCRLContext(existing
);
2426 TRACE("returning %d\n", ret
);
2430 BOOL WINAPI
CertDeleteCRLFromStore(PCCRL_CONTEXT pCrlContext
)
2434 TRACE("(%p)\n", pCrlContext
);
2438 else if (!pCrlContext
->hCertStore
)
2441 CertFreeCRLContext(pCrlContext
);
2445 PWINECRYPT_CERTSTORE hcs
=
2446 (PWINECRYPT_CERTSTORE
)pCrlContext
->hCertStore
;
2448 if (hcs
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2451 ret
= hcs
->crls
.deleteContext(hcs
, (void *)pCrlContext
);
2452 CertFreeCRLContext(pCrlContext
);
2457 PCCRL_CONTEXT WINAPI
CertEnumCRLsInStore(HCERTSTORE hCertStore
,
2458 PCCRL_CONTEXT pPrev
)
2460 WINECRYPT_CERTSTORE
*hcs
= (WINECRYPT_CERTSTORE
*)hCertStore
;
2463 TRACE("(%p, %p)\n", hCertStore
, pPrev
);
2466 else if (hcs
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2469 ret
= (PCCRL_CONTEXT
)hcs
->crls
.enumContext(hcs
, (void *)pPrev
);
2473 PCCTL_CONTEXT WINAPI
CertCreateCTLContext(DWORD dwCertEncodingType
,
2474 const BYTE
* pbCtlEncoded
, DWORD cbCtlEncoded
)
2476 FIXME("(%08x, %p, %08x): stub\n", dwCertEncodingType
, pbCtlEncoded
,
2481 BOOL WINAPI
CertAddEncodedCTLToStore(HCERTSTORE hCertStore
,
2482 DWORD dwMsgAndCertEncodingType
, const BYTE
*pbCtlEncoded
, DWORD cbCtlEncoded
,
2483 DWORD dwAddDisposition
, PCCTL_CONTEXT
*ppCtlContext
)
2485 FIXME("(%p, %08x, %p, %d, %08x, %p): stub\n", hCertStore
,
2486 dwMsgAndCertEncodingType
, pbCtlEncoded
, cbCtlEncoded
, dwAddDisposition
,
2491 BOOL WINAPI
CertAddCTLContextToStore(HCERTSTORE hCertStore
,
2492 PCCTL_CONTEXT pCtlContext
, DWORD dwAddDisposition
,
2493 PCCTL_CONTEXT
* ppStoreContext
)
2495 FIXME("(%p, %p, %08x, %p): stub\n", hCertStore
, pCtlContext
,
2496 dwAddDisposition
, ppStoreContext
);
2500 PCCTL_CONTEXT WINAPI
CertDuplicateCTLContext(PCCTL_CONTEXT pCtlContext
)
2502 FIXME("(%p): stub\n", pCtlContext
);
2506 BOOL WINAPI
CertFreeCTLContext(PCCTL_CONTEXT pCtlContext
)
2508 FIXME("(%p): stub\n", pCtlContext
);
2512 BOOL WINAPI
CertDeleteCTLFromStore(PCCTL_CONTEXT pCtlContext
)
2514 FIXME("(%p): stub\n", pCtlContext
);
2518 PCCTL_CONTEXT WINAPI
CertEnumCTLsInStore(HCERTSTORE hCertStore
,
2519 PCCTL_CONTEXT pPrev
)
2521 FIXME("(%p, %p): stub\n", hCertStore
, pPrev
);
2525 HCERTSTORE WINAPI
CertDuplicateStore(HCERTSTORE hCertStore
)
2527 WINECRYPT_CERTSTORE
*hcs
= (WINECRYPT_CERTSTORE
*)hCertStore
;
2529 TRACE("(%p)\n", hCertStore
);
2531 if (hcs
&& hcs
->dwMagic
== WINE_CRYPTCERTSTORE_MAGIC
)
2532 InterlockedIncrement(&hcs
->ref
);
2536 BOOL WINAPI
CertCloseStore(HCERTSTORE hCertStore
, DWORD dwFlags
)
2538 WINECRYPT_CERTSTORE
*hcs
= (WINECRYPT_CERTSTORE
*) hCertStore
;
2540 TRACE("(%p, %08x)\n", hCertStore
, dwFlags
);
2545 if ( hcs
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2548 if (InterlockedDecrement(&hcs
->ref
) == 0)
2550 TRACE("%p's ref count is 0, freeing\n", hcs
);
2552 if (!(hcs
->dwOpenFlags
& CERT_STORE_NO_CRYPT_RELEASE_FLAG
))
2553 CryptReleaseContext(hcs
->cryptProv
, 0);
2554 hcs
->closeStore(hcs
, dwFlags
);
2557 TRACE("%p's ref count is %d\n", hcs
, hcs
->ref
);
2561 BOOL WINAPI
CertControlStore(HCERTSTORE hCertStore
, DWORD dwFlags
,
2562 DWORD dwCtrlType
, void const *pvCtrlPara
)
2564 WINECRYPT_CERTSTORE
*hcs
= (WINECRYPT_CERTSTORE
*)hCertStore
;
2567 TRACE("(%p, %08x, %d, %p)\n", hCertStore
, dwFlags
, dwCtrlType
,
2572 else if (hcs
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2577 ret
= hcs
->control(hCertStore
, dwFlags
, dwCtrlType
, pvCtrlPara
);
2584 BOOL WINAPI
CertGetStoreProperty(HCERTSTORE hCertStore
, DWORD dwPropId
,
2585 void *pvData
, DWORD
*pcbData
)
2587 PWINECRYPT_CERTSTORE store
= (PWINECRYPT_CERTSTORE
)hCertStore
;
2590 TRACE("(%p, %d, %p, %p)\n", hCertStore
, dwPropId
, pvData
, pcbData
);
2594 case CERT_ACCESS_STATE_PROP_ID
:
2597 *pcbData
= sizeof(DWORD
);
2600 else if (*pcbData
< sizeof(DWORD
))
2602 SetLastError(ERROR_MORE_DATA
);
2603 *pcbData
= sizeof(DWORD
);
2609 if (store
->type
!= StoreTypeMem
&&
2610 !(store
->dwOpenFlags
& CERT_STORE_READONLY_FLAG
))
2611 state
|= CERT_ACCESS_STATE_WRITE_PERSIST_FLAG
;
2612 *(DWORD
*)pvData
= state
;
2617 if (store
->properties
)
2619 CRYPT_DATA_BLOB blob
;
2621 ret
= ContextPropertyList_FindProperty(store
->properties
, dwPropId
,
2626 *pcbData
= blob
.cbData
;
2627 else if (*pcbData
< blob
.cbData
)
2629 SetLastError(ERROR_MORE_DATA
);
2630 *pcbData
= blob
.cbData
;
2635 memcpy(pvData
, blob
.pbData
, blob
.cbData
);
2636 *pcbData
= blob
.cbData
;
2640 SetLastError(CRYPT_E_NOT_FOUND
);
2643 SetLastError(CRYPT_E_NOT_FOUND
);
2648 BOOL WINAPI
CertSetStoreProperty(HCERTSTORE hCertStore
, DWORD dwPropId
,
2649 DWORD dwFlags
, const void *pvData
)
2651 PWINECRYPT_CERTSTORE store
= (PWINECRYPT_CERTSTORE
)hCertStore
;
2654 TRACE("(%p, %d, %08x, %p)\n", hCertStore
, dwPropId
, dwFlags
, pvData
);
2656 if (!store
->properties
)
2657 store
->properties
= ContextPropertyList_Create();
2660 case CERT_ACCESS_STATE_PROP_ID
:
2661 SetLastError(E_INVALIDARG
);
2666 const CRYPT_DATA_BLOB
*blob
= (const CRYPT_DATA_BLOB
*)pvData
;
2668 ret
= ContextPropertyList_SetProperty(store
->properties
, dwPropId
,
2669 blob
->pbData
, blob
->cbData
);
2673 ContextPropertyList_RemoveProperty(store
->properties
, dwPropId
);
2680 DWORD WINAPI
CertEnumCTLContextProperties(PCCTL_CONTEXT pCTLContext
,
2683 FIXME("(%p, %d): stub\n", pCTLContext
, dwPropId
);
2687 BOOL WINAPI
CertGetCTLContextProperty(PCCTL_CONTEXT pCTLContext
,
2688 DWORD dwPropId
, void *pvData
, DWORD
*pcbData
)
2690 FIXME("(%p, %d, %p, %p): stub\n", pCTLContext
, dwPropId
, pvData
, pcbData
);
2694 BOOL WINAPI
CertSetCTLContextProperty(PCCTL_CONTEXT pCTLContext
,
2695 DWORD dwPropId
, DWORD dwFlags
, const void *pvData
)
2697 FIXME("(%p, %d, %08x, %p): stub\n", pCTLContext
, dwPropId
, dwFlags
,
2702 BOOL WINAPI
CertAddStoreToCollection(HCERTSTORE hCollectionStore
,
2703 HCERTSTORE hSiblingStore
, DWORD dwUpdateFlags
, DWORD dwPriority
)
2705 PWINE_COLLECTIONSTORE collection
= (PWINE_COLLECTIONSTORE
)hCollectionStore
;
2706 WINECRYPT_CERTSTORE
*sibling
= (WINECRYPT_CERTSTORE
*)hSiblingStore
;
2707 PWINE_STORE_LIST_ENTRY entry
;
2710 TRACE("(%p, %p, %08x, %d)\n", hCollectionStore
, hSiblingStore
,
2711 dwUpdateFlags
, dwPriority
);
2713 if (!collection
|| !sibling
)
2715 if (collection
->hdr
.dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2717 SetLastError(E_INVALIDARG
);
2720 if (collection
->hdr
.type
!= StoreTypeCollection
)
2722 SetLastError(E_INVALIDARG
);
2725 if (sibling
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2727 SetLastError(E_INVALIDARG
);
2731 entry
= CryptMemAlloc(sizeof(WINE_STORE_LIST_ENTRY
));
2734 InterlockedIncrement(&sibling
->ref
);
2735 TRACE("sibling %p's ref count is %d\n", sibling
, sibling
->ref
);
2736 entry
->store
= sibling
;
2737 entry
->dwUpdateFlags
= dwUpdateFlags
;
2738 entry
->dwPriority
= dwPriority
;
2739 list_init(&entry
->entry
);
2740 TRACE("%p: adding %p, priority %d\n", collection
, entry
, dwPriority
);
2741 EnterCriticalSection(&collection
->cs
);
2744 PWINE_STORE_LIST_ENTRY cursor
;
2747 LIST_FOR_EACH_ENTRY(cursor
, &collection
->stores
,
2748 WINE_STORE_LIST_ENTRY
, entry
)
2750 if (cursor
->dwPriority
< dwPriority
)
2752 list_add_before(&cursor
->entry
, &entry
->entry
);
2758 list_add_tail(&collection
->stores
, &entry
->entry
);
2761 list_add_tail(&collection
->stores
, &entry
->entry
);
2762 LeaveCriticalSection(&collection
->cs
);
2770 void WINAPI
CertRemoveStoreFromCollection(HCERTSTORE hCollectionStore
,
2771 HCERTSTORE hSiblingStore
)
2773 PWINE_COLLECTIONSTORE collection
= (PWINE_COLLECTIONSTORE
)hCollectionStore
;
2774 WINECRYPT_CERTSTORE
*sibling
= (WINECRYPT_CERTSTORE
*)hSiblingStore
;
2775 PWINE_STORE_LIST_ENTRY store
, next
;
2777 TRACE("(%p, %p)\n", hCollectionStore
, hSiblingStore
);
2779 if (!collection
|| !sibling
)
2781 if (collection
->hdr
.dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2783 SetLastError(E_INVALIDARG
);
2786 if (collection
->hdr
.type
!= StoreTypeCollection
)
2788 if (sibling
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
2790 SetLastError(E_INVALIDARG
);
2793 EnterCriticalSection(&collection
->cs
);
2794 LIST_FOR_EACH_ENTRY_SAFE(store
, next
, &collection
->stores
,
2795 WINE_STORE_LIST_ENTRY
, entry
)
2797 if (store
->store
== sibling
)
2799 list_remove(&store
->entry
);
2800 CertCloseStore(store
->store
, 0);
2801 CryptMemFree(store
);
2805 LeaveCriticalSection(&collection
->cs
);
2808 static LONG
CRYPT_OpenParentStore(DWORD dwFlags
,
2809 void *pvSystemStoreLocationPara
, HKEY
*key
)
2814 TRACE("(%08x, %p)\n", dwFlags
, pvSystemStoreLocationPara
);
2816 switch (dwFlags
& CERT_SYSTEM_STORE_LOCATION_MASK
)
2818 case CERT_SYSTEM_STORE_LOCAL_MACHINE
:
2819 root
= HKEY_LOCAL_MACHINE
;
2820 base
= CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH
;
2822 case CERT_SYSTEM_STORE_CURRENT_USER
:
2823 root
= HKEY_CURRENT_USER
;
2824 base
= CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH
;
2826 case CERT_SYSTEM_STORE_CURRENT_SERVICE
:
2827 /* hklm\Software\Microsoft\Cryptography\Services\servicename\
2828 * SystemCertificates
2830 FIXME("CERT_SYSTEM_STORE_CURRENT_SERVICE\n");
2831 return ERROR_FILE_NOT_FOUND
;
2832 case CERT_SYSTEM_STORE_SERVICES
:
2833 /* hklm\Software\Microsoft\Cryptography\Services\servicename\
2834 * SystemCertificates
2836 FIXME("CERT_SYSTEM_STORE_SERVICES\n");
2837 return ERROR_FILE_NOT_FOUND
;
2838 case CERT_SYSTEM_STORE_USERS
:
2839 /* hku\user sid\Software\Microsoft\SystemCertificates */
2840 FIXME("CERT_SYSTEM_STORE_USERS\n");
2841 return ERROR_FILE_NOT_FOUND
;
2842 case CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY
:
2843 root
= HKEY_CURRENT_USER
;
2844 base
= CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH
;
2846 case CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
:
2847 root
= HKEY_LOCAL_MACHINE
;
2848 base
= CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH
;
2850 case CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
:
2851 /* hklm\Software\Microsoft\EnterpriseCertificates */
2852 FIXME("CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE\n");
2853 return ERROR_FILE_NOT_FOUND
;
2855 return ERROR_FILE_NOT_FOUND
;
2858 return RegOpenKeyExW(root
, base
, 0, KEY_READ
, key
);
2861 BOOL WINAPI
CertEnumSystemStore(DWORD dwFlags
, void *pvSystemStoreLocationPara
,
2862 void *pvArg
, PFN_CERT_ENUM_SYSTEM_STORE pfnEnum
)
2868 TRACE("(%08x, %p, %p, %p)\n", dwFlags
, pvSystemStoreLocationPara
, pvArg
,
2871 rc
= CRYPT_OpenParentStore(dwFlags
, pvArg
, &key
);
2875 CERT_SYSTEM_STORE_INFO info
= { sizeof(info
) };
2879 WCHAR name
[MAX_PATH
];
2880 DWORD size
= sizeof(name
) / sizeof(name
[0]);
2882 rc
= RegEnumKeyExW(key
, index
++, name
, &size
, NULL
, NULL
, NULL
,
2885 ret
= pfnEnum(name
, 0, &info
, NULL
, pvArg
);
2886 } while (ret
&& !rc
);
2887 if (ret
&& rc
!= ERROR_NO_MORE_ITEMS
)