Commit 962aed51 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

crypt32: Add support for PFX objects in CryptQueryObject.

parent 4782b283
...@@ -696,6 +696,48 @@ static BOOL CRYPT_QueryEmbeddedMessageObject(DWORD dwObjectType, ...@@ -696,6 +696,48 @@ static BOOL CRYPT_QueryEmbeddedMessageObject(DWORD dwObjectType,
return ret; return ret;
} }
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;
TRACE("(%d, %p, %08x, %08x, %p, %p, %p, %p, %p)\n", dwObjectType, pvObject,
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;
}
BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject, BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject,
DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags, DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags,
DWORD dwFlags, DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType, DWORD dwFlags, DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
...@@ -703,8 +745,7 @@ BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject, ...@@ -703,8 +745,7 @@ BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject,
const void **ppvContext) const void **ppvContext)
{ {
static const DWORD unimplementedTypes = static const DWORD unimplementedTypes =
CERT_QUERY_CONTENT_FLAG_PKCS10 | CERT_QUERY_CONTENT_FLAG_PFX | CERT_QUERY_CONTENT_FLAG_PKCS10 | CERT_QUERY_CONTENT_FLAG_CERT_PAIR;
CERT_QUERY_CONTENT_FLAG_CERT_PAIR;
BOOL ret = TRUE; BOOL ret = TRUE;
TRACE("(%08x, %p, %08x, %08x, %08x, %p, %p, %p, %p, %p, %p)\n", TRACE("(%08x, %p, %08x, %08x, %08x, %p, %p, %p, %p, %p, %p)\n",
...@@ -779,6 +820,14 @@ BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject, ...@@ -779,6 +820,14 @@ BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject,
dwExpectedContentTypeFlags, pdwMsgAndCertEncodingType, pdwContentType, dwExpectedContentTypeFlags, pdwMsgAndCertEncodingType, pdwContentType,
phCertStore, phMsg); phCertStore, phMsg);
} }
if (!ret &&
(dwExpectedContentTypeFlags & CERT_QUERY_CONTENT_FLAG_PFX))
{
ret = CRYPT_QueryPFXObject(dwObjectType, pvObject,
dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags,
pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType,
phCertStore, phMsg);
}
if (!ret) if (!ret)
SetLastError(CRYPT_E_NO_MATCH); SetLastError(CRYPT_E_NO_MATCH);
TRACE("returning %d\n", ret); TRACE("returning %d\n", ret);
......
...@@ -3326,6 +3326,39 @@ static void test_PFXImportCertStore(void) ...@@ -3326,6 +3326,39 @@ static void test_PFXImportCertStore(void)
CertCloseStore( store, 0 ); CertCloseStore( store, 0 );
} }
static void test_CryptQueryObject(void)
{
CRYPT_DATA_BLOB pfx;
DWORD encoding_type, content_type, format_type;
HCERTSTORE store;
HCRYPTMSG msg;
const void *ctx;
BOOL ret;
SetLastError( 0xdeadbeef );
ret = CryptQueryObject( CERT_QUERY_OBJECT_BLOB, NULL, CERT_QUERY_CONTENT_FLAG_ALL,
CERT_QUERY_FORMAT_FLAG_BINARY, 0, NULL, NULL, NULL, NULL, NULL, NULL );
ok( !ret, "success\n" );
ok( GetLastError() == E_INVALIDARG, "got %u\n", GetLastError() );
pfx.pbData = (BYTE *)pfxdata;
pfx.cbData = sizeof(pfxdata);
encoding_type = content_type = format_type = 0xdeadbeef;
store = (HCERTSTORE *)0xdeadbeef;
msg = (HCRYPTMSG *)0xdeadbeef;
ctx = (void *)0xdeadbeef;
ret = CryptQueryObject( CERT_QUERY_OBJECT_BLOB, &pfx, CERT_QUERY_CONTENT_FLAG_ALL,
CERT_QUERY_FORMAT_FLAG_BINARY, 0, &encoding_type, &content_type, &format_type,
&store, &msg, &ctx );
ok( ret, "got %u\n", GetLastError() );
ok( encoding_type == X509_ASN_ENCODING, "got %08x\n", encoding_type );
ok( content_type == CERT_QUERY_CONTENT_PFX, "got %08x\n", content_type );
ok( format_type == CERT_QUERY_FORMAT_BINARY, "got %08x\n", format_type );
ok( store == NULL, "got %p\n", store );
ok( msg == NULL, "got %p\n", msg );
ok( ctx == NULL, "got %p\n", ctx );
}
START_TEST(store) START_TEST(store)
{ {
/* various combinations of CertOpenStore */ /* various combinations of CertOpenStore */
...@@ -3357,4 +3390,5 @@ START_TEST(store) ...@@ -3357,4 +3390,5 @@ START_TEST(store)
test_I_UpdateStore(); test_I_UpdateStore();
test_PFXImportCertStore(); test_PFXImportCertStore();
test_CryptQueryObject();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment