2 * Copyright 2008 Juan Lang
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msisip
);
31 static GUID mySubject
= { 0x000c10f1, 0x0000, 0x0000,
32 { 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 }};
34 /***********************************************************************
35 * DllRegisterServer (MSISIP.@)
37 HRESULT WINAPI
DllRegisterServer(void)
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";
47 SIP_ADD_NEWPROVIDER prov
;
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
;
59 prov
.pwszGetCapFuncName
= NULL
;
60 return CryptSIPAddProvider(&prov
) ? S_OK
: S_FALSE
;
63 /***********************************************************************
64 * DllUnregisterServer (MSISIP.@)
66 HRESULT WINAPI
DllUnregisterServer(void)
68 CryptSIPRemoveProvider(&mySubject
);
72 /***********************************************************************
73 * MsiSIPGetSignedDataMsg (MSISIP.@)
75 BOOL WINAPI
MsiSIPGetSignedDataMsg(SIP_SUBJECTINFO
*pSubjectInfo
,
76 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
77 BYTE
*pbSignedDataMsg
)
83 BYTE hdr
[2], len
[sizeof(DWORD
)];
84 DWORD count
, lenBytes
, dataBytes
;
86 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
87 pcbSignedDataMsg
, pbSignedDataMsg
);
89 r
= StgOpenStorage(pSubjectInfo
->pwsFileName
, NULL
,
90 STGM_DIRECT
|STGM_READ
|STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
93 TRACE("couldn't open %s\n", debugstr_w(pSubjectInfo
->pwsFileName
));
97 r
= IStorage_OpenStream(stg
, L
"\5DigitalSignature", 0,
98 STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stm
);
101 TRACE("couldn't find digital signature stream\n");
105 r
= IStream_Read(stm
, hdr
, sizeof(hdr
), &count
);
106 if (FAILED(r
) || count
!= sizeof(hdr
))
110 WARN("unexpected data in digital sig: 0x%02x%02x\n", hdr
[0], hdr
[1]);
114 /* Read the asn.1 length from the stream. Only supports definite-length
115 * values, which DER-encoded signatures should be.
119 WARN("indefinite-length encoding not supported!\n");
122 else if (hdr
[1] & 0x80)
127 lenBytes
= hdr
[1] & 0x7f;
128 if (lenBytes
> sizeof(DWORD
))
130 WARN("asn.1 length too long (%d)\n", lenBytes
);
133 r
= IStream_Read(stm
, len
, lenBytes
, &count
);
134 if (FAILED(r
) || count
!= lenBytes
)
151 if (!pbSignedDataMsg
)
153 *pcbSignedDataMsg
= 2 + lenBytes
+ dataBytes
;
156 else if (*pcbSignedDataMsg
< 2 + lenBytes
+ dataBytes
)
158 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
159 *pcbSignedDataMsg
= 2 + lenBytes
+ dataBytes
;
163 LPBYTE ptr
= pbSignedDataMsg
;
165 memcpy(ptr
, hdr
, sizeof(hdr
));
169 memcpy(ptr
, len
, lenBytes
);
172 r
= IStream_Read(stm
, ptr
, dataBytes
, &count
);
173 if (SUCCEEDED(r
) && count
== dataBytes
)
175 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
176 *pcbSignedDataMsg
= 2 + lenBytes
+ dataBytes
;
182 IStream_Release(stm
);
184 IStorage_Release(stg
);
187 TRACE("returning %d\n", ret
);
191 DEFINE_GUID(CLSID_MsiTransform
, 0x000c1082,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
192 DEFINE_GUID(CLSID_MsiDatabase
, 0x000c1084,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
193 DEFINE_GUID(CLSID_MsiPatch
, 0x000c1086,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
195 /***********************************************************************
196 * MsiSIPIsMyTypeOfFile (MSISIP.@)
198 BOOL WINAPI
MsiSIPIsMyTypeOfFile(WCHAR
*name
, GUID
*subject
)
201 IStorage
*stg
= NULL
;
204 TRACE("(%s, %p)\n", debugstr_w(name
), subject
);
206 r
= StgOpenStorage(name
, NULL
, STGM_DIRECT
|STGM_READ
|STGM_SHARE_DENY_WRITE
,
212 r
= IStorage_Stat(stg
, &stat
, STATFLAG_NONAME
);
215 if (IsEqualGUID(&stat
.clsid
, &CLSID_MsiDatabase
) ||
216 IsEqualGUID(&stat
.clsid
, &CLSID_MsiPatch
) ||
217 IsEqualGUID(&stat
.clsid
, &CLSID_MsiTransform
))
220 *subject
= mySubject
;
223 IStorage_Release(stg
);