dxgi: Implement IDXGIFactory::GetParent().
[wine/testsucceed.git] / dlls / crypt32 / crl.c
bloba24e6adf8873a0a858d3dd320b8d64de8ea70da3
1 /*
2 * Copyright 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 <assert.h>
21 #include <stdarg.h>
22 #define NONAMELESSUNION
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wincrypt.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
28 #include "crypt32_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
32 PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType,
33 const BYTE* pbCrlEncoded, DWORD cbCrlEncoded)
35 PCRL_CONTEXT crl = NULL;
36 BOOL ret;
37 PCRL_INFO crlInfo = NULL;
38 DWORD size = 0;
40 TRACE("(%08x, %p, %d)\n", dwCertEncodingType, pbCrlEncoded,
41 cbCrlEncoded);
43 if ((dwCertEncodingType & CERT_ENCODING_TYPE_MASK) != X509_ASN_ENCODING)
45 SetLastError(E_INVALIDARG);
46 return NULL;
48 ret = CryptDecodeObjectEx(dwCertEncodingType, X509_CERT_CRL_TO_BE_SIGNED,
49 pbCrlEncoded, cbCrlEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL,
50 &crlInfo, &size);
51 if (ret)
53 BYTE *data = NULL;
55 crl = Context_CreateDataContext(sizeof(CRL_CONTEXT));
56 if (!crl)
57 goto end;
58 data = CryptMemAlloc(cbCrlEncoded);
59 if (!data)
61 CryptMemFree(crl);
62 crl = NULL;
63 goto end;
65 memcpy(data, pbCrlEncoded, cbCrlEncoded);
66 crl->dwCertEncodingType = dwCertEncodingType;
67 crl->pbCrlEncoded = data;
68 crl->cbCrlEncoded = cbCrlEncoded;
69 crl->pCrlInfo = crlInfo;
70 crl->hCertStore = 0;
73 end:
74 return crl;
77 BOOL WINAPI CertAddEncodedCRLToStore(HCERTSTORE hCertStore,
78 DWORD dwCertEncodingType, const BYTE *pbCrlEncoded, DWORD cbCrlEncoded,
79 DWORD dwAddDisposition, PCCRL_CONTEXT *ppCrlContext)
81 PCCRL_CONTEXT crl = CertCreateCRLContext(dwCertEncodingType,
82 pbCrlEncoded, cbCrlEncoded);
83 BOOL ret;
85 TRACE("(%p, %08x, %p, %d, %08x, %p)\n", hCertStore, dwCertEncodingType,
86 pbCrlEncoded, cbCrlEncoded, dwAddDisposition, ppCrlContext);
88 if (crl)
90 ret = CertAddCRLContextToStore(hCertStore, crl, dwAddDisposition,
91 ppCrlContext);
92 CertFreeCRLContext(crl);
94 else
95 ret = FALSE;
96 return ret;
99 typedef BOOL (*CrlCompareFunc)(PCCRL_CONTEXT pCrlContext, DWORD dwType,
100 DWORD dwFlags, const void *pvPara);
102 static BOOL compare_crl_any(PCCRL_CONTEXT pCrlContext, DWORD dwType,
103 DWORD dwFlags, const void *pvPara)
105 return TRUE;
108 static BOOL compare_crl_issued_by(PCCRL_CONTEXT pCrlContext, DWORD dwType,
109 DWORD dwFlags, const void *pvPara)
111 BOOL ret;
113 if (pvPara)
115 PCCERT_CONTEXT issuer = pvPara;
117 ret = CertCompareCertificateName(issuer->dwCertEncodingType,
118 &issuer->pCertInfo->Subject, &pCrlContext->pCrlInfo->Issuer);
119 if (ret && (dwFlags & CRL_FIND_ISSUED_BY_SIGNATURE_FLAG))
120 ret = CryptVerifyCertificateSignatureEx(0,
121 issuer->dwCertEncodingType,
122 CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL, (void *)pCrlContext,
123 CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT, (void *)issuer, 0, NULL);
124 if (ret && (dwFlags & CRL_FIND_ISSUED_BY_AKI_FLAG))
126 PCERT_EXTENSION ext = CertFindExtension(
127 szOID_AUTHORITY_KEY_IDENTIFIER2, pCrlContext->pCrlInfo->cExtension,
128 pCrlContext->pCrlInfo->rgExtension);
130 if (ext)
132 CERT_AUTHORITY_KEY_ID2_INFO *info;
133 DWORD size;
135 if ((ret = CryptDecodeObjectEx(X509_ASN_ENCODING,
136 X509_AUTHORITY_KEY_ID2, ext->Value.pbData, ext->Value.cbData,
137 CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &size)))
139 if (info->AuthorityCertIssuer.cAltEntry &&
140 info->AuthorityCertSerialNumber.cbData)
142 PCERT_ALT_NAME_ENTRY directoryName = NULL;
143 DWORD i;
145 for (i = 0; !directoryName &&
146 i < info->AuthorityCertIssuer.cAltEntry; i++)
147 if (info->AuthorityCertIssuer.rgAltEntry[i].
148 dwAltNameChoice == CERT_ALT_NAME_DIRECTORY_NAME)
149 directoryName =
150 &info->AuthorityCertIssuer.rgAltEntry[i];
151 if (directoryName)
153 ret = CertCompareCertificateName(
154 issuer->dwCertEncodingType,
155 &issuer->pCertInfo->Subject,
156 &directoryName->u.DirectoryName);
157 if (ret)
158 ret = CertCompareIntegerBlob(
159 &issuer->pCertInfo->SerialNumber,
160 &info->AuthorityCertSerialNumber);
162 else
164 FIXME("no supported name type in authority key id2\n");
165 ret = FALSE;
168 else if (info->KeyId.cbData)
170 if ((ext = CertFindExtension(
171 szOID_SUBJECT_KEY_IDENTIFIER,
172 issuer->pCertInfo->cExtension,
173 issuer->pCertInfo->rgExtension)))
175 if (info->KeyId.cbData == ext->Value.cbData)
176 ret = !memcmp(info->KeyId.pbData,
177 ext->Value.pbData, info->KeyId.cbData);
178 else
179 ret = FALSE;
181 else
182 ret = FALSE;
184 else
186 FIXME("unsupported value for AKI extension\n");
187 ret = FALSE;
189 LocalFree(info);
192 /* else: a CRL without an AKI matches any cert */
195 else
196 ret = TRUE;
197 return ret;
200 static BOOL compare_crl_existing(PCCRL_CONTEXT pCrlContext, DWORD dwType,
201 DWORD dwFlags, const void *pvPara)
203 BOOL ret;
205 if (pvPara)
207 PCCRL_CONTEXT crl = pvPara;
209 ret = CertCompareCertificateName(pCrlContext->dwCertEncodingType,
210 &pCrlContext->pCrlInfo->Issuer, &crl->pCrlInfo->Issuer);
212 else
213 ret = TRUE;
214 return ret;
217 static BOOL compare_crl_issued_for(PCCRL_CONTEXT pCrlContext, DWORD dwType,
218 DWORD dwFlags, const void *pvPara)
220 const CRL_FIND_ISSUED_FOR_PARA *para = pvPara;
221 BOOL ret;
223 ret = CertCompareCertificateName(para->pIssuerCert->dwCertEncodingType,
224 &para->pIssuerCert->pCertInfo->Issuer, &pCrlContext->pCrlInfo->Issuer);
225 return ret;
228 PCCRL_CONTEXT WINAPI CertFindCRLInStore(HCERTSTORE hCertStore,
229 DWORD dwCertEncodingType, DWORD dwFindFlags, DWORD dwFindType,
230 const void *pvFindPara, PCCRL_CONTEXT pPrevCrlContext)
232 PCCRL_CONTEXT ret;
233 CrlCompareFunc compare;
235 TRACE("(%p, %d, %d, %d, %p, %p)\n", hCertStore, dwCertEncodingType,
236 dwFindFlags, dwFindType, pvFindPara, pPrevCrlContext);
238 switch (dwFindType)
240 case CRL_FIND_ANY:
241 compare = compare_crl_any;
242 break;
243 case CRL_FIND_ISSUED_BY:
244 compare = compare_crl_issued_by;
245 break;
246 case CRL_FIND_EXISTING:
247 compare = compare_crl_existing;
248 break;
249 case CRL_FIND_ISSUED_FOR:
250 compare = compare_crl_issued_for;
251 break;
252 default:
253 FIXME("find type %08x unimplemented\n", dwFindType);
254 compare = NULL;
257 if (compare)
259 BOOL matches = FALSE;
261 ret = pPrevCrlContext;
262 do {
263 ret = CertEnumCRLsInStore(hCertStore, ret);
264 if (ret)
265 matches = compare(ret, dwFindType, dwFindFlags, pvFindPara);
266 } while (ret != NULL && !matches);
267 if (!ret)
268 SetLastError(CRYPT_E_NOT_FOUND);
270 else
272 SetLastError(CRYPT_E_NOT_FOUND);
273 ret = NULL;
275 return ret;
278 PCCRL_CONTEXT WINAPI CertGetCRLFromStore(HCERTSTORE hCertStore,
279 PCCERT_CONTEXT pIssuerContext, PCCRL_CONTEXT pPrevCrlContext, DWORD *pdwFlags)
281 static const DWORD supportedFlags = CERT_STORE_SIGNATURE_FLAG |
282 CERT_STORE_TIME_VALIDITY_FLAG | CERT_STORE_BASE_CRL_FLAG |
283 CERT_STORE_DELTA_CRL_FLAG;
284 PCCRL_CONTEXT ret;
286 TRACE("(%p, %p, %p, %08x)\n", hCertStore, pIssuerContext, pPrevCrlContext,
287 *pdwFlags);
289 if (*pdwFlags & ~supportedFlags)
291 SetLastError(E_INVALIDARG);
292 return NULL;
294 if (pIssuerContext)
295 ret = CertFindCRLInStore(hCertStore, pIssuerContext->dwCertEncodingType,
296 0, CRL_FIND_ISSUED_BY, pIssuerContext, pPrevCrlContext);
297 else
298 ret = CertFindCRLInStore(hCertStore, 0, 0, CRL_FIND_ANY, NULL,
299 pPrevCrlContext);
300 if (ret)
302 if (*pdwFlags & CERT_STORE_TIME_VALIDITY_FLAG)
304 if (0 == CertVerifyCRLTimeValidity(NULL, ret->pCrlInfo))
305 *pdwFlags &= ~CERT_STORE_TIME_VALIDITY_FLAG;
307 if (*pdwFlags & CERT_STORE_SIGNATURE_FLAG)
309 if (CryptVerifyCertificateSignatureEx(0, ret->dwCertEncodingType,
310 CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL, (void *)ret,
311 CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT, (void *)pIssuerContext, 0,
312 NULL))
313 *pdwFlags &= ~CERT_STORE_SIGNATURE_FLAG;
316 return ret;
319 PCCRL_CONTEXT WINAPI CertDuplicateCRLContext(PCCRL_CONTEXT pCrlContext)
321 TRACE("(%p)\n", pCrlContext);
322 if (pCrlContext)
323 Context_AddRef((void *)pCrlContext, sizeof(CRL_CONTEXT));
324 return pCrlContext;
327 static void CrlDataContext_Free(void *context)
329 PCRL_CONTEXT crlContext = context;
331 CryptMemFree(crlContext->pbCrlEncoded);
332 LocalFree(crlContext->pCrlInfo);
335 BOOL WINAPI CertFreeCRLContext( PCCRL_CONTEXT pCrlContext)
337 BOOL ret = TRUE;
339 TRACE("(%p)\n", pCrlContext);
341 if (pCrlContext)
342 ret = Context_Release((void *)pCrlContext, sizeof(CRL_CONTEXT),
343 CrlDataContext_Free);
344 return ret;
347 DWORD WINAPI CertEnumCRLContextProperties(PCCRL_CONTEXT pCRLContext,
348 DWORD dwPropId)
350 PCONTEXT_PROPERTY_LIST properties = Context_GetProperties(
351 pCRLContext, sizeof(CRL_CONTEXT));
352 DWORD ret;
354 TRACE("(%p, %d)\n", pCRLContext, dwPropId);
356 if (properties)
357 ret = ContextPropertyList_EnumPropIDs(properties, dwPropId);
358 else
359 ret = 0;
360 return ret;
363 static BOOL CRLContext_SetProperty(PCCRL_CONTEXT context, DWORD dwPropId,
364 DWORD dwFlags, const void *pvData);
366 static BOOL CRLContext_GetHashProp(PCCRL_CONTEXT context, DWORD dwPropId,
367 ALG_ID algID, const BYTE *toHash, DWORD toHashLen, void *pvData,
368 DWORD *pcbData)
370 BOOL ret = CryptHashCertificate(0, algID, 0, toHash, toHashLen, pvData,
371 pcbData);
372 if (ret && pvData)
374 CRYPT_DATA_BLOB blob = { *pcbData, pvData };
376 ret = CRLContext_SetProperty(context, dwPropId, 0, &blob);
378 return ret;
381 static BOOL CRLContext_GetProperty(PCCRL_CONTEXT context, DWORD dwPropId,
382 void *pvData, DWORD *pcbData)
384 PCONTEXT_PROPERTY_LIST properties =
385 Context_GetProperties(context, sizeof(CRL_CONTEXT));
386 BOOL ret;
387 CRYPT_DATA_BLOB blob;
389 TRACE("(%p, %d, %p, %p)\n", context, dwPropId, pvData, pcbData);
391 if (properties)
392 ret = ContextPropertyList_FindProperty(properties, dwPropId, &blob);
393 else
394 ret = FALSE;
395 if (ret)
397 if (!pvData)
398 *pcbData = blob.cbData;
399 else if (*pcbData < blob.cbData)
401 SetLastError(ERROR_MORE_DATA);
402 *pcbData = blob.cbData;
403 ret = FALSE;
405 else
407 memcpy(pvData, blob.pbData, blob.cbData);
408 *pcbData = blob.cbData;
411 else
413 /* Implicit properties */
414 switch (dwPropId)
416 case CERT_SHA1_HASH_PROP_ID:
417 ret = CRLContext_GetHashProp(context, dwPropId, CALG_SHA1,
418 context->pbCrlEncoded, context->cbCrlEncoded, pvData,
419 pcbData);
420 break;
421 case CERT_MD5_HASH_PROP_ID:
422 ret = CRLContext_GetHashProp(context, dwPropId, CALG_MD5,
423 context->pbCrlEncoded, context->cbCrlEncoded, pvData,
424 pcbData);
425 break;
426 default:
427 SetLastError(CRYPT_E_NOT_FOUND);
430 TRACE("returning %d\n", ret);
431 return ret;
434 BOOL WINAPI CertGetCRLContextProperty(PCCRL_CONTEXT pCRLContext,
435 DWORD dwPropId, void *pvData, DWORD *pcbData)
437 BOOL ret;
439 TRACE("(%p, %d, %p, %p)\n", pCRLContext, dwPropId, pvData, pcbData);
441 switch (dwPropId)
443 case 0:
444 case CERT_CERT_PROP_ID:
445 case CERT_CRL_PROP_ID:
446 case CERT_CTL_PROP_ID:
447 SetLastError(E_INVALIDARG);
448 ret = FALSE;
449 break;
450 case CERT_ACCESS_STATE_PROP_ID:
451 if (!pvData)
453 *pcbData = sizeof(DWORD);
454 ret = TRUE;
456 else if (*pcbData < sizeof(DWORD))
458 SetLastError(ERROR_MORE_DATA);
459 *pcbData = sizeof(DWORD);
460 ret = FALSE;
462 else
464 if (pCRLContext->hCertStore)
465 ret = CertGetStoreProperty(pCRLContext->hCertStore, dwPropId,
466 pvData, pcbData);
467 else
468 *(DWORD *)pvData = 0;
469 ret = TRUE;
471 break;
472 default:
473 ret = CRLContext_GetProperty(pCRLContext, dwPropId, pvData,
474 pcbData);
476 return ret;
479 static BOOL CRLContext_SetProperty(PCCRL_CONTEXT context, DWORD dwPropId,
480 DWORD dwFlags, const void *pvData)
482 PCONTEXT_PROPERTY_LIST properties =
483 Context_GetProperties(context, sizeof(CRL_CONTEXT));
484 BOOL ret;
486 TRACE("(%p, %d, %08x, %p)\n", context, dwPropId, dwFlags, pvData);
488 if (!properties)
489 ret = FALSE;
490 else if (!pvData)
492 ContextPropertyList_RemoveProperty(properties, dwPropId);
493 ret = TRUE;
495 else
497 switch (dwPropId)
499 case CERT_AUTO_ENROLL_PROP_ID:
500 case CERT_CTL_USAGE_PROP_ID: /* same as CERT_ENHKEY_USAGE_PROP_ID */
501 case CERT_DESCRIPTION_PROP_ID:
502 case CERT_FRIENDLY_NAME_PROP_ID:
503 case CERT_HASH_PROP_ID:
504 case CERT_KEY_IDENTIFIER_PROP_ID:
505 case CERT_MD5_HASH_PROP_ID:
506 case CERT_NEXT_UPDATE_LOCATION_PROP_ID:
507 case CERT_PUBKEY_ALG_PARA_PROP_ID:
508 case CERT_PVK_FILE_PROP_ID:
509 case CERT_SIGNATURE_HASH_PROP_ID:
510 case CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID:
511 case CERT_SUBJECT_NAME_MD5_HASH_PROP_ID:
512 case CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID:
513 case CERT_ENROLLMENT_PROP_ID:
514 case CERT_CROSS_CERT_DIST_POINTS_PROP_ID:
515 case CERT_RENEWAL_PROP_ID:
517 PCRYPT_DATA_BLOB blob = (PCRYPT_DATA_BLOB)pvData;
519 ret = ContextPropertyList_SetProperty(properties, dwPropId,
520 blob->pbData, blob->cbData);
521 break;
523 case CERT_DATE_STAMP_PROP_ID:
524 ret = ContextPropertyList_SetProperty(properties, dwPropId,
525 pvData, sizeof(FILETIME));
526 break;
527 default:
528 FIXME("%d: stub\n", dwPropId);
529 ret = FALSE;
532 TRACE("returning %d\n", ret);
533 return ret;
536 BOOL WINAPI CertSetCRLContextProperty(PCCRL_CONTEXT pCRLContext,
537 DWORD dwPropId, DWORD dwFlags, const void *pvData)
539 BOOL ret;
541 TRACE("(%p, %d, %08x, %p)\n", pCRLContext, dwPropId, dwFlags, pvData);
543 /* Handle special cases for "read-only"/invalid prop IDs. Windows just
544 * crashes on most of these, I'll be safer.
546 switch (dwPropId)
548 case 0:
549 case CERT_ACCESS_STATE_PROP_ID:
550 case CERT_CERT_PROP_ID:
551 case CERT_CRL_PROP_ID:
552 case CERT_CTL_PROP_ID:
553 SetLastError(E_INVALIDARG);
554 return FALSE;
556 ret = CRLContext_SetProperty(pCRLContext, dwPropId, dwFlags, pvData);
557 TRACE("returning %d\n", ret);
558 return ret;
561 static BOOL compare_dist_point_name(const CRL_DIST_POINT_NAME *name1,
562 const CRL_DIST_POINT_NAME *name2)
564 BOOL match;
566 if (name1->dwDistPointNameChoice == name2->dwDistPointNameChoice)
568 match = TRUE;
569 if (name1->dwDistPointNameChoice == CRL_DIST_POINT_FULL_NAME)
571 if (name1->u.FullName.cAltEntry == name2->u.FullName.cAltEntry)
573 DWORD i;
575 for (i = 0; match && i < name1->u.FullName.cAltEntry; i++)
577 const CERT_ALT_NAME_ENTRY *entry1 =
578 &name1->u.FullName.rgAltEntry[i];
579 const CERT_ALT_NAME_ENTRY *entry2 =
580 &name2->u.FullName.rgAltEntry[i];
582 if (entry1->dwAltNameChoice == entry2->dwAltNameChoice)
584 switch (entry1->dwAltNameChoice)
586 case CERT_ALT_NAME_URL:
587 match = !strcmpiW(entry1->u.pwszURL,
588 entry2->u.pwszURL);
589 break;
590 case CERT_ALT_NAME_DIRECTORY_NAME:
591 match = (entry1->u.DirectoryName.cbData ==
592 entry2->u.DirectoryName.cbData) &&
593 !memcmp(entry1->u.DirectoryName.pbData,
594 entry2->u.DirectoryName.pbData,
595 entry1->u.DirectoryName.cbData);
596 break;
597 default:
598 FIXME("unimplemented for type %d\n",
599 entry1->dwAltNameChoice);
600 match = FALSE;
603 else
604 match = FALSE;
607 else
608 match = FALSE;
611 else
612 match = FALSE;
613 return match;
616 static BOOL match_dist_point_with_issuing_dist_point(
617 const CRL_DIST_POINT *distPoint, const CRL_ISSUING_DIST_POINT *idp)
619 BOOL match;
621 /* While RFC 5280, section 4.2.1.13 recommends against segmenting
622 * CRL distribution points by reasons, it doesn't preclude doing so.
623 * "This profile RECOMMENDS against segmenting CRLs by reason code."
624 * If the issuing distribution point for this CRL is only valid for
625 * some reasons, only match if the reasons covered also match the
626 * reasons in the CRL distribution point.
628 if (idp->OnlySomeReasonFlags.cbData)
630 if (idp->OnlySomeReasonFlags.cbData == distPoint->ReasonFlags.cbData)
632 DWORD i;
634 match = TRUE;
635 for (i = 0; match && i < distPoint->ReasonFlags.cbData; i++)
636 if (idp->OnlySomeReasonFlags.pbData[i] !=
637 distPoint->ReasonFlags.pbData[i])
638 match = FALSE;
640 else
641 match = FALSE;
643 else
644 match = TRUE;
645 if (match)
646 match = compare_dist_point_name(&idp->DistPointName,
647 &distPoint->DistPointName);
648 return match;
651 BOOL WINAPI CertIsValidCRLForCertificate(PCCERT_CONTEXT pCert,
652 PCCRL_CONTEXT pCrl, DWORD dwFlags, void *pvReserved)
654 PCERT_EXTENSION ext;
655 BOOL ret;
657 TRACE("(%p, %p, %08x, %p)\n", pCert, pCrl, dwFlags, pvReserved);
659 if (!pCert)
660 return TRUE;
662 if ((ext = CertFindExtension(szOID_ISSUING_DIST_POINT,
663 pCrl->pCrlInfo->cExtension, pCrl->pCrlInfo->rgExtension)))
665 CRL_ISSUING_DIST_POINT *idp;
666 DWORD size;
668 if ((ret = CryptDecodeObjectEx(pCrl->dwCertEncodingType,
669 X509_ISSUING_DIST_POINT, ext->Value.pbData, ext->Value.cbData,
670 CRYPT_DECODE_ALLOC_FLAG, NULL, &idp, &size)))
672 if ((ext = CertFindExtension(szOID_CRL_DIST_POINTS,
673 pCert->pCertInfo->cExtension, pCert->pCertInfo->rgExtension)))
675 CRL_DIST_POINTS_INFO *distPoints;
677 if ((ret = CryptDecodeObjectEx(pCert->dwCertEncodingType,
678 X509_CRL_DIST_POINTS, ext->Value.pbData, ext->Value.cbData,
679 CRYPT_DECODE_ALLOC_FLAG, NULL, &distPoints, &size)))
681 DWORD i;
683 ret = FALSE;
684 for (i = 0; !ret && i < distPoints->cDistPoint; i++)
685 ret = match_dist_point_with_issuing_dist_point(
686 &distPoints->rgDistPoint[i], idp);
687 if (!ret)
688 SetLastError(CRYPT_E_NO_MATCH);
689 LocalFree(distPoints);
692 else
694 /* no CRL dist points extension in cert, can't match the CRL
695 * (which has an issuing dist point extension)
697 ret = FALSE;
698 SetLastError(CRYPT_E_NO_MATCH);
700 LocalFree(idp);
703 else
704 ret = TRUE;
705 return ret;
708 static PCRL_ENTRY CRYPT_FindCertificateInCRL(PCERT_INFO cert, const CRL_INFO *crl)
710 DWORD i;
711 PCRL_ENTRY entry = NULL;
713 for (i = 0; !entry && i < crl->cCRLEntry; i++)
714 if (CertCompareIntegerBlob(&crl->rgCRLEntry[i].SerialNumber,
715 &cert->SerialNumber))
716 entry = &crl->rgCRLEntry[i];
717 return entry;
720 BOOL WINAPI CertFindCertificateInCRL(PCCERT_CONTEXT pCert,
721 PCCRL_CONTEXT pCrlContext, DWORD dwFlags, void *pvReserved,
722 PCRL_ENTRY *ppCrlEntry)
724 TRACE("(%p, %p, %08x, %p, %p)\n", pCert, pCrlContext, dwFlags, pvReserved,
725 ppCrlEntry);
727 *ppCrlEntry = CRYPT_FindCertificateInCRL(pCert->pCertInfo,
728 pCrlContext->pCrlInfo);
729 return TRUE;
732 BOOL WINAPI CertVerifyCRLRevocation(DWORD dwCertEncodingType,
733 PCERT_INFO pCertId, DWORD cCrlInfo, PCRL_INFO rgpCrlInfo[])
735 DWORD i;
736 PCRL_ENTRY entry = NULL;
738 TRACE("(%08x, %p, %d, %p)\n", dwCertEncodingType, pCertId, cCrlInfo,
739 rgpCrlInfo);
741 for (i = 0; !entry && i < cCrlInfo; i++)
742 entry = CRYPT_FindCertificateInCRL(pCertId, rgpCrlInfo[i]);
743 return entry == NULL;
746 LONG WINAPI CertVerifyCRLTimeValidity(LPFILETIME pTimeToVerify,
747 PCRL_INFO pCrlInfo)
749 FILETIME fileTime;
750 LONG ret;
752 if (!pTimeToVerify)
754 GetSystemTimeAsFileTime(&fileTime);
755 pTimeToVerify = &fileTime;
757 if ((ret = CompareFileTime(pTimeToVerify, &pCrlInfo->ThisUpdate)) >= 0)
759 ret = CompareFileTime(pTimeToVerify, &pCrlInfo->NextUpdate);
760 if (ret < 0)
761 ret = 0;
763 return ret;