2 * Copyright 2002 Mike McCormack for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
33 /* this function is called by Internet Explorer when it is about to verify a downloaded component */
34 BOOL WINAPI I_CryptCreateLruCache(DWORD x, DWORD y)
40 /* these functions all have an unknown number of args */
41 BOOL WINAPI I_CryptFindLruEntryData(DWORD x)
47 BOOL WINAPI I_CryptFlushLruCache(DWORD x)
53 BOOL WINAPI I_CryptFreeLruCache(DWORD x)
59 BOOL WINAPI CryptProtectData(DATA_BLOB* pDataIn, LPCWSTR szDataDescr, DATA_BLOB* pOptionalEntropy,
60 PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
61 DWORD dwFlags, DATA_BLOB* pDataOut)
67 BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
73 /* convert a guid to a wide character string */
74 static void CRYPT_guid2wstr( LPGUID guid, LPWSTR wstr )
78 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
79 guid->Data1, guid->Data2, guid->Data3,
80 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
81 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
82 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
86 * Helper for CryptSIPAddProvider
88 * Add a registry key containing a dll name and function under
89 * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>"
91 static LONG CRYPT_SIPWriteFunction( LPGUID guid, LPCWSTR szKey,
92 LPCWSTR szDll, LPCWSTR szFunction )
94 static const WCHAR szOID[] = {
95 'S','o','f','t','w','a','r','e','\\',
96 'M','i','c','r','o','s','o','f','t','\\',
97 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
99 'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\',
100 'C','r','y','p','t','S','I','P','D','l','l', 0 };
101 static const WCHAR szBackSlash[] = { '\\', 0 };
102 static const WCHAR szDllName[] = { 'D','l','l',0 };
103 static const WCHAR szFuncName[] = { 'F','u','n','c','N','a','m','e',0 };
104 WCHAR szFullKey[ 0x100 ];
109 return ERROR_SUCCESS;
111 /* max length of szFullKey depends on our code only, so we won't overrun */
112 lstrcpyW( szFullKey, szOID );
113 lstrcatW( szFullKey, szKey );
114 lstrcatW( szFullKey, szBackSlash );
115 CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] );
116 lstrcatW( szFullKey, szBackSlash );
118 TRACE("key is %s\n", debugstr_w( szFullKey ) );
120 r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey );
121 if( r != ERROR_SUCCESS )
124 /* write the values */
125 RegSetValueExW( hKey, szFuncName, 0, REG_SZ, (const BYTE*) szFunction,
126 ( lstrlenW( szFunction ) + 1 ) * sizeof (WCHAR) );
127 RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) szDll,
128 ( lstrlenW( szDll ) + 1) * sizeof (WCHAR) );
132 return ERROR_SUCCESS;
135 BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
137 static const WCHAR szCreate[] = {
138 'C','r','e','a','t','e',
139 'I','n','d','i','r','e','c','t','D','a','t','a',0};
140 static const WCHAR szGetSigned[] = {
141 'G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
142 static const WCHAR szIsMyFile[] = {
143 'I','s','M','y','F','i','l','e','T','y','p','e', 0 };
144 static const WCHAR szPutSigned[] = {
145 'P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
146 static const WCHAR szRemoveSigned[] = {
147 'R','e','m','o','v','e',
148 'S','i','g','n','e','d','D','a','t','a','M','s','g',0};
149 static const WCHAR szVerify[] = {
150 'V','e','r','i','f','y',
151 'I','n','d','i','r','e','c','t','D','a','t','a',0};
153 TRACE("%p\n", psNewProv);
158 TRACE("%s %s %s %s\n",
159 debugstr_guid( psNewProv->pgSubject ),
160 debugstr_w( psNewProv->pwszDLLFileName ),
161 debugstr_w( psNewProv->pwszMagicNumber ),
162 debugstr_w( psNewProv->pwszIsFunctionName ) );
164 #define CRYPT_SIPADDPROV( key, field ) \
165 CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
166 psNewProv->pwszDLLFileName, psNewProv->field)
168 CRYPT_SIPADDPROV( szGetSigned, pwszGetFuncName );
169 CRYPT_SIPADDPROV( szPutSigned, pwszPutFuncName );
170 CRYPT_SIPADDPROV( szCreate, pwszCreateFuncName );
171 CRYPT_SIPADDPROV( szVerify, pwszVerifyFuncName );
172 CRYPT_SIPADDPROV( szRemoveSigned, pwszRemoveFuncName );
173 CRYPT_SIPADDPROV( szIsMyFile, pwszIsFunctionNameFmt2 );
175 #undef CRYPT_SIPADDPROV
180 BOOL WINAPI CryptSIPRetrieveSubjectGuid
181 (LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
187 BOOL WINAPI CryptSIPLoad
188 (const GUID *pgSubject, DWORD dwFlags, SIP_DISPATCH_INFO *pSipDispatch)
194 BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
195 LPCSTR pszOID, LPCWSTR pwszValueName,
196 DWORD *pdwValueType, BYTE *pbValueData,
199 FIXME("(%lx,%s,%s,%s,%p,%p,%p) stub!\n", dwEncodingType, pszFuncName, pszOID,
200 debugstr_w(pwszValueName), pdwValueType, pbValueData, pcbValueData);
204 BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
205 LPCSTR pszFuncName, DWORD dwIndex,
208 FIXME("(%lx,%s,%lx,%s) stub!\n", dwEncodingType, pszFuncName, dwIndex,
209 debugstr_w(pwszDll));
213 BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
214 LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
217 static const char szOID[] = "Software\\Microsoft\\Cryptography\\OID";
218 static const char szType1[] = "EncodingType 1";
219 static const WCHAR szDllName[] = { 'D','l','l',0 };
224 TRACE("%lx %s %s %s %s\n", dwEncodingType, pszFuncName, pszOID,
225 debugstr_w(pwszDll), pszOverrideFuncName);
227 if( dwEncodingType & PKCS_7_ASN_ENCODING )
228 FIXME("PKCS_7_ASN_ENCODING not implemented\n");
230 if( dwEncodingType & X509_ASN_ENCODING )
232 /* construct the name of the key */
233 len = sizeof szOID + sizeof szType1 + 2 +
234 lstrlenA( pszFuncName ) + lstrlenA( pszOID );
235 szKey = HeapAlloc( GetProcessHeap(), 0, len );
238 sprintf( szKey, "%s\\%s\\%s\\%s",
239 szOID, szType1, pszFuncName, pszOID );
241 TRACE("Key name is %s\n", debugstr_a( szKey ) );
243 r = RegCreateKeyA( HKEY_LOCAL_MACHINE, szKey, &hKey );
244 HeapFree( GetProcessHeap(), 0, szKey );
245 if( r != ERROR_SUCCESS )
248 /* write the values */
249 RegSetValueExA( hKey, "FuncName", 0, REG_SZ, pszOverrideFuncName,
250 lstrlenA( pszOverrideFuncName ) + 1 );
251 RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) pwszDll,
252 (lstrlenW( pwszDll ) + 1) * sizeof (WCHAR) );