d3d9: Add tests for IDirect3D9Device_Reset.
[wine/hacks.git] / dlls / wintrust / crypt.c
blobe01a23006fab3ce7493b641dab3b080a6e8ea258
1 /*
2 * WinTrust Cryptography functions
4 * Copyright 2006 James Hawkins
5 * Copyright 2000-2002 Stuart Caie
6 * Copyright 2002 Patrik Stridvall
7 * Copyright 2003 Greg Turner
8 * Copyright 2008 Juan Lang
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wintrust.h"
30 #include "mscat.h"
31 #include "mssip.h"
32 #include "imagehlp.h"
33 #include "winternl.h"
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
40 #define CATADMIN_MAGIC 0x43415441 /* 'CATA' */
41 #define CRYPTCAT_MAGIC 0x43415443 /* 'CATC' */
42 #define CATINFO_MAGIC 0x43415449 /* 'CATI' */
44 struct cryptcat
46 DWORD magic;
47 HCRYPTMSG msg;
48 DWORD encoding;
49 CTL_INFO *inner;
50 DWORD inner_len;
51 GUID subject;
52 DWORD attr_count;
53 CRYPTCATATTRIBUTE *attr;
56 struct catadmin
58 DWORD magic;
59 WCHAR path[MAX_PATH];
60 HANDLE find;
63 struct catinfo
65 DWORD magic;
66 WCHAR file[MAX_PATH];
69 static HCATINFO create_catinfo(const WCHAR *filename)
71 struct catinfo *ci;
73 if (!(ci = HeapAlloc(GetProcessHeap(), 0, sizeof(*ci))))
75 SetLastError(ERROR_OUTOFMEMORY);
76 return INVALID_HANDLE_VALUE;
78 strcpyW(ci->file, filename);
79 ci->magic = CATINFO_MAGIC;
80 return ci;
83 /***********************************************************************
84 * CryptCATAdminAcquireContext (WINTRUST.@)
86 * Get a catalog administrator context handle.
88 * PARAMS
89 * catAdmin [O] Pointer to the context handle.
90 * sys [I] Pointer to a GUID for the needed subsystem.
91 * dwFlags [I] Reserved.
93 * RETURNS
94 * Success: TRUE. catAdmin contains the context handle.
95 * Failure: FALSE.
98 BOOL WINAPI CryptCATAdminAcquireContext(HCATADMIN *catAdmin,
99 const GUID *sys, DWORD dwFlags)
101 static const WCHAR catroot[] =
102 {'\\','c','a','t','r','o','o','t',0};
103 static const WCHAR fmt[] =
104 {'%','s','\\','{','%','0','8','x','-','%','0','4','x','-','%','0',
105 '4','x','-','%','0','2','x','%','0','2','x','-','%','0','2','x',
106 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
107 '%','0','2','x','}',0};
108 static const GUID defsys =
109 {0x127d0a1d,0x4ef2,0x11d1,{0x86,0x08,0x00,0xc0,0x4f,0xc2,0x95,0xee}};
111 WCHAR catroot_dir[MAX_PATH];
112 struct catadmin *ca;
114 TRACE("%p %s %x\n", catAdmin, debugstr_guid(sys), dwFlags);
116 if (!catAdmin)
118 SetLastError(ERROR_INVALID_PARAMETER);
119 return FALSE;
121 if (!(ca = HeapAlloc(GetProcessHeap(), 0, sizeof(*ca))))
123 SetLastError(ERROR_OUTOFMEMORY);
124 return FALSE;
127 GetSystemDirectoryW(catroot_dir, MAX_PATH);
128 strcatW(catroot_dir, catroot);
130 /* create the directory if it doesn't exist */
131 CreateDirectoryW(catroot_dir, NULL);
133 if (!sys) sys = &defsys;
134 sprintfW(ca->path, fmt, catroot_dir, sys->Data1, sys->Data2,
135 sys->Data3, sys->Data4[0], sys->Data4[1], sys->Data4[2],
136 sys->Data4[3], sys->Data4[4], sys->Data4[5], sys->Data4[6],
137 sys->Data4[7]);
139 /* create the directory if it doesn't exist */
140 CreateDirectoryW(ca->path, NULL);
142 ca->magic = CATADMIN_MAGIC;
143 ca->find = INVALID_HANDLE_VALUE;
145 *catAdmin = ca;
146 return TRUE;
149 /***********************************************************************
150 * CryptCATAdminAddCatalog (WINTRUST.@)
152 HCATINFO WINAPI CryptCATAdminAddCatalog(HCATADMIN catAdmin, PWSTR catalogFile,
153 PWSTR selectBaseName, DWORD flags)
155 static const WCHAR slashW[] = {'\\',0};
156 struct catadmin *ca = catAdmin;
157 struct catinfo *ci;
158 WCHAR *target;
159 DWORD len;
161 TRACE("%p %s %s %d\n", catAdmin, debugstr_w(catalogFile),
162 debugstr_w(selectBaseName), flags);
164 if (!selectBaseName)
166 FIXME("NULL basename not handled\n");
167 SetLastError(ERROR_INVALID_PARAMETER);
168 return NULL;
170 if (!ca || ca->magic != CATADMIN_MAGIC || !catalogFile || flags)
172 SetLastError(ERROR_INVALID_PARAMETER);
173 return NULL;
176 len = strlenW(ca->path) + strlenW(selectBaseName) + 2;
177 if (!(target = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
179 SetLastError(ERROR_OUTOFMEMORY);
180 return NULL;
182 strcpyW(target, ca->path);
183 strcatW(target, slashW);
184 strcatW(target, selectBaseName);
186 if (!CopyFileW(catalogFile, target, FALSE))
188 HeapFree(GetProcessHeap(), 0, target);
189 return NULL;
191 SetFileAttributesW(target, FILE_ATTRIBUTE_SYSTEM);
193 if (!(ci = HeapAlloc(GetProcessHeap(), 0, sizeof(*ci))))
195 HeapFree(GetProcessHeap(), 0, target);
196 SetLastError(ERROR_OUTOFMEMORY);
197 return NULL;
199 ci->magic = CATINFO_MAGIC;
200 strcpyW(ci->file, target);
202 HeapFree(GetProcessHeap(), 0, target);
203 return ci;
206 /***********************************************************************
207 * CryptCATAdminCalcHashFromFileHandle (WINTRUST.@)
209 BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD* pcbHash,
210 BYTE* pbHash, DWORD dwFlags )
212 BOOL ret = FALSE;
214 TRACE("%p %p %p %x\n", hFile, pcbHash, pbHash, dwFlags);
216 if (!hFile || !pcbHash || dwFlags)
218 SetLastError(ERROR_INVALID_PARAMETER);
219 return FALSE;
221 if (*pcbHash < 20)
223 *pcbHash = 20;
224 SetLastError(ERROR_INSUFFICIENT_BUFFER);
225 return TRUE;
228 *pcbHash = 20;
229 if (pbHash)
231 HCRYPTPROV prov;
232 HCRYPTHASH hash;
233 DWORD bytes_read;
234 BYTE *buffer;
236 if (!(buffer = HeapAlloc(GetProcessHeap(), 0, 4096)))
238 SetLastError(ERROR_OUTOFMEMORY);
239 return FALSE;
241 ret = CryptAcquireContextW(&prov, NULL, MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
242 if (!ret)
244 HeapFree(GetProcessHeap(), 0, buffer);
245 return FALSE;
247 ret = CryptCreateHash(prov, CALG_SHA1, 0, 0, &hash);
248 if (!ret)
250 HeapFree(GetProcessHeap(), 0, buffer);
251 CryptReleaseContext(prov, 0);
252 return FALSE;
254 while ((ret = ReadFile(hFile, buffer, 4096, &bytes_read, NULL)) && bytes_read)
256 CryptHashData(hash, buffer, bytes_read, 0);
258 if (ret) ret = CryptGetHashParam(hash, HP_HASHVAL, pbHash, pcbHash, 0);
260 HeapFree(GetProcessHeap(), 0, buffer);
261 CryptDestroyHash(hash);
262 CryptReleaseContext(prov, 0);
264 return ret;
267 /***********************************************************************
268 * CryptCATAdminEnumCatalogFromHash (WINTRUST.@)
270 HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin, BYTE* pbHash,
271 DWORD cbHash, DWORD dwFlags,
272 HCATINFO* phPrevCatInfo )
274 static const WCHAR slashW[] = {'\\',0};
275 static const WCHAR globW[] = {'\\','*','.','c','a','t',0};
277 struct catadmin *ca = hCatAdmin;
278 WIN32_FIND_DATAW data;
279 HCATINFO prev = NULL;
280 HCRYPTPROV prov;
281 DWORD size;
282 BOOL ret;
284 TRACE("%p %p %d %x %p\n", hCatAdmin, pbHash, cbHash, dwFlags, phPrevCatInfo);
286 if (!ca || ca->magic != CATADMIN_MAGIC || !pbHash || cbHash != 20 || dwFlags)
288 SetLastError(ERROR_INVALID_PARAMETER);
289 return NULL;
291 if (phPrevCatInfo) prev = *phPrevCatInfo;
293 ret = CryptAcquireContextW(&prov, NULL, MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
294 if (!ret) return NULL;
296 if (!prev)
298 WCHAR *path;
300 size = strlenW(ca->path) * sizeof(WCHAR) + sizeof(globW);
301 if (!(path = HeapAlloc(GetProcessHeap(), 0, size)))
303 CryptReleaseContext(prov, 0);
304 SetLastError(ERROR_OUTOFMEMORY);
305 return NULL;
307 strcpyW(path, ca->path);
308 strcatW(path, globW);
310 FindClose(ca->find);
311 ca->find = FindFirstFileW(path, &data);
313 HeapFree(GetProcessHeap(), 0, path);
314 if (ca->find == INVALID_HANDLE_VALUE)
316 CryptReleaseContext(prov, 0);
317 return NULL;
320 else if (!FindNextFileW(ca->find, &data))
322 CryptCATAdminReleaseCatalogContext(hCatAdmin, prev, 0);
323 CryptReleaseContext(prov, 0);
324 return NULL;
327 while (1)
329 WCHAR *filename;
330 CRYPTCATMEMBER *member = NULL;
331 struct catinfo *ci;
332 HANDLE hcat;
334 size = (strlenW(ca->path) + strlenW(data.cFileName) + 2) * sizeof(WCHAR);
335 if (!(filename = HeapAlloc(GetProcessHeap(), 0, size)))
337 SetLastError(ERROR_OUTOFMEMORY);
338 return NULL;
340 strcpyW(filename, ca->path);
341 strcatW(filename, slashW);
342 strcatW(filename, data.cFileName);
344 hcat = CryptCATOpen(filename, CRYPTCAT_OPEN_EXISTING, prov, 0, 0);
345 if (hcat == INVALID_HANDLE_VALUE)
347 WARN("couldn't open %s (%u)\n", debugstr_w(filename), GetLastError());
348 continue;
350 while ((member = CryptCATEnumerateMember(hcat, member)))
352 if (member->pIndirectData->Digest.cbData != cbHash)
354 WARN("amount of hash bytes differs: %u/%u\n", member->pIndirectData->Digest.cbData, cbHash);
355 continue;
357 if (!memcmp(member->pIndirectData->Digest.pbData, pbHash, cbHash))
359 TRACE("file %s matches\n", debugstr_w(data.cFileName));
361 CryptCATClose(hcat);
362 CryptReleaseContext(prov, 0);
363 if (!phPrevCatInfo)
365 FindClose(ca->find);
366 ca->find = INVALID_HANDLE_VALUE;
368 ci = create_catinfo(filename);
369 HeapFree(GetProcessHeap(), 0, filename);
370 return ci;
373 CryptCATClose(hcat);
374 HeapFree(GetProcessHeap(), 0, filename);
376 if (!FindNextFileW(ca->find, &data))
378 FindClose(ca->find);
379 ca->find = INVALID_HANDLE_VALUE;
380 CryptReleaseContext(prov, 0);
381 return NULL;
384 return NULL;
387 /***********************************************************************
388 * CryptCATAdminReleaseCatalogContext (WINTRUST.@)
390 * Release a catalog context handle.
392 * PARAMS
393 * hCatAdmin [I] Context handle.
394 * hCatInfo [I] Catalog handle.
395 * dwFlags [I] Reserved.
397 * RETURNS
398 * Success: TRUE.
399 * Failure: FALSE.
402 BOOL WINAPI CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin,
403 HCATINFO hCatInfo,
404 DWORD dwFlags)
406 struct catinfo *ci = hCatInfo;
407 struct catadmin *ca = hCatAdmin;
409 TRACE("%p %p %x\n", hCatAdmin, hCatInfo, dwFlags);
411 if (!ca || ca->magic != CATADMIN_MAGIC || !ci || ci->magic != CATINFO_MAGIC)
413 SetLastError(ERROR_INVALID_PARAMETER);
414 return FALSE;
416 ci->magic = 0;
417 return HeapFree(GetProcessHeap(), 0, ci);
420 /***********************************************************************
421 * CryptCATAdminReleaseContext (WINTRUST.@)
423 * Release a catalog administrator context handle.
425 * PARAMS
426 * catAdmin [I] Context handle.
427 * dwFlags [I] Reserved.
429 * RETURNS
430 * Success: TRUE.
431 * Failure: FALSE.
434 BOOL WINAPI CryptCATAdminReleaseContext(HCATADMIN hCatAdmin, DWORD dwFlags )
436 struct catadmin *ca = hCatAdmin;
438 TRACE("%p %x\n", hCatAdmin, dwFlags);
440 if (!ca || ca->magic != CATADMIN_MAGIC)
442 SetLastError(ERROR_INVALID_PARAMETER);
443 return FALSE;
445 if (ca->find != INVALID_HANDLE_VALUE) FindClose(ca->find);
446 ca->magic = 0;
447 return HeapFree(GetProcessHeap(), 0, ca);
450 /***********************************************************************
451 * CryptCATAdminRemoveCatalog (WINTRUST.@)
453 * Remove a catalog file.
455 * PARAMS
456 * catAdmin [I] Context handle.
457 * pwszCatalogFile [I] Catalog file.
458 * dwFlags [I] Reserved.
460 * RETURNS
461 * Success: TRUE.
462 * Failure: FALSE.
465 BOOL WINAPI CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, LPCWSTR pwszCatalogFile, DWORD dwFlags)
467 struct catadmin *ca = hCatAdmin;
469 TRACE("%p %s %x\n", hCatAdmin, debugstr_w(pwszCatalogFile), dwFlags);
471 if (!ca || ca->magic != CATADMIN_MAGIC)
473 SetLastError(ERROR_INVALID_PARAMETER);
474 return FALSE;
477 /* Only delete when there is a filename and no path */
478 if (pwszCatalogFile && pwszCatalogFile[0] != 0 &&
479 !strchrW(pwszCatalogFile, '\\') && !strchrW(pwszCatalogFile, '/') &&
480 !strchrW(pwszCatalogFile, ':'))
482 static const WCHAR slashW[] = {'\\',0};
483 WCHAR *target;
484 DWORD len;
486 len = strlenW(ca->path) + strlenW(pwszCatalogFile) + 2;
487 if (!(target = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
489 SetLastError(ERROR_OUTOFMEMORY);
490 return FALSE;
492 strcpyW(target, ca->path);
493 strcatW(target, slashW);
494 strcatW(target, pwszCatalogFile);
496 DeleteFileW(target);
498 HeapFree(GetProcessHeap(), 0, target);
501 return TRUE;
504 /***********************************************************************
505 * CryptCATAdminResolveCatalogPath (WINTRUST.@)
507 BOOL WINAPI CryptCATAdminResolveCatalogPath(HCATADMIN hcatadmin, WCHAR *catalog_file,
508 CATALOG_INFO *info, DWORD flags)
510 static const WCHAR slashW[] = {'\\',0};
511 struct catadmin *ca = hcatadmin;
513 TRACE("%p %s %p %x\n", hcatadmin, debugstr_w(catalog_file), info, flags);
515 if (!ca || ca->magic != CATADMIN_MAGIC || !info || info->cbStruct != sizeof(*info) || flags)
517 SetLastError(ERROR_INVALID_PARAMETER);
518 return FALSE;
520 strcpyW(info->wszCatalogFile, ca->path);
521 strcatW(info->wszCatalogFile, slashW);
522 strcatW(info->wszCatalogFile, catalog_file);
524 return TRUE;
527 /***********************************************************************
528 * CryptCATClose (WINTRUST.@)
530 BOOL WINAPI CryptCATClose(HANDLE hCatalog)
532 struct cryptcat *cc = hCatalog;
534 TRACE("(%p)\n", hCatalog);
536 if (!hCatalog || hCatalog == INVALID_HANDLE_VALUE || cc->magic != CRYPTCAT_MAGIC)
538 SetLastError(ERROR_INVALID_PARAMETER);
539 return FALSE;
541 HeapFree(GetProcessHeap(), 0, cc->attr);
542 HeapFree(GetProcessHeap(), 0, cc->inner);
543 CryptMsgClose(cc->msg);
545 cc->magic = 0;
546 HeapFree(GetProcessHeap(), 0, cc);
547 return TRUE;
550 /***********************************************************************
551 * CryptCATGetAttrInfo (WINTRUST.@)
553 CRYPTCATATTRIBUTE * WINAPI CryptCATGetAttrInfo(HANDLE hCatalog, CRYPTCATMEMBER *member, LPWSTR tag)
555 struct cryptcat *cc = hCatalog;
557 FIXME("%p, %p, %s\n", hCatalog, member, debugstr_w(tag));
559 if (!hCatalog || hCatalog == INVALID_HANDLE_VALUE || cc->magic != CRYPTCAT_MAGIC)
561 SetLastError(ERROR_INVALID_PARAMETER);
562 return NULL;
564 SetLastError(CRYPT_E_NOT_FOUND);
565 return NULL;
568 /***********************************************************************
569 * CryptCATGetCatAttrInfo (WINTRUST.@)
571 CRYPTCATATTRIBUTE * WINAPI CryptCATGetCatAttrInfo(HANDLE hCatalog, LPWSTR tag)
573 struct cryptcat *cc = hCatalog;
575 FIXME("%p, %s\n", hCatalog, debugstr_w(tag));
577 if (!hCatalog || hCatalog == INVALID_HANDLE_VALUE || cc->magic != CRYPTCAT_MAGIC)
579 SetLastError(ERROR_INVALID_PARAMETER);
580 return NULL;
582 SetLastError(CRYPT_E_NOT_FOUND);
583 return NULL;
586 CRYPTCATMEMBER * WINAPI CryptCATGetMemberInfo(HANDLE hCatalog, LPWSTR tag)
588 struct cryptcat *cc = hCatalog;
590 FIXME("%p, %s\n", hCatalog, debugstr_w(tag));
592 if (!hCatalog || hCatalog == INVALID_HANDLE_VALUE || cc->magic != CRYPTCAT_MAGIC)
594 SetLastError(ERROR_INVALID_PARAMETER);
595 return NULL;
597 SetLastError(CRYPT_E_NOT_FOUND);
598 return NULL;
601 /***********************************************************************
602 * CryptCATEnumerateAttr (WINTRUST.@)
604 CRYPTCATATTRIBUTE * WINAPI CryptCATEnumerateAttr(HANDLE hCatalog, CRYPTCATMEMBER *member, CRYPTCATATTRIBUTE *prev)
606 struct cryptcat *cc = hCatalog;
608 FIXME("%p, %p, %p\n", hCatalog, member, prev);
610 if (!hCatalog || hCatalog == INVALID_HANDLE_VALUE || cc->magic != CRYPTCAT_MAGIC)
612 SetLastError(ERROR_INVALID_PARAMETER);
613 return NULL;
615 SetLastError(CRYPT_E_NOT_FOUND);
616 return NULL;
619 /***********************************************************************
620 * CryptCATEnumerateCatAttr (WINTRUST.@)
622 CRYPTCATATTRIBUTE * WINAPI CryptCATEnumerateCatAttr(HANDLE hCatalog, CRYPTCATATTRIBUTE *prev)
624 struct cryptcat *cc = hCatalog;
626 FIXME("%p, %p\n", hCatalog, prev);
628 if (!hCatalog || hCatalog == INVALID_HANDLE_VALUE || cc->magic != CRYPTCAT_MAGIC)
630 SetLastError(ERROR_INVALID_PARAMETER);
631 return NULL;
633 SetLastError(CRYPT_E_NOT_FOUND);
634 return NULL;
637 /***********************************************************************
638 * CryptCATEnumerateMember (WINTRUST.@)
640 CRYPTCATMEMBER * WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER *prev)
642 struct cryptcat *cc = hCatalog;
643 CRYPTCATMEMBER *member = prev;
644 CTL_ENTRY *entry;
645 DWORD size, i;
647 TRACE("%p, %p\n", hCatalog, prev);
649 if (!hCatalog || hCatalog == INVALID_HANDLE_VALUE || cc->magic != CRYPTCAT_MAGIC)
651 SetLastError(ERROR_INVALID_PARAMETER);
652 return NULL;
655 /* dumping the contents makes me think that dwReserved is the iteration number */
656 if (!member)
658 if (!(member = HeapAlloc(GetProcessHeap(), 0, sizeof(*member))))
660 SetLastError(ERROR_OUTOFMEMORY);
661 return NULL;
663 member->cbStruct = sizeof(*member);
664 member->pwszFileName = member->pwszReferenceTag = NULL;
665 member->dwReserved = 0;
666 member->hReserved = NULL;
667 member->gSubjectType = cc->subject;
668 member->fdwMemberFlags = 0;
669 member->pIndirectData = NULL;
670 member->dwCertVersion = cc->inner->dwVersion;
672 else member->dwReserved++;
674 if (member->dwReserved >= cc->inner->cCTLEntry)
676 SetLastError(ERROR_INVALID_PARAMETER);
677 goto error;
680 /* list them backwards, like native */
681 entry = &cc->inner->rgCTLEntry[cc->inner->cCTLEntry - member->dwReserved - 1];
683 member->sEncodedIndirectData.cbData = member->sEncodedMemberInfo.cbData = 0;
684 member->sEncodedIndirectData.pbData = member->sEncodedMemberInfo.pbData = NULL;
685 HeapFree(GetProcessHeap(), 0, member->pIndirectData);
686 member->pIndirectData = NULL;
688 for (i = 0; i < entry->cAttribute; i++)
690 CRYPT_ATTRIBUTE *attr = entry->rgAttribute + i;
692 if (attr->cValue != 1)
694 ERR("Can't handle attr->cValue of %u\n", attr->cValue);
695 continue;
697 if (!strcmp(attr->pszObjId, CAT_MEMBERINFO_OBJID))
699 CAT_MEMBERINFO *mi;
700 BOOL ret;
702 member->sEncodedMemberInfo.cbData = attr->rgValue->cbData;
703 member->sEncodedMemberInfo.pbData = attr->rgValue->pbData;
705 CryptDecodeObject(cc->encoding, CAT_MEMBERINFO_OBJID, attr->rgValue->pbData, attr->rgValue->cbData, 0, NULL, &size);
707 if (!(mi = HeapAlloc(GetProcessHeap(), 0, size)))
709 SetLastError(ERROR_OUTOFMEMORY);
710 goto error;
712 ret = CryptDecodeObject(cc->encoding, CAT_MEMBERINFO_OBJID, attr->rgValue->pbData, attr->rgValue->cbData, 0, mi, &size);
713 if (ret)
715 UNICODE_STRING guid;
717 member->dwCertVersion = mi->dwCertVersion;
718 RtlInitUnicodeString(&guid, mi->pwszSubjGuid);
719 if (RtlGUIDFromString(&guid, &member->gSubjectType))
721 HeapFree(GetProcessHeap(), 0, mi);
722 goto error;
725 HeapFree(GetProcessHeap(), 0, mi);
726 if (!ret) goto error;
728 else if (!strcmp(attr->pszObjId, SPC_INDIRECT_DATA_OBJID))
730 /* SPC_INDIRECT_DATA_CONTENT is equal to SIP_INDIRECT_DATA */
732 member->sEncodedIndirectData.cbData = attr->rgValue->cbData;
733 member->sEncodedIndirectData.pbData = attr->rgValue->pbData;
735 CryptDecodeObject(cc->encoding, SPC_INDIRECT_DATA_OBJID, attr->rgValue->pbData, attr->rgValue->cbData, 0, NULL, &size);
737 if (!(member->pIndirectData = HeapAlloc(GetProcessHeap(), 0, size)))
739 SetLastError(ERROR_OUTOFMEMORY);
740 goto error;
742 CryptDecodeObject(cc->encoding, SPC_INDIRECT_DATA_OBJID, attr->rgValue->pbData, attr->rgValue->cbData, 0, member->pIndirectData, &size);
744 else
745 /* this object id should probably be handled in CryptCATEnumerateAttr */
746 FIXME("unhandled object id \"%s\"\n", attr->pszObjId);
749 if (!member->sEncodedMemberInfo.cbData || !member->sEncodedIndirectData.cbData)
751 ERR("Corrupted catalog entry?\n");
752 SetLastError(CRYPT_E_ATTRIBUTES_MISSING);
753 goto error;
755 size = (2 * member->pIndirectData->Digest.cbData + 1) * sizeof(WCHAR);
756 if (member->pwszReferenceTag)
757 member->pwszReferenceTag = HeapReAlloc(GetProcessHeap(), 0, member->pwszReferenceTag, size);
758 else
759 member->pwszReferenceTag = HeapAlloc(GetProcessHeap(), 0, size);
761 if (!member->pwszReferenceTag)
763 SetLastError(ERROR_OUTOFMEMORY);
764 goto error;
766 /* FIXME: reference tag is usually the file hash but doesn't have to be */
767 for (i = 0; i < member->pIndirectData->Digest.cbData; i++)
769 DWORD sub;
771 sub = member->pIndirectData->Digest.pbData[i] >> 4;
772 member->pwszReferenceTag[i * 2] = (sub < 10 ? '0' + sub : 'A' + sub - 10);
773 sub = member->pIndirectData->Digest.pbData[i] & 0xf;
774 member->pwszReferenceTag[i * 2 + 1] = (sub < 10 ? '0' + sub : 'A' + sub - 10);
776 member->pwszReferenceTag[i * 2] = 0;
777 return member;
779 error:
780 HeapFree(GetProcessHeap(), 0, member->pIndirectData);
781 HeapFree(GetProcessHeap(), 0, member->pwszReferenceTag);
782 HeapFree(GetProcessHeap(), 0, member);
783 return NULL;
786 static CTL_INFO *decode_inner_content(HANDLE hmsg, DWORD encoding, DWORD *len)
788 DWORD size;
789 LPSTR oid = NULL;
790 BYTE *buffer = NULL;
791 CTL_INFO *inner = NULL;
793 if (!CryptMsgGetParam(hmsg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, NULL, &size)) return NULL;
794 if (!(oid = HeapAlloc(GetProcessHeap(), 0, size)))
796 SetLastError(ERROR_OUTOFMEMORY);
797 return NULL;
799 if (!CryptMsgGetParam(hmsg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, oid, &size)) goto out;
800 if (!CryptMsgGetParam(hmsg, CMSG_CONTENT_PARAM, 0, NULL, &size)) goto out;
801 if (!(buffer = HeapAlloc(GetProcessHeap(), 0, size)))
803 SetLastError(ERROR_OUTOFMEMORY);
804 goto out;
806 if (!CryptMsgGetParam(hmsg, CMSG_CONTENT_PARAM, 0, buffer, &size)) goto out;
807 if (!CryptDecodeObject(encoding, oid, buffer, size, 0, NULL, &size)) goto out;
808 if (!(inner = HeapAlloc(GetProcessHeap(), 0, size)))
810 SetLastError(ERROR_OUTOFMEMORY);
811 goto out;
813 if (!CryptDecodeObject(encoding, oid, buffer, size, 0, inner, &size)) goto out;
814 *len = size;
816 out:
817 HeapFree(GetProcessHeap(), 0, oid);
818 HeapFree(GetProcessHeap(), 0, buffer);
819 return inner;
822 /***********************************************************************
823 * CryptCATCatalogInfoFromContext (WINTRUST.@)
825 BOOL WINAPI CryptCATCatalogInfoFromContext(HCATINFO hcatinfo, CATALOG_INFO *info, DWORD flags)
827 struct catinfo *ci = hcatinfo;
829 TRACE("%p, %p, %x\n", hcatinfo, info, flags);
831 if (!hcatinfo || hcatinfo == INVALID_HANDLE_VALUE || ci->magic != CATINFO_MAGIC ||
832 flags || !info || info->cbStruct != sizeof(*info))
834 SetLastError(ERROR_INVALID_PARAMETER);
835 return FALSE;
837 strcpyW(info->wszCatalogFile, ci->file);
838 return TRUE;
841 /***********************************************************************
842 * CryptCATOpen (WINTRUST.@)
844 HANDLE WINAPI CryptCATOpen(LPWSTR pwszFileName, DWORD fdwOpenFlags, HCRYPTPROV hProv,
845 DWORD dwPublicVersion, DWORD dwEncodingType)
847 HANDLE file, hmsg;
848 BYTE *buffer = NULL;
849 DWORD size, flags = OPEN_EXISTING;
850 struct cryptcat *cc;
852 TRACE("%s, %x, %lx, %x, %x\n", debugstr_w(pwszFileName), fdwOpenFlags,
853 hProv, dwPublicVersion, dwEncodingType);
855 if (!pwszFileName)
857 SetLastError(ERROR_INVALID_PARAMETER);
858 return INVALID_HANDLE_VALUE;
861 if (!dwPublicVersion) dwPublicVersion = 0x00000100;
862 if (!dwEncodingType) dwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
864 if (fdwOpenFlags & CRYPTCAT_OPEN_ALWAYS) flags |= OPEN_ALWAYS;
865 if (fdwOpenFlags & CRYPTCAT_OPEN_CREATENEW) flags |= CREATE_NEW;
867 file = CreateFileW(pwszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, flags, 0, NULL);
868 if (file == INVALID_HANDLE_VALUE) return INVALID_HANDLE_VALUE;
870 size = GetFileSize(file, NULL);
871 if (!(buffer = HeapAlloc(GetProcessHeap(), 0, size)))
873 CloseHandle(file);
874 SetLastError(ERROR_OUTOFMEMORY);
875 return INVALID_HANDLE_VALUE;
877 if (!(hmsg = CryptMsgOpenToDecode(dwEncodingType, 0, 0, hProv, NULL, NULL)))
879 CloseHandle(file);
880 HeapFree(GetProcessHeap(), 0, buffer);
881 return INVALID_HANDLE_VALUE;
883 if (!ReadFile(file, buffer, size, &size, NULL) || !CryptMsgUpdate(hmsg, buffer, size, TRUE))
885 CloseHandle(file);
886 HeapFree(GetProcessHeap(), 0, buffer);
887 CryptMsgClose(hmsg);
888 return INVALID_HANDLE_VALUE;
890 HeapFree(GetProcessHeap(), 0, buffer);
891 CloseHandle(file);
893 size = sizeof(DWORD);
894 if (!(cc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*cc))))
896 CryptMsgClose(hmsg);
897 SetLastError(ERROR_OUTOFMEMORY);
898 return INVALID_HANDLE_VALUE;
901 cc->msg = hmsg;
902 cc->encoding = dwEncodingType;
903 if (CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_COUNT_PARAM, 0, &cc->attr_count, &size))
905 DWORD i, sum = 0;
906 BYTE *p;
908 for (i = 0; i < cc->attr_count; i++)
910 if (!CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_PARAM, i, NULL, &size))
912 CryptMsgClose(hmsg);
913 return INVALID_HANDLE_VALUE;
915 sum += size;
917 if (!(cc->attr = HeapAlloc(GetProcessHeap(), 0, sizeof(*cc->attr) * cc->attr_count + sum)))
919 CryptMsgClose(hmsg);
920 SetLastError(ERROR_OUTOFMEMORY);
921 return INVALID_HANDLE_VALUE;
923 p = (BYTE *)(cc->attr + cc->attr_count);
924 for (i = 0; i < cc->attr_count; i++)
926 if (!CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_PARAM, i, NULL, &size))
928 CryptMsgClose(hmsg);
929 HeapFree(GetProcessHeap(), 0, cc->attr);
930 return INVALID_HANDLE_VALUE;
932 if (!CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_PARAM, i, p, &size))
934 CryptMsgClose(hmsg);
935 HeapFree(GetProcessHeap(), 0, cc->attr);
936 return INVALID_HANDLE_VALUE;
938 p += size;
940 cc->inner = decode_inner_content(hmsg, dwEncodingType, &cc->inner_len);
941 if (!cc->inner || !CryptSIPRetrieveSubjectGuid(pwszFileName, NULL, &cc->subject))
943 CryptMsgClose(hmsg);
944 HeapFree(GetProcessHeap(), 0, cc->attr);
945 HeapFree(GetProcessHeap(), 0, cc->inner);
946 HeapFree(GetProcessHeap(), 0, cc);
947 return INVALID_HANDLE_VALUE;
949 cc->magic = CRYPTCAT_MAGIC;
950 return cc;
952 return INVALID_HANDLE_VALUE;
955 /***********************************************************************
956 * CryptSIPCreateIndirectData (WINTRUST.@)
958 BOOL WINAPI CryptSIPCreateIndirectData(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pcbIndirectData,
959 SIP_INDIRECT_DATA* pIndirectData)
961 FIXME("(%p %p %p) stub\n", pSubjectInfo, pcbIndirectData, pIndirectData);
963 return FALSE;
967 /***********************************************************************
968 * CryptCATCDFClose (WINTRUST.@)
970 BOOL WINAPI CryptCATCDFClose(CRYPTCATCDF *pCDF)
972 FIXME("(%p) stub\n", pCDF);
974 return FALSE;
977 /***********************************************************************
978 * CryptCATCDFEnumCatAttributes (WINTRUST.@)
980 CRYPTCATATTRIBUTE * WINAPI CryptCATCDFEnumCatAttributes(CRYPTCATCDF *pCDF,
981 CRYPTCATATTRIBUTE *pPrevAttr,
982 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError)
984 FIXME("(%p %p %p) stub\n", pCDF, pPrevAttr, pfnParseError);
986 return NULL;
989 /***********************************************************************
990 * CryptCATCDFEnumMembersByCDFTagEx (WINTRUST.@)
992 LPWSTR WINAPI CryptCATCDFEnumMembersByCDFTagEx(CRYPTCATCDF *pCDF, LPWSTR pwszPrevCDFTag,
993 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError,
994 CRYPTCATMEMBER **ppMember, BOOL fContinueOnError,
995 LPVOID pvReserved)
997 FIXME("(%p %s %p %p %d %p) stub\n", pCDF, debugstr_w(pwszPrevCDFTag), pfnParseError,
998 ppMember, fContinueOnError, pvReserved);
1000 return NULL;
1003 /***********************************************************************
1004 * CryptCATCDFOpen (WINTRUST.@)
1006 CRYPTCATCDF * WINAPI CryptCATCDFOpen(LPWSTR pwszFilePath,
1007 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError)
1009 FIXME("(%s %p) stub\n", debugstr_w(pwszFilePath), pfnParseError);
1011 return NULL;
1014 static BOOL WINTRUST_GetSignedMsgFromPEFile(SIP_SUBJECTINFO *pSubjectInfo,
1015 DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg,
1016 BYTE *pbSignedDataMsg)
1018 BOOL ret;
1019 WIN_CERTIFICATE *pCert = NULL;
1021 TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
1022 pcbSignedDataMsg, pbSignedDataMsg);
1024 if (!pbSignedDataMsg)
1026 WIN_CERTIFICATE cert;
1028 /* app hasn't passed buffer, just get the length */
1029 ret = ImageGetCertificateHeader(pSubjectInfo->hFile, dwIndex, &cert);
1030 if (ret)
1031 *pcbSignedDataMsg = cert.dwLength;
1033 else
1035 DWORD len = 0;
1037 ret = ImageGetCertificateData(pSubjectInfo->hFile, dwIndex, NULL, &len);
1038 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1039 goto error;
1040 pCert = HeapAlloc(GetProcessHeap(), 0, len);
1041 if (!pCert)
1043 ret = FALSE;
1044 goto error;
1046 ret = ImageGetCertificateData(pSubjectInfo->hFile, dwIndex, pCert,
1047 &len);
1048 if (!ret)
1049 goto error;
1050 if (*pcbSignedDataMsg < pCert->dwLength)
1052 *pcbSignedDataMsg = pCert->dwLength;
1053 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1054 ret = FALSE;
1056 else
1058 memcpy(pbSignedDataMsg, pCert->bCertificate, pCert->dwLength);
1059 switch (pCert->wCertificateType)
1061 case WIN_CERT_TYPE_X509:
1062 *pdwEncodingType = X509_ASN_ENCODING;
1063 break;
1064 case WIN_CERT_TYPE_PKCS_SIGNED_DATA:
1065 *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
1066 break;
1067 default:
1068 FIXME("don't know what to do for encoding type %d\n",
1069 pCert->wCertificateType);
1070 *pdwEncodingType = 0;
1074 error:
1075 HeapFree(GetProcessHeap(), 0, pCert);
1076 return ret;
1079 /* structure offsets */
1080 #define cfhead_Signature (0x00)
1081 #define cfhead_CabinetSize (0x08)
1082 #define cfhead_MinorVersion (0x18)
1083 #define cfhead_MajorVersion (0x19)
1084 #define cfhead_Flags (0x1E)
1085 #define cfhead_SIZEOF (0x24)
1086 #define cfheadext_HeaderReserved (0x00)
1087 #define cfheadext_SIZEOF (0x04)
1088 #define cfsigninfo_CertOffset (0x04)
1089 #define cfsigninfo_CertSize (0x08)
1090 #define cfsigninfo_SIZEOF (0x0C)
1092 /* flags */
1093 #define cfheadRESERVE_PRESENT (0x0004)
1095 /* endian-neutral reading of little-endian data */
1096 #define EndGetI32(a) ((((a)[3])<<24)|(((a)[2])<<16)|(((a)[1])<<8)|((a)[0]))
1097 #define EndGetI16(a) ((((a)[1])<<8)|((a)[0]))
1099 /* For documentation purposes only: this is the structure in the reserved
1100 * area of a signed cabinet file. The cert offset indicates where in the
1101 * cabinet file the signature resides, and the count indicates its size.
1103 typedef struct _CAB_SIGNINFO
1105 WORD unk0; /* always 0? */
1106 WORD unk1; /* always 0x0010? */
1107 DWORD dwCertOffset;
1108 DWORD cbCertBlock;
1109 } CAB_SIGNINFO, *PCAB_SIGNINFO;
1111 static BOOL WINTRUST_GetSignedMsgFromCabFile(SIP_SUBJECTINFO *pSubjectInfo,
1112 DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg,
1113 BYTE *pbSignedDataMsg)
1115 int header_resv;
1116 LONG base_offset, cabsize;
1117 USHORT flags;
1118 BYTE buf[64];
1119 DWORD cert_offset, cert_size, dwRead;
1121 TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
1122 pcbSignedDataMsg, pbSignedDataMsg);
1125 * FIXME: I just noticed that I am memorizing the initial file pointer
1126 * offset and restoring it before reading in the rest of the header
1127 * information in the cabinet. Perhaps that's correct -- that is, perhaps
1128 * this API is supposed to support "streaming" cabinets which are embedded
1129 * in other files, or cabinets which begin at file offsets other than zero.
1130 * Otherwise, I should instead go to the absolute beginning of the file.
1131 * (Either way, the semantics of wine's FDICopy require me to leave the
1132 * file pointer where it is afterwards -- If Windows does not do so, we
1133 * ought to duplicate the native behavior in the FDIIsCabinet API, not here.
1135 * So, the answer lies in Windows; will native cabinet.dll recognize a
1136 * cabinet "file" embedded in another file? Note that cabextract.c does
1137 * support this, which implies that Microsoft's might. I haven't tried it
1138 * yet so I don't know. ATM, most of wine's FDI cabinet routines (except
1139 * this one) would not work in this way. To fix it, we could just make the
1140 * various references to absolute file positions in the code relative to an
1141 * initial "beginning" offset. Because the FDICopy API doesn't take a
1142 * file-handle like this one, we would therein need to search through the
1143 * file for the beginning of the cabinet (as we also do in cabextract.c).
1144 * Note that this limits us to a maximum of one cabinet per. file: the first.
1146 * So, in summary: either the code below is wrong, or the rest of fdi.c is
1147 * wrong... I cannot imagine that both are correct ;) One of these flaws
1148 * should be fixed after determining the behavior on Windows. We ought
1149 * to check both FDIIsCabinet and FDICopy for the right behavior.
1151 * -gmt
1154 /* get basic offset & size info */
1155 base_offset = SetFilePointer(pSubjectInfo->hFile, 0L, NULL, SEEK_CUR);
1157 if (SetFilePointer(pSubjectInfo->hFile, 0, NULL, SEEK_END) == INVALID_SET_FILE_POINTER)
1159 TRACE("seek error\n");
1160 return FALSE;
1163 cabsize = SetFilePointer(pSubjectInfo->hFile, 0L, NULL, SEEK_CUR);
1164 if ((cabsize == -1) || (base_offset == -1) ||
1165 (SetFilePointer(pSubjectInfo->hFile, base_offset, NULL, SEEK_SET) == INVALID_SET_FILE_POINTER))
1167 TRACE("seek error\n");
1168 return FALSE;
1171 /* read in the CFHEADER */
1172 if (!ReadFile(pSubjectInfo->hFile, buf, cfhead_SIZEOF, &dwRead, NULL) ||
1173 dwRead != cfhead_SIZEOF)
1175 TRACE("reading header failed\n");
1176 return FALSE;
1179 /* check basic MSCF signature */
1180 if (EndGetI32(buf+cfhead_Signature) != 0x4643534d)
1182 WARN("cabinet signature not present\n");
1183 return FALSE;
1186 /* Ignore the number of folders and files and the set and cabinet IDs */
1188 /* check the header revision */
1189 if ((buf[cfhead_MajorVersion] > 1) ||
1190 (buf[cfhead_MajorVersion] == 1 && buf[cfhead_MinorVersion] > 3))
1192 WARN("cabinet format version > 1.3\n");
1193 return FALSE;
1196 /* pull the flags out */
1197 flags = EndGetI16(buf+cfhead_Flags);
1199 if (!(flags & cfheadRESERVE_PRESENT))
1201 TRACE("no header present, not signed\n");
1202 return FALSE;
1205 if (!ReadFile(pSubjectInfo->hFile, buf, cfheadext_SIZEOF, &dwRead, NULL) ||
1206 dwRead != cfheadext_SIZEOF)
1208 ERR("bunk reserve-sizes?\n");
1209 return FALSE;
1212 header_resv = EndGetI16(buf+cfheadext_HeaderReserved);
1213 if (!header_resv)
1215 TRACE("no header_resv, not signed\n");
1216 return FALSE;
1218 else if (header_resv < cfsigninfo_SIZEOF)
1220 TRACE("header_resv too small, not signed\n");
1221 return FALSE;
1224 if (header_resv > 60000)
1226 WARN("WARNING; header reserved space > 60000\n");
1229 if (!ReadFile(pSubjectInfo->hFile, buf, cfsigninfo_SIZEOF, &dwRead, NULL) ||
1230 dwRead != cfsigninfo_SIZEOF)
1232 ERR("couldn't read reserve\n");
1233 return FALSE;
1236 cert_offset = EndGetI32(buf+cfsigninfo_CertOffset);
1237 TRACE("cert_offset: %d\n", cert_offset);
1238 cert_size = EndGetI32(buf+cfsigninfo_CertSize);
1239 TRACE("cert_size: %d\n", cert_size);
1241 /* The redundant checks are to avoid wraparound */
1242 if (cert_offset > cabsize || cert_size > cabsize ||
1243 cert_offset + cert_size > cabsize)
1245 WARN("offset beyond file, not attempting to read\n");
1246 return FALSE;
1249 SetFilePointer(pSubjectInfo->hFile, base_offset, NULL, SEEK_SET);
1250 if (!pbSignedDataMsg)
1252 *pcbSignedDataMsg = cert_size;
1253 return TRUE;
1255 if (*pcbSignedDataMsg < cert_size)
1257 *pcbSignedDataMsg = cert_size;
1258 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1259 return FALSE;
1261 if (SetFilePointer(pSubjectInfo->hFile, cert_offset, NULL, SEEK_SET) == INVALID_SET_FILE_POINTER)
1263 ERR("couldn't seek to cert location\n");
1264 return FALSE;
1266 if (!ReadFile(pSubjectInfo->hFile, pbSignedDataMsg, cert_size, &dwRead,
1267 NULL) || dwRead != cert_size)
1269 ERR("couldn't read cert\n");
1270 return FALSE;
1272 /* The encoding of the files I've seen appears to be in ASN.1
1273 * format, and there isn't a field indicating the type, so assume it
1274 * always is.
1276 *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
1277 return TRUE;
1280 static BOOL WINTRUST_GetSignedMsgFromCatFile(SIP_SUBJECTINFO *pSubjectInfo,
1281 DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg,
1282 BYTE *pbSignedDataMsg)
1284 BOOL ret;
1286 TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
1287 pcbSignedDataMsg, pbSignedDataMsg);
1289 if (!pbSignedDataMsg)
1291 *pcbSignedDataMsg = GetFileSize(pSubjectInfo->hFile, NULL);
1292 ret = TRUE;
1294 else
1296 DWORD len = GetFileSize(pSubjectInfo->hFile, NULL);
1298 if (*pcbSignedDataMsg < len)
1300 *pcbSignedDataMsg = len;
1301 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1302 ret = FALSE;
1304 else
1306 ret = ReadFile(pSubjectInfo->hFile, pbSignedDataMsg, len,
1307 pcbSignedDataMsg, NULL);
1308 if (ret)
1309 *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
1312 return ret;
1315 /***********************************************************************
1316 * CryptSIPGetSignedDataMsg (WINTRUST.@)
1318 BOOL WINAPI CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pdwEncodingType,
1319 DWORD dwIndex, DWORD* pcbSignedDataMsg, BYTE* pbSignedDataMsg)
1321 static const GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
1322 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1323 static const GUID cabGUID = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,
1324 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1325 static const GUID catGUID = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,
1326 0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1327 BOOL ret;
1329 TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
1330 pcbSignedDataMsg, pbSignedDataMsg);
1332 if (!memcmp(pSubjectInfo->pgSubjectType, &unknown, sizeof(unknown)))
1333 ret = WINTRUST_GetSignedMsgFromPEFile(pSubjectInfo, pdwEncodingType,
1334 dwIndex, pcbSignedDataMsg, pbSignedDataMsg);
1335 else if (!memcmp(pSubjectInfo->pgSubjectType, &cabGUID, sizeof(cabGUID)))
1336 ret = WINTRUST_GetSignedMsgFromCabFile(pSubjectInfo, pdwEncodingType,
1337 dwIndex, pcbSignedDataMsg, pbSignedDataMsg);
1338 else if (!memcmp(pSubjectInfo->pgSubjectType, &catGUID, sizeof(catGUID)))
1339 ret = WINTRUST_GetSignedMsgFromCatFile(pSubjectInfo, pdwEncodingType,
1340 dwIndex, pcbSignedDataMsg, pbSignedDataMsg);
1341 else
1343 FIXME("unimplemented for subject type %s\n",
1344 debugstr_guid(pSubjectInfo->pgSubjectType));
1345 ret = FALSE;
1348 TRACE("returning %d\n", ret);
1349 return ret;
1352 /***********************************************************************
1353 * CryptSIPPutSignedDataMsg (WINTRUST.@)
1355 BOOL WINAPI CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD pdwEncodingType,
1356 DWORD* pdwIndex, DWORD cbSignedDataMsg, BYTE* pbSignedDataMsg)
1358 FIXME("(%p %d %p %d %p) stub\n", pSubjectInfo, pdwEncodingType, pdwIndex,
1359 cbSignedDataMsg, pbSignedDataMsg);
1361 return FALSE;
1364 /***********************************************************************
1365 * CryptSIPRemoveSignedDataMsg (WINTRUST.@)
1367 BOOL WINAPI CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo,
1368 DWORD dwIndex)
1370 FIXME("(%p %d) stub\n", pSubjectInfo, dwIndex);
1372 return FALSE;
1375 /***********************************************************************
1376 * CryptSIPVerifyIndirectData (WINTRUST.@)
1378 BOOL WINAPI CryptSIPVerifyIndirectData(SIP_SUBJECTINFO* pSubjectInfo,
1379 SIP_INDIRECT_DATA* pIndirectData)
1381 FIXME("(%p %p) stub\n", pSubjectInfo, pIndirectData);
1383 return FALSE;