| 
									
										
										
										
											2016-05-18 02:52:22 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-01-28 20:54:57 +08:00
										 |  |  |  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 21:00:36 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:52:22 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2015-05-14 22:56:48 +08:00
										 |  |  | #include "internal/cryptlib.h"
 | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | #include <openssl/asn1t.h>
 | 
					
						
							| 
									
										
										
										
											1999-04-24 06:13:45 +08:00
										 |  |  | #include <openssl/x509.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:33 +08:00
										 |  |  | #include "crypto/x509.h"
 | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  | #include <openssl/x509v3.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:40 +08:00
										 |  |  | #include "x509_local.h"
 | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-01 10:36:58 +08:00
										 |  |  | static int X509_REVOKED_cmp(const X509_REVOKED *const *a, | 
					
						
							|  |  |  |                             const X509_REVOKED *const *b); | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  | static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | ASN1_SEQUENCE(X509_REVOKED) = { | 
					
						
							| 
									
										
										
										
											2021-10-26 15:16:18 +08:00
										 |  |  |         ASN1_EMBED(X509_REVOKED, serialNumber, ASN1_INTEGER), | 
					
						
							|  |  |  |         ASN1_SIMPLE(X509_REVOKED, revocationDate, ASN1_TIME), | 
					
						
							|  |  |  |         ASN1_SEQUENCE_OF_OPT(X509_REVOKED, extensions, X509_EXTENSION) | 
					
						
							| 
									
										
										
										
											2001-02-23 20:47:06 +08:00
										 |  |  | } ASN1_SEQUENCE_END(X509_REVOKED) | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r); | 
					
						
							|  |  |  | static int def_crl_lookup(X509_CRL *crl, | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  |                           X509_REVOKED **ret, const ASN1_INTEGER *serial, | 
					
						
							|  |  |  |                           const X509_NAME *issuer); | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | static X509_CRL_METHOD int_crl_meth = { | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     0, 0, | 
					
						
							|  |  |  |     def_crl_lookup, | 
					
						
							|  |  |  |     def_crl_verify | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const X509_CRL_METHOD *default_crl_method = &int_crl_meth; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-05 00:30:12 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * The X509_CRL_INFO structure needs a bit of customisation. Since we cache | 
					
						
							| 
									
										
										
										
											2016-08-06 01:56:58 +08:00
										 |  |  |  * the original encoding the signature won't be affected by reordering of the | 
					
						
							| 
									
										
										
										
											2004-10-05 00:30:12 +08:00
										 |  |  |  * revoked field. | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-09-02 04:42:52 +08:00
										 |  |  | static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 
					
						
							|  |  |  |                       void *exarg) | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     X509_CRL_INFO *a = (X509_CRL_INFO *)*pval; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |     if (!a || !a->revoked) | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     switch (operation) { | 
					
						
							| 
									
										
										
										
											2004-10-05 00:30:12 +08:00
										 |  |  |         /*
 | 
					
						
							|  |  |  |          * Just set cmp function here. We don't sort because that would | 
					
						
							|  |  |  |          * affect the output of X509_CRL_print(). | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |     case ASN1_OP_D2I_POST: | 
					
						
							| 
									
										
										
										
											2007-09-07 21:25:15 +08:00
										 |  |  |         (void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp); | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-05 00:30:12 +08:00
										 |  |  | ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = { | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |         ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER), | 
					
						
							| 
									
										
										
										
											2015-09-17 21:44:19 +08:00
										 |  |  |         ASN1_EMBED(X509_CRL_INFO, sig_alg, X509_ALGOR), | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |         ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME), | 
					
						
							|  |  |  |         ASN1_SIMPLE(X509_CRL_INFO, lastUpdate, ASN1_TIME), | 
					
						
							|  |  |  |         ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME), | 
					
						
							|  |  |  |         ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED), | 
					
						
							|  |  |  |         ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0) | 
					
						
							| 
									
										
										
										
											2004-10-05 00:30:12 +08:00
										 |  |  | } ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO) | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Set CRL entry issuer according to CRL certificate issuer extension. Check | 
					
						
							|  |  |  |  * for unhandled critical CRL entry extensions. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int crl_set_issuers(X509_CRL *crl) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     int i, j; | 
					
						
							|  |  |  |     GENERAL_NAMES *gens, *gtmp; | 
					
						
							|  |  |  |     STACK_OF(X509_REVOKED) *revoked; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     revoked = X509_CRL_get_REVOKED(crl); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     gens = NULL; | 
					
						
							|  |  |  |     for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) { | 
					
						
							|  |  |  |         X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); | 
					
						
							|  |  |  |         STACK_OF(X509_EXTENSION) *exts; | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |         ASN1_ENUMERATED *reason; | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         X509_EXTENSION *ext; | 
					
						
							| 
									
										
										
										
											2022-05-23 23:26:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         gtmp = X509_REVOKED_get_ext_d2i(rev, | 
					
						
							|  |  |  |                                         NID_certificate_issuer, &j, NULL); | 
					
						
							| 
									
										
										
										
											2022-05-23 23:26:15 +08:00
										 |  |  |         if (gtmp == NULL && j != -1) { | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |             crl->flags |= EXFLAG_INVALID; | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-23 23:26:15 +08:00
										 |  |  |         if (gtmp != NULL) { | 
					
						
							| 
									
										
										
										
											2022-05-21 13:50:46 +08:00
										 |  |  |             if (crl->issuers == NULL) { | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |                 crl->issuers = sk_GENERAL_NAMES_new_null(); | 
					
						
							| 
									
										
										
										
											2022-05-21 13:50:46 +08:00
										 |  |  |                 if (crl->issuers == NULL) { | 
					
						
							|  |  |  |                     GENERAL_NAMES_free(gtmp); | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |                     return 0; | 
					
						
							| 
									
										
										
										
											2022-05-21 13:50:46 +08:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-05-21 13:50:46 +08:00
										 |  |  |             if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) { | 
					
						
							|  |  |  |                 GENERAL_NAMES_free(gtmp); | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |                 return 0; | 
					
						
							| 
									
										
										
										
											2022-05-21 13:50:46 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-05-23 23:26:15 +08:00
										 |  |  |             gens = gtmp; | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         rev->issuer = gens; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |         reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, &j, NULL); | 
					
						
							| 
									
										
										
										
											2022-05-23 23:26:15 +08:00
										 |  |  |         if (reason == NULL && j != -1) { | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |             crl->flags |= EXFLAG_INVALID; | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-23 23:26:15 +08:00
										 |  |  |         if (reason != NULL) { | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |             rev->reason = ASN1_ENUMERATED_get(reason); | 
					
						
							|  |  |  |             ASN1_ENUMERATED_free(reason); | 
					
						
							|  |  |  |         } else | 
					
						
							|  |  |  |             rev->reason = CRL_REASON_NONE; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         /* Check for critical CRL entry extensions */ | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         exts = rev->extensions; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) { | 
					
						
							|  |  |  |             ext = sk_X509_EXTENSION_value(exts, j); | 
					
						
							| 
									
										
										
										
											2015-03-15 21:43:56 +08:00
										 |  |  |             if (X509_EXTENSION_get_critical(ext)) { | 
					
						
							| 
									
										
										
										
											2022-05-23 23:26:15 +08:00
										 |  |  |                 if (OBJ_obj2nid(X509_EXTENSION_get_object(ext)) | 
					
						
							|  |  |  |                     == NID_certificate_issuer) | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |                     continue; | 
					
						
							|  |  |  |                 crl->flags |= EXFLAG_CRITICAL; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     return 1; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * The X509_CRL structure needs a bit of customisation. Cache some extensions | 
					
						
							| 
									
										
										
										
											2020-12-30 16:49:20 +08:00
										 |  |  |  * and hash of the whole CRL or set EXFLAG_NO_FINGERPRINT if this fails. | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 
					
						
							|  |  |  |                   void *exarg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     X509_CRL *crl = (X509_CRL *)*pval; | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |     STACK_OF(X509_EXTENSION) *exts; | 
					
						
							|  |  |  |     X509_EXTENSION *ext; | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |     int idx, i; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |     switch (operation) { | 
					
						
							| 
									
										
										
										
											2019-01-29 21:16:28 +08:00
										 |  |  |     case ASN1_OP_D2I_PRE: | 
					
						
							|  |  |  |         if (crl->meth->crl_free) { | 
					
						
							|  |  |  |             if (!crl->meth->crl_free(crl)) | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         AUTHORITY_KEYID_free(crl->akid); | 
					
						
							|  |  |  |         ISSUING_DIST_POINT_free(crl->idp); | 
					
						
							|  |  |  |         ASN1_INTEGER_free(crl->crl_number); | 
					
						
							|  |  |  |         ASN1_INTEGER_free(crl->base_crl_number); | 
					
						
							|  |  |  |         sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); | 
					
						
							| 
									
										
										
										
											2022-08-24 02:37:03 +08:00
										 |  |  |         /* fall through */ | 
					
						
							| 
									
										
										
										
											2019-01-29 21:16:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |     case ASN1_OP_NEW_POST: | 
					
						
							|  |  |  |         crl->idp = NULL; | 
					
						
							|  |  |  |         crl->akid = NULL; | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  |         crl->flags = 0; | 
					
						
							|  |  |  |         crl->idp_flags = 0; | 
					
						
							| 
									
										
										
										
											2008-08-29 19:37:21 +08:00
										 |  |  |         crl->idp_reasons = CRLDP_ALL_REASONS; | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |         crl->meth = default_crl_method; | 
					
						
							|  |  |  |         crl->meth_data = NULL; | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         crl->issuers = NULL; | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |         crl->crl_number = NULL; | 
					
						
							|  |  |  |         crl->base_crl_number = NULL; | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |     case ASN1_OP_D2I_POST: | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |         if (!X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL)) | 
					
						
							| 
									
										
										
										
											2020-12-30 16:49:20 +08:00
										 |  |  |             crl->flags |= EXFLAG_NO_FINGERPRINT; | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |         crl->idp = X509_CRL_get_ext_d2i(crl, | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |                                         NID_issuing_distribution_point, &i, | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |                                         NULL); | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |         if (crl->idp != NULL) { | 
					
						
							|  |  |  |             if (!setup_idp(crl, crl->idp)) | 
					
						
							|  |  |  |                 crl->flags |= EXFLAG_INVALID; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (i != -1) { | 
					
						
							|  |  |  |             crl->flags |= EXFLAG_INVALID; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |         crl->akid = X509_CRL_get_ext_d2i(crl, | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |                                          NID_authority_key_identifier, &i, | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |                                          NULL); | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |         if (crl->akid == NULL && i != -1) | 
					
						
							|  |  |  |             crl->flags |= EXFLAG_INVALID; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |         crl->crl_number = X509_CRL_get_ext_d2i(crl, | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |                                                NID_crl_number, &i, NULL); | 
					
						
							|  |  |  |         if (crl->crl_number == NULL && i != -1) | 
					
						
							|  |  |  |             crl->flags |= EXFLAG_INVALID; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |         crl->base_crl_number = X509_CRL_get_ext_d2i(crl, | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |                                                     NID_delta_crl, &i, | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |                                                     NULL); | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  |         if (crl->base_crl_number == NULL && i != -1) | 
					
						
							|  |  |  |             crl->flags |= EXFLAG_INVALID; | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |         /* Delta CRLs must have CRL number */ | 
					
						
							|  |  |  |         if (crl->base_crl_number && !crl->crl_number) | 
					
						
							|  |  |  |             crl->flags |= EXFLAG_INVALID; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |         /*
 | 
					
						
							|  |  |  |          * See if we have any unhandled critical CRL extensions and indicate | 
					
						
							|  |  |  |          * this in a flag. We only currently handle IDP so anything else | 
					
						
							|  |  |  |          * critical sets the flag. This code accesses the X509_CRL structure | 
					
						
							|  |  |  |          * directly: applications shouldn't do this. | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-16 07:24:43 +08:00
										 |  |  |         exts = crl->crl.extensions; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |         for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) { | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |             int nid; | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |             ext = sk_X509_EXTENSION_value(exts, idx); | 
					
						
							| 
									
										
										
										
											2015-03-15 21:43:56 +08:00
										 |  |  |             nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext)); | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |             if (nid == NID_freshest_crl) | 
					
						
							|  |  |  |                 crl->flags |= EXFLAG_FRESHEST; | 
					
						
							| 
									
										
										
										
											2015-03-15 21:43:56 +08:00
										 |  |  |             if (X509_EXTENSION_get_critical(ext)) { | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |                 /* We handle IDP and deltas */ | 
					
						
							|  |  |  |                 if ((nid == NID_issuing_distribution_point) | 
					
						
							| 
									
										
										
										
											2014-06-28 01:49:32 +08:00
										 |  |  |                     || (nid == NID_authority_key_identifier) | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |                     || (nid == NID_delta_crl)) | 
					
						
							| 
									
										
										
										
											2016-11-29 04:33:40 +08:00
										 |  |  |                     continue; | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |                 crl->flags |= EXFLAG_CRITICAL; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         if (!crl_set_issuers(crl)) | 
					
						
							|  |  |  |             return 0; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |         if (crl->meth->crl_init) { | 
					
						
							|  |  |  |             if (crl->meth->crl_init(crl) == 0) | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-29 00:43:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         crl->flags |= EXFLAG_SET; | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |     case ASN1_OP_FREE_POST: | 
					
						
							| 
									
										
										
										
											2022-05-20 14:02:47 +08:00
										 |  |  |         if (crl->meth != NULL && crl->meth->crl_free != NULL) { | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |             if (!crl->meth->crl_free(crl)) | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-02 02:37:16 +08:00
										 |  |  |         AUTHORITY_KEYID_free(crl->akid); | 
					
						
							|  |  |  |         ISSUING_DIST_POINT_free(crl->idp); | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |         ASN1_INTEGER_free(crl->crl_number); | 
					
						
							|  |  |  |         ASN1_INTEGER_free(crl->base_crl_number); | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); | 
					
						
							| 
									
										
										
										
											2020-12-02 18:50:32 +08:00
										 |  |  |         OPENSSL_free(crl->propq); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case ASN1_OP_DUP_POST: | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             X509_CRL *old = exarg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-09 12:18:03 +08:00
										 |  |  |             if (!ossl_x509_crl_set0_libctx(crl, old->libctx, old->propq)) | 
					
						
							| 
									
										
										
										
											2020-12-02 18:50:32 +08:00
										 |  |  |                 return 0; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-07-24 20:39:22 +08:00
										 |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  | /* Convert IDP into a more convenient form */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  | static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     int idp_only = 0; | 
					
						
							| 
									
										
										
										
											2025-07-24 01:48:50 +08:00
										 |  |  |     int ret = 0; | 
					
						
							| 
									
										
										
										
											2020-01-04 22:54:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  |     /* Set various flags according to IDP */ | 
					
						
							|  |  |  |     crl->idp_flags |= IDP_PRESENT; | 
					
						
							|  |  |  |     if (idp->onlyuser > 0) { | 
					
						
							|  |  |  |         idp_only++; | 
					
						
							|  |  |  |         crl->idp_flags |= IDP_ONLYUSER; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (idp->onlyCA > 0) { | 
					
						
							|  |  |  |         idp_only++; | 
					
						
							|  |  |  |         crl->idp_flags |= IDP_ONLYCA; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (idp->onlyattr > 0) { | 
					
						
							|  |  |  |         idp_only++; | 
					
						
							|  |  |  |         crl->idp_flags |= IDP_ONLYATTR; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  |     if (idp_only > 1) | 
					
						
							|  |  |  |         crl->idp_flags |= IDP_INVALID; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  |     if (idp->indirectCRL > 0) | 
					
						
							|  |  |  |         crl->idp_flags |= IDP_INDIRECT; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  |     if (idp->onlysomereasons) { | 
					
						
							|  |  |  |         crl->idp_flags |= IDP_REASONS; | 
					
						
							|  |  |  |         if (idp->onlysomereasons->length > 0) | 
					
						
							|  |  |  |             crl->idp_reasons = idp->onlysomereasons->data[0]; | 
					
						
							|  |  |  |         if (idp->onlysomereasons->length > 1) | 
					
						
							|  |  |  |             crl->idp_reasons |= (idp->onlysomereasons->data[1] << 8); | 
					
						
							| 
									
										
										
										
											2008-08-29 19:37:21 +08:00
										 |  |  |         crl->idp_reasons &= CRLDP_ALL_REASONS; | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-24 01:48:50 +08:00
										 |  |  |     ret = DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * RFC5280 specifies that if onlyContainsUserCerts, onlyContainsCACerts, | 
					
						
							|  |  |  |      * indirectCRL, and OnlyContainsAttributeCerts are all FALSE, there must | 
					
						
							|  |  |  |      * be either a distributionPoint field or an onlySomeReasons field present. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (crl->idp_flags == IDP_PRESENT && idp->distpoint == NULL) | 
					
						
							|  |  |  |         crl->idp_flags |= IDP_INVALID; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2006-09-10 20:38:37 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-02 02:06:15 +08:00
										 |  |  | ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = { | 
					
						
							| 
									
										
										
										
											2015-09-16 07:24:43 +08:00
										 |  |  |         ASN1_EMBED(X509_CRL, crl, X509_CRL_INFO), | 
					
						
							| 
									
										
										
										
											2015-09-17 21:44:19 +08:00
										 |  |  |         ASN1_EMBED(X509_CRL, sig_alg, X509_ALGOR), | 
					
						
							| 
									
										
										
										
											2015-10-12 04:13:42 +08:00
										 |  |  |         ASN1_EMBED(X509_CRL, signature, ASN1_BIT_STRING) | 
					
						
							| 
									
										
										
										
											2001-02-23 20:47:06 +08:00
										 |  |  | } ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL) | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-05 02:35:36 +08:00
										 |  |  | IMPLEMENT_ASN1_DUP_FUNCTION(X509_REVOKED) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:41:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:41:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 10:22:42 +08:00
										 |  |  | IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-01 10:36:58 +08:00
										 |  |  | static int X509_REVOKED_cmp(const X509_REVOKED *const *a, | 
					
						
							|  |  |  |                             const X509_REVOKED *const *b) | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-12 04:13:42 +08:00
										 |  |  |     return (ASN1_STRING_cmp((ASN1_STRING *)&(*a)->serialNumber, | 
					
						
							|  |  |  |                             (ASN1_STRING *)&(*b)->serialNumber)); | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 13:10:22 +08:00
										 |  |  | X509_CRL *X509_CRL_new_ex(OSSL_LIB_CTX *libctx, const char *propq) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     X509_CRL *crl = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     crl = (X509_CRL *)ASN1_item_new((X509_CRL_it())); | 
					
						
							|  |  |  |     if (!ossl_x509_crl_set0_libctx(crl, libctx, propq)) { | 
					
						
							|  |  |  |         X509_CRL_free(crl); | 
					
						
							|  |  |  |         crl = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return crl; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     X509_CRL_INFO *inf; | 
					
						
							| 
									
										
										
										
											2018-03-29 04:32:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-16 07:24:43 +08:00
										 |  |  |     inf = &crl->crl; | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (inf->revoked == NULL) | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |         inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (inf->revoked == NULL || !sk_X509_REVOKED_push(inf->revoked, rev)) { | 
					
						
							| 
									
										
										
										
											2022-09-29 19:57:34 +08:00
										 |  |  |         ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-12-09 21:35:06 +08:00
										 |  |  |     inf->enc.modified = 1; | 
					
						
							| 
									
										
										
										
											2000-12-09 03:09:35 +08:00
										 |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  | int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |     if (crl->meth->crl_verify) | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |         return crl->meth->crl_verify(crl, r); | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int X509_CRL_get0_by_serial(X509_CRL *crl, | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  |                             X509_REVOKED **ret, const ASN1_INTEGER *serial) | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     if (crl->meth->crl_lookup) | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |         return crl->meth->crl_lookup(crl, ret, serial, NULL); | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (crl->meth->crl_lookup) | 
					
						
							|  |  |  |         return crl->meth->crl_lookup(crl, ret, | 
					
						
							| 
									
										
										
										
											2020-07-13 23:13:48 +08:00
										 |  |  |                                      X509_get0_serialNumber(x), | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |                                      X509_get_issuer_name(x)); | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-04-12 09:19:21 +08:00
										 |  |  |     return ASN1_item_verify_ex(ASN1_ITEM_rptr(X509_CRL_INFO), | 
					
						
							|  |  |  |                                &crl->sig_alg, &crl->signature, &crl->crl, NULL, | 
					
						
							|  |  |  |                                r, crl->libctx, crl->propq); | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  | static int crl_revoked_issuer_match(X509_CRL *crl, const X509_NAME *nm, | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |                                     X509_REVOKED *rev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int i; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     if (!rev->issuer) { | 
					
						
							|  |  |  |         if (!nm) | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     if (!nm) | 
					
						
							|  |  |  |         nm = X509_CRL_get_issuer(crl); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) { | 
					
						
							|  |  |  |         GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); | 
					
						
							|  |  |  |         if (gen->type != GEN_DIRNAME) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         if (!X509_NAME_cmp(nm, gen->d.directoryName)) | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  | static int def_crl_lookup(X509_CRL *crl, | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  |                           X509_REVOKED **ret, const ASN1_INTEGER *serial, | 
					
						
							|  |  |  |                           const X509_NAME *issuer) | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     X509_REVOKED rtmp, *rev; | 
					
						
							| 
									
										
										
										
											2018-08-05 22:50:41 +08:00
										 |  |  |     int idx, num; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (crl->crl.revoked == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * Sort revoked into serial number order if not already sorted. Do this | 
					
						
							|  |  |  |      * under a lock to avoid race condition. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-09-16 07:24:43 +08:00
										 |  |  |     if (!sk_X509_REVOKED_is_sorted(crl->crl.revoked)) { | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  |         if (!CRYPTO_THREAD_write_lock(crl->lock)) | 
					
						
							|  |  |  |             return 0; | 
					
						
							| 
									
										
										
										
											2015-09-16 07:24:43 +08:00
										 |  |  |         sk_X509_REVOKED_sort(crl->crl.revoked); | 
					
						
							| 
									
										
										
										
											2016-03-02 02:06:15 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(crl->lock); | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-05 22:50:41 +08:00
										 |  |  |     rtmp.serialNumber = *serial; | 
					
						
							| 
									
										
										
										
											2015-09-16 07:24:43 +08:00
										 |  |  |     idx = sk_X509_REVOKED_find(crl->crl.revoked, &rtmp); | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |     if (idx < 0) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     /* Need to look for matching name */ | 
					
						
							| 
									
										
										
										
											2018-08-05 22:50:41 +08:00
										 |  |  |     for (num = sk_X509_REVOKED_num(crl->crl.revoked); idx < num; idx++) { | 
					
						
							| 
									
										
										
										
											2015-09-16 07:24:43 +08:00
										 |  |  |         rev = sk_X509_REVOKED_value(crl->crl.revoked, idx); | 
					
						
							| 
									
										
										
										
											2015-10-12 04:13:42 +08:00
										 |  |  |         if (ASN1_INTEGER_cmp(&rev->serialNumber, serial)) | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |             return 0; | 
					
						
							|  |  |  |         if (crl_revoked_issuer_match(crl, issuer, rev)) { | 
					
						
							|  |  |  |             if (ret) | 
					
						
							|  |  |  |                 *ret = rev; | 
					
						
							| 
									
										
										
										
											2008-09-01 23:15:16 +08:00
										 |  |  |             if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) | 
					
						
							|  |  |  |                 return 2; | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |             return 1; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-09-21 20:42:15 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (meth == NULL) | 
					
						
							|  |  |  |         default_crl_method = &int_crl_meth; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         default_crl_method = meth; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  | X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init) (X509_CRL *crl), | 
					
						
							|  |  |  |                                      int (*crl_free) (X509_CRL *crl), | 
					
						
							| 
									
										
										
										
											2008-08-21 00:42:19 +08:00
										 |  |  |                                      int (*crl_lookup) (X509_CRL *crl, | 
					
						
							|  |  |  |                                                         X509_REVOKED **ret, | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  |                                                         const ASN1_INTEGER *ser, | 
					
						
							|  |  |  |                                                         const X509_NAME *issuer), | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |                                      int (*crl_verify) (X509_CRL *crl, | 
					
						
							|  |  |  |                                                         EVP_PKEY *pk)) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-29 04:32:31 +08:00
										 |  |  |     X509_CRL_METHOD *m = OPENSSL_malloc(sizeof(*m)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-29 19:57:34 +08:00
										 |  |  |     if (m == NULL) | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |     m->crl_init = crl_init; | 
					
						
							|  |  |  |     m->crl_free = crl_free; | 
					
						
							|  |  |  |     m->crl_lookup = crl_lookup; | 
					
						
							|  |  |  |     m->crl_verify = crl_verify; | 
					
						
							|  |  |  |     m->flags = X509_CRL_METHOD_DYNAMIC; | 
					
						
							|  |  |  |     return m; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void X509_CRL_METHOD_free(X509_CRL_METHOD *m) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-09-28 05:36:37 +08:00
										 |  |  |     if (m == NULL || !(m->flags & X509_CRL_METHOD_DYNAMIC)) | 
					
						
							| 
									
										
										
										
											2006-10-03 10:47:59 +08:00
										 |  |  |         return; | 
					
						
							|  |  |  |     OPENSSL_free(m); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     crl->meth_data = dat; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void *X509_CRL_get_meth_data(X509_CRL *crl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return crl->meth_data; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-23 04:55:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-09 12:18:03 +08:00
										 |  |  | int ossl_x509_crl_set0_libctx(X509_CRL *x, OSSL_LIB_CTX *libctx, | 
					
						
							|  |  |  |                               const char *propq) | 
					
						
							| 
									
										
										
										
											2020-07-23 04:55:00 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     if (x != NULL) { | 
					
						
							|  |  |  |         x->libctx = libctx; | 
					
						
							| 
									
										
										
										
											2020-12-02 18:50:32 +08:00
										 |  |  |         OPENSSL_free(x->propq); | 
					
						
							|  |  |  |         x->propq = NULL; | 
					
						
							|  |  |  |         if (propq != NULL) { | 
					
						
							|  |  |  |             x->propq = OPENSSL_strdup(propq); | 
					
						
							|  |  |  |             if (x->propq == NULL) | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-23 04:55:00 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } |