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
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' */
53 CRYPTCATATTRIBUTE
*attr
;
69 static HCATINFO
create_catinfo(const WCHAR
*filename
)
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
;
83 /***********************************************************************
84 * CryptCATAdminAcquireContext (WINTRUST.@)
86 * Get a catalog administrator context handle.
89 * catAdmin [O] Pointer to the context handle.
90 * sys [I] Pointer to a GUID for the needed subsystem.
91 * dwFlags [I] Reserved.
94 * Success: TRUE. catAdmin contains the context handle.
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
];
114 TRACE("%p %s %x\n", catAdmin
, debugstr_guid(sys
), dwFlags
);
116 if (!catAdmin
|| dwFlags
)
118 SetLastError(ERROR_INVALID_PARAMETER
);
121 if (!(ca
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ca
))))
123 SetLastError(ERROR_OUTOFMEMORY
);
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],
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
;
149 /***********************************************************************
150 * CryptCATAdminAcquireContext2 (WINTRUST.@)
152 BOOL WINAPI
CryptCATAdminAcquireContext2(HCATADMIN
*catAdmin
, const GUID
*sys
, const WCHAR
*algorithm
,
153 const CERT_STRONG_SIGN_PARA
*policy
, DWORD flags
)
155 FIXME("%p %s %s %p %x stub\n", catAdmin
, debugstr_guid(sys
), debugstr_w(algorithm
), policy
, flags
);
156 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
160 /***********************************************************************
161 * CryptCATAdminAddCatalog (WINTRUST.@)
163 HCATINFO WINAPI
CryptCATAdminAddCatalog(HCATADMIN catAdmin
, PWSTR catalogFile
,
164 PWSTR selectBaseName
, DWORD flags
)
166 static const WCHAR slashW
[] = {'\\',0};
167 struct catadmin
*ca
= catAdmin
;
172 TRACE("%p %s %s %d\n", catAdmin
, debugstr_w(catalogFile
),
173 debugstr_w(selectBaseName
), flags
);
177 FIXME("NULL basename not handled\n");
178 SetLastError(ERROR_INVALID_PARAMETER
);
181 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !catalogFile
|| flags
)
183 SetLastError(ERROR_INVALID_PARAMETER
);
187 len
= strlenW(ca
->path
) + strlenW(selectBaseName
) + 2;
188 if (!(target
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
190 SetLastError(ERROR_OUTOFMEMORY
);
193 strcpyW(target
, ca
->path
);
194 strcatW(target
, slashW
);
195 strcatW(target
, selectBaseName
);
197 if (!CopyFileW(catalogFile
, target
, FALSE
))
199 HeapFree(GetProcessHeap(), 0, target
);
202 SetFileAttributesW(target
, FILE_ATTRIBUTE_SYSTEM
);
204 if (!(ci
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ci
))))
206 HeapFree(GetProcessHeap(), 0, target
);
207 SetLastError(ERROR_OUTOFMEMORY
);
210 ci
->magic
= CATINFO_MAGIC
;
211 strcpyW(ci
->file
, target
);
213 HeapFree(GetProcessHeap(), 0, target
);
217 /***********************************************************************
218 * CryptCATAdminCalcHashFromFileHandle (WINTRUST.@)
220 BOOL WINAPI
CryptCATAdminCalcHashFromFileHandle(HANDLE hFile
, DWORD
* pcbHash
,
221 BYTE
* pbHash
, DWORD dwFlags
)
225 TRACE("%p %p %p %x\n", hFile
, pcbHash
, pbHash
, dwFlags
);
227 if (!hFile
|| !pcbHash
|| dwFlags
)
229 SetLastError(ERROR_INVALID_PARAMETER
);
235 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
247 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, 4096)))
249 SetLastError(ERROR_OUTOFMEMORY
);
252 ret
= CryptAcquireContextW(&prov
, NULL
, MS_DEF_PROV_W
, PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
255 HeapFree(GetProcessHeap(), 0, buffer
);
258 ret
= CryptCreateHash(prov
, CALG_SHA1
, 0, 0, &hash
);
261 HeapFree(GetProcessHeap(), 0, buffer
);
262 CryptReleaseContext(prov
, 0);
265 while ((ret
= ReadFile(hFile
, buffer
, 4096, &bytes_read
, NULL
)) && bytes_read
)
267 CryptHashData(hash
, buffer
, bytes_read
, 0);
269 if (ret
) ret
= CryptGetHashParam(hash
, HP_HASHVAL
, pbHash
, pcbHash
, 0);
271 HeapFree(GetProcessHeap(), 0, buffer
);
272 CryptDestroyHash(hash
);
273 CryptReleaseContext(prov
, 0);
278 /***********************************************************************
279 * CryptCATAdminEnumCatalogFromHash (WINTRUST.@)
281 HCATINFO WINAPI
CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin
, BYTE
* pbHash
,
282 DWORD cbHash
, DWORD dwFlags
,
283 HCATINFO
* phPrevCatInfo
)
285 static const WCHAR slashW
[] = {'\\',0};
286 static const WCHAR globW
[] = {'\\','*','.','c','a','t',0};
288 struct catadmin
*ca
= hCatAdmin
;
289 WIN32_FIND_DATAW data
;
290 HCATINFO prev
= NULL
;
295 TRACE("%p %p %d %x %p\n", hCatAdmin
, pbHash
, cbHash
, dwFlags
, phPrevCatInfo
);
297 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !pbHash
|| cbHash
!= 20 || dwFlags
)
299 SetLastError(ERROR_INVALID_PARAMETER
);
302 if (phPrevCatInfo
) prev
= *phPrevCatInfo
;
304 ret
= CryptAcquireContextW(&prov
, NULL
, MS_DEF_PROV_W
, PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
305 if (!ret
) return NULL
;
311 size
= strlenW(ca
->path
) * sizeof(WCHAR
) + sizeof(globW
);
312 if (!(path
= HeapAlloc(GetProcessHeap(), 0, size
)))
314 CryptReleaseContext(prov
, 0);
315 SetLastError(ERROR_OUTOFMEMORY
);
318 strcpyW(path
, ca
->path
);
319 strcatW(path
, globW
);
322 ca
->find
= FindFirstFileW(path
, &data
);
324 HeapFree(GetProcessHeap(), 0, path
);
325 if (ca
->find
== INVALID_HANDLE_VALUE
)
327 CryptReleaseContext(prov
, 0);
331 else if (!FindNextFileW(ca
->find
, &data
))
333 CryptCATAdminReleaseCatalogContext(hCatAdmin
, prev
, 0);
334 CryptReleaseContext(prov
, 0);
341 CRYPTCATMEMBER
*member
= NULL
;
345 size
= (strlenW(ca
->path
) + strlenW(data
.cFileName
) + 2) * sizeof(WCHAR
);
346 if (!(filename
= HeapAlloc(GetProcessHeap(), 0, size
)))
348 SetLastError(ERROR_OUTOFMEMORY
);
351 strcpyW(filename
, ca
->path
);
352 strcatW(filename
, slashW
);
353 strcatW(filename
, data
.cFileName
);
355 hcat
= CryptCATOpen(filename
, CRYPTCAT_OPEN_EXISTING
, prov
, 0, 0);
356 if (hcat
== INVALID_HANDLE_VALUE
)
358 WARN("couldn't open %s (%u)\n", debugstr_w(filename
), GetLastError());
361 while ((member
= CryptCATEnumerateMember(hcat
, member
)))
363 if (member
->pIndirectData
->Digest
.cbData
!= cbHash
)
365 WARN("amount of hash bytes differs: %u/%u\n", member
->pIndirectData
->Digest
.cbData
, cbHash
);
368 if (!memcmp(member
->pIndirectData
->Digest
.pbData
, pbHash
, cbHash
))
370 TRACE("file %s matches\n", debugstr_w(data
.cFileName
));
373 CryptReleaseContext(prov
, 0);
377 ca
->find
= INVALID_HANDLE_VALUE
;
379 ci
= create_catinfo(filename
);
380 HeapFree(GetProcessHeap(), 0, filename
);
385 HeapFree(GetProcessHeap(), 0, filename
);
387 if (!FindNextFileW(ca
->find
, &data
))
390 ca
->find
= INVALID_HANDLE_VALUE
;
391 CryptReleaseContext(prov
, 0);
398 /***********************************************************************
399 * CryptCATAdminReleaseCatalogContext (WINTRUST.@)
401 * Release a catalog context handle.
404 * hCatAdmin [I] Context handle.
405 * hCatInfo [I] Catalog handle.
406 * dwFlags [I] Reserved.
413 BOOL WINAPI
CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin
,
417 struct catinfo
*ci
= hCatInfo
;
418 struct catadmin
*ca
= hCatAdmin
;
420 TRACE("%p %p %x\n", hCatAdmin
, hCatInfo
, dwFlags
);
422 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !ci
|| ci
->magic
!= CATINFO_MAGIC
)
424 SetLastError(ERROR_INVALID_PARAMETER
);
428 return HeapFree(GetProcessHeap(), 0, ci
);
431 /***********************************************************************
432 * CryptCATAdminReleaseContext (WINTRUST.@)
434 * Release a catalog administrator context handle.
437 * catAdmin [I] Context handle.
438 * dwFlags [I] Reserved.
445 BOOL WINAPI
CryptCATAdminReleaseContext(HCATADMIN hCatAdmin
, DWORD dwFlags
)
447 struct catadmin
*ca
= hCatAdmin
;
449 TRACE("%p %x\n", hCatAdmin
, dwFlags
);
451 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
)
453 SetLastError(ERROR_INVALID_PARAMETER
);
456 if (ca
->find
!= INVALID_HANDLE_VALUE
) FindClose(ca
->find
);
458 return HeapFree(GetProcessHeap(), 0, ca
);
461 /***********************************************************************
462 * CryptCATAdminRemoveCatalog (WINTRUST.@)
464 * Remove a catalog file.
467 * catAdmin [I] Context handle.
468 * pwszCatalogFile [I] Catalog file.
469 * dwFlags [I] Reserved.
476 BOOL WINAPI
CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin
, LPCWSTR pwszCatalogFile
, DWORD dwFlags
)
478 struct catadmin
*ca
= hCatAdmin
;
480 TRACE("%p %s %x\n", hCatAdmin
, debugstr_w(pwszCatalogFile
), dwFlags
);
482 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
)
484 SetLastError(ERROR_INVALID_PARAMETER
);
488 /* Only delete when there is a filename and no path */
489 if (pwszCatalogFile
&& pwszCatalogFile
[0] != 0 &&
490 !strchrW(pwszCatalogFile
, '\\') && !strchrW(pwszCatalogFile
, '/') &&
491 !strchrW(pwszCatalogFile
, ':'))
493 static const WCHAR slashW
[] = {'\\',0};
497 len
= strlenW(ca
->path
) + strlenW(pwszCatalogFile
) + 2;
498 if (!(target
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
500 SetLastError(ERROR_OUTOFMEMORY
);
503 strcpyW(target
, ca
->path
);
504 strcatW(target
, slashW
);
505 strcatW(target
, pwszCatalogFile
);
509 HeapFree(GetProcessHeap(), 0, target
);
515 /***********************************************************************
516 * CryptCATAdminResolveCatalogPath (WINTRUST.@)
518 BOOL WINAPI
CryptCATAdminResolveCatalogPath(HCATADMIN hcatadmin
, WCHAR
*catalog_file
,
519 CATALOG_INFO
*info
, DWORD flags
)
521 static const WCHAR slashW
[] = {'\\',0};
522 struct catadmin
*ca
= hcatadmin
;
524 TRACE("%p %s %p %x\n", hcatadmin
, debugstr_w(catalog_file
), info
, flags
);
526 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !info
|| info
->cbStruct
!= sizeof(*info
) || flags
)
528 SetLastError(ERROR_INVALID_PARAMETER
);
531 strcpyW(info
->wszCatalogFile
, ca
->path
);
532 strcatW(info
->wszCatalogFile
, slashW
);
533 strcatW(info
->wszCatalogFile
, catalog_file
);
538 /***********************************************************************
539 * CryptCATClose (WINTRUST.@)
541 BOOL WINAPI
CryptCATClose(HANDLE hCatalog
)
543 struct cryptcat
*cc
= hCatalog
;
545 TRACE("(%p)\n", hCatalog
);
547 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
549 SetLastError(ERROR_INVALID_PARAMETER
);
552 HeapFree(GetProcessHeap(), 0, cc
->attr
);
553 HeapFree(GetProcessHeap(), 0, cc
->inner
);
554 CryptMsgClose(cc
->msg
);
557 HeapFree(GetProcessHeap(), 0, cc
);
561 /***********************************************************************
562 * CryptCATGetAttrInfo (WINTRUST.@)
564 CRYPTCATATTRIBUTE
* WINAPI
CryptCATGetAttrInfo(HANDLE hCatalog
, CRYPTCATMEMBER
*member
, LPWSTR tag
)
566 struct cryptcat
*cc
= hCatalog
;
568 FIXME("%p, %p, %s\n", hCatalog
, member
, debugstr_w(tag
));
570 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
572 SetLastError(ERROR_INVALID_PARAMETER
);
575 SetLastError(CRYPT_E_NOT_FOUND
);
579 /***********************************************************************
580 * CryptCATGetCatAttrInfo (WINTRUST.@)
582 CRYPTCATATTRIBUTE
* WINAPI
CryptCATGetCatAttrInfo(HANDLE hCatalog
, LPWSTR tag
)
584 struct cryptcat
*cc
= hCatalog
;
586 FIXME("%p, %s\n", hCatalog
, debugstr_w(tag
));
588 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
590 SetLastError(ERROR_INVALID_PARAMETER
);
593 SetLastError(CRYPT_E_NOT_FOUND
);
597 CRYPTCATMEMBER
* WINAPI
CryptCATGetMemberInfo(HANDLE hCatalog
, LPWSTR tag
)
599 struct cryptcat
*cc
= hCatalog
;
601 FIXME("%p, %s\n", hCatalog
, debugstr_w(tag
));
603 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
605 SetLastError(ERROR_INVALID_PARAMETER
);
608 SetLastError(CRYPT_E_NOT_FOUND
);
612 /***********************************************************************
613 * CryptCATEnumerateAttr (WINTRUST.@)
615 CRYPTCATATTRIBUTE
* WINAPI
CryptCATEnumerateAttr(HANDLE hCatalog
, CRYPTCATMEMBER
*member
, CRYPTCATATTRIBUTE
*prev
)
617 struct cryptcat
*cc
= hCatalog
;
619 FIXME("%p, %p, %p\n", hCatalog
, member
, prev
);
621 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
623 SetLastError(ERROR_INVALID_PARAMETER
);
626 SetLastError(CRYPT_E_NOT_FOUND
);
630 /***********************************************************************
631 * CryptCATEnumerateCatAttr (WINTRUST.@)
633 CRYPTCATATTRIBUTE
* WINAPI
CryptCATEnumerateCatAttr(HANDLE hCatalog
, CRYPTCATATTRIBUTE
*prev
)
635 struct cryptcat
*cc
= hCatalog
;
637 FIXME("%p, %p\n", hCatalog
, prev
);
639 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
641 SetLastError(ERROR_INVALID_PARAMETER
);
644 SetLastError(CRYPT_E_NOT_FOUND
);
648 /***********************************************************************
649 * CryptCATEnumerateMember (WINTRUST.@)
651 CRYPTCATMEMBER
* WINAPI
CryptCATEnumerateMember(HANDLE hCatalog
, CRYPTCATMEMBER
*prev
)
653 struct cryptcat
*cc
= hCatalog
;
654 CRYPTCATMEMBER
*member
= prev
;
658 TRACE("%p, %p\n", hCatalog
, prev
);
660 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
662 SetLastError(ERROR_INVALID_PARAMETER
);
666 /* dumping the contents makes me think that dwReserved is the iteration number */
669 if (!(member
= HeapAlloc(GetProcessHeap(), 0, sizeof(*member
))))
671 SetLastError(ERROR_OUTOFMEMORY
);
674 member
->cbStruct
= sizeof(*member
);
675 member
->pwszFileName
= member
->pwszReferenceTag
= NULL
;
676 member
->dwReserved
= 0;
677 member
->hReserved
= NULL
;
678 member
->gSubjectType
= cc
->subject
;
679 member
->fdwMemberFlags
= 0;
680 member
->pIndirectData
= NULL
;
681 member
->dwCertVersion
= cc
->inner
->dwVersion
;
683 else member
->dwReserved
++;
685 if (member
->dwReserved
>= cc
->inner
->cCTLEntry
)
687 SetLastError(ERROR_INVALID_PARAMETER
);
691 /* list them backwards, like native */
692 entry
= &cc
->inner
->rgCTLEntry
[cc
->inner
->cCTLEntry
- member
->dwReserved
- 1];
694 member
->sEncodedIndirectData
.cbData
= member
->sEncodedMemberInfo
.cbData
= 0;
695 member
->sEncodedIndirectData
.pbData
= member
->sEncodedMemberInfo
.pbData
= NULL
;
696 HeapFree(GetProcessHeap(), 0, member
->pIndirectData
);
697 member
->pIndirectData
= NULL
;
699 for (i
= 0; i
< entry
->cAttribute
; i
++)
701 CRYPT_ATTRIBUTE
*attr
= entry
->rgAttribute
+ i
;
703 if (attr
->cValue
!= 1)
705 ERR("Can't handle attr->cValue of %u\n", attr
->cValue
);
708 if (!strcmp(attr
->pszObjId
, CAT_MEMBERINFO_OBJID
))
713 member
->sEncodedMemberInfo
.cbData
= attr
->rgValue
->cbData
;
714 member
->sEncodedMemberInfo
.pbData
= attr
->rgValue
->pbData
;
716 CryptDecodeObject(cc
->encoding
, CAT_MEMBERINFO_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, NULL
, &size
);
718 if (!(mi
= HeapAlloc(GetProcessHeap(), 0, size
)))
720 SetLastError(ERROR_OUTOFMEMORY
);
723 ret
= CryptDecodeObject(cc
->encoding
, CAT_MEMBERINFO_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, mi
, &size
);
728 member
->dwCertVersion
= mi
->dwCertVersion
;
729 RtlInitUnicodeString(&guid
, mi
->pwszSubjGuid
);
730 if (RtlGUIDFromString(&guid
, &member
->gSubjectType
))
732 HeapFree(GetProcessHeap(), 0, mi
);
736 HeapFree(GetProcessHeap(), 0, mi
);
737 if (!ret
) goto error
;
739 else if (!strcmp(attr
->pszObjId
, SPC_INDIRECT_DATA_OBJID
))
741 /* SPC_INDIRECT_DATA_CONTENT is equal to SIP_INDIRECT_DATA */
743 member
->sEncodedIndirectData
.cbData
= attr
->rgValue
->cbData
;
744 member
->sEncodedIndirectData
.pbData
= attr
->rgValue
->pbData
;
746 CryptDecodeObject(cc
->encoding
, SPC_INDIRECT_DATA_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, NULL
, &size
);
748 if (!(member
->pIndirectData
= HeapAlloc(GetProcessHeap(), 0, size
)))
750 SetLastError(ERROR_OUTOFMEMORY
);
753 CryptDecodeObject(cc
->encoding
, SPC_INDIRECT_DATA_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, member
->pIndirectData
, &size
);
756 /* this object id should probably be handled in CryptCATEnumerateAttr */
757 FIXME("unhandled object id \"%s\"\n", attr
->pszObjId
);
760 if (!member
->sEncodedMemberInfo
.cbData
|| !member
->sEncodedIndirectData
.cbData
)
762 ERR("Corrupted catalog entry?\n");
763 SetLastError(CRYPT_E_ATTRIBUTES_MISSING
);
766 size
= (2 * member
->pIndirectData
->Digest
.cbData
+ 1) * sizeof(WCHAR
);
767 if (member
->pwszReferenceTag
)
768 member
->pwszReferenceTag
= HeapReAlloc(GetProcessHeap(), 0, member
->pwszReferenceTag
, size
);
770 member
->pwszReferenceTag
= HeapAlloc(GetProcessHeap(), 0, size
);
772 if (!member
->pwszReferenceTag
)
774 SetLastError(ERROR_OUTOFMEMORY
);
777 /* FIXME: reference tag is usually the file hash but doesn't have to be */
778 for (i
= 0; i
< member
->pIndirectData
->Digest
.cbData
; i
++)
782 sub
= member
->pIndirectData
->Digest
.pbData
[i
] >> 4;
783 member
->pwszReferenceTag
[i
* 2] = (sub
< 10 ? '0' + sub
: 'A' + sub
- 10);
784 sub
= member
->pIndirectData
->Digest
.pbData
[i
] & 0xf;
785 member
->pwszReferenceTag
[i
* 2 + 1] = (sub
< 10 ? '0' + sub
: 'A' + sub
- 10);
787 member
->pwszReferenceTag
[i
* 2] = 0;
791 HeapFree(GetProcessHeap(), 0, member
->pIndirectData
);
792 HeapFree(GetProcessHeap(), 0, member
->pwszReferenceTag
);
793 HeapFree(GetProcessHeap(), 0, member
);
797 static CTL_INFO
*decode_inner_content(HANDLE hmsg
, DWORD encoding
, DWORD
*len
)
802 CTL_INFO
*inner
= NULL
;
804 if (!CryptMsgGetParam(hmsg
, CMSG_INNER_CONTENT_TYPE_PARAM
, 0, NULL
, &size
)) return NULL
;
805 if (!(oid
= HeapAlloc(GetProcessHeap(), 0, size
)))
807 SetLastError(ERROR_OUTOFMEMORY
);
810 if (!CryptMsgGetParam(hmsg
, CMSG_INNER_CONTENT_TYPE_PARAM
, 0, oid
, &size
)) goto out
;
811 if (!CryptMsgGetParam(hmsg
, CMSG_CONTENT_PARAM
, 0, NULL
, &size
)) goto out
;
812 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, size
)))
814 SetLastError(ERROR_OUTOFMEMORY
);
817 if (!CryptMsgGetParam(hmsg
, CMSG_CONTENT_PARAM
, 0, buffer
, &size
)) goto out
;
818 if (!CryptDecodeObject(encoding
, oid
, buffer
, size
, 0, NULL
, &size
)) goto out
;
819 if (!(inner
= HeapAlloc(GetProcessHeap(), 0, size
)))
821 SetLastError(ERROR_OUTOFMEMORY
);
824 if (!CryptDecodeObject(encoding
, oid
, buffer
, size
, 0, inner
, &size
)) goto out
;
828 HeapFree(GetProcessHeap(), 0, oid
);
829 HeapFree(GetProcessHeap(), 0, buffer
);
833 /***********************************************************************
834 * CryptCATCatalogInfoFromContext (WINTRUST.@)
836 BOOL WINAPI
CryptCATCatalogInfoFromContext(HCATINFO hcatinfo
, CATALOG_INFO
*info
, DWORD flags
)
838 struct catinfo
*ci
= hcatinfo
;
840 TRACE("%p, %p, %x\n", hcatinfo
, info
, flags
);
842 if (!hcatinfo
|| hcatinfo
== INVALID_HANDLE_VALUE
|| ci
->magic
!= CATINFO_MAGIC
||
843 flags
|| !info
|| info
->cbStruct
!= sizeof(*info
))
845 SetLastError(ERROR_INVALID_PARAMETER
);
848 strcpyW(info
->wszCatalogFile
, ci
->file
);
852 /***********************************************************************
853 * CryptCATOpen (WINTRUST.@)
855 HANDLE WINAPI
CryptCATOpen(LPWSTR pwszFileName
, DWORD fdwOpenFlags
, HCRYPTPROV hProv
,
856 DWORD dwPublicVersion
, DWORD dwEncodingType
)
860 DWORD size
, flags
= OPEN_EXISTING
;
863 TRACE("%s, %x, %lx, %x, %x\n", debugstr_w(pwszFileName
), fdwOpenFlags
,
864 hProv
, dwPublicVersion
, dwEncodingType
);
868 SetLastError(ERROR_INVALID_PARAMETER
);
869 return INVALID_HANDLE_VALUE
;
872 if (!dwEncodingType
) dwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
874 if (fdwOpenFlags
& CRYPTCAT_OPEN_ALWAYS
) flags
|= OPEN_ALWAYS
;
875 if (fdwOpenFlags
& CRYPTCAT_OPEN_CREATENEW
) flags
|= CREATE_NEW
;
877 file
= CreateFileW(pwszFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, flags
, 0, NULL
);
878 if (file
== INVALID_HANDLE_VALUE
) return INVALID_HANDLE_VALUE
;
880 size
= GetFileSize(file
, NULL
);
881 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, size
)))
884 SetLastError(ERROR_OUTOFMEMORY
);
885 return INVALID_HANDLE_VALUE
;
887 if (!(hmsg
= CryptMsgOpenToDecode(dwEncodingType
, 0, 0, hProv
, NULL
, NULL
)))
890 HeapFree(GetProcessHeap(), 0, buffer
);
891 return INVALID_HANDLE_VALUE
;
893 if (!ReadFile(file
, buffer
, size
, &size
, NULL
) || !CryptMsgUpdate(hmsg
, buffer
, size
, TRUE
))
896 HeapFree(GetProcessHeap(), 0, buffer
);
898 return INVALID_HANDLE_VALUE
;
900 HeapFree(GetProcessHeap(), 0, buffer
);
903 size
= sizeof(DWORD
);
904 if (!(cc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cc
))))
907 SetLastError(ERROR_OUTOFMEMORY
);
908 return INVALID_HANDLE_VALUE
;
912 cc
->encoding
= dwEncodingType
;
913 if (CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_COUNT_PARAM
, 0, &cc
->attr_count
, &size
))
918 for (i
= 0; i
< cc
->attr_count
; i
++)
920 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, NULL
, &size
))
923 HeapFree(GetProcessHeap(), 0, cc
);
924 return INVALID_HANDLE_VALUE
;
928 if (!(cc
->attr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*cc
->attr
) * cc
->attr_count
+ sum
)))
931 HeapFree(GetProcessHeap(), 0, cc
);
932 SetLastError(ERROR_OUTOFMEMORY
);
933 return INVALID_HANDLE_VALUE
;
935 p
= (BYTE
*)(cc
->attr
+ cc
->attr_count
);
936 for (i
= 0; i
< cc
->attr_count
; i
++)
938 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, NULL
, &size
))
941 HeapFree(GetProcessHeap(), 0, cc
->attr
);
942 HeapFree(GetProcessHeap(), 0, cc
);
943 return INVALID_HANDLE_VALUE
;
945 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, p
, &size
))
948 HeapFree(GetProcessHeap(), 0, cc
->attr
);
949 HeapFree(GetProcessHeap(), 0, cc
);
950 return INVALID_HANDLE_VALUE
;
954 cc
->inner
= decode_inner_content(hmsg
, dwEncodingType
, &cc
->inner_len
);
955 if (!cc
->inner
|| !CryptSIPRetrieveSubjectGuid(pwszFileName
, NULL
, &cc
->subject
))
958 HeapFree(GetProcessHeap(), 0, cc
->attr
);
959 HeapFree(GetProcessHeap(), 0, cc
->inner
);
960 HeapFree(GetProcessHeap(), 0, cc
);
961 return INVALID_HANDLE_VALUE
;
963 cc
->magic
= CRYPTCAT_MAGIC
;
966 HeapFree(GetProcessHeap(), 0, cc
);
967 return INVALID_HANDLE_VALUE
;
970 /***********************************************************************
971 * CryptSIPCreateIndirectData (WINTRUST.@)
973 BOOL WINAPI
CryptSIPCreateIndirectData(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD
* pcbIndirectData
,
974 SIP_INDIRECT_DATA
* pIndirectData
)
976 FIXME("(%p %p %p) stub\n", pSubjectInfo
, pcbIndirectData
, pIndirectData
);
982 /***********************************************************************
983 * CryptCATCDFClose (WINTRUST.@)
985 BOOL WINAPI
CryptCATCDFClose(CRYPTCATCDF
*pCDF
)
987 FIXME("(%p) stub\n", pCDF
);
992 /***********************************************************************
993 * CryptCATCDFEnumCatAttributes (WINTRUST.@)
995 CRYPTCATATTRIBUTE
* WINAPI
CryptCATCDFEnumCatAttributes(CRYPTCATCDF
*pCDF
,
996 CRYPTCATATTRIBUTE
*pPrevAttr
,
997 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
)
999 FIXME("(%p %p %p) stub\n", pCDF
, pPrevAttr
, pfnParseError
);
1004 /***********************************************************************
1005 * CryptCATCDFEnumMembersByCDFTagEx (WINTRUST.@)
1007 LPWSTR WINAPI
CryptCATCDFEnumMembersByCDFTagEx(CRYPTCATCDF
*pCDF
, LPWSTR pwszPrevCDFTag
,
1008 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
,
1009 CRYPTCATMEMBER
**ppMember
, BOOL fContinueOnError
,
1012 FIXME("(%p %s %p %p %d %p) stub\n", pCDF
, debugstr_w(pwszPrevCDFTag
), pfnParseError
,
1013 ppMember
, fContinueOnError
, pvReserved
);
1018 /***********************************************************************
1019 * CryptCATCDFOpen (WINTRUST.@)
1021 CRYPTCATCDF
* WINAPI
CryptCATCDFOpen(LPWSTR pwszFilePath
,
1022 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
)
1024 FIXME("(%s %p) stub\n", debugstr_w(pwszFilePath
), pfnParseError
);
1029 static BOOL
WINTRUST_GetSignedMsgFromPEFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1030 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1031 BYTE
*pbSignedDataMsg
)
1034 WIN_CERTIFICATE
*pCert
= NULL
;
1037 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1038 pcbSignedDataMsg
, pbSignedDataMsg
);
1040 if(pSubjectInfo
->hFile
&& pSubjectInfo
->hFile
!=INVALID_HANDLE_VALUE
)
1041 file
= pSubjectInfo
->hFile
;
1044 file
= CreateFileW(pSubjectInfo
->pwsFileName
, GENERIC_READ
,
1045 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
1046 if(file
== INVALID_HANDLE_VALUE
)
1050 if (!pbSignedDataMsg
)
1052 WIN_CERTIFICATE cert
;
1054 /* app hasn't passed buffer, just get the length */
1055 ret
= ImageGetCertificateHeader(file
, dwIndex
, &cert
);
1058 switch (cert
.wCertificateType
)
1060 case WIN_CERT_TYPE_X509
:
1061 case WIN_CERT_TYPE_PKCS_SIGNED_DATA
:
1062 *pcbSignedDataMsg
= cert
.dwLength
;
1065 WARN("unknown certificate type %d\n", cert
.wCertificateType
);
1074 ret
= ImageGetCertificateData(file
, dwIndex
, NULL
, &len
);
1075 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1077 pCert
= HeapAlloc(GetProcessHeap(), 0, len
);
1083 ret
= ImageGetCertificateData(file
, dwIndex
, pCert
, &len
);
1086 pCert
->dwLength
-= FIELD_OFFSET(WIN_CERTIFICATE
, bCertificate
);
1087 if (*pcbSignedDataMsg
< pCert
->dwLength
)
1089 *pcbSignedDataMsg
= pCert
->dwLength
;
1090 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1095 memcpy(pbSignedDataMsg
, pCert
->bCertificate
, pCert
->dwLength
);
1096 *pcbSignedDataMsg
= pCert
->dwLength
;
1097 switch (pCert
->wCertificateType
)
1099 case WIN_CERT_TYPE_X509
:
1100 *pdwEncodingType
= X509_ASN_ENCODING
;
1102 case WIN_CERT_TYPE_PKCS_SIGNED_DATA
:
1103 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1106 WARN("don't know what to do for encoding type %d\n",
1107 pCert
->wCertificateType
);
1108 *pdwEncodingType
= 0;
1114 if(pSubjectInfo
->hFile
!= file
)
1116 HeapFree(GetProcessHeap(), 0, pCert
);
1120 static BOOL
WINTRUST_PutSignedMsgToPEFile(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD pdwEncodingType
,
1121 DWORD
* pdwIndex
, DWORD cbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1123 WIN_CERTIFICATE
*cert
;
1128 if(pSubjectInfo
->hFile
&& pSubjectInfo
->hFile
!=INVALID_HANDLE_VALUE
)
1129 file
= pSubjectInfo
->hFile
;
1132 file
= CreateFileW(pSubjectInfo
->pwsFileName
, GENERIC_READ
|GENERIC_WRITE
,
1133 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
1134 if(file
== INVALID_HANDLE_VALUE
)
1138 /* int aligned WIN_CERTIFICATE structure with cbSignedDataMsg+1 bytes of data */
1139 size
= FIELD_OFFSET(WIN_CERTIFICATE
, bCertificate
[cbSignedDataMsg
+4]) & (~3);
1140 cert
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1144 cert
->dwLength
= size
;
1145 cert
->wRevision
= WIN_CERT_REVISION_2_0
;
1146 cert
->wCertificateType
= WIN_CERT_TYPE_PKCS_SIGNED_DATA
;
1147 memcpy(cert
->bCertificate
, pbSignedDataMsg
, cbSignedDataMsg
);
1148 ret
= ImageAddCertificate(file
, cert
, pdwIndex
);
1150 HeapFree(GetProcessHeap(), 0, cert
);
1151 if(file
!= pSubjectInfo
->hFile
)
1156 /* structure offsets */
1157 #define cfhead_Signature (0x00)
1158 #define cfhead_CabinetSize (0x08)
1159 #define cfhead_MinorVersion (0x18)
1160 #define cfhead_MajorVersion (0x19)
1161 #define cfhead_Flags (0x1E)
1162 #define cfhead_SIZEOF (0x24)
1163 #define cfheadext_HeaderReserved (0x00)
1164 #define cfheadext_SIZEOF (0x04)
1165 #define cfsigninfo_CertOffset (0x04)
1166 #define cfsigninfo_CertSize (0x08)
1167 #define cfsigninfo_SIZEOF (0x0C)
1170 #define cfheadRESERVE_PRESENT (0x0004)
1172 /* endian-neutral reading of little-endian data */
1173 #define EndGetI32(a) ((((a)[3])<<24)|(((a)[2])<<16)|(((a)[1])<<8)|((a)[0]))
1174 #define EndGetI16(a) ((((a)[1])<<8)|((a)[0]))
1176 /* For documentation purposes only: this is the structure in the reserved
1177 * area of a signed cabinet file. The cert offset indicates where in the
1178 * cabinet file the signature resides, and the count indicates its size.
1180 typedef struct _CAB_SIGNINFO
1182 WORD unk0
; /* always 0? */
1183 WORD unk1
; /* always 0x0010? */
1186 } CAB_SIGNINFO
, *PCAB_SIGNINFO
;
1188 static BOOL
WINTRUST_GetSignedMsgFromCabFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1189 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1190 BYTE
*pbSignedDataMsg
)
1193 LONG base_offset
, cabsize
;
1196 DWORD cert_offset
, cert_size
, dwRead
;
1198 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1199 pcbSignedDataMsg
, pbSignedDataMsg
);
1201 /* get basic offset & size info */
1202 base_offset
= SetFilePointer(pSubjectInfo
->hFile
, 0L, NULL
, SEEK_CUR
);
1204 if (SetFilePointer(pSubjectInfo
->hFile
, 0, NULL
, SEEK_END
) == INVALID_SET_FILE_POINTER
)
1206 TRACE("seek error\n");
1210 cabsize
= SetFilePointer(pSubjectInfo
->hFile
, 0L, NULL
, SEEK_CUR
);
1211 if ((cabsize
== -1) || (base_offset
== -1) ||
1212 (SetFilePointer(pSubjectInfo
->hFile
, 0, NULL
, SEEK_SET
) == INVALID_SET_FILE_POINTER
))
1214 TRACE("seek error\n");
1218 /* read in the CFHEADER */
1219 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfhead_SIZEOF
, &dwRead
, NULL
) ||
1220 dwRead
!= cfhead_SIZEOF
)
1222 TRACE("reading header failed\n");
1226 /* check basic MSCF signature */
1227 if (EndGetI32(buf
+cfhead_Signature
) != 0x4643534d)
1229 WARN("cabinet signature not present\n");
1233 /* Ignore the number of folders and files and the set and cabinet IDs */
1235 /* check the header revision */
1236 if ((buf
[cfhead_MajorVersion
] > 1) ||
1237 (buf
[cfhead_MajorVersion
] == 1 && buf
[cfhead_MinorVersion
] > 3))
1239 WARN("cabinet format version > 1.3\n");
1243 /* pull the flags out */
1244 flags
= EndGetI16(buf
+cfhead_Flags
);
1246 if (!(flags
& cfheadRESERVE_PRESENT
))
1248 TRACE("no header present, not signed\n");
1252 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfheadext_SIZEOF
, &dwRead
, NULL
) ||
1253 dwRead
!= cfheadext_SIZEOF
)
1255 ERR("bunk reserve-sizes?\n");
1259 header_resv
= EndGetI16(buf
+cfheadext_HeaderReserved
);
1262 TRACE("no header_resv, not signed\n");
1265 else if (header_resv
< cfsigninfo_SIZEOF
)
1267 TRACE("header_resv too small, not signed\n");
1271 if (header_resv
> 60000)
1273 WARN("WARNING; header reserved space > 60000\n");
1276 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfsigninfo_SIZEOF
, &dwRead
, NULL
) ||
1277 dwRead
!= cfsigninfo_SIZEOF
)
1279 ERR("couldn't read reserve\n");
1283 cert_offset
= EndGetI32(buf
+cfsigninfo_CertOffset
);
1284 TRACE("cert_offset: %d\n", cert_offset
);
1285 cert_size
= EndGetI32(buf
+cfsigninfo_CertSize
);
1286 TRACE("cert_size: %d\n", cert_size
);
1288 /* The redundant checks are to avoid wraparound */
1289 if (cert_offset
> cabsize
|| cert_size
> cabsize
||
1290 cert_offset
+ cert_size
> cabsize
)
1292 WARN("offset beyond file, not attempting to read\n");
1296 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1297 if (!pbSignedDataMsg
)
1299 *pcbSignedDataMsg
= cert_size
;
1302 if (*pcbSignedDataMsg
< cert_size
)
1304 *pcbSignedDataMsg
= cert_size
;
1305 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1308 if (SetFilePointer(pSubjectInfo
->hFile
, cert_offset
, NULL
, SEEK_SET
) == INVALID_SET_FILE_POINTER
)
1310 ERR("couldn't seek to cert location\n");
1313 if (!ReadFile(pSubjectInfo
->hFile
, pbSignedDataMsg
, cert_size
, &dwRead
,
1314 NULL
) || dwRead
!= cert_size
)
1316 ERR("couldn't read cert\n");
1317 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1320 /* The encoding of the files I've seen appears to be in ASN.1
1321 * format, and there isn't a field indicating the type, so assume it
1324 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1325 /* Restore base offset */
1326 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1330 static BOOL
WINTRUST_GetSignedMsgFromCatFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1331 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1332 BYTE
*pbSignedDataMsg
)
1336 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1337 pcbSignedDataMsg
, pbSignedDataMsg
);
1339 if (!pbSignedDataMsg
)
1341 *pcbSignedDataMsg
= GetFileSize(pSubjectInfo
->hFile
, NULL
);
1346 DWORD len
= GetFileSize(pSubjectInfo
->hFile
, NULL
);
1348 if (*pcbSignedDataMsg
< len
)
1350 *pcbSignedDataMsg
= len
;
1351 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1356 ret
= ReadFile(pSubjectInfo
->hFile
, pbSignedDataMsg
, len
,
1357 pcbSignedDataMsg
, NULL
);
1359 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1365 /* GUIDs used by CryptSIPGetSignedDataMsg and CryptSIPPutSignedDataMsg */
1366 static const GUID unknown
= { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
1367 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1368 static const GUID cabGUID
= { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,
1369 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1370 static const GUID catGUID
= { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,
1371 0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1373 /***********************************************************************
1374 * CryptSIPGetSignedDataMsg (WINTRUST.@)
1376 BOOL WINAPI
CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD
* pdwEncodingType
,
1377 DWORD dwIndex
, DWORD
* pcbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1381 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1382 pcbSignedDataMsg
, pbSignedDataMsg
);
1386 SetLastError(ERROR_INVALID_PARAMETER
);
1390 if (!memcmp(pSubjectInfo
->pgSubjectType
, &unknown
, sizeof(unknown
)))
1391 ret
= WINTRUST_GetSignedMsgFromPEFile(pSubjectInfo
, pdwEncodingType
,
1392 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1393 else if (!memcmp(pSubjectInfo
->pgSubjectType
, &cabGUID
, sizeof(cabGUID
)))
1394 ret
= WINTRUST_GetSignedMsgFromCabFile(pSubjectInfo
, pdwEncodingType
,
1395 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1396 else if (!memcmp(pSubjectInfo
->pgSubjectType
, &catGUID
, sizeof(catGUID
)))
1397 ret
= WINTRUST_GetSignedMsgFromCatFile(pSubjectInfo
, pdwEncodingType
,
1398 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1401 FIXME("unimplemented for subject type %s\n",
1402 debugstr_guid(pSubjectInfo
->pgSubjectType
));
1406 TRACE("returning %d\n", ret
);
1410 /***********************************************************************
1411 * CryptSIPPutSignedDataMsg (WINTRUST.@)
1413 BOOL WINAPI
CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD pdwEncodingType
,
1414 DWORD
* pdwIndex
, DWORD cbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1416 TRACE("(%p %d %p %d %p)\n", pSubjectInfo
, pdwEncodingType
, pdwIndex
,
1417 cbSignedDataMsg
, pbSignedDataMsg
);
1420 SetLastError(ERROR_INVALID_PARAMETER
);
1424 if(!memcmp(pSubjectInfo
->pgSubjectType
, &unknown
, sizeof(unknown
)))
1425 return WINTRUST_PutSignedMsgToPEFile(pSubjectInfo
, pdwEncodingType
,
1426 pdwIndex
, cbSignedDataMsg
, pbSignedDataMsg
);
1428 FIXME("unimplemented for subject type %s\n",
1429 debugstr_guid(pSubjectInfo
->pgSubjectType
));
1434 /***********************************************************************
1435 * CryptSIPRemoveSignedDataMsg (WINTRUST.@)
1437 BOOL WINAPI
CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
,
1440 FIXME("(%p %d) stub\n", pSubjectInfo
, dwIndex
);
1445 /***********************************************************************
1446 * CryptSIPVerifyIndirectData (WINTRUST.@)
1448 BOOL WINAPI
CryptSIPVerifyIndirectData(SIP_SUBJECTINFO
* pSubjectInfo
,
1449 SIP_INDIRECT_DATA
* pIndirectData
)
1451 FIXME("(%p %p) stub\n", pSubjectInfo
, pIndirectData
);