2007-08-16 17:54:03 +00: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 <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincrypt.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "crypt32_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
|
|
|
|
|
|
|
typedef struct _WINE_HASH_TO_DELETE
|
|
|
|
{
|
|
|
|
BYTE hash[20];
|
|
|
|
struct list entry;
|
2013-09-04 10:40:17 +00:00
|
|
|
} WINE_HASH_TO_DELETE;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
typedef struct _WINE_REGSTOREINFO
|
|
|
|
{
|
|
|
|
DWORD dwOpenFlags;
|
|
|
|
HCERTSTORE memStore;
|
|
|
|
HKEY key;
|
|
|
|
BOOL dirty;
|
|
|
|
CRITICAL_SECTION cs;
|
|
|
|
struct list certsToDelete;
|
|
|
|
struct list crlsToDelete;
|
2008-08-29 14:33:24 +00:00
|
|
|
struct list ctlsToDelete;
|
2013-09-04 10:40:17 +00:00
|
|
|
} WINE_REGSTOREINFO;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
static void CRYPT_HashToStr(const BYTE *hash, LPWSTR asciiHash)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
assert(hash);
|
|
|
|
assert(asciiHash);
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
2020-11-09 10:41:52 +00:00
|
|
|
wsprintfW(asciiHash + i * 2, L"%02X", hash[i]);
|
2007-08-16 17:54:03 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 01:07:23 +00:00
|
|
|
void CRYPT_RegReadSerializedFromReg(HKEY key, DWORD contextType, HCERTSTORE store, DWORD disposition)
|
2007-08-16 17:54:03 +00:00
|
|
|
{
|
|
|
|
LONG rc;
|
|
|
|
DWORD index = 0;
|
|
|
|
WCHAR subKeyName[MAX_PATH];
|
|
|
|
|
|
|
|
do {
|
2018-06-20 07:37:55 +00:00
|
|
|
DWORD size = ARRAY_SIZE(subKeyName);
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
rc = RegEnumKeyExW(key, index++, subKeyName, &size, NULL, NULL, NULL,
|
|
|
|
NULL);
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
HKEY subKey;
|
|
|
|
|
|
|
|
rc = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
LPBYTE buf = NULL;
|
|
|
|
|
|
|
|
size = 0;
|
2020-11-09 10:41:52 +00:00
|
|
|
rc = RegQueryValueExW(subKey, L"Blob", NULL, NULL, NULL, &size);
|
2007-08-16 17:54:03 +00:00
|
|
|
if (!rc)
|
|
|
|
buf = CryptMemAlloc(size);
|
|
|
|
if (buf)
|
|
|
|
{
|
2020-11-09 10:41:52 +00:00
|
|
|
rc = RegQueryValueExW(subKey, L"Blob", NULL, NULL, buf,
|
2007-08-16 17:54:03 +00:00
|
|
|
&size);
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
const void *context;
|
|
|
|
DWORD addedType;
|
|
|
|
|
|
|
|
TRACE("Adding cert with hash %s\n",
|
|
|
|
debugstr_w(subKeyName));
|
|
|
|
context = CRYPT_ReadSerializedElement(buf, size,
|
|
|
|
contextType, &addedType);
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
const WINE_CONTEXT_INTERFACE *contextInterface;
|
|
|
|
BYTE hash[20];
|
|
|
|
|
|
|
|
switch (addedType)
|
|
|
|
{
|
|
|
|
case CERT_STORE_CERTIFICATE_CONTEXT:
|
|
|
|
contextInterface = pCertInterface;
|
|
|
|
break;
|
|
|
|
case CERT_STORE_CRL_CONTEXT:
|
|
|
|
contextInterface = pCRLInterface;
|
|
|
|
break;
|
|
|
|
case CERT_STORE_CTL_CONTEXT:
|
|
|
|
contextInterface = pCTLInterface;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
contextInterface = NULL;
|
|
|
|
}
|
|
|
|
if (contextInterface)
|
|
|
|
{
|
|
|
|
size = sizeof(hash);
|
|
|
|
if (contextInterface->getProp(context,
|
|
|
|
CERT_HASH_PROP_ID, hash, &size))
|
|
|
|
{
|
|
|
|
WCHAR asciiHash[20 * 2 + 1];
|
|
|
|
|
|
|
|
CRYPT_HashToStr(hash, asciiHash);
|
|
|
|
TRACE("comparing %s\n",
|
|
|
|
debugstr_w(asciiHash));
|
|
|
|
TRACE("with %s\n", debugstr_w(subKeyName));
|
2020-11-09 10:41:21 +00:00
|
|
|
if (!wcscmp(asciiHash, subKeyName))
|
2007-08-16 17:54:03 +00:00
|
|
|
{
|
|
|
|
TRACE("hash matches, adding\n");
|
|
|
|
contextInterface->addContextToStore(
|
2007-10-18 18:12:32 +00:00
|
|
|
store, context,
|
2023-03-23 19:23:53 +00:00
|
|
|
disposition, NULL);
|
2007-08-16 17:54:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
TRACE("hash doesn't match, ignoring\n");
|
|
|
|
}
|
2013-10-14 12:47:50 +00:00
|
|
|
Context_Release(context_from_ptr(context));
|
2007-08-16 17:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CryptMemFree(buf);
|
|
|
|
}
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
|
|
|
/* Ignore intermediate errors, continue enumerating */
|
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
} while (!rc);
|
|
|
|
}
|
|
|
|
|
2023-03-23 19:23:53 +00:00
|
|
|
static void CRYPT_RegReadFromReg(HKEY key, HCERTSTORE store, DWORD disposition)
|
2007-08-16 17:54:03 +00:00
|
|
|
{
|
2020-11-09 10:41:52 +00:00
|
|
|
static const WCHAR * const subKeys[] = { L"Certificates", L"CRLs", L"CTLs" };
|
2007-08-16 17:54:03 +00:00
|
|
|
static const DWORD contextFlags[] = { CERT_STORE_CERTIFICATE_CONTEXT_FLAG,
|
|
|
|
CERT_STORE_CRL_CONTEXT_FLAG, CERT_STORE_CTL_CONTEXT_FLAG };
|
|
|
|
DWORD i;
|
|
|
|
|
2018-06-20 07:37:55 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(subKeys); i++)
|
2007-08-16 17:54:03 +00:00
|
|
|
{
|
2007-10-18 18:12:32 +00:00
|
|
|
HKEY hKey;
|
2007-08-16 17:54:03 +00:00
|
|
|
LONG rc;
|
|
|
|
|
2007-10-18 18:12:32 +00:00
|
|
|
rc = RegCreateKeyExW(key, subKeys[i], 0, NULL, 0, KEY_READ, NULL,
|
|
|
|
&hKey, NULL);
|
2007-08-16 17:54:03 +00:00
|
|
|
if (!rc)
|
|
|
|
{
|
2023-03-23 19:23:53 +00:00
|
|
|
CRYPT_RegReadSerializedFromReg(hKey, contextFlags[i], store, disposition);
|
2007-10-18 18:12:32 +00:00
|
|
|
RegCloseKey(hKey);
|
2007-08-16 17:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hash is assumed to be 20 bytes in length (a SHA-1 hash) */
|
2016-11-07 16:37:29 +00:00
|
|
|
static BOOL CRYPT_WriteSerializedToReg(HKEY key, DWORD flags, const BYTE *hash, const BYTE *buf,
|
2007-08-16 17:54:03 +00:00
|
|
|
DWORD len)
|
|
|
|
{
|
|
|
|
WCHAR asciiHash[20 * 2 + 1];
|
|
|
|
LONG rc;
|
|
|
|
HKEY subKey;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
CRYPT_HashToStr(hash, asciiHash);
|
2016-11-07 16:37:29 +00:00
|
|
|
rc = RegCreateKeyExW(key, asciiHash, 0, NULL, flags, KEY_ALL_ACCESS, NULL,
|
2007-08-16 17:54:03 +00:00
|
|
|
&subKey, NULL);
|
|
|
|
if (!rc)
|
|
|
|
{
|
2020-11-09 10:41:52 +00:00
|
|
|
rc = RegSetValueExW(subKey, L"Blob", 0, REG_BINARY, buf, len);
|
2007-08-16 17:54:03 +00:00
|
|
|
RegCloseKey(subKey);
|
|
|
|
}
|
|
|
|
if (!rc)
|
|
|
|
ret = TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(rc);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-07 16:37:29 +00:00
|
|
|
BOOL CRYPT_SerializeContextsToReg(HKEY key, DWORD flags,
|
2007-08-16 17:54:03 +00:00
|
|
|
const WINE_CONTEXT_INTERFACE *contextInterface, HCERTSTORE memStore)
|
|
|
|
{
|
|
|
|
const void *context = NULL;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
do {
|
|
|
|
context = contextInterface->enumContextsInStore(memStore, context);
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
BYTE hash[20];
|
|
|
|
DWORD hashSize = sizeof(hash);
|
|
|
|
|
|
|
|
ret = contextInterface->getProp(context, CERT_HASH_PROP_ID, hash,
|
|
|
|
&hashSize);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
DWORD size = 0;
|
|
|
|
LPBYTE buf = NULL;
|
|
|
|
|
|
|
|
ret = contextInterface->serialize(context, 0, NULL, &size);
|
|
|
|
if (size)
|
|
|
|
buf = CryptMemAlloc(size);
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
ret = contextInterface->serialize(context, 0, buf, &size);
|
|
|
|
if (ret)
|
2016-11-07 16:37:29 +00:00
|
|
|
ret = CRYPT_WriteSerializedToReg(key, flags, hash, buf, size);
|
2007-08-16 17:54:03 +00:00
|
|
|
}
|
|
|
|
CryptMemFree(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = TRUE;
|
|
|
|
} while (ret && context != NULL);
|
|
|
|
if (context)
|
2013-10-14 12:47:50 +00:00
|
|
|
Context_Release(context_from_ptr(context));
|
2007-08-16 17:54:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:40:17 +00:00
|
|
|
static BOOL CRYPT_RegWriteToReg(WINE_REGSTOREINFO *store)
|
2007-08-16 17:54:03 +00:00
|
|
|
{
|
2020-11-09 10:41:52 +00:00
|
|
|
static const WCHAR * const subKeys[] = { L"Certificates", L"CRLs", L"CTLs" };
|
2007-08-16 17:54:03 +00:00
|
|
|
const WINE_CONTEXT_INTERFACE * const interfaces[] = { pCertInterface,
|
|
|
|
pCRLInterface, pCTLInterface };
|
|
|
|
struct list *listToDelete[] = { &store->certsToDelete, &store->crlsToDelete,
|
2008-08-29 14:33:24 +00:00
|
|
|
&store->ctlsToDelete };
|
2007-08-16 17:54:03 +00:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
DWORD i;
|
|
|
|
|
2018-06-20 07:37:55 +00:00
|
|
|
for (i = 0; ret && i < ARRAY_SIZE(subKeys); i++)
|
2007-08-16 17:54:03 +00:00
|
|
|
{
|
|
|
|
HKEY key;
|
|
|
|
LONG rc = RegCreateKeyExW(store->key, subKeys[i], 0, NULL, 0,
|
|
|
|
KEY_ALL_ACCESS, NULL, &key, NULL);
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
if (listToDelete[i])
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_HASH_TO_DELETE *toDelete, *next;
|
2007-08-16 17:54:03 +00:00
|
|
|
WCHAR asciiHash[20 * 2 + 1];
|
|
|
|
|
|
|
|
EnterCriticalSection(&store->cs);
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(toDelete, next, listToDelete[i],
|
|
|
|
WINE_HASH_TO_DELETE, entry)
|
|
|
|
{
|
|
|
|
LONG rc;
|
|
|
|
|
|
|
|
CRYPT_HashToStr(toDelete->hash, asciiHash);
|
|
|
|
TRACE("Removing %s\n", debugstr_w(asciiHash));
|
|
|
|
rc = RegDeleteKeyW(key, asciiHash);
|
|
|
|
if (rc != ERROR_SUCCESS && rc != ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
SetLastError(rc);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
list_remove(&toDelete->entry);
|
|
|
|
CryptMemFree(toDelete);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&store->cs);
|
|
|
|
}
|
2016-11-07 16:37:29 +00:00
|
|
|
ret = CRYPT_SerializeContextsToReg(key, 0, interfaces[i], store->memStore);
|
2007-08-16 17:54:03 +00:00
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(rc);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If force is true or the registry store is dirty, writes the contents of the
|
|
|
|
* store to the registry.
|
|
|
|
*/
|
2013-09-04 10:40:17 +00:00
|
|
|
static BOOL CRYPT_RegFlushStore(WINE_REGSTOREINFO *store, BOOL force)
|
2007-08-16 17:54:03 +00:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %d)\n", store, force);
|
|
|
|
|
|
|
|
if (store->dirty || force)
|
2018-05-04 21:38:50 +00:00
|
|
|
{
|
2007-08-16 17:54:03 +00:00
|
|
|
ret = CRYPT_RegWriteToReg(store);
|
2018-05-04 21:38:50 +00:00
|
|
|
if (ret)
|
|
|
|
store->dirty = FALSE;
|
|
|
|
}
|
2007-08-16 17:54:03 +00:00
|
|
|
else
|
|
|
|
ret = TRUE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI CRYPT_RegCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *store = hCertStore;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%p, %08lx)\n", store, dwFlags);
|
2007-08-16 17:54:03 +00:00
|
|
|
if (dwFlags)
|
2022-02-09 08:25:50 +00:00
|
|
|
FIXME("Unimplemented flags: %08lx\n", dwFlags);
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
CRYPT_RegFlushStore(store, FALSE);
|
|
|
|
RegCloseKey(store->key);
|
|
|
|
store->cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&store->cs);
|
|
|
|
CryptMemFree(store);
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:40:17 +00:00
|
|
|
static BOOL CRYPT_RegWriteContext(WINE_REGSTOREINFO *store,
|
2007-08-16 17:54:03 +00:00
|
|
|
const void *context, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG)
|
|
|
|
{
|
|
|
|
store->dirty = TRUE;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:40:17 +00:00
|
|
|
static BOOL CRYPT_RegDeleteContext(WINE_REGSTOREINFO *store,
|
2007-08-16 17:54:03 +00:00
|
|
|
struct list *deleteList, const void *context,
|
2013-09-04 10:38:17 +00:00
|
|
|
const WINE_CONTEXT_INTERFACE *contextInterface)
|
2007-08-16 17:54:03 +00:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (store->dwOpenFlags & CERT_STORE_READONLY_FLAG)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_ACCESS_DENIED);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_HASH_TO_DELETE *toDelete = CryptMemAlloc(sizeof(WINE_HASH_TO_DELETE));
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
if (toDelete)
|
|
|
|
{
|
|
|
|
DWORD size = sizeof(toDelete->hash);
|
|
|
|
|
|
|
|
ret = contextInterface->getProp(context, CERT_HASH_PROP_ID,
|
|
|
|
toDelete->hash, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&store->cs);
|
|
|
|
list_add_tail(deleteList, &toDelete->entry);
|
|
|
|
LeaveCriticalSection(&store->cs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CryptMemFree(toDelete);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
if (ret)
|
|
|
|
store->dirty = TRUE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_RegWriteCert(HCERTSTORE hCertStore,
|
|
|
|
PCCERT_CONTEXT cert, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *store = hCertStore;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%p, %p, %ld)\n", hCertStore, cert, dwFlags);
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
return CRYPT_RegWriteContext(store, cert, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore,
|
|
|
|
PCCERT_CONTEXT pCertContext, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *store = hCertStore;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%p, %p, %08lx)\n", store, pCertContext, dwFlags);
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
return CRYPT_RegDeleteContext(store, &store->certsToDelete, pCertContext,
|
|
|
|
pCertInterface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_RegWriteCRL(HCERTSTORE hCertStore,
|
|
|
|
PCCRL_CONTEXT crl, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *store = hCertStore;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%p, %p, %ld)\n", hCertStore, crl, dwFlags);
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
return CRYPT_RegWriteContext(store, crl, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_RegDeleteCRL(HCERTSTORE hCertStore,
|
|
|
|
PCCRL_CONTEXT pCrlContext, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *store = hCertStore;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%p, %p, %08lx)\n", store, pCrlContext, dwFlags);
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
return CRYPT_RegDeleteContext(store, &store->crlsToDelete, pCrlContext,
|
|
|
|
pCRLInterface);
|
|
|
|
}
|
|
|
|
|
2008-08-29 14:33:24 +00:00
|
|
|
static BOOL WINAPI CRYPT_RegWriteCTL(HCERTSTORE hCertStore,
|
|
|
|
PCCTL_CONTEXT ctl, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *store = hCertStore;
|
2008-08-29 14:33:24 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%p, %p, %ld)\n", hCertStore, ctl, dwFlags);
|
2008-08-29 14:33:24 +00:00
|
|
|
|
|
|
|
return CRYPT_RegWriteContext(store, ctl, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_RegDeleteCTL(HCERTSTORE hCertStore,
|
|
|
|
PCCTL_CONTEXT pCtlContext, DWORD dwFlags)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *store = hCertStore;
|
2008-08-29 14:33:24 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%p, %p, %08lx)\n", store, pCtlContext, dwFlags);
|
2008-08-29 14:33:24 +00:00
|
|
|
|
|
|
|
return CRYPT_RegDeleteContext(store, &store->ctlsToDelete, pCtlContext,
|
|
|
|
pCTLInterface);
|
|
|
|
}
|
|
|
|
|
2007-08-16 17:54:03 +00:00
|
|
|
static BOOL WINAPI CRYPT_RegControl(HCERTSTORE hCertStore, DWORD dwFlags,
|
|
|
|
DWORD dwCtrlType, void const *pvCtrlPara)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *store = hCertStore;
|
2018-04-11 10:05:46 +00:00
|
|
|
BOOL ret = TRUE;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%p, %08lx, %ld, %p)\n", hCertStore, dwFlags, dwCtrlType,
|
2007-08-16 17:54:03 +00:00
|
|
|
pvCtrlPara);
|
|
|
|
|
|
|
|
switch (dwCtrlType)
|
|
|
|
{
|
|
|
|
case CERT_STORE_CTRL_RESYNC:
|
2007-10-18 18:13:20 +00:00
|
|
|
{
|
|
|
|
HCERTSTORE memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
|
|
|
|
2007-08-16 17:54:03 +00:00
|
|
|
CRYPT_RegFlushStore(store, FALSE);
|
2023-03-23 19:23:53 +00:00
|
|
|
CRYPT_RegReadFromReg(store->key, memStore, CERT_STORE_ADD_REPLACE_EXISTING);
|
2007-10-18 18:13:20 +00:00
|
|
|
I_CertUpdateStore(store->memStore, memStore, 0, 0);
|
|
|
|
CertCloseStore(memStore, 0);
|
2007-08-16 17:54:03 +00:00
|
|
|
break;
|
2007-10-18 18:13:20 +00:00
|
|
|
}
|
2007-08-16 17:54:03 +00:00
|
|
|
case CERT_STORE_CTRL_COMMIT:
|
|
|
|
ret = CRYPT_RegFlushStore(store,
|
|
|
|
dwFlags & CERT_STORE_CTRL_COMMIT_FORCE_FLAG);
|
|
|
|
break;
|
2010-05-14 20:37:26 +00:00
|
|
|
case CERT_STORE_CTRL_AUTO_RESYNC:
|
|
|
|
FIXME("CERT_STORE_CTRL_AUTO_RESYNC: stub\n");
|
2018-04-11 10:05:46 +00:00
|
|
|
break;
|
|
|
|
case CERT_STORE_CTRL_NOTIFY_CHANGE:
|
|
|
|
FIXME("CERT_STORE_CTRL_NOTIFY_CHANGE: stub\n");
|
2010-05-14 20:37:26 +00:00
|
|
|
break;
|
2007-08-16 17:54:03 +00:00
|
|
|
default:
|
2022-02-09 08:25:50 +00:00
|
|
|
FIXME("%lu: stub\n", dwCtrlType);
|
2007-08-16 17:54:03 +00:00
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *regProvFuncs[] = {
|
|
|
|
CRYPT_RegCloseStore,
|
|
|
|
NULL, /* CERT_STORE_PROV_READ_CERT_FUNC */
|
|
|
|
CRYPT_RegWriteCert,
|
|
|
|
CRYPT_RegDeleteCert,
|
|
|
|
NULL, /* CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC */
|
|
|
|
NULL, /* CERT_STORE_PROV_READ_CRL_FUNC */
|
|
|
|
CRYPT_RegWriteCRL,
|
|
|
|
CRYPT_RegDeleteCRL,
|
|
|
|
NULL, /* CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC */
|
|
|
|
NULL, /* CERT_STORE_PROV_READ_CTL_FUNC */
|
2008-08-29 14:33:24 +00:00
|
|
|
CRYPT_RegWriteCTL,
|
|
|
|
CRYPT_RegDeleteCTL,
|
2007-08-16 17:54:03 +00:00
|
|
|
NULL, /* CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC */
|
|
|
|
CRYPT_RegControl,
|
|
|
|
};
|
|
|
|
|
2013-09-04 10:38:51 +00:00
|
|
|
WINECRYPT_CERTSTORE *CRYPT_RegOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags,
|
2007-08-16 17:54:03 +00:00
|
|
|
const void *pvPara)
|
|
|
|
{
|
2013-09-04 10:38:51 +00:00
|
|
|
WINECRYPT_CERTSTORE *store = NULL;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
2022-02-09 08:25:50 +00:00
|
|
|
TRACE("(%Id, %08lx, %p)\n", hCryptProv, dwFlags, pvPara);
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
if (dwFlags & CERT_STORE_DELETE_FLAG)
|
|
|
|
{
|
2020-11-09 10:41:52 +00:00
|
|
|
DWORD rc = RegDeleteTreeW((HKEY)pvPara, L"Certificates");
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
if (rc == ERROR_SUCCESS || rc == ERROR_NO_MORE_ITEMS)
|
2020-11-09 10:41:52 +00:00
|
|
|
rc = RegDeleteTreeW((HKEY)pvPara, L"CRLs");
|
2007-08-16 17:54:03 +00:00
|
|
|
if (rc == ERROR_SUCCESS || rc == ERROR_NO_MORE_ITEMS)
|
2020-11-09 10:41:52 +00:00
|
|
|
rc = RegDeleteTreeW((HKEY)pvPara, L"CTLs");
|
2007-08-16 17:54:03 +00:00
|
|
|
if (rc == ERROR_NO_MORE_ITEMS)
|
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
SetLastError(rc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HKEY key;
|
|
|
|
|
|
|
|
if (DuplicateHandle(GetCurrentProcess(), (HANDLE)pvPara,
|
|
|
|
GetCurrentProcess(), (LPHANDLE)&key,
|
|
|
|
dwFlags & CERT_STORE_READONLY_FLAG ? KEY_READ : KEY_ALL_ACCESS,
|
|
|
|
TRUE, 0))
|
|
|
|
{
|
2013-09-04 10:38:51 +00:00
|
|
|
WINECRYPT_CERTSTORE *memStore;
|
2007-08-16 17:54:03 +00:00
|
|
|
|
|
|
|
memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, hCryptProv,
|
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
|
|
|
if (memStore)
|
|
|
|
{
|
2013-09-04 10:40:17 +00:00
|
|
|
WINE_REGSTOREINFO *regInfo = CryptMemAlloc(
|
2007-08-16 17:54:03 +00:00
|
|
|
sizeof(WINE_REGSTOREINFO));
|
|
|
|
|
|
|
|
if (regInfo)
|
|
|
|
{
|
|
|
|
CERT_STORE_PROV_INFO provInfo = { 0 };
|
|
|
|
|
|
|
|
regInfo->dwOpenFlags = dwFlags;
|
|
|
|
regInfo->memStore = memStore;
|
|
|
|
regInfo->key = key;
|
|
|
|
InitializeCriticalSection(®Info->cs);
|
|
|
|
regInfo->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PWINE_REGSTOREINFO->cs");
|
|
|
|
list_init(®Info->certsToDelete);
|
|
|
|
list_init(®Info->crlsToDelete);
|
2008-08-29 14:33:24 +00:00
|
|
|
list_init(®Info->ctlsToDelete);
|
2023-03-23 19:23:53 +00:00
|
|
|
CRYPT_RegReadFromReg(regInfo->key, regInfo->memStore, CERT_STORE_ADD_ALWAYS);
|
2007-08-16 17:54:03 +00:00
|
|
|
regInfo->dirty = FALSE;
|
|
|
|
provInfo.cbSize = sizeof(provInfo);
|
2018-06-20 07:37:55 +00:00
|
|
|
provInfo.cStoreProvFunc = ARRAY_SIZE(regProvFuncs);
|
2007-08-16 17:54:03 +00:00
|
|
|
provInfo.rgpvStoreProvFunc = regProvFuncs;
|
|
|
|
provInfo.hStoreProv = regInfo;
|
2007-08-17 18:59:28 +00:00
|
|
|
store = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo);
|
|
|
|
/* Reg store doesn't need crypto provider, so close it */
|
|
|
|
if (hCryptProv &&
|
|
|
|
!(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG))
|
|
|
|
CryptReleaseContext(hCryptProv, 0);
|
2007-08-16 17:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("returning %p\n", store);
|
|
|
|
return store;
|
|
|
|
}
|