| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							|  |  |  |  * 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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <openssl/err.h>
 | 
					
						
							|  |  |  | #include <openssl/asn1t.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  | #include <openssl/cms.h>
 | 
					
						
							| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  | #include <openssl/ess.h>
 | 
					
						
							|  |  |  | #include <openssl/x509v3.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:33 +08:00
										 |  |  | #include "crypto/ess.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  | #include "crypto/cms.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ASN1 stuff for ESS Structure */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASN1_SEQUENCE(ESS_ISSUER_SERIAL) = { | 
					
						
							|  |  |  |         ASN1_SEQUENCE_OF(ESS_ISSUER_SERIAL, issuer, GENERAL_NAME), | 
					
						
							|  |  |  |         ASN1_SIMPLE(ESS_ISSUER_SERIAL, serial, ASN1_INTEGER) | 
					
						
							|  |  |  | } static_ASN1_SEQUENCE_END(ESS_ISSUER_SERIAL) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 04:51:25 +08:00
										 |  |  | IMPLEMENT_ASN1_FUNCTIONS(ESS_ISSUER_SERIAL) | 
					
						
							| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  | IMPLEMENT_ASN1_DUP_FUNCTION(ESS_ISSUER_SERIAL) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASN1_SEQUENCE(ESS_CERT_ID) = { | 
					
						
							|  |  |  |         ASN1_SIMPLE(ESS_CERT_ID, hash, ASN1_OCTET_STRING), | 
					
						
							|  |  |  |         ASN1_OPT(ESS_CERT_ID, issuer_serial, ESS_ISSUER_SERIAL) | 
					
						
							|  |  |  | } static_ASN1_SEQUENCE_END(ESS_CERT_ID) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 04:51:25 +08:00
										 |  |  | IMPLEMENT_ASN1_FUNCTIONS(ESS_CERT_ID) | 
					
						
							| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  | IMPLEMENT_ASN1_DUP_FUNCTION(ESS_CERT_ID) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASN1_SEQUENCE(ESS_SIGNING_CERT) = { | 
					
						
							|  |  |  |         ASN1_SEQUENCE_OF(ESS_SIGNING_CERT, cert_ids, ESS_CERT_ID), | 
					
						
							|  |  |  |         ASN1_SEQUENCE_OF_OPT(ESS_SIGNING_CERT, policy_info, POLICYINFO) | 
					
						
							|  |  |  | } static_ASN1_SEQUENCE_END(ESS_SIGNING_CERT) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 04:51:25 +08:00
										 |  |  | IMPLEMENT_ASN1_FUNCTIONS(ESS_SIGNING_CERT) | 
					
						
							| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  | IMPLEMENT_ASN1_DUP_FUNCTION(ESS_SIGNING_CERT) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASN1_SEQUENCE(ESS_CERT_ID_V2) = { | 
					
						
							|  |  |  |         ASN1_OPT(ESS_CERT_ID_V2, hash_alg, X509_ALGOR), | 
					
						
							|  |  |  |         ASN1_SIMPLE(ESS_CERT_ID_V2, hash, ASN1_OCTET_STRING), | 
					
						
							|  |  |  |         ASN1_OPT(ESS_CERT_ID_V2, issuer_serial, ESS_ISSUER_SERIAL) | 
					
						
							|  |  |  | } static_ASN1_SEQUENCE_END(ESS_CERT_ID_V2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 04:51:25 +08:00
										 |  |  | IMPLEMENT_ASN1_FUNCTIONS(ESS_CERT_ID_V2) | 
					
						
							| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  | IMPLEMENT_ASN1_DUP_FUNCTION(ESS_CERT_ID_V2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASN1_SEQUENCE(ESS_SIGNING_CERT_V2) = { | 
					
						
							|  |  |  |         ASN1_SEQUENCE_OF(ESS_SIGNING_CERT_V2, cert_ids, ESS_CERT_ID_V2), | 
					
						
							|  |  |  |         ASN1_SEQUENCE_OF_OPT(ESS_SIGNING_CERT_V2, policy_info, POLICYINFO) | 
					
						
							|  |  |  | } static_ASN1_SEQUENCE_END(ESS_SIGNING_CERT_V2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 04:51:25 +08:00
										 |  |  | IMPLEMENT_ASN1_FUNCTIONS(ESS_SIGNING_CERT_V2) | 
					
						
							| 
									
										
										
										
											2018-12-13 06:08:49 +08:00
										 |  |  | IMPLEMENT_ASN1_DUP_FUNCTION(ESS_SIGNING_CERT_V2) | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 03:24:40 +08:00
										 |  |  | /* TODO the following two functions should be moved to ../cms/ */ | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  | /* No cms support means no CMS_SignerInfo* definitions */ | 
					
						
							|  |  |  | #ifndef OPENSSL_NO_CMS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-03-16 03:24:40 +08:00
										 |  |  |  * Returns 0 if attribute is not found, 1 if found, | 
					
						
							|  |  |  |  * or -1 on attribute parsing failure. | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-03-13 02:45:40 +08:00
										 |  |  | int ossl_cms_signerinfo_get_signing_cert_v2(const CMS_SignerInfo *si, | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |                                             ESS_SIGNING_CERT_V2 **psc) | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     ASN1_STRING *str; | 
					
						
							|  |  |  |     ESS_SIGNING_CERT_V2 *sc; | 
					
						
							|  |  |  |     ASN1_OBJECT *obj = OBJ_nid2obj(NID_id_smime_aa_signingCertificateV2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (psc != NULL) | 
					
						
							|  |  |  |         *psc = NULL; | 
					
						
							|  |  |  |     str = CMS_signed_get0_data_by_OBJ(si, obj, -3, V_ASN1_SEQUENCE); | 
					
						
							|  |  |  |     if (str == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sc = ASN1_item_unpack(str, ASN1_ITEM_rptr(ESS_SIGNING_CERT_V2)); | 
					
						
							|  |  |  |     if (sc == NULL) | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     if (psc != NULL) | 
					
						
							|  |  |  |         *psc = sc; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         ESS_SIGNING_CERT_V2_free(sc); | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-03-16 03:24:40 +08:00
										 |  |  |  * Returns 0 if attribute is not found, 1 if found, | 
					
						
							|  |  |  |  * or -1 on attribute parsing failure. | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-03-13 02:45:40 +08:00
										 |  |  | int ossl_cms_signerinfo_get_signing_cert(const CMS_SignerInfo *si, | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |                                          ESS_SIGNING_CERT **psc) | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     ASN1_STRING *str; | 
					
						
							|  |  |  |     ESS_SIGNING_CERT *sc; | 
					
						
							|  |  |  |     ASN1_OBJECT *obj = OBJ_nid2obj(NID_id_smime_aa_signingCertificate); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (psc != NULL) | 
					
						
							|  |  |  |         *psc = NULL; | 
					
						
							|  |  |  |     str = CMS_signed_get0_data_by_OBJ(si, obj, -3, V_ASN1_SEQUENCE); | 
					
						
							|  |  |  |     if (str == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sc = ASN1_item_unpack(str, ASN1_ITEM_rptr(ESS_SIGNING_CERT)); | 
					
						
							|  |  |  |     if (sc == NULL) | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     if (psc != NULL) | 
					
						
							|  |  |  |         *psc = sc; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         ESS_SIGNING_CERT_free(sc); | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif  /* !OPENSSL_NO_CMS */
 |