2002-04-03 21:55:13 +02:00
|
|
|
/*
|
2003-09-08 21:38:45 +02:00
|
|
|
* Copyright 2002 Mike McCormack for CodeWeavers
|
2005-06-14 13:38:36 +02:00
|
|
|
* Copyright 2005 Juan Lang
|
2002-04-03 21:55:13 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-04-03 21:55:13 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-12-11 05:26:05 +01:00
|
|
|
#include <stdio.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
2002-04-03 21:55:13 +02:00
|
|
|
#include "winbase.h"
|
2020-11-09 11:29:15 +01:00
|
|
|
#include "winternl.h"
|
2002-06-14 00:02:17 +02:00
|
|
|
#include "wincrypt.h"
|
2003-12-11 05:26:05 +01:00
|
|
|
#include "winreg.h"
|
2006-08-09 23:45:34 +02:00
|
|
|
#include "winuser.h"
|
2007-09-11 16:48:04 +02:00
|
|
|
#include "i_cryptasn1tls.h"
|
2005-08-25 11:51:59 +02:00
|
|
|
#include "crypt32_private.h"
|
2002-08-16 03:36:53 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
2002-06-14 00:02:17 +02:00
|
|
|
|
2005-08-25 11:51:59 +02:00
|
|
|
static HCRYPTPROV hDefProv;
|
2008-10-31 17:33:58 +01:00
|
|
|
HINSTANCE hInstance;
|
2021-10-31 17:09:05 +01:00
|
|
|
unixlib_handle_t crypt32_handle = 0;
|
2005-08-25 11:51:59 +02:00
|
|
|
|
2018-11-06 11:40:59 +01:00
|
|
|
static CRITICAL_SECTION prov_param_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG prov_param_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &prov_param_cs,
|
|
|
|
{ &prov_param_cs_debug.ProcessLocksList,
|
|
|
|
&prov_param_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": prov_param_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION prov_param_cs = { &prov_param_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2020-11-09 11:29:15 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, PVOID pvReserved)
|
2005-08-25 11:51:59 +02:00
|
|
|
{
|
2020-11-09 11:29:15 +01:00
|
|
|
switch (reason)
|
2005-08-25 11:51:59 +02:00
|
|
|
{
|
2005-12-02 11:28:09 +01:00
|
|
|
case DLL_PROCESS_ATTACH:
|
2008-10-31 17:33:58 +01:00
|
|
|
hInstance = hInst;
|
|
|
|
DisableThreadLibraryCalls(hInst);
|
2013-10-14 14:46:40 +02:00
|
|
|
init_empty_store();
|
2008-10-31 17:33:58 +01:00
|
|
|
crypt_oid_init();
|
2021-10-31 17:09:05 +01:00
|
|
|
if (NtQueryVirtualMemory( GetCurrentProcess(), hInst, MemoryWineUnixFuncs,
|
|
|
|
&crypt32_handle, sizeof(crypt32_handle), NULL ))
|
|
|
|
return FALSE;
|
|
|
|
CRYPT32_CALL( process_attach, NULL );
|
2005-12-02 11:28:09 +01:00
|
|
|
break;
|
2005-08-25 11:51:59 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
2013-05-15 10:16:05 +02:00
|
|
|
if (pvReserved) break;
|
2006-02-23 22:18:13 +01:00
|
|
|
crypt_oid_free();
|
2007-07-10 02:07:54 +02:00
|
|
|
crypt_sip_free();
|
2007-08-16 01:22:43 +02:00
|
|
|
default_chain_engine_free();
|
2013-05-15 10:16:05 +02:00
|
|
|
if (hDefProv) CryptReleaseContext(hDefProv, 0);
|
2021-10-31 17:09:05 +01:00
|
|
|
CRYPT32_CALL( process_detach, NULL );
|
2005-08-25 11:51:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-02 15:06:57 +01:00
|
|
|
static HCRYPTPROV CRYPT_GetDefaultProvider(void)
|
2005-08-25 11:51:59 +02:00
|
|
|
{
|
|
|
|
if (!hDefProv)
|
2008-01-14 20:15:35 +01:00
|
|
|
{
|
|
|
|
HCRYPTPROV prov;
|
|
|
|
|
2010-03-08 21:16:55 +01:00
|
|
|
if (!CryptAcquireContextW(&prov, NULL, MS_ENH_RSA_AES_PROV_W,
|
|
|
|
PROV_RSA_AES, CRYPT_VERIFYCONTEXT))
|
2009-11-06 13:18:14 +01:00
|
|
|
return hDefProv;
|
2008-01-14 20:15:35 +01:00
|
|
|
InterlockedCompareExchangePointer((PVOID *)&hDefProv, (PVOID)prov,
|
|
|
|
NULL);
|
|
|
|
if (hDefProv != prov)
|
|
|
|
CryptReleaseContext(prov, 0);
|
|
|
|
}
|
2005-08-25 11:51:59 +02:00
|
|
|
return hDefProv;
|
|
|
|
}
|
|
|
|
|
2005-11-28 20:52:13 +01:00
|
|
|
typedef void * HLRUCACHE;
|
|
|
|
|
|
|
|
/* this function is called by Internet Explorer when it is about to verify a
|
|
|
|
* downloaded component. The first parameter appears to be a pointer to an
|
|
|
|
* unknown type, native fails unless it points to a buffer of at least 20 bytes.
|
|
|
|
* The second parameter appears to be an out parameter, whatever it's set to is
|
|
|
|
* passed (by cryptnet.dll) to I_CryptFlushLruCache.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
|
2002-04-03 21:55:13 +02:00
|
|
|
{
|
2005-11-28 20:52:13 +01:00
|
|
|
FIXME("(%p, %p): stub!\n", unknown, out);
|
|
|
|
*out = (void *)0xbaadf00d;
|
|
|
|
return TRUE;
|
2002-04-03 21:55:13 +02:00
|
|
|
}
|
|
|
|
|
2007-10-18 19:36:28 +02:00
|
|
|
BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
|
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%08lx, %08lx): stub!\n", unk0, unk1);
|
2007-10-18 19:36:28 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-28 20:52:13 +01:00
|
|
|
BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
|
2002-04-03 21:55:13 +02:00
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%08lx, %08lx, %08lx): stub!\n", unk0, unk1, unk2);
|
2002-04-03 21:55:13 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-10-18 19:36:28 +02:00
|
|
|
BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
|
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%p, %08lx, %08lx): stub!\n", h, unk0, unk1);
|
2007-10-18 19:36:28 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-28 20:52:13 +01:00
|
|
|
DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
|
2002-04-03 21:55:13 +02:00
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%p, %08lx, %08lx): stub!\n", h, unk0, unk1);
|
2005-11-28 20:52:13 +01:00
|
|
|
return 0;
|
2002-04-03 21:55:13 +02:00
|
|
|
}
|
|
|
|
|
2005-11-28 20:52:13 +01:00
|
|
|
HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
|
2002-04-03 21:55:13 +02:00
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%p, %08lx, %08lx): stub!\n", h, unk0, unk1);
|
2005-11-28 20:52:13 +01:00
|
|
|
return h;
|
2002-04-03 21:55:13 +02:00
|
|
|
}
|
2002-06-14 00:02:17 +02:00
|
|
|
|
2005-10-27 12:24:20 +02:00
|
|
|
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, cbSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
|
|
|
|
{
|
|
|
|
return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID WINAPI CryptMemFree(LPVOID pv)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pv);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI I_CryptAllocTls(void)
|
|
|
|
{
|
|
|
|
return TlsAlloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
|
|
|
|
{
|
|
|
|
LPVOID ret;
|
|
|
|
|
|
|
|
ret = TlsGetValue(dwTlsIndex);
|
|
|
|
TlsSetValue(dwTlsIndex, NULL);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
|
|
|
|
{
|
|
|
|
return TlsGetValue(dwTlsIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
|
|
|
|
{
|
|
|
|
return TlsSetValue(dwTlsIndex, lpTlsValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
|
|
|
|
{
|
2010-03-02 22:31:46 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2022-02-09 09:25:50 +01:00
|
|
|
TRACE("(%ld, %ld)\n", dwTlsIndex, unknown);
|
2010-03-02 22:31:46 +01:00
|
|
|
|
|
|
|
ret = TlsFree(dwTlsIndex);
|
|
|
|
if (!ret) SetLastError( E_INVALIDARG );
|
|
|
|
return ret;
|
2005-10-27 12:24:20 +02:00
|
|
|
}
|
2006-01-23 11:54:58 +01:00
|
|
|
|
|
|
|
BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
|
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("%08lx\n", x);
|
2006-01-23 11:54:58 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-11-06 11:40:59 +01:00
|
|
|
static BOOL is_supported_algid(HCRYPTPROV prov, ALG_ID algid)
|
|
|
|
{
|
|
|
|
PROV_ENUMALGS prov_algs;
|
|
|
|
DWORD size = sizeof(prov_algs);
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
/* This enumeration is not thread safe */
|
|
|
|
EnterCriticalSection(&prov_param_cs);
|
|
|
|
if (CryptGetProvParam(prov, PP_ENUMALGS, (BYTE *)&prov_algs, &size, CRYPT_FIRST))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (prov_algs.aiAlgid == algid)
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (CryptGetProvParam(prov, PP_ENUMALGS, (BYTE *)&prov_algs, &size, CRYPT_NEXT));
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&prov_param_cs);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HCRYPTPROV WINAPI DECLSPEC_HOTPATCH I_CryptGetDefaultCryptProv(ALG_ID algid)
|
2006-08-09 23:45:34 +02:00
|
|
|
{
|
2018-11-06 11:40:59 +01:00
|
|
|
HCRYPTPROV prov, defprov;
|
|
|
|
|
|
|
|
TRACE("(%08x)\n", algid);
|
2006-08-12 05:37:04 +02:00
|
|
|
|
2018-11-06 11:40:59 +01:00
|
|
|
defprov = CRYPT_GetDefaultProvider();
|
2006-08-12 05:37:04 +02:00
|
|
|
|
2018-11-06 11:40:59 +01:00
|
|
|
if (algid && !is_supported_algid(defprov, algid))
|
2006-08-12 05:37:04 +02:00
|
|
|
{
|
2018-11-06 11:40:59 +01:00
|
|
|
DWORD i = 0, type, size;
|
|
|
|
|
|
|
|
while (CryptEnumProvidersW(i, NULL, 0, &type, NULL, &size))
|
|
|
|
{
|
|
|
|
WCHAR *name = CryptMemAlloc(size);
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
if (CryptEnumProvidersW(i, NULL, 0, &type, name, &size))
|
|
|
|
{
|
|
|
|
if (CryptAcquireContextW(&prov, NULL, name, type, CRYPT_VERIFYCONTEXT))
|
|
|
|
{
|
|
|
|
if (is_supported_algid(prov, algid))
|
|
|
|
{
|
|
|
|
CryptMemFree(name);
|
|
|
|
return prov;
|
|
|
|
}
|
|
|
|
CryptReleaseContext(prov, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CryptMemFree(name);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2006-08-12 05:37:04 +02:00
|
|
|
SetLastError(E_INVALIDARG);
|
2008-12-08 09:26:31 +01:00
|
|
|
return 0;
|
2006-08-12 05:37:04 +02:00
|
|
|
}
|
2018-11-06 11:40:59 +01:00
|
|
|
|
|
|
|
CryptContextAddRef(defprov, NULL, 0);
|
|
|
|
return defprov;
|
2006-08-09 23:45:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
|
|
|
|
DWORD *value)
|
|
|
|
{
|
|
|
|
HKEY key;
|
|
|
|
LONG rc;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s, %p)\n", debugstr_w(name), value);
|
|
|
|
|
2006-08-12 05:37:04 +02:00
|
|
|
*value = 0;
|
2020-11-09 11:41:52 +01:00
|
|
|
rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, L"Software\\Policies\\Microsoft\\SystemCertificates\\TrustedPublisher\\Safer", &key);
|
2006-08-09 23:45:34 +02:00
|
|
|
if (rc == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DWORD size = sizeof(DWORD);
|
|
|
|
|
|
|
|
if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
|
|
|
|
ret = TRUE;
|
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-04 03:13:39 +02:00
|
|
|
DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
|
2006-01-23 11:54:58 +01:00
|
|
|
{
|
2006-11-24 20:32:10 +01:00
|
|
|
static int ret = 8;
|
|
|
|
ret++;
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("%08lx %08lx %08lx, return value %d\n", x, y, z,ret);
|
2006-11-24 20:32:10 +01:00
|
|
|
return ret;
|
2006-01-23 11:54:58 +01:00
|
|
|
}
|
2006-02-13 13:22:25 +01:00
|
|
|
|
2007-09-11 16:48:04 +02:00
|
|
|
BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
|
2006-02-22 16:37:24 +01:00
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%p %08lx %p): stub\n", x, y, z);
|
2006-02-22 16:37:24 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-09-11 16:48:04 +02:00
|
|
|
BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
|
2006-08-09 23:45:34 +02:00
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%08lx): stub\n", x);
|
2006-08-09 23:45:34 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-09-11 16:48:04 +02:00
|
|
|
ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
|
2007-08-09 22:20:00 +02:00
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%08lx): stub\n", x);
|
2007-09-11 16:48:04 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
|
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("(%08lx): stub\n", x);
|
2007-08-09 22:20:00 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-05 17:12:44 +02:00
|
|
|
|
|
|
|
BOOL WINAPI CryptProtectMemory(void *data, DWORD len, DWORD flags)
|
|
|
|
{
|
2018-09-09 14:35:18 +02:00
|
|
|
static int fixme_once;
|
2022-02-09 09:25:50 +01:00
|
|
|
if (!fixme_once++) FIXME("(%p %lu %08lx): stub\n", data, len, flags);
|
2015-08-05 17:12:44 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI CryptUnprotectMemory(void *data, DWORD len, DWORD flags)
|
|
|
|
{
|
2018-09-09 14:35:18 +02:00
|
|
|
static int fixme_once;
|
2022-02-09 09:25:50 +01:00
|
|
|
if (!fixme_once++) FIXME("(%p %lu %08lx): stub\n", data, len, flags);
|
2015-08-05 17:12:44 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|