ReactOS 0.4.17-dev-966-gf06eace
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
31static GUID mySubject = { 0x000c10f1, 0x0000, 0x0000,
32 { 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 }};
33
34/***********************************************************************
35 * DllRegisterServer (MSISIP.@)
36 */
38{
39 static WCHAR msisip[] = L"MSISIP.DLL";
40 static WCHAR getSignedDataMsg[] = L"MsiSIPGetSignedDataMsg";
41 static WCHAR putSignedDataMsg[] = L"MsiSIPPutSignedDataMsg";
42 static WCHAR createIndirectData[] = L"MsiSIPCreateIndirectData";
43 static WCHAR verifyIndirectData[] = L"MsiSIPVerifyIndirectData";
44 static WCHAR removeSignedDataMsg[] = L"MsiSIPRemoveSignedDataMsg";
45 static WCHAR isMyTypeOfFile[] = L"MsiSIPIsMyTypeOfFile";
46
48
49 memset(&prov, 0, sizeof(prov));
50 prov.cbStruct = sizeof(prov);
51 prov.pwszDLLFileName = msisip;
52 prov.pgSubject = &mySubject;
53 prov.pwszGetFuncName = getSignedDataMsg;
54 prov.pwszPutFuncName = putSignedDataMsg;
55 prov.pwszCreateFuncName = createIndirectData;
56 prov.pwszVerifyFuncName = verifyIndirectData;
57 prov.pwszRemoveFuncName = removeSignedDataMsg;
58 prov.pwszIsFunctionNameFmt2 = isMyTypeOfFile;
60 return CryptSIPAddProvider(&prov) ? S_OK : S_FALSE;
61}
62
63/***********************************************************************
64 * DllUnregisterServer (MSISIP.@)
65 */
67{
69 return S_OK;
70}
71
72/***********************************************************************
73 * MsiSIPGetSignedDataMsg (MSISIP.@)
74 */
76 DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg,
77 BYTE *pbSignedDataMsg)
78{
79 BOOL ret = FALSE;
80 IStorage *stg = NULL;
81 HRESULT r;
82 IStream *stm = NULL;
83 BYTE hdr[2], len[sizeof(DWORD)];
84 DWORD count, lenBytes, dataBytes;
85
86 TRACE("(%p %p %ld %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
87 pcbSignedDataMsg, pbSignedDataMsg);
88
89 r = StgOpenStorage(pSubjectInfo->pwsFileName, NULL,
91 if (FAILED(r))
92 {
93 TRACE("couldn't open %s\n", debugstr_w(pSubjectInfo->pwsFileName));
94 goto end;
95 }
96
97 r = IStorage_OpenStream(stg, L"\5DigitalSignature", 0,
99 if (FAILED(r))
100 {
101 TRACE("couldn't find digital signature stream\n");
102 goto freestorage;
103 }
104
105 r = IStream_Read(stm, hdr, sizeof(hdr), &count);
106 if (FAILED(r) || count != sizeof(hdr))
107 goto freestream;
108 if (hdr[0] != 0x30)
109 {
110 WARN("unexpected data in digital sig: 0x%02x%02x\n", hdr[0], hdr[1]);
111 goto freestream;
112 }
113
114 /* Read the asn.1 length from the stream. Only supports definite-length
115 * values, which DER-encoded signatures should be.
116 */
117 if (hdr[1] == 0x80)
118 {
119 WARN("indefinite-length encoding not supported!\n");
120 goto freestream;
121 }
122 else if (hdr[1] & 0x80)
123 {
124 DWORD temp;
125 LPBYTE ptr;
126
127 lenBytes = hdr[1] & 0x7f;
128 if (lenBytes > sizeof(DWORD))
129 {
130 WARN("asn.1 length too long (%ld)\n", lenBytes);
131 goto freestream;
132 }
133 r = IStream_Read(stm, len, lenBytes, &count);
134 if (FAILED(r) || count != lenBytes)
135 goto freestream;
136 dataBytes = 0;
137 temp = lenBytes;
138 ptr = len;
139 while (temp--)
140 {
141 dataBytes <<= 8;
142 dataBytes |= *ptr++;
143 }
144 }
145 else
146 {
147 lenBytes = 0;
148 dataBytes = hdr[1];
149 }
150
151 if (!pbSignedDataMsg)
152 {
153 *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
154 ret = TRUE;
155 }
156 else if (*pcbSignedDataMsg < 2 + lenBytes + dataBytes)
157 {
159 *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
160 }
161 else
162 {
163 LPBYTE ptr = pbSignedDataMsg;
164
165 memcpy(ptr, hdr, sizeof(hdr));
166 ptr += sizeof(hdr);
167 if (lenBytes)
168 {
169 memcpy(ptr, len, lenBytes);
170 ptr += lenBytes;
171 }
172 r = IStream_Read(stm, ptr, dataBytes, &count);
173 if (SUCCEEDED(r) && count == dataBytes)
174 {
175 *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
176 *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
177 ret = TRUE;
178 }
179 }
180
181freestream:
182 IStream_Release(stm);
183freestorage:
184 IStorage_Release(stg);
185end:
186
187 TRACE("returning %d\n", ret);
188 return ret;
189}
190
191DEFINE_GUID(CLSID_MsiTransform, 0x000c1082,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
192DEFINE_GUID(CLSID_MsiDatabase, 0x000c1084,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
193DEFINE_GUID(CLSID_MsiPatch, 0x000c1086,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
194
195/***********************************************************************
196 * MsiSIPIsMyTypeOfFile (MSISIP.@)
197 */
199{
200 BOOL ret = FALSE;
201 IStorage *stg = NULL;
202 HRESULT r;
203
204 TRACE("(%s, %p)\n", debugstr_w(name), subject);
205
207 NULL, 0, &stg);
208 if (SUCCEEDED(r))
209 {
210 STATSTG stat;
211
212 r = IStorage_Stat(stg, &stat, STATFLAG_NONAME);
213 if (SUCCEEDED(r))
214 {
215 if (IsEqualGUID(&stat.clsid, &CLSID_MsiDatabase) ||
216 IsEqualGUID(&stat.clsid, &CLSID_MsiPatch) ||
217 IsEqualGUID(&stat.clsid, &CLSID_MsiTransform))
218 {
219 ret = TRUE;
220 *subject = mySubject;
221 }
222 }
223 IStorage_Release(stg);
224 }
225 return ret;
226}
#define stat
Definition: acwin.h:100
#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
HRESULT WINAPI DllRegisterServer(void)
Definition: main.c:235
HRESULT WINAPI DllUnregisterServer(void)
Definition: main.c:259
BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
Definition: sip.c:86
BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
Definition: sip.c:181
#define SetLastError(x)
Definition: compat.h:752
static GUID mySubject
Definition: main.c:31
BOOL WINAPI MsiSIPIsMyTypeOfFile(WCHAR *name, GUID *subject)
Definition: main.c:198
BOOL WINAPI MsiSIPGetSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo, DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg, BYTE *pbSignedDataMsg)
Definition: main.c:75
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8701
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
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
#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:933
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:942
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:941
#define STGM_READ
Definition: objbase.h:936
short WCHAR
Definition: pedump.c:58
#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:66
unsigned char * LPBYTE
Definition: typedefs.h:53
#define X509_ASN_ENCODING
Definition: wincrypt.h:2501
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2503
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
unsigned char BYTE
Definition: xxhash.c:193