/src/openssl34/crypto/cms/cms_smime.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2008-2024 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
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 |
8 | | */ |
9 | | |
10 | | #include "internal/cryptlib.h" |
11 | | #include <openssl/asn1t.h> |
12 | | #include <openssl/x509.h> |
13 | | #include <openssl/x509v3.h> |
14 | | #include <openssl/err.h> |
15 | | #include <openssl/cms.h> |
16 | | #include "cms_local.h" |
17 | | #include "crypto/asn1.h" |
18 | | #include "crypto/x509.h" |
19 | | |
20 | | static BIO *cms_get_text_bio(BIO *out, unsigned int flags) |
21 | 0 | { |
22 | 0 | BIO *rbio; |
23 | |
|
24 | 0 | if (out == NULL) |
25 | 0 | rbio = BIO_new(BIO_s_null()); |
26 | 0 | else if (flags & CMS_TEXT) { |
27 | 0 | rbio = BIO_new(BIO_s_mem()); |
28 | 0 | BIO_set_mem_eof_return(rbio, 0); |
29 | 0 | } else |
30 | 0 | rbio = out; |
31 | 0 | return rbio; |
32 | 0 | } |
33 | | |
34 | | static int cms_copy_content(BIO *out, BIO *in, unsigned int flags) |
35 | 0 | { |
36 | 0 | unsigned char buf[4096]; |
37 | 0 | int r = 0, i; |
38 | 0 | BIO *tmpout; |
39 | |
|
40 | 0 | tmpout = cms_get_text_bio(out, flags); |
41 | |
|
42 | 0 | if (tmpout == NULL) { |
43 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB); |
44 | 0 | goto err; |
45 | 0 | } |
46 | | |
47 | | /* Read all content through chain to process digest, decrypt etc */ |
48 | 0 | for (;;) { |
49 | 0 | i = BIO_read(in, buf, sizeof(buf)); |
50 | 0 | if (i <= 0) { |
51 | 0 | if (BIO_method_type(in) == BIO_TYPE_CIPHER) { |
52 | 0 | if (BIO_get_cipher_status(in) <= 0) |
53 | 0 | goto err; |
54 | 0 | } |
55 | 0 | if (i < 0) |
56 | 0 | goto err; |
57 | 0 | break; |
58 | 0 | } |
59 | | |
60 | 0 | if (tmpout != NULL && (BIO_write(tmpout, buf, i) != i)) |
61 | 0 | goto err; |
62 | 0 | } |
63 | | |
64 | 0 | if (flags & CMS_TEXT) { |
65 | 0 | if (!SMIME_text(tmpout, out)) { |
66 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_SMIME_TEXT_ERROR); |
67 | 0 | goto err; |
68 | 0 | } |
69 | 0 | } |
70 | | |
71 | 0 | r = 1; |
72 | 0 | err: |
73 | 0 | if (tmpout != out) |
74 | 0 | BIO_free(tmpout); |
75 | 0 | return r; |
76 | 0 | } |
77 | | |
78 | | static int check_content(CMS_ContentInfo *cms) |
79 | 0 | { |
80 | 0 | ASN1_OCTET_STRING **pos = CMS_get0_content(cms); |
81 | |
|
82 | 0 | if (pos == NULL || *pos == NULL) { |
83 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_NO_CONTENT); |
84 | 0 | return 0; |
85 | 0 | } |
86 | 0 | return 1; |
87 | 0 | } |
88 | | |
89 | | static void do_free_upto(BIO *f, BIO *upto) |
90 | 0 | { |
91 | 0 | if (upto != NULL) { |
92 | 0 | BIO *tbio; |
93 | |
|
94 | 0 | do { |
95 | 0 | tbio = BIO_pop(f); |
96 | 0 | BIO_free(f); |
97 | 0 | f = tbio; |
98 | 0 | } while (f != NULL && f != upto); |
99 | 0 | } else { |
100 | 0 | BIO_free_all(f); |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | | int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags) |
105 | 0 | { |
106 | 0 | BIO *cont; |
107 | 0 | int r; |
108 | |
|
109 | 0 | if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_data) { |
110 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_DATA); |
111 | 0 | return 0; |
112 | 0 | } |
113 | 0 | cont = CMS_dataInit(cms, NULL); |
114 | 0 | if (cont == NULL) |
115 | 0 | return 0; |
116 | 0 | r = cms_copy_content(out, cont, flags); |
117 | 0 | BIO_free_all(cont); |
118 | 0 | return r; |
119 | 0 | } |
120 | | |
121 | | CMS_ContentInfo *CMS_data_create_ex(BIO *in, unsigned int flags, |
122 | | OSSL_LIB_CTX *libctx, const char *propq) |
123 | 0 | { |
124 | 0 | CMS_ContentInfo *cms = ossl_cms_Data_create(libctx, propq); |
125 | |
|
126 | 0 | if (cms == NULL) |
127 | 0 | return NULL; |
128 | | |
129 | 0 | if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) |
130 | 0 | return cms; |
131 | | |
132 | 0 | CMS_ContentInfo_free(cms); |
133 | 0 | return NULL; |
134 | 0 | } |
135 | | |
136 | | CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags) |
137 | 0 | { |
138 | 0 | return CMS_data_create_ex(in, flags, NULL, NULL); |
139 | 0 | } |
140 | | |
141 | | int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, |
142 | | unsigned int flags) |
143 | 0 | { |
144 | 0 | BIO *cont; |
145 | 0 | int r; |
146 | |
|
147 | 0 | if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_digest) { |
148 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_DIGESTED_DATA); |
149 | 0 | return 0; |
150 | 0 | } |
151 | | |
152 | 0 | if (dcont == NULL && !check_content(cms)) |
153 | 0 | return 0; |
154 | | |
155 | 0 | cont = CMS_dataInit(cms, dcont); |
156 | 0 | if (cont == NULL) |
157 | 0 | return 0; |
158 | | |
159 | 0 | r = cms_copy_content(out, cont, flags); |
160 | 0 | if (r) |
161 | 0 | r = ossl_cms_DigestedData_do_final(cms, cont, 1); |
162 | 0 | do_free_upto(cont, dcont); |
163 | 0 | return r; |
164 | 0 | } |
165 | | |
166 | | CMS_ContentInfo *CMS_digest_create_ex(BIO *in, const EVP_MD *md, |
167 | | unsigned int flags, OSSL_LIB_CTX *ctx, |
168 | | const char *propq) |
169 | 0 | { |
170 | 0 | CMS_ContentInfo *cms; |
171 | | |
172 | | /* |
173 | | * Because the EVP_MD is cached and can be a legacy algorithm, we |
174 | | * cannot fetch the algorithm if it isn't supplied. |
175 | | */ |
176 | 0 | if (md == NULL) |
177 | 0 | md = EVP_sha1(); |
178 | 0 | cms = ossl_cms_DigestedData_create(md, ctx, propq); |
179 | 0 | if (cms == NULL) |
180 | 0 | return NULL; |
181 | | |
182 | 0 | if (!(flags & CMS_DETACHED)) |
183 | 0 | CMS_set_detached(cms, 0); |
184 | |
|
185 | 0 | if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) |
186 | 0 | return cms; |
187 | | |
188 | 0 | CMS_ContentInfo_free(cms); |
189 | 0 | return NULL; |
190 | 0 | } |
191 | | |
192 | | CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, |
193 | | unsigned int flags) |
194 | 0 | { |
195 | 0 | return CMS_digest_create_ex(in, md, flags, NULL, NULL); |
196 | 0 | } |
197 | | |
198 | | int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, |
199 | | const unsigned char *key, size_t keylen, |
200 | | BIO *dcont, BIO *out, unsigned int flags) |
201 | 0 | { |
202 | 0 | BIO *cont; |
203 | 0 | int r; |
204 | |
|
205 | 0 | if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_encrypted) { |
206 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_ENCRYPTED_DATA); |
207 | 0 | return 0; |
208 | 0 | } |
209 | | |
210 | 0 | if (dcont == NULL && !check_content(cms)) |
211 | 0 | return 0; |
212 | | |
213 | 0 | if (CMS_EncryptedData_set1_key(cms, NULL, key, keylen) <= 0) |
214 | 0 | return 0; |
215 | 0 | cont = CMS_dataInit(cms, dcont); |
216 | 0 | if (cont == NULL) |
217 | 0 | return 0; |
218 | 0 | r = cms_copy_content(out, cont, flags); |
219 | 0 | do_free_upto(cont, dcont); |
220 | 0 | return r; |
221 | 0 | } |
222 | | |
223 | | CMS_ContentInfo *CMS_EncryptedData_encrypt_ex(BIO *in, const EVP_CIPHER *cipher, |
224 | | const unsigned char *key, |
225 | | size_t keylen, unsigned int flags, |
226 | | OSSL_LIB_CTX *libctx, |
227 | | const char *propq) |
228 | 0 | { |
229 | 0 | CMS_ContentInfo *cms; |
230 | |
|
231 | 0 | if (cipher == NULL) { |
232 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_NO_CIPHER); |
233 | 0 | return NULL; |
234 | 0 | } |
235 | 0 | cms = CMS_ContentInfo_new_ex(libctx, propq); |
236 | 0 | if (cms == NULL) |
237 | 0 | return NULL; |
238 | 0 | if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) |
239 | 0 | goto err; |
240 | | |
241 | 0 | if (!(flags & CMS_DETACHED)) |
242 | 0 | CMS_set_detached(cms, 0); |
243 | |
|
244 | 0 | if ((flags & (CMS_STREAM | CMS_PARTIAL)) |
245 | 0 | || CMS_final(cms, in, NULL, flags)) |
246 | 0 | return cms; |
247 | | |
248 | 0 | err: |
249 | 0 | CMS_ContentInfo_free(cms); |
250 | 0 | return NULL; |
251 | 0 | } |
252 | | |
253 | | CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, |
254 | | const unsigned char *key, |
255 | | size_t keylen, unsigned int flags) |
256 | 0 | { |
257 | 0 | return CMS_EncryptedData_encrypt_ex(in, cipher, key, keylen, flags, NULL, |
258 | 0 | NULL); |
259 | 0 | } |
260 | | |
261 | | static int cms_signerinfo_verify_cert(CMS_SignerInfo *si, |
262 | | X509_STORE *store, |
263 | | STACK_OF(X509) *untrusted, |
264 | | STACK_OF(X509_CRL) *crls, |
265 | | STACK_OF(X509) **chain, |
266 | | const CMS_CTX *cms_ctx) |
267 | 0 | { |
268 | 0 | X509_STORE_CTX *ctx; |
269 | 0 | X509 *signer; |
270 | 0 | int i, j, r = 0; |
271 | |
|
272 | 0 | ctx = X509_STORE_CTX_new_ex(ossl_cms_ctx_get0_libctx(cms_ctx), |
273 | 0 | ossl_cms_ctx_get0_propq(cms_ctx)); |
274 | 0 | if (ctx == NULL) { |
275 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_X509_LIB); |
276 | 0 | goto err; |
277 | 0 | } |
278 | 0 | CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL); |
279 | 0 | if (!X509_STORE_CTX_init(ctx, store, signer, untrusted)) { |
280 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_STORE_INIT_ERROR); |
281 | 0 | goto err; |
282 | 0 | } |
283 | 0 | X509_STORE_CTX_set_default(ctx, "smime_sign"); |
284 | 0 | if (crls != NULL) |
285 | 0 | X509_STORE_CTX_set0_crls(ctx, crls); |
286 | |
|
287 | 0 | i = X509_verify_cert(ctx); |
288 | 0 | if (i <= 0) { |
289 | 0 | j = X509_STORE_CTX_get_error(ctx); |
290 | 0 | ERR_raise_data(ERR_LIB_CMS, CMS_R_CERTIFICATE_VERIFY_ERROR, |
291 | 0 | "Verify error: %s", X509_verify_cert_error_string(j)); |
292 | 0 | goto err; |
293 | 0 | } |
294 | 0 | r = 1; |
295 | | |
296 | | /* also send back the trust chain when required */ |
297 | 0 | if (chain != NULL) |
298 | 0 | *chain = X509_STORE_CTX_get1_chain(ctx); |
299 | 0 | err: |
300 | 0 | X509_STORE_CTX_free(ctx); |
301 | 0 | return r; |
302 | 0 | } |
303 | | |
304 | | /* This strongly overlaps with PKCS7_verify() */ |
305 | | int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, |
306 | | X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags) |
307 | 0 | { |
308 | 0 | CMS_SignerInfo *si; |
309 | 0 | STACK_OF(CMS_SignerInfo) *sinfos; |
310 | 0 | STACK_OF(X509) *untrusted = NULL; |
311 | 0 | STACK_OF(X509_CRL) *crls = NULL; |
312 | 0 | STACK_OF(X509) **si_chains = NULL; |
313 | 0 | X509 *signer; |
314 | 0 | int i, scount = 0, ret = 0; |
315 | 0 | BIO *cmsbio = NULL, *tmpin = NULL, *tmpout = NULL; |
316 | 0 | int cadesVerify = (flags & CMS_CADES) != 0; |
317 | 0 | const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms); |
318 | |
|
319 | 0 | if (dcont == NULL && !check_content(cms)) |
320 | 0 | return 0; |
321 | 0 | if (dcont != NULL && !(flags & CMS_BINARY)) { |
322 | 0 | const ASN1_OBJECT *coid = CMS_get0_eContentType(cms); |
323 | |
|
324 | 0 | if (OBJ_obj2nid(coid) == NID_id_ct_asciiTextWithCRLF) |
325 | 0 | flags |= CMS_ASCIICRLF; |
326 | 0 | } |
327 | | |
328 | | /* Attempt to find all signer certificates */ |
329 | |
|
330 | 0 | sinfos = CMS_get0_SignerInfos(cms); |
331 | |
|
332 | 0 | if (sk_CMS_SignerInfo_num(sinfos) <= 0) { |
333 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_NO_SIGNERS); |
334 | 0 | goto err; |
335 | 0 | } |
336 | | |
337 | 0 | for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { |
338 | 0 | si = sk_CMS_SignerInfo_value(sinfos, i); |
339 | 0 | CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL); |
340 | 0 | if (signer != NULL) |
341 | 0 | scount++; |
342 | 0 | } |
343 | |
|
344 | 0 | if (scount != sk_CMS_SignerInfo_num(sinfos)) |
345 | 0 | scount += CMS_set1_signers_certs(cms, certs, flags); |
346 | |
|
347 | 0 | if (scount != sk_CMS_SignerInfo_num(sinfos)) { |
348 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_SIGNER_CERTIFICATE_NOT_FOUND); |
349 | 0 | goto err; |
350 | 0 | } |
351 | | |
352 | | /* Attempt to verify all signers certs */ |
353 | | /* at this point scount == sk_CMS_SignerInfo_num(sinfos) */ |
354 | | |
355 | 0 | if ((flags & CMS_NO_SIGNER_CERT_VERIFY) == 0 || cadesVerify) { |
356 | 0 | if (cadesVerify) { |
357 | | /* Certificate trust chain is required to check CAdES signature */ |
358 | 0 | si_chains = OPENSSL_zalloc(scount * sizeof(si_chains[0])); |
359 | 0 | if (si_chains == NULL) |
360 | 0 | goto err; |
361 | 0 | } |
362 | 0 | if (!ossl_cms_get1_certs_ex(cms, &untrusted)) |
363 | 0 | goto err; |
364 | 0 | if (sk_X509_num(certs) > 0 |
365 | 0 | && !ossl_x509_add_certs_new(&untrusted, certs, |
366 | 0 | X509_ADD_FLAG_UP_REF | X509_ADD_FLAG_NO_DUP)) |
367 | 0 | goto err; |
368 | | |
369 | 0 | if ((flags & CMS_NOCRL) == 0 |
370 | 0 | && !ossl_cms_get1_crls_ex(cms, &crls)) |
371 | 0 | goto err; |
372 | 0 | for (i = 0; i < scount; i++) { |
373 | 0 | si = sk_CMS_SignerInfo_value(sinfos, i); |
374 | |
|
375 | 0 | if (!cms_signerinfo_verify_cert(si, store, untrusted, crls, |
376 | 0 | si_chains ? &si_chains[i] : NULL, |
377 | 0 | ctx)) |
378 | 0 | goto err; |
379 | 0 | } |
380 | 0 | } |
381 | | |
382 | | /* Attempt to verify all SignerInfo signed attribute signatures */ |
383 | | |
384 | 0 | if ((flags & CMS_NO_ATTR_VERIFY) == 0 || cadesVerify) { |
385 | 0 | for (i = 0; i < scount; i++) { |
386 | 0 | si = sk_CMS_SignerInfo_value(sinfos, i); |
387 | 0 | if (CMS_signed_get_attr_count(si) < 0) |
388 | 0 | continue; |
389 | 0 | if (CMS_SignerInfo_verify(si) <= 0) |
390 | 0 | goto err; |
391 | 0 | if (cadesVerify) { |
392 | 0 | STACK_OF(X509) *si_chain = si_chains ? si_chains[i] : NULL; |
393 | |
|
394 | 0 | if (ossl_cms_check_signing_certs(si, si_chain) <= 0) |
395 | 0 | goto err; |
396 | 0 | } |
397 | 0 | } |
398 | 0 | } |
399 | | |
400 | | /* |
401 | | * Performance optimization: if the content is a memory BIO then store |
402 | | * its contents in a temporary read only memory BIO. This avoids |
403 | | * potentially large numbers of slow copies of data which will occur when |
404 | | * reading from a read write memory BIO when signatures are calculated. |
405 | | */ |
406 | | |
407 | 0 | if (dcont != NULL && (BIO_method_type(dcont) == BIO_TYPE_MEM)) { |
408 | 0 | char *ptr; |
409 | 0 | long len; |
410 | |
|
411 | 0 | len = BIO_get_mem_data(dcont, &ptr); |
412 | 0 | tmpin = (len == 0) ? dcont : BIO_new_mem_buf(ptr, len); |
413 | 0 | if (tmpin == NULL) { |
414 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_BIO_LIB); |
415 | 0 | goto err2; |
416 | 0 | } |
417 | 0 | } else { |
418 | 0 | tmpin = dcont; |
419 | 0 | } |
420 | | /* |
421 | | * If not binary mode and detached generate digests by *writing* through |
422 | | * the BIO. That makes it possible to canonicalise the input. |
423 | | */ |
424 | 0 | if (!(flags & SMIME_BINARY) && dcont) { |
425 | | /* |
426 | | * Create output BIO so we can either handle text or to ensure |
427 | | * included content doesn't override detached content. |
428 | | */ |
429 | 0 | tmpout = cms_get_text_bio(out, flags); |
430 | 0 | if (tmpout == NULL) { |
431 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB); |
432 | 0 | goto err; |
433 | 0 | } |
434 | 0 | cmsbio = CMS_dataInit(cms, tmpout); |
435 | 0 | if (cmsbio == NULL) |
436 | 0 | goto err; |
437 | | /* |
438 | | * Don't use SMIME_TEXT for verify: it adds headers and we want to |
439 | | * remove them. |
440 | | */ |
441 | 0 | if (!SMIME_crlf_copy(dcont, cmsbio, flags & ~SMIME_TEXT)) |
442 | 0 | goto err; |
443 | | |
444 | 0 | if (flags & CMS_TEXT) { |
445 | 0 | if (!SMIME_text(tmpout, out)) { |
446 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_SMIME_TEXT_ERROR); |
447 | 0 | goto err; |
448 | 0 | } |
449 | 0 | } |
450 | 0 | } else { |
451 | 0 | cmsbio = CMS_dataInit(cms, tmpin); |
452 | 0 | if (cmsbio == NULL) |
453 | 0 | goto err; |
454 | | |
455 | 0 | if (!cms_copy_content(out, cmsbio, flags)) |
456 | 0 | goto err; |
457 | 0 | } |
458 | 0 | if (!(flags & CMS_NO_CONTENT_VERIFY)) { |
459 | 0 | for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { |
460 | 0 | si = sk_CMS_SignerInfo_value(sinfos, i); |
461 | 0 | if (CMS_SignerInfo_verify_content(si, cmsbio) <= 0) { |
462 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_VERIFY_ERROR); |
463 | 0 | goto err; |
464 | 0 | } |
465 | 0 | } |
466 | 0 | } |
467 | | |
468 | 0 | ret = 1; |
469 | 0 | err: |
470 | 0 | if (!(flags & SMIME_BINARY) && dcont) { |
471 | 0 | do_free_upto(cmsbio, tmpout); |
472 | 0 | if (tmpin != dcont) |
473 | 0 | BIO_free(tmpin); |
474 | 0 | } else { |
475 | 0 | if (dcont && (tmpin == dcont)) |
476 | 0 | do_free_upto(cmsbio, dcont); |
477 | 0 | else if (cmsbio != NULL) |
478 | 0 | BIO_free_all(cmsbio); |
479 | 0 | else |
480 | 0 | BIO_free(tmpin); |
481 | 0 | } |
482 | |
|
483 | 0 | if (out != tmpout) |
484 | 0 | BIO_free_all(tmpout); |
485 | |
|
486 | 0 | err2: |
487 | 0 | if (si_chains != NULL) { |
488 | 0 | for (i = 0; i < scount; ++i) |
489 | 0 | OSSL_STACK_OF_X509_free(si_chains[i]); |
490 | 0 | OPENSSL_free(si_chains); |
491 | 0 | } |
492 | 0 | sk_X509_pop_free(untrusted, X509_free); |
493 | 0 | sk_X509_CRL_pop_free(crls, X509_CRL_free); |
494 | |
|
495 | 0 | return ret; |
496 | 0 | } |
497 | | |
498 | | int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, |
499 | | STACK_OF(X509) *certs, |
500 | | X509_STORE *store, unsigned int flags) |
501 | 0 | { |
502 | 0 | int r; |
503 | |
|
504 | 0 | flags &= ~(CMS_DETACHED | CMS_TEXT); |
505 | 0 | r = CMS_verify(rcms, certs, store, NULL, NULL, flags); |
506 | 0 | if (r <= 0) |
507 | 0 | return r; |
508 | 0 | return ossl_cms_Receipt_verify(rcms, ocms); |
509 | 0 | } |
510 | | |
511 | | CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey, |
512 | | STACK_OF(X509) *certs, BIO *data, |
513 | | unsigned int flags, OSSL_LIB_CTX *libctx, |
514 | | const char *propq) |
515 | 0 | { |
516 | 0 | CMS_ContentInfo *cms; |
517 | 0 | int i; |
518 | |
|
519 | 0 | cms = CMS_ContentInfo_new_ex(libctx, propq); |
520 | 0 | if (cms == NULL || !CMS_SignedData_init(cms)) { |
521 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB); |
522 | 0 | goto err; |
523 | 0 | } |
524 | 0 | if (flags & CMS_ASCIICRLF |
525 | 0 | && !CMS_set1_eContentType(cms, |
526 | 0 | OBJ_nid2obj(NID_id_ct_asciiTextWithCRLF))) { |
527 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB); |
528 | 0 | goto err; |
529 | 0 | } |
530 | | |
531 | 0 | if (pkey != NULL && !CMS_add1_signer(cms, signcert, pkey, NULL, flags)) { |
532 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_ADD_SIGNER_ERROR); |
533 | 0 | goto err; |
534 | 0 | } |
535 | | |
536 | 0 | for (i = 0; i < sk_X509_num(certs); i++) { |
537 | 0 | X509 *x = sk_X509_value(certs, i); |
538 | |
|
539 | 0 | if (!CMS_add1_cert(cms, x)) { |
540 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB); |
541 | 0 | goto err; |
542 | 0 | } |
543 | 0 | } |
544 | | |
545 | 0 | if (!(flags & CMS_DETACHED)) |
546 | 0 | CMS_set_detached(cms, 0); |
547 | |
|
548 | 0 | if ((flags & (CMS_STREAM | CMS_PARTIAL)) |
549 | 0 | || CMS_final(cms, data, NULL, flags)) |
550 | 0 | return cms; |
551 | 0 | else |
552 | 0 | goto err; |
553 | | |
554 | 0 | err: |
555 | 0 | CMS_ContentInfo_free(cms); |
556 | 0 | return NULL; |
557 | 0 | } |
558 | | |
559 | | CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, |
560 | | BIO *data, unsigned int flags) |
561 | 0 | { |
562 | 0 | return CMS_sign_ex(signcert, pkey, certs, data, flags, NULL, NULL); |
563 | 0 | } |
564 | | |
565 | | CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, |
566 | | X509 *signcert, EVP_PKEY *pkey, |
567 | | STACK_OF(X509) *certs, unsigned int flags) |
568 | 0 | { |
569 | 0 | CMS_SignerInfo *rct_si; |
570 | 0 | CMS_ContentInfo *cms = NULL; |
571 | 0 | ASN1_OCTET_STRING **pos, *os = NULL; |
572 | 0 | BIO *rct_cont = NULL; |
573 | 0 | int r = 0; |
574 | 0 | const CMS_CTX *ctx = si->cms_ctx; |
575 | |
|
576 | 0 | flags &= ~(CMS_STREAM | CMS_TEXT); |
577 | | /* Not really detached but avoids content being allocated */ |
578 | 0 | flags |= CMS_PARTIAL | CMS_BINARY | CMS_DETACHED; |
579 | 0 | if (pkey == NULL || signcert == NULL) { |
580 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_NO_KEY_OR_CERT); |
581 | 0 | return NULL; |
582 | 0 | } |
583 | | |
584 | | /* Initialize signed data */ |
585 | | |
586 | 0 | cms = CMS_sign_ex(NULL, NULL, certs, NULL, flags, |
587 | 0 | ossl_cms_ctx_get0_libctx(ctx), |
588 | 0 | ossl_cms_ctx_get0_propq(ctx)); |
589 | 0 | if (cms == NULL) |
590 | 0 | goto err; |
591 | | |
592 | | /* Set inner content type to signed receipt */ |
593 | 0 | if (!CMS_set1_eContentType(cms, OBJ_nid2obj(NID_id_smime_ct_receipt))) |
594 | 0 | goto err; |
595 | | |
596 | 0 | rct_si = CMS_add1_signer(cms, signcert, pkey, NULL, flags); |
597 | 0 | if (!rct_si) { |
598 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_ADD_SIGNER_ERROR); |
599 | 0 | goto err; |
600 | 0 | } |
601 | | |
602 | 0 | os = ossl_cms_encode_Receipt(si); |
603 | 0 | if (os == NULL) |
604 | 0 | goto err; |
605 | | |
606 | | /* Set content to digest */ |
607 | 0 | rct_cont = BIO_new_mem_buf(os->data, os->length); |
608 | 0 | if (rct_cont == NULL) |
609 | 0 | goto err; |
610 | | |
611 | | /* Add msgSigDigest attribute */ |
612 | | |
613 | 0 | if (!ossl_cms_msgSigDigest_add1(rct_si, si)) |
614 | 0 | goto err; |
615 | | |
616 | | /* Finalize structure */ |
617 | 0 | if (!CMS_final(cms, rct_cont, NULL, flags)) |
618 | 0 | goto err; |
619 | | |
620 | | /* Set embedded content */ |
621 | 0 | pos = CMS_get0_content(cms); |
622 | 0 | if (pos == NULL) |
623 | 0 | goto err; |
624 | 0 | *pos = os; |
625 | |
|
626 | 0 | r = 1; |
627 | |
|
628 | 0 | err: |
629 | 0 | BIO_free(rct_cont); |
630 | 0 | if (r) |
631 | 0 | return cms; |
632 | 0 | CMS_ContentInfo_free(cms); |
633 | 0 | ASN1_OCTET_STRING_free(os); |
634 | 0 | return NULL; |
635 | 0 | } |
636 | | |
637 | | CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *data, |
638 | | const EVP_CIPHER *cipher, unsigned int flags, |
639 | | OSSL_LIB_CTX *libctx, const char *propq) |
640 | 0 | { |
641 | 0 | CMS_ContentInfo *cms; |
642 | 0 | int i; |
643 | 0 | X509 *recip; |
644 | |
|
645 | 0 | cms = (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) |
646 | 0 | ? CMS_AuthEnvelopedData_create_ex(cipher, libctx, propq) |
647 | 0 | : CMS_EnvelopedData_create_ex(cipher, libctx, propq); |
648 | 0 | if (cms == NULL) { |
649 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB); |
650 | 0 | goto err; |
651 | 0 | } |
652 | 0 | for (i = 0; i < sk_X509_num(certs); i++) { |
653 | 0 | recip = sk_X509_value(certs, i); |
654 | 0 | if (!CMS_add1_recipient_cert(cms, recip, flags)) { |
655 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_RECIPIENT_ERROR); |
656 | 0 | goto err; |
657 | 0 | } |
658 | 0 | } |
659 | | |
660 | 0 | if (!(flags & CMS_DETACHED)) |
661 | 0 | CMS_set_detached(cms, 0); |
662 | |
|
663 | 0 | if ((flags & (CMS_STREAM | CMS_PARTIAL)) |
664 | 0 | || CMS_final(cms, data, NULL, flags)) |
665 | 0 | return cms; |
666 | 0 | else |
667 | 0 | ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB); |
668 | | |
669 | 0 | err: |
670 | 0 | CMS_ContentInfo_free(cms); |
671 | 0 | return NULL; |
672 | 0 | } |
673 | | |
674 | | CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data, |
675 | | const EVP_CIPHER *cipher, unsigned int flags) |
676 | 0 | { |
677 | 0 | return CMS_encrypt_ex(certs, data, cipher, flags, NULL, NULL); |
678 | 0 | } |
679 | | |
680 | | static int cms_kari_set1_pkey_and_peer(CMS_ContentInfo *cms, |
681 | | CMS_RecipientInfo *ri, |
682 | | EVP_PKEY *pk, X509 *cert, X509 *peer) |
683 | 0 | { |
684 | 0 | int i; |
685 | 0 | STACK_OF(CMS_RecipientEncryptedKey) *reks; |
686 | 0 | CMS_RecipientEncryptedKey *rek; |
687 | |
|
688 | 0 | reks = CMS_RecipientInfo_kari_get0_reks(ri); |
689 | 0 | for (i = 0; i < sk_CMS_RecipientEncryptedKey_num(reks); i++) { |
690 | 0 | int rv; |
691 | |
|
692 | 0 | rek = sk_CMS_RecipientEncryptedKey_value(reks, i); |
693 | 0 | if (cert != NULL && CMS_RecipientEncryptedKey_cert_cmp(rek, cert)) |
694 | 0 | continue; |
695 | 0 | CMS_RecipientInfo_kari_set0_pkey_and_peer(ri, pk, peer); |
696 | 0 | rv = CMS_RecipientInfo_kari_decrypt(cms, ri, rek); |
697 | 0 | CMS_RecipientInfo_kari_set0_pkey(ri, NULL); |
698 | 0 | if (rv > 0) |
699 | 0 | return 1; |
700 | 0 | return cert == NULL ? 0 : -1; |
701 | 0 | } |
702 | 0 | return 0; |
703 | 0 | } |
704 | | |
705 | | int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert) |
706 | 0 | { |
707 | 0 | return CMS_decrypt_set1_pkey_and_peer(cms, pk, cert, NULL); |
708 | 0 | } |
709 | | |
710 | | int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms, EVP_PKEY *pk, |
711 | | X509 *cert, X509 *peer) |
712 | 0 | { |
713 | 0 | STACK_OF(CMS_RecipientInfo) *ris = CMS_get0_RecipientInfos(cms); |
714 | 0 | CMS_RecipientInfo *ri; |
715 | 0 | int i, r, cms_pkey_ri_type; |
716 | 0 | int debug = 0, match_ri = 0; |
717 | 0 | CMS_EncryptedContentInfo *ec = ossl_cms_get0_env_enc_content(cms); |
718 | | |
719 | | /* Prevent mem leak on earlier CMS_decrypt_set1_{pkey_and_peer,password} */ |
720 | 0 | if (ec != NULL) { |
721 | 0 | OPENSSL_clear_free(ec->key, ec->keylen); |
722 | 0 | ec->key = NULL; |
723 | 0 | ec->keylen = 0; |
724 | 0 | } |
725 | |
|
726 | 0 | if (ris != NULL && ec != NULL) |
727 | 0 | debug = ec->debug; |
728 | |
|
729 | 0 | cms_pkey_ri_type = ossl_cms_pkey_get_ri_type(pk); |
730 | 0 | if (cms_pkey_ri_type == CMS_RECIPINFO_NONE) { |
731 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); |
732 | 0 | return 0; |
733 | 0 | } |
734 | | |
735 | 0 | for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) { |
736 | 0 | int ri_type; |
737 | |
|
738 | 0 | ri = sk_CMS_RecipientInfo_value(ris, i); |
739 | 0 | ri_type = CMS_RecipientInfo_type(ri); |
740 | 0 | if (!ossl_cms_pkey_is_ri_type_supported(pk, ri_type)) |
741 | 0 | continue; |
742 | 0 | match_ri = 1; |
743 | 0 | if (ri_type == CMS_RECIPINFO_AGREE) { |
744 | 0 | r = cms_kari_set1_pkey_and_peer(cms, ri, pk, cert, peer); |
745 | 0 | if (r > 0) |
746 | 0 | return 1; |
747 | 0 | if (r < 0) |
748 | 0 | return 0; |
749 | 0 | } |
750 | | /* If we have a cert, try matching RecipientInfo, else try them all */ |
751 | 0 | else if (cert == NULL || !CMS_RecipientInfo_ktri_cert_cmp(ri, cert)) { |
752 | 0 | EVP_PKEY_up_ref(pk); |
753 | 0 | CMS_RecipientInfo_set0_pkey(ri, pk); |
754 | 0 | r = CMS_RecipientInfo_decrypt(cms, ri); |
755 | 0 | CMS_RecipientInfo_set0_pkey(ri, NULL); |
756 | 0 | if (cert != NULL) { |
757 | | /* |
758 | | * If not debugging clear any error and return success to |
759 | | * avoid leaking of information useful to MMA |
760 | | */ |
761 | 0 | if (!debug) { |
762 | 0 | ERR_clear_error(); |
763 | 0 | return 1; |
764 | 0 | } |
765 | 0 | if (r > 0) |
766 | 0 | return 1; |
767 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_DECRYPT_ERROR); |
768 | 0 | return 0; |
769 | 0 | } |
770 | | /* |
771 | | * If no cert and not debugging don't leave loop after first |
772 | | * successful decrypt. Always attempt to decrypt all recipients |
773 | | * to avoid leaking timing of a successful decrypt. |
774 | | */ |
775 | 0 | else if (r > 0 && (debug || cms_pkey_ri_type != CMS_RECIPINFO_TRANS)) |
776 | 0 | return 1; |
777 | 0 | } |
778 | 0 | } |
779 | | /* If no cert, key transport and not debugging always return success */ |
780 | 0 | if (cert == NULL |
781 | 0 | && cms_pkey_ri_type == CMS_RECIPINFO_TRANS |
782 | 0 | && match_ri |
783 | 0 | && !debug) { |
784 | 0 | ERR_clear_error(); |
785 | 0 | return 1; |
786 | 0 | } |
787 | | |
788 | 0 | if (!match_ri) |
789 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_RECIPIENT); |
790 | 0 | return 0; |
791 | 0 | } |
792 | | |
793 | | int CMS_decrypt_set1_key(CMS_ContentInfo *cms, |
794 | | unsigned char *key, size_t keylen, |
795 | | const unsigned char *id, size_t idlen) |
796 | 0 | { |
797 | 0 | STACK_OF(CMS_RecipientInfo) *ris; |
798 | 0 | CMS_RecipientInfo *ri; |
799 | 0 | int i, r, match_ri = 0; |
800 | |
|
801 | 0 | ris = CMS_get0_RecipientInfos(cms); |
802 | 0 | for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) { |
803 | 0 | ri = sk_CMS_RecipientInfo_value(ris, i); |
804 | 0 | if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_KEK) |
805 | 0 | continue; |
806 | | |
807 | | /* If we have an id, try matching RecipientInfo, else try them all */ |
808 | 0 | if (id == NULL |
809 | 0 | || (CMS_RecipientInfo_kekri_id_cmp(ri, id, idlen) == 0)) { |
810 | 0 | match_ri = 1; |
811 | 0 | CMS_RecipientInfo_set0_key(ri, key, keylen); |
812 | 0 | r = CMS_RecipientInfo_decrypt(cms, ri); |
813 | 0 | CMS_RecipientInfo_set0_key(ri, NULL, 0); |
814 | 0 | if (r > 0) |
815 | 0 | return 1; |
816 | 0 | if (id != NULL) { |
817 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_DECRYPT_ERROR); |
818 | 0 | return 0; |
819 | 0 | } |
820 | 0 | ERR_clear_error(); |
821 | 0 | } |
822 | 0 | } |
823 | | |
824 | 0 | if (!match_ri) |
825 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_RECIPIENT); |
826 | 0 | return 0; |
827 | 0 | } |
828 | | |
829 | | int CMS_decrypt_set1_password(CMS_ContentInfo *cms, |
830 | | unsigned char *pass, ossl_ssize_t passlen) |
831 | 0 | { |
832 | 0 | STACK_OF(CMS_RecipientInfo) *ris = CMS_get0_RecipientInfos(cms); |
833 | 0 | CMS_RecipientInfo *ri; |
834 | 0 | int i, r, match_ri = 0; |
835 | 0 | CMS_EncryptedContentInfo *ec = ossl_cms_get0_env_enc_content(cms); |
836 | | |
837 | | /* Prevent mem leak on earlier CMS_decrypt_set1_{pkey_and_peer,password} */ |
838 | 0 | if (ec != NULL) { |
839 | 0 | OPENSSL_clear_free(ec->key, ec->keylen); |
840 | 0 | ec->key = NULL; |
841 | 0 | ec->keylen = 0; |
842 | 0 | } |
843 | |
|
844 | 0 | for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) { |
845 | 0 | ri = sk_CMS_RecipientInfo_value(ris, i); |
846 | 0 | if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_PASS) |
847 | 0 | continue; |
848 | | |
849 | | /* Must try each PasswordRecipientInfo */ |
850 | 0 | match_ri = 1; |
851 | 0 | CMS_RecipientInfo_set0_password(ri, pass, passlen); |
852 | 0 | r = CMS_RecipientInfo_decrypt(cms, ri); |
853 | 0 | CMS_RecipientInfo_set0_password(ri, NULL, 0); |
854 | 0 | if (r > 0) |
855 | 0 | return 1; |
856 | 0 | } |
857 | | |
858 | 0 | if (!match_ri) |
859 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_RECIPIENT); |
860 | 0 | return 0; |
861 | 0 | } |
862 | | |
863 | | int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert, |
864 | | BIO *dcont, BIO *out, unsigned int flags) |
865 | 0 | { |
866 | 0 | int r; |
867 | 0 | BIO *cont; |
868 | 0 | CMS_EncryptedContentInfo *ec; |
869 | 0 | int nid = OBJ_obj2nid(CMS_get0_type(cms)); |
870 | |
|
871 | 0 | if (nid != NID_pkcs7_enveloped |
872 | 0 | && nid != NID_id_smime_ct_authEnvelopedData) { |
873 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_ENVELOPED_DATA); |
874 | 0 | return 0; |
875 | 0 | } |
876 | 0 | if (dcont == NULL && !check_content(cms)) |
877 | 0 | return 0; |
878 | 0 | ec = ossl_cms_get0_env_enc_content(cms); |
879 | 0 | ec->debug = (flags & CMS_DEBUG_DECRYPT) != 0; |
880 | 0 | ec->havenocert = cert == NULL; |
881 | 0 | if (pk == NULL && cert == NULL && dcont == NULL && out == NULL) |
882 | 0 | return 1; |
883 | 0 | if (pk != NULL && !CMS_decrypt_set1_pkey(cms, pk, cert)) |
884 | 0 | return 0; |
885 | 0 | cont = CMS_dataInit(cms, dcont); |
886 | 0 | if (cont == NULL) |
887 | 0 | return 0; |
888 | 0 | r = cms_copy_content(out, cont, flags); |
889 | 0 | do_free_upto(cont, dcont); |
890 | 0 | return r; |
891 | 0 | } |
892 | | |
893 | | int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags) |
894 | 0 | { |
895 | 0 | BIO *cmsbio; |
896 | 0 | int ret = 0; |
897 | |
|
898 | 0 | if ((cmsbio = CMS_dataInit(cms, dcont)) == NULL) { |
899 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_CMS_LIB); |
900 | 0 | return 0; |
901 | 0 | } |
902 | | |
903 | 0 | if (!SMIME_crlf_copy(data, cmsbio, flags)) { |
904 | 0 | goto err; |
905 | 0 | } |
906 | | |
907 | 0 | (void)BIO_flush(cmsbio); |
908 | |
|
909 | 0 | if (!CMS_dataFinal(cms, cmsbio)) { |
910 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_CMS_DATAFINAL_ERROR); |
911 | 0 | goto err; |
912 | 0 | } |
913 | | |
914 | 0 | ret = 1; |
915 | |
|
916 | 0 | err: |
917 | 0 | do_free_upto(cmsbio, dcont); |
918 | |
|
919 | 0 | return ret; |
920 | 0 | } |
921 | | |
922 | | int CMS_final_digest(CMS_ContentInfo *cms, |
923 | | const unsigned char *md, unsigned int mdlen, |
924 | | BIO *dcont, unsigned int flags) |
925 | 0 | { |
926 | 0 | BIO *cmsbio; |
927 | 0 | int ret = 0; |
928 | |
|
929 | 0 | if ((cmsbio = CMS_dataInit(cms, dcont)) == NULL) { |
930 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_CMS_LIB); |
931 | 0 | return 0; |
932 | 0 | } |
933 | | |
934 | 0 | (void)BIO_flush(cmsbio); |
935 | |
|
936 | 0 | if (!ossl_cms_DataFinal(cms, cmsbio, md, mdlen)) { |
937 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_CMS_DATAFINAL_ERROR); |
938 | 0 | goto err; |
939 | 0 | } |
940 | 0 | ret = 1; |
941 | |
|
942 | 0 | err: |
943 | 0 | do_free_upto(cmsbio, dcont); |
944 | 0 | return ret; |
945 | 0 | } |
946 | | |
947 | | #ifndef OPENSSL_NO_ZLIB |
948 | | |
949 | | int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, |
950 | | unsigned int flags) |
951 | | { |
952 | | BIO *cont; |
953 | | int r; |
954 | | |
955 | | if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_id_smime_ct_compressedData) { |
956 | | ERR_raise(ERR_LIB_CMS, CMS_R_TYPE_NOT_COMPRESSED_DATA); |
957 | | return 0; |
958 | | } |
959 | | |
960 | | if (dcont == NULL && !check_content(cms)) |
961 | | return 0; |
962 | | |
963 | | cont = CMS_dataInit(cms, dcont); |
964 | | if (cont == NULL) |
965 | | return 0; |
966 | | r = cms_copy_content(out, cont, flags); |
967 | | do_free_upto(cont, dcont); |
968 | | return r; |
969 | | } |
970 | | |
971 | | CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags) |
972 | | { |
973 | | CMS_ContentInfo *cms; |
974 | | |
975 | | if (comp_nid <= 0) |
976 | | comp_nid = NID_zlib_compression; |
977 | | cms = ossl_cms_CompressedData_create(comp_nid, NULL, NULL); |
978 | | if (cms == NULL) |
979 | | return NULL; |
980 | | |
981 | | if (!(flags & CMS_DETACHED)) |
982 | | CMS_set_detached(cms, 0); |
983 | | |
984 | | if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) |
985 | | return cms; |
986 | | |
987 | | CMS_ContentInfo_free(cms); |
988 | | return NULL; |
989 | | } |
990 | | |
991 | | #else |
992 | | |
993 | | int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, |
994 | | unsigned int flags) |
995 | 0 | { |
996 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); |
997 | 0 | return 0; |
998 | 0 | } |
999 | | |
1000 | | CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags) |
1001 | 0 | { |
1002 | 0 | ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); |
1003 | | return NULL; |
1004 | 0 | } |
1005 | | |
1006 | | #endif |