2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2020-10-15 14:10:06 +01:00
|
|
|
* Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2008-03-12 21:14:28 +00:00
|
|
|
*
|
2018-12-06 13:32:50 +01:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 14:52:22 -04: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-12 21:14:28 +00:00
|
|
|
*/
|
|
|
|
|
2015-05-14 16:56:48 +02:00
|
|
|
#include "internal/cryptlib.h"
|
2008-03-12 21:14:28 +00:00
|
|
|
#include <openssl/asn1t.h>
|
|
|
|
#include <openssl/pem.h>
|
|
|
|
#include <openssl/x509v3.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#include <openssl/cms.h>
|
|
|
|
#include <openssl/bio.h>
|
2016-03-18 14:30:20 -04:00
|
|
|
#include <openssl/comp.h>
|
2019-09-28 00:45:40 +02:00
|
|
|
#include "cms_local.h"
|
2008-03-12 21:14:28 +00:00
|
|
|
|
|
|
|
#ifdef ZLIB
|
|
|
|
|
|
|
|
/* CMS CompressedData Utilities */
|
|
|
|
|
2020-10-15 12:55:50 +03:00
|
|
|
CMS_ContentInfo *cms_CompressedData_create(int comp_nid, OSSL_LIB_CTX *libctx,
|
2020-07-25 18:04:55 +10:00
|
|
|
const char *propq)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
CMS_ContentInfo *cms;
|
|
|
|
CMS_CompressedData *cd;
|
2020-07-25 18:04:55 +10:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* Will need something cleverer if there is ever more than one
|
|
|
|
* compression algorithm or parameters have some meaning...
|
|
|
|
*/
|
|
|
|
if (comp_nid != NID_zlib_compression) {
|
|
|
|
CMSerr(CMS_F_CMS_COMPRESSEDDATA_CREATE,
|
|
|
|
CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-09-24 10:42:23 +01:00
|
|
|
cms = CMS_ContentInfo_new_ex(libctx, propq);
|
2015-10-30 11:12:26 +00:00
|
|
|
if (cms == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
return NULL;
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
cd = M_ASN1_new_of(CMS_CompressedData);
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2015-10-30 11:12:26 +00:00
|
|
|
if (cd == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData);
|
|
|
|
cms->d.compressedData = cd;
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
cd->version = 0;
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
X509_ALGOR_set0(cd->compressionAlgorithm,
|
|
|
|
OBJ_nid2obj(NID_zlib_compression), V_ASN1_UNDEF, NULL);
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
return cms;
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
err:
|
2015-05-01 14:37:16 -04:00
|
|
|
CMS_ContentInfo_free(cms);
|
2015-01-22 03:40:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-03-12 21:14:28 +00:00
|
|
|
|
2019-03-07 14:14:30 +00:00
|
|
|
BIO *cms_CompressedData_init_bio(const CMS_ContentInfo *cms)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
CMS_CompressedData *cd;
|
2016-08-20 00:12:16 +01:00
|
|
|
const ASN1_OBJECT *compoid;
|
2020-07-25 18:04:55 +10:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_compressedData) {
|
|
|
|
CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO,
|
|
|
|
CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
cd = cms->d.compressedData;
|
|
|
|
X509_ALGOR_get0(&compoid, NULL, NULL, cd->compressionAlgorithm);
|
|
|
|
if (OBJ_obj2nid(compoid) != NID_zlib_compression) {
|
|
|
|
CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO,
|
|
|
|
CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return BIO_new(BIO_f_zlib());
|
|
|
|
}
|
2008-03-12 21:14:28 +00:00
|
|
|
|
|
|
|
#endif
|