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"
37 WINE_DEFAULT_DEBUG_CHANNEL(wintrust
);
39 #define CATADMIN_MAGIC 0x43415441 /* 'CATA' */
40 #define CRYPTCAT_MAGIC 0x43415443 /* 'CATC' */
41 #define CATINFO_MAGIC 0x43415449 /* 'CATI' */
52 CRYPTCATATTRIBUTE
*attr
;
68 static HCATINFO
create_catinfo(const WCHAR
*filename
)
72 if (!(ci
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ci
))))
74 SetLastError(ERROR_OUTOFMEMORY
);
75 return INVALID_HANDLE_VALUE
;
77 lstrcpyW(ci
->file
, filename
);
78 ci
->magic
= CATINFO_MAGIC
;
82 /***********************************************************************
83 * CryptCATAdminAcquireContext (WINTRUST.@)
85 * Get a catalog administrator context handle.
88 * catAdmin [O] Pointer to the context handle.
89 * sys [I] Pointer to a GUID for the needed subsystem.
90 * dwFlags [I] Reserved.
93 * Success: TRUE. catAdmin contains the context handle.
97 BOOL WINAPI
CryptCATAdminAcquireContext(HCATADMIN
*catAdmin
,
98 const GUID
*sys
, DWORD dwFlags
)
100 static const WCHAR catroot
[] =
101 {'\\','c','a','t','r','o','o','t',0};
102 static const WCHAR fmt
[] =
103 {'%','s','\\','{','%','0','8','x','-','%','0','4','x','-','%','0',
104 '4','x','-','%','0','2','x','%','0','2','x','-','%','0','2','x',
105 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
106 '%','0','2','x','}',0};
107 static const GUID defsys
=
108 {0x127d0a1d,0x4ef2,0x11d1,{0x86,0x08,0x00,0xc0,0x4f,0xc2,0x95,0xee}};
110 WCHAR catroot_dir
[MAX_PATH
];
113 TRACE("%p %s %x\n", catAdmin
, debugstr_guid(sys
), dwFlags
);
115 if (!catAdmin
|| dwFlags
)
117 SetLastError(ERROR_INVALID_PARAMETER
);
120 if (!(ca
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ca
))))
122 SetLastError(ERROR_OUTOFMEMORY
);
126 GetSystemDirectoryW(catroot_dir
, MAX_PATH
);
127 lstrcatW(catroot_dir
, catroot
);
129 /* create the directory if it doesn't exist */
130 CreateDirectoryW(catroot_dir
, NULL
);
132 if (!sys
) sys
= &defsys
;
133 swprintf(ca
->path
, ARRAY_SIZE(ca
->path
), fmt
, catroot_dir
, sys
->Data1
, sys
->Data2
,
134 sys
->Data3
, sys
->Data4
[0], sys
->Data4
[1], sys
->Data4
[2],
135 sys
->Data4
[3], sys
->Data4
[4], sys
->Data4
[5], sys
->Data4
[6],
138 /* create the directory if it doesn't exist */
139 CreateDirectoryW(ca
->path
, NULL
);
141 ca
->magic
= CATADMIN_MAGIC
;
142 ca
->find
= INVALID_HANDLE_VALUE
;
148 /***********************************************************************
149 * CryptCATAdminAcquireContext2 (WINTRUST.@)
151 BOOL WINAPI
CryptCATAdminAcquireContext2(HCATADMIN
*catAdmin
, const GUID
*sys
, const WCHAR
*algorithm
,
152 const CERT_STRONG_SIGN_PARA
*policy
, DWORD flags
)
154 FIXME("%p %s %s %p %x stub\n", catAdmin
, debugstr_guid(sys
), debugstr_w(algorithm
), policy
, flags
);
155 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
159 /***********************************************************************
160 * CryptCATAdminAddCatalog (WINTRUST.@)
162 HCATINFO WINAPI
CryptCATAdminAddCatalog(HCATADMIN catAdmin
, PWSTR catalogFile
,
163 PWSTR selectBaseName
, DWORD flags
)
165 static const WCHAR slashW
[] = {'\\',0};
166 struct catadmin
*ca
= catAdmin
;
171 TRACE("%p %s %s %d\n", catAdmin
, debugstr_w(catalogFile
),
172 debugstr_w(selectBaseName
), flags
);
176 FIXME("NULL basename not handled\n");
177 SetLastError(ERROR_INVALID_PARAMETER
);
180 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !catalogFile
|| flags
)
182 SetLastError(ERROR_INVALID_PARAMETER
);
186 len
= lstrlenW(ca
->path
) + lstrlenW(selectBaseName
) + 2;
187 if (!(target
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
189 SetLastError(ERROR_OUTOFMEMORY
);
192 lstrcpyW(target
, ca
->path
);
193 lstrcatW(target
, slashW
);
194 lstrcatW(target
, selectBaseName
);
196 if (!CopyFileW(catalogFile
, target
, FALSE
))
198 HeapFree(GetProcessHeap(), 0, target
);
201 SetFileAttributesW(target
, FILE_ATTRIBUTE_SYSTEM
);
203 if (!(ci
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ci
))))
205 HeapFree(GetProcessHeap(), 0, target
);
206 SetLastError(ERROR_OUTOFMEMORY
);
209 ci
->magic
= CATINFO_MAGIC
;
210 lstrcpyW(ci
->file
, target
);
212 HeapFree(GetProcessHeap(), 0, target
);
216 /***********************************************************************
217 * CryptCATAdminCalcHashFromFileHandle (WINTRUST.@)
219 BOOL WINAPI
CryptCATAdminCalcHashFromFileHandle(HANDLE hFile
, DWORD
* pcbHash
,
220 BYTE
* pbHash
, DWORD dwFlags
)
224 TRACE("%p %p %p %x\n", hFile
, pcbHash
, pbHash
, dwFlags
);
226 if (!hFile
|| !pcbHash
|| dwFlags
)
228 SetLastError(ERROR_INVALID_PARAMETER
);
234 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
246 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, 4096)))
248 SetLastError(ERROR_OUTOFMEMORY
);
251 ret
= CryptAcquireContextW(&prov
, NULL
, MS_DEF_PROV_W
, PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
254 HeapFree(GetProcessHeap(), 0, buffer
);
257 ret
= CryptCreateHash(prov
, CALG_SHA1
, 0, 0, &hash
);
260 HeapFree(GetProcessHeap(), 0, buffer
);
261 CryptReleaseContext(prov
, 0);
264 while ((ret
= ReadFile(hFile
, buffer
, 4096, &bytes_read
, NULL
)) && bytes_read
)
266 CryptHashData(hash
, buffer
, bytes_read
, 0);
268 if (ret
) ret
= CryptGetHashParam(hash
, HP_HASHVAL
, pbHash
, pcbHash
, 0);
270 HeapFree(GetProcessHeap(), 0, buffer
);
271 CryptDestroyHash(hash
);
272 CryptReleaseContext(prov
, 0);
277 /***********************************************************************
278 * CryptCATAdminEnumCatalogFromHash (WINTRUST.@)
280 HCATINFO WINAPI
CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin
, BYTE
* pbHash
,
281 DWORD cbHash
, DWORD dwFlags
,
282 HCATINFO
* phPrevCatInfo
)
284 static const WCHAR slashW
[] = {'\\',0};
285 static const WCHAR globW
[] = {'\\','*','.','c','a','t',0};
287 struct catadmin
*ca
= hCatAdmin
;
288 WIN32_FIND_DATAW data
;
289 HCATINFO prev
= NULL
;
294 TRACE("%p %p %d %x %p\n", hCatAdmin
, pbHash
, cbHash
, dwFlags
, phPrevCatInfo
);
296 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !pbHash
|| cbHash
!= 20 || dwFlags
)
298 SetLastError(ERROR_INVALID_PARAMETER
);
301 if (phPrevCatInfo
) prev
= *phPrevCatInfo
;
303 ret
= CryptAcquireContextW(&prov
, NULL
, MS_DEF_PROV_W
, PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
304 if (!ret
) return NULL
;
310 size
= lstrlenW(ca
->path
) * sizeof(WCHAR
) + sizeof(globW
);
311 if (!(path
= HeapAlloc(GetProcessHeap(), 0, size
)))
313 CryptReleaseContext(prov
, 0);
314 SetLastError(ERROR_OUTOFMEMORY
);
317 lstrcpyW(path
, ca
->path
);
318 lstrcatW(path
, globW
);
321 ca
->find
= FindFirstFileW(path
, &data
);
323 HeapFree(GetProcessHeap(), 0, path
);
324 if (ca
->find
== INVALID_HANDLE_VALUE
)
326 CryptReleaseContext(prov
, 0);
330 else if (!FindNextFileW(ca
->find
, &data
))
332 CryptCATAdminReleaseCatalogContext(hCatAdmin
, prev
, 0);
333 CryptReleaseContext(prov
, 0);
340 CRYPTCATMEMBER
*member
= NULL
;
344 size
= (lstrlenW(ca
->path
) + lstrlenW(data
.cFileName
) + 2) * sizeof(WCHAR
);
345 if (!(filename
= HeapAlloc(GetProcessHeap(), 0, size
)))
347 SetLastError(ERROR_OUTOFMEMORY
);
350 lstrcpyW(filename
, ca
->path
);
351 lstrcatW(filename
, slashW
);
352 lstrcatW(filename
, data
.cFileName
);
354 hcat
= CryptCATOpen(filename
, CRYPTCAT_OPEN_EXISTING
, prov
, 0, 0);
355 if (hcat
== INVALID_HANDLE_VALUE
)
357 WARN("couldn't open %s (%u)\n", debugstr_w(filename
), GetLastError());
360 while ((member
= CryptCATEnumerateMember(hcat
, member
)))
362 if (member
->pIndirectData
->Digest
.cbData
!= cbHash
)
364 WARN("amount of hash bytes differs: %u/%u\n", member
->pIndirectData
->Digest
.cbData
, cbHash
);
367 if (!memcmp(member
->pIndirectData
->Digest
.pbData
, pbHash
, cbHash
))
369 TRACE("file %s matches\n", debugstr_w(data
.cFileName
));
372 CryptReleaseContext(prov
, 0);
376 ca
->find
= INVALID_HANDLE_VALUE
;
378 ci
= create_catinfo(filename
);
379 HeapFree(GetProcessHeap(), 0, filename
);
384 HeapFree(GetProcessHeap(), 0, filename
);
386 if (!FindNextFileW(ca
->find
, &data
))
389 ca
->find
= INVALID_HANDLE_VALUE
;
390 CryptReleaseContext(prov
, 0);
397 /***********************************************************************
398 * CryptCATAdminReleaseCatalogContext (WINTRUST.@)
400 * Release a catalog context handle.
403 * hCatAdmin [I] Context handle.
404 * hCatInfo [I] Catalog handle.
405 * dwFlags [I] Reserved.
412 BOOL WINAPI
CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin
,
416 struct catinfo
*ci
= hCatInfo
;
417 struct catadmin
*ca
= hCatAdmin
;
419 TRACE("%p %p %x\n", hCatAdmin
, hCatInfo
, dwFlags
);
421 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !ci
|| ci
->magic
!= CATINFO_MAGIC
)
423 SetLastError(ERROR_INVALID_PARAMETER
);
427 return HeapFree(GetProcessHeap(), 0, ci
);
430 /***********************************************************************
431 * CryptCATAdminReleaseContext (WINTRUST.@)
433 * Release a catalog administrator context handle.
436 * catAdmin [I] Context handle.
437 * dwFlags [I] Reserved.
444 BOOL WINAPI
CryptCATAdminReleaseContext(HCATADMIN hCatAdmin
, DWORD dwFlags
)
446 struct catadmin
*ca
= hCatAdmin
;
448 TRACE("%p %x\n", hCatAdmin
, dwFlags
);
450 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
)
452 SetLastError(ERROR_INVALID_PARAMETER
);
455 if (ca
->find
!= INVALID_HANDLE_VALUE
) FindClose(ca
->find
);
457 return HeapFree(GetProcessHeap(), 0, ca
);
460 /***********************************************************************
461 * CryptCATAdminRemoveCatalog (WINTRUST.@)
463 * Remove a catalog file.
466 * catAdmin [I] Context handle.
467 * pwszCatalogFile [I] Catalog file.
468 * dwFlags [I] Reserved.
475 BOOL WINAPI
CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin
, LPCWSTR pwszCatalogFile
, DWORD dwFlags
)
477 struct catadmin
*ca
= hCatAdmin
;
479 TRACE("%p %s %x\n", hCatAdmin
, debugstr_w(pwszCatalogFile
), dwFlags
);
481 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
)
483 SetLastError(ERROR_INVALID_PARAMETER
);
487 /* Only delete when there is a filename and no path */
488 if (pwszCatalogFile
&& pwszCatalogFile
[0] != 0 &&
489 !wcschr(pwszCatalogFile
, '\\') && !wcschr(pwszCatalogFile
, '/') &&
490 !wcschr(pwszCatalogFile
, ':'))
492 static const WCHAR slashW
[] = {'\\',0};
496 len
= lstrlenW(ca
->path
) + lstrlenW(pwszCatalogFile
) + 2;
497 if (!(target
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
499 SetLastError(ERROR_OUTOFMEMORY
);
502 lstrcpyW(target
, ca
->path
);
503 lstrcatW(target
, slashW
);
504 lstrcatW(target
, pwszCatalogFile
);
508 HeapFree(GetProcessHeap(), 0, target
);
514 /***********************************************************************
515 * CryptCATAdminResolveCatalogPath (WINTRUST.@)
517 BOOL WINAPI
CryptCATAdminResolveCatalogPath(HCATADMIN hcatadmin
, WCHAR
*catalog_file
,
518 CATALOG_INFO
*info
, DWORD flags
)
520 static const WCHAR slashW
[] = {'\\',0};
521 struct catadmin
*ca
= hcatadmin
;
523 TRACE("%p %s %p %x\n", hcatadmin
, debugstr_w(catalog_file
), info
, flags
);
525 if (!ca
|| ca
->magic
!= CATADMIN_MAGIC
|| !info
|| info
->cbStruct
!= sizeof(*info
) || flags
)
527 SetLastError(ERROR_INVALID_PARAMETER
);
530 lstrcpyW(info
->wszCatalogFile
, ca
->path
);
531 lstrcatW(info
->wszCatalogFile
, slashW
);
532 lstrcatW(info
->wszCatalogFile
, catalog_file
);
537 /***********************************************************************
538 * CryptCATClose (WINTRUST.@)
540 BOOL WINAPI
CryptCATClose(HANDLE hCatalog
)
542 struct cryptcat
*cc
= hCatalog
;
544 TRACE("(%p)\n", hCatalog
);
546 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
548 SetLastError(ERROR_INVALID_PARAMETER
);
551 HeapFree(GetProcessHeap(), 0, cc
->attr
);
552 HeapFree(GetProcessHeap(), 0, cc
->inner
);
553 CryptMsgClose(cc
->msg
);
556 HeapFree(GetProcessHeap(), 0, cc
);
560 /***********************************************************************
561 * CryptCATGetAttrInfo (WINTRUST.@)
563 CRYPTCATATTRIBUTE
* WINAPI
CryptCATGetAttrInfo(HANDLE hCatalog
, CRYPTCATMEMBER
*member
, LPWSTR tag
)
565 struct cryptcat
*cc
= hCatalog
;
567 FIXME("%p, %p, %s\n", hCatalog
, member
, debugstr_w(tag
));
569 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
571 SetLastError(ERROR_INVALID_PARAMETER
);
574 SetLastError(CRYPT_E_NOT_FOUND
);
578 /***********************************************************************
579 * CryptCATGetCatAttrInfo (WINTRUST.@)
581 CRYPTCATATTRIBUTE
* WINAPI
CryptCATGetCatAttrInfo(HANDLE hCatalog
, LPWSTR tag
)
583 struct cryptcat
*cc
= hCatalog
;
585 FIXME("%p, %s\n", hCatalog
, debugstr_w(tag
));
587 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
589 SetLastError(ERROR_INVALID_PARAMETER
);
592 SetLastError(CRYPT_E_NOT_FOUND
);
596 CRYPTCATMEMBER
* WINAPI
CryptCATGetMemberInfo(HANDLE hCatalog
, LPWSTR tag
)
598 struct cryptcat
*cc
= hCatalog
;
600 FIXME("%p, %s\n", hCatalog
, debugstr_w(tag
));
602 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
604 SetLastError(ERROR_INVALID_PARAMETER
);
607 SetLastError(CRYPT_E_NOT_FOUND
);
611 /***********************************************************************
612 * CryptCATEnumerateAttr (WINTRUST.@)
614 CRYPTCATATTRIBUTE
* WINAPI
CryptCATEnumerateAttr(HANDLE hCatalog
, CRYPTCATMEMBER
*member
, CRYPTCATATTRIBUTE
*prev
)
616 struct cryptcat
*cc
= hCatalog
;
618 FIXME("%p, %p, %p\n", hCatalog
, member
, prev
);
620 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
622 SetLastError(ERROR_INVALID_PARAMETER
);
625 SetLastError(CRYPT_E_NOT_FOUND
);
629 /***********************************************************************
630 * CryptCATEnumerateCatAttr (WINTRUST.@)
632 CRYPTCATATTRIBUTE
* WINAPI
CryptCATEnumerateCatAttr(HANDLE hCatalog
, CRYPTCATATTRIBUTE
*prev
)
634 struct cryptcat
*cc
= hCatalog
;
636 FIXME("%p, %p\n", hCatalog
, prev
);
638 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
640 SetLastError(ERROR_INVALID_PARAMETER
);
643 SetLastError(CRYPT_E_NOT_FOUND
);
647 /***********************************************************************
648 * CryptCATEnumerateMember (WINTRUST.@)
650 CRYPTCATMEMBER
* WINAPI
CryptCATEnumerateMember(HANDLE hCatalog
, CRYPTCATMEMBER
*prev
)
652 struct cryptcat
*cc
= hCatalog
;
653 CRYPTCATMEMBER
*member
= prev
;
657 TRACE("%p, %p\n", hCatalog
, prev
);
659 if (!hCatalog
|| hCatalog
== INVALID_HANDLE_VALUE
|| cc
->magic
!= CRYPTCAT_MAGIC
)
661 SetLastError(ERROR_INVALID_PARAMETER
);
665 /* dumping the contents makes me think that dwReserved is the iteration number */
668 if (!(member
= HeapAlloc(GetProcessHeap(), 0, sizeof(*member
))))
670 SetLastError(ERROR_OUTOFMEMORY
);
673 member
->cbStruct
= sizeof(*member
);
674 member
->pwszFileName
= member
->pwszReferenceTag
= NULL
;
675 member
->dwReserved
= 0;
676 member
->hReserved
= NULL
;
677 member
->gSubjectType
= cc
->subject
;
678 member
->fdwMemberFlags
= 0;
679 member
->pIndirectData
= NULL
;
680 member
->dwCertVersion
= cc
->inner
->dwVersion
;
682 else member
->dwReserved
++;
684 if (member
->dwReserved
>= cc
->inner
->cCTLEntry
)
686 SetLastError(ERROR_INVALID_PARAMETER
);
690 /* list them backwards, like native */
691 entry
= &cc
->inner
->rgCTLEntry
[cc
->inner
->cCTLEntry
- member
->dwReserved
- 1];
693 member
->sEncodedIndirectData
.cbData
= member
->sEncodedMemberInfo
.cbData
= 0;
694 member
->sEncodedIndirectData
.pbData
= member
->sEncodedMemberInfo
.pbData
= NULL
;
695 HeapFree(GetProcessHeap(), 0, member
->pIndirectData
);
696 member
->pIndirectData
= NULL
;
698 for (i
= 0; i
< entry
->cAttribute
; i
++)
700 CRYPT_ATTRIBUTE
*attr
= entry
->rgAttribute
+ i
;
702 if (attr
->cValue
!= 1)
704 ERR("Can't handle attr->cValue of %u\n", attr
->cValue
);
707 if (!strcmp(attr
->pszObjId
, CAT_MEMBERINFO_OBJID
))
712 member
->sEncodedMemberInfo
.cbData
= attr
->rgValue
->cbData
;
713 member
->sEncodedMemberInfo
.pbData
= attr
->rgValue
->pbData
;
715 CryptDecodeObject(cc
->encoding
, CAT_MEMBERINFO_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, NULL
, &size
);
717 if (!(mi
= HeapAlloc(GetProcessHeap(), 0, size
)))
719 SetLastError(ERROR_OUTOFMEMORY
);
722 ret
= CryptDecodeObject(cc
->encoding
, CAT_MEMBERINFO_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, mi
, &size
);
727 member
->dwCertVersion
= mi
->dwCertVersion
;
728 RtlInitUnicodeString(&guid
, mi
->pwszSubjGuid
);
729 if (RtlGUIDFromString(&guid
, &member
->gSubjectType
))
731 HeapFree(GetProcessHeap(), 0, mi
);
735 HeapFree(GetProcessHeap(), 0, mi
);
736 if (!ret
) goto error
;
738 else if (!strcmp(attr
->pszObjId
, SPC_INDIRECT_DATA_OBJID
))
740 /* SPC_INDIRECT_DATA_CONTENT is equal to SIP_INDIRECT_DATA */
742 member
->sEncodedIndirectData
.cbData
= attr
->rgValue
->cbData
;
743 member
->sEncodedIndirectData
.pbData
= attr
->rgValue
->pbData
;
745 CryptDecodeObject(cc
->encoding
, SPC_INDIRECT_DATA_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, NULL
, &size
);
747 if (!(member
->pIndirectData
= HeapAlloc(GetProcessHeap(), 0, size
)))
749 SetLastError(ERROR_OUTOFMEMORY
);
752 CryptDecodeObject(cc
->encoding
, SPC_INDIRECT_DATA_OBJID
, attr
->rgValue
->pbData
, attr
->rgValue
->cbData
, 0, member
->pIndirectData
, &size
);
755 /* this object id should probably be handled in CryptCATEnumerateAttr */
756 FIXME("unhandled object id \"%s\"\n", attr
->pszObjId
);
759 if (!member
->sEncodedMemberInfo
.cbData
|| !member
->sEncodedIndirectData
.cbData
)
761 ERR("Corrupted catalog entry?\n");
762 SetLastError(CRYPT_E_ATTRIBUTES_MISSING
);
765 size
= (2 * member
->pIndirectData
->Digest
.cbData
+ 1) * sizeof(WCHAR
);
766 if (member
->pwszReferenceTag
)
767 member
->pwszReferenceTag
= HeapReAlloc(GetProcessHeap(), 0, member
->pwszReferenceTag
, size
);
769 member
->pwszReferenceTag
= HeapAlloc(GetProcessHeap(), 0, size
);
771 if (!member
->pwszReferenceTag
)
773 SetLastError(ERROR_OUTOFMEMORY
);
776 /* FIXME: reference tag is usually the file hash but doesn't have to be */
777 for (i
= 0; i
< member
->pIndirectData
->Digest
.cbData
; i
++)
781 sub
= member
->pIndirectData
->Digest
.pbData
[i
] >> 4;
782 member
->pwszReferenceTag
[i
* 2] = (sub
< 10 ? '0' + sub
: 'A' + sub
- 10);
783 sub
= member
->pIndirectData
->Digest
.pbData
[i
] & 0xf;
784 member
->pwszReferenceTag
[i
* 2 + 1] = (sub
< 10 ? '0' + sub
: 'A' + sub
- 10);
786 member
->pwszReferenceTag
[i
* 2] = 0;
790 HeapFree(GetProcessHeap(), 0, member
->pIndirectData
);
791 HeapFree(GetProcessHeap(), 0, member
->pwszReferenceTag
);
792 HeapFree(GetProcessHeap(), 0, member
);
796 static CTL_INFO
*decode_inner_content(HANDLE hmsg
, DWORD encoding
, DWORD
*len
)
801 CTL_INFO
*inner
= NULL
;
803 if (!CryptMsgGetParam(hmsg
, CMSG_INNER_CONTENT_TYPE_PARAM
, 0, NULL
, &size
)) return NULL
;
804 if (!(oid
= HeapAlloc(GetProcessHeap(), 0, size
)))
806 SetLastError(ERROR_OUTOFMEMORY
);
809 if (!CryptMsgGetParam(hmsg
, CMSG_INNER_CONTENT_TYPE_PARAM
, 0, oid
, &size
)) goto out
;
810 if (!CryptMsgGetParam(hmsg
, CMSG_CONTENT_PARAM
, 0, NULL
, &size
)) goto out
;
811 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, size
)))
813 SetLastError(ERROR_OUTOFMEMORY
);
816 if (!CryptMsgGetParam(hmsg
, CMSG_CONTENT_PARAM
, 0, buffer
, &size
)) goto out
;
817 if (!CryptDecodeObject(encoding
, oid
, buffer
, size
, 0, NULL
, &size
)) goto out
;
818 if (!(inner
= HeapAlloc(GetProcessHeap(), 0, size
)))
820 SetLastError(ERROR_OUTOFMEMORY
);
823 if (!CryptDecodeObject(encoding
, oid
, buffer
, size
, 0, inner
, &size
)) goto out
;
827 HeapFree(GetProcessHeap(), 0, oid
);
828 HeapFree(GetProcessHeap(), 0, buffer
);
832 /***********************************************************************
833 * CryptCATCatalogInfoFromContext (WINTRUST.@)
835 BOOL WINAPI
CryptCATCatalogInfoFromContext(HCATINFO hcatinfo
, CATALOG_INFO
*info
, DWORD flags
)
837 struct catinfo
*ci
= hcatinfo
;
839 TRACE("%p, %p, %x\n", hcatinfo
, info
, flags
);
841 if (!hcatinfo
|| hcatinfo
== INVALID_HANDLE_VALUE
|| ci
->magic
!= CATINFO_MAGIC
||
842 flags
|| !info
|| info
->cbStruct
!= sizeof(*info
))
844 SetLastError(ERROR_INVALID_PARAMETER
);
847 lstrcpyW(info
->wszCatalogFile
, ci
->file
);
851 /***********************************************************************
852 * CryptCATPutAttrInfo (WINTRUST.@)
854 CRYPTCATATTRIBUTE
* WINAPI
CryptCATPutAttrInfo(HANDLE catalog
, CRYPTCATMEMBER
*member
,
855 WCHAR
*name
, DWORD flags
, DWORD size
, BYTE
*data
)
857 FIXME("catalog %p, member %p, name %s, flags %#x, size %u, data %p, stub!\n",
858 catalog
, member
, debugstr_w(name
), flags
, size
, data
);
860 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
864 /***********************************************************************
865 * CryptCATPutCatAttrInfo (WINTRUST.@)
867 CRYPTCATATTRIBUTE
* WINAPI
CryptCATPutCatAttrInfo(HANDLE catalog
,
868 WCHAR
*name
, DWORD flags
, DWORD size
, BYTE
*data
)
870 FIXME("catalog %p, name %s, flags %#x, size %u, data %p, stub!\n",
871 catalog
, debugstr_w(name
), flags
, size
, data
);
873 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
877 /***********************************************************************
878 * CryptCATPutMemberInfo (WINTRUST.@)
880 CRYPTCATMEMBER
* WINAPI
CryptCATPutMemberInfo(HANDLE catalog
, WCHAR
*filename
,
881 WCHAR
*member
, GUID
*subject
, DWORD version
, DWORD size
, BYTE
*data
)
883 FIXME("catalog %p, filename %s, member %s, subject %s, version %u, size %u, data %p, stub!\n",
884 catalog
, debugstr_w(filename
), debugstr_w(member
), debugstr_guid(subject
), version
, size
, data
);
886 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
890 /***********************************************************************
891 * CryptCATPersistStore (WINTRUST.@)
893 BOOL WINAPI
CryptCATPersistStore(HANDLE catalog
)
895 FIXME("catalog %p, stub!\n", catalog
);
897 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
901 /***********************************************************************
902 * CryptCATOpen (WINTRUST.@)
904 HANDLE WINAPI
CryptCATOpen(WCHAR
*filename
, DWORD flags
, HCRYPTPROV hProv
,
905 DWORD dwPublicVersion
, DWORD dwEncodingType
)
909 DWORD size
, open_mode
= OPEN_ALWAYS
;
913 TRACE("filename %s, flags %#x, provider %#lx, version %#x, type %#x\n",
914 debugstr_w(filename
), flags
, hProv
, dwPublicVersion
, dwEncodingType
);
918 SetLastError(ERROR_INVALID_PARAMETER
);
919 return INVALID_HANDLE_VALUE
;
922 if (!dwEncodingType
) dwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
924 if (flags
== CRYPTCAT_OPEN_EXISTING
)
925 open_mode
= OPEN_EXISTING
;
926 if (flags
& CRYPTCAT_OPEN_CREATENEW
)
927 open_mode
= CREATE_ALWAYS
;
929 file
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, open_mode
, 0, NULL
);
930 if (file
== INVALID_HANDLE_VALUE
) return INVALID_HANDLE_VALUE
;
932 size
= GetFileSize(file
, NULL
);
933 if (!(buffer
= HeapAlloc(GetProcessHeap(), 0, size
)))
936 SetLastError(ERROR_OUTOFMEMORY
);
937 return INVALID_HANDLE_VALUE
;
939 if (!(hmsg
= CryptMsgOpenToDecode(dwEncodingType
, 0, 0, hProv
, NULL
, NULL
)))
942 HeapFree(GetProcessHeap(), 0, buffer
);
943 return INVALID_HANDLE_VALUE
;
945 if (!size
) valid
= FALSE
;
946 else if (!ReadFile(file
, buffer
, size
, &size
, NULL
))
949 HeapFree(GetProcessHeap(), 0, buffer
);
951 return INVALID_HANDLE_VALUE
;
953 else valid
= CryptMsgUpdate(hmsg
, buffer
, size
, TRUE
);
954 HeapFree(GetProcessHeap(), 0, buffer
);
957 size
= sizeof(DWORD
);
958 if (!(cc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cc
))))
961 SetLastError(ERROR_OUTOFMEMORY
);
962 return INVALID_HANDLE_VALUE
;
966 cc
->encoding
= dwEncodingType
;
969 cc
->magic
= CRYPTCAT_MAGIC
;
970 SetLastError(ERROR_SUCCESS
);
973 else if (CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_COUNT_PARAM
, 0, &cc
->attr_count
, &size
))
978 for (i
= 0; i
< cc
->attr_count
; i
++)
980 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, NULL
, &size
))
983 HeapFree(GetProcessHeap(), 0, cc
);
984 return INVALID_HANDLE_VALUE
;
988 if (!(cc
->attr
= HeapAlloc(GetProcessHeap(), 0, sizeof(*cc
->attr
) * cc
->attr_count
+ sum
)))
991 HeapFree(GetProcessHeap(), 0, cc
);
992 SetLastError(ERROR_OUTOFMEMORY
);
993 return INVALID_HANDLE_VALUE
;
995 p
= (BYTE
*)(cc
->attr
+ cc
->attr_count
);
996 for (i
= 0; i
< cc
->attr_count
; i
++)
998 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, NULL
, &size
))
1000 CryptMsgClose(hmsg
);
1001 HeapFree(GetProcessHeap(), 0, cc
->attr
);
1002 HeapFree(GetProcessHeap(), 0, cc
);
1003 return INVALID_HANDLE_VALUE
;
1005 if (!CryptMsgGetParam(hmsg
, CMSG_ATTR_CERT_PARAM
, i
, p
, &size
))
1007 CryptMsgClose(hmsg
);
1008 HeapFree(GetProcessHeap(), 0, cc
->attr
);
1009 HeapFree(GetProcessHeap(), 0, cc
);
1010 return INVALID_HANDLE_VALUE
;
1014 cc
->inner
= decode_inner_content(hmsg
, dwEncodingType
, &cc
->inner_len
);
1015 if (!cc
->inner
|| !CryptSIPRetrieveSubjectGuid(filename
, NULL
, &cc
->subject
))
1017 CryptMsgClose(hmsg
);
1018 HeapFree(GetProcessHeap(), 0, cc
->attr
);
1019 HeapFree(GetProcessHeap(), 0, cc
->inner
);
1020 HeapFree(GetProcessHeap(), 0, cc
);
1021 return INVALID_HANDLE_VALUE
;
1023 cc
->magic
= CRYPTCAT_MAGIC
;
1024 SetLastError(ERROR_SUCCESS
);
1027 HeapFree(GetProcessHeap(), 0, cc
);
1028 return INVALID_HANDLE_VALUE
;
1031 /***********************************************************************
1032 * CryptSIPCreateIndirectData (WINTRUST.@)
1034 BOOL WINAPI
CryptSIPCreateIndirectData(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD
* pcbIndirectData
,
1035 SIP_INDIRECT_DATA
* pIndirectData
)
1037 FIXME("(%p %p %p) stub\n", pSubjectInfo
, pcbIndirectData
, pIndirectData
);
1043 /***********************************************************************
1044 * CryptCATCDFClose (WINTRUST.@)
1046 BOOL WINAPI
CryptCATCDFClose(CRYPTCATCDF
*pCDF
)
1048 FIXME("(%p) stub\n", pCDF
);
1053 /***********************************************************************
1054 * CryptCATCDFEnumCatAttributes (WINTRUST.@)
1056 CRYPTCATATTRIBUTE
* WINAPI
CryptCATCDFEnumCatAttributes(CRYPTCATCDF
*pCDF
,
1057 CRYPTCATATTRIBUTE
*pPrevAttr
,
1058 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
)
1060 FIXME("(%p %p %p) stub\n", pCDF
, pPrevAttr
, pfnParseError
);
1065 /***********************************************************************
1066 * CryptCATCDFEnumMembersByCDFTagEx (WINTRUST.@)
1068 LPWSTR WINAPI
CryptCATCDFEnumMembersByCDFTagEx(CRYPTCATCDF
*pCDF
, LPWSTR pwszPrevCDFTag
,
1069 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
,
1070 CRYPTCATMEMBER
**ppMember
, BOOL fContinueOnError
,
1073 FIXME("(%p %s %p %p %d %p) stub\n", pCDF
, debugstr_w(pwszPrevCDFTag
), pfnParseError
,
1074 ppMember
, fContinueOnError
, pvReserved
);
1079 /***********************************************************************
1080 * CryptCATCDFOpen (WINTRUST.@)
1082 CRYPTCATCDF
* WINAPI
CryptCATCDFOpen(LPWSTR pwszFilePath
,
1083 PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError
)
1085 FIXME("(%s %p) stub\n", debugstr_w(pwszFilePath
), pfnParseError
);
1090 static BOOL
WINTRUST_GetSignedMsgFromPEFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1091 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1092 BYTE
*pbSignedDataMsg
)
1095 WIN_CERTIFICATE
*pCert
= NULL
;
1098 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1099 pcbSignedDataMsg
, pbSignedDataMsg
);
1101 if(pSubjectInfo
->hFile
&& pSubjectInfo
->hFile
!=INVALID_HANDLE_VALUE
)
1102 file
= pSubjectInfo
->hFile
;
1105 file
= CreateFileW(pSubjectInfo
->pwsFileName
, GENERIC_READ
,
1106 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
1107 if(file
== INVALID_HANDLE_VALUE
)
1111 if (!pbSignedDataMsg
)
1113 WIN_CERTIFICATE cert
;
1115 /* app hasn't passed buffer, just get the length */
1116 ret
= ImageGetCertificateHeader(file
, dwIndex
, &cert
);
1119 switch (cert
.wCertificateType
)
1121 case WIN_CERT_TYPE_X509
:
1122 case WIN_CERT_TYPE_PKCS_SIGNED_DATA
:
1123 *pcbSignedDataMsg
= cert
.dwLength
;
1126 WARN("unknown certificate type %d\n", cert
.wCertificateType
);
1135 ret
= ImageGetCertificateData(file
, dwIndex
, NULL
, &len
);
1136 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1138 pCert
= HeapAlloc(GetProcessHeap(), 0, len
);
1144 ret
= ImageGetCertificateData(file
, dwIndex
, pCert
, &len
);
1147 pCert
->dwLength
-= FIELD_OFFSET(WIN_CERTIFICATE
, bCertificate
);
1148 if (*pcbSignedDataMsg
< pCert
->dwLength
)
1150 *pcbSignedDataMsg
= pCert
->dwLength
;
1151 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1156 memcpy(pbSignedDataMsg
, pCert
->bCertificate
, pCert
->dwLength
);
1157 *pcbSignedDataMsg
= pCert
->dwLength
;
1158 switch (pCert
->wCertificateType
)
1160 case WIN_CERT_TYPE_X509
:
1161 *pdwEncodingType
= X509_ASN_ENCODING
;
1163 case WIN_CERT_TYPE_PKCS_SIGNED_DATA
:
1164 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1167 WARN("don't know what to do for encoding type %d\n",
1168 pCert
->wCertificateType
);
1169 *pdwEncodingType
= 0;
1175 if(pSubjectInfo
->hFile
!= file
)
1177 HeapFree(GetProcessHeap(), 0, pCert
);
1181 static BOOL
WINTRUST_PutSignedMsgToPEFile(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD pdwEncodingType
,
1182 DWORD
* pdwIndex
, DWORD cbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1184 WIN_CERTIFICATE
*cert
;
1189 if(pSubjectInfo
->hFile
&& pSubjectInfo
->hFile
!=INVALID_HANDLE_VALUE
)
1190 file
= pSubjectInfo
->hFile
;
1193 file
= CreateFileW(pSubjectInfo
->pwsFileName
, GENERIC_READ
|GENERIC_WRITE
,
1194 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
1195 if(file
== INVALID_HANDLE_VALUE
)
1199 /* int aligned WIN_CERTIFICATE structure with cbSignedDataMsg+1 bytes of data */
1200 size
= FIELD_OFFSET(WIN_CERTIFICATE
, bCertificate
[cbSignedDataMsg
+4]) & (~3);
1201 cert
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1205 cert
->dwLength
= size
;
1206 cert
->wRevision
= WIN_CERT_REVISION_2_0
;
1207 cert
->wCertificateType
= WIN_CERT_TYPE_PKCS_SIGNED_DATA
;
1208 memcpy(cert
->bCertificate
, pbSignedDataMsg
, cbSignedDataMsg
);
1209 ret
= ImageAddCertificate(file
, cert
, pdwIndex
);
1211 HeapFree(GetProcessHeap(), 0, cert
);
1212 if(file
!= pSubjectInfo
->hFile
)
1217 /* structure offsets */
1218 #define cfhead_Signature (0x00)
1219 #define cfhead_CabinetSize (0x08)
1220 #define cfhead_MinorVersion (0x18)
1221 #define cfhead_MajorVersion (0x19)
1222 #define cfhead_Flags (0x1E)
1223 #define cfhead_SIZEOF (0x24)
1224 #define cfheadext_HeaderReserved (0x00)
1225 #define cfheadext_SIZEOF (0x04)
1226 #define cfsigninfo_CertOffset (0x04)
1227 #define cfsigninfo_CertSize (0x08)
1228 #define cfsigninfo_SIZEOF (0x0C)
1231 #define cfheadRESERVE_PRESENT (0x0004)
1233 /* endian-neutral reading of little-endian data */
1234 #define EndGetI32(a) ((((a)[3])<<24)|(((a)[2])<<16)|(((a)[1])<<8)|((a)[0]))
1235 #define EndGetI16(a) ((((a)[1])<<8)|((a)[0]))
1237 /* For documentation purposes only: this is the structure in the reserved
1238 * area of a signed cabinet file. The cert offset indicates where in the
1239 * cabinet file the signature resides, and the count indicates its size.
1241 typedef struct _CAB_SIGNINFO
1243 WORD unk0
; /* always 0? */
1244 WORD unk1
; /* always 0x0010? */
1247 } CAB_SIGNINFO
, *PCAB_SIGNINFO
;
1249 static BOOL
WINTRUST_GetSignedMsgFromCabFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1250 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1251 BYTE
*pbSignedDataMsg
)
1254 LONG base_offset
, cabsize
;
1257 DWORD cert_offset
, cert_size
, dwRead
;
1259 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1260 pcbSignedDataMsg
, pbSignedDataMsg
);
1262 /* get basic offset & size info */
1263 base_offset
= SetFilePointer(pSubjectInfo
->hFile
, 0L, NULL
, SEEK_CUR
);
1265 if (SetFilePointer(pSubjectInfo
->hFile
, 0, NULL
, SEEK_END
) == INVALID_SET_FILE_POINTER
)
1267 TRACE("seek error\n");
1271 cabsize
= SetFilePointer(pSubjectInfo
->hFile
, 0L, NULL
, SEEK_CUR
);
1272 if ((cabsize
== -1) || (base_offset
== -1) ||
1273 (SetFilePointer(pSubjectInfo
->hFile
, 0, NULL
, SEEK_SET
) == INVALID_SET_FILE_POINTER
))
1275 TRACE("seek error\n");
1279 /* read in the CFHEADER */
1280 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfhead_SIZEOF
, &dwRead
, NULL
) ||
1281 dwRead
!= cfhead_SIZEOF
)
1283 TRACE("reading header failed\n");
1287 /* check basic MSCF signature */
1288 if (EndGetI32(buf
+cfhead_Signature
) != 0x4643534d)
1290 WARN("cabinet signature not present\n");
1294 /* Ignore the number of folders and files and the set and cabinet IDs */
1296 /* check the header revision */
1297 if ((buf
[cfhead_MajorVersion
] > 1) ||
1298 (buf
[cfhead_MajorVersion
] == 1 && buf
[cfhead_MinorVersion
] > 3))
1300 WARN("cabinet format version > 1.3\n");
1304 /* pull the flags out */
1305 flags
= EndGetI16(buf
+cfhead_Flags
);
1307 if (!(flags
& cfheadRESERVE_PRESENT
))
1309 TRACE("no header present, not signed\n");
1313 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfheadext_SIZEOF
, &dwRead
, NULL
) ||
1314 dwRead
!= cfheadext_SIZEOF
)
1316 ERR("bunk reserve-sizes?\n");
1320 header_resv
= EndGetI16(buf
+cfheadext_HeaderReserved
);
1323 TRACE("no header_resv, not signed\n");
1326 else if (header_resv
< cfsigninfo_SIZEOF
)
1328 TRACE("header_resv too small, not signed\n");
1332 if (header_resv
> 60000)
1334 WARN("WARNING; header reserved space > 60000\n");
1337 if (!ReadFile(pSubjectInfo
->hFile
, buf
, cfsigninfo_SIZEOF
, &dwRead
, NULL
) ||
1338 dwRead
!= cfsigninfo_SIZEOF
)
1340 ERR("couldn't read reserve\n");
1344 cert_offset
= EndGetI32(buf
+cfsigninfo_CertOffset
);
1345 TRACE("cert_offset: %d\n", cert_offset
);
1346 cert_size
= EndGetI32(buf
+cfsigninfo_CertSize
);
1347 TRACE("cert_size: %d\n", cert_size
);
1349 /* The redundant checks are to avoid wraparound */
1350 if (cert_offset
> cabsize
|| cert_size
> cabsize
||
1351 cert_offset
+ cert_size
> cabsize
)
1353 WARN("offset beyond file, not attempting to read\n");
1357 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1358 if (!pbSignedDataMsg
)
1360 *pcbSignedDataMsg
= cert_size
;
1363 if (*pcbSignedDataMsg
< cert_size
)
1365 *pcbSignedDataMsg
= cert_size
;
1366 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1369 if (SetFilePointer(pSubjectInfo
->hFile
, cert_offset
, NULL
, SEEK_SET
) == INVALID_SET_FILE_POINTER
)
1371 ERR("couldn't seek to cert location\n");
1374 if (!ReadFile(pSubjectInfo
->hFile
, pbSignedDataMsg
, cert_size
, &dwRead
,
1375 NULL
) || dwRead
!= cert_size
)
1377 ERR("couldn't read cert\n");
1378 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1381 /* The encoding of the files I've seen appears to be in ASN.1
1382 * format, and there isn't a field indicating the type, so assume it
1385 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1386 /* Restore base offset */
1387 SetFilePointer(pSubjectInfo
->hFile
, base_offset
, NULL
, SEEK_SET
);
1391 static BOOL
WINTRUST_GetSignedMsgFromCatFile(SIP_SUBJECTINFO
*pSubjectInfo
,
1392 DWORD
*pdwEncodingType
, DWORD dwIndex
, DWORD
*pcbSignedDataMsg
,
1393 BYTE
*pbSignedDataMsg
)
1397 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1398 pcbSignedDataMsg
, pbSignedDataMsg
);
1400 if (!pbSignedDataMsg
)
1402 *pcbSignedDataMsg
= GetFileSize(pSubjectInfo
->hFile
, NULL
);
1407 DWORD len
= GetFileSize(pSubjectInfo
->hFile
, NULL
);
1409 if (*pcbSignedDataMsg
< len
)
1411 *pcbSignedDataMsg
= len
;
1412 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1417 ret
= ReadFile(pSubjectInfo
->hFile
, pbSignedDataMsg
, len
,
1418 pcbSignedDataMsg
, NULL
);
1420 *pdwEncodingType
= X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
;
1426 /* GUIDs used by CryptSIPGetSignedDataMsg and CryptSIPPutSignedDataMsg */
1427 static const GUID unknown
= { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
1428 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1429 static const GUID cabGUID
= { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,
1430 0x00,0xC0,0x4F,0xC2,0x95,0xEE } };
1431 static const GUID catGUID
= { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,
1432 0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
1434 /***********************************************************************
1435 * CryptSIPGetSignedDataMsg (WINTRUST.@)
1437 BOOL WINAPI
CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD
* pdwEncodingType
,
1438 DWORD dwIndex
, DWORD
* pcbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1442 TRACE("(%p %p %d %p %p)\n", pSubjectInfo
, pdwEncodingType
, dwIndex
,
1443 pcbSignedDataMsg
, pbSignedDataMsg
);
1447 SetLastError(ERROR_INVALID_PARAMETER
);
1451 if (!memcmp(pSubjectInfo
->pgSubjectType
, &unknown
, sizeof(unknown
)))
1452 ret
= WINTRUST_GetSignedMsgFromPEFile(pSubjectInfo
, pdwEncodingType
,
1453 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1454 else if (!memcmp(pSubjectInfo
->pgSubjectType
, &cabGUID
, sizeof(cabGUID
)))
1455 ret
= WINTRUST_GetSignedMsgFromCabFile(pSubjectInfo
, pdwEncodingType
,
1456 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1457 else if (!memcmp(pSubjectInfo
->pgSubjectType
, &catGUID
, sizeof(catGUID
)))
1458 ret
= WINTRUST_GetSignedMsgFromCatFile(pSubjectInfo
, pdwEncodingType
,
1459 dwIndex
, pcbSignedDataMsg
, pbSignedDataMsg
);
1462 FIXME("unimplemented for subject type %s\n",
1463 debugstr_guid(pSubjectInfo
->pgSubjectType
));
1467 TRACE("returning %d\n", ret
);
1471 /***********************************************************************
1472 * CryptSIPPutSignedDataMsg (WINTRUST.@)
1474 BOOL WINAPI
CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
, DWORD pdwEncodingType
,
1475 DWORD
* pdwIndex
, DWORD cbSignedDataMsg
, BYTE
* pbSignedDataMsg
)
1477 TRACE("(%p %d %p %d %p)\n", pSubjectInfo
, pdwEncodingType
, pdwIndex
,
1478 cbSignedDataMsg
, pbSignedDataMsg
);
1481 SetLastError(ERROR_INVALID_PARAMETER
);
1485 if(!memcmp(pSubjectInfo
->pgSubjectType
, &unknown
, sizeof(unknown
)))
1486 return WINTRUST_PutSignedMsgToPEFile(pSubjectInfo
, pdwEncodingType
,
1487 pdwIndex
, cbSignedDataMsg
, pbSignedDataMsg
);
1489 FIXME("unimplemented for subject type %s\n",
1490 debugstr_guid(pSubjectInfo
->pgSubjectType
));
1495 /***********************************************************************
1496 * CryptSIPRemoveSignedDataMsg (WINTRUST.@)
1498 BOOL WINAPI
CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO
* pSubjectInfo
,
1501 FIXME("(%p %d) stub\n", pSubjectInfo
, dwIndex
);
1506 /***********************************************************************
1507 * CryptSIPVerifyIndirectData (WINTRUST.@)
1509 BOOL WINAPI
CryptSIPVerifyIndirectData(SIP_SUBJECTINFO
* pSubjectInfo
,
1510 SIP_INDIRECT_DATA
* pIndirectData
)
1512 FIXME("(%p %p) stub\n", pSubjectInfo
, pIndirectData
);