2 * Copyright 2007 Juan Lang
3 * Copyright 2016 Mark Jansen
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wintrust
);
34 HRESULT WINAPI
SoftpubDefCertInit(CRYPT_PROVIDER_DATA
*data
)
36 HRESULT ret
= S_FALSE
;
38 TRACE("(%p)\n", data
);
40 if (data
->padwTrustStepErrors
&&
41 !data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_WVTINIT
])
43 TRACE("returning %08lx\n", ret
);
47 HRESULT WINAPI
SoftpubInitialize(CRYPT_PROVIDER_DATA
*data
)
49 HRESULT ret
= S_FALSE
;
51 TRACE("(%p)\n", data
);
53 if (data
->padwTrustStepErrors
&&
54 !data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_WVTINIT
])
56 TRACE("returning %08lx\n", ret
);
60 HRESULT WINAPI
DriverInitializePolicy(CRYPT_PROVIDER_DATA
*data
)
66 HRESULT WINAPI
DriverCleanupPolicy(CRYPT_PROVIDER_DATA
*data
)
72 HRESULT WINAPI
DriverFinalPolicy(CRYPT_PROVIDER_DATA
*data
)
78 /* Assumes data->pWintrustData->u.pFile exists. Makes sure a file handle is
81 static DWORD
SOFTPUB_OpenFile(CRYPT_PROVIDER_DATA
*data
)
83 DWORD err
= ERROR_SUCCESS
;
85 /* PSDK implies that all values should be initialized to NULL, so callers
86 * typically have hFile as NULL rather than INVALID_HANDLE_VALUE. Check
89 if (!data
->pWintrustData
->u
.pFile
->hFile
||
90 data
->pWintrustData
->u
.pFile
->hFile
== INVALID_HANDLE_VALUE
)
92 data
->pWintrustData
->u
.pFile
->hFile
=
93 CreateFileW(data
->pWintrustData
->u
.pFile
->pcwszFilePath
, GENERIC_READ
,
94 FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
95 if (data
->pWintrustData
->u
.pFile
->hFile
!= INVALID_HANDLE_VALUE
)
96 data
->fOpenedFile
= TRUE
;
101 GetFileTime(data
->pWintrustData
->u
.pFile
->hFile
, &data
->sftSystemTime
,
103 TRACE("returning %ld\n", err
);
107 /* Assumes data->pWintrustData->u.pFile exists. Sets data->pPDSip->gSubject to
108 * the file's subject GUID.
110 static DWORD
SOFTPUB_GetFileSubject(CRYPT_PROVIDER_DATA
*data
)
112 DWORD err
= ERROR_SUCCESS
;
114 if (!WVT_ISINSTRUCT(WINTRUST_FILE_INFO
,
115 data
->pWintrustData
->u
.pFile
->cbStruct
, pgKnownSubject
) ||
116 !data
->pWintrustData
->u
.pFile
->pgKnownSubject
)
118 if (!CryptSIPRetrieveSubjectGuid(
119 data
->pWintrustData
->u
.pFile
->pcwszFilePath
,
120 data
->pWintrustData
->u
.pFile
->hFile
,
121 &data
->u
.pPDSip
->gSubject
))
123 LARGE_INTEGER fileSize
;
124 DWORD sipError
= GetLastError();
126 /* Special case for empty files: the error is expected to be
127 * TRUST_E_SUBJECT_FORM_UNKNOWN, rather than whatever
128 * CryptSIPRetrieveSubjectGuid returns.
130 if (GetFileSizeEx(data
->pWintrustData
->u
.pFile
->hFile
, &fileSize
)
131 && !fileSize
.QuadPart
)
132 err
= TRUST_E_SUBJECT_FORM_UNKNOWN
;
138 data
->u
.pPDSip
->gSubject
= *data
->pWintrustData
->u
.pFile
->pgKnownSubject
;
139 TRACE("returning %ld\n", err
);
143 /* Assumes data->u.pPDSip exists, and its gSubject member set.
144 * Allocates data->u.pPDSip->pSip and loads it, if possible.
146 static DWORD
SOFTPUB_GetSIP(CRYPT_PROVIDER_DATA
*data
)
148 DWORD err
= ERROR_SUCCESS
;
150 data
->u
.pPDSip
->pSip
= data
->psPfns
->pfnAlloc(sizeof(SIP_DISPATCH_INFO
));
151 if (data
->u
.pPDSip
->pSip
)
153 if (!CryptSIPLoad(&data
->u
.pPDSip
->gSubject
, 0, data
->u
.pPDSip
->pSip
))
154 err
= GetLastError();
157 err
= ERROR_OUTOFMEMORY
;
158 TRACE("returning %ld\n", err
);
162 /* Assumes data->u.pPDSip has been loaded, and data->u.pPDSip->pSip allocated.
163 * Calls data->u.pPDSip->pSip->pfGet to construct data->hMsg.
165 static DWORD
SOFTPUB_GetMessageFromFile(CRYPT_PROVIDER_DATA
*data
, HANDLE file
,
168 DWORD err
= ERROR_SUCCESS
;
173 data
->u
.pPDSip
->psSipSubjectInfo
=
174 data
->psPfns
->pfnAlloc(sizeof(SIP_SUBJECTINFO
));
175 if (!data
->u
.pPDSip
->psSipSubjectInfo
)
176 return ERROR_OUTOFMEMORY
;
178 data
->u
.pPDSip
->psSipSubjectInfo
->cbSize
= sizeof(SIP_SUBJECTINFO
);
179 data
->u
.pPDSip
->psSipSubjectInfo
->pgSubjectType
= &data
->u
.pPDSip
->gSubject
;
180 data
->u
.pPDSip
->psSipSubjectInfo
->hFile
= file
;
181 data
->u
.pPDSip
->psSipSubjectInfo
->pwsFileName
= filePath
;
182 data
->u
.pPDSip
->psSipSubjectInfo
->hProv
= data
->hProv
;
183 ret
= data
->u
.pPDSip
->pSip
->pfGet(data
->u
.pPDSip
->psSipSubjectInfo
,
184 &data
->dwEncoding
, 0, &size
, 0);
186 return TRUST_E_NOSIGNATURE
;
188 buf
= data
->psPfns
->pfnAlloc(size
);
190 return ERROR_OUTOFMEMORY
;
192 ret
= data
->u
.pPDSip
->pSip
->pfGet(data
->u
.pPDSip
->psSipSubjectInfo
,
193 &data
->dwEncoding
, 0, &size
, buf
);
196 data
->hMsg
= CryptMsgOpenToDecode(data
->dwEncoding
, 0, 0, data
->hProv
,
200 ret
= CryptMsgUpdate(data
->hMsg
, buf
, size
, TRUE
);
202 err
= GetLastError();
206 err
= GetLastError();
208 data
->psPfns
->pfnFree(buf
);
209 TRACE("returning %ld\n", err
);
213 static BOOL
hash_file_data( HANDLE file
, DWORD start
, DWORD end
, HCRYPTHASH hash
)
215 DWORD bytes_read
, size
= end
- start
;
216 DWORD buffer_size
= min( size
, 1024*1024 );
217 BYTE
*buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
);
219 if (!buffer
) return FALSE
;
220 SetFilePointer( file
, start
, NULL
, FILE_BEGIN
);
223 if (!ReadFile( file
, buffer
, min( buffer_size
, size
), &bytes_read
, NULL
)) break;
224 if (!bytes_read
) break;
225 if (!CryptHashData( hash
, buffer
, bytes_read
, 0 )) break;
228 HeapFree( GetProcessHeap(), 0, buffer
);
232 /* See https://www.cs.auckland.ac.nz/~pgut001/pubs/authenticode.txt
233 * for details about the hashing.
235 static BOOL
SOFTPUB_HashPEFile(HANDLE file
, HCRYPTHASH hash
)
237 DWORD checksum
, security_dir
;
238 IMAGE_DOS_HEADER dos_header
;
241 IMAGE_NT_HEADERS32 nt32
;
242 IMAGE_NT_HEADERS64 nt64
;
244 IMAGE_DATA_DIRECTORY secdir
;
245 LARGE_INTEGER file_size
;
249 if (!GetFileSizeEx(file
, &file_size
))
252 SetFilePointer(file
, 0, NULL
, FILE_BEGIN
);
253 ret
= ReadFile(file
, &dos_header
, sizeof(dos_header
), &bytes_read
, NULL
);
254 if (!ret
|| bytes_read
!= sizeof(dos_header
))
257 if (dos_header
.e_magic
!= IMAGE_DOS_SIGNATURE
)
259 if (dos_header
.e_lfanew
>= 256 * 1024 * 1024) /* see RtlImageNtHeaderEx */
261 if (dos_header
.e_lfanew
+ FIELD_OFFSET(IMAGE_NT_HEADERS
, OptionalHeader
.MajorLinkerVersion
) > file_size
.QuadPart
)
264 SetFilePointer(file
, dos_header
.e_lfanew
, NULL
, FILE_BEGIN
);
265 ret
= ReadFile(file
, &nt_header
, sizeof(nt_header
), &bytes_read
, NULL
);
266 if (!ret
|| bytes_read
< FIELD_OFFSET(IMAGE_NT_HEADERS32
, OptionalHeader
.Magic
) +
267 sizeof(nt_header
.nt32
.OptionalHeader
.Magic
))
270 if (nt_header
.nt32
.Signature
!= IMAGE_NT_SIGNATURE
)
273 if (nt_header
.nt32
.OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR32_MAGIC
)
275 if (bytes_read
< sizeof(nt_header
.nt32
))
278 checksum
= dos_header
.e_lfanew
+ FIELD_OFFSET(IMAGE_NT_HEADERS32
, OptionalHeader
.CheckSum
);
279 security_dir
= dos_header
.e_lfanew
+ FIELD_OFFSET(IMAGE_NT_HEADERS32
, OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_SECURITY
]);
280 secdir
= nt_header
.nt32
.OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_SECURITY
];
282 else if (nt_header
.nt32
.OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
284 if (bytes_read
< sizeof(nt_header
.nt64
))
287 checksum
= dos_header
.e_lfanew
+ FIELD_OFFSET(IMAGE_NT_HEADERS64
, OptionalHeader
.CheckSum
);
288 security_dir
= dos_header
.e_lfanew
+ FIELD_OFFSET(IMAGE_NT_HEADERS64
, OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_SECURITY
]);
289 secdir
= nt_header
.nt64
.OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_SECURITY
];
294 if (secdir
.VirtualAddress
< security_dir
+ sizeof(IMAGE_DATA_DIRECTORY
))
296 if (secdir
.VirtualAddress
> file_size
.QuadPart
)
298 if (secdir
.VirtualAddress
+ secdir
.Size
!= file_size
.QuadPart
)
301 if (!hash_file_data( file
, 0, checksum
, hash
)) return FALSE
;
302 if (!hash_file_data( file
, checksum
+ sizeof(DWORD
), security_dir
, hash
)) return FALSE
;
303 if (!hash_file_data( file
, security_dir
+ sizeof(IMAGE_DATA_DIRECTORY
), secdir
.VirtualAddress
, hash
))
309 static DWORD
SOFTPUB_VerifyImageHash(CRYPT_PROVIDER_DATA
*data
, HANDLE file
)
311 SPC_INDIRECT_DATA_CONTENT
*indirect
= (SPC_INDIRECT_DATA_CONTENT
*)data
->u
.pPDSip
->psIndirectData
;
312 DWORD err
, hash_size
, length
;
314 BOOL release_prov
= FALSE
;
315 HCRYPTPROV prov
= data
->hProv
;
319 if (((ULONG_PTR
)indirect
->Data
.pszObjId
>> 16) == 0 ||
320 strcmp(indirect
->Data
.pszObjId
, SPC_PE_IMAGE_DATA_OBJID
))
322 FIXME("Cannot verify hash for pszObjId=%s\n", debugstr_a(indirect
->Data
.pszObjId
));
323 return ERROR_SUCCESS
;
326 if (!(algID
= CertOIDToAlgId(indirect
->DigestAlgorithm
.pszObjId
)))
327 return TRUST_E_SYSTEM_ERROR
; /* FIXME */
331 if (!CryptAcquireContextW(&prov
, NULL
, MS_ENH_RSA_AES_PROV_W
, PROV_RSA_AES
, CRYPT_VERIFYCONTEXT
))
332 return GetLastError();
336 if (!CryptCreateHash(prov
, algID
, 0, 0, &hash
))
338 err
= GetLastError();
342 if (!SOFTPUB_HashPEFile(file
, hash
))
344 err
= TRUST_E_NOSIGNATURE
;
348 length
= sizeof(hash_size
);
349 if (!CryptGetHashParam(hash
, HP_HASHSIZE
, (BYTE
*)&hash_size
, &length
, 0))
351 err
= GetLastError();
355 if (!(hash_data
= data
->psPfns
->pfnAlloc(hash_size
)))
357 err
= ERROR_OUTOFMEMORY
;
361 if (!CryptGetHashParam(hash
, HP_HASHVAL
, hash_data
, &hash_size
, 0))
363 err
= GetLastError();
364 data
->psPfns
->pfnFree(hash_data
);
368 err
= (hash_size
== indirect
->Digest
.cbData
&&
369 !memcmp(hash_data
, indirect
->Digest
.pbData
, hash_size
)) ? S_OK
: TRUST_E_BAD_DIGEST
;
370 data
->psPfns
->pfnFree(hash_data
);
374 CryptDestroyHash(hash
);
376 CryptReleaseContext(prov
, 0);
381 static DWORD
SOFTPUB_CreateStoreFromMessage(CRYPT_PROVIDER_DATA
*data
)
383 DWORD err
= ERROR_SUCCESS
;
386 store
= CertOpenStore(CERT_STORE_PROV_MSG
, data
->dwEncoding
,
387 data
->hProv
, CERT_STORE_NO_CRYPT_RELEASE_FLAG
, data
->hMsg
);
390 if (!data
->psPfns
->pfnAddStore2Chain(data
, store
))
391 err
= GetLastError();
392 CertCloseStore(store
, 0);
395 err
= GetLastError();
396 TRACE("returning %ld\n", err
);
400 static DWORD
SOFTPUB_DecodeInnerContent(CRYPT_PROVIDER_DATA
*data
)
403 DWORD size
, err
= ERROR_SUCCESS
;
407 ret
= CryptMsgGetParam(data
->hMsg
, CMSG_INNER_CONTENT_TYPE_PARAM
, 0, NULL
,
411 err
= GetLastError();
414 oid
= data
->psPfns
->pfnAlloc(size
);
417 err
= ERROR_OUTOFMEMORY
;
420 ret
= CryptMsgGetParam(data
->hMsg
, CMSG_INNER_CONTENT_TYPE_PARAM
, 0, oid
,
424 err
= GetLastError();
427 ret
= CryptMsgGetParam(data
->hMsg
, CMSG_CONTENT_PARAM
, 0, NULL
, &size
);
430 err
= GetLastError();
433 buf
= data
->psPfns
->pfnAlloc(size
);
436 err
= ERROR_OUTOFMEMORY
;
439 ret
= CryptMsgGetParam(data
->hMsg
, CMSG_CONTENT_PARAM
, 0, buf
, &size
);
442 err
= GetLastError();
445 ret
= CryptDecodeObject(data
->dwEncoding
, oid
, buf
, size
, 0, NULL
, &size
);
448 err
= GetLastError();
451 data
->u
.pPDSip
->psIndirectData
= data
->psPfns
->pfnAlloc(size
);
452 if (!data
->u
.pPDSip
->psIndirectData
)
454 err
= ERROR_OUTOFMEMORY
;
457 ret
= CryptDecodeObject(data
->dwEncoding
, oid
, buf
, size
, 0,
458 data
->u
.pPDSip
->psIndirectData
, &size
);
460 err
= GetLastError();
463 TRACE("returning %ld\n", err
);
464 data
->psPfns
->pfnFree(oid
);
465 data
->psPfns
->pfnFree(buf
);
469 static DWORD
SOFTPUB_LoadCertMessage(CRYPT_PROVIDER_DATA
*data
)
471 DWORD err
= ERROR_SUCCESS
;
473 if (data
->pWintrustData
->u
.pCert
&&
474 WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(WINTRUST_CERT_INFO
,
475 data
->pWintrustData
->u
.pCert
->cbStruct
, psCertContext
))
479 CRYPT_PROVIDER_SGNR signer
= { sizeof(signer
), { 0 } };
483 /* Add a signer with nothing but the time to verify, so we can
486 if (WVT_ISINSTRUCT(WINTRUST_CERT_INFO
,
487 data
->pWintrustData
->u
.pCert
->cbStruct
, psftVerifyAsOf
) &&
488 data
->pWintrustData
->u
.pCert
->psftVerifyAsOf
)
489 data
->sftSystemTime
= signer
.sftVerifyAsOf
;
494 GetSystemTime(&sysTime
);
495 SystemTimeToFileTime(&sysTime
, &signer
.sftVerifyAsOf
);
497 ret
= data
->psPfns
->pfnAddSgnr2Chain(data
, FALSE
, 0, &signer
);
500 ret
= data
->psPfns
->pfnAddCert2Chain(data
, 0, FALSE
, 0,
501 data
->pWintrustData
->u
.pCert
->psCertContext
);
502 if (WVT_ISINSTRUCT(WINTRUST_CERT_INFO
,
503 data
->pWintrustData
->u
.pCert
->cbStruct
, pahStores
))
505 ret
&& i
< data
->pWintrustData
->u
.pCert
->chStores
; i
++)
506 ret
= data
->psPfns
->pfnAddStore2Chain(data
,
507 data
->pWintrustData
->u
.pCert
->pahStores
[i
]);
510 err
= GetLastError();
514 err
= ERROR_INVALID_PARAMETER
;
518 static DWORD
SOFTPUB_LoadFileMessage(CRYPT_PROVIDER_DATA
*data
)
520 DWORD err
= ERROR_SUCCESS
;
522 if (!data
->pWintrustData
->u
.pFile
)
524 err
= ERROR_INVALID_PARAMETER
;
527 err
= SOFTPUB_OpenFile(data
);
530 err
= SOFTPUB_GetFileSubject(data
);
533 err
= SOFTPUB_GetSIP(data
);
536 err
= SOFTPUB_GetMessageFromFile(data
, data
->pWintrustData
->u
.pFile
->hFile
,
537 data
->pWintrustData
->u
.pFile
->pcwszFilePath
);
540 err
= SOFTPUB_CreateStoreFromMessage(data
);
543 err
= SOFTPUB_DecodeInnerContent(data
);
546 err
= SOFTPUB_VerifyImageHash(data
, data
->pWintrustData
->u
.pFile
->hFile
);
549 if (err
&& data
->fOpenedFile
&& data
->pWintrustData
->u
.pFile
)
551 /* The caller won't expect the file to be open on failure, so close it.
553 CloseHandle(data
->pWintrustData
->u
.pFile
->hFile
);
554 data
->pWintrustData
->u
.pFile
->hFile
= INVALID_HANDLE_VALUE
;
555 data
->fOpenedFile
= FALSE
;
560 static DWORD
SOFTPUB_LoadCatalogMessage(CRYPT_PROVIDER_DATA
*data
)
563 HANDLE catalog
= INVALID_HANDLE_VALUE
;
565 if (!data
->pWintrustData
->u
.pCatalog
)
567 SetLastError(ERROR_INVALID_PARAMETER
);
570 catalog
= CreateFileW(data
->pWintrustData
->u
.pCatalog
->pcwszCatalogFilePath
,
571 GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
,
573 if (catalog
== INVALID_HANDLE_VALUE
)
574 return GetLastError();
575 if (!CryptSIPRetrieveSubjectGuid(
576 data
->pWintrustData
->u
.pCatalog
->pcwszCatalogFilePath
, catalog
,
577 &data
->u
.pPDSip
->gSubject
))
579 err
= GetLastError();
582 err
= SOFTPUB_GetSIP(data
);
585 err
= SOFTPUB_GetMessageFromFile(data
, catalog
,
586 data
->pWintrustData
->u
.pCatalog
->pcwszCatalogFilePath
);
589 err
= SOFTPUB_CreateStoreFromMessage(data
);
592 err
= SOFTPUB_DecodeInnerContent(data
);
593 /* FIXME: this loads the catalog file, but doesn't validate the member. */
595 CloseHandle(catalog
);
599 HRESULT WINAPI
SoftpubLoadMessage(CRYPT_PROVIDER_DATA
*data
)
601 DWORD err
= ERROR_SUCCESS
;
603 TRACE("(%p)\n", data
);
605 if (!data
->padwTrustStepErrors
)
608 switch (data
->pWintrustData
->dwUnionChoice
)
610 case WTD_CHOICE_CERT
:
611 err
= SOFTPUB_LoadCertMessage(data
);
613 case WTD_CHOICE_FILE
:
614 err
= SOFTPUB_LoadFileMessage(data
);
616 case WTD_CHOICE_CATALOG
:
617 err
= SOFTPUB_LoadCatalogMessage(data
);
620 FIXME("unimplemented for %ld\n", data
->pWintrustData
->dwUnionChoice
);
621 err
= ERROR_INVALID_PARAMETER
;
625 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_OBJPROV
] = err
;
626 TRACE("returning %ld (%08lx)\n", !err
? S_OK
: S_FALSE
,
627 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_OBJPROV
]);
628 return !err
? S_OK
: S_FALSE
;
631 static CMSG_SIGNER_INFO
*WINTRUST_GetSigner(CRYPT_PROVIDER_DATA
*data
,
635 CMSG_SIGNER_INFO
*signerInfo
= NULL
;
638 ret
= CryptMsgGetParam(data
->hMsg
, CMSG_SIGNER_INFO_PARAM
, signerIdx
,
642 signerInfo
= data
->psPfns
->pfnAlloc(size
);
645 ret
= CryptMsgGetParam(data
->hMsg
, CMSG_SIGNER_INFO_PARAM
,
646 signerIdx
, signerInfo
, &size
);
649 data
->psPfns
->pfnFree(signerInfo
);
654 SetLastError(ERROR_OUTOFMEMORY
);
659 static BOOL
WINTRUST_GetTimeFromCounterSigner(
660 const CMSG_CMS_SIGNER_INFO
*counterSignerInfo
, FILETIME
*time
)
663 BOOL foundTimeStamp
= FALSE
;
665 for (i
= 0; !foundTimeStamp
&& i
< counterSignerInfo
->AuthAttrs
.cAttr
; i
++)
667 if (!strcmp(counterSignerInfo
->AuthAttrs
.rgAttr
[i
].pszObjId
,
668 szOID_RSA_signingTime
))
670 const CRYPT_ATTRIBUTE
*attr
=
671 &counterSignerInfo
->AuthAttrs
.rgAttr
[i
];
674 for (j
= 0; !foundTimeStamp
&& j
< attr
->cValue
; j
++)
676 static const DWORD encoding
= X509_ASN_ENCODING
|
678 DWORD size
= sizeof(FILETIME
);
680 foundTimeStamp
= CryptDecodeObjectEx(encoding
,
682 attr
->rgValue
[j
].pbData
, attr
->rgValue
[j
].cbData
, 0, NULL
,
687 return foundTimeStamp
;
690 static LPCSTR
filetime_to_str(const FILETIME
*time
)
692 static char date
[80];
693 char dateFmt
[80]; /* sufficient for all versions of LOCALE_SSHORTDATE */
696 if (!time
) return NULL
;
698 GetLocaleInfoA(LOCALE_SYSTEM_DEFAULT
, LOCALE_SSHORTDATE
, dateFmt
, ARRAY_SIZE(dateFmt
));
699 FileTimeToSystemTime(time
, &sysTime
);
700 GetDateFormatA(LOCALE_SYSTEM_DEFAULT
, 0, &sysTime
, dateFmt
, date
, ARRAY_SIZE(date
));
704 static FILETIME
WINTRUST_GetTimeFromSigner(const CRYPT_PROVIDER_DATA
*data
,
705 const CMSG_SIGNER_INFO
*signerInfo
)
709 BOOL foundTimeStamp
= FALSE
;
711 for (i
= 0; !foundTimeStamp
&& i
< signerInfo
->UnauthAttrs
.cAttr
; i
++)
713 if (!strcmp(signerInfo
->UnauthAttrs
.rgAttr
[i
].pszObjId
,
714 szOID_RSA_counterSign
))
716 const CRYPT_ATTRIBUTE
*attr
= &signerInfo
->UnauthAttrs
.rgAttr
[i
];
719 for (j
= 0; j
< attr
->cValue
; j
++)
721 static const DWORD encoding
= X509_ASN_ENCODING
|
723 CMSG_CMS_SIGNER_INFO
*counterSignerInfo
;
725 BOOL ret
= CryptDecodeObjectEx(encoding
, CMS_SIGNER_INFO
,
726 attr
->rgValue
[j
].pbData
, attr
->rgValue
[j
].cbData
,
727 CRYPT_DECODE_ALLOC_FLAG
, NULL
, &counterSignerInfo
, &size
);
730 /* FIXME: need to verify countersigner signature too */
731 foundTimeStamp
= WINTRUST_GetTimeFromCounterSigner(
732 counterSignerInfo
, &time
);
733 LocalFree(counterSignerInfo
);
740 TRACE("returning system time %s\n",
741 filetime_to_str(&data
->sftSystemTime
));
742 time
= data
->sftSystemTime
;
745 TRACE("returning time from message %s\n", filetime_to_str(&time
));
749 static DWORD
WINTRUST_SaveSigner(CRYPT_PROVIDER_DATA
*data
, DWORD signerIdx
)
752 CMSG_SIGNER_INFO
*signerInfo
= WINTRUST_GetSigner(data
, signerIdx
);
756 CRYPT_PROVIDER_SGNR sgnr
= { sizeof(sgnr
), { 0 } };
758 sgnr
.psSigner
= signerInfo
;
759 sgnr
.sftVerifyAsOf
= WINTRUST_GetTimeFromSigner(data
, signerInfo
);
760 if (!data
->psPfns
->pfnAddSgnr2Chain(data
, FALSE
, signerIdx
, &sgnr
))
761 err
= GetLastError();
766 err
= GetLastError();
770 static CERT_INFO
*WINTRUST_GetSignerCertInfo(CRYPT_PROVIDER_DATA
*data
,
774 CERT_INFO
*certInfo
= NULL
;
777 ret
= CryptMsgGetParam(data
->hMsg
, CMSG_SIGNER_CERT_INFO_PARAM
, signerIdx
,
781 certInfo
= data
->psPfns
->pfnAlloc(size
);
784 ret
= CryptMsgGetParam(data
->hMsg
, CMSG_SIGNER_CERT_INFO_PARAM
,
785 signerIdx
, certInfo
, &size
);
788 data
->psPfns
->pfnFree(certInfo
);
793 SetLastError(ERROR_OUTOFMEMORY
);
798 static DWORD
WINTRUST_VerifySigner(CRYPT_PROVIDER_DATA
*data
, DWORD signerIdx
)
801 CERT_INFO
*certInfo
= WINTRUST_GetSignerCertInfo(data
, signerIdx
);
805 PCCERT_CONTEXT subject
= CertGetSubjectCertificateFromStore(
806 data
->pahStores
[0], data
->dwEncoding
, certInfo
);
810 CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA para
= { sizeof(para
), 0,
811 signerIdx
, CMSG_VERIFY_SIGNER_CERT
, (LPVOID
)subject
};
813 if (!CryptMsgControl(data
->hMsg
, 0, CMSG_CTRL_VERIFY_SIGNATURE_EX
,
815 err
= TRUST_E_CERT_SIGNATURE
;
818 data
->psPfns
->pfnAddCert2Chain(data
, signerIdx
, FALSE
, 0,
822 CertFreeCertificateContext(subject
);
825 err
= TRUST_E_NO_SIGNER_CERT
;
826 data
->psPfns
->pfnFree(certInfo
);
829 err
= GetLastError();
833 static void load_secondary_signatures(CRYPT_PROVIDER_DATA
*data
, HCRYPTMSG msg
)
835 CRYPT_PROVIDER_SIGSTATE
*s
= data
->pSigState
;
836 CRYPT_ATTRIBUTES
*attrs
;
840 if (!CryptMsgGetParam(msg
, CMSG_SIGNER_UNAUTH_ATTR_PARAM
, 0, NULL
, &size
))
843 if (!(attrs
= data
->psPfns
->pfnAlloc(size
)))
848 if (!CryptMsgGetParam(msg
, CMSG_SIGNER_UNAUTH_ATTR_PARAM
, 0, attrs
, &size
))
851 for (i
= 0; i
< attrs
->cAttr
; ++i
)
853 if (strcmp(attrs
->rgAttr
[i
].pszObjId
, szOID_NESTED_SIGNATURE
))
856 if (!(s
->rhSecondarySigs
= data
->psPfns
->pfnAlloc(attrs
->rgAttr
[i
].cValue
* sizeof(*s
->rhSecondarySigs
))))
861 s
->cSecondarySigs
= 0;
862 for (j
= 0; j
< attrs
->rgAttr
[i
].cValue
; ++j
)
864 if (!(msg
= CryptMsgOpenToDecode(X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
, 0, 0, 0, NULL
, NULL
)))
866 ERR("Could not create crypt message.\n");
869 if (!CryptMsgUpdate(msg
, attrs
->rgAttr
[i
].rgValue
[j
].pbData
, attrs
->rgAttr
[i
].rgValue
[j
].cbData
, TRUE
))
871 ERR("Could not update crypt message, err %lu.\n", GetLastError());
875 s
->rhSecondarySigs
[j
] = msg
;
881 data
->psPfns
->pfnFree(attrs
);
884 HRESULT WINAPI
SoftpubLoadSignature(CRYPT_PROVIDER_DATA
*data
)
886 DWORD err
= ERROR_SUCCESS
;
888 TRACE("(%p)\n", data
);
890 if (!data
->padwTrustStepErrors
)
895 /* We did not initialize this, probably an unsupported usage. */
896 FIXME("pSigState %p already initialized.\n", data
->pSigState
);
898 if (!(data
->pSigState
= data
->psPfns
->pfnAlloc(sizeof(*data
->pSigState
))))
900 err
= ERROR_OUTOFMEMORY
;
904 data
->pSigState
->cbStruct
= sizeof(*data
->pSigState
);
905 data
->pSigState
->fSupportMultiSig
= TRUE
;
906 data
->pSigState
->dwCryptoPolicySupport
= WSS_SIGTRUST_SUPPORT
| WSS_OBJTRUST_SUPPORT
| WSS_CERTTRUST_SUPPORT
;
909 data
->pSigState
->hPrimarySig
= CryptMsgDuplicate(data
->hMsg
);
910 load_secondary_signatures(data
, data
->pSigState
->hPrimarySig
);
912 if (data
->pSigSettings
)
914 if (data
->pSigSettings
->dwFlags
& WSS_GET_SECONDARY_SIG_COUNT
)
915 data
->pSigSettings
->cSecondarySigs
= data
->pSigState
->cSecondarySigs
;
919 if (!err
&& data
->hMsg
)
921 DWORD signerCount
, size
;
923 size
= sizeof(signerCount
);
924 if (CryptMsgGetParam(data
->hMsg
, CMSG_SIGNER_COUNT_PARAM
, 0,
925 &signerCount
, &size
))
930 for (i
= 0; !err
&& i
< signerCount
; i
++)
932 if (!(err
= WINTRUST_SaveSigner(data
, i
)))
933 err
= WINTRUST_VerifySigner(data
, i
);
937 err
= TRUST_E_NOSIGNATURE
;
941 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_SIGPROV
] = err
;
942 return !err
? S_OK
: S_FALSE
;
945 static DWORD
WINTRUST_TrustStatusToConfidence(DWORD errorStatus
)
947 DWORD confidence
= 0;
950 if (!(errorStatus
& CERT_TRUST_IS_NOT_SIGNATURE_VALID
))
951 confidence
|= CERT_CONFIDENCE_SIG
;
952 if (!(errorStatus
& CERT_TRUST_IS_NOT_TIME_VALID
))
953 confidence
|= CERT_CONFIDENCE_TIME
;
954 if (!(errorStatus
& CERT_TRUST_IS_NOT_TIME_NESTED
))
955 confidence
|= CERT_CONFIDENCE_TIMENEST
;
959 BOOL WINAPI
SoftpubCheckCert(CRYPT_PROVIDER_DATA
*data
, DWORD idxSigner
,
960 BOOL fCounterSignerChain
, DWORD idxCounterSigner
)
964 TRACE("(%p, %ld, %d, %ld)\n", data
, idxSigner
, fCounterSignerChain
,
967 if (fCounterSignerChain
)
969 FIXME("unimplemented for counter signers\n");
974 PCERT_SIMPLE_CHAIN simpleChain
=
975 data
->pasSigners
[idxSigner
].pChainContext
->rgpChain
[0];
979 for (i
= 0; i
< simpleChain
->cElement
; i
++)
982 data
->pasSigners
[idxSigner
].pasCertChain
[i
].dwConfidence
=
983 WINTRUST_TrustStatusToConfidence(
984 simpleChain
->rgpElement
[i
]->TrustStatus
.dwErrorStatus
);
985 /* Set additional flags */
986 if (!(simpleChain
->rgpElement
[i
]->TrustStatus
.dwErrorStatus
&
987 CERT_TRUST_IS_UNTRUSTED_ROOT
))
988 data
->pasSigners
[idxSigner
].pasCertChain
[i
].fTrustedRoot
= TRUE
;
989 if (simpleChain
->rgpElement
[i
]->TrustStatus
.dwInfoStatus
&
990 CERT_TRUST_IS_SELF_SIGNED
)
991 data
->pasSigners
[idxSigner
].pasCertChain
[i
].fSelfSigned
= TRUE
;
992 if (simpleChain
->rgpElement
[i
]->TrustStatus
.dwErrorStatus
&
993 CERT_TRUST_IS_CYCLIC
)
994 data
->pasSigners
[idxSigner
].pasCertChain
[i
].fIsCyclic
= TRUE
;
1000 static DWORD
WINTRUST_TrustStatusToError(DWORD errorStatus
)
1004 if (errorStatus
& CERT_TRUST_IS_NOT_SIGNATURE_VALID
)
1005 error
= TRUST_E_CERT_SIGNATURE
;
1006 else if (errorStatus
& CERT_TRUST_IS_UNTRUSTED_ROOT
)
1007 error
= CERT_E_UNTRUSTEDROOT
;
1008 else if (errorStatus
& CERT_TRUST_IS_NOT_TIME_VALID
)
1009 error
= CERT_E_EXPIRED
;
1010 else if (errorStatus
& CERT_TRUST_IS_NOT_TIME_NESTED
)
1011 error
= CERT_E_VALIDITYPERIODNESTING
;
1012 else if (errorStatus
& CERT_TRUST_IS_REVOKED
)
1013 error
= CERT_E_REVOKED
;
1014 else if (errorStatus
& CERT_TRUST_IS_OFFLINE_REVOCATION
||
1015 errorStatus
& CERT_TRUST_REVOCATION_STATUS_UNKNOWN
)
1016 error
= CERT_E_REVOCATION_FAILURE
;
1017 else if (errorStatus
& CERT_TRUST_IS_NOT_VALID_FOR_USAGE
)
1018 error
= CERT_E_WRONG_USAGE
;
1019 else if (errorStatus
& CERT_TRUST_IS_CYCLIC
)
1020 error
= CERT_E_CHAINING
;
1021 else if (errorStatus
& CERT_TRUST_INVALID_EXTENSION
)
1022 error
= CERT_E_CRITICAL
;
1023 else if (errorStatus
& CERT_TRUST_INVALID_POLICY_CONSTRAINTS
)
1024 error
= CERT_E_INVALID_POLICY
;
1025 else if (errorStatus
& CERT_TRUST_INVALID_BASIC_CONSTRAINTS
)
1026 error
= TRUST_E_BASIC_CONSTRAINTS
;
1027 else if (errorStatus
& CERT_TRUST_INVALID_NAME_CONSTRAINTS
||
1028 errorStatus
& CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT
||
1029 errorStatus
& CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT
||
1030 errorStatus
& CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT
||
1031 errorStatus
& CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT
)
1032 error
= CERT_E_INVALID_NAME
;
1033 else if (errorStatus
& CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY
)
1034 error
= CERT_E_INVALID_POLICY
;
1035 else if (errorStatus
)
1037 FIXME("unknown error status %08lx\n", errorStatus
);
1038 error
= TRUST_E_SYSTEM_ERROR
;
1045 static DWORD
WINTRUST_CopyChain(CRYPT_PROVIDER_DATA
*data
, DWORD signerIdx
)
1048 PCERT_SIMPLE_CHAIN simpleChain
=
1049 data
->pasSigners
[signerIdx
].pChainContext
->rgpChain
[0];
1051 data
->pasSigners
[signerIdx
].pasCertChain
[0].dwConfidence
=
1052 WINTRUST_TrustStatusToConfidence(
1053 simpleChain
->rgpElement
[0]->TrustStatus
.dwErrorStatus
);
1054 data
->pasSigners
[signerIdx
].pasCertChain
[0].pChainElement
=
1055 simpleChain
->rgpElement
[0];
1056 err
= ERROR_SUCCESS
;
1057 for (i
= 1; !err
&& i
< simpleChain
->cElement
; i
++)
1059 if (data
->psPfns
->pfnAddCert2Chain(data
, signerIdx
, FALSE
, 0,
1060 simpleChain
->rgpElement
[i
]->pCertContext
))
1062 data
->pasSigners
[signerIdx
].pasCertChain
[i
].pChainElement
=
1063 simpleChain
->rgpElement
[i
];
1064 data
->pasSigners
[signerIdx
].pasCertChain
[i
].dwConfidence
=
1065 WINTRUST_TrustStatusToConfidence(
1066 simpleChain
->rgpElement
[i
]->TrustStatus
.dwErrorStatus
);
1069 err
= GetLastError();
1071 data
->pasSigners
[signerIdx
].pasCertChain
[simpleChain
->cElement
- 1].dwError
1072 = WINTRUST_TrustStatusToError(
1073 simpleChain
->rgpElement
[simpleChain
->cElement
- 1]->
1074 TrustStatus
.dwErrorStatus
);
1078 static void WINTRUST_CreateChainPolicyCreateInfo(
1079 const CRYPT_PROVIDER_DATA
*data
, PWTD_GENERIC_CHAIN_POLICY_CREATE_INFO info
,
1080 PCERT_CHAIN_PARA chainPara
)
1082 chainPara
->cbSize
= sizeof(CERT_CHAIN_PARA
);
1083 if (data
->pRequestUsage
)
1084 chainPara
->RequestedUsage
= *data
->pRequestUsage
;
1087 chainPara
->RequestedUsage
.dwType
= 0;
1088 chainPara
->RequestedUsage
.Usage
.cUsageIdentifier
= 0;
1090 info
->u
.cbSize
= sizeof(WTD_GENERIC_CHAIN_POLICY_CREATE_INFO
);
1091 info
->hChainEngine
= NULL
;
1092 info
->pChainPara
= chainPara
;
1093 if (data
->dwProvFlags
& CPD_REVOCATION_CHECK_END_CERT
)
1094 info
->dwFlags
= CERT_CHAIN_REVOCATION_CHECK_END_CERT
;
1095 else if (data
->dwProvFlags
& CPD_REVOCATION_CHECK_CHAIN
)
1096 info
->dwFlags
= CERT_CHAIN_REVOCATION_CHECK_CHAIN
;
1097 else if (data
->dwProvFlags
& CPD_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT
)
1098 info
->dwFlags
= CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT
;
1101 info
->pvReserved
= NULL
;
1104 static DWORD
WINTRUST_CreateChainForSigner(CRYPT_PROVIDER_DATA
*data
,
1105 DWORD signer
, PWTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo
,
1106 PCERT_CHAIN_PARA chainPara
)
1108 DWORD err
= ERROR_SUCCESS
;
1109 HCERTSTORE store
= NULL
;
1113 store
= CertOpenStore(CERT_STORE_PROV_COLLECTION
, 0, 0,
1114 CERT_STORE_CREATE_NEW_FLAG
, NULL
);
1119 for (i
= 0; i
< data
->chStores
; i
++)
1120 CertAddStoreToCollection(store
, data
->pahStores
[i
], 0, 0);
1123 err
= GetLastError();
1127 /* Expect the end certificate for each signer to be the only cert in
1130 if (data
->pasSigners
[signer
].csCertChain
)
1134 /* Create a certificate chain for each signer */
1135 ret
= CertGetCertificateChain(createInfo
->hChainEngine
,
1136 data
->pasSigners
[signer
].pasCertChain
[0].pCert
,
1137 &data
->pasSigners
[signer
].sftVerifyAsOf
, store
,
1138 chainPara
, createInfo
->dwFlags
, createInfo
->pvReserved
,
1139 &data
->pasSigners
[signer
].pChainContext
);
1142 if (data
->pasSigners
[signer
].pChainContext
->cChain
!= 1)
1144 FIXME("unimplemented for more than 1 simple chain\n");
1149 if (!(err
= WINTRUST_CopyChain(data
, signer
)))
1151 if (data
->psPfns
->pfnCertCheckPolicy
)
1153 ret
= data
->psPfns
->pfnCertCheckPolicy(data
, signer
,
1156 err
= GetLastError();
1160 "no cert check policy, skipping policy check\n");
1165 err
= GetLastError();
1167 CertCloseStore(store
, 0);
1172 HRESULT WINAPI
WintrustCertificateTrust(CRYPT_PROVIDER_DATA
*data
)
1176 TRACE("(%p)\n", data
);
1178 if (!data
->csSigners
)
1179 err
= TRUST_E_NOSIGNATURE
;
1183 WTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo
;
1184 CERT_CHAIN_PARA chainPara
;
1186 WINTRUST_CreateChainPolicyCreateInfo(data
, &createInfo
, &chainPara
);
1187 err
= ERROR_SUCCESS
;
1188 for (i
= 0; !err
&& i
< data
->csSigners
; i
++)
1189 err
= WINTRUST_CreateChainForSigner(data
, i
, &createInfo
,
1193 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_CERTPROV
] = err
;
1194 TRACE("returning %ld (%08lx)\n", !err
? S_OK
: S_FALSE
,
1195 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_CERTPROV
]);
1196 return !err
? S_OK
: S_FALSE
;
1199 HRESULT WINAPI
GenericChainCertificateTrust(CRYPT_PROVIDER_DATA
*data
)
1202 WTD_GENERIC_CHAIN_POLICY_DATA
*policyData
=
1203 data
->pWintrustData
->pPolicyCallbackData
;
1205 TRACE("(%p)\n", data
);
1207 if (policyData
&& policyData
->u
.cbSize
!=
1208 sizeof(WTD_GENERIC_CHAIN_POLICY_CREATE_INFO
))
1210 err
= ERROR_INVALID_PARAMETER
;
1213 if (!data
->csSigners
)
1214 err
= TRUST_E_NOSIGNATURE
;
1218 WTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo
, *pCreateInfo
;
1219 CERT_CHAIN_PARA chainPara
, *pChainPara
;
1223 pCreateInfo
= policyData
->pSignerChainInfo
;
1224 pChainPara
= pCreateInfo
->pChainPara
;
1228 WINTRUST_CreateChainPolicyCreateInfo(data
, &createInfo
, &chainPara
);
1229 pChainPara
= &chainPara
;
1230 pCreateInfo
= &createInfo
;
1232 err
= ERROR_SUCCESS
;
1233 for (i
= 0; !err
&& i
< data
->csSigners
; i
++)
1234 err
= WINTRUST_CreateChainForSigner(data
, i
, pCreateInfo
,
1240 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_CERTPROV
] = err
;
1241 TRACE("returning %ld (%08lx)\n", !err
? S_OK
: S_FALSE
,
1242 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_CERTPROV
]);
1243 return !err
? S_OK
: S_FALSE
;
1246 HRESULT WINAPI
SoftpubAuthenticode(CRYPT_PROVIDER_DATA
*data
)
1249 CERT_CHAIN_POLICY_STATUS policyStatus
= { sizeof(policyStatus
), 0 };
1251 TRACE("(%p)\n", data
);
1253 if (data
->pWintrustData
->dwUIChoice
!= WTD_UI_NONE
)
1254 FIXME("unimplemented for UI choice %ld\n",
1255 data
->pWintrustData
->dwUIChoice
);
1256 if (!data
->csSigners
)
1259 policyStatus
.dwError
= TRUST_E_NOSIGNATURE
;
1266 for (i
= 0; ret
&& i
< data
->csSigners
; i
++)
1269 DWORD size
= sizeof(hash
);
1271 /* First make sure cert isn't disallowed */
1272 if ((ret
= CertGetCertificateContextProperty(
1273 data
->pasSigners
[i
].pasCertChain
[0].pCert
,
1274 CERT_SIGNATURE_HASH_PROP_ID
, hash
, &size
)))
1276 static const WCHAR disallowedW
[] =
1277 { 'D','i','s','a','l','l','o','w','e','d',0 };
1278 HCERTSTORE disallowed
= CertOpenStore(CERT_STORE_PROV_SYSTEM_W
,
1279 X509_ASN_ENCODING
, 0, CERT_SYSTEM_STORE_CURRENT_USER
,
1284 PCCERT_CONTEXT found
= CertFindCertificateInStore(
1285 disallowed
, X509_ASN_ENCODING
, 0, CERT_FIND_SIGNATURE_HASH
,
1290 /* Disallowed! Can't verify it. */
1291 policyStatus
.dwError
= TRUST_E_SUBJECT_NOT_TRUSTED
;
1293 CertFreeCertificateContext(found
);
1295 CertCloseStore(disallowed
, 0);
1300 CERT_CHAIN_POLICY_PARA policyPara
= { sizeof(policyPara
), 0 };
1302 if (data
->dwRegPolicySettings
& WTPF_TRUSTTEST
)
1303 policyPara
.dwFlags
|= CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG
;
1304 if (data
->dwRegPolicySettings
& WTPF_TESTCANBEVALID
)
1305 policyPara
.dwFlags
|= CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG
;
1306 if (data
->dwRegPolicySettings
& WTPF_IGNOREEXPIRATION
)
1307 policyPara
.dwFlags
|=
1308 CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG
|
1309 CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG
|
1310 CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG
;
1311 if (data
->dwRegPolicySettings
& WTPF_IGNOREREVOKATION
)
1312 policyPara
.dwFlags
|=
1313 CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG
|
1314 CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG
|
1315 CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG
|
1316 CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG
;
1317 CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_AUTHENTICODE
,
1318 data
->pasSigners
[i
].pChainContext
, &policyPara
, &policyStatus
);
1319 if (policyStatus
.dwError
!= NO_ERROR
)
1325 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_POLICYPROV
] =
1326 policyStatus
.dwError
;
1327 TRACE("returning %ld (%08lx)\n", ret
? S_OK
: S_FALSE
,
1328 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_POLICYPROV
]);
1329 return ret
? S_OK
: S_FALSE
;
1332 static HRESULT WINAPI
WINTRUST_DefaultPolicy(CRYPT_PROVIDER_DATA
*pProvData
,
1333 DWORD dwStepError
, DWORD dwRegPolicySettings
, DWORD cSigner
,
1334 PWTD_GENERIC_CHAIN_POLICY_SIGNER_INFO rgpSigner
, void *pvPolicyArg
)
1337 CERT_CHAIN_POLICY_STATUS policyStatus
= { sizeof(policyStatus
), 0 };
1339 for (i
= 0; !policyStatus
.dwError
&& i
< cSigner
; i
++)
1341 CERT_CHAIN_POLICY_PARA policyPara
= { sizeof(policyPara
), 0 };
1343 if (dwRegPolicySettings
& WTPF_IGNOREEXPIRATION
)
1344 policyPara
.dwFlags
|=
1345 CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG
|
1346 CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG
|
1347 CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG
;
1348 if (dwRegPolicySettings
& WTPF_IGNOREREVOKATION
)
1349 policyPara
.dwFlags
|=
1350 CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG
|
1351 CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG
|
1352 CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG
|
1353 CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG
;
1354 CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE
,
1355 rgpSigner
[i
].pChainContext
, &policyPara
, &policyStatus
);
1357 return policyStatus
.dwError
;
1360 HRESULT WINAPI
GenericChainFinalProv(CRYPT_PROVIDER_DATA
*data
)
1362 HRESULT err
= NO_ERROR
; /* not a typo, MS confused the types */
1363 WTD_GENERIC_CHAIN_POLICY_DATA
*policyData
=
1364 data
->pWintrustData
->pPolicyCallbackData
;
1366 TRACE("(%p)\n", data
);
1368 if (data
->pWintrustData
->dwUIChoice
!= WTD_UI_NONE
)
1369 FIXME("unimplemented for UI choice %ld\n",
1370 data
->pWintrustData
->dwUIChoice
);
1371 if (!data
->csSigners
)
1372 err
= TRUST_E_NOSIGNATURE
;
1375 PFN_WTD_GENERIC_CHAIN_POLICY_CALLBACK policyCallback
;
1377 WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO
*signers
= NULL
;
1381 policyCallback
= policyData
->pfnPolicyCallback
;
1382 policyArg
= policyData
->pvPolicyArg
;
1386 policyCallback
= WINTRUST_DefaultPolicy
;
1389 if (data
->csSigners
)
1393 signers
= data
->psPfns
->pfnAlloc(
1394 data
->csSigners
* sizeof(WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO
));
1397 for (i
= 0; i
< data
->csSigners
; i
++)
1399 signers
[i
].u
.cbSize
=
1400 sizeof(WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO
);
1401 signers
[i
].pChainContext
=
1402 data
->pasSigners
[i
].pChainContext
;
1403 signers
[i
].dwSignerType
= data
->pasSigners
[i
].dwSignerType
;
1404 signers
[i
].pMsgSignerInfo
= data
->pasSigners
[i
].psSigner
;
1405 signers
[i
].dwError
= data
->pasSigners
[i
].dwError
;
1406 if (data
->pasSigners
[i
].csCounterSigners
)
1407 FIXME("unimplemented for counter signers\n");
1408 signers
[i
].cCounterSigner
= 0;
1409 signers
[i
].rgpCounterSigner
= NULL
;
1413 err
= ERROR_OUTOFMEMORY
;
1415 if (err
== NO_ERROR
)
1416 err
= policyCallback(data
, TRUSTERROR_STEP_FINAL_POLICYPROV
,
1417 data
->dwRegPolicySettings
, data
->csSigners
, signers
, policyArg
);
1418 data
->psPfns
->pfnFree(signers
);
1420 if (err
!= NO_ERROR
)
1421 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_POLICYPROV
] = err
;
1422 TRACE("returning %ld (%08lx)\n", err
== NO_ERROR
? S_OK
: S_FALSE
,
1423 data
->padwTrustStepErrors
[TRUSTERROR_STEP_FINAL_POLICYPROV
]);
1424 return err
== NO_ERROR
? S_OK
: S_FALSE
;
1427 HRESULT WINAPI
SoftpubCleanup(CRYPT_PROVIDER_DATA
*data
)
1431 for (i
= 0; i
< data
->csSigners
; i
++)
1433 for (j
= 0; j
< data
->pasSigners
[i
].csCertChain
; j
++)
1434 CertFreeCertificateContext(data
->pasSigners
[i
].pasCertChain
[j
].pCert
);
1435 data
->psPfns
->pfnFree(data
->pasSigners
[i
].pasCertChain
);
1436 data
->psPfns
->pfnFree(data
->pasSigners
[i
].psSigner
);
1437 CertFreeCertificateChain(data
->pasSigners
[i
].pChainContext
);
1439 data
->psPfns
->pfnFree(data
->pasSigners
);
1441 for (i
= 0; i
< data
->chStores
; i
++)
1442 CertCloseStore(data
->pahStores
[i
], 0);
1443 data
->psPfns
->pfnFree(data
->pahStores
);
1447 data
->psPfns
->pfnFree(data
->u
.pPDSip
->pSip
);
1448 data
->psPfns
->pfnFree(data
->u
.pPDSip
->pCATSip
);
1449 data
->psPfns
->pfnFree(data
->u
.pPDSip
->psSipSubjectInfo
);
1450 data
->psPfns
->pfnFree(data
->u
.pPDSip
->psSipCATSubjectInfo
);
1451 data
->psPfns
->pfnFree(data
->u
.pPDSip
->psIndirectData
);
1454 if (WVT_ISINSTRUCT(CRYPT_PROVIDER_DATA
, data
->cbStruct
, pSigState
) && data
->pSigState
)
1456 CryptMsgClose(data
->pSigState
->hPrimarySig
);
1457 for (i
= 0; i
< data
->pSigState
->cSecondarySigs
; ++i
)
1458 CryptMsgClose(data
->pSigState
->rhSecondarySigs
[i
]);
1459 data
->psPfns
->pfnFree(data
->pSigState
);
1461 CryptMsgClose(data
->hMsg
);
1463 if (data
->fOpenedFile
&&
1464 data
->pWintrustData
->dwUnionChoice
== WTD_CHOICE_FILE
&&
1465 data
->pWintrustData
->u
.pFile
)
1467 CloseHandle(data
->pWintrustData
->u
.pFile
->hFile
);
1468 data
->pWintrustData
->u
.pFile
->hFile
= INVALID_HANDLE_VALUE
;
1469 data
->fOpenedFile
= FALSE
;
1475 HRESULT WINAPI
HTTPSCertificateTrust(CRYPT_PROVIDER_DATA
*data
)
1477 FIXME("(%p)\n", data
);
1481 HRESULT WINAPI
HTTPSFinalProv(CRYPT_PROVIDER_DATA
*data
)
1483 FIXME("(%p)\n", data
);