ReactOS 0.4.15-dev-7842-g558ab78
provstore.c
Go to the documentation of this file.
1/*
2 * Copyright 2004-2007 Juan Lang
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include <stdarg.h>
20#include <assert.h>
21
22#include "windef.h"
23#include "winbase.h"
24#include "wincrypt.h"
25#include "wine/debug.h"
26#include "crypt32_private.h"
27
29
30typedef struct _WINE_PROVIDERSTORE
31{
45
47{
49 TRACE("ref = %d\n", ref);
50}
51
53{
55 LONG ref;
56
57 if(flags)
58 FIXME("Unimplemented flags %x\n", flags);
59
61 TRACE("(%p) ref=%d\n", store, ref);
62
63 if(ref)
64 return ERROR_SUCCESS;
65
66 if (store->provCloseStore)
67 store->provCloseStore(store->hStoreProv, flags);
69 store->memStore->vtbl->release(store->memStore, flags);
70 CRYPT_FreeStore(&store->hdr);
71 return ERROR_SUCCESS;
72}
73
75{
76 /* As long as we don't have contexts properly stored (and hack around hCertStore
77 in add* and enum* functions), this function should never be called. */
78 assert(0);
79}
80
82 context_t *toReplace, context_t **ppStoreContext, BOOL use_link)
83{
85 BOOL ret;
86
87 TRACE("(%p, %p, %p, %p)\n", store, cert, toReplace, ppStoreContext);
88
89 if (toReplace)
90 ret = ps->memStore->vtbl->certs.addContext(ps->memStore, cert, toReplace,
92 else
93 {
94 ret = TRUE;
95 if (ps->provWriteCert)
97 if (ret)
100 }
101 /* dirty trick: replace the returned context's hCertStore with
102 * store.
103 */
104 if (ret && ppStoreContext)
105 (*(cert_t**)ppStoreContext)->ctx.hCertStore = store;
106 return ret;
107}
108
110{
112 cert_t *ret;
113
114 ret = (cert_t*)ps->memStore->vtbl->certs.enumContext(ps->memStore, prev);
115 if (!ret)
116 return NULL;
117
118 /* same dirty trick: replace the returned context's hCertStore with
119 * store.
120 */
121 ret->ctx.hCertStore = store;
122 return &ret->base;
123}
124
126{
128 BOOL ret = TRUE;
129
130 TRACE("(%p, %p)\n", store, context);
131
132 if (ps->provDeleteCert)
134 if (ret)
136 return ret;
137}
138
140 context_t *toReplace, context_t **ppStoreContext, BOOL use_link)
141{
143 BOOL ret;
144
145 TRACE("(%p, %p, %p, %p)\n", store, crl, toReplace, ppStoreContext);
146
147 if (toReplace)
148 ret = ps->memStore->vtbl->crls.addContext(ps->memStore, crl, toReplace,
150 else
151 {
153 {
155 ret = FALSE;
156 }
157 else
158 {
159 ret = TRUE;
160 if (ps->provWriteCrl)
163 if (ret)
166 }
167 }
168 /* dirty trick: replace the returned context's hCertStore with
169 * store.
170 */
171 if (ret && ppStoreContext)
172 (*(crl_t**)ppStoreContext)->ctx.hCertStore = store;
173 return ret;
174}
175
177{
179 crl_t *ret;
180
181 ret = (crl_t*)ps->memStore->vtbl->crls.enumContext(ps->memStore, prev);
182 if (!ret)
183 return NULL;
184
185 /* same dirty trick: replace the returned context's hCertStore with
186 * store.
187 */
188 ret->ctx.hCertStore = store;
189 return &ret->base;
190}
191
193{
195 BOOL ret = TRUE;
196
197 TRACE("(%p, %p)\n", store, crl);
198
199 if (ps->provDeleteCrl)
201 if (ret)
202 ret = ps->memStore->vtbl->crls.delete(ps->memStore, crl);
203 return ret;
204}
205
207 context_t *toReplace, context_t **ppStoreContext, BOOL use_link)
208{
210 BOOL ret;
211
212 TRACE("(%p, %p, %p, %p)\n", store, ctl, toReplace, ppStoreContext);
213
214 if (toReplace)
215 ret = ps->memStore->vtbl->ctls.addContext(ps->memStore, ctl, toReplace,
217 else
218 {
220 {
222 ret = FALSE;
223 }
224 else
225 {
226 ret = TRUE;
227 if (ps->provWriteCtl)
228 ret = ps->provWriteCtl(ps->hStoreProv, context_ptr(ctl),
230 if (ret)
231 ret = ps->memStore->vtbl->ctls.addContext(ps->memStore, ctl, NULL,
233 }
234 }
235 /* dirty trick: replace the returned context's hCertStore with
236 * store.
237 */
238 if (ret && ppStoreContext)
239 (*(ctl_t**)ppStoreContext)->ctx.hCertStore = store;
240 return ret;
241}
242
244{
246 ctl_t *ret;
247
248 ret = (ctl_t*)ps->memStore->vtbl->ctls.enumContext(ps->memStore, prev);
249 if (!ret)
250 return NULL;
251
252 /* same dirty trick: replace the returned context's hCertStore with
253 * store.
254 */
255 ret->ctx.hCertStore = store;
256 return &ret->base;
257}
258
260{
262 BOOL ret = TRUE;
263
264 TRACE("(%p, %p)\n", store, ctl);
265
266 if (ps->provDeleteCtl)
267 ret = ps->provDeleteCtl(ps->hStoreProv, context_ptr(ctl), 0);
268 if (ret)
269 ret = ps->memStore->vtbl->ctls.delete(ps->memStore, ctl);
270 return ret;
271}
272
273static BOOL ProvStore_control(WINECRYPT_CERTSTORE *cert_store, DWORD dwFlags, DWORD dwCtrlType, void const *pvCtrlPara)
274{
276 BOOL ret = TRUE;
277
278 TRACE("(%p, %08x, %d, %p)\n", store, dwFlags, dwCtrlType,
279 pvCtrlPara);
280
281 if (store->provControl)
282 ret = store->provControl(store->hStoreProv, dwFlags, dwCtrlType,
283 pvCtrlPara);
284 return ret;
285}
286
292 {
296 }, {
300 }, {
304 }
305};
306
308 WINECRYPT_CERTSTORE *memStore, const CERT_STORE_PROV_INFO *pProvInfo)
309{
311
312 if (ret)
313 {
315 ret->dwStoreProvFlags = pProvInfo->dwStoreProvFlags;
316 if (ret->dwStoreProvFlags & CERT_STORE_PROV_EXTERNAL_FLAG)
317 {
318 CertCloseStore(memStore, 0);
319 ret->memStore = NULL;
320 }
321 else
322 ret->memStore = memStore;
323 ret->hStoreProv = pProvInfo->hStoreProv;
325 ret->provCloseStore =
327 else
328 ret->provCloseStore = NULL;
329 if (pProvInfo->cStoreProvFunc >
331 ret->provWriteCert = pProvInfo->rgpvStoreProvFunc[
333 else
334 ret->provWriteCert = NULL;
335 if (pProvInfo->cStoreProvFunc >
337 ret->provDeleteCert = pProvInfo->rgpvStoreProvFunc[
339 else
340 ret->provDeleteCert = NULL;
341 if (pProvInfo->cStoreProvFunc >
343 ret->provWriteCrl = pProvInfo->rgpvStoreProvFunc[
345 else
346 ret->provWriteCrl = NULL;
347 if (pProvInfo->cStoreProvFunc >
349 ret->provDeleteCrl = pProvInfo->rgpvStoreProvFunc[
351 else
352 ret->provDeleteCrl = NULL;
353 if (pProvInfo->cStoreProvFunc >
355 ret->provWriteCtl = pProvInfo->rgpvStoreProvFunc[
357 else
358 ret->provWriteCtl = NULL;
359 if (pProvInfo->cStoreProvFunc >
361 ret->provDeleteCtl = pProvInfo->rgpvStoreProvFunc[
363 else
364 ret->provDeleteCtl = NULL;
365 if (pProvInfo->cStoreProvFunc >
367 ret->provControl = pProvInfo->rgpvStoreProvFunc[
369 else
370 ret->provControl = NULL;
371 }
372 return (WINECRYPT_CERTSTORE*)ret;
373}
374
376 DWORD dwEncodingType, HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara)
377{
378 static HCRYPTOIDFUNCSET set = NULL;
380 HCRYPTOIDFUNCADDR hFunc;
382
383 if (!set)
385 CryptGetOIDFunctionAddress(set, dwEncodingType, lpszStoreProvider, 0,
386 (void **)&provOpenFunc, &hFunc);
387 if (provOpenFunc)
388 {
389 CERT_STORE_PROV_INFO provInfo = { 0 };
390
391 provInfo.cbSize = sizeof(provInfo);
393 provOpenFunc(lpszStoreProvider, dwEncodingType, hCryptProv,
394 dwFlags, pvPara, NULL, &provInfo);
395 else
396 {
397 HCERTSTORE memStore;
398
399 memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
401 if (memStore)
402 {
403 if (provOpenFunc(lpszStoreProvider, dwEncodingType, hCryptProv,
404 dwFlags, pvPara, memStore, &provInfo))
405 ret = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo);
406 else
407 CertCloseStore(memStore, 0);
408 }
409 }
411 }
412 else
414 return ret;
415}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: debug.h:111
Definition: _set.h:50
static void * context_ptr(context_t *context)
void CRYPT_FreeStore(WINECRYPT_CERTSTORE *store) DECLSPEC_HIDDEN
Definition: store.c:101
@ StoreTypeProvider
void CRYPT_InitStore(WINECRYPT_CERTSTORE *store, DWORD dwFlags, CertStoreType type, const store_vtbl_t *) DECLSPEC_HIDDEN
Definition: store.c:91
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:131
HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName, DWORD dwFlags)
Definition: oid.c:114
BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
Definition: oid.c:387
BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr, DWORD dwFlags)
Definition: oid.c:468
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static const BYTE crl[]
Definition: message.c:864
static BYTE cert[]
Definition: msg.c:1437
DWORD cert_store
Definition: store.c:344
long LONG
Definition: pedump.c:60
WINECRYPT_CERTSTORE * CRYPT_ProvOpenStore(LPCSTR lpszStoreProvider, DWORD dwEncodingType, HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: provstore.c:375
WINECRYPT_CERTSTORE * CRYPT_ProvCreateStore(DWORD dwFlags, WINECRYPT_CERTSTORE *memStore, const CERT_STORE_PROV_INFO *pProvInfo)
Definition: provstore.c:307
static BOOL ProvStore_addCRL(WINECRYPT_CERTSTORE *store, context_t *crl, context_t *toReplace, context_t **ppStoreContext, BOOL use_link)
Definition: provstore.c:139
static BOOL ProvStore_deleteCert(WINECRYPT_CERTSTORE *store, context_t *context)
Definition: provstore.c:125
static void ProvStore_addref(WINECRYPT_CERTSTORE *store)
Definition: provstore.c:46
static context_t * ProvStore_enumCert(WINECRYPT_CERTSTORE *store, context_t *prev)
Definition: provstore.c:109
static BOOL ProvStore_deleteCRL(WINECRYPT_CERTSTORE *store, context_t *crl)
Definition: provstore.c:192
static BOOL ProvStore_deleteCTL(WINECRYPT_CERTSTORE *store, context_t *ctl)
Definition: provstore.c:259
static BOOL ProvStore_addCTL(WINECRYPT_CERTSTORE *store, context_t *ctl, context_t *toReplace, context_t **ppStoreContext, BOOL use_link)
Definition: provstore.c:206
static BOOL ProvStore_addCert(WINECRYPT_CERTSTORE *store, context_t *cert, context_t *toReplace, context_t **ppStoreContext, BOOL use_link)
Definition: provstore.c:81
static context_t * ProvStore_enumCTL(WINECRYPT_CERTSTORE *store, context_t *prev)
Definition: provstore.c:243
static BOOL ProvStore_control(WINECRYPT_CERTSTORE *cert_store, DWORD dwFlags, DWORD dwCtrlType, void const *pvCtrlPara)
Definition: provstore.c:273
static const store_vtbl_t ProvStoreVtbl
Definition: provstore.c:287
static context_t * ProvStore_enumCRL(WINECRYPT_CERTSTORE *store, context_t *prev)
Definition: provstore.c:176
static DWORD ProvStore_release(WINECRYPT_CERTSTORE *cert_store, DWORD flags)
Definition: provstore.c:52
struct _WINE_PROVIDERSTORE WINE_PROVIDERSTORE
static void ProvStore_releaseContext(WINECRYPT_CERTSTORE *store, context_t *context)
Definition: provstore.c:74
#define TRACE(s)
Definition: solgame.cpp:4
const store_vtbl_t * vtbl
void ** rgpvStoreProvFunc
Definition: wincrypt.h:1149
HCERTSTOREPROV hStoreProv
Definition: wincrypt.h:1150
BOOL(* delete)(struct WINE_CRYPTCERTSTORE *, context_t *)
context_t *(* enumContext)(struct WINE_CRYPTCERTSTORE *store, context_t *prev)
BOOL(* addContext)(struct WINE_CRYPTCERTSTORE *, context_t *, context_t *, context_t **, BOOL)
WINECRYPT_CERTSTORE hdr
Definition: provstore.c:32
PFN_CERT_STORE_PROV_CLOSE provCloseStore
Definition: provstore.c:36
PFN_CERT_STORE_PROV_WRITE_CRL provWriteCrl
Definition: provstore.c:39
PFN_CERT_STORE_PROV_DELETE_CTL provDeleteCtl
Definition: provstore.c:42
HCERTSTOREPROV hStoreProv
Definition: provstore.c:35
WINECRYPT_CERTSTORE * memStore
Definition: provstore.c:34
PFN_CERT_STORE_PROV_WRITE_CERT provWriteCert
Definition: provstore.c:37
PFN_CERT_STORE_PROV_WRITE_CTL provWriteCtl
Definition: provstore.c:41
PFN_CERT_STORE_PROV_DELETE_CRL provDeleteCrl
Definition: provstore.c:40
PFN_CERT_STORE_PROV_DELETE_CERT provDeleteCert
Definition: provstore.c:38
PFN_CERT_STORE_PROV_CONTROL provControl
Definition: provstore.c:43
DWORD dwStoreProvFlags
Definition: provstore.c:33
Definition: http.c:7252
Definition: send.c:48
DWORD(* release)(struct WINE_CRYPTCERTSTORE *, DWORD)
CONTEXT_FUNCS ctls
CONTEXT_FUNCS crls
CONTEXT_FUNCS certs
int ret
BOOL(WINAPI * PFN_CERT_STORE_PROV_WRITE_CTL)(_Inout_ HCERTSTOREPROV hStoreProv, _In_ PCCTL_CONTEXT pCtlContext, _In_ DWORD dwFlags)
Definition: wincrypt.h:1238
#define CERT_STORE_PROV_WRITE_CTL_FUNC
Definition: wincrypt.h:2563
void(WINAPI * PFN_CERT_STORE_PROV_CLOSE)(_Inout_opt_ HCERTSTOREPROV hStoreProv, _In_ DWORD dwFlags)
Definition: wincrypt.h:1166
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define CERT_STORE_PROV_CONTROL_FUNC
Definition: wincrypt.h:2566
BOOL(WINAPI * PFN_CERT_STORE_PROV_WRITE_CRL)(_Inout_ HCERTSTOREPROV hStoreProv, _In_ PCCRL_CONTEXT pCrlContext, _In_ DWORD dwFlags)
Definition: wincrypt.h:1209
BOOL(WINAPI * PFN_CERT_STORE_PROV_DELETE_CTL)(_Inout_ HCERTSTOREPROV hStoreProv, _In_ PCCTL_CONTEXT pCtlContext, _In_ DWORD dwFlags)
Definition: wincrypt.h:1244
#define CERT_STORE_PROV_EXTERNAL_FLAG
Definition: wincrypt.h:2546
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
_In_ DWORD dwEncodingType
Definition: wincrypt.h:4625
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define CERT_STORE_PROV_CLOSE_FUNC
Definition: wincrypt.h:2553
#define CERT_STORE_PROV_DELETE_CTL_FUNC
Definition: wincrypt.h:2564
BOOL(WINAPI * PFN_CERT_STORE_PROV_DELETE_CERT)(_Inout_ HCERTSTOREPROV hStoreProv, _In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwFlags)
Definition: wincrypt.h:1186
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
_In_ void * pvPara
Definition: wincrypt.h:6077
BOOL(WINAPI * PFN_CERT_DLL_OPEN_STORE_PROV_FUNC)(_In_ LPCSTR lpszStoreProvider, _In_ DWORD dwEncodingType, _In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_ DWORD dwFlags, _In_opt_ const void *pvPara, _In_ HCERTSTORE hCertStore, _Inout_ PCERT_STORE_PROV_INFO pStoreProvInfo)
Definition: wincrypt.h:1156
#define CRYPT_OID_OPEN_STORE_PROV_FUNC
Definition: wincrypt.h:2491
_In_ PCCERT_CONTEXT _In_ DWORD _Outptr_opt_ PCCERT_CONTEXT * ppStoreContext
Definition: wincrypt.h:4985
#define CERT_STORE_PROV_DELETE_CRL_FUNC
Definition: wincrypt.h:2560
#define CERT_STORE_PROV_WRITE_ADD_FLAG
Definition: wincrypt.h:2971
#define CERT_STORE_PROV_DELETE_CERT_FUNC
Definition: wincrypt.h:2556
BOOL(WINAPI * PFN_CERT_STORE_PROV_DELETE_CRL)(_Inout_ HCERTSTOREPROV hStoreProv, _In_ PCCRL_CONTEXT pCrlContext, _In_ DWORD dwFlags)
Definition: wincrypt.h:1215
BOOL(WINAPI * PFN_CERT_STORE_PROV_WRITE_CERT)(_Inout_ HCERTSTOREPROV hStoreProv, _In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwFlags)
Definition: wincrypt.h:1180
#define CERT_STORE_DELETE_FLAG
Definition: wincrypt.h:2455
BOOL(WINAPI * PFN_CERT_STORE_PROV_CONTROL)(_Inout_ HCERTSTOREPROV hStoreProv, _In_ DWORD dwFlags, _In_ DWORD dwCtrlType, _In_opt_ void const *pvCtrlPara)
Definition: wincrypt.h:1258
#define CERT_STORE_PROV_WRITE_CERT_FUNC
Definition: wincrypt.h:2555
#define CERT_STORE_READONLY_FLAG
Definition: wincrypt.h:2466
#define CERT_STORE_PROV_WRITE_CRL_FUNC
Definition: wincrypt.h:2559
const char * LPCSTR
Definition: xmlstorage.h:183