wintrust: Remove redundant check of pbSignedDataMsg (Coverity).
[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) *catAdmin = (HCATADMIN)0xdeadbeef;
55     return TRUE;
56 }
57
58 /***********************************************************************
59  *             CryptCATAdminAddCatalog (WINTRUST.@)
60  */
61 BOOL WINAPI CryptCATAdminAddCatalog(HCATADMIN catAdmin, PWSTR catalogFile,
62                                     PWSTR selectBaseName, DWORD flags)
63 {
64     FIXME("%p %s %s %d\n", catAdmin, debugstr_w(catalogFile),
65           debugstr_w(selectBaseName), flags);
66     return TRUE;
67 }
68
69 /***********************************************************************
70  *             CryptCATAdminCalcHashFromFileHandle (WINTRUST.@)
71  */
72 BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD* pcbHash,
73                                                 BYTE* pbHash, DWORD dwFlags )
74 {
75     FIXME("%p %p %p %x\n", hFile, pcbHash, pbHash, dwFlags);
76
77     if (pbHash && pcbHash) memset(pbHash, 0, *pcbHash);
78     return TRUE;
79 }
80
81 /***********************************************************************
82  *             CryptCATAdminEnumCatalogFromHash (WINTRUST.@)
83  */
84 HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin,
85                                                  BYTE* pbHash,
86                                                  DWORD cbHash,
87                                                  DWORD dwFlags,
88                                                  HCATINFO* phPrevCatInfo )
89 {
90     FIXME("%p %p %d %d %p\n", hCatAdmin, pbHash, cbHash, dwFlags, phPrevCatInfo);
91     return NULL;
92 }
93
94 /***********************************************************************
95  *      CryptCATAdminReleaseCatalogContext (WINTRUST.@)
96  *
97  * Release a catalog context handle.
98  *
99  * PARAMS
100  *   hCatAdmin [I] Context handle.
101  *   hCatInfo  [I] Catalog handle.
102  *   dwFlags   [I] Reserved.
103  *
104  * RETURNS
105  *   Success: TRUE.
106  *   Failure: FAIL.
107  *
108  */
109 BOOL WINAPI CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin,
110                                                HCATINFO hCatInfo,
111                                                DWORD dwFlags)
112 {
113     FIXME("%p %p %x\n", hCatAdmin, hCatInfo, dwFlags);
114     return TRUE;
115 }
116
117 /***********************************************************************
118  *      CryptCATAdminReleaseContext (WINTRUST.@)
119  *
120  * Release a catalog administrator context handle.
121  *
122  * PARAMS
123  *   catAdmin  [I] Context handle.
124  *   dwFlags   [I] Reserved.
125  *
126  * RETURNS
127  *   Success: TRUE.
128  *   Failure: FAIL.
129  *
130  */
131 BOOL WINAPI CryptCATAdminReleaseContext(HCATADMIN hCatAdmin, DWORD dwFlags )
132 {
133     FIXME("%p %x\n", hCatAdmin, dwFlags);
134     return TRUE;
135 }
136
137 /***********************************************************************
138  *      CryptCATAdminRemoveCatalog (WINTRUST.@)
139  *
140  * Remove a catalog file.
141  *
142  * PARAMS
143  *   catAdmin         [I] Context handle.
144  *   pwszCatalogFile  [I] Catalog file.
145  *   dwFlags          [I] Reserved.
146  *
147  * RETURNS
148  *   Success: TRUE.
149  *   Failure: FALSE.
150  *
151  */
152 BOOL WINAPI CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, LPCWSTR pwszCatalogFile, DWORD dwFlags)
153 {
154     FIXME("%p %s %x\n", hCatAdmin, debugstr_w(pwszCatalogFile), dwFlags);
155     return DeleteFileW(pwszCatalogFile);
156 }
157
158 /***********************************************************************
159  *      CryptCATClose  (WINTRUST.@)
160  */
161 BOOL WINAPI CryptCATClose(HANDLE hCatalog)
162 {
163     FIXME("(%p) stub\n", hCatalog);
164     return TRUE;
165 }
166
167 /***********************************************************************
168  *      CryptCATEnumerateMember  (WINTRUST.@)
169  */
170 CRYPTCATMEMBER *WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER* pPrevMember)
171 {
172     FIXME("(%p, %p) stub\n", hCatalog, pPrevMember);
173     return NULL;
174 }
175
176 /***********************************************************************
177  *      CryptCATOpen  (WINTRUST.@)
178  */
179 HANDLE WINAPI CryptCATOpen(LPWSTR pwszFileName, DWORD fdwOpenFlags, HCRYPTPROV hProv,
180                            DWORD dwPublicVersion, DWORD dwEncodingType)
181 {
182     FIXME("(%s, %d, %ld, %d, %d) stub\n", debugstr_w(pwszFileName), fdwOpenFlags,
183           hProv, dwPublicVersion, dwEncodingType);
184     return 0;
185 }
186
187 /***********************************************************************
188  *      CryptSIPCreateIndirectData  (WINTRUST.@)
189  */
190 BOOL WINAPI CryptSIPCreateIndirectData(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pcbIndirectData,
191                                        SIP_INDIRECT_DATA* pIndirectData)
192 {
193     FIXME("(%p %p %p) stub\n", pSubjectInfo, pcbIndirectData, pIndirectData);
194  
195     return FALSE;
196 }
197
198 /***********************************************************************
199  *      CryptSIPGetSignedDataMsg  (WINTRUST.@)
200  */
201 BOOL WINAPI CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pdwEncodingType,
202                                        DWORD dwIndex, DWORD* pcbSignedDataMsg, BYTE* pbSignedDataMsg)
203 {
204     BOOL ret;
205     WIN_CERTIFICATE *pCert = NULL;
206
207     TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
208           pcbSignedDataMsg, pbSignedDataMsg);
209  
210     if (!pbSignedDataMsg)
211     {
212         WIN_CERTIFICATE cert;
213
214         /* app hasn't passed buffer, just get the length */
215         ret = ImageGetCertificateHeader(pSubjectInfo->hFile, dwIndex, &cert);
216         if (ret)
217             *pcbSignedDataMsg = cert.dwLength;
218     }
219     else
220     {
221         DWORD len;
222
223         ret = ImageGetCertificateData(pSubjectInfo->hFile, dwIndex, NULL, &len);
224         if (!ret)
225             goto error;
226         pCert = HeapAlloc(GetProcessHeap(), 0, len);
227         if (!pCert)
228         {
229             ret = FALSE;
230             goto error;
231         }
232         ret = ImageGetCertificateData(pSubjectInfo->hFile, dwIndex, pCert,
233          &len);
234         if (!ret)
235             goto error;
236         if (*pcbSignedDataMsg < pCert->dwLength)
237         {
238             *pcbSignedDataMsg = pCert->dwLength;
239             SetLastError(ERROR_INSUFFICIENT_BUFFER);
240             ret = FALSE;
241         }
242         else
243         {
244             memcpy(pbSignedDataMsg, pCert->bCertificate, pCert->dwLength);
245             switch (pCert->wCertificateType)
246             {
247             case WIN_CERT_TYPE_X509:
248                 *pdwEncodingType = X509_ASN_ENCODING;
249                 break;
250             case WIN_CERT_TYPE_PKCS_SIGNED_DATA:
251                 *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
252                 break;
253             default:
254                 FIXME("don't know what to do for encoding type %d\n",
255                  pCert->wCertificateType);
256                 *pdwEncodingType = 0;
257             }
258         }
259     }
260
261 error:
262     HeapFree(GetProcessHeap(), 0, pCert);
263     TRACE("returning %d\n", ret);
264     return ret;
265 }
266
267 /***********************************************************************
268  *      CryptSIPPutSignedDataMsg  (WINTRUST.@)
269  */
270 BOOL WINAPI CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD pdwEncodingType,
271                                        DWORD* pdwIndex, DWORD cbSignedDataMsg, BYTE* pbSignedDataMsg)
272 {
273     FIXME("(%p %d %p %d %p) stub\n", pSubjectInfo, pdwEncodingType, pdwIndex,
274           cbSignedDataMsg, pbSignedDataMsg);
275  
276     return FALSE;
277 }
278
279 /***********************************************************************
280  *      CryptSIPRemoveSignedDataMsg  (WINTRUST.@)
281  */
282 BOOL WINAPI CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo,
283                                        DWORD dwIndex)
284 {
285     FIXME("(%p %d) stub\n", pSubjectInfo, dwIndex);
286  
287     return FALSE;
288 }
289
290 /***********************************************************************
291  *      CryptSIPVerifyIndirectData  (WINTRUST.@)
292  */
293 BOOL WINAPI CryptSIPVerifyIndirectData(SIP_SUBJECTINFO* pSubjectInfo,
294                                        SIP_INDIRECT_DATA* pIndirectData)
295 {
296     FIXME("(%p %p) stub\n", pSubjectInfo, pIndirectData);
297  
298     return FALSE;
299 }