ReactOS 0.4.17-dev-444-g71ee754
filestore.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wincrypt.h"
#include "winnls.h"
#include "wine/debug.h"
#include "crypt32_private.h"
Include dependency graph for filestore.c:

Go to the source code of this file.

Classes

struct  _WINE_FILESTOREINFO
 

Typedefs

typedef struct _WINE_FILESTOREINFO WINE_FILESTOREINFO
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (crypt)
 
static void WINAPI CRYPT_FileCloseStore (HCERTSTORE hCertStore, DWORD dwFlags)
 
static BOOL WINAPI CRYPT_FileWriteCert (HCERTSTORE hCertStore, PCCERT_CONTEXT cert, DWORD dwFlags)
 
static BOOL WINAPI CRYPT_FileDeleteCert (HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwFlags)
 
static BOOL WINAPI CRYPT_FileWriteCRL (HCERTSTORE hCertStore, PCCRL_CONTEXT crl, DWORD dwFlags)
 
static BOOL WINAPI CRYPT_FileDeleteCRL (HCERTSTORE hCertStore, PCCRL_CONTEXT pCrlContext, DWORD dwFlags)
 
static BOOL WINAPI CRYPT_FileWriteCTL (HCERTSTORE hCertStore, PCCTL_CONTEXT ctl, DWORD dwFlags)
 
static BOOL WINAPI CRYPT_FileDeleteCTL (HCERTSTORE hCertStore, PCCTL_CONTEXT pCtlContext, DWORD dwFlags)
 
static BOOL CRYPT_ReadBlobFromFile (HANDLE file, PCERT_BLOB blob)
 
static BOOL WINAPI CRYPT_FileControl (HCERTSTORE hCertStore, DWORD dwFlags, DWORD dwCtrlType, void const *pvCtrlPara)
 
static WINECRYPT_CERTSTORECRYPT_CreateFileStore (DWORD dwFlags, HCERTSTORE memStore, HANDLE file, DWORD type)
 
WINECRYPT_CERTSTORECRYPT_FileOpenStore (HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara)
 
WINECRYPT_CERTSTORECRYPT_FileNameOpenStoreW (HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara)
 
WINECRYPT_CERTSTORECRYPT_FileNameOpenStoreA (HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara)
 

Variables

static voidfileProvFuncs []
 

Typedef Documentation

◆ WINE_FILESTOREINFO

Function Documentation

◆ CRYPT_CreateFileStore()

static WINECRYPT_CERTSTORE * CRYPT_CreateFileStore ( DWORD  dwFlags,
HCERTSTORE  memStore,
HANDLE  file,
DWORD  type 
)
static

Definition at line 217 of file filestore.c.

219{
220 WINECRYPT_CERTSTORE *store = NULL;
222
223 if (info)
224 {
225 CERT_STORE_PROV_INFO provInfo = { 0 };
226
227 info->dwOpenFlags = dwFlags;
228 info->memStore = memStore;
229 info->file = file;
230 info->type = type;
231 info->dirty = FALSE;
232 provInfo.cbSize = sizeof(provInfo);
235 provInfo.hStoreProv = info;
236 store = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo);
237 }
238 return store;
239}
#define ARRAY_SIZE(A)
Definition: main.h:20
WINECRYPT_CERTSTORE * CRYPT_ProvCreateStore(DWORD dwFlags, WINECRYPT_CERTSTORE *memStore, const CERT_STORE_PROV_INFO *pProvInfo)
Definition: provstore.c:307
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:136
static void * fileProvFuncs[]
Definition: filestore.c:200
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
void ** rgpvStoreProvFunc
Definition: wincrypt.h:1275
HCERTSTOREPROV hStoreProv
Definition: wincrypt.h:1276
Definition: fci.c:127

Referenced by CRYPT_FileNameOpenStoreW(), and CRYPT_FileOpenStore().

◆ CRYPT_FileCloseStore()

static void WINAPI CRYPT_FileCloseStore ( HCERTSTORE  hCertStore,
DWORD  dwFlags 
)
static

Definition at line 37 of file filestore.c.

38{
39 WINE_FILESTOREINFO *store = hCertStore;
40
41 TRACE("(%p, %08lx)\n", store, dwFlags);
42 if (store->dirty)
44 store->type, CERT_STORE_SAVE_TO_FILE, store->file, 0);
45 CloseHandle(store->file);
46 CryptMemFree(store);
47}
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:146
#define CloseHandle
Definition: compat.h:739
BOOL WINAPI CertSaveStore(HCERTSTORE hCertStore, DWORD dwMsgAndCertEncodingType, DWORD dwSaveAs, DWORD dwSaveTo, void *pvSaveToPara, DWORD dwFlags)
Definition: serialize.c:1082
#define TRACE(s)
Definition: solgame.cpp:4
HCERTSTORE memStore
Definition: filestore.c:31
#define X509_ASN_ENCODING
Definition: wincrypt.h:2501
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2503
#define CERT_STORE_SAVE_TO_FILE
Definition: wincrypt.h:2796

◆ CRYPT_FileControl()

static BOOL WINAPI CRYPT_FileControl ( HCERTSTORE  hCertStore,
DWORD  dwFlags,
DWORD  dwCtrlType,
void const pvCtrlPara 
)
static

Definition at line 130 of file filestore.c.

132{
133 WINE_FILESTOREINFO *store = hCertStore;
134 BOOL ret;
135
136 TRACE("(%p, %08lx, %ld, %p)\n", hCertStore, dwFlags, dwCtrlType,
137 pvCtrlPara);
138
139 switch (dwCtrlType)
140 {
142 store->dirty = FALSE;
143 if (store->type == CERT_STORE_SAVE_AS_STORE)
144 {
147
148 /* FIXME: if I could translate a handle to a path, I could use
149 * CryptQueryObject instead, but there's no API to do so yet.
150 */
151 ret = CRYPT_ReadSerializedStoreFromFile(store->file, memStore);
152 if (ret)
153 I_CertUpdateStore(store->memStore, memStore, 0, 0);
154 CertCloseStore(memStore, 0);
155 }
156 else if (store->type == CERT_STORE_SAVE_AS_PKCS7)
157 {
158 CERT_BLOB blob = { 0, NULL };
159
161 if (ret)
162 {
163 HCERTSTORE messageStore;
164
168 &messageStore, NULL, NULL);
169 I_CertUpdateStore(store->memStore, messageStore, 0, 0);
170 CertCloseStore(messageStore, 0);
171 CryptMemFree(blob.pbData);
172 }
173 }
174 else
175 {
176 WARN("unknown type %ld\n", store->type);
177 ret = FALSE;
178 }
179 break;
182 {
184 ret = FALSE;
185 }
186 else if (store->dirty)
187 ret = CertSaveStore(store->memStore,
189 store->type, CERT_STORE_SAVE_TO_FILE, store->file, 0);
190 else
191 ret = TRUE;
192 break;
193 default:
194 FIXME("%ld: stub\n", dwCtrlType);
195 ret = FALSE;
196 }
197 return ret;
198}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store)
Definition: serialize.c:731
BOOL WINAPI I_CertUpdateStore(HCERTSTORE store1, HCERTSTORE store2, DWORD unk0, DWORD unk1)
Definition: store.c:106
#define TRUE
Definition: types.h:120
BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject, DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags, DWORD dwFlags, DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType, DWORD *pdwFormatType, HCERTSTORE *phCertStore, HCRYPTMSG *phMsg, const void **ppvContext)
Definition: object.c:770
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:809
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1121
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SetLastError(x)
Definition: compat.h:752
return ret
Definition: mutex.c:146
static BOOL CRYPT_ReadBlobFromFile(HANDLE file, PCERT_BLOB blob)
Definition: filestore.c:109
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: image.c:134
#define CERT_STORE_SAVE_AS_STORE
Definition: wincrypt.h:2793
#define CERT_STORE_SAVE_AS_PKCS7
Definition: wincrypt.h:2794
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2633
#define CERT_QUERY_OBJECT_BLOB
Definition: wincrypt.h:3687
#define CERT_QUERY_FORMAT_FLAG_BINARY
Definition: wincrypt.h:3743
#define CERT_STORE_CTRL_RESYNC
Definition: wincrypt.h:2967
#define CERT_FILE_STORE_COMMIT_ENABLE_FLAG
Definition: wincrypt.h:2644
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2455
#define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
Definition: wincrypt.h:3714
#define CERT_STORE_CTRL_COMMIT
Definition: wincrypt.h:2969

◆ CRYPT_FileDeleteCert()

static BOOL WINAPI CRYPT_FileDeleteCert ( HCERTSTORE  hCertStore,
PCCERT_CONTEXT  pCertContext,
DWORD  dwFlags 
)
static

Definition at line 59 of file filestore.c.

61{
62 WINE_FILESTOREINFO *store = hCertStore;
63
64 TRACE("(%p, %p, %08lx)\n", hCertStore, pCertContext, dwFlags);
65 store->dirty = TRUE;
66 return TRUE;
67}

◆ CRYPT_FileDeleteCRL()

static BOOL WINAPI CRYPT_FileDeleteCRL ( HCERTSTORE  hCertStore,
PCCRL_CONTEXT  pCrlContext,
DWORD  dwFlags 
)
static

Definition at line 79 of file filestore.c.

81{
82 WINE_FILESTOREINFO *store = hCertStore;
83
84 TRACE("(%p, %p, %08lx)\n", hCertStore, pCrlContext, dwFlags);
85 store->dirty = TRUE;
86 return TRUE;
87}

◆ CRYPT_FileDeleteCTL()

static BOOL WINAPI CRYPT_FileDeleteCTL ( HCERTSTORE  hCertStore,
PCCTL_CONTEXT  pCtlContext,
DWORD  dwFlags 
)
static

Definition at line 99 of file filestore.c.

101{
102 WINE_FILESTOREINFO *store = hCertStore;
103
104 TRACE("(%p, %p, %08lx)\n", hCertStore, pCtlContext, dwFlags);
105 store->dirty = TRUE;
106 return TRUE;
107}

◆ CRYPT_FileNameOpenStoreA()

WINECRYPT_CERTSTORE * CRYPT_FileNameOpenStoreA ( HCRYPTPROV  hCryptProv,
DWORD  dwFlags,
const void pvPara 
)

Definition at line 380 of file filestore.c.

382{
383 int len;
385
386 TRACE("(%Id, %08lx, %s)\n", hCryptProv, dwFlags,
387 debugstr_a(pvPara));
388
389 if (!pvPara)
390 {
392 return NULL;
393 }
394 len = MultiByteToWideChar(CP_ACP, 0, pvPara, -1, NULL, 0);
395 if (len)
396 {
397 LPWSTR storeName = CryptMemAlloc(len * sizeof(WCHAR));
398
399 if (storeName)
400 {
401 MultiByteToWideChar(CP_ACP, 0, pvPara, -1, storeName, len);
402 ret = CRYPT_FileNameOpenStoreW(hCryptProv, dwFlags, storeName);
403 CryptMemFree(storeName);
404 }
405 }
406 return ret;
407}
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
WINECRYPT_CERTSTORE * CRYPT_FileNameOpenStoreW(HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: filestore.c:291
GLenum GLsizei len
Definition: glext.h:6722
#define debugstr_a
Definition: kernel32.h:31
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
short WCHAR
Definition: pedump.c:58
uint16_t * LPWSTR
Definition: typedefs.h:56

Referenced by CertOpenStore().

◆ CRYPT_FileNameOpenStoreW()

WINECRYPT_CERTSTORE * CRYPT_FileNameOpenStoreW ( HCRYPTPROV  hCryptProv,
DWORD  dwFlags,
const void pvPara 
)

Definition at line 291 of file filestore.c.

293{
294 HCERTSTORE store = 0;
295 LPCWSTR fileName = pvPara;
297 HANDLE file;
298
299 TRACE("(%Id, %08lx, %s)\n", hCryptProv, dwFlags, debugstr_w(fileName));
300
301 if (!fileName)
302 {
304 return NULL;
305 }
308 {
310 return NULL;
311 }
312
320 else
325 {
326 HCERTSTORE memStore = NULL;
328
329 /* If the file isn't empty, try to get the type from the file itself */
330 if (size)
331 {
332 DWORD contentType;
333 BOOL ret;
334
335 /* Close the file so CryptQueryObject can succeed.. */
341 CERT_QUERY_FORMAT_FLAG_ALL, 0, NULL, &contentType, NULL,
342 &memStore, NULL, NULL);
343 if (ret)
344 {
345 if (contentType == CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED)
347 else
349 /* and reopen the file. */
352 }
353 }
354 else
355 {
356 LPCWSTR ext = wcsrchr(fileName, '.');
357
358 if (ext)
359 {
360 ext++;
361 if (!lstrcmpiW(ext, L"spc") || !lstrcmpiW(ext, L"p7c"))
363 }
364 if (!type)
366 memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
368 }
369 if (memStore)
370 {
371 store = CRYPT_CreateFileStore(dwFlags, memStore, file, type);
372 /* File store doesn't need crypto provider, so close it */
373 if (hCryptProv && !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG))
374 CryptReleaseContext(hCryptProv, 0);
375 }
376 }
377 return store;
378}
#define E_INVALIDARG
Definition: ddrawi.h:101
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:641
#define wcsrchr
Definition: compat.h:16
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
static const WCHAR *const ext[]
Definition: module.c:53
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4171
#define L(x)
Definition: resources.c:13
static WINECRYPT_CERTSTORE * CRYPT_CreateFileStore(DWORD dwFlags, HCERTSTORE memStore, HANDLE file, DWORD type)
Definition: filestore.c:217
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define debugstr_w
Definition: kernel32.h:32
#define CREATE_NEW
Definition: disk.h:69
#define OPEN_ALWAYS
Definition: disk.h:70
static const struct access_res create[16]
Definition: package.c:7505
#define GENERIC_WRITE
Definition: nt_native.h:90
const uint16_t * LPCWSTR
Definition: typedefs.h:57
#define CERT_QUERY_OBJECT_FILE
Definition: wincrypt.h:3686
#define CERT_QUERY_CONTENT_FLAG_CERT
Definition: wincrypt.h:3703
#define CERT_STORE_OPEN_EXISTING_FLAG
Definition: wincrypt.h:2634
#define CERT_QUERY_FORMAT_FLAG_ALL
Definition: wincrypt.h:3749
#define CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
Definition: wincrypt.h:3706
#define CERT_STORE_NO_CRYPT_RELEASE_FLAG
Definition: wincrypt.h:2621
#define CERT_STORE_READONLY_FLAG
Definition: wincrypt.h:2635
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228

Referenced by CertOpenStore(), and CRYPT_FileNameOpenStoreA().

◆ CRYPT_FileOpenStore()

WINECRYPT_CERTSTORE * CRYPT_FileOpenStore ( HCRYPTPROV  hCryptProv,
DWORD  dwFlags,
const void pvPara 
)

Definition at line 241 of file filestore.c.

243{
244 WINECRYPT_CERTSTORE *store = NULL;
245 HANDLE file = (HANDLE)pvPara;
246
247 TRACE("(%Id, %08lx, %p)\n", hCryptProv, dwFlags, pvPara);
248
249 if (!pvPara)
250 {
252 return NULL;
253 }
255 {
257 return NULL;
258 }
261 {
263 return NULL;
264 }
265
269 {
270 HCERTSTORE memStore;
271
272 memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
274 if (memStore)
275 {
277 {
278 store = CRYPT_CreateFileStore(dwFlags, memStore, file,
280 /* File store doesn't need crypto provider, so close it */
281 if (hCryptProv &&
283 CryptReleaseContext(hCryptProv, 0);
284 }
285 }
286 }
287 TRACE("returning %p\n", store);
288 return store;
289}
#define GetCurrentProcess()
Definition: compat.h:759
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
PVOID HANDLE
Definition: typedefs.h:73
#define CERT_STORE_DELETE_FLAG
Definition: wincrypt.h:2624

Referenced by CertOpenStore().

◆ CRYPT_FileWriteCert()

static BOOL WINAPI CRYPT_FileWriteCert ( HCERTSTORE  hCertStore,
PCCERT_CONTEXT  cert,
DWORD  dwFlags 
)
static

Definition at line 49 of file filestore.c.

51{
52 WINE_FILESTOREINFO *store = hCertStore;
53
54 TRACE("(%p, %p, %ld)\n", hCertStore, cert, dwFlags);
55 store->dirty = TRUE;
56 return TRUE;
57}
static BYTE cert[]
Definition: msg.c:1374

◆ CRYPT_FileWriteCRL()

static BOOL WINAPI CRYPT_FileWriteCRL ( HCERTSTORE  hCertStore,
PCCRL_CONTEXT  crl,
DWORD  dwFlags 
)
static

Definition at line 69 of file filestore.c.

71{
72 WINE_FILESTOREINFO *store = hCertStore;
73
74 TRACE("(%p, %p, %ld)\n", hCertStore, crl, dwFlags);
75 store->dirty = TRUE;
76 return TRUE;
77}
static const BYTE crl[]
Definition: message.c:817

◆ CRYPT_FileWriteCTL()

static BOOL WINAPI CRYPT_FileWriteCTL ( HCERTSTORE  hCertStore,
PCCTL_CONTEXT  ctl,
DWORD  dwFlags 
)
static

Definition at line 89 of file filestore.c.

91{
92 WINE_FILESTOREINFO *store = hCertStore;
93
94 TRACE("(%p, %p, %ld)\n", hCertStore, ctl, dwFlags);
95 store->dirty = TRUE;
96 return TRUE;
97}

◆ CRYPT_ReadBlobFromFile()

static BOOL CRYPT_ReadBlobFromFile ( HANDLE  file,
PCERT_BLOB  blob 
)
static

Definition at line 109 of file filestore.c.

110{
111 BOOL ret = TRUE;
112
113 blob->cbData = GetFileSize(file, NULL);
114 if (blob->cbData)
115 {
116 blob->pbData = CryptMemAlloc(blob->cbData);
117 if (blob->pbData)
118 {
119 DWORD read;
120
121 ret = ReadFile(file, blob->pbData, blob->cbData, &read, NULL) && read == blob->cbData;
122 if (!ret) CryptMemFree(blob->pbData);
123 }
124 else
125 ret = FALSE;
126 }
127 return ret;
128}
#define read
Definition: acwin.h:97
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742

Referenced by CRYPT_FileControl().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( crypt  )

Variable Documentation

◆ fileProvFuncs

void* fileProvFuncs[]
static
Initial value:
= {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
}
static BOOL WINAPI CRYPT_FileControl(HCERTSTORE hCertStore, DWORD dwFlags, DWORD dwCtrlType, void const *pvCtrlPara)
Definition: filestore.c:130
static BOOL WINAPI CRYPT_FileDeleteCert(HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwFlags)
Definition: filestore.c:59
static BOOL WINAPI CRYPT_FileWriteCTL(HCERTSTORE hCertStore, PCCTL_CONTEXT ctl, DWORD dwFlags)
Definition: filestore.c:89
static BOOL WINAPI CRYPT_FileWriteCert(HCERTSTORE hCertStore, PCCERT_CONTEXT cert, DWORD dwFlags)
Definition: filestore.c:49
static BOOL WINAPI CRYPT_FileDeleteCTL(HCERTSTORE hCertStore, PCCTL_CONTEXT pCtlContext, DWORD dwFlags)
Definition: filestore.c:99
static BOOL WINAPI CRYPT_FileDeleteCRL(HCERTSTORE hCertStore, PCCRL_CONTEXT pCrlContext, DWORD dwFlags)
Definition: filestore.c:79
static BOOL WINAPI CRYPT_FileWriteCRL(HCERTSTORE hCertStore, PCCRL_CONTEXT crl, DWORD dwFlags)
Definition: filestore.c:69
static void WINAPI CRYPT_FileCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: filestore.c:37

Definition at line 200 of file filestore.c.

Referenced by CRYPT_CreateFileStore().