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
20 #include "crypt32_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(crypt
);
26 /* Internal version of CertGetCertificateContextProperty that gets properties
27 * directly from the context (or the context it's linked to, depending on its
28 * type.) Doesn't handle special-case properties, since they are handled by
29 * CertGetCertificateContextProperty, and are particular to the store in which
30 * the property exists (which is separate from the context.)
32 static BOOL
CertContext_GetProperty(cert_t
*cert
, DWORD dwPropId
,
33 void *pvData
, DWORD
*pcbData
);
35 /* Internal version of CertSetCertificateContextProperty that sets properties
36 * directly on the context (or the context it's linked to, depending on its
37 * type.) Doesn't handle special cases, since they're handled by
38 * CertSetCertificateContextProperty anyway.
40 static BOOL
CertContext_SetProperty(cert_t
*cert
, DWORD dwPropId
,
41 DWORD dwFlags
, const void *pvData
);
43 BOOL WINAPI
CertAddEncodedCertificateToStore(HCERTSTORE hCertStore
,
44 DWORD dwCertEncodingType
, const BYTE
*pbCertEncoded
, DWORD cbCertEncoded
,
45 DWORD dwAddDisposition
, PCCERT_CONTEXT
*ppCertContext
)
47 PCCERT_CONTEXT cert
= CertCreateCertificateContext(dwCertEncodingType
,
48 pbCertEncoded
, cbCertEncoded
);
51 TRACE("(%p, %08x, %p, %d, %08x, %p)\n", hCertStore
, dwCertEncodingType
,
52 pbCertEncoded
, cbCertEncoded
, dwAddDisposition
, ppCertContext
);
56 ret
= CertAddCertificateContextToStore(hCertStore
, cert
,
57 dwAddDisposition
, ppCertContext
);
58 CertFreeCertificateContext(cert
);
65 BOOL WINAPI
CertAddEncodedCertificateToSystemStoreA(LPCSTR pszCertStoreName
,
66 const BYTE
*pbCertEncoded
, DWORD cbCertEncoded
)
71 TRACE("(%s, %p, %d)\n", debugstr_a(pszCertStoreName
), pbCertEncoded
,
74 store
= CertOpenSystemStoreA(0, pszCertStoreName
);
77 ret
= CertAddEncodedCertificateToStore(store
, X509_ASN_ENCODING
,
78 pbCertEncoded
, cbCertEncoded
, CERT_STORE_ADD_USE_EXISTING
, NULL
);
79 CertCloseStore(store
, 0);
84 BOOL WINAPI
CertAddEncodedCertificateToSystemStoreW(LPCWSTR pszCertStoreName
,
85 const BYTE
*pbCertEncoded
, DWORD cbCertEncoded
)
90 TRACE("(%s, %p, %d)\n", debugstr_w(pszCertStoreName
), pbCertEncoded
,
93 store
= CertOpenSystemStoreW(0, pszCertStoreName
);
96 ret
= CertAddEncodedCertificateToStore(store
, X509_ASN_ENCODING
,
97 pbCertEncoded
, cbCertEncoded
, CERT_STORE_ADD_USE_EXISTING
, NULL
);
98 CertCloseStore(store
, 0);
103 static const context_vtbl_t cert_vtbl
;
105 static void Cert_free(context_t
*context
)
107 cert_t
*cert
= (cert_t
*)context
;
109 CryptMemFree(cert
->ctx
.pbCertEncoded
);
110 LocalFree(cert
->ctx
.pCertInfo
);
113 static context_t
*Cert_clone(context_t
*context
, WINECRYPT_CERTSTORE
*store
, BOOL use_link
)
118 cert
= (cert_t
*)Context_CreateLinkContext(sizeof(CERT_CONTEXT
), context
, store
);
122 const cert_t
*cloned
= (const cert_t
*)context
;
126 cert
= (cert_t
*)Context_CreateDataContext(sizeof(CERT_CONTEXT
), &cert_vtbl
, store
);
130 Context_CopyProperties(&cert
->ctx
, &cloned
->ctx
);
132 cert
->ctx
.dwCertEncodingType
= cloned
->ctx
.dwCertEncodingType
;
133 cert
->ctx
.pbCertEncoded
= CryptMemAlloc(cloned
->ctx
.cbCertEncoded
);
134 memcpy(cert
->ctx
.pbCertEncoded
, cloned
->ctx
.pbCertEncoded
, cloned
->ctx
.cbCertEncoded
);
135 cert
->ctx
.cbCertEncoded
= cloned
->ctx
.cbCertEncoded
;
137 /* FIXME: We don't need to decode the object here, we could just clone cert info. */
138 res
= CryptDecodeObjectEx(cert
->ctx
.dwCertEncodingType
, X509_CERT_TO_BE_SIGNED
,
139 cert
->ctx
.pbCertEncoded
, cert
->ctx
.cbCertEncoded
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
140 &cert
->ctx
.pCertInfo
, &size
);
142 CertFreeCertificateContext(&cert
->ctx
);
147 cert
->ctx
.hCertStore
= store
;
151 static const context_vtbl_t cert_vtbl
= {
156 static BOOL
add_cert_to_store(WINECRYPT_CERTSTORE
*store
, const CERT_CONTEXT
*cert
,
157 DWORD add_disposition
, BOOL use_link
, PCCERT_CONTEXT
*ret_context
)
159 const CERT_CONTEXT
*existing
= NULL
;
160 BOOL ret
= TRUE
, inherit_props
= FALSE
;
161 context_t
*new_context
= NULL
;
163 switch (add_disposition
)
165 case CERT_STORE_ADD_ALWAYS
:
167 case CERT_STORE_ADD_NEW
:
168 case CERT_STORE_ADD_REPLACE_EXISTING
:
169 case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
:
170 case CERT_STORE_ADD_USE_EXISTING
:
171 case CERT_STORE_ADD_NEWER
:
172 case CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
:
175 DWORD size
= sizeof(hashToAdd
);
177 ret
= CertGetCertificateContextProperty(cert
, CERT_HASH_PROP_ID
,
181 CRYPT_HASH_BLOB blob
= { sizeof(hashToAdd
), hashToAdd
};
183 existing
= CertFindCertificateInStore(store
, cert
->dwCertEncodingType
, 0,
184 CERT_FIND_SHA1_HASH
, &blob
, NULL
);
189 FIXME("Unimplemented add disposition %d\n", add_disposition
);
190 SetLastError(E_INVALIDARG
);
194 switch (add_disposition
)
196 case CERT_STORE_ADD_ALWAYS
:
198 case CERT_STORE_ADD_NEW
:
201 TRACE("found matching certificate, not adding\n");
202 SetLastError(CRYPT_E_EXISTS
);
206 case CERT_STORE_ADD_REPLACE_EXISTING
:
208 case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
:
210 FIXME("CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES: semi-stub for links\n");
212 inherit_props
= TRUE
;
214 case CERT_STORE_ADD_USE_EXISTING
:
216 FIXME("CERT_STORE_ADD_USE_EXISTING: semi-stub for links\n");
219 Context_CopyProperties(existing
, cert
);
221 *ret_context
= CertDuplicateCertificateContext(existing
);
225 case CERT_STORE_ADD_NEWER
:
226 if (existing
&& CompareFileTime(&existing
->pCertInfo
->NotBefore
, &cert
->pCertInfo
->NotBefore
) >= 0)
228 TRACE("existing certificate is newer, not adding\n");
229 SetLastError(CRYPT_E_EXISTS
);
233 case CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
:
236 if (CompareFileTime(&existing
->pCertInfo
->NotBefore
, &cert
->pCertInfo
->NotBefore
) >= 0)
238 TRACE("existing certificate is newer, not adding\n");
239 SetLastError(CRYPT_E_EXISTS
);
242 inherit_props
= TRUE
;
247 /* FIXME: We have tests that this works, but what should we really do in this case? */
250 *ret_context
= CertDuplicateCertificateContext(cert
);
254 ret
= store
->vtbl
->certs
.addContext(store
, context_from_ptr(cert
), existing
? context_from_ptr(existing
) : NULL
,
255 (ret_context
|| inherit_props
) ? &new_context
: NULL
, use_link
);
260 Context_CopyProperties(context_ptr(new_context
), existing
);
263 *ret_context
= context_ptr(new_context
);
265 Context_Release(new_context
);
267 TRACE("returning %d\n", ret
);
271 BOOL WINAPI
CertAddCertificateContextToStore(HCERTSTORE hCertStore
, PCCERT_CONTEXT pCertContext
,
272 DWORD dwAddDisposition
, PCCERT_CONTEXT
*ppStoreContext
)
274 WINECRYPT_CERTSTORE
*store
= hCertStore
;
276 TRACE("(%p, %p, %08x, %p)\n", hCertStore
, pCertContext
, dwAddDisposition
, ppStoreContext
);
278 return add_cert_to_store(store
, pCertContext
, dwAddDisposition
, FALSE
, ppStoreContext
);
281 BOOL WINAPI
CertAddCertificateLinkToStore(HCERTSTORE hCertStore
,
282 PCCERT_CONTEXT pCertContext
, DWORD dwAddDisposition
,
283 PCCERT_CONTEXT
*ppCertContext
)
286 WINECRYPT_CERTSTORE
*store
= (WINECRYPT_CERTSTORE
*)hCertStore
;
289 FIXME("(%p, %p, %08x, %p): semi-stub\n", hCertStore
, pCertContext
,
290 dwAddDisposition
, ppCertContext
);
291 if (store
->dwMagic
!= WINE_CRYPTCERTSTORE_MAGIC
)
293 if (store
->type
== StoreTypeCollection
)
295 SetLastError(E_INVALIDARG
);
298 return add_cert_to_store(hCertStore
, pCertContext
, dwAddDisposition
, TRUE
, ppCertContext
);
301 PCCERT_CONTEXT WINAPI
CertCreateCertificateContext(DWORD dwCertEncodingType
,
302 const BYTE
*pbCertEncoded
, DWORD cbCertEncoded
)
307 PCERT_INFO certInfo
= NULL
;
310 TRACE("(%08x, %p, %d)\n", dwCertEncodingType
, pbCertEncoded
,
313 if ((dwCertEncodingType
& CERT_ENCODING_TYPE_MASK
) != X509_ASN_ENCODING
)
315 SetLastError(E_INVALIDARG
);
319 ret
= CryptDecodeObjectEx(dwCertEncodingType
, X509_CERT_TO_BE_SIGNED
,
320 pbCertEncoded
, cbCertEncoded
, CRYPT_DECODE_ALLOC_FLAG
, NULL
,
325 cert
= (cert_t
*)Context_CreateDataContext(sizeof(CERT_CONTEXT
), &cert_vtbl
, &empty_store
);
328 data
= CryptMemAlloc(cbCertEncoded
);
331 Context_Release(&cert
->base
);
335 memcpy(data
, pbCertEncoded
, cbCertEncoded
);
336 cert
->ctx
.dwCertEncodingType
= dwCertEncodingType
;
337 cert
->ctx
.pbCertEncoded
= data
;
338 cert
->ctx
.cbCertEncoded
= cbCertEncoded
;
339 cert
->ctx
.pCertInfo
= certInfo
;
340 cert
->ctx
.hCertStore
= &empty_store
;
345 PCCERT_CONTEXT WINAPI
CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContext
)
347 TRACE("(%p)\n", pCertContext
);
352 Context_AddRef(&cert_from_ptr(pCertContext
)->base
);
356 BOOL WINAPI
CertFreeCertificateContext(PCCERT_CONTEXT pCertContext
)
358 TRACE("(%p)\n", pCertContext
);
361 Context_Release(&cert_from_ptr(pCertContext
)->base
);
365 DWORD WINAPI
CertEnumCertificateContextProperties(PCCERT_CONTEXT pCertContext
,
368 cert_t
*cert
= cert_from_ptr(pCertContext
);
371 TRACE("(%p, %d)\n", pCertContext
, dwPropId
);
373 if (cert
->base
.properties
)
374 ret
= ContextPropertyList_EnumPropIDs(cert
->base
.properties
, dwPropId
);
380 static BOOL
CertContext_GetHashProp(cert_t
*cert
, DWORD dwPropId
,
381 ALG_ID algID
, const BYTE
*toHash
, DWORD toHashLen
, void *pvData
,
384 BOOL ret
= CryptHashCertificate(0, algID
, 0, toHash
, toHashLen
, pvData
,
388 CRYPT_DATA_BLOB blob
= { *pcbData
, pvData
};
390 ret
= CertContext_SetProperty(cert
, dwPropId
, 0, &blob
);
395 static BOOL
CertContext_CopyParam(void *pvData
, DWORD
*pcbData
, const void *pb
,
402 else if (*pcbData
< cb
)
404 SetLastError(ERROR_MORE_DATA
);
410 memcpy(pvData
, pb
, cb
);
416 static BOOL
CertContext_GetProperty(cert_t
*cert
, DWORD dwPropId
,
417 void *pvData
, DWORD
*pcbData
)
420 CRYPT_DATA_BLOB blob
;
422 TRACE("(%p, %d, %p, %p)\n", cert
, dwPropId
, pvData
, pcbData
);
424 if (cert
->base
.properties
)
425 ret
= ContextPropertyList_FindProperty(cert
->base
.properties
, dwPropId
, &blob
);
429 ret
= CertContext_CopyParam(pvData
, pcbData
, blob
.pbData
, blob
.cbData
);
432 /* Implicit properties */
435 case CERT_SHA1_HASH_PROP_ID
:
436 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_SHA1
,
437 cert
->ctx
.pbCertEncoded
, cert
->ctx
.cbCertEncoded
, pvData
,
440 case CERT_MD5_HASH_PROP_ID
:
441 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_MD5
,
442 cert
->ctx
.pbCertEncoded
, cert
->ctx
.cbCertEncoded
, pvData
,
445 case CERT_SUBJECT_NAME_MD5_HASH_PROP_ID
:
446 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_MD5
,
447 cert
->ctx
.pCertInfo
->Subject
.pbData
,
448 cert
->ctx
.pCertInfo
->Subject
.cbData
,
451 case CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID
:
452 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_MD5
,
453 cert
->ctx
.pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.pbData
,
454 cert
->ctx
.pCertInfo
->SubjectPublicKeyInfo
.PublicKey
.cbData
,
457 case CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID
:
458 ret
= CertContext_GetHashProp(cert
, dwPropId
, CALG_MD5
,
459 cert
->ctx
.pCertInfo
->SerialNumber
.pbData
,
460 cert
->ctx
.pCertInfo
->SerialNumber
.cbData
,
463 case CERT_SIGNATURE_HASH_PROP_ID
:
464 ret
= CryptHashToBeSigned(0, cert
->ctx
.dwCertEncodingType
,
465 cert
->ctx
.pbCertEncoded
, cert
->ctx
.cbCertEncoded
, pvData
,
469 CRYPT_DATA_BLOB blob
= { *pcbData
, pvData
};
471 ret
= CertContext_SetProperty(cert
, dwPropId
, 0, &blob
);
474 case CERT_KEY_IDENTIFIER_PROP_ID
:
476 PCERT_EXTENSION ext
= CertFindExtension(
477 szOID_SUBJECT_KEY_IDENTIFIER
, cert
->ctx
.pCertInfo
->cExtension
,
478 cert
->ctx
.pCertInfo
->rgExtension
);
482 CRYPT_DATA_BLOB value
;
483 DWORD size
= sizeof(value
);
485 ret
= CryptDecodeObjectEx(X509_ASN_ENCODING
,
486 szOID_SUBJECT_KEY_IDENTIFIER
, ext
->Value
.pbData
,
487 ext
->Value
.cbData
, CRYPT_DECODE_NOCOPY_FLAG
, NULL
, &value
,
491 ret
= CertContext_CopyParam(pvData
, pcbData
, value
.pbData
,
493 CertContext_SetProperty(cert
, dwPropId
, 0, &value
);
497 SetLastError(ERROR_INVALID_DATA
);
501 SetLastError(CRYPT_E_NOT_FOUND
);
504 TRACE("returning %d\n", ret
);
508 void CRYPT_FixKeyProvInfoPointers(PCRYPT_KEY_PROV_INFO info
)
510 DWORD i
, containerLen
, provNameLen
;
511 LPBYTE data
= (LPBYTE
)info
+ sizeof(CRYPT_KEY_PROV_INFO
);
513 info
->pwszContainerName
= (LPWSTR
)data
;
514 containerLen
= (lstrlenW(info
->pwszContainerName
) + 1) * sizeof(WCHAR
);
515 data
+= containerLen
;
517 info
->pwszProvName
= (LPWSTR
)data
;
518 provNameLen
= (lstrlenW(info
->pwszProvName
) + 1) * sizeof(WCHAR
);
521 info
->rgProvParam
= (PCRYPT_KEY_PROV_PARAM
)data
;
522 data
+= info
->cProvParam
* sizeof(CRYPT_KEY_PROV_PARAM
);
524 for (i
= 0; i
< info
->cProvParam
; i
++)
526 info
->rgProvParam
[i
].pbData
= data
;
527 data
+= info
->rgProvParam
[i
].cbData
;
531 BOOL WINAPI
CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext
,
532 DWORD dwPropId
, void *pvData
, DWORD
*pcbData
)
534 cert_t
*cert
= cert_from_ptr(pCertContext
);
537 TRACE("(%p, %d, %p, %p)\n", pCertContext
, dwPropId
, pvData
, pcbData
);
542 case CERT_CERT_PROP_ID
:
543 case CERT_CRL_PROP_ID
:
544 case CERT_CTL_PROP_ID
:
545 SetLastError(E_INVALIDARG
);
548 case CERT_ACCESS_STATE_PROP_ID
:
549 ret
= CertGetStoreProperty(cert
->ctx
.hCertStore
, dwPropId
, pvData
, pcbData
);
551 case CERT_KEY_PROV_HANDLE_PROP_ID
:
553 CERT_KEY_CONTEXT keyContext
;
554 DWORD size
= sizeof(keyContext
);
556 ret
= CertContext_GetProperty(cert
,
557 CERT_KEY_CONTEXT_PROP_ID
, &keyContext
, &size
);
559 ret
= CertContext_CopyParam(pvData
, pcbData
, &keyContext
.hCryptProv
,
560 sizeof(keyContext
.hCryptProv
));
563 case CERT_KEY_PROV_INFO_PROP_ID
:
564 ret
= CertContext_GetProperty(cert
, dwPropId
, pvData
,
567 CRYPT_FixKeyProvInfoPointers(pvData
);
570 ret
= CertContext_GetProperty(cert
, dwPropId
, pvData
,
574 TRACE("returning %d\n", ret
);
578 /* Copies key provider info from from into to, where to is assumed to be a
579 * contiguous buffer of memory large enough for from and all its associated
580 * data, but whose pointers are uninitialized.
581 * Upon return, to contains a contiguous copy of from, packed in the following
583 * - CRYPT_KEY_PROV_INFO
584 * - pwszContainerName
586 * - rgProvParam[0]...
588 static void CRYPT_CopyKeyProvInfo(PCRYPT_KEY_PROV_INFO to
,
589 const CRYPT_KEY_PROV_INFO
*from
)
592 LPBYTE nextData
= (LPBYTE
)to
+ sizeof(CRYPT_KEY_PROV_INFO
);
594 if (from
->pwszContainerName
)
596 to
->pwszContainerName
= (LPWSTR
)nextData
;
597 lstrcpyW(to
->pwszContainerName
, from
->pwszContainerName
);
598 nextData
+= (lstrlenW(from
->pwszContainerName
) + 1) * sizeof(WCHAR
);
601 to
->pwszContainerName
= NULL
;
602 if (from
->pwszProvName
)
604 to
->pwszProvName
= (LPWSTR
)nextData
;
605 lstrcpyW(to
->pwszProvName
, from
->pwszProvName
);
606 nextData
+= (lstrlenW(from
->pwszProvName
) + 1) * sizeof(WCHAR
);
609 to
->pwszProvName
= NULL
;
610 to
->dwProvType
= from
->dwProvType
;
611 to
->dwFlags
= from
->dwFlags
;
612 to
->cProvParam
= from
->cProvParam
;
613 to
->rgProvParam
= (PCRYPT_KEY_PROV_PARAM
)nextData
;
614 nextData
+= to
->cProvParam
* sizeof(CRYPT_KEY_PROV_PARAM
);
615 to
->dwKeySpec
= from
->dwKeySpec
;
616 for (i
= 0; i
< to
->cProvParam
; i
++)
618 memcpy(&to
->rgProvParam
[i
], &from
->rgProvParam
[i
],
619 sizeof(CRYPT_KEY_PROV_PARAM
));
620 to
->rgProvParam
[i
].pbData
= nextData
;
621 memcpy(to
->rgProvParam
[i
].pbData
, from
->rgProvParam
[i
].pbData
,
622 from
->rgProvParam
[i
].cbData
);
623 nextData
+= from
->rgProvParam
[i
].cbData
;
627 static BOOL
CertContext_SetKeyProvInfoProperty(CONTEXT_PROPERTY_LIST
*properties
,
628 const CRYPT_KEY_PROV_INFO
*info
)
632 DWORD size
= sizeof(CRYPT_KEY_PROV_INFO
), i
, containerSize
, provNameSize
;
634 if (info
->pwszContainerName
)
635 containerSize
= (lstrlenW(info
->pwszContainerName
) + 1) * sizeof(WCHAR
);
638 if (info
->pwszProvName
)
639 provNameSize
= (lstrlenW(info
->pwszProvName
) + 1) * sizeof(WCHAR
);
642 size
+= containerSize
+ provNameSize
;
643 for (i
= 0; i
< info
->cProvParam
; i
++)
644 size
+= sizeof(CRYPT_KEY_PROV_PARAM
) + info
->rgProvParam
[i
].cbData
;
645 buf
= CryptMemAlloc(size
);
648 CRYPT_CopyKeyProvInfo((PCRYPT_KEY_PROV_INFO
)buf
, info
);
649 ret
= ContextPropertyList_SetProperty(properties
,
650 CERT_KEY_PROV_INFO_PROP_ID
, buf
, size
);
658 static BOOL
CertContext_SetProperty(cert_t
*cert
, DWORD dwPropId
,
659 DWORD dwFlags
, const void *pvData
)
663 TRACE("(%p, %d, %08x, %p)\n", cert
, dwPropId
, dwFlags
, pvData
);
665 if (!cert
->base
.properties
)
671 case CERT_AUTO_ENROLL_PROP_ID
:
672 case CERT_CTL_USAGE_PROP_ID
: /* same as CERT_ENHKEY_USAGE_PROP_ID */
673 case CERT_DESCRIPTION_PROP_ID
:
674 case CERT_FRIENDLY_NAME_PROP_ID
:
675 case CERT_HASH_PROP_ID
:
676 case CERT_KEY_IDENTIFIER_PROP_ID
:
677 case CERT_MD5_HASH_PROP_ID
:
678 case CERT_NEXT_UPDATE_LOCATION_PROP_ID
:
679 case CERT_PUBKEY_ALG_PARA_PROP_ID
:
680 case CERT_PVK_FILE_PROP_ID
:
681 case CERT_SIGNATURE_HASH_PROP_ID
:
682 case CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID
:
683 case CERT_SUBJECT_NAME_MD5_HASH_PROP_ID
:
684 case CERT_EXTENDED_ERROR_INFO_PROP_ID
:
685 case CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID
:
686 case CERT_ENROLLMENT_PROP_ID
:
687 case CERT_CROSS_CERT_DIST_POINTS_PROP_ID
:
688 case CERT_RENEWAL_PROP_ID
:
692 const CRYPT_DATA_BLOB
*blob
= pvData
;
694 ret
= ContextPropertyList_SetProperty(cert
->base
.properties
, dwPropId
,
695 blob
->pbData
, blob
->cbData
);
699 ContextPropertyList_RemoveProperty(cert
->base
.properties
, dwPropId
);
704 case CERT_DATE_STAMP_PROP_ID
:
706 ret
= ContextPropertyList_SetProperty(cert
->base
.properties
, dwPropId
,
707 pvData
, sizeof(FILETIME
));
710 ContextPropertyList_RemoveProperty(cert
->base
.properties
, dwPropId
);
714 case CERT_KEY_CONTEXT_PROP_ID
:
718 const CERT_KEY_CONTEXT
*keyContext
= pvData
;
720 if (keyContext
->cbSize
!= sizeof(CERT_KEY_CONTEXT
))
722 SetLastError(E_INVALIDARG
);
726 ret
= ContextPropertyList_SetProperty(cert
->base
.properties
, dwPropId
,
727 (const BYTE
*)keyContext
, keyContext
->cbSize
);
731 ContextPropertyList_RemoveProperty(cert
->base
.properties
, dwPropId
);
736 case CERT_KEY_PROV_INFO_PROP_ID
:
738 ret
= CertContext_SetKeyProvInfoProperty(cert
->base
.properties
, pvData
);
741 ContextPropertyList_RemoveProperty(cert
->base
.properties
, dwPropId
);
745 case CERT_KEY_PROV_HANDLE_PROP_ID
:
747 CERT_KEY_CONTEXT keyContext
;
748 DWORD size
= sizeof(keyContext
);
750 ret
= CertContext_GetProperty(cert
, CERT_KEY_CONTEXT_PROP_ID
,
754 if (!(dwFlags
& CERT_STORE_NO_CRYPT_RELEASE_FLAG
))
755 CryptReleaseContext(keyContext
.hCryptProv
, 0);
757 keyContext
.cbSize
= sizeof(keyContext
);
759 keyContext
.hCryptProv
= *(const HCRYPTPROV
*)pvData
;
762 keyContext
.hCryptProv
= 0;
763 keyContext
.dwKeySpec
= AT_SIGNATURE
;
765 ret
= CertContext_SetProperty(cert
, CERT_KEY_CONTEXT_PROP_ID
,
770 FIXME("%d: stub\n", dwPropId
);
774 TRACE("returning %d\n", ret
);
778 BOOL WINAPI
CertSetCertificateContextProperty(PCCERT_CONTEXT pCertContext
,
779 DWORD dwPropId
, DWORD dwFlags
, const void *pvData
)
783 TRACE("(%p, %d, %08x, %p)\n", pCertContext
, dwPropId
, dwFlags
, pvData
);
785 /* Handle special cases for "read-only"/invalid prop IDs. Windows just
786 * crashes on most of these, I'll be safer.
791 case CERT_ACCESS_STATE_PROP_ID
:
792 case CERT_CERT_PROP_ID
:
793 case CERT_CRL_PROP_ID
:
794 case CERT_CTL_PROP_ID
:
795 SetLastError(E_INVALIDARG
);
798 ret
= CertContext_SetProperty(cert_from_ptr(pCertContext
), dwPropId
, dwFlags
,
800 TRACE("returning %d\n", ret
);
804 /* Acquires the private key using the key provider info, retrieving info from
805 * the certificate if info is NULL. The acquired provider is returned in
806 * *phCryptProv, and the key spec for the provider is returned in *pdwKeySpec.
808 static BOOL
CRYPT_AcquirePrivateKeyFromProvInfo(PCCERT_CONTEXT pCert
,
809 PCRYPT_KEY_PROV_INFO info
, HCRYPTPROV
*phCryptProv
, DWORD
*pdwKeySpec
)
812 BOOL allocated
= FALSE
, ret
= TRUE
;
816 ret
= CertGetCertificateContextProperty(pCert
,
817 CERT_KEY_PROV_INFO_PROP_ID
, 0, &size
);
820 info
= HeapAlloc(GetProcessHeap(), 0, size
);
823 ret
= CertGetCertificateContextProperty(pCert
,
824 CERT_KEY_PROV_INFO_PROP_ID
, info
, &size
);
829 SetLastError(ERROR_OUTOFMEMORY
);
834 SetLastError(CRYPT_E_NO_KEY_PROPERTY
);
838 ret
= CryptAcquireContextW(phCryptProv
, info
->pwszContainerName
,
839 info
->pwszProvName
, info
->dwProvType
, 0);
844 for (i
= 0; i
< info
->cProvParam
; i
++)
846 CryptSetProvParam(*phCryptProv
,
847 info
->rgProvParam
[i
].dwParam
, info
->rgProvParam
[i
].pbData
,
848 info
->rgProvParam
[i
].dwFlags
);
850 *pdwKeySpec
= info
->dwKeySpec
;
853 SetLastError(CRYPT_E_NO_KEY_PROPERTY
);
856 HeapFree(GetProcessHeap(), 0, info
);
860 BOOL WINAPI
CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert
,
861 DWORD dwFlags
, void *pvReserved
, HCRYPTPROV_OR_NCRYPT_KEY_HANDLE
*phCryptProv
,
862 DWORD
*pdwKeySpec
, BOOL
*pfCallerFreeProv
)
864 BOOL ret
= FALSE
, cache
= FALSE
;
865 PCRYPT_KEY_PROV_INFO info
= NULL
;
866 CERT_KEY_CONTEXT keyContext
;
869 TRACE("(%p, %08x, %p, %p, %p, %p)\n", pCert
, dwFlags
, pvReserved
,
870 phCryptProv
, pdwKeySpec
, pfCallerFreeProv
);
872 if (dwFlags
& CRYPT_ACQUIRE_USE_PROV_INFO_FLAG
)
876 ret
= CertGetCertificateContextProperty(pCert
,
877 CERT_KEY_PROV_INFO_PROP_ID
, 0, &size
);
880 info
= HeapAlloc(GetProcessHeap(), 0, size
);
881 ret
= CertGetCertificateContextProperty(pCert
,
882 CERT_KEY_PROV_INFO_PROP_ID
, info
, &size
);
884 cache
= info
->dwFlags
& CERT_SET_KEY_CONTEXT_PROP_ID
;
887 else if (dwFlags
& CRYPT_ACQUIRE_CACHE_FLAG
)
892 size
= sizeof(keyContext
);
893 ret
= CertGetCertificateContextProperty(pCert
, CERT_KEY_CONTEXT_PROP_ID
,
897 *phCryptProv
= keyContext
.hCryptProv
;
899 *pdwKeySpec
= keyContext
.dwKeySpec
;
900 if (pfCallerFreeProv
)
901 *pfCallerFreeProv
= !cache
;
906 ret
= CRYPT_AcquirePrivateKeyFromProvInfo(pCert
, info
,
907 &keyContext
.hCryptProv
, &keyContext
.dwKeySpec
);
910 *phCryptProv
= keyContext
.hCryptProv
;
912 *pdwKeySpec
= keyContext
.dwKeySpec
;
915 keyContext
.cbSize
= sizeof(keyContext
);
916 if (CertSetCertificateContextProperty(pCert
,
917 CERT_KEY_CONTEXT_PROP_ID
, 0, &keyContext
))
919 if (pfCallerFreeProv
)
920 *pfCallerFreeProv
= FALSE
;
925 if (pfCallerFreeProv
)
926 *pfCallerFreeProv
= TRUE
;
930 HeapFree(GetProcessHeap(), 0, info
);
934 static BOOL
key_prov_info_matches_cert(PCCERT_CONTEXT pCert
,
935 const CRYPT_KEY_PROV_INFO
*keyProvInfo
)
938 BOOL matches
= FALSE
;
940 if (CryptAcquireContextW(&csp
, keyProvInfo
->pwszContainerName
,
941 keyProvInfo
->pwszProvName
, keyProvInfo
->dwProvType
, keyProvInfo
->dwFlags
))
945 /* Need to sign something to verify the sig. What to sign? Why not
946 * the certificate itself?
948 if (CryptSignAndEncodeCertificate(csp
, AT_SIGNATURE
,
949 pCert
->dwCertEncodingType
, X509_CERT_TO_BE_SIGNED
, pCert
->pCertInfo
,
950 &pCert
->pCertInfo
->SignatureAlgorithm
, NULL
, NULL
, &size
))
952 BYTE
*certEncoded
= CryptMemAlloc(size
);
956 if (CryptSignAndEncodeCertificate(csp
, AT_SIGNATURE
,
957 pCert
->dwCertEncodingType
, X509_CERT_TO_BE_SIGNED
,
958 pCert
->pCertInfo
, &pCert
->pCertInfo
->SignatureAlgorithm
,
959 NULL
, certEncoded
, &size
))
961 if (size
== pCert
->cbCertEncoded
&&
962 !memcmp(certEncoded
, pCert
->pbCertEncoded
, size
))
965 CryptMemFree(certEncoded
);
968 CryptReleaseContext(csp
, 0);
973 static BOOL
container_matches_cert(PCCERT_CONTEXT pCert
, LPCSTR container
,
974 CRYPT_KEY_PROV_INFO
*keyProvInfo
)
976 CRYPT_KEY_PROV_INFO copy
;
977 WCHAR containerW
[MAX_PATH
];
978 BOOL matches
= FALSE
;
980 MultiByteToWideChar(CP_ACP
, 0, container
, -1,
981 containerW
, sizeof(containerW
) / sizeof(containerW
[0]));
982 /* We make a copy of the CRYPT_KEY_PROV_INFO because the caller expects
983 * keyProvInfo->pwszContainerName to be NULL or a heap-allocated container
987 copy
.pwszContainerName
= containerW
;
988 matches
= key_prov_info_matches_cert(pCert
, ©
);
991 keyProvInfo
->pwszContainerName
=
992 CryptMemAlloc((strlenW(containerW
) + 1) * sizeof(WCHAR
));
993 if (keyProvInfo
->pwszContainerName
)
995 strcpyW(keyProvInfo
->pwszContainerName
, containerW
);
996 keyProvInfo
->dwKeySpec
= AT_SIGNATURE
;
1004 /* Searches the provider named keyProvInfo.pwszProvName for a container whose
1005 * private key matches pCert's public key. Upon success, updates keyProvInfo
1006 * with the matching container's info (free keyProvInfo.pwszContainerName upon
1008 * Returns TRUE if found, FALSE if not.
1010 static BOOL
find_key_prov_info_in_provider(PCCERT_CONTEXT pCert
,
1011 CRYPT_KEY_PROV_INFO
*keyProvInfo
)
1013 HCRYPTPROV defProvider
;
1014 BOOL ret
, found
= FALSE
;
1015 char containerA
[MAX_PATH
];
1017 assert(keyProvInfo
->pwszContainerName
== NULL
);
1018 if ((ret
= CryptAcquireContextW(&defProvider
, NULL
,
1019 keyProvInfo
->pwszProvName
, keyProvInfo
->dwProvType
,
1020 keyProvInfo
->dwFlags
| CRYPT_VERIFYCONTEXT
)))
1022 DWORD enumFlags
= keyProvInfo
->dwFlags
| CRYPT_FIRST
;
1024 while (ret
&& !found
)
1026 DWORD size
= sizeof(containerA
);
1028 ret
= CryptGetProvParam(defProvider
, PP_ENUMCONTAINERS
,
1029 (BYTE
*)containerA
, &size
, enumFlags
);
1031 found
= container_matches_cert(pCert
, containerA
, keyProvInfo
);
1032 if (enumFlags
& CRYPT_FIRST
)
1034 enumFlags
&= ~CRYPT_FIRST
;
1035 enumFlags
|= CRYPT_NEXT
;
1038 CryptReleaseContext(defProvider
, 0);
1043 static BOOL
find_matching_provider(PCCERT_CONTEXT pCert
, DWORD dwFlags
)
1045 BOOL found
= FALSE
, ret
= TRUE
;
1046 DWORD index
= 0, cbProvName
= 0;
1047 CRYPT_KEY_PROV_INFO keyProvInfo
;
1049 TRACE("(%p, %08x)\n", pCert
, dwFlags
);
1051 memset(&keyProvInfo
, 0, sizeof(keyProvInfo
));
1052 while (ret
&& !found
)
1056 ret
= CryptEnumProvidersW(index
, NULL
, 0, &keyProvInfo
.dwProvType
,
1060 if (size
<= cbProvName
)
1061 ret
= CryptEnumProvidersW(index
, NULL
, 0,
1062 &keyProvInfo
.dwProvType
, keyProvInfo
.pwszProvName
, &size
);
1065 CryptMemFree(keyProvInfo
.pwszProvName
);
1066 keyProvInfo
.pwszProvName
= CryptMemAlloc(size
);
1067 if (keyProvInfo
.pwszProvName
)
1070 ret
= CryptEnumProvidersW(index
, NULL
, 0,
1071 &keyProvInfo
.dwProvType
, keyProvInfo
.pwszProvName
, &size
);
1074 if (dwFlags
& CRYPT_FIND_SILENT_KEYSET_FLAG
)
1075 keyProvInfo
.dwFlags
|= CRYPT_SILENT
;
1076 if (dwFlags
& CRYPT_FIND_USER_KEYSET_FLAG
||
1077 !(dwFlags
& (CRYPT_FIND_USER_KEYSET_FLAG
|
1078 CRYPT_FIND_MACHINE_KEYSET_FLAG
)))
1080 keyProvInfo
.dwFlags
|= CRYPT_USER_KEYSET
;
1081 found
= find_key_prov_info_in_provider(pCert
,
1086 if (dwFlags
& CRYPT_FIND_MACHINE_KEYSET_FLAG
||
1087 !(dwFlags
& (CRYPT_FIND_USER_KEYSET_FLAG
|
1088 CRYPT_FIND_MACHINE_KEYSET_FLAG
)))
1090 keyProvInfo
.dwFlags
&= ~CRYPT_USER_KEYSET
;
1091 keyProvInfo
.dwFlags
|= CRYPT_MACHINE_KEYSET
;
1092 found
= find_key_prov_info_in_provider(pCert
,
1105 CertSetCertificateContextProperty(pCert
, CERT_KEY_PROV_INFO_PROP_ID
,
1107 CryptMemFree(keyProvInfo
.pwszProvName
);
1108 CryptMemFree(keyProvInfo
.pwszContainerName
);
1112 static BOOL
cert_prov_info_matches_cert(PCCERT_CONTEXT pCert
)
1114 BOOL matches
= FALSE
;
1117 if (CertGetCertificateContextProperty(pCert
, CERT_KEY_PROV_INFO_PROP_ID
,
1120 CRYPT_KEY_PROV_INFO
*keyProvInfo
= CryptMemAlloc(size
);
1124 if (CertGetCertificateContextProperty(pCert
,
1125 CERT_KEY_PROV_INFO_PROP_ID
, keyProvInfo
, &size
))
1126 matches
= key_prov_info_matches_cert(pCert
, keyProvInfo
);
1127 CryptMemFree(keyProvInfo
);
1133 BOOL WINAPI
CryptFindCertificateKeyProvInfo(PCCERT_CONTEXT pCert
,
1134 DWORD dwFlags
, void *pvReserved
)
1136 BOOL matches
= FALSE
;
1138 TRACE("(%p, %08x, %p)\n", pCert
, dwFlags
, pvReserved
);
1140 matches
= cert_prov_info_matches_cert(pCert
);
1142 matches
= find_matching_provider(pCert
, dwFlags
);
1146 BOOL WINAPI
CertCompareCertificate(DWORD dwCertEncodingType
,
1147 PCERT_INFO pCertId1
, PCERT_INFO pCertId2
)
1151 TRACE("(%08x, %p, %p)\n", dwCertEncodingType
, pCertId1
, pCertId2
);
1153 ret
= CertCompareCertificateName(dwCertEncodingType
, &pCertId1
->Issuer
,
1154 &pCertId2
->Issuer
) && CertCompareIntegerBlob(&pCertId1
->SerialNumber
,
1155 &pCertId2
->SerialNumber
);
1156 TRACE("returning %d\n", ret
);
1160 BOOL WINAPI
CertCompareCertificateName(DWORD dwCertEncodingType
,
1161 PCERT_NAME_BLOB pCertName1
, PCERT_NAME_BLOB pCertName2
)
1165 TRACE("(%08x, %p, %p)\n", dwCertEncodingType
, pCertName1
, pCertName2
);
1167 if (pCertName1
->cbData
== pCertName2
->cbData
)
1169 if (pCertName1
->cbData
)
1170 ret
= !memcmp(pCertName1
->pbData
, pCertName2
->pbData
,
1171 pCertName1
->cbData
);
1177 TRACE("returning %d\n", ret
);
1181 /* Returns the number of significant bytes in pInt, where a byte is
1182 * insignificant if it's a leading 0 for positive numbers or a leading 0xff
1183 * for negative numbers. pInt is assumed to be little-endian.
1185 static DWORD
CRYPT_significantBytes(const CRYPT_INTEGER_BLOB
*pInt
)
1187 DWORD ret
= pInt
->cbData
;
1191 if (pInt
->pbData
[ret
- 2] <= 0x7f && pInt
->pbData
[ret
- 1] == 0)
1193 else if (pInt
->pbData
[ret
- 2] >= 0x80 && pInt
->pbData
[ret
- 1] == 0xff)
1201 BOOL WINAPI
CertCompareIntegerBlob(PCRYPT_INTEGER_BLOB pInt1
,
1202 PCRYPT_INTEGER_BLOB pInt2
)
1207 TRACE("(%p, %p)\n", pInt1
, pInt2
);
1209 cb1
= CRYPT_significantBytes(pInt1
);
1210 cb2
= CRYPT_significantBytes(pInt2
);
1214 ret
= !memcmp(pInt1
->pbData
, pInt2
->pbData
, cb1
);
1220 TRACE("returning %d\n", ret
);
1224 BOOL WINAPI
CertComparePublicKeyInfo(DWORD dwCertEncodingType
,
1225 PCERT_PUBLIC_KEY_INFO pPublicKey1
, PCERT_PUBLIC_KEY_INFO pPublicKey2
)
1229 TRACE("(%08x, %p, %p)\n", dwCertEncodingType
, pPublicKey1
, pPublicKey2
);
1231 switch (GET_CERT_ENCODING_TYPE(dwCertEncodingType
))
1233 case 0: /* Seems to mean "raw binary bits" */
1234 if (pPublicKey1
->PublicKey
.cbData
== pPublicKey2
->PublicKey
.cbData
&&
1235 pPublicKey1
->PublicKey
.cUnusedBits
== pPublicKey2
->PublicKey
.cUnusedBits
)
1237 if (pPublicKey2
->PublicKey
.cbData
)
1238 ret
= !memcmp(pPublicKey1
->PublicKey
.pbData
,
1239 pPublicKey2
->PublicKey
.pbData
, pPublicKey1
->PublicKey
.cbData
);
1247 WARN("Unknown encoding type %08x\n", dwCertEncodingType
);
1249 case X509_ASN_ENCODING
:
1251 BLOBHEADER
*pblob1
, *pblob2
;
1254 if (CryptDecodeObject(dwCertEncodingType
, RSA_CSP_PUBLICKEYBLOB
,
1255 pPublicKey1
->PublicKey
.pbData
, pPublicKey1
->PublicKey
.cbData
,
1258 pblob1
= CryptMemAlloc(length
);
1259 if (CryptDecodeObject(dwCertEncodingType
, RSA_CSP_PUBLICKEYBLOB
,
1260 pPublicKey1
->PublicKey
.pbData
, pPublicKey1
->PublicKey
.cbData
,
1261 0, pblob1
, &length
))
1263 if (CryptDecodeObject(dwCertEncodingType
, RSA_CSP_PUBLICKEYBLOB
,
1264 pPublicKey2
->PublicKey
.pbData
, pPublicKey2
->PublicKey
.cbData
,
1267 pblob2
= CryptMemAlloc(length
);
1268 if (CryptDecodeObject(dwCertEncodingType
, RSA_CSP_PUBLICKEYBLOB
,
1269 pPublicKey2
->PublicKey
.pbData
, pPublicKey2
->PublicKey
.cbData
,
1270 0, pblob2
, &length
))
1272 /* The RSAPUBKEY structure directly follows the BLOBHEADER */
1273 RSAPUBKEY
*pk1
= (LPVOID
)(pblob1
+ 1),
1274 *pk2
= (LPVOID
)(pblob2
+ 1);
1275 ret
= (pk1
->bitlen
== pk2
->bitlen
) && (pk1
->pubexp
== pk2
->pubexp
)
1276 && !memcmp(pk1
+ 1, pk2
+ 1, pk1
->bitlen
/8);
1278 CryptMemFree(pblob2
);
1281 CryptMemFree(pblob1
);
1290 DWORD WINAPI
CertGetPublicKeyLength(DWORD dwCertEncodingType
,
1291 PCERT_PUBLIC_KEY_INFO pPublicKey
)
1295 TRACE("(%08x, %p)\n", dwCertEncodingType
, pPublicKey
);
1297 if (GET_CERT_ENCODING_TYPE(dwCertEncodingType
) != X509_ASN_ENCODING
)
1299 SetLastError(ERROR_FILE_NOT_FOUND
);
1302 if (pPublicKey
->Algorithm
.pszObjId
&&
1303 !strcmp(pPublicKey
->Algorithm
.pszObjId
, szOID_RSA_DH
))
1305 FIXME("unimplemented for DH public keys\n");
1306 SetLastError(CRYPT_E_ASN1_BADTAG
);
1312 BOOL ret
= CryptDecodeObjectEx(dwCertEncodingType
,
1313 RSA_CSP_PUBLICKEYBLOB
, pPublicKey
->PublicKey
.pbData
,
1314 pPublicKey
->PublicKey
.cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
, &buf
,
1319 RSAPUBKEY
*rsaPubKey
= (RSAPUBKEY
*)(buf
+ sizeof(BLOBHEADER
));
1321 len
= rsaPubKey
->bitlen
;
1328 typedef BOOL (*CertCompareFunc
)(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1329 DWORD dwFlags
, const void *pvPara
);
1331 static BOOL
compare_cert_by_md5_hash(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1332 DWORD dwFlags
, const void *pvPara
)
1336 DWORD size
= sizeof(hash
);
1338 ret
= CertGetCertificateContextProperty(pCertContext
,
1339 CERT_MD5_HASH_PROP_ID
, hash
, &size
);
1342 const CRYPT_HASH_BLOB
*pHash
= pvPara
;
1344 if (size
== pHash
->cbData
)
1345 ret
= !memcmp(pHash
->pbData
, hash
, size
);
1352 static BOOL
compare_cert_by_sha1_hash(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1353 DWORD dwFlags
, const void *pvPara
)
1357 DWORD size
= sizeof(hash
);
1359 ret
= CertGetCertificateContextProperty(pCertContext
,
1360 CERT_SHA1_HASH_PROP_ID
, hash
, &size
);
1363 const CRYPT_HASH_BLOB
*pHash
= pvPara
;
1365 if (size
== pHash
->cbData
)
1366 ret
= !memcmp(pHash
->pbData
, hash
, size
);
1373 static BOOL
compare_cert_by_name(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1374 DWORD dwFlags
, const void *pvPara
)
1376 CERT_NAME_BLOB
*blob
= (CERT_NAME_BLOB
*)pvPara
, *toCompare
;
1379 if (dwType
& CERT_INFO_SUBJECT_FLAG
)
1380 toCompare
= &pCertContext
->pCertInfo
->Subject
;
1382 toCompare
= &pCertContext
->pCertInfo
->Issuer
;
1383 ret
= CertCompareCertificateName(pCertContext
->dwCertEncodingType
,
1388 static BOOL
compare_cert_by_public_key(PCCERT_CONTEXT pCertContext
,
1389 DWORD dwType
, DWORD dwFlags
, const void *pvPara
)
1391 CERT_PUBLIC_KEY_INFO
*publicKey
= (CERT_PUBLIC_KEY_INFO
*)pvPara
;
1394 ret
= CertComparePublicKeyInfo(pCertContext
->dwCertEncodingType
,
1395 &pCertContext
->pCertInfo
->SubjectPublicKeyInfo
, publicKey
);
1399 static BOOL
compare_cert_by_subject_cert(PCCERT_CONTEXT pCertContext
,
1400 DWORD dwType
, DWORD dwFlags
, const void *pvPara
)
1402 CERT_INFO
*pCertInfo
= (CERT_INFO
*)pvPara
;
1405 /* Matching serial number and subject match.. */
1406 ret
= CertCompareCertificateName(pCertContext
->dwCertEncodingType
,
1407 &pCertContext
->pCertInfo
->Subject
, &pCertInfo
->Issuer
);
1409 ret
= CertCompareIntegerBlob(&pCertContext
->pCertInfo
->SerialNumber
,
1410 &pCertInfo
->SerialNumber
);
1413 /* failing that, if the serial number and issuer match, we match */
1414 ret
= CertCompareIntegerBlob(&pCertContext
->pCertInfo
->SerialNumber
,
1415 &pCertInfo
->SerialNumber
);
1417 ret
= CertCompareCertificateName(pCertContext
->dwCertEncodingType
,
1418 &pCertContext
->pCertInfo
->Issuer
, &pCertInfo
->Issuer
);
1420 TRACE("returning %d\n", ret
);
1424 static BOOL
compare_cert_by_cert_id(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1425 DWORD dwFlags
, const void *pvPara
)
1427 CERT_ID
*id
= (CERT_ID
*)pvPara
;
1430 switch (id
->dwIdChoice
)
1432 case CERT_ID_ISSUER_SERIAL_NUMBER
:
1433 ret
= CertCompareCertificateName(pCertContext
->dwCertEncodingType
,
1434 &pCertContext
->pCertInfo
->Issuer
, &id
->u
.IssuerSerialNumber
.Issuer
);
1436 ret
= CertCompareIntegerBlob(&pCertContext
->pCertInfo
->SerialNumber
,
1437 &id
->u
.IssuerSerialNumber
.SerialNumber
);
1439 case CERT_ID_SHA1_HASH
:
1440 ret
= compare_cert_by_sha1_hash(pCertContext
, dwType
, dwFlags
,
1443 case CERT_ID_KEY_IDENTIFIER
:
1447 ret
= CertGetCertificateContextProperty(pCertContext
,
1448 CERT_KEY_IDENTIFIER_PROP_ID
, NULL
, &size
);
1449 if (ret
&& size
== id
->u
.KeyId
.cbData
)
1451 LPBYTE buf
= CryptMemAlloc(size
);
1455 CertGetCertificateContextProperty(pCertContext
,
1456 CERT_KEY_IDENTIFIER_PROP_ID
, buf
, &size
);
1457 ret
= !memcmp(buf
, id
->u
.KeyId
.pbData
, size
);
1474 static BOOL
compare_existing_cert(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1475 DWORD dwFlags
, const void *pvPara
)
1477 PCCERT_CONTEXT toCompare
= pvPara
;
1478 return CertCompareCertificate(pCertContext
->dwCertEncodingType
,
1479 pCertContext
->pCertInfo
, toCompare
->pCertInfo
);
1482 static BOOL
compare_cert_by_signature_hash(PCCERT_CONTEXT pCertContext
, DWORD dwType
,
1483 DWORD dwFlags
, const void *pvPara
)
1485 const CRYPT_HASH_BLOB
*hash
= pvPara
;
1489 ret
= CertGetCertificateContextProperty(pCertContext
,
1490 CERT_SIGNATURE_HASH_PROP_ID
, NULL
, &size
);
1491 if (ret
&& size
== hash
->cbData
)
1493 LPBYTE buf
= CryptMemAlloc(size
);
1497 CertGetCertificateContextProperty(pCertContext
,
1498 CERT_SIGNATURE_HASH_PROP_ID
, buf
, &size
);
1499 ret
= !memcmp(buf
, hash
->pbData
, size
);
1510 static inline PCCERT_CONTEXT
cert_compare_certs_in_store(HCERTSTORE store
,
1511 PCCERT_CONTEXT prev
, CertCompareFunc compare
, DWORD dwType
, DWORD dwFlags
,
1514 BOOL matches
= FALSE
;
1519 ret
= CertEnumCertificatesInStore(store
, ret
);
1521 matches
= compare(ret
, dwType
, dwFlags
, pvPara
);
1522 } while (ret
!= NULL
&& !matches
);
1526 typedef PCCERT_CONTEXT (*CertFindFunc
)(HCERTSTORE store
, DWORD dwType
,
1527 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
);
1529 static PCCERT_CONTEXT
find_cert_any(HCERTSTORE store
, DWORD dwType
,
1530 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
)
1532 return CertEnumCertificatesInStore(store
, prev
);
1535 static PCCERT_CONTEXT
find_cert_by_issuer(HCERTSTORE store
, DWORD dwType
,
1536 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
)
1539 PCCERT_CONTEXT found
= NULL
, subject
= pvPara
;
1540 PCERT_EXTENSION ext
;
1543 if ((ext
= CertFindExtension(szOID_AUTHORITY_KEY_IDENTIFIER
,
1544 subject
->pCertInfo
->cExtension
, subject
->pCertInfo
->rgExtension
)))
1546 CERT_AUTHORITY_KEY_ID_INFO
*info
;
1548 ret
= CryptDecodeObjectEx(subject
->dwCertEncodingType
,
1549 X509_AUTHORITY_KEY_ID
, ext
->Value
.pbData
, ext
->Value
.cbData
,
1550 CRYPT_DECODE_ALLOC_FLAG
| CRYPT_DECODE_NOCOPY_FLAG
, NULL
,
1556 if (info
->CertIssuer
.cbData
&& info
->CertSerialNumber
.cbData
)
1558 id
.dwIdChoice
= CERT_ID_ISSUER_SERIAL_NUMBER
;
1559 memcpy(&id
.u
.IssuerSerialNumber
.Issuer
, &info
->CertIssuer
,
1560 sizeof(CERT_NAME_BLOB
));
1561 memcpy(&id
.u
.IssuerSerialNumber
.SerialNumber
,
1562 &info
->CertSerialNumber
, sizeof(CRYPT_INTEGER_BLOB
));
1564 else if (info
->KeyId
.cbData
)
1566 id
.dwIdChoice
= CERT_ID_KEY_IDENTIFIER
;
1567 memcpy(&id
.u
.KeyId
, &info
->KeyId
, sizeof(CRYPT_HASH_BLOB
));
1572 found
= cert_compare_certs_in_store(store
, prev
,
1573 compare_cert_by_cert_id
, dwType
, dwFlags
, &id
);
1577 else if ((ext
= CertFindExtension(szOID_AUTHORITY_KEY_IDENTIFIER2
,
1578 subject
->pCertInfo
->cExtension
, subject
->pCertInfo
->rgExtension
)))
1580 CERT_AUTHORITY_KEY_ID2_INFO
*info
;
1582 ret
= CryptDecodeObjectEx(subject
->dwCertEncodingType
,
1583 X509_AUTHORITY_KEY_ID2
, ext
->Value
.pbData
, ext
->Value
.cbData
,
1584 CRYPT_DECODE_ALLOC_FLAG
| CRYPT_DECODE_NOCOPY_FLAG
, NULL
,
1590 if (info
->AuthorityCertIssuer
.cAltEntry
&&
1591 info
->AuthorityCertSerialNumber
.cbData
)
1593 PCERT_ALT_NAME_ENTRY directoryName
= NULL
;
1596 for (i
= 0; !directoryName
&&
1597 i
< info
->AuthorityCertIssuer
.cAltEntry
; i
++)
1598 if (info
->AuthorityCertIssuer
.rgAltEntry
[i
].dwAltNameChoice
1599 == CERT_ALT_NAME_DIRECTORY_NAME
)
1601 &info
->AuthorityCertIssuer
.rgAltEntry
[i
];
1604 id
.dwIdChoice
= CERT_ID_ISSUER_SERIAL_NUMBER
;
1605 memcpy(&id
.u
.IssuerSerialNumber
.Issuer
,
1606 &directoryName
->u
.DirectoryName
, sizeof(CERT_NAME_BLOB
));
1607 memcpy(&id
.u
.IssuerSerialNumber
.SerialNumber
,
1608 &info
->AuthorityCertSerialNumber
,
1609 sizeof(CRYPT_INTEGER_BLOB
));
1613 FIXME("no supported name type in authority key id2\n");
1617 else if (info
->KeyId
.cbData
)
1619 id
.dwIdChoice
= CERT_ID_KEY_IDENTIFIER
;
1620 memcpy(&id
.u
.KeyId
, &info
->KeyId
, sizeof(CRYPT_HASH_BLOB
));
1625 found
= cert_compare_certs_in_store(store
, prev
,
1626 compare_cert_by_cert_id
, dwType
, dwFlags
, &id
);
1631 found
= cert_compare_certs_in_store(store
, prev
,
1632 compare_cert_by_name
, CERT_COMPARE_NAME
| CERT_COMPARE_SUBJECT_CERT
,
1633 dwFlags
, &subject
->pCertInfo
->Issuer
);
1637 static BOOL
compare_cert_by_name_str(PCCERT_CONTEXT pCertContext
,
1638 DWORD dwType
, DWORD dwFlags
, const void *pvPara
)
1640 PCERT_NAME_BLOB name
;
1644 if (dwType
& CERT_INFO_SUBJECT_FLAG
)
1645 name
= &pCertContext
->pCertInfo
->Subject
;
1647 name
= &pCertContext
->pCertInfo
->Issuer
;
1648 len
= CertNameToStrW(pCertContext
->dwCertEncodingType
, name
,
1649 CERT_SIMPLE_NAME_STR
, NULL
, 0);
1652 LPWSTR str
= CryptMemAlloc(len
* sizeof(WCHAR
));
1658 CertNameToStrW(pCertContext
->dwCertEncodingType
, name
,
1659 CERT_SIMPLE_NAME_STR
, str
, len
);
1660 for (ptr
= str
; *ptr
; ptr
++)
1661 *ptr
= tolowerW(*ptr
);
1662 if (strstrW(str
, pvPara
))
1670 static PCCERT_CONTEXT
find_cert_by_name_str_a(HCERTSTORE store
, DWORD dwType
,
1671 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
)
1673 PCCERT_CONTEXT found
= NULL
;
1675 TRACE("%s\n", debugstr_a(pvPara
));
1679 int len
= MultiByteToWideChar(CP_ACP
, 0, pvPara
, -1, NULL
, 0);
1680 LPWSTR str
= CryptMemAlloc(len
* sizeof(WCHAR
));
1686 MultiByteToWideChar(CP_ACP
, 0, pvPara
, -1, str
, len
);
1687 for (ptr
= str
; *ptr
; ptr
++)
1688 *ptr
= tolowerW(*ptr
);
1689 found
= cert_compare_certs_in_store(store
, prev
,
1690 compare_cert_by_name_str
, dwType
, dwFlags
, str
);
1695 found
= find_cert_any(store
, dwType
, dwFlags
, NULL
, prev
);
1699 static PCCERT_CONTEXT
find_cert_by_name_str_w(HCERTSTORE store
, DWORD dwType
,
1700 DWORD dwFlags
, const void *pvPara
, PCCERT_CONTEXT prev
)
1702 PCCERT_CONTEXT found
= NULL
;
1704 TRACE("%s\n", debugstr_w(pvPara
));
1708 DWORD len
= strlenW(pvPara
);
1709 LPWSTR str
= CryptMemAlloc((len
+ 1) * sizeof(WCHAR
));
1716 for (src
= pvPara
, dst
= str
; *src
; src
++, dst
++)
1717 *dst
= tolowerW(*src
);
1719 found
= cert_compare_certs_in_store(store
, prev
,
1720 compare_cert_by_name_str
, dwType
, dwFlags
, str
);
1725 found
= find_cert_any(store
, dwType
, dwFlags
, NULL
, prev
);
1729 PCCERT_CONTEXT WINAPI
CertFindCertificateInStore(HCERTSTORE hCertStore
,
1730 DWORD dwCertEncodingType
, DWORD dwFlags
, DWORD dwType
, const void *pvPara
,
1731 PCCERT_CONTEXT pPrevCertContext
)
1734 CertFindFunc find
= NULL
;
1735 CertCompareFunc compare
= NULL
;
1737 TRACE("(%p, %08x, %08x, %08x, %p, %p)\n", hCertStore
, dwCertEncodingType
,
1738 dwFlags
, dwType
, pvPara
, pPrevCertContext
);
1740 switch (dwType
>> CERT_COMPARE_SHIFT
)
1742 case CERT_COMPARE_ANY
:
1743 find
= find_cert_any
;
1745 case CERT_COMPARE_MD5_HASH
:
1746 compare
= compare_cert_by_md5_hash
;
1748 case CERT_COMPARE_SHA1_HASH
:
1749 compare
= compare_cert_by_sha1_hash
;
1751 case CERT_COMPARE_NAME
:
1752 compare
= compare_cert_by_name
;
1754 case CERT_COMPARE_PUBLIC_KEY
:
1755 compare
= compare_cert_by_public_key
;
1757 case CERT_COMPARE_NAME_STR_A
:
1758 find
= find_cert_by_name_str_a
;
1760 case CERT_COMPARE_NAME_STR_W
:
1761 find
= find_cert_by_name_str_w
;
1763 case CERT_COMPARE_SUBJECT_CERT
:
1764 compare
= compare_cert_by_subject_cert
;
1766 case CERT_COMPARE_CERT_ID
:
1767 compare
= compare_cert_by_cert_id
;
1769 case CERT_COMPARE_ISSUER_OF
:
1770 find
= find_cert_by_issuer
;
1772 case CERT_COMPARE_EXISTING
:
1773 compare
= compare_existing_cert
;
1775 case CERT_COMPARE_SIGNATURE_HASH
:
1776 compare
= compare_cert_by_signature_hash
;
1779 FIXME("find type %08x unimplemented\n", dwType
);
1783 ret
= find(hCertStore
, dwFlags
, dwType
, pvPara
, pPrevCertContext
);
1785 ret
= cert_compare_certs_in_store(hCertStore
, pPrevCertContext
,
1786 compare
, dwType
, dwFlags
, pvPara
);
1790 SetLastError(CRYPT_E_NOT_FOUND
);
1791 TRACE("returning %p\n", ret
);
1795 PCCERT_CONTEXT WINAPI
CertGetSubjectCertificateFromStore(HCERTSTORE hCertStore
,
1796 DWORD dwCertEncodingType
, PCERT_INFO pCertId
)
1798 TRACE("(%p, %08x, %p)\n", hCertStore
, dwCertEncodingType
, pCertId
);
1802 SetLastError(E_INVALIDARG
);
1805 return CertFindCertificateInStore(hCertStore
, dwCertEncodingType
, 0,
1806 CERT_FIND_SUBJECT_CERT
, pCertId
, NULL
);
1809 BOOL WINAPI
CertVerifySubjectCertificateContext(PCCERT_CONTEXT pSubject
,
1810 PCCERT_CONTEXT pIssuer
, DWORD
*pdwFlags
)
1812 static const DWORD supportedFlags
= CERT_STORE_REVOCATION_FLAG
|
1813 CERT_STORE_SIGNATURE_FLAG
| CERT_STORE_TIME_VALIDITY_FLAG
;
1815 if (*pdwFlags
& ~supportedFlags
)
1817 SetLastError(E_INVALIDARG
);
1820 if (*pdwFlags
& CERT_STORE_REVOCATION_FLAG
)
1823 PCCRL_CONTEXT crl
= CertGetCRLFromStore(pSubject
->hCertStore
, pSubject
,
1826 /* FIXME: what if the CRL has expired? */
1829 if (CertVerifyCRLRevocation(pSubject
->dwCertEncodingType
,
1830 pSubject
->pCertInfo
, 1, (PCRL_INFO
*)&crl
->pCrlInfo
))
1831 *pdwFlags
&= CERT_STORE_REVOCATION_FLAG
;
1834 *pdwFlags
|= CERT_STORE_NO_CRL_FLAG
;
1836 if (*pdwFlags
& CERT_STORE_TIME_VALIDITY_FLAG
)
1838 if (0 == CertVerifyTimeValidity(NULL
, pSubject
->pCertInfo
))
1839 *pdwFlags
&= ~CERT_STORE_TIME_VALIDITY_FLAG
;
1841 if (*pdwFlags
& CERT_STORE_SIGNATURE_FLAG
)
1843 if (CryptVerifyCertificateSignatureEx(0, pSubject
->dwCertEncodingType
,
1844 CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT
, (void *)pSubject
,
1845 CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT
, (void *)pIssuer
, 0, NULL
))
1846 *pdwFlags
&= ~CERT_STORE_SIGNATURE_FLAG
;
1851 PCCERT_CONTEXT WINAPI
CertGetIssuerCertificateFromStore(HCERTSTORE hCertStore
,
1852 PCCERT_CONTEXT pSubjectContext
, PCCERT_CONTEXT pPrevIssuerContext
,
1857 TRACE("(%p, %p, %p, %08x)\n", hCertStore
, pSubjectContext
,
1858 pPrevIssuerContext
, *pdwFlags
);
1860 if (!pSubjectContext
)
1862 SetLastError(E_INVALIDARG
);
1866 ret
= CertFindCertificateInStore(hCertStore
,
1867 pSubjectContext
->dwCertEncodingType
, 0, CERT_FIND_ISSUER_OF
,
1868 pSubjectContext
, pPrevIssuerContext
);
1871 if (!CertVerifySubjectCertificateContext(pSubjectContext
, ret
,
1874 CertFreeCertificateContext(ret
);
1877 if (CRYPT_IsCertificateSelfSigned(pSubjectContext
))
1879 CertFreeCertificateContext(ret
);
1881 SetLastError(CRYPT_E_SELF_SIGNED
);
1884 TRACE("returning %p\n", ret
);
1888 typedef struct _OLD_CERT_REVOCATION_STATUS
{
1893 } OLD_CERT_REVOCATION_STATUS
;
1895 typedef BOOL (WINAPI
*CertVerifyRevocationFunc
)(DWORD
, DWORD
, DWORD
,
1896 void **, DWORD
, PCERT_REVOCATION_PARA
, PCERT_REVOCATION_STATUS
);
1898 BOOL WINAPI
CertVerifyRevocation(DWORD dwEncodingType
, DWORD dwRevType
,
1899 DWORD cContext
, PVOID rgpvContext
[], DWORD dwFlags
,
1900 PCERT_REVOCATION_PARA pRevPara
, PCERT_REVOCATION_STATUS pRevStatus
)
1904 TRACE("(%08x, %d, %d, %p, %08x, %p, %p)\n", dwEncodingType
, dwRevType
,
1905 cContext
, rgpvContext
, dwFlags
, pRevPara
, pRevStatus
);
1907 if (pRevStatus
->cbSize
!= sizeof(OLD_CERT_REVOCATION_STATUS
) &&
1908 pRevStatus
->cbSize
!= sizeof(CERT_REVOCATION_STATUS
))
1910 SetLastError(E_INVALIDARG
);
1915 static HCRYPTOIDFUNCSET set
= NULL
;
1919 set
= CryptInitOIDFunctionSet(CRYPT_OID_VERIFY_REVOCATION_FUNC
, 0);
1920 ret
= CryptGetDefaultOIDDllList(set
, dwEncodingType
, NULL
, &size
);
1926 SetLastError(CRYPT_E_NO_REVOCATION_DLL
);
1931 LPWSTR dllList
= CryptMemAlloc(size
* sizeof(WCHAR
)), ptr
;
1935 ret
= CryptGetDefaultOIDDllList(set
, dwEncodingType
,
1939 for (ptr
= dllList
; ret
&& *ptr
;
1940 ptr
+= lstrlenW(ptr
) + 1)
1942 CertVerifyRevocationFunc func
;
1943 HCRYPTOIDFUNCADDR hFunc
;
1945 ret
= CryptGetDefaultOIDFunctionAddress(set
,
1946 dwEncodingType
, ptr
, 0, (void **)&func
, &hFunc
);
1949 ret
= func(dwEncodingType
, dwRevType
, cContext
,
1950 rgpvContext
, dwFlags
, pRevPara
, pRevStatus
);
1951 CryptFreeOIDFunctionAddress(hFunc
, 0);
1955 CryptMemFree(dllList
);
1959 SetLastError(ERROR_OUTOFMEMORY
);
1970 PCRYPT_ATTRIBUTE WINAPI
CertFindAttribute(LPCSTR pszObjId
, DWORD cAttr
,
1971 CRYPT_ATTRIBUTE rgAttr
[])
1973 PCRYPT_ATTRIBUTE ret
= NULL
;
1976 TRACE("%s %d %p\n", debugstr_a(pszObjId
), cAttr
, rgAttr
);
1982 SetLastError(ERROR_INVALID_PARAMETER
);
1986 for (i
= 0; !ret
&& i
< cAttr
; i
++)
1987 if (rgAttr
[i
].pszObjId
&& !strcmp(pszObjId
, rgAttr
[i
].pszObjId
))
1992 PCERT_EXTENSION WINAPI
CertFindExtension(LPCSTR pszObjId
, DWORD cExtensions
,
1993 CERT_EXTENSION rgExtensions
[])
1995 PCERT_EXTENSION ret
= NULL
;
1998 TRACE("%s %d %p\n", debugstr_a(pszObjId
), cExtensions
, rgExtensions
);
2004 SetLastError(ERROR_INVALID_PARAMETER
);
2008 for (i
= 0; !ret
&& i
< cExtensions
; i
++)
2009 if (rgExtensions
[i
].pszObjId
&& !strcmp(pszObjId
,
2010 rgExtensions
[i
].pszObjId
))
2011 ret
= &rgExtensions
[i
];
2015 PCERT_RDN_ATTR WINAPI
CertFindRDNAttr(LPCSTR pszObjId
, PCERT_NAME_INFO pName
)
2017 PCERT_RDN_ATTR ret
= NULL
;
2020 TRACE("%s %p\n", debugstr_a(pszObjId
), pName
);
2024 SetLastError(ERROR_INVALID_PARAMETER
);
2028 for (i
= 0; !ret
&& i
< pName
->cRDN
; i
++)
2029 for (j
= 0; !ret
&& j
< pName
->rgRDN
[i
].cRDNAttr
; j
++)
2030 if (pName
->rgRDN
[i
].rgRDNAttr
[j
].pszObjId
&& !strcmp(pszObjId
,
2031 pName
->rgRDN
[i
].rgRDNAttr
[j
].pszObjId
))
2032 ret
= &pName
->rgRDN
[i
].rgRDNAttr
[j
];
2036 static BOOL
find_matching_rdn_attr(DWORD dwFlags
, const CERT_NAME_INFO
*name
,
2037 const CERT_RDN_ATTR
*attr
)
2042 for (i
= 0; !match
&& i
< name
->cRDN
; i
++)
2044 for (j
= 0; j
< name
->rgRDN
[i
].cRDNAttr
; j
++)
2046 if (!strcmp(name
->rgRDN
[i
].rgRDNAttr
[j
].pszObjId
,
2048 name
->rgRDN
[i
].rgRDNAttr
[j
].dwValueType
==
2051 if (dwFlags
& CERT_UNICODE_IS_RDN_ATTRS_FLAG
)
2054 (LPCWSTR
)name
->rgRDN
[i
].rgRDNAttr
[j
].Value
.pbData
;
2055 LPCWSTR attrStr
= (LPCWSTR
)attr
->Value
.pbData
;
2057 if (attr
->Value
.cbData
!=
2058 name
->rgRDN
[i
].rgRDNAttr
[j
].Value
.cbData
)
2060 else if (dwFlags
& CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG
)
2061 match
= !strncmpiW(nameStr
, attrStr
,
2062 attr
->Value
.cbData
/ sizeof(WCHAR
));
2064 match
= !strncmpW(nameStr
, attrStr
,
2065 attr
->Value
.cbData
/ sizeof(WCHAR
));
2066 TRACE("%s : %s => %d\n",
2067 debugstr_wn(nameStr
, attr
->Value
.cbData
/ sizeof(WCHAR
)),
2068 debugstr_wn(attrStr
, attr
->Value
.cbData
/ sizeof(WCHAR
)),
2074 (LPCSTR
)name
->rgRDN
[i
].rgRDNAttr
[j
].Value
.pbData
;
2075 LPCSTR attrStr
= (LPCSTR
)attr
->Value
.pbData
;
2077 if (attr
->Value
.cbData
!=
2078 name
->rgRDN
[i
].rgRDNAttr
[j
].Value
.cbData
)
2080 else if (dwFlags
& CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG
)
2081 match
= !strncasecmp(nameStr
, attrStr
,
2082 attr
->Value
.cbData
);
2084 match
= !strncmp(nameStr
, attrStr
, attr
->Value
.cbData
);
2085 TRACE("%s : %s => %d\n",
2086 debugstr_an(nameStr
, attr
->Value
.cbData
),
2087 debugstr_an(attrStr
, attr
->Value
.cbData
), match
);
2095 BOOL WINAPI
CertIsRDNAttrsInCertificateName(DWORD dwCertEncodingType
,
2096 DWORD dwFlags
, PCERT_NAME_BLOB pCertName
, PCERT_RDN pRDN
)
2098 CERT_NAME_INFO
*name
;
2103 TRACE("(%08x, %08x, %p, %p)\n", dwCertEncodingType
, dwFlags
, pCertName
,
2106 type
= dwFlags
& CERT_UNICODE_IS_RDN_ATTRS_FLAG
? X509_UNICODE_NAME
:
2108 if ((ret
= CryptDecodeObjectEx(dwCertEncodingType
, type
, pCertName
->pbData
,
2109 pCertName
->cbData
, CRYPT_DECODE_ALLOC_FLAG
, NULL
, &name
, &size
)))
2113 for (i
= 0; ret
&& i
< pRDN
->cRDNAttr
; i
++)
2114 ret
= find_matching_rdn_attr(dwFlags
, name
, &pRDN
->rgRDNAttr
[i
]);
2116 SetLastError(CRYPT_E_NO_MATCH
);
2122 LONG WINAPI
CertVerifyTimeValidity(LPFILETIME pTimeToVerify
,
2123 PCERT_INFO pCertInfo
)
2130 GetSystemTimeAsFileTime(&fileTime
);
2131 pTimeToVerify
= &fileTime
;
2133 if ((ret
= CompareFileTime(pTimeToVerify
, &pCertInfo
->NotBefore
)) >= 0)
2135 ret
= CompareFileTime(pTimeToVerify
, &pCertInfo
->NotAfter
);
2142 BOOL WINAPI
CertVerifyValidityNesting(PCERT_INFO pSubjectInfo
,
2143 PCERT_INFO pIssuerInfo
)
2145 TRACE("(%p, %p)\n", pSubjectInfo
, pIssuerInfo
);
2147 return CertVerifyTimeValidity(&pSubjectInfo
->NotBefore
, pIssuerInfo
) == 0
2148 && CertVerifyTimeValidity(&pSubjectInfo
->NotAfter
, pIssuerInfo
) == 0;
2151 BOOL WINAPI
CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv
, ALG_ID Algid
,
2152 DWORD dwFlags
, const BYTE
*pbEncoded
, DWORD cbEncoded
, BYTE
*pbComputedHash
,
2153 DWORD
*pcbComputedHash
)
2156 HCRYPTHASH hHash
= 0;
2158 TRACE("(%08lx, %d, %08x, %p, %d, %p, %p)\n", hCryptProv
, Algid
, dwFlags
,
2159 pbEncoded
, cbEncoded
, pbComputedHash
, pcbComputedHash
);
2162 hCryptProv
= CRYPT_GetDefaultProvider();
2167 ret
= CryptCreateHash(hCryptProv
, Algid
, 0, 0, &hHash
);
2170 ret
= CryptHashData(hHash
, pbEncoded
, cbEncoded
, 0);
2172 ret
= CryptGetHashParam(hHash
, HP_HASHVAL
, pbComputedHash
,
2173 pcbComputedHash
, 0);
2174 CryptDestroyHash(hHash
);
2180 BOOL WINAPI
CryptHashPublicKeyInfo(HCRYPTPROV_LEGACY hCryptProv
, ALG_ID Algid
,
2181 DWORD dwFlags
, DWORD dwCertEncodingType
, PCERT_PUBLIC_KEY_INFO pInfo
,
2182 BYTE
*pbComputedHash
, DWORD
*pcbComputedHash
)
2185 HCRYPTHASH hHash
= 0;
2187 TRACE("(%08lx, %d, %08x, %d, %p, %p, %p)\n", hCryptProv
, Algid
, dwFlags
,
2188 dwCertEncodingType
, pInfo
, pbComputedHash
, pcbComputedHash
);
2191 hCryptProv
= CRYPT_GetDefaultProvider();
2194 if ((dwCertEncodingType
& CERT_ENCODING_TYPE_MASK
) != X509_ASN_ENCODING
)
2196 SetLastError(ERROR_FILE_NOT_FOUND
);
2204 ret
= CRYPT_AsnEncodePubKeyInfoNoNull(dwCertEncodingType
,
2205 X509_PUBLIC_KEY_INFO
, pInfo
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
,
2206 (LPBYTE
)&buf
, &size
);
2209 ret
= CryptCreateHash(hCryptProv
, Algid
, 0, 0, &hHash
);
2212 ret
= CryptHashData(hHash
, buf
, size
, 0);
2214 ret
= CryptGetHashParam(hHash
, HP_HASHVAL
, pbComputedHash
,
2215 pcbComputedHash
, 0);
2216 CryptDestroyHash(hHash
);
2224 BOOL WINAPI
CryptHashToBeSigned(HCRYPTPROV_LEGACY hCryptProv
,
2225 DWORD dwCertEncodingType
, const BYTE
*pbEncoded
, DWORD cbEncoded
,
2226 BYTE
*pbComputedHash
, DWORD
*pcbComputedHash
)
2229 CERT_SIGNED_CONTENT_INFO
*info
;
2232 TRACE("(%08lx, %08x, %p, %d, %p, %d)\n", hCryptProv
, dwCertEncodingType
,
2233 pbEncoded
, cbEncoded
, pbComputedHash
, *pcbComputedHash
);
2235 ret
= CryptDecodeObjectEx(dwCertEncodingType
, X509_CERT
,
2236 pbEncoded
, cbEncoded
, CRYPT_DECODE_ALLOC_FLAG
, NULL
, &info
, &size
);
2239 PCCRYPT_OID_INFO oidInfo
;
2243 hCryptProv
= CRYPT_GetDefaultProvider();
2244 oidInfo
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2245 info
->SignatureAlgorithm
.pszObjId
, 0);
2248 SetLastError(NTE_BAD_ALGID
);
2253 ret
= CryptCreateHash(hCryptProv
, oidInfo
->u
.Algid
, 0, 0, &hHash
);
2256 ret
= CryptHashData(hHash
, info
->ToBeSigned
.pbData
,
2257 info
->ToBeSigned
.cbData
, 0);
2259 ret
= CryptGetHashParam(hHash
, HP_HASHVAL
, pbComputedHash
,
2260 pcbComputedHash
, 0);
2261 CryptDestroyHash(hHash
);
2269 BOOL WINAPI
CryptSignCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProv
,
2270 DWORD dwKeySpec
, DWORD dwCertEncodingType
, const BYTE
*pbEncodedToBeSigned
,
2271 DWORD cbEncodedToBeSigned
, PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm
,
2272 const void *pvHashAuxInfo
, BYTE
*pbSignature
, DWORD
*pcbSignature
)
2275 PCCRYPT_OID_INFO info
;
2278 TRACE("(%08lx, %d, %d, %p, %d, %p, %p, %p, %p)\n", hCryptProv
,
2279 dwKeySpec
, dwCertEncodingType
, pbEncodedToBeSigned
, cbEncodedToBeSigned
,
2280 pSignatureAlgorithm
, pvHashAuxInfo
, pbSignature
, pcbSignature
);
2282 info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2283 pSignatureAlgorithm
->pszObjId
, 0);
2286 SetLastError(NTE_BAD_ALGID
);
2289 if (info
->dwGroupId
== CRYPT_HASH_ALG_OID_GROUP_ID
)
2292 hCryptProv
= CRYPT_GetDefaultProvider();
2293 ret
= CryptCreateHash(hCryptProv
, info
->u
.Algid
, 0, 0, &hHash
);
2296 ret
= CryptHashData(hHash
, pbEncodedToBeSigned
,
2297 cbEncodedToBeSigned
, 0);
2299 ret
= CryptGetHashParam(hHash
, HP_HASHVAL
, pbSignature
,
2301 CryptDestroyHash(hHash
);
2308 SetLastError(ERROR_INVALID_PARAMETER
);
2313 ret
= CryptCreateHash(hCryptProv
, info
->u
.Algid
, 0, 0, &hHash
);
2316 ret
= CryptHashData(hHash
, pbEncodedToBeSigned
,
2317 cbEncodedToBeSigned
, 0);
2319 ret
= CryptSignHashW(hHash
, dwKeySpec
, NULL
, 0, pbSignature
,
2321 CryptDestroyHash(hHash
);
2328 BOOL WINAPI
CryptSignAndEncodeCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProv
,
2329 DWORD dwKeySpec
, DWORD dwCertEncodingType
, LPCSTR lpszStructType
,
2330 const void *pvStructInfo
, PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm
,
2331 const void *pvHashAuxInfo
, BYTE
*pbEncoded
, DWORD
*pcbEncoded
)
2334 DWORD encodedSize
, hashSize
;
2336 TRACE("(%08lx, %d, %d, %s, %p, %p, %p, %p, %p)\n", hCryptProv
, dwKeySpec
,
2337 dwCertEncodingType
, debugstr_a(lpszStructType
), pvStructInfo
,
2338 pSignatureAlgorithm
, pvHashAuxInfo
, pbEncoded
, pcbEncoded
);
2340 ret
= CryptEncodeObject(dwCertEncodingType
, lpszStructType
, pvStructInfo
,
2341 NULL
, &encodedSize
);
2344 PBYTE encoded
= CryptMemAlloc(encodedSize
);
2348 ret
= CryptEncodeObject(dwCertEncodingType
, lpszStructType
,
2349 pvStructInfo
, encoded
, &encodedSize
);
2352 ret
= CryptSignCertificate(hCryptProv
, dwKeySpec
,
2353 dwCertEncodingType
, encoded
, encodedSize
, pSignatureAlgorithm
,
2354 pvHashAuxInfo
, NULL
, &hashSize
);
2357 PBYTE hash
= CryptMemAlloc(hashSize
);
2361 ret
= CryptSignCertificate(hCryptProv
, dwKeySpec
,
2362 dwCertEncodingType
, encoded
, encodedSize
,
2363 pSignatureAlgorithm
, pvHashAuxInfo
, hash
, &hashSize
);
2366 CERT_SIGNED_CONTENT_INFO info
= { { 0 } };
2368 info
.ToBeSigned
.cbData
= encodedSize
;
2369 info
.ToBeSigned
.pbData
= encoded
;
2370 info
.SignatureAlgorithm
= *pSignatureAlgorithm
;
2371 info
.Signature
.cbData
= hashSize
;
2372 info
.Signature
.pbData
= hash
;
2373 info
.Signature
.cUnusedBits
= 0;
2374 ret
= CryptEncodeObject(dwCertEncodingType
,
2375 X509_CERT
, &info
, pbEncoded
, pcbEncoded
);
2383 CryptMemFree(encoded
);
2391 BOOL WINAPI
CryptVerifyCertificateSignature(HCRYPTPROV_LEGACY hCryptProv
,
2392 DWORD dwCertEncodingType
, const BYTE
*pbEncoded
, DWORD cbEncoded
,
2393 PCERT_PUBLIC_KEY_INFO pPublicKey
)
2395 CRYPT_DATA_BLOB blob
= { cbEncoded
, (BYTE
*)pbEncoded
};
2397 return CryptVerifyCertificateSignatureEx(hCryptProv
, dwCertEncodingType
,
2398 CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB
, &blob
,
2399 CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY
, pPublicKey
, 0, NULL
);
2402 static BOOL
CRYPT_VerifyCertSignatureFromPublicKeyInfo(HCRYPTPROV_LEGACY hCryptProv
,
2403 DWORD dwCertEncodingType
, PCERT_PUBLIC_KEY_INFO pubKeyInfo
,
2404 const CERT_SIGNED_CONTENT_INFO
*signedCert
)
2408 PCCRYPT_OID_INFO info
;
2409 ALG_ID pubKeyID
, hashID
;
2411 info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
,
2412 signedCert
->SignatureAlgorithm
.pszObjId
, 0);
2413 if (!info
|| info
->dwGroupId
!= CRYPT_SIGN_ALG_OID_GROUP_ID
)
2415 SetLastError(NTE_BAD_ALGID
);
2418 hashID
= info
->u
.Algid
;
2419 if (info
->ExtraInfo
.cbData
>= sizeof(ALG_ID
))
2420 pubKeyID
= *(ALG_ID
*)info
->ExtraInfo
.pbData
;
2423 /* Load the default provider if necessary */
2425 hCryptProv
= CRYPT_GetDefaultProvider();
2426 ret
= CryptImportPublicKeyInfoEx(hCryptProv
, dwCertEncodingType
,
2427 pubKeyInfo
, pubKeyID
, 0, NULL
, &key
);
2432 ret
= CryptCreateHash(hCryptProv
, hashID
, 0, 0, &hash
);
2435 ret
= CryptHashData(hash
, signedCert
->ToBeSigned
.pbData
,
2436 signedCert
->ToBeSigned
.cbData
, 0);
2438 ret
= CryptVerifySignatureW(hash
, signedCert
->Signature
.pbData
,
2439 signedCert
->Signature
.cbData
, key
, NULL
, 0);
2440 CryptDestroyHash(hash
);
2442 CryptDestroyKey(key
);
2447 BOOL WINAPI
CryptVerifyCertificateSignatureEx(HCRYPTPROV_LEGACY hCryptProv
,
2448 DWORD dwCertEncodingType
, DWORD dwSubjectType
, void *pvSubject
,
2449 DWORD dwIssuerType
, void *pvIssuer
, DWORD dwFlags
, void *pvReserved
)
2452 CRYPT_DATA_BLOB subjectBlob
;
2454 TRACE("(%08lx, %d, %d, %p, %d, %p, %08x, %p)\n", hCryptProv
,
2455 dwCertEncodingType
, dwSubjectType
, pvSubject
, dwIssuerType
, pvIssuer
,
2456 dwFlags
, pvReserved
);
2458 switch (dwSubjectType
)
2460 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB
:
2462 PCRYPT_DATA_BLOB blob
= pvSubject
;
2464 subjectBlob
.pbData
= blob
->pbData
;
2465 subjectBlob
.cbData
= blob
->cbData
;
2468 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT
:
2470 PCERT_CONTEXT context
= pvSubject
;
2472 subjectBlob
.pbData
= context
->pbCertEncoded
;
2473 subjectBlob
.cbData
= context
->cbCertEncoded
;
2476 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL
:
2478 PCRL_CONTEXT context
= pvSubject
;
2480 subjectBlob
.pbData
= context
->pbCrlEncoded
;
2481 subjectBlob
.cbData
= context
->cbCrlEncoded
;
2485 SetLastError(E_INVALIDARG
);
2491 PCERT_SIGNED_CONTENT_INFO signedCert
= NULL
;
2494 ret
= CryptDecodeObjectEx(dwCertEncodingType
, X509_CERT
,
2495 subjectBlob
.pbData
, subjectBlob
.cbData
,
2496 CRYPT_DECODE_ALLOC_FLAG
| CRYPT_DECODE_NOCOPY_FLAG
, NULL
,
2497 &signedCert
, &size
);
2500 switch (dwIssuerType
)
2502 case CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY
:
2503 ret
= CRYPT_VerifyCertSignatureFromPublicKeyInfo(hCryptProv
,
2504 dwCertEncodingType
, pvIssuer
,
2507 case CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT
:
2508 ret
= CRYPT_VerifyCertSignatureFromPublicKeyInfo(hCryptProv
,
2510 &((PCCERT_CONTEXT
)pvIssuer
)->pCertInfo
->SubjectPublicKeyInfo
,
2513 case CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN
:
2514 FIXME("CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN: stub\n");
2517 case CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL
:
2520 SetLastError(E_INVALIDARG
);
2525 FIXME("unimplemented for NULL signer\n");
2526 SetLastError(E_INVALIDARG
);
2531 SetLastError(E_INVALIDARG
);
2534 LocalFree(signedCert
);
2540 BOOL WINAPI
CertGetIntendedKeyUsage(DWORD dwCertEncodingType
,
2541 PCERT_INFO pCertInfo
, BYTE
*pbKeyUsage
, DWORD cbKeyUsage
)
2543 PCERT_EXTENSION ext
;
2546 TRACE("(%08x, %p, %p, %d)\n", dwCertEncodingType
, pCertInfo
, pbKeyUsage
,
2549 ext
= CertFindExtension(szOID_KEY_USAGE
, pCertInfo
->cExtension
,
2550 pCertInfo
->rgExtension
);
2553 CRYPT_BIT_BLOB usage
;
2554 DWORD size
= sizeof(usage
);
2556 ret
= CryptDecodeObjectEx(dwCertEncodingType
, X509_BITS
,
2557 ext
->Value
.pbData
, ext
->Value
.cbData
, CRYPT_DECODE_NOCOPY_FLAG
, NULL
,
2561 if (cbKeyUsage
< usage
.cbData
)
2565 memcpy(pbKeyUsage
, usage
.pbData
, usage
.cbData
);
2566 if (cbKeyUsage
> usage
.cbData
)
2567 memset(pbKeyUsage
+ usage
.cbData
, 0,
2568 cbKeyUsage
- usage
.cbData
);
2577 BOOL WINAPI
CertGetEnhancedKeyUsage(PCCERT_CONTEXT pCertContext
, DWORD dwFlags
,
2578 PCERT_ENHKEY_USAGE pUsage
, DWORD
*pcbUsage
)
2580 PCERT_ENHKEY_USAGE usage
= NULL
;
2584 if (!pCertContext
|| !pcbUsage
)
2586 SetLastError(ERROR_INVALID_PARAMETER
);
2590 TRACE("(%p, %08x, %p, %d)\n", pCertContext
, dwFlags
, pUsage
, *pcbUsage
);
2592 if (!(dwFlags
& CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
))
2596 if (CertGetCertificateContextProperty(pCertContext
,
2597 CERT_ENHKEY_USAGE_PROP_ID
, NULL
, &propSize
))
2599 LPBYTE buf
= CryptMemAlloc(propSize
);
2603 if (CertGetCertificateContextProperty(pCertContext
,
2604 CERT_ENHKEY_USAGE_PROP_ID
, buf
, &propSize
))
2606 ret
= CryptDecodeObjectEx(pCertContext
->dwCertEncodingType
,
2607 X509_ENHANCED_KEY_USAGE
, buf
, propSize
,
2608 CRYPT_ENCODE_ALLOC_FLAG
, NULL
, &usage
, &bytesNeeded
);
2614 if (!usage
&& !(dwFlags
& CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
))
2616 PCERT_EXTENSION ext
= CertFindExtension(szOID_ENHANCED_KEY_USAGE
,
2617 pCertContext
->pCertInfo
->cExtension
,
2618 pCertContext
->pCertInfo
->rgExtension
);
2622 ret
= CryptDecodeObjectEx(pCertContext
->dwCertEncodingType
,
2623 X509_ENHANCED_KEY_USAGE
, ext
->Value
.pbData
, ext
->Value
.cbData
,
2624 CRYPT_ENCODE_ALLOC_FLAG
, NULL
, &usage
, &bytesNeeded
);
2629 /* If a particular location is specified, this should fail. Otherwise
2630 * it should succeed with an empty usage. (This is true on Win2k and
2631 * later, which we emulate.)
2635 SetLastError(CRYPT_E_NOT_FOUND
);
2639 bytesNeeded
= sizeof(CERT_ENHKEY_USAGE
);
2645 *pcbUsage
= bytesNeeded
;
2646 else if (*pcbUsage
< bytesNeeded
)
2648 SetLastError(ERROR_MORE_DATA
);
2649 *pcbUsage
= bytesNeeded
;
2654 *pcbUsage
= bytesNeeded
;
2658 LPSTR nextOID
= (LPSTR
)((LPBYTE
)pUsage
+
2659 sizeof(CERT_ENHKEY_USAGE
) +
2660 usage
->cUsageIdentifier
* sizeof(LPSTR
));
2662 pUsage
->cUsageIdentifier
= usage
->cUsageIdentifier
;
2663 pUsage
->rgpszUsageIdentifier
= (LPSTR
*)((LPBYTE
)pUsage
+
2664 sizeof(CERT_ENHKEY_USAGE
));
2665 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
2667 pUsage
->rgpszUsageIdentifier
[i
] = nextOID
;
2668 strcpy(nextOID
, usage
->rgpszUsageIdentifier
[i
]);
2669 nextOID
+= strlen(nextOID
) + 1;
2673 pUsage
->cUsageIdentifier
= 0;
2678 TRACE("returning %d\n", ret
);
2682 BOOL WINAPI
CertSetEnhancedKeyUsage(PCCERT_CONTEXT pCertContext
,
2683 PCERT_ENHKEY_USAGE pUsage
)
2687 TRACE("(%p, %p)\n", pCertContext
, pUsage
);
2691 CRYPT_DATA_BLOB blob
= { 0, NULL
};
2693 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
, X509_ENHANCED_KEY_USAGE
,
2694 pUsage
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
, &blob
.pbData
, &blob
.cbData
);
2697 ret
= CertSetCertificateContextProperty(pCertContext
,
2698 CERT_ENHKEY_USAGE_PROP_ID
, 0, &blob
);
2699 LocalFree(blob
.pbData
);
2703 ret
= CertSetCertificateContextProperty(pCertContext
,
2704 CERT_ENHKEY_USAGE_PROP_ID
, 0, NULL
);
2708 BOOL WINAPI
CertAddEnhancedKeyUsageIdentifier(PCCERT_CONTEXT pCertContext
,
2709 LPCSTR pszUsageIdentifier
)
2714 TRACE("(%p, %s)\n", pCertContext
, debugstr_a(pszUsageIdentifier
));
2716 if (CertGetEnhancedKeyUsage(pCertContext
,
2717 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, NULL
, &size
))
2719 PCERT_ENHKEY_USAGE usage
= CryptMemAlloc(size
);
2723 ret
= CertGetEnhancedKeyUsage(pCertContext
,
2724 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, usage
, &size
);
2728 BOOL exists
= FALSE
;
2730 /* Make sure usage doesn't already exist */
2731 for (i
= 0; !exists
&& i
< usage
->cUsageIdentifier
; i
++)
2733 if (!strcmp(usage
->rgpszUsageIdentifier
[i
],
2734 pszUsageIdentifier
))
2739 PCERT_ENHKEY_USAGE newUsage
= CryptMemAlloc(size
+
2740 sizeof(LPSTR
) + strlen(pszUsageIdentifier
) + 1);
2746 newUsage
->rgpszUsageIdentifier
= (LPSTR
*)
2747 ((LPBYTE
)newUsage
+ sizeof(CERT_ENHKEY_USAGE
));
2748 nextOID
= (LPSTR
)((LPBYTE
)newUsage
->rgpszUsageIdentifier
2749 + (usage
->cUsageIdentifier
+ 1) * sizeof(LPSTR
));
2750 for (i
= 0; i
< usage
->cUsageIdentifier
; i
++)
2752 newUsage
->rgpszUsageIdentifier
[i
] = nextOID
;
2753 strcpy(nextOID
, usage
->rgpszUsageIdentifier
[i
]);
2754 nextOID
+= strlen(nextOID
) + 1;
2756 newUsage
->rgpszUsageIdentifier
[i
] = nextOID
;
2757 strcpy(nextOID
, pszUsageIdentifier
);
2758 newUsage
->cUsageIdentifier
= i
+ 1;
2759 ret
= CertSetEnhancedKeyUsage(pCertContext
, newUsage
);
2760 CryptMemFree(newUsage
);
2766 CryptMemFree(usage
);
2773 PCERT_ENHKEY_USAGE usage
= CryptMemAlloc(sizeof(CERT_ENHKEY_USAGE
) +
2774 sizeof(LPSTR
) + strlen(pszUsageIdentifier
) + 1);
2778 usage
->rgpszUsageIdentifier
=
2779 (LPSTR
*)((LPBYTE
)usage
+ sizeof(CERT_ENHKEY_USAGE
));
2780 usage
->rgpszUsageIdentifier
[0] = (LPSTR
)((LPBYTE
)usage
+
2781 sizeof(CERT_ENHKEY_USAGE
) + sizeof(LPSTR
));
2782 strcpy(usage
->rgpszUsageIdentifier
[0], pszUsageIdentifier
);
2783 usage
->cUsageIdentifier
= 1;
2784 ret
= CertSetEnhancedKeyUsage(pCertContext
, usage
);
2785 CryptMemFree(usage
);
2793 BOOL WINAPI
CertRemoveEnhancedKeyUsageIdentifier(PCCERT_CONTEXT pCertContext
,
2794 LPCSTR pszUsageIdentifier
)
2798 CERT_ENHKEY_USAGE usage
;
2800 TRACE("(%p, %s)\n", pCertContext
, debugstr_a(pszUsageIdentifier
));
2802 size
= sizeof(usage
);
2803 ret
= CertGetEnhancedKeyUsage(pCertContext
,
2804 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, &usage
, &size
);
2805 if (!ret
&& GetLastError() == ERROR_MORE_DATA
)
2807 PCERT_ENHKEY_USAGE pUsage
= CryptMemAlloc(size
);
2811 ret
= CertGetEnhancedKeyUsage(pCertContext
,
2812 CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
, pUsage
, &size
);
2815 if (pUsage
->cUsageIdentifier
)
2820 for (i
= 0; i
< pUsage
->cUsageIdentifier
; i
++)
2822 if (!strcmp(pUsage
->rgpszUsageIdentifier
[i
],
2823 pszUsageIdentifier
))
2825 if (found
&& i
< pUsage
->cUsageIdentifier
- 1)
2826 pUsage
->rgpszUsageIdentifier
[i
] =
2827 pUsage
->rgpszUsageIdentifier
[i
+ 1];
2829 pUsage
->cUsageIdentifier
--;
2830 /* Remove the usage if it's empty */
2831 if (pUsage
->cUsageIdentifier
)
2832 ret
= CertSetEnhancedKeyUsage(pCertContext
, pUsage
);
2834 ret
= CertSetEnhancedKeyUsage(pCertContext
, NULL
);
2837 CryptMemFree(pUsage
);
2844 /* it fit in an empty usage, therefore there's nothing to remove */
2856 #define BITS_PER_DWORD (sizeof(DWORD) * 8)
2858 static void CRYPT_SetBitInField(struct BitField
*field
, DWORD bit
)
2860 DWORD indexIndex
= bit
/ BITS_PER_DWORD
;
2862 if (indexIndex
+ 1 > field
->cIndexes
)
2864 if (field
->cIndexes
)
2865 field
->indexes
= CryptMemRealloc(field
->indexes
,
2866 (indexIndex
+ 1) * sizeof(DWORD
));
2868 field
->indexes
= CryptMemAlloc(sizeof(DWORD
));
2871 field
->indexes
[indexIndex
] = 0;
2872 field
->cIndexes
= indexIndex
+ 1;
2876 field
->indexes
[indexIndex
] |= 1 << (bit
% BITS_PER_DWORD
);
2879 static BOOL
CRYPT_IsBitInFieldSet(const struct BitField
*field
, DWORD bit
)
2882 DWORD indexIndex
= bit
/ BITS_PER_DWORD
;
2884 assert(field
->cIndexes
);
2885 set
= field
->indexes
[indexIndex
] & (1 << (bit
% BITS_PER_DWORD
));
2889 BOOL WINAPI
CertGetValidUsages(DWORD cCerts
, PCCERT_CONTEXT
*rghCerts
,
2890 int *cNumOIDs
, LPSTR
*rghOIDs
, DWORD
*pcbOIDs
)
2893 DWORD i
, cbOIDs
= 0;
2894 BOOL allUsagesValid
= TRUE
;
2895 CERT_ENHKEY_USAGE validUsages
= { 0, NULL
};
2897 TRACE("(%d, %p, %d, %p, %d)\n", cCerts
, rghCerts
, *cNumOIDs
,
2900 for (i
= 0; i
< cCerts
; i
++)
2902 CERT_ENHKEY_USAGE usage
;
2903 DWORD size
= sizeof(usage
);
2905 ret
= CertGetEnhancedKeyUsage(rghCerts
[i
], 0, &usage
, &size
);
2906 /* Success is deliberately ignored: it implies all usages are valid */
2907 if (!ret
&& GetLastError() == ERROR_MORE_DATA
)
2909 PCERT_ENHKEY_USAGE pUsage
= CryptMemAlloc(size
);
2911 allUsagesValid
= FALSE
;
2914 ret
= CertGetEnhancedKeyUsage(rghCerts
[i
], 0, pUsage
, &size
);
2917 if (!validUsages
.cUsageIdentifier
)
2921 cbOIDs
= pUsage
->cUsageIdentifier
* sizeof(LPSTR
);
2922 validUsages
.cUsageIdentifier
= pUsage
->cUsageIdentifier
;
2923 for (j
= 0; j
< validUsages
.cUsageIdentifier
; j
++)
2924 cbOIDs
+= lstrlenA(pUsage
->rgpszUsageIdentifier
[j
])
2926 validUsages
.rgpszUsageIdentifier
=
2927 CryptMemAlloc(cbOIDs
);
2928 if (validUsages
.rgpszUsageIdentifier
)
2930 LPSTR nextOID
= (LPSTR
)
2931 ((LPBYTE
)validUsages
.rgpszUsageIdentifier
+
2932 validUsages
.cUsageIdentifier
* sizeof(LPSTR
));
2934 for (j
= 0; j
< validUsages
.cUsageIdentifier
; j
++)
2936 validUsages
.rgpszUsageIdentifier
[j
] = nextOID
;
2937 lstrcpyA(validUsages
.rgpszUsageIdentifier
[j
],
2938 pUsage
->rgpszUsageIdentifier
[j
]);
2939 nextOID
+= lstrlenA(nextOID
) + 1;
2945 struct BitField validIndexes
= { 0, NULL
};
2946 DWORD j
, k
, numRemoved
= 0;
2948 /* Merge: build a bitmap of all the indexes of
2949 * validUsages.rgpszUsageIdentifier that are in pUsage.
2951 for (j
= 0; j
< pUsage
->cUsageIdentifier
; j
++)
2953 for (k
= 0; k
< validUsages
.cUsageIdentifier
; k
++)
2955 if (!strcmp(pUsage
->rgpszUsageIdentifier
[j
],
2956 validUsages
.rgpszUsageIdentifier
[k
]))
2958 CRYPT_SetBitInField(&validIndexes
, k
);
2963 /* Merge by removing from validUsages those that are
2964 * not in the bitmap.
2966 for (j
= 0; j
< validUsages
.cUsageIdentifier
; j
++)
2968 if (!CRYPT_IsBitInFieldSet(&validIndexes
, j
))
2970 if (j
< validUsages
.cUsageIdentifier
- 1)
2972 memmove(&validUsages
.rgpszUsageIdentifier
[j
],
2973 &validUsages
.rgpszUsageIdentifier
[j
+
2975 (validUsages
.cUsageIdentifier
- numRemoved
2976 - j
- 1) * sizeof(LPSTR
));
2978 validUsages
.rgpszUsageIdentifier
[j
]) + 1 +
2980 validUsages
.cUsageIdentifier
--;
2984 validUsages
.cUsageIdentifier
--;
2987 CryptMemFree(validIndexes
.indexes
);
2990 CryptMemFree(pUsage
);
3002 *cNumOIDs
= validUsages
.cUsageIdentifier
;
3005 else if (*pcbOIDs
< cbOIDs
)
3008 SetLastError(ERROR_MORE_DATA
);
3013 LPSTR nextOID
= (LPSTR
)((LPBYTE
)rghOIDs
+
3014 validUsages
.cUsageIdentifier
* sizeof(LPSTR
));
3017 for (i
= 0; i
< validUsages
.cUsageIdentifier
; i
++)
3019 rghOIDs
[i
] = nextOID
;
3020 lstrcpyA(nextOID
, validUsages
.rgpszUsageIdentifier
[i
]);
3021 nextOID
+= lstrlenA(nextOID
) + 1;
3025 CryptMemFree(validUsages
.rgpszUsageIdentifier
);
3026 TRACE("cNumOIDs: %d\n", *cNumOIDs
);
3027 TRACE("returning %d\n", ret
);
3031 /* Sets the CERT_KEY_PROV_INFO_PROP_ID property of context from pInfo, or, if
3032 * pInfo is NULL, from the attributes of hProv.
3034 static void CertContext_SetKeyProvInfo(PCCERT_CONTEXT context
,
3035 const CRYPT_KEY_PROV_INFO
*pInfo
, HCRYPTPROV hProv
)
3037 CRYPT_KEY_PROV_INFO info
= { 0 };
3045 ret
= CryptGetProvParam(hProv
, PP_CONTAINER
, NULL
, &size
, 0);
3048 LPSTR szContainer
= CryptMemAlloc(size
);
3052 ret
= CryptGetProvParam(hProv
, PP_CONTAINER
,
3053 (BYTE
*)szContainer
, &size
, 0);
3056 len
= MultiByteToWideChar(CP_ACP
, 0, szContainer
, -1,
3060 info
.pwszContainerName
= CryptMemAlloc(len
*
3062 MultiByteToWideChar(CP_ACP
, 0, szContainer
, -1,
3063 info
.pwszContainerName
, len
);
3066 CryptMemFree(szContainer
);
3069 ret
= CryptGetProvParam(hProv
, PP_NAME
, NULL
, &size
, 0);
3072 LPSTR szProvider
= CryptMemAlloc(size
);
3076 ret
= CryptGetProvParam(hProv
, PP_NAME
, (BYTE
*)szProvider
,
3080 len
= MultiByteToWideChar(CP_ACP
, 0, szProvider
, -1,
3084 info
.pwszProvName
= CryptMemAlloc(len
*
3086 MultiByteToWideChar(CP_ACP
, 0, szProvider
, -1,
3087 info
.pwszProvName
, len
);
3090 CryptMemFree(szProvider
);
3093 size
= sizeof(info
.dwKeySpec
);
3094 /* in case no CRYPT_KEY_PROV_INFO given,
3095 * we always use AT_SIGNATURE key spec
3097 info
.dwKeySpec
= AT_SIGNATURE
;
3098 size
= sizeof(info
.dwProvType
);
3099 ret
= CryptGetProvParam(hProv
, PP_PROVTYPE
, (LPBYTE
)&info
.dwProvType
,
3102 info
.dwProvType
= PROV_RSA_FULL
;
3106 CertSetCertificateContextProperty(context
, CERT_KEY_PROV_INFO_PROP_ID
,
3111 CryptMemFree(info
.pwszContainerName
);
3112 CryptMemFree(info
.pwszProvName
);
3116 /* Creates a signed certificate context from the unsigned, encoded certificate
3117 * in blob, using the crypto provider hProv and the signature algorithm sigAlgo.
3119 static PCCERT_CONTEXT
CRYPT_CreateSignedCert(const CRYPT_DER_BLOB
*blob
,
3120 HCRYPTPROV hProv
, DWORD dwKeySpec
, PCRYPT_ALGORITHM_IDENTIFIER sigAlgo
)
3122 PCCERT_CONTEXT context
= NULL
;
3126 ret
= CryptSignCertificate(hProv
, dwKeySpec
, X509_ASN_ENCODING
,
3127 blob
->pbData
, blob
->cbData
, sigAlgo
, NULL
, NULL
, &sigSize
);
3130 LPBYTE sig
= CryptMemAlloc(sigSize
);
3132 ret
= CryptSignCertificate(hProv
, dwKeySpec
, X509_ASN_ENCODING
,
3133 blob
->pbData
, blob
->cbData
, sigAlgo
, NULL
, sig
, &sigSize
);
3136 CERT_SIGNED_CONTENT_INFO signedInfo
;
3137 BYTE
*encodedSignedCert
= NULL
;
3138 DWORD encodedSignedCertSize
= 0;
3140 signedInfo
.ToBeSigned
.cbData
= blob
->cbData
;
3141 signedInfo
.ToBeSigned
.pbData
= blob
->pbData
;
3142 signedInfo
.SignatureAlgorithm
= *sigAlgo
;
3143 signedInfo
.Signature
.cbData
= sigSize
;
3144 signedInfo
.Signature
.pbData
= sig
;
3145 signedInfo
.Signature
.cUnusedBits
= 0;
3146 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
, X509_CERT
,
3147 &signedInfo
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
,
3148 &encodedSignedCert
, &encodedSignedCertSize
);
3151 context
= CertCreateCertificateContext(X509_ASN_ENCODING
,
3152 encodedSignedCert
, encodedSignedCertSize
);
3153 LocalFree(encodedSignedCert
);
3161 /* Copies data from the parameters into info, where:
3162 * pSerialNumber: The serial number. Must not be NULL.
3163 * pSubjectIssuerBlob: Specifies both the subject and issuer for info.
3165 * pSignatureAlgorithm: Optional.
3166 * pStartTime: The starting time of the certificate. If NULL, the current
3167 * system time is used.
3168 * pEndTime: The ending time of the certificate. If NULL, one year past the
3169 * starting time is used.
3170 * pubKey: The public key of the certificate. Must not be NULL.
3171 * pExtensions: Extensions to be included with the certificate. Optional.
3173 static void CRYPT_MakeCertInfo(PCERT_INFO info
, const CRYPT_DATA_BLOB
*pSerialNumber
,
3174 const CERT_NAME_BLOB
*pSubjectIssuerBlob
,
3175 const CRYPT_ALGORITHM_IDENTIFIER
*pSignatureAlgorithm
, const SYSTEMTIME
*pStartTime
,
3176 const SYSTEMTIME
*pEndTime
, const CERT_PUBLIC_KEY_INFO
*pubKey
,
3177 const CERT_EXTENSIONS
*pExtensions
)
3179 static CHAR oid
[] = szOID_RSA_SHA1RSA
;
3182 assert(pSerialNumber
);
3183 assert(pSubjectIssuerBlob
);
3186 if (pExtensions
&& pExtensions
->cExtension
)
3187 info
->dwVersion
= CERT_V3
;
3189 info
->dwVersion
= CERT_V1
;
3190 info
->SerialNumber
.cbData
= pSerialNumber
->cbData
;
3191 info
->SerialNumber
.pbData
= pSerialNumber
->pbData
;
3192 if (pSignatureAlgorithm
)
3193 info
->SignatureAlgorithm
= *pSignatureAlgorithm
;
3196 info
->SignatureAlgorithm
.pszObjId
= oid
;
3197 info
->SignatureAlgorithm
.Parameters
.cbData
= 0;
3198 info
->SignatureAlgorithm
.Parameters
.pbData
= NULL
;
3200 info
->Issuer
.cbData
= pSubjectIssuerBlob
->cbData
;
3201 info
->Issuer
.pbData
= pSubjectIssuerBlob
->pbData
;
3203 SystemTimeToFileTime(pStartTime
, &info
->NotBefore
);
3205 GetSystemTimeAsFileTime(&info
->NotBefore
);
3207 SystemTimeToFileTime(pEndTime
, &info
->NotAfter
);
3212 if (FileTimeToSystemTime(&info
->NotBefore
, &endTime
))
3215 SystemTimeToFileTime(&endTime
, &info
->NotAfter
);
3218 info
->Subject
.cbData
= pSubjectIssuerBlob
->cbData
;
3219 info
->Subject
.pbData
= pSubjectIssuerBlob
->pbData
;
3220 info
->SubjectPublicKeyInfo
= *pubKey
;
3223 info
->cExtension
= pExtensions
->cExtension
;
3224 info
->rgExtension
= pExtensions
->rgExtension
;
3228 info
->cExtension
= 0;
3229 info
->rgExtension
= NULL
;
3233 typedef RPC_STATUS (RPC_ENTRY
*UuidCreateFunc
)(UUID
*);
3234 typedef RPC_STATUS (RPC_ENTRY
*UuidToStringFunc
)(UUID
*, unsigned char **);
3235 typedef RPC_STATUS (RPC_ENTRY
*RpcStringFreeFunc
)(unsigned char **);
3237 static HCRYPTPROV
CRYPT_CreateKeyProv(void)
3239 HCRYPTPROV hProv
= 0;
3240 HMODULE rpcrt
= LoadLibraryA("rpcrt4");
3244 UuidCreateFunc uuidCreate
= (UuidCreateFunc
)GetProcAddress(rpcrt
,
3246 UuidToStringFunc uuidToString
= (UuidToStringFunc
)GetProcAddress(rpcrt
,
3248 RpcStringFreeFunc rpcStringFree
= (RpcStringFreeFunc
)GetProcAddress(
3249 rpcrt
, "RpcStringFreeA");
3251 if (uuidCreate
&& uuidToString
&& rpcStringFree
)
3254 RPC_STATUS status
= uuidCreate(&uuid
);
3256 if (status
== RPC_S_OK
|| status
== RPC_S_UUID_LOCAL_ONLY
)
3258 unsigned char *uuidStr
;
3260 status
= uuidToString(&uuid
, &uuidStr
);
3261 if (status
== RPC_S_OK
)
3263 BOOL ret
= CryptAcquireContextA(&hProv
, (LPCSTR
)uuidStr
,
3264 MS_DEF_PROV_A
, PROV_RSA_FULL
, CRYPT_NEWKEYSET
);
3270 ret
= CryptGenKey(hProv
, AT_SIGNATURE
, 0, &key
);
3272 CryptDestroyKey(key
);
3274 rpcStringFree(&uuidStr
);
3283 PCCERT_CONTEXT WINAPI
CertCreateSelfSignCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hProv
,
3284 PCERT_NAME_BLOB pSubjectIssuerBlob
, DWORD dwFlags
,
3285 PCRYPT_KEY_PROV_INFO pKeyProvInfo
,
3286 PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm
, PSYSTEMTIME pStartTime
,
3287 PSYSTEMTIME pEndTime
, PCERT_EXTENSIONS pExtensions
)
3289 PCCERT_CONTEXT context
= NULL
;
3290 BOOL ret
, releaseContext
= FALSE
;
3291 PCERT_PUBLIC_KEY_INFO pubKey
= NULL
;
3292 DWORD pubKeySize
= 0, dwKeySpec
;
3294 TRACE("(%08lx, %p, %08x, %p, %p, %p, %p, %p)\n", hProv
,
3295 pSubjectIssuerBlob
, dwFlags
, pKeyProvInfo
, pSignatureAlgorithm
, pStartTime
,
3296 pExtensions
, pExtensions
);
3298 if(!pSubjectIssuerBlob
)
3300 SetLastError(ERROR_INVALID_PARAMETER
);
3304 dwKeySpec
= pKeyProvInfo
? pKeyProvInfo
->dwKeySpec
: AT_SIGNATURE
;
3309 hProv
= CRYPT_CreateKeyProv();
3310 releaseContext
= TRUE
;
3312 else if (pKeyProvInfo
->dwFlags
& CERT_SET_KEY_PROV_HANDLE_PROP_ID
)
3314 SetLastError(NTE_BAD_FLAGS
);
3320 /* acquire the context using the given information*/
3321 ret
= CryptAcquireContextW(&hProv
,pKeyProvInfo
->pwszContainerName
,
3322 pKeyProvInfo
->pwszProvName
,pKeyProvInfo
->dwProvType
,
3323 pKeyProvInfo
->dwFlags
);
3326 if(GetLastError() != NTE_BAD_KEYSET
)
3328 /* create the key set */
3329 ret
= CryptAcquireContextW(&hProv
,pKeyProvInfo
->pwszContainerName
,
3330 pKeyProvInfo
->pwszProvName
,pKeyProvInfo
->dwProvType
,
3331 pKeyProvInfo
->dwFlags
|CRYPT_NEWKEYSET
);
3335 /* check if the key is here */
3336 ret
= CryptGetUserKey(hProv
,dwKeySpec
,&hKey
);
3339 if (NTE_NO_KEY
== GetLastError())
3340 { /* generate the key */
3341 ret
= CryptGenKey(hProv
,dwKeySpec
,0,&hKey
);
3345 CryptReleaseContext(hProv
,0);
3346 SetLastError(NTE_BAD_KEYSET
);
3350 CryptDestroyKey(hKey
);
3351 releaseContext
= TRUE
;
3355 ret
= CryptExportPublicKeyInfo(hProv
, dwKeySpec
, X509_ASN_ENCODING
, NULL
,
3359 pubKey
= CryptMemAlloc(pubKeySize
);
3362 ret
= CryptExportPublicKeyInfo(hProv
, dwKeySpec
, X509_ASN_ENCODING
,
3363 pubKey
, &pubKeySize
);
3366 CERT_INFO info
= { 0 };
3367 CRYPT_DER_BLOB blob
= { 0, NULL
};
3369 CRYPT_DATA_BLOB serialBlob
= { sizeof(serial
), serial
};
3371 CryptGenRandom(hProv
, sizeof(serial
), serial
);
3372 CRYPT_MakeCertInfo(&info
, &serialBlob
, pSubjectIssuerBlob
,
3373 pSignatureAlgorithm
, pStartTime
, pEndTime
, pubKey
, pExtensions
);
3374 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
, X509_CERT_TO_BE_SIGNED
,
3375 &info
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
, &blob
.pbData
,
3379 if (!(dwFlags
& CERT_CREATE_SELFSIGN_NO_SIGN
))
3380 context
= CRYPT_CreateSignedCert(&blob
, hProv
,dwKeySpec
,
3381 &info
.SignatureAlgorithm
);
3383 context
= CertCreateCertificateContext(X509_ASN_ENCODING
,
3384 blob
.pbData
, blob
.cbData
);
3385 if (context
&& !(dwFlags
& CERT_CREATE_SELFSIGN_NO_KEY_INFO
))
3386 CertContext_SetKeyProvInfo(context
, pKeyProvInfo
, hProv
);
3387 LocalFree(blob
.pbData
);
3390 CryptMemFree(pubKey
);
3394 CryptReleaseContext(hProv
, 0);
3398 BOOL WINAPI
CertVerifyCTLUsage(DWORD dwEncodingType
, DWORD dwSubjectType
,
3399 void *pvSubject
, PCTL_USAGE pSubjectUsage
, DWORD dwFlags
,
3400 PCTL_VERIFY_USAGE_PARA pVerifyUsagePara
,
3401 PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
)
3403 FIXME("(0x%x, %d, %p, %p, 0x%x, %p, %p): stub\n", dwEncodingType
,
3404 dwSubjectType
, pvSubject
, pSubjectUsage
, dwFlags
, pVerifyUsagePara
,
3405 pVerifyUsageStatus
);
3406 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3410 const void * WINAPI
CertCreateContext(DWORD dwContextType
, DWORD dwEncodingType
,
3411 const BYTE
*pbEncoded
, DWORD cbEncoded
,
3412 DWORD dwFlags
, PCERT_CREATE_CONTEXT_PARA pCreatePara
)
3414 TRACE("(0x%x, 0x%x, %p, %d, 0x%08x, %p)\n", dwContextType
, dwEncodingType
,
3415 pbEncoded
, cbEncoded
, dwFlags
, pCreatePara
);
3419 FIXME("dwFlags 0x%08x not handled\n", dwFlags
);
3424 FIXME("pCreatePara not handled\n");
3428 switch (dwContextType
)
3430 case CERT_STORE_CERTIFICATE_CONTEXT
:
3431 return CertCreateCertificateContext(dwEncodingType
, pbEncoded
, cbEncoded
);
3432 case CERT_STORE_CRL_CONTEXT
:
3433 return CertCreateCRLContext(dwEncodingType
, pbEncoded
, cbEncoded
);
3434 case CERT_STORE_CTL_CONTEXT
:
3435 return CertCreateCTLContext(dwEncodingType
, pbEncoded
, cbEncoded
);
3437 WARN("unknown context type: 0x%x\n", dwContextType
);