2007-09-25 23:45:29 +02:00
|
|
|
/*
|
|
|
|
* crypt32 Crypt*Object functions
|
|
|
|
*
|
|
|
|
* 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>
|
2008-11-06 22:48:14 +01:00
|
|
|
#define NONAMELESSUNION
|
2007-09-25 23:45:29 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincrypt.h"
|
2008-08-05 07:04:10 +02:00
|
|
|
#include "mssip.h"
|
2008-11-06 22:48:14 +01:00
|
|
|
#include "winuser.h"
|
2008-11-06 23:42:58 +01:00
|
|
|
#include "wintrust.h"
|
2007-09-25 23:45:29 +02:00
|
|
|
#include "crypt32_private.h"
|
2008-11-06 22:48:14 +01:00
|
|
|
#include "cryptres.h"
|
2007-09-25 23:45:29 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
|
|
|
|
|
|
|
static BOOL CRYPT_ReadBlobFromFile(LPCWSTR fileName, PCERT_BLOB blob)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
HANDLE file;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(fileName));
|
|
|
|
|
|
|
|
file = CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, 0, NULL);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
blob->cbData = GetFileSize(file, NULL);
|
|
|
|
if (blob->cbData)
|
|
|
|
{
|
|
|
|
blob->pbData = CryptMemAlloc(blob->cbData);
|
|
|
|
if (blob->pbData)
|
|
|
|
{
|
|
|
|
DWORD read;
|
|
|
|
|
2013-10-29 08:09:05 +01:00
|
|
|
ret = ReadFile(file, blob->pbData, blob->cbData, &read, NULL) && read == blob->cbData;
|
|
|
|
if (!ret) CryptMemFree(blob->pbData);
|
2007-09-25 23:45:29 +02:00
|
|
|
}
|
2013-12-08 06:09:17 +01:00
|
|
|
else
|
|
|
|
ret = FALSE;
|
2007-09-25 23:45:29 +02:00
|
|
|
}
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-12 00:42:06 +01:00
|
|
|
static BOOL CRYPT_QueryContextBlob(const CERT_BLOB *blob,
|
|
|
|
DWORD dwExpectedContentTypeFlags, HCERTSTORE store,
|
|
|
|
DWORD *contentType, const void **ppvContext)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_CERT)
|
|
|
|
{
|
|
|
|
ret = pCertInterface->addEncodedToStore(store, X509_ASN_ENCODING,
|
|
|
|
blob->pbData, blob->cbData, CERT_STORE_ADD_ALWAYS, ppvContext);
|
|
|
|
if (ret && contentType)
|
|
|
|
*contentType = CERT_QUERY_CONTENT_CERT;
|
|
|
|
}
|
|
|
|
if (!ret && (dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_CRL))
|
|
|
|
{
|
|
|
|
ret = pCRLInterface->addEncodedToStore(store, X509_ASN_ENCODING,
|
|
|
|
blob->pbData, blob->cbData, CERT_STORE_ADD_ALWAYS, ppvContext);
|
|
|
|
if (ret && contentType)
|
|
|
|
*contentType = CERT_QUERY_CONTENT_CRL;
|
|
|
|
}
|
|
|
|
if (!ret && (dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_CTL))
|
|
|
|
{
|
|
|
|
ret = pCTLInterface->addEncodedToStore(store, X509_ASN_ENCODING,
|
|
|
|
blob->pbData, blob->cbData, CERT_STORE_ADD_ALWAYS, ppvContext);
|
|
|
|
if (ret && contentType)
|
|
|
|
*contentType = CERT_QUERY_CONTENT_CTL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:45:29 +02:00
|
|
|
static BOOL CRYPT_QueryContextObject(DWORD dwObjectType, const void *pvObject,
|
2008-12-12 00:42:06 +01:00
|
|
|
DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType, DWORD *pdwFormatType,
|
|
|
|
HCERTSTORE *phCertStore, const void **ppvContext)
|
2007-09-25 23:45:29 +02:00
|
|
|
{
|
|
|
|
CERT_BLOB fileBlob;
|
|
|
|
const CERT_BLOB *blob;
|
|
|
|
HCERTSTORE store;
|
|
|
|
BOOL ret;
|
2008-12-12 00:42:06 +01:00
|
|
|
DWORD formatType = 0;
|
2007-09-25 23:45:29 +02:00
|
|
|
|
|
|
|
switch (dwObjectType)
|
|
|
|
{
|
|
|
|
case CERT_QUERY_OBJECT_FILE:
|
|
|
|
/* Cert, CRL, and CTL contexts can't be "embedded" in a file, so
|
|
|
|
* just read the file directly
|
|
|
|
*/
|
2009-01-28 10:25:22 +01:00
|
|
|
ret = CRYPT_ReadBlobFromFile(pvObject, &fileBlob);
|
2007-09-25 23:45:29 +02:00
|
|
|
blob = &fileBlob;
|
|
|
|
break;
|
|
|
|
case CERT_QUERY_OBJECT_BLOB:
|
2009-01-28 10:25:22 +01:00
|
|
|
blob = pvObject;
|
2007-09-25 23:45:29 +02:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError(E_INVALIDARG); /* FIXME: is this the correct error? */
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-12-12 00:42:06 +01:00
|
|
|
ret = FALSE;
|
2007-09-25 23:45:29 +02:00
|
|
|
store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
2008-12-12 00:42:06 +01:00
|
|
|
if (dwExpectedFormatTypeFlags & CERT_QUERY_FORMAT_FLAG_BINARY)
|
2007-09-25 23:45:29 +02:00
|
|
|
{
|
2008-12-12 00:42:06 +01:00
|
|
|
ret = CRYPT_QueryContextBlob(blob, dwExpectedContentTypeFlags, store,
|
|
|
|
pdwContentType, ppvContext);
|
2007-09-25 23:45:29 +02:00
|
|
|
if (ret)
|
2008-12-12 00:42:06 +01:00
|
|
|
formatType = CERT_QUERY_FORMAT_BINARY;
|
2007-09-25 23:45:29 +02:00
|
|
|
}
|
2008-12-12 00:42:06 +01:00
|
|
|
if (!ret &&
|
|
|
|
(dwExpectedFormatTypeFlags & CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED))
|
2007-09-25 23:45:29 +02:00
|
|
|
{
|
2008-12-12 00:42:06 +01:00
|
|
|
CRYPT_DATA_BLOB trimmed = { blob->cbData, blob->pbData };
|
|
|
|
CRYPT_DATA_BLOB decoded;
|
|
|
|
|
|
|
|
while (trimmed.cbData && !trimmed.pbData[trimmed.cbData - 1])
|
|
|
|
trimmed.cbData--;
|
|
|
|
ret = CryptStringToBinaryA((LPSTR)trimmed.pbData, trimmed.cbData,
|
|
|
|
CRYPT_STRING_BASE64_ANY, NULL, &decoded.cbData, NULL, NULL);
|
2007-09-25 23:45:29 +02:00
|
|
|
if (ret)
|
2008-12-12 00:42:06 +01:00
|
|
|
{
|
|
|
|
decoded.pbData = CryptMemAlloc(decoded.cbData);
|
|
|
|
if (decoded.pbData)
|
|
|
|
{
|
|
|
|
ret = CryptStringToBinaryA((LPSTR)trimmed.pbData,
|
|
|
|
trimmed.cbData, CRYPT_STRING_BASE64_ANY, decoded.pbData,
|
|
|
|
&decoded.cbData, NULL, NULL);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
ret = CRYPT_QueryContextBlob(&decoded,
|
|
|
|
dwExpectedContentTypeFlags, store, pdwContentType,
|
|
|
|
ppvContext);
|
|
|
|
if (ret)
|
|
|
|
formatType = CERT_QUERY_FORMAT_BASE64_ENCODED;
|
|
|
|
}
|
|
|
|
CryptMemFree(decoded.pbData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
2007-09-25 23:45:29 +02:00
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (pdwMsgAndCertEncodingType)
|
|
|
|
*pdwMsgAndCertEncodingType = X509_ASN_ENCODING;
|
2008-12-12 00:42:06 +01:00
|
|
|
if (pdwFormatType)
|
|
|
|
*pdwFormatType = formatType;
|
2007-09-25 23:45:29 +02:00
|
|
|
if (phCertStore)
|
|
|
|
*phCertStore = CertDuplicateStore(store);
|
|
|
|
}
|
|
|
|
CertCloseStore(store, 0);
|
|
|
|
if (blob == &fileBlob)
|
|
|
|
CryptMemFree(blob->pbData);
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CRYPT_QuerySerializedContextObject(DWORD dwObjectType,
|
|
|
|
const void *pvObject, DWORD dwExpectedContentTypeFlags,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
|
|
|
|
HCERTSTORE *phCertStore, const void **ppvContext)
|
|
|
|
{
|
|
|
|
CERT_BLOB fileBlob;
|
|
|
|
const CERT_BLOB *blob;
|
|
|
|
const WINE_CONTEXT_INTERFACE *contextInterface = NULL;
|
|
|
|
const void *context;
|
|
|
|
DWORD contextType;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
switch (dwObjectType)
|
|
|
|
{
|
|
|
|
case CERT_QUERY_OBJECT_FILE:
|
|
|
|
/* Cert, CRL, and CTL contexts can't be "embedded" in a file, so
|
|
|
|
* just read the file directly
|
|
|
|
*/
|
2009-01-28 10:25:22 +01:00
|
|
|
ret = CRYPT_ReadBlobFromFile(pvObject, &fileBlob);
|
2007-09-25 23:45:29 +02:00
|
|
|
blob = &fileBlob;
|
|
|
|
break;
|
|
|
|
case CERT_QUERY_OBJECT_BLOB:
|
2009-01-28 10:25:22 +01:00
|
|
|
blob = pvObject;
|
2007-09-25 23:45:29 +02:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError(E_INVALIDARG); /* FIXME: is this the correct error? */
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-12-12 00:23:31 +01:00
|
|
|
ret = FALSE;
|
2007-09-25 23:45:29 +02:00
|
|
|
context = CRYPT_ReadSerializedElement(blob->pbData, blob->cbData,
|
|
|
|
CERT_STORE_ALL_CONTEXT_FLAG, &contextType);
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
DWORD contentType, certStoreOffset;
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
switch (contextType)
|
|
|
|
{
|
|
|
|
case CERT_STORE_CERTIFICATE_CONTEXT:
|
|
|
|
contextInterface = pCertInterface;
|
|
|
|
contentType = CERT_QUERY_CONTENT_SERIALIZED_CERT;
|
|
|
|
certStoreOffset = offsetof(CERT_CONTEXT, hCertStore);
|
|
|
|
if (!(dwExpectedContentTypeFlags &
|
|
|
|
CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CERT_STORE_CRL_CONTEXT:
|
|
|
|
contextInterface = pCRLInterface;
|
|
|
|
contentType = CERT_QUERY_CONTENT_SERIALIZED_CRL;
|
|
|
|
certStoreOffset = offsetof(CRL_CONTEXT, hCertStore);
|
|
|
|
if (!(dwExpectedContentTypeFlags &
|
|
|
|
CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CERT_STORE_CTL_CONTEXT:
|
|
|
|
contextInterface = pCTLInterface;
|
|
|
|
contentType = CERT_QUERY_CONTENT_SERIALIZED_CTL;
|
|
|
|
certStoreOffset = offsetof(CTL_CONTEXT, hCertStore);
|
|
|
|
if (!(dwExpectedContentTypeFlags &
|
|
|
|
CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (pdwMsgAndCertEncodingType)
|
|
|
|
*pdwMsgAndCertEncodingType = X509_ASN_ENCODING;
|
|
|
|
if (pdwContentType)
|
|
|
|
*pdwContentType = contentType;
|
|
|
|
if (phCertStore)
|
|
|
|
*phCertStore = CertDuplicateStore(
|
|
|
|
*(HCERTSTORE *)((const BYTE *)context + certStoreOffset));
|
|
|
|
if (ppvContext)
|
2013-10-14 14:47:40 +02:00
|
|
|
{
|
|
|
|
*ppvContext = context;
|
|
|
|
Context_AddRef(context_from_ptr(context));
|
|
|
|
}
|
2007-09-25 23:45:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (contextInterface && context)
|
2013-10-14 14:47:50 +02:00
|
|
|
Context_Release(context_from_ptr(context));
|
2007-09-25 23:45:29 +02:00
|
|
|
if (blob == &fileBlob)
|
|
|
|
CryptMemFree(blob->pbData);
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-30 00:48:52 +01:00
|
|
|
static BOOL CRYPT_QuerySerializedStoreFromFile(LPCWSTR fileName,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
|
2007-09-25 23:45:29 +02:00
|
|
|
HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
|
|
|
|
{
|
|
|
|
HANDLE file;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(fileName));
|
|
|
|
file = CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, 0, NULL);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
|
|
|
|
2007-09-27 20:54:24 +02:00
|
|
|
ret = CRYPT_ReadSerializedStoreFromFile(file, store);
|
2007-09-25 23:45:29 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (pdwMsgAndCertEncodingType)
|
|
|
|
*pdwMsgAndCertEncodingType = X509_ASN_ENCODING;
|
|
|
|
if (pdwContentType)
|
|
|
|
*pdwContentType = CERT_QUERY_CONTENT_SERIALIZED_STORE;
|
|
|
|
if (phCertStore)
|
|
|
|
*phCertStore = CertDuplicateStore(store);
|
|
|
|
}
|
|
|
|
CertCloseStore(store, 0);
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-30 00:48:52 +01:00
|
|
|
static BOOL CRYPT_QuerySerializedStoreFromBlob(const CRYPT_DATA_BLOB *blob,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
|
|
|
|
HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
|
|
|
|
{
|
|
|
|
HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
|
|
|
|
CERT_STORE_CREATE_NEW_FLAG, NULL);
|
|
|
|
BOOL ret;
|
|
|
|
|
2022-02-09 09:25:50 +01:00
|
|
|
TRACE("(%ld, %p)\n", blob->cbData, blob->pbData);
|
2009-10-30 00:48:52 +01:00
|
|
|
|
|
|
|
ret = CRYPT_ReadSerializedStoreFromBlob(blob, store);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (pdwMsgAndCertEncodingType)
|
|
|
|
*pdwMsgAndCertEncodingType = X509_ASN_ENCODING;
|
|
|
|
if (pdwContentType)
|
|
|
|
*pdwContentType = CERT_QUERY_CONTENT_SERIALIZED_STORE;
|
|
|
|
if (phCertStore)
|
|
|
|
*phCertStore = CertDuplicateStore(store);
|
|
|
|
}
|
|
|
|
CertCloseStore(store, 0);
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CRYPT_QuerySerializedStoreObject(DWORD dwObjectType,
|
|
|
|
const void *pvObject, DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
|
|
|
|
HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
|
|
|
|
{
|
|
|
|
switch (dwObjectType)
|
|
|
|
{
|
|
|
|
case CERT_QUERY_OBJECT_FILE:
|
|
|
|
return CRYPT_QuerySerializedStoreFromFile(pvObject,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, phCertStore, phMsg);
|
|
|
|
case CERT_QUERY_OBJECT_BLOB:
|
|
|
|
return CRYPT_QuerySerializedStoreFromBlob(pvObject,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, phCertStore, phMsg);
|
|
|
|
default:
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("unimplemented for type %ld\n", dwObjectType);
|
2009-10-30 00:48:52 +01:00
|
|
|
SetLastError(E_INVALIDARG); /* FIXME: is this the correct error? */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-12 01:18:47 +01:00
|
|
|
static BOOL CRYPT_QuerySignedMessage(const CRYPT_DATA_BLOB *blob,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType, HCRYPTMSG *phMsg)
|
|
|
|
{
|
|
|
|
DWORD encodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
HCRYPTMSG msg;
|
|
|
|
|
|
|
|
if ((msg = CryptMsgOpenToDecode(encodingType, 0, 0, 0, NULL, NULL)))
|
|
|
|
{
|
|
|
|
ret = CryptMsgUpdate(msg, blob->pbData, blob->cbData, TRUE);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
DWORD type, len = sizeof(type);
|
|
|
|
|
|
|
|
ret = CryptMsgGetParam(msg, CMSG_TYPE_PARAM, 0, &type, &len);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (type != CMSG_SIGNED)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
CryptMsgClose(msg);
|
|
|
|
msg = CryptMsgOpenToDecode(encodingType, 0, CMSG_SIGNED, 0, NULL,
|
|
|
|
NULL);
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
ret = CryptMsgUpdate(msg, blob->pbData, blob->cbData, TRUE);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
CryptMsgClose(msg);
|
|
|
|
msg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (pdwMsgAndCertEncodingType)
|
|
|
|
*pdwMsgAndCertEncodingType = encodingType;
|
|
|
|
if (pdwContentType)
|
|
|
|
*pdwContentType = CERT_QUERY_CONTENT_PKCS7_SIGNED;
|
|
|
|
if (phMsg)
|
|
|
|
*phMsg = msg;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CRYPT_QueryUnsignedMessage(const CRYPT_DATA_BLOB *blob,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType, HCRYPTMSG *phMsg)
|
|
|
|
{
|
|
|
|
DWORD encodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
HCRYPTMSG msg;
|
|
|
|
|
|
|
|
if ((msg = CryptMsgOpenToDecode(encodingType, 0, 0, 0, NULL, NULL)))
|
|
|
|
{
|
|
|
|
ret = CryptMsgUpdate(msg, blob->pbData, blob->cbData, TRUE);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
DWORD type, len = sizeof(type);
|
|
|
|
|
|
|
|
ret = CryptMsgGetParam(msg, CMSG_TYPE_PARAM, 0, &type, &len);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (type != CMSG_DATA)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
CryptMsgClose(msg);
|
|
|
|
msg = CryptMsgOpenToDecode(encodingType, 0, CMSG_DATA, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
ret = CryptMsgUpdate(msg, blob->pbData, blob->cbData, TRUE);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
CryptMsgClose(msg);
|
|
|
|
msg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (pdwMsgAndCertEncodingType)
|
|
|
|
*pdwMsgAndCertEncodingType = encodingType;
|
|
|
|
if (pdwContentType)
|
|
|
|
*pdwContentType = CERT_QUERY_CONTENT_PKCS7_SIGNED;
|
|
|
|
if (phMsg)
|
|
|
|
*phMsg = msg;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:45:29 +02:00
|
|
|
/* Used to decode non-embedded messages */
|
|
|
|
static BOOL CRYPT_QueryMessageObject(DWORD dwObjectType, const void *pvObject,
|
2008-12-12 01:36:46 +01:00
|
|
|
DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType, DWORD *pdwFormatType,
|
|
|
|
HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
|
2007-09-25 23:45:29 +02:00
|
|
|
{
|
|
|
|
CERT_BLOB fileBlob;
|
|
|
|
const CERT_BLOB *blob;
|
|
|
|
BOOL ret;
|
|
|
|
HCRYPTMSG msg = NULL;
|
|
|
|
DWORD encodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
|
2008-12-12 01:36:46 +01:00
|
|
|
DWORD formatType = 0;
|
|
|
|
|
2022-02-09 09:25:50 +01:00
|
|
|
TRACE("(%ld, %p, %08lx, %08lx, %p, %p, %p, %p, %p)\n", dwObjectType, pvObject,
|
2008-12-12 01:36:46 +01:00
|
|
|
dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType, phCertStore,
|
|
|
|
phMsg);
|
2007-09-25 23:45:29 +02:00
|
|
|
|
|
|
|
switch (dwObjectType)
|
|
|
|
{
|
|
|
|
case CERT_QUERY_OBJECT_FILE:
|
|
|
|
/* This isn't an embedded PKCS7 message, so just read the file
|
|
|
|
* directly
|
|
|
|
*/
|
2009-01-28 10:25:22 +01:00
|
|
|
ret = CRYPT_ReadBlobFromFile(pvObject, &fileBlob);
|
2007-09-25 23:45:29 +02:00
|
|
|
blob = &fileBlob;
|
|
|
|
break;
|
|
|
|
case CERT_QUERY_OBJECT_BLOB:
|
2009-01-28 10:25:22 +01:00
|
|
|
blob = pvObject;
|
2007-09-25 23:45:29 +02:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError(E_INVALIDARG); /* FIXME: is this the correct error? */
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ret = FALSE;
|
2008-12-12 01:36:46 +01:00
|
|
|
if (dwExpectedFormatTypeFlags & CERT_QUERY_FORMAT_FLAG_BINARY)
|
|
|
|
{
|
|
|
|
/* Try it first as a signed message */
|
|
|
|
if (dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED)
|
|
|
|
ret = CRYPT_QuerySignedMessage(blob, pdwMsgAndCertEncodingType,
|
|
|
|
pdwContentType, &msg);
|
|
|
|
/* Failing that, try as an unsigned message */
|
|
|
|
if (!ret &&
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED))
|
|
|
|
ret = CRYPT_QueryUnsignedMessage(blob, pdwMsgAndCertEncodingType,
|
|
|
|
pdwContentType, &msg);
|
|
|
|
if (ret)
|
|
|
|
formatType = CERT_QUERY_FORMAT_BINARY;
|
|
|
|
}
|
2007-09-25 23:45:29 +02:00
|
|
|
if (!ret &&
|
2008-12-12 01:36:46 +01:00
|
|
|
(dwExpectedFormatTypeFlags & CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED))
|
|
|
|
{
|
|
|
|
CRYPT_DATA_BLOB trimmed = { blob->cbData, blob->pbData };
|
|
|
|
CRYPT_DATA_BLOB decoded;
|
|
|
|
|
|
|
|
while (trimmed.cbData && !trimmed.pbData[trimmed.cbData - 1])
|
|
|
|
trimmed.cbData--;
|
|
|
|
ret = CryptStringToBinaryA((LPSTR)trimmed.pbData, trimmed.cbData,
|
|
|
|
CRYPT_STRING_BASE64_ANY, NULL, &decoded.cbData, NULL, NULL);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
decoded.pbData = CryptMemAlloc(decoded.cbData);
|
|
|
|
if (decoded.pbData)
|
|
|
|
{
|
|
|
|
ret = CryptStringToBinaryA((LPSTR)trimmed.pbData,
|
|
|
|
trimmed.cbData, CRYPT_STRING_BASE64_ANY, decoded.pbData,
|
|
|
|
&decoded.cbData, NULL, NULL);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
/* Try it first as a signed message */
|
|
|
|
if (dwExpectedContentTypeFlags &
|
|
|
|
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED)
|
|
|
|
ret = CRYPT_QuerySignedMessage(&decoded,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, &msg);
|
|
|
|
/* Failing that, try as an unsigned message */
|
|
|
|
if (!ret && (dwExpectedContentTypeFlags &
|
|
|
|
CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED))
|
|
|
|
ret = CRYPT_QueryUnsignedMessage(&decoded,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, &msg);
|
|
|
|
if (ret)
|
|
|
|
formatType = CERT_QUERY_FORMAT_BASE64_ENCODED;
|
|
|
|
}
|
|
|
|
CryptMemFree(decoded.pbData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
2008-12-12 02:02:13 +01:00
|
|
|
if (!ret && !(blob->cbData % sizeof(WCHAR)))
|
|
|
|
{
|
|
|
|
CRYPT_DATA_BLOB decoded;
|
|
|
|
LPWSTR str = (LPWSTR)blob->pbData;
|
|
|
|
DWORD strLen = blob->cbData / sizeof(WCHAR);
|
|
|
|
|
|
|
|
/* Try again, assuming the input string is UTF-16 base64 */
|
|
|
|
while (strLen && !str[strLen - 1])
|
|
|
|
strLen--;
|
|
|
|
ret = CryptStringToBinaryW(str, strLen, CRYPT_STRING_BASE64_ANY,
|
|
|
|
NULL, &decoded.cbData, NULL, NULL);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
decoded.pbData = CryptMemAlloc(decoded.cbData);
|
|
|
|
if (decoded.pbData)
|
|
|
|
{
|
|
|
|
ret = CryptStringToBinaryW(str, strLen,
|
|
|
|
CRYPT_STRING_BASE64_ANY, decoded.pbData, &decoded.cbData,
|
|
|
|
NULL, NULL);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
/* Try it first as a signed message */
|
|
|
|
if (dwExpectedContentTypeFlags &
|
|
|
|
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED)
|
|
|
|
ret = CRYPT_QuerySignedMessage(&decoded,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, &msg);
|
|
|
|
/* Failing that, try as an unsigned message */
|
|
|
|
if (!ret && (dwExpectedContentTypeFlags &
|
|
|
|
CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED))
|
|
|
|
ret = CRYPT_QueryUnsignedMessage(&decoded,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, &msg);
|
|
|
|
if (ret)
|
|
|
|
formatType = CERT_QUERY_FORMAT_BASE64_ENCODED;
|
|
|
|
}
|
|
|
|
CryptMemFree(decoded.pbData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2008-12-12 01:36:46 +01:00
|
|
|
}
|
2008-12-12 01:18:47 +01:00
|
|
|
if (ret)
|
2007-09-25 23:45:29 +02:00
|
|
|
{
|
2008-12-12 01:36:46 +01:00
|
|
|
if (pdwFormatType)
|
|
|
|
*pdwFormatType = formatType;
|
2007-09-25 23:45:29 +02:00
|
|
|
if (phCertStore)
|
|
|
|
*phCertStore = CertOpenStore(CERT_STORE_PROV_MSG, encodingType, 0,
|
|
|
|
0, msg);
|
2009-11-02 19:27:25 +01:00
|
|
|
if (phMsg)
|
|
|
|
*phMsg = msg;
|
|
|
|
else
|
|
|
|
CryptMsgClose(msg);
|
2007-09-25 23:45:29 +02:00
|
|
|
}
|
|
|
|
if (blob == &fileBlob)
|
|
|
|
CryptMemFree(blob->pbData);
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CRYPT_QueryEmbeddedMessageObject(DWORD dwObjectType,
|
|
|
|
const void *pvObject, DWORD dwExpectedContentTypeFlags,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
|
|
|
|
HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
|
|
|
|
{
|
|
|
|
HANDLE file;
|
2008-08-05 07:04:10 +02:00
|
|
|
GUID subject;
|
2007-09-25 23:45:29 +02:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2009-01-28 10:25:22 +01:00
|
|
|
TRACE("%s\n", debugstr_w(pvObject));
|
2008-08-05 07:04:10 +02:00
|
|
|
|
2022-04-13 16:00:35 +02:00
|
|
|
if (dwObjectType == CERT_QUERY_OBJECT_BLOB)
|
2007-09-25 23:45:29 +02:00
|
|
|
{
|
2022-04-13 16:00:35 +02:00
|
|
|
WCHAR temp_path[MAX_PATH], temp_name[MAX_PATH];
|
|
|
|
const CERT_BLOB *b = pvObject;
|
|
|
|
|
|
|
|
TRACE("cbData %lu, pbData %p.\n", b->cbData, b->pbData);
|
|
|
|
|
|
|
|
if (!GetTempPathW(MAX_PATH, temp_path) || !GetTempFileNameW(temp_path, L"blb", 0, temp_name))
|
|
|
|
{
|
|
|
|
ERR("Failed getting temp file name.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
file = CreateFileW(temp_name, GENERIC_READ | GENERIC_WRITE, 0,
|
|
|
|
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL);
|
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ERR("Could not create temp file.\n");
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!WriteFile(file, b->pbData, b->cbData, NULL, NULL))
|
|
|
|
{
|
|
|
|
CloseHandle(file);
|
|
|
|
ERR("Could not write temp file.\n");
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dwObjectType == CERT_QUERY_OBJECT_FILE)
|
|
|
|
{
|
|
|
|
file = CreateFileW(pvObject, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Unknown dwObjectType %lu.\n", dwObjectType);
|
2007-09-25 23:45:29 +02:00
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2022-04-13 16:00:35 +02:00
|
|
|
|
2007-09-25 23:45:29 +02:00
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2009-01-28 10:25:22 +01:00
|
|
|
ret = CryptSIPRetrieveSubjectGuid(pvObject, file, &subject);
|
2008-08-05 07:04:10 +02:00
|
|
|
if (ret)
|
2007-09-25 23:45:29 +02:00
|
|
|
{
|
2008-08-05 07:04:10 +02:00
|
|
|
SIP_DISPATCH_INFO sip;
|
2007-09-27 19:00:44 +02:00
|
|
|
|
2008-08-05 07:04:10 +02:00
|
|
|
memset(&sip, 0, sizeof(sip));
|
|
|
|
sip.cbSize = sizeof(sip);
|
|
|
|
ret = CryptSIPLoad(&subject, 0, &sip);
|
|
|
|
if (ret)
|
2007-09-25 23:45:29 +02:00
|
|
|
{
|
2008-08-05 07:04:10 +02:00
|
|
|
SIP_SUBJECTINFO subjectInfo;
|
|
|
|
CERT_BLOB blob;
|
|
|
|
DWORD encodingType;
|
|
|
|
|
|
|
|
memset(&subjectInfo, 0, sizeof(subjectInfo));
|
|
|
|
subjectInfo.cbSize = sizeof(subjectInfo);
|
|
|
|
subjectInfo.pgSubjectType = &subject;
|
|
|
|
subjectInfo.hFile = file;
|
2009-01-28 10:25:22 +01:00
|
|
|
subjectInfo.pwsFileName = pvObject;
|
2008-08-05 07:04:10 +02:00
|
|
|
ret = sip.pfGet(&subjectInfo, &encodingType, 0, &blob.cbData,
|
|
|
|
NULL);
|
2007-09-25 23:45:29 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
2008-08-05 07:04:10 +02:00
|
|
|
blob.pbData = CryptMemAlloc(blob.cbData);
|
|
|
|
if (blob.pbData)
|
|
|
|
{
|
|
|
|
ret = sip.pfGet(&subjectInfo, &encodingType, 0,
|
|
|
|
&blob.cbData, blob.pbData);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
ret = CRYPT_QueryMessageObject(
|
|
|
|
CERT_QUERY_OBJECT_BLOB, &blob,
|
|
|
|
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED,
|
2008-12-12 01:36:46 +01:00
|
|
|
CERT_QUERY_FORMAT_FLAG_BINARY,
|
|
|
|
pdwMsgAndCertEncodingType, NULL, NULL,
|
|
|
|
phCertStore, phMsg);
|
2008-08-05 07:04:10 +02:00
|
|
|
if (ret && pdwContentType)
|
2011-05-03 18:51:09 +02:00
|
|
|
*pdwContentType = CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED;
|
2008-08-05 07:04:10 +02:00
|
|
|
}
|
|
|
|
CryptMemFree(blob.pbData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
2007-09-25 23:45:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-01 15:30:31 +01:00
|
|
|
static BOOL CRYPT_QueryPFXObject(DWORD dwObjectType, const void *pvObject,
|
|
|
|
DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags,
|
|
|
|
DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType, DWORD *pdwFormatType,
|
|
|
|
HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
|
|
|
|
{
|
|
|
|
CRYPT_DATA_BLOB blob = {0}, *ptr;
|
|
|
|
BOOL ret;
|
|
|
|
|
2022-02-09 09:25:50 +01:00
|
|
|
TRACE("(%ld, %p, %08lx, %08lx, %p, %p, %p, %p, %p)\n", dwObjectType, pvObject,
|
2019-02-01 15:30:31 +01:00
|
|
|
dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType, phCertStore,
|
|
|
|
phMsg);
|
|
|
|
|
|
|
|
switch (dwObjectType)
|
|
|
|
{
|
|
|
|
case CERT_QUERY_OBJECT_FILE:
|
|
|
|
if (!CRYPT_ReadBlobFromFile(pvObject, &blob)) return FALSE;
|
|
|
|
ptr = &blob;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CERT_QUERY_OBJECT_BLOB:
|
|
|
|
ptr = (CRYPT_DATA_BLOB *)pvObject;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = PFXIsPFXBlob(ptr);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (pdwMsgAndCertEncodingType) *pdwMsgAndCertEncodingType = X509_ASN_ENCODING;
|
|
|
|
if (pdwContentType) *pdwContentType = CERT_QUERY_CONTENT_PFX;
|
|
|
|
if (pdwFormatType) *pdwFormatType = CERT_QUERY_FORMAT_BINARY;
|
|
|
|
if (phCertStore) *phCertStore = NULL;
|
|
|
|
if (phMsg) *phMsg = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CryptMemFree(blob.pbData);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:45:29 +02:00
|
|
|
BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject,
|
|
|
|
DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags,
|
|
|
|
DWORD dwFlags, DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
|
|
|
|
DWORD *pdwFormatType, HCERTSTORE *phCertStore, HCRYPTMSG *phMsg,
|
|
|
|
const void **ppvContext)
|
|
|
|
{
|
|
|
|
static const DWORD unimplementedTypes =
|
2019-02-01 15:30:31 +01:00
|
|
|
CERT_QUERY_CONTENT_FLAG_PKCS10 | CERT_QUERY_CONTENT_FLAG_CERT_PAIR;
|
2007-09-25 23:45:29 +02:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
2022-02-09 09:25:50 +01:00
|
|
|
TRACE("(%08lx, %p, %08lx, %08lx, %08lx, %p, %p, %p, %p, %p, %p)\n",
|
2007-09-25 23:45:29 +02:00
|
|
|
dwObjectType, pvObject, dwExpectedContentTypeFlags,
|
|
|
|
dwExpectedFormatTypeFlags, dwFlags, pdwMsgAndCertEncodingType,
|
|
|
|
pdwContentType, pdwFormatType, phCertStore, phMsg, ppvContext);
|
|
|
|
|
2008-12-12 00:21:47 +01:00
|
|
|
if (dwObjectType != CERT_QUERY_OBJECT_BLOB &&
|
|
|
|
dwObjectType != CERT_QUERY_OBJECT_FILE)
|
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
WARN("unsupported type %ld\n", dwObjectType);
|
2008-12-12 00:21:47 +01:00
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!pvObject)
|
|
|
|
{
|
|
|
|
WARN("missing required argument\n");
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-09-25 23:45:29 +02:00
|
|
|
if (dwExpectedContentTypeFlags & unimplementedTypes)
|
2022-02-09 09:25:50 +01:00
|
|
|
WARN("unimplemented for types %08lx\n",
|
2007-09-25 23:45:29 +02:00
|
|
|
dwExpectedContentTypeFlags & unimplementedTypes);
|
2008-12-12 00:42:06 +01:00
|
|
|
|
2007-09-25 23:45:29 +02:00
|
|
|
if (pdwFormatType)
|
|
|
|
*pdwFormatType = CERT_QUERY_FORMAT_BINARY;
|
|
|
|
if (phCertStore)
|
|
|
|
*phCertStore = NULL;
|
|
|
|
if (phMsg)
|
|
|
|
*phMsg = NULL;
|
|
|
|
if (ppvContext)
|
|
|
|
*ppvContext = NULL;
|
|
|
|
|
|
|
|
ret = FALSE;
|
|
|
|
if ((dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_CERT) ||
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_CRL) ||
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_CTL))
|
|
|
|
{
|
|
|
|
ret = CRYPT_QueryContextObject(dwObjectType, pvObject,
|
2008-12-12 00:42:06 +01:00
|
|
|
dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType, phCertStore,
|
|
|
|
ppvContext);
|
2007-09-25 23:45:29 +02:00
|
|
|
}
|
|
|
|
if (!ret &&
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE))
|
|
|
|
{
|
|
|
|
ret = CRYPT_QuerySerializedStoreObject(dwObjectType, pvObject,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, phCertStore, phMsg);
|
|
|
|
}
|
|
|
|
if (!ret &&
|
|
|
|
((dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT) ||
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL) ||
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL)))
|
|
|
|
{
|
|
|
|
ret = CRYPT_QuerySerializedContextObject(dwObjectType, pvObject,
|
|
|
|
dwExpectedContentTypeFlags, pdwMsgAndCertEncodingType, pdwContentType,
|
|
|
|
phCertStore, ppvContext);
|
|
|
|
}
|
|
|
|
if (!ret &&
|
|
|
|
((dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED) ||
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED)))
|
|
|
|
{
|
|
|
|
ret = CRYPT_QueryMessageObject(dwObjectType, pvObject,
|
2008-12-12 01:36:46 +01:00
|
|
|
dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType,
|
2007-09-25 23:45:29 +02:00
|
|
|
phCertStore, phMsg);
|
|
|
|
}
|
|
|
|
if (!ret &&
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED))
|
|
|
|
{
|
|
|
|
ret = CRYPT_QueryEmbeddedMessageObject(dwObjectType, pvObject,
|
|
|
|
dwExpectedContentTypeFlags, pdwMsgAndCertEncodingType, pdwContentType,
|
|
|
|
phCertStore, phMsg);
|
|
|
|
}
|
2019-02-01 15:30:31 +01:00
|
|
|
if (!ret &&
|
|
|
|
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_PFX))
|
|
|
|
{
|
|
|
|
ret = CRYPT_QueryPFXObject(dwObjectType, pvObject,
|
|
|
|
dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags,
|
|
|
|
pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType,
|
|
|
|
phCertStore, phMsg);
|
|
|
|
}
|
2008-12-12 00:23:31 +01:00
|
|
|
if (!ret)
|
|
|
|
SetLastError(CRYPT_E_NO_MATCH);
|
2007-09-26 18:57:38 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2007-09-25 23:45:29 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2008-10-31 17:32:31 +01:00
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FormatHexString(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD bytesNeeded;
|
|
|
|
|
|
|
|
if (cbEncoded)
|
|
|
|
bytesNeeded = (cbEncoded * 3) * sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
bytesNeeded = sizeof(WCHAR);
|
|
|
|
if (!pbFormat)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
LPWSTR ptr = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
if (cbEncoded)
|
|
|
|
{
|
|
|
|
for (i = 0; i < cbEncoded; i++)
|
|
|
|
{
|
|
|
|
if (i < cbEncoded - 1)
|
2020-11-09 11:41:52 +01:00
|
|
|
ptr += swprintf(ptr, 4, L"%02x ", pbEncoded[i]);
|
2008-10-31 17:32:31 +01:00
|
|
|
else
|
2020-11-09 11:41:52 +01:00
|
|
|
ptr += swprintf(ptr, 3, L"%02x", pbEncoded[i]);
|
2008-10-31 17:32:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ptr = 0;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-06 22:48:14 +01:00
|
|
|
#define MAX_STRING_RESOURCE_LEN 128
|
|
|
|
|
2020-11-09 11:41:52 +01:00
|
|
|
static const WCHAR commaSpace[] = L", ";
|
2008-11-06 22:48:54 +01:00
|
|
|
|
2008-11-19 20:42:34 +01:00
|
|
|
struct BitToString
|
|
|
|
{
|
|
|
|
BYTE bit;
|
|
|
|
int id;
|
|
|
|
WCHAR str[MAX_STRING_RESOURCE_LEN];
|
|
|
|
};
|
|
|
|
|
2008-11-20 18:19:15 +01:00
|
|
|
static BOOL CRYPT_FormatBits(BYTE bits, const struct BitToString *map,
|
|
|
|
DWORD mapEntries, void *pbFormat, DWORD *pcbFormat, BOOL *first)
|
2008-11-19 20:42:34 +01:00
|
|
|
{
|
2008-11-20 18:19:15 +01:00
|
|
|
DWORD bytesNeeded = sizeof(WCHAR);
|
2013-01-01 16:48:26 +01:00
|
|
|
unsigned int i;
|
2008-11-19 20:42:34 +01:00
|
|
|
BOOL ret = TRUE, localFirst = *first;
|
|
|
|
|
|
|
|
for (i = 0; i < mapEntries; i++)
|
|
|
|
if (bits & map[i].bit)
|
|
|
|
{
|
|
|
|
if (!localFirst)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(commaSpace) * sizeof(WCHAR);
|
2008-11-19 20:42:34 +01:00
|
|
|
localFirst = FALSE;
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(map[i].str) * sizeof(WCHAR);
|
2008-11-19 20:42:34 +01:00
|
|
|
}
|
|
|
|
if (!pbFormat)
|
|
|
|
{
|
|
|
|
*first = localFirst;
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
}
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*first = localFirst;
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
localFirst = *first;
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
for (i = 0; i < mapEntries; i++)
|
|
|
|
if (bits & map[i].bit)
|
|
|
|
{
|
|
|
|
if (!localFirst)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, commaSpace);
|
|
|
|
str += lstrlenW(commaSpace);
|
2008-11-19 20:42:34 +01:00
|
|
|
}
|
|
|
|
localFirst = FALSE;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, map[i].str);
|
|
|
|
str += lstrlenW(map[i].str);
|
2008-11-19 20:42:34 +01:00
|
|
|
}
|
|
|
|
*first = localFirst;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct BitToString keyUsageByte0Map[] = {
|
|
|
|
{ CERT_DIGITAL_SIGNATURE_KEY_USAGE, IDS_DIGITAL_SIGNATURE, { 0 } },
|
|
|
|
{ CERT_NON_REPUDIATION_KEY_USAGE, IDS_NON_REPUDIATION, { 0 } },
|
|
|
|
{ CERT_KEY_ENCIPHERMENT_KEY_USAGE, IDS_KEY_ENCIPHERMENT, { 0 } },
|
|
|
|
{ CERT_DATA_ENCIPHERMENT_KEY_USAGE, IDS_DATA_ENCIPHERMENT, { 0 } },
|
|
|
|
{ CERT_KEY_AGREEMENT_KEY_USAGE, IDS_KEY_AGREEMENT, { 0 } },
|
|
|
|
{ CERT_KEY_CERT_SIGN_KEY_USAGE, IDS_CERT_SIGN, { 0 } },
|
|
|
|
{ CERT_OFFLINE_CRL_SIGN_KEY_USAGE, IDS_OFFLINE_CRL_SIGN, { 0 } },
|
|
|
|
{ CERT_CRL_SIGN_KEY_USAGE, IDS_CRL_SIGN, { 0 } },
|
|
|
|
{ CERT_ENCIPHER_ONLY_KEY_USAGE, IDS_ENCIPHER_ONLY, { 0 } },
|
|
|
|
};
|
|
|
|
static struct BitToString keyUsageByte1Map[] = {
|
|
|
|
{ CERT_DECIPHER_ONLY_KEY_USAGE, IDS_DECIPHER_ONLY, { 0 } },
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FormatKeyUsage(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
CRYPT_BIT_BLOB *bits;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_KEY_USAGE,
|
|
|
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &bits, &size)))
|
|
|
|
{
|
|
|
|
WCHAR infoNotAvailable[MAX_STRING_RESOURCE_LEN];
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR);
|
|
|
|
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_INFO_NOT_AVAILABLE, infoNotAvailable, ARRAY_SIZE(infoNotAvailable));
|
2008-11-19 20:42:34 +01:00
|
|
|
if (!bits->cbData || bits->cbData > 2)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(infoNotAvailable) * sizeof(WCHAR);
|
2008-11-19 20:42:34 +01:00
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, infoNotAvailable);
|
2008-11-19 20:42:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static BOOL stringsLoaded = FALSE;
|
2013-01-01 16:48:26 +01:00
|
|
|
unsigned int i;
|
2008-11-19 20:42:34 +01:00
|
|
|
DWORD bitStringLen;
|
|
|
|
BOOL first = TRUE;
|
|
|
|
|
|
|
|
if (!stringsLoaded)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(keyUsageByte0Map); i++)
|
|
|
|
LoadStringW(hInstance, keyUsageByte0Map[i].id, keyUsageByte0Map[i].str, MAX_STRING_RESOURCE_LEN);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(keyUsageByte1Map); i++)
|
|
|
|
LoadStringW(hInstance, keyUsageByte1Map[i].id, keyUsageByte1Map[i].str, MAX_STRING_RESOURCE_LEN);
|
2008-11-19 20:42:34 +01:00
|
|
|
stringsLoaded = TRUE;
|
|
|
|
}
|
2018-06-20 09:37:55 +02:00
|
|
|
CRYPT_FormatBits(bits->pbData[0], keyUsageByte0Map, ARRAY_SIZE(keyUsageByte0Map),
|
|
|
|
NULL, &bitStringLen, &first);
|
2008-11-19 20:42:34 +01:00
|
|
|
bytesNeeded += bitStringLen;
|
|
|
|
if (bits->cbData == 2)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
CRYPT_FormatBits(bits->pbData[1], keyUsageByte1Map, ARRAY_SIZE(keyUsageByte1Map),
|
2008-11-19 20:42:34 +01:00
|
|
|
NULL, &bitStringLen, &first);
|
|
|
|
bytesNeeded += bitStringLen;
|
|
|
|
}
|
|
|
|
bytesNeeded += 3 * sizeof(WCHAR); /* " (" + ")" */
|
|
|
|
CRYPT_FormatHexString(0, 0, 0, NULL, NULL, bits->pbData,
|
|
|
|
bits->cbData, NULL, &size);
|
|
|
|
bytesNeeded += size;
|
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
bitStringLen = bytesNeeded;
|
|
|
|
first = TRUE;
|
2018-06-20 09:37:55 +02:00
|
|
|
CRYPT_FormatBits(bits->pbData[0], keyUsageByte0Map, ARRAY_SIZE(keyUsageByte0Map),
|
2008-11-19 20:42:34 +01:00
|
|
|
str, &bitStringLen, &first);
|
|
|
|
str += bitStringLen / sizeof(WCHAR) - 1;
|
|
|
|
if (bits->cbData == 2)
|
|
|
|
{
|
|
|
|
bitStringLen = bytesNeeded;
|
2018-06-20 09:37:55 +02:00
|
|
|
CRYPT_FormatBits(bits->pbData[1], keyUsageByte1Map, ARRAY_SIZE(keyUsageByte1Map),
|
2008-11-19 20:42:34 +01:00
|
|
|
str, &bitStringLen, &first);
|
|
|
|
str += bitStringLen / sizeof(WCHAR) - 1;
|
|
|
|
}
|
|
|
|
*str++ = ' ';
|
|
|
|
*str++ = '(';
|
|
|
|
CRYPT_FormatHexString(0, 0, 0, NULL, NULL, bits->pbData,
|
|
|
|
bits->cbData, str, &size);
|
|
|
|
str += size / sizeof(WCHAR) - 1;
|
|
|
|
*str++ = ')';
|
|
|
|
*str = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LocalFree(bits);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-11-09 11:41:52 +01:00
|
|
|
static const WCHAR crlf[] = L"\r\n";
|
2008-11-20 18:19:15 +01:00
|
|
|
|
2008-11-06 22:48:54 +01:00
|
|
|
static WCHAR subjectTypeHeader[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR subjectTypeCA[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR subjectTypeEndCert[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR pathLengthHeader[MAX_STRING_RESOURCE_LEN];
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FormatBasicConstraints2(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
CERT_BASIC_CONSTRAINTS2_INFO *info;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_BASIC_CONSTRAINTS2,
|
|
|
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size)))
|
|
|
|
{
|
|
|
|
static BOOL stringsLoaded = FALSE;
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR); /* space for the NULL terminator */
|
|
|
|
WCHAR pathLength[MAX_STRING_RESOURCE_LEN];
|
|
|
|
LPCWSTR sep, subjectType;
|
|
|
|
DWORD sepLen;
|
|
|
|
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
sep = crlf;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(crlf) * sizeof(WCHAR);
|
2008-11-06 22:48:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sep = commaSpace;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(commaSpace) * sizeof(WCHAR);
|
2008-11-06 22:48:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!stringsLoaded)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_SUBJECT_TYPE, subjectTypeHeader, ARRAY_SIZE(subjectTypeHeader));
|
|
|
|
LoadStringW(hInstance, IDS_SUBJECT_TYPE_CA, subjectTypeCA, ARRAY_SIZE(subjectTypeCA));
|
|
|
|
LoadStringW(hInstance, IDS_SUBJECT_TYPE_END_CERT, subjectTypeEndCert, ARRAY_SIZE(subjectTypeEndCert));
|
|
|
|
LoadStringW(hInstance, IDS_PATH_LENGTH, pathLengthHeader, ARRAY_SIZE(pathLengthHeader));
|
2008-11-06 22:48:54 +01:00
|
|
|
stringsLoaded = TRUE;
|
|
|
|
}
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(subjectTypeHeader) * sizeof(WCHAR);
|
2008-11-06 22:48:54 +01:00
|
|
|
if (info->fCA)
|
|
|
|
subjectType = subjectTypeCA;
|
|
|
|
else
|
|
|
|
subjectType = subjectTypeEndCert;
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(subjectType) * sizeof(WCHAR);
|
2008-11-06 22:48:54 +01:00
|
|
|
bytesNeeded += sepLen;
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(pathLengthHeader) * sizeof(WCHAR);
|
2008-11-06 22:48:54 +01:00
|
|
|
if (info->fPathLenConstraint)
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(pathLength, ARRAY_SIZE(pathLength), L"%d", info->dwPathLenConstraint);
|
2008-11-06 22:48:54 +01:00
|
|
|
else
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_PATH_LENGTH_NONE, pathLength, ARRAY_SIZE(pathLength));
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(pathLength) * sizeof(WCHAR);
|
2008-11-06 22:48:54 +01:00
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, subjectTypeHeader);
|
|
|
|
str += lstrlenW(subjectTypeHeader);
|
|
|
|
lstrcpyW(str, subjectType);
|
|
|
|
str += lstrlenW(subjectType);
|
|
|
|
lstrcpyW(str, sep);
|
2008-11-06 22:48:54 +01:00
|
|
|
str += sepLen / sizeof(WCHAR);
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, pathLengthHeader);
|
|
|
|
str += lstrlenW(pathLengthHeader);
|
|
|
|
lstrcpyW(str, pathLength);
|
2008-11-06 22:48:54 +01:00
|
|
|
}
|
|
|
|
LocalFree(info);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-16 22:14:05 +02:00
|
|
|
static BOOL CRYPT_FormatHexStringWithPrefix(const CRYPT_DATA_BLOB *blob, int id,
|
2008-11-06 22:48:14 +01:00
|
|
|
LPWSTR str, DWORD *pcbStr)
|
|
|
|
{
|
|
|
|
WCHAR buf[MAX_STRING_RESOURCE_LEN];
|
|
|
|
DWORD bytesNeeded;
|
|
|
|
BOOL ret;
|
|
|
|
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, id, buf, ARRAY_SIZE(buf));
|
2008-11-06 22:48:14 +01:00
|
|
|
CRYPT_FormatHexString(X509_ASN_ENCODING, 0, 0, NULL, NULL,
|
|
|
|
blob->pbData, blob->cbData, NULL, &bytesNeeded);
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(buf) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
if (!str)
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else if (*pcbStr < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, buf);
|
|
|
|
str += lstrlenW(str);
|
|
|
|
bytesNeeded -= lstrlenW(str) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
ret = CRYPT_FormatHexString(X509_ASN_ENCODING, 0, 0, NULL, NULL,
|
|
|
|
blob->pbData, blob->cbData, str, &bytesNeeded);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-16 22:14:05 +02:00
|
|
|
static BOOL CRYPT_FormatKeyId(const CRYPT_DATA_BLOB *keyId, LPWSTR str,
|
2008-11-06 22:48:14 +01:00
|
|
|
DWORD *pcbStr)
|
|
|
|
{
|
|
|
|
return CRYPT_FormatHexStringWithPrefix(keyId, IDS_KEY_ID, str, pcbStr);
|
|
|
|
}
|
|
|
|
|
2009-06-16 22:14:05 +02:00
|
|
|
static BOOL CRYPT_FormatCertSerialNumber(const CRYPT_DATA_BLOB *serialNum, LPWSTR str,
|
2008-11-06 22:48:14 +01:00
|
|
|
DWORD *pcbStr)
|
|
|
|
{
|
|
|
|
return CRYPT_FormatHexStringWithPrefix(serialNum, IDS_CERT_SERIAL_NUMBER,
|
|
|
|
str, pcbStr);
|
|
|
|
}
|
|
|
|
|
2020-11-09 11:41:52 +01:00
|
|
|
static const WCHAR indent[] = L" ";
|
|
|
|
static const WCHAR colonCrlf[] = L":\r\n";
|
2008-11-06 23:01:48 +01:00
|
|
|
|
|
|
|
static BOOL CRYPT_FormatAltNameEntry(DWORD dwFormatStrType, DWORD indentLevel,
|
2010-08-19 23:35:15 +02:00
|
|
|
const CERT_ALT_NAME_ENTRY *entry, LPWSTR str, DWORD *pcbStr)
|
2008-11-06 22:48:14 +01:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
WCHAR buf[MAX_STRING_RESOURCE_LEN];
|
|
|
|
WCHAR mask[MAX_STRING_RESOURCE_LEN];
|
|
|
|
WCHAR ipAddrBuf[32];
|
|
|
|
WCHAR maskBuf[16];
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR);
|
2008-11-14 19:02:10 +01:00
|
|
|
DWORD strType = CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG;
|
2008-11-06 22:48:14 +01:00
|
|
|
|
2008-11-06 23:01:48 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += indentLevel * lstrlenW(indent) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
switch (entry->dwAltNameChoice)
|
|
|
|
{
|
|
|
|
case CERT_ALT_NAME_RFC822_NAME:
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_ALT_NAME_RFC822_NAME, buf, ARRAY_SIZE(buf));
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(entry->u.pwszRfc822Name) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
case CERT_ALT_NAME_DNS_NAME:
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_ALT_NAME_DNS_NAME, buf, ARRAY_SIZE(buf));
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(entry->u.pwszDNSName) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
2008-11-13 05:37:02 +01:00
|
|
|
case CERT_ALT_NAME_DIRECTORY_NAME:
|
|
|
|
{
|
2008-11-14 19:02:10 +01:00
|
|
|
DWORD directoryNameLen;
|
2008-11-13 05:37:02 +01:00
|
|
|
|
2008-11-14 19:02:10 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
strType |= CERT_NAME_STR_CRLF_FLAG;
|
|
|
|
directoryNameLen = cert_name_to_str_with_indent(X509_ASN_ENCODING,
|
|
|
|
indentLevel + 1, &entry->u.DirectoryName, strType, NULL, 0);
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_ALT_NAME_DIRECTORY_NAME, buf, ARRAY_SIZE(buf));
|
2008-11-13 05:37:02 +01:00
|
|
|
bytesNeeded += (directoryNameLen - 1) * sizeof(WCHAR);
|
2008-11-14 19:25:40 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(colonCrlf) * sizeof(WCHAR);
|
2008-11-14 19:25:40 +01:00
|
|
|
else
|
|
|
|
bytesNeeded += sizeof(WCHAR); /* '=' */
|
2008-11-13 05:37:02 +01:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-06 22:48:14 +01:00
|
|
|
case CERT_ALT_NAME_URL:
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_ALT_NAME_URL, buf, ARRAY_SIZE(buf));
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(entry->u.pwszURL) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
case CERT_ALT_NAME_IP_ADDRESS:
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_ALT_NAME_IP_ADDRESS, buf, ARRAY_SIZE(buf));
|
2008-11-06 22:48:14 +01:00
|
|
|
if (entry->u.IPAddress.cbData == 8)
|
|
|
|
{
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_ALT_NAME_MASK, mask, ARRAY_SIZE(mask));
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(mask) * sizeof(WCHAR);
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(ipAddrBuf, ARRAY_SIZE(ipAddrBuf), L"%d.%d.%d.%d",
|
2008-11-06 22:48:14 +01:00
|
|
|
entry->u.IPAddress.pbData[0],
|
|
|
|
entry->u.IPAddress.pbData[1],
|
|
|
|
entry->u.IPAddress.pbData[2],
|
|
|
|
entry->u.IPAddress.pbData[3]);
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(ipAddrBuf) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
/* indent again, for the mask line */
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += indentLevel * lstrlenW(indent) * sizeof(WCHAR);
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(maskBuf, ARRAY_SIZE(maskBuf), L"%d.%d.%d.%d",
|
2008-11-06 22:48:14 +01:00
|
|
|
entry->u.IPAddress.pbData[4],
|
|
|
|
entry->u.IPAddress.pbData[5],
|
|
|
|
entry->u.IPAddress.pbData[6],
|
|
|
|
entry->u.IPAddress.pbData[7]);
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(maskBuf) * sizeof(WCHAR);
|
|
|
|
bytesNeeded += lstrlenW(crlf) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(ipAddrBuf, ARRAY_SIZE(ipAddrBuf), L"%d.%d.%d.%d/%d.%d.%d.%d",
|
2008-11-06 22:48:14 +01:00
|
|
|
entry->u.IPAddress.pbData[0],
|
|
|
|
entry->u.IPAddress.pbData[1],
|
|
|
|
entry->u.IPAddress.pbData[2],
|
|
|
|
entry->u.IPAddress.pbData[3],
|
|
|
|
entry->u.IPAddress.pbData[4],
|
|
|
|
entry->u.IPAddress.pbData[5],
|
|
|
|
entry->u.IPAddress.pbData[6],
|
|
|
|
entry->u.IPAddress.pbData[7]);
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += (lstrlenW(ipAddrBuf) + 1) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("unknown IP address format (%ld bytes)\n",
|
2008-11-06 22:48:14 +01:00
|
|
|
entry->u.IPAddress.cbData);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2022-02-09 09:25:50 +01:00
|
|
|
FIXME("unimplemented for %ld\n", entry->dwAltNameChoice);
|
2008-11-06 22:48:14 +01:00
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(buf) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
if (!str)
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
else if (*pcbStr < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-06 23:01:48 +01:00
|
|
|
DWORD i;
|
|
|
|
|
2008-11-06 22:48:14 +01:00
|
|
|
*pcbStr = bytesNeeded;
|
2008-11-06 23:01:48 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
for (i = 0; i < indentLevel; i++)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, indent);
|
|
|
|
str += lstrlenW(indent);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, buf);
|
|
|
|
str += lstrlenW(str);
|
2008-11-06 22:48:14 +01:00
|
|
|
switch (entry->dwAltNameChoice)
|
|
|
|
{
|
|
|
|
case CERT_ALT_NAME_RFC822_NAME:
|
|
|
|
case CERT_ALT_NAME_DNS_NAME:
|
|
|
|
case CERT_ALT_NAME_URL:
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, entry->u.pwszURL);
|
2008-11-06 22:48:14 +01:00
|
|
|
break;
|
2008-11-13 05:37:02 +01:00
|
|
|
case CERT_ALT_NAME_DIRECTORY_NAME:
|
2008-11-14 19:25:40 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, colonCrlf);
|
|
|
|
str += lstrlenW(colonCrlf);
|
2008-11-14 19:25:40 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*str++ = '=';
|
2008-11-14 19:02:10 +01:00
|
|
|
cert_name_to_str_with_indent(X509_ASN_ENCODING,
|
|
|
|
indentLevel + 1, &entry->u.DirectoryName, strType, str,
|
|
|
|
bytesNeeded / sizeof(WCHAR));
|
2008-11-13 05:37:02 +01:00
|
|
|
break;
|
2008-11-06 22:48:14 +01:00
|
|
|
case CERT_ALT_NAME_IP_ADDRESS:
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, ipAddrBuf);
|
|
|
|
str += lstrlenW(ipAddrBuf);
|
|
|
|
lstrcpyW(str, crlf);
|
|
|
|
str += lstrlenW(crlf);
|
2008-11-06 23:01:48 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
for (i = 0; i < indentLevel; i++)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, indent);
|
|
|
|
str += lstrlenW(indent);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, mask);
|
|
|
|
str += lstrlenW(mask);
|
|
|
|
lstrcpyW(str, maskBuf);
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
else
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, ipAddrBuf);
|
2008-11-06 22:48:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-06 23:18:55 +01:00
|
|
|
static BOOL CRYPT_FormatAltNameInfo(DWORD dwFormatStrType, DWORD indentLevel,
|
2010-08-19 23:35:15 +02:00
|
|
|
const CERT_ALT_NAME_INFO *name, LPWSTR str, DWORD *pcbStr)
|
2008-11-06 22:48:14 +01:00
|
|
|
{
|
|
|
|
DWORD i, size, bytesNeeded = 0;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
LPCWSTR sep;
|
|
|
|
DWORD sepLen;
|
|
|
|
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
sep = crlf;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(crlf) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sep = commaSpace;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(commaSpace) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; ret && i < name->cAltEntry; i++)
|
|
|
|
{
|
2008-11-06 23:18:55 +01:00
|
|
|
ret = CRYPT_FormatAltNameEntry(dwFormatStrType, indentLevel,
|
|
|
|
&name->rgAltEntry[i], NULL, &size);
|
2008-11-06 22:48:14 +01:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
bytesNeeded += size - sizeof(WCHAR);
|
|
|
|
if (i < name->cAltEntry - 1)
|
|
|
|
bytesNeeded += sepLen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
bytesNeeded += sizeof(WCHAR);
|
|
|
|
if (!str)
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
else if (*pcbStr < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
for (i = 0; ret && i < name->cAltEntry; i++)
|
|
|
|
{
|
2008-11-06 23:18:55 +01:00
|
|
|
ret = CRYPT_FormatAltNameEntry(dwFormatStrType, indentLevel,
|
2008-11-06 22:48:14 +01:00
|
|
|
&name->rgAltEntry[i], str, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
str += size / sizeof(WCHAR) - 1;
|
|
|
|
if (i < name->cAltEntry - 1)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, sep);
|
2008-11-06 22:48:14 +01:00
|
|
|
str += sepLen / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-11-09 11:41:52 +01:00
|
|
|
static const WCHAR colonSep[] = L": ";
|
2008-11-14 18:00:23 +01:00
|
|
|
|
2008-11-14 21:31:28 +01:00
|
|
|
static BOOL WINAPI CRYPT_FormatAltName(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CERT_ALT_NAME_INFO *info;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_ALTERNATE_NAME,
|
|
|
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size)))
|
|
|
|
{
|
|
|
|
ret = CRYPT_FormatAltNameInfo(dwFormatStrType, 0, info, pbFormat, pcbFormat);
|
|
|
|
LocalFree(info);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-06 22:48:14 +01:00
|
|
|
static BOOL CRYPT_FormatCertIssuer(DWORD dwFormatStrType,
|
2010-08-19 23:35:15 +02:00
|
|
|
const CERT_ALT_NAME_INFO *issuer, LPWSTR str, DWORD *pcbStr)
|
2008-11-06 22:48:14 +01:00
|
|
|
{
|
|
|
|
WCHAR buf[MAX_STRING_RESOURCE_LEN];
|
2008-11-14 18:00:23 +01:00
|
|
|
DWORD bytesNeeded, sepLen;
|
|
|
|
LPCWSTR sep;
|
2008-11-06 22:48:14 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_CERT_ISSUER, buf, ARRAY_SIZE(buf));
|
2008-11-14 18:00:23 +01:00
|
|
|
ret = CRYPT_FormatAltNameInfo(dwFormatStrType, 1, issuer, NULL,
|
2008-11-06 23:18:55 +01:00
|
|
|
&bytesNeeded);
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(buf) * sizeof(WCHAR);
|
2008-11-14 18:00:23 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
sep = colonCrlf;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(colonCrlf) * sizeof(WCHAR);
|
2008-11-14 18:00:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sep = colonSep;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(colonSep) * sizeof(WCHAR);
|
2008-11-14 18:00:23 +01:00
|
|
|
}
|
|
|
|
bytesNeeded += sepLen;
|
2008-11-06 22:48:14 +01:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (!str)
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
else if (*pcbStr < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, buf);
|
|
|
|
bytesNeeded -= lstrlenW(str) * sizeof(WCHAR);
|
|
|
|
str += lstrlenW(str);
|
|
|
|
lstrcpyW(str, sep);
|
2008-11-14 18:00:23 +01:00
|
|
|
str += sepLen / sizeof(WCHAR);
|
|
|
|
ret = CRYPT_FormatAltNameInfo(dwFormatStrType, 1, issuer, str,
|
2008-11-06 22:48:14 +01:00
|
|
|
&bytesNeeded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FormatAuthorityKeyId2(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
CERT_AUTHORITY_KEY_ID2_INFO *info;
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_AUTHORITY_KEY_ID2,
|
|
|
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size)))
|
|
|
|
{
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR); /* space for the NULL terminator */
|
|
|
|
LPCWSTR sep;
|
|
|
|
DWORD sepLen;
|
|
|
|
BOOL needSeparator = FALSE;
|
|
|
|
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
sep = crlf;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(crlf) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sep = commaSpace;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(commaSpace) * sizeof(WCHAR);
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (info->KeyId.cbData)
|
|
|
|
{
|
|
|
|
needSeparator = TRUE;
|
|
|
|
ret = CRYPT_FormatKeyId(&info->KeyId, NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
/* don't include NULL-terminator more than once */
|
|
|
|
bytesNeeded += size - sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (info->AuthorityCertIssuer.cAltEntry)
|
|
|
|
{
|
|
|
|
if (needSeparator)
|
|
|
|
bytesNeeded += sepLen;
|
|
|
|
needSeparator = TRUE;
|
|
|
|
ret = CRYPT_FormatCertIssuer(dwFormatStrType,
|
|
|
|
&info->AuthorityCertIssuer, NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
/* don't include NULL-terminator more than once */
|
|
|
|
bytesNeeded += size - sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (info->AuthorityCertSerialNumber.cbData)
|
|
|
|
{
|
|
|
|
if (needSeparator)
|
|
|
|
bytesNeeded += sepLen;
|
|
|
|
ret = CRYPT_FormatCertSerialNumber(
|
|
|
|
&info->AuthorityCertSerialNumber, NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
/* don't include NULL-terminator more than once */
|
|
|
|
bytesNeeded += size - sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
needSeparator = FALSE;
|
|
|
|
if (info->KeyId.cbData)
|
|
|
|
{
|
|
|
|
needSeparator = TRUE;
|
2008-11-13 05:22:32 +01:00
|
|
|
/* Overestimate size available, it's already been checked
|
|
|
|
* above.
|
|
|
|
*/
|
|
|
|
size = bytesNeeded;
|
2008-11-06 22:48:14 +01:00
|
|
|
ret = CRYPT_FormatKeyId(&info->KeyId, str, &size);
|
|
|
|
if (ret)
|
2008-11-13 05:36:33 +01:00
|
|
|
str += size / sizeof(WCHAR) - 1;
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
if (info->AuthorityCertIssuer.cAltEntry)
|
|
|
|
{
|
|
|
|
if (needSeparator)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, sep);
|
2008-11-06 22:48:14 +01:00
|
|
|
str += sepLen / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
needSeparator = TRUE;
|
2008-11-13 05:22:32 +01:00
|
|
|
/* Overestimate size available, it's already been checked
|
|
|
|
* above.
|
|
|
|
*/
|
|
|
|
size = bytesNeeded;
|
2008-11-06 22:48:14 +01:00
|
|
|
ret = CRYPT_FormatCertIssuer(dwFormatStrType,
|
|
|
|
&info->AuthorityCertIssuer, str, &size);
|
|
|
|
if (ret)
|
2008-11-13 05:36:33 +01:00
|
|
|
str += size / sizeof(WCHAR) - 1;
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
if (info->AuthorityCertSerialNumber.cbData)
|
|
|
|
{
|
|
|
|
if (needSeparator)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, sep);
|
2008-11-06 22:48:14 +01:00
|
|
|
str += sepLen / sizeof(WCHAR);
|
|
|
|
}
|
2008-11-13 05:22:32 +01:00
|
|
|
/* Overestimate size available, it's already been checked
|
|
|
|
* above.
|
|
|
|
*/
|
|
|
|
size = bytesNeeded;
|
2008-11-06 22:48:14 +01:00
|
|
|
ret = CRYPT_FormatCertSerialNumber(
|
|
|
|
&info->AuthorityCertSerialNumber, str, &size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LocalFree(info);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-06 23:01:48 +01:00
|
|
|
static WCHAR aia[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR accessMethod[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR ocsp[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR caIssuers[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR unknown[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR accessLocation[MAX_STRING_RESOURCE_LEN];
|
|
|
|
|
2008-11-14 18:00:23 +01:00
|
|
|
static BOOL WINAPI CRYPT_FormatAuthorityInfoAccess(DWORD dwCertEncodingType,
|
2008-11-06 23:01:48 +01:00
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
CERT_AUTHORITY_INFO_ACCESS *info;
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType,
|
|
|
|
X509_AUTHORITY_INFO_ACCESS, pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG,
|
|
|
|
NULL, &info, &size)))
|
|
|
|
{
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (!info->cAccDescr)
|
|
|
|
{
|
|
|
|
WCHAR infoNotAvailable[MAX_STRING_RESOURCE_LEN];
|
|
|
|
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_INFO_NOT_AVAILABLE, infoNotAvailable, ARRAY_SIZE(infoNotAvailable));
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(infoNotAvailable) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(pbFormat, infoNotAvailable);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-09 11:41:52 +01:00
|
|
|
static const WCHAR equal[] = L"=";
|
2008-11-06 23:01:48 +01:00
|
|
|
static BOOL stringsLoaded = FALSE;
|
|
|
|
DWORD i;
|
|
|
|
LPCWSTR headingSep, accessMethodSep, locationSep;
|
|
|
|
WCHAR accessDescrNum[11];
|
|
|
|
|
|
|
|
if (!stringsLoaded)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_AIA, aia, ARRAY_SIZE(aia));
|
|
|
|
LoadStringW(hInstance, IDS_ACCESS_METHOD, accessMethod, ARRAY_SIZE(accessMethod));
|
|
|
|
LoadStringW(hInstance, IDS_ACCESS_METHOD_OCSP, ocsp, ARRAY_SIZE(ocsp));
|
|
|
|
LoadStringW(hInstance, IDS_ACCESS_METHOD_CA_ISSUERS, caIssuers, ARRAY_SIZE(caIssuers));
|
|
|
|
LoadStringW(hInstance, IDS_ACCESS_METHOD_UNKNOWN, unknown, ARRAY_SIZE(unknown));
|
|
|
|
LoadStringW(hInstance, IDS_ACCESS_LOCATION, accessLocation, ARRAY_SIZE(accessLocation));
|
2008-11-06 23:01:48 +01:00
|
|
|
stringsLoaded = TRUE;
|
|
|
|
}
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
headingSep = crlf;
|
|
|
|
accessMethodSep = crlf;
|
2008-11-06 23:18:55 +01:00
|
|
|
locationSep = colonCrlf;
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
headingSep = colonSep;
|
|
|
|
accessMethodSep = commaSpace;
|
|
|
|
locationSep = equal;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; ret && i < info->cAccDescr; i++)
|
|
|
|
{
|
|
|
|
/* Heading */
|
|
|
|
bytesNeeded += sizeof(WCHAR); /* left bracket */
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(accessDescrNum, ARRAY_SIZE(accessDescrNum), L"%d", i + 1);
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(accessDescrNum) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
bytesNeeded += sizeof(WCHAR); /* right bracket */
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(aia) * sizeof(WCHAR);
|
|
|
|
bytesNeeded += lstrlenW(headingSep) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
/* Access method */
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(accessMethod) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(indent) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
if (!strcmp(info->rgAccDescr[i].pszAccessMethod,
|
|
|
|
szOID_PKIX_OCSP))
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(ocsp) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
else if (!strcmp(info->rgAccDescr[i].pszAccessMethod,
|
|
|
|
szOID_PKIX_CA_ISSUERS))
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(caIssuers) * sizeof(caIssuers);
|
2008-11-06 23:01:48 +01:00
|
|
|
else
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(unknown) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
bytesNeeded += sizeof(WCHAR); /* space */
|
|
|
|
bytesNeeded += sizeof(WCHAR); /* left paren */
|
|
|
|
bytesNeeded += strlen(info->rgAccDescr[i].pszAccessMethod)
|
|
|
|
* sizeof(WCHAR);
|
|
|
|
bytesNeeded += sizeof(WCHAR); /* right paren */
|
|
|
|
/* Delimiter between access method and location */
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(accessMethodSep) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(indent) * sizeof(WCHAR);
|
|
|
|
bytesNeeded += lstrlenW(accessLocation) * sizeof(WCHAR);
|
|
|
|
bytesNeeded += lstrlenW(locationSep) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
ret = CRYPT_FormatAltNameEntry(dwFormatStrType, 2,
|
|
|
|
&info->rgAccDescr[i].AccessLocation, NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
bytesNeeded += size - sizeof(WCHAR);
|
|
|
|
/* Need extra delimiter between access method entries */
|
|
|
|
if (i < info->cAccDescr - 1)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(accessMethodSep) * sizeof(WCHAR);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
DWORD altNameEntrySize;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
for (i = 0; ret && i < info->cAccDescr; i++)
|
|
|
|
{
|
|
|
|
LPCSTR oidPtr;
|
|
|
|
|
|
|
|
*str++ = '[';
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(accessDescrNum, ARRAY_SIZE(accessDescrNum), L"%d", i + 1);
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, accessDescrNum);
|
|
|
|
str += lstrlenW(accessDescrNum);
|
2008-11-06 23:01:48 +01:00
|
|
|
*str++ = ']';
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, aia);
|
|
|
|
str += lstrlenW(aia);
|
|
|
|
lstrcpyW(str, headingSep);
|
|
|
|
str += lstrlenW(headingSep);
|
2008-11-06 23:01:48 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, indent);
|
|
|
|
str += lstrlenW(indent);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, accessMethod);
|
|
|
|
str += lstrlenW(accessMethod);
|
2008-11-06 23:01:48 +01:00
|
|
|
if (!strcmp(info->rgAccDescr[i].pszAccessMethod,
|
|
|
|
szOID_PKIX_OCSP))
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, ocsp);
|
|
|
|
str += lstrlenW(ocsp);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(info->rgAccDescr[i].pszAccessMethod,
|
|
|
|
szOID_PKIX_CA_ISSUERS))
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, caIssuers);
|
|
|
|
str += lstrlenW(caIssuers);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, unknown);
|
|
|
|
str += lstrlenW(unknown);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
*str++ = ' ';
|
|
|
|
*str++ = '(';
|
|
|
|
for (oidPtr = info->rgAccDescr[i].pszAccessMethod;
|
|
|
|
*oidPtr; oidPtr++, str++)
|
|
|
|
*str = *oidPtr;
|
|
|
|
*str++ = ')';
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, accessMethodSep);
|
|
|
|
str += lstrlenW(accessMethodSep);
|
2008-11-06 23:01:48 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, indent);
|
|
|
|
str += lstrlenW(indent);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, accessLocation);
|
|
|
|
str += lstrlenW(accessLocation);
|
|
|
|
lstrcpyW(str, locationSep);
|
|
|
|
str += lstrlenW(locationSep);
|
2008-11-06 23:01:48 +01:00
|
|
|
/* This overestimates the size available, but that
|
|
|
|
* won't matter since we checked earlier whether enough
|
|
|
|
* space for the entire string was available.
|
|
|
|
*/
|
|
|
|
altNameEntrySize = bytesNeeded;
|
|
|
|
ret = CRYPT_FormatAltNameEntry(dwFormatStrType, 2,
|
|
|
|
&info->rgAccDescr[i].AccessLocation, str,
|
|
|
|
&altNameEntrySize);
|
|
|
|
if (ret)
|
|
|
|
str += altNameEntrySize / sizeof(WCHAR) - 1;
|
|
|
|
if (i < info->cAccDescr - 1)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, accessMethodSep);
|
|
|
|
str += lstrlenW(accessMethodSep);
|
2008-11-06 23:01:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LocalFree(info);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-06 23:18:55 +01:00
|
|
|
static WCHAR keyCompromise[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR caCompromise[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR affiliationChanged[MAX_STRING_RESOURCE_LEN];
|
2008-11-17 15:02:48 +01:00
|
|
|
static WCHAR superseded[MAX_STRING_RESOURCE_LEN];
|
2008-11-06 23:18:55 +01:00
|
|
|
static WCHAR operationCeased[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR certificateHold[MAX_STRING_RESOURCE_LEN];
|
|
|
|
|
|
|
|
struct reason_map_entry
|
|
|
|
{
|
|
|
|
BYTE reasonBit;
|
|
|
|
LPWSTR reason;
|
|
|
|
int id;
|
|
|
|
};
|
|
|
|
static struct reason_map_entry reason_map[] = {
|
|
|
|
{ CRL_REASON_KEY_COMPROMISE_FLAG, keyCompromise, IDS_REASON_KEY_COMPROMISE },
|
|
|
|
{ CRL_REASON_CA_COMPROMISE_FLAG, caCompromise, IDS_REASON_CA_COMPROMISE },
|
|
|
|
{ CRL_REASON_AFFILIATION_CHANGED_FLAG, affiliationChanged,
|
|
|
|
IDS_REASON_AFFILIATION_CHANGED },
|
2008-11-17 15:02:48 +01:00
|
|
|
{ CRL_REASON_SUPERSEDED_FLAG, superseded, IDS_REASON_SUPERSEDED },
|
2008-11-06 23:18:55 +01:00
|
|
|
{ CRL_REASON_CESSATION_OF_OPERATION_FLAG, operationCeased,
|
|
|
|
IDS_REASON_CESSATION_OF_OPERATION },
|
|
|
|
{ CRL_REASON_CERTIFICATE_HOLD_FLAG, certificateHold,
|
|
|
|
IDS_REASON_CERTIFICATE_HOLD },
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL CRYPT_FormatReason(DWORD dwFormatStrType,
|
|
|
|
const CRYPT_BIT_BLOB *reasonFlags, LPWSTR str, DWORD *pcbStr)
|
|
|
|
{
|
2020-11-09 11:41:52 +01:00
|
|
|
static const WCHAR sep[] = L", ";
|
2008-11-06 23:18:55 +01:00
|
|
|
static BOOL stringsLoaded = FALSE;
|
2013-01-01 16:48:26 +01:00
|
|
|
unsigned int i, numReasons = 0;
|
2008-11-06 23:18:55 +01:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR);
|
|
|
|
WCHAR bits[6];
|
|
|
|
|
|
|
|
if (!stringsLoaded)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(reason_map); i++)
|
2008-11-06 23:18:55 +01:00
|
|
|
LoadStringW(hInstance, reason_map[i].id, reason_map[i].reason,
|
|
|
|
MAX_STRING_RESOURCE_LEN);
|
|
|
|
stringsLoaded = TRUE;
|
|
|
|
}
|
|
|
|
/* No need to check reasonFlags->cbData, we already know it's positive.
|
|
|
|
* Ignore any other bytes, as they're for undefined bits.
|
|
|
|
*/
|
2018-06-20 09:37:55 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(reason_map); i++)
|
2008-11-06 23:18:55 +01:00
|
|
|
{
|
|
|
|
if (reasonFlags->pbData[0] & reason_map[i].reasonBit)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(reason_map[i].reason) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
if (numReasons++)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(sep) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(bits, ARRAY_SIZE(bits), L" (%02x)", reasonFlags->pbData[0]);
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(bits);
|
2008-11-06 23:18:55 +01:00
|
|
|
if (!str)
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
else if (*pcbStr < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pcbStr = bytesNeeded;
|
2018-06-20 09:37:55 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(reason_map); i++)
|
2008-11-06 23:18:55 +01:00
|
|
|
{
|
|
|
|
if (reasonFlags->pbData[0] & reason_map[i].reasonBit)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, reason_map[i].reason);
|
|
|
|
str += lstrlenW(reason_map[i].reason);
|
2018-06-20 09:37:55 +02:00
|
|
|
if (i < ARRAY_SIZE(reason_map) - 1 && numReasons)
|
2008-11-06 23:18:55 +01:00
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, sep);
|
|
|
|
str += lstrlenW(sep);
|
2008-11-06 23:18:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, bits);
|
2008-11-06 23:18:55 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR crlDistPoint[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR distPointName[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR fullName[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR rdnName[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR reason[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR issuer[MAX_STRING_RESOURCE_LEN];
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FormatCRLDistPoints(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
CRL_DIST_POINTS_INFO *info;
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_CRL_DIST_POINTS,
|
|
|
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size)))
|
|
|
|
{
|
2020-11-09 11:41:52 +01:00
|
|
|
static const WCHAR colon[] = L":";
|
2008-11-06 23:18:55 +01:00
|
|
|
static BOOL stringsLoaded = FALSE;
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR); /* space for NULL terminator */
|
|
|
|
BOOL haveAnEntry = FALSE;
|
2008-12-03 04:30:03 +01:00
|
|
|
LPCWSTR headingSep, nameSep;
|
2008-11-06 23:18:55 +01:00
|
|
|
WCHAR distPointNum[11];
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if (!stringsLoaded)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_CRL_DIST_POINT, crlDistPoint, ARRAY_SIZE(crlDistPoint));
|
|
|
|
LoadStringW(hInstance, IDS_CRL_DIST_POINT_NAME, distPointName, ARRAY_SIZE(distPointName));
|
|
|
|
LoadStringW(hInstance, IDS_CRL_DIST_POINT_FULL_NAME, fullName, ARRAY_SIZE(fullName));
|
|
|
|
LoadStringW(hInstance, IDS_CRL_DIST_POINT_RDN_NAME, rdnName, ARRAY_SIZE(rdnName));
|
|
|
|
LoadStringW(hInstance, IDS_CRL_DIST_POINT_REASON, reason, ARRAY_SIZE(reason));
|
|
|
|
LoadStringW(hInstance, IDS_CRL_DIST_POINT_ISSUER, issuer, ARRAY_SIZE(issuer));
|
2008-11-06 23:18:55 +01:00
|
|
|
stringsLoaded = TRUE;
|
|
|
|
}
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
headingSep = crlf;
|
|
|
|
nameSep = colonCrlf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
headingSep = colonSep;
|
|
|
|
nameSep = colon;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; ret && i < info->cDistPoint; i++)
|
|
|
|
{
|
|
|
|
CRL_DIST_POINT *distPoint = &info->rgDistPoint[i];
|
|
|
|
|
|
|
|
if (distPoint->DistPointName.dwDistPointNameChoice !=
|
|
|
|
CRL_DIST_POINT_NO_NAME)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(distPointName) * sizeof(WCHAR);
|
|
|
|
bytesNeeded += lstrlenW(nameSep) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
if (distPoint->DistPointName.dwDistPointNameChoice ==
|
|
|
|
CRL_DIST_POINT_FULL_NAME)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(fullName) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
else
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(rdnName) * sizeof(WCHAR);
|
|
|
|
bytesNeeded += lstrlenW(nameSep) * sizeof(WCHAR);
|
2008-11-13 05:41:23 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += 2 * lstrlenW(indent) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
/* The indent level (3) is higher than when used as the issuer,
|
2008-11-13 05:37:15 +01:00
|
|
|
* because the name is subordinate to the name type (full vs.
|
2008-11-06 23:18:55 +01:00
|
|
|
* RDN.)
|
|
|
|
*/
|
|
|
|
ret = CRYPT_FormatAltNameInfo(dwFormatStrType, 3,
|
|
|
|
&distPoint->DistPointName.u.FullName, NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
bytesNeeded += size - sizeof(WCHAR);
|
|
|
|
haveAnEntry = TRUE;
|
|
|
|
}
|
|
|
|
else if (distPoint->ReasonFlags.cbData)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(reason) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
ret = CRYPT_FormatReason(dwFormatStrType,
|
|
|
|
&distPoint->ReasonFlags, NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
bytesNeeded += size - sizeof(WCHAR);
|
|
|
|
haveAnEntry = TRUE;
|
|
|
|
}
|
|
|
|
else if (distPoint->CRLIssuer.cAltEntry)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(issuer) * sizeof(WCHAR);
|
|
|
|
bytesNeeded += lstrlenW(nameSep) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
ret = CRYPT_FormatAltNameInfo(dwFormatStrType, 2,
|
|
|
|
&distPoint->CRLIssuer, NULL, &size);
|
|
|
|
if (ret)
|
|
|
|
bytesNeeded += size - sizeof(WCHAR);
|
|
|
|
haveAnEntry = TRUE;
|
|
|
|
}
|
|
|
|
if (haveAnEntry)
|
|
|
|
{
|
|
|
|
bytesNeeded += sizeof(WCHAR); /* left bracket */
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(distPointNum, ARRAY_SIZE(distPointNum), L"%d", i + 1);
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(distPointNum) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
bytesNeeded += sizeof(WCHAR); /* right bracket */
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(crlDistPoint) * sizeof(WCHAR);
|
|
|
|
bytesNeeded += lstrlenW(headingSep) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(indent) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!haveAnEntry)
|
|
|
|
{
|
|
|
|
WCHAR infoNotAvailable[MAX_STRING_RESOURCE_LEN];
|
|
|
|
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_INFO_NOT_AVAILABLE, infoNotAvailable, ARRAY_SIZE(infoNotAvailable));
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(infoNotAvailable) * sizeof(WCHAR);
|
2008-11-06 23:18:55 +01:00
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(pbFormat, infoNotAvailable);
|
2008-11-06 23:18:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
for (i = 0; ret && i < info->cDistPoint; i++)
|
|
|
|
{
|
|
|
|
CRL_DIST_POINT *distPoint = &info->rgDistPoint[i];
|
|
|
|
|
|
|
|
*str++ = '[';
|
2020-11-09 11:41:52 +01:00
|
|
|
swprintf(distPointNum, ARRAY_SIZE(distPointNum), L"%d", i + 1);
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, distPointNum);
|
|
|
|
str += lstrlenW(distPointNum);
|
2008-11-06 23:18:55 +01:00
|
|
|
*str++ = ']';
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, crlDistPoint);
|
|
|
|
str += lstrlenW(crlDistPoint);
|
|
|
|
lstrcpyW(str, headingSep);
|
|
|
|
str += lstrlenW(headingSep);
|
2008-11-06 23:18:55 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, indent);
|
|
|
|
str += lstrlenW(indent);
|
2008-11-06 23:18:55 +01:00
|
|
|
}
|
|
|
|
if (distPoint->DistPointName.dwDistPointNameChoice !=
|
|
|
|
CRL_DIST_POINT_NO_NAME)
|
|
|
|
{
|
|
|
|
DWORD altNameSize = bytesNeeded;
|
|
|
|
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, distPointName);
|
|
|
|
str += lstrlenW(distPointName);
|
|
|
|
lstrcpyW(str, nameSep);
|
|
|
|
str += lstrlenW(nameSep);
|
2008-11-13 05:41:23 +01:00
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, indent);
|
|
|
|
str += lstrlenW(indent);
|
|
|
|
lstrcpyW(str, indent);
|
|
|
|
str += lstrlenW(indent);
|
2008-11-13 05:41:23 +01:00
|
|
|
}
|
2008-11-06 23:18:55 +01:00
|
|
|
if (distPoint->DistPointName.dwDistPointNameChoice ==
|
|
|
|
CRL_DIST_POINT_FULL_NAME)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, fullName);
|
|
|
|
str += lstrlenW(fullName);
|
2008-11-06 23:18:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, rdnName);
|
|
|
|
str += lstrlenW(rdnName);
|
2008-11-06 23:18:55 +01:00
|
|
|
}
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, nameSep);
|
|
|
|
str += lstrlenW(nameSep);
|
2008-11-06 23:18:55 +01:00
|
|
|
ret = CRYPT_FormatAltNameInfo(dwFormatStrType, 3,
|
|
|
|
&distPoint->DistPointName.u.FullName, str,
|
|
|
|
&altNameSize);
|
|
|
|
if (ret)
|
|
|
|
str += altNameSize / sizeof(WCHAR) - 1;
|
|
|
|
}
|
|
|
|
else if (distPoint->ReasonFlags.cbData)
|
|
|
|
{
|
|
|
|
DWORD reasonSize = bytesNeeded;
|
|
|
|
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, reason);
|
|
|
|
str += lstrlenW(reason);
|
2008-11-06 23:18:55 +01:00
|
|
|
ret = CRYPT_FormatReason(dwFormatStrType,
|
|
|
|
&distPoint->ReasonFlags, str, &reasonSize);
|
|
|
|
if (ret)
|
|
|
|
str += reasonSize / sizeof(WCHAR) - 1;
|
|
|
|
}
|
|
|
|
else if (distPoint->CRLIssuer.cAltEntry)
|
|
|
|
{
|
|
|
|
DWORD crlIssuerSize = bytesNeeded;
|
|
|
|
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, issuer);
|
|
|
|
str += lstrlenW(issuer);
|
|
|
|
lstrcpyW(str, nameSep);
|
|
|
|
str += lstrlenW(nameSep);
|
2008-11-06 23:18:55 +01:00
|
|
|
ret = CRYPT_FormatAltNameInfo(dwFormatStrType, 2,
|
|
|
|
&distPoint->CRLIssuer, str,
|
|
|
|
&crlIssuerSize);
|
|
|
|
if (ret)
|
|
|
|
str += crlIssuerSize / sizeof(WCHAR) - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LocalFree(info);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-06 22:48:34 +01:00
|
|
|
static BOOL WINAPI CRYPT_FormatEnhancedKeyUsage(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
CERT_ENHKEY_USAGE *usage;
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_ENHANCED_KEY_USAGE,
|
|
|
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &usage, &size)))
|
|
|
|
{
|
|
|
|
WCHAR unknown[MAX_STRING_RESOURCE_LEN];
|
|
|
|
DWORD i;
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR); /* space for the NULL terminator */
|
|
|
|
LPCWSTR sep;
|
|
|
|
DWORD sepLen;
|
|
|
|
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
sep = crlf;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(crlf) * sizeof(WCHAR);
|
2008-11-06 22:48:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sep = commaSpace;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(commaSpace) * sizeof(WCHAR);
|
2008-11-06 22:48:34 +01:00
|
|
|
}
|
|
|
|
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_USAGE_UNKNOWN, unknown, ARRAY_SIZE(unknown));
|
2008-11-06 22:48:34 +01:00
|
|
|
for (i = 0; i < usage->cUsageIdentifier; i++)
|
|
|
|
{
|
|
|
|
PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY,
|
|
|
|
usage->rgpszUsageIdentifier[i], CRYPT_ENHKEY_USAGE_OID_GROUP_ID);
|
|
|
|
|
|
|
|
if (info)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(info->pwszName) * sizeof(WCHAR);
|
2008-11-06 22:48:34 +01:00
|
|
|
else
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(unknown) * sizeof(WCHAR);
|
2008-11-06 22:48:34 +01:00
|
|
|
bytesNeeded += sizeof(WCHAR); /* space */
|
|
|
|
bytesNeeded += sizeof(WCHAR); /* left paren */
|
|
|
|
bytesNeeded += strlen(usage->rgpszUsageIdentifier[i]) *
|
|
|
|
sizeof(WCHAR);
|
|
|
|
bytesNeeded += sizeof(WCHAR); /* right paren */
|
|
|
|
if (i < usage->cUsageIdentifier - 1)
|
|
|
|
bytesNeeded += sepLen;
|
|
|
|
}
|
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
for (i = 0; i < usage->cUsageIdentifier; i++)
|
|
|
|
{
|
|
|
|
PCCRYPT_OID_INFO info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY,
|
|
|
|
usage->rgpszUsageIdentifier[i],
|
|
|
|
CRYPT_ENHKEY_USAGE_OID_GROUP_ID);
|
|
|
|
LPCSTR oidPtr;
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, info->pwszName);
|
|
|
|
str += lstrlenW(info->pwszName);
|
2008-11-06 22:48:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, unknown);
|
|
|
|
str += lstrlenW(unknown);
|
2008-11-06 22:48:34 +01:00
|
|
|
}
|
|
|
|
*str++ = ' ';
|
|
|
|
*str++ = '(';
|
|
|
|
for (oidPtr = usage->rgpszUsageIdentifier[i]; *oidPtr; oidPtr++)
|
|
|
|
*str++ = *oidPtr;
|
|
|
|
*str++ = ')';
|
|
|
|
*str = 0;
|
|
|
|
if (i < usage->cUsageIdentifier - 1)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, sep);
|
2008-11-06 22:48:34 +01:00
|
|
|
str += sepLen / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LocalFree(usage);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-19 21:06:08 +01:00
|
|
|
static struct BitToString netscapeCertTypeMap[] = {
|
|
|
|
{ NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE, IDS_NETSCAPE_SSL_CLIENT, { 0 } },
|
|
|
|
{ NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE, IDS_NETSCAPE_SSL_SERVER, { 0 } },
|
|
|
|
{ NETSCAPE_SMIME_CERT_TYPE, IDS_NETSCAPE_SMIME, { 0 } },
|
|
|
|
{ NETSCAPE_SIGN_CERT_TYPE, IDS_NETSCAPE_SIGN, { 0 } },
|
|
|
|
{ NETSCAPE_SSL_CA_CERT_TYPE, IDS_NETSCAPE_SSL_CA, { 0 } },
|
|
|
|
{ NETSCAPE_SMIME_CA_CERT_TYPE, IDS_NETSCAPE_SMIME_CA, { 0 } },
|
|
|
|
{ NETSCAPE_SIGN_CA_CERT_TYPE, IDS_NETSCAPE_SIGN_CA, { 0 } },
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FormatNetscapeCertType(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
CRYPT_BIT_BLOB *bits;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_BITS,
|
|
|
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &bits, &size)))
|
|
|
|
{
|
|
|
|
WCHAR infoNotAvailable[MAX_STRING_RESOURCE_LEN];
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR);
|
|
|
|
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_INFO_NOT_AVAILABLE, infoNotAvailable, ARRAY_SIZE(infoNotAvailable));
|
2008-11-19 21:06:08 +01:00
|
|
|
if (!bits->cbData || bits->cbData > 1)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(infoNotAvailable) * sizeof(WCHAR);
|
2008-11-19 21:06:08 +01:00
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, infoNotAvailable);
|
2008-11-19 21:06:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static BOOL stringsLoaded = FALSE;
|
2013-01-01 16:48:26 +01:00
|
|
|
unsigned int i;
|
2008-11-19 21:06:08 +01:00
|
|
|
DWORD bitStringLen;
|
|
|
|
BOOL first = TRUE;
|
|
|
|
|
|
|
|
if (!stringsLoaded)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(netscapeCertTypeMap); i++)
|
2008-11-19 21:06:08 +01:00
|
|
|
LoadStringW(hInstance, netscapeCertTypeMap[i].id,
|
|
|
|
netscapeCertTypeMap[i].str, MAX_STRING_RESOURCE_LEN);
|
|
|
|
stringsLoaded = TRUE;
|
|
|
|
}
|
2018-06-20 09:37:55 +02:00
|
|
|
CRYPT_FormatBits(bits->pbData[0], netscapeCertTypeMap, ARRAY_SIZE(netscapeCertTypeMap),
|
|
|
|
NULL, &bitStringLen, &first);
|
2008-11-19 21:06:08 +01:00
|
|
|
bytesNeeded += bitStringLen;
|
|
|
|
bytesNeeded += 3 * sizeof(WCHAR); /* " (" + ")" */
|
|
|
|
CRYPT_FormatHexString(0, 0, 0, NULL, NULL, bits->pbData,
|
|
|
|
bits->cbData, NULL, &size);
|
|
|
|
bytesNeeded += size;
|
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
bitStringLen = bytesNeeded;
|
|
|
|
first = TRUE;
|
2018-06-20 09:37:55 +02:00
|
|
|
CRYPT_FormatBits(bits->pbData[0], netscapeCertTypeMap, ARRAY_SIZE(netscapeCertTypeMap),
|
|
|
|
str, &bitStringLen, &first);
|
2008-11-19 21:06:08 +01:00
|
|
|
str += bitStringLen / sizeof(WCHAR) - 1;
|
|
|
|
*str++ = ' ';
|
|
|
|
*str++ = '(';
|
|
|
|
CRYPT_FormatHexString(0, 0, 0, NULL, NULL, bits->pbData,
|
|
|
|
bits->cbData, str, &size);
|
|
|
|
str += size / sizeof(WCHAR) - 1;
|
|
|
|
*str++ = ')';
|
|
|
|
*str = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LocalFree(bits);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-06 23:42:58 +01:00
|
|
|
static WCHAR financialCriteria[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR available[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR notAvailable[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR meetsCriteria[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR yes[MAX_STRING_RESOURCE_LEN];
|
|
|
|
static WCHAR no[MAX_STRING_RESOURCE_LEN];
|
|
|
|
|
|
|
|
static BOOL WINAPI CRYPT_FormatSpcFinancialCriteria(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
SPC_FINANCIAL_CRITERIA criteria;
|
|
|
|
DWORD size = sizeof(criteria);
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType,
|
|
|
|
SPC_FINANCIAL_CRITERIA_STRUCT, pbEncoded, cbEncoded, 0, NULL, &criteria,
|
|
|
|
&size)))
|
|
|
|
{
|
|
|
|
static BOOL stringsLoaded = FALSE;
|
|
|
|
DWORD bytesNeeded = sizeof(WCHAR);
|
|
|
|
LPCWSTR sep;
|
|
|
|
DWORD sepLen;
|
|
|
|
|
|
|
|
if (!stringsLoaded)
|
|
|
|
{
|
2018-06-20 09:37:55 +02:00
|
|
|
LoadStringW(hInstance, IDS_FINANCIAL_CRITERIA, financialCriteria, ARRAY_SIZE(financialCriteria));
|
|
|
|
LoadStringW(hInstance, IDS_FINANCIAL_CRITERIA_AVAILABLE, available, ARRAY_SIZE(available));
|
|
|
|
LoadStringW(hInstance, IDS_FINANCIAL_CRITERIA_NOT_AVAILABLE, notAvailable, ARRAY_SIZE(notAvailable));
|
|
|
|
LoadStringW(hInstance, IDS_FINANCIAL_CRITERIA_MEETS_CRITERIA, meetsCriteria, ARRAY_SIZE(meetsCriteria));
|
|
|
|
LoadStringW(hInstance, IDS_YES, yes, ARRAY_SIZE(yes));
|
|
|
|
LoadStringW(hInstance, IDS_NO, no, ARRAY_SIZE(no));
|
2008-11-06 23:42:58 +01:00
|
|
|
stringsLoaded = TRUE;
|
|
|
|
}
|
|
|
|
if (dwFormatStrType & CRYPT_FORMAT_STR_MULTI_LINE)
|
|
|
|
{
|
|
|
|
sep = crlf;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(crlf) * sizeof(WCHAR);
|
2008-11-06 23:42:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sep = commaSpace;
|
2020-11-09 11:41:21 +01:00
|
|
|
sepLen = lstrlenW(commaSpace) * sizeof(WCHAR);
|
2008-11-06 23:42:58 +01:00
|
|
|
}
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(financialCriteria) * sizeof(WCHAR);
|
2008-11-06 23:42:58 +01:00
|
|
|
if (criteria.fFinancialInfoAvailable)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(available) * sizeof(WCHAR);
|
2008-11-06 23:42:58 +01:00
|
|
|
bytesNeeded += sepLen;
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(meetsCriteria) * sizeof(WCHAR);
|
2008-11-06 23:42:58 +01:00
|
|
|
if (criteria.fMeetsCriteria)
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(yes) * sizeof(WCHAR);
|
2008-11-06 23:42:58 +01:00
|
|
|
else
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(no) * sizeof(WCHAR);
|
2008-11-06 23:42:58 +01:00
|
|
|
}
|
|
|
|
else
|
2020-11-09 11:41:21 +01:00
|
|
|
bytesNeeded += lstrlenW(notAvailable) * sizeof(WCHAR);
|
2008-11-06 23:42:58 +01:00
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
else if (*pcbFormat < bytesNeeded)
|
|
|
|
{
|
|
|
|
*pcbFormat = bytesNeeded;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = bytesNeeded;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, financialCriteria);
|
|
|
|
str += lstrlenW(financialCriteria);
|
2008-11-06 23:42:58 +01:00
|
|
|
if (criteria.fFinancialInfoAvailable)
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, available);
|
|
|
|
str += lstrlenW(available);
|
|
|
|
lstrcpyW(str, sep);
|
2008-11-06 23:42:58 +01:00
|
|
|
str += sepLen / sizeof(WCHAR);
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, meetsCriteria);
|
|
|
|
str += lstrlenW(meetsCriteria);
|
2008-11-06 23:42:58 +01:00
|
|
|
if (criteria.fMeetsCriteria)
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, yes);
|
2008-11-06 23:42:58 +01:00
|
|
|
else
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, no);
|
2008-11-06 23:42:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, notAvailable);
|
2008-11-06 23:42:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-21 16:44:19 +01:00
|
|
|
static BOOL WINAPI CRYPT_FormatUnicodeString(DWORD dwCertEncodingType,
|
|
|
|
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
|
|
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
|
|
|
DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
CERT_NAME_VALUE *value;
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!cbEncoded)
|
|
|
|
{
|
|
|
|
SetLastError(E_INVALIDARG);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = CryptDecodeObjectEx(dwCertEncodingType, X509_UNICODE_ANY_STRING,
|
|
|
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &value, &size)))
|
|
|
|
{
|
|
|
|
if (!pbFormat)
|
|
|
|
*pcbFormat = value->Value.cbData;
|
|
|
|
else if (*pcbFormat < value->Value.cbData)
|
|
|
|
{
|
|
|
|
*pcbFormat = value->Value.cbData;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR str = pbFormat;
|
|
|
|
|
|
|
|
*pcbFormat = value->Value.cbData;
|
2020-11-09 11:41:21 +01:00
|
|
|
lstrcpyW(str, (LPWSTR)value->Value.pbData);
|
2008-11-21 16:44:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-31 17:32:31 +01:00
|
|
|
typedef BOOL (WINAPI *CryptFormatObjectFunc)(DWORD, DWORD, DWORD, void *,
|
|
|
|
LPCSTR, const BYTE *, DWORD, void *, DWORD *);
|
|
|
|
|
2008-11-06 22:48:14 +01:00
|
|
|
static CryptFormatObjectFunc CRYPT_GetBuiltinFormatFunction(DWORD encodingType,
|
|
|
|
DWORD formatStrType, LPCSTR lpszStructType)
|
|
|
|
{
|
|
|
|
CryptFormatObjectFunc format = NULL;
|
|
|
|
|
|
|
|
if ((encodingType & CERT_ENCODING_TYPE_MASK) != X509_ASN_ENCODING)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_FILE_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-29 01:39:26 +01:00
|
|
|
if (IS_INTOID(lpszStructType))
|
2008-11-06 22:48:14 +01:00
|
|
|
{
|
|
|
|
switch (LOWORD(lpszStructType))
|
|
|
|
{
|
2008-11-19 20:42:34 +01:00
|
|
|
case LOWORD(X509_KEY_USAGE):
|
|
|
|
format = CRYPT_FormatKeyUsage;
|
|
|
|
break;
|
2008-11-14 21:31:28 +01:00
|
|
|
case LOWORD(X509_ALTERNATE_NAME):
|
|
|
|
format = CRYPT_FormatAltName;
|
|
|
|
break;
|
2008-11-06 22:48:54 +01:00
|
|
|
case LOWORD(X509_BASIC_CONSTRAINTS2):
|
|
|
|
format = CRYPT_FormatBasicConstraints2;
|
|
|
|
break;
|
2008-11-06 22:48:14 +01:00
|
|
|
case LOWORD(X509_AUTHORITY_KEY_ID2):
|
|
|
|
format = CRYPT_FormatAuthorityKeyId2;
|
|
|
|
break;
|
2008-11-06 23:01:48 +01:00
|
|
|
case LOWORD(X509_AUTHORITY_INFO_ACCESS):
|
|
|
|
format = CRYPT_FormatAuthorityInfoAccess;
|
|
|
|
break;
|
2008-11-06 23:18:55 +01:00
|
|
|
case LOWORD(X509_CRL_DIST_POINTS):
|
|
|
|
format = CRYPT_FormatCRLDistPoints;
|
|
|
|
break;
|
2008-11-06 22:48:34 +01:00
|
|
|
case LOWORD(X509_ENHANCED_KEY_USAGE):
|
|
|
|
format = CRYPT_FormatEnhancedKeyUsage;
|
|
|
|
break;
|
2008-11-06 23:42:58 +01:00
|
|
|
case LOWORD(SPC_FINANCIAL_CRITERIA_STRUCT):
|
|
|
|
format = CRYPT_FormatSpcFinancialCriteria;
|
|
|
|
break;
|
2008-11-06 22:48:14 +01:00
|
|
|
}
|
|
|
|
}
|
2008-11-14 21:31:28 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_SUBJECT_ALT_NAME))
|
|
|
|
format = CRYPT_FormatAltName;
|
|
|
|
else if (!strcmp(lpszStructType, szOID_ISSUER_ALT_NAME))
|
|
|
|
format = CRYPT_FormatAltName;
|
2008-11-19 20:42:34 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_KEY_USAGE))
|
|
|
|
format = CRYPT_FormatKeyUsage;
|
2008-11-14 21:31:28 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_SUBJECT_ALT_NAME2))
|
|
|
|
format = CRYPT_FormatAltName;
|
|
|
|
else if (!strcmp(lpszStructType, szOID_ISSUER_ALT_NAME2))
|
|
|
|
format = CRYPT_FormatAltName;
|
2008-11-06 22:48:54 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_BASIC_CONSTRAINTS2))
|
|
|
|
format = CRYPT_FormatBasicConstraints2;
|
2008-11-06 23:01:48 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_AUTHORITY_INFO_ACCESS))
|
|
|
|
format = CRYPT_FormatAuthorityInfoAccess;
|
2008-11-06 22:48:14 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_AUTHORITY_KEY_IDENTIFIER2))
|
|
|
|
format = CRYPT_FormatAuthorityKeyId2;
|
2008-11-06 23:18:55 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_CRL_DIST_POINTS))
|
|
|
|
format = CRYPT_FormatCRLDistPoints;
|
2008-11-06 22:48:34 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_ENHANCED_KEY_USAGE))
|
|
|
|
format = CRYPT_FormatEnhancedKeyUsage;
|
2008-11-19 21:06:08 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_NETSCAPE_CERT_TYPE))
|
|
|
|
format = CRYPT_FormatNetscapeCertType;
|
2008-11-21 16:44:19 +01:00
|
|
|
else if (!strcmp(lpszStructType, szOID_NETSCAPE_BASE_URL) ||
|
|
|
|
!strcmp(lpszStructType, szOID_NETSCAPE_REVOCATION_URL) ||
|
|
|
|
!strcmp(lpszStructType, szOID_NETSCAPE_CA_REVOCATION_URL) ||
|
|
|
|
!strcmp(lpszStructType, szOID_NETSCAPE_CERT_RENEWAL_URL) ||
|
|
|
|
!strcmp(lpszStructType, szOID_NETSCAPE_CA_POLICY_URL) ||
|
|
|
|
!strcmp(lpszStructType, szOID_NETSCAPE_SSL_SERVER_NAME) ||
|
|
|
|
!strcmp(lpszStructType, szOID_NETSCAPE_COMMENT))
|
|
|
|
format = CRYPT_FormatUnicodeString;
|
2008-11-06 23:42:58 +01:00
|
|
|
else if (!strcmp(lpszStructType, SPC_FINANCIAL_CRITERIA_OBJID))
|
|
|
|
format = CRYPT_FormatSpcFinancialCriteria;
|
2008-11-06 22:48:14 +01:00
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2008-10-31 17:32:31 +01:00
|
|
|
BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
|
|
|
|
DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
|
|
|
|
const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
|
|
|
|
{
|
|
|
|
CryptFormatObjectFunc format = NULL;
|
|
|
|
HCRYPTOIDFUNCADDR hFunc = NULL;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2022-02-09 09:25:50 +01:00
|
|
|
TRACE("(%08lx, %ld, %08lx, %p, %s, %p, %ld, %p, %p)\n", dwCertEncodingType,
|
2008-10-31 17:32:31 +01:00
|
|
|
dwFormatType, dwFormatStrType, pFormatStruct, debugstr_a(lpszStructType),
|
|
|
|
pbEncoded, cbEncoded, pbFormat, pcbFormat);
|
|
|
|
|
2008-11-06 22:48:14 +01:00
|
|
|
if (!(format = CRYPT_GetBuiltinFormatFunction(dwCertEncodingType,
|
|
|
|
dwFormatStrType, lpszStructType)))
|
|
|
|
{
|
|
|
|
static HCRYPTOIDFUNCSET set = NULL;
|
|
|
|
|
|
|
|
if (!set)
|
|
|
|
set = CryptInitOIDFunctionSet(CRYPT_OID_FORMAT_OBJECT_FUNC, 0);
|
|
|
|
CryptGetOIDFunctionAddress(set, dwCertEncodingType, lpszStructType, 0,
|
|
|
|
(void **)&format, &hFunc);
|
|
|
|
}
|
2008-11-20 18:32:57 +01:00
|
|
|
if (!format && (dwCertEncodingType & CERT_ENCODING_TYPE_MASK) ==
|
|
|
|
X509_ASN_ENCODING && !(dwFormatStrType & CRYPT_FORMAT_STR_NO_HEX))
|
|
|
|
format = CRYPT_FormatHexString;
|
2008-10-31 17:32:31 +01:00
|
|
|
if (format)
|
|
|
|
ret = format(dwCertEncodingType, dwFormatType, dwFormatStrType,
|
|
|
|
pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat,
|
|
|
|
pcbFormat);
|
|
|
|
if (hFunc)
|
|
|
|
CryptFreeOIDFunctionAddress(hFunc, 0);
|
|
|
|
return ret;
|
|
|
|
}
|