2 * Copyright 2007 Juan Lang
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define NONAMELESSUNION
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
31 HRESULT WINAPI SoftpubDefCertInit(CRYPT_PROVIDER_DATA *data)
33 HRESULT ret = S_FALSE;
35 TRACE("(%p)\n", data);
37 if (data->padwTrustStepErrors &&
38 !data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT])
40 TRACE("returning %08x\n", ret);
44 HRESULT WINAPI SoftpubInitialize(CRYPT_PROVIDER_DATA *data)
46 HRESULT ret = S_FALSE;
48 TRACE("(%p)\n", data);
50 if (data->padwTrustStepErrors &&
51 !data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT])
53 TRACE("returning %08x\n", ret);
57 /* Assumes data->pWintrustData->u.pFile exists. Makes sure a file handle is
60 static BOOL SOFTPUB_OpenFile(CRYPT_PROVIDER_DATA *data)
64 /* PSDK implies that all values should be initialized to NULL, so callers
65 * typically have hFile as NULL rather than INVALID_HANDLE_VALUE. Check
68 if (!data->pWintrustData->u.pFile->hFile ||
69 data->pWintrustData->u.pFile->hFile == INVALID_HANDLE_VALUE)
71 data->pWintrustData->u.pFile->hFile =
72 CreateFileW(data->pWintrustData->u.pFile->pcwszFilePath, GENERIC_READ,
73 FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
74 if (data->pWintrustData->u.pFile->hFile != INVALID_HANDLE_VALUE)
75 data->fOpenedFile = TRUE;
80 GetFileTime(data->pWintrustData->u.pFile->hFile, &data->sftSystemTime,
82 TRACE("returning %d\n", ret);
86 /* Assumes data->pWintrustData->u.pFile exists. Sets data->pPDSip->gSubject to
87 * the file's subject GUID.
89 static BOOL SOFTPUB_GetFileSubject(CRYPT_PROVIDER_DATA *data)
93 if (!data->pWintrustData->u.pFile->pgKnownSubject)
95 ret = CryptSIPRetrieveSubjectGuid(
96 data->pWintrustData->u.pFile->pcwszFilePath,
97 data->pWintrustData->u.pFile->hFile,
98 &data->u.pPDSip->gSubject);
102 data->u.pPDSip->gSubject = *data->pWintrustData->u.pFile->pgKnownSubject;
105 TRACE("returning %d\n", ret);
109 /* Assumes data->u.pPDSip exists, and its gSubject member set.
110 * Allocates data->u.pPDSip->pSip and loads it, if possible.
112 static BOOL SOFTPUB_GetSIP(CRYPT_PROVIDER_DATA *data)
116 data->u.pPDSip->pSip = data->psPfns->pfnAlloc(sizeof(SIP_DISPATCH_INFO));
117 if (data->u.pPDSip->pSip)
118 ret = CryptSIPLoad(&data->u.pPDSip->gSubject, 0, data->u.pPDSip->pSip);
121 SetLastError(ERROR_OUTOFMEMORY);
124 TRACE("returning %d\n", ret);
128 /* Assumes data->u.pPDSip has been loaded, and data->u.pPDSip->pSip allocated.
129 * Calls data->u.pPDSip->pSip->pfGet to construct data->hMsg.
131 static BOOL SOFTPUB_GetMessageFromFile(CRYPT_PROVIDER_DATA *data)
137 data->u.pPDSip->psSipSubjectInfo =
138 data->psPfns->pfnAlloc(sizeof(SIP_SUBJECTINFO));
139 if (!data->u.pPDSip->psSipSubjectInfo)
141 SetLastError(ERROR_OUTOFMEMORY);
145 data->u.pPDSip->psSipSubjectInfo->cbSize = sizeof(SIP_SUBJECTINFO);
146 data->u.pPDSip->psSipSubjectInfo->pgSubjectType = &data->u.pPDSip->gSubject;
147 data->u.pPDSip->psSipSubjectInfo->hFile = data->pWintrustData->u.pFile->hFile;
148 data->u.pPDSip->psSipSubjectInfo->pwsFileName =
149 data->pWintrustData->u.pFile->pcwszFilePath;
150 data->u.pPDSip->psSipSubjectInfo->hProv = data->hProv;
151 ret = data->u.pPDSip->pSip->pfGet(data->u.pPDSip->psSipSubjectInfo,
152 &data->dwEncoding, 0, &size, 0);
155 SetLastError(TRUST_E_NOSIGNATURE);
159 buf = data->psPfns->pfnAlloc(size);
162 SetLastError(ERROR_OUTOFMEMORY);
166 ret = data->u.pPDSip->pSip->pfGet(data->u.pPDSip->psSipSubjectInfo,
167 &data->dwEncoding, 0, &size, buf);
170 data->hMsg = CryptMsgOpenToDecode(data->dwEncoding, 0, 0, data->hProv,
173 ret = CryptMsgUpdate(data->hMsg, buf, size, TRUE);
176 data->psPfns->pfnFree(buf);
177 TRACE("returning %d\n", ret);
181 static BOOL SOFTPUB_CreateStoreFromMessage(CRYPT_PROVIDER_DATA *data)
186 store = CertOpenStore(CERT_STORE_PROV_MSG, data->dwEncoding,
187 data->hProv, CERT_STORE_NO_CRYPT_RELEASE_FLAG, data->hMsg);
190 ret = data->psPfns->pfnAddStore2Chain(data, store);
191 CertCloseStore(store, 0);
193 TRACE("returning %d\n", ret);
197 static DWORD SOFTPUB_DecodeInnerContent(CRYPT_PROVIDER_DATA *data)
203 ret = CryptMsgGetParam(data->hMsg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, NULL,
207 buf = data->psPfns->pfnAlloc(size);
210 SetLastError(ERROR_OUTOFMEMORY);
214 ret = CryptMsgGetParam(data->hMsg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, buf,
218 if (!strcmp((LPCSTR)buf, SPC_INDIRECT_DATA_OBJID))
220 data->psPfns->pfnFree(buf);
222 ret = CryptMsgGetParam(data->hMsg, CMSG_CONTENT_PARAM, 0, NULL, &size);
225 buf = data->psPfns->pfnAlloc(size);
228 SetLastError(ERROR_OUTOFMEMORY);
232 ret = CryptMsgGetParam(data->hMsg, CMSG_CONTENT_PARAM, 0, buf, &size);
235 ret = CryptDecodeObject(data->dwEncoding,
236 SPC_INDIRECT_DATA_CONTENT_STRUCT, buf, size, 0, NULL, &size);
239 data->u.pPDSip->psIndirectData = data->psPfns->pfnAlloc(size);
240 if (!data->u.pPDSip->psIndirectData)
242 SetLastError(ERROR_OUTOFMEMORY);
246 ret = CryptDecodeObject(data->dwEncoding,
247 SPC_INDIRECT_DATA_CONTENT_STRUCT, buf, size, 0,
248 data->u.pPDSip->psIndirectData, &size);
252 FIXME("unimplemented for OID %s\n", (LPCSTR)buf);
253 SetLastError(TRUST_E_SUBJECT_FORM_UNKNOWN);
258 TRACE("returning %d\n", ret);
262 HRESULT WINAPI SoftpubLoadMessage(CRYPT_PROVIDER_DATA *data)
266 TRACE("(%p)\n", data);
268 if (!data->padwTrustStepErrors)
271 switch (data->pWintrustData->dwUnionChoice)
273 case WTD_CHOICE_CERT:
274 if (data->pWintrustData->u.pCert &&
275 data->pWintrustData->u.pCert->cbStruct == sizeof(WINTRUST_CERT_INFO))
279 CRYPT_PROVIDER_SGNR signer = { sizeof(signer), { 0 } };
282 /* Add a signer with nothing but the time to verify, so we can
285 if (data->pWintrustData->u.pCert->psftVerifyAsOf)
286 data->sftSystemTime = signer.sftVerifyAsOf;
291 GetSystemTime(&sysTime);
292 SystemTimeToFileTime(&sysTime, &signer.sftVerifyAsOf);
294 ret = data->psPfns->pfnAddSgnr2Chain(data, FALSE, 0, &signer);
297 ret = data->psPfns->pfnAddCert2Chain(data, 0, FALSE, 0,
298 data->pWintrustData->u.pCert->psCertContext);
301 for (i = 0; ret && i < data->pWintrustData->u.pCert->chStores;
303 ret = data->psPfns->pfnAddStore2Chain(data,
304 data->pWintrustData->u.pCert->pahStores[i]);
308 /* Do nothing!? See the tests */
314 SetLastError(ERROR_INVALID_PARAMETER);
318 case WTD_CHOICE_FILE:
319 if (!data->pWintrustData->u.pFile)
321 SetLastError(ERROR_INVALID_PARAMETER);
325 ret = SOFTPUB_OpenFile(data);
328 ret = SOFTPUB_GetFileSubject(data);
331 ret = SOFTPUB_GetSIP(data);
334 ret = SOFTPUB_GetMessageFromFile(data);
337 ret = SOFTPUB_CreateStoreFromMessage(data);
340 ret = SOFTPUB_DecodeInnerContent(data);
343 FIXME("unimplemented for %d\n", data->pWintrustData->dwUnionChoice);
344 SetLastError(ERROR_INVALID_PARAMETER);
350 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] =
352 TRACE("returning %d (%08x)\n", ret ? S_OK : S_FALSE,
353 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
354 return ret ? S_OK : S_FALSE;
357 static CMSG_SIGNER_INFO *WINTRUST_GetSigner(CRYPT_PROVIDER_DATA *data,
361 CMSG_SIGNER_INFO *signerInfo = NULL;
364 ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_INFO_PARAM, signerIdx,
368 signerInfo = data->psPfns->pfnAlloc(size);
371 ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_INFO_PARAM,
372 signerIdx, signerInfo, &size);
375 data->psPfns->pfnFree(signerInfo);
380 SetLastError(ERROR_OUTOFMEMORY);
385 static BOOL WINTRUST_SaveSigner(CRYPT_PROVIDER_DATA *data, DWORD signerIdx)
388 CMSG_SIGNER_INFO *signerInfo = WINTRUST_GetSigner(data, signerIdx);
392 CRYPT_PROVIDER_SGNR sgnr = { sizeof(sgnr), { 0 } };
394 sgnr.psSigner = signerInfo;
395 sgnr.sftVerifyAsOf = data->sftSystemTime;
396 ret = data->psPfns->pfnAddSgnr2Chain(data, FALSE, signerIdx, &sgnr);
403 static CERT_INFO *WINTRUST_GetSignerCertInfo(CRYPT_PROVIDER_DATA *data,
407 CERT_INFO *certInfo = NULL;
410 ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_CERT_INFO_PARAM, signerIdx,
414 certInfo = data->psPfns->pfnAlloc(size);
417 ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_CERT_INFO_PARAM,
418 signerIdx, certInfo, &size);
421 data->psPfns->pfnFree(certInfo);
426 SetLastError(ERROR_OUTOFMEMORY);
431 static BOOL WINTRUST_VerifySigner(CRYPT_PROVIDER_DATA *data, DWORD signerIdx)
434 CERT_INFO *certInfo = WINTRUST_GetSignerCertInfo(data, signerIdx);
438 PCCERT_CONTEXT subject = CertGetSubjectCertificateFromStore(
439 data->pahStores[0], data->dwEncoding, certInfo);
443 CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA para = { sizeof(para), 0,
444 signerIdx, CMSG_VERIFY_SIGNER_CERT, (LPVOID)subject };
446 ret = CryptMsgControl(data->hMsg, 0, CMSG_CTRL_VERIFY_SIGNATURE_EX,
449 SetLastError(TRUST_E_CERT_SIGNATURE);
451 data->psPfns->pfnAddCert2Chain(data, signerIdx, FALSE, 0,
453 CertFreeCertificateContext(subject);
457 SetLastError(TRUST_E_NO_SIGNER_CERT);
460 data->psPfns->pfnFree(certInfo);
467 HRESULT WINAPI SoftpubLoadSignature(CRYPT_PROVIDER_DATA *data)
471 TRACE("(%p)\n", data);
473 if (!data->padwTrustStepErrors)
478 DWORD signerCount, size;
480 size = sizeof(signerCount);
481 ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_COUNT_PARAM, 0,
482 &signerCount, &size);
487 for (i = 0; ret && i < signerCount; i++)
489 if ((ret = WINTRUST_SaveSigner(data, i)))
490 ret = WINTRUST_VerifySigner(data, i);
494 SetLastError(TRUST_E_NOSIGNATURE);
499 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] =
501 return ret ? S_OK : S_FALSE;
504 BOOL WINAPI SoftpubCheckCert(CRYPT_PROVIDER_DATA *data, DWORD idxSigner,
505 BOOL fCounterSignerChain, DWORD idxCounterSigner)
509 TRACE("(%p, %d, %d, %d)\n", data, idxSigner, fCounterSignerChain,
512 if (fCounterSignerChain)
514 FIXME("unimplemented for counter signers\n");
519 PCERT_SIMPLE_CHAIN simpleChain =
520 data->pasSigners[idxSigner].pChainContext->rgpChain[0];
524 for (i = 0; i < simpleChain->cElement; i++)
527 data->pasSigners[idxSigner].pasCertChain[i].dwConfidence = 0;
528 if (!(simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus &
529 CERT_TRUST_IS_NOT_TIME_VALID))
530 data->pasSigners[idxSigner].pasCertChain[i].dwConfidence
531 |= CERT_CONFIDENCE_TIME;
532 if (!(simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus &
533 CERT_TRUST_IS_NOT_TIME_NESTED))
534 data->pasSigners[idxSigner].pasCertChain[i].dwConfidence
535 |= CERT_CONFIDENCE_TIMENEST;
536 if (!(simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus &
537 CERT_TRUST_IS_NOT_SIGNATURE_VALID))
538 data->pasSigners[idxSigner].pasCertChain[i].dwConfidence
539 |= CERT_CONFIDENCE_SIG;
540 /* Set additional flags */
541 if (!(simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus &
542 CERT_TRUST_IS_UNTRUSTED_ROOT))
543 data->pasSigners[idxSigner].pasCertChain[i].fTrustedRoot = TRUE;
544 if (simpleChain->rgpElement[i]->TrustStatus.dwInfoStatus &
545 CERT_TRUST_IS_SELF_SIGNED)
546 data->pasSigners[idxSigner].pasCertChain[i].fSelfSigned = TRUE;
547 if (simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus &
548 CERT_TRUST_IS_CYCLIC)
549 data->pasSigners[idxSigner].pasCertChain[i].fIsCyclic = TRUE;
555 static BOOL WINTRUST_CopyChain(CRYPT_PROVIDER_DATA *data, DWORD signerIdx)
558 PCERT_SIMPLE_CHAIN simpleChain =
559 data->pasSigners[signerIdx].pChainContext->rgpChain[0];
562 data->pasSigners[signerIdx].pasCertChain[0].pChainElement =
563 simpleChain->rgpElement[0];
565 for (i = 1; ret && i < simpleChain->cElement; i++)
567 ret = data->psPfns->pfnAddCert2Chain(data, signerIdx, FALSE, 0,
568 simpleChain->rgpElement[i]->pCertContext);
570 data->pasSigners[signerIdx].pasCertChain[i].pChainElement =
571 simpleChain->rgpElement[i];
576 static void WINTRUST_CreateChainPolicyCreateInfo(
577 const CRYPT_PROVIDER_DATA *data, PWTD_GENERIC_CHAIN_POLICY_CREATE_INFO info,
578 PCERT_CHAIN_PARA chainPara)
580 chainPara->cbSize = sizeof(CERT_CHAIN_PARA);
581 if (data->pRequestUsage)
582 chainPara->RequestedUsage = *data->pRequestUsage;
583 info->u.cbSize = sizeof(WTD_GENERIC_CHAIN_POLICY_CREATE_INFO);
584 info->hChainEngine = NULL;
585 info->pChainPara = chainPara;
586 if (data->dwProvFlags & CPD_REVOCATION_CHECK_END_CERT)
587 info->dwFlags = CERT_CHAIN_REVOCATION_CHECK_END_CERT;
588 else if (data->dwProvFlags & CPD_REVOCATION_CHECK_CHAIN)
589 info->dwFlags = CERT_CHAIN_REVOCATION_CHECK_CHAIN;
590 else if (data->dwProvFlags & CPD_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT)
591 info->dwFlags = CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
594 info->pvReserved = NULL;
597 static BOOL WINTRUST_CreateChainForSigner(CRYPT_PROVIDER_DATA *data,
598 DWORD signer, PWTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo,
599 PCERT_CHAIN_PARA chainPara)
603 /* Expect the end certificate for each signer to be the only cert in the
606 if (data->pasSigners[signer].csCertChain)
608 /* Create a certificate chain for each signer */
609 ret = CertGetCertificateChain(createInfo->hChainEngine,
610 data->pasSigners[signer].pasCertChain[0].pCert,
611 &data->pasSigners[signer].sftVerifyAsOf,
612 data->chStores ? data->pahStores[0] : NULL,
613 chainPara, createInfo->dwFlags, createInfo->pvReserved,
614 &data->pasSigners[signer].pChainContext);
617 if (data->pasSigners[signer].pChainContext->cChain != 1)
619 FIXME("unimplemented for more than 1 simple chain\n");
624 if ((ret = WINTRUST_CopyChain(data, signer)))
625 ret = data->psPfns->pfnCertCheckPolicy(data, signer, FALSE,
633 HRESULT WINAPI WintrustCertificateTrust(CRYPT_PROVIDER_DATA *data)
637 TRACE("(%p)\n", data);
639 if (!data->csSigners)
642 SetLastError(TRUST_E_NOSIGNATURE);
647 WTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo;
648 CERT_CHAIN_PARA chainPara;
650 WINTRUST_CreateChainPolicyCreateInfo(data, &createInfo, &chainPara);
652 for (i = 0; i < data->csSigners; i++)
653 ret = WINTRUST_CreateChainForSigner(data, i, &createInfo,
657 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV] =
659 TRACE("returning %d (%08x)\n", ret ? S_OK : S_FALSE,
660 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV]);
661 return ret ? S_OK : S_FALSE;
664 HRESULT WINAPI GenericChainCertificateTrust(CRYPT_PROVIDER_DATA *data)
667 WTD_GENERIC_CHAIN_POLICY_DATA *policyData =
668 (WTD_GENERIC_CHAIN_POLICY_DATA *)data->pWintrustData->pPolicyCallbackData;
670 TRACE("(%p)\n", data);
672 if (policyData && policyData->u.cbSize !=
673 sizeof(WTD_GENERIC_CHAIN_POLICY_CREATE_INFO))
675 SetLastError(ERROR_INVALID_PARAMETER);
679 if (!data->csSigners)
682 SetLastError(TRUST_E_NOSIGNATURE);
687 WTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo, *pCreateInfo;
688 CERT_CHAIN_PARA chainPara, *pChainPara;
692 pCreateInfo = policyData->pSignerChainInfo;
693 pChainPara = pCreateInfo->pChainPara;
697 WINTRUST_CreateChainPolicyCreateInfo(data, &createInfo, &chainPara);
698 pChainPara = &chainPara;
699 pCreateInfo = &createInfo;
702 for (i = 0; i < data->csSigners; i++)
703 ret = WINTRUST_CreateChainForSigner(data, i, pCreateInfo,
709 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV] =
711 TRACE("returning %d (%08x)\n", ret ? S_OK : S_FALSE,
712 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV]);
713 return ret ? S_OK : S_FALSE;
716 HRESULT WINAPI SoftpubAuthenticode(CRYPT_PROVIDER_DATA *data)
719 CERT_CHAIN_POLICY_STATUS policyStatus = { sizeof(policyStatus), 0 };
721 TRACE("(%p)\n", data);
723 if (data->pWintrustData->dwUIChoice != WTD_UI_NONE)
724 FIXME("unimplemented for UI choice %d\n",
725 data->pWintrustData->dwUIChoice);
726 if (!data->csSigners)
729 policyStatus.dwError = TRUST_E_NOSIGNATURE;
736 for (i = 0; ret && i < data->csSigners; i++)
738 CERT_CHAIN_POLICY_PARA policyPara = { sizeof(policyPara), 0 };
740 if (data->dwRegPolicySettings & WTPF_TRUSTTEST)
741 policyPara.dwFlags |= CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG;
742 if (data->dwRegPolicySettings & WTPF_TESTCANBEVALID)
743 policyPara.dwFlags |= CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG;
744 if (data->dwRegPolicySettings & WTPF_IGNOREEXPIRATION)
745 policyPara.dwFlags |=
746 CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG |
747 CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG |
748 CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG;
749 if (data->dwRegPolicySettings & WTPF_IGNOREREVOKATION)
750 policyPara.dwFlags |=
751 CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG |
752 CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG |
753 CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG |
754 CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG;
755 CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_AUTHENTICODE,
756 data->pasSigners[i].pChainContext, &policyPara, &policyStatus);
757 if (policyStatus.dwError != NO_ERROR)
762 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV] =
763 policyStatus.dwError;
764 TRACE("returning %d (%08x)\n", ret ? S_OK : S_FALSE,
765 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV]);
766 return ret ? S_OK : S_FALSE;
769 static HRESULT WINAPI WINTRUST_DefaultPolicy(CRYPT_PROVIDER_DATA *pProvData,
770 DWORD dwStepError, DWORD dwRegPolicySettings, DWORD cSigner,
771 PWTD_GENERIC_CHAIN_POLICY_SIGNER_INFO rgpSigner, void *pvPolicyArg)
774 CERT_CHAIN_POLICY_STATUS policyStatus = { sizeof(policyStatus), 0 };
776 for (i = 0; !policyStatus.dwError && i < cSigner; i++)
778 CERT_CHAIN_POLICY_PARA policyPara = { sizeof(policyPara), 0 };
780 if (dwRegPolicySettings & WTPF_IGNOREEXPIRATION)
781 policyPara.dwFlags |=
782 CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG |
783 CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG |
784 CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG;
785 if (dwRegPolicySettings & WTPF_IGNOREREVOKATION)
786 policyPara.dwFlags |=
787 CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG |
788 CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG |
789 CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG |
790 CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG;
791 CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE,
792 rgpSigner[i].pChainContext, &policyPara, &policyStatus);
794 return policyStatus.dwError;
797 HRESULT WINAPI GenericChainFinalProv(CRYPT_PROVIDER_DATA *data)
799 HRESULT err = NO_ERROR; /* not a typo, MS confused the types */
800 WTD_GENERIC_CHAIN_POLICY_DATA *policyData =
801 (WTD_GENERIC_CHAIN_POLICY_DATA *)data->pWintrustData->pPolicyCallbackData;
803 TRACE("(%p)\n", data);
805 if (data->pWintrustData->dwUIChoice != WTD_UI_NONE)
806 FIXME("unimplemented for UI choice %d\n",
807 data->pWintrustData->dwUIChoice);
808 if (!data->csSigners)
809 err = TRUST_E_NOSIGNATURE;
812 PFN_WTD_GENERIC_CHAIN_POLICY_CALLBACK policyCallback;
814 WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO *signers = NULL;
818 policyCallback = policyData->pfnPolicyCallback;
819 policyArg = policyData->pvPolicyArg;
823 policyCallback = WINTRUST_DefaultPolicy;
830 signers = data->psPfns->pfnAlloc(
831 data->csSigners * sizeof(WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO));
834 for (i = 0; i < data->csSigners; i++)
836 signers[i].u.cbSize =
837 sizeof(WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO);
838 signers[i].pChainContext =
839 data->pasSigners[i].pChainContext;
840 signers[i].dwSignerType = data->pasSigners[i].dwSignerType;
841 signers[i].pMsgSignerInfo = data->pasSigners[i].psSigner;
842 signers[i].dwError = data->pasSigners[i].dwError;
843 if (data->pasSigners[i].csCounterSigners)
844 FIXME("unimplemented for counter signers\n");
845 signers[i].cCounterSigner = 0;
846 signers[i].rgpCounterSigner = NULL;
850 err = ERROR_OUTOFMEMORY;
853 err = policyCallback(data, TRUSTERROR_STEP_FINAL_POLICYPROV,
854 data->dwRegPolicySettings, data->csSigners, signers, policyArg);
855 data->psPfns->pfnFree(signers);
858 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV] = err;
859 TRACE("returning %d (%08x)\n", !err ? S_OK : S_FALSE,
860 data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV]);
861 return err == NO_ERROR ? S_OK : S_FALSE;
864 HRESULT WINAPI SoftpubCleanup(CRYPT_PROVIDER_DATA *data)
868 for (i = 0; i < data->csSigners; i++)
870 for (j = 0; j < data->pasSigners[i].csCertChain; j++)
871 CertFreeCertificateContext(data->pasSigners[i].pasCertChain[j].pCert);
872 data->psPfns->pfnFree(data->pasSigners[i].pasCertChain);
873 data->psPfns->pfnFree(data->pasSigners[i].psSigner);
874 CertFreeCertificateChain(data->pasSigners[i].pChainContext);
876 data->psPfns->pfnFree(data->pasSigners);
878 for (i = 0; i < data->chStores; i++)
879 CertCloseStore(data->pahStores[i], 0);
880 data->psPfns->pfnFree(data->pahStores);
884 data->psPfns->pfnFree(data->u.pPDSip->pSip);
885 data->psPfns->pfnFree(data->u.pPDSip->pCATSip);
886 data->psPfns->pfnFree(data->u.pPDSip->psSipSubjectInfo);
887 data->psPfns->pfnFree(data->u.pPDSip->psSipCATSubjectInfo);
888 data->psPfns->pfnFree(data->u.pPDSip->psIndirectData);
891 CryptMsgClose(data->hMsg);
893 if (data->fOpenedFile)
894 CloseHandle(data->pWintrustData->u.pFile->hFile);