2005-11-17 21:02:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2002 Mike McCormack for CodeWeavers
|
|
|
|
* Copyright 2005 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
|
2006-07-06 10:19:03 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-11-17 21:02:48 +00:00
|
|
|
*/
|
|
|
|
|
2018-03-09 11:59:49 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2005-11-20 15:43:38 +00:00
|
|
|
|
2018-03-09 11:59:49 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincrypt.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winuser.h"
|
2008-05-10 18:43:43 +00:00
|
|
|
#include "i_cryptasn1tls.h"
|
2018-03-09 11:59:49 +00:00
|
|
|
#include "crypt32_private.h"
|
|
|
|
#include "wine/debug.h"
|
2005-11-17 21:02:48 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
|
|
|
|
|
|
|
static HCRYPTPROV hDefProv;
|
2008-12-27 11:03:19 +00:00
|
|
|
HINSTANCE hInstance;
|
2005-11-17 21:02:48 +00:00
|
|
|
|
2008-12-27 11:03:19 +00:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, PVOID pvReserved)
|
2005-11-17 21:02:48 +00:00
|
|
|
{
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
2005-12-12 22:56:08 +00:00
|
|
|
case DLL_PROCESS_ATTACH:
|
2008-12-27 11:03:19 +00:00
|
|
|
hInstance = hInst;
|
|
|
|
DisableThreadLibraryCalls(hInst);
|
2014-04-22 15:10:43 +00:00
|
|
|
init_empty_store();
|
2008-12-27 11:03:19 +00:00
|
|
|
crypt_oid_init();
|
2005-12-12 22:56:08 +00:00
|
|
|
break;
|
2005-11-17 21:02:48 +00:00
|
|
|
case DLL_PROCESS_DETACH:
|
2013-09-15 13:58:50 +00:00
|
|
|
if (pvReserved) break;
|
2006-04-16 19:12:28 +00:00
|
|
|
crypt_oid_free();
|
2008-05-10 18:43:43 +00:00
|
|
|
crypt_sip_free();
|
|
|
|
default_chain_engine_free();
|
2013-09-15 13:58:50 +00:00
|
|
|
if (hDefProv) CryptReleaseContext(hDefProv, 0);
|
2005-11-17 21:02:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HCRYPTPROV CRYPT_GetDefaultProvider(void)
|
|
|
|
{
|
|
|
|
if (!hDefProv)
|
2008-05-10 18:43:43 +00:00
|
|
|
{
|
|
|
|
HCRYPTPROV prov;
|
|
|
|
|
2010-03-21 14:58:20 +00:00
|
|
|
if (!CryptAcquireContextW(&prov, NULL, MS_ENH_RSA_AES_PROV_W,
|
|
|
|
PROV_RSA_AES, CRYPT_VERIFYCONTEXT))
|
2009-11-15 22:58:08 +00:00
|
|
|
return hDefProv;
|
2009-01-22 13:51:17 +00:00
|
|
|
InterlockedCompareExchangePointer((PVOID *)&hDefProv, (PVOID)prov,
|
2008-11-25 14:17:27 +00:00
|
|
|
NULL);
|
|
|
|
if (hDefProv != prov)
|
2008-05-10 18:43:43 +00:00
|
|
|
CryptReleaseContext(prov, 0);
|
|
|
|
}
|
2005-11-17 21:02:48 +00:00
|
|
|
return hDefProv;
|
|
|
|
}
|
|
|
|
|
2005-12-12 22:56:08 +00: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)
|
2005-11-17 21:02:48 +00:00
|
|
|
{
|
2005-12-12 22:56:08 +00:00
|
|
|
FIXME("(%p, %p): stub!\n", unknown, out);
|
|
|
|
*out = (void *)0xbaadf00d;
|
|
|
|
return TRUE;
|
2005-11-17 21:02:48 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 18:43:43 +00:00
|
|
|
BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
|
|
|
|
{
|
|
|
|
FIXME("(%08x, %08x): stub!\n", unk0, unk1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-12-12 22:56:08 +00:00
|
|
|
BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
|
2005-11-17 21:02:48 +00:00
|
|
|
{
|
2007-04-26 13:37:57 +00:00
|
|
|
FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
|
2005-11-17 21:02:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-05-10 18:43:43 +00:00
|
|
|
BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-12-12 22:56:08 +00:00
|
|
|
DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
|
2005-11-17 21:02:48 +00:00
|
|
|
{
|
2007-04-26 13:37:57 +00:00
|
|
|
FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
|
2005-12-12 22:56:08 +00:00
|
|
|
return 0;
|
2005-11-17 21:02:48 +00:00
|
|
|
}
|
|
|
|
|
2005-12-12 22:56:08 +00:00
|
|
|
HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
|
2005-11-17 21:02:48 +00:00
|
|
|
{
|
2007-04-26 13:37:57 +00:00
|
|
|
FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
|
2005-12-12 22:56:08 +00:00
|
|
|
return h;
|
2005-11-17 21:02:48 +00: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);
|
2005-11-20 15:43:38 +00:00
|
|
|
TlsSetValue(dwTlsIndex, NULL);
|
2005-11-17 21:02:48 +00:00
|
|
|
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-06 11:06:56 +00:00
|
|
|
BOOL ret;
|
|
|
|
|
2007-04-26 13:37:57 +00:00
|
|
|
TRACE("(%d, %d)\n", dwTlsIndex, unknown);
|
2010-03-06 11:06:56 +00:00
|
|
|
|
|
|
|
ret = TlsFree(dwTlsIndex);
|
|
|
|
if (!ret) SetLastError( E_INVALIDARG );
|
|
|
|
return ret;
|
2005-11-17 21:02:48 +00:00
|
|
|
}
|
2006-04-16 19:12:28 +00:00
|
|
|
|
|
|
|
BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
|
|
|
|
{
|
2007-04-26 13:37:57 +00:00
|
|
|
FIXME("%08x\n", x);
|
2006-04-16 19:12:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-26 13:37:57 +00:00
|
|
|
HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
|
2006-04-16 19:12:28 +00:00
|
|
|
{
|
2007-04-26 13:37:57 +00:00
|
|
|
HCRYPTPROV ret;
|
|
|
|
|
|
|
|
TRACE("(%08x)\n", reserved);
|
|
|
|
|
|
|
|
if (reserved)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
2008-12-27 11:03:19 +00:00
|
|
|
return 0;
|
2007-04-26 13:37:57 +00:00
|
|
|
}
|
|
|
|
ret = CRYPT_GetDefaultProvider();
|
|
|
|
CryptContextAddRef(ret, NULL, 0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
|
|
|
|
DWORD *value)
|
|
|
|
{
|
2008-05-10 18:43:43 +00:00
|
|
|
static const WCHAR safer[] = {
|
2007-04-26 13:37:57 +00:00
|
|
|
'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
|
|
|
|
'C','e','r','t','i','f','i','c','a','t','e','s','\\',
|
|
|
|
'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
|
|
|
|
'S','a','f','e','r',0 };
|
|
|
|
HKEY key;
|
|
|
|
LONG rc;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s, %p)\n", debugstr_w(name), value);
|
|
|
|
|
|
|
|
*value = 0;
|
|
|
|
rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
|
|
|
|
if (rc == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DWORD size = sizeof(DWORD);
|
|
|
|
|
|
|
|
if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
|
|
|
|
ret = TRUE;
|
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-10 18:43:43 +00:00
|
|
|
DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
|
2007-04-26 13:37:57 +00:00
|
|
|
{
|
|
|
|
static int ret = 8;
|
|
|
|
ret++;
|
|
|
|
FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
|
|
|
|
return ret;
|
2006-04-16 19:12:28 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 18:43:43 +00:00
|
|
|
BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
|
2006-04-16 19:12:28 +00:00
|
|
|
{
|
2008-05-10 18:43:43 +00:00
|
|
|
FIXME("(%p %08x %p): stub\n", x, y, z);
|
2006-04-16 19:12:28 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-05-10 18:43:43 +00:00
|
|
|
BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
|
2007-04-26 13:37:57 +00:00
|
|
|
{
|
2008-05-10 18:43:43 +00:00
|
|
|
FIXME("(%08x): stub\n", x);
|
2007-04-26 13:37:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-05-10 18:43:43 +00:00
|
|
|
ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
|
2007-04-26 13:37:57 +00:00
|
|
|
{
|
2008-05-10 18:43:43 +00:00
|
|
|
FIXME("(%08x): stub\n", x);
|
|
|
|
return NULL;
|
2007-04-26 13:37:57 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 18:43:43 +00:00
|
|
|
ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
|
2006-04-16 19:12:28 +00:00
|
|
|
{
|
2008-05-10 18:43:43 +00:00
|
|
|
FIXME("(%08x): stub\n", x);
|
|
|
|
return NULL;
|
2006-04-16 19:12:28 +00:00
|
|
|
}
|
2015-11-17 21:12:00 +00:00
|
|
|
|
|
|
|
BOOL WINAPI CryptProtectMemory(void *data, DWORD len, DWORD flags)
|
|
|
|
{
|
2018-10-01 11:47:51 +00:00
|
|
|
static int fixme_once;
|
|
|
|
if (!fixme_once++) FIXME("(%p %u %08x): stub\n", data, len, flags);
|
2015-11-17 21:12:00 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI CryptUnprotectMemory(void *data, DWORD len, DWORD flags)
|
|
|
|
{
|
|
|
|
static int fixme_once;
|
|
|
|
if (!fixme_once++) FIXME("(%p %u %08x): stub\n", data, len, flags);
|
|
|
|
return TRUE;
|
|
|
|
}
|