2 * Copyright 2004-2007 Juan Lang
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
26 #include "wine/debug.h"
27 #include "wine/exception.h"
28 #include "crypt32_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
32 /* An extended certificate property in serialized form is prefixed by this
35 typedef struct _WINE_CERT_PROP_HEADER
38 DWORD unknown
; /* always 1 */
40 } WINE_CERT_PROP_HEADER
, *PWINE_CERT_PROP_HEADER
;
42 static BOOL
CRYPT_SerializeStoreElement(const void *context
,
43 const BYTE
*encodedContext
, DWORD cbEncodedContext
, DWORD contextPropID
,
44 PCWINE_CONTEXT_INTERFACE contextInterface
, DWORD dwFlags
, BOOL omitHashes
,
45 BYTE
*pbElement
, DWORD
*pcbElement
)
49 TRACE("(%p, %p, %08x, %d, %p, %p)\n", context
, contextInterface
, dwFlags
,
50 omitHashes
, pbElement
, pcbElement
);
54 DWORD bytesNeeded
= sizeof(WINE_CERT_PROP_HEADER
) + cbEncodedContext
;
59 prop
= contextInterface
->enumProps(context
, prop
);
60 if (prop
&& (!omitHashes
|| !IS_CERT_HASH_PROP_ID(prop
)))
64 ret
= contextInterface
->getProp(context
, prop
, NULL
, &propSize
);
66 bytesNeeded
+= sizeof(WINE_CERT_PROP_HEADER
) + propSize
;
68 } while (ret
&& prop
!= 0);
72 *pcbElement
= bytesNeeded
;
75 else if (*pcbElement
< bytesNeeded
)
77 *pcbElement
= bytesNeeded
;
78 SetLastError(ERROR_MORE_DATA
);
83 PWINE_CERT_PROP_HEADER hdr
;
89 prop
= contextInterface
->enumProps(context
, prop
);
90 if (prop
&& (!omitHashes
|| !IS_CERT_HASH_PROP_ID(prop
)))
94 ret
= contextInterface
->getProp(context
, prop
, NULL
,
98 if (bufSize
< propSize
)
101 buf
= CryptMemRealloc(buf
, propSize
);
103 buf
= CryptMemAlloc(propSize
);
108 ret
= contextInterface
->getProp(context
, prop
, buf
,
112 hdr
= (PWINE_CERT_PROP_HEADER
)pbElement
;
116 pbElement
+= sizeof(WINE_CERT_PROP_HEADER
);
119 memcpy(pbElement
, buf
, propSize
);
120 pbElement
+= propSize
;
128 } while (ret
&& prop
!= 0);
131 hdr
= (PWINE_CERT_PROP_HEADER
)pbElement
;
132 hdr
->propID
= contextPropID
;
134 hdr
->cb
= cbEncodedContext
;
135 memcpy(pbElement
+ sizeof(WINE_CERT_PROP_HEADER
),
136 encodedContext
, cbEncodedContext
);
144 BOOL WINAPI
CertSerializeCertificateStoreElement(PCCERT_CONTEXT pCertContext
,
145 DWORD dwFlags
, BYTE
*pbElement
, DWORD
*pcbElement
)
147 return CRYPT_SerializeStoreElement(pCertContext
,
148 pCertContext
->pbCertEncoded
, pCertContext
->cbCertEncoded
,
149 CERT_CERT_PROP_ID
, pCertInterface
, dwFlags
, FALSE
, pbElement
, pcbElement
);
152 BOOL WINAPI
CertSerializeCRLStoreElement(PCCRL_CONTEXT pCrlContext
,
153 DWORD dwFlags
, BYTE
*pbElement
, DWORD
*pcbElement
)
155 return CRYPT_SerializeStoreElement(pCrlContext
,
156 pCrlContext
->pbCrlEncoded
, pCrlContext
->cbCrlEncoded
,
157 CERT_CRL_PROP_ID
, pCRLInterface
, dwFlags
, FALSE
, pbElement
, pcbElement
);
160 BOOL WINAPI
CertSerializeCTLStoreElement(PCCTL_CONTEXT pCtlContext
,
161 DWORD dwFlags
, BYTE
*pbElement
, DWORD
*pcbElement
)
163 return CRYPT_SerializeStoreElement(pCtlContext
,
164 pCtlContext
->pbCtlEncoded
, pCtlContext
->cbCtlEncoded
,
165 CERT_CTL_PROP_ID
, pCTLInterface
, dwFlags
, FALSE
, pbElement
, pcbElement
);
168 /* Looks for the property with ID propID in the buffer buf. Returns a pointer
169 * to its header if a valid header is found, NULL if not. Valid means the
170 * length of thte property won't overrun buf, and the unknown field is 1.
172 static const WINE_CERT_PROP_HEADER
*CRYPT_findPropID(const BYTE
*buf
,
173 DWORD size
, DWORD propID
)
175 const WINE_CERT_PROP_HEADER
*ret
= NULL
;
178 while (size
&& !ret
&& !done
)
180 if (size
< sizeof(WINE_CERT_PROP_HEADER
))
182 SetLastError(CRYPT_E_FILE_ERROR
);
187 const WINE_CERT_PROP_HEADER
*hdr
=
188 (const WINE_CERT_PROP_HEADER
*)buf
;
190 size
-= sizeof(WINE_CERT_PROP_HEADER
);
191 buf
+= sizeof(WINE_CERT_PROP_HEADER
);
194 SetLastError(E_INVALIDARG
);
197 else if (!hdr
->propID
)
199 /* assume a zero prop ID means the data are uninitialized, so
204 else if (hdr
->unknown
!= 1)
206 SetLastError(ERROR_FILE_NOT_FOUND
);
209 else if (hdr
->propID
== propID
)
221 static BOOL
CRYPT_ReadContextProp(
222 const WINE_CONTEXT_INTERFACE
*contextInterface
, const void *context
,
223 const WINE_CERT_PROP_HEADER
*hdr
, const BYTE
*pbElement
, DWORD cbElement
)
227 if (cbElement
< hdr
->cb
)
229 SetLastError(E_INVALIDARG
);
232 else if (hdr
->unknown
!= 1)
234 SetLastError(ERROR_FILE_NOT_FOUND
);
237 else if (hdr
->propID
!= CERT_CERT_PROP_ID
&&
238 hdr
->propID
!= CERT_CRL_PROP_ID
&& hdr
->propID
!= CERT_CTL_PROP_ID
)
240 /* Have to create a blob for most types, but not
245 case CERT_AUTO_ENROLL_PROP_ID
:
246 case CERT_CTL_USAGE_PROP_ID
:
247 case CERT_DESCRIPTION_PROP_ID
:
248 case CERT_FRIENDLY_NAME_PROP_ID
:
249 case CERT_HASH_PROP_ID
:
250 case CERT_KEY_IDENTIFIER_PROP_ID
:
251 case CERT_MD5_HASH_PROP_ID
:
252 case CERT_NEXT_UPDATE_LOCATION_PROP_ID
:
253 case CERT_PUBKEY_ALG_PARA_PROP_ID
:
254 case CERT_PVK_FILE_PROP_ID
:
255 case CERT_SIGNATURE_HASH_PROP_ID
:
256 case CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID
:
257 case CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID
:
258 case CERT_ENROLLMENT_PROP_ID
:
259 case CERT_CROSS_CERT_DIST_POINTS_PROP_ID
:
260 case CERT_RENEWAL_PROP_ID
:
262 CRYPT_DATA_BLOB blob
= { hdr
->cb
,
265 ret
= contextInterface
->setProp(context
,
266 hdr
->propID
, 0, &blob
);
269 case CERT_DATE_STAMP_PROP_ID
:
270 ret
= contextInterface
->setProp(context
,
271 hdr
->propID
, 0, pbElement
);
273 case CERT_KEY_PROV_INFO_PROP_ID
:
275 PCRYPT_KEY_PROV_INFO info
=
276 (PCRYPT_KEY_PROV_INFO
)pbElement
;
278 CRYPT_FixKeyProvInfoPointers(info
);
279 ret
= contextInterface
->setProp(context
,
280 hdr
->propID
, 0, pbElement
);
289 /* ignore the context itself */
295 const void *CRYPT_ReadSerializedElement(const BYTE
*pbElement
, DWORD cbElement
,
296 DWORD dwContextTypeFlags
, DWORD
*pdwContentType
)
300 TRACE("(%p, %d, %08x, %p)\n", pbElement
, cbElement
, dwContextTypeFlags
,
305 SetLastError(ERROR_END_OF_MEDIA
);
311 const WINE_CONTEXT_INTERFACE
*contextInterface
= NULL
;
312 const WINE_CERT_PROP_HEADER
*hdr
= NULL
;
318 if (dwContextTypeFlags
== CERT_STORE_ALL_CONTEXT_FLAG
)
320 hdr
= CRYPT_findPropID(pbElement
, cbElement
, CERT_CERT_PROP_ID
);
322 type
= CERT_STORE_CERTIFICATE_CONTEXT
;
325 hdr
= CRYPT_findPropID(pbElement
, cbElement
, CERT_CRL_PROP_ID
);
327 type
= CERT_STORE_CRL_CONTEXT
;
330 hdr
= CRYPT_findPropID(pbElement
, cbElement
,
333 type
= CERT_STORE_CTL_CONTEXT
;
337 else if (dwContextTypeFlags
& CERT_STORE_CERTIFICATE_CONTEXT_FLAG
)
339 hdr
= CRYPT_findPropID(pbElement
, cbElement
, CERT_CERT_PROP_ID
);
340 type
= CERT_STORE_CERTIFICATE_CONTEXT
;
342 else if (dwContextTypeFlags
& CERT_STORE_CRL_CONTEXT_FLAG
)
344 hdr
= CRYPT_findPropID(pbElement
, cbElement
, CERT_CRL_PROP_ID
);
345 type
= CERT_STORE_CRL_CONTEXT
;
347 else if (dwContextTypeFlags
& CERT_STORE_CTL_CONTEXT_FLAG
)
349 hdr
= CRYPT_findPropID(pbElement
, cbElement
, CERT_CTL_PROP_ID
);
350 type
= CERT_STORE_CTL_CONTEXT
;
355 case CERT_STORE_CERTIFICATE_CONTEXT
:
356 contextInterface
= pCertInterface
;
358 case CERT_STORE_CRL_CONTEXT
:
359 contextInterface
= pCRLInterface
;
361 case CERT_STORE_CTL_CONTEXT
:
362 contextInterface
= pCTLInterface
;
365 SetLastError(E_INVALIDARG
);
372 context
= contextInterface
->create(X509_ASN_ENCODING
,
373 (BYTE
*)hdr
+ sizeof(WINE_CERT_PROP_HEADER
), hdr
->cb
);
376 BOOL noMoreProps
= FALSE
;
378 while (!noMoreProps
&& ret
)
380 if (cbElement
< sizeof(WINE_CERT_PROP_HEADER
))
384 const WINE_CERT_PROP_HEADER
*hdr
=
385 (const WINE_CERT_PROP_HEADER
*)pbElement
;
387 TRACE("prop is %d\n", hdr
->propID
);
388 cbElement
-= sizeof(WINE_CERT_PROP_HEADER
);
389 pbElement
+= sizeof(WINE_CERT_PROP_HEADER
);
392 /* Like in CRYPT_findPropID, stop if the propID is zero
397 ret
= CRYPT_ReadContextProp(contextInterface
, context
,
398 hdr
, pbElement
, cbElement
);
399 pbElement
+= hdr
->cb
;
400 cbElement
-= hdr
->cb
;
408 *pdwContentType
= type
;
412 contextInterface
->free(context
);
419 SetLastError(STATUS_ACCESS_VIOLATION
);
426 static const BYTE fileHeader
[] = { 0, 0, 0, 0, 'C','E','R','T' };
428 BOOL
CRYPT_ReadSerializedStoreFromFile(HANDLE file
, HCERTSTORE store
)
430 BYTE fileHeaderBuf
[sizeof(fileHeader
)];
434 /* Failure reading is non-critical, we'll leave the store empty */
435 ret
= ReadFile(file
, fileHeaderBuf
, sizeof(fileHeaderBuf
), &read
, NULL
);
439 ; /* an empty file is okay */
440 else if (read
!= sizeof(fileHeaderBuf
))
442 else if (!memcmp(fileHeaderBuf
, fileHeader
, read
))
444 WINE_CERT_PROP_HEADER propHdr
;
445 const void *context
= NULL
;
446 const WINE_CONTEXT_INTERFACE
*contextInterface
= NULL
;
451 ret
= ReadFile(file
, &propHdr
, sizeof(propHdr
), &read
, NULL
);
452 if (ret
&& read
== sizeof(propHdr
))
454 if (contextInterface
&& context
&&
455 (propHdr
.propID
== CERT_CERT_PROP_ID
||
456 propHdr
.propID
== CERT_CRL_PROP_ID
||
457 propHdr
.propID
== CERT_CTL_PROP_ID
))
459 /* We have a new context, so free the existing one */
460 contextInterface
->free(context
);
462 if (propHdr
.cb
> bufSize
)
464 /* Not reusing realloc, because the old data aren't
468 buf
= CryptMemAlloc(propHdr
.cb
);
469 bufSize
= propHdr
.cb
;
473 ret
= ReadFile(file
, buf
, propHdr
.cb
, &read
, NULL
);
474 if (ret
&& read
== propHdr
.cb
)
476 if (propHdr
.propID
== CERT_CERT_PROP_ID
)
478 contextInterface
= pCertInterface
;
479 ret
= contextInterface
->addEncodedToStore(store
,
480 X509_ASN_ENCODING
, buf
, read
,
481 CERT_STORE_ADD_NEW
, &context
);
483 else if (propHdr
.propID
== CERT_CRL_PROP_ID
)
485 contextInterface
= pCRLInterface
;
486 ret
= contextInterface
->addEncodedToStore(store
,
487 X509_ASN_ENCODING
, buf
, read
,
488 CERT_STORE_ADD_NEW
, &context
);
490 else if (propHdr
.propID
== CERT_CTL_PROP_ID
)
492 contextInterface
= pCTLInterface
;
493 ret
= contextInterface
->addEncodedToStore(store
,
494 X509_ASN_ENCODING
, buf
, read
,
495 CERT_STORE_ADD_NEW
, &context
);
498 ret
= CRYPT_ReadContextProp(contextInterface
,
499 context
, &propHdr
, buf
, read
);
505 } while (ret
&& read
> 0);
506 if (contextInterface
&& context
)
508 /* Free the last context added */
509 contextInterface
->free(context
);
522 static BOOL WINAPI
CRYPT_SerializeCertNoHash(PCCERT_CONTEXT pCertContext
,
523 DWORD dwFlags
, BYTE
*pbElement
, DWORD
*pcbElement
)
525 return CRYPT_SerializeStoreElement(pCertContext
,
526 pCertContext
->pbCertEncoded
, pCertContext
->cbCertEncoded
,
527 CERT_CERT_PROP_ID
, pCertInterface
, dwFlags
, TRUE
, pbElement
, pcbElement
);
530 static BOOL WINAPI
CRYPT_SerializeCRLNoHash(PCCRL_CONTEXT pCrlContext
,
531 DWORD dwFlags
, BYTE
*pbElement
, DWORD
*pcbElement
)
533 return CRYPT_SerializeStoreElement(pCrlContext
,
534 pCrlContext
->pbCrlEncoded
, pCrlContext
->cbCrlEncoded
,
535 CERT_CRL_PROP_ID
, pCRLInterface
, dwFlags
, TRUE
, pbElement
, pcbElement
);
538 static BOOL WINAPI
CRYPT_SerializeCTLNoHash(PCCTL_CONTEXT pCtlContext
,
539 DWORD dwFlags
, BYTE
*pbElement
, DWORD
*pcbElement
)
541 return CRYPT_SerializeStoreElement(pCtlContext
,
542 pCtlContext
->pbCtlEncoded
, pCtlContext
->cbCtlEncoded
,
543 CERT_CTL_PROP_ID
, pCTLInterface
, dwFlags
, TRUE
, pbElement
, pcbElement
);
546 typedef BOOL (*SerializedOutputFunc
)(void *handle
, const void *buffer
,
549 static BOOL
CRYPT_SerializeContextsToStream(SerializedOutputFunc output
,
550 void *handle
, const WINE_CONTEXT_INTERFACE
*contextInterface
, HCERTSTORE store
)
552 const void *context
= NULL
;
556 context
= contextInterface
->enumContextsInStore(store
, context
);
562 ret
= contextInterface
->serialize(context
, 0, NULL
, &size
);
564 buf
= CryptMemAlloc(size
);
567 ret
= contextInterface
->serialize(context
, 0, buf
, &size
);
569 ret
= output(handle
, buf
, size
);
575 } while (ret
&& context
!= NULL
);
577 contextInterface
->free(context
);
581 static BOOL
CRYPT_WriteSerializedStoreToStream(HCERTSTORE store
,
582 SerializedOutputFunc output
, void *handle
)
584 static const BYTE fileTrailer
[12] = { 0 };
585 WINE_CONTEXT_INTERFACE interface
;
588 ret
= output(handle
, fileHeader
, sizeof(fileHeader
));
591 memcpy(&interface
, pCertInterface
, sizeof(interface
));
592 interface
.serialize
= (SerializeElementFunc
)CRYPT_SerializeCertNoHash
;
593 ret
= CRYPT_SerializeContextsToStream(output
, handle
, &interface
,
598 memcpy(&interface
, pCRLInterface
, sizeof(interface
));
599 interface
.serialize
= (SerializeElementFunc
)CRYPT_SerializeCRLNoHash
;
600 ret
= CRYPT_SerializeContextsToStream(output
, handle
, &interface
,
605 memcpy(&interface
, pCTLInterface
, sizeof(interface
));
606 interface
.serialize
= (SerializeElementFunc
)CRYPT_SerializeCTLNoHash
;
607 ret
= CRYPT_SerializeContextsToStream(output
, handle
, &interface
,
611 ret
= output(handle
, fileTrailer
, sizeof(fileTrailer
));
615 static BOOL
CRYPT_FileOutputFunc(void *handle
, const void *buffer
, DWORD size
)
617 return WriteFile(handle
, buffer
, size
, &size
, NULL
);
620 static BOOL
CRYPT_WriteSerializedStoreToFile(HANDLE file
, HCERTSTORE store
)
622 SetFilePointer(file
, 0, NULL
, FILE_BEGIN
);
623 return CRYPT_WriteSerializedStoreToStream(store
, CRYPT_FileOutputFunc
,
627 static BOOL
CRYPT_SavePKCSToMem(HCERTSTORE store
,
628 DWORD dwMsgAndCertEncodingType
, void *handle
)
630 CERT_BLOB
*blob
= (CERT_BLOB
*)handle
;
631 CRYPT_SIGNED_INFO signedInfo
= { 0 };
632 PCCERT_CONTEXT cert
= NULL
;
633 PCCRL_CONTEXT crl
= NULL
;
637 TRACE("(%d, %p)\n", blob
->pbData
? blob
->cbData
: 0, blob
->pbData
);
640 cert
= CertEnumCertificatesInStore(store
, cert
);
642 signedInfo
.cCertEncoded
++;
644 if (signedInfo
.cCertEncoded
)
646 signedInfo
.rgCertEncoded
= CryptMemAlloc(
647 signedInfo
.cCertEncoded
* sizeof(CERT_BLOB
));
648 if (!signedInfo
.rgCertEncoded
)
650 SetLastError(ERROR_OUTOFMEMORY
);
658 cert
= CertEnumCertificatesInStore(store
, cert
);
661 signedInfo
.rgCertEncoded
[i
].cbData
= cert
->cbCertEncoded
;
662 signedInfo
.rgCertEncoded
[i
].pbData
= cert
->pbCertEncoded
;
670 crl
= CertEnumCRLsInStore(store
, crl
);
672 signedInfo
.cCrlEncoded
++;
674 if (signedInfo
.cCrlEncoded
)
676 signedInfo
.rgCrlEncoded
= CryptMemAlloc(
677 signedInfo
.cCrlEncoded
* sizeof(CERT_BLOB
));
678 if (!signedInfo
.rgCrlEncoded
)
680 SetLastError(ERROR_OUTOFMEMORY
);
688 crl
= CertEnumCRLsInStore(store
, crl
);
691 signedInfo
.rgCrlEncoded
[i
].cbData
= crl
->cbCrlEncoded
;
692 signedInfo
.rgCrlEncoded
[i
].pbData
= crl
->pbCrlEncoded
;
700 ret
= CRYPT_AsnEncodeCMSSignedInfo(&signedInfo
, NULL
, &size
);
705 else if (blob
->cbData
< size
)
708 SetLastError(ERROR_MORE_DATA
);
714 ret
= CRYPT_AsnEncodeCMSSignedInfo(&signedInfo
, blob
->pbData
,
719 CryptMemFree(signedInfo
.rgCertEncoded
);
720 CryptMemFree(signedInfo
.rgCrlEncoded
);
721 TRACE("returning %d\n", ret
);
725 static BOOL
CRYPT_SavePKCSToFile(HCERTSTORE store
,
726 DWORD dwMsgAndCertEncodingType
, void *handle
)
728 CERT_BLOB blob
= { 0, NULL
};
731 TRACE("(%p)\n", handle
);
733 ret
= CRYPT_SavePKCSToMem(store
, dwMsgAndCertEncodingType
, &blob
);
736 blob
.pbData
= CryptMemAlloc(blob
.cbData
);
739 ret
= CRYPT_SavePKCSToMem(store
, dwMsgAndCertEncodingType
, &blob
);
741 ret
= WriteFile(handle
, blob
.pbData
, blob
.cbData
,
746 SetLastError(ERROR_OUTOFMEMORY
);
750 TRACE("returning %d\n", ret
);
754 static BOOL
CRYPT_SaveSerializedToFile(HCERTSTORE store
,
755 DWORD dwMsgAndCertEncodingType
, void *handle
)
757 return CRYPT_WriteSerializedStoreToFile(handle
, store
);
760 struct MemWrittenTracker
767 /* handle is a pointer to a MemWrittenTracker. Assumes its pointer is valid. */
768 static BOOL
CRYPT_MemOutputFunc(void *handle
, const void *buffer
, DWORD size
)
770 struct MemWrittenTracker
*tracker
= (struct MemWrittenTracker
*)handle
;
773 if (tracker
->written
+ size
> tracker
->cbData
)
775 SetLastError(ERROR_MORE_DATA
);
776 /* Update written so caller can notify its caller of the required size
778 tracker
->written
+= size
;
783 memcpy(tracker
->pbData
+ tracker
->written
, buffer
, size
);
784 tracker
->written
+= size
;
790 static BOOL
CRYPT_CountSerializedBytes(void *handle
, const void *buffer
,
793 *(DWORD
*)handle
+= size
;
797 static BOOL
CRYPT_SaveSerializedToMem(HCERTSTORE store
,
798 DWORD dwMsgAndCertEncodingType
, void *handle
)
800 CERT_BLOB
*blob
= (CERT_BLOB
*)handle
;
804 ret
= CRYPT_WriteSerializedStoreToStream(store
, CRYPT_CountSerializedBytes
,
810 else if (blob
->cbData
< size
)
812 SetLastError(ERROR_MORE_DATA
);
818 struct MemWrittenTracker tracker
= { blob
->cbData
, blob
->pbData
,
821 ret
= CRYPT_WriteSerializedStoreToStream(store
, CRYPT_MemOutputFunc
,
823 if (!ret
&& GetLastError() == ERROR_MORE_DATA
)
824 blob
->cbData
= tracker
.written
;
827 TRACE("returning %d\n", ret
);
831 BOOL WINAPI
CertSaveStore(HCERTSTORE hCertStore
, DWORD dwMsgAndCertEncodingType
,
832 DWORD dwSaveAs
, DWORD dwSaveTo
, void *pvSaveToPara
, DWORD dwFlags
)
834 BOOL (*saveFunc
)(HCERTSTORE
, DWORD
, void *);
838 TRACE("(%p, %08x, %d, %d, %p, %08x)\n", hCertStore
,
839 dwMsgAndCertEncodingType
, dwSaveAs
, dwSaveTo
, pvSaveToPara
, dwFlags
);
843 case CERT_STORE_SAVE_AS_STORE
:
844 case CERT_STORE_SAVE_AS_PKCS7
:
847 WARN("unimplemented for %d\n", dwSaveAs
);
848 SetLastError(ERROR_INVALID_PARAMETER
);
853 case CERT_STORE_SAVE_TO_FILE
:
854 handle
= pvSaveToPara
;
855 saveFunc
= dwSaveAs
== CERT_STORE_SAVE_AS_STORE
?
856 CRYPT_SaveSerializedToFile
: CRYPT_SavePKCSToFile
;
858 case CERT_STORE_SAVE_TO_FILENAME_A
:
859 handle
= CreateFileA((LPCSTR
)pvSaveToPara
, GENERIC_WRITE
, 0, NULL
,
860 CREATE_ALWAYS
, 0, NULL
);
861 saveFunc
= dwSaveAs
== CERT_STORE_SAVE_AS_STORE
?
862 CRYPT_SaveSerializedToFile
: CRYPT_SavePKCSToFile
;
864 case CERT_STORE_SAVE_TO_FILENAME_W
:
865 handle
= CreateFileW((LPCWSTR
)pvSaveToPara
, GENERIC_WRITE
, 0, NULL
,
866 CREATE_ALWAYS
, 0, NULL
);
867 saveFunc
= dwSaveAs
== CERT_STORE_SAVE_AS_STORE
?
868 CRYPT_SaveSerializedToFile
: CRYPT_SavePKCSToFile
;
870 case CERT_STORE_SAVE_TO_MEMORY
:
871 handle
= pvSaveToPara
;
872 saveFunc
= dwSaveAs
== CERT_STORE_SAVE_AS_STORE
?
873 CRYPT_SaveSerializedToMem
: CRYPT_SavePKCSToMem
;
876 WARN("unimplemented for %d\n", dwSaveTo
);
877 SetLastError(ERROR_INVALID_PARAMETER
);
880 ret
= saveFunc(hCertStore
, dwMsgAndCertEncodingType
, handle
);
881 TRACE("returning %d\n", ret
);
885 BOOL WINAPI
CertAddSerializedElementToStore(HCERTSTORE hCertStore
,
886 const BYTE
*pbElement
, DWORD cbElement
, DWORD dwAddDisposition
, DWORD dwFlags
,
887 DWORD dwContextTypeFlags
, DWORD
*pdwContentType
, const void **ppvContext
)
893 TRACE("(%p, %p, %d, %08x, %08x, %08x, %p, %p)\n", hCertStore
,
894 pbElement
, cbElement
, dwAddDisposition
, dwFlags
, dwContextTypeFlags
,
895 pdwContentType
, ppvContext
);
897 /* Call the internal function, then delete the hashes. Tests show this
898 * function uses real hash values, not whatever's stored in the hash
901 context
= CRYPT_ReadSerializedElement(pbElement
, cbElement
,
902 dwContextTypeFlags
, &type
);
905 const WINE_CONTEXT_INTERFACE
*contextInterface
= NULL
;
909 case CERT_STORE_CERTIFICATE_CONTEXT
:
910 contextInterface
= pCertInterface
;
912 case CERT_STORE_CRL_CONTEXT
:
913 contextInterface
= pCRLInterface
;
915 case CERT_STORE_CTL_CONTEXT
:
916 contextInterface
= pCTLInterface
;
919 SetLastError(E_INVALIDARG
);
921 if (contextInterface
)
923 contextInterface
->setProp(context
, CERT_HASH_PROP_ID
, 0, NULL
);
924 contextInterface
->setProp(context
, CERT_MD5_HASH_PROP_ID
, 0, NULL
);
925 contextInterface
->setProp(context
, CERT_SIGNATURE_HASH_PROP_ID
, 0,
928 *pdwContentType
= type
;
929 ret
= contextInterface
->addContextToStore(hCertStore
, context
,
930 dwAddDisposition
, ppvContext
);
931 contextInterface
->free(context
);