crypt32: Add tests for opening non-detached signed messages, and clarify detached...
[wine/wine64.git] / dlls / crypt32 / main.c
bloba377b24e7f487fa1b8423b465eb2815270023025
1 /*
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
20 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wincrypt.h"
27 #include "winreg.h"
28 #include "winuser.h"
29 #include "crypt32_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
34 static HCRYPTPROV hDefProv;
36 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
38 switch (fdwReason)
40 case DLL_PROCESS_ATTACH:
41 DisableThreadLibraryCalls(hInstance);
42 crypt_oid_init(hInstance);
43 break;
44 case DLL_PROCESS_DETACH:
45 crypt_oid_free();
46 crypt_sip_free();
47 if (hDefProv) CryptReleaseContext(hDefProv, 0);
48 break;
50 return TRUE;
53 HCRYPTPROV CRYPT_GetDefaultProvider(void)
55 if (!hDefProv)
56 CryptAcquireContextW(&hDefProv, NULL, MS_ENHANCED_PROV_W,
57 PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
58 return hDefProv;
61 typedef void * HLRUCACHE;
63 /* this function is called by Internet Explorer when it is about to verify a
64 * downloaded component. The first parameter appears to be a pointer to an
65 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
66 * The second parameter appears to be an out parameter, whatever it's set to is
67 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
69 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
71 FIXME("(%p, %p): stub!\n", unknown, out);
72 *out = (void *)0xbaadf00d;
73 return TRUE;
76 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
78 FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
79 return FALSE;
82 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
84 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
85 return 0;
88 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
90 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
91 return h;
94 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
96 return HeapAlloc(GetProcessHeap(), 0, cbSize);
99 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
101 return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
104 VOID WINAPI CryptMemFree(LPVOID pv)
106 HeapFree(GetProcessHeap(), 0, pv);
109 DWORD WINAPI I_CryptAllocTls(void)
111 return TlsAlloc();
114 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
116 LPVOID ret;
118 ret = TlsGetValue(dwTlsIndex);
119 TlsSetValue(dwTlsIndex, NULL);
120 return ret;
123 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
125 return TlsGetValue(dwTlsIndex);
128 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
130 return TlsSetValue(dwTlsIndex, lpTlsValue);
133 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
135 TRACE("(%d, %d)\n", dwTlsIndex, unknown);
136 return TlsFree(dwTlsIndex);
139 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
141 FIXME("%08x\n", x);
142 return FALSE;
145 HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
147 HCRYPTPROV ret;
149 TRACE("(%08x)\n", reserved);
151 if (reserved)
153 SetLastError(E_INVALIDARG);
154 return (HCRYPTPROV)0;
156 ret = CRYPT_GetDefaultProvider();
157 CryptContextAddRef(ret, NULL, 0);
158 return ret;
161 BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
162 DWORD *value)
164 static const WCHAR safer[] = {
165 'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
166 'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
167 'C','e','r','t','i','f','i','c','a','t','e','s','\\',
168 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
169 'S','a','f','e','r',0 };
170 HKEY key;
171 LONG rc;
172 BOOL ret = FALSE;
174 TRACE("(%s, %p)\n", debugstr_w(name), value);
176 *value = 0;
177 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
178 if (rc == ERROR_SUCCESS)
180 DWORD size = sizeof(DWORD);
182 if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
183 ret = TRUE;
184 RegCloseKey(key);
186 return ret;
189 int WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
191 static int ret = 8;
192 ret++;
193 FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
194 return ret;
197 BOOL WINAPI I_CryptInstallAsn1Module(void *x, DWORD y, DWORD z)
199 FIXME("%p %08x %08x\n", x, y, z);
200 return TRUE;
203 BOOL WINAPI I_CryptUninstallAsn1Module(void *x)
205 FIXME("%p\n", x);
206 return TRUE;
209 BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
210 DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
211 const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
213 FIXME("(%08x, %d, %d, %p, %s, %p, %d, %p, %p): stub\n",
214 dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct,
215 debugstr_a(lpszStructType), pbEncoded, cbEncoded, pbFormat, pcbFormat);
216 return FALSE;
219 BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void* pvObject,
220 DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags,
221 DWORD dwFlags, DWORD* pdwMsgAndCertEncodingType, DWORD* pdwContentType,
222 DWORD* pdwFormatType, HCERTSTORE* phCertStore, HCRYPTMSG* phMsg,
223 const void** ppvContext)
225 FIXME( "%08x %p %08x %08x %08x %p %p %p %p %p %p\n", dwObjectType,
226 pvObject, dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags,
227 dwFlags, pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType,
228 phCertStore, phMsg, ppvContext);
229 return FALSE;
232 BOOL WINAPI CryptVerifyMessageSignature(PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
233 DWORD dwSignerIndex, const BYTE* pbSignedBlob, DWORD cbSignedBlob,
234 BYTE* pbDecoded, DWORD* pcbDecoded, PCCERT_CONTEXT* ppSignerCert)
236 FIXME("stub: %p, %d, %p, %d, %p, %p, %p\n",
237 pVerifyPara, dwSignerIndex, pbSignedBlob, cbSignedBlob,
238 pbDecoded, pcbDecoded, ppSignerCert);
239 if (ppSignerCert)
240 *ppSignerCert = NULL;
241 return FALSE;