2 * Copyright 2002 Mike McCormack for CodeWeavers
3 * Copyright 2005 Juan Lang
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "i_cryptasn1tls.h"
30 #include "crypt32_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
35 static HCRYPTPROV hDefProv
;
37 const struct unix_funcs
*unix_funcs
= NULL
;
39 static CRITICAL_SECTION prov_param_cs
;
40 static CRITICAL_SECTION_DEBUG prov_param_cs_debug
=
43 { &prov_param_cs_debug
.ProcessLocksList
,
44 &prov_param_cs_debug
.ProcessLocksList
},
45 0, 0, { (DWORD_PTR
)(__FILE__
": prov_param_cs") }
47 static CRITICAL_SECTION prov_param_cs
= { &prov_param_cs_debug
, -1, 0, 0, 0, 0 };
49 BOOL WINAPI
DllMain(HINSTANCE hInst
, DWORD reason
, PVOID pvReserved
)
53 case DLL_PROCESS_ATTACH
:
55 DisableThreadLibraryCalls(hInst
);
58 __wine_init_unix_lib( hInst
, reason
, NULL
, &unix_funcs
);
60 case DLL_PROCESS_DETACH
:
61 if (pvReserved
) break;
64 default_chain_engine_free();
65 if (hDefProv
) CryptReleaseContext(hDefProv
, 0);
66 __wine_init_unix_lib( hInst
, reason
, NULL
, NULL
);
72 static HCRYPTPROV
CRYPT_GetDefaultProvider(void)
78 if (!CryptAcquireContextW(&prov
, NULL
, MS_ENH_RSA_AES_PROV_W
,
79 PROV_RSA_AES
, CRYPT_VERIFYCONTEXT
))
81 InterlockedCompareExchangePointer((PVOID
*)&hDefProv
, (PVOID
)prov
,
84 CryptReleaseContext(prov
, 0);
89 typedef void * HLRUCACHE
;
91 /* this function is called by Internet Explorer when it is about to verify a
92 * downloaded component. The first parameter appears to be a pointer to an
93 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
94 * The second parameter appears to be an out parameter, whatever it's set to is
95 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
97 BOOL WINAPI
I_CryptCreateLruCache(void *unknown
, HLRUCACHE
*out
)
99 FIXME("(%p, %p): stub!\n", unknown
, out
);
100 *out
= (void *)0xbaadf00d;
104 BOOL WINAPI
I_CryptFindLruEntry(DWORD unk0
, DWORD unk1
)
106 FIXME("(%08x, %08x): stub!\n", unk0
, unk1
);
110 BOOL WINAPI
I_CryptFindLruEntryData(DWORD unk0
, DWORD unk1
, DWORD unk2
)
112 FIXME("(%08x, %08x, %08x): stub!\n", unk0
, unk1
, unk2
);
116 BOOL WINAPI
I_CryptCreateLruEntry(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
118 FIXME("(%p, %08x, %08x): stub!\n", h
, unk0
, unk1
);
122 DWORD WINAPI
I_CryptFlushLruCache(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
124 FIXME("(%p, %08x, %08x): stub!\n", h
, unk0
, unk1
);
128 HLRUCACHE WINAPI
I_CryptFreeLruCache(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
130 FIXME("(%p, %08x, %08x): stub!\n", h
, unk0
, unk1
);
134 LPVOID WINAPI
CryptMemAlloc(ULONG cbSize
)
136 return HeapAlloc(GetProcessHeap(), 0, cbSize
);
139 LPVOID WINAPI
CryptMemRealloc(LPVOID pv
, ULONG cbSize
)
141 return HeapReAlloc(GetProcessHeap(), 0, pv
, cbSize
);
144 VOID WINAPI
CryptMemFree(LPVOID pv
)
146 HeapFree(GetProcessHeap(), 0, pv
);
149 DWORD WINAPI
I_CryptAllocTls(void)
154 LPVOID WINAPI
I_CryptDetachTls(DWORD dwTlsIndex
)
158 ret
= TlsGetValue(dwTlsIndex
);
159 TlsSetValue(dwTlsIndex
, NULL
);
163 LPVOID WINAPI
I_CryptGetTls(DWORD dwTlsIndex
)
165 return TlsGetValue(dwTlsIndex
);
168 BOOL WINAPI
I_CryptSetTls(DWORD dwTlsIndex
, LPVOID lpTlsValue
)
170 return TlsSetValue(dwTlsIndex
, lpTlsValue
);
173 BOOL WINAPI
I_CryptFreeTls(DWORD dwTlsIndex
, DWORD unknown
)
177 TRACE("(%d, %d)\n", dwTlsIndex
, unknown
);
179 ret
= TlsFree(dwTlsIndex
);
180 if (!ret
) SetLastError( E_INVALIDARG
);
184 BOOL WINAPI
I_CryptGetOssGlobal(DWORD x
)
190 static BOOL
is_supported_algid(HCRYPTPROV prov
, ALG_ID algid
)
192 PROV_ENUMALGS prov_algs
;
193 DWORD size
= sizeof(prov_algs
);
196 /* This enumeration is not thread safe */
197 EnterCriticalSection(&prov_param_cs
);
198 if (CryptGetProvParam(prov
, PP_ENUMALGS
, (BYTE
*)&prov_algs
, &size
, CRYPT_FIRST
))
202 if (prov_algs
.aiAlgid
== algid
)
207 } while (CryptGetProvParam(prov
, PP_ENUMALGS
, (BYTE
*)&prov_algs
, &size
, CRYPT_NEXT
));
209 LeaveCriticalSection(&prov_param_cs
);
213 HCRYPTPROV WINAPI DECLSPEC_HOTPATCH
I_CryptGetDefaultCryptProv(ALG_ID algid
)
215 HCRYPTPROV prov
, defprov
;
217 TRACE("(%08x)\n", algid
);
219 defprov
= CRYPT_GetDefaultProvider();
221 if (algid
&& !is_supported_algid(defprov
, algid
))
223 DWORD i
= 0, type
, size
;
225 while (CryptEnumProvidersW(i
, NULL
, 0, &type
, NULL
, &size
))
227 WCHAR
*name
= CryptMemAlloc(size
);
230 if (CryptEnumProvidersW(i
, NULL
, 0, &type
, name
, &size
))
232 if (CryptAcquireContextW(&prov
, NULL
, name
, type
, CRYPT_VERIFYCONTEXT
))
234 if (is_supported_algid(prov
, algid
))
239 CryptReleaseContext(prov
, 0);
247 SetLastError(E_INVALIDARG
);
251 CryptContextAddRef(defprov
, NULL
, 0);
255 BOOL WINAPI
I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name
,
262 TRACE("(%s, %p)\n", debugstr_w(name
), value
);
265 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, L
"Software\\Policies\\Microsoft\\SystemCertificates\\TrustedPublisher\\Safer", &key
);
266 if (rc
== ERROR_SUCCESS
)
268 DWORD size
= sizeof(DWORD
);
270 if (!RegQueryValueExW(key
, name
, NULL
, NULL
, (LPBYTE
)value
, &size
))
277 DWORD WINAPI
I_CryptInstallOssGlobal(DWORD x
, DWORD y
, DWORD z
)
281 FIXME("%08x %08x %08x, return value %d\n", x
, y
, z
,ret
);
285 BOOL WINAPI
I_CryptInstallAsn1Module(ASN1module_t x
, DWORD y
, void* z
)
287 FIXME("(%p %08x %p): stub\n", x
, y
, z
);
291 BOOL WINAPI
I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x
)
293 FIXME("(%08x): stub\n", x
);
297 ASN1decoding_t WINAPI
I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x
)
299 FIXME("(%08x): stub\n", x
);
303 ASN1encoding_t WINAPI
I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x
)
305 FIXME("(%08x): stub\n", x
);
309 BOOL WINAPI
CryptProtectMemory(void *data
, DWORD len
, DWORD flags
)
311 static int fixme_once
;
312 if (!fixme_once
++) FIXME("(%p %u %08x): stub\n", data
, len
, flags
);
316 BOOL WINAPI
CryptUnprotectMemory(void *data
, DWORD len
, DWORD flags
)
318 static int fixme_once
;
319 if (!fixme_once
++) FIXME("(%p %u %08x): stub\n", data
, len
, flags
);