crypt32: Use CryptSIPRetrieveSubjectGuid to determine how to read a message object from a file, rather than assuming the source file is always a PE executable.

This commit is contained in:
Juan Lang 2008-08-04 22:04:10 -07:00 committed by Alexandre Julliard
parent 0dcdbcd3cc
commit 10f23fa7f5
2 changed files with 45 additions and 18 deletions

View File

@ -6,7 +6,6 @@ VPATH = @srcdir@
MODULE = crypt32.dll MODULE = crypt32.dll
IMPORTLIB = crypt32 IMPORTLIB = crypt32
IMPORTS = user32 advapi32 kernel32 ntdll IMPORTS = user32 advapi32 kernel32 ntdll
DELAYIMPORTS = imagehlp
C_SRCS = \ C_SRCS = \
base64.c \ base64.c \

View File

@ -21,7 +21,7 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "wincrypt.h" #include "wincrypt.h"
#include "imagehlp.h" #include "mssip.h"
#include "crypt32_private.h" #include "crypt32_private.h"
#include "wine/debug.h" #include "wine/debug.h"
@ -400,8 +400,11 @@ static BOOL CRYPT_QueryEmbeddedMessageObject(DWORD dwObjectType,
HCERTSTORE *phCertStore, HCRYPTMSG *phMsg) HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
{ {
HANDLE file; HANDLE file;
GUID subject;
BOOL ret = FALSE; BOOL ret = FALSE;
TRACE("%s\n", debugstr_w((LPCWSTR)pvObject));
if (dwObjectType != CERT_QUERY_OBJECT_FILE) if (dwObjectType != CERT_QUERY_OBJECT_FILE)
{ {
FIXME("don't know what to do for type %d embedded signed messages\n", FIXME("don't know what to do for type %d embedded signed messages\n",
@ -413,28 +416,53 @@ static BOOL CRYPT_QueryEmbeddedMessageObject(DWORD dwObjectType,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (file != INVALID_HANDLE_VALUE) if (file != INVALID_HANDLE_VALUE)
{ {
DWORD len = 0; ret = CryptSIPRetrieveSubjectGuid((LPCWSTR)pvObject, file, &subject);
ret = ImageGetCertificateData(file, 0, NULL, &len);
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
WIN_CERTIFICATE *winCert = HeapAlloc(GetProcessHeap(), 0, len);
if (winCert)
{
ret = ImageGetCertificateData(file, 0, winCert, &len);
if (ret) if (ret)
{ {
CERT_BLOB blob = { winCert->dwLength, SIP_DISPATCH_INFO sip;
winCert->bCertificate };
ret = CRYPT_QueryMessageObject(CERT_QUERY_OBJECT_BLOB, memset(&sip, 0, sizeof(sip));
&blob, CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED, sip.cbSize = sizeof(sip);
pdwMsgAndCertEncodingType, NULL, phCertStore, phMsg); ret = CryptSIPLoad(&subject, 0, &sip);
if (ret)
{
SIP_SUBJECTINFO subjectInfo;
CERT_BLOB blob;
DWORD encodingType;
memset(&subjectInfo, 0, sizeof(subjectInfo));
subjectInfo.cbSize = sizeof(subjectInfo);
subjectInfo.pgSubjectType = &subject;
subjectInfo.hFile = file;
subjectInfo.pwsFileName = (LPCWSTR)pvObject;
ret = sip.pfGet(&subjectInfo, &encodingType, 0, &blob.cbData,
NULL);
if (ret)
{
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,
pdwMsgAndCertEncodingType, NULL, phCertStore,
phMsg);
if (ret && pdwContentType) if (ret && pdwContentType)
*pdwContentType = CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED; *pdwContentType =
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED;
}
CryptMemFree(blob.pbData);
}
else
{
SetLastError(ERROR_OUTOFMEMORY);
ret = FALSE;
}
} }
HeapFree(GetProcessHeap(), 0, winCert);
} }
} }
CloseHandle(file); CloseHandle(file);