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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "crypt32_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
35 static HCRYPTPROV hDefProv
;
37 BOOL WINAPI
DllMain(HINSTANCE hInstance
, DWORD fdwReason
, PVOID pvReserved
)
41 case DLL_PROCESS_ATTACH
:
42 DisableThreadLibraryCalls(hInstance
);
43 crypt_oid_init(hInstance
);
45 case DLL_PROCESS_DETACH
:
47 if (hDefProv
) CryptReleaseContext(hDefProv
, 0);
53 HCRYPTPROV
CRYPT_GetDefaultProvider(void)
56 CryptAcquireContextW(&hDefProv
, NULL
, MS_ENHANCED_PROV_W
,
57 PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
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;
76 BOOL WINAPI
I_CryptFindLruEntryData(DWORD unk0
, DWORD unk1
, DWORD unk2
)
78 FIXME("(%08lx, %08lx, %08lx): stub!\n", unk0
, unk1
, unk2
);
82 DWORD WINAPI
I_CryptFlushLruCache(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
84 FIXME("(%p, %08lx, %08lx): stub!\n", h
, unk0
, unk1
);
88 HLRUCACHE WINAPI
I_CryptFreeLruCache(HLRUCACHE h
, DWORD unk0
, DWORD unk1
)
90 FIXME("(%p, %08lx, %08lx): stub!\n", h
, unk0
, unk1
);
94 BOOL WINAPI
CryptSIPRemoveProvider(GUID
*pgProv
)
100 /* convert a guid to a wide character string */
101 static void CRYPT_guid2wstr( LPGUID guid
, LPWSTR wstr
)
105 sprintf(str
, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
106 guid
->Data1
, guid
->Data2
, guid
->Data3
,
107 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
108 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
109 MultiByteToWideChar( CP_ACP
, 0, str
, -1, wstr
, 40 );
113 * Helper for CryptSIPAddProvider
115 * Add a registry key containing a dll name and function under
116 * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>"
118 static LONG
CRYPT_SIPWriteFunction( LPGUID guid
, LPCWSTR szKey
,
119 LPCWSTR szDll
, LPCWSTR szFunction
)
121 static const WCHAR szOID
[] = {
122 'S','o','f','t','w','a','r','e','\\',
123 'M','i','c','r','o','s','o','f','t','\\',
124 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
126 'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\',
127 'C','r','y','p','t','S','I','P','D','l','l', 0 };
128 static const WCHAR szBackSlash
[] = { '\\', 0 };
129 static const WCHAR szDllName
[] = { 'D','l','l',0 };
130 static const WCHAR szFuncName
[] = { 'F','u','n','c','N','a','m','e',0 };
131 WCHAR szFullKey
[ 0x100 ];
136 return ERROR_SUCCESS
;
138 /* max length of szFullKey depends on our code only, so we won't overrun */
139 lstrcpyW( szFullKey
, szOID
);
140 lstrcatW( szFullKey
, szKey
);
141 lstrcatW( szFullKey
, szBackSlash
);
142 CRYPT_guid2wstr( guid
, &szFullKey
[ lstrlenW( szFullKey
) ] );
143 lstrcatW( szFullKey
, szBackSlash
);
145 TRACE("key is %s\n", debugstr_w( szFullKey
) );
147 r
= RegCreateKeyW( HKEY_LOCAL_MACHINE
, szFullKey
, &hKey
);
148 if( r
!= ERROR_SUCCESS
)
151 /* write the values */
152 RegSetValueExW( hKey
, szFuncName
, 0, REG_SZ
, (const BYTE
*) szFunction
,
153 ( lstrlenW( szFunction
) + 1 ) * sizeof (WCHAR
) );
154 RegSetValueExW( hKey
, szDllName
, 0, REG_SZ
, (const BYTE
*) szDll
,
155 ( lstrlenW( szDll
) + 1) * sizeof (WCHAR
) );
159 return ERROR_SUCCESS
;
162 BOOL WINAPI
CryptSIPAddProvider(SIP_ADD_NEWPROVIDER
*psNewProv
)
164 static const WCHAR szCreate
[] = {
165 'C','r','e','a','t','e',
166 'I','n','d','i','r','e','c','t','D','a','t','a',0};
167 static const WCHAR szGetSigned
[] = {
168 'G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
169 static const WCHAR szIsMyFile
[] = {
170 'I','s','M','y','F','i','l','e','T','y','p','e', 0 };
171 static const WCHAR szPutSigned
[] = {
172 'P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
173 static const WCHAR szRemoveSigned
[] = {
174 'R','e','m','o','v','e',
175 'S','i','g','n','e','d','D','a','t','a','M','s','g',0};
176 static const WCHAR szVerify
[] = {
177 'V','e','r','i','f','y',
178 'I','n','d','i','r','e','c','t','D','a','t','a',0};
180 TRACE("%p\n", psNewProv
);
185 TRACE("%s %s %s %s\n",
186 debugstr_guid( psNewProv
->pgSubject
),
187 debugstr_w( psNewProv
->pwszDLLFileName
),
188 debugstr_w( psNewProv
->pwszMagicNumber
),
189 debugstr_w( psNewProv
->pwszIsFunctionName
) );
191 #define CRYPT_SIPADDPROV( key, field ) \
192 CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
193 psNewProv->pwszDLLFileName, psNewProv->field)
195 CRYPT_SIPADDPROV( szGetSigned
, pwszGetFuncName
);
196 CRYPT_SIPADDPROV( szPutSigned
, pwszPutFuncName
);
197 CRYPT_SIPADDPROV( szCreate
, pwszCreateFuncName
);
198 CRYPT_SIPADDPROV( szVerify
, pwszVerifyFuncName
);
199 CRYPT_SIPADDPROV( szRemoveSigned
, pwszRemoveFuncName
);
200 CRYPT_SIPADDPROV( szIsMyFile
, pwszIsFunctionNameFmt2
);
202 #undef CRYPT_SIPADDPROV
207 BOOL WINAPI CryptSIPRetrieveSubjectGuid
208 (LPCWSTR FileName
, HANDLE hFileIn
, GUID
*pgSubject
)
214 BOOL WINAPI CryptSIPLoad
215 (const GUID
*pgSubject
, DWORD dwFlags
, SIP_DISPATCH_INFO
*pSipDispatch
)
221 LPVOID WINAPI
CryptMemAlloc(ULONG cbSize
)
223 return HeapAlloc(GetProcessHeap(), 0, cbSize
);
226 LPVOID WINAPI
CryptMemRealloc(LPVOID pv
, ULONG cbSize
)
228 return HeapReAlloc(GetProcessHeap(), 0, pv
, cbSize
);
231 VOID WINAPI
CryptMemFree(LPVOID pv
)
233 HeapFree(GetProcessHeap(), 0, pv
);
236 DWORD WINAPI
I_CryptAllocTls(void)
241 LPVOID WINAPI
I_CryptDetachTls(DWORD dwTlsIndex
)
245 ret
= TlsGetValue(dwTlsIndex
);
246 TlsSetValue(dwTlsIndex
, NULL
);
250 LPVOID WINAPI
I_CryptGetTls(DWORD dwTlsIndex
)
252 return TlsGetValue(dwTlsIndex
);
255 BOOL WINAPI
I_CryptSetTls(DWORD dwTlsIndex
, LPVOID lpTlsValue
)
257 return TlsSetValue(dwTlsIndex
, lpTlsValue
);
260 BOOL WINAPI
I_CryptFreeTls(DWORD dwTlsIndex
, DWORD unknown
)
262 TRACE("(%ld, %ld)\n", dwTlsIndex
, unknown
);
263 return TlsFree(dwTlsIndex
);
266 BOOL WINAPI
I_CryptGetOssGlobal(DWORD x
)
272 BOOL WINAPI
I_CryptInstallOssGlobal(DWORD x
, DWORD y
, DWORD z
)
274 FIXME("%08lx %08lx %08lx\n", x
, y
, z
);
278 BOOL WINAPI
I_CryptInstallAsn1Module(void *x
, DWORD y
, DWORD z
)
280 FIXME("%p %08lx %08lx\n", x
, y
, z
);
284 BOOL WINAPI
CryptQueryObject(DWORD dwObjectType
, const void* pvObject
,
285 DWORD dwExpectedContentTypeFlags
, DWORD dwExpectedFormatTypeFlags
,
286 DWORD dwFlags
, DWORD
* pdwMsgAndCertEncodingType
, DWORD
* pdwContentType
,
287 DWORD
* pdwFormatType
, HCERTSTORE
* phCertStore
, HCRYPTMSG
* phMsg
,
288 const void** ppvContext
)
290 FIXME( "%08lx %p %08lx %08lx %08lx %p %p %p %p %p %p", dwObjectType
,
291 pvObject
, dwExpectedContentTypeFlags
, dwExpectedFormatTypeFlags
,
292 dwFlags
, pdwMsgAndCertEncodingType
, pdwContentType
, pdwFormatType
,
293 phCertStore
, phMsg
, ppvContext
);
297 BOOL WINAPI
CryptVerifyMessageSignature(/*PCRYPT_VERIFY_MESSAGE_PARA*/ void* pVerifyPara
,
298 DWORD dwSignerIndex
, const BYTE
* pbSignedBlob
, DWORD cbSignedBlob
,
299 BYTE
* pbDecoded
, DWORD
* pcbDecoded
, PCCERT_CONTEXT
* ppSignerCert
)
301 FIXME("stub: %p, %ld, %p, %ld, %p, %p, %p\n",
302 pVerifyPara
, dwSignerIndex
, pbSignedBlob
, cbSignedBlob
,
303 pbDecoded
, pcbDecoded
, ppSignerCert
);