wrc: Store version and characteristics as simple integers.
[wine.git] / dlls / crypt32 / sip.c
blob132f491b2f1ec881757c1f96cfdb69693c4197ad
1 /*
2 * Copyright 2002 Mike McCormack for CodeWeavers
3 * Copyright 2005-2008 Juan Lang
4 * Copyright 2006 Paul Vriens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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 "winnls.h"
29 #include "mssip.h"
30 #include "winuser.h"
31 #include "crypt32_private.h"
33 #include "wine/debug.h"
34 #include "wine/list.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
38 /* convert a guid to a wide character string */
39 static void CRYPT_guid2wstr( const GUID *guid, LPWSTR wstr )
41 char str[40];
43 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
44 guid->Data1, guid->Data2, guid->Data3,
45 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
46 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
47 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
50 /***********************************************************************
51 * CRYPT_SIPDeleteFunction
53 * Helper function for CryptSIPRemoveProvider
55 static LONG CRYPT_SIPDeleteFunction( const GUID *guid, LPCWSTR szKey )
57 WCHAR szFullKey[ 0x100 ];
58 LONG r = ERROR_SUCCESS;
60 /* max length of szFullKey depends on our code only, so we won't overrun */
61 lstrcpyW( szFullKey, L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptSIPDll" );
62 lstrcatW( szFullKey, szKey );
63 CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] );
65 r = RegDeleteKeyW(HKEY_LOCAL_MACHINE, szFullKey);
67 return r;
70 /***********************************************************************
71 * CryptSIPRemoveProvider (CRYPT32.@)
73 * Remove a SIP provider and its functions from the registry.
75 * PARAMS
76 * pgProv [I] Pointer to a GUID for this SIP provider
78 * RETURNS
79 * Success: TRUE.
80 * Failure: FALSE. (Look at GetLastError()).
82 * NOTES
83 * Registry errors are always reported via SetLastError(). Every registry
84 * deletion will be tried.
86 BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
88 LONG r = ERROR_SUCCESS;
89 LONG remove_error = ERROR_SUCCESS;
91 TRACE("%s\n", debugstr_guid(pgProv));
93 if (!pgProv)
95 SetLastError(ERROR_INVALID_PARAMETER);
96 return FALSE;
100 #define CRYPT_SIPREMOVEPROV( key ) \
101 r = CRYPT_SIPDeleteFunction( pgProv, key); \
102 if (r != ERROR_SUCCESS) remove_error = r
104 CRYPT_SIPREMOVEPROV( L"PutSignedDataMsg\\" );
105 CRYPT_SIPREMOVEPROV( L"GetSignedDataMsg\\" );
106 CRYPT_SIPREMOVEPROV( L"RemoveSignedDataMsg\\" );
107 CRYPT_SIPREMOVEPROV( L"CreateIndirectData\\" );
108 CRYPT_SIPREMOVEPROV( L"VerifyIndirectData\\" );
109 CRYPT_SIPREMOVEPROV( L"IsMyFileType\\" );
110 CRYPT_SIPREMOVEPROV( L"IsMyFileType2\\" );
112 #undef CRYPT_SIPREMOVEPROV
114 if (remove_error != ERROR_SUCCESS)
116 SetLastError(remove_error);
117 return FALSE;
120 return TRUE;
124 * Helper for CryptSIPAddProvider
126 * Add a registry key containing a dll name and function under
127 * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>"
129 static LONG CRYPT_SIPWriteFunction( const GUID *guid, LPCWSTR szKey,
130 LPCWSTR szDll, LPCWSTR szFunction )
132 WCHAR szFullKey[ 0x100 ];
133 LONG r = ERROR_SUCCESS;
134 HKEY hKey;
136 if( !szFunction )
137 return ERROR_SUCCESS;
139 /* max length of szFullKey depends on our code only, so we won't overrun */
140 lstrcpyW( szFullKey, L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptSIPDll" );
141 lstrcatW( szFullKey, szKey );
142 CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] );
144 TRACE("key is %s\n", debugstr_w( szFullKey ) );
146 r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey );
147 if( r != ERROR_SUCCESS ) goto error_close_key;
149 /* write the values */
150 r = RegSetValueExW( hKey, L"FuncName", 0, REG_SZ, (const BYTE*) szFunction,
151 ( lstrlenW( szFunction ) + 1 ) * sizeof (WCHAR) );
152 if( r != ERROR_SUCCESS ) goto error_close_key;
153 r = RegSetValueExW( hKey, L"Dll", 0, REG_SZ, (const BYTE*) szDll,
154 ( lstrlenW( szDll ) + 1) * sizeof (WCHAR) );
156 error_close_key:
158 RegCloseKey( hKey );
160 return r;
163 /***********************************************************************
164 * CryptSIPAddProvider (CRYPT32.@)
166 * Add a SIP provider and its functions to the registry.
168 * PARAMS
169 * psNewProv [I] Pointer to a structure with information about
170 * the functions this SIP provider can perform.
172 * RETURNS
173 * Success: TRUE.
174 * Failure: FALSE. (Look at GetLastError()).
176 * NOTES
177 * Registry errors are always reported via SetLastError(). If a
178 * registry error occurs the rest of the registry write operations
179 * will be skipped.
181 BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
183 LONG r = ERROR_SUCCESS;
185 TRACE("%p\n", psNewProv);
187 if (!psNewProv ||
188 psNewProv->cbStruct < FIELD_OFFSET(SIP_ADD_NEWPROVIDER, pwszGetCapFuncName) ||
189 !psNewProv->pwszGetFuncName ||
190 !psNewProv->pwszPutFuncName ||
191 !psNewProv->pwszCreateFuncName ||
192 !psNewProv->pwszVerifyFuncName ||
193 !psNewProv->pwszRemoveFuncName)
195 SetLastError(ERROR_INVALID_PARAMETER);
196 return FALSE;
199 TRACE("%s %s %s %s %s\n",
200 debugstr_guid( psNewProv->pgSubject ),
201 debugstr_w( psNewProv->pwszDLLFileName ),
202 debugstr_w( psNewProv->pwszMagicNumber ),
203 debugstr_w( psNewProv->pwszIsFunctionName ),
204 debugstr_w( psNewProv->pwszIsFunctionNameFmt2 ) );
206 #define CRYPT_SIPADDPROV( key, field ) \
207 r = CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
208 psNewProv->pwszDLLFileName, psNewProv->field); \
209 if (r != ERROR_SUCCESS) goto end_function
211 CRYPT_SIPADDPROV( L"PutSignedDataMsg\\", pwszPutFuncName );
212 CRYPT_SIPADDPROV( L"GetSignedDataMsg\\", pwszGetFuncName );
213 CRYPT_SIPADDPROV( L"RemoveSignedDataMsg\\", pwszRemoveFuncName );
214 CRYPT_SIPADDPROV( L"CreateIndirectData\\", pwszCreateFuncName );
215 CRYPT_SIPADDPROV( L"VerifyIndirectData\\", pwszVerifyFuncName );
216 CRYPT_SIPADDPROV( L"IsMyFileType\\", pwszIsFunctionName );
217 CRYPT_SIPADDPROV( L"IsMyFileType2\\", pwszIsFunctionNameFmt2 );
219 #undef CRYPT_SIPADDPROV
221 end_function:
223 if (r != ERROR_SUCCESS)
225 SetLastError(r);
226 return FALSE;
229 return TRUE;
232 static void *CRYPT_LoadSIPFuncFromKey(HKEY key, HMODULE *pLib)
234 LONG r;
235 DWORD size;
236 WCHAR dllName[MAX_PATH];
237 char functionName[MAX_PATH];
238 HMODULE lib;
239 void *func = NULL;
241 /* Read the DLL entry */
242 size = sizeof(dllName);
243 r = RegQueryValueExW(key, L"Dll", NULL, NULL, (LPBYTE)dllName, &size);
244 if (r) goto end;
246 /* Read the Function entry */
247 size = sizeof(functionName);
248 r = RegQueryValueExA(key, "FuncName", NULL, NULL, (LPBYTE)functionName,
249 &size);
250 if (r) goto end;
252 lib = LoadLibraryW(dllName);
253 if (!lib)
254 goto end;
255 func = GetProcAddress(lib, functionName);
256 if (func)
257 *pLib = lib;
258 else
259 FreeLibrary(lib);
261 end:
262 return func;
265 /***********************************************************************
266 * CryptSIPRetrieveSubjectGuid (CRYPT32.@)
268 * Determine the right SIP GUID for the given file.
270 * PARAMS
271 * FileName [I] Filename.
272 * hFileIn [I] Optional handle to the file.
273 * pgSubject [O] The SIP's GUID.
275 * RETURNS
276 * Success: TRUE. pgSubject contains the SIP GUID.
277 * Failure: FALSE. (Look at GetLastError()).
279 * NOTES
280 * On failure pgSubject will contain a NULL GUID.
281 * The handle is always preferred above the filename.
283 BOOL WINAPI CryptSIPRetrieveSubjectGuid
284 (LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
286 HANDLE hFile;
287 BOOL bRet = FALSE;
288 DWORD count;
289 LARGE_INTEGER zero, oldPos;
290 /* FIXME, find out if there is a name for this GUID */
291 static const GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
292 static const GUID cabGUID = { 0xc689aaba, 0x8e78, 0x11d0, {0x8c,0x47,0x00,0xc0,0x4f,0xc2,0x95,0xee }};
293 static const GUID catGUID = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
294 static const WORD dosHdr = IMAGE_DOS_SIGNATURE;
295 static const BYTE cabHdr[] = { 'M','S','C','F' };
296 BYTE hdr[SIP_MAX_MAGIC_NUMBER];
297 LONG r = ERROR_SUCCESS;
298 HKEY key;
300 TRACE("(%s %p %p)\n", wine_dbgstr_w(FileName), hFileIn, pgSubject);
302 if (!pgSubject || (!FileName && !hFileIn))
304 SetLastError(ERROR_INVALID_PARAMETER);
305 return FALSE;
308 /* Set pgSubject to zero's */
309 memset(pgSubject, 0 , sizeof(GUID));
311 if (hFileIn)
312 /* Use the given handle, make sure not to close this one ourselves */
313 hFile = hFileIn;
314 else
316 hFile = CreateFileW(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
317 /* Last error is set by CreateFile */
318 if (hFile == INVALID_HANDLE_VALUE) return FALSE;
321 zero.QuadPart = 0;
322 SetFilePointerEx(hFile, zero, &oldPos, FILE_CURRENT);
323 SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
324 if (!ReadFile(hFile, hdr, sizeof(hdr), &count, NULL))
325 goto cleanup;
327 if (count < SIP_MAX_MAGIC_NUMBER)
329 SetLastError(ERROR_INVALID_PARAMETER);
330 goto cleanup;
333 TRACE("file magic = 0x%02x%02x%02x%02x\n", hdr[0], hdr[1], hdr[2], hdr[3]);
334 /* As everything is in place now we start looking at the file header */
335 if (!memcmp(hdr, &dosHdr, sizeof(dosHdr)))
337 *pgSubject = unknown;
338 SetLastError(S_OK);
339 bRet = TRUE;
340 goto cleanup;
342 /* Quick-n-dirty check for a cab file. */
343 if (!memcmp(hdr, cabHdr, sizeof(cabHdr)))
345 *pgSubject = cabGUID;
346 SetLastError(S_OK);
347 bRet = TRUE;
348 goto cleanup;
350 /* If it's asn.1-encoded, it's probably a .cat file. */
351 if (hdr[0] == 0x30)
353 DWORD fileLen = GetFileSize(hFile, NULL);
355 TRACE("fileLen = %ld\n", fileLen);
356 /* Sanity-check length */
357 if (hdr[1] < 0x80 && fileLen == 2 + hdr[1])
359 *pgSubject = catGUID;
360 SetLastError(S_OK);
361 bRet = TRUE;
362 goto cleanup;
364 else if (hdr[1] == 0x80)
366 /* Indefinite length, can't verify with just the header, assume it
367 * is.
369 *pgSubject = catGUID;
370 SetLastError(S_OK);
371 bRet = TRUE;
372 goto cleanup;
374 else
376 BYTE lenBytes = hdr[1] & 0x7f;
378 if (lenBytes == 1 && fileLen == 2 + lenBytes + hdr[2])
380 *pgSubject = catGUID;
381 SetLastError(S_OK);
382 bRet = TRUE;
383 goto cleanup;
385 else if (lenBytes == 2 && fileLen == 2 + lenBytes +
386 (hdr[2] << 8 | hdr[3]))
388 *pgSubject = catGUID;
389 SetLastError(S_OK);
390 bRet = TRUE;
391 goto cleanup;
393 else if (fileLen > 0xffff)
395 /* The file size must be greater than 2 bytes in length, so
396 * assume it is a .cat file
398 *pgSubject = catGUID;
399 SetLastError(S_OK);
400 bRet = TRUE;
401 goto cleanup;
406 /* Check for supported functions using CryptSIPDllIsMyFileType */
407 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptSIPDllIsMyFileType\\", 0, KEY_READ, &key);
408 if (r == ERROR_SUCCESS)
410 DWORD index = 0, size;
411 WCHAR subKeyName[MAX_PATH];
413 do {
414 size = ARRAY_SIZE(subKeyName);
415 r = RegEnumKeyExW(key, index++, subKeyName, &size, NULL, NULL,
416 NULL, NULL);
417 if (r == ERROR_SUCCESS)
419 HKEY subKey;
421 r = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
422 if (r == ERROR_SUCCESS)
424 HMODULE lib;
425 pfnIsFileSupported isMy = CRYPT_LoadSIPFuncFromKey(subKey,
426 &lib);
428 if (isMy)
430 bRet = isMy(hFile, pgSubject);
431 FreeLibrary(lib);
433 RegCloseKey(subKey);
436 } while (!bRet && r == ERROR_SUCCESS);
437 RegCloseKey(key);
440 /* Check for supported functions using CryptSIPDllIsMyFileType2 */
441 if (!bRet)
443 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptSIPDllIsMyFileType2\\", 0, KEY_READ, &key);
444 if (r == ERROR_SUCCESS)
446 DWORD index = 0, size;
447 WCHAR subKeyName[MAX_PATH];
449 do {
450 size = ARRAY_SIZE(subKeyName);
451 r = RegEnumKeyExW(key, index++, subKeyName, &size, NULL, NULL,
452 NULL, NULL);
453 if (r == ERROR_SUCCESS)
455 HKEY subKey;
457 r = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
458 if (r == ERROR_SUCCESS)
460 HMODULE lib;
461 pfnIsFileSupportedName isMy2 =
462 CRYPT_LoadSIPFuncFromKey(subKey, &lib);
464 if (isMy2)
466 bRet = isMy2((LPWSTR)FileName, pgSubject);
467 FreeLibrary(lib);
469 RegCloseKey(subKey);
472 } while (!bRet && r == ERROR_SUCCESS);
473 RegCloseKey(key);
477 if (!bRet)
478 SetLastError(TRUST_E_SUBJECT_FORM_UNKNOWN);
480 cleanup:
481 /* If we didn't open this one we shouldn't close it (hFile is a copy),
482 * but we should reset the file pointer to its original position.
484 if (!hFileIn)
485 CloseHandle(hFile);
486 else
487 SetFilePointerEx(hFile, oldPos, NULL, FILE_BEGIN);
489 return bRet;
492 static LONG CRYPT_OpenSIPFunctionKey(const GUID *guid, LPCWSTR function,
493 HKEY *key)
495 WCHAR szFullKey[ 0x100 ];
497 lstrcpyW(szFullKey, L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptSIPDll");
498 lstrcatW(szFullKey, function);
499 CRYPT_guid2wstr(guid, &szFullKey[lstrlenW(szFullKey)]);
500 return RegOpenKeyExW(HKEY_LOCAL_MACHINE, szFullKey, 0, KEY_READ, key);
503 /* Loads the function named function for the SIP specified by pgSubject, and
504 * returns it if found. Returns NULL on error. If the function is loaded,
505 * *pLib is set to the library in which it is found.
507 static void *CRYPT_LoadSIPFunc(const GUID *pgSubject, LPCWSTR function,
508 HMODULE *pLib)
510 LONG r;
511 HKEY key;
512 void *func = NULL;
514 TRACE("(%s, %s)\n", debugstr_guid(pgSubject), debugstr_w(function));
516 r = CRYPT_OpenSIPFunctionKey(pgSubject, function, &key);
517 if (!r)
519 func = CRYPT_LoadSIPFuncFromKey(key, pLib);
520 RegCloseKey(key);
522 TRACE("returning %p\n", func);
523 return func;
526 typedef struct _WINE_SIP_PROVIDER {
527 GUID subject;
528 SIP_DISPATCH_INFO info;
529 struct list entry;
530 } WINE_SIP_PROVIDER;
532 static struct list providers = { &providers, &providers };
533 static CRITICAL_SECTION providers_cs;
534 static CRITICAL_SECTION_DEBUG providers_cs_debug =
536 0, 0, &providers_cs,
537 { &providers_cs_debug.ProcessLocksList,
538 &providers_cs_debug.ProcessLocksList },
539 0, 0, { (DWORD_PTR)(__FILE__ ": providers_cs") }
541 static CRITICAL_SECTION providers_cs = { &providers_cs_debug, -1, 0, 0, 0, 0 };
543 static void CRYPT_CacheSIP(const GUID *pgSubject, SIP_DISPATCH_INFO *info)
545 WINE_SIP_PROVIDER *prov = CryptMemAlloc(sizeof(WINE_SIP_PROVIDER));
547 if (prov)
549 prov->subject = *pgSubject;
550 prov->info = *info;
551 EnterCriticalSection(&providers_cs);
552 list_add_tail(&providers, &prov->entry);
553 LeaveCriticalSection(&providers_cs);
557 static WINE_SIP_PROVIDER *CRYPT_GetCachedSIP(const GUID *pgSubject)
559 WINE_SIP_PROVIDER *provider = NULL, *ret = NULL;
561 EnterCriticalSection(&providers_cs);
562 LIST_FOR_EACH_ENTRY(provider, &providers, WINE_SIP_PROVIDER, entry)
564 if (IsEqualGUID(pgSubject, &provider->subject))
565 break;
567 if (provider && IsEqualGUID(pgSubject, &provider->subject))
568 ret = provider;
569 LeaveCriticalSection(&providers_cs);
570 return ret;
573 static inline BOOL CRYPT_IsSIPCached(const GUID *pgSubject)
575 return CRYPT_GetCachedSIP(pgSubject) != NULL;
578 void crypt_sip_free(void)
580 WINE_SIP_PROVIDER *prov, *next;
582 LIST_FOR_EACH_ENTRY_SAFE(prov, next, &providers, WINE_SIP_PROVIDER, entry)
584 list_remove(&prov->entry);
585 FreeLibrary(prov->info.hSIP);
586 CryptMemFree(prov);
588 DeleteCriticalSection(&providers_cs);
591 /* Loads the SIP for pgSubject into the global cache. Returns FALSE if the
592 * SIP isn't registered or is invalid.
594 static BOOL CRYPT_LoadSIP(const GUID *pgSubject)
596 SIP_DISPATCH_INFO sip = { 0 };
597 HMODULE lib = NULL, temp = NULL;
599 sip.pfGet = CRYPT_LoadSIPFunc(pgSubject, L"GetSignedDataMsg\\", &lib);
600 if (!sip.pfGet)
601 goto error;
602 sip.pfPut = CRYPT_LoadSIPFunc(pgSubject, L"PutSignedDataMsg\\", &temp);
603 if (!sip.pfPut || temp != lib)
604 goto error;
605 FreeLibrary(temp);
606 temp = NULL;
607 sip.pfCreate = CRYPT_LoadSIPFunc(pgSubject, L"CreateIndirectData\\", &temp);
608 if (!sip.pfCreate || temp != lib)
609 goto error;
610 FreeLibrary(temp);
611 temp = NULL;
612 sip.pfVerify = CRYPT_LoadSIPFunc(pgSubject, L"VerifyIndirectData\\", &temp);
613 if (!sip.pfVerify || temp != lib)
614 goto error;
615 FreeLibrary(temp);
616 temp = NULL;
617 sip.pfRemove = CRYPT_LoadSIPFunc(pgSubject, L"RemoveSignedDataMsg\\", &temp);
618 if (!sip.pfRemove || temp != lib)
619 goto error;
620 FreeLibrary(temp);
621 sip.hSIP = lib;
622 CRYPT_CacheSIP(pgSubject, &sip);
623 return TRUE;
625 error:
626 FreeLibrary(lib);
627 FreeLibrary(temp);
628 SetLastError(TRUST_E_SUBJECT_FORM_UNKNOWN);
629 return FALSE;
632 /***********************************************************************
633 * CryptSIPLoad (CRYPT32.@)
635 * Load some internal crypt32 functions into a SIP_DISPATCH_INFO structure.
637 * PARAMS
638 * pgSubject [I] The GUID.
639 * dwFlags [I] Flags.
640 * pSipDispatch [I] The loaded functions.
642 * RETURNS
643 * Success: TRUE. pSipDispatch contains the functions.
644 * Failure: FALSE. (Look at GetLastError()).
646 * NOTES
647 * CryptSIPLoad uses caching for the list of GUIDs and whether a SIP is
648 * already loaded.
650 * An application calls CryptSipLoad which will return a structure with the
651 * function addresses of some internal crypt32 functions. The application will
652 * then call these functions which will be forwarded to the appropriate SIP.
654 * CryptSIPLoad will load the needed SIP but doesn't unload this dll. The unloading
655 * is done when crypt32 is unloaded.
657 BOOL WINAPI CryptSIPLoad
658 (const GUID *pgSubject, DWORD dwFlags, SIP_DISPATCH_INFO *pSipDispatch)
660 TRACE("(%s %ld %p)\n", debugstr_guid(pgSubject), dwFlags, pSipDispatch);
662 if (!pgSubject || dwFlags != 0 || !pSipDispatch)
664 SetLastError(ERROR_INVALID_PARAMETER);
665 return FALSE;
667 if (!CRYPT_IsSIPCached(pgSubject) && !CRYPT_LoadSIP(pgSubject))
668 return FALSE;
670 pSipDispatch->hSIP = NULL;
671 pSipDispatch->pfGet = CryptSIPGetSignedDataMsg;
672 pSipDispatch->pfPut = CryptSIPPutSignedDataMsg;
673 pSipDispatch->pfCreate = CryptSIPCreateIndirectData;
674 pSipDispatch->pfVerify = CryptSIPVerifyIndirectData;
675 pSipDispatch->pfRemove = CryptSIPRemoveSignedDataMsg;
677 return TRUE;
680 /***********************************************************************
681 * CryptSIPCreateIndirectData (CRYPT32.@)
683 BOOL WINAPI CryptSIPCreateIndirectData(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pcbIndirectData,
684 SIP_INDIRECT_DATA* pIndirectData)
686 WINE_SIP_PROVIDER *sip;
687 BOOL ret = FALSE;
689 TRACE("(%p %p %p)\n", pSubjectInfo, pcbIndirectData, pIndirectData);
691 if (!pSubjectInfo || !pSubjectInfo->pgSubjectType || !pcbIndirectData)
693 SetLastError(ERROR_INVALID_PARAMETER);
694 return FALSE;
696 if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
697 ret = sip->info.pfCreate(pSubjectInfo, pcbIndirectData, pIndirectData);
698 TRACE("returning %d\n", ret);
699 return ret;
702 /***********************************************************************
703 * CryptSIPGetSignedDataMsg (CRYPT32.@)
705 BOOL WINAPI CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pdwEncodingType,
706 DWORD dwIndex, DWORD* pcbSignedDataMsg, BYTE* pbSignedDataMsg)
708 WINE_SIP_PROVIDER *sip;
709 BOOL ret = FALSE;
711 TRACE("(%p %p %ld %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
712 pcbSignedDataMsg, pbSignedDataMsg);
714 if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
715 ret = sip->info.pfGet(pSubjectInfo, pdwEncodingType, dwIndex,
716 pcbSignedDataMsg, pbSignedDataMsg);
717 TRACE("returning %d\n", ret);
718 return ret;
721 /***********************************************************************
722 * CryptSIPPutSignedDataMsg (CRYPT32.@)
724 BOOL WINAPI CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD pdwEncodingType,
725 DWORD* pdwIndex, DWORD cbSignedDataMsg, BYTE* pbSignedDataMsg)
727 WINE_SIP_PROVIDER *sip;
728 BOOL ret = FALSE;
730 TRACE("(%p %ld %p %ld %p)\n", pSubjectInfo, pdwEncodingType, pdwIndex,
731 cbSignedDataMsg, pbSignedDataMsg);
733 if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
734 ret = sip->info.pfPut(pSubjectInfo, pdwEncodingType, pdwIndex,
735 cbSignedDataMsg, pbSignedDataMsg);
736 TRACE("returning %d\n", ret);
737 return ret;
740 /***********************************************************************
741 * CryptSIPRemoveSignedDataMsg (CRYPT32.@)
743 BOOL WINAPI CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo,
744 DWORD dwIndex)
746 WINE_SIP_PROVIDER *sip;
747 BOOL ret = FALSE;
749 TRACE("(%p %ld)\n", pSubjectInfo, dwIndex);
751 if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
752 ret = sip->info.pfRemove(pSubjectInfo, dwIndex);
753 TRACE("returning %d\n", ret);
754 return ret;
757 /***********************************************************************
758 * CryptSIPVerifyIndirectData (CRYPT32.@)
760 BOOL WINAPI CryptSIPVerifyIndirectData(SIP_SUBJECTINFO* pSubjectInfo,
761 SIP_INDIRECT_DATA* pIndirectData)
763 WINE_SIP_PROVIDER *sip;
764 BOOL ret = FALSE;
766 TRACE("(%p %p)\n", pSubjectInfo, pIndirectData);
768 if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
769 ret = sip->info.pfVerify(pSubjectInfo, pIndirectData);
770 TRACE("returning %d\n", ret);
771 return ret;
774 /***********************************************************************
775 * CryptSIPRetrieveSubjectGuidForCatalogFile (CRYPT32.@)
777 BOOL WINAPI CryptSIPRetrieveSubjectGuidForCatalogFile(LPCWSTR filename, HANDLE handle, GUID *subject)
779 FIXME("(%s %p %p)\n", debugstr_w(filename), handle, subject);
780 SetLastError(ERROR_INVALID_PARAMETER);
781 return FALSE;