2 * Copyright 2004-2006 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
23 #define NONAMELESSUNION
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
31 #include "crypt32_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
35 /* Internal version of CertGetCertificateContextProperty that gets properties
36 * directly from the context (or the context it's linked to, depending on its
37 * type.) Doesn't handle special-case properties, since they are handled by
38 * CertGetCertificateContextProperty, and are particular to the store in which
39 * the property exists (which is separate from the context.)
41 static BOOL
CertContext_GetProperty(cert_t
*cert
, DWORD dwPropId
,
42 void *pvData
, DWORD
*pcbData
);
44 /* Internal version of CertSetCertificateContextProperty that sets properties
45 * directly on the context (or the context it's linked to, depending on its
46 * type.) Doesn't handle special cases, since they're handled by
47 * CertSetCertificateContextProperty anyway.
49 static BOOL
CertContext_SetProperty(cert_t
*cert
, DWORD dwPropId
,
50 DWORD dwFlags
, const void *pvData
);
52 BOOL WINAPI
CertAddEncodedCertificateToStore(HCERTSTORE hCertStore
,
53 DWORD dwCertEncodingType
, const BYTE
*pbCertEncoded
, DWORD cbCertEncoded
,
54 DWORD dwAddDisposition
, PCCERT_CONTEXT
*ppCertContext
)
56 PCCERT_CONTEXT cert
= CertCreateCertificateContext(dwCertEncodingType
,
57 pbCertEncoded
, cbCertEncoded
);
60 TRACE("(%p, %08x, %p, %d, %08x, %p)\n", hCertStore
, dwCertEncodingType
,
61 pbCertEncoded
, cbCertEncoded
, dwAddDisposition
, ppCertContext
);
65 ret
= CertAddCertificateContextToStore(hCertStore
, cert
,
66 dwAddDisposition
, ppCertContext
);
67 CertFreeCertificateContext(cert
);
74 BOOL WINAPI
CertAddEncodedCertificateToSystemStoreA(LPCSTR pszCertStoreName
,
75 const BYTE
*pbCertEncoded
, DWORD cbCertEncoded
)
80 TRACE("(%s, %p, %d)\n", debugstr_a(pszCertStoreName
), pbCertEncoded
,
83 store
= CertOpenSystemStoreA(0, pszCertStoreName
);
86 ret
= CertAddEncodedCertificateToStore(store
, X509_ASN_ENCODING
,
87 pbCertEncoded
, cbCertEncoded
, CERT_STORE_ADD_USE_EXISTING
, NULL
);
88 CertCloseStore(store
, 0);
93 BOOL WINAPI
CertAddEncodedCertificateToSystemStoreW(LPCWSTR pszCertStoreName
,
94 const BYTE
*pbCertEncoded
, DWORD cbCertEncoded
)
99 TRACE("(%s, %p, %d)\n", debugstr_w(pszCertStoreName
), pbCertEncoded
,
102 store
= CertOpenSystemStoreW(0, pszCertStoreName
);
105 ret
= CertAddEncodedCertificateToStore(store
, X509_ASN_ENCODING
,
106 pbCertEncoded
, cbCertEncoded
, CERT_STORE_ADD_USE_EXISTING
, NULL
);
107 CertCloseStore(store
, 0);
112 static const context_vtbl_t cert_vtbl
;
114 static void Cert_free(context_t
*context
)
116 cert_t
*cert
= (cert_t
*)context
;
118 CryptMemFree(cert
->ctx
.pbCertEncoded
);
119 LocalFree(cert
->ctx
.pCertInfo
);
122 static context_t
*Cert_clone(context_t
*context
, WINECRYPT_CERTSTORE
*store
, BOOL use_link
)
127 cert
= (cert_t
*)Context_CreateLinkContext(sizeof(CERT_CONTEXT
), context
, store
);
131 const cert_t
*cloned
= (const cert_t
*)context
;
135 cert
= (cert_t
*)Context_CreateDataContext(sizeof(CERT_CONTEXT
), &cert_vtbl
, store
);
139 Context_CopyProperties(&cert
->ctx
, &cloned
->ctx
);
141 cert
->ctx
.dwCertEncodingType
= cloned
->ctx
.dwCertEncodingType
;
142 cert
->ctx
.pbCertEncoded
= CryptMemAlloc(cloned
->ctx
.cbCertEncoded
);
143 memcpy(cert
->ctx
.pbCertEncoded
, cloned
->ctx
.pbCertEncoded
, cloned
->ctx
.cbCertEncoded
);
144 cert
->ctx
.cbCertEncoded
= cloned
->ctx
.cbCertEncoded
;
146 /* FIXME: We don't need to decode the object here, we could just clone cert info. */
147 res
= CryptDecodeObjectEx(cert
->ctx
.dwCertEncodingType
, X509_CERT_TO_BE_SIGNED
,
148 cert
->ctx
.pbCertEncoded
, cert
->ctx
.cbCertEncoded
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
149 &cert
->ctx
.pCertInfo
, &size
);
151 CertFreeCertificateContext(&cert
->ctx
);
156 cert
->ctx
.hCertStore
= store
;
160 static const context_vtbl_t cert_vtbl
= {
165 static BOOL
add_cert_to_store(WINECRYPT_CERTSTORE
*store
, const CERT_CONTEXT
*cert
,
166 DWORD add_disposition
, BOOL use_link
, PCCERT_CONTEXT
*ret_context
)
168 const CERT_CONTEXT
*existing
= NULL
;
169 BOOL ret
= TRUE
, inherit_props
= FALSE
;
170 context_t
*new_context
= NULL
;
172 switch (add_disposition
)
174 case CERT_STORE_ADD_ALWAYS
:
176 case CERT_STORE_ADD_NEW
:
177 case CERT_STORE_ADD_REPLACE_EXISTING
:
178 case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
:
179 case CERT_STORE_ADD_USE_EXISTING
:
180 case CERT_STORE_ADD_NEWER
:
181 case CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
:
184 DWORD size
= sizeof(hashToAdd
);
186 ret
= CertGetCertificateContextProperty(cert
, CERT_HASH_PROP_ID
,
190 CRYPT_HASH_BLOB blob
= { sizeof(hashToAdd
), hashToAdd
};
192 existing
= CertFindCertificateInStore(store
, cert
->dwCertEncodingType
, 0,
193 CERT_FIND_SHA1_HASH
, &blob
, NULL
);
198 FIXME("Unimplemented add disposition %d\n", add_disposition
);
199 SetLastError(E_INVALIDARG
);
203 switch (add_disposition
)
205 case CERT_STORE_ADD_ALWAYS
:
207 case CERT_STORE_ADD_NEW
:
210 TRACE("found matching certificate, not adding\n");
211 SetLastError(CRYPT_E_EXISTS
);
215 case CERT_STORE_ADD_REPLACE_EXISTING
:
217 case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
:
219 FIXME("CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES: semi-stub for links\n");
221 inherit_props
= TRUE
;
223 case CERT_STORE_ADD_USE_EXISTING
:
225 FIXME("CERT_STORE_ADD_USE_EXISTING: semi-stub for links\n");
228 Context_CopyProperties(existing
, cert
);
230 *ret_context
= CertDuplicateCertificateContext(existing
);
234 case CERT_STORE_ADD_NEWER
:
235 if (existing
&& CompareFileTime(&existing
->pCertInfo
->NotBefore
, &cert
->pCertInfo
->NotBefore
) >= 0)
237 TRACE("existing certificate is newer, not adding\n");
238 SetLastError(CRYPT_E_EXISTS
);
242 case CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
:
245 if (CompareFileTime(&existing
->pCertInfo
->NotBefore
, &cert
->pCertInfo
->NotBefore
) >= 0)
247 TRACE("existing certificate is newer, not adding\n");
248 SetLastError(CRYPT_E_EXISTS
);
251 inherit_props
= TRUE
;
256 /* FIXME: We have tests that this works, but what should we really do in this case? */
259 *ret_context
= CertDuplicateCertificateContext(cert
);
263 ret
= store
->vtbl
->certs
.addContext(store
, context_from_ptr(cert
), existing
? context_from_ptr(existing
) : NULL
,
264 (ret_context
|| inherit_props
) ? &new_context
: NULL
, use_link
);
269 Context_CopyProperties(context_ptr(new_context
), existing
);
272 *ret_context
= context_ptr(new_context
);
274 Context_Release(new_context
);
276 TRACE("returning %d\n", ret
);
280 BOOL WINAPI
CertAddCertificateContextToStore(HCERTSTORE hCertStore
, PCCERT_CONTEXT pCertContext
,
281 DWORD dwAddDisposition
, PCCERT_CONTEXT
*ppStoreContext
)
283 WINECRYPT_CERTSTORE
*store
= hCertStore
;
285 TRACE("(%p, %p, %08x, %p)\n", hCertStore
, pCertContext
, dwAddDisposition
, ppStoreContext
);
287 return add_cert_to_store(store
, pCertContext
, dwAddDisposition
, FALSE
, ppStoreContext
);
290 BOOL WINAPI
CertAddCertificateLinkToStore(HCERTSTORE hCertStore
,
291 PCCERT_CONTEXT pCertContext
, DWORD dwAddDisposition
,
292 PCCERT_CONTEXT
*ppCertContext
)
295 WINECRYPT_CERTSTORE
*store
= (WINECRYPT_CERTSTORE
*)hCertStore
;
298 FIXME("(%p, %p, %08x, %p): semi-stub\n", hCertStore
, pCertContext
,
299 dwAddDisposition
, ppCertContext
);
300 if (store
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
302 if (store
->type
== StoreTypeCollection
)
304 SetLastError(E_INVALIDARG
);
307 return add_cert_to_store(hCertStore
, pCertContext
, dwAddDisposition
, TRUE
, ppCertContext
);
310 PCCERT_CONTEXT WINAPI
CertCreateCertificateContext(DWORD dwCertEncodingType
,
311 const BYTE
*pbCertEncoded
, DWORD cbCertEncoded
)
316 PCERT_INFO certInfo
= NULL
;
319 TRACE("(%08x, %p, %d)\n", dwCertEncodingType
, pbCertEncoded
,
322 if ((dwCertEncodingType
& CERT_ENCODING_TYPE_MASK
) != X509_ASN_ENCODING
)
324 SetLastError(E_INVALIDARG
);
328 ret
= CryptDecodeObjectEx(dwCertEncodingType
, X509_CERT_TO_BE_SIGNED
,
329 pbCertEncoded
, cbCertEncoded
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
334 cert
= (cert_t
*)Context_CreateDataContext(sizeof(CERT_CONTEXT
), &cert_vtbl
, &empty_store
);
337 data
= CryptMemAlloc(cbCertEncoded
);
340 Context_Release(&cert
->base
);
344 memcpy(data
, pbCertEncoded
, cbCertEncoded
);
345 cert
->ctx
.dwCertEncodingType
= dwCertEncodingType
;
346 cert
->ctx
.pbCertEncoded
= data
;
347 cert
->ctx
.cbCertEncoded
= cbCertEncoded
;
348 cert
->ctx
.pCertInfo
= certInfo
;
349 cert
->ctx
.hCertStore
= &empty_store
;
354 PCCERT_CONTEXT WINAPI
CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContext
)
356 TRACE("(%p)\n", pCertContext
);
361 Context_AddRef(&cert_from_ptr(pCertContext
)->base
);
365 BOOL WINAPI
CertFreeCertificateContext(PCCERT_CONTEXT pCertContext
)
367 TRACE("(%p)\n", pCertContext
);
370 Context_Release(&cert_from_ptr(pCertContext
)->base
);
374 DWORD WINAPI
CertEnumCertificateContextProperties(PCCERT_CONTEXT pCertContext
,
377 cert_t
*cert
= cert_from_ptr(pCertContext
);
380 TRACE("(%p, %d)\n", pCertContext
, dwPropId
);
382 if (cert
->base
.properties
)
383 ret
= ContextPropertyList_EnumPropIDs(cert
->base
.properties
, dwPropId
);
389 static BOOL
CertContext_GetHashProp(cert_t
*cert
, DWORD dwPropId
,
390 ALG_ID algID
, const BYTE
*toHash
, DWORD toHashLen
, void *pvData
,
393 BOOL ret
= CryptHashCertificate(0, algID
, 0, toHash
, toHashLen
, pvData
,
397 CRYPT_DATA_BLOB blob
= { *pcbData
, pvData
};
399 ret
= CertContext_SetProperty(cert
, dwPropId
, 0, &blob
);
404 static BOOL
CertContext_CopyParam(void *pvData
, DWORD
*pcbData
, const void *pb
,
411 else if (*pcbData
< cb
)
413 SetLastError(ERROR_MORE_DATA
);
419 memcpy(pvData
, pb
, cb
);
425 static BOOL
CertContext_GetProperty(cert_t
*cert
, DWORD dwPropId
,
426 void *pvData
, DWORD
*pcbData
)
429 CRYPT_DATA_BLOB blob
;
431 TRACE("(%p, %d, %p, %p)\n", cert
, dwPropId
, pvData
, pcbData
);
433 if (cert
->base
.properties
)
434 ret
= ContextPropertyList_FindProperty(cert
->base
.properties
, dwPropId
, &blob
);
438 ret
= CertContext_CopyParam(pvData
, pcbData
, blob
.pbData
, blob
.cbData
);
441 /* Implicit properties */
444 case CERT_SHA1_HASH_PROP_ID
:
445 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_SHA1
,
446 cert
->ctx
.pbCertEncoded
, cert
->ctx
.cbCertEncoded
, pvData
,
449 case CERT_MD5_HASH_PROP_ID
:
450 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_MD5
,
451 cert
->ctx
.pbCertEncoded
, cert
->ctx
.cbCertEncoded
, pvData
,
454 case CERT_SUBJECT_NAME_MD5_HASH_PROP_ID
:
455 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_MD5
,
456 cert
->ctx
.pCertInfo
->Subject
.pbData
,
457 cert
->ctx
.pCertInfo
->Subject
.cbData
,
460 case CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID
:
461 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_MD5
,
462 cert
->ctx
.pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.pbData
,
463 cert
->ctx
.pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.cbData
,
466 case CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID
:
467 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_MD5
,
468 cert
->ctx
.pCertInfo
->SerialNumber
.pbData
,
469 cert
->ctx
.pCertInfo
->SerialNumber
.cbData
,
472 case CERT_SIGNATURE_HASH_PROP_ID
:
473 ret
= CryptHashToBeSigned(0, cert
->ctx
.dwCertEncodingType
,
474 cert
->ctx
.pbCertEncoded
, cert
->ctx
.cbCertEncoded
, pvData
,
478 CRYPT_DATA_BLOB blob
= { *pcbData
, pvData
};
480 ret
= CertContext_SetProperty(cert
, dwPropId
, 0, &blob
);
483 case CERT_KEY_IDENTIFIER_PROP_ID
:
485 PCERT_EXTENSION ext
= CertFindExtension(
486 szOID_SUBJECT_KEY_IDENTIFIER
, cert
->ctx
.pCertInfo
->cExtension
,
487 cert
->ctx
.pCertInfo
->rgExtension
);
491 CRYPT_DATA_BLOB value
;
492 DWORD size
= sizeof(value
);
494 ret
= CryptDecodeObjectEx(X509_ASN_ENCODING
,
495 szOID_SUBJECT_KEY_IDENTIFIER
, ext
->Value
.pbData
,
496 ext
->Value
.cbData
, CRYPT_DECODE_NOCOPY_FLAG
, NULL
, &value
,
500 ret
= CertContext_CopyParam(pvData
, pcbData
, value
.pbData
,
502 CertContext_SetProperty(cert
, dwPropId
, 0, &value
);
506 SetLastError(ERROR_INVALID_DATA
);
510 SetLastError(CRYPT_E_NOT_FOUND
);
513 TRACE("returning %d\n", ret
);
517 void CRYPT_FixKeyProvInfoPointers(PCRYPT_KEY_PROV_INFO info
)
519 DWORD i
, containerLen
, provNameLen
;
520 LPBYTE data
= (LPBYTE
)info
+ sizeof(CRYPT_KEY_PROV_INFO
);
522 info
->pwszContainerName
= (LPWSTR
)data
;
523 containerLen
= (lstrlenW(info
->pwszContainerName
) + 1) * sizeof(WCHAR
);
524 data
+= containerLen
;
526 info
->pwszProvName
= (LPWSTR
)data
;
527 provNameLen
= (lstrlenW(info
->pwszProvName
) + 1) * sizeof(WCHAR
);
530 info
->rgProvParam
= (PCRYPT_KEY_PROV_PARAM
)data
;
531 data
+= info
->cProvParam
* sizeof(CRYPT_KEY_PROV_PARAM
);
533 for (i
= 0; i
< info
->cProvParam
; i
++)
535 info
->rgProvParam
[i
].pbData
= data
;
536 data
+= info
->rgProvParam
[i
].cbData
;
540 BOOL WINAPI
CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext
,
541 DWORD dwPropId
, void *pvData
, DWORD
*pcbData
)
543 cert_t
*cert
= cert_from_ptr(pCertContext
);
546 TRACE("(%p, %d, %p, %p)\n", pCertContext
, dwPropId
, pvData
, pcbData
);
551 case CERT_CERT_PROP_ID
:
552 case CERT_CRL_PROP_ID
:
553 case CERT_CTL_PROP_ID
:
554 SetLastError(E_INVALIDARG
);
557 case CERT_ACCESS_STATE_PROP_ID
:
558 ret
= CertGetStoreProperty(cert
->ctx
.hCertStore
, dwPropId
, pvData
, pcbData
);
560 case CERT_KEY_PROV_HANDLE_PROP_ID
:
562 CERT_KEY_CONTEXT keyContext
;
563 DWORD size
= sizeof(keyContext
);
565 ret
= CertContext_GetProperty(cert
,
566 CERT_KEY_CONTEXT_PROP_ID
, &keyContext
, &size
);
568 ret
= CertContext_CopyParam(pvData
, pcbData
, &keyContext
.hCryptProv
,
569 sizeof(keyContext
.hCryptProv
));
572 case CERT_KEY_PROV_INFO_PROP_ID
:
573 ret
= CertContext_GetProperty(cert
, dwPropId
, pvData
,
576 CRYPT_FixKeyProvInfoPointers(pvData
);
579 ret
= CertContext_GetProperty(cert
, dwPropId
, pvData
,
583 TRACE("returning %d\n", ret
);
587 /* Copies key provider info from from into to, where to is assumed to be a
588 * contiguous buffer of memory large enough for from and all its associated
589 * data, but whose pointers are uninitialized.
590 * Upon return, to contains a contiguous copy of from, packed in the following
592 * - CRYPT_KEY_PROV_INFO
593 * - pwszContainerName
595 * - rgProvParam[0]...
597 static void CRYPT_CopyKeyProvInfo(PCRYPT_KEY_PROV_INFO to
,
598 const CRYPT_KEY_PROV_INFO
*from
)
601 LPBYTE nextData
= (LPBYTE
)to
+ sizeof(CRYPT_KEY_PROV_INFO
);
603 if (from
->pwszContainerName
)
605 to
->pwszContainerName
= (LPWSTR
)nextData
;
606 lstrcpyW(to
->pwszContainerName
, from
->pwszContainerName
);
607 nextData
+= (lstrlenW(from
->pwszContainerName
) + 1) * sizeof(WCHAR
);
610 to
->pwszContainerName
= NULL
;
611 if (from
->pwszProvName
)
613 to
->pwszProvName
= (LPWSTR
)nextData
;
614 lstrcpyW(to
->pwszProvName
, from
->pwszProvName
);
615 nextData
+= (lstrlenW(from
->pwszProvName
) + 1) * sizeof(WCHAR
);
618 to
->pwszProvName
= NULL
;
619 to
->dwProvType
= from
->dwProvType
;
620 to
->dwFlags
= from
->dwFlags
;
621 to
->cProvParam
= from
->cProvParam
;
622 to
->rgProvParam
= (PCRYPT_KEY_PROV_PARAM
)nextData
;
623 nextData
+= to
->cProvParam
* sizeof(CRYPT_KEY_PROV_PARAM
);
624 to
->dwKeySpec
= from
->dwKeySpec
;
625 for (i
= 0; i
< to
->cProvParam
; i
++)
627 memcpy(&to
->rgProvParam
[i
], &from
->rgProvParam
[i
],
628 sizeof(CRYPT_KEY_PROV_PARAM
));
629 to
->rgProvParam
[i
].pbData
= nextData
;
630 memcpy(to
->rgProvParam
[i
].pbData
, from
->rgProvParam
[i
].pbData
,
631 from
->rgProvParam
[i
].cbData
);
632 nextData
+= from
->rgProvParam
[i
].cbData
;
636 static BOOL
CertContext_SetKeyProvInfoProperty(CONTEXT_PROPERTY_LIST
*properties
,
637 const CRYPT_KEY_PROV_INFO
*info
)
641 DWORD size
= sizeof(CRYPT_KEY_PROV_INFO
), i
, containerSize
, provNameSize
;
643 if (info
->pwszContainerName
)
644 containerSize
= (lstrlenW(info
->pwszContainerName
) + 1) * sizeof(WCHAR
);
647 if (info
->pwszProvName
)
648 provNameSize
= (lstrlenW(info
->pwszProvName
) + 1) * sizeof(WCHAR
);
651 size
+= containerSize
+ provNameSize
;
652 for (i
= 0; i
< info
->cProvParam
; i
++)
653 size
+= sizeof(CRYPT_KEY_PROV_PARAM
) + info
->rgProvParam
[i
].cbData
;
654 buf
= CryptMemAlloc(size
);
657 CRYPT_CopyKeyProvInfo((PCRYPT_KEY_PROV_INFO
)buf
, info
);
658 ret
= ContextPropertyList_SetProperty(properties
,
659 CERT_KEY_PROV_INFO_PROP_ID
, buf
, size
);
667 static BOOL
CertContext_SetProperty(cert_t
*cert
, DWORD dwPropId
,
668 DWORD dwFlags
, const void *pvData
)
672 TRACE("(%p, %d, %08x, %p)\n", cert
, dwPropId
, dwFlags
, pvData
);
674 if (!cert
->base
.properties
)
680 case CERT_AUTO_ENROLL_PROP_ID
:
681 case CERT_CTL_USAGE_PROP_ID
: /* same as CERT_ENHKEY_USAGE_PROP_ID */
682 case CERT_DESCRIPTION_PROP_ID
:
683 case CERT_FRIENDLY_NAME_PROP_ID
:
684 case CERT_HASH_PROP_ID
:
685 case CERT_KEY_IDENTIFIER_PROP_ID
:
686 case CERT_MD5_HASH_PROP_ID
:
687 case CERT_NEXT_UPDATE_LOCATION_PROP_ID
:
688 case CERT_PUBKEY_ALG_PARA_PROP_ID
:
689 case CERT_PVK_FILE_PROP_ID
:
690 case CERT_SIGNATURE_HASH_PROP_ID
:
691 case CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID
:
692 case CERT_SUBJECT_NAME_MD5_HASH_PROP_ID
:
693 case CERT_EXTENDED_ERROR_INFO_PROP_ID
:
694 case CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID
:
695 case CERT_ENROLLMENT_PROP_ID
:
696 case CERT_CROSS_CERT_DIST_POINTS_PROP_ID
:
697 case CERT_RENEWAL_PROP_ID
:
701 const CRYPT_DATA_BLOB
*blob
= pvData
;
703 ret
= ContextPropertyList_SetProperty(cert
->base
.properties
, dwPropId
,
704 blob
->pbData
, blob
->cbData
);
708 ContextPropertyList_RemoveProperty(cert
->base
.properties
, dwPropId
);
713 case CERT_DATE_STAMP_PROP_ID
:
715 ret
= ContextPropertyList_SetProperty(cert
->base
.properties
, dwPropId
,
716 pvData
, sizeof(FILETIME
));
719 ContextPropertyList_RemoveProperty(cert
->base
.properties
, dwPropId
);
723 case CERT_KEY_CONTEXT_PROP_ID
:
727 const CERT_KEY_CONTEXT
*keyContext
= pvData
;
729 if (keyContext
->cbSize
!= sizeof(CERT_KEY_CONTEXT
))
731 SetLastError(E_INVALIDARG
);
735 ret
= ContextPropertyList_SetProperty(cert
->base
.properties
, dwPropId
,
736 (const BYTE
*)keyContext
, keyContext
->cbSize
);
740 ContextPropertyList_RemoveProperty(cert
->base
.properties
, dwPropId
);
745 case CERT_KEY_PROV_INFO_PROP_ID
:
747 ret
= CertContext_SetKeyProvInfoProperty(cert
->base
.properties
, pvData
);
750 ContextPropertyList_RemoveProperty(cert
->base
.properties
, dwPropId
);
754 case CERT_KEY_PROV_HANDLE_PROP_ID
:
756 CERT_KEY_CONTEXT keyContext
;
757 DWORD size
= sizeof(keyContext
);
759 ret
= CertContext_GetProperty(cert
, CERT_KEY_CONTEXT_PROP_ID
,
763 if (!(dwFlags
& CERT_STORE_NO_CRYPT_RELEASE_FLAG
))
764 CryptReleaseContext(keyContext
.hCryptProv
, 0);
766 keyContext
.cbSize
= sizeof(keyContext
);
768 keyContext
.hCryptProv
= *(const HCRYPTPROV
*)pvData
;
771 keyContext
.hCryptProv
= 0;
772 keyContext
.dwKeySpec
= AT_SIGNATURE
;
774 ret
= CertContext_SetProperty(cert
, CERT_KEY_CONTEXT_PROP_ID
,
779 FIXME("%d: stub\n", dwPropId
);
783 TRACE("returning %d\n", ret
);
787 BOOL WINAPI
CertSetCertificateContextProperty(PCCERT_CONTEXT pCertContext
,
788 DWORD dwPropId
, DWORD dwFlags
, const void *pvData
)
792 TRACE("(%p, %d, %08x, %p)\n", pCertContext
, dwPropId
, dwFlags
, pvData
);
794 /* Handle special cases for "read-only"/invalid prop IDs. Windows just
795 * crashes on most of these, I'll be safer.
800 case CERT_ACCESS_STATE_PROP_ID
:
801 case CERT_CERT_PROP_ID
:
802 case CERT_CRL_PROP_ID
:
803 case CERT_CTL_PROP_ID
:
804 SetLastError(E_INVALIDARG
);
807 ret
= CertContext_SetProperty(cert_from_ptr(pCertContext
), dwPropId
, dwFlags
,
809 TRACE("returning %d\n", ret
);
813 /* Acquires the private key using the key provider info, retrieving info from
814 * the certificate if info is NULL. The acquired provider is returned in
815 * *phCryptProv, and the key spec for the provider is returned in *pdwKeySpec.
817 static BOOL
CRYPT_AcquirePrivateKeyFromProvInfo(PCCERT_CONTEXT pCert
,
818 PCRYPT_KEY_PROV_INFO info
, HCRYPTPROV
*phCryptProv
, DWORD
*pdwKeySpec
)
821 BOOL allocated
= FALSE
, ret
= TRUE
;
825 ret
= CertGetCertificateContextProperty(pCert
,
826 CERT_KEY_PROV_INFO_PROP_ID
, 0, &size
);
829 info
= HeapAlloc(GetProcessHeap(), 0, size
);
832 ret
= CertGetCertificateContextProperty(pCert
,
833 CERT_KEY_PROV_INFO_PROP_ID
, info
, &size
);
838 SetLastError(ERROR_OUTOFMEMORY
);
843 SetLastError(CRYPT_E_NO_KEY_PROPERTY
);
847 ret
= CryptAcquireContextW(phCryptProv
, info
->pwszContainerName
,
848 info
->pwszProvName
, info
->dwProvType
, 0);
853 for (i
= 0; i
< info
->cProvParam
; i
++)
855 CryptSetProvParam(*phCryptProv
,
856 info
->rgProvParam
[i
].dwParam
, info
->rgProvParam
[i
].pbData
,
857 info
->rgProvParam
[i
].dwFlags
);
859 *pdwKeySpec
= info
->dwKeySpec
;
862 SetLastError(CRYPT_E_NO_KEY_PROPERTY
);
865 HeapFree(GetProcessHeap(), 0, info
);
869 BOOL WINAPI
CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert
,
870 DWORD dwFlags
, void *pvReserved
, HCRYPTPROV_OR_NCRYPT_KEY_HANDLE
*phCryptProv
,
871 DWORD
*pdwKeySpec
, BOOL
*pfCallerFreeProv
)
873 BOOL ret
= FALSE
, cache
= FALSE
;
874 PCRYPT_KEY_PROV_INFO info
= NULL
;
875 CERT_KEY_CONTEXT keyContext
;
878 TRACE("(%p, %08x, %p, %p, %p, %p)\n", pCert
, dwFlags
, pvReserved
,
879 phCryptProv
, pdwKeySpec
, pfCallerFreeProv
);
881 if (dwFlags
& CRYPT_ACQUIRE_USE_PROV_INFO_FLAG
)
885 ret
= CertGetCertificateContextProperty(pCert
,
886 CERT_KEY_PROV_INFO_PROP_ID
, 0, &size
);
889 info
= HeapAlloc(GetProcessHeap(), 0, size
);
890 ret
= CertGetCertificateContextProperty(pCert
,
891 CERT_KEY_PROV_INFO_PROP_ID
, info
, &size
);
893 cache
= info
->dwFlags
& CERT_SET_KEY_CONTEXT_PROP_ID
;
896 else if (dwFlags
& CRYPT_ACQUIRE_CACHE_FLAG
)
901 size
= sizeof(keyContext
);
902 ret
= CertGetCertificateContextProperty(pCert
, CERT_KEY_CONTEXT_PROP_ID
,
906 *phCryptProv
= keyContext
.hCryptProv
;
908 *pdwKeySpec
= keyContext
.dwKeySpec
;
909 if (pfCallerFreeProv
)
910 *pfCallerFreeProv
= !cache
;
915 ret
= CRYPT_AcquirePrivateKeyFromProvInfo(pCert
, info
,
916 &keyContext
.hCryptProv
, &keyContext
.dwKeySpec
);
919 *phCryptProv
= keyContext
.hCryptProv
;
921 *pdwKeySpec
= keyContext
.dwKeySpec
;
924 keyContext
.cbSize
= sizeof(keyContext
);
925 if (CertSetCertificateContextProperty(pCert
,
926 CERT_KEY_CONTEXT_PROP_ID
, 0, &keyContext
))
928 if (pfCallerFreeProv
)
929 *pfCallerFreeProv
= FALSE
;
934 if (pfCallerFreeProv
)
935 *pfCallerFreeProv
= TRUE
;
939 HeapFree(GetProcessHeap(), 0, info
);
943 static BOOL
key_prov_info_matches_cert(PCCERT_CONTEXT pCert
,
944 const CRYPT_KEY_PROV_INFO
*keyProvInfo
)
947 BOOL matches
= FALSE
;
949 if (CryptAcquireContextW(&csp
, keyProvInfo
->pwszContainerName
,
950 keyProvInfo
->pwszProvName
, keyProvInfo
->dwProvType
, keyProvInfo
->dwFlags
))
954 /* Need to sign something to verify the sig. What to sign? Why not
955 * the certificate itself?
957 if (CryptSignAndEncodeCertificate(csp
, AT_SIGNATURE
,
958 pCert
->dwCertEncodingType
, X509_CERT_TO_BE_SIGNED
, pCert
->pCertInfo
,
959 &pCert
->pCertInfo
->SignatureAlgorithm
, NULL
, NULL
, &size
))
961 BYTE
*certEncoded
= CryptMemAlloc(size
);
965 if (CryptSignAndEncodeCertificate(csp
, AT_SIGNATURE
,
966 pCert
->dwCertEncodingType
, X509_CERT_TO_BE_SIGNED
,
967 pCert
->pCertInfo
, &pCert
->pCertInfo
->SignatureAlgorithm
,
968 NULL
, certEncoded
, &size
))
970 if (size
== pCert
->cbCertEncoded
&&
971 !memcmp(certEncoded
, pCert
->pbCertEncoded
, size
))
974 CryptMemFree(certEncoded
);
977 CryptReleaseContext(csp
, 0);
982 static BOOL
container_matches_cert(PCCERT_CONTEXT pCert
, LPCSTR container
,
983 CRYPT_KEY_PROV_INFO
*keyProvInfo
)
985 CRYPT_KEY_PROV_INFO copy
;
986 WCHAR containerW
[MAX_PATH
];
987 BOOL matches
= FALSE
;
989 MultiByteToWideChar(CP_ACP
, 0, container
, -1,
990 containerW
, sizeof(containerW
) / sizeof(containerW
[0]));
991 /* We make a copy of the CRYPT_KEY_PROV_INFO because the caller expects
992 * keyProvInfo->pwszContainerName to be NULL or a heap-allocated container
996 copy
.pwszContainerName
= containerW
;
997 matches
= key_prov_info_matches_cert(pCert
, ©
);
1000 keyProvInfo
->pwszContainerName
=
1001 CryptMemAlloc((strlenW(containerW
) + 1) * sizeof(WCHAR
));
1002 if (keyProvInfo
->pwszContainerName
)
1004 strcpyW(keyProvInfo
->pwszContainerName
, containerW
);
1005 keyProvInfo
->dwKeySpec
= AT_SIGNATURE
;
1013 /* Searches the provider named keyProvInfo.pwszProvName for a container whose
1014 * private key matches pCert's public key. Upon success, updates keyProvInfo
1015 * with the matching container's info (free keyProvInfo.pwszContainerName upon
1017 * Returns TRUE if found, FALSE if not.
1019 static BOOL
find_key_prov_info_in_provider(PCCERT_CONTEXT pCert
,
1020 CRYPT_KEY_PROV_INFO
*keyProvInfo
)
1022 HCRYPTPROV defProvider
;
1023 BOOL ret
, found
= FALSE
;
1024 char containerA
[MAX_PATH
];
1026 assert(keyProvInfo
->pwszContainerName
== NULL
);
1027 if ((ret
= CryptAcquireContextW(&defProvider
, NULL
,
1028 keyProvInfo
->pwszProvName
, keyProvInfo
->dwProvType
,
1029 keyProvInfo
->dwFlags
| CRYPT_VERIFYCONTEXT
)))
1031 DWORD enumFlags
= keyProvInfo
->dwFlags
| CRYPT_FIRST
;
1033 while (ret
&& !found
)
1035 DWORD size
= sizeof(containerA
);
1037 ret
= CryptGetProvParam(defProvider
, PP_ENUMCONTAINERS
,
1038 (BYTE
*)containerA
, &size
, enumFlags
);
1040 found
= container_matches_cert(pCert
, containerA
, keyProvInfo
);
1041 if (enumFlags
& CRYPT_FIRST
)
1043 enumFlags
&= ~CRYPT_FIRST
;
1044 enumFlags
|= CRYPT_NEXT
;
1047 CryptReleaseContext(defProvider
, 0);
1052 static BOOL
find_matching_provider(PCCERT_CONTEXT pCert
, DWORD dwFlags
)
1054 BOOL found
= FALSE
, ret
= TRUE
;
1055 DWORD index
= 0, cbProvName
= 0;
1056 CRYPT_KEY_PROV_INFO keyProvInfo
;
1058 TRACE("(%p, %08x)\n", pCert
, dwFlags
);
1060 memset(&keyProvInfo
, 0, sizeof(keyProvInfo
));
1061 while (ret
&& !found
)
1065 ret
= CryptEnumProvidersW(index
, NULL
, 0, &keyProvInfo
.dwProvType
,
1069 if (size
<= cbProvName
)
1070 ret
= CryptEnumProvidersW(index
, NULL
, 0,
1071 &keyProvInfo
.dwProvType
, keyProvInfo
.pwszProvName
, &size
);
1074 CryptMemFree(keyProvInfo
.pwszProvName
);
1075 keyProvInfo
.pwszProvName
= CryptMemAlloc(size
);
1076 if (keyProvInfo
.pwszProvName
)
1079 ret
= CryptEnumProvidersW(index
, NULL
, 0,
1080 &keyProvInfo
.dwProvType
, keyProvInfo
.pwszProvName
, &size
);
1083 if (dwFlags
& CRYPT_FIND_SILENT_KEYSET_FLAG
)
1084 keyProvInfo
.dwFlags
|= CRYPT_SILENT
;
1085 if (dwFlags
& CRYPT_FIND_USER_KEYSET_FLAG
||
1086 !(dwFlags
& (CRYPT_FIND_USER_KEYSET_FLAG
|
1087 CRYPT_FIND_MACHINE_KEYSET_FLAG
)))
1089 keyProvInfo
.dwFlags
|= CRYPT_USER_KEYSET
;
1090 found
= find_key_prov_info_in_provider(pCert
,
1095 if (dwFlags
& CRYPT_FIND_MACHINE_KEYSET_FLAG
||
1096 !(dwFlags
& (CRYPT_FIND_USER_KEYSET_FLAG
|
1097 CRYPT_FIND_MACHINE_KEYSET_FLAG
)))
1099 keyProvInfo
.dwFlags
&= ~CRYPT_USER_KEYSET
;
1100 keyProvInfo
.dwFlags
|= CRYPT_MACHINE_KEYSET
;
1101 found
= find_key_prov_info_in_provider(pCert
,
1114 CertSetCertificateContextProperty(pCert
, CERT_KEY_PROV_INFO_PROP_ID
,
1116 CryptMemFree(keyProvInfo
.pwszProvName
);
1117 CryptMemFree(keyProvInfo
.pwszContainerName
);
1121 static BOOL
cert_prov_info_matches_cert(PCCERT_CONTEXT pCert
)
1123 BOOL matches
= FALSE
;
1126 if (CertGetCertificateContextProperty(pCert
, CERT_KEY_PROV_INFO_PROP_ID
,
1129 CRYPT_KEY_PROV_INFO
*keyProvInfo
= CryptMemAlloc(size
);
1133 if (CertGetCertificateContextProperty(pCert
,
1134 CERT_KEY_PROV_INFO_PROP_ID
, keyProvInfo
, &size
))
1135 matches
= key_prov_info_matches_cert(pCert
, keyProvInfo
);
1136 CryptMemFree(keyProvInfo
);
1142 BOOL WINAPI
CryptFindCertificateKeyProvInfo(PCCERT_CONTEXT pCert
,
1143 DWORD dwFlags
, void *pvReserved
)
1145 BOOL matches
= FALSE
;
1147 TRACE("(%p, %08x, %p)\n", pCert
, dwFlags
, pvReserved
);
1149 matches
= cert_prov_info_matches_cert(pCert
);
1151 matches
= find_matching_provider(pCert
, dwFlags
);
1155 BOOL WINAPI
CertCompareCertificate(DWORD dwCertEncodingType
,
1156 PCERT_INFO pCertId1
, PCERT_INFO pCertId2
)
1160 TRACE("(%08x, %p, %p)\n", dwCertEncodingType
, pCertId1
, pCertId2
);
1162 ret
= CertCompareCertificateName(dwCertEncodingType
, &pCertId1
->Issuer
,
1163 &pCertId2
->Issuer
) && CertCompareIntegerBlob(&pCertId1
->SerialNumber
,
1164 &pCertId2
->SerialNumber
);
1165 TRACE("returning %d\n", ret
);
1169 BOOL WINAPI
CertCompareCertificateName(DWORD dwCertEncodingType
,
1170 PCERT_NAME_BLOB pCertName1
, PCERT_NAME_BLOB pCertName2
)
1174 TRACE("(%08x, %p, %p)\n", dwCertEncodingType
, pCertName1
, pCertName2
);
1176 if (pCertName1
->cbData
== pCertName2
->cbData
)
1178 if (pCertName1
->cbData
)
1179 ret
= !memcmp(pCertName1
->pbData
, pCertName2
->pbData
,
1180 pCertName1
->cbData
);
1186 TRACE("returning %d\n", ret
);
1190 /* Returns the number of significant bytes in pInt, where a byte is
1191 * insignificant if it's a leading 0 for positive numbers or a leading 0xff
1192 * for negative numbers. pInt is assumed to be little-endian.
1194 static DWORD
CRYPT_significantBytes(const CRYPT_INTEGER_BLOB
*pInt
)
1196 DWORD ret
= pInt
->cbData
;
1200 if (pInt
->pbData
[ret
- 2] <= 0x7f && pInt
->pbData
[ret
- 1] == 0)
1202 else if (pInt
->pbData
[ret
- 2] >= 0x80 && pInt
->pbData
[ret
- 1] == 0xff)
1210 BOOL WINAPI
CertCompareIntegerBlob(PCRYPT_INTEGER_BLOB pInt1
,
1211 PCRYPT_INTEGER_BLOB pInt2
)
1216 TRACE("(%p, %p)\n", pInt1
, pInt2
);
1218 cb1
= CRYPT_significantBytes(pInt1
);
1219 cb2
= CRYPT_significantBytes(pInt2
);
1223 ret
= !memcmp(pInt1
->pbData
, pInt2
->pbData
, cb1
);
1229 TRACE("returning %d\n", ret
);
1233 BOOL WINAPI
CertComparePublicKeyInfo(DWORD dwCertEncodingType
,
1234 PCERT_PUBLIC_KEY_INFO pPublicKey1
, PCERT_PUBLIC_KEY_INFO pPublicKey2
)
1238 TRACE("(%08x, %p, %p)\n", dwCertEncodingType
, pPublicKey1
, pPublicKey2
);
1240 switch (GET_CERT_ENCODING_TYPE(dwCertEncodingType
))
1242 case 0: /* Seems to mean "raw binary bits" */
1243 if (pPublicKey1
->PublicKey
.cbData
== pPublicKey2
->PublicKey
.cbData
&&
1244 pPublicKey1
->PublicKey
.cUnusedBits
== pPublicKey2
->PublicKey
.cUnusedBits
)
1246 if (pPublicKey2
->PublicKey
.cbData
)
1247 ret
= !memcmp(pPublicKey1
->PublicKey
.pbData
,
1248 pPublicKey2
->PublicKey
.pbData
, pPublicKey1
->PublicKey
.cbData
);
1256 WARN("Unknown encoding type %08x\n", dwCertEncodingType
);
1258 case X509_ASN_ENCODING
:
1260 BLOBHEADER
*pblob1
, *pblob2
;
1263 if (CryptDecodeObject(dwCertEncodingType
, RSA_CSP_PUBLICKEYBLOB
,
1264 pPublicKey1
->PublicKey
.pbData
, pPublicKey1
->PublicKey
.cbData
,
1267 pblob1
= CryptMemAlloc(length
);
1268 if (CryptDecodeObject(dwCertEncodingType
, RSA_CSP_PUBLICKEYBLOB
,
1269 pPublicKey1
->PublicKey
.pbData
, pPublicKey1
->PublicKey
.cbData
,
1270 0, pblob1
, &length
))
1272 if (CryptDecodeObject(dwCertEncodingType
, RSA_CSP_PUBLICKEYBLOB
,
1273 pPublicKey2
->PublicKey
.pbData
, pPublicKey2
->PublicKey
.cbData
,
1276 pblob2
= CryptMemAlloc(length
);
1277 if (CryptDecodeObject(dwCertEncodingType
, RSA_CSP_PUBLICKEYBLOB
,
1278 pPublicKey2
->PublicKey
.pbData
, pPublicKey2
->PublicKey
.cbData
,
1279 0, pblob2
, &length
))
1281 /* The RSAPUBKEY structure directly follows the BLOBHEADER */
1282 RSAPUBKEY
*pk1
= (LPVOID
)(pblob1
+ 1),
1283 *pk2
= (LPVOID
)(pblob2
+ 1);
1284 ret
= (pk1
->bitlen
== pk2
->bitlen
) && (pk1
->pubexp
== pk2
->pubexp
)
1285 && !memcmp(pk1
+ 1, pk2
+ 1, pk1
->bitlen
/8);
1287 CryptMemFree(pblob2
);
1290 CryptMemFree(pblob1
);
1299 DWORD WINAPI
CertGetPublicKeyLength(DWORD dwCertEncodingType
,
1300 PCERT_PUBLIC_KEY_INFO pPublicKey
)
1304 TRACE("(%08x, %p)\n", dwCertEncodingType
, pPublicKey
);
1306 if (GET_CERT_ENCODING_TYPE(dwCertEncodingType
) != X509_ASN_ENCODING
)
1308 SetLastError(ERROR_FILE_NOT_FOUND
);
1311 if (pPublicKey
->Algorithm
.pszObjId
&&
1312 !strcmp(pPublicKey
->Algorithm
.pszObjId
, szOID_RSA_DH
))
1314 FIXME("unimplemented for DH public keys\n");
1315 SetLastError(CRYPT_E_ASN1_BADTAG
);
1321 BOOL ret
= CryptDecodeObjectEx(dwCertEncodingType
,
1322 RSA_CSP_PUBLICKEYBLOB
, pPublicKey
->PublicKey
.pbData
,
1323 pPublicKey
->PublicKey
.cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
, &buf
,
1328 RSAPUBKEY
*rsaPubKey
= (RSAPUBKEY
*)(buf
+ sizeof(BLOBHEADER
));
1330 len
= rsaPubKey
->bitlen
;
1337 typedef BOOL (*CertCompareFunc
)(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1338 DWORD dwFlags
, const void *pvPara
);
1340 static BOOL
compare_cert_by_md5_hash(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1341 DWORD dwFlags
, const void *pvPara
)
1345 DWORD size
= sizeof(hash
);
1347 ret
= CertGetCertificateContextProperty(pCertContext
,
1348 CERT_MD5_HASH_PROP_ID
, hash
, &size
);
1351 const CRYPT_HASH_BLOB
*pHash
= pvPara
;
1353 if (size
== pHash
->cbData
)
1354 ret
= !memcmp(pHash
->pbData
, hash
, size
);
1361 static BOOL
compare_cert_by_sha1_hash(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1362 DWORD dwFlags
, const void *pvPara
)
1366 DWORD size
= sizeof(hash
);
1368 ret
= CertGetCertificateContextProperty(pCertContext
,
1369 CERT_SHA1_HASH_PROP_ID
, hash
, &size
);
1372 const CRYPT_HASH_BLOB
*pHash
= pvPara
;
1374 if (size
== pHash
->cbData
)
1375 ret
= !memcmp(pHash
->pbData
, hash
, size
);
1382 static BOOL
compare_cert_by_name(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1383 DWORD dwFlags
, const void *pvPara
)
1385 CERT_NAME_BLOB
*blob
= (CERT_NAME_BLOB
*)pvPara
, *toCompare
;
1388 if (dwType
& CERT_INFO_SUBJECT_FLAG
)
1389 toCompare
= &pCertContext
->pCertInfo
->Subject
;
1391 toCompare
= &pCertContext
->pCertInfo
->Issuer
;
1392 ret
= CertCompareCertificateName(pCertContext
->dwCertEncodingType
,
1397 static BOOL
compare_cert_by_public_key(PCCERT_CONTEXT pCertContext
,
1398 DWORD dwType
, DWORD dwFlags
, const void *pvPara
)
1400 CERT_PUBLIC_KEY_INFO
*publicKey
= (CERT_PUBLIC_KEY_INFO
*)pvPara
;
1403 ret
= CertComparePublicKeyInfo(pCertContext
->dwCertEncodingType
,
1404 &pCertContext
->pCertInfo
->SubjectPublicKeyInfo
, publicKey
);
1408 static BOOL
compare_cert_by_subject_cert(PCCERT_CONTEXT pCertContext
,
1409 DWORD dwType
, DWORD dwFlags
, const void *pvPara
)
1411 CERT_INFO
*pCertInfo
= (CERT_INFO
*)pvPara
;
1414 /* Matching serial number and subject match.. */
1415 ret
= CertCompareCertificateName(pCertContext
->dwCertEncodingType
,
1416 &pCertContext
->pCertInfo
->Subject
, &pCertInfo
->Issuer
);
1418 ret
= CertCompareIntegerBlob(&pCertContext
->pCertInfo
->SerialNumber
,
1419 &pCertInfo
->SerialNumber
);
1422 /* failing that, if the serial number and issuer match, we match */
1423 ret
= CertCompareIntegerBlob(&pCertContext
->pCertInfo
->SerialNumber
,
1424 &pCertInfo
->SerialNumber
);
1426 ret
= CertCompareCertificateName(pCertContext
->dwCertEncodingType
,
1427 &pCertContext
->pCertInfo
->Issuer
, &pCertInfo
->Issuer
);
1429 TRACE("returning %d\n", ret
);
1433 static BOOL
compare_cert_by_cert_id(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1434 DWORD dwFlags
, const void *pvPara
)
1436 CERT_ID
*id
= (CERT_ID
*)pvPara
;
1439 switch (id
->dwIdChoice
)
1441 case CERT_ID_ISSUER_SERIAL_NUMBER
:
1442 ret
= CertCompareCertificateName(pCertContext
->dwCertEncodingType
,
1443 &pCertContext
->pCertInfo
->Issuer
, &id
->u
.IssuerSerialNumber
.Issuer
);
1445 ret
= CertCompareIntegerBlob(&pCertContext
->pCertInfo
->SerialNumber
,
1446 &id
->u
.IssuerSerialNumber
.SerialNumber
);
1448 case CERT_ID_SHA1_HASH
:
1449 ret
= compare_cert_by_sha1_hash(pCertContext
, dwType
, dwFlags
,
1452 case CERT_ID_KEY_IDENTIFIER
:
1456 ret
= CertGetCertificateContextProperty(pCertContext
,
1457 CERT_KEY_IDENTIFIER_PROP_ID
, NULL
, &size
);
1458 if (ret
&& size
== id
->u
.KeyId
.cbData
)
1460 LPBYTE buf
= CryptMemAlloc(size
);
1464 CertGetCertificateContextProperty(pCertContext
,
1465 CERT_KEY_IDENTIFIER_PROP_ID
, buf
, &size
);
1466 ret
= !memcmp(buf
, id
->u
.KeyId
.pbData
, size
);
1481 static BOOL
compare_existing_cert(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1482 DWORD dwFlags
, const void *pvPara
)
1484 PCCERT_CONTEXT toCompare
= pvPara
;
1485 return CertCompareCertificate(pCertContext
->dwCertEncodingType
,
1486 pCertContext
->pCertInfo
, toCompare
->pCertInfo
);
1489 static BOOL
compare_cert_by_signature_hash(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1490 DWORD dwFlags
, const void *pvPara
)
1492 const CRYPT_HASH_BLOB
*hash
= pvPara
;
1496 ret
= CertGetCertificateContextProperty(pCertContext
,
1497 CERT_SIGNATURE_HASH_PROP_ID
, NULL
, &size
);
1498 if (ret
&& size
== hash
->cbData
)
1500 LPBYTE buf
= CryptMemAlloc(size
);
1504 CertGetCertificateContextProperty(pCertContext
,
1505 CERT_SIGNATURE_HASH_PROP_ID
, buf
, &size
);
1506 ret
= !memcmp(buf
, hash
->pbData
, size
);
1515 static inline PCCERT_CONTEXT
cert_compare_certs_in_store(HCERTSTORE store
,
1516 PCCERT_CONTEXT prev
, CertCompareFunc compare
, DWORD dwType
, DWORD dwFlags
,
1519 BOOL matches
= FALSE
;
1524 ret
= CertEnumCertificatesInStore(store
, ret
);
1526 matches
= compare(ret
, dwType
, dwFlags
, pvPara
);
1527 } while (ret
!= NULL
&& !matches
);
1531 typedef PCCERT_CONTEXT (*CertFindFunc
)(HCERTSTORE store
, DWORD dwType
,
1532 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
);
1534 static PCCERT_CONTEXT
find_cert_any(HCERTSTORE store
, DWORD dwType
,
1535 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
)
1537 return CertEnumCertificatesInStore(store
, prev
);
1540 static PCCERT_CONTEXT
find_cert_by_issuer(HCERTSTORE store
, DWORD dwType
,
1541 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
)
1544 PCCERT_CONTEXT found
= NULL
, subject
= pvPara
;
1545 PCERT_EXTENSION ext
;
1548 if ((ext
= CertFindExtension(szOID_AUTHORITY_KEY_IDENTIFIER
,
1549 subject
->pCertInfo
->cExtension
, subject
->pCertInfo
->rgExtension
)))
1551 CERT_AUTHORITY_KEY_ID_INFO
*info
;
1553 ret
= CryptDecodeObjectEx(subject
->dwCertEncodingType
,
1554 X509_AUTHORITY_KEY_ID
, ext
->Value
.pbData
, ext
->Value
.cbData
,
1555 CRYPT_DECODE_ALLOC_FLAG
| CRYPT_DECODE_NOCOPY_FLAG
, NULL
,
1561 if (info
->CertIssuer
.cbData
&& info
->CertSerialNumber
.cbData
)
1563 id
.dwIdChoice
= CERT_ID_ISSUER_SERIAL_NUMBER
;
1564 memcpy(&id
.u
.IssuerSerialNumber
.Issuer
, &info
->CertIssuer
,
1565 sizeof(CERT_NAME_BLOB
));
1566 memcpy(&id
.u
.IssuerSerialNumber
.SerialNumber
,
1567 &info
->CertSerialNumber
, sizeof(CRYPT_INTEGER_BLOB
));
1569 else if (info
->KeyId
.cbData
)
1571 id
.dwIdChoice
= CERT_ID_KEY_IDENTIFIER
;
1572 memcpy(&id
.u
.KeyId
, &info
->KeyId
, sizeof(CRYPT_HASH_BLOB
));
1577 found
= cert_compare_certs_in_store(store
, prev
,
1578 compare_cert_by_cert_id
, dwType
, dwFlags
, &id
);
1582 else if ((ext
= CertFindExtension(szOID_AUTHORITY_KEY_IDENTIFIER2
,
1583 subject
->pCertInfo
->cExtension
, subject
->pCertInfo
->rgExtension
)))
1585 CERT_AUTHORITY_KEY_ID2_INFO
*info
;
1587 ret
= CryptDecodeObjectEx(subject
->dwCertEncodingType
,
1588 X509_AUTHORITY_KEY_ID2
, ext
->Value
.pbData
, ext
->Value
.cbData
,
1589 CRYPT_DECODE_ALLOC_FLAG
| CRYPT_DECODE_NOCOPY_FLAG
, NULL
,
1595 if (info
->AuthorityCertIssuer
.cAltEntry
&&
1596 info
->AuthorityCertSerialNumber
.cbData
)
1598 PCERT_ALT_NAME_ENTRY directoryName
= NULL
;
1601 for (i
= 0; !directoryName
&&
1602 i
< info
->AuthorityCertIssuer
.cAltEntry
; i
++)
1603 if (info
->AuthorityCertIssuer
.rgAltEntry
[i
].dwAltNameChoice
1604 == CERT_ALT_NAME_DIRECTORY_NAME
)
1606 &info
->AuthorityCertIssuer
.rgAltEntry
[i
];
1609 id
.dwIdChoice
= CERT_ID_ISSUER_SERIAL_NUMBER
;
1610 memcpy(&id
.u
.IssuerSerialNumber
.Issuer
,
1611 &directoryName
->u
.DirectoryName
, sizeof(CERT_NAME_BLOB
));
1612 memcpy(&id
.u
.IssuerSerialNumber
.SerialNumber
,
1613 &info
->AuthorityCertSerialNumber
,
1614 sizeof(CRYPT_INTEGER_BLOB
));
1618 FIXME("no supported name type in authority key id2\n");
1622 else if (info
->KeyId
.cbData
)
1624 id
.dwIdChoice
= CERT_ID_KEY_IDENTIFIER
;
1625 memcpy(&id
.u
.KeyId
, &info
->KeyId
, sizeof(CRYPT_HASH_BLOB
));
1630 found
= cert_compare_certs_in_store(store
, prev
,
1631 compare_cert_by_cert_id
, dwType
, dwFlags
, &id
);
1636 found
= cert_compare_certs_in_store(store
, prev
,
1637 compare_cert_by_name
, CERT_COMPARE_NAME
| CERT_COMPARE_SUBJECT_CERT
,
1638 dwFlags
, &subject
->pCertInfo
->Issuer
);
1642 static BOOL
compare_cert_by_name_str(PCCERT_CONTEXT pCertContext
,
1643 DWORD dwType
, DWORD dwFlags
, const void *pvPara
)
1645 PCERT_NAME_BLOB name
;
1649 if (dwType
& CERT_INFO_SUBJECT_FLAG
)
1650 name
= &pCertContext
->pCertInfo
->Subject
;
1652 name
= &pCertContext
->pCertInfo
->Issuer
;
1653 len
= CertNameToStrW(pCertContext
->dwCertEncodingType
, name
,
1654 CERT_SIMPLE_NAME_STR
, NULL
, 0);
1657 LPWSTR str
= CryptMemAlloc(len
* sizeof(WCHAR
));
1663 CertNameToStrW(pCertContext
->dwCertEncodingType
, name
,
1664 CERT_SIMPLE_NAME_STR
, str
, len
);
1665 for (ptr
= str
; *ptr
; ptr
++)
1666 *ptr
= tolowerW(*ptr
);
1667 if (strstrW(str
, pvPara
))
1675 static PCCERT_CONTEXT
find_cert_by_name_str_a(HCERTSTORE store
, DWORD dwType
,
1676 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
)
1678 PCCERT_CONTEXT found
= NULL
;
1680 TRACE("%s\n", debugstr_a(pvPara
));
1684 int len
= MultiByteToWideChar(CP_ACP
, 0, pvPara
, -1, NULL
, 0);
1685 LPWSTR str
= CryptMemAlloc(len
* sizeof(WCHAR
));
1691 MultiByteToWideChar(CP_ACP
, 0, pvPara
, -1, str
, len
);
1692 for (ptr
= str
; *ptr
; ptr
++)
1693 *ptr
= tolowerW(*ptr
);
1694 found
= cert_compare_certs_in_store(store
, prev
,
1695 compare_cert_by_name_str
, dwType
, dwFlags
, str
);
1700 found
= find_cert_any(store
, dwType
, dwFlags
, NULL
, prev
);
1704 static PCCERT_CONTEXT
find_cert_by_name_str_w(HCERTSTORE store
, DWORD dwType
,
1705 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
)
1707 PCCERT_CONTEXT found
= NULL
;
1709 TRACE("%s\n", debugstr_w(pvPara
));
1713 DWORD len
= strlenW(pvPara
);
1714 LPWSTR str
= CryptMemAlloc((len
+ 1) * sizeof(WCHAR
));
1721 for (src
= pvPara
, dst
= str
; *src
; src
++, dst
++)
1722 *dst
= tolowerW(*src
);
1724 found
= cert_compare_certs_in_store(store
, prev
,
1725 compare_cert_by_name_str
, dwType
, dwFlags
, str
);
1730 found
= find_cert_any(store
, dwType
, dwFlags
, NULL
, prev
);
1734 PCCERT_CONTEXT WINAPI
CertFindCertificateInStore(HCERTSTORE hCertStore
,
1735 DWORD dwCertEncodingType
, DWORD dwFlags
, DWORD dwType
, const void *pvPara
,
1736 PCCERT_CONTEXT pPrevCertContext
)
1739 CertFindFunc find
= NULL
;
1740 CertCompareFunc compare
= NULL
;
1742 TRACE("(%p, %08x, %08x, %08x, %p, %p)\n", hCertStore
, dwCertEncodingType
,
1743 dwFlags
, dwType
, pvPara
, pPrevCertContext
);
1745 switch (dwType
>> CERT_COMPARE_SHIFT
)
1747 case CERT_COMPARE_ANY
:
1748 find
= find_cert_any
;
1750 case CERT_COMPARE_MD5_HASH
:
1751 compare
= compare_cert_by_md5_hash
;
1753 case CERT_COMPARE_SHA1_HASH
:
1754 compare
= compare_cert_by_sha1_hash
;
1756 case CERT_COMPARE_NAME
:
1757 compare
= compare_cert_by_name
;
1759 case CERT_COMPARE_PUBLIC_KEY
:
1760 compare
= compare_cert_by_public_key
;
1762 case CERT_COMPARE_NAME_STR_A
:
1763 find
= find_cert_by_name_str_a
;
1765 case CERT_COMPARE_NAME_STR_W
:
1766 find
= find_cert_by_name_str_w
;
1768 case CERT_COMPARE_SUBJECT_CERT
:
1769 compare
= compare_cert_by_subject_cert
;
1771 case CERT_COMPARE_CERT_ID
:
1772 compare
= compare_cert_by_cert_id
;
1774 case CERT_COMPARE_ISSUER_OF
:
1775 find
= find_cert_by_issuer
;
1777 case CERT_COMPARE_EXISTING
:
1778 compare
= compare_existing_cert
;
1780 case CERT_COMPARE_SIGNATURE_HASH
:
1781 compare
= compare_cert_by_signature_hash
;
1784 FIXME("find type %08x unimplemented\n", dwType
);
1788 ret
= find(hCertStore
, dwFlags
, dwType
, pvPara
, pPrevCertContext
);
1790 ret
= cert_compare_certs_in_store(hCertStore
, pPrevCertContext
,
1791 compare
, dwType
, dwFlags
, pvPara
);
1795 SetLastError(CRYPT_E_NOT_FOUND
);
1796 TRACE("returning %p\n", ret
);
1800 PCCERT_CONTEXT WINAPI
CertGetSubjectCertificateFromStore(HCERTSTORE hCertStore
,
1801 DWORD dwCertEncodingType
, PCERT_INFO pCertId
)
1803 TRACE("(%p, %08x, %p)\n", hCertStore
, dwCertEncodingType
, pCertId
);
1807 SetLastError(E_INVALIDARG
);
1810 return CertFindCertificateInStore(hCertStore
, dwCertEncodingType
, 0,
1811 CERT_FIND_SUBJECT_CERT
, pCertId
, NULL
);
1814 BOOL WINAPI
CertVerifySubjectCertificateContext(PCCERT_CONTEXT pSubject
,
1815 PCCERT_CONTEXT pIssuer
, DWORD
*pdwFlags
)
1817 static const DWORD supportedFlags
= CERT_STORE_REVOCATION_FLAG
|
1818 CERT_STORE_SIGNATURE_FLAG
| CERT_STORE_TIME_VALIDITY_FLAG
;
1820 if (*pdwFlags
& ~supportedFlags
)
1822 SetLastError(E_INVALIDARG
);
1825 if (*pdwFlags
& CERT_STORE_REVOCATION_FLAG
)
1828 PCCRL_CONTEXT crl
= CertGetCRLFromStore(pSubject
->hCertStore
, pSubject
,
1831 /* FIXME: what if the CRL has expired? */
1834 if (CertVerifyCRLRevocation(pSubject
->dwCertEncodingType
,
1835 pSubject
->pCertInfo
, 1, (PCRL_INFO
*)&crl
->pCrlInfo
))
1836 *pdwFlags
&= CERT_STORE_REVOCATION_FLAG
;
1839 *pdwFlags
|= CERT_STORE_NO_CRL_FLAG
;
1841 if (*pdwFlags
& CERT_STORE_TIME_VALIDITY_FLAG
)
1843 if (0 == CertVerifyTimeValidity(NULL
, pSubject
->pCertInfo
))
1844 *pdwFlags
&= ~CERT_STORE_TIME_VALIDITY_FLAG
;
1846 if (*pdwFlags
& CERT_STORE_SIGNATURE_FLAG
)
1848 if (CryptVerifyCertificateSignatureEx(0, pSubject
->dwCertEncodingType
,
1849 CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT
, (void *)pSubject
,
1850 CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT
, (void *)pIssuer
, 0, NULL
))
1851 *pdwFlags
&= ~CERT_STORE_SIGNATURE_FLAG
;
1856 PCCERT_CONTEXT WINAPI
CertGetIssuerCertificateFromStore(HCERTSTORE hCertStore
,
1857 PCCERT_CONTEXT pSubjectContext
, PCCERT_CONTEXT pPrevIssuerContext
,
1862 TRACE("(%p, %p, %p, %08x)\n", hCertStore
, pSubjectContext
,
1863 pPrevIssuerContext
, *pdwFlags
);
1865 if (!pSubjectContext
)
1867 SetLastError(E_INVALIDARG
);
1871 ret
= CertFindCertificateInStore(hCertStore
,
1872 pSubjectContext
->dwCertEncodingType
, 0, CERT_FIND_ISSUER_OF
,
1873 pSubjectContext
, pPrevIssuerContext
);
1876 if (!CertVerifySubjectCertificateContext(pSubjectContext
, ret
,
1879 CertFreeCertificateContext(ret
);
1883 TRACE("returning %p\n", ret
);
1887 typedef struct _OLD_CERT_REVOCATION_STATUS
{
1892 } OLD_CERT_REVOCATION_STATUS
;
1894 typedef BOOL (WINAPI
*CertVerifyRevocationFunc
)(DWORD
, DWORD
, DWORD
,
1895 void **, DWORD
, PCERT_REVOCATION_PARA
, PCERT_REVOCATION_STATUS
);
1897 BOOL WINAPI
CertVerifyRevocation(DWORD dwEncodingType
, DWORD dwRevType
,
1898 DWORD cContext
, PVOID rgpvContext
[], DWORD dwFlags
,
1899 PCERT_REVOCATION_PARA pRevPara
, PCERT_REVOCATION_STATUS pRevStatus
)
1903 TRACE("(%08x, %d, %d, %p, %08x, %p, %p)\n", dwEncodingType
, dwRevType
,
1904 cContext
, rgpvContext
, dwFlags
, pRevPara
, pRevStatus
);
1906 if (pRevStatus
->cbSize
!= sizeof(OLD_CERT_REVOCATION_STATUS
) &&
1907 pRevStatus
->cbSize
!= sizeof(CERT_REVOCATION_STATUS
))
1909 SetLastError(E_INVALIDARG
);
1914 static HCRYPTOIDFUNCSET set
= NULL
;
1918 set
= CryptInitOIDFunctionSet(CRYPT_OID_VERIFY_REVOCATION_FUNC
, 0);
1919 ret
= CryptGetDefaultOIDDllList(set
, dwEncodingType
, NULL
, &size
);
1925 SetLastError(CRYPT_E_NO_REVOCATION_DLL
);
1930 LPWSTR dllList
= CryptMemAlloc(size
* sizeof(WCHAR
)), ptr
;
1934 ret
= CryptGetDefaultOIDDllList(set
, dwEncodingType
,
1938 for (ptr
= dllList
; ret
&& *ptr
;
1939 ptr
+= lstrlenW(ptr
) + 1)
1941 CertVerifyRevocationFunc func
;
1942 HCRYPTOIDFUNCADDR hFunc
;
1944 ret
= CryptGetDefaultOIDFunctionAddress(set
,
1945 dwEncodingType
, ptr
, 0, (void **)&func
, &hFunc
);
1948 ret
= func(dwEncodingType
, dwRevType
, cContext
,
1949 rgpvContext
, dwFlags
, pRevPara
, pRevStatus
);
1950 CryptFreeOIDFunctionAddress(hFunc
, 0);
1954 CryptMemFree(dllList
);
1958 SetLastError(ERROR_OUTOFMEMORY
);
1969 PCRYPT_ATTRIBUTE WINAPI
CertFindAttribute(LPCSTR pszObjId
, DWORD cAttr
,
1970 CRYPT_ATTRIBUTE rgAttr
[])
1972 PCRYPT_ATTRIBUTE ret
= NULL
;
1975 TRACE("%s %d %p\n", debugstr_a(pszObjId
), cAttr
, rgAttr
);
1981 SetLastError(ERROR_INVALID_PARAMETER
);
1985 for (i
= 0; !ret
&& i
< cAttr
; i
++)
1986 if (rgAttr
[i
].pszObjId
&& !strcmp(pszObjId
, rgAttr
[i
].pszObjId
))
1991 PCERT_EXTENSION WINAPI
CertFindExtension(LPCSTR pszObjId
, DWORD cExtensions
,
1992 CERT_EXTENSION rgExtensions
[])
1994 PCERT_EXTENSION ret
= NULL
;
1997 TRACE("%s %d %p\n", debugstr_a(pszObjId
), cExtensions
, rgExtensions
);
2003 SetLastError(ERROR_INVALID_PARAMETER
);
2007 for (i
= 0; !ret
&& i
< cExtensions
; i
++)
2008 if (rgExtensions
[i
].pszObjId
&& !strcmp(pszObjId
,
2009 rgExtensions
[i
].pszObjId
))
2010 ret
= &rgExtensions
[i
];
2014 PCERT_RDN_ATTR WINAPI
CertFindRDNAttr(LPCSTR pszObjId
, PCERT_NAME_INFO pName
)
2016 PCERT_RDN_ATTR ret
= NULL
;
2019 TRACE("%s %p\n", debugstr_a(pszObjId
), pName
);
2023 SetLastError(ERROR_INVALID_PARAMETER
);
2027 for (i
= 0; !ret
&& i
< pName
->cRDN
; i
++)
2028 for (j
= 0; !ret
&& j
< pName
->rgRDN
[i
].cRDNAttr
; j
++)
2029 if (pName
->rgRDN
[i
].rgRDNAttr
[j
].pszObjId
&& !strcmp(pszObjId
,
2030 pName
->rgRDN
[i
].rgRDNAttr
[j
].pszObjId
))
2031 ret
= &pName
->rgRDN
[i
].rgRDNAttr
[j
];
2035 static BOOL
find_matching_rdn_attr(DWORD dwFlags
, const CERT_NAME_INFO
*name
,
2036 const CERT_RDN_ATTR
*attr
)
2041 for (i
= 0; !match
&& i
< name
->cRDN
; i
++)
2043 for (j
= 0; j
< name
->rgRDN
[i
].cRDNAttr
; j
++)
2045 if (!strcmp(name
->rgRDN
[i
].rgRDNAttr
[j
].pszObjId
,
2047 name
->rgRDN
[i
].rgRDNAttr
[j
].dwValueType
==
2050 if (dwFlags
& CERT_UNICODE_IS_RDN_ATTRS_FLAG
)
2053 (LPCWSTR
)name
->rgRDN
[i
].rgRDNAttr
[j
].Value
.pbData
;
2054 LPCWSTR attrStr
= (LPCWSTR
)attr
->Value
.pbData
;
2056 if (attr
->Value
.cbData
!=
2057 name
->rgRDN
[i
].rgRDNAttr
[j
].Value
.cbData
)
2059 else if (dwFlags
& CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG
)
2060 match
= !strncmpiW(nameStr
, attrStr
,
2061 attr
->Value
.cbData
/ sizeof(WCHAR
));
2063 match
= !strncmpW(nameStr
, attrStr
,
2064 attr
->Value
.cbData
/ sizeof(WCHAR
));
2065 TRACE("%s : %s => %d\n",
2066 debugstr_wn(nameStr
, attr
->Value
.cbData
/ sizeof(WCHAR
)),
2067 debugstr_wn(attrStr
, attr
->Value
.cbData
/ sizeof(WCHAR
)),
2073 (LPCSTR
)name
->rgRDN
[i
].rgRDNAttr
[j
].Value
.pbData
;
2074 LPCSTR attrStr
= (LPCSTR
)attr
->Value
.pbData
;
2076 if (attr
->Value
.cbData
!=
2077 name
->rgRDN
[i
].rgRDNAttr
[j
].Value
.cbData
)
2079 else if (dwFlags
& CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG
)
2080 match
= !strncasecmp(nameStr
, attrStr
,
2081 attr
->Value
.cbData
);
2083 match
= !strncmp(nameStr
, attrStr
, attr
->Value
.cbData
);
2084 TRACE("%s : %s => %d\n",
2085 debugstr_an(nameStr
, attr
->Value
.cbData
),
2086 debugstr_an(attrStr
, attr
->Value
.cbData
), match
);
2094 BOOL WINAPI
CertIsRDNAttrsInCertificateName(DWORD dwCertEncodingType
,
2095 DWORD dwFlags
, PCERT_NAME_BLOB pCertName
, PCERT_RDN pRDN
)
2097 CERT_NAME_INFO
*name
;
2102 TRACE("(%08x, %08x, %p, %p)\n", dwCertEncodingType
, dwFlags
, pCertName
,
2105 type
= dwFlags
& CERT_UNICODE_IS_RDN_ATTRS_FLAG
? X509_UNICODE_NAME
:
2107 if ((ret
= CryptDecodeObjectEx(dwCertEncodingType
, type
, pCertName
->pbData
,
2108 pCertName
->cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
, &name
, &size
)))
2112 for (i
= 0; ret
&& i
< pRDN
->cRDNAttr
; i
++)
2113 ret
= find_matching_rdn_attr(dwFlags
, name
, &pRDN
->rgRDNAttr
[i
]);
2115 SetLastError(CRYPT_E_NO_MATCH
);
2121 LONG WINAPI
CertVerifyTimeValidity(LPFILETIME pTimeToVerify
,
2122 PCERT_INFO pCertInfo
)
2129 GetSystemTimeAsFileTime(&fileTime
);
2130 pTimeToVerify
= &fileTime
;
2132 if ((ret
= CompareFileTime(pTimeToVerify
, &pCertInfo
->NotBefore
)) >= 0)
2134 ret
= CompareFileTime(pTimeToVerify
, &pCertInfo
->NotAfter
);
2141 BOOL WINAPI
CertVerifyValidityNesting(PCERT_INFO pSubjectInfo
,
2142 PCERT_INFO pIssuerInfo
)
2144 TRACE("(%p, %p)\n", pSubjectInfo
, pIssuerInfo
);
2146 return CertVerifyTimeValidity(&pSubjectInfo
->NotBefore
, pIssuerInfo
) == 0
2147 && CertVerifyTimeValidity(&pSubjectInfo
->NotAfter
, pIssuerInfo
) == 0;
2150 BOOL WINAPI
CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv
, ALG_ID Algid
,
2151 DWORD dwFlags
, const BYTE
*pbEncoded
, DWORD cbEncoded
, BYTE
*pbComputedHash
,
2152 DWORD
*pcbComputedHash
)
2155 HCRYPTHASH hHash
= 0;
2157 TRACE("(%08lx, %d, %08x, %p, %d, %p, %p)\n", hCryptProv
, Algid
, dwFlags
,
2158 pbEncoded
, cbEncoded
, pbComputedHash
, pcbComputedHash
);
2161 hCryptProv
= CRYPT_GetDefaultProvider();
2166 ret
= CryptCreateHash(hCryptProv
, Algid
, 0, 0, &hHash
);
2169 ret
= CryptHashData(hHash
, pbEncoded
, cbEncoded
, 0);
2171 ret
= CryptGetHashParam(hHash
, HP_HASHVAL
, pbComputedHash
,
2172 pcbComputedHash
, 0);
2173 CryptDestroyHash(hHash
);
2179 BOOL WINAPI
CryptHashPublicKeyInfo(HCRYPTPROV_LEGACY hCryptProv
, ALG_ID Algid
,
2180 DWORD dwFlags
, DWORD dwCertEncodingType
, PCERT_PUBLIC_KEY_INFO pInfo
,
2181 BYTE
*pbComputedHash
, DWORD
*pcbComputedHash
)
2184 HCRYPTHASH hHash
= 0;
2186 TRACE("(%08lx, %d, %08x, %d, %p, %p, %p)\n", hCryptProv
, Algid
, dwFlags
,
2187 dwCertEncodingType
, pInfo
, pbComputedHash
, pcbComputedHash
);
2190 hCryptProv
= CRYPT_GetDefaultProvider();
2193 if ((dwCertEncodingType
& CERT_ENCODING_TYPE_MASK
) != X509_ASN_ENCODING
)
2195 SetLastError(ERROR_FILE_NOT_FOUND
);
2203 ret
= CRYPT_AsnEncodePubKeyInfoNoNull(dwCertEncodingType
,
2204 X509_PUBLIC_KEY_INFO
, pInfo
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
,
2205 (LPBYTE
)&buf
, &size
);
2208 ret
= CryptCreateHash(hCryptProv
, Algid
, 0, 0, &hHash
);
2211 ret
= CryptHashData(hHash
, buf
, size
, 0);
2213 ret
= CryptGetHashParam(hHash
, HP_HASHVAL
, pbComputedHash
,
2214 pcbComputedHash
, 0);
2215 CryptDestroyHash(hHash
);
2223 BOOL WINAPI
CryptHashToBeSigned(HCRYPTPROV_LEGACY hCryptProv
,
2224 DWORD dwCertEncodingType
, const BYTE
*pbEncoded
, DWORD cbEncoded
,
2225 BYTE
*pbComputedHash
, DWORD
*pcbComputedHash
)
2228 CERT_SIGNED_CONTENT_INFO
*info
;
2231 TRACE("(%08lx, %08x, %p, %d, %p, %d)\n", hCryptProv
, dwCertEncodingType
,
2232 pbEncoded
, cbEncoded
, pbComputedHash
, *pcbComputedHash
);
2234 ret
= CryptDecodeObjectEx(dwCertEncodingType
, X509_CERT
,
2235 pbEncoded
, cbEncoded
, CRYPT_DECODE_ALLOC_FLAG
, NULL
, &info
, &size
);
2238 PCCRYPT_OID_INFO oidInfo
;
2242 hCryptProv
= CRYPT_GetDefaultProvider();
2243 oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2244 info
->SignatureAlgorithm
.pszObjId
, 0);
2247 SetLastError(NTE_BAD_ALGID
);
2252 ret
= CryptCreateHash(hCryptProv
, oidInfo
->u
.Algid
, 0, 0, &hHash
);
2255 ret
= CryptHashData(hHash
, info
->ToBeSigned
.pbData
,
2256 info
->ToBeSigned
.cbData
, 0);
2258 ret
= CryptGetHashParam(hHash
, HP_HASHVAL
, pbComputedHash
,
2259 pcbComputedHash
, 0);
2260 CryptDestroyHash(hHash
);
2268 BOOL WINAPI
CryptSignCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProv
,
2269 DWORD dwKeySpec
, DWORD dwCertEncodingType
, const BYTE
*pbEncodedToBeSigned
,
2270 DWORD cbEncodedToBeSigned
, PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm
,
2271 const void *pvHashAuxInfo
, BYTE
*pbSignature
, DWORD
*pcbSignature
)
2274 PCCRYPT_OID_INFO info
;
2277 TRACE("(%08lx, %d, %d, %p, %d, %p, %p, %p, %p)\n", hCryptProv
,
2278 dwKeySpec
, dwCertEncodingType
, pbEncodedToBeSigned
, cbEncodedToBeSigned
,
2279 pSignatureAlgorithm
, pvHashAuxInfo
, pbSignature
, pcbSignature
);
2281 info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2282 pSignatureAlgorithm
->pszObjId
, 0);
2285 SetLastError(NTE_BAD_ALGID
);
2288 if (info
->dwGroupId
== CRYPT_HASH_ALG_OID_GROUP_ID
)
2291 hCryptProv
= CRYPT_GetDefaultProvider();
2292 ret
= CryptCreateHash(hCryptProv
, info
->u
.Algid
, 0, 0, &hHash
);
2295 ret
= CryptHashData(hHash
, pbEncodedToBeSigned
,
2296 cbEncodedToBeSigned
, 0);
2298 ret
= CryptGetHashParam(hHash
, HP_HASHVAL
, pbSignature
,
2300 CryptDestroyHash(hHash
);
2307 SetLastError(ERROR_INVALID_PARAMETER
);
2312 ret
= CryptCreateHash(hCryptProv
, info
->u
.Algid
, 0, 0, &hHash
);
2315 ret
= CryptHashData(hHash
, pbEncodedToBeSigned
,
2316 cbEncodedToBeSigned
, 0);
2318 ret
= CryptSignHashW(hHash
, dwKeySpec
, NULL
, 0, pbSignature
,
2320 CryptDestroyHash(hHash
);
2327 BOOL WINAPI
CryptSignAndEncodeCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProv
,
2328 DWORD dwKeySpec
, DWORD dwCertEncodingType
, LPCSTR lpszStructType
,
2329 const void *pvStructInfo
, PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm
,
2330 const void *pvHashAuxInfo
, BYTE
*pbEncoded
, DWORD
*pcbEncoded
)
2333 DWORD encodedSize
, hashSize
;
2335 TRACE("(%08lx, %d, %d, %s, %p, %p, %p, %p, %p)\n", hCryptProv
, dwKeySpec
,
2336 dwCertEncodingType
, debugstr_a(lpszStructType
), pvStructInfo
,
2337 pSignatureAlgorithm
, pvHashAuxInfo
, pbEncoded
, pcbEncoded
);
2339 ret
= CryptEncodeObject(dwCertEncodingType
, lpszStructType
, pvStructInfo
,
2340 NULL
, &encodedSize
);
2343 PBYTE encoded
= CryptMemAlloc(encodedSize
);
2347 ret
= CryptEncodeObject(dwCertEncodingType
, lpszStructType
,
2348 pvStructInfo
, encoded
, &encodedSize
);
2351 ret
= CryptSignCertificate(hCryptProv
, dwKeySpec
,
2352 dwCertEncodingType
, encoded
, encodedSize
, pSignatureAlgorithm
,
2353 pvHashAuxInfo
, NULL
, &hashSize
);
2356 PBYTE hash
= CryptMemAlloc(hashSize
);
2360 ret
= CryptSignCertificate(hCryptProv
, dwKeySpec
,
2361 dwCertEncodingType
, encoded
, encodedSize
,
2362 pSignatureAlgorithm
, pvHashAuxInfo
, hash
, &hashSize
);
2365 CERT_SIGNED_CONTENT_INFO info
= { { 0 } };
2367 info
.ToBeSigned
.cbData
= encodedSize
;
2368 info
.ToBeSigned
.pbData
= encoded
;
2369 info
.SignatureAlgorithm
= *pSignatureAlgorithm
;
2370 info
.Signature
.cbData
= hashSize
;
2371 info
.Signature
.pbData
= hash
;
2372 info
.Signature
.cUnusedBits
= 0;
2373 ret
= CryptEncodeObject(dwCertEncodingType
,
2374 X509_CERT
, &info
, pbEncoded
, pcbEncoded
);
2380 CryptMemFree(encoded
);
2386 BOOL WINAPI
CryptVerifyCertificateSignature(HCRYPTPROV_LEGACY hCryptProv
,
2387 DWORD dwCertEncodingType
, const BYTE
*pbEncoded
, DWORD cbEncoded
,
2388 PCERT_PUBLIC_KEY_INFO pPublicKey
)
2390 CRYPT_DATA_BLOB blob
= { cbEncoded
, (BYTE
*)pbEncoded
};
2392 return CryptVerifyCertificateSignatureEx(hCryptProv
, dwCertEncodingType
,
2393 CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB
, &blob
,
2394 CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY
, pPublicKey
, 0, NULL
);
2397 static BOOL
CRYPT_VerifyCertSignatureFromPublicKeyInfo(HCRYPTPROV_LEGACY hCryptProv
,
2398 DWORD dwCertEncodingType
, PCERT_PUBLIC_KEY_INFO pubKeyInfo
,
2399 const CERT_SIGNED_CONTENT_INFO
*signedCert
)
2403 PCCRYPT_OID_INFO info
;
2404 ALG_ID pubKeyID
, hashID
;
2406 info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2407 signedCert
->SignatureAlgorithm
.pszObjId
, 0);
2408 if (!info
|| info
->dwGroupId
!= CRYPT_SIGN_ALG_OID_GROUP_ID
)
2410 SetLastError(NTE_BAD_ALGID
);
2413 hashID
= info
->u
.Algid
;
2414 if (info
->ExtraInfo
.cbData
>= sizeof(ALG_ID
))
2415 pubKeyID
= *(ALG_ID
*)info
->ExtraInfo
.pbData
;
2418 /* Load the default provider if necessary */
2420 hCryptProv
= CRYPT_GetDefaultProvider();
2421 ret
= CryptImportPublicKeyInfoEx(hCryptProv
, dwCertEncodingType
,
2422 pubKeyInfo
, pubKeyID
, 0, NULL
, &key
);
2427 ret
= CryptCreateHash(hCryptProv
, hashID
, 0, 0, &hash
);
2430 ret
= CryptHashData(hash
, signedCert
->ToBeSigned
.pbData
,
2431 signedCert
->ToBeSigned
.cbData
, 0);
2433 ret
= CryptVerifySignatureW(hash
, signedCert
->Signature
.pbData
,
2434 signedCert
->Signature
.cbData
, key
, NULL
, 0);
2435 CryptDestroyHash(hash
);
2437 CryptDestroyKey(key
);
2442 BOOL WINAPI
CryptVerifyCertificateSignatureEx(HCRYPTPROV_LEGACY hCryptProv
,
2443 DWORD dwCertEncodingType
, DWORD dwSubjectType
, void *pvSubject
,
2444 DWORD dwIssuerType
, void *pvIssuer
, DWORD dwFlags
, void *pvReserved
)
2447 CRYPT_DATA_BLOB subjectBlob
;
2449 TRACE("(%08lx, %d, %d, %p, %d, %p, %08x, %p)\n", hCryptProv
,
2450 dwCertEncodingType
, dwSubjectType
, pvSubject
, dwIssuerType
, pvIssuer
,
2451 dwFlags
, pvReserved
);
2453 switch (dwSubjectType
)
2455 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB
:
2457 PCRYPT_DATA_BLOB blob
= pvSubject
;
2459 subjectBlob
.pbData
= blob
->pbData
;
2460 subjectBlob
.cbData
= blob
->cbData
;
2463 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT
:
2465 PCERT_CONTEXT context
= pvSubject
;
2467 subjectBlob
.pbData
= context
->pbCertEncoded
;
2468 subjectBlob
.cbData
= context
->cbCertEncoded
;
2471 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL
:
2473 PCRL_CONTEXT context
= pvSubject
;
2475 subjectBlob
.pbData
= context
->pbCrlEncoded
;
2476 subjectBlob
.cbData
= context
->cbCrlEncoded
;
2480 SetLastError(E_INVALIDARG
);
2486 PCERT_SIGNED_CONTENT_INFO signedCert
= NULL
;
2489 ret
= CryptDecodeObjectEx(dwCertEncodingType
, X509_CERT
,
2490 subjectBlob
.pbData
, subjectBlob
.cbData
,
2491 CRYPT_DECODE_ALLOC_FLAG
| CRYPT_DECODE_NOCOPY_FLAG
, NULL
,
2492 &signedCert
, &size
);
2495 switch (dwIssuerType
)
2497 case CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY
:
2498 ret
= CRYPT_VerifyCertSignatureFromPublicKeyInfo(hCryptProv
,
2499 dwCertEncodingType
, pvIssuer
,
2502 case CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT
:
2503 ret
= CRYPT_VerifyCertSignatureFromPublicKeyInfo(hCryptProv
,
2505 &((PCCERT_CONTEXT
)pvIssuer
)->pCertInfo
->SubjectPublicKeyInfo
,
2508 case CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN
:
2509 FIXME("CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN: stub\n");
2512 case CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL
:
2515 SetLastError(E_INVALIDARG
);
2520 FIXME("unimplemented for NULL signer\n");
2521 SetLastError(E_INVALIDARG
);
2526 SetLastError(E_INVALIDARG
);
2529 LocalFree(signedCert
);
2535 BOOL WINAPI
CertGetIntendedKeyUsage(DWORD dwCertEncodingType
,
2536 PCERT_INFO pCertInfo
, BYTE
*pbKeyUsage
, DWORD cbKeyUsage
)
2538 PCERT_EXTENSION ext
;
2541 TRACE("(%08x, %p, %p, %d)\n", dwCertEncodingType
, pCertInfo
, pbKeyUsage
,
2544 ext
= CertFindExtension(szOID_KEY_USAGE
, pCertInfo
->cExtension
,
2545 pCertInfo
->rgExtension
);
2548 CRYPT_BIT_BLOB usage
;
2549 DWORD size
= sizeof(usage
);
2551 ret
= CryptDecodeObjectEx(dwCertEncodingType
, X509_BITS
,
2552 ext
->Value
.pbData
, ext
->Value
.cbData
, CRYPT_DECODE_NOCOPY_FLAG
, NULL
,
2556 if (cbKeyUsage
< usage
.cbData
)
2560 memcpy(pbKeyUsage
, usage
.pbData
, usage
.cbData
);
2561 if (cbKeyUsage
> usage
.cbData
)
2562 memset(pbKeyUsage
+ usage
.cbData
, 0,
2563 cbKeyUsage
- usage
.cbData
);
2572 BOOL WINAPI
CertGetEnhancedKeyUsage(PCCERT_CONTEXT pCertContext
, DWORD dwFlags
,
2573 PCERT_ENHKEY_USAGE pUsage
, DWORD
*pcbUsage
)
2575 PCERT_ENHKEY_USAGE usage
= NULL
;
2579 if (!pCertContext
|| !pcbUsage
)
2581 SetLastError(ERROR_INVALID_PARAMETER
);
2585 TRACE("(%p, %08x, %p, %d)\n", pCertContext
, dwFlags
, pUsage
, *pcbUsage
);
2587 if (!(dwFlags
& CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
))
2591 if (CertGetCertificateContextProperty(pCertContext
,
2592 CERT_ENHKEY_USAGE_PROP_ID
, NULL
, &propSize
))
2594 LPBYTE buf
= CryptMemAlloc(propSize
);
2598 if (CertGetCertificateContextProperty(pCertContext
,
2599 CERT_ENHKEY_USAGE_PROP_ID
, buf
, &propSize
))
2601 ret
= CryptDecodeObjectEx(pCertContext
->dwCertEncodingType
,
2602 X509_ENHANCED_KEY_USAGE
, buf
, propSize
,
2603 CRYPT_ENCODE_ALLOC_FLAG
, NULL
, &usage
, &bytesNeeded
);
2609 if (!usage
&& !(dwFlags
& CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
))
2611 PCERT_EXTENSION ext
= CertFindExtension(szOID_ENHANCED_KEY_USAGE
,
2612 pCertContext
->pCertInfo
->cExtension
,
2613 pCertContext
->pCertInfo
->rgExtension
);
2617 ret
= CryptDecodeObjectEx(pCertContext
->dwCertEncodingType
,
2618 X509_ENHANCED_KEY_USAGE
, ext
->Value
.pbData
, ext
->Value
.cbData
,
2619 CRYPT_ENCODE_ALLOC_FLAG
, NULL
, &usage
, &bytesNeeded
);
2624 /* If a particular location is specified, this should fail. Otherwise
2625 * it should succeed with an empty usage. (This is true on Win2k and
2626 * later, which we emulate.)
2630 SetLastError(CRYPT_E_NOT_FOUND
);
2634 bytesNeeded
= sizeof(CERT_ENHKEY_USAGE
);
2640 *pcbUsage
= bytesNeeded
;
2641 else if (*pcbUsage
< bytesNeeded
)
2643 SetLastError(ERROR_MORE_DATA
);
2644 *pcbUsage
= bytesNeeded
;
2649 *pcbUsage
= bytesNeeded
;
2653 LPSTR nextOID
= (LPSTR
)((LPBYTE
)pUsage
+
2654 sizeof(CERT_ENHKEY_USAGE
) +
2655 usage
->cUsageIdentifier
* sizeof(LPSTR
));
2657 pUsage
->cUsageIdentifier
= usage
->cUsageIdentifier
;
2658 pUsage
->rgpszUsageIdentifier
= (LPSTR
*)((LPBYTE
)pUsage
+
2659 sizeof(CERT_ENHKEY_USAGE
));
2660 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
2662 pUsage
->rgpszUsageIdentifier
[i
] = nextOID
;
2663 strcpy(nextOID
, usage
->rgpszUsageIdentifier
[i
]);
2664 nextOID
+= strlen(nextOID
) + 1;
2668 pUsage
->cUsageIdentifier
= 0;
2673 TRACE("returning %d\n", ret
);
2677 BOOL WINAPI
CertSetEnhancedKeyUsage(PCCERT_CONTEXT pCertContext
,
2678 PCERT_ENHKEY_USAGE pUsage
)
2682 TRACE("(%p, %p)\n", pCertContext
, pUsage
);
2686 CRYPT_DATA_BLOB blob
= { 0, NULL
};
2688 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
, X509_ENHANCED_KEY_USAGE
,
2689 pUsage
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
, &blob
.pbData
, &blob
.cbData
);
2692 ret
= CertSetCertificateContextProperty(pCertContext
,
2693 CERT_ENHKEY_USAGE_PROP_ID
, 0, &blob
);
2694 LocalFree(blob
.pbData
);
2698 ret
= CertSetCertificateContextProperty(pCertContext
,
2699 CERT_ENHKEY_USAGE_PROP_ID
, 0, NULL
);
2703 BOOL WINAPI
CertAddEnhancedKeyUsageIdentifier(PCCERT_CONTEXT pCertContext
,
2704 LPCSTR pszUsageIdentifier
)
2709 TRACE("(%p, %s)\n", pCertContext
, debugstr_a(pszUsageIdentifier
));
2711 if (CertGetEnhancedKeyUsage(pCertContext
,
2712 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, NULL
, &size
))
2714 PCERT_ENHKEY_USAGE usage
= CryptMemAlloc(size
);
2718 ret
= CertGetEnhancedKeyUsage(pCertContext
,
2719 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
);
2723 BOOL exists
= FALSE
;
2725 /* Make sure usage doesn't already exist */
2726 for (i
= 0; !exists
&& i
< usage
->cUsageIdentifier
; i
++)
2728 if (!strcmp(usage
->rgpszUsageIdentifier
[i
],
2729 pszUsageIdentifier
))
2734 PCERT_ENHKEY_USAGE newUsage
= CryptMemAlloc(size
+
2735 sizeof(LPSTR
) + strlen(pszUsageIdentifier
) + 1);
2741 newUsage
->rgpszUsageIdentifier
= (LPSTR
*)
2742 ((LPBYTE
)newUsage
+ sizeof(CERT_ENHKEY_USAGE
));
2743 nextOID
= (LPSTR
)((LPBYTE
)newUsage
->rgpszUsageIdentifier
2744 + (usage
->cUsageIdentifier
+ 1) * sizeof(LPSTR
));
2745 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
2747 newUsage
->rgpszUsageIdentifier
[i
] = nextOID
;
2748 strcpy(nextOID
, usage
->rgpszUsageIdentifier
[i
]);
2749 nextOID
+= strlen(nextOID
) + 1;
2751 newUsage
->rgpszUsageIdentifier
[i
] = nextOID
;
2752 strcpy(nextOID
, pszUsageIdentifier
);
2753 newUsage
->cUsageIdentifier
= i
+ 1;
2754 ret
= CertSetEnhancedKeyUsage(pCertContext
, newUsage
);
2755 CryptMemFree(newUsage
);
2761 CryptMemFree(usage
);
2768 PCERT_ENHKEY_USAGE usage
= CryptMemAlloc(sizeof(CERT_ENHKEY_USAGE
) +
2769 sizeof(LPSTR
) + strlen(pszUsageIdentifier
) + 1);
2773 usage
->rgpszUsageIdentifier
=
2774 (LPSTR
*)((LPBYTE
)usage
+ sizeof(CERT_ENHKEY_USAGE
));
2775 usage
->rgpszUsageIdentifier
[0] = (LPSTR
)((LPBYTE
)usage
+
2776 sizeof(CERT_ENHKEY_USAGE
) + sizeof(LPSTR
));
2777 strcpy(usage
->rgpszUsageIdentifier
[0], pszUsageIdentifier
);
2778 usage
->cUsageIdentifier
= 1;
2779 ret
= CertSetEnhancedKeyUsage(pCertContext
, usage
);
2780 CryptMemFree(usage
);
2788 BOOL WINAPI
CertRemoveEnhancedKeyUsageIdentifier(PCCERT_CONTEXT pCertContext
,
2789 LPCSTR pszUsageIdentifier
)
2793 CERT_ENHKEY_USAGE usage
;
2795 TRACE("(%p, %s)\n", pCertContext
, debugstr_a(pszUsageIdentifier
));
2797 size
= sizeof(usage
);
2798 ret
= CertGetEnhancedKeyUsage(pCertContext
,
2799 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, &usage
, &size
);
2800 if (!ret
&& GetLastError() == ERROR_MORE_DATA
)
2802 PCERT_ENHKEY_USAGE pUsage
= CryptMemAlloc(size
);
2806 ret
= CertGetEnhancedKeyUsage(pCertContext
,
2807 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, pUsage
, &size
);
2810 if (pUsage
->cUsageIdentifier
)
2815 for (i
= 0; i
< pUsage
->cUsageIdentifier
; i
++)
2817 if (!strcmp(pUsage
->rgpszUsageIdentifier
[i
],
2818 pszUsageIdentifier
))
2820 if (found
&& i
< pUsage
->cUsageIdentifier
- 1)
2821 pUsage
->rgpszUsageIdentifier
[i
] =
2822 pUsage
->rgpszUsageIdentifier
[i
+ 1];
2824 pUsage
->cUsageIdentifier
--;
2825 /* Remove the usage if it's empty */
2826 if (pUsage
->cUsageIdentifier
)
2827 ret
= CertSetEnhancedKeyUsage(pCertContext
, pUsage
);
2829 ret
= CertSetEnhancedKeyUsage(pCertContext
, NULL
);
2832 CryptMemFree(pUsage
);
2839 /* it fit in an empty usage, therefore there's nothing to remove */
2851 #define BITS_PER_DWORD (sizeof(DWORD) * 8)
2853 static void CRYPT_SetBitInField(struct BitField
*field
, DWORD bit
)
2855 DWORD indexIndex
= bit
/ BITS_PER_DWORD
;
2857 if (indexIndex
+ 1 > field
->cIndexes
)
2859 if (field
->cIndexes
)
2860 field
->indexes
= CryptMemRealloc(field
->indexes
,
2861 (indexIndex
+ 1) * sizeof(DWORD
));
2863 field
->indexes
= CryptMemAlloc(sizeof(DWORD
));
2866 field
->indexes
[indexIndex
] = 0;
2867 field
->cIndexes
= indexIndex
+ 1;
2871 field
->indexes
[indexIndex
] |= 1 << (bit
% BITS_PER_DWORD
);
2874 static BOOL
CRYPT_IsBitInFieldSet(const struct BitField
*field
, DWORD bit
)
2877 DWORD indexIndex
= bit
/ BITS_PER_DWORD
;
2879 assert(field
->cIndexes
);
2880 set
= field
->indexes
[indexIndex
] & (1 << (bit
% BITS_PER_DWORD
));
2884 BOOL WINAPI
CertGetValidUsages(DWORD cCerts
, PCCERT_CONTEXT
*rghCerts
,
2885 int *cNumOIDs
, LPSTR
*rghOIDs
, DWORD
*pcbOIDs
)
2888 DWORD i
, cbOIDs
= 0;
2889 BOOL allUsagesValid
= TRUE
;
2890 CERT_ENHKEY_USAGE validUsages
= { 0, NULL
};
2892 TRACE("(%d, %p, %d, %p, %d)\n", cCerts
, rghCerts
, *cNumOIDs
,
2895 for (i
= 0; i
< cCerts
; i
++)
2897 CERT_ENHKEY_USAGE usage
;
2898 DWORD size
= sizeof(usage
);
2900 ret
= CertGetEnhancedKeyUsage(rghCerts
[i
], 0, &usage
, &size
);
2901 /* Success is deliberately ignored: it implies all usages are valid */
2902 if (!ret
&& GetLastError() == ERROR_MORE_DATA
)
2904 PCERT_ENHKEY_USAGE pUsage
= CryptMemAlloc(size
);
2906 allUsagesValid
= FALSE
;
2909 ret
= CertGetEnhancedKeyUsage(rghCerts
[i
], 0, pUsage
, &size
);
2912 if (!validUsages
.cUsageIdentifier
)
2916 cbOIDs
= pUsage
->cUsageIdentifier
* sizeof(LPSTR
);
2917 validUsages
.cUsageIdentifier
= pUsage
->cUsageIdentifier
;
2918 for (j
= 0; j
< validUsages
.cUsageIdentifier
; j
++)
2919 cbOIDs
+= lstrlenA(pUsage
->rgpszUsageIdentifier
[j
])
2921 validUsages
.rgpszUsageIdentifier
=
2922 CryptMemAlloc(cbOIDs
);
2923 if (validUsages
.rgpszUsageIdentifier
)
2925 LPSTR nextOID
= (LPSTR
)
2926 ((LPBYTE
)validUsages
.rgpszUsageIdentifier
+
2927 validUsages
.cUsageIdentifier
* sizeof(LPSTR
));
2929 for (j
= 0; j
< validUsages
.cUsageIdentifier
; j
++)
2931 validUsages
.rgpszUsageIdentifier
[j
] = nextOID
;
2932 lstrcpyA(validUsages
.rgpszUsageIdentifier
[j
],
2933 pUsage
->rgpszUsageIdentifier
[j
]);
2934 nextOID
+= lstrlenA(nextOID
) + 1;
2940 struct BitField validIndexes
= { 0, NULL
};
2941 DWORD j
, k
, numRemoved
= 0;
2943 /* Merge: build a bitmap of all the indexes of
2944 * validUsages.rgpszUsageIdentifier that are in pUsage.
2946 for (j
= 0; j
< pUsage
->cUsageIdentifier
; j
++)
2948 for (k
= 0; k
< validUsages
.cUsageIdentifier
; k
++)
2950 if (!strcmp(pUsage
->rgpszUsageIdentifier
[j
],
2951 validUsages
.rgpszUsageIdentifier
[k
]))
2953 CRYPT_SetBitInField(&validIndexes
, k
);
2958 /* Merge by removing from validUsages those that are
2959 * not in the bitmap.
2961 for (j
= 0; j
< validUsages
.cUsageIdentifier
; j
++)
2963 if (!CRYPT_IsBitInFieldSet(&validIndexes
, j
))
2965 if (j
< validUsages
.cUsageIdentifier
- 1)
2967 memmove(&validUsages
.rgpszUsageIdentifier
[j
],
2968 &validUsages
.rgpszUsageIdentifier
[j
+
2970 (validUsages
.cUsageIdentifier
- numRemoved
2971 - j
- 1) * sizeof(LPSTR
));
2973 validUsages
.rgpszUsageIdentifier
[j
]) + 1 +
2975 validUsages
.cUsageIdentifier
--;
2979 validUsages
.cUsageIdentifier
--;
2982 CryptMemFree(validIndexes
.indexes
);
2985 CryptMemFree(pUsage
);
2997 *cNumOIDs
= validUsages
.cUsageIdentifier
;
3000 else if (*pcbOIDs
< cbOIDs
)
3003 SetLastError(ERROR_MORE_DATA
);
3008 LPSTR nextOID
= (LPSTR
)((LPBYTE
)rghOIDs
+
3009 validUsages
.cUsageIdentifier
* sizeof(LPSTR
));
3012 for (i
= 0; i
< validUsages
.cUsageIdentifier
; i
++)
3014 rghOIDs
[i
] = nextOID
;
3015 lstrcpyA(nextOID
, validUsages
.rgpszUsageIdentifier
[i
]);
3016 nextOID
+= lstrlenA(nextOID
) + 1;
3020 CryptMemFree(validUsages
.rgpszUsageIdentifier
);
3021 TRACE("cNumOIDs: %d\n", *cNumOIDs
);
3022 TRACE("returning %d\n", ret
);
3026 /* Sets the CERT_KEY_PROV_INFO_PROP_ID property of context from pInfo, or, if
3027 * pInfo is NULL, from the attributes of hProv.
3029 static void CertContext_SetKeyProvInfo(PCCERT_CONTEXT context
,
3030 const CRYPT_KEY_PROV_INFO
*pInfo
, HCRYPTPROV hProv
)
3032 CRYPT_KEY_PROV_INFO info
= { 0 };
3040 ret
= CryptGetProvParam(hProv
, PP_CONTAINER
, NULL
, &size
, 0);
3043 LPSTR szContainer
= CryptMemAlloc(size
);
3047 ret
= CryptGetProvParam(hProv
, PP_CONTAINER
,
3048 (BYTE
*)szContainer
, &size
, 0);
3051 len
= MultiByteToWideChar(CP_ACP
, 0, szContainer
, -1,
3055 info
.pwszContainerName
= CryptMemAlloc(len
*
3057 MultiByteToWideChar(CP_ACP
, 0, szContainer
, -1,
3058 info
.pwszContainerName
, len
);
3061 CryptMemFree(szContainer
);
3064 ret
= CryptGetProvParam(hProv
, PP_NAME
, NULL
, &size
, 0);
3067 LPSTR szProvider
= CryptMemAlloc(size
);
3071 ret
= CryptGetProvParam(hProv
, PP_NAME
, (BYTE
*)szProvider
,
3075 len
= MultiByteToWideChar(CP_ACP
, 0, szProvider
, -1,
3079 info
.pwszProvName
= CryptMemAlloc(len
*
3081 MultiByteToWideChar(CP_ACP
, 0, szProvider
, -1,
3082 info
.pwszProvName
, len
);
3085 CryptMemFree(szProvider
);
3088 size
= sizeof(info
.dwKeySpec
);
3089 /* in case no CRYPT_KEY_PROV_INFO given,
3090 * we always use AT_SIGNATURE key spec
3092 info
.dwKeySpec
= AT_SIGNATURE
;
3093 size
= sizeof(info
.dwProvType
);
3094 ret
= CryptGetProvParam(hProv
, PP_PROVTYPE
, (LPBYTE
)&info
.dwProvType
,
3097 info
.dwProvType
= PROV_RSA_FULL
;
3101 CertSetCertificateContextProperty(context
, CERT_KEY_PROV_INFO_PROP_ID
,
3106 CryptMemFree(info
.pwszContainerName
);
3107 CryptMemFree(info
.pwszProvName
);
3111 /* Creates a signed certificate context from the unsigned, encoded certificate
3112 * in blob, using the crypto provider hProv and the signature algorithm sigAlgo.
3114 static PCCERT_CONTEXT
CRYPT_CreateSignedCert(const CRYPT_DER_BLOB
*blob
,
3115 HCRYPTPROV hProv
, DWORD dwKeySpec
, PCRYPT_ALGORITHM_IDENTIFIER sigAlgo
)
3117 PCCERT_CONTEXT context
= NULL
;
3121 ret
= CryptSignCertificate(hProv
, dwKeySpec
, X509_ASN_ENCODING
,
3122 blob
->pbData
, blob
->cbData
, sigAlgo
, NULL
, NULL
, &sigSize
);
3125 LPBYTE sig
= CryptMemAlloc(sigSize
);
3127 ret
= CryptSignCertificate(hProv
, dwKeySpec
, X509_ASN_ENCODING
,
3128 blob
->pbData
, blob
->cbData
, sigAlgo
, NULL
, sig
, &sigSize
);
3131 CERT_SIGNED_CONTENT_INFO signedInfo
;
3132 BYTE
*encodedSignedCert
= NULL
;
3133 DWORD encodedSignedCertSize
= 0;
3135 signedInfo
.ToBeSigned
.cbData
= blob
->cbData
;
3136 signedInfo
.ToBeSigned
.pbData
= blob
->pbData
;
3137 signedInfo
.SignatureAlgorithm
= *sigAlgo
;
3138 signedInfo
.Signature
.cbData
= sigSize
;
3139 signedInfo
.Signature
.pbData
= sig
;
3140 signedInfo
.Signature
.cUnusedBits
= 0;
3141 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
, X509_CERT
,
3142 &signedInfo
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
,
3143 &encodedSignedCert
, &encodedSignedCertSize
);
3146 context
= CertCreateCertificateContext(X509_ASN_ENCODING
,
3147 encodedSignedCert
, encodedSignedCertSize
);
3148 LocalFree(encodedSignedCert
);
3156 /* Copies data from the parameters into info, where:
3157 * pSerialNumber: The serial number. Must not be NULL.
3158 * pSubjectIssuerBlob: Specifies both the subject and issuer for info.
3160 * pSignatureAlgorithm: Optional.
3161 * pStartTime: The starting time of the certificate. If NULL, the current
3162 * system time is used.
3163 * pEndTime: The ending time of the certificate. If NULL, one year past the
3164 * starting time is used.
3165 * pubKey: The public key of the certificate. Must not be NULL.
3166 * pExtensions: Extensions to be included with the certificate. Optional.
3168 static void CRYPT_MakeCertInfo(PCERT_INFO info
, const CRYPT_DATA_BLOB
*pSerialNumber
,
3169 const CERT_NAME_BLOB
*pSubjectIssuerBlob
,
3170 const CRYPT_ALGORITHM_IDENTIFIER
*pSignatureAlgorithm
, const SYSTEMTIME
*pStartTime
,
3171 const SYSTEMTIME
*pEndTime
, const CERT_PUBLIC_KEY_INFO
*pubKey
,
3172 const CERT_EXTENSIONS
*pExtensions
)
3174 static CHAR oid
[] = szOID_RSA_SHA1RSA
;
3177 assert(pSerialNumber
);
3178 assert(pSubjectIssuerBlob
);
3181 if (pExtensions
&& pExtensions
->cExtension
)
3182 info
->dwVersion
= CERT_V3
;
3184 info
->dwVersion
= CERT_V1
;
3185 info
->SerialNumber
.cbData
= pSerialNumber
->cbData
;
3186 info
->SerialNumber
.pbData
= pSerialNumber
->pbData
;
3187 if (pSignatureAlgorithm
)
3188 info
->SignatureAlgorithm
= *pSignatureAlgorithm
;
3191 info
->SignatureAlgorithm
.pszObjId
= oid
;
3192 info
->SignatureAlgorithm
.Parameters
.cbData
= 0;
3193 info
->SignatureAlgorithm
.Parameters
.pbData
= NULL
;
3195 info
->Issuer
.cbData
= pSubjectIssuerBlob
->cbData
;
3196 info
->Issuer
.pbData
= pSubjectIssuerBlob
->pbData
;
3198 SystemTimeToFileTime(pStartTime
, &info
->NotBefore
);
3200 GetSystemTimeAsFileTime(&info
->NotBefore
);
3202 SystemTimeToFileTime(pEndTime
, &info
->NotAfter
);
3207 if (FileTimeToSystemTime(&info
->NotBefore
, &endTime
))
3210 SystemTimeToFileTime(&endTime
, &info
->NotAfter
);
3213 info
->Subject
.cbData
= pSubjectIssuerBlob
->cbData
;
3214 info
->Subject
.pbData
= pSubjectIssuerBlob
->pbData
;
3215 info
->SubjectPublicKeyInfo
= *pubKey
;
3218 info
->cExtension
= pExtensions
->cExtension
;
3219 info
->rgExtension
= pExtensions
->rgExtension
;
3223 info
->cExtension
= 0;
3224 info
->rgExtension
= NULL
;
3228 typedef RPC_STATUS (RPC_ENTRY
*UuidCreateFunc
)(UUID
*);
3229 typedef RPC_STATUS (RPC_ENTRY
*UuidToStringFunc
)(UUID
*, unsigned char **);
3230 typedef RPC_STATUS (RPC_ENTRY
*RpcStringFreeFunc
)(unsigned char **);
3232 static HCRYPTPROV
CRYPT_CreateKeyProv(void)
3234 HCRYPTPROV hProv
= 0;
3235 HMODULE rpcrt
= LoadLibraryA("rpcrt4");
3239 UuidCreateFunc uuidCreate
= (UuidCreateFunc
)GetProcAddress(rpcrt
,
3241 UuidToStringFunc uuidToString
= (UuidToStringFunc
)GetProcAddress(rpcrt
,
3243 RpcStringFreeFunc rpcStringFree
= (RpcStringFreeFunc
)GetProcAddress(
3244 rpcrt
, "RpcStringFreeA");
3246 if (uuidCreate
&& uuidToString
&& rpcStringFree
)
3249 RPC_STATUS status
= uuidCreate(&uuid
);
3251 if (status
== RPC_S_OK
|| status
== RPC_S_UUID_LOCAL_ONLY
)
3253 unsigned char *uuidStr
;
3255 status
= uuidToString(&uuid
, &uuidStr
);
3256 if (status
== RPC_S_OK
)
3258 BOOL ret
= CryptAcquireContextA(&hProv
, (LPCSTR
)uuidStr
,
3259 MS_DEF_PROV_A
, PROV_RSA_FULL
, CRYPT_NEWKEYSET
);
3265 ret
= CryptGenKey(hProv
, AT_SIGNATURE
, 0, &key
);
3267 CryptDestroyKey(key
);
3269 rpcStringFree(&uuidStr
);
3278 PCCERT_CONTEXT WINAPI
CertCreateSelfSignCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hProv
,
3279 PCERT_NAME_BLOB pSubjectIssuerBlob
, DWORD dwFlags
,
3280 PCRYPT_KEY_PROV_INFO pKeyProvInfo
,
3281 PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm
, PSYSTEMTIME pStartTime
,
3282 PSYSTEMTIME pEndTime
, PCERT_EXTENSIONS pExtensions
)
3284 PCCERT_CONTEXT context
= NULL
;
3285 BOOL ret
, releaseContext
= FALSE
;
3286 PCERT_PUBLIC_KEY_INFO pubKey
= NULL
;
3287 DWORD pubKeySize
= 0, dwKeySpec
;
3289 TRACE("(%08lx, %p, %08x, %p, %p, %p, %p, %p)\n", hProv
,
3290 pSubjectIssuerBlob
, dwFlags
, pKeyProvInfo
, pSignatureAlgorithm
, pStartTime
,
3291 pExtensions
, pExtensions
);
3293 if(!pSubjectIssuerBlob
)
3295 SetLastError(ERROR_INVALID_PARAMETER
);
3299 dwKeySpec
= pKeyProvInfo
? pKeyProvInfo
->dwKeySpec
: AT_SIGNATURE
;
3304 hProv
= CRYPT_CreateKeyProv();
3305 releaseContext
= TRUE
;
3307 else if (pKeyProvInfo
->dwFlags
& CERT_SET_KEY_PROV_HANDLE_PROP_ID
)
3309 SetLastError(NTE_BAD_FLAGS
);
3315 /* acquire the context using the given information*/
3316 ret
= CryptAcquireContextW(&hProv
,pKeyProvInfo
->pwszContainerName
,
3317 pKeyProvInfo
->pwszProvName
,pKeyProvInfo
->dwProvType
,
3318 pKeyProvInfo
->dwFlags
);
3321 if(GetLastError() != NTE_BAD_KEYSET
)
3323 /* create the key set */
3324 ret
= CryptAcquireContextW(&hProv
,pKeyProvInfo
->pwszContainerName
,
3325 pKeyProvInfo
->pwszProvName
,pKeyProvInfo
->dwProvType
,
3326 pKeyProvInfo
->dwFlags
|CRYPT_NEWKEYSET
);
3330 /* check if the key is here */
3331 ret
= CryptGetUserKey(hProv
,dwKeySpec
,&hKey
);
3334 if (NTE_NO_KEY
== GetLastError())
3335 { /* generate the key */
3336 ret
= CryptGenKey(hProv
,dwKeySpec
,0,&hKey
);
3340 CryptReleaseContext(hProv
,0);
3341 SetLastError(NTE_BAD_KEYSET
);
3345 CryptDestroyKey(hKey
);
3346 releaseContext
= TRUE
;
3350 ret
= CryptExportPublicKeyInfo(hProv
, dwKeySpec
, X509_ASN_ENCODING
, NULL
,
3354 pubKey
= CryptMemAlloc(pubKeySize
);
3357 ret
= CryptExportPublicKeyInfo(hProv
, dwKeySpec
, X509_ASN_ENCODING
,
3358 pubKey
, &pubKeySize
);
3361 CERT_INFO info
= { 0 };
3362 CRYPT_DER_BLOB blob
= { 0, NULL
};
3364 CRYPT_DATA_BLOB serialBlob
= { sizeof(serial
), serial
};
3366 CryptGenRandom(hProv
, sizeof(serial
), serial
);
3367 CRYPT_MakeCertInfo(&info
, &serialBlob
, pSubjectIssuerBlob
,
3368 pSignatureAlgorithm
, pStartTime
, pEndTime
, pubKey
, pExtensions
);
3369 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
, X509_CERT_TO_BE_SIGNED
,
3370 &info
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
, &blob
.pbData
,
3374 if (!(dwFlags
& CERT_CREATE_SELFSIGN_NO_SIGN
))
3375 context
= CRYPT_CreateSignedCert(&blob
, hProv
,dwKeySpec
,
3376 &info
.SignatureAlgorithm
);
3378 context
= CertCreateCertificateContext(X509_ASN_ENCODING
,
3379 blob
.pbData
, blob
.cbData
);
3380 if (context
&& !(dwFlags
& CERT_CREATE_SELFSIGN_NO_KEY_INFO
))
3381 CertContext_SetKeyProvInfo(context
, pKeyProvInfo
, hProv
);
3382 LocalFree(blob
.pbData
);
3385 CryptMemFree(pubKey
);
3389 CryptReleaseContext(hProv
, 0);
3393 BOOL WINAPI
CertVerifyCTLUsage(DWORD dwEncodingType
, DWORD dwSubjectType
,
3394 void *pvSubject
, PCTL_USAGE pSubjectUsage
, DWORD dwFlags
,
3395 PCTL_VERIFY_USAGE_PARA pVerifyUsagePara
,
3396 PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
)
3398 FIXME("(0x%x, %d, %p, %p, 0x%x, %p, %p): stub\n", dwEncodingType
,
3399 dwSubjectType
, pvSubject
, pSubjectUsage
, dwFlags
, pVerifyUsagePara
,
3400 pVerifyUsageStatus
);
3401 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3405 const void * WINAPI
CertCreateContext(DWORD dwContextType
, DWORD dwEncodingType
,
3406 const BYTE
*pbEncoded
, DWORD cbEncoded
,
3407 DWORD dwFlags
, PCERT_CREATE_CONTEXT_PARA pCreatePara
)
3409 TRACE("(0x%x, 0x%x, %p, %d, 0x%08x, %p)\n", dwContextType
, dwEncodingType
,
3410 pbEncoded
, cbEncoded
, dwFlags
, pCreatePara
);
3414 FIXME("dwFlags 0x%08x not handled\n", dwFlags
);
3419 FIXME("pCreatePara not handled\n");
3423 switch (dwContextType
)
3425 case CERT_STORE_CERTIFICATE_CONTEXT
:
3426 return CertCreateCertificateContext(dwEncodingType
, pbEncoded
, cbEncoded
);
3427 case CERT_STORE_CRL_CONTEXT
:
3428 return CertCreateCRLContext(dwEncodingType
, pbEncoded
, cbEncoded
);
3429 case CERT_STORE_CTL_CONTEXT
:
3430 return CertCreateCTLContext(dwEncodingType
, pbEncoded
, cbEncoded
);
3432 WARN("unknown context type: 0x%x\n", dwContextType
);