listview: Implement 2 pixel decoration at top of report style with grid lines.
[wine] / dlls / wintrust / crypt.c
1 /*
2  * WinTrust Cryptography functions
3  *
4  * Copyright 2006 James Hawkins
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wintrust.h"
26 #include "mscat.h"
27 #include "mssip.h"
28 #include "imagehlp.h"
29
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
33
34 /***********************************************************************
35  *      CryptCATAdminAcquireContext (WINTRUST.@)
36  *
37  * Get a catalog administrator context handle.
38  *
39  * PARAMS
40  *   catAdmin  [O] Pointer to the context handle.
41  *   sysSystem [I] Pointer to a GUID for the needed subsystem.
42  *   dwFlags   [I] Reserved.
43  *
44  * RETURNS
45  *   Success: TRUE. catAdmin contains the context handle.
46  *   Failure: FALSE.
47  *
48  */
49 BOOL WINAPI CryptCATAdminAcquireContext(HCATADMIN* catAdmin,
50                     const GUID *sysSystem, DWORD dwFlags )
51 {
52     FIXME("%p %s %x\n", catAdmin, debugstr_guid(sysSystem), dwFlags);
53
54     if (!catAdmin)
55     {
56         SetLastError(ERROR_INVALID_PARAMETER);
57         return FALSE;
58     }
59
60     *catAdmin = (HCATADMIN)0xdeadbeef;
61
62     return TRUE;
63 }
64
65 /***********************************************************************
66  *             CryptCATAdminAddCatalog (WINTRUST.@)
67  */
68 BOOL WINAPI CryptCATAdminAddCatalog(HCATADMIN catAdmin, PWSTR catalogFile,
69                                     PWSTR selectBaseName, DWORD flags)
70 {
71     FIXME("%p %s %s %d\n", catAdmin, debugstr_w(catalogFile),
72           debugstr_w(selectBaseName), flags);
73     return TRUE;
74 }
75
76 /***********************************************************************
77  *             CryptCATAdminCalcHashFromFileHandle (WINTRUST.@)
78  */
79 BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD* pcbHash,
80                                                 BYTE* pbHash, DWORD dwFlags )
81 {
82     FIXME("%p %p %p %x\n", hFile, pcbHash, pbHash, dwFlags);
83
84     if (pbHash && pcbHash) memset(pbHash, 0, *pcbHash);
85     return TRUE;
86 }
87
88 /***********************************************************************
89  *             CryptCATAdminEnumCatalogFromHash (WINTRUST.@)
90  */
91 HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin,
92                                                  BYTE* pbHash,
93                                                  DWORD cbHash,
94                                                  DWORD dwFlags,
95                                                  HCATINFO* phPrevCatInfo )
96 {
97     FIXME("%p %p %d %d %p\n", hCatAdmin, pbHash, cbHash, dwFlags, phPrevCatInfo);
98     return NULL;
99 }
100
101 /***********************************************************************
102  *      CryptCATAdminReleaseCatalogContext (WINTRUST.@)
103  *
104  * Release a catalog context handle.
105  *
106  * PARAMS
107  *   hCatAdmin [I] Context handle.
108  *   hCatInfo  [I] Catalog handle.
109  *   dwFlags   [I] Reserved.
110  *
111  * RETURNS
112  *   Success: TRUE.
113  *   Failure: FAIL.
114  *
115  */
116 BOOL WINAPI CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin,
117                                                HCATINFO hCatInfo,
118                                                DWORD dwFlags)
119 {
120     FIXME("%p %p %x\n", hCatAdmin, hCatInfo, dwFlags);
121     return TRUE;
122 }
123
124 /***********************************************************************
125  *      CryptCATAdminReleaseContext (WINTRUST.@)
126  *
127  * Release a catalog administrator context handle.
128  *
129  * PARAMS
130  *   catAdmin  [I] Context handle.
131  *   dwFlags   [I] Reserved.
132  *
133  * RETURNS
134  *   Success: TRUE.
135  *   Failure: FAIL.
136  *
137  */
138 BOOL WINAPI CryptCATAdminReleaseContext(HCATADMIN hCatAdmin, DWORD dwFlags )
139 {
140     FIXME("%p %x\n", hCatAdmin, dwFlags);
141     return TRUE;
142 }
143
144 /***********************************************************************
145  *      CryptCATAdminRemoveCatalog (WINTRUST.@)
146  *
147  * Remove a catalog file.
148  *
149  * PARAMS
150  *   catAdmin         [I] Context handle.
151  *   pwszCatalogFile  [I] Catalog file.
152  *   dwFlags          [I] Reserved.
153  *
154  * RETURNS
155  *   Success: TRUE.
156  *   Failure: FALSE.
157  *
158  */
159 BOOL WINAPI CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, LPCWSTR pwszCatalogFile, DWORD dwFlags)
160 {
161     FIXME("%p %s %x\n", hCatAdmin, debugstr_w(pwszCatalogFile), dwFlags);
162     return DeleteFileW(pwszCatalogFile);
163 }
164
165 /***********************************************************************
166  *      CryptCATClose  (WINTRUST.@)
167  */
168 BOOL WINAPI CryptCATClose(HANDLE hCatalog)
169 {
170     FIXME("(%p) stub\n", hCatalog);
171     return TRUE;
172 }
173
174 /***********************************************************************
175  *      CryptCATEnumerateMember  (WINTRUST.@)
176  */
177 CRYPTCATMEMBER *WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER* pPrevMember)
178 {
179     FIXME("(%p, %p) stub\n", hCatalog, pPrevMember);
180     return NULL;
181 }
182
183 /***********************************************************************
184  *      CryptCATOpen  (WINTRUST.@)
185  */
186 HANDLE WINAPI CryptCATOpen(LPWSTR pwszFileName, DWORD fdwOpenFlags, HCRYPTPROV hProv,
187                            DWORD dwPublicVersion, DWORD dwEncodingType)
188 {
189     FIXME("(%s, %d, %ld, %d, %d) stub\n", debugstr_w(pwszFileName), fdwOpenFlags,
190           hProv, dwPublicVersion, dwEncodingType);
191     return 0;
192 }
193
194 /***********************************************************************
195  *      CryptSIPCreateIndirectData  (WINTRUST.@)
196  */
197 BOOL WINAPI CryptSIPCreateIndirectData(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pcbIndirectData,
198                                        SIP_INDIRECT_DATA* pIndirectData)
199 {
200     FIXME("(%p %p %p) stub\n", pSubjectInfo, pcbIndirectData, pIndirectData);
201  
202     return FALSE;
203 }
204
205 /***********************************************************************
206  *      CryptSIPGetSignedDataMsg  (WINTRUST.@)
207  */
208 BOOL WINAPI CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pdwEncodingType,
209                                        DWORD dwIndex, DWORD* pcbSignedDataMsg, BYTE* pbSignedDataMsg)
210 {
211     BOOL ret;
212     WIN_CERTIFICATE *pCert = NULL;
213
214     TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
215           pcbSignedDataMsg, pbSignedDataMsg);
216  
217     if (!pbSignedDataMsg)
218     {
219         WIN_CERTIFICATE cert;
220
221         /* app hasn't passed buffer, just get the length */
222         ret = ImageGetCertificateHeader(pSubjectInfo->hFile, dwIndex, &cert);
223         if (ret)
224             *pcbSignedDataMsg = cert.dwLength;
225     }
226     else
227     {
228         DWORD len = 0;
229
230         ret = ImageGetCertificateData(pSubjectInfo->hFile, dwIndex, NULL, &len);
231         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
232             goto error;
233         pCert = HeapAlloc(GetProcessHeap(), 0, len);
234         if (!pCert)
235         {
236             ret = FALSE;
237             goto error;
238         }
239         ret = ImageGetCertificateData(pSubjectInfo->hFile, dwIndex, pCert,
240          &len);
241         if (!ret)
242             goto error;
243         if (*pcbSignedDataMsg < pCert->dwLength)
244         {
245             *pcbSignedDataMsg = pCert->dwLength;
246             SetLastError(ERROR_INSUFFICIENT_BUFFER);
247             ret = FALSE;
248         }
249         else
250         {
251             memcpy(pbSignedDataMsg, pCert->bCertificate, pCert->dwLength);
252             switch (pCert->wCertificateType)
253             {
254             case WIN_CERT_TYPE_X509:
255                 *pdwEncodingType = X509_ASN_ENCODING;
256                 break;
257             case WIN_CERT_TYPE_PKCS_SIGNED_DATA:
258                 *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
259                 break;
260             default:
261                 FIXME("don't know what to do for encoding type %d\n",
262                  pCert->wCertificateType);
263                 *pdwEncodingType = 0;
264             }
265         }
266     }
267
268 error:
269     HeapFree(GetProcessHeap(), 0, pCert);
270     TRACE("returning %d\n", ret);
271     return ret;
272 }
273
274 /***********************************************************************
275  *      CryptSIPPutSignedDataMsg  (WINTRUST.@)
276  */
277 BOOL WINAPI CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD pdwEncodingType,
278                                        DWORD* pdwIndex, DWORD cbSignedDataMsg, BYTE* pbSignedDataMsg)
279 {
280     FIXME("(%p %d %p %d %p) stub\n", pSubjectInfo, pdwEncodingType, pdwIndex,
281           cbSignedDataMsg, pbSignedDataMsg);
282  
283     return FALSE;
284 }
285
286 /***********************************************************************
287  *      CryptSIPRemoveSignedDataMsg  (WINTRUST.@)
288  */
289 BOOL WINAPI CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo,
290                                        DWORD dwIndex)
291 {
292     FIXME("(%p %d) stub\n", pSubjectInfo, dwIndex);
293  
294     return FALSE;
295 }
296
297 /***********************************************************************
298  *      CryptSIPVerifyIndirectData  (WINTRUST.@)
299  */
300 BOOL WINAPI CryptSIPVerifyIndirectData(SIP_SUBJECTINFO* pSubjectInfo,
301                                        SIP_INDIRECT_DATA* pIndirectData)
302 {
303     FIXME("(%p %p) stub\n", pSubjectInfo, pIndirectData);
304  
305     return FALSE;
306 }