2007-08-16 19:54:52 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2004-2007 Juan Lang
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincrypt.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/debug.h"
|
2007-09-28 18:03:53 +02:00
|
|
|
#include "wine/unicode.h"
|
2007-08-16 19:54:52 +02:00
|
|
|
#include "crypt32_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
|
|
|
|
|
|
|
typedef struct _WINE_FILESTOREINFO
|
|
|
|
{
|
|
|
|
DWORD dwOpenFlags;
|
|
|
|
HCERTSTORE memStore;
|
|
|
|
HANDLE file;
|
2007-09-28 17:38:12 +02:00
|
|
|
DWORD type;
|
2007-08-16 19:54:52 +02:00
|
|
|
BOOL dirty;
|
2013-09-04 12:39:43 +02:00
|
|
|
} WINE_FILESTOREINFO;
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
static void WINAPI CRYPT_FileCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *store = hCertStore;
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %08x)\n", store, dwFlags);
|
|
|
|
if (store->dirty)
|
2007-09-27 23:01:30 +02:00
|
|
|
CertSaveStore(store->memStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
|
2007-09-28 17:38:12 +02:00
|
|
|
store->type, CERT_STORE_SAVE_TO_FILE, store->file, 0);
|
2007-08-16 19:54:52 +02:00
|
|
|
CloseHandle(store->file);
|
|
|
|
CryptMemFree(store);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FileWriteCert(HCERTSTORE hCertStore,
|
|
|
|
PCCERT_CONTEXT cert, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *store = hCertStore;
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %d)\n", hCertStore, cert, dwFlags);
|
|
|
|
store->dirty = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FileDeleteCert(HCERTSTORE hCertStore,
|
|
|
|
PCCERT_CONTEXT pCertContext, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *store = hCertStore;
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %08x)\n", hCertStore, pCertContext, dwFlags);
|
|
|
|
store->dirty = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FileWriteCRL(HCERTSTORE hCertStore,
|
|
|
|
PCCRL_CONTEXT crl, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *store = hCertStore;
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %d)\n", hCertStore, crl, dwFlags);
|
|
|
|
store->dirty = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FileDeleteCRL(HCERTSTORE hCertStore,
|
|
|
|
PCCRL_CONTEXT pCrlContext, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *store = hCertStore;
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %08x)\n", hCertStore, pCrlContext, dwFlags);
|
|
|
|
store->dirty = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-29 16:33:03 +02:00
|
|
|
static BOOL WINAPI CRYPT_FileWriteCTL(HCERTSTORE hCertStore,
|
|
|
|
PCCTL_CONTEXT ctl, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *store = hCertStore;
|
2008-08-29 16:33:03 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %d)\n", hCertStore, ctl, dwFlags);
|
|
|
|
store->dirty = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FileDeleteCTL(HCERTSTORE hCertStore,
|
|
|
|
PCCTL_CONTEXT pCtlContext, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *store = hCertStore;
|
2008-08-29 16:33:03 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %08x)\n", hCertStore, pCtlContext, dwFlags);
|
|
|
|
store->dirty = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-09-28 18:03:53 +02:00
|
|
|
static BOOL CRYPT_ReadBlobFromFile(HANDLE file, PCERT_BLOB blob)
|
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
blob->cbData = GetFileSize(file, NULL);
|
|
|
|
if (blob->cbData)
|
|
|
|
{
|
|
|
|
blob->pbData = CryptMemAlloc(blob->cbData);
|
|
|
|
if (blob->pbData)
|
|
|
|
{
|
|
|
|
DWORD read;
|
|
|
|
|
2013-10-29 08:08:59 +01:00
|
|
|
ret = ReadFile(file, blob->pbData, blob->cbData, &read, NULL) && read == blob->cbData;
|
|
|
|
if (!ret) CryptMemFree(blob->pbData);
|
2007-09-28 18:03:53 +02:00
|
|
|
}
|
2013-12-08 06:09:17 +01:00
|
|
|
else
|
|
|
|
ret = FALSE;
|
2007-09-28 18:03:53 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-16 19:54:52 +02:00
|
|
|
static BOOL WINAPI CRYPT_FileControl(HCERTSTORE hCertStore, DWORD dwFlags,
|
|
|
|
DWORD dwCtrlType, void const *pvCtrlPara)
|
|
|
|
{
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *store = hCertStore;
|
2007-08-16 19:54:52 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %08x, %d, %p)\n", hCertStore, dwFlags, dwCtrlType,
|
|
|
|
pvCtrlPara);
|
|
|
|
|
|
|
|
switch (dwCtrlType)
|
|
|
|
{
|
|
|
|
case CERT_STORE_CTRL_RESYNC:
|
2007-09-28 17:37:17 +02:00
|
|
|
store->dirty = FALSE;
|
2007-09-28 17:38:12 +02:00
|
|
|
if (store->type == CERT_STORE_SAVE_AS_STORE)
|
2007-10-18 20:11:54 +02:00
|
|
|
{
|
|
|
|
HCERTSTORE memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
|
|
|
|
|
|
|
/* FIXME: if I could translate a handle to a path, I could use
|
|
|
|
* CryptQueryObject instead, but there's no API to do so yet.
|
|
|
|
*/
|
|
|
|
ret = CRYPT_ReadSerializedStoreFromFile(store->file, memStore);
|
|
|
|
if (ret)
|
|
|
|
I_CertUpdateStore(store->memStore, memStore, 0, 0);
|
|
|
|
CertCloseStore(memStore, 0);
|
|
|
|
}
|
2007-09-28 17:38:12 +02:00
|
|
|
else if (store->type == CERT_STORE_SAVE_AS_PKCS7)
|
|
|
|
{
|
2007-09-28 18:03:53 +02:00
|
|
|
CERT_BLOB blob = { 0, NULL };
|
|
|
|
|
|
|
|
ret = CRYPT_ReadBlobFromFile(store->file, &blob);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
HCERTSTORE messageStore;
|
|
|
|
|
|
|
|
ret = CryptQueryObject(CERT_QUERY_OBJECT_BLOB, &blob,
|
|
|
|
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED,
|
|
|
|
CERT_QUERY_FORMAT_FLAG_BINARY, 0, NULL, NULL, NULL,
|
|
|
|
&messageStore, NULL, NULL);
|
2007-10-18 20:11:54 +02:00
|
|
|
I_CertUpdateStore(store->memStore, messageStore, 0, 0);
|
|
|
|
CertCloseStore(messageStore, 0);
|
2007-09-28 18:03:53 +02:00
|
|
|
CryptMemFree(blob.pbData);
|
|
|
|
}
|
2007-09-28 17:38:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("unknown type %d\n", store->type);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
2007-08-16 19:54:52 +02:00
|
|
|
break;
|
|
|
|
case CERT_STORE_CTRL_COMMIT:
|
|
|
|
if (!(store->dwOpenFlags & CERT_FILE_STORE_COMMIT_ENABLE_FLAG))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else if (store->dirty)
|
2007-09-27 23:01:30 +02:00
|
|
|
ret = CertSaveStore(store->memStore,
|
|
|
|
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
|
2007-09-28 17:38:12 +02:00
|
|
|
store->type, CERT_STORE_SAVE_TO_FILE, store->file, 0);
|
2007-08-16 19:54:52 +02:00
|
|
|
else
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("%d: stub\n", dwCtrlType);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *fileProvFuncs[] = {
|
|
|
|
CRYPT_FileCloseStore,
|
|
|
|
NULL, /* CERT_STORE_PROV_READ_CERT_FUNC */
|
|
|
|
CRYPT_FileWriteCert,
|
|
|
|
CRYPT_FileDeleteCert,
|
|
|
|
NULL, /* CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC */
|
|
|
|
NULL, /* CERT_STORE_PROV_READ_CRL_FUNC */
|
|
|
|
CRYPT_FileWriteCRL,
|
|
|
|
CRYPT_FileDeleteCRL,
|
|
|
|
NULL, /* CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC */
|
|
|
|
NULL, /* CERT_STORE_PROV_READ_CTL_FUNC */
|
2008-08-29 16:33:03 +02:00
|
|
|
CRYPT_FileWriteCTL,
|
|
|
|
CRYPT_FileDeleteCTL,
|
2007-08-16 19:54:52 +02:00
|
|
|
NULL, /* CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC */
|
|
|
|
CRYPT_FileControl,
|
|
|
|
};
|
|
|
|
|
2013-09-04 12:38:51 +02:00
|
|
|
static WINECRYPT_CERTSTORE *CRYPT_CreateFileStore(DWORD dwFlags,
|
2007-09-28 17:38:12 +02:00
|
|
|
HCERTSTORE memStore, HANDLE file, DWORD type)
|
2007-09-28 17:37:17 +02:00
|
|
|
{
|
2013-09-04 12:38:51 +02:00
|
|
|
WINECRYPT_CERTSTORE *store = NULL;
|
2013-09-04 12:39:43 +02:00
|
|
|
WINE_FILESTOREINFO *info = CryptMemAlloc(sizeof(WINE_FILESTOREINFO));
|
2007-09-28 17:37:17 +02:00
|
|
|
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
CERT_STORE_PROV_INFO provInfo = { 0 };
|
|
|
|
|
|
|
|
info->dwOpenFlags = dwFlags;
|
|
|
|
info->memStore = memStore;
|
|
|
|
info->file = file;
|
2007-09-28 17:38:12 +02:00
|
|
|
info->type = type;
|
2007-09-28 17:37:17 +02:00
|
|
|
info->dirty = FALSE;
|
|
|
|
provInfo.cbSize = sizeof(provInfo);
|
|
|
|
provInfo.cStoreProvFunc = sizeof(fileProvFuncs) /
|
|
|
|
sizeof(fileProvFuncs[0]);
|
|
|
|
provInfo.rgpvStoreProvFunc = fileProvFuncs;
|
|
|
|
provInfo.hStoreProv = info;
|
|
|
|
store = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo);
|
|
|
|
}
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
2013-09-04 12:38:51 +02:00
|
|
|
WINECRYPT_CERTSTORE *CRYPT_FileOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags,
|
2007-08-16 19:54:52 +02:00
|
|
|
const void *pvPara)
|
|
|
|
{
|
2013-09-04 12:38:51 +02:00
|
|
|
WINECRYPT_CERTSTORE *store = NULL;
|
2007-08-16 19:54:52 +02:00
|
|
|
HANDLE file = (HANDLE)pvPara;
|
|
|
|
|
|
|
|
TRACE("(%ld, %08x, %p)\n", hCryptProv, dwFlags, pvPara);
|
|
|
|
|
|
|
|
if (!pvPara)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (dwFlags & CERT_STORE_DELETE_FLAG)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if ((dwFlags & CERT_STORE_READONLY_FLAG) &&
|
|
|
|
(dwFlags & CERT_FILE_STORE_COMMIT_ENABLE_FLAG))
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DuplicateHandle(GetCurrentProcess(), (HANDLE)pvPara,
|
|
|
|
GetCurrentProcess(), &file, dwFlags & CERT_STORE_READONLY_FLAG ?
|
|
|
|
GENERIC_READ : GENERIC_READ | GENERIC_WRITE, TRUE, 0))
|
|
|
|
{
|
2007-09-28 17:37:17 +02:00
|
|
|
HCERTSTORE memStore;
|
2007-08-16 19:54:52 +02:00
|
|
|
|
2007-08-17 20:59:28 +02:00
|
|
|
memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
2007-08-16 19:54:52 +02:00
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
|
|
|
if (memStore)
|
|
|
|
{
|
2007-09-27 20:54:24 +02:00
|
|
|
if (CRYPT_ReadSerializedStoreFromFile(file, memStore))
|
2007-08-16 19:54:52 +02:00
|
|
|
{
|
2007-09-28 17:38:12 +02:00
|
|
|
store = CRYPT_CreateFileStore(dwFlags, memStore, file,
|
|
|
|
CERT_STORE_SAVE_AS_STORE);
|
2007-09-28 17:37:17 +02:00
|
|
|
/* File store doesn't need crypto provider, so close it */
|
|
|
|
if (hCryptProv &&
|
|
|
|
!(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG))
|
|
|
|
CryptReleaseContext(hCryptProv, 0);
|
2007-08-16 19:54:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("returning %p\n", store);
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
2013-09-04 12:38:51 +02:00
|
|
|
WINECRYPT_CERTSTORE *CRYPT_FileNameOpenStoreW(HCRYPTPROV hCryptProv,
|
2007-08-16 19:54:52 +02:00
|
|
|
DWORD dwFlags, const void *pvPara)
|
|
|
|
{
|
|
|
|
HCERTSTORE store = 0;
|
2009-01-28 10:25:22 +01:00
|
|
|
LPCWSTR fileName = pvPara;
|
2007-08-16 19:54:52 +02:00
|
|
|
DWORD access, create;
|
|
|
|
HANDLE file;
|
|
|
|
|
|
|
|
TRACE("(%ld, %08x, %s)\n", hCryptProv, dwFlags, debugstr_w(fileName));
|
|
|
|
|
|
|
|
if (!fileName)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_PATH_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-28 17:37:47 +02:00
|
|
|
if ((dwFlags & CERT_STORE_READONLY_FLAG) &&
|
|
|
|
(dwFlags & CERT_FILE_STORE_COMMIT_ENABLE_FLAG))
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
access = GENERIC_READ;
|
|
|
|
if (dwFlags & CERT_FILE_STORE_COMMIT_ENABLE_FLAG)
|
|
|
|
access |= GENERIC_WRITE;
|
|
|
|
if (dwFlags & CERT_STORE_CREATE_NEW_FLAG)
|
|
|
|
create = CREATE_NEW;
|
|
|
|
else if (dwFlags & CERT_STORE_OPEN_EXISTING_FLAG)
|
|
|
|
create = OPEN_EXISTING;
|
|
|
|
else
|
|
|
|
create = OPEN_ALWAYS;
|
|
|
|
file = CreateFileW(fileName, access, FILE_SHARE_READ, NULL, create,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2007-09-28 18:03:53 +02:00
|
|
|
HCERTSTORE memStore = NULL;
|
|
|
|
DWORD size = GetFileSize(file, NULL), type = 0;
|
2007-09-28 17:37:47 +02:00
|
|
|
|
2007-09-28 18:03:53 +02:00
|
|
|
/* If the file isn't empty, try to get the type from the file itself */
|
|
|
|
if (size)
|
2007-09-28 17:37:47 +02:00
|
|
|
{
|
2007-09-28 18:03:53 +02:00
|
|
|
DWORD contentType;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
/* Close the file so CryptQueryObject can succeed.. */
|
|
|
|
CloseHandle(file);
|
|
|
|
ret = CryptQueryObject(CERT_QUERY_OBJECT_FILE, fileName,
|
|
|
|
CERT_QUERY_CONTENT_FLAG_CERT |
|
|
|
|
CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE |
|
|
|
|
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED,
|
2008-12-20 00:36:58 +01:00
|
|
|
CERT_QUERY_FORMAT_FLAG_ALL, 0, NULL, &contentType, NULL,
|
2007-09-28 18:03:53 +02:00
|
|
|
&memStore, NULL, NULL);
|
|
|
|
if (ret)
|
2007-09-28 17:37:47 +02:00
|
|
|
{
|
2007-09-28 18:03:53 +02:00
|
|
|
if (contentType == CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED)
|
|
|
|
type = CERT_STORE_SAVE_AS_PKCS7;
|
|
|
|
else
|
|
|
|
type = CERT_STORE_SAVE_AS_STORE;
|
|
|
|
/* and reopen the file. */
|
|
|
|
file = CreateFileW(fileName, access, FILE_SHARE_READ, NULL,
|
|
|
|
create, FILE_ATTRIBUTE_NORMAL, NULL);
|
2007-09-28 17:37:47 +02:00
|
|
|
}
|
2007-09-28 18:03:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const WCHAR spc[] = { 's','p','c',0 };
|
|
|
|
static const WCHAR p7c[] = { 'p','7','c',0 };
|
|
|
|
LPCWSTR ext = strrchrW(fileName, '.');
|
|
|
|
|
|
|
|
if (ext)
|
2007-09-28 17:37:47 +02:00
|
|
|
{
|
2007-09-28 18:03:53 +02:00
|
|
|
ext++;
|
|
|
|
if (!lstrcmpiW(ext, spc) || !lstrcmpiW(ext, p7c))
|
|
|
|
type = CERT_STORE_SAVE_AS_PKCS7;
|
2007-09-28 17:37:47 +02:00
|
|
|
}
|
2007-09-28 18:03:53 +02:00
|
|
|
if (!type)
|
|
|
|
type = CERT_STORE_SAVE_AS_STORE;
|
|
|
|
memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
|
|
|
}
|
|
|
|
if (memStore)
|
|
|
|
{
|
|
|
|
store = CRYPT_CreateFileStore(dwFlags, memStore, file, type);
|
|
|
|
/* File store doesn't need crypto provider, so close it */
|
|
|
|
if (hCryptProv && !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG))
|
|
|
|
CryptReleaseContext(hCryptProv, 0);
|
2007-09-28 17:37:47 +02:00
|
|
|
}
|
2007-08-16 19:54:52 +02:00
|
|
|
}
|
2009-01-28 10:25:22 +01:00
|
|
|
return store;
|
2007-08-16 19:54:52 +02:00
|
|
|
}
|
|
|
|
|
2013-09-04 12:38:51 +02:00
|
|
|
WINECRYPT_CERTSTORE *CRYPT_FileNameOpenStoreA(HCRYPTPROV hCryptProv,
|
2007-08-16 19:54:52 +02:00
|
|
|
DWORD dwFlags, const void *pvPara)
|
|
|
|
{
|
|
|
|
int len;
|
2013-09-04 12:38:51 +02:00
|
|
|
WINECRYPT_CERTSTORE *ret = NULL;
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
TRACE("(%ld, %08x, %s)\n", hCryptProv, dwFlags,
|
2009-01-28 10:25:22 +01:00
|
|
|
debugstr_a(pvPara));
|
2007-08-16 19:54:52 +02:00
|
|
|
|
|
|
|
if (!pvPara)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_FILE_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-28 10:25:22 +01:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pvPara, -1, NULL, 0);
|
2007-08-16 19:54:52 +02:00
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
LPWSTR storeName = CryptMemAlloc(len * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (storeName)
|
|
|
|
{
|
2009-01-28 10:25:22 +01:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, pvPara, -1, storeName, len);
|
2007-08-16 19:54:52 +02:00
|
|
|
ret = CRYPT_FileNameOpenStoreW(hCryptProv, dwFlags, storeName);
|
|
|
|
CryptMemFree(storeName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|