ReactOS 0.4.17-dev-470-gf9e3448
sip.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "wincrypt.h"
#include "winreg.h"
#include "winnls.h"
#include "mssip.h"
#include "winuser.h"
#include "crypt32_private.h"
#include "wine/debug.h"
#include "wine/list.h"
Include dependency graph for sip.c:

Go to the source code of this file.

Classes

struct  _WINE_SIP_PROVIDER
 

Macros

#define CRYPT_SIPREMOVEPROV(key)
 
#define CRYPT_SIPADDPROV(key, field)
 

Typedefs

typedef struct _WINE_SIP_PROVIDER WINE_SIP_PROVIDER
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (crypt)
 
static void CRYPT_guid2wstr (const GUID *guid, LPWSTR wstr)
 
static LONG CRYPT_SIPDeleteFunction (const GUID *guid, LPCWSTR szKey)
 
BOOL WINAPI CryptSIPRemoveProvider (GUID *pgProv)
 
static LONG CRYPT_SIPWriteFunction (const GUID *guid, LPCWSTR szKey, LPCWSTR szDll, LPCWSTR szFunction)
 
BOOL WINAPI CryptSIPAddProvider (SIP_ADD_NEWPROVIDER *psNewProv)
 
static voidCRYPT_LoadSIPFuncFromKey (HKEY key, HMODULE *pLib)
 
BOOL WINAPI CryptSIPRetrieveSubjectGuid (LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
 
static LONG CRYPT_OpenSIPFunctionKey (const GUID *guid, LPCWSTR function, HKEY *key)
 
static voidCRYPT_LoadSIPFunc (const GUID *pgSubject, LPCWSTR function, HMODULE *pLib)
 
static void CRYPT_CacheSIP (const GUID *pgSubject, SIP_DISPATCH_INFO *info)
 
static WINE_SIP_PROVIDERCRYPT_GetCachedSIP (const GUID *pgSubject)
 
static BOOL CRYPT_IsSIPCached (const GUID *pgSubject)
 
void crypt_sip_free (void)
 
static BOOL CRYPT_LoadSIP (const GUID *pgSubject)
 
BOOL WINAPI CryptSIPLoad (const GUID *pgSubject, DWORD dwFlags, SIP_DISPATCH_INFO *pSipDispatch)
 
BOOL WINAPI CryptSIPCreateIndirectData (SIP_SUBJECTINFO *pSubjectInfo, DWORD *pcbIndirectData, SIP_INDIRECT_DATA *pIndirectData)
 
BOOL WINAPI CryptSIPGetSignedDataMsg (SIP_SUBJECTINFO *pSubjectInfo, DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg, BYTE *pbSignedDataMsg)
 
BOOL WINAPI CryptSIPPutSignedDataMsg (SIP_SUBJECTINFO *pSubjectInfo, DWORD pdwEncodingType, DWORD *pdwIndex, DWORD cbSignedDataMsg, BYTE *pbSignedDataMsg)
 
BOOL WINAPI CryptSIPRemoveSignedDataMsg (SIP_SUBJECTINFO *pSubjectInfo, DWORD dwIndex)
 
BOOL WINAPI CryptSIPVerifyIndirectData (SIP_SUBJECTINFO *pSubjectInfo, SIP_INDIRECT_DATA *pIndirectData)
 
BOOL WINAPI CryptSIPRetrieveSubjectGuidForCatalogFile (LPCWSTR filename, HANDLE handle, GUID *subject)
 

Variables

static struct list providers = { &providers, &providers }
 
static CRITICAL_SECTION providers_cs = { &providers_cs_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG providers_cs_debug
 

Macro Definition Documentation

◆ CRYPT_SIPADDPROV

#define CRYPT_SIPADDPROV (   key,
  field 
)
Value:
r = CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
psNewProv->pwszDLLFileName, psNewProv->field); \
if (r != ERROR_SUCCESS) goto end_function
#define ERROR_SUCCESS
Definition: deptool.c:10
static LONG CRYPT_SIPWriteFunction(const GUID *guid, LPCWSTR szKey, LPCWSTR szDll, LPCWSTR szFunction)
Definition: sip.c:129
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
Definition: copy.c:22

◆ CRYPT_SIPREMOVEPROV

#define CRYPT_SIPREMOVEPROV (   key)
Value:
r = CRYPT_SIPDeleteFunction( pgProv, key); \
if (r != ERROR_SUCCESS) remove_error = r
static LONG CRYPT_SIPDeleteFunction(const GUID *guid, LPCWSTR szKey)
Definition: sip.c:55

Typedef Documentation

◆ WINE_SIP_PROVIDER

Function Documentation

◆ CRYPT_CacheSIP()

static void CRYPT_CacheSIP ( const GUID pgSubject,
SIP_DISPATCH_INFO info 
)
static

Definition at line 543 of file sip.c.

544{
546
547 if (prov)
548 {
549 prov->subject = *pgSubject;
550 prov->info = *info;
552 list_add_tail(&providers, &prov->entry);
554 }
555}
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:136
static struct list providers
Definition: sip.c:532
static CRITICAL_SECTION providers_cs
Definition: sip.c:533
struct list entry
Definition: sip.c:529
SIP_DISPATCH_INFO info
Definition: sip.c:528
GUID subject
Definition: sip.c:527
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by CRYPT_LoadSIP().

◆ CRYPT_GetCachedSIP()

static WINE_SIP_PROVIDER * CRYPT_GetCachedSIP ( const GUID pgSubject)
static

Definition at line 557 of file sip.c.

558{
559 WINE_SIP_PROVIDER *provider = NULL, *ret = NULL;
560
563 {
564 if (IsEqualGUID(pgSubject, &provider->subject))
565 break;
566 }
567 if (provider && IsEqualGUID(pgSubject, &provider->subject))
568 ret = provider;
570 return ret;
571}
#define NULL
Definition: types.h:112
return ret
Definition: mutex.c:146
uint32_t entry
Definition: isohybrid.c:63
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198

Referenced by CRYPT_IsSIPCached(), CryptSIPCreateIndirectData(), CryptSIPGetSignedDataMsg(), CryptSIPPutSignedDataMsg(), CryptSIPRemoveSignedDataMsg(), and CryptSIPVerifyIndirectData().

◆ CRYPT_guid2wstr()

static void CRYPT_guid2wstr ( const GUID guid,
LPWSTR  wstr 
)
static

Definition at line 39 of file sip.c.

40{
41 char str[40];
42
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 );
48}
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
GUID guid
Definition: version.c:147
#define sprintf
Definition: sprintf.c:45
const WCHAR * str

Referenced by CRYPT_OpenSIPFunctionKey(), CRYPT_SIPDeleteFunction(), and CRYPT_SIPWriteFunction().

◆ CRYPT_IsSIPCached()

static BOOL CRYPT_IsSIPCached ( const GUID pgSubject)
inlinestatic

Definition at line 573 of file sip.c.

574{
575 return CRYPT_GetCachedSIP(pgSubject) != NULL;
576}
static WINE_SIP_PROVIDER * CRYPT_GetCachedSIP(const GUID *pgSubject)
Definition: sip.c:557

Referenced by CryptSIPLoad().

◆ CRYPT_LoadSIP()

static BOOL CRYPT_LoadSIP ( const GUID pgSubject)
static

Definition at line 594 of file sip.c.

595{
596 SIP_DISPATCH_INFO sip = { 0 };
597 HMODULE lib = NULL, temp = NULL;
598
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;
606 temp = NULL;
607 sip.pfCreate = CRYPT_LoadSIPFunc(pgSubject, L"CreateIndirectData\\", &temp);
608 if (!sip.pfCreate || temp != lib)
609 goto error;
611 temp = NULL;
612 sip.pfVerify = CRYPT_LoadSIPFunc(pgSubject, L"VerifyIndirectData\\", &temp);
613 if (!sip.pfVerify || temp != lib)
614 goto error;
616 temp = NULL;
617 sip.pfRemove = CRYPT_LoadSIPFunc(pgSubject, L"RemoveSignedDataMsg\\", &temp);
618 if (!sip.pfRemove || temp != lib)
619 goto error;
621 sip.hSIP = lib;
622 CRYPT_CacheSIP(pgSubject, &sip);
623 return TRUE;
624
625error:
626 FreeLibrary(lib);
629 return FALSE;
630}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static void * CRYPT_LoadSIPFunc(const GUID *pgSubject, LPCWSTR function, HMODULE *pLib)
Definition: sip.c:507
static void CRYPT_CacheSIP(const GUID *pgSubject, SIP_DISPATCH_INFO *info)
Definition: sip.c:543
#define SetLastError(x)
Definition: compat.h:752
#define FreeLibrary(x)
Definition: compat.h:748
#define L(x)
Definition: resources.c:13
#define error(str)
Definition: mkdosfs.c:1605
static calc_node_t temp
Definition: rpn_ieee.c:38
pCryptSIPVerifyIndirectData pfVerify
Definition: mssip.h:132
pCryptSIPRemoveSignedDataMsg pfRemove
Definition: mssip.h:133
pCryptSIPGetSignedDataMsg pfGet
Definition: mssip.h:129
pCryptSIPPutSignedDataMsg pfPut
Definition: mssip.h:130
pCryptSIPCreateIndirectData pfCreate
Definition: mssip.h:131
#define TRUST_E_SUBJECT_FORM_UNKNOWN
Definition: winerror.h:4621

Referenced by CryptSIPLoad().

◆ CRYPT_LoadSIPFunc()

static void * CRYPT_LoadSIPFunc ( const GUID pgSubject,
LPCWSTR  function,
HMODULE pLib 
)
static

Definition at line 507 of file sip.c.

509{
510 LONG r;
511 HKEY key;
512 void *func = NULL;
513
514 TRACE("(%s, %s)\n", debugstr_guid(pgSubject), debugstr_w(function));
515
516 r = CRYPT_OpenSIPFunctionKey(pgSubject, function, &key);
517 if (!r)
518 {
521 }
522 TRACE("returning %p\n", func);
523 return func;
524}
#define RegCloseKey(hKey)
Definition: registry.h:49
static void * CRYPT_LoadSIPFuncFromKey(HKEY key, HMODULE *pLib)
Definition: sip.c:232
static LONG CRYPT_OpenSIPFunctionKey(const GUID *guid, LPCWSTR function, HKEY *key)
Definition: sip.c:492
GLenum func
Definition: glext.h:6028
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
long LONG
Definition: pedump.c:60
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by CRYPT_LoadSIP().

◆ CRYPT_LoadSIPFuncFromKey()

static void * CRYPT_LoadSIPFuncFromKey ( HKEY  key,
HMODULE pLib 
)
static

Definition at line 232 of file sip.c.

233{
234 LONG r;
235 DWORD size;
236 WCHAR dllName[MAX_PATH];
237 char functionName[MAX_PATH];
238 HMODULE lib;
239 void *func = NULL;
240
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;
245
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;
251
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);
260
261end:
262 return func;
263}
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint end
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
short WCHAR
Definition: pedump.c:58
unsigned char * LPBYTE
Definition: typedefs.h:53

Referenced by CRYPT_LoadSIPFunc(), and CryptSIPRetrieveSubjectGuid().

◆ CRYPT_OpenSIPFunctionKey()

static LONG CRYPT_OpenSIPFunctionKey ( const GUID guid,
LPCWSTR  function,
HKEY key 
)
static

Definition at line 492 of file sip.c.

494{
495 WCHAR szFullKey[ 0x100 ];
496
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);
501}
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
static void CRYPT_guid2wstr(const GUID *guid, LPWSTR wstr)
Definition: sip.c:39
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
#define KEY_READ
Definition: nt_native.h:1026
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by CRYPT_LoadSIPFunc().

◆ crypt_sip_free()

void crypt_sip_free ( void  )

Definition at line 578 of file sip.c.

579{
580 WINE_SIP_PROVIDER *prov, *next;
581
583 {
584 list_remove(&prov->entry);
585 FreeLibrary(prov->info.hSIP);
586 CryptMemFree(prov);
587 }
589}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:146
static unsigned __int64 next
Definition: rand_nt.c:6
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by DllMain().

◆ CRYPT_SIPDeleteFunction()

static LONG CRYPT_SIPDeleteFunction ( const GUID guid,
LPCWSTR  szKey 
)
static

Definition at line 55 of file sip.c.

56{
57 WCHAR szFullKey[ 0x100 ];
59
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 ) ] );
64
66
67 return r;
68}
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1239

◆ CRYPT_SIPWriteFunction()

static LONG CRYPT_SIPWriteFunction ( const GUID guid,
LPCWSTR  szKey,
LPCWSTR  szDll,
LPCWSTR  szFunction 
)
static

Definition at line 129 of file sip.c.

131{
132 WCHAR szFullKey[ 0x100 ];
134 HKEY hKey;
135
136 if( !szFunction )
137 return ERROR_SUCCESS;
138
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 ) ] );
143
144 TRACE("key is %s\n", debugstr_w( szFullKey ) );
145
146 r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey );
147 if( r != ERROR_SUCCESS ) goto error_close_key;
148
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) );
155
156error_close_key:
157
158 RegCloseKey( hKey );
159
160 return r;
161}
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1201
FxAutoRegKey hKey
#define REG_SZ
Definition: layer.c:22
unsigned char BYTE
Definition: xxhash.c:193

◆ CryptSIPAddProvider()

BOOL WINAPI CryptSIPAddProvider ( SIP_ADD_NEWPROVIDER psNewProv)

Definition at line 181 of file sip.c.

182{
184
185 TRACE("%p\n", psNewProv);
186
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)
194 {
196 return FALSE;
197 }
198
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 ) );
205
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
210
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 );
218
219#undef CRYPT_SIPADDPROV
220
221end_function:
222
223 if (r != ERROR_SUCCESS)
224 {
226 return FALSE;
227 }
228
229 return TRUE;
230}
#define CRYPT_SIPADDPROV(key, field)
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
WCHAR * pwszPutFuncName
Definition: mssip.h:153
WCHAR * pwszCreateFuncName
Definition: mssip.h:154
GUID * pgSubject
Definition: mssip.h:145
WCHAR * pwszMagicNumber
Definition: mssip.h:148
WCHAR * pwszRemoveFuncName
Definition: mssip.h:156
WCHAR * pwszIsFunctionName
Definition: mssip.h:150
WCHAR * pwszGetFuncName
Definition: mssip.h:152
WCHAR * pwszIsFunctionNameFmt2
Definition: mssip.h:158
WCHAR * pwszVerifyFuncName
Definition: mssip.h:155
WCHAR * pwszDLLFileName
Definition: mssip.h:147
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Referenced by DllRegisterServer(), test_AddRemoveProvider(), and WINTRUST_SIPPAddProvider().

◆ CryptSIPCreateIndirectData()

BOOL WINAPI CryptSIPCreateIndirectData ( SIP_SUBJECTINFO pSubjectInfo,
DWORD pcbIndirectData,
SIP_INDIRECT_DATA pIndirectData 
)

Definition at line 683 of file sip.c.

685{
687 BOOL ret = FALSE;
688
689 TRACE("(%p %p %p)\n", pSubjectInfo, pcbIndirectData, pIndirectData);
690
691 if (!pSubjectInfo || !pSubjectInfo->pgSubjectType || !pcbIndirectData)
692 {
694 return FALSE;
695 }
696 if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
697 ret = sip->info.pfCreate(pSubjectInfo, pcbIndirectData, pIndirectData);
698 TRACE("returning %d\n", ret);
699 return ret;
700}
unsigned int BOOL
Definition: ntddk_ex.h:94
GUID * pgSubjectType
Definition: mssip.h:52

Referenced by CryptSIPLoad(), InitFunctionPtrs(), and WINTRUST_SIPPAddProvider().

◆ CryptSIPGetSignedDataMsg()

BOOL WINAPI CryptSIPGetSignedDataMsg ( SIP_SUBJECTINFO pSubjectInfo,
DWORD pdwEncodingType,
DWORD  dwIndex,
DWORD pcbSignedDataMsg,
BYTE pbSignedDataMsg 
)

Definition at line 705 of file sip.c.

707{
709 BOOL ret = FALSE;
710
711 TRACE("(%p %p %ld %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
712 pcbSignedDataMsg, pbSignedDataMsg);
713
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;
719}

Referenced by CryptSIPLoad(), and WINTRUST_SIPPAddProvider().

◆ CryptSIPLoad()

BOOL WINAPI CryptSIPLoad ( const GUID pgSubject,
DWORD  dwFlags,
SIP_DISPATCH_INFO pSipDispatch 
)

Definition at line 657 of file sip.c.

659{
660 TRACE("(%s %ld %p)\n", debugstr_guid(pgSubject), dwFlags, pSipDispatch);
661
662 if (!pgSubject || dwFlags != 0 || !pSipDispatch)
663 {
665 return FALSE;
666 }
667 if (!CRYPT_IsSIPCached(pgSubject) && !CRYPT_LoadSIP(pgSubject))
668 return FALSE;
669
670 pSipDispatch->hSIP = NULL;
671 pSipDispatch->pfGet = CryptSIPGetSignedDataMsg;
672 pSipDispatch->pfPut = CryptSIPPutSignedDataMsg;
673 pSipDispatch->pfCreate = CryptSIPCreateIndirectData;
674 pSipDispatch->pfVerify = CryptSIPVerifyIndirectData;
676
677 return TRUE;
678}
BOOL WINAPI CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo, DWORD pdwEncodingType, DWORD *pdwIndex, DWORD cbSignedDataMsg, BYTE *pbSignedDataMsg)
Definition: sip.c:724
BOOL WINAPI CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo, DWORD dwIndex)
Definition: sip.c:743
static BOOL CRYPT_IsSIPCached(const GUID *pgSubject)
Definition: sip.c:573
BOOL WINAPI CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo, DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg, BYTE *pbSignedDataMsg)
Definition: sip.c:705
BOOL WINAPI CryptSIPCreateIndirectData(SIP_SUBJECTINFO *pSubjectInfo, DWORD *pcbIndirectData, SIP_INDIRECT_DATA *pIndirectData)
Definition: sip.c:683
static BOOL CRYPT_LoadSIP(const GUID *pgSubject)
Definition: sip.c:594
BOOL WINAPI CryptSIPVerifyIndirectData(SIP_SUBJECTINFO *pSubjectInfo, SIP_INDIRECT_DATA *pIndirectData)
Definition: sip.c:760
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141

Referenced by CRYPT_QueryEmbeddedMessageObject(), SOFTPUB_GetSIP(), and test_SIPLoad().

◆ CryptSIPPutSignedDataMsg()

BOOL WINAPI CryptSIPPutSignedDataMsg ( SIP_SUBJECTINFO pSubjectInfo,
DWORD  pdwEncodingType,
DWORD pdwIndex,
DWORD  cbSignedDataMsg,
BYTE pbSignedDataMsg 
)

Definition at line 724 of file sip.c.

726{
728 BOOL ret = FALSE;
729
730 TRACE("(%p %ld %p %ld %p)\n", pSubjectInfo, pdwEncodingType, pdwIndex,
731 cbSignedDataMsg, pbSignedDataMsg);
732
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;
738}

Referenced by CryptSIPLoad(), and WINTRUST_SIPPAddProvider().

◆ CryptSIPRemoveProvider()

BOOL WINAPI CryptSIPRemoveProvider ( GUID pgProv)

Definition at line 86 of file sip.c.

87{
89 LONG remove_error = ERROR_SUCCESS;
90
91 TRACE("%s\n", debugstr_guid(pgProv));
92
93 if (!pgProv)
94 {
96 return FALSE;
97 }
98
99
100#define CRYPT_SIPREMOVEPROV( key ) \
101 r = CRYPT_SIPDeleteFunction( pgProv, key); \
102 if (r != ERROR_SUCCESS) remove_error = r
103
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\\" );
111
112#undef CRYPT_SIPREMOVEPROV
113
114 if (remove_error != ERROR_SUCCESS)
115 {
116 SetLastError(remove_error);
117 return FALSE;
118 }
119
120 return TRUE;
121}
#define CRYPT_SIPREMOVEPROV(key)

Referenced by DllUnregisterServer(), and test_AddRemoveProvider().

◆ CryptSIPRemoveSignedDataMsg()

BOOL WINAPI CryptSIPRemoveSignedDataMsg ( SIP_SUBJECTINFO pSubjectInfo,
DWORD  dwIndex 
)

Definition at line 743 of file sip.c.

745{
747 BOOL ret = FALSE;
748
749 TRACE("(%p %ld)\n", pSubjectInfo, dwIndex);
750
751 if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
752 ret = sip->info.pfRemove(pSubjectInfo, dwIndex);
753 TRACE("returning %d\n", ret);
754 return ret;
755}

Referenced by CryptSIPLoad(), and WINTRUST_SIPPAddProvider().

◆ CryptSIPRetrieveSubjectGuid()

BOOL WINAPI CryptSIPRetrieveSubjectGuid ( LPCWSTR  FileName,
HANDLE  hFileIn,
GUID pgSubject 
)

Definition at line 283 of file sip.c.

285{
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' };
298 HKEY key;
299
300 TRACE("(%s %p %p)\n", wine_dbgstr_w(FileName), hFileIn, pgSubject);
301
302 if (!pgSubject || (!FileName && !hFileIn))
303 {
305 return FALSE;
306 }
307
308 /* Set pgSubject to zero's */
309 memset(pgSubject, 0 , sizeof(GUID));
310
311 if (hFileIn)
312 /* Use the given handle, make sure not to close this one ourselves */
313 hFile = hFileIn;
314 else
315 {
317 /* Last error is set by CreateFile */
318 if (hFile == INVALID_HANDLE_VALUE) return FALSE;
319 }
320
321 zero.QuadPart = 0;
324 if (!ReadFile(hFile, hdr, sizeof(hdr), &count, NULL))
325 goto cleanup;
326
328 {
330 goto cleanup;
331 }
332
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)))
336 {
337 *pgSubject = unknown;
339 bRet = TRUE;
340 goto cleanup;
341 }
342 /* Quick-n-dirty check for a cab file. */
343 if (!memcmp(hdr, cabHdr, sizeof(cabHdr)))
344 {
345 *pgSubject = cabGUID;
347 bRet = TRUE;
348 goto cleanup;
349 }
350 /* If it's asn.1-encoded, it's probably a .cat file. */
351 if (hdr[0] == 0x30)
352 {
353 DWORD fileLen = GetFileSize(hFile, NULL);
354
355 TRACE("fileLen = %ld\n", fileLen);
356 /* Sanity-check length */
357 if (hdr[1] < 0x80 && fileLen == 2 + hdr[1])
358 {
359 *pgSubject = catGUID;
361 bRet = TRUE;
362 goto cleanup;
363 }
364 else if (hdr[1] == 0x80)
365 {
366 /* Indefinite length, can't verify with just the header, assume it
367 * is.
368 */
369 *pgSubject = catGUID;
371 bRet = TRUE;
372 goto cleanup;
373 }
374 else
375 {
376 BYTE lenBytes = hdr[1] & 0x7f;
377
378 if (lenBytes == 1 && fileLen == 2 + lenBytes + hdr[2])
379 {
380 *pgSubject = catGUID;
382 bRet = TRUE;
383 goto cleanup;
384 }
385 else if (lenBytes == 2 && fileLen == 2 + lenBytes +
386 (hdr[2] << 8 | hdr[3]))
387 {
388 *pgSubject = catGUID;
390 bRet = TRUE;
391 goto cleanup;
392 }
393 else if (fileLen > 0xffff)
394 {
395 /* The file size must be greater than 2 bytes in length, so
396 * assume it is a .cat file
397 */
398 *pgSubject = catGUID;
400 bRet = TRUE;
401 goto cleanup;
402 }
403 }
404 }
405
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)
409 {
410 DWORD index = 0, size;
411 WCHAR subKeyName[MAX_PATH];
412
413 do {
414 size = ARRAY_SIZE(subKeyName);
415 r = RegEnumKeyExW(key, index++, subKeyName, &size, NULL, NULL,
416 NULL, NULL);
417 if (r == ERROR_SUCCESS)
418 {
419 HKEY subKey;
420
421 r = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
422 if (r == ERROR_SUCCESS)
423 {
424 HMODULE lib;
426 &lib);
427
428 if (isMy)
429 {
430 bRet = isMy(hFile, pgSubject);
431 FreeLibrary(lib);
432 }
433 RegCloseKey(subKey);
434 }
435 }
436 } while (!bRet && r == ERROR_SUCCESS);
438 }
439
440 /* Check for supported functions using CryptSIPDllIsMyFileType2 */
441 if (!bRet)
442 {
443 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptSIPDllIsMyFileType2\\", 0, KEY_READ, &key);
444 if (r == ERROR_SUCCESS)
445 {
446 DWORD index = 0, size;
447 WCHAR subKeyName[MAX_PATH];
448
449 do {
450 size = ARRAY_SIZE(subKeyName);
451 r = RegEnumKeyExW(key, index++, subKeyName, &size, NULL, NULL,
452 NULL, NULL);
453 if (r == ERROR_SUCCESS)
454 {
455 HKEY subKey;
456
457 r = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
458 if (r == ERROR_SUCCESS)
459 {
460 HMODULE lib;
462 CRYPT_LoadSIPFuncFromKey(subKey, &lib);
463
464 if (isMy2)
465 {
466 bRet = isMy2((LPWSTR)FileName, pgSubject);
467 FreeLibrary(lib);
468 }
469 RegCloseKey(subKey);
470 }
471 }
472 } while (!bRet && r == ERROR_SUCCESS);
474 }
475 }
476
477 if (!bRet)
479
480cleanup:
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.
483 */
484 if (!hFileIn)
486 else
488
489 return bRet;
490}
#define ARRAY_SIZE(A)
Definition: main.h:20
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
static WCHAR unknown[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1674
#define CloseHandle
Definition: compat.h:739
#define FILE_BEGIN
Definition: compat.h:761
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
static void cleanup(void)
Definition: main.c:1335
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
BOOL WINAPI SetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
Definition: fileinfo.c:177
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
static const GUID catGUID
Definition: crypt.c:1619
static const GUID cabGUID
Definition: crypt.c:1617
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint index
Definition: glext.h:6031
#define S_OK
Definition: intsafe.h:52
char hdr[14]
Definition: iptest.cpp:33
#define wine_dbgstr_w
Definition: kernel32.h:34
BOOL(WINAPI * pfnIsFileSupportedName)(WCHAR *, GUID *)
Definition: mssip.h:138
BOOL(WINAPI * pfnIsFileSupported)(HANDLE, GUID *)
Definition: mssip.h:137
#define SIP_MAX_MAGIC_NUMBER
Definition: mssip.h:45
_In_ HANDLE hFile
Definition: mswsock.h:90
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
#define memset(x, y, z)
Definition: compat.h:39
int zero
Definition: sehframes.cpp:29
uint16_t * LPWSTR
Definition: typedefs.h:56
#define FILE_CURRENT
Definition: winbase.h:116

Referenced by CRYPT_QueryEmbeddedMessageObject(), CryptCATOpen(), IsCatalogFile(), SOFTPUB_GetFileSubject(), SOFTPUB_LoadCatalogMessage(), test_sip(), and test_SIPRetrieveSubjectGUID().

◆ CryptSIPRetrieveSubjectGuidForCatalogFile()

BOOL WINAPI CryptSIPRetrieveSubjectGuidForCatalogFile ( LPCWSTR  filename,
HANDLE  handle,
GUID subject 
)

Definition at line 777 of file sip.c.

778{
779 FIXME("(%s %p %p)\n", debugstr_w(filename), handle, subject);
781 return FALSE;
782}
#define FIXME(fmt,...)
Definition: precomp.h:53
const char * filename
Definition: ioapi.h:137

◆ CryptSIPVerifyIndirectData()

BOOL WINAPI CryptSIPVerifyIndirectData ( SIP_SUBJECTINFO pSubjectInfo,
SIP_INDIRECT_DATA pIndirectData 
)

Definition at line 760 of file sip.c.

762{
764 BOOL ret = FALSE;
765
766 TRACE("(%p %p)\n", pSubjectInfo, pIndirectData);
767
768 if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
769 ret = sip->info.pfVerify(pSubjectInfo, pIndirectData);
770 TRACE("returning %d\n", ret);
771 return ret;
772}

Referenced by CryptSIPLoad(), and WINTRUST_SIPPAddProvider().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( crypt  )

Variable Documentation

◆ providers

struct list providers = { &providers, &providers }
static

Definition at line 532 of file sip.c.

Referenced by CRYPT_CacheSIP(), CRYPT_GetCachedSIP(), crypt_sip_free(), and wnetInit().

◆ providers_cs

static CRITICAL_SECTION providers_cs = { &providers_cs_debug, -1, 0, 0, 0, 0 }
static

Definition at line 533 of file sip.c.

Referenced by CRYPT_CacheSIP(), CRYPT_GetCachedSIP(), and crypt_sip_free().

◆ providers_cs_debug

CRITICAL_SECTION_DEBUG providers_cs_debug
static
Initial value:
=
{
0, 0, &providers_cs,
0, 0, { (DWORD_PTR)(__FILE__ ": providers_cs") }
}
static CRITICAL_SECTION_DEBUG providers_cs_debug
Definition: sip.c:534
#define DWORD_PTR
Definition: treelist.c:76

Definition at line 534 of file sip.c.