ReactOS  0.4.14-dev-390-g34947ad
serialize.c File Reference
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wincrypt.h"
#include "wine/debug.h"
#include "wine/exception.h"
#include "crypt32_private.h"
Include dependency graph for serialize.c:

Go to the source code of this file.

Classes

struct  _WINE_CERT_PROP_HEADER
 
struct  BlobReader
 
struct  MemWrittenTracker
 

Typedefs

typedef struct _WINE_CERT_PROP_HEADER WINE_CERT_PROP_HEADER
 
typedef BOOL(* read_serialized_func) (void *handle, void *buffer, DWORD bytesToRead, DWORD *bytesRead)
 
typedef BOOL(* SerializedOutputFunc) (void *handle, const void *buffer, DWORD size)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (crypt)
 
static BOOL CRYPT_SerializeStoreElement (const void *context, const BYTE *encodedContext, DWORD cbEncodedContext, DWORD contextPropID, const WINE_CONTEXT_INTERFACE *contextInterface, DWORD dwFlags, BOOL omitHashes, BYTE *pbElement, DWORD *pcbElement)
 
BOOL WINAPI CertSerializeCertificateStoreElement (PCCERT_CONTEXT pCertContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
 
BOOL WINAPI CertSerializeCRLStoreElement (PCCRL_CONTEXT pCrlContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
 
BOOL WINAPI CertSerializeCTLStoreElement (PCCTL_CONTEXT pCtlContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
 
static const WINE_CERT_PROP_HEADERCRYPT_findPropID (const BYTE *buf, DWORD size, DWORD propID)
 
static BOOL CRYPT_ReadContextProp (const WINE_CONTEXT_INTERFACE *contextInterface, const void *context, const WINE_CERT_PROP_HEADER *hdr, const BYTE *pbElement, DWORD cbElement)
 
const voidCRYPT_ReadSerializedElement (const BYTE *pbElement, DWORD cbElement, DWORD dwContextTypeFlags, DWORD *pdwContentType)
 
static BOOL CRYPT_ReadSerializedStore (void *handle, read_serialized_func read_func, HCERTSTORE store)
 
static BOOL read_file_wrapper (void *handle, void *buffer, DWORD bytesToRead, DWORD *bytesRead)
 
BOOL CRYPT_ReadSerializedStoreFromFile (HANDLE file, HCERTSTORE store)
 
static BOOL read_blob_wrapper (void *handle, void *buffer, DWORD bytesToRead, DWORD *bytesRead)
 
BOOL CRYPT_ReadSerializedStoreFromBlob (const CRYPT_DATA_BLOB *blob, HCERTSTORE store)
 
static BOOL WINAPI CRYPT_SerializeCertNoHash (PCCERT_CONTEXT pCertContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
 
static BOOL WINAPI CRYPT_SerializeCRLNoHash (PCCRL_CONTEXT pCrlContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
 
static BOOL WINAPI CRYPT_SerializeCTLNoHash (PCCTL_CONTEXT pCtlContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
 
static BOOL CRYPT_SerializeContextsToStream (SerializedOutputFunc output, void *handle, const WINE_CONTEXT_INTERFACE *contextInterface, HCERTSTORE store)
 
static BOOL CRYPT_WriteSerializedStoreToStream (HCERTSTORE store, SerializedOutputFunc output, void *handle)
 
static BOOL CRYPT_FileOutputFunc (void *handle, const void *buffer, DWORD size)
 
static BOOL CRYPT_WriteSerializedStoreToFile (HANDLE file, HCERTSTORE store)
 
static BOOL CRYPT_SavePKCSToMem (HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
 
static BOOL CRYPT_SavePKCSToFile (HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
 
static BOOL CRYPT_SaveSerializedToFile (HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
 
static BOOL CRYPT_MemOutputFunc (void *handle, const void *buffer, DWORD size)
 
static BOOL CRYPT_CountSerializedBytes (void *handle, const void *buffer, DWORD size)
 
static BOOL CRYPT_SaveSerializedToMem (HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
 
BOOL WINAPI CertSaveStore (HCERTSTORE hCertStore, DWORD dwMsgAndCertEncodingType, DWORD dwSaveAs, DWORD dwSaveTo, void *pvSaveToPara, DWORD dwFlags)
 
BOOL WINAPI CertAddSerializedElementToStore (HCERTSTORE hCertStore, const BYTE *pbElement, DWORD cbElement, DWORD dwAddDisposition, DWORD dwFlags, DWORD dwContextTypeFlags, DWORD *pdwContentType, const void **ppvContext)
 

Variables

static const BYTE fileHeader [] = { 0, 0, 0, 0, 'C','E','R','T' }
 

Typedef Documentation

◆ read_serialized_func

typedef BOOL(* read_serialized_func) (void *handle, void *buffer, DWORD bytesToRead, DWORD *bytesRead)

Definition at line 428 of file serialize.c.

◆ SerializedOutputFunc

typedef BOOL(* SerializedOutputFunc) (void *handle, const void *buffer, DWORD size)

Definition at line 610 of file serialize.c.

◆ WINE_CERT_PROP_HEADER

Function Documentation

◆ CertAddSerializedElementToStore()

BOOL WINAPI CertAddSerializedElementToStore ( HCERTSTORE  hCertStore,
const BYTE pbElement,
DWORD  cbElement,
DWORD  dwAddDisposition,
DWORD  dwFlags,
DWORD  dwContextTypeFlags,
DWORD pdwContentType,
const void **  ppvContext 
)

Definition at line 953 of file serialize.c.

956 {
957  const void *context;
958  DWORD type;
959  BOOL ret;
960 
961  TRACE("(%p, %p, %d, %08x, %08x, %08x, %p, %p)\n", hCertStore,
963  pdwContentType, ppvContext);
964 
965  /* Call the internal function, then delete the hashes. Tests show this
966  * function uses real hash values, not whatever's stored in the hash
967  * property.
968  */
971  if (context)
972  {
973  const WINE_CONTEXT_INTERFACE *contextInterface = NULL;
974 
975  switch (type)
976  {
978  contextInterface = pCertInterface;
979  break;
981  contextInterface = pCRLInterface;
982  break;
984  contextInterface = pCTLInterface;
985  break;
986  default:
988  }
989  if (contextInterface)
990  {
991  contextInterface->setProp(context, CERT_HASH_PROP_ID, 0, NULL);
992  contextInterface->setProp(context, CERT_MD5_HASH_PROP_ID, 0, NULL);
993  contextInterface->setProp(context, CERT_SIGNATURE_HASH_PROP_ID, 0,
994  NULL);
995  if (pdwContentType)
996  *pdwContentType = type;
997  ret = contextInterface->addContextToStore(hCertStore, context,
1000  }
1001  else
1002  ret = FALSE;
1003  }
1004  else
1005  ret = FALSE;
1006  return ret;
1007 }
const WINE_CONTEXT_INTERFACE * pCRLInterface
Definition: store.c:67
const void * CRYPT_ReadSerializedElement(const BYTE *pbElement, DWORD cbElement, DWORD dwContextTypeFlags, DWORD *pdwContentType)
Definition: serialize.c:295
static context_t * context_from_ptr(const void *ptr)
_In_ DWORD _In_ DWORD _In_ DWORD _In_ DWORD dwContextTypeFlags
Definition: wincrypt.h:5092
Definition: http.c:6587
const WINE_CONTEXT_INTERFACE * pCTLInterface
Definition: store.c:80
_In_ PCCERT_CONTEXT _In_ DWORD dwAddDisposition
Definition: wincrypt.h:4987
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
void Context_Release(context_t *context)
Definition: context.c:106
SetContextPropertyFunc setProp
unsigned int BOOL
Definition: ntddk_ex.h:94
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
_In_ DWORD _In_ DWORD _In_ DWORD _In_ DWORD _Out_opt_ DWORD _Outptr_opt_ const void ** ppvContext
Definition: wincrypt.h:5092
_In_ DWORD cbElement
Definition: wincrypt.h:5092
#define CERT_STORE_CERTIFICATE_CONTEXT
Definition: wincrypt.h:2974
#define TRACE(s)
Definition: solgame.cpp:4
#define CERT_MD5_HASH_PROP_ID
Definition: wincrypt.h:2689
#define CERT_SIGNATURE_HASH_PROP_ID
Definition: wincrypt.h:2701
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define CERT_HASH_PROP_ID
Definition: wincrypt.h:2688
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
AddContextToStoreFunc addContextToStore
#define CERT_STORE_CTL_CONTEXT
Definition: wincrypt.h:2976
#define CERT_STORE_CRL_CONTEXT
Definition: wincrypt.h:2975
const WINE_CONTEXT_INTERFACE * pCertInterface
Definition: store.c:54

Referenced by testAddSerialized().

◆ CertSaveStore()

BOOL WINAPI CertSaveStore ( HCERTSTORE  hCertStore,
DWORD  dwMsgAndCertEncodingType,
DWORD  dwSaveAs,
DWORD  dwSaveTo,
void pvSaveToPara,
DWORD  dwFlags 
)

Definition at line 895 of file serialize.c.

897 {
898  BOOL (*saveFunc)(HCERTSTORE, DWORD, void *);
899  void *handle;
900  BOOL ret, closeFile = TRUE;
901 
902  TRACE("(%p, %08x, %d, %d, %p, %08x)\n", hCertStore,
903  dwMsgAndCertEncodingType, dwSaveAs, dwSaveTo, pvSaveToPara, dwFlags);
904 
905  switch (dwSaveAs)
906  {
908  if (dwSaveTo == CERT_STORE_SAVE_TO_MEMORY)
909  saveFunc = CRYPT_SaveSerializedToMem;
910  else
911  saveFunc = CRYPT_SaveSerializedToFile;
912  break;
914  if (dwSaveTo == CERT_STORE_SAVE_TO_MEMORY)
915  saveFunc = CRYPT_SavePKCSToMem;
916  else
917  saveFunc = CRYPT_SavePKCSToFile;
918  break;
919  default:
920  WARN("unimplemented for %d\n", dwSaveAs);
922  return FALSE;
923  }
924  switch (dwSaveTo)
925  {
927  handle = pvSaveToPara;
928  closeFile = FALSE;
929  break;
931  handle = CreateFileA(pvSaveToPara, GENERIC_WRITE, 0, NULL,
932  CREATE_ALWAYS, 0, NULL);
933  break;
935  handle = CreateFileW(pvSaveToPara, GENERIC_WRITE, 0, NULL,
936  CREATE_ALWAYS, 0, NULL);
937  break;
939  handle = pvSaveToPara;
940  break;
941  default:
942  WARN("unimplemented for %d\n", dwSaveTo);
944  return FALSE;
945  }
946  ret = saveFunc(hCertStore, dwMsgAndCertEncodingType, handle);
947  if (closeFile)
949  TRACE("returning %d\n", ret);
950  return ret;
951 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define CERT_STORE_SAVE_TO_FILENAME_W
Definition: wincrypt.h:2652
#define CERT_STORE_SAVE_TO_FILE
Definition: wincrypt.h:2649
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
static BOOL CRYPT_SavePKCSToFile(HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
Definition: serialize.c:789
#define WARN(fmt,...)
Definition: debug.h:111
static BOOL CRYPT_SaveSerializedToFile(HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
Definition: serialize.c:818
#define CERT_STORE_SAVE_TO_FILENAME_A
Definition: wincrypt.h:2651
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
static BOOL CRYPT_SavePKCSToMem(HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
Definition: serialize.c:691
#define TRACE(s)
Definition: solgame.cpp:4
#define CERT_STORE_SAVE_AS_PKCS7
Definition: wincrypt.h:2647
#define CERT_STORE_SAVE_AS_STORE
Definition: wincrypt.h:2646
#define SetLastError(x)
Definition: compat.h:417
int ret
static BOOL CRYPT_SaveSerializedToMem(HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
Definition: serialize.c:861
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define CREATE_ALWAYS
Definition: disk.h:72
#define CERT_STORE_SAVE_TO_MEMORY
Definition: wincrypt.h:2650
#define CreateFileW
Definition: compat.h:408
_In_ DWORD dwMsgAndCertEncodingType
Definition: wincrypt.h:5080
void * HCERTSTORE
Definition: wincrypt.h:51
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407

Referenced by compareStore(), CRYPT_FileCloseStore(), CRYPT_FileControl(), save_serialized_store(), and save_store_as_cms().

◆ CertSerializeCertificateStoreElement()

BOOL WINAPI CertSerializeCertificateStoreElement ( PCCERT_CONTEXT  pCertContext,
DWORD  dwFlags,
BYTE pbElement,
DWORD pcbElement 
)

Definition at line 144 of file serialize.c.

146 {
149  CERT_CERT_PROP_ID, pCertInterface, dwFlags, FALSE, pbElement, pcbElement);
150 }
static BOOL CRYPT_SerializeStoreElement(const void *context, const BYTE *encodedContext, DWORD cbEncodedContext, DWORD contextPropID, const WINE_CONTEXT_INTERFACE *contextInterface, DWORD dwFlags, BOOL omitHashes, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:42
#define CERT_CERT_PROP_ID
BYTE * pbCertEncoded
Definition: wincrypt.h:480
DWORD cbCertEncoded
Definition: wincrypt.h:481
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
const WINE_CONTEXT_INTERFACE * pCertInterface
Definition: store.c:54
_In_ PCCERT_CONTEXT pCertContext
Definition: wincrypt.h:4840

Referenced by testAddCertificateLink(), and testMemStore().

◆ CertSerializeCRLStoreElement()

BOOL WINAPI CertSerializeCRLStoreElement ( PCCRL_CONTEXT  pCrlContext,
DWORD  dwFlags,
BYTE pbElement,
DWORD pcbElement 
)

Definition at line 152 of file serialize.c.

154 {
157  CERT_CRL_PROP_ID, pCRLInterface, dwFlags, FALSE, pbElement, pcbElement);
158 }
const WINE_CONTEXT_INTERFACE * pCRLInterface
Definition: store.c:67
static BOOL CRYPT_SerializeStoreElement(const void *context, const BYTE *encodedContext, DWORD cbEncodedContext, DWORD contextPropID, const WINE_CONTEXT_INTERFACE *contextInterface, DWORD dwFlags, BOOL omitHashes, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:42
BYTE * pbCrlEncoded
Definition: wincrypt.h:620
DWORD cbCrlEncoded
Definition: wincrypt.h:621
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ PCCRL_CONTEXT pCrlContext
Definition: wincrypt.h:4996
#define CERT_CRL_PROP_ID

◆ CertSerializeCTLStoreElement()

BOOL WINAPI CertSerializeCTLStoreElement ( PCCTL_CONTEXT  pCtlContext,
DWORD  dwFlags,
BYTE pbElement,
DWORD pcbElement 
)

Definition at line 160 of file serialize.c.

162 {
165  CERT_CTL_PROP_ID, pCTLInterface, dwFlags, FALSE, pbElement, pcbElement);
166 }
static BOOL CRYPT_SerializeStoreElement(const void *context, const BYTE *encodedContext, DWORD cbEncodedContext, DWORD contextPropID, const WINE_CONTEXT_INTERFACE *contextInterface, DWORD dwFlags, BOOL omitHashes, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:42
const WINE_CONTEXT_INTERFACE * pCTLInterface
Definition: store.c:80
#define CERT_CTL_PROP_ID
DWORD cbCtlEncoded
Definition: wincrypt.h:746
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ PCCTL_CONTEXT pCtlContext
Definition: wincrypt.h:5005
BYTE * pbCtlEncoded
Definition: wincrypt.h:745

◆ CRYPT_CountSerializedBytes()

static BOOL CRYPT_CountSerializedBytes ( void handle,
const void buffer,
DWORD  size 
)
static

Definition at line 854 of file serialize.c.

856 {
857  *(DWORD *)handle += size;
858  return TRUE;
859 }
#define TRUE
Definition: types.h:120
GLsizeiptr size
Definition: glext.h:5919
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by CRYPT_SaveSerializedToMem().

◆ CRYPT_FileOutputFunc()

static BOOL CRYPT_FileOutputFunc ( void handle,
const void buffer,
DWORD  size 
)
static

Definition at line 679 of file serialize.c.

680 {
681  return WriteFile(handle, buffer, size, &size, NULL);
682 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
GLuint buffer
Definition: glext.h:5915
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919

Referenced by CRYPT_WriteSerializedStoreToFile().

◆ CRYPT_findPropID()

static const WINE_CERT_PROP_HEADER* CRYPT_findPropID ( const BYTE buf,
DWORD  size,
DWORD  propID 
)
static

Definition at line 172 of file serialize.c.

174 {
175  const WINE_CERT_PROP_HEADER *ret = NULL;
176  BOOL done = FALSE;
177 
178  while (size && !ret && !done)
179  {
180  if (size < sizeof(WINE_CERT_PROP_HEADER))
181  {
183  done = TRUE;
184  }
185  else
186  {
187  const WINE_CERT_PROP_HEADER *hdr =
188  (const WINE_CERT_PROP_HEADER *)buf;
189 
190  size -= sizeof(WINE_CERT_PROP_HEADER);
191  buf += sizeof(WINE_CERT_PROP_HEADER);
192  if (size < hdr->cb)
193  {
195  done = TRUE;
196  }
197  else if (!hdr->propID)
198  {
199  /* assume a zero prop ID means the data are uninitialized, so
200  * stop looking.
201  */
202  done = TRUE;
203  }
204  else if (hdr->unknown != 1)
205  {
207  done = TRUE;
208  }
209  else if (hdr->propID == propID)
210  ret = hdr;
211  else
212  {
213  buf += hdr->cb;
214  size -= hdr->cb;
215  }
216  }
217  }
218  return ret;
219 }
#define TRUE
Definition: types.h:120
char hdr[14]
Definition: iptest.cpp:33
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CRYPT_E_FILE_ERROR
Definition: winerror.h:3006
unsigned int BOOL
Definition: ntddk_ex.h:94
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
struct _WINE_CERT_PROP_HEADER WINE_CERT_PROP_HEADER
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
GLsizeiptr size
Definition: glext.h:5919
#define SetLastError(x)
Definition: compat.h:417
int ret
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32

Referenced by CRYPT_ReadSerializedElement().

◆ CRYPT_MemOutputFunc()

static BOOL CRYPT_MemOutputFunc ( void handle,
const void buffer,
DWORD  size 
)
static

Definition at line 832 of file serialize.c.

833 {
834  struct MemWrittenTracker *tracker = handle;
835  BOOL ret;
836 
837  if (tracker->written + size > tracker->cbData)
838  {
840  /* Update written so caller can notify its caller of the required size
841  */
842  tracker->written += size;
843  ret = FALSE;
844  }
845  else
846  {
847  memcpy(tracker->pbData + tracker->written, buffer, size);
848  tracker->written += size;
849  ret = TRUE;
850  }
851  return ret;
852 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
GLuint buffer
Definition: glext.h:5915
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
#define SetLastError(x)
Definition: compat.h:417
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERROR_MORE_DATA
Definition: dderror.h:13

Referenced by CRYPT_SaveSerializedToMem().

◆ CRYPT_ReadContextProp()

static BOOL CRYPT_ReadContextProp ( const WINE_CONTEXT_INTERFACE contextInterface,
const void context,
const WINE_CERT_PROP_HEADER hdr,
const BYTE pbElement,
DWORD  cbElement 
)
static

Definition at line 221 of file serialize.c.

224 {
225  BOOL ret;
226 
227  if (cbElement < hdr->cb)
228  {
230  ret = FALSE;
231  }
232  else if (hdr->unknown != 1)
233  {
235  ret = FALSE;
236  }
237  else if (hdr->propID != CERT_CERT_PROP_ID &&
238  hdr->propID != CERT_CRL_PROP_ID && hdr->propID != CERT_CTL_PROP_ID)
239  {
240  /* Have to create a blob for most types, but not
241  * for all.. arghh.
242  */
243  switch (hdr->propID)
244  {
249  case CERT_HASH_PROP_ID:
261  {
262  CRYPT_DATA_BLOB blob = { hdr->cb,
263  (LPBYTE)pbElement };
264 
265  ret = contextInterface->setProp(context,
266  hdr->propID, 0, &blob);
267  break;
268  }
270  ret = contextInterface->setProp(context,
271  hdr->propID, 0, pbElement);
272  break;
274  {
276  (PCRYPT_KEY_PROV_INFO)pbElement;
277 
279  ret = contextInterface->setProp(context,
280  hdr->propID, 0, pbElement);
281  break;
282  }
283  default:
284  ret = FALSE;
285  }
286  }
287  else
288  {
289  /* ignore the context itself */
290  ret = TRUE;
291  }
292  return ret;
293 }
#define CERT_ENROLLMENT_PROP_ID
Definition: wincrypt.h:2712
#define CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID
Definition: wincrypt.h:2711
#define TRUE
Definition: types.h:120
char hdr[14]
Definition: iptest.cpp:33
#define CERT_CERT_PROP_ID
Definition: image.c:133
Definition: http.c:6587
#define CERT_DATE_STAMP_PROP_ID
Definition: wincrypt.h:2713
#define CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID
Definition: wincrypt.h:2710
#define CERT_AUTO_ENROLL_PROP_ID
Definition: wincrypt.h:2707
#define CERT_CTL_PROP_ID
#define CERT_KEY_IDENTIFIER_PROP_ID
Definition: wincrypt.h:2706
unsigned char * LPBYTE
Definition: typedefs.h:52
SetContextPropertyFunc setProp
unsigned int BOOL
Definition: ntddk_ex.h:94
#define E_INVALIDARG
Definition: ddrawi.h:101
#define CERT_PVK_FILE_PROP_ID
Definition: wincrypt.h:2698
#define CERT_FRIENDLY_NAME_PROP_ID
Definition: wincrypt.h:2697
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define CERT_MD5_HASH_PROP_ID
Definition: wincrypt.h:2689
#define CERT_SIGNATURE_HASH_PROP_ID
Definition: wincrypt.h:2701
#define CERT_CROSS_CERT_DIST_POINTS_PROP_ID
Definition: wincrypt.h:2709
#define SetLastError(x)
Definition: compat.h:417
#define CERT_HASH_PROP_ID
Definition: wincrypt.h:2688
int ret
#define CERT_NEXT_UPDATE_LOCATION_PROP_ID
Definition: wincrypt.h:2696
#define CERT_RENEWAL_PROP_ID
Definition: wincrypt.h:2724
void CRYPT_FixKeyProvInfoPointers(PCRYPT_KEY_PROV_INFO info)
Definition: cert.c:523
struct _CRYPT_KEY_PROV_INFO * PCRYPT_KEY_PROV_INFO
#define CERT_KEY_PROV_INFO_PROP_ID
Definition: wincrypt.h:2686
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
#define CERT_DESCRIPTION_PROP_ID
Definition: wincrypt.h:2699
#define CERT_CTL_USAGE_PROP_ID
Definition: wincrypt.h:2695
#define CERT_CRL_PROP_ID
#define CERT_PUBKEY_ALG_PARA_PROP_ID
Definition: wincrypt.h:2708

Referenced by CRYPT_ReadSerializedElement(), and CRYPT_ReadSerializedStore().

◆ CRYPT_ReadSerializedElement()

const void* CRYPT_ReadSerializedElement ( const BYTE pbElement,
DWORD  cbElement,
DWORD  dwContextTypeFlags,
DWORD pdwContentType 
)

Definition at line 295 of file serialize.c.

297 {
298  const void *context;
299 
300  TRACE("(%p, %d, %08x, %p)\n", pbElement, cbElement, dwContextTypeFlags,
301  pdwContentType);
302 
303  if (!cbElement)
304  {
306  return NULL;
307  }
308 
309  __TRY
310  {
311  const WINE_CONTEXT_INTERFACE *contextInterface = NULL;
312  const WINE_CERT_PROP_HEADER *hdr = NULL;
313  DWORD type = 0;
314  BOOL ret;
315 
316  ret = TRUE;
317  context = NULL;
319  {
321  if (hdr)
323  else
324  {
326  if (hdr)
328  else
329  {
330  hdr = CRYPT_findPropID(pbElement, cbElement,
332  if (hdr)
334  }
335  }
336  }
338  {
341  }
343  {
346  }
348  {
351  }
352 
353  switch (type)
354  {
356  contextInterface = pCertInterface;
357  break;
359  contextInterface = pCRLInterface;
360  break;
362  contextInterface = pCTLInterface;
363  break;
364  default:
366  ret = FALSE;
367  }
368  if (!hdr)
369  ret = FALSE;
370 
371  if (ret)
372  context = contextInterface->create(X509_ASN_ENCODING,
373  (BYTE *)hdr + sizeof(WINE_CERT_PROP_HEADER), hdr->cb);
374  if (ret && context)
375  {
376  BOOL noMoreProps = FALSE;
377 
378  while (!noMoreProps && ret)
379  {
380  if (cbElement < sizeof(WINE_CERT_PROP_HEADER))
381  ret = FALSE;
382  else
383  {
384  const WINE_CERT_PROP_HEADER *hdr =
385  (const WINE_CERT_PROP_HEADER *)pbElement;
386 
387  TRACE("prop is %d\n", hdr->propID);
388  cbElement -= sizeof(WINE_CERT_PROP_HEADER);
389  pbElement += sizeof(WINE_CERT_PROP_HEADER);
390  if (!hdr->propID)
391  {
392  /* Like in CRYPT_findPropID, stop if the propID is zero
393  */
394  noMoreProps = TRUE;
395  }
396  else
397  ret = CRYPT_ReadContextProp(contextInterface, context,
398  hdr, pbElement, cbElement);
399  pbElement += hdr->cb;
400  cbElement -= hdr->cb;
401  if (!cbElement)
402  noMoreProps = TRUE;
403  }
404  }
405  if (ret)
406  {
407  if (pdwContentType)
408  *pdwContentType = type;
409  }
410  else
411  {
413  context = NULL;
414  }
415  }
416  }
418  {
420  context = NULL;
421  }
422  __ENDTRY
423  return context;
424 }
const WINE_CONTEXT_INTERFACE * pCRLInterface
Definition: store.c:67
static context_t * context_from_ptr(const void *ptr)
#define TRUE
Definition: types.h:120
char hdr[14]
Definition: iptest.cpp:33
_In_ DWORD _In_ DWORD _In_ DWORD _In_ DWORD dwContextTypeFlags
Definition: wincrypt.h:5092
#define CERT_CERT_PROP_ID
Definition: http.c:6587
const WINE_CONTEXT_INTERFACE * pCTLInterface
Definition: store.c:80
#define CERT_STORE_CERTIFICATE_CONTEXT_FLAG
Definition: wincrypt.h:2978
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define CERT_CTL_PROP_ID
void Context_Release(context_t *context)
Definition: context.c:106
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
static const WINE_CERT_PROP_HEADER * CRYPT_findPropID(const BYTE *buf, DWORD size, DWORD propID)
Definition: serialize.c:172
static BOOL CRYPT_ReadContextProp(const WINE_CONTEXT_INTERFACE *contextInterface, const void *context, const WINE_CERT_PROP_HEADER *hdr, const BYTE *pbElement, DWORD cbElement)
Definition: serialize.c:221
#define CERT_STORE_CTL_CONTEXT_FLAG
Definition: wincrypt.h:2981
unsigned int BOOL
Definition: ntddk_ex.h:94
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
struct _WINE_CERT_PROP_HEADER WINE_CERT_PROP_HEADER
#define __TRY
Definition: compat.h:70
_In_ DWORD cbElement
Definition: wincrypt.h:5092
#define CERT_STORE_CERTIFICATE_CONTEXT
Definition: wincrypt.h:2974
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define __ENDTRY
Definition: compat.h:72
int ret
CreateContextFunc create
unsigned char BYTE
Definition: mem.h:68
#define CERT_STORE_ALL_CONTEXT_FLAG
Definition: wincrypt.h:2977
#define CERT_STORE_CRL_CONTEXT_FLAG
Definition: wincrypt.h:2980
#define CERT_STORE_CTL_CONTEXT
Definition: wincrypt.h:2976
#define ERROR_END_OF_MEDIA
Definition: winerror.h:636
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define CERT_STORE_CRL_CONTEXT
Definition: wincrypt.h:2975
#define CERT_CRL_PROP_ID
const WINE_CONTEXT_INTERFACE * pCertInterface
Definition: store.c:54
#define __EXCEPT_PAGE_FAULT
Definition: compat.h:71

Referenced by CertAddSerializedElementToStore(), CRYPT_QuerySerializedContextObject(), and CRYPT_RegReadSerializedFromReg().

◆ CRYPT_ReadSerializedStore()

static BOOL CRYPT_ReadSerializedStore ( void handle,
read_serialized_func  read_func,
HCERTSTORE  store 
)
static

Definition at line 431 of file serialize.c.

433 {
434  BYTE fileHeaderBuf[sizeof(fileHeader)];
435  DWORD read;
436  BOOL ret;
437 
438  /* Failure reading is non-critical, we'll leave the store empty */
439  ret = read_func(handle, fileHeaderBuf, sizeof(fileHeaderBuf), &read);
440  if (ret)
441  {
442  if (!read)
443  ; /* an empty file is okay */
444  else if (read != sizeof(fileHeaderBuf))
445  ret = FALSE;
446  else if (!memcmp(fileHeaderBuf, fileHeader, read))
447  {
448  WINE_CERT_PROP_HEADER propHdr;
449  const void *context = NULL;
450  const WINE_CONTEXT_INTERFACE *contextInterface = NULL;
451  LPBYTE buf = NULL;
452  DWORD bufSize = 0;
453 
454  do {
455  ret = read_func(handle, &propHdr, sizeof(propHdr), &read);
456  if (ret && read == sizeof(propHdr))
457  {
458  if (contextInterface && context &&
459  (propHdr.propID == CERT_CERT_PROP_ID ||
460  propHdr.propID == CERT_CRL_PROP_ID ||
461  propHdr.propID == CERT_CTL_PROP_ID))
462  {
463  /* We have a new context, so free the existing one */
465  }
466  if (propHdr.cb > bufSize)
467  {
468  /* Not reusing realloc, because the old data aren't
469  * needed any longer.
470  */
471  CryptMemFree(buf);
472  buf = CryptMemAlloc(propHdr.cb);
473  bufSize = propHdr.cb;
474  }
475  if (!propHdr.cb)
476  ; /* Property is empty, nothing to do */
477  else if (buf)
478  {
479  ret = read_func(handle, buf, propHdr.cb, &read);
480  if (ret && read == propHdr.cb)
481  {
482  if (propHdr.propID == CERT_CERT_PROP_ID)
483  {
484  contextInterface = pCertInterface;
485  ret = contextInterface->addEncodedToStore(store,
488  }
489  else if (propHdr.propID == CERT_CRL_PROP_ID)
490  {
491  contextInterface = pCRLInterface;
492  ret = contextInterface->addEncodedToStore(store,
495  }
496  else if (propHdr.propID == CERT_CTL_PROP_ID)
497  {
498  contextInterface = pCTLInterface;
499  ret = contextInterface->addEncodedToStore(store,
502  }
503  else
504  {
505  if (!contextInterface)
506  {
507  WARN("prop id %d before a context id\n",
508  propHdr.propID);
509  ret = FALSE;
510  }
511  else
513  contextInterface, context, &propHdr, buf,
514  read);
515  }
516  }
517  }
518  else
519  ret = FALSE;
520  }
521  } while (ret && read > 0 && propHdr.cb);
522  if (contextInterface && context)
523  {
524  /* Free the last context added */
526  }
527  CryptMemFree(buf);
528  ret = TRUE;
529  }
530  else
531  ret = FALSE;
532  }
533  else
534  ret = TRUE;
535  return ret;
536 }
const WINE_CONTEXT_INTERFACE * pCRLInterface
Definition: store.c:67
static context_t * context_from_ptr(const void *ptr)
#define TRUE
Definition: types.h:120
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define CERT_CERT_PROP_ID
Definition: http.c:6587
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
const WINE_CONTEXT_INTERFACE * pCTLInterface
Definition: store.c:80
#define WARN(fmt,...)
Definition: debug.h:111
#define CERT_STORE_ADD_NEW
Definition: wincrypt.h:2482
#define CERT_CTL_PROP_ID
void Context_Release(context_t *context)
Definition: context.c:106
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
GLuint GLsizei bufSize
Definition: glext.h:6040
static BOOL CRYPT_ReadContextProp(const WINE_CONTEXT_INTERFACE *contextInterface, const void *context, const WINE_CERT_PROP_HEADER *hdr, const BYTE *pbElement, DWORD cbElement)
Definition: serialize.c:221
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:131
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
AddEncodedContextToStoreFunc addEncodedToStore
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static const BYTE fileHeader[]
Definition: serialize.c:426
unsigned char BYTE
Definition: mem.h:68
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:141
#define CERT_CRL_PROP_ID
const WINE_CONTEXT_INTERFACE * pCertInterface
Definition: store.c:54
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by CRYPT_ReadSerializedStoreFromBlob(), and CRYPT_ReadSerializedStoreFromFile().

◆ CRYPT_ReadSerializedStoreFromBlob()

BOOL CRYPT_ReadSerializedStoreFromBlob ( const CRYPT_DATA_BLOB blob,
HCERTSTORE  store 
)

Definition at line 578 of file serialize.c.

580 {
581  struct BlobReader reader = { blob, 0 };
582 
584 }
static BOOL CRYPT_ReadSerializedStore(void *handle, read_serialized_func read_func, HCERTSTORE store)
Definition: serialize.c:431
const CRYPT_DATA_BLOB * blob
Definition: serialize.c:551
static BOOL read_blob_wrapper(void *handle, void *buffer, DWORD bytesToRead, DWORD *bytesRead)
Definition: serialize.c:555
Definition: reader.h:83

Referenced by CRYPT_QuerySerializedStoreFromBlob(), and CRYPT_SerializedOpenStore().

◆ CRYPT_ReadSerializedStoreFromFile()

BOOL CRYPT_ReadSerializedStoreFromFile ( HANDLE  file,
HCERTSTORE  store 
)

Definition at line 544 of file serialize.c.

545 {
547 }
static BOOL CRYPT_ReadSerializedStore(void *handle, read_serialized_func read_func, HCERTSTORE store)
Definition: serialize.c:431
static BOOL read_file_wrapper(void *handle, void *buffer, DWORD bytesToRead, DWORD *bytesRead)
Definition: serialize.c:538
Definition: fci.c:126

Referenced by CRYPT_FileControl(), CRYPT_FileOpenStore(), and CRYPT_QuerySerializedStoreFromFile().

◆ CRYPT_SavePKCSToFile()

static BOOL CRYPT_SavePKCSToFile ( HCERTSTORE  store,
DWORD  dwMsgAndCertEncodingType,
void handle 
)
static

Definition at line 789 of file serialize.c.

791 {
792  CERT_BLOB blob = { 0, NULL };
793  BOOL ret;
794 
795  TRACE("(%p)\n", handle);
796 
798  if (ret)
799  {
800  blob.pbData = CryptMemAlloc(blob.cbData);
801  if (blob.pbData)
802  {
804  if (ret)
805  ret = WriteFile(handle, blob.pbData, blob.cbData,
806  &blob.cbData, NULL);
807  }
808  else
809  {
811  ret = FALSE;
812  }
813  }
814  TRACE("returning %d\n", ret);
815  return ret;
816 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
Definition: image.c:133
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:131
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
static BOOL CRYPT_SavePKCSToMem(HCERTSTORE store, DWORD dwMsgAndCertEncodingType, void *handle)
Definition: serialize.c:691
#define TRACE(s)
Definition: solgame.cpp:4
#define SetLastError(x)
Definition: compat.h:417
int ret
_In_ DWORD dwMsgAndCertEncodingType
Definition: wincrypt.h:5080
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by CertSaveStore().

◆ CRYPT_SavePKCSToMem()

static BOOL CRYPT_SavePKCSToMem ( HCERTSTORE  store,
DWORD  dwMsgAndCertEncodingType,
void handle 
)
static

Definition at line 691 of file serialize.c.

693 {
694  CERT_BLOB *blob = handle;
695  CRYPT_SIGNED_INFO signedInfo = { 0 };
698  DWORD size;
699  BOOL ret = TRUE;
700 
701  TRACE("(%d, %p)\n", blob->pbData ? blob->cbData : 0, blob->pbData);
702 
703  do {
705  if (cert)
706  signedInfo.cCertEncoded++;
707  } while (cert);
708  if (signedInfo.cCertEncoded)
709  {
710  signedInfo.rgCertEncoded = CryptMemAlloc(
711  signedInfo.cCertEncoded * sizeof(CERT_BLOB));
712  if (!signedInfo.rgCertEncoded)
713  {
715  ret = FALSE;
716  }
717  else
718  {
719  DWORD i = 0;
720 
721  do {
723  if (cert)
724  {
725  signedInfo.rgCertEncoded[i].cbData = cert->cbCertEncoded;
726  signedInfo.rgCertEncoded[i].pbData = cert->pbCertEncoded;
727  i++;
728  }
729  } while (cert);
730  }
731  }
732 
733  do {
734  crl = CertEnumCRLsInStore(store, crl);
735  if (crl)
736  signedInfo.cCrlEncoded++;
737  } while (crl);
738  if (signedInfo.cCrlEncoded)
739  {
740  signedInfo.rgCrlEncoded = CryptMemAlloc(
741  signedInfo.cCrlEncoded * sizeof(CERT_BLOB));
742  if (!signedInfo.rgCrlEncoded)
743  {
745  ret = FALSE;
746  }
747  else
748  {
749  DWORD i = 0;
750 
751  do {
752  crl = CertEnumCRLsInStore(store, crl);
753  if (crl)
754  {
755  signedInfo.rgCrlEncoded[i].cbData = crl->cbCrlEncoded;
756  signedInfo.rgCrlEncoded[i].pbData = crl->pbCrlEncoded;
757  i++;
758  }
759  } while (crl);
760  }
761  }
762  if (ret)
763  {
764  ret = CRYPT_AsnEncodeCMSSignedInfo(&signedInfo, NULL, &size);
765  if (ret)
766  {
767  if (!blob->pbData)
768  blob->cbData = size;
769  else if (blob->cbData < size)
770  {
771  blob->cbData = size;
773  ret = FALSE;
774  }
775  else
776  {
777  blob->cbData = size;
778  ret = CRYPT_AsnEncodeCMSSignedInfo(&signedInfo, blob->pbData,
779  &blob->cbData);
780  }
781  }
782  }
783  CryptMemFree(signedInfo.rgCertEncoded);
784  CryptMemFree(signedInfo.rgCrlEncoded);
785  TRACE("returning %d\n", ret);
786  return ret;
787 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#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
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
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:131
BOOL CRYPT_AsnEncodeCMSSignedInfo(CRYPT_SIGNED_INFO *, void *pvData, DWORD *pcbData) DECLSPEC_HIDDEN
Definition: encode.c:4307
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
static BYTE cert[]
Definition: msg.c:1437
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
int ret
BYTE * pbData
Definition: wincrypt.h:103
#define ERROR_MORE_DATA
Definition: dderror.h:13
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev)
Definition: store.c:928
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:141
PCERT_BLOB rgCertEncoded
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by CertSaveStore(), and CRYPT_SavePKCSToFile().

◆ CRYPT_SaveSerializedToFile()

static BOOL CRYPT_SaveSerializedToFile ( HCERTSTORE  store,
DWORD  dwMsgAndCertEncodingType,
void handle 
)
static

Definition at line 818 of file serialize.c.

820 {
822 }
static BOOL CRYPT_WriteSerializedStoreToFile(HANDLE file, HCERTSTORE store)
Definition: serialize.c:684

Referenced by CertSaveStore().

◆ CRYPT_SaveSerializedToMem()

static BOOL CRYPT_SaveSerializedToMem ( HCERTSTORE  store,
DWORD  dwMsgAndCertEncodingType,
void handle 
)
static

Definition at line 861 of file serialize.c.

863 {
864  CERT_BLOB *blob = handle;
865  DWORD size = 0;
866  BOOL ret;
867 
869  &size);
870  if (ret)
871  {
872  if (!blob->pbData)
873  blob->cbData = size;
874  else if (blob->cbData < size)
875  {
877  blob->cbData = size;
878  ret = FALSE;
879  }
880  else
881  {
882  struct MemWrittenTracker tracker = { blob->cbData, blob->pbData,
883  0 };
884 
886  &tracker);
887  if (!ret && GetLastError() == ERROR_MORE_DATA)
888  blob->cbData = tracker.written;
889  }
890  }
891  TRACE("returning %d\n", ret);
892  return ret;
893 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
Definition: image.c:133
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static BOOL CRYPT_CountSerializedBytes(void *handle, const void *buffer, DWORD size)
Definition: serialize.c:854
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL CRYPT_WriteSerializedStoreToStream(HCERTSTORE store, SerializedOutputFunc output, void *handle)
Definition: serialize.c:645
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
int ret
#define ERROR_MORE_DATA
Definition: dderror.h:13
static BOOL CRYPT_MemOutputFunc(void *handle, const void *buffer, DWORD size)
Definition: serialize.c:832

Referenced by CertSaveStore().

◆ CRYPT_SerializeCertNoHash()

static BOOL WINAPI CRYPT_SerializeCertNoHash ( PCCERT_CONTEXT  pCertContext,
DWORD  dwFlags,
BYTE pbElement,
DWORD pcbElement 
)
static

Definition at line 586 of file serialize.c.

588 {
591  CERT_CERT_PROP_ID, pCertInterface, dwFlags, TRUE, pbElement, pcbElement);
592 }
#define TRUE
Definition: types.h:120
static BOOL CRYPT_SerializeStoreElement(const void *context, const BYTE *encodedContext, DWORD cbEncodedContext, DWORD contextPropID, const WINE_CONTEXT_INTERFACE *contextInterface, DWORD dwFlags, BOOL omitHashes, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:42
#define CERT_CERT_PROP_ID
BYTE * pbCertEncoded
Definition: wincrypt.h:480
DWORD cbCertEncoded
Definition: wincrypt.h:481
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
const WINE_CONTEXT_INTERFACE * pCertInterface
Definition: store.c:54
_In_ PCCERT_CONTEXT pCertContext
Definition: wincrypt.h:4840

Referenced by CRYPT_WriteSerializedStoreToStream().

◆ CRYPT_SerializeContextsToStream()

static BOOL CRYPT_SerializeContextsToStream ( SerializedOutputFunc  output,
void handle,
const WINE_CONTEXT_INTERFACE contextInterface,
HCERTSTORE  store 
)
static

Definition at line 613 of file serialize.c.

615 {
616  const void *context = NULL;
617  BOOL ret;
618 
619  do {
620  context = contextInterface->enumContextsInStore(store, context);
621  if (context)
622  {
623  DWORD size = 0;
624  LPBYTE buf = NULL;
625 
626  ret = contextInterface->serialize(context, 0, NULL, &size);
627  if (size)
629  if (buf)
630  {
631  ret = contextInterface->serialize(context, 0, buf, &size);
632  if (ret)
633  ret = output(handle, buf, size);
634  }
635  CryptMemFree(buf);
636  }
637  else
638  ret = TRUE;
639  } while (ret && context != NULL);
640  if (context)
642  return ret;
643 }
static context_t * context_from_ptr(const void *ptr)
#define TRUE
Definition: types.h:120
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
Definition: http.c:6587
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
void Context_Release(context_t *context)
Definition: context.c:106
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:131
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
SerializeElementFunc serialize
GLsizeiptr size
Definition: glext.h:5919
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
EnumContextsInStoreFunc enumContextsInStore
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:141

Referenced by CRYPT_WriteSerializedStoreToStream().

◆ CRYPT_SerializeCRLNoHash()

static BOOL WINAPI CRYPT_SerializeCRLNoHash ( PCCRL_CONTEXT  pCrlContext,
DWORD  dwFlags,
BYTE pbElement,
DWORD pcbElement 
)
static

Definition at line 594 of file serialize.c.

596 {
599  CERT_CRL_PROP_ID, pCRLInterface, dwFlags, TRUE, pbElement, pcbElement);
600 }
const WINE_CONTEXT_INTERFACE * pCRLInterface
Definition: store.c:67
#define TRUE
Definition: types.h:120
static BOOL CRYPT_SerializeStoreElement(const void *context, const BYTE *encodedContext, DWORD cbEncodedContext, DWORD contextPropID, const WINE_CONTEXT_INTERFACE *contextInterface, DWORD dwFlags, BOOL omitHashes, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:42
BYTE * pbCrlEncoded
Definition: wincrypt.h:620
DWORD cbCrlEncoded
Definition: wincrypt.h:621
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ PCCRL_CONTEXT pCrlContext
Definition: wincrypt.h:4996
#define CERT_CRL_PROP_ID

Referenced by CRYPT_WriteSerializedStoreToStream().

◆ CRYPT_SerializeCTLNoHash()

static BOOL WINAPI CRYPT_SerializeCTLNoHash ( PCCTL_CONTEXT  pCtlContext,
DWORD  dwFlags,
BYTE pbElement,
DWORD pcbElement 
)
static

Definition at line 602 of file serialize.c.

604 {
607  CERT_CTL_PROP_ID, pCTLInterface, dwFlags, TRUE, pbElement, pcbElement);
608 }
#define TRUE
Definition: types.h:120
static BOOL CRYPT_SerializeStoreElement(const void *context, const BYTE *encodedContext, DWORD cbEncodedContext, DWORD contextPropID, const WINE_CONTEXT_INTERFACE *contextInterface, DWORD dwFlags, BOOL omitHashes, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:42
const WINE_CONTEXT_INTERFACE * pCTLInterface
Definition: store.c:80
#define CERT_CTL_PROP_ID
DWORD cbCtlEncoded
Definition: wincrypt.h:746
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ PCCTL_CONTEXT pCtlContext
Definition: wincrypt.h:5005
BYTE * pbCtlEncoded
Definition: wincrypt.h:745

Referenced by CRYPT_WriteSerializedStoreToStream().

◆ CRYPT_SerializeStoreElement()

static BOOL CRYPT_SerializeStoreElement ( const void context,
const BYTE encodedContext,
DWORD  cbEncodedContext,
DWORD  contextPropID,
const WINE_CONTEXT_INTERFACE contextInterface,
DWORD  dwFlags,
BOOL  omitHashes,
BYTE pbElement,
DWORD pcbElement 
)
static

Definition at line 42 of file serialize.c.

46 {
47  BOOL ret;
48 
49  TRACE("(%p, %p, %08x, %d, %p, %p)\n", context, contextInterface, dwFlags,
50  omitHashes, pbElement, pcbElement);
51 
52  if (context)
53  {
54  DWORD bytesNeeded = sizeof(WINE_CERT_PROP_HEADER) + cbEncodedContext;
55  DWORD prop = 0;
56 
57  ret = TRUE;
58  do {
59  prop = contextInterface->enumProps(context, prop);
60  if (prop && (!omitHashes || !IS_CERT_HASH_PROP_ID(prop)))
61  {
62  DWORD propSize = 0;
63 
64  ret = contextInterface->getProp(context, prop, NULL, &propSize);
65  if (ret)
66  bytesNeeded += sizeof(WINE_CERT_PROP_HEADER) + propSize;
67  }
68  } while (ret && prop != 0);
69 
70  if (!pbElement)
71  {
72  *pcbElement = bytesNeeded;
73  ret = TRUE;
74  }
75  else if (*pcbElement < bytesNeeded)
76  {
77  *pcbElement = bytesNeeded;
79  ret = FALSE;
80  }
81  else
82  {
84  DWORD bufSize = 0;
85  LPBYTE buf = NULL;
86 
87  prop = 0;
88  do {
89  prop = contextInterface->enumProps(context, prop);
90  if (prop && (!omitHashes || !IS_CERT_HASH_PROP_ID(prop)))
91  {
92  DWORD propSize = 0;
93 
94  ret = contextInterface->getProp(context, prop, NULL,
95  &propSize);
96  if (ret)
97  {
98  if (bufSize < propSize)
99  {
100  if (buf)
101  buf = CryptMemRealloc(buf, propSize);
102  else
103  buf = CryptMemAlloc(propSize);
104  bufSize = propSize;
105  }
106  if (buf)
107  {
108  ret = contextInterface->getProp(context, prop, buf,
109  &propSize);
110  if (ret)
111  {
112  hdr = (WINE_CERT_PROP_HEADER*)pbElement;
113  hdr->propID = prop;
114  hdr->unknown = 1;
115  hdr->cb = propSize;
116  pbElement += sizeof(WINE_CERT_PROP_HEADER);
117  if (propSize)
118  {
119  memcpy(pbElement, buf, propSize);
120  pbElement += propSize;
121  }
122  }
123  }
124  else
125  ret = FALSE;
126  }
127  }
128  } while (ret && prop != 0);
129  CryptMemFree(buf);
130 
131  hdr = (WINE_CERT_PROP_HEADER*)pbElement;
132  hdr->propID = contextPropID;
133  hdr->unknown = 1;
134  hdr->cb = cbEncodedContext;
135  memcpy(pbElement + sizeof(WINE_CERT_PROP_HEADER),
136  encodedContext, cbEncodedContext);
137  }
138  }
139  else
140  ret = FALSE;
141  return ret;
142 }
#define TRUE
Definition: types.h:120
char hdr[14]
Definition: iptest.cpp:33
Definition: http.c:6587
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
EnumPropertiesFunc enumProps
#define IS_CERT_HASH_PROP_ID(x)
Definition: wincrypt.h:2751
GLuint GLsizei bufSize
Definition: glext.h:6040
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:131
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
struct _WINE_CERT_PROP_HEADER WINE_CERT_PROP_HEADER
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
Definition: main.c:136
int ret
GetContextPropertyFunc getProp
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERROR_MORE_DATA
Definition: dderror.h:13
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:141

Referenced by CertSerializeCertificateStoreElement(), CertSerializeCRLStoreElement(), CertSerializeCTLStoreElement(), CRYPT_SerializeCertNoHash(), CRYPT_SerializeCRLNoHash(), and CRYPT_SerializeCTLNoHash().

◆ CRYPT_WriteSerializedStoreToFile()

static BOOL CRYPT_WriteSerializedStoreToFile ( HANDLE  file,
HCERTSTORE  store 
)
static

Definition at line 684 of file serialize.c.

685 {
688  file);
689 }
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
static BOOL CRYPT_WriteSerializedStoreToStream(HCERTSTORE store, SerializedOutputFunc output, void *handle)
Definition: serialize.c:645
smooth NULL
Definition: ftsmooth.c:416
static BOOL CRYPT_FileOutputFunc(void *handle, const void *buffer, DWORD size)
Definition: serialize.c:679
#define FILE_BEGIN
Definition: winbase.h:112
Definition: fci.c:126

Referenced by CRYPT_SaveSerializedToFile().

◆ CRYPT_WriteSerializedStoreToStream()

static BOOL CRYPT_WriteSerializedStoreToStream ( HCERTSTORE  store,
SerializedOutputFunc  output,
void handle 
)
static

Definition at line 645 of file serialize.c.

647 {
648  static const BYTE fileTrailer[12] = { 0 };
650  BOOL ret;
651 
652  ret = output(handle, fileHeader, sizeof(fileHeader));
653  if (ret)
654  {
655  interface = *pCertInterface;
658  store);
659  }
660  if (ret)
661  {
662  interface = *pCRLInterface;
665  store);
666  }
667  if (ret)
668  {
669  interface = *pCTLInterface;
672  store);
673  }
674  if (ret)
675  ret = output(handle, fileTrailer, sizeof(fileTrailer));
676  return ret;
677 }
const WINE_CONTEXT_INTERFACE * pCRLInterface
Definition: store.c:67
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
const WINE_CONTEXT_INTERFACE * pCTLInterface
Definition: store.c:80
static BOOL CRYPT_SerializeContextsToStream(SerializedOutputFunc output, void *handle, const WINE_CONTEXT_INTERFACE *contextInterface, HCERTSTORE store)
Definition: serialize.c:613
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL(WINAPI * SerializeElementFunc)(const void *context, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
int ret
static BOOL WINAPI CRYPT_SerializeCertNoHash(PCCERT_CONTEXT pCertContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:586
static const BYTE fileHeader[]
Definition: serialize.c:426
unsigned char BYTE
Definition: mem.h:68
#define interface
Definition: basetyps.h:61
static BOOL WINAPI CRYPT_SerializeCTLNoHash(PCCTL_CONTEXT pCtlContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:602
const WINE_CONTEXT_INTERFACE * pCertInterface
Definition: store.c:54
static BOOL WINAPI CRYPT_SerializeCRLNoHash(PCCRL_CONTEXT pCrlContext, DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
Definition: serialize.c:594

Referenced by CRYPT_SaveSerializedToMem(), and CRYPT_WriteSerializedStoreToFile().

◆ read_blob_wrapper()

static BOOL read_blob_wrapper ( void handle,
void buffer,
DWORD  bytesToRead,
DWORD bytesRead 
)
static

Definition at line 555 of file serialize.c.

557 {
558  struct BlobReader *reader = handle;
559  BOOL ret;
560 
561  if (reader->current < reader->blob->cbData)
562  {
563  *bytesRead = min(bytesToRead, reader->blob->cbData - reader->current);
564  memcpy(buffer, reader->blob->pbData + reader->current, *bytesRead);
565  reader->current += *bytesRead;
566  ret = TRUE;
567  }
568  else if (reader->current == reader->blob->cbData)
569  {
570  *bytesRead = 0;
571  ret = TRUE;
572  }
573  else
574  ret = FALSE;
575  return ret;
576 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
GLuint buffer
Definition: glext.h:5915
unsigned int BOOL
Definition: ntddk_ex.h:94
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
Definition: reader.h:83

Referenced by CRYPT_ReadSerializedStoreFromBlob().

◆ read_file_wrapper()

static BOOL read_file_wrapper ( void handle,
void buffer,
DWORD  bytesToRead,
DWORD bytesRead 
)
static

Definition at line 538 of file serialize.c.

540 {
541  return ReadFile(handle, buffer, bytesToRead, bytesRead, NULL);
542 }
GLuint buffer
Definition: glext.h:5915
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123

Referenced by CRYPT_ReadSerializedStoreFromFile().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( crypt  )

Variable Documentation

◆ fileHeader

const BYTE fileHeader[] = { 0, 0, 0, 0, 'C','E','R','T' }
static

Definition at line 426 of file serialize.c.

Referenced by CRYPT_ReadSerializedStore(), and CRYPT_WriteSerializedStoreToStream().