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
30 #include "i_cryptasn1tls.h"
31 #include "crypt32_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
36 static HCRYPTPROV hDefProv
;
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 if (__wine_init_unix_call())
60 CRYPT32_CALL( process_attach
, NULL
);
62 case DLL_PROCESS_DETACH
:
63 if (pvReserved
) break;
66 default_chain_engine_free();
67 if (hDefProv
) CryptReleaseContext(hDefProv
, 0);
68 CRYPT32_CALL( process_detach
, NULL
);
74 static HCRYPTPROV
CRYPT_GetDefaultProvider(void)
80 if (!CryptAcquireContextW(&prov
, NULL
, MS_ENH_RSA_AES_PROV_W
,
81 PROV_RSA_AES
, CRYPT_VERIFYCONTEXT
))
83 InterlockedCompareExchangePointer((PVOID
*)&hDefProv
, (PVOID
)prov
,
86 CryptReleaseContext(prov
, 0);
91 typedef void * HLRUCACHE
;
93 /* this function is called by Internet Explorer when it is about to verify a
94 * downloaded component. The first parameter appears to be a pointer to an
95 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
96 * The second parameter appears to be an out parameter, whatever it's set to is
97 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
99 BOOL WINAPI
I_CryptCreateLruCache(void *unknown
, HLRUCACHE
*out
)
101 FIXME("(%p, %p): stub!\n", unknown
, out
);
102 *out
= (void *)0xbaadf00d;
106 BOOL WINAPI
I_CryptFindLruEntry(DWORD unk0
, DWORD unk1
)
108 FIXME("(%08lx, %08lx): stub!\n", unk0
, unk1
);
112 BOOL WINAPI
I_CryptFindLruEntryData(DWORD unk0
, DWORD unk1
, DWORD unk2
)
114 FIXME("(%08lx, %08lx, %08lx): stub!\n", unk0
, unk1
, unk2
);
118 BOOL WINAPI
I_CryptCreateLruEntry(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
120 FIXME("(%p, %08lx, %08lx): stub!\n", h
, unk0
, unk1
);
124 DWORD WINAPI
I_CryptFlushLruCache(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
126 FIXME("(%p, %08lx, %08lx): stub!\n", h
, unk0
, unk1
);
130 HLRUCACHE WINAPI
I_CryptFreeLruCache(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
132 FIXME("(%p, %08lx, %08lx): stub!\n", h
, unk0
, unk1
);
136 LPVOID WINAPI
CryptMemAlloc(ULONG cbSize
)
138 return malloc(cbSize
);
141 LPVOID WINAPI
CryptMemRealloc(LPVOID pv
, ULONG cbSize
)
143 return realloc(pv
, cbSize
);
146 VOID WINAPI
CryptMemFree(LPVOID pv
)
151 DWORD WINAPI
I_CryptAllocTls(void)
156 LPVOID WINAPI
I_CryptDetachTls(DWORD dwTlsIndex
)
160 ret
= TlsGetValue(dwTlsIndex
);
161 TlsSetValue(dwTlsIndex
, NULL
);
165 LPVOID WINAPI
I_CryptGetTls(DWORD dwTlsIndex
)
167 return TlsGetValue(dwTlsIndex
);
170 BOOL WINAPI
I_CryptSetTls(DWORD dwTlsIndex
, LPVOID lpTlsValue
)
172 return TlsSetValue(dwTlsIndex
, lpTlsValue
);
175 BOOL WINAPI
I_CryptFreeTls(DWORD dwTlsIndex
, DWORD unknown
)
179 TRACE("(%ld, %ld)\n", dwTlsIndex
, unknown
);
181 ret
= TlsFree(dwTlsIndex
);
182 if (!ret
) SetLastError( E_INVALIDARG
);
186 BOOL WINAPI
I_CryptGetOssGlobal(DWORD x
)
192 static BOOL
is_supported_algid(HCRYPTPROV prov
, ALG_ID algid
)
194 PROV_ENUMALGS prov_algs
;
195 DWORD size
= sizeof(prov_algs
);
198 /* This enumeration is not thread safe */
199 EnterCriticalSection(&prov_param_cs
);
200 if (CryptGetProvParam(prov
, PP_ENUMALGS
, (BYTE
*)&prov_algs
, &size
, CRYPT_FIRST
))
204 if (prov_algs
.aiAlgid
== algid
)
209 } while (CryptGetProvParam(prov
, PP_ENUMALGS
, (BYTE
*)&prov_algs
, &size
, CRYPT_NEXT
));
211 LeaveCriticalSection(&prov_param_cs
);
215 HCRYPTPROV WINAPI DECLSPEC_HOTPATCH
I_CryptGetDefaultCryptProv(ALG_ID algid
)
217 HCRYPTPROV prov
, defprov
;
219 TRACE("(%08x)\n", algid
);
221 defprov
= CRYPT_GetDefaultProvider();
223 if (algid
&& !is_supported_algid(defprov
, algid
))
225 DWORD i
= 0, type
, size
;
227 while (CryptEnumProvidersW(i
, NULL
, 0, &type
, NULL
, &size
))
229 WCHAR
*name
= CryptMemAlloc(size
);
232 if (CryptEnumProvidersW(i
, NULL
, 0, &type
, name
, &size
))
234 if (CryptAcquireContextW(&prov
, NULL
, name
, type
, CRYPT_VERIFYCONTEXT
))
236 if (is_supported_algid(prov
, algid
))
241 CryptReleaseContext(prov
, 0);
249 SetLastError(E_INVALIDARG
);
253 CryptContextAddRef(defprov
, NULL
, 0);
257 BOOL WINAPI
I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name
,
264 TRACE("(%s, %p)\n", debugstr_w(name
), value
);
267 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, L
"Software\\Policies\\Microsoft\\SystemCertificates\\TrustedPublisher\\Safer", &key
);
268 if (rc
== ERROR_SUCCESS
)
270 DWORD size
= sizeof(DWORD
);
272 if (!RegQueryValueExW(key
, name
, NULL
, NULL
, (LPBYTE
)value
, &size
))
279 DWORD WINAPI
I_CryptInstallOssGlobal(DWORD x
, DWORD y
, DWORD z
)
283 FIXME("%08lx %08lx %08lx, return value %d\n", x
, y
, z
,ret
);
287 BOOL WINAPI
I_CryptInstallAsn1Module(ASN1module_t x
, DWORD y
, void* z
)
289 FIXME("(%p %08lx %p): stub\n", x
, y
, z
);
293 BOOL WINAPI
I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x
)
295 FIXME("(%08lx): stub\n", x
);
299 ASN1decoding_t WINAPI
I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x
)
301 FIXME("(%08lx): stub\n", x
);
305 ASN1encoding_t WINAPI
I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x
)
307 FIXME("(%08lx): stub\n", x
);
311 BOOL WINAPI
CryptProtectMemory(void *data
, DWORD len
, DWORD flags
)
313 static int fixme_once
;
314 if (!fixme_once
++) FIXME("(%p %lu %08lx): stub\n", data
, len
, flags
);
318 BOOL WINAPI
CryptUnprotectMemory(void *data
, DWORD len
, DWORD flags
)
320 static int fixme_once
;
321 if (!fixme_once
++) FIXME("(%p %lu %08lx): stub\n", data
, len
, flags
);