1 /* crypto/cms/cms_smime.c */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
55 #include <openssl/asn1t.h>
56 #include <openssl/x509.h>
57 #include <openssl/x509v3.h>
58 #include <openssl/err.h>
59 #include <openssl/cms.h>
61 #include "asn1_locl.h"
63 static BIO *cms_get_text_bio(BIO *out, unsigned int flags)
67 rbio = BIO_new(BIO_s_null());
68 else if (flags & CMS_TEXT)
70 rbio = BIO_new(BIO_s_mem());
71 BIO_set_mem_eof_return(rbio, 0);
78 static int cms_copy_content(BIO *out, BIO *in, unsigned int flags)
80 unsigned char buf[4096];
84 tmpout = cms_get_text_bio(out, flags);
88 CMSerr(CMS_F_CMS_COPY_CONTENT,ERR_R_MALLOC_FAILURE);
92 /* Read all content through chain to process digest, decrypt etc */
95 i=BIO_read(in,buf,sizeof(buf));
98 if (BIO_method_type(in) == BIO_TYPE_CIPHER)
100 if (!BIO_get_cipher_status(in))
108 if (tmpout && (BIO_write(tmpout, buf, i) != i))
114 if(!SMIME_text(tmpout, out))
116 CMSerr(CMS_F_CMS_COPY_CONTENT,CMS_R_SMIME_TEXT_ERROR);
124 if (tmpout && (tmpout != out))
130 static int check_content(CMS_ContentInfo *cms)
132 ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
135 CMSerr(CMS_F_CHECK_CONTENT, CMS_R_NO_CONTENT);
141 static void do_free_upto(BIO *f, BIO *upto)
152 while (f && f != upto);
158 int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags)
162 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_data)
164 CMSerr(CMS_F_CMS_DATA, CMS_R_TYPE_NOT_DATA);
167 cont = CMS_dataInit(cms, NULL);
170 r = cms_copy_content(out, cont, flags);
175 CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags)
177 CMS_ContentInfo *cms;
178 cms = cms_Data_create();
182 if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
185 CMS_ContentInfo_free(cms);
190 int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
195 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_digest)
197 CMSerr(CMS_F_CMS_DIGEST_VERIFY, CMS_R_TYPE_NOT_DIGESTED_DATA);
201 if (!dcont && !check_content(cms))
204 cont = CMS_dataInit(cms, dcont);
207 r = cms_copy_content(out, cont, flags);
209 r = cms_DigestedData_do_final(cms, cont, 1);
210 do_free_upto(cont, dcont);
214 CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,
217 CMS_ContentInfo *cms;
220 cms = cms_DigestedData_create(md);
224 if(!(flags & CMS_DETACHED))
225 CMS_set_detached(cms, 0);
227 if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
230 CMS_ContentInfo_free(cms);
234 int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms,
235 const unsigned char *key, size_t keylen,
236 BIO *dcont, BIO *out, unsigned int flags)
240 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_encrypted)
242 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_DECRYPT,
243 CMS_R_TYPE_NOT_ENCRYPTED_DATA);
247 if (!dcont && !check_content(cms))
250 if (CMS_EncryptedData_set1_key(cms, NULL, key, keylen) <= 0)
252 cont = CMS_dataInit(cms, dcont);
255 r = cms_copy_content(out, cont, flags);
256 do_free_upto(cont, dcont);
260 CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
261 const unsigned char *key, size_t keylen,
264 CMS_ContentInfo *cms;
267 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER);
270 cms = CMS_ContentInfo_new();
273 if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen))
276 if(!(flags & CMS_DETACHED))
277 CMS_set_detached(cms, 0);
279 if ((flags & (CMS_STREAM|CMS_PARTIAL))
280 || CMS_final(cms, in, NULL, flags))
283 CMS_ContentInfo_free(cms);
287 static int cms_signerinfo_verify_cert(CMS_SignerInfo *si,
289 STACK_OF(X509) *certs,
290 STACK_OF(X509_CRL) *crls,
296 CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
297 if (!X509_STORE_CTX_init(&ctx, store, signer, certs))
299 CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT,
300 CMS_R_STORE_INIT_ERROR);
303 X509_STORE_CTX_set_default(&ctx, "smime_sign");
305 X509_STORE_CTX_set0_crls(&ctx, crls);
307 i = X509_verify_cert(&ctx);
310 j = X509_STORE_CTX_get_error(&ctx);
311 CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT,
312 CMS_R_CERTIFICATE_VERIFY_ERROR);
313 ERR_add_error_data(2, "Verify error:",
314 X509_verify_cert_error_string(j));
319 X509_STORE_CTX_cleanup(&ctx);
324 int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
325 X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags)
328 STACK_OF(CMS_SignerInfo) *sinfos;
329 STACK_OF(X509) *cms_certs = NULL;
330 STACK_OF(X509_CRL) *crls = NULL;
332 int i, scount = 0, ret = 0;
333 BIO *cmsbio = NULL, *tmpin = NULL, *tmpout = NULL;
335 if (!dcont && !check_content(cms))
337 if (dcont && !(flags & CMS_BINARY))
339 const ASN1_OBJECT *coid = CMS_get0_eContentType(cms);
340 if (OBJ_obj2nid(coid) == NID_id_ct_asciiTextWithCRLF)
341 flags |= CMS_ASCIICRLF;
344 /* Attempt to find all signer certificates */
346 sinfos = CMS_get0_SignerInfos(cms);
348 if (sk_CMS_SignerInfo_num(sinfos) <= 0)
350 CMSerr(CMS_F_CMS_VERIFY, CMS_R_NO_SIGNERS);
354 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
356 si = sk_CMS_SignerInfo_value(sinfos, i);
357 CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
362 if (scount != sk_CMS_SignerInfo_num(sinfos))
363 scount += CMS_set1_signers_certs(cms, certs, flags);
365 if (scount != sk_CMS_SignerInfo_num(sinfos))
367 CMSerr(CMS_F_CMS_VERIFY, CMS_R_SIGNER_CERTIFICATE_NOT_FOUND);
371 /* Attempt to verify all signers certs */
373 if (!(flags & CMS_NO_SIGNER_CERT_VERIFY))
375 cms_certs = CMS_get1_certs(cms);
376 if (!(flags & CMS_NOCRL))
377 crls = CMS_get1_crls(cms);
378 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
380 si = sk_CMS_SignerInfo_value(sinfos, i);
381 if (!cms_signerinfo_verify_cert(si, store,
382 cms_certs, crls, flags))
387 /* Attempt to verify all SignerInfo signed attribute signatures */
389 if (!(flags & CMS_NO_ATTR_VERIFY))
391 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
393 si = sk_CMS_SignerInfo_value(sinfos, i);
394 if (CMS_signed_get_attr_count(si) < 0)
396 if (CMS_SignerInfo_verify(si) <= 0)
401 /* Performance optimization: if the content is a memory BIO then
402 * store its contents in a temporary read only memory BIO. This
403 * avoids potentially large numbers of slow copies of data which will
404 * occur when reading from a read write memory BIO when signatures
408 if (dcont && (BIO_method_type(dcont) == BIO_TYPE_MEM))
412 len = BIO_get_mem_data(dcont, &ptr);
413 tmpin = BIO_new_mem_buf(ptr, len);
416 CMSerr(CMS_F_CMS_VERIFY,ERR_R_MALLOC_FAILURE);
422 /* If not binary mode and detached generate digests by *writing*
423 * through the BIO. That makes it possible to canonicalise the
426 if (!(flags & SMIME_BINARY) && dcont)
428 /* Create output BIO so we can either handle text or to
429 * ensure included content doesn't override detached content.
431 tmpout = cms_get_text_bio(out, flags);
434 CMSerr(CMS_F_CMS_VERIFY,ERR_R_MALLOC_FAILURE);
437 cmsbio = CMS_dataInit(cms, tmpout);
440 /* Don't use SMIME_TEXT for verify: it adds headers and
441 * we want to remove them.
443 SMIME_crlf_copy(dcont, cmsbio, flags & ~SMIME_TEXT);
447 if (!SMIME_text(tmpout, out))
449 CMSerr(CMS_F_CMS_VERIFY,CMS_R_SMIME_TEXT_ERROR);
456 cmsbio=CMS_dataInit(cms, tmpin);
460 if (!cms_copy_content(out, cmsbio, flags))
464 if (!(flags & CMS_NO_CONTENT_VERIFY))
466 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
468 si = sk_CMS_SignerInfo_value(sinfos, i);
469 if (CMS_SignerInfo_verify_content(si, cmsbio) <= 0)
471 CMSerr(CMS_F_CMS_VERIFY,
472 CMS_R_CONTENT_VERIFY_ERROR);
481 if (!(flags & SMIME_BINARY) && dcont)
483 do_free_upto(cmsbio, tmpout);
490 if (dcont && (tmpin == dcont))
491 do_free_upto(cmsbio, dcont);
493 BIO_free_all(cmsbio);
496 if (tmpout && out != tmpout)
497 BIO_free_all(tmpout);
500 sk_X509_pop_free(cms_certs, X509_free);
502 sk_X509_CRL_pop_free(crls, X509_CRL_free);
507 int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms,
508 STACK_OF(X509) *certs,
509 X509_STORE *store, unsigned int flags)
512 flags &= ~(CMS_DETACHED|CMS_TEXT);
513 r = CMS_verify(rcms, certs, store, NULL, NULL, flags);
516 return cms_Receipt_verify(rcms, ocms);
519 CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
520 BIO *data, unsigned int flags)
522 CMS_ContentInfo *cms;
525 cms = CMS_ContentInfo_new();
526 if (!cms || !CMS_SignedData_init(cms))
528 if (flags & CMS_ASCIICRLF && !CMS_set1_eContentType(cms, OBJ_nid2obj(NID_id_ct_asciiTextWithCRLF)))
531 if (pkey && !CMS_add1_signer(cms, signcert, pkey, NULL, flags))
533 CMSerr(CMS_F_CMS_SIGN, CMS_R_ADD_SIGNER_ERROR);
537 for (i = 0; i < sk_X509_num(certs); i++)
539 X509 *x = sk_X509_value(certs, i);
540 if (!CMS_add1_cert(cms, x))
544 if(!(flags & CMS_DETACHED))
545 CMS_set_detached(cms, 0);
547 if ((flags & (CMS_STREAM|CMS_PARTIAL))
548 || CMS_final(cms, data, NULL, flags))
554 CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE);
558 CMS_ContentInfo_free(cms);
562 CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
563 X509 *signcert, EVP_PKEY *pkey,
564 STACK_OF(X509) *certs,
567 CMS_SignerInfo *rct_si;
568 CMS_ContentInfo *cms = NULL;
569 ASN1_OCTET_STRING **pos, *os;
570 BIO *rct_cont = NULL;
573 flags &= ~(CMS_STREAM|CMS_TEXT);
574 /* Not really detached but avoids content being allocated */
575 flags |= CMS_PARTIAL|CMS_BINARY|CMS_DETACHED;
576 if (!pkey || !signcert)
578 CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_NO_KEY_OR_CERT);
582 /* Initialize signed data */
584 cms = CMS_sign(NULL, NULL, certs, NULL, flags);
588 /* Set inner content type to signed receipt */
589 if (!CMS_set1_eContentType(cms, OBJ_nid2obj(NID_id_smime_ct_receipt)))
592 rct_si = CMS_add1_signer(cms, signcert, pkey, NULL, flags);
595 CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_ADD_SIGNER_ERROR);
599 os = cms_encode_Receipt(si);
604 /* Set content to digest */
605 rct_cont = BIO_new_mem_buf(os->data, os->length);
609 /* Add msgSigDigest attribute */
611 if (!cms_msgSigDigest_add1(rct_si, si))
614 /* Finalize structure */
615 if (!CMS_final(cms, rct_cont, NULL, flags))
618 /* Set embedded content */
619 pos = CMS_get0_content(cms);
629 CMS_ContentInfo_free(cms);
634 CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data,
635 const EVP_CIPHER *cipher, unsigned int flags)
637 CMS_ContentInfo *cms;
640 cms = CMS_EnvelopedData_create(cipher);
643 for (i = 0; i < sk_X509_num(certs); i++)
645 recip = sk_X509_value(certs, i);
646 if (!CMS_add1_recipient_cert(cms, recip, flags))
648 CMSerr(CMS_F_CMS_ENCRYPT, CMS_R_RECIPIENT_ERROR);
653 if(!(flags & CMS_DETACHED))
654 CMS_set_detached(cms, 0);
656 if ((flags & (CMS_STREAM|CMS_PARTIAL))
657 || CMS_final(cms, data, NULL, flags))
663 CMSerr(CMS_F_CMS_ENCRYPT, ERR_R_MALLOC_FAILURE);
666 CMS_ContentInfo_free(cms);
670 static int cms_kari_set1_pkey(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
671 EVP_PKEY *pk, X509 *cert)
674 STACK_OF(CMS_RecipientEncryptedKey) *reks;
675 CMS_RecipientEncryptedKey *rek;
676 reks = CMS_RecipientInfo_kari_get0_reks(ri);
679 for (i = 0; i < sk_CMS_RecipientEncryptedKey_num(reks); i++)
682 rek = sk_CMS_RecipientEncryptedKey_value(reks, i);
683 if (CMS_RecipientEncryptedKey_cert_cmp(rek, cert))
685 CMS_RecipientInfo_kari_set0_pkey(ri, pk);
686 rv = CMS_RecipientInfo_kari_decrypt(cms, ri, rek);
687 CMS_RecipientInfo_kari_set0_pkey(ri, NULL);
695 int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
697 STACK_OF(CMS_RecipientInfo) *ris;
698 CMS_RecipientInfo *ri;
700 int debug = 0, match_ri = 0;
701 ris = CMS_get0_RecipientInfos(cms);
703 debug = cms->d.envelopedData->encryptedContentInfo->debug;
704 ri_type = cms_pkey_get_ri_type(pk);
705 if (ri_type == CMS_RECIPINFO_NONE)
707 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY,
708 CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
712 for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++)
714 ri = sk_CMS_RecipientInfo_value(ris, i);
715 if (CMS_RecipientInfo_type(ri) != ri_type)
718 if (ri_type == CMS_RECIPINFO_AGREE)
720 r = cms_kari_set1_pkey(cms, ri, pk, cert);
726 /* If we have a cert try matching RecipientInfo
727 * otherwise try them all.
729 else if (!cert || !CMS_RecipientInfo_ktri_cert_cmp(ri, cert))
731 CMS_RecipientInfo_set0_pkey(ri, pk);
732 r = CMS_RecipientInfo_decrypt(cms, ri);
733 CMS_RecipientInfo_set0_pkey(ri, NULL);
736 /* If not debugging clear any error and
737 * return success to avoid leaking of
738 * information useful to MMA
747 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY,
748 CMS_R_DECRYPT_ERROR);
751 /* If no cert and not debugging don't leave loop
752 * after first successful decrypt. Always attempt
753 * to decrypt all recipients to avoid leaking timing
754 * of a successful decrypt.
756 else if (r > 0 && debug)
760 /* If no cert and not debugging always return success */
761 if (match_ri && !cert && !debug)
767 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, CMS_R_NO_MATCHING_RECIPIENT);
772 int CMS_decrypt_set1_key(CMS_ContentInfo *cms,
773 unsigned char *key, size_t keylen,
774 unsigned char *id, size_t idlen)
776 STACK_OF(CMS_RecipientInfo) *ris;
777 CMS_RecipientInfo *ri;
779 ris = CMS_get0_RecipientInfos(cms);
780 for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++)
782 ri = sk_CMS_RecipientInfo_value(ris, i);
783 if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_KEK)
786 /* If we have an id try matching RecipientInfo
787 * otherwise try them all.
789 if (!id || (CMS_RecipientInfo_kekri_id_cmp(ri, id, idlen) == 0))
791 CMS_RecipientInfo_set0_key(ri, key, keylen);
792 r = CMS_RecipientInfo_decrypt(cms, ri);
793 CMS_RecipientInfo_set0_key(ri, NULL, 0);
798 CMSerr(CMS_F_CMS_DECRYPT_SET1_KEY,
799 CMS_R_DECRYPT_ERROR);
806 CMSerr(CMS_F_CMS_DECRYPT_SET1_KEY, CMS_R_NO_MATCHING_RECIPIENT);
811 int CMS_decrypt_set1_password(CMS_ContentInfo *cms,
812 unsigned char *pass, ossl_ssize_t passlen)
814 STACK_OF(CMS_RecipientInfo) *ris;
815 CMS_RecipientInfo *ri;
817 ris = CMS_get0_RecipientInfos(cms);
818 for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++)
820 ri = sk_CMS_RecipientInfo_value(ris, i);
821 if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_PASS)
823 CMS_RecipientInfo_set0_password(ri, pass, passlen);
824 r = CMS_RecipientInfo_decrypt(cms, ri);
825 CMS_RecipientInfo_set0_password(ri, NULL, 0);
830 CMSerr(CMS_F_CMS_DECRYPT_SET1_PASSWORD, CMS_R_NO_MATCHING_RECIPIENT);
835 int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert,
836 BIO *dcont, BIO *out,
841 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_enveloped)
843 CMSerr(CMS_F_CMS_DECRYPT, CMS_R_TYPE_NOT_ENVELOPED_DATA);
846 if (!dcont && !check_content(cms))
848 if (flags & CMS_DEBUG_DECRYPT)
849 cms->d.envelopedData->encryptedContentInfo->debug = 1;
851 cms->d.envelopedData->encryptedContentInfo->debug = 0;
852 if (!pk && !cert && !dcont && !out)
854 if (pk && !CMS_decrypt_set1_pkey(cms, pk, cert))
856 cont = CMS_dataInit(cms, dcont);
859 r = cms_copy_content(out, cont, flags);
860 do_free_upto(cont, dcont);
864 int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags)
868 if (!(cmsbio = CMS_dataInit(cms, dcont)))
870 CMSerr(CMS_F_CMS_FINAL,ERR_R_MALLOC_FAILURE);
874 SMIME_crlf_copy(data, cmsbio, flags);
876 (void)BIO_flush(cmsbio);
879 if (!CMS_dataFinal(cms, cmsbio))
881 CMSerr(CMS_F_CMS_FINAL,CMS_R_CMS_DATAFINAL_ERROR);
888 do_free_upto(cmsbio, dcont);
896 int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
901 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_id_smime_ct_compressedData)
903 CMSerr(CMS_F_CMS_UNCOMPRESS,
904 CMS_R_TYPE_NOT_COMPRESSED_DATA);
908 if (!dcont && !check_content(cms))
911 cont = CMS_dataInit(cms, dcont);
914 r = cms_copy_content(out, cont, flags);
915 do_free_upto(cont, dcont);
919 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags)
921 CMS_ContentInfo *cms;
923 comp_nid = NID_zlib_compression;
924 cms = cms_CompressedData_create(comp_nid);
928 if(!(flags & CMS_DETACHED))
929 CMS_set_detached(cms, 0);
931 if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
934 CMS_ContentInfo_free(cms);
940 int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
943 CMSerr(CMS_F_CMS_UNCOMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
947 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags)
949 CMSerr(CMS_F_CMS_COMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);