ReactOS  0.4.13-dev-563-g0561610
store.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <winreg.h>
#include <winerror.h>
#include <wincrypt.h>
#include "wine/test.h"
Include dependency graph for store.c:

Go to the source code of this file.

Classes

struct  CertPropIDHeader
 
struct  EnumSystemStoreInfo
 

Macros

#define CERT_CERT_PROP_ID   32
 
#define CERT_CRL_PROP_ID   33
 
#define CERT_CTL_PROP_ID   34
 
#define test_store_is_empty(store)   _test_store_is_empty(__LINE__,store)
 

Functions

static void _test_store_is_empty (unsigned line, HCERTSTORE store)
 
static void testMemStore (void)
 
static void compareStore (HCERTSTORE store, LPCSTR name, const BYTE *pb, DWORD cb, BOOL todo)
 
static void testRegStoreSavedCerts (void)
 
static void testStoresInCollection (void)
 
static void testCollectionStore (void)
 
static const struct CertPropIDHeaderfindPropID (const BYTE *buf, DWORD size, DWORD propID)
 
static void testRegStore (void)
 
static void testSystemRegStore (void)
 
static void testSystemStore (void)
 
static void testFileStore (void)
 
static BOOL initFileFromData (LPCWSTR filename, const BYTE *pb, DWORD cb)
 
static void testFileNameStore (void)
 
static void testMessageStore (void)
 
static void testSerializedStore (void)
 
static void testCertOpenSystemStore (void)
 
static void testCertRegisterSystemStore (void)
 
static BOOL CALLBACK enumSystemStoreCB (const void *systemStore, DWORD dwFlags, PCERT_SYSTEM_STORE_INFO pStoreInfo, void *pvReserved, void *pvArg)
 
static void testCertEnumSystemStore (void)
 
static void testStoreProperty (void)
 
static void testAddSerialized (void)
 
static void delete_test_key (void)
 
static void testAddCertificateLink (void)
 
static DWORD countCertsInStore (HCERTSTORE store)
 
static DWORD countCRLsInStore (HCERTSTORE store)
 
static void testEmptyStore (void)
 
static void testCloseStore (void)
 
static void test_I_UpdateStore (void)
 
 START_TEST (store)
 

Variables

static const BYTE emptyCert [] = { 0x30, 0x00 }
 
static const BYTE bigCert []
 
static const BYTE signedBigCert []
 
static const BYTE serializedCert []
 
static const BYTE signedCRL []
 
static const BYTE bigCert2 []
 
static const BYTE signedCTLWithCTLInnerContent []
 
static const BYTE serializedStoreWithCert []
 
struct {
   HKEY   key
 
   DWORD   cert_store
 
   BOOL   appdata_file
 
   WCHAR   store_name [16]
 
   const WCHAR *   base_reg_path
 
reg_store_saved_certs []
 
static const char MyA [] = { 'M','y',0,0 }
 
static const WCHAR MyW [] = { 'M','y',0 }
 
static const WCHAR BogusW [] = { 'B','o','g','u','s',0 }
 
static const WCHAR BogusPathW []
 
static const BYTE serializedStoreWithCertAndCRL []
 
static const BYTE base64SPC []
 
static const WCHAR utf16Base64SPC []
 
static const BYTE signedContent []
 
static const BYTE signedWithCertAndCrlBareContent []
 
static const BYTE hashContent []
 
static const BYTE hashBareContent []
 
struct {
   DWORD   cert_store
 
   BOOL   expected
 
   BOOL   todo
 
reg_system_store_test_data []
 
static const BYTE serializedCertWithFriendlyName []
 
static const BYTE serializedStoreWithCertWithFriendlyName []
 
static const BYTE serializedStoreWithCertAndHash []
 

Macro Definition Documentation

◆ CERT_CERT_PROP_ID

#define CERT_CERT_PROP_ID   32

Definition at line 36 of file store.c.

◆ CERT_CRL_PROP_ID

#define CERT_CRL_PROP_ID   33

Definition at line 37 of file store.c.

◆ CERT_CTL_PROP_ID

#define CERT_CTL_PROP_ID   34

Definition at line 38 of file store.c.

◆ test_store_is_empty

#define test_store_is_empty (   store)    _test_store_is_empty(__LINE__,store)

Definition at line 120 of file store.c.

Function Documentation

◆ _test_store_is_empty()

static void _test_store_is_empty ( unsigned  line,
HCERTSTORE  store 
)
static

Definition at line 121 of file store.c.

122 {
123  const CERT_CONTEXT *cert;
124 
126  ok_(__FILE__,line)(!cert && GetLastError() == CRYPT_E_NOT_FOUND, "store is not empty\n");
127 }
#define CRYPT_E_NOT_FOUND
Definition: winerror.h:3007
#define ok_(x1, x2)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
static BYTE cert[]
Definition: msg.c:1437
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928

◆ compareStore()

static void compareStore ( HCERTSTORE  store,
LPCSTR  name,
const BYTE pb,
DWORD  cb,
BOOL  todo 
)
static

Definition at line 304 of file store.c.

306 {
307  BOOL ret;
308  CRYPT_DATA_BLOB blob = { 0, NULL };
309 
312  ok(ret, "CertSaveStore failed: %08x\n", GetLastError());
314  ok(blob.cbData == cb, "%s: expected size %d, got %d\n", name, cb,
315  blob.cbData);
316  blob.pbData = HeapAlloc(GetProcessHeap(), 0, blob.cbData);
317  if (blob.pbData)
318  {
321  ok(ret, "CertSaveStore failed: %08x\n", GetLastError());
323  ok(!memcmp(pb, blob.pbData, cb), "%s: unexpected value\n", name);
324  HeapFree(GetProcessHeap(), 0, blob.pbData);
325  }
326 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
Definition: image.c:133
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
#define todo_wine_if(is_todo)
Definition: test.h:155
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CERT_STORE_SAVE_AS_STORE
Definition: wincrypt.h:2646
static DWORD cb
Definition: integrity.c:41
int ret
BOOL todo
Definition: store.c:2064
BOOL WINAPI CertSaveStore(HCERTSTORE hCertStore, DWORD dwMsgAndCertEncodingType, DWORD dwSaveAs, DWORD dwSaveTo, void *pvSaveToPara, DWORD dwFlags)
Definition: serialize.c:895
#define CERT_STORE_SAVE_TO_MEMORY
Definition: wincrypt.h:2650
Definition: name.c:36
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by testAddCertificateLink(), testCollectionStore(), testFileNameStore(), and testFileStore().

◆ countCertsInStore()

static DWORD countCertsInStore ( HCERTSTORE  store)
static

Definition at line 2775 of file store.c.

2776 {
2778  DWORD certs = 0;
2779 
2780  do {
2782  if (cert)
2783  certs++;
2784  } while (cert);
2785  return certs;
2786 }
smooth NULL
Definition: ftsmooth.c:416
static BYTE cert[]
Definition: msg.c:1437
unsigned long DWORD
Definition: ntddk_ex.h:95
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928

Referenced by test_I_UpdateStore().

◆ countCRLsInStore()

static DWORD countCRLsInStore ( HCERTSTORE  store)
static

Definition at line 2788 of file store.c.

2789 {
2791  DWORD crls = 0;
2792 
2793  do {
2794  crl = CertEnumCRLsInStore(store, crl);
2795  if (crl)
2796  crls++;
2797  } while (crl);
2798  return crls;
2799 }
static const BYTE crl[]
Definition: message.c:864
PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(HCERTSTORE hCertStore, PCCRL_CONTEXT pPrev)
Definition: store.c:1101
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by test_I_UpdateStore().

◆ delete_test_key()

static void delete_test_key ( void  )
static

Definition at line 2452 of file store.c.

2453 {
2454  HKEY root_key, test_key;
2455  static const WCHAR SysCertW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2456  'S','y','s','t','e','m','C','e','r','t','i','f','i','c','a','t','e','s',0};
2457  static const WCHAR WineTestW[] = {'W','i','n','e','T','e','s','t',0};
2458  WCHAR subkey_name[32];
2459  DWORD num_subkeys, subkey_name_len;
2460  int idx;
2461 
2462  if (RegOpenKeyExW(HKEY_CURRENT_USER, SysCertW, 0, KEY_READ, &root_key))
2463  return;
2464  if (RegOpenKeyExW(root_key, WineTestW, 0, KEY_READ, &test_key))
2465  {
2467  return;
2468  }
2469  RegQueryInfoKeyW(test_key, NULL, NULL, NULL, &num_subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
2470  for (idx = num_subkeys; idx-- > 0;)
2471  {
2472  subkey_name_len = ARRAY_SIZE(subkey_name);
2473  RegEnumKeyExW(test_key, idx, subkey_name, &subkey_name_len, NULL, NULL, NULL, NULL);
2474  RegDeleteKeyW(test_key, subkey_name);
2475  }
2476  RegCloseKey(test_key);
2477  RegDeleteKeyW(root_key, WineTestW);
2479 }
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1237
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned int idx
Definition: utils.c:41
struct reiserfs_key root_key
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
#define ARRAY_SIZE(a)
Definition: main.h:24
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527

Referenced by testAddCertificateLink().

◆ enumSystemStoreCB()

static BOOL CALLBACK enumSystemStoreCB ( const void systemStore,
DWORD  dwFlags,
PCERT_SYSTEM_STORE_INFO  pStoreInfo,
void pvReserved,
void pvArg 
)
static

Definition at line 2142 of file store.c.

2144 {
2145  struct EnumSystemStoreInfo *info = pvArg;
2146 
2147  info->storeCount++;
2148  return info->goOn;
2149 }

Referenced by testCertEnumSystemStore().

◆ findPropID()

static const struct CertPropIDHeader* findPropID ( const BYTE buf,
DWORD  size,
DWORD  propID 
)
static

Definition at line 984 of file store.c.

986 {
987  const struct CertPropIDHeader *ret = NULL;
988  BOOL failed = FALSE;
989 
990  while (size && !ret && !failed)
991  {
992  if (size < sizeof(struct CertPropIDHeader))
993  failed = TRUE;
994  else
995  {
996  const struct CertPropIDHeader *hdr =
997  (const struct CertPropIDHeader *)buf;
998 
999  size -= sizeof(struct CertPropIDHeader);
1000  buf += sizeof(struct CertPropIDHeader);
1001  if (size < hdr->cb)
1002  failed = TRUE;
1003  else if (hdr->propID == propID)
1004  ret = hdr;
1005  else
1006  {
1007  buf += hdr->cb;
1008  size -= hdr->cb;
1009  }
1010  }
1011  }
1012  return ret;
1013 }
#define TRUE
Definition: types.h:120
char hdr[14]
Definition: iptest.cpp:33
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
DWORD propID
Definition: store.c:42
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
static DWORD cb
Definition: integrity.c:41
int ret

Referenced by testRegStore().

◆ initFileFromData()

static BOOL initFileFromData ( LPCWSTR  filename,
const BYTE pb,
DWORD  cb 
)
static

Definition at line 1568 of file store.c.

1569 {
1572  BOOL ret;
1573 
1574  if (file != INVALID_HANDLE_VALUE)
1575  {
1576  DWORD written;
1577 
1578  ret = WriteFile(file, pb, cb, &written, NULL);
1579  CloseHandle(file);
1580  }
1581  else
1582  ret = FALSE;
1583  return ret;
1584 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
const char * filename
Definition: ioapi.h:135
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD cb
Definition: integrity.c:41
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
#define CREATE_ALWAYS
Definition: disk.h:72
#define CreateFileW
Definition: compat.h:400
Definition: fci.c:126

Referenced by testFileNameStore().

◆ START_TEST()

START_TEST ( store  )

Definition at line 3041 of file store.c.

3042 {
3043  /* various combinations of CertOpenStore */
3044  testMemStore();
3047 
3048  testRegStore();
3050 
3052  testSystemStore();
3053  testFileStore();
3055  testMessageStore();
3057  testCloseStore();
3058 
3060 
3064 
3067 
3068  testEmptyStore();
3069 
3071 }
static void testCloseStore(void)
Definition: store.c:2877
static void test_I_UpdateStore(void)
Definition: store.c:2970
static void testEmptyStore(void)
Definition: store.c:2801
static void testAddSerialized(void)
Definition: store.c:2256
static void testCertOpenSystemStore(void)
Definition: store.c:2040
static void testSerializedStore(void)
Definition: store.c:1981
static void testStoresInCollection(void)
Definition: store.c:485
static void testAddCertificateLink(void)
Definition: store.c:2481
static void testSystemStore(void)
Definition: store.c:1349
static void testCertEnumSystemStore(void)
Definition: store.c:2151
static void testRegStore(void)
Definition: store.c:1015
static void testFileStore(void)
Definition: store.c:1440
static void testRegStoreSavedCerts(void)
Definition: store.c:367
static void testCollectionStore(void)
Definition: store.c:622
static void testCertRegisterSystemStore(void)
Definition: store.c:2075
static void testFileNameStore(void)
Definition: store.c:1646
static void testSystemRegStore(void)
Definition: store.c:1291
static void testStoreProperty(void)
Definition: store.c:2183
static void testMemStore(void)
Definition: store.c:129
static void testMessageStore(void)
Definition: store.c:1869

◆ test_I_UpdateStore()

static void test_I_UpdateStore ( void  )
static

Definition at line 2970 of file store.c.

2971 {
2972  HMODULE lib = GetModuleHandleA("crypt32");
2973  BOOL (WINAPI *pI_CertUpdatestore)(HCERTSTORE, HCERTSTORE, DWORD, DWORD) =
2974  (void *)GetProcAddress(lib, "I_CertUpdateStore");
2975  BOOL ret;
2976  HCERTSTORE store1, store2;
2978  DWORD certs;
2979 
2980  if (!pI_CertUpdatestore)
2981  {
2982  win_skip("No I_CertUpdateStore\n");
2983  return;
2984  }
2985  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
2987  store2 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
2989 
2990  /* Crash
2991  ret = pI_CertUpdatestore(NULL, NULL, 0, 0);
2992  ret = pI_CertUpdatestore(store1, NULL, 0, 0);
2993  ret = pI_CertUpdatestore(NULL, store2, 0, 0);
2994  */
2995  ret = pI_CertUpdatestore(store1, store2, 0, 0);
2996  ok(ret, "I_CertUpdateStore failed: %08x\n", GetLastError());
2997 
2999  sizeof(bigCert), CERT_STORE_ADD_ALWAYS, &cert);
3000  /* I_CertUpdateStore adds the contexts from store2 to store1 */
3001  ret = pI_CertUpdatestore(store1, store2, 0, 0);
3002  ok(ret, "I_CertUpdateStore failed: %08x\n", GetLastError());
3003  certs = countCertsInStore(store1);
3004  ok(certs == 1, "Expected 1 cert, got %d\n", certs);
3005  /* Calling it a second time has no effect */
3006  ret = pI_CertUpdatestore(store1, store2, 0, 0);
3007  ok(ret, "I_CertUpdateStore failed: %08x\n", GetLastError());
3008  certs = countCertsInStore(store1);
3009  ok(certs == 1, "Expected 1 cert, got %d\n", certs);
3010 
3011  /* The last parameters to I_CertUpdateStore appear to be ignored */
3012  ret = pI_CertUpdatestore(store1, store2, 1, 0);
3013  ok(ret, "I_CertUpdateStore failed: %08x\n", GetLastError());
3014  ret = pI_CertUpdatestore(store1, store2, 0, 1);
3015  ok(ret, "I_CertUpdateStore failed: %08x\n", GetLastError());
3016 
3019 
3020  /* I_CertUpdateStore also adds the CRLs from store2 to store1 */
3021  ret = pI_CertUpdatestore(store1, store2, 0, 0);
3022  ok(ret, "I_CertUpdateStore failed: %08x\n", GetLastError());
3023  certs = countCertsInStore(store1);
3024  ok(certs == 1, "Expected 1 cert, got %d\n", certs);
3025  certs = countCRLsInStore(store1);
3026  ok(certs == 1, "Expected 1 CRL, got %d\n", certs);
3027 
3029  /* If a context is deleted from store2, I_CertUpdateStore deletes it
3030  * from store1
3031  */
3032  ret = pI_CertUpdatestore(store1, store2, 0, 0);
3033  ok(ret, "I_CertUpdateStore failed: %08x\n", GetLastError());
3034  certs = countCertsInStore(store1);
3035  ok(certs == 0, "Expected 0 certs, got %d\n", certs);
3036 
3037  CertCloseStore(store1, 0);
3038  CertCloseStore(store2, 0);
3039 }
static const BYTE bigCert[]
Definition: store.c:48
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
BOOL WINAPI CertAddEncodedCRLToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCrlEncoded, DWORD cbCrlEncoded, DWORD dwAddDisposition, PCCRL_CONTEXT *ppCrlContext)
Definition: crl.c:129
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
static BYTE cert[]
Definition: msg.c:1437
static const BYTE signedCRL[]
Definition: store.c:83
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
static DWORD countCertsInStore(HCERTSTORE store)
Definition: store.c:2775
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
static DWORD countCRLsInStore(HCERTSTORE store)
Definition: store.c:2788
#define GetProcAddress(x, y)
Definition: compat.h:410
void * HCERTSTORE
Definition: wincrypt.h:51
#define win_skip
Definition: test.h:141
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485

Referenced by START_TEST().

◆ testAddCertificateLink()

static void testAddCertificateLink ( void  )
static

Definition at line 2481 of file store.c.

2482 {
2483  BOOL ret;
2484  HCERTSTORE store1, store2;
2485  PCCERT_CONTEXT source, linked;
2486  DWORD size;
2487  LPBYTE buf;
2489  static const WCHAR szPrefix[] = { 'c','e','r',0 };
2490  static const WCHAR szDot[] = { '.',0 };
2491  static const WCHAR WineTestW[] = { 'W','i','n','e','T','e','s','t',0 };
2492  WCHAR filename1[MAX_PATH], filename2[MAX_PATH];
2493  HANDLE file;
2494 
2495  if (0)
2496  {
2497  /* Crashes, i.e. the store is dereferenced without checking. */
2499  }
2500 
2501  /* Adding a certificate link to a store requires a valid add disposition */
2502  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
2504  SetLastError(0xdeadbeef);
2505  ret = CertAddCertificateLinkToStore(store1, NULL, 0, NULL);
2506  ok(!ret && GetLastError() == E_INVALIDARG,
2507  "expected E_INVALIDARG, got %08x\n", GetLastError());
2509  sizeof(bigCert));
2510  SetLastError(0xdeadbeef);
2512  ok(!ret && GetLastError() == E_INVALIDARG,
2513  "expected E_INVALIDARG, got %08x\n", GetLastError());
2515  NULL);
2516  ok(ret, "CertAddCertificateLinkToStore failed: %08x\n", GetLastError());
2517  if (0)
2518  {
2519  /* Crashes, i.e. the source certificate is dereferenced without
2520  * checking when a valid add disposition is given.
2521  */
2523  NULL);
2524  }
2525  CertCloseStore(store1, 0);
2526 
2527  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
2530  &linked);
2531  ok(ret, "CertAddCertificateLinkToStore failed: %08x\n", GetLastError());
2532  if (ret)
2533  {
2534  ok(linked->hCertStore == store1, "unexpected store\n");
2536  ok(ret, "CertSerializeCertificateStoreElement failed: %08x\n",
2537  GetLastError());
2538  buf = HeapAlloc(GetProcessHeap(), 0, size);
2539  if (buf)
2540  {
2542  ok(ret, "CertSerializeCertificateStoreElement failed: %08x\n",
2543  GetLastError());
2544  /* The serialized linked certificate is identical to the serialized
2545  * original certificate.
2546  */
2547  ok(size == sizeof(serializedCert), "Wrong size %d\n", size);
2549  "Unexpected serialized cert\n");
2550  HeapFree(GetProcessHeap(), 0, buf);
2551  }
2552  /* Set a friendly name on the source certificate... */
2553  blob.pbData = (LPBYTE)WineTestW;
2554  blob.cbData = sizeof(WineTestW);
2557  ok(ret, "CertSetCertificateContextProperty failed: %08x\n",
2558  GetLastError());
2559  /* and the linked certificate has the same friendly name. */
2562  ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
2563  GetLastError());
2564  buf = HeapAlloc(GetProcessHeap(), 0, size);
2565  if (buf)
2566  {
2569  ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
2570  GetLastError());
2571  ok(!lstrcmpW((LPCWSTR)buf, WineTestW),
2572  "unexpected friendly name\n");
2573  HeapFree(GetProcessHeap(), 0, buf);
2574  }
2576  }
2578  CertCloseStore(store1, 0);
2579 
2580  /* Test adding a cert to a file store, committing the change to the store,
2581  * and creating a link to the resulting cert.
2582  */
2583  if (!GetTempFileNameW(szDot, szPrefix, 0, filename1))
2584  return;
2585 
2586  DeleteFileW(filename1);
2587  file = CreateFileW(filename1, GENERIC_READ | GENERIC_WRITE, 0, NULL,
2589  if (file == INVALID_HANDLE_VALUE)
2590  return;
2591 
2592  store1 = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
2594  ok(store1 != NULL, "CertOpenStore failed: %08x\n", GetLastError());
2595  CloseHandle(file);
2596 
2599  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
2600  GetLastError());
2601 
2602  /* Test adding a link to a memory store. */
2603  store2 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
2606  &linked);
2607  ok(ret, "CertAddCertificateLinkToStore failed: %08x\n", GetLastError());
2608  if (ret)
2609  {
2610  ok(linked->hCertStore == store2, "unexpected store\n");
2612  ok(ret, "CertSerializeCertificateStoreElement failed: %08x\n",
2613  GetLastError());
2614  buf = HeapAlloc(GetProcessHeap(), 0, size);
2615  if (buf)
2616  {
2618  /* The serialized linked certificate is identical to the serialized
2619  * original certificate.
2620  */
2621  ok(ret, "CertSerializeCertificateStoreElement failed: %08x\n", GetLastError());
2622  ok(size == sizeof(serializedCert), "Wrong size %d\n", size);
2624  "Unexpected serialized cert\n");
2625  HeapFree(GetProcessHeap(), 0, buf);
2626  }
2627  /* Set a friendly name on the source certificate... */
2628  blob.pbData = (LPBYTE)WineTestW;
2629  blob.cbData = sizeof(WineTestW);
2632  ok(ret, "CertSetCertificateContextProperty failed: %08x\n",
2633  GetLastError());
2634  /* and the linked certificate has the same friendly name. */
2637  ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
2638  GetLastError());
2639  buf = HeapAlloc(GetProcessHeap(), 0, size);
2640  if (buf)
2641  {
2644  ok(ret, "CertGetCertificateContextProperty failed: %08x\n", GetLastError());
2645  ok(!lstrcmpW((LPCWSTR)buf, WineTestW),
2646  "unexpected friendly name\n");
2647  HeapFree(GetProcessHeap(), 0, buf);
2648  }
2650  }
2651  CertCloseStore(store2, 0);
2652 
2653  if (!GetTempFileNameW(szDot, szPrefix, 0, filename2))
2654  return;
2655 
2659  if (file == INVALID_HANDLE_VALUE)
2660  return;
2661 
2662  store2 = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
2664  ok(store2 != NULL, "CertOpenStore failed: %08x\n", GetLastError());
2665  CloseHandle(file);
2666  /* Test adding a link to a file store. */
2668  &linked);
2669  ok(ret, "CertAddCertificateLinkToStore failed: %08x\n", GetLastError());
2670  if (ret)
2671  {
2672  ok(linked->hCertStore == store2, "unexpected store\n");
2674  ok(ret, "CertSerializeCertificateStoreElement failed: %08x\n",
2675  GetLastError());
2676  buf = HeapAlloc(GetProcessHeap(), 0, size);
2677  if (buf)
2678  {
2680  ok(ret, "CertSerializeCertificateStoreElement failed: %08x\n",
2681  GetLastError());
2682  /* The serialized linked certificate now contains the friendly
2683  * name property.
2684  */
2686  "Wrong size %d\n", size);
2688  "Unexpected serialized cert\n");
2689  HeapFree(GetProcessHeap(), 0, buf);
2690  }
2692  compareStore(store2, "file store -> file store",
2695  }
2696  CertCloseStore(store2, 0);
2698 
2700 
2701  CertCloseStore(store1, 0);
2702  DeleteFileW(filename1);
2703 
2704  /* Test adding a link to a system store (which is a collection store.) */
2705  store1 = CertOpenSystemStoreA(0, "My");
2707  sizeof(bigCert));
2708  SetLastError(0xdeadbeef);
2710  &linked);
2711  ok(!ret && GetLastError() == E_INVALIDARG,
2712  "expected E_INVALIDARG, got %08x\n", GetLastError());
2714 
2715  /* Test adding a link to a file store, where the linked certificate is
2716  * in a system store.
2717  */
2720  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
2721  GetLastError());
2722  if (!GetTempFileNameW(szDot, szPrefix, 0, filename1))
2723  return;
2724 
2725  DeleteFileW(filename1);
2726  file = CreateFileW(filename1, GENERIC_READ | GENERIC_WRITE, 0, NULL,
2728  if (file == INVALID_HANDLE_VALUE)
2729  return;
2730 
2731  store2 = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
2733  ok(store2 != NULL, "CertOpenStore failed: %08x\n", GetLastError());
2734  CloseHandle(file);
2735 
2737  &linked);
2738  ok(ret, "CertAddCertificateLinkToStore failed: %08x\n", GetLastError());
2739  if (ret)
2740  {
2741  ok(linked->hCertStore == store2, "unexpected store\n");
2743  ok(ret, "CertControlStore failed: %d\n", ret);
2744  compareStore(store2, "file store -> system store",
2748  }
2749 
2750  CertCloseStore(store2, 0);
2751  DeleteFileW(filename1);
2752 
2753  /* Test adding a link to a registry store, where the linked certificate is
2754  * in a system store.
2755  */
2757  CERT_SYSTEM_STORE_CURRENT_USER, WineTestW);
2758  ok(store2 != NULL, "CertOpenStore failed: %08x\n", GetLastError());
2760  &linked);
2761  ok(ret, "CertAddCertificateLinkToStore failed: %08x\n", GetLastError());
2762  if (ret)
2763  {
2764  ok(linked->hCertStore == store2, "unexpected store\n");
2766  }
2767  CertCloseStore(store2, 0);
2768 
2770  CertCloseStore(store1, 0);
2771 
2772  delete_test_key();
2773 }
static const BYTE serializedCertWithFriendlyName[]
Definition: store.c:2410
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
Definition: image.c:133
static const BYTE bigCert[]
Definition: store.c:48
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
HCERTSTORE hCertStore
Definition: wincrypt.h:483
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CERT_STORE_CTRL_COMMIT
Definition: wincrypt.h:2822
#define CERT_FILE_STORE_COMMIT_ENABLE_FLAG
Definition: wincrypt.h:2475
static void compareStore(HCERTSTORE store, LPCSTR name, const BYTE *pb, DWORD cb, BOOL todo)
Definition: store.c:304
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
BOOL WINAPI CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext, DWORD dwPropId, void *pvData, DWORD *pcbData)
Definition: cert.c:551
unsigned char * LPBYTE
Definition: typedefs.h:52
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
#define E_INVALIDARG
Definition: ddrawi.h:101
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
smooth NULL
Definition: ftsmooth.c:416
static char filename2[]
Definition: lzexpand_main.c:51
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
BOOL WINAPI CertControlStore(HCERTSTORE hCertStore, DWORD dwFlags, DWORD dwCtrlType, void const *pvCtrlPara)
Definition: store.c:1149
#define CERT_FRIENDLY_NAME_PROP_ID
Definition: wincrypt.h:2697
static const BYTE serializedCert[]
Definition: store.c:71
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const BYTE serializedStoreWithCertWithFriendlyName[]
Definition: store.c:2423
#define MAX_PATH
Definition: compat.h:26
const char file[]
Definition: icontest.c:11
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CERT_STORE_PROV_SYSTEM_REGISTRY
Definition: wincrypt.h:2264
#define SetLastError(x)
Definition: compat.h:409
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded)
Definition: cert.c:316
static const WCHAR szDot[]
Definition: msipriv.h:1113
HCERTSTORE WINAPI CertOpenSystemStoreA(HCRYPTPROV_LEGACY hProv, LPCSTR szSubSystemProtocol)
Definition: store.c:904
#define GENERIC_READ
Definition: compat.h:124
static const BYTE serializedStoreWithCertAndHash[]
Definition: store.c:2437
#define CREATE_ALWAYS
Definition: disk.h:72
GLsizei GLsizei GLchar * source
Definition: glext.h:6048
#define CERT_SYSTEM_STORE_CURRENT_USER
Definition: wincrypt.h:2324
#define CERT_STORE_PROV_FILE
Definition: wincrypt.h:2252
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
BOOL WINAPI CertSerializeCertificateStoreElement(PCCERT_CONTEXT pCertContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:144
static void delete_test_key(void)
Definition: store.c:2452
#define CreateFileW
Definition: compat.h:400
BOOL WINAPI CertAddCertificateLinkToStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:296
BOOL WINAPI CertSetCertificateContextProperty(PCCERT_CONTEXT pCertContext, DWORD dwPropId, DWORD dwFlags, const void *pvData)
Definition: cert.c:799
#define HeapFree(x, y, z)
Definition: compat.h:394
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
Definition: fci.c:126

Referenced by START_TEST().

◆ testAddSerialized()

static void testAddSerialized ( void  )
static

Definition at line 2256 of file store.c.

2257 {
2258  BOOL ret;
2259  HCERTSTORE store;
2260  BYTE buf[sizeof(struct CertPropIDHeader) * 2 + 20 + sizeof(bigCert)] =
2261  { 0 };
2262  BYTE hash[20];
2263  struct CertPropIDHeader *hdr;
2265 
2266  ret = CertAddSerializedElementToStore(0, NULL, 0, 0, 0, 0, NULL, NULL);
2268  "Expected ERROR_END_OF_MEDIA, got %08x\n", GetLastError());
2269 
2270  store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
2272  ok(store != 0, "CertOpenStore failed: %08x\n", GetLastError());
2273 
2274  ret = CertAddSerializedElementToStore(store, NULL, 0, 0, 0, 0, NULL, NULL);
2276  "Expected ERROR_END_OF_MEDIA, got %08x\n", GetLastError());
2277 
2278  /* Test with an empty property */
2279  hdr = (struct CertPropIDHeader *)buf;
2280  hdr->propID = CERT_CERT_PROP_ID;
2281  hdr->unknown1 = 1;
2282  hdr->cb = 0;
2283  ret = CertAddSerializedElementToStore(store, buf, sizeof(buf), 0, 0, 0,
2284  NULL, NULL);
2285  ok(!ret && GetLastError() == E_INVALIDARG,
2286  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2287  /* Test with a bad size in property header */
2288  hdr->cb = sizeof(bigCert) - 1;
2289  memcpy(buf + sizeof(struct CertPropIDHeader), bigCert, sizeof(bigCert));
2290  ret = CertAddSerializedElementToStore(store, buf, sizeof(buf), 0, 0, 0,
2291  NULL, NULL);
2292  ok(!ret && GetLastError() == E_INVALIDARG,
2293  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2295  sizeof(struct CertPropIDHeader) + sizeof(bigCert), 0, 0, 0, NULL,
2296  NULL);
2297  ok(!ret && GetLastError() == E_INVALIDARG,
2298  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2300  sizeof(struct CertPropIDHeader) + sizeof(bigCert), CERT_STORE_ADD_NEW,
2301  0, 0, NULL, NULL);
2302  ok(!ret && GetLastError() == E_INVALIDARG,
2303  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2304  /* Kosher size in property header, but no context type */
2305  hdr->cb = sizeof(bigCert);
2306  ret = CertAddSerializedElementToStore(store, buf, sizeof(buf), 0, 0, 0,
2307  NULL, NULL);
2308  ok(!ret && GetLastError() == E_INVALIDARG,
2309  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2311  sizeof(struct CertPropIDHeader) + sizeof(bigCert), 0, 0, 0, NULL,
2312  NULL);
2313  ok(!ret && GetLastError() == E_INVALIDARG,
2314  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2316  sizeof(struct CertPropIDHeader) + sizeof(bigCert), CERT_STORE_ADD_NEW,
2317  0, 0, NULL, NULL);
2318  ok(!ret && GetLastError() == E_INVALIDARG,
2319  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2320  /* With a bad context type */
2321  ret = CertAddSerializedElementToStore(store, buf, sizeof(buf), 0, 0,
2323  ok(!ret && GetLastError() == E_INVALIDARG,
2324  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2326  sizeof(struct CertPropIDHeader) + sizeof(bigCert), 0, 0,
2328  ok(!ret && GetLastError() == E_INVALIDARG,
2329  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2331  sizeof(struct CertPropIDHeader) + sizeof(bigCert), CERT_STORE_ADD_NEW,
2333  ok(!ret && GetLastError() == E_INVALIDARG,
2334  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2335  /* Bad unknown field, good type */
2336  hdr->unknown1 = 2;
2337  ret = CertAddSerializedElementToStore(store, buf, sizeof(buf), 0, 0,
2340  "Expected ERROR_FILE_NOT_FOUND got %08x\n", GetLastError());
2342  sizeof(struct CertPropIDHeader) + sizeof(bigCert), 0, 0,
2345  "Expected ERROR_FILE_NOT_FOUND got %08x\n", GetLastError());
2347  sizeof(struct CertPropIDHeader) + sizeof(bigCert), CERT_STORE_ADD_NEW,
2350  "Expected ERROR_FILE_NOT_FOUND got %08x\n", GetLastError());
2351  /* Most everything okay, but bad add disposition */
2352  hdr->unknown1 = 1;
2353  /* This crashes
2354  ret = CertAddSerializedElementToStore(store, buf, sizeof(buf), 0, 0,
2355  CERT_STORE_CERTIFICATE_CONTEXT_FLAG, NULL, NULL);
2356  * as does this
2357  ret = CertAddSerializedElementToStore(store, buf,
2358  sizeof(struct CertPropIDHeader) + sizeof(bigCert), 0, 0,
2359  CERT_STORE_CERTIFICATE_CONTEXT_FLAG, NULL, NULL);
2360  */
2361  /* Everything okay, but buffer's too big */
2362  ret = CertAddSerializedElementToStore(store, buf, sizeof(buf),
2364  ok(ret, "CertAddSerializedElementToStore failed: %08x\n", GetLastError());
2365  /* Everything okay, check it's not re-added */
2367  sizeof(struct CertPropIDHeader) + sizeof(bigCert), CERT_STORE_ADD_NEW,
2369  ok(!ret && GetLastError() == CRYPT_E_EXISTS,
2370  "Expected CRYPT_E_EXISTS, got %08x\n", GetLastError());
2371 
2373  ok(context != NULL, "Expected a cert\n");
2374  if (context)
2376 
2377  /* Try adding with a bogus hash. Oddly enough, it succeeds, and the hash,
2378  * when queried, is the real hash rather than the bogus hash.
2379  */
2380  hdr = (struct CertPropIDHeader *)(buf + sizeof(struct CertPropIDHeader) +
2381  sizeof(bigCert));
2382  hdr->propID = CERT_HASH_PROP_ID;
2383  hdr->unknown1 = 1;
2384  hdr->cb = sizeof(hash);
2385  memset(hash, 0xc, sizeof(hash));
2386  memcpy((LPBYTE)hdr + sizeof(struct CertPropIDHeader), hash, sizeof(hash));
2387  ret = CertAddSerializedElementToStore(store, buf, sizeof(buf),
2389  (const void **)&context);
2390  ok(ret, "CertAddSerializedElementToStore failed: %08x\n", GetLastError());
2391  if (context)
2392  {
2393  BYTE hashVal[20], realHash[20];
2394  DWORD size = sizeof(hashVal);
2395 
2396  ret = CryptHashCertificate(0, 0, 0, bigCert, sizeof(bigCert),
2397  realHash, &size);
2398  ok(ret, "CryptHashCertificate failed: %08x\n", GetLastError());
2400  hashVal, &size);
2401  ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
2402  GetLastError());
2403  ok(!memcmp(hashVal, realHash, size), "Unexpected hash\n");
2405  }
2406 
2407  CertCloseStore(store, 0);
2408 }
char hdr[14]
Definition: iptest.cpp:33
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static const BYTE bigCert[]
Definition: store.c:48
Definition: http.c:6587
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
#define CERT_STORE_CERTIFICATE_CONTEXT_FLAG
Definition: wincrypt.h:2978
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static const BYTE hashVal[]
Definition: message.c:650
#define CRYPT_E_EXISTS
Definition: winerror.h:3008
#define CERT_STORE_ADD_NEW
Definition: wincrypt.h:2482
BOOL WINAPI CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext, DWORD dwPropId, void *pvData, DWORD *pcbData)
Definition: cert.c:551
unsigned char * LPBYTE
Definition: typedefs.h:52
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
int hash
Definition: main.c:58
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
#define E_INVALIDARG
Definition: ddrawi.h:101
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
GLsizeiptr size
Definition: glext.h:5919
#define CERT_CERT_PROP_ID
Definition: store.c:36
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CERT_HASH_PROP_ID
Definition: wincrypt.h:2688
int ret
BOOL WINAPI CertAddSerializedElementToStore(HCERTSTORE hCertStore, const BYTE *pbElement, DWORD cbElement, DWORD dwAddDisposition, DWORD dwFlags, DWORD dwContextTypeFlags, DWORD *pdwContentType, const void **ppvContext)
Definition: serialize.c:953
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
#define CERT_STORE_CRL_CONTEXT_FLAG
Definition: wincrypt.h:2980
#define ERROR_END_OF_MEDIA
Definition: winerror.h:636
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
BOOL WINAPI CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid, DWORD dwFlags, const BYTE *pbEncoded, DWORD cbEncoded, BYTE *pbComputedHash, DWORD *pcbComputedHash)
Definition: cert.c:2187
Definition: _hash_fun.h:40
#define memset(x, y, z)
Definition: compat.h:39

Referenced by START_TEST().

◆ testCertEnumSystemStore()

static void testCertEnumSystemStore ( void  )
static

Definition at line 2151 of file store.c.

2152 {
2153  BOOL ret;
2154  struct EnumSystemStoreInfo info = { FALSE, 0 };
2155 
2156  SetLastError(0xdeadbeef);
2159  "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
2160  /* Crashes
2161  ret = CertEnumSystemStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, NULL, NULL,
2162  NULL);
2163  */
2164 
2165  SetLastError(0xdeadbeef);
2168  /* Callback returning FALSE stops enumeration */
2169  ok(!ret, "Expected CertEnumSystemStore to stop\n");
2170  ok(info.storeCount == 0 || info.storeCount == 1,
2171  "Expected 0 or 1 stores\n");
2172 
2173  info.goOn = TRUE;
2174  info.storeCount = 0;
2177  ok(ret, "CertEnumSystemStore failed: %08x\n", GetLastError());
2178  /* There should always be at least My, Root, and CA stores */
2179  ok(info.storeCount == 0 || info.storeCount >= 3,
2180  "Expected at least 3 stores\n");
2181 }
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CERT_SYSTEM_STORE_LOCAL_MACHINE
Definition: wincrypt.h:2326
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
static BOOL CALLBACK enumSystemStoreCB(const void *systemStore, DWORD dwFlags, PCERT_SYSTEM_STORE_INFO pStoreInfo, void *pvReserved, void *pvArg)
Definition: store.c:2142
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define SetLastError(x)
Definition: compat.h:409
BOOL WINAPI CertEnumSystemStore(DWORD dwFlags, void *pvSystemStoreLocationPara, void *pvArg, PFN_CERT_ENUM_SYSTEM_STORE pfnEnum)
Definition: store.c:1321
int ret

Referenced by START_TEST().

◆ testCertOpenSystemStore()

static void testCertOpenSystemStore ( void  )
static

Definition at line 2040 of file store.c.

2041 {
2042  HCERTSTORE store;
2043 
2044  store = CertOpenSystemStoreW(0, NULL);
2045  ok(!store && GetLastError() == E_INVALIDARG,
2046  "Expected E_INVALIDARG, got %08x\n", GetLastError());
2047  /* This succeeds, and on WinXP at least, the Bogus key is created under
2048  * HKCU (but not under HKLM, even when run as an administrator.)
2049  */
2050  store = CertOpenSystemStoreW(0, BogusW);
2051  ok(store != 0, "CertOpenSystemStore failed: %08x\n", GetLastError());
2052  if (store)
2053  CertCloseStore(store, 0);
2054  /* Delete it so other tests succeed next time around */
2058 }
#define CERT_STORE_DELETE_FLAG
Definition: wincrypt.h:2455
static const WCHAR BogusW[]
Definition: store.c:1286
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1237
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HCERTSTORE WINAPI CertOpenSystemStoreW(HCRYPTPROV_LEGACY hProv, LPCWSTR szSubSystemProtocol)
Definition: store.c:916
#define ok(value,...)
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
#define CERT_SYSTEM_STORE_CURRENT_USER
Definition: wincrypt.h:2324
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
static const WCHAR BogusPathW[]
Definition: store.c:1287
#define CERT_STORE_PROV_SYSTEM
Definition: wincrypt.h:2260

Referenced by START_TEST().

◆ testCertRegisterSystemStore()

static void testCertRegisterSystemStore ( void  )
static

Definition at line 2075 of file store.c.

2076 {
2077  BOOL ret, cur_flag;
2078  DWORD err = 0;
2079  HCERTSTORE hstore;
2080  static const WCHAR WineTestW[] = {'W','i','n','e','T','e','s','t',0};
2081  const CERT_CONTEXT *cert, *cert2;
2082  unsigned int i;
2083 
2084  for (i = 0; i < ARRAY_SIZE(reg_system_store_test_data); i++) {
2085  cur_flag = reg_system_store_test_data[i].cert_store;
2086  ret = CertRegisterSystemStore(WineTestW, cur_flag, NULL, NULL);
2087  if (!ret)
2088  {
2089  err = GetLastError();
2090  if (err == ERROR_ACCESS_DENIED)
2091  {
2092  win_skip("Insufficient privileges for the flag %08x test\n", cur_flag);
2093  continue;
2094  }
2095  }
2098  "Store registration (dwFlags=%08x) failed, last error %x\n", cur_flag, err);
2099  if (!ret)
2100  {
2101  skip("Nothing to test without registered store at %08x\n", cur_flag);
2102  continue;
2103  }
2104 
2105  hstore = CertOpenStore(CERT_STORE_PROV_SYSTEM_W, 0, 0, CERT_STORE_OPEN_EXISTING_FLAG | cur_flag, WineTestW);
2106  ok (hstore != NULL, "Opening just registered store at %08x failed, last error %x\n", cur_flag, GetLastError());
2107 
2109  ok (cert != NULL, "Failed creating cert at %08x, last error: %x\n", cur_flag, GetLastError());
2110  if (cert)
2111  {
2113  ok (ret, "Failed to add cert at %08x, last error: %x\n", cur_flag, GetLastError());
2114 
2116  ok (cert2 != NULL && cert2->cbCertEncoded == cert->cbCertEncoded,
2117  "Unexpected cert encoded size at %08x, last error: %x\n", cur_flag, GetLastError());
2118 
2120  ok (ret, "Failed to delete certificate from the new store at %08x, last error: %x\n", cur_flag, GetLastError());
2121 
2123  }
2124 
2125  ret = CertCloseStore(hstore, 0);
2126  ok (ret, "CertCloseStore failed at %08x, last error %x\n", cur_flag, GetLastError());
2127 
2128  ret = CertUnregisterSystemStore(WineTestW, cur_flag );
2131  "Unregistering failed at %08x, last error %d\n", cur_flag, GetLastError());
2132  }
2133 
2134 }
static const BYTE bigCert[]
Definition: store.c:48
BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition, PCCERT_CONTEXT *ppStoreContext)
Definition: cert.c:286
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
#define CERT_STORE_OPEN_EXISTING_FLAG
Definition: wincrypt.h:2465
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CERT_STORE_ADD_NEW
Definition: wincrypt.h:2482
BOOL WINAPI CertRegisterSystemStore(const void *pvSystemStore, DWORD dwFlags, PCERT_SYSTEM_STORE_INFO pStoreInfo, void *pvReserved)
Definition: store.c:1393
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
static BYTE cert[]
Definition: msg.c:1437
#define todo_wine_if(is_todo)
Definition: test.h:155
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const BYTE cert2[]
Definition: message.c:844
int ret
PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded)
Definition: cert.c:316
BOOL WINAPI CertUnregisterSystemStore(const void *pvSystemStore, DWORD dwFlags)
Definition: store.c:1416
static const struct @1590 reg_system_store_test_data[]
#define err(...)
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
BOOL todo
Definition: store.c:2064
#define CERT_STORE_PROV_SYSTEM_W
Definition: wincrypt.h:2259
#define ARRAY_SIZE(a)
Definition: main.h:24
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
#define skip(...)
#define win_skip
Definition: test.h:141
BOOL expected
Definition: store.c:2063

Referenced by START_TEST().

◆ testCloseStore()

static void testCloseStore ( void  )
static

Definition at line 2877 of file store.c.

2878 {
2879  const CERT_CONTEXT *cert;
2880  const CRL_CONTEXT *crl;
2881  const CTL_CONTEXT *ctl;
2882  HCERTSTORE store, store2;
2883  BOOL res;
2884 
2886  ok(store != NULL, "CertOpenStore failed\n");
2887 
2889  ok(res, "CertCloseStore failed\n");
2890 
2892  ok(store != NULL, "CertOpenStore failed\n");
2893 
2894  store2 = CertDuplicateStore(store);
2895  ok(store2 != NULL, "CertCloneStore failed\n");
2896  ok(store2 == store, "unexpected store2\n");
2897 
2899  ok(!res && GetLastError() == CRYPT_E_PENDING_CLOSE, "CertCloseStore failed\n");
2900 
2902  ok(res, "CertCloseStore failed\n");
2903 
2905  ok(store != NULL, "CertOpenStore failed\n");
2906 
2908  sizeof(bigCert), CERT_STORE_ADD_ALWAYS, &cert);
2909  ok(res, "CertAddEncodedCertificateToStore failed\n");
2910 
2911  /* There is still a reference from cert */
2913  ok(!res && GetLastError() == CRYPT_E_PENDING_CLOSE, "CertCloseStore failed\n");
2914 
2916  ok(res, "CertFreeCertificateContext failed\n");
2917 
2919  ok(store != NULL, "CertOpenStore failed\n");
2920 
2922  sizeof(signedCRL), CERT_STORE_ADD_ALWAYS, &crl);
2923  ok(res, "CertAddEncodedCRLToStore failed\n");
2924 
2925  /* There is still a reference from CRL */
2927  ok(!res && GetLastError() == CRYPT_E_PENDING_CLOSE, "CertCloseStore failed\n");
2928 
2930  ok(res, "CertFreeCRLContext failed\n");
2931 
2933  ok(store != NULL, "CertOpenStore failed\n");
2934 
2937  ok(res, "CertAddEncodedCTLToStore failed\n");
2938 
2939  /* There is still a reference from CTL */
2941  ok(!res && GetLastError() == CRYPT_E_PENDING_CLOSE, "CertCloseStore returned: %x(%u)\n", res, GetLastError());
2942 
2943  res = CertFreeCTLContext(ctl);
2944  ok(res, "CertFreeCTLContext failed\n");
2945 
2946  /* Add all kinds of contexts, then release external references and make sure that store is properly closed. */
2948  ok(store != NULL, "CertOpenStore failed\n");
2949 
2951  sizeof(bigCert), CERT_STORE_ADD_ALWAYS, &cert);
2952  ok(res, "CertAddEncodedCertificateToStore failed\n");
2953 
2955  sizeof(signedCRL), CERT_STORE_ADD_ALWAYS, &crl);
2956  ok(res, "CertAddEncodedCRLToStore failed\n");
2957 
2960  ok(res, "CertAddEncodedCTLToStore failed\n");
2961 
2964  CertFreeCTLContext(ctl);
2965 
2967  ok(res, "CertCloseStore failed\n");
2968 }
static const BYTE crl[]
Definition: message.c:864
static const BYTE bigCert[]
Definition: store.c:48
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI CertAddEncodedCRLToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCrlEncoded, DWORD cbCrlEncoded, DWORD dwAddDisposition, PCCRL_CONTEXT *ppCrlContext)
Definition: crl.c:129
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
static BYTE cert[]
Definition: msg.c:1437
static const BYTE signedCRL[]
Definition: store.c:83
HCERTSTORE WINAPI CertDuplicateStore(HCERTSTORE hCertStore)
Definition: store.c:1116
static const BYTE signedCTLWithCTLInnerContent[]
Definition: store.c:99
BOOL WINAPI CertAddEncodedCTLToStore(HCERTSTORE hCertStore, DWORD dwMsgAndCertEncodingType, const BYTE *pbCtlEncoded, DWORD cbCtlEncoded, DWORD dwAddDisposition, PCCTL_CONTEXT *ppCtlContext)
Definition: ctl.c:177
#define CRYPT_E_PENDING_CLOSE
Definition: winerror.h:3018
BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
Definition: ctl.c:499
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
GLuint res
Definition: glext.h:9613
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
BOOL WINAPI CertFreeCRLContext(PCCRL_CONTEXT pCrlContext)
Definition: crl.c:386
#define CERT_CLOSE_STORE_CHECK_FLAG
Definition: wincrypt.h:2479

Referenced by START_TEST().

◆ testCollectionStore()

static void testCollectionStore ( void  )
static

Definition at line 622 of file store.c.

623 {
624  HCERTSTORE store1, store2, collection, collection2;
626  BOOL ret;
627  static const WCHAR szPrefix[] = { 'c','e','r',0 };
628  static const WCHAR szDot[] = { '.',0 };
630  HANDLE file;
631 
634 
635  /* Try adding a cert to any empty collection */
639  "Expected E_ACCESSDENIED, got %08x\n", GetLastError());
640 
641  /* Create and add a cert to a memory store */
642  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
646  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
647  /* Add the memory store to the collection, without allowing adding */
648  ret = CertAddStoreToCollection(collection, store1, 0, 0);
649  ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
650  /* Verify the cert is in the collection */
652  ok(context != NULL, "Expected a valid context\n");
653  if (context)
654  {
655  ok(context->hCertStore == collection, "Unexpected store\n");
657  }
658  /* Check that adding to the collection isn't allowed */
662  "Expected E_ACCESSDENIED, got %08x\n", GetLastError());
663 
664  /* Create a new memory store */
665  store2 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
667  /* Try adding a store to a non-collection store */
668  ret = CertAddStoreToCollection(store1, store2,
670  ok(!ret && GetLastError() == E_INVALIDARG,
671  "Expected E_INVALIDARG, got %08x\n", GetLastError());
672  /* Try adding some bogus stores */
673  /* This crashes in Windows
674  ret = pCertAddStoreToCollection(0, store2,
675  CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
676  */
677  /* This "succeeds"... */
680  ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
681  /* while this crashes.
682  ret = pCertAddStoreToCollection(collection, 1,
683  CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
684  */
685 
686  /* Add it to the collection, this time allowing adding */
689  ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
690  /* Check that adding to the collection is allowed */
693  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
694  /* Now check that it was actually added to store2 */
696  ok(context != NULL, "Expected a valid context\n");
697  if (context)
698  {
699  ok(context->hCertStore == store2, "Unexpected store\n");
701  }
702  /* Check that the collection has both bigCert and bigCert2. bigCert comes
703  * first because store1 was added first.
704  */
706  ok(context != NULL, "Expected a valid context\n");
707  if (context)
708  {
709  ok(context->hCertStore == collection, "Unexpected store\n");
710  ok(context->cbCertEncoded == sizeof(bigCert),
711  "Wrong size %d\n", context->cbCertEncoded);
712  ok(!memcmp(context->pbCertEncoded, bigCert, context->cbCertEncoded),
713  "Unexpected cert\n");
715  ok(context != NULL, "Expected a valid context\n");
716  if (context)
717  {
718  ok(context->hCertStore == collection, "Unexpected store\n");
719  ok(context->cbCertEncoded == sizeof(bigCert2),
720  "Wrong size %d\n", context->cbCertEncoded);
721  ok(!memcmp(context->pbCertEncoded, bigCert2,
722  context->cbCertEncoded), "Unexpected cert\n");
724  ok(!context, "Unexpected cert\n");
725  }
726  }
727  /* close store2, and check that the collection is unmodified */
728  CertCloseStore(store2, 0);
730  ok(context != NULL, "Expected a valid context\n");
731  if (context)
732  {
733  ok(context->hCertStore == collection, "Unexpected store\n");
734  ok(context->cbCertEncoded == sizeof(bigCert),
735  "Wrong size %d\n", context->cbCertEncoded);
736  ok(!memcmp(context->pbCertEncoded, bigCert, context->cbCertEncoded),
737  "Unexpected cert\n");
739  ok(context != NULL, "Expected a valid context\n");
740  if (context)
741  {
742  ok(context->hCertStore == collection, "Unexpected store\n");
743  ok(context->cbCertEncoded == sizeof(bigCert2),
744  "Wrong size %d\n", context->cbCertEncoded);
745  ok(!memcmp(context->pbCertEncoded, bigCert2,
746  context->cbCertEncoded), "Unexpected cert\n");
748  ok(!context, "Unexpected cert\n");
749  }
750  }
751 
752  /* Adding a collection to a collection is legal */
753  collection2 = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
755  ret = CertAddStoreToCollection(collection2, collection,
757  ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
758  /* check the contents of collection2 */
759  context = CertEnumCertificatesInStore(collection2, NULL);
760  ok(context != NULL, "Expected a valid context\n");
761  if (context)
762  {
763  ok(context->hCertStore == collection2, "Unexpected store\n");
764  ok(context->cbCertEncoded == sizeof(bigCert),
765  "Wrong size %d\n", context->cbCertEncoded);
766  ok(!memcmp(context->pbCertEncoded, bigCert, context->cbCertEncoded),
767  "Unexpected cert\n");
769  ok(context != NULL, "Expected a valid context\n");
770  if (context)
771  {
772  ok(context->hCertStore == collection2, "Unexpected store\n");
773  ok(context->cbCertEncoded == sizeof(bigCert2),
774  "Wrong size %d\n", context->cbCertEncoded);
775  ok(!memcmp(context->pbCertEncoded, bigCert2,
776  context->cbCertEncoded), "Unexpected cert\n");
778  ok(!context, "Unexpected cert\n");
779  }
780  }
781 
782  /* I'd like to test closing the collection in the middle of enumeration,
783  * but my tests have been inconsistent. The first time calling
784  * CertEnumCertificatesInStore on a closed collection succeeded, while the
785  * second crashed. So anything appears to be fair game.
786  * I'd also like to test removing a store from a collection in the middle
787  * of an enumeration, but my tests in Windows have been inconclusive.
788  * In one scenario it worked. In another scenario, about a third of the
789  * time this leads to "random" crashes elsewhere in the code. This
790  * probably means this is not allowed.
791  */
792 
793  CertCloseStore(store1, 0);
795  CertCloseStore(collection2, 0);
796 
797  /* Add the same cert to two memory stores, then put them in a collection */
798  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
800  ok(store1 != 0, "CertOpenStore failed: %08x\n", GetLastError());
801  store2 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
803  ok(store2 != 0, "CertOpenStore failed: %08x\n", GetLastError());
804 
807  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
810  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
813  ok(collection != 0, "CertOpenStore failed: %08x\n", GetLastError());
814 
816  ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
818  ok(ret, "CertAddStoreToCollection failed: %08x\n", GetLastError());
819 
820  /* Check that the collection has two copies of the same cert */
822  ok(context != NULL, "Expected a valid context\n");
823  if (context)
824  {
825  ok(context->hCertStore == collection, "Unexpected store\n");
826  ok(context->cbCertEncoded == sizeof(bigCert),
827  "Wrong size %d\n", context->cbCertEncoded);
828  ok(!memcmp(context->pbCertEncoded, bigCert, context->cbCertEncoded),
829  "Unexpected cert\n");
831  ok(context != NULL, "Expected a valid context\n");
832  if (context)
833  {
834  ok(context->hCertStore == collection, "Unexpected store\n");
835  ok(context->cbCertEncoded == sizeof(bigCert),
836  "Wrong size %d\n", context->cbCertEncoded);
837  ok(!memcmp(context->pbCertEncoded, bigCert, context->cbCertEncoded),
838  "Unexpected cert\n");
840  ok(context == NULL, "Unexpected cert\n");
841  }
842  }
843 
844  /* The following would check whether I can delete an identical cert, rather
845  * than one enumerated from the store. It crashes, so that means I must
846  * only call CertDeleteCertificateFromStore with contexts enumerated from
847  * the store.
848  context = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert,
849  sizeof(bigCert));
850  ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
851  GetLastError());
852  if (context)
853  {
854  ret = CertDeleteCertificateFromStore(collection, context);
855  printf("ret is %d, GetLastError is %08x\n", ret, GetLastError());
856  CertFreeCertificateContext(context);
857  }
858  */
859 
860  /* Now check deleting from the collection. */
862  ok(context != NULL, "Expected a valid context\n");
863  if (context)
864  {
866  /* store1 should now be empty */
868  ok(!context, "Unexpected cert\n");
869  /* and there should be one certificate in the collection */
871  ok(context != NULL, "Expected a valid cert\n");
872  if (context)
873  {
874  ok(context->hCertStore == collection, "Unexpected store\n");
875  ok(context->cbCertEncoded == sizeof(bigCert),
876  "Wrong size %d\n", context->cbCertEncoded);
877  ok(!memcmp(context->pbCertEncoded, bigCert, context->cbCertEncoded),
878  "Unexpected cert\n");
879  }
881  ok(context == NULL, "Unexpected cert\n");
882  }
883 
884  /* Finally, test removing stores from the collection. No return
885  * value, so it's a bit funny to test.
886  */
887  /* This crashes
888  * CertRemoveStoreFromCollection(NULL, NULL);
889  */
890  /* This "succeeds," no crash, no last error set */
891  SetLastError(0xdeadbeef);
893  ok(GetLastError() == 0xdeadbeef,
894  "Didn't expect an error to be set: %08x\n", GetLastError());
895 
896  /* After removing store2, the collection should be empty */
897  SetLastError(0xdeadbeef);
899  ok(GetLastError() == 0xdeadbeef,
900  "Didn't expect an error to be set: %08x\n", GetLastError());
902  ok(!context, "Unexpected cert\n");
903 
905  CertCloseStore(store2, 0);
906  CertCloseStore(store1, 0);
907 
908  /* Test adding certificates to and deleting certificates from collections.
909  */
910  store1 = CertOpenSystemStoreA(0, "My");
913 
916  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
918 
920 
923  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
925 
927  CertCloseStore(store1, 0);
928 
929  /* Test whether a collection store can be committed */
932 
933  SetLastError(0xdeadbeef);
935  ok(ret, "CertControlStore failed: %08x\n", GetLastError());
936 
937  /* Adding a mem store that can't be committed prevents a successful commit.
938  */
939  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
941  CertAddStoreToCollection(collection, store1, 0, 0);
942  SetLastError(0xdeadbeef);
945  "expected ERROR_CALL_NOT_IMPLEMENTED, got %d\n", GetLastError());
947  CertCloseStore(store1, 0);
948 
949  /* Test adding a cert to a collection with a file store, committing the
950  * change to the collection, and comparing the resulting file.
951  */
952  if (!GetTempFileNameW(szDot, szPrefix, 0, filename))
953  return;
954 
958  if (file == INVALID_HANDLE_VALUE)
959  return;
960 
961  store1 = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
963  ok(store1 != NULL, "CertOpenStore failed: %08x\n", GetLastError());
964  CloseHandle(file);
966  CertCloseStore(store1, 0);
967 
970  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
971  GetLastError());
973  ok(ret, "CertControlStore failed: %d\n", ret);
974  compareStore(collection, "serialized store with cert",
977 
979 }
#define E_ACCESSDENIED
Definition: winerror.h:2849
#define CloseHandle
Definition: compat.h:398
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static const BYTE bigCert[]
Definition: store.c:48
Definition: http.c:6587
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI CertAddStoreToCollection(HCERTSTORE hCollectionStore, HCERTSTORE hSiblingStore, DWORD dwUpdateFlags, DWORD dwPriority)
const char * filename
Definition: ioapi.h:135
#define CERT_STORE_CTRL_COMMIT
Definition: wincrypt.h:2822
#define CERT_STORE_PROV_COLLECTION
Definition: wincrypt.h:2261
#define CERT_FILE_STORE_COMMIT_ENABLE_FLAG
Definition: wincrypt.h:2475
static void compareStore(HCERTSTORE store, LPCSTR name, const BYTE *pb, DWORD cb, BOOL todo)
Definition: store.c:304
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
#define E_INVALIDARG
Definition: ddrawi.h:101
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
BOOL WINAPI CertControlStore(HCERTSTORE hCertStore, DWORD dwFlags, DWORD dwCtrlType, void const *pvCtrlPara)
Definition: store.c:1149
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
const char file[]
Definition: icontest.c:11
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
#define SetLastError(x)
Definition: compat.h:409
void WINAPI CertRemoveStoreFromCollection(HCERTSTORE hCollectionStore, HCERTSTORE hSiblingStore)
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR szDot[]
Definition: msipriv.h:1113
HCERTSTORE WINAPI CertOpenSystemStoreA(HCRYPTPROV_LEGACY hProv, LPCSTR szSubSystemProtocol)
Definition: store.c:904
static const BYTE bigCert2[]
Definition: store.c:89
#define GENERIC_READ
Definition: compat.h:124
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
#define CREATE_ALWAYS
Definition: disk.h:72
static ICollection collection
Definition: typelib.c:184
#define CERT_STORE_PROV_FILE
Definition: wincrypt.h:2252
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
#define CreateFileW
Definition: compat.h:400
static const BYTE serializedStoreWithCert[]
Definition: store.c:328
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG
Definition: wincrypt.h:2580
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
Definition: fci.c:126

Referenced by START_TEST().

◆ testEmptyStore()

static void testEmptyStore ( void  )
static

Definition at line 2801 of file store.c.

2802 {
2803  const CERT_CONTEXT *cert, *cert2, *cert3;
2804  const CRL_CONTEXT *crl;
2805  const CTL_CONTEXT *ctl;
2806  HCERTSTORE store;
2807  BOOL res;
2808 
2810  ok(cert != NULL, "CertCreateCertificateContext failed\n");
2811  ok(cert->hCertStore != NULL, "cert->hCertStore == NULL\n");
2812  if(!cert->hCertStore) {
2814  return;
2815  }
2816 
2817  test_store_is_empty(cert->hCertStore);
2818 
2820  ok(cert2 != NULL, "CertCreateCertificateContext failed\n");
2821  ok(cert2->hCertStore == cert->hCertStore, "Unexpected hCertStore\n");
2822 
2823  test_store_is_empty(cert2->hCertStore);
2824 
2826  ok(res, "CertAddCertificateContextToStore failed\n");
2827  todo_wine
2828  ok(cert3 && cert3 != cert2, "Unexpected cert3\n");
2829  ok(cert3->hCertStore == cert->hCertStore, "Unexpected hCertStore\n");
2830 
2831  test_store_is_empty(cert->hCertStore);
2832 
2834  ok(res, "CertDeleteCertificateContextFromStore failed\n");
2835  ok(cert3->hCertStore == cert->hCertStore, "Unexpected hCertStore\n");
2836 
2838 
2840  ok(store != NULL, "CertOpenStore failed\n");
2841 
2843  ok(res, "CertAddCertificateContextToStore failed\n");
2844  ok(cert3 && cert3 != cert2, "Unexpected cert3\n");
2845  ok(cert3->hCertStore == store, "Unexpected hCertStore\n");
2846 
2848  ok(res, "CertDeleteCertificateContextFromStore failed\n");
2849  ok(cert3->hCertStore == store, "Unexpected hCertStore\n");
2850 
2851  CertCloseStore(store, 0);
2853 
2855  ok(!res && GetLastError() == E_UNEXPECTED, "CertCloseStore returned: %x(%x)\n", res, GetLastError());
2856 
2857  res = CertCloseStore(cert->hCertStore, 0);
2858  ok(!res && GetLastError() == E_UNEXPECTED, "CertCloseStore returned: %x(%x)\n", res, GetLastError());
2859 
2861 
2863  ok(crl != NULL, "CertCreateCRLContext failed\n");
2864  ok(crl->hCertStore == cert->hCertStore, "unexpected hCertStore\n");
2865 
2867 
2869  ok(ctl != NULL, "CertCreateCTLContext failed\n");
2870  ok(ctl->hCertStore == cert->hCertStore, "unexpected hCertStore\n");
2871 
2872  CertFreeCTLContext(ctl);
2873 
2875 }
static const BYTE crl[]
Definition: message.c:864
static const BYTE bigCert[]
Definition: store.c:48
BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition, PCCERT_CONTEXT *ppStoreContext)
Definition: cert.c:286
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
#define test_store_is_empty(store)
Definition: store.c:120
HCERTSTORE hCertStore
Definition: wincrypt.h:483
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CERT_STORE_ADD_NEW
Definition: wincrypt.h:2482
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
PCCTL_CONTEXT WINAPI CertCreateCTLContext(DWORD dwMsgAndCertEncodingType, const BYTE *pbCtlEncoded, DWORD cbCtlEncoded)
Definition: ctl.c:363
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
static BYTE cert[]
Definition: msg.c:1437
static const BYTE signedCRL[]
Definition: store.c:83
static const BYTE signedCTLWithCTLInnerContent[]
Definition: store.c:99
PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType, const BYTE *pbCrlEncoded, DWORD cbCrlEncoded)
Definition: crl.c:85
static const BYTE cert2[]
Definition: message.c:844
HCERTSTORE hCertStore
Definition: wincrypt.h:748
#define todo_wine
Definition: test.h:154
PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded)
Definition: cert.c:316
static const BYTE bigCert2[]
Definition: store.c:89
BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
Definition: ctl.c:499
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
#define E_UNEXPECTED
Definition: winerror.h:2456
GLuint res
Definition: glext.h:9613
BOOL WINAPI CertFreeCRLContext(PCCRL_CONTEXT pCrlContext)
Definition: crl.c:386
#define CERT_CLOSE_STORE_CHECK_FLAG
Definition: wincrypt.h:2479

Referenced by START_TEST().

◆ testFileNameStore()

static void testFileNameStore ( void  )
static

Definition at line 1646 of file store.c.

1647 {
1648  static const WCHAR szPrefix[] = { 'c','e','r',0 };
1649  static const WCHAR spcPrefix[] = { 's','p','c',0 };
1650  static const WCHAR szDot[] = { '.',0 };
1652  HCERTSTORE store;
1653  BOOL ret;
1654  DWORD GLE;
1655 
1656  store = CertOpenStore(CERT_STORE_PROV_FILENAME_W, 0, 0, 0, NULL);
1657  GLE = GetLastError();
1658  ok(!store && (GLE == ERROR_PATH_NOT_FOUND || GLE == ERROR_INVALID_PARAMETER),
1659  "Expected ERROR_PATH_NOT_FOUND or ERROR_INVALID_PARAMETER, got %08x\n",
1660  GLE);
1661 
1662  if (!GetTempFileNameW(szDot, szPrefix, 0, filename))
1663  return;
1665 
1666  /* The two flags are mutually exclusive */
1669  ok(!store && GetLastError() == E_INVALIDARG,
1670  "Expected E_INVALIDARG, got %08x\n", GetLastError());
1671 
1672  /* In all of the following tests, the encoding type seems to be ignored */
1673  if (initFileFromData(filename, bigCert, sizeof(bigCert)))
1674  {
1677 
1680  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1681 
1683  ok(cert != NULL, "CertEnumCertificatesInStore failed: %08x\n",
1684  GetLastError());
1686  ok(!cert, "Expected only one cert\n");
1687  crl = CertEnumCRLsInStore(store, NULL);
1688  ok(!crl, "Expected no CRLs\n");
1689 
1690  CertCloseStore(store, 0);
1692  }
1694  sizeof(serializedStoreWithCert)))
1695  {
1698 
1701  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1702 
1704  ok(cert != NULL, "CertEnumCertificatesInStore failed: %08x\n",
1705  GetLastError());
1707  ok(!cert, "Expected only one cert\n");
1708  crl = CertEnumCRLsInStore(store, NULL);
1709  ok(!crl, "Expected no CRLs\n");
1710 
1711  CertCloseStore(store, 0);
1713  }
1716  {
1719 
1722  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1723 
1725  ok(cert != NULL, "CertEnumCertificatesInStore failed: %08x\n",
1726  GetLastError());
1728  ok(!cert, "Expected only one cert\n");
1729  crl = CertEnumCRLsInStore(store, NULL);
1730  ok(crl != NULL, "CertEnumCRLsInStore failed: %08x\n", GetLastError());
1731  crl = CertEnumCRLsInStore(store, crl);
1732  ok(!crl, "Expected only one CRL\n");
1733 
1734  CertCloseStore(store, 0);
1735  /* Don't delete it this time, the next test uses it */
1736  }
1737  /* Now that the file exists, we can open it read-only */
1740  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1741  CertCloseStore(store, 0);
1743 
1746  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1747  if (store)
1748  {
1751  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1752  GetLastError());
1753  compareStore(store, "serialized store with cert",
1755  CertCloseStore(store, 0);
1756  }
1759  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1760  if (store)
1761  {
1764  ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError());
1765  compareStore(store, "serialized store with cert and CRL",
1767  FALSE);
1768  CertCloseStore(store, 0);
1769  }
1771 
1772  if (!GetTempFileNameW(szDot, spcPrefix, 0, filename))
1773  return;
1775 
1777  {
1780 
1783  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1784 
1786  ok(cert != NULL, "CertEnumCertificatesInStore failed: %08x\n",
1787  GetLastError());
1789  ok(!cert, "Expected only one cert\n");
1790  crl = CertEnumCRLsInStore(store, NULL);
1791  ok(!crl, "Expected no CRLs\n");
1792 
1793  CertCloseStore(store, 0);
1795  }
1797  sizeof(utf16Base64SPC)))
1798  {
1801 
1804  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1805 
1807  ok(cert != NULL, "CertEnumCertificatesInStore failed: %08x\n",
1808  GetLastError());
1810  ok(!cert, "Expected only one cert\n");
1811  crl = CertEnumCRLsInStore(store, NULL);
1812  ok(!crl, "Expected no CRLs\n");
1813 
1814  CertCloseStore(store, 0);
1816  }
1817 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
static const BYTE crl[]
Definition: message.c:864
static const BYTE serializedStoreWithCertAndCRL[]
Definition: store.c:1422
PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(HCERTSTORE hCertStore, PCCRL_CONTEXT pPrev)
Definition: store.c:1101
static const BYTE bigCert[]
Definition: store.c:48
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
const char * filename
Definition: ioapi.h:135
#define CERT_STORE_PROV_FILENAME_W
Definition: wincrypt.h:2257
BOOL WINAPI CertAddEncodedCRLToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCrlEncoded, DWORD cbCrlEncoded, DWORD dwAddDisposition, PCCRL_CONTEXT *ppCrlContext)
Definition: crl.c:129
#define CERT_FILE_STORE_COMMIT_ENABLE_FLAG
Definition: wincrypt.h:2475
static void compareStore(HCERTSTORE store, LPCSTR name, const BYTE *pb, DWORD cb, BOOL todo)
Definition: store.c:304
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
static BYTE cert[]
Definition: msg.c:1437
static const BYTE signedCRL[]
Definition: store.c:83
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CERT_STORE_READONLY_FLAG
Definition: wincrypt.h:2466
static const BYTE base64SPC[]
Definition: store.c:1586
int ret
static const WCHAR szDot[]
Definition: msipriv.h:1113
unsigned char BYTE
Definition: mem.h:68
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
static BOOL initFileFromData(LPCWSTR filename, const BYTE *pb, DWORD cb)
Definition: store.c:1568
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
static const BYTE serializedStoreWithCert[]
Definition: store.c:328
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
static const WCHAR utf16Base64SPC[]
Definition: store.c:1600
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
static DWORD GLE
Definition: registry.c:38

Referenced by START_TEST().

◆ testFileStore()

static void testFileStore ( void  )
static

Definition at line 1440 of file store.c.

1441 {
1442  static const WCHAR szPrefix[] = { 'c','e','r',0 };
1443  static const WCHAR szDot[] = { '.',0 };
1445  HCERTSTORE store;
1446  BOOL ret;
1448  HANDLE file;
1449 
1450  store = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0, 0, NULL);
1451  ok(!store && GetLastError() == ERROR_INVALID_HANDLE,
1452  "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1453 
1454  if (!GetTempFileNameW(szDot, szPrefix, 0, filename))
1455  return;
1456 
1460  if (file == INVALID_HANDLE_VALUE)
1461  return;
1462 
1464  file);
1465  ok(!store && GetLastError() == E_INVALIDARG,
1466  "Expected E_INVALIDARG, got %08x\n", GetLastError());
1467  store = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
1469  ok(!store && GetLastError() == E_INVALIDARG,
1470  "Expected E_INVALIDARG, got %08x\n", GetLastError());
1471 
1472  /* A "read-only" file store.. */
1473  store = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
1475  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1476  if (store)
1477  {
1478  DWORD size;
1479 
1482  /* apparently allows adding certificates.. */
1483  ok(ret, "CertAddEncodedCertificateToStore failed: %d\n", ret);
1484  /* but not commits.. */
1487  "Expected ERROR_CALL_NOT_IMPLEMENTED, got %08x\n", GetLastError());
1488  /* It still has certs in memory.. */
1490  ok(cert != NULL, "CertEnumCertificatesInStore failed: %08x\n",
1491  GetLastError());
1493  /* but the file size is still 0. */
1494  size = GetFileSize(file, NULL);
1495  ok(size == 0, "Expected size 0, got %d\n", size);
1496  CertCloseStore(store, 0);
1497  }
1498 
1499  /* The create new flag is allowed.. */
1500  store = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
1502  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1503  if (store)
1504  {
1505  /* but without the commit enable flag, commits don't happen. */
1508  ok(ret, "CertAddEncodedCertificateToStore failed: %d\n", ret);
1511  "Expected ERROR_CALL_NOT_IMPLEMENTED, got %08x\n", GetLastError());
1512  CertCloseStore(store, 0);
1513  }
1514  /* as is the open existing flag. */
1515  store = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
1517  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1518  if (store)
1519  {
1520  /* but without the commit enable flag, commits don't happen. */
1523  ok(ret, "CertAddEncodedCertificateToStore failed: %d\n", ret);
1526  "Expected ERROR_CALL_NOT_IMPLEMENTED, got %08x\n", GetLastError());
1527  CertCloseStore(store, 0);
1528  }
1529  store = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
1531  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1532  if (store)
1533  {
1534  CloseHandle(file);
1537  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1538  GetLastError());
1539  /* with commits enabled, commit is allowed */
1541  ok(ret, "CertControlStore failed: %d\n", ret);
1542  compareStore(store, "serialized store with cert",
1544  CertCloseStore(store, 0);
1545  }
1548  if (file == INVALID_HANDLE_VALUE)
1549  return;
1550  store = CertOpenStore(CERT_STORE_PROV_FILE, 0, 0,
1552  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1553  if (store)
1554  {
1555  CloseHandle(file);
1558  ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError());
1559  compareStore(store, "serialized store with cert and CRL",
1561  FALSE);
1562  CertCloseStore(store, 0);
1563  }
1564 
1566 }
#define CERT_STORE_DELETE_FLAG
Definition: wincrypt.h:2455
#define CloseHandle
Definition: compat.h:398
static const BYTE serializedStoreWithCertAndCRL[]
Definition: store.c:1422
static const BYTE bigCert[]
Definition: store.c:48
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
#define CERT_STORE_OPEN_EXISTING_FLAG
Definition: wincrypt.h:2465
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
const char * filename
Definition: ioapi.h:135
#define CERT_STORE_CTRL_COMMIT
Definition: wincrypt.h:2822
BOOL WINAPI CertAddEncodedCRLToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCrlEncoded, DWORD cbCrlEncoded, DWORD dwAddDisposition, PCCRL_CONTEXT *ppCrlContext)
Definition: crl.c:129
#define CERT_FILE_STORE_COMMIT_ENABLE_FLAG
Definition: wincrypt.h:2475
static void compareStore(HCERTSTORE store, LPCSTR name, const BYTE *pb, DWORD cb, BOOL todo)
Definition: store.c:304
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
BOOL WINAPI CertControlStore(HCERTSTORE hCertStore, DWORD dwFlags, DWORD dwCtrlType, void const *pvCtrlPara)
Definition: store.c:1149
static BYTE cert[]
Definition: msg.c:1437
static const BYTE signedCRL[]
Definition: store.c:83
#define OPEN_EXISTING
Definition: compat.h:426
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
const char file[]
Definition: icontest.c:11
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define CERT_STORE_READONLY_FLAG
Definition: wincrypt.h:2466
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR szDot[]
Definition: msipriv.h:1113
#define GENERIC_READ
Definition: compat.h:124
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
#define CREATE_ALWAYS
Definition: disk.h:72
#define CERT_STORE_PROV_FILE
Definition: wincrypt.h:2252
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
#define CreateFileW
Definition: compat.h:400
static const BYTE serializedStoreWithCert[]
Definition: store.c:328
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
Definition: fci.c:126

Referenced by START_TEST().

◆ testMemStore()

static void testMemStore ( void  )
static

Definition at line 129 of file store.c.

130 {
131  HCERTSTORE store1, store2;
133  BOOL ret;
134  DWORD GLE;
135 
136  /* NULL provider */
137  store1 = CertOpenStore(0, 0, 0, 0, NULL);
138  ok(!store1 && GetLastError() == ERROR_FILE_NOT_FOUND,
139  "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
140  /* weird flags */
141  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
144  "Expected ERROR_CALL_NOT_IMPLEMENTED, got %d\n", GetLastError());
145 
146  /* normal */
147  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
149  ok(store1 != NULL, "CertOpenStore failed: %d\n", GetLastError());
150  /* open existing doesn't */
151  store2 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
153  ok(store2 != NULL, "CertOpenStore failed: %d\n", GetLastError());
154  ok(store1 != store2, "Expected different stores\n");
155 
156  /* add a bogus (empty) cert */
157  context = NULL;
160  /* Windows returns CRYPT_E_ASN1_EOD or OSS_DATA_ERROR, but accept
161  * CRYPT_E_ASN1_CORRUPT as well (because matching errors is tough in this
162  * case)
163  */
164  GLE = GetLastError();
166  GLE == OSS_DATA_ERROR),
167  "Expected CRYPT_E_ASN1_EOD or CRYPT_E_ASN1_CORRUPT or OSS_DATA_ERROR, got %08x\n",
168  GLE);
169  /* add a "signed" cert--the signature isn't a real signature, so this adds
170  * without any check of the signature's validity
171  */
174  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
175  ok(context != NULL, "Expected a valid cert context\n");
176  if (context)
177  {
178  ok(context->cbCertEncoded == sizeof(signedBigCert),
179  "Wrong cert size %d\n", context->cbCertEncoded);
180  ok(!memcmp(context->pbCertEncoded, signedBigCert,
181  sizeof(signedBigCert)), "Unexpected encoded cert in context\n");
182  /* remove it, the rest of the tests will work on an unsigned cert */
184  ok(ret, "CertDeleteCertificateFromStore failed: %08x\n",
185  GetLastError());
186  }
187  /* try adding a "signed" CRL as a cert */
190  GLE = GetLastError();
192  GLE == OSS_DATA_ERROR),
193  "Expected CRYPT_E_ASN1_BADTAG or CRYPT_E_ASN1_CORRUPT or OSS_DATA_ERROR, got %08x\n",
194  GLE);
195  /* add a cert to store1 */
198  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
199  ok(context != NULL, "Expected a valid cert context\n");
200  if (context)
201  {
202  DWORD size;
203  BYTE *buf;
204 
205  ok(context->cbCertEncoded == sizeof(bigCert),
206  "Wrong cert size %d\n", context->cbCertEncoded);
207  ok(!memcmp(context->pbCertEncoded, bigCert, sizeof(bigCert)),
208  "Unexpected encoded cert in context\n");
209  ok(context->hCertStore == store1, "Unexpected store\n");
210 
211  /* check serializing this element */
212  /* These crash
213  ret = CertSerializeCertificateStoreElement(NULL, 0, NULL, NULL);
214  ret = CertSerializeCertificateStoreElement(context, 0, NULL, NULL);
215  ret = CertSerializeCertificateStoreElement(NULL, 0, NULL, &size);
216  */
217  /* apparently flags are ignored */
219  ok(ret, "CertSerializeCertificateStoreElement failed: %08x\n",
220  GetLastError());
221  buf = HeapAlloc(GetProcessHeap(), 0, size);
222  if (buf)
223  {
225  ok(ret, "CertSerializeCertificateStoreElement failed: %08x\n", GetLastError());
226  ok(size == sizeof(serializedCert), "Wrong size %d\n", size);
228  "Unexpected serialized cert\n");
229  HeapFree(GetProcessHeap(), 0, buf);
230  }
231 
233  ok(ret, "CertFreeCertificateContext failed: %08x\n", GetLastError());
234  }
235  /* verify the cert's in store1 */
237  ok(context != NULL, "Expected a valid context\n");
240  "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
241  /* verify store2 (the "open existing" mem store) is still empty */
243  ok(!context, "Expected an empty store\n");
244  /* delete the cert from store1, and check it's empty */
246  if (context)
247  {
248  /* Deleting a bitwise copy crashes with an access to an uninitialized
249  * pointer, so a cert context has some special data out there in memory
250  * someplace
251  CERT_CONTEXT copy;
252  memcpy(&copy, context, sizeof(copy));
253  ret = CertDeleteCertificateFromStore(&copy);
254  */
256 
257  ok(copy != NULL, "CertDuplicateCertificateContext failed: %08x\n",
258  GetLastError());
260  ok(ret, "CertDeleteCertificateFromStore failed: %08x\n",
261  GetLastError());
262  /* try deleting a copy */
264  ok(ret, "CertDeleteCertificateFromStore failed: %08x\n",
265  GetLastError());
266  /* check that the store is empty */
268  ok(!context, "Expected an empty store\n");
269  }
270 
271  /* close an empty store */
272  ret = CertCloseStore(NULL, 0);
273  ok(ret, "CertCloseStore failed: %d\n", GetLastError());
274  ret = CertCloseStore(store1, 0);
275  ok(ret, "CertCloseStore failed: %d\n", GetLastError());
276  ret = CertCloseStore(store2, 0);
277  ok(ret, "CertCloseStore failed: %d\n", GetLastError());
278 
279  /* This seems nonsensical, but you can open a read-only mem store, only
280  * it isn't read-only
281  */
282  store1 = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
284  ok(store1 != NULL, "CertOpenStore failed: %d\n", GetLastError());
285  /* yep, this succeeds */
288  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
289  ok(context != NULL, "Expected a valid cert context\n");
290  if (context)
291  {
292  ok(context->cbCertEncoded == sizeof(bigCert),
293  "Wrong cert size %d\n", context->cbCertEncoded);
294  ok(!memcmp(context->pbCertEncoded, bigCert, sizeof(bigCert)),
295  "Unexpected encoded cert in context\n");
296  ok(context->hCertStore == store1, "Unexpected store\n");
298  ok(ret, "CertDeleteCertificateFromStore failed: %08x\n",
299  GetLastError());
300  }
301  CertCloseStore(store1, 0);
302 }
#define CERT_STORE_DELETE_FLAG
Definition: wincrypt.h:2455
#define CRYPT_E_ASN1_BADTAG
Definition: winerror.h:3095
static const BYTE signedBigCert[]
Definition: store.c:58
#define CRYPT_E_ASN1_CORRUPT
Definition: winerror.h:3087
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define CRYPT_E_NOT_FOUND
Definition: winerror.h:3007
static const BYTE bigCert[]
Definition: store.c:48
Definition: http.c:6587
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
#define CERT_STORE_OPEN_EXISTING_FLAG
Definition: wincrypt.h:2465
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2464
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
#define CERT_STORE_PROV_MEMORY
Definition: wincrypt.h:2251
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static const BYTE signedCRL[]
Definition: store.c:83
static const BYTE serializedCert[]
Definition: store.c:71
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CRYPT_E_ASN1_EOD
Definition: winerror.h:3086
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CERT_STORE_READONLY_FLAG
Definition: wincrypt.h:2466
int ret
#define OSS_DATA_ERROR
Definition: winerror.h:3042
static const BYTE emptyCert[]
Definition: store.c:47
unsigned char BYTE
Definition: mem.h:68
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:360
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
BOOL WINAPI CertSerializeCertificateStoreElement(PCCERT_CONTEXT pCertContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:144
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define HeapFree(x, y, z)
Definition: compat.h:394
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
static DWORD GLE
Definition: registry.c:38

Referenced by START_TEST().

◆ testMessageStore()

static void testMessageStore ( void  )
static

Definition at line 1869 of file store.c.

1870 {
1871  HCERTSTORE store;
1873  NULL);
1876  DWORD count, size;
1877  BOOL ret;
1878 
1879  /* Crashes
1880  store = CertOpenStore(CERT_STORE_PROV_MSG, 0, 0, 0, NULL);
1881  */
1882  SetLastError(0xdeadbeef);
1883  store = CertOpenStore(CERT_STORE_PROV_MSG, 0, 0, 0, msg);
1884  ok(!store && GetLastError() == CRYPT_E_INVALID_MSG_TYPE,
1885  "Expected CRYPT_E_INVALID_MSG_TYPE, got %08x\n", GetLastError());
1887  store = CertOpenStore(CERT_STORE_PROV_MSG, 0, 0, 0, msg);
1888  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1889  if (store)
1890  {
1893 
1894  count = 0;
1895  do {
1897  if (cert)
1898  count++;
1899  } while (cert);
1900  ok(count == 0, "Expected 0 certificates, got %d\n", count);
1901 
1902  count = 0;
1903  do {
1904  crl = CertEnumCRLsInStore(store, crl);
1905  if (crl)
1906  count++;
1907  } while (crl);
1908  ok(count == 0, "Expected 0 CRLs, got %d\n", count);
1909 
1910  /* Can add certs to a message store */
1913  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1914  GetLastError());
1915  count = 0;
1916  do {
1918  if (cert)
1919  count++;
1920  } while (cert);
1921  ok(count == 1, "Expected 1 certificate, got %d\n", count);
1922 
1923  CertCloseStore(store, 0);
1924  }
1925  /* but the added certs weren't actually added to the message */
1926  size = sizeof(count);
1928  ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
1929  ok(count == 0, "Expected 0 certificates, got %d\n", count);
1930  CryptMsgClose(msg);
1931 
1932  /* Crashes
1933  store = CertOpenStore(CERT_STORE_PROV_PKCS7, 0, 0, 0, NULL);
1934  */
1935  store = CertOpenStore(CERT_STORE_PROV_PKCS7, 0, 0, 0, &blob);
1936  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1937  if (store)
1938  {
1939  DWORD count = 0;
1942 
1943  do {
1945  if (cert)
1946  count++;
1947  } while (cert);
1948  ok(count == 1, "Expected 1 certificate, got %d\n", count);
1949 
1950  count = 0;
1951  do {
1952  crl = CertEnumCRLsInStore(store, crl);
1953  if (crl)
1954  count++;
1955  } while (crl);
1956  ok(count == 1, "Expected 1 CRL, got %d\n", count);
1957 
1958  CertCloseStore(store, 0);
1959  }
1960  /* Encoding appears to be ignored */
1962  &blob);
1963  ok(store != NULL, "CertOpenStore failed: %08x\n", GetLastError());
1964  if (store)
1965  CertCloseStore(store, 0);
1966  /* Messages other than signed messages aren't allowed */
1967  blob.cbData = sizeof(hashContent);
1968  blob.pbData = (LPBYTE)hashContent;
1969  SetLastError(0xdeadbeef);
1970  store = CertOpenStore(CERT_STORE_PROV_PKCS7, 0, 0, 0, &blob);
1971  ok(!store && GetLastError() == CRYPT_E_INVALID_MSG_TYPE,
1972  "Expected CRYPT_E_INVALID_MSG_TYPE, got %08x\n", GetLastError());
1973  blob.cbData = sizeof(hashBareContent);
1974  blob.pbData = (LPBYTE)hashBareContent;
1975  SetLastError(0xdeadbeef);
1976  store = CertOpenStore(CERT_STORE_PROV_PKCS7, 0, 0, 0, &blob);
1977  ok(!store && GetLastError() == CRYPT_E_ASN1_BADTAG,
1978  "Expected CRYPT_E_ASN1_BADTAG, got %08x\n", GetLastError());
1979 }
#define CRYPT_E_ASN1_BADTAG
Definition: winerror.h:3095
#define TRUE
Definition: types.h:120
static const BYTE crl[]
Definition: message.c:864
PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(HCERTSTORE hCertStore, PCCRL_CONTEXT pPrev)
Definition: store.c:1101
Definition: image.c:133
static const BYTE bigCert[]
Definition: store.c:48
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define CERT_STORE_PROV_MSG
Definition: wincrypt.h:2250
static const BYTE hashBareContent[]
Definition: store.c:1863
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2299
HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags, DWORD dwMsgType, HCRYPTPROV_LEGACY hCryptProv, PCERT_INFO pRecipientInfo, PCMSG_STREAM_INFO pStreamInfo)
Definition: msg.c:3553
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
#define CRYPT_E_INVALID_MSG_TYPE
Definition: winerror.h:2988
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
static BYTE cert[]
Definition: msg.c:1437
GLsizeiptr size
Definition: glext.h:5919
static const BYTE signedWithCertAndCrlBareContent[]
Definition: store.c:1833
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define CMSG_CERT_COUNT_PARAM
Definition: wincrypt.h:3935
int ret
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
#define CERT_STORE_PROV_PKCS7
Definition: wincrypt.h:2254
static const BYTE hashContent[]
Definition: store.c:1857
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
BOOL WINAPI CryptMsgClose(HCRYPTMSG hCryptMsg)
Definition: msg.c:3598
#define msg(x)
Definition: auth_time.c:54
BOOL WINAPI CryptMsgUpdate(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal)
Definition: msg.c:3617
BOOL WINAPI CryptMsgGetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:3627
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
static const BYTE signedContent[]
Definition: store.c:1819

Referenced by START_TEST().

◆ testRegStore()

static void testRegStore ( void  )
static

Definition at line 1015 of file store.c.

1016 {
1017  static const char tempKey[] = "Software\\Wine\\CryptTemp";
1018  HCERTSTORE store;
1019  LONG rc;
1020  HKEY key = NULL;
1021  DWORD disp, GLE;
1022 
1023  store = CertOpenStore(CERT_STORE_PROV_REG, 0, 0, 0, NULL);
1024  GLE = GetLastError();
1025  ok(!store && (GLE == ERROR_INVALID_HANDLE || GLE == ERROR_BADKEY),
1026  "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", GLE);
1027  store = CertOpenStore(CERT_STORE_PROV_REG, 0, 0, 0, key);
1028  GLE = GetLastError();
1029  ok(!store && (GLE == ERROR_INVALID_HANDLE || GLE == ERROR_BADKEY),
1030  "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", GLE);
1031 
1032  /* Opening up any old key works.. */
1034  store = CertOpenStore(CERT_STORE_PROV_REG, 0, 0, 0, key);
1035  /* Not sure if this is a bug in DuplicateHandle, marking todo_wine for now
1036  */
1037  todo_wine ok(store != 0, "CertOpenStore failed: %08x\n", GetLastError());
1038  CertCloseStore(store, 0);
1039 
1040  rc = RegCreateKeyExA(HKEY_CURRENT_USER, tempKey, 0, NULL, 0, KEY_ALL_ACCESS,
1041  NULL, &key, NULL);
1042  ok(!rc, "RegCreateKeyExA failed: %d\n", rc);
1043  if (key)
1044  {
1045  BOOL ret;
1046  BYTE hash[20];
1047  DWORD size, i;
1048  static const char certificates[] = "Certificates\\";
1049  char subKeyName[sizeof(certificates) + 20 * 2 + 1], *ptr;
1050  HKEY subKey;
1052 
1053  store = CertOpenStore(CERT_STORE_PROV_REG, 0, 0, 0, key);
1054  ok(store != 0, "CertOpenStore failed: %08x\n", GetLastError());
1055  /* Add a certificate. It isn't persisted right away, since it's only
1056  * added to the cache..
1057  */
1060  ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
1061  GetLastError());
1062  /* so flush the cache to force a commit.. */
1064  ok(ret, "CertControlStore failed: %08x\n", GetLastError());
1065  /* and check that the expected subkey was written. */
1066  size = sizeof(hash);
1067  ret = CryptHashCertificate(0, 0, 0, bigCert2, sizeof(bigCert2),
1068  hash, &size);
1069  ok(ret, "CryptHashCertificate failed: %d\n", GetLastError());
1070  strcpy(subKeyName, certificates);
1071  for (i = 0, ptr = subKeyName + sizeof(certificates) - 1; i < size;
1072  i++, ptr += 2)
1073  sprintf(ptr, "%02X", hash[i]);
1074  rc = RegCreateKeyExA(key, subKeyName, 0, NULL, 0, KEY_ALL_ACCESS, NULL,
1075  &subKey, NULL);
1076  ok(!rc, "RegCreateKeyExA failed: %d\n", rc);
1077  if (subKey)
1078  {
1079  LPBYTE buf;
1080 
1081  size = 0;
1082  RegQueryValueExA(subKey, "Blob", NULL, NULL, NULL, &size);
1083  buf = HeapAlloc(GetProcessHeap(), 0, size);
1084  if (buf)
1085  {
1086  rc = RegQueryValueExA(subKey, "Blob", NULL, NULL, buf, &size);
1087  ok(!rc, "RegQueryValueExA failed: %d\n", rc);
1088  if (!rc)
1089  {
1090  const struct CertPropIDHeader *hdr;
1091 
1092  /* Both the hash and the cert should be present */
1094  ok(hdr != NULL, "Expected to find a cert property\n");
1095  if (hdr)
1096  {
1097  ok(hdr->cb == sizeof(bigCert2),
1098  "Wrong size %d of cert property\n", hdr->cb);
1099  ok(!memcmp((const BYTE *)hdr + sizeof(*hdr), bigCert2,
1100  hdr->cb), "Unexpected cert in cert property\n");
1101  }
1103  ok(hdr != NULL, "Expected to find a hash property\n");
1104  if (hdr)
1105  {
1106  ok(hdr->cb == sizeof(hash),
1107  "Wrong size %d of hash property\n", hdr->cb);
1108  ok(!memcmp((const BYTE *)hdr + sizeof(*hdr), hash,
1109  hdr->cb), "Unexpected hash in cert property\n");
1110  }
1111  }
1112  HeapFree(GetProcessHeap(), 0, buf);
1113  }
1114  RegCloseKey(subKey);
1115  }
1116 
1117  /* Remove the existing context */
1119  ok(context != NULL, "Expected a cert context\n");
1120  if (context)
1123  ok(ret, "CertControlStore failed: %08x\n", GetLastError());
1124 
1125  /* Add a serialized cert with a bogus hash directly to the registry */
1126  memset(hash, 0, sizeof(hash));
1127  strcpy(subKeyName, certificates);
1128  for (i = 0, ptr = subKeyName + sizeof(certificates) - 1;
1129  i < sizeof(hash); i++, ptr += 2)
1130  sprintf(ptr, "%02X", hash[i]);
1131  rc = RegCreateKeyExA(key, subKeyName, 0, NULL, 0, KEY_ALL_ACCESS, NULL,
1132  &subKey, NULL);
1133  ok(!rc, "RegCreateKeyExA failed: %d\n", rc);
1134  if (subKey)
1135  {
1136  BYTE buf[sizeof(struct CertPropIDHeader) * 2 + sizeof(hash) +
1137  sizeof(bigCert)], *ptr;
1138  DWORD certCount = 0;
1139  struct CertPropIDHeader *hdr;
1140 
1141  hdr = (struct CertPropIDHeader *)buf;
1142  hdr->propID = CERT_HASH_PROP_ID;
1143  hdr->unknown1 = 1;
1144  hdr->cb = sizeof(hash);
1145  ptr = buf + sizeof(*hdr);
1146  memcpy(ptr, hash, sizeof(hash));
1147  ptr += sizeof(hash);
1148  hdr = (struct CertPropIDHeader *)ptr;
1149  hdr->propID = CERT_CERT_PROP_ID;
1150  hdr->unknown1 = 1;
1151  hdr->cb = sizeof(bigCert);
1152  ptr += sizeof(*hdr);
1153  memcpy(ptr, bigCert, sizeof(bigCert));
1154 
1155  rc = RegSetValueExA(subKey, "Blob", 0, REG_BINARY, buf,
1156  sizeof(buf));
1157  ok(!rc, "RegSetValueExA failed: %d\n", rc);
1158 
1160  ok(ret, "CertControlStore failed: %08x\n", GetLastError());
1161 
1162  /* Make sure the bogus hash cert gets loaded. */
1163  certCount = 0;
1164  context = NULL;
1165  do {
1167  if (context)
1168  certCount++;
1169  } while (context != NULL);
1170  ok(certCount == 1, "Expected 1 certificates, got %d\n", certCount);
1171 
1172  RegCloseKey(subKey);
1173  }
1174 
1175  /* Add another serialized cert directly to the registry, this time
1176  * under the correct key name (named with the correct hash value).
1177  */
1178  size = sizeof(hash);
1179  ret = CryptHashCertificate(0, 0, 0, bigCert2,
1180  sizeof(bigCert2), hash, &size);
1181  ok(ret, "CryptHashCertificate failed: %d\n", GetLastError());
1182  strcpy(subKeyName, certificates);
1183  for (i = 0, ptr = subKeyName + sizeof(certificates) - 1;
1184  i < sizeof(hash); i++, ptr += 2)
1185  sprintf(ptr, "%02X", hash[i]);
1186  rc = RegCreateKeyExA(key, subKeyName, 0, NULL, 0, KEY_ALL_ACCESS, NULL,
1187  &subKey, NULL);
1188  ok(!rc, "RegCreateKeyExA failed: %d\n", rc);
1189  if (subKey)
1190  {
1191  BYTE buf[sizeof(struct CertPropIDHeader) * 2 + sizeof(hash) +
1192  sizeof(bigCert2)], *ptr;
1193  DWORD certCount = 0;
1195  struct CertPropIDHeader *hdr;
1196 
1197  /* First try with a bogus hash... */
1198  hdr = (struct CertPropIDHeader *)buf;
1199  hdr->propID = CERT_HASH_PROP_ID;
1200  hdr->unknown1 = 1;
1201  hdr->cb = sizeof(hash);
1202  ptr = buf + sizeof(*hdr);
1203  memset(ptr, 0, sizeof(hash));
1204  ptr += sizeof(hash);
1205  hdr = (struct CertPropIDHeader *)ptr;
1206  hdr->propID = CERT_CERT_PROP_ID;
1207  hdr->unknown1 = 1;
1208  hdr->cb = sizeof(bigCert2);
1209  ptr += sizeof(*hdr);
1210  memcpy(ptr, bigCert2, sizeof(bigCert2));
1211 
1212  rc = RegSetValueExA(subKey, "Blob", 0, REG_BINARY, buf,
1213  sizeof(buf));
1214  ok(!rc, "RegSetValueExA failed: %d\n", rc);
1215 
1217  ok(ret, "CertControlStore failed: %08x\n", GetLastError());
1218 
1219  /* and make sure just one cert still gets loaded. */
1220  certCount = 0;
1221  context = NULL;
1222  do {
1224  if (context)
1225  certCount++;
1226  } while (context != NULL);
1227  ok(certCount == 1, "Expected 1 certificate, got %d\n", certCount);
1228 
1229  /* Try again with the correct hash... */
1230  ptr = buf + sizeof(*hdr);
1231  memcpy(ptr, hash, sizeof(hash));
1232 
1233  rc = RegSetValueExA(subKey, "Blob", 0, REG_BINARY, buf,
1234  sizeof(buf));
1235  ok(!rc, "RegSetValueExA failed: %d\n", rc);
1236 
1238  ok(ret, "CertControlStore failed: %08x\n", GetLastError());
1239 
1240  /* and make sure two certs get loaded. */
1241  certCount = 0;
1242  context = NULL;
1243  do {
1245  if (context)
1246  certCount++;
1247  } while (context != NULL);
1248  ok(certCount == 2, "Expected 2 certificates, got %d\n", certCount);
1249 
1250  RegCloseKey(subKey);
1251  }
1252  CertCloseStore(store, 0);
1253  /* Is delete allowed on a reg store? */
1254  store = CertOpenStore(CERT_STORE_PROV_REG, 0, 0,
1256  ok(store == NULL, "Expected NULL return from CERT_STORE_DELETE_FLAG\n");
1257  ok(GetLastError() == 0, "CertOpenStore failed: %08x\n",
1258  GetLastError());
1259 
1260  RegCloseKey(key);
1261  }
1262  /* The CertOpenStore with CERT_STORE_DELETE_FLAG above will delete the
1263  * contents of the key, but not the key itself.
1264  */
1265  rc = RegCreateKeyExA(HKEY_CURRENT_USER, tempKey, 0, NULL, 0, KEY_ALL_ACCESS,
1266  NULL, &key, &disp);
1267  ok(!rc, "RegCreateKeyExA failed: %d\n", rc);
1269  "Expected REG_OPENED_EXISTING_KEY, got %d\n", disp);
1270  if (!rc)
1271  {
1272  RegCloseKey(key);
1273  rc = RegDeleteKeyA(HKEY_CURRENT_USER, tempKey);
1274  if (rc)
1275  {
1276  /* Use shlwapi's SHDeleteKeyA to _really_ blow away the key,
1277  * otherwise subsequent tests will fail.
1278  */
1279  SHDeleteKeyA(HKEY_CURRENT_USER, tempKey);
1280  }
1281  }
1282 }
#define CERT_STORE_DELETE_FLAG
Definition: wincrypt.h:2455
disp
Definition: i386-dis.c:3181
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
char hdr[14]
Definition: iptest.cpp:33
#define CERT_STORE_CTRL_RESYNC
Definition: wincrypt.h:2820
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static const BYTE bigCert[]
Definition: store.c:48
Definition: http.c:6587
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define REG_BINARY
Definition: nt_native.h:1496
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
BOOL WINAPI CertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext)
Definition: cert.c:58
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define CERT_STORE_CTRL_COMMIT
Definition: wincrypt.h:2822
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
int hash
Definition: main.c:58
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
static PVOID ptr
Definition: dispmode.c:27
#define ok(value,...)
BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
Definition: store.c:943
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1127
BOOL WINAPI CertControlStore(HCERTSTORE hCertStore, DWORD dwFlags, DWORD dwCtrlType, void const *pvCtrlPara)
Definition: store.c:1149
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CERT_CERT_PROP_ID
Definition: store.c:36
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CERT_HASH_PROP_ID
Definition: wincrypt.h:2688
int ret
#define ERROR_BADKEY
Definition: winerror.h:589
#define todo_wine
Definition: test.h:154
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const BYTE bigCert2[]
Definition: store.c:89
unsigned char BYTE
Definition: mem.h:68
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
LONG WINAPI RegDeleteKeyA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey)
Definition: reg.c:1222
DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
Definition: reg.c:1533
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define CERT_STORE_PROV_REG
Definition: wincrypt.h:2253
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:815
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
BOOL WINAPI CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid, DWORD dwFlags, const BYTE *pbEncoded, DWORD cbEncoded, BYTE *pbComputedHash, DWORD *pcbComputedHash)
Definition: cert.c:2187
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4812
LONG WINAPI RegCreateKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD Reserved, _In_ LPSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_ LPDWORD lpdwDisposition)
Definition: reg.c:1029
Definition: _hash_fun.h:40
#define memset(x, y, z)
Definition: compat.h:39
static const struct CertPropIDHeader * findPropID(const BYTE *buf, DWORD size, DWORD propID)
Definition: store.c:984
#define HeapFree(x, y, z)
Definition: compat.h:394
#define CERT_STORE_ADD_ALWAYS
Definition: wincrypt.h:2485
Definition: path.c:42
static DWORD GLE
Definition: registry.c:38

Referenced by START_TEST().

◆ testRegStoreSavedCerts()

static void testRegStoreSavedCerts ( void  )
static

Definition at line 367 of file store.c.

368 {
369  static const WCHAR fmt[] =
370  { '%','s','\\','%','s','\\','%','s','\\','%','s',0},
371  ms_certs[] =
372  { 'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m','C','e','r','t','i','f','i','c','a','t','e','s',0},
373  certs[] =
374  {'C','e','r','t','i','f','i','c','a','t','e','s',0},
375  bigCert_hash[] = {
376  '6','E','3','0','9','0','7','1','5','F','D','9','2','3',
377  '5','6','E','B','A','E','2','5','4','0','E','6','2','2',
378  'D','A','1','9','2','6','0','2','A','6','0','8',0};
380  HCERTSTORE store;
381  HANDLE cert_file;
382  HRESULT pathres;
383  WCHAR key_name[MAX_PATH], appdata_path[MAX_PATH];
384  HKEY key;
385  BOOL ret;
386  DWORD res,i;
387 
388  for (i = 0; i < ARRAY_SIZE(reg_store_saved_certs); i++)
389  {
390  DWORD err;
391 
394 
395  err = GetLastError();
396  if (!store)
397  {
398  ok (err == ERROR_ACCESS_DENIED, "Failed to create store at %d (%08x)\n", i, err);
399  skip("Insufficient privileges for the test %d\n", i);
400  continue;
401  }
402  ok (store!=NULL, "Failed to open the store at %d, %x\n", i, GetLastError());
404  ok (cert1 != NULL, "Create cert context failed at %d, %x\n", i, GetLastError());
406  /* Addittional skip per Win7, it allows opening HKLM store, but disallows adding certs */
407  err = GetLastError();
408  if (!ret)
409  {
410  ok (err == ERROR_ACCESS_DENIED, "Failed to add certificate to store at %d (%08x)\n", i, err);
411  skip("Insufficient privileges for the test %d\n", i);
412  continue;
413  }
414  ok (ret, "Adding to the store failed at %d, %x\n", i, err);
416  CertCloseStore(store, 0);
417 
419  reg_store_saved_certs[i].store_name, certs, bigCert_hash);
420 
422  {
424  ok (!res, "The cert hasn't been saved at %d, %x\n", i, GetLastError());
425  if (!res) RegCloseKey(key);
426  } else
427  {
428  pathres = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, appdata_path);
429  ok (pathres == S_OK,
430  "Failed to get app data path at %d (%x)\n", pathres, GetLastError());
431  if (pathres == S_OK)
432  {
433  PathAppendW(appdata_path, ms_certs);
435  PathAppendW(appdata_path, certs);
436  PathAppendW(appdata_path, bigCert_hash);
437 
438  cert_file = CreateFileW(appdata_path, GENERIC_READ, 0, NULL,
440  todo_wine ok (cert_file != INVALID_HANDLE_VALUE,
441  "Cert was not saved in AppData at %d (%x)\n", i, GetLastError());
442  CloseHandle(cert_file);
443  }
444  }
445 
446  /* deleting cert from store */
449  ok (store!=NULL, "Failed to open the store at %d, %x\n", i, GetLastError());
450 
452  ok (cert1 != NULL, "Create cert context failed at %d, %x\n", i, GetLastError());
453