dpnet: Assign to structs instead of using memcpy.
[wine.git] / dlls / wintrust / crypt.c
blob8819ea8bb20b225f9c43a94cbb93c4141da50d6e
1 /*
2 * WinTrust Cryptography functions
4 * Copyright 2006 James Hawkins
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.
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.
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wintrust.h"
26 #include "mscat.h"
27 #include "mssip.h"
28 #include "imagehlp.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
34 /***********************************************************************
35 * CryptCATAdminAcquireContext (WINTRUST.@)
37 * Get a catalog administrator context handle.
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.
44 * RETURNS
45 * Success: TRUE. catAdmin contains the context handle.
46 * Failure: FALSE.
49 BOOL WINAPI CryptCATAdminAcquireContext(HCATADMIN* catAdmin,
50 const GUID *sysSystem, DWORD dwFlags )
52 FIXME("%p %s %x\n", catAdmin, debugstr_guid(sysSystem), dwFlags);
54 if (!catAdmin)
56 SetLastError(ERROR_INVALID_PARAMETER);
57 return FALSE;
60 *catAdmin = (HCATADMIN)0xdeadbeef;
62 return TRUE;
65 /***********************************************************************
66 * CryptCATAdminAddCatalog (WINTRUST.@)
68 BOOL WINAPI CryptCATAdminAddCatalog(HCATADMIN catAdmin, PWSTR catalogFile,
69 PWSTR selectBaseName, DWORD flags)
71 FIXME("%p %s %s %d\n", catAdmin, debugstr_w(catalogFile),
72 debugstr_w(selectBaseName), flags);
73 return TRUE;
76 /***********************************************************************
77 * CryptCATAdminCalcHashFromFileHandle (WINTRUST.@)
79 BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD* pcbHash,
80 BYTE* pbHash, DWORD dwFlags )
82 FIXME("%p %p %p %x\n", hFile, pcbHash, pbHash, dwFlags);
84 if (pbHash && pcbHash) memset(pbHash, 0, *pcbHash);
85 return TRUE;
88 /***********************************************************************
89 * CryptCATAdminEnumCatalogFromHash (WINTRUST.@)
91 HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin,
92 BYTE* pbHash,
93 DWORD cbHash,
94 DWORD dwFlags,
95 HCATINFO* phPrevCatInfo )
97 FIXME("%p %p %d %d %p\n", hCatAdmin, pbHash, cbHash, dwFlags, phPrevCatInfo);
98 return NULL;
101 /***********************************************************************
102 * CryptCATAdminReleaseCatalogContext (WINTRUST.@)
104 * Release a catalog context handle.
106 * PARAMS
107 * hCatAdmin [I] Context handle.
108 * hCatInfo [I] Catalog handle.
109 * dwFlags [I] Reserved.
111 * RETURNS
112 * Success: TRUE.
113 * Failure: FAIL.
116 BOOL WINAPI CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin,
117 HCATINFO hCatInfo,
118 DWORD dwFlags)
120 FIXME("%p %p %x\n", hCatAdmin, hCatInfo, dwFlags);
121 return TRUE;
124 /***********************************************************************
125 * CryptCATAdminReleaseContext (WINTRUST.@)
127 * Release a catalog administrator context handle.
129 * PARAMS
130 * catAdmin [I] Context handle.
131 * dwFlags [I] Reserved.
133 * RETURNS
134 * Success: TRUE.
135 * Failure: FAIL.
138 BOOL WINAPI CryptCATAdminReleaseContext(HCATADMIN hCatAdmin, DWORD dwFlags )
140 FIXME("%p %x\n", hCatAdmin, dwFlags);
141 return TRUE;
144 /***********************************************************************
145 * CryptCATAdminRemoveCatalog (WINTRUST.@)
147 * Remove a catalog file.
149 * PARAMS
150 * catAdmin [I] Context handle.
151 * pwszCatalogFile [I] Catalog file.
152 * dwFlags [I] Reserved.
154 * RETURNS
155 * Success: TRUE.
156 * Failure: FALSE.
159 BOOL WINAPI CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, LPCWSTR pwszCatalogFile, DWORD dwFlags)
161 FIXME("%p %s %x\n", hCatAdmin, debugstr_w(pwszCatalogFile), dwFlags);
162 return DeleteFileW(pwszCatalogFile);
165 /***********************************************************************
166 * CryptCATClose (WINTRUST.@)
168 BOOL WINAPI CryptCATClose(HANDLE hCatalog)
170 FIXME("(%p) stub\n", hCatalog);
171 return TRUE;
174 /***********************************************************************
175 * CryptCATEnumerateMember (WINTRUST.@)
177 CRYPTCATMEMBER *WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER* pPrevMember)
179 FIXME("(%p, %p) stub\n", hCatalog, pPrevMember);
180 return NULL;
183 /***********************************************************************
184 * CryptCATOpen (WINTRUST.@)
186 HANDLE WINAPI CryptCATOpen(LPWSTR pwszFileName, DWORD fdwOpenFlags, HCRYPTPROV hProv,
187 DWORD dwPublicVersion, DWORD dwEncodingType)
189 FIXME("(%s, %d, %ld, %d, %d) stub\n", debugstr_w(pwszFileName), fdwOpenFlags,
190 hProv, dwPublicVersion, dwEncodingType);
191 return 0;
194 /***********************************************************************
195 * CryptSIPCreateIndirectData (WINTRUST.@)
197 BOOL WINAPI CryptSIPCreateIndirectData(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pcbIndirectData,
198 SIP_INDIRECT_DATA* pIndirectData)
200 FIXME("(%p %p %p) stub\n", pSubjectInfo, pcbIndirectData, pIndirectData);
202 return FALSE;
205 /***********************************************************************
206 * CryptSIPGetSignedDataMsg (WINTRUST.@)
208 BOOL WINAPI CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pdwEncodingType,
209 DWORD dwIndex, DWORD* pcbSignedDataMsg, BYTE* pbSignedDataMsg)
211 BOOL ret;
212 WIN_CERTIFICATE *pCert = NULL;
214 TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
215 pcbSignedDataMsg, pbSignedDataMsg);
217 if (!pbSignedDataMsg)
219 WIN_CERTIFICATE cert;
221 /* app hasn't passed buffer, just get the length */
222 ret = ImageGetCertificateHeader(pSubjectInfo->hFile, dwIndex, &cert);
223 if (ret)
224 *pcbSignedDataMsg = cert.dwLength;
226 else
228 DWORD len = 0;
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)
236 ret = FALSE;
237 goto error;
239 ret = ImageGetCertificateData(pSubjectInfo->hFile, dwIndex, pCert,
240 &len);
241 if (!ret)
242 goto error;
243 if (*pcbSignedDataMsg < pCert->dwLength)
245 *pcbSignedDataMsg = pCert->dwLength;
246 SetLastError(ERROR_INSUFFICIENT_BUFFER);
247 ret = FALSE;
249 else
251 memcpy(pbSignedDataMsg, pCert->bCertificate, pCert->dwLength);
252 switch (pCert->wCertificateType)
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;
268 error:
269 HeapFree(GetProcessHeap(), 0, pCert);
270 TRACE("returning %d\n", ret);
271 return ret;
274 /***********************************************************************
275 * CryptSIPPutSignedDataMsg (WINTRUST.@)
277 BOOL WINAPI CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD pdwEncodingType,
278 DWORD* pdwIndex, DWORD cbSignedDataMsg, BYTE* pbSignedDataMsg)
280 FIXME("(%p %d %p %d %p) stub\n", pSubjectInfo, pdwEncodingType, pdwIndex,
281 cbSignedDataMsg, pbSignedDataMsg);
283 return FALSE;
286 /***********************************************************************
287 * CryptSIPRemoveSignedDataMsg (WINTRUST.@)
289 BOOL WINAPI CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo,
290 DWORD dwIndex)
292 FIXME("(%p %d) stub\n", pSubjectInfo, dwIndex);
294 return FALSE;
297 /***********************************************************************
298 * CryptSIPVerifyIndirectData (WINTRUST.@)
300 BOOL WINAPI CryptSIPVerifyIndirectData(SIP_SUBJECTINFO* pSubjectInfo,
301 SIP_INDIRECT_DATA* pIndirectData)
303 FIXME("(%p %p) stub\n", pSubjectInfo, pIndirectData);
305 return FALSE;