2007-08-25 00:12:31 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Juan Lang
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#include <stdarg.h>
|
2007-09-11 16:37:44 +02:00
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
2007-08-25 00:12:31 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wintrust.h"
|
2007-08-28 01:17:52 +02:00
|
|
|
#include "mssip.h"
|
2007-10-09 00:34:54 +02:00
|
|
|
#include "softpub.h"
|
2010-10-14 23:21:21 +02:00
|
|
|
#include "winnls.h"
|
2007-08-25 00:12:31 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
|
|
|
|
|
2007-09-28 21:42:47 +02:00
|
|
|
HRESULT WINAPI SoftpubDefCertInit(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
HRESULT ret = S_FALSE;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
|
|
|
if (data->padwTrustStepErrors &&
|
|
|
|
!data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT])
|
|
|
|
ret = S_OK;
|
|
|
|
TRACE("returning %08x\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-25 00:12:31 +02:00
|
|
|
HRESULT WINAPI SoftpubInitialize(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
HRESULT ret = S_FALSE;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
|
|
|
if (data->padwTrustStepErrors &&
|
|
|
|
!data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT])
|
|
|
|
ret = S_OK;
|
|
|
|
TRACE("returning %08x\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2007-08-28 01:17:52 +02:00
|
|
|
|
2009-08-14 15:29:26 +02:00
|
|
|
HRESULT WINAPI DriverInitializePolicy(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DriverCleanupPolicy(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DriverFinalPolicy(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-11 16:37:44 +02:00
|
|
|
/* Assumes data->pWintrustData->u.pFile exists. Makes sure a file handle is
|
2007-08-28 01:17:52 +02:00
|
|
|
* open for the file.
|
|
|
|
*/
|
2010-01-27 19:27:49 +01:00
|
|
|
static DWORD SOFTPUB_OpenFile(CRYPT_PROVIDER_DATA *data)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:27:49 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2007-08-28 01:17:52 +02:00
|
|
|
|
|
|
|
/* PSDK implies that all values should be initialized to NULL, so callers
|
|
|
|
* typically have hFile as NULL rather than INVALID_HANDLE_VALUE. Check
|
|
|
|
* for both.
|
|
|
|
*/
|
2007-09-11 16:37:44 +02:00
|
|
|
if (!data->pWintrustData->u.pFile->hFile ||
|
|
|
|
data->pWintrustData->u.pFile->hFile == INVALID_HANDLE_VALUE)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2007-09-11 16:37:44 +02:00
|
|
|
data->pWintrustData->u.pFile->hFile =
|
|
|
|
CreateFileW(data->pWintrustData->u.pFile->pcwszFilePath, GENERIC_READ,
|
2007-08-28 01:17:52 +02:00
|
|
|
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
2007-09-11 16:37:44 +02:00
|
|
|
if (data->pWintrustData->u.pFile->hFile != INVALID_HANDLE_VALUE)
|
2007-08-28 01:17:52 +02:00
|
|
|
data->fOpenedFile = TRUE;
|
|
|
|
else
|
2010-01-27 19:27:49 +01:00
|
|
|
err = GetLastError();
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
2010-01-27 19:27:49 +01:00
|
|
|
if (!err)
|
2007-10-03 21:00:59 +02:00
|
|
|
GetFileTime(data->pWintrustData->u.pFile->hFile, &data->sftSystemTime,
|
|
|
|
NULL, NULL);
|
2010-01-27 19:27:49 +01:00
|
|
|
TRACE("returning %d\n", err);
|
|
|
|
return err;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
|
|
|
|
2007-09-11 16:37:44 +02:00
|
|
|
/* Assumes data->pWintrustData->u.pFile exists. Sets data->pPDSip->gSubject to
|
2007-08-28 01:17:52 +02:00
|
|
|
* the file's subject GUID.
|
|
|
|
*/
|
2010-01-27 19:29:35 +01:00
|
|
|
static DWORD SOFTPUB_GetFileSubject(CRYPT_PROVIDER_DATA *data)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:29:35 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2007-08-28 01:17:52 +02:00
|
|
|
|
2009-06-11 23:34:58 +02:00
|
|
|
if (!WVT_ISINSTRUCT(WINTRUST_FILE_INFO,
|
|
|
|
data->pWintrustData->u.pFile->cbStruct, pgKnownSubject) ||
|
|
|
|
!data->pWintrustData->u.pFile->pgKnownSubject)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:29:35 +01:00
|
|
|
if (!CryptSIPRetrieveSubjectGuid(
|
2007-09-11 16:37:44 +02:00
|
|
|
data->pWintrustData->u.pFile->pcwszFilePath,
|
|
|
|
data->pWintrustData->u.pFile->hFile,
|
2010-01-27 19:29:35 +01:00
|
|
|
&data->u.pPDSip->gSubject))
|
2011-09-14 17:45:10 +02:00
|
|
|
{
|
|
|
|
LARGE_INTEGER fileSize;
|
|
|
|
DWORD sipError = GetLastError();
|
|
|
|
|
|
|
|
/* Special case for empty files: the error is expected to be
|
|
|
|
* TRUST_E_SUBJECT_FORM_UNKNOWN, rather than whatever
|
|
|
|
* CryptSIPRetrieveSubjectGuid returns.
|
|
|
|
*/
|
|
|
|
if (GetFileSizeEx(data->pWintrustData->u.pFile->hFile, &fileSize)
|
|
|
|
&& !fileSize.QuadPart)
|
|
|
|
err = TRUST_E_SUBJECT_FORM_UNKNOWN;
|
|
|
|
else
|
|
|
|
err = sipError;
|
|
|
|
}
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
|
|
|
else
|
2008-03-22 18:10:13 +01:00
|
|
|
data->u.pPDSip->gSubject = *data->pWintrustData->u.pFile->pgKnownSubject;
|
2010-01-27 19:29:35 +01:00
|
|
|
TRACE("returning %d\n", err);
|
|
|
|
return err;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
|
|
|
|
2007-09-11 16:37:44 +02:00
|
|
|
/* Assumes data->u.pPDSip exists, and its gSubject member set.
|
|
|
|
* Allocates data->u.pPDSip->pSip and loads it, if possible.
|
2007-08-28 01:17:52 +02:00
|
|
|
*/
|
2010-01-27 19:31:26 +01:00
|
|
|
static DWORD SOFTPUB_GetSIP(CRYPT_PROVIDER_DATA *data)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:31:26 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2007-08-28 01:17:52 +02:00
|
|
|
|
2007-09-11 16:37:44 +02:00
|
|
|
data->u.pPDSip->pSip = data->psPfns->pfnAlloc(sizeof(SIP_DISPATCH_INFO));
|
|
|
|
if (data->u.pPDSip->pSip)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:31:26 +01:00
|
|
|
if (!CryptSIPLoad(&data->u.pPDSip->gSubject, 0, data->u.pPDSip->pSip))
|
|
|
|
err = GetLastError();
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
2010-01-27 19:31:26 +01:00
|
|
|
else
|
|
|
|
err = ERROR_OUTOFMEMORY;
|
|
|
|
TRACE("returning %d\n", err);
|
|
|
|
return err;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
|
|
|
|
2007-09-11 16:37:44 +02:00
|
|
|
/* Assumes data->u.pPDSip has been loaded, and data->u.pPDSip->pSip allocated.
|
|
|
|
* Calls data->u.pPDSip->pSip->pfGet to construct data->hMsg.
|
2007-08-28 01:17:52 +02:00
|
|
|
*/
|
2010-01-27 19:35:07 +01:00
|
|
|
static DWORD SOFTPUB_GetMessageFromFile(CRYPT_PROVIDER_DATA *data, HANDLE file,
|
2008-10-23 22:46:20 +02:00
|
|
|
LPCWSTR filePath)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:35:07 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2007-08-28 01:17:52 +02:00
|
|
|
BOOL ret;
|
|
|
|
LPBYTE buf = NULL;
|
|
|
|
DWORD size = 0;
|
|
|
|
|
2007-09-11 16:37:44 +02:00
|
|
|
data->u.pPDSip->psSipSubjectInfo =
|
2007-08-28 01:17:52 +02:00
|
|
|
data->psPfns->pfnAlloc(sizeof(SIP_SUBJECTINFO));
|
2007-09-11 16:37:44 +02:00
|
|
|
if (!data->u.pPDSip->psSipSubjectInfo)
|
2010-01-27 19:35:07 +01:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2007-08-28 01:17:52 +02:00
|
|
|
|
2007-09-11 16:37:44 +02:00
|
|
|
data->u.pPDSip->psSipSubjectInfo->cbSize = sizeof(SIP_SUBJECTINFO);
|
|
|
|
data->u.pPDSip->psSipSubjectInfo->pgSubjectType = &data->u.pPDSip->gSubject;
|
2008-10-23 22:46:20 +02:00
|
|
|
data->u.pPDSip->psSipSubjectInfo->hFile = file;
|
|
|
|
data->u.pPDSip->psSipSubjectInfo->pwsFileName = filePath;
|
2007-09-11 16:37:44 +02:00
|
|
|
data->u.pPDSip->psSipSubjectInfo->hProv = data->hProv;
|
|
|
|
ret = data->u.pPDSip->pSip->pfGet(data->u.pPDSip->psSipSubjectInfo,
|
2007-08-28 01:17:52 +02:00
|
|
|
&data->dwEncoding, 0, &size, 0);
|
|
|
|
if (!ret)
|
2010-01-27 19:35:07 +01:00
|
|
|
return TRUST_E_NOSIGNATURE;
|
2007-08-28 01:17:52 +02:00
|
|
|
|
|
|
|
buf = data->psPfns->pfnAlloc(size);
|
|
|
|
if (!buf)
|
2010-01-27 19:35:07 +01:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2007-08-28 01:17:52 +02:00
|
|
|
|
2007-09-11 16:37:44 +02:00
|
|
|
ret = data->u.pPDSip->pSip->pfGet(data->u.pPDSip->psSipSubjectInfo,
|
2007-08-28 01:17:52 +02:00
|
|
|
&data->dwEncoding, 0, &size, buf);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
data->hMsg = CryptMsgOpenToDecode(data->dwEncoding, 0, 0, data->hProv,
|
|
|
|
NULL, NULL);
|
|
|
|
if (data->hMsg)
|
2010-01-27 19:35:07 +01:00
|
|
|
{
|
2007-08-28 01:17:52 +02:00
|
|
|
ret = CryptMsgUpdate(data->hMsg, buf, size, TRUE);
|
2010-01-27 19:35:07 +01:00
|
|
|
if (!ret)
|
|
|
|
err = GetLastError();
|
|
|
|
}
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
2010-01-27 19:35:07 +01:00
|
|
|
else
|
|
|
|
err = GetLastError();
|
2007-08-28 01:17:52 +02:00
|
|
|
|
|
|
|
data->psPfns->pfnFree(buf);
|
2010-01-27 19:35:07 +01:00
|
|
|
TRACE("returning %d\n", err);
|
|
|
|
return err;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 19:37:59 +01:00
|
|
|
static DWORD SOFTPUB_CreateStoreFromMessage(CRYPT_PROVIDER_DATA *data)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:37:59 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2007-08-28 01:17:52 +02:00
|
|
|
HCERTSTORE store;
|
|
|
|
|
|
|
|
store = CertOpenStore(CERT_STORE_PROV_MSG, data->dwEncoding,
|
|
|
|
data->hProv, CERT_STORE_NO_CRYPT_RELEASE_FLAG, data->hMsg);
|
|
|
|
if (store)
|
|
|
|
{
|
2010-01-27 19:37:59 +01:00
|
|
|
if (!data->psPfns->pfnAddStore2Chain(data, store))
|
|
|
|
err = GetLastError();
|
2007-08-29 01:09:34 +02:00
|
|
|
CertCloseStore(store, 0);
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
2010-01-27 19:37:59 +01:00
|
|
|
else
|
|
|
|
err = GetLastError();
|
|
|
|
TRACE("returning %d\n", err);
|
|
|
|
return err;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD SOFTPUB_DecodeInnerContent(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
2010-01-27 19:40:32 +01:00
|
|
|
DWORD size, err = ERROR_SUCCESS;
|
2008-10-08 18:09:31 +02:00
|
|
|
LPSTR oid = NULL;
|
2007-08-28 01:17:52 +02:00
|
|
|
LPBYTE buf = NULL;
|
|
|
|
|
|
|
|
ret = CryptMsgGetParam(data->hMsg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, NULL,
|
|
|
|
&size);
|
|
|
|
if (!ret)
|
2010-01-27 19:40:32 +01:00
|
|
|
{
|
|
|
|
err = GetLastError();
|
2007-08-28 01:17:52 +02:00
|
|
|
goto error;
|
2010-01-27 19:40:32 +01:00
|
|
|
}
|
2008-10-08 18:09:31 +02:00
|
|
|
oid = data->psPfns->pfnAlloc(size);
|
|
|
|
if (!oid)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:40:32 +01:00
|
|
|
err = ERROR_OUTOFMEMORY;
|
2007-08-28 01:17:52 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2008-10-08 18:09:31 +02:00
|
|
|
ret = CryptMsgGetParam(data->hMsg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, oid,
|
2007-08-28 01:17:52 +02:00
|
|
|
&size);
|
|
|
|
if (!ret)
|
2010-01-27 19:40:32 +01:00
|
|
|
{
|
|
|
|
err = GetLastError();
|
2007-08-28 01:17:52 +02:00
|
|
|
goto error;
|
2010-01-27 19:40:32 +01:00
|
|
|
}
|
2008-10-08 18:09:31 +02:00
|
|
|
ret = CryptMsgGetParam(data->hMsg, CMSG_CONTENT_PARAM, 0, NULL, &size);
|
|
|
|
if (!ret)
|
2010-01-27 19:40:32 +01:00
|
|
|
{
|
|
|
|
err = GetLastError();
|
2008-10-08 18:09:31 +02:00
|
|
|
goto error;
|
2010-01-27 19:40:32 +01:00
|
|
|
}
|
2008-10-08 18:09:31 +02:00
|
|
|
buf = data->psPfns->pfnAlloc(size);
|
|
|
|
if (!buf)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:40:32 +01:00
|
|
|
err = ERROR_OUTOFMEMORY;
|
2008-10-08 18:09:31 +02:00
|
|
|
goto error;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
2008-10-08 18:09:31 +02:00
|
|
|
ret = CryptMsgGetParam(data->hMsg, CMSG_CONTENT_PARAM, 0, buf, &size);
|
|
|
|
if (!ret)
|
2010-01-27 19:40:32 +01:00
|
|
|
{
|
|
|
|
err = GetLastError();
|
2008-10-08 18:09:31 +02:00
|
|
|
goto error;
|
2010-01-27 19:40:32 +01:00
|
|
|
}
|
2008-10-08 18:09:31 +02:00
|
|
|
ret = CryptDecodeObject(data->dwEncoding, oid, buf, size, 0, NULL, &size);
|
|
|
|
if (!ret)
|
2010-01-27 19:40:32 +01:00
|
|
|
{
|
|
|
|
err = GetLastError();
|
2008-10-08 18:09:31 +02:00
|
|
|
goto error;
|
2010-01-27 19:40:32 +01:00
|
|
|
}
|
2008-10-08 18:09:31 +02:00
|
|
|
data->u.pPDSip->psIndirectData = data->psPfns->pfnAlloc(size);
|
|
|
|
if (!data->u.pPDSip->psIndirectData)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-01-27 19:40:32 +01:00
|
|
|
err = ERROR_OUTOFMEMORY;
|
2008-10-08 18:09:31 +02:00
|
|
|
goto error;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
2008-10-08 18:09:31 +02:00
|
|
|
ret = CryptDecodeObject(data->dwEncoding, oid, buf, size, 0,
|
|
|
|
data->u.pPDSip->psIndirectData, &size);
|
2010-01-27 19:40:32 +01:00
|
|
|
if (!ret)
|
|
|
|
err = GetLastError();
|
2007-08-28 01:17:52 +02:00
|
|
|
|
|
|
|
error:
|
2010-01-27 19:40:32 +01:00
|
|
|
TRACE("returning %d\n", err);
|
2008-10-08 18:09:31 +02:00
|
|
|
data->psPfns->pfnFree(oid);
|
|
|
|
data->psPfns->pfnFree(buf);
|
2010-01-27 19:40:32 +01:00
|
|
|
return err;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 19:42:34 +01:00
|
|
|
static DWORD SOFTPUB_LoadCertMessage(CRYPT_PROVIDER_DATA *data)
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2010-02-01 18:11:51 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2007-08-28 01:17:52 +02:00
|
|
|
|
2008-10-23 22:40:34 +02:00
|
|
|
if (data->pWintrustData->u.pCert &&
|
2009-06-12 18:35:41 +02:00
|
|
|
WVT_IS_CBSTRUCT_GT_MEMBEROFFSET(WINTRUST_CERT_INFO,
|
|
|
|
data->pWintrustData->u.pCert->cbStruct, psCertContext))
|
2007-08-28 01:17:52 +02:00
|
|
|
{
|
2008-10-23 22:40:34 +02:00
|
|
|
if (data->psPfns)
|
2007-09-28 21:44:27 +02:00
|
|
|
{
|
2008-10-23 22:40:34 +02:00
|
|
|
CRYPT_PROVIDER_SGNR signer = { sizeof(signer), { 0 } };
|
|
|
|
DWORD i;
|
2010-01-27 19:42:34 +01:00
|
|
|
BOOL ret;
|
2008-10-23 22:40:34 +02:00
|
|
|
|
|
|
|
/* Add a signer with nothing but the time to verify, so we can
|
|
|
|
* add a cert to it
|
|
|
|
*/
|
2009-06-12 18:35:41 +02:00
|
|
|
if (WVT_ISINSTRUCT(WINTRUST_CERT_INFO,
|
|
|
|
data->pWintrustData->u.pCert->cbStruct, psftVerifyAsOf) &&
|
|
|
|
data->pWintrustData->u.pCert->psftVerifyAsOf)
|
2008-10-23 22:40:34 +02:00
|
|
|
data->sftSystemTime = signer.sftVerifyAsOf;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SYSTEMTIME sysTime;
|
|
|
|
|
|
|
|
GetSystemTime(&sysTime);
|
|
|
|
SystemTimeToFileTime(&sysTime, &signer.sftVerifyAsOf);
|
|
|
|
}
|
|
|
|
ret = data->psPfns->pfnAddSgnr2Chain(data, FALSE, 0, &signer);
|
|
|
|
if (ret)
|
2007-09-28 21:44:27 +02:00
|
|
|
{
|
|
|
|
ret = data->psPfns->pfnAddCert2Chain(data, 0, FALSE, 0,
|
|
|
|
data->pWintrustData->u.pCert->psCertContext);
|
2009-06-12 18:35:41 +02:00
|
|
|
if (WVT_ISINSTRUCT(WINTRUST_CERT_INFO,
|
|
|
|
data->pWintrustData->u.pCert->cbStruct, pahStores))
|
|
|
|
for (i = 0;
|
|
|
|
ret && i < data->pWintrustData->u.pCert->chStores; i++)
|
|
|
|
ret = data->psPfns->pfnAddStore2Chain(data,
|
|
|
|
data->pWintrustData->u.pCert->pahStores[i]);
|
2007-09-28 21:44:27 +02:00
|
|
|
}
|
2010-01-27 19:42:34 +01:00
|
|
|
if (!ret)
|
|
|
|
err = GetLastError();
|
2007-09-28 21:44:27 +02:00
|
|
|
}
|
2008-10-23 22:40:34 +02:00
|
|
|
}
|
|
|
|
else
|
2010-01-27 19:42:34 +01:00
|
|
|
err = ERROR_INVALID_PARAMETER;
|
|
|
|
return err;
|
2008-10-23 22:40:34 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 19:25:48 +01:00
|
|
|
static DWORD SOFTPUB_LoadFileMessage(CRYPT_PROVIDER_DATA *data)
|
2008-10-23 22:42:08 +02:00
|
|
|
{
|
2010-01-27 19:25:48 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2008-10-23 22:42:08 +02:00
|
|
|
|
|
|
|
if (!data->pWintrustData->u.pFile)
|
|
|
|
{
|
2010-01-27 19:25:48 +01:00
|
|
|
err = ERROR_INVALID_PARAMETER;
|
2008-10-23 22:42:08 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2010-01-27 19:27:49 +01:00
|
|
|
err = SOFTPUB_OpenFile(data);
|
|
|
|
if (err)
|
2008-10-23 22:42:08 +02:00
|
|
|
goto error;
|
2010-01-27 19:29:35 +01:00
|
|
|
err = SOFTPUB_GetFileSubject(data);
|
|
|
|
if (err)
|
2008-10-23 22:42:08 +02:00
|
|
|
goto error;
|
2010-01-27 19:31:26 +01:00
|
|
|
err = SOFTPUB_GetSIP(data);
|
|
|
|
if (err)
|
2008-10-23 22:42:08 +02:00
|
|
|
goto error;
|
2010-01-27 19:35:07 +01:00
|
|
|
err = SOFTPUB_GetMessageFromFile(data, data->pWintrustData->u.pFile->hFile,
|
|
|
|
data->pWintrustData->u.pFile->pcwszFilePath);
|
|
|
|
if (err)
|
2008-10-23 22:42:08 +02:00
|
|
|
goto error;
|
2010-01-27 19:37:59 +01:00
|
|
|
err = SOFTPUB_CreateStoreFromMessage(data);
|
|
|
|
if (err)
|
2008-10-23 22:42:08 +02:00
|
|
|
goto error;
|
2010-01-27 19:40:32 +01:00
|
|
|
err = SOFTPUB_DecodeInnerContent(data);
|
|
|
|
|
2008-10-23 22:42:08 +02:00
|
|
|
error:
|
2010-01-27 20:01:21 +01:00
|
|
|
if (err && data->fOpenedFile && data->pWintrustData->u.pFile)
|
|
|
|
{
|
|
|
|
/* The caller won't expect the file to be open on failure, so close it.
|
|
|
|
*/
|
|
|
|
CloseHandle(data->pWintrustData->u.pFile->hFile);
|
|
|
|
data->pWintrustData->u.pFile->hFile = INVALID_HANDLE_VALUE;
|
|
|
|
data->fOpenedFile = FALSE;
|
|
|
|
}
|
2010-01-27 19:25:48 +01:00
|
|
|
return err;
|
2008-10-23 22:42:08 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 19:26:36 +01:00
|
|
|
static DWORD SOFTPUB_LoadCatalogMessage(CRYPT_PROVIDER_DATA *data)
|
2008-10-24 02:14:13 +02:00
|
|
|
{
|
2010-01-27 19:26:36 +01:00
|
|
|
DWORD err;
|
2008-10-24 02:14:13 +02:00
|
|
|
HANDLE catalog = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
if (!data->pWintrustData->u.pCatalog)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
catalog = CreateFileW(data->pWintrustData->u.pCatalog->pcwszCatalogFilePath,
|
|
|
|
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
if (catalog == INVALID_HANDLE_VALUE)
|
2010-01-27 19:26:36 +01:00
|
|
|
return GetLastError();
|
|
|
|
if (!CryptSIPRetrieveSubjectGuid(
|
2008-10-24 02:14:13 +02:00
|
|
|
data->pWintrustData->u.pCatalog->pcwszCatalogFilePath, catalog,
|
2010-01-27 19:26:36 +01:00
|
|
|
&data->u.pPDSip->gSubject))
|
|
|
|
{
|
|
|
|
err = GetLastError();
|
2008-10-24 02:14:13 +02:00
|
|
|
goto error;
|
2010-01-27 19:26:36 +01:00
|
|
|
}
|
2010-01-27 19:31:26 +01:00
|
|
|
err = SOFTPUB_GetSIP(data);
|
|
|
|
if (err)
|
2008-10-24 02:14:13 +02:00
|
|
|
goto error;
|
2010-02-01 18:23:30 +01:00
|
|
|
err = SOFTPUB_GetMessageFromFile(data, catalog,
|
|
|
|
data->pWintrustData->u.pCatalog->pcwszCatalogFilePath);
|
2010-01-27 19:35:07 +01:00
|
|
|
if (err)
|
2008-10-24 02:14:13 +02:00
|
|
|
goto error;
|
2010-01-27 19:37:59 +01:00
|
|
|
err = SOFTPUB_CreateStoreFromMessage(data);
|
|
|
|
if (err)
|
2008-10-24 02:14:13 +02:00
|
|
|
goto error;
|
2010-01-27 19:40:32 +01:00
|
|
|
err = SOFTPUB_DecodeInnerContent(data);
|
2008-10-24 02:14:13 +02:00
|
|
|
/* FIXME: this loads the catalog file, but doesn't validate the member. */
|
|
|
|
error:
|
|
|
|
CloseHandle(catalog);
|
2010-01-27 19:26:36 +01:00
|
|
|
return err;
|
2008-10-24 02:14:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-23 22:40:34 +02:00
|
|
|
HRESULT WINAPI SoftpubLoadMessage(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
2010-01-27 19:25:48 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2008-10-23 22:40:34 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
|
|
|
if (!data->padwTrustStepErrors)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
switch (data->pWintrustData->dwUnionChoice)
|
|
|
|
{
|
|
|
|
case WTD_CHOICE_CERT:
|
2010-01-27 19:42:34 +01:00
|
|
|
err = SOFTPUB_LoadCertMessage(data);
|
2007-08-28 01:17:52 +02:00
|
|
|
break;
|
|
|
|
case WTD_CHOICE_FILE:
|
2010-01-27 19:25:48 +01:00
|
|
|
err = SOFTPUB_LoadFileMessage(data);
|
2007-08-28 01:17:52 +02:00
|
|
|
break;
|
2008-10-24 02:14:13 +02:00
|
|
|
case WTD_CHOICE_CATALOG:
|
2010-01-27 19:26:36 +01:00
|
|
|
err = SOFTPUB_LoadCatalogMessage(data);
|
2008-10-24 02:14:13 +02:00
|
|
|
break;
|
2007-08-28 01:17:52 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented for %d\n", data->pWintrustData->dwUnionChoice);
|
2010-01-27 19:42:34 +01:00
|
|
|
err = ERROR_INVALID_PARAMETER;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 19:42:34 +01:00
|
|
|
if (err)
|
2010-01-27 19:25:48 +01:00
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] = err;
|
2010-01-27 19:42:34 +01:00
|
|
|
TRACE("returning %d (%08x)\n", !err ? S_OK : S_FALSE,
|
2007-09-28 21:44:27 +02:00
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
|
2010-01-27 19:42:34 +01:00
|
|
|
return !err ? S_OK : S_FALSE;
|
2007-08-28 01:17:52 +02:00
|
|
|
}
|
2007-08-28 01:18:50 +02:00
|
|
|
|
2007-08-29 01:10:41 +02:00
|
|
|
static CMSG_SIGNER_INFO *WINTRUST_GetSigner(CRYPT_PROVIDER_DATA *data,
|
|
|
|
DWORD signerIdx)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CMSG_SIGNER_INFO *signerInfo = NULL;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_INFO_PARAM, signerIdx,
|
|
|
|
NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
signerInfo = data->psPfns->pfnAlloc(size);
|
|
|
|
if (signerInfo)
|
|
|
|
{
|
|
|
|
ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_INFO_PARAM,
|
|
|
|
signerIdx, signerInfo, &size);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
data->psPfns->pfnFree(signerInfo);
|
|
|
|
signerInfo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
return signerInfo;
|
|
|
|
}
|
|
|
|
|
2010-10-14 23:21:21 +02:00
|
|
|
static BOOL WINTRUST_GetTimeFromCounterSigner(
|
|
|
|
const CMSG_CMS_SIGNER_INFO *counterSignerInfo, FILETIME *time)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
BOOL foundTimeStamp = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; !foundTimeStamp && i < counterSignerInfo->AuthAttrs.cAttr; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(counterSignerInfo->AuthAttrs.rgAttr[i].pszObjId,
|
|
|
|
szOID_RSA_signingTime))
|
|
|
|
{
|
|
|
|
const CRYPT_ATTRIBUTE *attr =
|
|
|
|
&counterSignerInfo->AuthAttrs.rgAttr[i];
|
|
|
|
DWORD j;
|
|
|
|
|
|
|
|
for (j = 0; !foundTimeStamp && j < attr->cValue; j++)
|
|
|
|
{
|
|
|
|
static const DWORD encoding = X509_ASN_ENCODING |
|
|
|
|
PKCS_7_ASN_ENCODING;
|
|
|
|
DWORD size = sizeof(FILETIME);
|
|
|
|
|
|
|
|
foundTimeStamp = CryptDecodeObjectEx(encoding,
|
|
|
|
X509_CHOICE_OF_TIME,
|
|
|
|
attr->rgValue[j].pbData, attr->rgValue[j].cbData, 0, NULL,
|
|
|
|
time, &size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundTimeStamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPCSTR filetime_to_str(const FILETIME *time)
|
|
|
|
{
|
|
|
|
static char date[80];
|
|
|
|
char dateFmt[80]; /* sufficient for all versions of LOCALE_SSHORTDATE */
|
|
|
|
SYSTEMTIME sysTime;
|
|
|
|
|
|
|
|
if (!time) return NULL;
|
|
|
|
|
2018-07-18 23:01:37 +02:00
|
|
|
GetLocaleInfoA(LOCALE_SYSTEM_DEFAULT, LOCALE_SSHORTDATE, dateFmt, ARRAY_SIZE(dateFmt));
|
2010-10-14 23:21:21 +02:00
|
|
|
FileTimeToSystemTime(time, &sysTime);
|
2018-07-18 23:01:37 +02:00
|
|
|
GetDateFormatA(LOCALE_SYSTEM_DEFAULT, 0, &sysTime, dateFmt, date, ARRAY_SIZE(date));
|
2010-10-14 23:21:21 +02:00
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FILETIME WINTRUST_GetTimeFromSigner(const CRYPT_PROVIDER_DATA *data,
|
|
|
|
const CMSG_SIGNER_INFO *signerInfo)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
FILETIME time;
|
|
|
|
BOOL foundTimeStamp = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; !foundTimeStamp && i < signerInfo->UnauthAttrs.cAttr; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(signerInfo->UnauthAttrs.rgAttr[i].pszObjId,
|
|
|
|
szOID_RSA_counterSign))
|
|
|
|
{
|
|
|
|
const CRYPT_ATTRIBUTE *attr = &signerInfo->UnauthAttrs.rgAttr[i];
|
|
|
|
DWORD j;
|
|
|
|
|
|
|
|
for (j = 0; j < attr->cValue; j++)
|
|
|
|
{
|
|
|
|
static const DWORD encoding = X509_ASN_ENCODING |
|
|
|
|
PKCS_7_ASN_ENCODING;
|
|
|
|
CMSG_CMS_SIGNER_INFO *counterSignerInfo;
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret = CryptDecodeObjectEx(encoding, CMS_SIGNER_INFO,
|
|
|
|
attr->rgValue[j].pbData, attr->rgValue[j].cbData,
|
|
|
|
CRYPT_DECODE_ALLOC_FLAG, NULL, &counterSignerInfo, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
/* FIXME: need to verify countersigner signature too */
|
|
|
|
foundTimeStamp = WINTRUST_GetTimeFromCounterSigner(
|
|
|
|
counterSignerInfo, &time);
|
|
|
|
LocalFree(counterSignerInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!foundTimeStamp)
|
|
|
|
{
|
|
|
|
TRACE("returning system time %s\n",
|
|
|
|
filetime_to_str(&data->sftSystemTime));
|
|
|
|
time = data->sftSystemTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TRACE("returning time from message %s\n", filetime_to_str(&time));
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2010-01-27 23:07:58 +01:00
|
|
|
static DWORD WINTRUST_SaveSigner(CRYPT_PROVIDER_DATA *data, DWORD signerIdx)
|
2007-08-29 01:10:41 +02:00
|
|
|
{
|
2010-01-27 23:07:58 +01:00
|
|
|
DWORD err;
|
2007-08-29 01:10:41 +02:00
|
|
|
CMSG_SIGNER_INFO *signerInfo = WINTRUST_GetSigner(data, signerIdx);
|
|
|
|
|
|
|
|
if (signerInfo)
|
|
|
|
{
|
|
|
|
CRYPT_PROVIDER_SGNR sgnr = { sizeof(sgnr), { 0 } };
|
|
|
|
|
|
|
|
sgnr.psSigner = signerInfo;
|
2010-10-14 23:21:21 +02:00
|
|
|
sgnr.sftVerifyAsOf = WINTRUST_GetTimeFromSigner(data, signerInfo);
|
2010-01-27 23:07:58 +01:00
|
|
|
if (!data->psPfns->pfnAddSgnr2Chain(data, FALSE, signerIdx, &sgnr))
|
|
|
|
err = GetLastError();
|
|
|
|
else
|
|
|
|
err = ERROR_SUCCESS;
|
2007-08-29 01:10:41 +02:00
|
|
|
}
|
|
|
|
else
|
2010-01-27 23:07:58 +01:00
|
|
|
err = GetLastError();
|
|
|
|
return err;
|
2007-08-29 01:10:41 +02:00
|
|
|
}
|
|
|
|
|
2007-08-29 01:10:00 +02:00
|
|
|
static CERT_INFO *WINTRUST_GetSignerCertInfo(CRYPT_PROVIDER_DATA *data,
|
|
|
|
DWORD signerIdx)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CERT_INFO *certInfo = NULL;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_CERT_INFO_PARAM, signerIdx,
|
|
|
|
NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
certInfo = data->psPfns->pfnAlloc(size);
|
|
|
|
if (certInfo)
|
|
|
|
{
|
|
|
|
ret = CryptMsgGetParam(data->hMsg, CMSG_SIGNER_CERT_INFO_PARAM,
|
|
|
|
signerIdx, certInfo, &size);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
data->psPfns->pfnFree(certInfo);
|
|
|
|
certInfo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
return certInfo;
|
|
|
|
}
|
|
|
|
|
2010-01-27 23:03:13 +01:00
|
|
|
static DWORD WINTRUST_VerifySigner(CRYPT_PROVIDER_DATA *data, DWORD signerIdx)
|
2007-08-29 01:10:41 +02:00
|
|
|
{
|
2010-01-27 23:03:13 +01:00
|
|
|
DWORD err;
|
2007-08-29 01:10:41 +02:00
|
|
|
CERT_INFO *certInfo = WINTRUST_GetSignerCertInfo(data, signerIdx);
|
|
|
|
|
|
|
|
if (certInfo)
|
|
|
|
{
|
2007-09-12 17:59:18 +02:00
|
|
|
PCCERT_CONTEXT subject = CertGetSubjectCertificateFromStore(
|
2007-08-29 01:10:41 +02:00
|
|
|
data->pahStores[0], data->dwEncoding, certInfo);
|
2007-09-12 17:59:18 +02:00
|
|
|
|
|
|
|
if (subject)
|
2007-08-29 01:10:41 +02:00
|
|
|
{
|
2007-09-12 17:59:18 +02:00
|
|
|
CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA para = { sizeof(para), 0,
|
|
|
|
signerIdx, CMSG_VERIFY_SIGNER_CERT, (LPVOID)subject };
|
|
|
|
|
2010-01-27 23:03:13 +01:00
|
|
|
if (!CryptMsgControl(data->hMsg, 0, CMSG_CTRL_VERIFY_SIGNATURE_EX,
|
|
|
|
¶))
|
|
|
|
err = TRUST_E_CERT_SIGNATURE;
|
2007-09-12 17:59:18 +02:00
|
|
|
else
|
2010-01-27 23:03:13 +01:00
|
|
|
{
|
2007-09-12 17:59:18 +02:00
|
|
|
data->psPfns->pfnAddCert2Chain(data, signerIdx, FALSE, 0,
|
|
|
|
subject);
|
2010-01-27 23:03:13 +01:00
|
|
|
err = ERROR_SUCCESS;
|
|
|
|
}
|
2007-09-12 17:59:18 +02:00
|
|
|
CertFreeCertificateContext(subject);
|
2007-08-29 01:10:41 +02:00
|
|
|
}
|
|
|
|
else
|
2010-01-27 23:03:13 +01:00
|
|
|
err = TRUST_E_NO_SIGNER_CERT;
|
2007-08-29 01:10:41 +02:00
|
|
|
data->psPfns->pfnFree(certInfo);
|
|
|
|
}
|
|
|
|
else
|
2010-01-27 23:03:13 +01:00
|
|
|
err = GetLastError();
|
|
|
|
return err;
|
2007-08-29 01:10:41 +02:00
|
|
|
}
|
|
|
|
|
2007-08-28 01:18:50 +02:00
|
|
|
HRESULT WINAPI SoftpubLoadSignature(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
2010-01-27 23:09:37 +01:00
|
|
|
DWORD err;
|
2007-08-28 01:18:50 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
|
|
|
if (!data->padwTrustStepErrors)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2007-09-28 21:47:03 +02:00
|
|
|
if (data->hMsg)
|
2007-08-28 01:18:50 +02:00
|
|
|
{
|
2007-09-28 21:47:03 +02:00
|
|
|
DWORD signerCount, size;
|
2007-08-28 01:18:50 +02:00
|
|
|
|
2007-09-28 21:47:03 +02:00
|
|
|
size = sizeof(signerCount);
|
2010-01-27 23:09:37 +01:00
|
|
|
if (CryptMsgGetParam(data->hMsg, CMSG_SIGNER_COUNT_PARAM, 0,
|
|
|
|
&signerCount, &size))
|
2007-08-28 01:18:50 +02:00
|
|
|
{
|
2007-09-28 21:47:03 +02:00
|
|
|
DWORD i;
|
|
|
|
|
2010-01-27 23:09:37 +01:00
|
|
|
err = ERROR_SUCCESS;
|
2010-01-27 23:07:58 +01:00
|
|
|
for (i = 0; !err && i < signerCount; i++)
|
2007-09-28 21:47:03 +02:00
|
|
|
{
|
2010-01-27 23:07:58 +01:00
|
|
|
if (!(err = WINTRUST_SaveSigner(data, i)))
|
2010-01-27 23:03:13 +01:00
|
|
|
err = WINTRUST_VerifySigner(data, i);
|
2007-09-28 21:47:03 +02:00
|
|
|
}
|
2007-08-28 01:18:50 +02:00
|
|
|
}
|
2007-09-28 21:47:03 +02:00
|
|
|
else
|
2010-01-27 23:09:37 +01:00
|
|
|
err = TRUST_E_NOSIGNATURE;
|
2007-08-28 01:18:50 +02:00
|
|
|
}
|
|
|
|
else
|
2010-01-27 23:09:37 +01:00
|
|
|
err = ERROR_SUCCESS;
|
|
|
|
if (err)
|
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_SIGPROV] = err;
|
|
|
|
return !err ? S_OK : S_FALSE;
|
2007-08-28 01:18:50 +02:00
|
|
|
}
|
2007-08-29 01:11:14 +02:00
|
|
|
|
2008-09-27 20:32:04 +02:00
|
|
|
static DWORD WINTRUST_TrustStatusToConfidence(DWORD errorStatus)
|
|
|
|
{
|
|
|
|
DWORD confidence = 0;
|
|
|
|
|
|
|
|
confidence = 0;
|
|
|
|
if (!(errorStatus & CERT_TRUST_IS_NOT_SIGNATURE_VALID))
|
|
|
|
confidence |= CERT_CONFIDENCE_SIG;
|
|
|
|
if (!(errorStatus & CERT_TRUST_IS_NOT_TIME_VALID))
|
|
|
|
confidence |= CERT_CONFIDENCE_TIME;
|
|
|
|
if (!(errorStatus & CERT_TRUST_IS_NOT_TIME_NESTED))
|
|
|
|
confidence |= CERT_CONFIDENCE_TIMENEST;
|
|
|
|
return confidence;
|
|
|
|
}
|
|
|
|
|
2007-08-29 01:11:14 +02:00
|
|
|
BOOL WINAPI SoftpubCheckCert(CRYPT_PROVIDER_DATA *data, DWORD idxSigner,
|
|
|
|
BOOL fCounterSignerChain, DWORD idxCounterSigner)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %d, %d)\n", data, idxSigner, fCounterSignerChain,
|
|
|
|
idxCounterSigner);
|
|
|
|
|
|
|
|
if (fCounterSignerChain)
|
|
|
|
{
|
|
|
|
FIXME("unimplemented for counter signers\n");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCERT_SIMPLE_CHAIN simpleChain =
|
|
|
|
data->pasSigners[idxSigner].pChainContext->rgpChain[0];
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
for (i = 0; i < simpleChain->cElement; i++)
|
|
|
|
{
|
|
|
|
/* Set confidence */
|
2008-09-27 20:32:04 +02:00
|
|
|
data->pasSigners[idxSigner].pasCertChain[i].dwConfidence =
|
|
|
|
WINTRUST_TrustStatusToConfidence(
|
|
|
|
simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus);
|
2007-08-29 01:11:14 +02:00
|
|
|
/* Set additional flags */
|
|
|
|
if (!(simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus &
|
|
|
|
CERT_TRUST_IS_UNTRUSTED_ROOT))
|
|
|
|
data->pasSigners[idxSigner].pasCertChain[i].fTrustedRoot = TRUE;
|
|
|
|
if (simpleChain->rgpElement[i]->TrustStatus.dwInfoStatus &
|
|
|
|
CERT_TRUST_IS_SELF_SIGNED)
|
|
|
|
data->pasSigners[idxSigner].pasCertChain[i].fSelfSigned = TRUE;
|
|
|
|
if (simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus &
|
|
|
|
CERT_TRUST_IS_CYCLIC)
|
|
|
|
data->pasSigners[idxSigner].pasCertChain[i].fIsCyclic = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-27 20:31:23 +02:00
|
|
|
static DWORD WINTRUST_TrustStatusToError(DWORD errorStatus)
|
|
|
|
{
|
|
|
|
DWORD error;
|
|
|
|
|
|
|
|
if (errorStatus & CERT_TRUST_IS_NOT_SIGNATURE_VALID)
|
|
|
|
error = TRUST_E_CERT_SIGNATURE;
|
|
|
|
else if (errorStatus & CERT_TRUST_IS_UNTRUSTED_ROOT)
|
|
|
|
error = CERT_E_UNTRUSTEDROOT;
|
|
|
|
else if (errorStatus & CERT_TRUST_IS_NOT_TIME_VALID)
|
|
|
|
error = CERT_E_EXPIRED;
|
|
|
|
else if (errorStatus & CERT_TRUST_IS_NOT_TIME_NESTED)
|
|
|
|
error = CERT_E_VALIDITYPERIODNESTING;
|
|
|
|
else if (errorStatus & CERT_TRUST_IS_REVOKED)
|
|
|
|
error = CERT_E_REVOKED;
|
|
|
|
else if (errorStatus & CERT_TRUST_IS_OFFLINE_REVOCATION ||
|
|
|
|
errorStatus & CERT_TRUST_REVOCATION_STATUS_UNKNOWN)
|
|
|
|
error = CERT_E_REVOCATION_FAILURE;
|
|
|
|
else if (errorStatus & CERT_TRUST_IS_NOT_VALID_FOR_USAGE)
|
|
|
|
error = CERT_E_WRONG_USAGE;
|
|
|
|
else if (errorStatus & CERT_TRUST_IS_CYCLIC)
|
|
|
|
error = CERT_E_CHAINING;
|
|
|
|
else if (errorStatus & CERT_TRUST_INVALID_EXTENSION)
|
|
|
|
error = CERT_E_CRITICAL;
|
|
|
|
else if (errorStatus & CERT_TRUST_INVALID_POLICY_CONSTRAINTS)
|
|
|
|
error = CERT_E_INVALID_POLICY;
|
|
|
|
else if (errorStatus & CERT_TRUST_INVALID_BASIC_CONSTRAINTS)
|
|
|
|
error = TRUST_E_BASIC_CONSTRAINTS;
|
|
|
|
else if (errorStatus & CERT_TRUST_INVALID_NAME_CONSTRAINTS ||
|
|
|
|
errorStatus & CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT ||
|
|
|
|
errorStatus & CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT ||
|
|
|
|
errorStatus & CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT ||
|
|
|
|
errorStatus & CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT)
|
|
|
|
error = CERT_E_INVALID_NAME;
|
|
|
|
else if (errorStatus & CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY)
|
|
|
|
error = CERT_E_INVALID_POLICY;
|
|
|
|
else if (errorStatus)
|
|
|
|
{
|
|
|
|
FIXME("unknown error status %08x\n", errorStatus);
|
|
|
|
error = TRUST_E_SYSTEM_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = S_OK;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-01-27 23:13:06 +01:00
|
|
|
static DWORD WINTRUST_CopyChain(CRYPT_PROVIDER_DATA *data, DWORD signerIdx)
|
2007-08-29 01:11:14 +02:00
|
|
|
{
|
2010-01-27 23:13:06 +01:00
|
|
|
DWORD err, i;
|
2007-08-29 01:11:14 +02:00
|
|
|
PCERT_SIMPLE_CHAIN simpleChain =
|
|
|
|
data->pasSigners[signerIdx].pChainContext->rgpChain[0];
|
|
|
|
|
2008-09-22 19:56:50 +02:00
|
|
|
data->pasSigners[signerIdx].pasCertChain[0].dwConfidence =
|
|
|
|
WINTRUST_TrustStatusToConfidence(
|
|
|
|
simpleChain->rgpElement[0]->TrustStatus.dwErrorStatus);
|
2007-08-29 01:11:14 +02:00
|
|
|
data->pasSigners[signerIdx].pasCertChain[0].pChainElement =
|
|
|
|
simpleChain->rgpElement[0];
|
2010-01-27 23:13:06 +01:00
|
|
|
err = ERROR_SUCCESS;
|
|
|
|
for (i = 1; !err && i < simpleChain->cElement; i++)
|
2007-08-29 01:11:14 +02:00
|
|
|
{
|
2010-01-27 23:13:06 +01:00
|
|
|
if (data->psPfns->pfnAddCert2Chain(data, signerIdx, FALSE, 0,
|
|
|
|
simpleChain->rgpElement[i]->pCertContext))
|
2008-09-22 19:56:50 +02:00
|
|
|
{
|
2007-08-29 01:11:14 +02:00
|
|
|
data->pasSigners[signerIdx].pasCertChain[i].pChainElement =
|
|
|
|
simpleChain->rgpElement[i];
|
2008-09-22 19:56:50 +02:00
|
|
|
data->pasSigners[signerIdx].pasCertChain[i].dwConfidence =
|
|
|
|
WINTRUST_TrustStatusToConfidence(
|
|
|
|
simpleChain->rgpElement[i]->TrustStatus.dwErrorStatus);
|
|
|
|
}
|
2010-01-27 23:13:06 +01:00
|
|
|
else
|
|
|
|
err = GetLastError();
|
2007-08-29 01:11:14 +02:00
|
|
|
}
|
2008-09-27 20:32:50 +02:00
|
|
|
data->pasSigners[signerIdx].pasCertChain[simpleChain->cElement - 1].dwError
|
|
|
|
= WINTRUST_TrustStatusToError(
|
|
|
|
simpleChain->rgpElement[simpleChain->cElement - 1]->
|
|
|
|
TrustStatus.dwErrorStatus);
|
2010-01-27 23:13:06 +01:00
|
|
|
return err;
|
2007-08-29 01:11:14 +02:00
|
|
|
}
|
|
|
|
|
2007-10-09 00:34:54 +02:00
|
|
|
static void WINTRUST_CreateChainPolicyCreateInfo(
|
|
|
|
const CRYPT_PROVIDER_DATA *data, PWTD_GENERIC_CHAIN_POLICY_CREATE_INFO info,
|
|
|
|
PCERT_CHAIN_PARA chainPara)
|
|
|
|
{
|
|
|
|
chainPara->cbSize = sizeof(CERT_CHAIN_PARA);
|
|
|
|
if (data->pRequestUsage)
|
2008-03-22 18:10:13 +01:00
|
|
|
chainPara->RequestedUsage = *data->pRequestUsage;
|
2008-09-22 20:42:59 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
chainPara->RequestedUsage.dwType = 0;
|
|
|
|
chainPara->RequestedUsage.Usage.cUsageIdentifier = 0;
|
|
|
|
}
|
2007-10-09 00:34:54 +02:00
|
|
|
info->u.cbSize = sizeof(WTD_GENERIC_CHAIN_POLICY_CREATE_INFO);
|
|
|
|
info->hChainEngine = NULL;
|
|
|
|
info->pChainPara = chainPara;
|
|
|
|
if (data->dwProvFlags & CPD_REVOCATION_CHECK_END_CERT)
|
|
|
|
info->dwFlags = CERT_CHAIN_REVOCATION_CHECK_END_CERT;
|
|
|
|
else if (data->dwProvFlags & CPD_REVOCATION_CHECK_CHAIN)
|
|
|
|
info->dwFlags = CERT_CHAIN_REVOCATION_CHECK_CHAIN;
|
|
|
|
else if (data->dwProvFlags & CPD_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT)
|
|
|
|
info->dwFlags = CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
|
|
|
|
else
|
|
|
|
info->dwFlags = 0;
|
|
|
|
info->pvReserved = NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-27 23:20:26 +01:00
|
|
|
static DWORD WINTRUST_CreateChainForSigner(CRYPT_PROVIDER_DATA *data,
|
2007-10-09 00:35:17 +02:00
|
|
|
DWORD signer, PWTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo,
|
|
|
|
PCERT_CHAIN_PARA chainPara)
|
|
|
|
{
|
2010-01-27 23:20:26 +01:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2008-09-22 19:56:19 +02:00
|
|
|
HCERTSTORE store = NULL;
|
2007-10-09 00:35:17 +02:00
|
|
|
|
2008-09-22 19:56:19 +02:00
|
|
|
if (data->chStores)
|
|
|
|
{
|
|
|
|
store = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
|
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
|
|
|
if (store)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for (i = 0; i < data->chStores; i++)
|
|
|
|
CertAddStoreToCollection(store, data->pahStores[i], 0, 0);
|
|
|
|
}
|
2010-01-27 23:14:53 +01:00
|
|
|
else
|
2010-01-27 23:20:26 +01:00
|
|
|
err = GetLastError();
|
2008-09-22 19:56:19 +02:00
|
|
|
}
|
2010-01-27 23:20:26 +01:00
|
|
|
if (!err)
|
2010-01-27 23:14:53 +01:00
|
|
|
{
|
|
|
|
/* Expect the end certificate for each signer to be the only cert in
|
|
|
|
* the chain:
|
|
|
|
*/
|
|
|
|
if (data->pasSigners[signer].csCertChain)
|
2007-10-09 00:35:17 +02:00
|
|
|
{
|
2010-01-27 23:20:26 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2010-01-27 23:14:53 +01:00
|
|
|
/* Create a certificate chain for each signer */
|
|
|
|
ret = CertGetCertificateChain(createInfo->hChainEngine,
|
|
|
|
data->pasSigners[signer].pasCertChain[0].pCert,
|
|
|
|
&data->pasSigners[signer].sftVerifyAsOf, store,
|
|
|
|
chainPara, createInfo->dwFlags, createInfo->pvReserved,
|
|
|
|
&data->pasSigners[signer].pChainContext);
|
|
|
|
if (ret)
|
2007-10-09 00:35:17 +02:00
|
|
|
{
|
2010-01-27 23:14:53 +01:00
|
|
|
if (data->pasSigners[signer].pChainContext->cChain != 1)
|
2008-09-22 22:19:24 +02:00
|
|
|
{
|
2010-01-27 23:14:53 +01:00
|
|
|
FIXME("unimplemented for more than 1 simple chain\n");
|
2010-01-27 23:20:26 +01:00
|
|
|
err = E_NOTIMPL;
|
2008-09-22 22:19:24 +02:00
|
|
|
}
|
2010-01-27 23:13:06 +01:00
|
|
|
else
|
|
|
|
{
|
2010-01-27 23:14:53 +01:00
|
|
|
if (!(err = WINTRUST_CopyChain(data, signer)))
|
|
|
|
{
|
|
|
|
if (data->psPfns->pfnCertCheckPolicy)
|
2010-01-27 23:20:26 +01:00
|
|
|
{
|
2010-01-27 23:14:53 +01:00
|
|
|
ret = data->psPfns->pfnCertCheckPolicy(data, signer,
|
|
|
|
FALSE, 0);
|
2010-01-27 23:20:26 +01:00
|
|
|
if (!ret)
|
|
|
|
err = GetLastError();
|
|
|
|
}
|
2010-01-27 23:14:53 +01:00
|
|
|
else
|
|
|
|
TRACE(
|
|
|
|
"no cert check policy, skipping policy check\n");
|
|
|
|
}
|
2010-01-27 23:13:06 +01:00
|
|
|
}
|
2007-10-09 00:35:17 +02:00
|
|
|
}
|
2010-01-27 23:20:26 +01:00
|
|
|
else
|
|
|
|
err = GetLastError();
|
2007-10-09 00:35:17 +02:00
|
|
|
}
|
2010-01-27 23:14:53 +01:00
|
|
|
CertCloseStore(store, 0);
|
2007-10-09 00:35:17 +02:00
|
|
|
}
|
2010-01-27 23:20:26 +01:00
|
|
|
return err;
|
2007-10-09 00:35:17 +02:00
|
|
|
}
|
|
|
|
|
2007-08-29 01:11:14 +02:00
|
|
|
HRESULT WINAPI WintrustCertificateTrust(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
2010-01-27 23:20:26 +01:00
|
|
|
DWORD err;
|
2007-08-29 01:11:14 +02:00
|
|
|
|
2007-10-09 00:45:28 +02:00
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
2007-08-29 01:11:14 +02:00
|
|
|
if (!data->csSigners)
|
2010-01-27 23:20:26 +01:00
|
|
|
err = TRUST_E_NOSIGNATURE;
|
2007-08-29 01:11:14 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD i;
|
2007-10-09 00:34:54 +02:00
|
|
|
WTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo;
|
|
|
|
CERT_CHAIN_PARA chainPara;
|
2007-08-29 01:11:14 +02:00
|
|
|
|
2007-10-09 00:34:54 +02:00
|
|
|
WINTRUST_CreateChainPolicyCreateInfo(data, &createInfo, &chainPara);
|
2010-01-27 23:20:26 +01:00
|
|
|
err = ERROR_SUCCESS;
|
|
|
|
for (i = 0; !err && i < data->csSigners; i++)
|
|
|
|
err = WINTRUST_CreateChainForSigner(data, i, &createInfo,
|
2007-10-09 00:35:17 +02:00
|
|
|
&chainPara);
|
2007-08-29 01:11:14 +02:00
|
|
|
}
|
2010-01-27 23:20:26 +01:00
|
|
|
if (err)
|
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV] = err;
|
|
|
|
TRACE("returning %d (%08x)\n", !err ? S_OK : S_FALSE,
|
2007-10-09 00:45:28 +02:00
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV]);
|
2010-01-27 23:20:26 +01:00
|
|
|
return !err ? S_OK : S_FALSE;
|
2007-08-29 01:11:14 +02:00
|
|
|
}
|
2007-09-12 17:58:45 +02:00
|
|
|
|
2007-10-09 00:40:22 +02:00
|
|
|
HRESULT WINAPI GenericChainCertificateTrust(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
2010-03-01 17:51:47 +01:00
|
|
|
DWORD err;
|
2007-10-09 00:40:22 +02:00
|
|
|
WTD_GENERIC_CHAIN_POLICY_DATA *policyData =
|
2009-01-29 11:15:29 +01:00
|
|
|
data->pWintrustData->pPolicyCallbackData;
|
2007-10-09 00:40:22 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
|
|
|
if (policyData && policyData->u.cbSize !=
|
|
|
|
sizeof(WTD_GENERIC_CHAIN_POLICY_CREATE_INFO))
|
|
|
|
{
|
2010-03-01 17:51:47 +01:00
|
|
|
err = ERROR_INVALID_PARAMETER;
|
2007-10-09 00:40:22 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (!data->csSigners)
|
2010-03-01 17:51:47 +01:00
|
|
|
err = TRUST_E_NOSIGNATURE;
|
2007-10-09 00:40:22 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
WTD_GENERIC_CHAIN_POLICY_CREATE_INFO createInfo, *pCreateInfo;
|
|
|
|
CERT_CHAIN_PARA chainPara, *pChainPara;
|
|
|
|
|
|
|
|
if (policyData)
|
|
|
|
{
|
|
|
|
pCreateInfo = policyData->pSignerChainInfo;
|
|
|
|
pChainPara = pCreateInfo->pChainPara;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINTRUST_CreateChainPolicyCreateInfo(data, &createInfo, &chainPara);
|
|
|
|
pChainPara = &chainPara;
|
|
|
|
pCreateInfo = &createInfo;
|
|
|
|
}
|
2010-03-01 17:51:47 +01:00
|
|
|
err = ERROR_SUCCESS;
|
|
|
|
for (i = 0; !err && i < data->csSigners; i++)
|
|
|
|
err = WINTRUST_CreateChainForSigner(data, i, pCreateInfo,
|
2007-10-09 00:40:22 +02:00
|
|
|
pChainPara);
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2010-03-01 17:51:47 +01:00
|
|
|
if (err)
|
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV] = err;
|
|
|
|
TRACE("returning %d (%08x)\n", !err ? S_OK : S_FALSE,
|
2007-10-09 00:40:22 +02:00
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV]);
|
2010-03-01 17:51:47 +01:00
|
|
|
return !err ? S_OK : S_FALSE;
|
2007-10-09 00:40:22 +02:00
|
|
|
}
|
|
|
|
|
2007-09-12 17:59:44 +02:00
|
|
|
HRESULT WINAPI SoftpubAuthenticode(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CERT_CHAIN_POLICY_STATUS policyStatus = { sizeof(policyStatus), 0 };
|
|
|
|
|
2007-10-09 00:45:28 +02:00
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
2007-09-12 17:59:44 +02:00
|
|
|
if (data->pWintrustData->dwUIChoice != WTD_UI_NONE)
|
|
|
|
FIXME("unimplemented for UI choice %d\n",
|
|
|
|
data->pWintrustData->dwUIChoice);
|
|
|
|
if (!data->csSigners)
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
policyStatus.dwError = TRUST_E_NOSIGNATURE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
for (i = 0; ret && i < data->csSigners; i++)
|
|
|
|
{
|
2008-09-22 22:19:59 +02:00
|
|
|
BYTE hash[20];
|
|
|
|
DWORD size = sizeof(hash);
|
|
|
|
|
|
|
|
/* First make sure cert isn't disallowed */
|
|
|
|
if ((ret = CertGetCertificateContextProperty(
|
|
|
|
data->pasSigners[i].pasCertChain[0].pCert,
|
|
|
|
CERT_SIGNATURE_HASH_PROP_ID, hash, &size)))
|
|
|
|
{
|
|
|
|
static const WCHAR disallowedW[] =
|
|
|
|
{ 'D','i','s','a','l','l','o','w','e','d',0 };
|
|
|
|
HCERTSTORE disallowed = CertOpenStore(CERT_STORE_PROV_SYSTEM_W,
|
|
|
|
X509_ASN_ENCODING, 0, CERT_SYSTEM_STORE_CURRENT_USER,
|
|
|
|
disallowedW);
|
|
|
|
|
|
|
|
if (disallowed)
|
|
|
|
{
|
|
|
|
PCCERT_CONTEXT found = CertFindCertificateInStore(
|
|
|
|
disallowed, X509_ASN_ENCODING, 0, CERT_FIND_SIGNATURE_HASH,
|
|
|
|
hash, NULL);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
/* Disallowed! Can't verify it. */
|
|
|
|
policyStatus.dwError = TRUST_E_SUBJECT_NOT_TRUSTED;
|
|
|
|
ret = FALSE;
|
|
|
|
CertFreeCertificateContext(found);
|
|
|
|
}
|
|
|
|
CertCloseStore(disallowed, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
CERT_CHAIN_POLICY_PARA policyPara = { sizeof(policyPara), 0 };
|
|
|
|
|
|
|
|
if (data->dwRegPolicySettings & WTPF_TRUSTTEST)
|
|
|
|
policyPara.dwFlags |= CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG;
|
|
|
|
if (data->dwRegPolicySettings & WTPF_TESTCANBEVALID)
|
|
|
|
policyPara.dwFlags |= CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG;
|
|
|
|
if (data->dwRegPolicySettings & WTPF_IGNOREEXPIRATION)
|
|
|
|
policyPara.dwFlags |=
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG;
|
|
|
|
if (data->dwRegPolicySettings & WTPF_IGNOREREVOKATION)
|
|
|
|
policyPara.dwFlags |=
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG;
|
|
|
|
CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_AUTHENTICODE,
|
|
|
|
data->pasSigners[i].pChainContext, &policyPara, &policyStatus);
|
|
|
|
if (policyStatus.dwError != NO_ERROR)
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
2007-09-12 17:59:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV] =
|
|
|
|
policyStatus.dwError;
|
2007-10-09 00:45:28 +02:00
|
|
|
TRACE("returning %d (%08x)\n", ret ? S_OK : S_FALSE,
|
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV]);
|
2007-09-12 17:59:44 +02:00
|
|
|
return ret ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-10-09 00:44:01 +02:00
|
|
|
static HRESULT WINAPI WINTRUST_DefaultPolicy(CRYPT_PROVIDER_DATA *pProvData,
|
|
|
|
DWORD dwStepError, DWORD dwRegPolicySettings, DWORD cSigner,
|
|
|
|
PWTD_GENERIC_CHAIN_POLICY_SIGNER_INFO rgpSigner, void *pvPolicyArg)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
CERT_CHAIN_POLICY_STATUS policyStatus = { sizeof(policyStatus), 0 };
|
|
|
|
|
|
|
|
for (i = 0; !policyStatus.dwError && i < cSigner; i++)
|
|
|
|
{
|
|
|
|
CERT_CHAIN_POLICY_PARA policyPara = { sizeof(policyPara), 0 };
|
|
|
|
|
|
|
|
if (dwRegPolicySettings & WTPF_IGNOREEXPIRATION)
|
|
|
|
policyPara.dwFlags |=
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG;
|
|
|
|
if (dwRegPolicySettings & WTPF_IGNOREREVOKATION)
|
|
|
|
policyPara.dwFlags |=
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG |
|
|
|
|
CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG;
|
|
|
|
CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE,
|
|
|
|
rgpSigner[i].pChainContext, &policyPara, &policyStatus);
|
|
|
|
}
|
|
|
|
return policyStatus.dwError;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI GenericChainFinalProv(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
HRESULT err = NO_ERROR; /* not a typo, MS confused the types */
|
|
|
|
WTD_GENERIC_CHAIN_POLICY_DATA *policyData =
|
2009-01-29 11:15:29 +01:00
|
|
|
data->pWintrustData->pPolicyCallbackData;
|
2007-10-09 00:44:01 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
|
|
|
if (data->pWintrustData->dwUIChoice != WTD_UI_NONE)
|
|
|
|
FIXME("unimplemented for UI choice %d\n",
|
|
|
|
data->pWintrustData->dwUIChoice);
|
|
|
|
if (!data->csSigners)
|
|
|
|
err = TRUST_E_NOSIGNATURE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PFN_WTD_GENERIC_CHAIN_POLICY_CALLBACK policyCallback;
|
|
|
|
void *policyArg;
|
|
|
|
WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO *signers = NULL;
|
|
|
|
|
|
|
|
if (policyData)
|
|
|
|
{
|
|
|
|
policyCallback = policyData->pfnPolicyCallback;
|
|
|
|
policyArg = policyData->pvPolicyArg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
policyCallback = WINTRUST_DefaultPolicy;
|
|
|
|
policyArg = NULL;
|
|
|
|
}
|
|
|
|
if (data->csSigners)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
signers = data->psPfns->pfnAlloc(
|
|
|
|
data->csSigners * sizeof(WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO));
|
|
|
|
if (signers)
|
|
|
|
{
|
|
|
|
for (i = 0; i < data->csSigners; i++)
|
|
|
|
{
|
|
|
|
signers[i].u.cbSize =
|
|
|
|
sizeof(WTD_GENERIC_CHAIN_POLICY_SIGNER_INFO);
|
|
|
|
signers[i].pChainContext =
|
|
|
|
data->pasSigners[i].pChainContext;
|
|
|
|
signers[i].dwSignerType = data->pasSigners[i].dwSignerType;
|
|
|
|
signers[i].pMsgSignerInfo = data->pasSigners[i].psSigner;
|
|
|
|
signers[i].dwError = data->pasSigners[i].dwError;
|
|
|
|
if (data->pasSigners[i].csCounterSigners)
|
|
|
|
FIXME("unimplemented for counter signers\n");
|
|
|
|
signers[i].cCounterSigner = 0;
|
|
|
|
signers[i].rgpCounterSigner = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2008-09-12 14:01:20 +02:00
|
|
|
if (err == NO_ERROR)
|
2007-10-09 00:44:01 +02:00
|
|
|
err = policyCallback(data, TRUSTERROR_STEP_FINAL_POLICYPROV,
|
|
|
|
data->dwRegPolicySettings, data->csSigners, signers, policyArg);
|
|
|
|
data->psPfns->pfnFree(signers);
|
|
|
|
}
|
2008-09-12 14:01:20 +02:00
|
|
|
if (err != NO_ERROR)
|
2007-10-09 00:44:01 +02:00
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV] = err;
|
2008-09-12 14:01:20 +02:00
|
|
|
TRACE("returning %d (%08x)\n", err == NO_ERROR ? S_OK : S_FALSE,
|
2007-10-09 00:44:01 +02:00
|
|
|
data->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV]);
|
|
|
|
return err == NO_ERROR ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-09-12 17:58:45 +02:00
|
|
|
HRESULT WINAPI SoftpubCleanup(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
DWORD i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < data->csSigners; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < data->pasSigners[i].csCertChain; j++)
|
|
|
|
CertFreeCertificateContext(data->pasSigners[i].pasCertChain[j].pCert);
|
|
|
|
data->psPfns->pfnFree(data->pasSigners[i].pasCertChain);
|
|
|
|
data->psPfns->pfnFree(data->pasSigners[i].psSigner);
|
|
|
|
CertFreeCertificateChain(data->pasSigners[i].pChainContext);
|
|
|
|
}
|
|
|
|
data->psPfns->pfnFree(data->pasSigners);
|
|
|
|
|
|
|
|
for (i = 0; i < data->chStores; i++)
|
|
|
|
CertCloseStore(data->pahStores[i], 0);
|
|
|
|
data->psPfns->pfnFree(data->pahStores);
|
|
|
|
|
|
|
|
if (data->u.pPDSip)
|
|
|
|
{
|
|
|
|
data->psPfns->pfnFree(data->u.pPDSip->pSip);
|
|
|
|
data->psPfns->pfnFree(data->u.pPDSip->pCATSip);
|
|
|
|
data->psPfns->pfnFree(data->u.pPDSip->psSipSubjectInfo);
|
|
|
|
data->psPfns->pfnFree(data->u.pPDSip->psSipCATSubjectInfo);
|
|
|
|
data->psPfns->pfnFree(data->u.pPDSip->psIndirectData);
|
|
|
|
}
|
|
|
|
|
|
|
|
CryptMsgClose(data->hMsg);
|
|
|
|
|
2009-11-04 01:15:32 +01:00
|
|
|
if (data->fOpenedFile &&
|
2011-12-11 17:36:55 +01:00
|
|
|
data->pWintrustData->dwUnionChoice == WTD_CHOICE_FILE &&
|
|
|
|
data->pWintrustData->u.pFile)
|
2014-11-25 21:26:54 +01:00
|
|
|
{
|
2007-09-12 17:58:45 +02:00
|
|
|
CloseHandle(data->pWintrustData->u.pFile->hFile);
|
2014-11-25 21:26:54 +01:00
|
|
|
data->pWintrustData->u.pFile->hFile = INVALID_HANDLE_VALUE;
|
|
|
|
data->fOpenedFile = FALSE;
|
|
|
|
}
|
2007-09-12 17:58:45 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-06-12 11:36:08 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI HTTPSCertificateTrust(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
FIXME("(%p)\n", data);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI HTTPSFinalProv(CRYPT_PROVIDER_DATA *data)
|
|
|
|
{
|
|
|
|
FIXME("(%p)\n", data);
|
|
|
|
return S_OK;
|
|
|
|
}
|