| 
									
										
										
										
											2008-11-06 02:39:08 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-04-08 20:04:41 +08:00
										 |  |  |  * Copyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 21:00:54 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:51:26 +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
 | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-14 22:56:48 +08:00
										 |  |  | #include "internal/cryptlib.h"
 | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  | #include <openssl/x509.h>
 | 
					
						
							|  |  |  | #include <openssl/x509v3.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:33 +08:00
										 |  |  | #include "crypto/x509.h"
 | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:40 +08:00
										 |  |  | #include "pcy_local.h"
 | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Set policy mapping entries in cache. Note: this modifies the passed | 
					
						
							|  |  |  |  * POLICY_MAPPINGS structure | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-09 11:23:45 +08:00
										 |  |  | int ossl_policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps) | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     POLICY_MAPPING *map; | 
					
						
							|  |  |  |     X509_POLICY_DATA *data; | 
					
						
							|  |  |  |     X509_POLICY_CACHE *cache = x->policy_cache; | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  |     int ret = 0; | 
					
						
							|  |  |  |     if (sk_POLICY_MAPPING_num(maps) == 0) { | 
					
						
							|  |  |  |         ret = -1; | 
					
						
							|  |  |  |         goto bad_mapping; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     for (i = 0; i < sk_POLICY_MAPPING_num(maps); i++) { | 
					
						
							|  |  |  |         map = sk_POLICY_MAPPING_value(maps, i); | 
					
						
							|  |  |  |         /* Reject if map to or from anyPolicy */ | 
					
						
							|  |  |  |         if ((OBJ_obj2nid(map->subjectDomainPolicy) == NID_any_policy) | 
					
						
							|  |  |  |             || (OBJ_obj2nid(map->issuerDomainPolicy) == NID_any_policy)) { | 
					
						
							|  |  |  |             ret = -1; | 
					
						
							|  |  |  |             goto bad_mapping; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* Attempt to find matching policy data */ | 
					
						
							| 
									
										
										
										
											2021-03-09 11:23:45 +08:00
										 |  |  |         data = ossl_policy_cache_find_data(cache, map->issuerDomainPolicy); | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  |         /* If we don't have anyPolicy can't map */ | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |         if (data == NULL && !cache->anyPolicy) | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  |             continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* Create a NODE from anyPolicy */ | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |         if (data == NULL) { | 
					
						
							| 
									
										
										
										
											2021-03-09 11:23:45 +08:00
										 |  |  |             data = ossl_policy_data_new(NULL, map->issuerDomainPolicy, | 
					
						
							|  |  |  |                                         cache->anyPolicy->flags | 
					
						
							|  |  |  |                                         & POLICY_DATA_FLAG_CRITICAL); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |             if (data == NULL) | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  |                 goto bad_mapping; | 
					
						
							|  |  |  |             data->qualifier_set = cache->anyPolicy->qualifier_set; | 
					
						
							| 
									
										
										
										
											2008-08-12 18:32:56 +08:00
										 |  |  |             /*
 | 
					
						
							|  |  |  |              * map->issuerDomainPolicy = NULL; | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  |             data->flags |= POLICY_DATA_FLAG_MAPPED_ANY; | 
					
						
							|  |  |  |             data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS; | 
					
						
							|  |  |  |             if (!sk_X509_POLICY_DATA_push(cache->data, data)) { | 
					
						
							| 
									
										
										
										
											2021-03-09 11:23:45 +08:00
										 |  |  |                 ossl_policy_data_free(data); | 
					
						
							| 
									
										
										
										
											2004-03-23 22:14:35 +08:00
										 |  |  |                 goto bad_mapping; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else | 
					
						
							|  |  |  |             data->flags |= POLICY_DATA_FLAG_MAPPED; | 
					
						
							|  |  |  |         if (!sk_ASN1_OBJECT_push(data->expected_policy_set, | 
					
						
							|  |  |  |                                  map->subjectDomainPolicy)) | 
					
						
							|  |  |  |             goto bad_mapping; | 
					
						
							|  |  |  |         map->subjectDomainPolicy = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ret = 1; | 
					
						
							|  |  |  |  bad_mapping: | 
					
						
							|  |  |  |     sk_POLICY_MAPPING_pop_free(maps, POLICY_MAPPING_free); | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |