| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-01-28 20:54:57 +08:00
										 |  |  |  * Copyright 2008-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 20:32:50 +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
 | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-14 22:56:48 +08:00
										 |  |  | #include "internal/cryptlib.h"
 | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | #include <openssl/asn1t.h>
 | 
					
						
							|  |  |  | #include <openssl/x509.h>
 | 
					
						
							|  |  |  | #include <openssl/x509v3.h>
 | 
					
						
							|  |  |  | #include <openssl/err.h>
 | 
					
						
							|  |  |  | #include <openssl/cms.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:40 +08:00
										 |  |  | #include "cms_local.h"
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:33 +08:00
										 |  |  | #include "crypto/asn1.h"
 | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-22 08:35:29 +08:00
										 |  |  | static BIO *cms_get_text_bio(BIO *out, unsigned int flags) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     BIO *rbio; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (out == NULL) | 
					
						
							|  |  |  |         rbio = BIO_new(BIO_s_null()); | 
					
						
							|  |  |  |     else if (flags & CMS_TEXT) { | 
					
						
							|  |  |  |         rbio = BIO_new(BIO_s_mem()); | 
					
						
							|  |  |  |         BIO_set_mem_eof_return(rbio, 0); | 
					
						
							|  |  |  |     } else | 
					
						
							|  |  |  |         rbio = out; | 
					
						
							|  |  |  |     return rbio; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-22 08:35:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int cms_copy_content(BIO *out, BIO *in, unsigned int flags) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     unsigned char buf[4096]; | 
					
						
							|  |  |  |     int r = 0, i; | 
					
						
							|  |  |  |     BIO *tmpout; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     tmpout = cms_get_text_bio(out, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (tmpout == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Read all content through chain to process digest, decrypt etc */ | 
					
						
							|  |  |  |     for (;;) { | 
					
						
							|  |  |  |         i = BIO_read(in, buf, sizeof(buf)); | 
					
						
							|  |  |  |         if (i <= 0) { | 
					
						
							|  |  |  |             if (BIO_method_type(in) == BIO_TYPE_CIPHER) { | 
					
						
							|  |  |  |                 if (!BIO_get_cipher_status(in)) | 
					
						
							|  |  |  |                     goto err; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (i < 0) | 
					
						
							|  |  |  |                 goto err; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |         if (tmpout != NULL && (BIO_write(tmpout, buf, i) != i)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (flags & CMS_TEXT) { | 
					
						
							|  |  |  |         if (!SMIME_text(tmpout, out)) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |             ERR_raise(ERR_LIB_CMS, CMS_R_SMIME_TEXT_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto err; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     r = 1; | 
					
						
							|  |  |  |  err: | 
					
						
							| 
									
										
										
										
											2015-03-25 23:31:18 +08:00
										 |  |  |     if (tmpout != out) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         BIO_free(tmpout); | 
					
						
							|  |  |  |     return r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-16 07:21:33 +08:00
										 |  |  | static int check_content(CMS_ContentInfo *cms) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     ASN1_OCTET_STRING **pos = CMS_get0_content(cms); | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (pos == NULL || *pos == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_NO_CONTENT); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-16 07:21:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-12 07:45:52 +08:00
										 |  |  | static void do_free_upto(BIO *f, BIO *upto) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  |     if (upto != NULL) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         BIO *tbio; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         do { | 
					
						
							|  |  |  |             tbio = BIO_pop(f); | 
					
						
							|  |  |  |             BIO_free(f); | 
					
						
							|  |  |  |             f = tbio; | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  |         } while (f != NULL && f != upto); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         BIO_free_all(f); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-04-12 07:45:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     BIO *cont; | 
					
						
							|  |  |  |     int r; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_data) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_DATA); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     cont = CMS_dataInit(cms, NULL); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cont == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     r = cms_copy_content(out, cont, flags); | 
					
						
							|  |  |  |     BIO_free_all(cont); | 
					
						
							|  |  |  |     return r; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  | CMS_ContentInfo *CMS_data_create_ex(BIO *in, unsigned int flags, | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |                                     OSSL_LIB_CTX *libctx, const char *propq) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     CMS_ContentInfo *cms = ossl_cms_Data_create(libctx, propq); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (cms == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) | 
					
						
							|  |  |  |         return cms; | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     CMS_ContentInfo_free(cms); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |     return CMS_data_create_ex(in, flags, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                       unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     BIO *cont; | 
					
						
							|  |  |  |     int r; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_digest) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_DIGESTED_DATA); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (dcont == NULL && !check_content(cms)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cont = CMS_dataInit(cms, dcont); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cont == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     r = cms_copy_content(out, cont, flags); | 
					
						
							|  |  |  |     if (r) | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |         r = ossl_cms_DigestedData_do_final(cms, cont, 1); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     do_free_upto(cont, dcont); | 
					
						
							|  |  |  |     return r; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  | CMS_ContentInfo *CMS_digest_create_ex(BIO *in, const EVP_MD *md, | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |                                       unsigned int flags, OSSL_LIB_CTX *ctx, | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |                                       const char *propq) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     CMS_ContentInfo *cms; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 08:33:59 +08:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * Because the EVP_MD is cached and can be a legacy algorithm, we | 
					
						
							|  |  |  |      * cannot fetch the algorithm if it isn't supplied. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (md == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         md = EVP_sha1(); | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     cms = ossl_cms_DigestedData_create(md, ctx, propq); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cms == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (!(flags & CMS_DETACHED)) | 
					
						
							|  |  |  |         CMS_set_detached(cms, 0); | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) | 
					
						
							|  |  |  |         return cms; | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     CMS_ContentInfo_free(cms); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, | 
					
						
							|  |  |  |                                    unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |     return CMS_digest_create_ex(in, md, flags, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-14 21:21:48 +08:00
										 |  |  | int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                               const unsigned char *key, size_t keylen, | 
					
						
							|  |  |  |                               BIO *dcont, BIO *out, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     BIO *cont; | 
					
						
							|  |  |  |     int r; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_encrypted) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_ENCRYPTED_DATA); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (dcont == NULL && !check_content(cms)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (CMS_EncryptedData_set1_key(cms, NULL, key, keylen) <= 0) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     cont = CMS_dataInit(cms, dcont); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cont == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     r = cms_copy_content(out, cont, flags); | 
					
						
							|  |  |  |     do_free_upto(cont, dcont); | 
					
						
							|  |  |  |     return r; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-14 21:21:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  | CMS_ContentInfo *CMS_EncryptedData_encrypt_ex(BIO *in, const EVP_CIPHER *cipher, | 
					
						
							|  |  |  |                                               const unsigned char *key, | 
					
						
							|  |  |  |                                               size_t keylen, unsigned int flags, | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |                                               OSSL_LIB_CTX *libctx, | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |                                               const char *propq) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     CMS_ContentInfo *cms; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (cipher == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_NO_CIPHER); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |     cms = CMS_ContentInfo_new_ex(libctx, propq); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (cms == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |     if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!(flags & CMS_DETACHED)) | 
					
						
							|  |  |  |         CMS_set_detached(cms, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((flags & (CMS_STREAM | CMS_PARTIAL)) | 
					
						
							|  |  |  |         || CMS_final(cms, in, NULL, flags)) | 
					
						
							|  |  |  |         return cms; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CMS_ContentInfo_free(cms); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-15 03:37:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, | 
					
						
							|  |  |  |                                            const unsigned char *key, | 
					
						
							|  |  |  |                                            size_t keylen, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |     return CMS_EncryptedData_encrypt_ex(in, cipher, key, keylen, flags, NULL, | 
					
						
							|  |  |  |                                         NULL); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | static int cms_signerinfo_verify_cert(CMS_SignerInfo *si, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                                       X509_STORE *store, | 
					
						
							|  |  |  |                                       STACK_OF(X509) *certs, | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |                                       STACK_OF(X509_CRL) *crls, | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |                                       STACK_OF(X509) **chain, | 
					
						
							|  |  |  |                                       const CMS_CTX *cms_ctx) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     X509_STORE_CTX *ctx; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     X509 *signer; | 
					
						
							|  |  |  |     int i, j, r = 0; | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     ctx = X509_STORE_CTX_new_ex(ossl_cms_ctx_get0_libctx(cms_ctx), | 
					
						
							|  |  |  |                                 ossl_cms_ctx_get0_propq(cms_ctx)); | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     if (ctx == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     if (!X509_STORE_CTX_init(ctx, store, signer, certs)) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_STORE_INIT_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     X509_STORE_CTX_set_default(ctx, "smime_sign"); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (crls != NULL) | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |         X509_STORE_CTX_set0_crls(ctx, crls); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     i = X509_verify_cert(ctx); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (i <= 0) { | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |         j = X509_STORE_CTX_get_error(ctx); | 
					
						
							| 
									
										
										
										
											2020-11-04 23:14:00 +08:00
										 |  |  |         ERR_raise_data(ERR_LIB_CMS, CMS_R_CERTIFICATE_VERIFY_ERROR, | 
					
						
							|  |  |  |                        "Verify error: %s", X509_verify_cert_error_string(j)); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     r = 1; | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* also send back the trust chain when required */ | 
					
						
							|  |  |  |     if (chain != NULL) | 
					
						
							|  |  |  |         *chain = X509_STORE_CTX_get1_chain(ctx); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |  err: | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     X509_STORE_CTX_free(ctx); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     CMS_SignerInfo *si; | 
					
						
							|  |  |  |     STACK_OF(CMS_SignerInfo) *sinfos; | 
					
						
							|  |  |  |     STACK_OF(X509) *cms_certs = NULL; | 
					
						
							|  |  |  |     STACK_OF(X509_CRL) *crls = NULL; | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |     STACK_OF(X509) **si_chains = NULL; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     X509 *signer; | 
					
						
							|  |  |  |     int i, scount = 0, ret = 0; | 
					
						
							|  |  |  |     BIO *cmsbio = NULL, *tmpin = NULL, *tmpout = NULL; | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |     int cadesVerify = (flags & CMS_CADES) != 0; | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (dcont == NULL && !check_content(cms)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (dcont != NULL && !(flags & CMS_BINARY)) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         const ASN1_OBJECT *coid = CMS_get0_eContentType(cms); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         if (OBJ_obj2nid(coid) == NID_id_ct_asciiTextWithCRLF) | 
					
						
							|  |  |  |             flags |= CMS_ASCIICRLF; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Attempt to find all signer certificates */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sinfos = CMS_get0_SignerInfos(cms); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (sk_CMS_SignerInfo_num(sinfos) <= 0) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_NO_SIGNERS); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { | 
					
						
							|  |  |  |         si = sk_CMS_SignerInfo_value(sinfos, i); | 
					
						
							|  |  |  |         CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL); | 
					
						
							|  |  |  |         if (signer) | 
					
						
							|  |  |  |             scount++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (scount != sk_CMS_SignerInfo_num(sinfos)) | 
					
						
							|  |  |  |         scount += CMS_set1_signers_certs(cms, certs, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (scount != sk_CMS_SignerInfo_num(sinfos)) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_SIGNER_CERTIFICATE_NOT_FOUND); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Attempt to verify all signers certs */ | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |     /* at this point scount == sk_CMS_SignerInfo_num(sinfos) */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((flags & CMS_NO_SIGNER_CERT_VERIFY) == 0 || cadesVerify) { | 
					
						
							|  |  |  |         if (cadesVerify) { | 
					
						
							|  |  |  |             /* Certificate trust chain is required to check CAdES signature */ | 
					
						
							|  |  |  |             si_chains = OPENSSL_zalloc(scount * sizeof(si_chains[0])); | 
					
						
							|  |  |  |             if (si_chains == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |                 ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |                 goto err; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         cms_certs = CMS_get1_certs(cms); | 
					
						
							|  |  |  |         if (!(flags & CMS_NOCRL)) | 
					
						
							|  |  |  |             crls = CMS_get1_crls(cms); | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |         for (i = 0; i < scount; i++) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             si = sk_CMS_SignerInfo_value(sinfos, i); | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (!cms_signerinfo_verify_cert(si, store, cms_certs, crls, | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |                                             si_chains ? &si_chains[i] : NULL, | 
					
						
							|  |  |  |                                             ctx)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 goto err; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Attempt to verify all SignerInfo signed attribute signatures */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |     if ((flags & CMS_NO_ATTR_VERIFY) == 0 || cadesVerify) { | 
					
						
							|  |  |  |         for (i = 0; i < scount; i++) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             si = sk_CMS_SignerInfo_value(sinfos, i); | 
					
						
							|  |  |  |             if (CMS_signed_get_attr_count(si) < 0) | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             if (CMS_SignerInfo_verify(si) <= 0) | 
					
						
							|  |  |  |                 goto err; | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |             if (cadesVerify) { | 
					
						
							|  |  |  |                 STACK_OF(X509) *si_chain = si_chains ? si_chains[i] : NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-13 02:45:40 +08:00
										 |  |  |                 if (ossl_cms_check_signing_certs(si, si_chain) <= 0) | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |                     goto err; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * Performance optimization: if the content is a memory BIO then store | 
					
						
							|  |  |  |      * its contents in a temporary read only memory BIO. This avoids | 
					
						
							|  |  |  |      * potentially large numbers of slow copies of data which will occur when | 
					
						
							|  |  |  |      * reading from a read write memory BIO when signatures are calculated. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (dcont != NULL && (BIO_method_type(dcont) == BIO_TYPE_MEM)) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         char *ptr; | 
					
						
							|  |  |  |         long len; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         len = BIO_get_mem_data(dcont, &ptr); | 
					
						
							| 
									
										
										
										
											2020-10-07 18:23:01 +08:00
										 |  |  |         tmpin = (len == 0) ? dcont : BIO_new_mem_buf(ptr, len); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         if (tmpin == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |             ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); | 
					
						
							| 
									
										
										
										
											2015-06-22 03:37:53 +08:00
										 |  |  |             goto err2; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         tmpin = dcont; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * If not binary mode and detached generate digests by *writing* through | 
					
						
							|  |  |  |      * the BIO. That makes it possible to canonicalise the input. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (!(flags & SMIME_BINARY) && dcont) { | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |          * Create output BIO so we can either handle text or to ensure | 
					
						
							|  |  |  |          * included content doesn't override detached content. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         tmpout = cms_get_text_bio(out, flags); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |         if (tmpout == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |             ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto err; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         cmsbio = CMS_dataInit(cms, tmpout); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |         if (cmsbio == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto err; | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |          * Don't use SMIME_TEXT for verify: it adds headers and we want to | 
					
						
							|  |  |  |          * remove them. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         SMIME_crlf_copy(dcont, cmsbio, flags & ~SMIME_TEXT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (flags & CMS_TEXT) { | 
					
						
							|  |  |  |             if (!SMIME_text(tmpout, out)) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |                 ERR_raise(ERR_LIB_CMS, CMS_R_SMIME_TEXT_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 goto err; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         cmsbio = CMS_dataInit(cms, tmpin); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |         if (cmsbio == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!cms_copy_content(out, cmsbio, flags)) | 
					
						
							|  |  |  |             goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!(flags & CMS_NO_CONTENT_VERIFY)) { | 
					
						
							|  |  |  |         for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { | 
					
						
							|  |  |  |             si = sk_CMS_SignerInfo_value(sinfos, i); | 
					
						
							|  |  |  |             if (CMS_SignerInfo_verify_content(si, cmsbio) <= 0) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |                 ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_VERIFY_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 goto err; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ret = 1; | 
					
						
							|  |  |  |  err: | 
					
						
							|  |  |  |     if (!(flags & SMIME_BINARY) && dcont) { | 
					
						
							|  |  |  |         do_free_upto(cmsbio, tmpout); | 
					
						
							|  |  |  |         if (tmpin != dcont) | 
					
						
							|  |  |  |             BIO_free(tmpin); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         if (dcont && (tmpin == dcont)) | 
					
						
							|  |  |  |             do_free_upto(cmsbio, dcont); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             BIO_free_all(cmsbio); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 23:31:18 +08:00
										 |  |  |     if (out != tmpout) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         BIO_free_all(tmpout); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 03:37:53 +08:00
										 |  |  |  err2: | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |     if (si_chains != NULL) { | 
					
						
							|  |  |  |         for (i = 0; i < scount; ++i) | 
					
						
							| 
									
										
										
										
											2021-12-18 23:15:49 +08:00
										 |  |  |             OSSL_STACK_OF_X509_free(si_chains[i]); | 
					
						
							| 
									
										
										
										
											2019-06-13 01:52:39 +08:00
										 |  |  |         OPENSSL_free(si_chains); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-18 23:15:49 +08:00
										 |  |  |     OSSL_STACK_OF_X509_free(cms_certs); | 
					
						
							| 
									
										
										
										
											2015-05-01 05:33:59 +08:00
										 |  |  |     sk_X509_CRL_pop_free(crls, X509_CRL_free); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-28 21:15:39 +08:00
										 |  |  | int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                        STACK_OF(X509) *certs, | 
					
						
							|  |  |  |                        X509_STORE *store, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int r; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     flags &= ~(CMS_DETACHED | CMS_TEXT); | 
					
						
							|  |  |  |     r = CMS_verify(rcms, certs, store, NULL, NULL, flags); | 
					
						
							|  |  |  |     if (r <= 0) | 
					
						
							|  |  |  |         return r; | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     return ossl_cms_Receipt_verify(rcms, ocms); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  | CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey, | 
					
						
							|  |  |  |                              STACK_OF(X509) *certs, BIO *data, | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |                              unsigned int flags, OSSL_LIB_CTX *libctx, | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |                              const char *propq) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     CMS_ContentInfo *cms; | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |     cms = CMS_ContentInfo_new_ex(libctx, propq); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (cms == NULL || !CMS_SignedData_init(cms)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto merr; | 
					
						
							|  |  |  |     if (flags & CMS_ASCIICRLF | 
					
						
							|  |  |  |         && !CMS_set1_eContentType(cms, | 
					
						
							|  |  |  |                                   OBJ_nid2obj(NID_id_ct_asciiTextWithCRLF))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (pkey != NULL && !CMS_add1_signer(cms, signcert, pkey, NULL, flags)) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_ADD_SIGNER_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < sk_X509_num(certs); i++) { | 
					
						
							|  |  |  |         X509 *x = sk_X509_value(certs, i); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         if (!CMS_add1_cert(cms, x)) | 
					
						
							|  |  |  |             goto merr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!(flags & CMS_DETACHED)) | 
					
						
							|  |  |  |         CMS_set_detached(cms, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((flags & (CMS_STREAM | CMS_PARTIAL)) | 
					
						
							|  |  |  |         || CMS_final(cms, data, NULL, flags)) | 
					
						
							|  |  |  |         return cms; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  merr: | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |     ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |  err: | 
					
						
							| 
									
										
										
										
											2015-05-02 02:37:16 +08:00
										 |  |  |     CMS_ContentInfo_free(cms); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, | 
					
						
							|  |  |  |                           BIO *data, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |     return CMS_sign_ex(signcert, pkey, certs, data, flags, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-29 03:43:16 +08:00
										 |  |  | CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                                   X509 *signcert, EVP_PKEY *pkey, | 
					
						
							|  |  |  |                                   STACK_OF(X509) *certs, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     CMS_SignerInfo *rct_si; | 
					
						
							|  |  |  |     CMS_ContentInfo *cms = NULL; | 
					
						
							|  |  |  |     ASN1_OCTET_STRING **pos, *os; | 
					
						
							|  |  |  |     BIO *rct_cont = NULL; | 
					
						
							|  |  |  |     int r = 0; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     const CMS_CTX *ctx = si->cms_ctx; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     flags &= ~(CMS_STREAM | CMS_TEXT); | 
					
						
							|  |  |  |     /* Not really detached but avoids content being allocated */ | 
					
						
							|  |  |  |     flags |= CMS_PARTIAL | CMS_BINARY | CMS_DETACHED; | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  |     if (pkey == NULL || signcert == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_NO_KEY_OR_CERT); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Initialize signed data */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     cms = CMS_sign_ex(NULL, NULL, certs, NULL, flags, | 
					
						
							|  |  |  |                       ossl_cms_ctx_get0_libctx(ctx), | 
					
						
							|  |  |  |                       ossl_cms_ctx_get0_propq(ctx)); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cms == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Set inner content type to signed receipt */ | 
					
						
							|  |  |  |     if (!CMS_set1_eContentType(cms, OBJ_nid2obj(NID_id_smime_ct_receipt))) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rct_si = CMS_add1_signer(cms, signcert, pkey, NULL, flags); | 
					
						
							|  |  |  |     if (!rct_si) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_ADD_SIGNER_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     os = ossl_cms_encode_Receipt(si); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (os == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Set content to digest */ | 
					
						
							|  |  |  |     rct_cont = BIO_new_mem_buf(os->data, os->length); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (rct_cont == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Add msgSigDigest attribute */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     if (!ossl_cms_msgSigDigest_add1(rct_si, si)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Finalize structure */ | 
					
						
							|  |  |  |     if (!CMS_final(cms, rct_cont, NULL, flags)) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Set embedded content */ | 
					
						
							|  |  |  |     pos = CMS_get0_content(cms); | 
					
						
							| 
									
										
										
										
											2021-11-11 04:49:49 +08:00
										 |  |  |     if (pos == NULL) | 
					
						
							|  |  |  |         goto err; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     *pos = os; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     r = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  err: | 
					
						
							| 
									
										
										
										
											2015-03-25 23:31:18 +08:00
										 |  |  |     BIO_free(rct_cont); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (r) | 
					
						
							|  |  |  |         return cms; | 
					
						
							|  |  |  |     CMS_ContentInfo_free(cms); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-29 03:43:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  | CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *data, | 
					
						
							|  |  |  |                                 const EVP_CIPHER *cipher, unsigned int flags, | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |                                 OSSL_LIB_CTX *libctx, const char *propq) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     CMS_ContentInfo *cms; | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  |     X509 *recip; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 02:11:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
											
										 
											2021-05-21 22:58:08 +08:00
										 |  |  |     cms = (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |           ? CMS_AuthEnvelopedData_create_ex(cipher, libctx, propq) | 
					
						
							|  |  |  |           : CMS_EnvelopedData_create_ex(cipher, libctx, propq); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cms == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto merr; | 
					
						
							|  |  |  |     for (i = 0; i < sk_X509_num(certs); i++) { | 
					
						
							|  |  |  |         recip = sk_X509_value(certs, i); | 
					
						
							|  |  |  |         if (!CMS_add1_recipient_cert(cms, recip, flags)) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |             ERR_raise(ERR_LIB_CMS, CMS_R_RECIPIENT_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto err; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!(flags & CMS_DETACHED)) | 
					
						
							|  |  |  |         CMS_set_detached(cms, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((flags & (CMS_STREAM | CMS_PARTIAL)) | 
					
						
							|  |  |  |         || CMS_final(cms, data, NULL, flags)) | 
					
						
							|  |  |  |         return cms; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  merr: | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |     ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |  err: | 
					
						
							| 
									
										
										
										
											2015-05-02 02:37:16 +08:00
										 |  |  |     CMS_ContentInfo_free(cms); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-20 02:39:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data, | 
					
						
							|  |  |  |                              const EVP_CIPHER *cipher, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |     return CMS_encrypt_ex(certs, data, cipher, flags, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int cms_kari_set1_pkey_and_peer(CMS_ContentInfo *cms, | 
					
						
							|  |  |  |                                        CMS_RecipientInfo *ri, | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |                                        EVP_PKEY *pk, X509 *cert, X509 *peer) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  |     STACK_OF(CMS_RecipientEncryptedKey) *reks; | 
					
						
							|  |  |  |     CMS_RecipientEncryptedKey *rek; | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     reks = CMS_RecipientInfo_kari_get0_reks(ri); | 
					
						
							|  |  |  |     for (i = 0; i < sk_CMS_RecipientEncryptedKey_num(reks); i++) { | 
					
						
							|  |  |  |         int rv; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         rek = sk_CMS_RecipientEncryptedKey_value(reks, i); | 
					
						
							| 
									
										
										
										
											2017-08-08 22:20:07 +08:00
										 |  |  |         if (cert != NULL && CMS_RecipientEncryptedKey_cert_cmp(rek, cert)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             continue; | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |         CMS_RecipientInfo_kari_set0_pkey_and_peer(ri, pk, peer); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         rv = CMS_RecipientInfo_kari_decrypt(cms, ri, rek); | 
					
						
							|  |  |  |         CMS_RecipientInfo_kari_set0_pkey(ri, NULL); | 
					
						
							|  |  |  |         if (rv > 0) | 
					
						
							|  |  |  |             return 1; | 
					
						
							| 
									
										
										
										
											2017-08-08 22:20:07 +08:00
										 |  |  |         return cert == NULL ? 0 : -1; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-17 21:36:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-20 02:39:51 +08:00
										 |  |  | int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert) | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  | { | 
					
						
							|  |  |  |      return CMS_decrypt_set1_pkey_and_peer(cms, pk, cert, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms, EVP_PKEY *pk, | 
					
						
							|  |  |  |                                    X509 *cert, X509 *peer) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     STACK_OF(CMS_RecipientInfo) *ris; | 
					
						
							|  |  |  |     CMS_RecipientInfo *ri; | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |     int i, r, cms_pkey_ri_type; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     int debug = 0, match_ri = 0; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     ris = CMS_get0_RecipientInfos(cms); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (ris != NULL) | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |         debug = ossl_cms_get0_env_enc_content(cms)->debug; | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     cms_pkey_ri_type = ossl_cms_pkey_get_ri_type(pk); | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |     if (cms_pkey_ri_type == CMS_RECIPINFO_NONE) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |          ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |          return 0; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) { | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |         int ri_type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         ri = sk_CMS_RecipientInfo_value(ris, i); | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |         ri_type = CMS_RecipientInfo_type(ri); | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |         if (!ossl_cms_pkey_is_ri_type_supported(pk, ri_type)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             continue; | 
					
						
							|  |  |  |         match_ri = 1; | 
					
						
							|  |  |  |         if (ri_type == CMS_RECIPINFO_AGREE) { | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |             r = cms_kari_set1_pkey_and_peer(cms, ri, pk, cert, peer); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             if (r > 0) | 
					
						
							|  |  |  |                 return 1; | 
					
						
							|  |  |  |             if (r < 0) | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |          * If we have a cert try matching RecipientInfo otherwise try them | 
					
						
							|  |  |  |          * all. | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |         else if (cert == NULL|| !CMS_RecipientInfo_ktri_cert_cmp(ri, cert)) { | 
					
						
							| 
									
										
										
										
											2018-05-01 16:29:17 +08:00
										 |  |  |             EVP_PKEY_up_ref(pk); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             CMS_RecipientInfo_set0_pkey(ri, pk); | 
					
						
							|  |  |  |             r = CMS_RecipientInfo_decrypt(cms, ri); | 
					
						
							|  |  |  |             CMS_RecipientInfo_set0_pkey(ri, NULL); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |             if (cert != NULL) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 /*
 | 
					
						
							|  |  |  |                  * If not debugging clear any error and return success to | 
					
						
							|  |  |  |                  * avoid leaking of information useful to MMA | 
					
						
							|  |  |  |                  */ | 
					
						
							|  |  |  |                 if (!debug) { | 
					
						
							|  |  |  |                     ERR_clear_error(); | 
					
						
							|  |  |  |                     return 1; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (r > 0) | 
					
						
							|  |  |  |                     return 1; | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |                 ERR_raise(ERR_LIB_CMS, CMS_R_DECRYPT_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 return 0; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             /*
 | 
					
						
							|  |  |  |              * If no cert and not debugging don't leave loop after first | 
					
						
							|  |  |  |              * successful decrypt. Always attempt to decrypt all recipients | 
					
						
							|  |  |  |              * to avoid leaking timing of a successful decrypt. | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2020-01-20 23:17:44 +08:00
										 |  |  |             else if (r > 0 && (debug || cms_pkey_ri_type != CMS_RECIPINFO_TRANS)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 return 1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-08-08 22:20:07 +08:00
										 |  |  |     /* If no cert, key transport and not debugging always return success */ | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cert == NULL | 
					
						
							|  |  |  |         && cms_pkey_ri_type == CMS_RECIPINFO_TRANS | 
					
						
							|  |  |  |         && match_ri | 
					
						
							|  |  |  |         && !debug) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         ERR_clear_error(); | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |     ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_RECIPIENT); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int CMS_decrypt_set1_key(CMS_ContentInfo *cms, | 
					
						
							|  |  |  |                          unsigned char *key, size_t keylen, | 
					
						
							| 
									
										
										
										
											2016-06-20 00:14:58 +08:00
										 |  |  |                          const unsigned char *id, size_t idlen) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     STACK_OF(CMS_RecipientInfo) *ris; | 
					
						
							|  |  |  |     CMS_RecipientInfo *ri; | 
					
						
							|  |  |  |     int i, r; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     ris = CMS_get0_RecipientInfos(cms); | 
					
						
							|  |  |  |     for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) { | 
					
						
							|  |  |  |         ri = sk_CMS_RecipientInfo_value(ris, i); | 
					
						
							|  |  |  |         if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_KEK) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |          * If we have an id try matching RecipientInfo otherwise try them | 
					
						
							|  |  |  |          * all. | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |         if (id == NULL || (CMS_RecipientInfo_kekri_id_cmp(ri, id, idlen) == 0)) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             CMS_RecipientInfo_set0_key(ri, key, keylen); | 
					
						
							|  |  |  |             r = CMS_RecipientInfo_decrypt(cms, ri); | 
					
						
							|  |  |  |             CMS_RecipientInfo_set0_key(ri, NULL, 0); | 
					
						
							|  |  |  |             if (r > 0) | 
					
						
							|  |  |  |                 return 1; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |             if (id != NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |                 ERR_raise(ERR_LIB_CMS, CMS_R_DECRYPT_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 return 0; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ERR_clear_error(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |     ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_RECIPIENT); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int CMS_decrypt_set1_password(CMS_ContentInfo *cms, | 
					
						
							|  |  |  |                               unsigned char *pass, ossl_ssize_t passlen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     STACK_OF(CMS_RecipientInfo) *ris; | 
					
						
							|  |  |  |     CMS_RecipientInfo *ri; | 
					
						
							|  |  |  |     int i, r; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     ris = CMS_get0_RecipientInfos(cms); | 
					
						
							|  |  |  |     for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) { | 
					
						
							|  |  |  |         ri = sk_CMS_RecipientInfo_value(ris, i); | 
					
						
							|  |  |  |         if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_PASS) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         CMS_RecipientInfo_set0_password(ri, pass, passlen); | 
					
						
							|  |  |  |         r = CMS_RecipientInfo_decrypt(cms, ri); | 
					
						
							|  |  |  |         CMS_RecipientInfo_set0_password(ri, NULL, 0); | 
					
						
							|  |  |  |         if (r > 0) | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |     ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_RECIPIENT); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-16 07:21:33 +08:00
										 |  |  | int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                 BIO *dcont, BIO *out, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int r; | 
					
						
							|  |  |  |     BIO *cont; | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 02:11:34 +08:00
										 |  |  |     int nid = OBJ_obj2nid(CMS_get0_type(cms)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (nid != NID_pkcs7_enveloped | 
					
						
							|  |  |  |             && nid != NID_id_smime_ct_authEnvelopedData) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_ENVELOPED_DATA); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (dcont == NULL && !check_content(cms)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     if (flags & CMS_DEBUG_DECRYPT) | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |         ossl_cms_get0_env_enc_content(cms)->debug = 1; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |         ossl_cms_get0_env_enc_content(cms)->debug = 0; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cert == NULL) | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |         ossl_cms_get0_env_enc_content(cms)->havenocert = 1; | 
					
						
							| 
									
										
										
										
											2019-09-01 06:16:28 +08:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |         ossl_cms_get0_env_enc_content(cms)->havenocert = 0; | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  |     if (pk == NULL && cert == NULL && dcont == NULL && out == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 1; | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  |     if (pk != NULL && !CMS_decrypt_set1_pkey(cms, pk, cert)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     cont = CMS_dataInit(cms, dcont); | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  |     if (cont == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     r = cms_copy_content(out, cont, flags); | 
					
						
							|  |  |  |     do_free_upto(cont, dcont); | 
					
						
							|  |  |  |     return r; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-10 19:22:14 +08:00
										 |  |  | int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     BIO *cmsbio; | 
					
						
							|  |  |  |     int ret = 0; | 
					
						
							| 
									
										
										
										
											2015-05-07 01:43:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if ((cmsbio = CMS_dataInit(cms, dcont)) == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_CMS_LIB); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     ret = SMIME_crlf_copy(data, cmsbio, flags); | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     (void)BIO_flush(cmsbio); | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (!CMS_dataFinal(cms, cmsbio)) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_CMS_DATAFINAL_ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | err: | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     do_free_upto(cmsbio, dcont); | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-28 16:54:57 +08:00
										 |  |  | int CMS_final_digest(CMS_ContentInfo *cms, | 
					
						
							|  |  |  |                      const unsigned char *md, unsigned int mdlen, | 
					
						
							|  |  |  |                      BIO *dcont, unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     BIO *cmsbio; | 
					
						
							|  |  |  |     int ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((cmsbio = CMS_dataInit(cms, dcont)) == NULL) { | 
					
						
							|  |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_CMS_LIB); | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     (void)BIO_flush(cmsbio); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!ossl_cms_DataFinal(cms, cmsbio, md, mdlen)) { | 
					
						
							|  |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_CMS_DATAFINAL_ERROR); | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ret = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err: | 
					
						
							|  |  |  |     do_free_upto(cmsbio, dcont); | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | #ifdef ZLIB
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-12 07:23:18 +08:00
										 |  |  | int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                    unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     BIO *cont; | 
					
						
							|  |  |  |     int r; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_id_smime_ct_compressedData) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_COMPRESSED_DATA); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (dcont == NULL && !check_content(cms)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cont = CMS_dataInit(cms, dcont); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cont == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     r = cms_copy_content(out, cont, flags); | 
					
						
							|  |  |  |     do_free_upto(cont, dcont); | 
					
						
							|  |  |  |     return r; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     CMS_ContentInfo *cms; | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (comp_nid <= 0) | 
					
						
							|  |  |  |         comp_nid = NID_zlib_compression; | 
					
						
							| 
									
										
										
										
											2021-02-18 12:03:25 +08:00
										 |  |  |     cms = ossl_cms_CompressedData_create(comp_nid, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2020-07-25 16:04:55 +08:00
										 |  |  |     if (cms == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (!(flags & CMS_DETACHED)) | 
					
						
							|  |  |  |         CMS_set_detached(cms, 0); | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) | 
					
						
							|  |  |  |         return cms; | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     CMS_ContentInfo_free(cms); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                    unsigned int flags) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |     ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |     ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-13 05:14:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 |