ReactOS 0.4.16-dev-983-g23ad936
main.c
Go to the documentation of this file.
1/*
2 * Copyright 2008 Juan Lang
3 *
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.
8 *
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.
13 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include <stdarg.h>
20#include "windef.h"
21#include "winbase.h"
22#include "wincrypt.h"
23#include "mssip.h"
24#define COBJMACROS
25#include "objbase.h"
26#include "initguid.h"
27#include "wine/debug.h"
28
30
32{
33 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
34
35 switch (fdwReason)
36 {
37#ifndef __REACTOS__
38 case DLL_WINE_PREATTACH:
39 return FALSE; /* prefer native version */
40#endif
43 break;
44 }
45
46 return TRUE;
47}
48
49static GUID mySubject = { 0x000c10f1, 0x0000, 0x0000,
50 { 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 }};
51
52/***********************************************************************
53 * DllRegisterServer (MSISIP.@)
54 */
56{
57 static WCHAR msisip[] = { 'M','S','I','S','I','P','.','D','L','L',0 };
58 static WCHAR getSignedDataMsg[] = { 'M','s','i','S','I','P','G','e','t',
59 'S','i','g','n','e','d','D','a','t','a','M','s','g',0 };
60 static WCHAR putSignedDataMsg[] = { 'M','s','i','S','I','P','P','u','t',
61 'S','i','g','n','e','d','D','a','t','a','M','s','g',0 };
62 static WCHAR createIndirectData[] = { 'M','s','i','S','I','P',
63 'C','r','e','a','t','e','I','n','d','i','r','e','c','t','D','a','t','a',
64 0 };
65 static WCHAR verifyIndirectData[] = { 'M','s','i','S','I','P',
66 'V','e','r','i','f','y','I','n','d','i','r','e','c','t','D','a','t','a',
67 0 };
68 static WCHAR removeSignedDataMsg[] = { 'M','s','i','S','I','P','R','e','m',
69 'o','v','e','S','i','g','n','e','d','D','a','t','a','M','s','g', 0 };
70 static WCHAR isMyTypeOfFile[] = { 'M','s','i','S','I','P',
71 'I','s','M','y','T','y','p','e','O','f','F','i','l','e',0 };
72
74
75 memset(&prov, 0, sizeof(prov));
76 prov.cbStruct = sizeof(prov);
77 prov.pwszDLLFileName = msisip;
78 prov.pgSubject = &mySubject;
79 prov.pwszGetFuncName = getSignedDataMsg;
80 prov.pwszPutFuncName = putSignedDataMsg;
81 prov.pwszCreateFuncName = createIndirectData;
82 prov.pwszVerifyFuncName = verifyIndirectData;
83 prov.pwszRemoveFuncName = removeSignedDataMsg;
84 prov.pwszIsFunctionNameFmt2 = isMyTypeOfFile;
86 return CryptSIPAddProvider(&prov) ? S_OK : S_FALSE;
87}
88
89/***********************************************************************
90 * DllUnregisterServer (MSISIP.@)
91 */
93{
95 return S_OK;
96}
97
98/***********************************************************************
99 * MsiSIPGetSignedDataMsg (MSISIP.@)
100 */
102 DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg,
103 BYTE *pbSignedDataMsg)
104{
105 static const WCHAR digitalSig[] = { 5,'D','i','g','i','t','a','l',
106 'S','i','g','n','a','t','u','r','e',0 };
107 BOOL ret = FALSE;
108 IStorage *stg = NULL;
109 HRESULT r;
110 IStream *stm = NULL;
111 BYTE hdr[2], len[sizeof(DWORD)];
112 DWORD count, lenBytes, dataBytes;
113
114 TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
115 pcbSignedDataMsg, pbSignedDataMsg);
116
117 r = StgOpenStorage(pSubjectInfo->pwsFileName, NULL,
119 if (FAILED(r))
120 {
121 TRACE("couldn't open %s\n", debugstr_w(pSubjectInfo->pwsFileName));
122 goto end;
123 }
124
125 r = IStorage_OpenStream(stg, digitalSig, 0,
127 if (FAILED(r))
128 {
129 TRACE("couldn't find digital signature stream\n");
130 goto freestorage;
131 }
132
133 r = IStream_Read(stm, hdr, sizeof(hdr), &count);
134 if (FAILED(r) || count != sizeof(hdr))
135 goto freestream;
136 if (hdr[0] != 0x30)
137 {
138 WARN("unexpected data in digital sig: 0x%02x%02x\n", hdr[0], hdr[1]);
139 goto freestream;
140 }
141
142 /* Read the asn.1 length from the stream. Only supports definite-length
143 * values, which DER-encoded signatures should be.
144 */
145 if (hdr[1] == 0x80)
146 {
147 WARN("indefinite-length encoding not supported!\n");
148 goto freestream;
149 }
150 else if (hdr[1] & 0x80)
151 {
152 DWORD temp;
153 LPBYTE ptr;
154
155 lenBytes = hdr[1] & 0x7f;
156 if (lenBytes > sizeof(DWORD))
157 {
158 WARN("asn.1 length too long (%d)\n", lenBytes);
159 goto freestream;
160 }
161 r = IStream_Read(stm, len, lenBytes, &count);
162 if (FAILED(r) || count != lenBytes)
163 goto freestream;
164 dataBytes = 0;
165 temp = lenBytes;
166 ptr = len;
167 while (temp--)
168 {
169 dataBytes <<= 8;
170 dataBytes |= *ptr++;
171 }
172 }
173 else
174 {
175 lenBytes = 0;
176 dataBytes = hdr[1];
177 }
178
179 if (!pbSignedDataMsg)
180 {
181 *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
182 ret = TRUE;
183 }
184 else if (*pcbSignedDataMsg < 2 + lenBytes + dataBytes)
185 {
187 *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
188 }
189 else
190 {
191 LPBYTE ptr = pbSignedDataMsg;
192
193 memcpy(ptr, hdr, sizeof(hdr));
194 ptr += sizeof(hdr);
195 if (lenBytes)
196 {
197 memcpy(ptr, len, lenBytes);
198 ptr += lenBytes;
199 }
200 r = IStream_Read(stm, ptr, dataBytes, &count);
201 if (SUCCEEDED(r) && count == dataBytes)
202 {
203 *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
204 *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
205 ret = TRUE;
206 }
207 }
208
209freestream:
210 IStream_Release(stm);
211freestorage:
212 IStorage_Release(stg);
213end:
214
215 TRACE("returning %d\n", ret);
216 return ret;
217}
218
219DEFINE_GUID(CLSID_MsiTransform, 0x000c1082,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
220DEFINE_GUID(CLSID_MsiDatabase, 0x000c1084,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
221DEFINE_GUID(CLSID_MsiPatch, 0x000c1086,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
222
223/***********************************************************************
224 * MsiSIPIsMyTypeOfFile (MSISIP.@)
225 */
227{
228 BOOL ret = FALSE;
229 IStorage *stg = NULL;
230 HRESULT r;
231
232 TRACE("(%s, %p)\n", debugstr_w(name), subject);
233
235 NULL, 0, &stg);
236 if (SUCCEEDED(r))
237 {
238 STATSTG stat;
239
240 r = IStorage_Stat(stg, &stat, STATFLAG_NONAME);
241 if (SUCCEEDED(r))
242 {
243 if (IsEqualGUID(&stat.clsid, &CLSID_MsiDatabase) ||
244 IsEqualGUID(&stat.clsid, &CLSID_MsiPatch) ||
245 IsEqualGUID(&stat.clsid, &CLSID_MsiTransform))
246 {
247 ret = TRUE;
248 *subject = mySubject;
249 }
250 }
251 IStorage_Release(stg);
252 }
253 return ret;
254}
#define stat
Definition: acwin.h:99
static DWORD const fdwReason
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: main.c:26
HRESULT WINAPI DllRegisterServer(void)
Definition: main.c:212
HRESULT WINAPI DllUnregisterServer(void)
Definition: main.c:220
BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
Definition: sip.c:112
BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
Definition: sip.c:207
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define SetLastError(x)
Definition: compat.h:752
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
static GUID mySubject
Definition: main.c:49
BOOL WINAPI MsiSIPIsMyTypeOfFile(WCHAR *name, GUID *subject)
Definition: main.c:226
BOOL WINAPI MsiSIPGetSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo, DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg, BYTE *pbSignedDataMsg)
Definition: main.c:101
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8755
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLsizei len
Definition: glext.h:6722
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
char hdr[14]
Definition: iptest.cpp:33
#define debugstr_w
Definition: kernel32.h:32
static IN DWORD IN LPVOID lpvReserved
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
#define DWORD
Definition: nt_native.h:44
#define STGM_DIRECT
Definition: objbase.h:914
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:923
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:922
#define STGM_READ
Definition: objbase.h:917
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
static calc_node_t temp
Definition: rpn_ieee.c:38
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
WCHAR * pwszPutFuncName
Definition: mssip.h:153
WCHAR * pwszCreateFuncName
Definition: mssip.h:154
GUID * pgSubject
Definition: mssip.h:145
WCHAR * pwszGetCapFuncName
Definition: mssip.h:161
WCHAR * pwszRemoveFuncName
Definition: mssip.h:156
WCHAR * pwszGetFuncName
Definition: mssip.h:152
WCHAR * pwszIsFunctionNameFmt2
Definition: mssip.h:158
WCHAR * pwszVerifyFuncName
Definition: mssip.h:155
WCHAR * pwszDLLFileName
Definition: mssip.h:147
LPCWSTR pwsFileName
Definition: mssip.h:54
Definition: name.c:39
Definition: stat.h:55
unsigned char * LPBYTE
Definition: typedefs.h:53
int ret
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2299
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193