ReactOS 0.4.16-dev-1946-g52006dd
object.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winerror.h>
#include <wincrypt.h>
#include "wine/test.h"
Include dependency graph for object.c:

Go to the source code of this file.

Functions

static void test_query_object (void)
 
 START_TEST (object)
 

Variables

static BYTE bigCert []
 
static char bigCertBase64 []
 
static WCHAR bigCertBase64W []
 
static BYTE signedWithCertWithValidPubKeyContent []
 
static char signedWithCertWithValidPubKeyContentBase64 []
 
static WCHAR signedWithCertWithValidPubKeyContentBase64W []
 
static const BYTE signed_pe_blob []
 

Function Documentation

◆ START_TEST()

START_TEST ( object  )

Definition at line 333 of file object.c.

334{
336}
static void test_query_object(void)
Definition: object.c:216

◆ test_query_object()

static void test_query_object ( void  )
static

Definition at line 216 of file object.c.

217{
218 WCHAR tmp_path[MAX_PATH];
219 BOOL ret;
222
223 /* Test the usual invalid arguments */
224 SetLastError(0xdeadbeef);
225 ret = CryptQueryObject(0, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
226 NULL);
228 "expected E_INVALIDARG, got %08lx\n", GetLastError());
229 SetLastError(0xdeadbeef);
231 NULL, NULL, NULL, NULL);
233 "expected E_INVALIDARG, got %08lx\n", GetLastError());
234 /* Test with a simple cert */
235 blob.pbData = bigCert;
236 blob.cbData = sizeof(bigCert);
237 SetLastError(0xdeadbeef);
240 NULL, NULL, NULL, NULL);
241 ok(ret, "CryptQueryObject failed: %08lx\n", GetLastError());
242 /* The same cert, base64-encoded */
243 blob.pbData = (BYTE *)bigCertBase64;
244 blob.cbData = sizeof(bigCertBase64);
245 SetLastError(0xdeadbeef);
248 NULL, NULL, NULL, NULL);
249 ok(ret, "CryptQueryObject failed: %08lx\n", GetLastError());
250 /* The same base64-encoded cert, restricting the format types */
251 SetLastError(0xdeadbeef);
254 NULL, NULL, NULL, NULL);
256 "expected CRYPT_E_NO_MATCH, got %08lx\n", GetLastError());
257 SetLastError(0xdeadbeef);
260 NULL, NULL, NULL, NULL, NULL, NULL);
261 ok(ret, "CryptQueryObject failed: %08lx\n", GetLastError());
262 /* The same cert, base64-encoded but as a wide character string */
263 blob.pbData = (BYTE *)bigCertBase64W;
264 blob.cbData = sizeof(bigCertBase64W);
265 SetLastError(0xdeadbeef);
268 NULL, NULL, NULL, NULL);
270 "expected CRYPT_E_NO_MATCH, got %08lx\n", GetLastError());
271 /* For brevity, not tested here, but tested on Windows: same failure
272 * (CRYPT_E_NO_MATCH) when the wide character base64-encoded cert
273 * is written to a file and queried.
274 */
275 /* Test with a valid signed message */
278 SetLastError(0xdeadbeef);
281 NULL, NULL, NULL, NULL);
282 ok(ret, "CryptQueryObject failed: %08lx\n", GetLastError());
285 SetLastError(0xdeadbeef);
288 NULL, NULL, NULL, NULL);
289 ok(ret, "CryptQueryObject failed: %08lx\n", GetLastError());
290 /* A valid signed message, encoded as a wide character base64 string, can
291 * be queried successfully.
292 */
295 SetLastError(0xdeadbeef);
298 NULL, NULL, NULL, NULL);
299 ok(ret, "CryptQueryObject failed: %08lx\n", GetLastError());
300 SetLastError(0xdeadbeef);
303 NULL, NULL, NULL, NULL);
305 "expected CRYPT_E_NO_MATCH, got %08lx\n", GetLastError());
306 SetLastError(0xdeadbeef);
309 NULL, NULL, NULL, NULL, NULL, NULL);
310 ok(ret, "CryptQueryObject failed: %08lx\n", GetLastError());
311
312 GetEnvironmentVariableW( L"TMP", tmp_path, MAX_PATH );
313 SetEnvironmentVariableW(L"TMP", L"C:\\nonexistent");
314 blob.pbData = (BYTE *)signed_pe_blob;
315 blob.cbData = sizeof(signed_pe_blob);
318 NULL, NULL, NULL, NULL);
319 ok(!ret, "CryptQueryObject succeeded\n");
320 ok(GetLastError() == CRYPT_E_NO_MATCH, "Unexpected error %lu.\n", GetLastError());
321 SetEnvironmentVariableW(L"TMP", tmp_path);
322
323 blob.pbData = (BYTE *)signed_pe_blob;
324 blob.cbData = sizeof(signed_pe_blob);
327 NULL, NULL, NULL, NULL);
328 ok(ret, "CryptQueryObject failed: %08lx\n", GetLastError());
330 "Got unexpected content_type %#lx.\n", content_type);
331}
#define ok(value,...)
Definition: atltest.h:57
#define E_INVALIDARG
Definition: ddrawi.h:101
#define NULL
Definition: types.h:112
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)
Definition: object.c:699
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define SetLastError(x)
Definition: compat.h:752
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpValue)
Definition: environ.c:259
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
static const BYTE signed_pe_blob[]
Definition: object.c:110
static char bigCertBase64[]
Definition: object.c:41
static WCHAR signedWithCertWithValidPubKeyContentBase64W[]
Definition: object.c:87
static BYTE bigCert[]
Definition: object.c:29
static BYTE signedWithCertWithValidPubKeyContent[]
Definition: object.c:49
static char signedWithCertWithValidPubKeyContentBase64[]
Definition: object.c:77
static WCHAR bigCertBase64W[]
Definition: object.c:45
static BSTR content_type
Definition: image.c:134
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CERT_QUERY_CONTENT_FLAG_ALL
Definition: wincrypt.h:3724
#define CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
Definition: wincrypt.h:3698
#define CERT_QUERY_OBJECT_BLOB
Definition: wincrypt.h:3687
#define CERT_QUERY_FORMAT_FLAG_BINARY
Definition: wincrypt.h:3743
#define CERT_QUERY_FORMAT_FLAG_ALL
Definition: wincrypt.h:3749
#define CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED
Definition: wincrypt.h:3744
#define CRYPT_E_NO_MATCH
Definition: winerror.h:4426
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

Variable Documentation

◆ bigCert

BYTE bigCert[]
static
Initial value:
= {
0x30,0x7a,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,
0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,
0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,
0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,
0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,
0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,
0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,
0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x30,0x07,0x30,0x02,0x06,
0x00,0x03,0x01,0x00,0xa3,0x16,0x30,0x14,0x30,0x12,0x06,0x03,
0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,
0xff,0x02,0x01,0x01 }

Definition at line 29 of file object.c.

Referenced by test_query_object().

◆ bigCertBase64

char bigCertBase64[]
static
Initial value:
=
"MHoCAQEwAgYAMBUxEzARBgNVBAMTCkp1YW4gTGFuZwAwIhgPMTYwMTAxMDEwMDAw\n"
"MDBaGA8xNjAxMDEwMTAwMDAwMFowFTETMBEGA1UEAxMKSnVhbiBMYW5nADAHMAIG\n"
"AAMBAKMWMBQwEgYDVR0TAQH/BAgwBgEB/wIBAQ==\n"

Definition at line 41 of file object.c.

Referenced by test_query_object().

◆ bigCertBase64W

WCHAR bigCertBase64W[]
static
Initial value:
=
L"MHoCAQEwAgYAMBUxEzARBgNVBAMTCkp1YW4gTGFuZwAwIhgPMTYwMTAxMDEw,DAw\n"
"MDBaGA8xNjAxMDEwMTAwMDAwMFowFTETMBEGA1UEAxMKSnVhbiBMYW5nADAHMAIG\n"
"AAMBAKMWMBQwEgYDVR0TAQH/BAgwBgEB/wIBAQ==\n"

Definition at line 45 of file object.c.

Referenced by test_query_object().

◆ signed_pe_blob

const BYTE signed_pe_blob[]
static

Definition at line 110 of file object.c.

Referenced by test_query_object().

◆ signedWithCertWithValidPubKeyContent

BYTE signedWithCertWithValidPubKeyContent[]
static
Initial value:
= {
0x30,0x82,0x01,0x89,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,
0xa0,0x82,0x01,0x7a,0x30,0x82,0x01,0x76,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,
0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x13,0x06,
0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x06,0x04,0x04,0x01,
0x02,0x03,0x04,0xa0,0x81,0xd2,0x30,0x81,0xcf,0x02,0x01,0x01,0x30,0x02,0x06,
0x00,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,
0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,
0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,
0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,
0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,
0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x30,0x5c,0x30,0x0d,0x06,0x09,0x2a,
0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x4b,0x00,0x30,0x48,
0x02,0x41,0x00,0xe2,0x54,0x3a,0xa7,0x83,0xb1,0x27,0x14,0x3e,0x59,0xbb,0xb4,
0x53,0xe6,0x1f,0xe7,0x5d,0xf1,0x21,0x68,0xad,0x85,0x53,0xdb,0x6b,0x1e,0xeb,
0x65,0x97,0x03,0x86,0x60,0xde,0xf3,0x6c,0x38,0x75,0xe0,0x4c,0x61,0xbb,0xbc,
0x62,0x17,0xa9,0xcd,0x79,0x3f,0x21,0x4e,0x96,0xcb,0x0e,0xdc,0x61,0x94,0x30,
0x18,0x10,0x6b,0xd0,0x1c,0x10,0x79,0x02,0x03,0x01,0x00,0x01,0xa3,0x16,0x30,
0x14,0x30,0x12,0x06,0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,
0x01,0x01,0xff,0x02,0x01,0x01,0x31,0x77,0x30,0x75,0x02,0x01,0x01,0x30,0x1a,
0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,
0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,
0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x04,0x06,0x00,0x05,
0x00,0x04,0x40,0x81,0xa6,0x70,0xb3,0xef,0x59,0xd1,0x66,0xd1,0x9b,0xc0,0x9a,
0xb6,0x9a,0x5e,0x6d,0x6f,0x6d,0x0d,0x59,0xa9,0xaa,0x6e,0xe9,0x2c,0xa0,0x1e,
0xee,0xc2,0x60,0xbc,0x59,0xbe,0x3f,0x63,0x06,0x8d,0xc9,0x11,0x1d,0x23,0x64,
0x92,0xef,0x2e,0xfc,0x57,0x29,0xa4,0xaf,0xe0,0xee,0x93,0x19,0x39,0x51,0xe4,
0x44,0xb8,0x0b,0x28,0xf4,0xa8,0x0d }

Definition at line 49 of file object.c.

Referenced by test_query_object().

◆ signedWithCertWithValidPubKeyContentBase64

char signedWithCertWithValidPubKeyContentBase64[]
static
Initial value:
=
"MIIBiQYJKoZIhvcNAQcCoIIBejCCAXYCAQExDjAMBggqhkiG9w0CBQUAMBMGCSqG"
"SIb3DQEHAaAGBAQBAgMEoIHSMIHPAgEBMAIGADAVMRMwEQYDVQQDEwpKdWFuIExh"
"bmcAMCIYDzE2MDEwMTAxMDAwMDAwWhgPMTYwMTAxMDEwMDAwMDBaMBUxEzARBgNV"
"BAMTCkp1YW4gTGFuZwAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA4lQ6p4OxJxQ+"
"Wbu0U+Yf513xIWithVPbax7rZZcDhmDe82w4deBMYbu8YhepzXk/IU6Wyw7cYZQw"
"GBBr0BwQeQIDAQABoxYwFDASBgNVHRMBAf8ECDAGAQH/AgEBMXcwdQIBATAaMBUx"
"EzARBgNVBAMTCkp1YW4gTGFuZwACAQEwDAYIKoZIhvcNAgUFADAEBgAFAARAgaZw"
"s+9Z0WbRm8CatppebW9tDVmpqm7pLKAe7sJgvFm+P2MGjckRHSNkku8u/FcppK/g"
"7pMZOVHkRLgLKPSoDQ=="

Definition at line 77 of file object.c.

Referenced by test_query_object().

◆ signedWithCertWithValidPubKeyContentBase64W

WCHAR signedWithCertWithValidPubKeyContentBase64W[]
static
Initial value:
=
L"MIIBiQYJKoZIhvcNAQcCoIIBejCCAXYCAQExDjAMBggqhkiG9w0CBQUAMBMGCSqG"
"SIb3DQEHAaAGBAQBAgMEoIHSMIHPAgEBMAIGADAVMRMwEQYDVQQDEwpKdWFuIExh"
"bmcAMCIYDzE2MDEwMTAxMDAwMDAwWhgPMTYwMTAxMDEwMDAwMDBaMBUxEzARBgNV"
"BAMTCkp1YW4gTGFuZwAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA4lQ6p4OxJxQ+"
"Wbu0U+Yf513xIWithVPbax7rZZcDhmDe82w4deBMYbu8YhepzXk/IU6Wyw7cYZQw"
"GBBr0BwQeQIDAQABoxYwFDASBgNVHRMBAf8ECDAGAQH/AgEBMXcwdQIBATAaMBUx"
"EzARBgNVBAMTCkp1YW4gTGFuZwACAQEwDAYIKoZIhvcNAgUFADAEBgAFAARAgaZw"
"s+9Z0WbRm8CatppebW9tDVmpqm7pLKAe7sJgvFm+P2MGjckRHSNkku8u/FcppK/g"
"7pMZOVHkRLgLKPSoDQ=="

Definition at line 87 of file object.c.

Referenced by test_query_object().