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 "wintrust_priv.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wintrust
);
31 #define CATADMIN_MAGIC 0x43415441 /* 'CATA' */
32 #define CRYPTCAT_MAGIC 0x43415443 /* 'CATC' */
33 #define CATINFO_MAGIC 0x43415449 /* 'CATI' */
44 CRYPTCATATTRIBUTE
*attr
;
60 static HCATINFO
create_catinfo(const WCHAR
*filename
)
64 if (!(ci
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ci
))))
66 SetLastError(ERROR_OUTOFMEMORY
);
67 return INVALID_HANDLE_VALUE
;
69 strcpyW(ci
->file
, filename
);
70 ci
->magic
= CATINFO_MAGIC
;
74 /***********************************************************************
75 * CryptCATAdminAcquireContext (WINTRUST.@)
77 * Get a catalog administrator context handle.
80 * catAdmin [O] Pointer to the context handle.
81 * sys [I] Pointer to a GUID for the needed subsystem.
82 * dwFlags [I] Reserved.
85 * Success: TRUE. catAdmin contains the context handle.
89 BOOL WINAPI
CryptCATAdminAcquireContext(HCATADMIN
*catAdmin
,
90 const GUID
*sys
, DWORD dwFlags
)
92 static const WCHAR catroot
[] =
93 {'\\','c','a','t','r','o','o','t',0};
94 static const WCHAR fmt
[] =
95 {'%','s','\\','{','%','0','8','x','-','%','0','4','x','-','%','0',
96 '4','x','-','%','0','2','x','%','0','2','x','-','%','0','2','x',
97 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
98 '%','0','2','x','}',0};
99 static const GUID defsys
=
100 {0x127d0a1d,0x4ef2,0x11d1,{0x86,0x08,0x00,0xc0,0x4f,0xc2,0x95,0xee}};
102 WCHAR catroot_dir
[MAX_PATH
];
105 TRACE("%p %s %x\n", catAdmin
, debugstr_guid(sys
), dwFlags
);
107 if (!catAdmin
|| dwFlags
)
109 SetLastError(ERROR_INVALID_PARAMETER
);
112 if (!(ca
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ca
))))
114 SetLastError(ERROR_OUTOFMEMORY
);
118 GetSystemDirectoryW(catroot_dir
, MAX_PATH
);
119 strcatW(catroot_dir
, catroot
);
121 /* create the directory if it doesn't exist */
122 CreateDirectoryW(catroot_dir
, NULL
);
124 if (!sys
) sys
= &defsys
;
125 sprintfW(ca
->path
, fmt
, catroot_dir
, sys
->Data1
, sys
->Data2
,
126 sys
->Data3
, sys
->Data4
[0], sys
->Data4
[1], sys
->Data4
[2],
127 sys
->Data4
[3], sys
->Data4
[4], sys
->Data4
[5], sys
->Data4
[6],
130 /* create the directory if it doesn't exist */
131 CreateDirectoryW(ca
->path
, NULL
);
133 ca
->magic
= CATADMIN_MAGIC
;
134 ca
->find
= INVALID_HANDLE_VALUE
;
140 /***********************************************************************
141 * CryptCATAdminAddCatalog (WINTRUST.@)
143 HCATINFO WINAPI
CryptCATAdminAddCatalog(HCATADMIN catAdmin
, PWSTR catalogFile
,
144 PWSTR selectBaseName
, DWORD flags
)
146 static const WCHAR slashW
[] = {'\\',0};
147 struct catadmin
*ca
= catAdmin
;
152 TRACE("%p %s %s %d\n", catAdmin
, debugstr_w(catalogFile
),
153 debugstr_w(selectBaseName
), flags
);
157 FIXME("NULL basename not handled\n");
158 SetLastError(ERROR_INVALID_PARAMETER
);
161 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !catalogFile
|| flags
)
163 SetLastError(ERROR_INVALID_PARAMETER
);
167 len
= strlenW(ca
->path
) + strlenW(selectBaseName
) + 2;
168 if (!(target
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
170 SetLastError(ERROR_OUTOFMEMORY
);
173 strcpyW(target
, ca
->path
);
174 strcatW(target
, slashW
);
175 strcatW(target
, selectBaseName
);
177 if (!CopyFileW(catalogFile
, target
, FALSE
))
179 HeapFree(GetProcessHeap(), 0, target
);
182 SetFileAttributesW(target
, FILE_ATTRIBUTE_SYSTEM
);
184 if (!(ci
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ci
))))
186 HeapFree(GetProcessHeap(), 0, target
);
187 SetLastError(ERROR_OUTOFMEMORY
);
190 ci
->magic
= CATINFO_MAGIC
;
191 strcpyW(ci
->file
, target
);
193 HeapFree(GetProcessHeap(), 0, target
);
197 /***********************************************************************
198 * CryptCATAdminCalcHashFromFileHandle (WINTRUST.@)
200 BOOL WINAPI
CryptCATAdminCalcHashFromFileHandle(HANDLE hFile
, DWORD
* pcbHash
,
201 BYTE
* pbHash
, DWORD dwFlags
)
205 TRACE("%p %p %p %x\n", hFile
, pcbHash
, pbHash
, dwFlags
);
207 if (!hFile
|| !pcbHash
|| dwFlags
)
209 SetLastError(ERROR_INVALID_PARAMETER
);
215 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
227 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, 4096)))
229 SetLastError(ERROR_OUTOFMEMORY
);
232 ret
= CryptAcquireContextW(&prov
, NULL
, MS_DEF_PROV_W
, PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
235 HeapFree(GetProcessHeap(), 0, buffer
);
238 ret
= CryptCreateHash(prov
, CALG_SHA1
, 0, 0, &hash
);
241 HeapFree(GetProcessHeap(), 0, buffer
);
242 CryptReleaseContext(prov
, 0);
245 while ((ret
= ReadFile(hFile
, buffer
, 4096, &bytes_read
, NULL
)) && bytes_read
)
247 CryptHashData(hash
, buffer
, bytes_read
, 0);
249 if (ret
) ret
= CryptGetHashParam(hash
, HP_HASHVAL
, pbHash
, pcbHash
, 0);
251 HeapFree(GetProcessHeap(), 0, buffer
);
252 CryptDestroyHash(hash
);
253 CryptReleaseContext(prov
, 0);
258 /***********************************************************************
259 * CryptCATAdminEnumCatalogFromHash (WINTRUST.@)
261 HCATINFO WINAPI
CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin
, BYTE
* pbHash
,
262 DWORD cbHash
, DWORD dwFlags
,
263 HCATINFO
* phPrevCatInfo
)
265 static const WCHAR slashW
[] = {'\\',0};
266 static const WCHAR globW
[] = {'\\','*','.','c','a','t',0};
268 struct catadmin
*ca
= hCatAdmin
;
269 WIN32_FIND_DATAW data
;
270 HCATINFO prev
= NULL
;
275 TRACE("%p %p %d %x %p\n", hCatAdmin
, pbHash
, cbHash
, dwFlags
, phPrevCatInfo
);
277 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !pbHash
|| cbHash
!= 20 || dwFlags
)
279 SetLastError(ERROR_INVALID_PARAMETER
);
282 if (phPrevCatInfo
) prev
= *phPrevCatInfo
;
284 ret
= CryptAcquireContextW(&prov
, NULL
, MS_DEF_PROV_W
, PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
285 if (!ret
) return NULL
;
291 size
= strlenW(ca
->path
) * sizeof(WCHAR
) + sizeof(globW
);
292 if (!(path
= HeapAlloc(GetProcessHeap(), 0, size
)))
294 CryptReleaseContext(prov
, 0);
295 SetLastError(ERROR_OUTOFMEMORY
);
298 strcpyW(path
, ca
->path
);
299 strcatW(path
, globW
);
302 ca
->find
= FindFirstFileW(path
, &data
);
304 HeapFree(GetProcessHeap(), 0, path
);
305 if (ca
->find
== INVALID_HANDLE_VALUE
)
307 CryptReleaseContext(prov
, 0);
311 else if (!FindNextFileW(ca
->find
, &data
))
313 CryptCATAdminReleaseCatalogContext(hCatAdmin
, prev
, 0);
314 CryptReleaseContext(prov
, 0);
321 CRYPTCATMEMBER
*member
= NULL
;
325 size
= (strlenW(ca
->path
) + strlenW(data
.cFileName
) + 2) * sizeof(WCHAR
);
326 if (!(filename
= HeapAlloc(GetProcessHeap(), 0, size
)))
328 SetLastError(ERROR_OUTOFMEMORY
);
331 strcpyW(filename
, ca
->path
);
332 strcatW(filename
, slashW
);
333 strcatW(filename
, data
.cFileName
);
335 hcat
= CryptCATOpen(filename
, CRYPTCAT_OPEN_EXISTING
, prov
, 0, 0);
336 if (hcat
== INVALID_HANDLE_VALUE
)
338 WARN("couldn't open %s (%u)\n", debugstr_w(filename
), GetLastError());
341 while ((member
= CryptCATEnumerateMember(hcat
, member
)))
343 if (member
->pIndirectData
->Digest
.cbData
!= cbHash
)
345 WARN("amount of hash bytes differs: %u/%u\n", member
->pIndirectData
->Digest
.cbData
, cbHash
);
348 if (!memcmp(member
->pIndirectData
->Digest
.pbData
, pbHash
, cbHash
))
350 TRACE("file %s matches\n", debugstr_w(data
.cFileName
));
353 CryptReleaseContext(prov
, 0);
357 ca
->find
= INVALID_HANDLE_VALUE
;
359 ci
= create_catinfo(filename
);
360 HeapFree(GetProcessHeap(), 0, filename
);
365 HeapFree(GetProcessHeap(), 0, filename
);
367 if (!FindNextFileW(ca
->find
, &data
))
370 ca
->find
= INVALID_HANDLE_VALUE
;
371 CryptReleaseContext(prov
, 0);
378 /***********************************************************************
379 * CryptCATAdminReleaseCatalogContext (WINTRUST.@)
381 * Release a catalog context handle.
384 * hCatAdmin [I] Context handle.
385 * hCatInfo [I] Catalog handle.
386 * dwFlags [I] Reserved.
393 BOOL WINAPI
CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin
,
397 struct catinfo
*ci
= hCatInfo
;
398 struct catadmin
*ca
= hCatAdmin
;
400 TRACE("%p %p %x\n", hCatAdmin
, hCatInfo
, dwFlags
);
402 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !ci
|| ci
->magic
!= CATINFO_MAGIC
)
404 SetLastError(ERROR_INVALID_PARAMETER
);
408 return HeapFree(GetProcessHeap(), 0, ci
);
411 /***********************************************************************
412 * CryptCATAdminReleaseContext (WINTRUST.@)
414 * Release a catalog administrator context handle.
417 * catAdmin [I] Context handle.
418 * dwFlags [I] Reserved.
425 BOOL WINAPI
CryptCATAdminReleaseContext(HCATADMIN hCatAdmin
, DWORD dwFlags
)
427 struct catadmin
*ca
= hCatAdmin
;
429 TRACE("%p %x\n", hCatAdmin
, dwFlags
);
431 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
)
433 SetLastError(ERROR_INVALID_PARAMETER
);
436 if (ca
->find
!= INVALID_HANDLE_VALUE
) FindClose(ca
->find
);
438 return HeapFree(GetProcessHeap(), 0, ca
);
441 /***********************************************************************
442 * CryptCATAdminRemoveCatalog (WINTRUST.@)
444 * Remove a catalog file.
447 * catAdmin [I] Context handle.
448 * pwszCatalogFile [I] Catalog file.
449 * dwFlags [I] Reserved.
456 BOOL WINAPI
CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin
, LPCWSTR pwszCatalogFile
, DWORD dwFlags
)
458 struct catadmin
*ca
= hCatAdmin
;
460 TRACE("%p %s %x\n", hCatAdmin
, debugstr_w(pwszCatalogFile
), dwFlags
);
462 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
)
464 SetLastError(ERROR_INVALID_PARAMETER
);
468 /* Only delete when there is a filename and no path */
469 if (pwszCatalogFile
&& pwszCatalogFile
[0] != 0 &&
470 !strchrW(pwszCatalogFile
, '\\') && !strchrW(pwszCatalogFile
, '/') &&
471 !strchrW(pwszCatalogFile
, ':'))
473 static const WCHAR slashW
[] = {'\\',0};
477 len
= strlenW(ca
->path
) + strlenW(pwszCatalogFile
) + 2;
478 if (!(target
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
480 SetLastError(ERROR_OUTOFMEMORY
);
483 strcpyW(target
, ca
->path
);
484 strcatW(target
, slashW
);
485 strcatW(target
, pwszCatalogFile
);
489 HeapFree(GetProcessHeap(), 0, target
);
495 /***********************************************************************
496 * CryptCATAdminResolveCatalogPath (WINTRUST.@)
498 BOOL WINAPI
CryptCATAdminResolveCatalogPath(HCATADMIN hcatadmin
, WCHAR
*catalog_file
,
499 CATALOG_INFO
*info
, DWORD flags
)
501 static const WCHAR slashW
[] = {'\\',0};
502 struct catadmin
*ca
= hcatadmin
;
504 TRACE("%p %s %p %x\n", hcatadmin
, debugstr_w(catalog_file
), info
, flags
);
506 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !info
|| info
->cbStruct
!= sizeof(*info
) || flags
)
508 SetLastError(ERROR_INVALID_PARAMETER
);
511 strcpyW(info
->wszCatalogFile
, ca
->path
);
512 strcatW(info
->wszCatalogFile
, slashW
);
513 strcatW(info
->wszCatalogFile
, catalog_file
);
518 /***********************************************************************
519 * CryptCATClose (WINTRUST.@)
521 BOOL WINAPI
CryptCATClose(HANDLE hCatalog
)
523 struct cryptcat
*cc
= hCatalog
;
525 TRACE("(%p)\n", hCatalog
);
527 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
529 SetLastError(ERROR_INVALID_PARAMETER
);
532 HeapFree(GetProcessHeap(), 0, cc
->attr
);
533 HeapFree(GetProcessHeap(), 0, cc
->inner
);
534 CryptMsgClose(cc
->msg
);
537 HeapFree(GetProcessHeap(), 0, cc
);
541 /***********************************************************************
542 * CryptCATGetAttrInfo (WINTRUST.@)
544 CRYPTCATATTRIBUTE
* WINAPI
CryptCATGetAttrInfo(HANDLE hCatalog
, CRYPTCATMEMBER
*member
, LPWSTR tag
)
546 struct cryptcat
*cc
= hCatalog
;
548 FIXME("%p, %p, %s\n", hCatalog
, member
, debugstr_w(tag
));
550 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
552 SetLastError(ERROR_INVALID_PARAMETER
);
555 SetLastError(CRYPT_E_NOT_FOUND
);
559 /***********************************************************************
560 * CryptCATGetCatAttrInfo (WINTRUST.@)
562 CRYPTCATATTRIBUTE
* WINAPI
CryptCATGetCatAttrInfo(HANDLE hCatalog
, LPWSTR tag
)
564 struct cryptcat
*cc
= hCatalog
;
566 FIXME("%p, %s\n", hCatalog
, debugstr_w(tag
));
568 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
570 SetLastError(ERROR_INVALID_PARAMETER
);
573 SetLastError(CRYPT_E_NOT_FOUND
);
577 CRYPTCATMEMBER
* WINAPI
CryptCATGetMemberInfo(HANDLE hCatalog
, LPWSTR tag
)
579 struct cryptcat
*cc
= hCatalog
;
581 FIXME("%p, %s\n", hCatalog
, debugstr_w(tag
));
583 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
585 SetLastError(ERROR_INVALID_PARAMETER
);
588 SetLastError(CRYPT_E_NOT_FOUND
);
592 /***********************************************************************
593 * CryptCATEnumerateAttr (WINTRUST.@)
595 CRYPTCATATTRIBUTE
* WINAPI
CryptCATEnumerateAttr(HANDLE hCatalog
, CRYPTCATMEMBER
*member
, CRYPTCATATTRIBUTE
*prev
)
597 struct cryptcat
*cc
= hCatalog
;
599 FIXME("%p, %p, %p\n", hCatalog
, member
, prev
);
601 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
603 SetLastError(ERROR_INVALID_PARAMETER
);
606 SetLastError(CRYPT_E_NOT_FOUND
);
610 /***********************************************************************
611 * CryptCATEnumerateCatAttr (WINTRUST.@)
613 CRYPTCATATTRIBUTE
* WINAPI
CryptCATEnumerateCatAttr(HANDLE hCatalog
, CRYPTCATATTRIBUTE
*prev
)
615 struct cryptcat
*cc
= hCatalog
;
617 FIXME("%p, %p\n", hCatalog
, prev
);
619 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
621 SetLastError(ERROR_INVALID_PARAMETER
);
624 SetLastError(CRYPT_E_NOT_FOUND
);
628 /***********************************************************************
629 * CryptCATEnumerateMember (WINTRUST.@)
631 CRYPTCATMEMBER
* WINAPI
CryptCATEnumerateMember(HANDLE hCatalog
, CRYPTCATMEMBER
*prev
)
633 struct cryptcat
*cc
= hCatalog
;
634 CRYPTCATMEMBER
*member
= prev
;
638 TRACE("%p, %p\n", hCatalog
, prev
);
640 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
642 SetLastError(ERROR_INVALID_PARAMETER
);
646 /* dumping the contents makes me think that dwReserved is the iteration number */
649 if (!(member
= HeapAlloc(GetProcessHeap(), 0, sizeof(*member
))))
651 SetLastError(ERROR_OUTOFMEMORY
);
654 member
->cbStruct
= sizeof(*member
);
655 member
->pwszFileName
= member
->pwszReferenceTag
= NULL
;
656 member
->dwReserved
= 0;
657 member
->hReserved
= NULL
;
658 member
->gSubjectType
= cc
->subject
;
659 member
->fdwMemberFlags
= 0;
660 member
->pIndirectData
= NULL
;
661 member
->dwCertVersion
= cc
->inner
->dwVersion
;
663 else member
->dwReserved
++;
665 if (member
->dwReserved
>= cc
->inner
->cCTLEntry
)
667 SetLastError(ERROR_INVALID_PARAMETER
);
671 /* list them backwards, like native */
672 entry
= &cc
->inner
->rgCTLEntry
[cc
->inner
->cCTLEntry
- member
->dwReserved
- 1];
674 member
->sEncodedIndirectData
.cbData
= member
->sEncodedMemberInfo
.cbData
= 0;
675 member
->sEncodedIndirectData
.pbData
= member
->sEncodedMemberInfo
.pbData
= NULL
;
676 HeapFree(GetProcessHeap(), 0, member
->pIndirectData
);
677 member
->pIndirectData
= NULL
;
679 for (i
= 0; i
< entry
->cAttribute
; i
++)
681 CRYPT_ATTRIBUTE
*attr
= entry
->rgAttribute
+ i
;
683 if (attr
->cValue
!= 1)
685 ERR("Can't handle attr->cValue of %u\n", attr
->cValue
);
688 if (!strcmp(attr
->pszObjId
, CAT_MEMBERINFO_OBJID
))
693 member
->sEncodedMemberInfo
.cbData
= attr
->rgValue
->cbData
;
694 member
->sEncodedMemberInfo
.pbData
= attr
->rgValue
->pbData
;
696 CryptDecodeObject(cc
->encoding
, CAT_MEMBERINFO_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, NULL
, &size
);
698 if (!(mi
= HeapAlloc(GetProcessHeap(), 0, size
)))
700 SetLastError(ERROR_OUTOFMEMORY
);
703 ret
= CryptDecodeObject(cc
->encoding
, CAT_MEMBERINFO_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, mi
, &size
);
708 member
->dwCertVersion
= mi
->dwCertVersion
;
709 RtlInitUnicodeString(&guid
, mi
->pwszSubjGuid
);
710 if (RtlGUIDFromString(&guid
, &member
->gSubjectType
))
712 HeapFree(GetProcessHeap(), 0, mi
);
716 HeapFree(GetProcessHeap(), 0, mi
);
717 if (!ret
) goto error
;
719 else if (!strcmp(attr
->pszObjId
, SPC_INDIRECT_DATA_OBJID
))
721 /* SPC_INDIRECT_DATA_CONTENT is equal to SIP_INDIRECT_DATA */
723 member
->sEncodedIndirectData
.cbData
= attr
->rgValue
->cbData
;
724 member
->sEncodedIndirectData
.pbData
= attr
->rgValue
->pbData
;
726 CryptDecodeObject(cc
->encoding
, SPC_INDIRECT_DATA_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, NULL
, &size
);
728 if (!(member
->pIndirectData
= HeapAlloc(GetProcessHeap(), 0, size
)))
730 SetLastError(ERROR_OUTOFMEMORY
);
733 CryptDecodeObject(cc
->encoding
, SPC_INDIRECT_DATA_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, member
->pIndirectData
, &size
);
736 /* this object id should probably be handled in CryptCATEnumerateAttr */
737 FIXME("unhandled object id \"%s\"\n", attr
->pszObjId
);
740 if (!member
->sEncodedMemberInfo
.cbData
|| !member
->sEncodedIndirectData
.cbData
)
742 ERR("Corrupted catalog entry?\n");
743 SetLastError(CRYPT_E_ATTRIBUTES_MISSING
);
746 size
= (2 * member
->pIndirectData
->Digest
.cbData
+ 1) * sizeof(WCHAR
);
747 if (member
->pwszReferenceTag
)
748 member
->pwszReferenceTag
= HeapReAlloc(GetProcessHeap(), 0, member
->pwszReferenceTag
, size
);
750 member
->pwszReferenceTag
= HeapAlloc(GetProcessHeap(), 0, size
);
752 if (!member
->pwszReferenceTag
)
754 SetLastError(ERROR_OUTOFMEMORY
);
757 /* FIXME: reference tag is usually the file hash but doesn't have to be */
758 for (i
= 0; i
< member
->pIndirectData
->Digest
.cbData
; i
++)
762 sub
= member
->pIndirectData
->Digest
.pbData
[i
] >> 4;
763 member
->pwszReferenceTag
[i
* 2] = (sub
< 10 ? '0' + sub
: 'A' + sub
- 10);
764 sub
= member
->pIndirectData
->Digest
.pbData
[i
] & 0xf;
765 member
->pwszReferenceTag
[i
* 2 + 1] = (sub
< 10 ? '0' + sub
: 'A' + sub
- 10);
767 member
->pwszReferenceTag
[i
* 2] = 0;
771 HeapFree(GetProcessHeap(), 0, member
->pIndirectData
);
772 HeapFree(GetProcessHeap(), 0, member
->pwszReferenceTag
);
773 HeapFree(GetProcessHeap(), 0, member
);
777 static CTL_INFO
*decode_inner_content(HANDLE hmsg
, DWORD encoding
, DWORD
*len
)
782 CTL_INFO
*inner
= NULL
;
784 if (!CryptMsgGetParam(hmsg
, CMSG_INNER_CONTENT_TYPE_PARAM
, 0, NULL
, &size
)) return NULL
;
785 if (!(oid
= HeapAlloc(GetProcessHeap(), 0, size
)))
787 SetLastError(ERROR_OUTOFMEMORY
);
790 if (!CryptMsgGetParam(hmsg
, CMSG_INNER_CONTENT_TYPE_PARAM
, 0, oid
, &size
)) goto out
;
791 if (!CryptMsgGetParam(hmsg
, CMSG_CONTENT_PARAM
, 0, NULL
, &size
)) goto out
;
792 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, size
)))
794 SetLastError(ERROR_OUTOFMEMORY
);
797 if (!CryptMsgGetParam(hmsg
, CMSG_CONTENT_PARAM
, 0, buffer
, &size
)) goto out
;
798 if (!CryptDecodeObject(encoding
, oid
, buffer
, size
, 0, NULL
, &size
)) goto out
;
799 if (!(inner
= HeapAlloc(GetProcessHeap(), 0, size
)))
801 SetLastError(ERROR_OUTOFMEMORY
);
804 if (!CryptDecodeObject(encoding
, oid
, buffer
, size
, 0, inner
, &size
)) goto out
;
808 HeapFree(GetProcessHeap(), 0, oid
);
809 HeapFree(GetProcessHeap(), 0, buffer
);
813 /***********************************************************************
814 * CryptCATCatalogInfoFromContext (WINTRUST.@)
816 BOOL WINAPI
CryptCATCatalogInfoFromContext(HCATINFO hcatinfo
, CATALOG_INFO
*info
, DWORD flags
)
818 struct catinfo
*ci
= hcatinfo
;
820 TRACE("%p, %p, %x\n", hcatinfo
, info
, flags
);
822 if (!hcatinfo
|| hcatinfo
== INVALID_HANDLE_VALUE
|| ci
->magic
!= CATINFO_MAGIC
||
823 flags
|| !info
|| info
->cbStruct
!= sizeof(*info
))
825 SetLastError(ERROR_INVALID_PARAMETER
);
828 strcpyW(info
->wszCatalogFile
, ci
->file
);
832 /***********************************************************************
833 * CryptCATOpen (WINTRUST.@)
835 HANDLE WINAPI
CryptCATOpen(LPWSTR pwszFileName
, DWORD fdwOpenFlags
, HCRYPTPROV hProv
,
836 DWORD dwPublicVersion
, DWORD dwEncodingType
)
840 DWORD size
, flags
= OPEN_EXISTING
;
843 TRACE("%s, %x, %lx, %x, %x\n", debugstr_w(pwszFileName
), fdwOpenFlags
,
844 hProv
, dwPublicVersion
, dwEncodingType
);
848 SetLastError(ERROR_INVALID_PARAMETER
);
849 return INVALID_HANDLE_VALUE
;
852 if (!dwEncodingType
) dwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
854 if (fdwOpenFlags
& CRYPTCAT_OPEN_ALWAYS
) flags
|= OPEN_ALWAYS
;
855 if (fdwOpenFlags
& CRYPTCAT_OPEN_CREATENEW
) flags
|= CREATE_NEW
;
857 file
= CreateFileW(pwszFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, flags
, 0, NULL
);
858 if (file
== INVALID_HANDLE_VALUE
) return INVALID_HANDLE_VALUE
;
860 size
= GetFileSize(file
, NULL
);
861 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, size
)))
864 SetLastError(ERROR_OUTOFMEMORY
);
865 return INVALID_HANDLE_VALUE
;
867 if (!(hmsg
= CryptMsgOpenToDecode(dwEncodingType
, 0, 0, hProv
, NULL
, NULL
)))
870 HeapFree(GetProcessHeap(), 0, buffer
);
871 return INVALID_HANDLE_VALUE
;
873 if (!ReadFile(file
, buffer
, size
, &size
, NULL
) || !CryptMsgUpdate(hmsg
, buffer
, size
, TRUE
))
876 HeapFree(GetProcessHeap(), 0, buffer
);
878 return INVALID_HANDLE_VALUE
;
880 HeapFree(GetProcessHeap(), 0, buffer
);
883 size
= sizeof(DWORD
);
884 if (!(cc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cc
))))
887 SetLastError(ERROR_OUTOFMEMORY
);
888 return INVALID_HANDLE_VALUE
;
892 cc
->encoding
= dwEncodingType
;
893 if (CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_COUNT_PARAM
, 0, &cc
->attr_count
, &size
))
898 for (i
= 0; i
< cc
->attr_count
; i
++)
900 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, NULL
, &size
))
903 HeapFree(GetProcessHeap(), 0, cc
);
904 return INVALID_HANDLE_VALUE
;
908 if (!(cc
->attr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*cc
->attr
) * cc
->attr_count
+ sum
)))
911 HeapFree(GetProcessHeap(), 0, cc
);
912 SetLastError(ERROR_OUTOFMEMORY
);
913 return INVALID_HANDLE_VALUE
;
915 p
= (BYTE
*)(cc
->attr
+ cc
->attr_count
);
916 for (i
= 0; i
< cc
->attr_count
; i
++)
918 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, NULL
, &size
))
921 HeapFree(GetProcessHeap(), 0, cc
->attr
);
922 HeapFree(GetProcessHeap(), 0, cc
);
923 return INVALID_HANDLE_VALUE
;
925 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, p
, &size
))
928 HeapFree(GetProcessHeap(), 0, cc
->attr
);
929 HeapFree(GetProcessHeap(), 0, cc
);
930 return INVALID_HANDLE_VALUE
;
934 cc
->inner
= decode_inner_content(hmsg
, dwEncodingType
, &cc
->inner_len
);
935 if (!cc
->inner
|| !CryptSIPRetrieveSubjectGuid(pwszFileName
, NULL
, &cc
->subject
))
938 HeapFree(GetProcessHeap(), 0, cc
->attr
);
939 HeapFree(GetProcessHeap(), 0, cc
->inner
);
940 HeapFree(GetProcessHeap(), 0, cc
);
941 return INVALID_HANDLE_VALUE
;
943 cc
->magic
= CRYPTCAT_MAGIC
;
946 HeapFree(GetProcessHeap(), 0, cc
);
947 return INVALID_HANDLE_VALUE
;
950 /***********************************************************************
951 * CryptSIPCreateIndirectData (WINTRUST.@)
953 BOOL WINAPI
CryptSIPCreateIndirectData(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD
* pcbIndirectData
,
954 SIP_INDIRECT_DATA
* pIndirectData
)
956 FIXME("(%p %p %p) stub\n", pSubjectInfo
, pcbIndirectData
, pIndirectData
);
962 /***********************************************************************
963 * CryptCATCDFClose (WINTRUST.@)
965 BOOL WINAPI
CryptCATCDFClose(CRYPTCATCDF
*pCDF
)
967 FIXME("(%p) stub\n", pCDF
);
972 /***********************************************************************
973 * CryptCATCDFEnumCatAttributes (WINTRUST.@)
975 CRYPTCATATTRIBUTE
* WINAPI
CryptCATCDFEnumCatAttributes(CRYPTCATCDF
*pCDF
,
976 CRYPTCATATTRIBUTE
*pPrevAttr
,
977 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
)
979 FIXME("(%p %p %p) stub\n", pCDF
, pPrevAttr
, pfnParseError
);
984 /***********************************************************************
985 * CryptCATCDFEnumMembersByCDFTagEx (WINTRUST.@)
987 LPWSTR WINAPI
CryptCATCDFEnumMembersByCDFTagEx(CRYPTCATCDF
*pCDF
, LPWSTR pwszPrevCDFTag
,
988 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
,
989 CRYPTCATMEMBER
**ppMember
, BOOL fContinueOnError
,
992 FIXME("(%p %s %p %p %d %p) stub\n", pCDF
, debugstr_w(pwszPrevCDFTag
), pfnParseError
,
993 ppMember
, fContinueOnError
, pvReserved
);
998 /***********************************************************************
999 * CryptCATCDFOpen (WINTRUST.@)
1001 CRYPTCATCDF
* WINAPI
CryptCATCDFOpen(LPWSTR pwszFilePath
,
1002 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
)
1004 FIXME("(%s %p) stub\n", debugstr_w(pwszFilePath
), pfnParseError
);
1009 static BOOL
WINTRUST_GetSignedMsgFromPEFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1010 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1011 BYTE
*pbSignedDataMsg
)
1014 WIN_CERTIFICATE
*pCert
= NULL
;
1017 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1018 pcbSignedDataMsg
, pbSignedDataMsg
);
1020 if(pSubjectInfo
->hFile
&& pSubjectInfo
->hFile
!=INVALID_HANDLE_VALUE
)
1021 file
= pSubjectInfo
->hFile
;
1024 file
= CreateFileW(pSubjectInfo
->pwsFileName
, GENERIC_READ
,
1025 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
1026 if(file
== INVALID_HANDLE_VALUE
)
1030 if (!pbSignedDataMsg
)
1032 WIN_CERTIFICATE cert
;
1034 /* app hasn't passed buffer, just get the length */
1035 ret
= ImageGetCertificateHeader(file
, dwIndex
, &cert
);
1038 switch (cert
.wCertificateType
)
1040 case WIN_CERT_TYPE_X509
:
1041 case WIN_CERT_TYPE_PKCS_SIGNED_DATA
:
1042 *pcbSignedDataMsg
= cert
.dwLength
;
1045 WARN("unknown certificate type %d\n", cert
.wCertificateType
);
1054 ret
= ImageGetCertificateData(file
, dwIndex
, NULL
, &len
);
1055 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1057 pCert
= HeapAlloc(GetProcessHeap(), 0, len
);
1063 ret
= ImageGetCertificateData(file
, dwIndex
, pCert
, &len
);
1066 pCert
->dwLength
-= FIELD_OFFSET(WIN_CERTIFICATE
, bCertificate
);
1067 if (*pcbSignedDataMsg
< pCert
->dwLength
)
1069 *pcbSignedDataMsg
= pCert
->dwLength
;
1070 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1075 memcpy(pbSignedDataMsg
, pCert
->bCertificate
, pCert
->dwLength
);
1076 *pcbSignedDataMsg
= pCert
->dwLength
;
1077 switch (pCert
->wCertificateType
)
1079 case WIN_CERT_TYPE_X509
:
1080 *pdwEncodingType
= X509_ASN_ENCODING
;
1082 case WIN_CERT_TYPE_PKCS_SIGNED_DATA
:
1083 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1086 WARN("don't know what to do for encoding type %d\n",
1087 pCert
->wCertificateType
);
1088 *pdwEncodingType
= 0;
1094 if(pSubjectInfo
->hFile
!= file
)
1096 HeapFree(GetProcessHeap(), 0, pCert
);
1100 static BOOL
WINTRUST_PutSignedMsgToPEFile(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD pdwEncodingType
,
1101 DWORD
* pdwIndex
, DWORD cbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1103 WIN_CERTIFICATE
*cert
;
1108 if(pSubjectInfo
->hFile
&& pSubjectInfo
->hFile
!=INVALID_HANDLE_VALUE
)
1109 file
= pSubjectInfo
->hFile
;
1112 file
= CreateFileW(pSubjectInfo
->pwsFileName
, GENERIC_READ
|GENERIC_WRITE
,
1113 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
1114 if(file
== INVALID_HANDLE_VALUE
)
1118 /* int aligned WIN_CERTIFICATE structure with cbSignedDataMsg+1 bytes of data */
1119 size
= FIELD_OFFSET(WIN_CERTIFICATE
, bCertificate
[cbSignedDataMsg
+4]) & (~3);
1120 cert
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1124 cert
->dwLength
= size
;
1125 cert
->wRevision
= WIN_CERT_REVISION_2_0
;
1126 cert
->wCertificateType
= WIN_CERT_TYPE_PKCS_SIGNED_DATA
;
1127 memcpy(cert
->bCertificate
, pbSignedDataMsg
, cbSignedDataMsg
);
1128 ret
= ImageAddCertificate(file
, cert
, pdwIndex
);
1130 HeapFree(GetProcessHeap(), 0, cert
);
1131 if(file
!= pSubjectInfo
->hFile
)
1136 /* structure offsets */
1137 #define cfhead_Signature (0x00)
1138 #define cfhead_CabinetSize (0x08)
1139 #define cfhead_MinorVersion (0x18)
1140 #define cfhead_MajorVersion (0x19)
1141 #define cfhead_Flags (0x1E)
1142 #define cfhead_SIZEOF (0x24)
1143 #define cfheadext_HeaderReserved (0x00)
1144 #define cfheadext_SIZEOF (0x04)
1145 #define cfsigninfo_CertOffset (0x04)
1146 #define cfsigninfo_CertSize (0x08)
1147 #define cfsigninfo_SIZEOF (0x0C)
1150 #define cfheadRESERVE_PRESENT (0x0004)
1152 /* endian-neutral reading of little-endian data */
1153 #define EndGetI32(a) ((((a)[3])<<24)|(((a)[2])<<16)|(((a)[1])<<8)|((a)[0]))
1154 #define EndGetI16(a) ((((a)[1])<<8)|((a)[0]))
1156 /* For documentation purposes only: this is the structure in the reserved
1157 * area of a signed cabinet file. The cert offset indicates where in the
1158 * cabinet file the signature resides, and the count indicates its size.
1160 typedef struct _CAB_SIGNINFO
1162 WORD unk0
; /* always 0? */
1163 WORD unk1
; /* always 0x0010? */
1166 } CAB_SIGNINFO
, *PCAB_SIGNINFO
;
1168 static BOOL
WINTRUST_GetSignedMsgFromCabFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1169 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1170 BYTE
*pbSignedDataMsg
)
1173 LONG base_offset
, cabsize
;
1176 DWORD cert_offset
, cert_size
, dwRead
;
1178 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1179 pcbSignedDataMsg
, pbSignedDataMsg
);
1181 /* get basic offset & size info */
1182 base_offset
= SetFilePointer(pSubjectInfo
->hFile
, 0L, NULL
, SEEK_CUR
);
1184 if (SetFilePointer(pSubjectInfo
->hFile
, 0, NULL
, SEEK_END
) == INVALID_SET_FILE_POINTER
)
1186 TRACE("seek error\n");
1190 cabsize
= SetFilePointer(pSubjectInfo
->hFile
, 0L, NULL
, SEEK_CUR
);
1191 if ((cabsize
== -1) || (base_offset
== -1) ||
1192 (SetFilePointer(pSubjectInfo
->hFile
, 0, NULL
, SEEK_SET
) == INVALID_SET_FILE_POINTER
))
1194 TRACE("seek error\n");
1198 /* read in the CFHEADER */
1199 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfhead_SIZEOF
, &dwRead
, NULL
) ||
1200 dwRead
!= cfhead_SIZEOF
)
1202 TRACE("reading header failed\n");
1206 /* check basic MSCF signature */
1207 if (EndGetI32(buf
+cfhead_Signature
) != 0x4643534d)
1209 WARN("cabinet signature not present\n");
1213 /* Ignore the number of folders and files and the set and cabinet IDs */
1215 /* check the header revision */
1216 if ((buf
[cfhead_MajorVersion
] > 1) ||
1217 (buf
[cfhead_MajorVersion
] == 1 && buf
[cfhead_MinorVersion
] > 3))
1219 WARN("cabinet format version > 1.3\n");
1223 /* pull the flags out */
1224 flags
= EndGetI16(buf
+cfhead_Flags
);
1226 if (!(flags
& cfheadRESERVE_PRESENT
))
1228 TRACE("no header present, not signed\n");
1232 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfheadext_SIZEOF
, &dwRead
, NULL
) ||
1233 dwRead
!= cfheadext_SIZEOF
)
1235 ERR("bunk reserve-sizes?\n");
1239 header_resv
= EndGetI16(buf
+cfheadext_HeaderReserved
);
1242 TRACE("no header_resv, not signed\n");
1245 else if (header_resv
< cfsigninfo_SIZEOF
)
1247 TRACE("header_resv too small, not signed\n");
1251 if (header_resv
> 60000)
1253 WARN("WARNING; header reserved space > 60000\n");
1256 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfsigninfo_SIZEOF
, &dwRead
, NULL
) ||
1257 dwRead
!= cfsigninfo_SIZEOF
)
1259 ERR("couldn't read reserve\n");
1263 cert_offset
= EndGetI32(buf
+cfsigninfo_CertOffset
);
1264 TRACE("cert_offset: %d\n", cert_offset
);
1265 cert_size
= EndGetI32(buf
+cfsigninfo_CertSize
);
1266 TRACE("cert_size: %d\n", cert_size
);
1268 /* The redundant checks are to avoid wraparound */
1269 if (cert_offset
> cabsize
|| cert_size
> cabsize
||
1270 cert_offset
+ cert_size
> cabsize
)
1272 WARN("offset beyond file, not attempting to read\n");
1276 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1277 if (!pbSignedDataMsg
)
1279 *pcbSignedDataMsg
= cert_size
;
1282 if (*pcbSignedDataMsg
< cert_size
)
1284 *pcbSignedDataMsg
= cert_size
;
1285 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1288 if (SetFilePointer(pSubjectInfo
->hFile
, cert_offset
, NULL
, SEEK_SET
) == INVALID_SET_FILE_POINTER
)
1290 ERR("couldn't seek to cert location\n");
1293 if (!ReadFile(pSubjectInfo
->hFile
, pbSignedDataMsg
, cert_size
, &dwRead
,
1294 NULL
) || dwRead
!= cert_size
)
1296 ERR("couldn't read cert\n");
1297 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1300 /* The encoding of the files I've seen appears to be in ASN.1
1301 * format, and there isn't a field indicating the type, so assume it
1304 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1305 /* Restore base offset */
1306 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1310 static BOOL
WINTRUST_GetSignedMsgFromCatFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1311 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1312 BYTE
*pbSignedDataMsg
)
1316 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1317 pcbSignedDataMsg
, pbSignedDataMsg
);
1319 if (!pbSignedDataMsg
)
1321 *pcbSignedDataMsg
= GetFileSize(pSubjectInfo
->hFile
, NULL
);
1326 DWORD len
= GetFileSize(pSubjectInfo
->hFile
, NULL
);
1328 if (*pcbSignedDataMsg
< len
)
1330 *pcbSignedDataMsg
= len
;
1331 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1336 ret
= ReadFile(pSubjectInfo
->hFile
, pbSignedDataMsg
, len
,
1337 pcbSignedDataMsg
, NULL
);
1339 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1345 /* GUIDs used by CryptSIPGetSignedDataMsg and CryptSIPPutSignedDataMsg */
1346 static const GUID unknown
= { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
1347 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1348 static const GUID cabGUID
= { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,
1349 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1350 static const GUID catGUID
= { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,
1351 0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1353 /***********************************************************************
1354 * CryptSIPGetSignedDataMsg (WINTRUST.@)
1356 BOOL WINAPI
CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD
* pdwEncodingType
,
1357 DWORD dwIndex
, DWORD
* pcbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1361 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1362 pcbSignedDataMsg
, pbSignedDataMsg
);
1366 SetLastError(ERROR_INVALID_PARAMETER
);
1370 if (!memcmp(pSubjectInfo
->pgSubjectType
, &unknown
, sizeof(unknown
)))
1371 ret
= WINTRUST_GetSignedMsgFromPEFile(pSubjectInfo
, pdwEncodingType
,
1372 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1373 else if (!memcmp(pSubjectInfo
->pgSubjectType
, &cabGUID
, sizeof(cabGUID
)))
1374 ret
= WINTRUST_GetSignedMsgFromCabFile(pSubjectInfo
, pdwEncodingType
,
1375 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1376 else if (!memcmp(pSubjectInfo
->pgSubjectType
, &catGUID
, sizeof(catGUID
)))
1377 ret
= WINTRUST_GetSignedMsgFromCatFile(pSubjectInfo
, pdwEncodingType
,
1378 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1381 FIXME("unimplemented for subject type %s\n",
1382 debugstr_guid(pSubjectInfo
->pgSubjectType
));
1386 TRACE("returning %d\n", ret
);
1390 /***********************************************************************
1391 * CryptSIPPutSignedDataMsg (WINTRUST.@)
1393 BOOL WINAPI
CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD pdwEncodingType
,
1394 DWORD
* pdwIndex
, DWORD cbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1396 TRACE("(%p %d %p %d %p)\n", pSubjectInfo
, pdwEncodingType
, pdwIndex
,
1397 cbSignedDataMsg
, pbSignedDataMsg
);
1400 SetLastError(ERROR_INVALID_PARAMETER
);
1404 if(!memcmp(pSubjectInfo
->pgSubjectType
, &unknown
, sizeof(unknown
)))
1405 return WINTRUST_PutSignedMsgToPEFile(pSubjectInfo
, pdwEncodingType
,
1406 pdwIndex
, cbSignedDataMsg
, pbSignedDataMsg
);
1408 FIXME("unimplemented for subject type %s\n",
1409 debugstr_guid(pSubjectInfo
->pgSubjectType
));
1414 /***********************************************************************
1415 * CryptSIPRemoveSignedDataMsg (WINTRUST.@)
1417 BOOL WINAPI
CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
,
1420 FIXME("(%p %d) stub\n", pSubjectInfo
, dwIndex
);
1425 /***********************************************************************
1426 * CryptSIPVerifyIndirectData (WINTRUST.@)
1428 BOOL WINAPI
CryptSIPVerifyIndirectData(SIP_SUBJECTINFO
* pSubjectInfo
,
1429 SIP_INDIRECT_DATA
* pIndirectData
)
1431 FIXME("(%p %p) stub\n", pSubjectInfo
, pIndirectData
);