]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
fecb3aae | 2 | * Copyright 2008-2022 The OpenSSL Project Authors. All Rights Reserved. |
8931b30d | 3 | * |
08ddd302 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8931b30d DSH |
8 | */ |
9 | ||
b39fc560 | 10 | #include "internal/cryptlib.h" |
8931b30d DSH |
11 | #include <openssl/asn1t.h> |
12 | #include <openssl/pem.h> | |
13 | #include <openssl/x509v3.h> | |
14 | #include <openssl/err.h> | |
15 | #include <openssl/cms.h> | |
16 | #include <openssl/bio.h> | |
3c27208f | 17 | #include <openssl/comp.h> |
706457b7 | 18 | #include "cms_local.h" |
8931b30d | 19 | |
59d21298 | 20 | #ifndef OPENSSL_NO_ZLIB |
8931b30d DSH |
21 | |
22 | /* CMS CompressedData Utilities */ | |
23 | ||
53155f1c SL |
24 | CMS_ContentInfo *ossl_cms_CompressedData_create(int comp_nid, |
25 | OSSL_LIB_CTX *libctx, | |
26 | const char *propq) | |
0f113f3e MC |
27 | { |
28 | CMS_ContentInfo *cms; | |
29 | CMS_CompressedData *cd; | |
c1669f41 | 30 | |
0f113f3e MC |
31 | /* |
32 | * Will need something cleverer if there is ever more than one | |
33 | * compression algorithm or parameters have some meaning... | |
34 | */ | |
35 | if (comp_nid != NID_zlib_compression) { | |
9311d0c4 | 36 | ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); |
0f113f3e MC |
37 | return NULL; |
38 | } | |
d8652be0 | 39 | cms = CMS_ContentInfo_new_ex(libctx, propq); |
90945fa3 | 40 | if (cms == NULL) |
0f113f3e | 41 | return NULL; |
8931b30d | 42 | |
0f113f3e | 43 | cd = M_ASN1_new_of(CMS_CompressedData); |
8931b30d | 44 | |
90945fa3 | 45 | if (cd == NULL) |
0f113f3e | 46 | goto err; |
8931b30d | 47 | |
0f113f3e MC |
48 | cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData); |
49 | cms->d.compressedData = cd; | |
8931b30d | 50 | |
0f113f3e | 51 | cd->version = 0; |
8931b30d | 52 | |
04bc3c12 DDO |
53 | (void)X509_ALGOR_set0(cd->compressionAlgorithm, |
54 | OBJ_nid2obj(NID_zlib_compression), | |
55 | V_ASN1_UNDEF, NULL); /* cannot fail */ | |
8931b30d | 56 | |
0f113f3e | 57 | cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); |
8931b30d | 58 | |
0f113f3e | 59 | return cms; |
8931b30d | 60 | |
0f113f3e | 61 | err: |
25aaa98a | 62 | CMS_ContentInfo_free(cms); |
0f113f3e MC |
63 | return NULL; |
64 | } | |
8931b30d | 65 | |
53155f1c | 66 | BIO *ossl_cms_CompressedData_init_bio(const CMS_ContentInfo *cms) |
0f113f3e MC |
67 | { |
68 | CMS_CompressedData *cd; | |
5dfd0381 | 69 | const ASN1_OBJECT *compoid; |
c1669f41 | 70 | |
0f113f3e | 71 | if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_compressedData) { |
9311d0c4 | 72 | ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA); |
0f113f3e MC |
73 | return NULL; |
74 | } | |
75 | cd = cms->d.compressedData; | |
76 | X509_ALGOR_get0(&compoid, NULL, NULL, cd->compressionAlgorithm); | |
77 | if (OBJ_obj2nid(compoid) != NID_zlib_compression) { | |
9311d0c4 | 78 | ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); |
0f113f3e MC |
79 | return NULL; |
80 | } | |
81 | return BIO_new(BIO_f_zlib()); | |
82 | } | |
8931b30d DSH |
83 | |
84 | #endif |