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 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
33 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
37 case DLL_WINE_PREATTACH
:
38 return FALSE
; /* prefer native version */
39 case DLL_PROCESS_ATTACH
:
40 DisableThreadLibraryCalls(hinstDLL
);
47 static GUID mySubject
= { 0x000c10f1, 0x0000, 0x0000,
48 { 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 }};
50 /***********************************************************************
51 * DllRegisterServer (MSISIP.@)
53 HRESULT WINAPI
DllRegisterServer(void)
55 static WCHAR msisip
[] = L
"MSISIP.DLL";
56 static WCHAR getSignedDataMsg
[] = L
"MsiSIPGetSignedDataMsg";
57 static WCHAR putSignedDataMsg
[] = L
"MsiSIPPutSignedDataMsg";
58 static WCHAR createIndirectData
[] = L
"MsiSIPCreateIndirectData";
59 static WCHAR verifyIndirectData
[] = L
"MsiSIPVerifyIndirectData";
60 static WCHAR removeSignedDataMsg
[] = L
"MsiSIPRemoveSignedDataMsg";
61 static WCHAR isMyTypeOfFile
[] = L
"MsiSIPIsMyTypeOfFile";
63 SIP_ADD_NEWPROVIDER prov
;
65 memset(&prov
, 0, sizeof(prov
));
66 prov
.cbStruct
= sizeof(prov
);
67 prov
.pwszDLLFileName
= msisip
;
68 prov
.pgSubject
= &mySubject
;
69 prov
.pwszGetFuncName
= getSignedDataMsg
;
70 prov
.pwszPutFuncName
= putSignedDataMsg
;
71 prov
.pwszCreateFuncName
= createIndirectData
;
72 prov
.pwszVerifyFuncName
= verifyIndirectData
;
73 prov
.pwszRemoveFuncName
= removeSignedDataMsg
;
74 prov
.pwszIsFunctionNameFmt2
= isMyTypeOfFile
;
75 prov
.pwszGetCapFuncName
= NULL
;
76 return CryptSIPAddProvider(&prov
) ? S_OK
: S_FALSE
;
79 /***********************************************************************
80 * DllUnregisterServer (MSISIP.@)
82 HRESULT WINAPI
DllUnregisterServer(void)
84 CryptSIPRemoveProvider(&mySubject
);
88 /***********************************************************************
89 * MsiSIPGetSignedDataMsg (MSISIP.@)
91 BOOL WINAPI
MsiSIPGetSignedDataMsg(SIP_SUBJECTINFO
*pSubjectInfo
,
92 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
93 BYTE
*pbSignedDataMsg
)
99 BYTE hdr
[2], len
[sizeof(DWORD
)];
100 DWORD count
, lenBytes
, dataBytes
;
102 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
103 pcbSignedDataMsg
, pbSignedDataMsg
);
105 r
= StgOpenStorage(pSubjectInfo
->pwsFileName
, NULL
,
106 STGM_DIRECT
|STGM_READ
|STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
109 TRACE("couldn't open %s\n", debugstr_w(pSubjectInfo
->pwsFileName
));
113 r
= IStorage_OpenStream(stg
, L
"\5DigitalSignature", 0,
114 STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stm
);
117 TRACE("couldn't find digital signature stream\n");
121 r
= IStream_Read(stm
, hdr
, sizeof(hdr
), &count
);
122 if (FAILED(r
) || count
!= sizeof(hdr
))
126 WARN("unexpected data in digital sig: 0x%02x%02x\n", hdr
[0], hdr
[1]);
130 /* Read the asn.1 length from the stream. Only supports definite-length
131 * values, which DER-encoded signatures should be.
135 WARN("indefinite-length encoding not supported!\n");
138 else if (hdr
[1] & 0x80)
143 lenBytes
= hdr
[1] & 0x7f;
144 if (lenBytes
> sizeof(DWORD
))
146 WARN("asn.1 length too long (%d)\n", lenBytes
);
149 r
= IStream_Read(stm
, len
, lenBytes
, &count
);
150 if (FAILED(r
) || count
!= lenBytes
)
167 if (!pbSignedDataMsg
)
169 *pcbSignedDataMsg
= 2 + lenBytes
+ dataBytes
;
172 else if (*pcbSignedDataMsg
< 2 + lenBytes
+ dataBytes
)
174 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
175 *pcbSignedDataMsg
= 2 + lenBytes
+ dataBytes
;
179 LPBYTE ptr
= pbSignedDataMsg
;
181 memcpy(ptr
, hdr
, sizeof(hdr
));
185 memcpy(ptr
, len
, lenBytes
);
188 r
= IStream_Read(stm
, ptr
, dataBytes
, &count
);
189 if (SUCCEEDED(r
) && count
== dataBytes
)
191 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
192 *pcbSignedDataMsg
= 2 + lenBytes
+ dataBytes
;
198 IStream_Release(stm
);
200 IStorage_Release(stg
);
203 TRACE("returning %d\n", ret
);
207 DEFINE_GUID(CLSID_MsiTransform
, 0x000c1082,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
208 DEFINE_GUID(CLSID_MsiDatabase
, 0x000c1084,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
209 DEFINE_GUID(CLSID_MsiPatch
, 0x000c1086,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
211 /***********************************************************************
212 * MsiSIPIsMyTypeOfFile (MSISIP.@)
214 BOOL WINAPI
MsiSIPIsMyTypeOfFile(WCHAR
*name
, GUID
*subject
)
217 IStorage
*stg
= NULL
;
220 TRACE("(%s, %p)\n", debugstr_w(name
), subject
);
222 r
= StgOpenStorage(name
, NULL
, STGM_DIRECT
|STGM_READ
|STGM_SHARE_DENY_WRITE
,
228 r
= IStorage_Stat(stg
, &stat
, STATFLAG_NONAME
);
231 if (IsEqualGUID(&stat
.clsid
, &CLSID_MsiDatabase
) ||
232 IsEqualGUID(&stat
.clsid
, &CLSID_MsiPatch
) ||
233 IsEqualGUID(&stat
.clsid
, &CLSID_MsiTransform
))
236 *subject
= mySubject
;
239 IStorage_Release(stg
);