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
32 #include "crypt32_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
37 static HCRYPTPROV hDefProv
;
39 BOOL WINAPI
DllMain(HINSTANCE hInstance
, DWORD fdwReason
, PVOID pvReserved
)
43 case DLL_PROCESS_ATTACH
:
44 DisableThreadLibraryCalls(hInstance
);
45 crypt_oid_init(hInstance
);
47 case DLL_PROCESS_DETACH
:
49 if (hDefProv
) CryptReleaseContext(hDefProv
, 0);
55 HCRYPTPROV
CRYPT_GetDefaultProvider(void)
58 CryptAcquireContextW(&hDefProv
, NULL
, MS_ENHANCED_PROV_W
,
59 PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
63 typedef void * HLRUCACHE
;
65 /* this function is called by Internet Explorer when it is about to verify a
66 * downloaded component. The first parameter appears to be a pointer to an
67 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
68 * The second parameter appears to be an out parameter, whatever it's set to is
69 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
71 BOOL WINAPI
I_CryptCreateLruCache(void *unknown
, HLRUCACHE
*out
)
73 FIXME("(%p, %p): stub!\n", unknown
, out
);
74 *out
= (void *)0xbaadf00d;
78 BOOL WINAPI
I_CryptFindLruEntryData(DWORD unk0
, DWORD unk1
, DWORD unk2
)
80 FIXME("(%08lx, %08lx, %08lx): stub!\n", unk0
, unk1
, unk2
);
84 DWORD WINAPI
I_CryptFlushLruCache(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
86 FIXME("(%p, %08lx, %08lx): stub!\n", h
, unk0
, unk1
);
90 HLRUCACHE WINAPI
I_CryptFreeLruCache(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
92 FIXME("(%p, %08lx, %08lx): stub!\n", h
, unk0
, unk1
);
96 BOOL WINAPI
CryptSIPRemoveProvider(GUID
*pgProv
)
102 /* convert a guid to a wide character string */
103 static void CRYPT_guid2wstr( LPGUID guid
, LPWSTR wstr
)
107 sprintf(str
, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
108 guid
->Data1
, guid
->Data2
, guid
->Data3
,
109 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
110 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
111 MultiByteToWideChar( CP_ACP
, 0, str
, -1, wstr
, 40 );
115 * Helper for CryptSIPAddProvider
117 * Add a registry key containing a dll name and function under
118 * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>"
120 static LONG
CRYPT_SIPWriteFunction( LPGUID guid
, LPCWSTR szKey
,
121 LPCWSTR szDll
, LPCWSTR szFunction
)
123 static const WCHAR szOID
[] = {
124 'S','o','f','t','w','a','r','e','\\',
125 'M','i','c','r','o','s','o','f','t','\\',
126 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
128 'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\',
129 'C','r','y','p','t','S','I','P','D','l','l', 0 };
130 static const WCHAR szBackSlash
[] = { '\\', 0 };
131 static const WCHAR szDllName
[] = { 'D','l','l',0 };
132 static const WCHAR szFuncName
[] = { 'F','u','n','c','N','a','m','e',0 };
133 WCHAR szFullKey
[ 0x100 ];
134 LONG r
= ERROR_SUCCESS
;
138 return ERROR_SUCCESS
;
140 /* max length of szFullKey depends on our code only, so we won't overrun */
141 lstrcpyW( szFullKey
, szOID
);
142 lstrcatW( szFullKey
, szKey
);
143 lstrcatW( szFullKey
, szBackSlash
);
144 CRYPT_guid2wstr( guid
, &szFullKey
[ lstrlenW( szFullKey
) ] );
145 lstrcatW( szFullKey
, szBackSlash
);
147 TRACE("key is %s\n", debugstr_w( szFullKey
) );
149 r
= RegCreateKeyW( HKEY_LOCAL_MACHINE
, szFullKey
, &hKey
);
150 if( r
!= ERROR_SUCCESS
) goto error_close_key
;
152 /* write the values */
153 r
= RegSetValueExW( hKey
, szFuncName
, 0, REG_SZ
, (const BYTE
*) szFunction
,
154 ( lstrlenW( szFunction
) + 1 ) * sizeof (WCHAR
) );
155 if( r
!= ERROR_SUCCESS
) goto error_close_key
;
156 r
= RegSetValueExW( hKey
, szDllName
, 0, REG_SZ
, (const BYTE
*) szDll
,
157 ( lstrlenW( szDll
) + 1) * sizeof (WCHAR
) );
166 BOOL WINAPI
CryptSIPAddProvider(SIP_ADD_NEWPROVIDER
*psNewProv
)
168 static const WCHAR szCreate
[] = {
169 'C','r','e','a','t','e',
170 'I','n','d','i','r','e','c','t','D','a','t','a',0};
171 static const WCHAR szGetSigned
[] = {
172 'G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
173 static const WCHAR szIsMyFile
[] = {
174 'I','s','M','y','F','i','l','e','T','y','p','e', 0 };
175 static const WCHAR szPutSigned
[] = {
176 'P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
177 static const WCHAR szRemoveSigned
[] = {
178 'R','e','m','o','v','e',
179 'S','i','g','n','e','d','D','a','t','a','M','s','g',0};
180 static const WCHAR szVerify
[] = {
181 'V','e','r','i','f','y',
182 'I','n','d','i','r','e','c','t','D','a','t','a',0};
184 TRACE("%p\n", psNewProv
);
187 psNewProv
->cbStruct
!= sizeof(SIP_ADD_NEWPROVIDER
) ||
188 !psNewProv
->pwszGetFuncName
||
189 !psNewProv
->pwszPutFuncName
||
190 !psNewProv
->pwszCreateFuncName
||
191 !psNewProv
->pwszVerifyFuncName
||
192 !psNewProv
->pwszRemoveFuncName
)
194 SetLastError(ERROR_INVALID_PARAMETER
);
198 TRACE("%s %s %s %s\n",
199 debugstr_guid( psNewProv
->pgSubject
),
200 debugstr_w( psNewProv
->pwszDLLFileName
),
201 debugstr_w( psNewProv
->pwszMagicNumber
),
202 debugstr_w( psNewProv
->pwszIsFunctionName
) );
204 #define CRYPT_SIPADDPROV( key, field ) \
205 CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
206 psNewProv->pwszDLLFileName, psNewProv->field)
208 CRYPT_SIPADDPROV( szGetSigned
, pwszGetFuncName
);
209 CRYPT_SIPADDPROV( szPutSigned
, pwszPutFuncName
);
210 CRYPT_SIPADDPROV( szCreate
, pwszCreateFuncName
);
211 CRYPT_SIPADDPROV( szVerify
, pwszVerifyFuncName
);
212 CRYPT_SIPADDPROV( szRemoveSigned
, pwszRemoveFuncName
);
213 CRYPT_SIPADDPROV( szIsMyFile
, pwszIsFunctionNameFmt2
);
215 #undef CRYPT_SIPADDPROV
220 /***********************************************************************
221 * CryptSIPRetrieveSubjectGuid (CRYPT32.@)
223 * Determine the right SIP GUID for the given file.
226 * FileName [I] Filename.
227 * hFileIn [I] Optional handle to the file.
228 * pgSubject [O] The SIP's GUID.
231 * Success: TRUE. pgSubject contains the SIP GUID.
232 * Failure: FALSE. (Look at GetLastError()).
235 BOOL WINAPI CryptSIPRetrieveSubjectGuid
236 (LPCWSTR FileName
, HANDLE hFileIn
, GUID
*pgSubject
)
238 FIXME("(%s %p %p) stub!\n", wine_dbgstr_w(FileName
), hFileIn
, pgSubject
);
242 /***********************************************************************
243 * CryptSIPLoad (CRYPT32.@)
245 * Load the functions for the given SIP.
248 * pgSubject [I] The GUID.
250 * pSipDispatch [I] The loaded functions.
253 * Success: TRUE. pSipDispatch contains the functions.
254 * Failure: FALSE. (Look at GetLastError()).
257 * Testing shows that (somehow) the table of functions is cached between
261 BOOL WINAPI CryptSIPLoad
262 (const GUID
*pgSubject
, DWORD dwFlags
, SIP_DISPATCH_INFO
*pSipDispatch
)
264 FIXME("(%s %ld %p) stub!\n", debugstr_guid(pgSubject
), dwFlags
, pSipDispatch
);
268 LPVOID WINAPI
CryptMemAlloc(ULONG cbSize
)
270 return HeapAlloc(GetProcessHeap(), 0, cbSize
);
273 LPVOID WINAPI
CryptMemRealloc(LPVOID pv
, ULONG cbSize
)
275 return HeapReAlloc(GetProcessHeap(), 0, pv
, cbSize
);
278 VOID WINAPI
CryptMemFree(LPVOID pv
)
280 HeapFree(GetProcessHeap(), 0, pv
);
283 DWORD WINAPI
I_CryptAllocTls(void)
288 LPVOID WINAPI
I_CryptDetachTls(DWORD dwTlsIndex
)
292 ret
= TlsGetValue(dwTlsIndex
);
293 TlsSetValue(dwTlsIndex
, NULL
);
297 LPVOID WINAPI
I_CryptGetTls(DWORD dwTlsIndex
)
299 return TlsGetValue(dwTlsIndex
);
302 BOOL WINAPI
I_CryptSetTls(DWORD dwTlsIndex
, LPVOID lpTlsValue
)
304 return TlsSetValue(dwTlsIndex
, lpTlsValue
);
307 BOOL WINAPI
I_CryptFreeTls(DWORD dwTlsIndex
, DWORD unknown
)
309 TRACE("(%ld, %ld)\n", dwTlsIndex
, unknown
);
310 return TlsFree(dwTlsIndex
);
313 BOOL WINAPI
I_CryptGetOssGlobal(DWORD x
)
319 HCRYPTPROV WINAPI
I_CryptGetDefaultCryptProv(DWORD reserved
)
323 TRACE("(%08lx)\n", reserved
);
327 SetLastError(E_INVALIDARG
);
328 return (HCRYPTPROV
)0;
330 ret
= CRYPT_GetDefaultProvider();
331 CryptContextAddRef(ret
, NULL
, 0);
335 BOOL WINAPI
I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name
,
338 static const WCHAR safer
[] = {
339 'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
340 'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
341 'C','e','r','t','i','f','i','c','a','t','e','s','\\',
342 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
343 'S','a','f','e','r',0 };
348 TRACE("(%s, %p)\n", debugstr_w(name
), value
);
351 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, safer
, &key
);
352 if (rc
== ERROR_SUCCESS
)
354 DWORD size
= sizeof(DWORD
);
356 if (!RegQueryValueExW(key
, name
, NULL
, NULL
, (LPBYTE
)value
, &size
))
363 BOOL WINAPI
I_CryptInstallOssGlobal(DWORD x
, DWORD y
, DWORD z
)
365 FIXME("%08lx %08lx %08lx\n", x
, y
, z
);
369 BOOL WINAPI
I_CryptInstallAsn1Module(void *x
, DWORD y
, DWORD z
)
371 FIXME("%p %08lx %08lx\n", x
, y
, z
);
375 BOOL WINAPI
I_CryptUninstallAsn1Module(void *x
)
381 BOOL WINAPI
CryptFormatObject(DWORD dwCertEncodingType
, DWORD dwFormatType
,
382 DWORD dwFormatStrType
, void *pFormatStruct
, LPCSTR lpszStructType
,
383 const BYTE
*pbEncoded
, DWORD cbEncoded
, void *pbFormat
, DWORD
*pcbFormat
)
385 FIXME("(%08lx, %ld, %ld, %p, %s, %p, %ld, %p, %p): stub\n",
386 dwCertEncodingType
, dwFormatType
, dwFormatStrType
, pFormatStruct
,
387 debugstr_a(lpszStructType
), pbEncoded
, cbEncoded
, pbFormat
, pcbFormat
);
391 BOOL WINAPI
CryptQueryObject(DWORD dwObjectType
, const void* pvObject
,
392 DWORD dwExpectedContentTypeFlags
, DWORD dwExpectedFormatTypeFlags
,
393 DWORD dwFlags
, DWORD
* pdwMsgAndCertEncodingType
, DWORD
* pdwContentType
,
394 DWORD
* pdwFormatType
, HCERTSTORE
* phCertStore
, HCRYPTMSG
* phMsg
,
395 const void** ppvContext
)
397 FIXME( "%08lx %p %08lx %08lx %08lx %p %p %p %p %p %p", dwObjectType
,
398 pvObject
, dwExpectedContentTypeFlags
, dwExpectedFormatTypeFlags
,
399 dwFlags
, pdwMsgAndCertEncodingType
, pdwContentType
, pdwFormatType
,
400 phCertStore
, phMsg
, ppvContext
);
404 BOOL WINAPI
CryptVerifyMessageSignature(PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara
,
405 DWORD dwSignerIndex
, const BYTE
* pbSignedBlob
, DWORD cbSignedBlob
,
406 BYTE
* pbDecoded
, DWORD
* pcbDecoded
, PCCERT_CONTEXT
* ppSignerCert
)
408 FIXME("stub: %p, %ld, %p, %ld, %p, %p, %p\n",
409 pVerifyPara
, dwSignerIndex
, pbSignedBlob
, cbSignedBlob
,
410 pbDecoded
, pcbDecoded
, ppSignerCert
);