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
36 #include "wine/debug.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 lstrcpyW(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 %lx\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 lstrcatW(catroot_dir
, catroot
);
130 /* create the directory if it doesn't exist */
131 CreateDirectoryW(catroot_dir
, NULL
);
133 if (!sys
) sys
= &defsys
;
134 swprintf(ca
->path
, ARRAY_SIZE(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 %lx 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 %ld\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
= lstrlenW(ca
->path
) + lstrlenW(selectBaseName
) + 2;
188 if (!(target
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
190 SetLastError(ERROR_OUTOFMEMORY
);
193 lstrcpyW(target
, ca
->path
);
194 lstrcatW(target
, slashW
);
195 lstrcatW(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 lstrcpyW(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 %lx\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 %ld %lx %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
= lstrlenW(ca
->path
) * sizeof(WCHAR
) + sizeof(globW
);
312 if (!(path
= HeapAlloc(GetProcessHeap(), 0, size
)))
314 CryptReleaseContext(prov
, 0);
315 SetLastError(ERROR_OUTOFMEMORY
);
318 lstrcpyW(path
, ca
->path
);
319 lstrcatW(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
= (lstrlenW(ca
->path
) + lstrlenW(data
.cFileName
) + 2) * sizeof(WCHAR
);
346 if (!(filename
= HeapAlloc(GetProcessHeap(), 0, size
)))
348 SetLastError(ERROR_OUTOFMEMORY
);
351 lstrcpyW(filename
, ca
->path
);
352 lstrcatW(filename
, slashW
);
353 lstrcatW(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 (%lu)\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: %lu/%lu\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 %lx\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 %lx\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 %lx\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 !wcschr(pwszCatalogFile
, '\\') && !wcschr(pwszCatalogFile
, '/') &&
491 !wcschr(pwszCatalogFile
, ':'))
493 static const WCHAR slashW
[] = {'\\',0};
497 len
= lstrlenW(ca
->path
) + lstrlenW(pwszCatalogFile
) + 2;
498 if (!(target
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
500 SetLastError(ERROR_OUTOFMEMORY
);
503 lstrcpyW(target
, ca
->path
);
504 lstrcatW(target
, slashW
);
505 lstrcatW(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 %lx\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 lstrcpyW(info
->wszCatalogFile
, ca
->path
);
532 lstrcatW(info
->wszCatalogFile
, slashW
);
533 lstrcatW(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 %lu\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, %lx\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 lstrcpyW(info
->wszCatalogFile
, ci
->file
);
852 /***********************************************************************
853 * CryptCATPutAttrInfo (WINTRUST.@)
855 CRYPTCATATTRIBUTE
* WINAPI
CryptCATPutAttrInfo(HANDLE catalog
, CRYPTCATMEMBER
*member
,
856 WCHAR
*name
, DWORD flags
, DWORD size
, BYTE
*data
)
858 FIXME("catalog %p, member %p, name %s, flags %#lx, size %lu, data %p, stub!\n",
859 catalog
, member
, debugstr_w(name
), flags
, size
, data
);
861 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
865 /***********************************************************************
866 * CryptCATPutCatAttrInfo (WINTRUST.@)
868 CRYPTCATATTRIBUTE
* WINAPI
CryptCATPutCatAttrInfo(HANDLE catalog
,
869 WCHAR
*name
, DWORD flags
, DWORD size
, BYTE
*data
)
871 FIXME("catalog %p, name %s, flags %#lx, size %lu, data %p, stub!\n",
872 catalog
, debugstr_w(name
), flags
, size
, data
);
874 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
878 /***********************************************************************
879 * CryptCATPutMemberInfo (WINTRUST.@)
881 CRYPTCATMEMBER
* WINAPI
CryptCATPutMemberInfo(HANDLE catalog
, WCHAR
*filename
,
882 WCHAR
*member
, GUID
*subject
, DWORD version
, DWORD size
, BYTE
*data
)
884 FIXME("catalog %p, filename %s, member %s, subject %s, version %lu, size %lu, data %p, stub!\n",
885 catalog
, debugstr_w(filename
), debugstr_w(member
), debugstr_guid(subject
), version
, size
, data
);
887 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
891 /***********************************************************************
892 * CryptCATPersistStore (WINTRUST.@)
894 BOOL WINAPI
CryptCATPersistStore(HANDLE catalog
)
896 FIXME("catalog %p, stub!\n", catalog
);
898 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
902 /***********************************************************************
903 * CryptCATOpen (WINTRUST.@)
905 HANDLE WINAPI
CryptCATOpen(WCHAR
*filename
, DWORD flags
, HCRYPTPROV hProv
,
906 DWORD dwPublicVersion
, DWORD dwEncodingType
)
910 DWORD size
, open_mode
= OPEN_ALWAYS
;
914 TRACE("filename %s, flags %#lx, provider %#Ix, version %#lx, type %#lx\n",
915 debugstr_w(filename
), flags
, hProv
, dwPublicVersion
, dwEncodingType
);
919 SetLastError(ERROR_INVALID_PARAMETER
);
920 return INVALID_HANDLE_VALUE
;
923 if (!dwEncodingType
) dwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
925 if (flags
== CRYPTCAT_OPEN_EXISTING
)
926 open_mode
= OPEN_EXISTING
;
927 if (flags
& CRYPTCAT_OPEN_CREATENEW
)
928 open_mode
= CREATE_ALWAYS
;
930 file
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, open_mode
, 0, NULL
);
931 if (file
== INVALID_HANDLE_VALUE
) return INVALID_HANDLE_VALUE
;
933 size
= GetFileSize(file
, NULL
);
934 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, size
)))
937 SetLastError(ERROR_OUTOFMEMORY
);
938 return INVALID_HANDLE_VALUE
;
940 if (!(hmsg
= CryptMsgOpenToDecode(dwEncodingType
, 0, 0, hProv
, NULL
, NULL
)))
943 HeapFree(GetProcessHeap(), 0, buffer
);
944 return INVALID_HANDLE_VALUE
;
946 if (!size
) valid
= FALSE
;
947 else if (!ReadFile(file
, buffer
, size
, &size
, NULL
))
950 HeapFree(GetProcessHeap(), 0, buffer
);
952 return INVALID_HANDLE_VALUE
;
954 else valid
= CryptMsgUpdate(hmsg
, buffer
, size
, TRUE
);
955 HeapFree(GetProcessHeap(), 0, buffer
);
958 size
= sizeof(DWORD
);
959 if (!(cc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cc
))))
962 SetLastError(ERROR_OUTOFMEMORY
);
963 return INVALID_HANDLE_VALUE
;
967 cc
->encoding
= dwEncodingType
;
970 cc
->magic
= CRYPTCAT_MAGIC
;
971 SetLastError(ERROR_SUCCESS
);
974 else if (CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_COUNT_PARAM
, 0, &cc
->attr_count
, &size
))
979 for (i
= 0; i
< cc
->attr_count
; i
++)
981 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, NULL
, &size
))
984 HeapFree(GetProcessHeap(), 0, cc
);
985 return INVALID_HANDLE_VALUE
;
989 if (!(cc
->attr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*cc
->attr
) * cc
->attr_count
+ sum
)))
992 HeapFree(GetProcessHeap(), 0, cc
);
993 SetLastError(ERROR_OUTOFMEMORY
);
994 return INVALID_HANDLE_VALUE
;
996 p
= (BYTE
*)(cc
->attr
+ cc
->attr_count
);
997 for (i
= 0; i
< cc
->attr_count
; i
++)
999 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, NULL
, &size
))
1001 CryptMsgClose(hmsg
);
1002 HeapFree(GetProcessHeap(), 0, cc
->attr
);
1003 HeapFree(GetProcessHeap(), 0, cc
);
1004 return INVALID_HANDLE_VALUE
;
1006 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, p
, &size
))
1008 CryptMsgClose(hmsg
);
1009 HeapFree(GetProcessHeap(), 0, cc
->attr
);
1010 HeapFree(GetProcessHeap(), 0, cc
);
1011 return INVALID_HANDLE_VALUE
;
1015 cc
->inner
= decode_inner_content(hmsg
, dwEncodingType
, &cc
->inner_len
);
1016 if (!cc
->inner
|| !CryptSIPRetrieveSubjectGuid(filename
, NULL
, &cc
->subject
))
1018 CryptMsgClose(hmsg
);
1019 HeapFree(GetProcessHeap(), 0, cc
->attr
);
1020 HeapFree(GetProcessHeap(), 0, cc
->inner
);
1021 HeapFree(GetProcessHeap(), 0, cc
);
1022 return INVALID_HANDLE_VALUE
;
1024 cc
->magic
= CRYPTCAT_MAGIC
;
1025 SetLastError(ERROR_SUCCESS
);
1028 HeapFree(GetProcessHeap(), 0, cc
);
1029 return INVALID_HANDLE_VALUE
;
1032 /***********************************************************************
1033 * CryptSIPCreateIndirectData (WINTRUST.@)
1035 BOOL WINAPI
CryptSIPCreateIndirectData(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD
* pcbIndirectData
,
1036 SIP_INDIRECT_DATA
* pIndirectData
)
1038 FIXME("(%p %p %p) stub\n", pSubjectInfo
, pcbIndirectData
, pIndirectData
);
1044 /***********************************************************************
1045 * CryptCATCDFClose (WINTRUST.@)
1047 BOOL WINAPI
CryptCATCDFClose(CRYPTCATCDF
*pCDF
)
1049 FIXME("(%p) stub\n", pCDF
);
1054 /***********************************************************************
1055 * CryptCATCDFEnumCatAttributes (WINTRUST.@)
1057 CRYPTCATATTRIBUTE
* WINAPI
CryptCATCDFEnumCatAttributes(CRYPTCATCDF
*pCDF
,
1058 CRYPTCATATTRIBUTE
*pPrevAttr
,
1059 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
)
1061 FIXME("(%p %p %p) stub\n", pCDF
, pPrevAttr
, pfnParseError
);
1066 /***********************************************************************
1067 * CryptCATCDFEnumMembersByCDFTagEx (WINTRUST.@)
1069 LPWSTR WINAPI
CryptCATCDFEnumMembersByCDFTagEx(CRYPTCATCDF
*pCDF
, LPWSTR pwszPrevCDFTag
,
1070 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
,
1071 CRYPTCATMEMBER
**ppMember
, BOOL fContinueOnError
,
1074 FIXME("(%p %s %p %p %d %p) stub\n", pCDF
, debugstr_w(pwszPrevCDFTag
), pfnParseError
,
1075 ppMember
, fContinueOnError
, pvReserved
);
1080 /***********************************************************************
1081 * CryptCATCDFOpen (WINTRUST.@)
1083 CRYPTCATCDF
* WINAPI
CryptCATCDFOpen(LPWSTR pwszFilePath
,
1084 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
)
1086 FIXME("(%s %p) stub\n", debugstr_w(pwszFilePath
), pfnParseError
);
1091 static BOOL
WINTRUST_GetSignedMsgFromPEFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1092 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1093 BYTE
*pbSignedDataMsg
)
1096 WIN_CERTIFICATE
*pCert
= NULL
;
1099 TRACE("(%p %p %ld %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1100 pcbSignedDataMsg
, pbSignedDataMsg
);
1102 if(pSubjectInfo
->hFile
&& pSubjectInfo
->hFile
!=INVALID_HANDLE_VALUE
)
1103 file
= pSubjectInfo
->hFile
;
1106 file
= CreateFileW(pSubjectInfo
->pwsFileName
, GENERIC_READ
,
1107 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
1108 if(file
== INVALID_HANDLE_VALUE
)
1112 if (!pbSignedDataMsg
)
1114 WIN_CERTIFICATE cert
;
1116 /* app hasn't passed buffer, just get the length */
1117 ret
= ImageGetCertificateHeader(file
, dwIndex
, &cert
);
1120 switch (cert
.wCertificateType
)
1122 case WIN_CERT_TYPE_X509
:
1123 case WIN_CERT_TYPE_PKCS_SIGNED_DATA
:
1124 *pcbSignedDataMsg
= cert
.dwLength
;
1127 WARN("unknown certificate type %d\n", cert
.wCertificateType
);
1136 ret
= ImageGetCertificateData(file
, dwIndex
, NULL
, &len
);
1137 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1139 pCert
= HeapAlloc(GetProcessHeap(), 0, len
);
1145 ret
= ImageGetCertificateData(file
, dwIndex
, pCert
, &len
);
1148 pCert
->dwLength
-= FIELD_OFFSET(WIN_CERTIFICATE
, bCertificate
);
1149 if (*pcbSignedDataMsg
< pCert
->dwLength
)
1151 *pcbSignedDataMsg
= pCert
->dwLength
;
1152 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1157 memcpy(pbSignedDataMsg
, pCert
->bCertificate
, pCert
->dwLength
);
1158 *pcbSignedDataMsg
= pCert
->dwLength
;
1159 switch (pCert
->wCertificateType
)
1161 case WIN_CERT_TYPE_X509
:
1162 *pdwEncodingType
= X509_ASN_ENCODING
;
1164 case WIN_CERT_TYPE_PKCS_SIGNED_DATA
:
1165 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1168 WARN("don't know what to do for encoding type %d\n",
1169 pCert
->wCertificateType
);
1170 *pdwEncodingType
= 0;
1176 if(pSubjectInfo
->hFile
!= file
)
1178 HeapFree(GetProcessHeap(), 0, pCert
);
1182 static BOOL
WINTRUST_PutSignedMsgToPEFile(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD pdwEncodingType
,
1183 DWORD
* pdwIndex
, DWORD cbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1185 WIN_CERTIFICATE
*cert
;
1190 if(pSubjectInfo
->hFile
&& pSubjectInfo
->hFile
!=INVALID_HANDLE_VALUE
)
1191 file
= pSubjectInfo
->hFile
;
1194 file
= CreateFileW(pSubjectInfo
->pwsFileName
, GENERIC_READ
|GENERIC_WRITE
,
1195 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
1196 if(file
== INVALID_HANDLE_VALUE
)
1200 /* int aligned WIN_CERTIFICATE structure with cbSignedDataMsg+1 bytes of data */
1201 size
= FIELD_OFFSET(WIN_CERTIFICATE
, bCertificate
[cbSignedDataMsg
+4]) & (~3);
1202 cert
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1206 cert
->dwLength
= size
;
1207 cert
->wRevision
= WIN_CERT_REVISION_2_0
;
1208 cert
->wCertificateType
= WIN_CERT_TYPE_PKCS_SIGNED_DATA
;
1209 memcpy(cert
->bCertificate
, pbSignedDataMsg
, cbSignedDataMsg
);
1210 ret
= ImageAddCertificate(file
, cert
, pdwIndex
);
1212 HeapFree(GetProcessHeap(), 0, cert
);
1213 if(file
!= pSubjectInfo
->hFile
)
1218 /* structure offsets */
1219 #define cfhead_Signature (0x00)
1220 #define cfhead_CabinetSize (0x08)
1221 #define cfhead_MinorVersion (0x18)
1222 #define cfhead_MajorVersion (0x19)
1223 #define cfhead_Flags (0x1E)
1224 #define cfhead_SIZEOF (0x24)
1225 #define cfheadext_HeaderReserved (0x00)
1226 #define cfheadext_SIZEOF (0x04)
1227 #define cfsigninfo_CertOffset (0x04)
1228 #define cfsigninfo_CertSize (0x08)
1229 #define cfsigninfo_SIZEOF (0x0C)
1232 #define cfheadRESERVE_PRESENT (0x0004)
1234 /* endian-neutral reading of little-endian data */
1235 #define EndGetI32(a) ((((a)[3])<<24)|(((a)[2])<<16)|(((a)[1])<<8)|((a)[0]))
1236 #define EndGetI16(a) ((((a)[1])<<8)|((a)[0]))
1238 /* For documentation purposes only: this is the structure in the reserved
1239 * area of a signed cabinet file. The cert offset indicates where in the
1240 * cabinet file the signature resides, and the count indicates its size.
1242 typedef struct _CAB_SIGNINFO
1244 WORD unk0
; /* always 0? */
1245 WORD unk1
; /* always 0x0010? */
1248 } CAB_SIGNINFO
, *PCAB_SIGNINFO
;
1250 static BOOL
WINTRUST_GetSignedMsgFromCabFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1251 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1252 BYTE
*pbSignedDataMsg
)
1255 LONG base_offset
, cabsize
;
1258 DWORD cert_offset
, cert_size
, dwRead
;
1260 TRACE("(%p %p %ld %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1261 pcbSignedDataMsg
, pbSignedDataMsg
);
1263 /* get basic offset & size info */
1264 base_offset
= SetFilePointer(pSubjectInfo
->hFile
, 0L, NULL
, SEEK_CUR
);
1266 if (SetFilePointer(pSubjectInfo
->hFile
, 0, NULL
, SEEK_END
) == INVALID_SET_FILE_POINTER
)
1268 TRACE("seek error\n");
1272 cabsize
= SetFilePointer(pSubjectInfo
->hFile
, 0L, NULL
, SEEK_CUR
);
1273 if ((cabsize
== -1) || (base_offset
== -1) ||
1274 (SetFilePointer(pSubjectInfo
->hFile
, 0, NULL
, SEEK_SET
) == INVALID_SET_FILE_POINTER
))
1276 TRACE("seek error\n");
1280 /* read in the CFHEADER */
1281 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfhead_SIZEOF
, &dwRead
, NULL
) ||
1282 dwRead
!= cfhead_SIZEOF
)
1284 TRACE("reading header failed\n");
1288 /* check basic MSCF signature */
1289 if (EndGetI32(buf
+cfhead_Signature
) != 0x4643534d)
1291 WARN("cabinet signature not present\n");
1295 /* Ignore the number of folders and files and the set and cabinet IDs */
1297 /* check the header revision */
1298 if ((buf
[cfhead_MajorVersion
] > 1) ||
1299 (buf
[cfhead_MajorVersion
] == 1 && buf
[cfhead_MinorVersion
] > 3))
1301 WARN("cabinet format version > 1.3\n");
1305 /* pull the flags out */
1306 flags
= EndGetI16(buf
+cfhead_Flags
);
1308 if (!(flags
& cfheadRESERVE_PRESENT
))
1310 TRACE("no header present, not signed\n");
1314 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfheadext_SIZEOF
, &dwRead
, NULL
) ||
1315 dwRead
!= cfheadext_SIZEOF
)
1317 ERR("bunk reserve-sizes?\n");
1321 header_resv
= EndGetI16(buf
+cfheadext_HeaderReserved
);
1324 TRACE("no header_resv, not signed\n");
1327 else if (header_resv
< cfsigninfo_SIZEOF
)
1329 TRACE("header_resv too small, not signed\n");
1333 if (header_resv
> 60000)
1335 WARN("WARNING; header reserved space > 60000\n");
1338 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfsigninfo_SIZEOF
, &dwRead
, NULL
) ||
1339 dwRead
!= cfsigninfo_SIZEOF
)
1341 ERR("couldn't read reserve\n");
1345 cert_offset
= EndGetI32(buf
+cfsigninfo_CertOffset
);
1346 TRACE("cert_offset: %ld\n", cert_offset
);
1347 cert_size
= EndGetI32(buf
+cfsigninfo_CertSize
);
1348 TRACE("cert_size: %ld\n", cert_size
);
1350 /* The redundant checks are to avoid wraparound */
1351 if (cert_offset
> cabsize
|| cert_size
> cabsize
||
1352 cert_offset
+ cert_size
> cabsize
)
1354 WARN("offset beyond file, not attempting to read\n");
1358 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1359 if (!pbSignedDataMsg
)
1361 *pcbSignedDataMsg
= cert_size
;
1364 if (*pcbSignedDataMsg
< cert_size
)
1366 *pcbSignedDataMsg
= cert_size
;
1367 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1370 if (SetFilePointer(pSubjectInfo
->hFile
, cert_offset
, NULL
, SEEK_SET
) == INVALID_SET_FILE_POINTER
)
1372 ERR("couldn't seek to cert location\n");
1375 if (!ReadFile(pSubjectInfo
->hFile
, pbSignedDataMsg
, cert_size
, &dwRead
,
1376 NULL
) || dwRead
!= cert_size
)
1378 ERR("couldn't read cert\n");
1379 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1382 /* The encoding of the files I've seen appears to be in ASN.1
1383 * format, and there isn't a field indicating the type, so assume it
1386 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1387 /* Restore base offset */
1388 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1392 static BOOL
WINTRUST_GetSignedMsgFromCatFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1393 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1394 BYTE
*pbSignedDataMsg
)
1398 TRACE("(%p %p %ld %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1399 pcbSignedDataMsg
, pbSignedDataMsg
);
1401 if (!pbSignedDataMsg
)
1403 *pcbSignedDataMsg
= GetFileSize(pSubjectInfo
->hFile
, NULL
);
1408 DWORD len
= GetFileSize(pSubjectInfo
->hFile
, NULL
);
1410 if (*pcbSignedDataMsg
< len
)
1412 *pcbSignedDataMsg
= len
;
1413 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1418 ret
= ReadFile(pSubjectInfo
->hFile
, pbSignedDataMsg
, len
,
1419 pcbSignedDataMsg
, NULL
);
1421 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1427 /* GUIDs used by CryptSIPGetSignedDataMsg and CryptSIPPutSignedDataMsg */
1428 static const GUID unknown
= { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
1429 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1430 static const GUID cabGUID
= { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,
1431 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1432 static const GUID catGUID
= { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,
1433 0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1435 /***********************************************************************
1436 * CryptSIPGetSignedDataMsg (WINTRUST.@)
1438 BOOL WINAPI
CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD
* pdwEncodingType
,
1439 DWORD dwIndex
, DWORD
* pcbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1443 TRACE("(%p %p %ld %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1444 pcbSignedDataMsg
, pbSignedDataMsg
);
1448 SetLastError(ERROR_INVALID_PARAMETER
);
1452 if (!memcmp(pSubjectInfo
->pgSubjectType
, &unknown
, sizeof(unknown
)))
1453 ret
= WINTRUST_GetSignedMsgFromPEFile(pSubjectInfo
, pdwEncodingType
,
1454 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1455 else if (!memcmp(pSubjectInfo
->pgSubjectType
, &cabGUID
, sizeof(cabGUID
)))
1456 ret
= WINTRUST_GetSignedMsgFromCabFile(pSubjectInfo
, pdwEncodingType
,
1457 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1458 else if (!memcmp(pSubjectInfo
->pgSubjectType
, &catGUID
, sizeof(catGUID
)))
1459 ret
= WINTRUST_GetSignedMsgFromCatFile(pSubjectInfo
, pdwEncodingType
,
1460 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1463 FIXME("unimplemented for subject type %s\n",
1464 debugstr_guid(pSubjectInfo
->pgSubjectType
));
1468 TRACE("returning %d\n", ret
);
1472 /***********************************************************************
1473 * CryptSIPPutSignedDataMsg (WINTRUST.@)
1475 BOOL WINAPI
CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD pdwEncodingType
,
1476 DWORD
* pdwIndex
, DWORD cbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1478 TRACE("(%p %ld %p %ld %p)\n", pSubjectInfo
, pdwEncodingType
, pdwIndex
,
1479 cbSignedDataMsg
, pbSignedDataMsg
);
1482 SetLastError(ERROR_INVALID_PARAMETER
);
1486 if(!memcmp(pSubjectInfo
->pgSubjectType
, &unknown
, sizeof(unknown
)))
1487 return WINTRUST_PutSignedMsgToPEFile(pSubjectInfo
, pdwEncodingType
,
1488 pdwIndex
, cbSignedDataMsg
, pbSignedDataMsg
);
1490 FIXME("unimplemented for subject type %s\n",
1491 debugstr_guid(pSubjectInfo
->pgSubjectType
));
1496 /***********************************************************************
1497 * CryptSIPRemoveSignedDataMsg (WINTRUST.@)
1499 BOOL WINAPI
CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
,
1502 FIXME("(%p %ld) stub\n", pSubjectInfo
, dwIndex
);
1507 /***********************************************************************
1508 * CryptSIPVerifyIndirectData (WINTRUST.@)
1510 BOOL WINAPI
CryptSIPVerifyIndirectData(SIP_SUBJECTINFO
* pSubjectInfo
,
1511 SIP_INDIRECT_DATA
* pIndirectData
)
1513 FIXME("(%p %p) stub\n", pSubjectInfo
, pIndirectData
);