summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cms/cms_smime.c
diff options
context:
space:
mode:
authorjsing <>2019-08-11 10:38:27 +0000
committerjsing <>2019-08-11 10:38:27 +0000
commit66c480d1798005c797335d0f02a75fc501efcc7f (patch)
tree42de514d40b8fbdc31f900b32db6a05e12455f76 /src/lib/libcrypto/cms/cms_smime.c
parent08cb6e4d4d31afbeec6bc3bdd6594710504fd25b (diff)
downloadopenbsd-66c480d1798005c797335d0f02a75fc501efcc7f.tar.gz
openbsd-66c480d1798005c797335d0f02a75fc501efcc7f.tar.bz2
openbsd-66c480d1798005c797335d0f02a75fc501efcc7f.zip
Convert CMSerr() to CMSerror().
Diffstat (limited to 'src/lib/libcrypto/cms/cms_smime.c')
-rw-r--r--src/lib/libcrypto/cms/cms_smime.c73
1 files changed, 35 insertions, 38 deletions
diff --git a/src/lib/libcrypto/cms/cms_smime.c b/src/lib/libcrypto/cms/cms_smime.c
index 6e546593e7..2bb3c363c9 100644
--- a/src/lib/libcrypto/cms/cms_smime.c
+++ b/src/lib/libcrypto/cms/cms_smime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_smime.c,v 1.21 2019/08/11 06:47:18 jsing Exp $ */ 1/* $OpenBSD: cms_smime.c,v 1.22 2019/08/11 10:38:27 jsing Exp $ */
2/* 2/*
3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
4 * project. 4 * project.
@@ -87,7 +87,7 @@ cms_copy_content(BIO *out, BIO *in, unsigned int flags)
87 tmpout = cms_get_text_bio(out, flags); 87 tmpout = cms_get_text_bio(out, flags);
88 88
89 if (tmpout == NULL) { 89 if (tmpout == NULL) {
90 CMSerr(CMS_F_CMS_COPY_CONTENT, ERR_R_MALLOC_FAILURE); 90 CMSerror(ERR_R_MALLOC_FAILURE);
91 goto err; 91 goto err;
92 } 92 }
93 93
@@ -110,7 +110,7 @@ cms_copy_content(BIO *out, BIO *in, unsigned int flags)
110 110
111 if (flags & CMS_TEXT) { 111 if (flags & CMS_TEXT) {
112 if (!SMIME_text(tmpout, out)) { 112 if (!SMIME_text(tmpout, out)) {
113 CMSerr(CMS_F_CMS_COPY_CONTENT, CMS_R_SMIME_TEXT_ERROR); 113 CMSerror(CMS_R_SMIME_TEXT_ERROR);
114 goto err; 114 goto err;
115 } 115 }
116 } 116 }
@@ -130,7 +130,7 @@ check_content(CMS_ContentInfo *cms)
130 ASN1_OCTET_STRING **pos = CMS_get0_content(cms); 130 ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
131 131
132 if (!pos || !*pos) { 132 if (!pos || !*pos) {
133 CMSerr(CMS_F_CHECK_CONTENT, CMS_R_NO_CONTENT); 133 CMSerror(CMS_R_NO_CONTENT);
134 return 0; 134 return 0;
135 } 135 }
136 136
@@ -159,7 +159,7 @@ CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags)
159 int r; 159 int r;
160 160
161 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_data) { 161 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_data) {
162 CMSerr(CMS_F_CMS_DATA, CMS_R_TYPE_NOT_DATA); 162 CMSerror(CMS_R_TYPE_NOT_DATA);
163 return 0; 163 return 0;
164 } 164 }
165 cont = CMS_dataInit(cms, NULL); 165 cont = CMS_dataInit(cms, NULL);
@@ -195,7 +195,7 @@ CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, unsigned int flags
195 int r; 195 int r;
196 196
197 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_digest) { 197 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_digest) {
198 CMSerr(CMS_F_CMS_DIGEST_VERIFY, CMS_R_TYPE_NOT_DIGESTED_DATA); 198 CMSerror(CMS_R_TYPE_NOT_DIGESTED_DATA);
199 return 0; 199 return 0;
200 } 200 }
201 201
@@ -243,8 +243,7 @@ CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, const unsigned char *key,
243 int r; 243 int r;
244 244
245 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_encrypted) { 245 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_encrypted) {
246 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_DECRYPT, 246 CMSerror(CMS_R_TYPE_NOT_ENCRYPTED_DATA);
247 CMS_R_TYPE_NOT_ENCRYPTED_DATA);
248 return 0; 247 return 0;
249 } 248 }
250 249
@@ -269,7 +268,7 @@ CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
269 CMS_ContentInfo *cms; 268 CMS_ContentInfo *cms;
270 269
271 if (!cipher) { 270 if (!cipher) {
272 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER); 271 CMSerror(CMS_R_NO_CIPHER);
273 return NULL; 272 return NULL;
274 } 273 }
275 cms = CMS_ContentInfo_new(); 274 cms = CMS_ContentInfo_new();
@@ -299,12 +298,12 @@ cms_signerinfo_verify_cert(CMS_SignerInfo *si, X509_STORE *store,
299 int i, j, r = 0; 298 int i, j, r = 0;
300 299
301 if (ctx == NULL) { 300 if (ctx == NULL) {
302 CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, ERR_R_MALLOC_FAILURE); 301 CMSerror(ERR_R_MALLOC_FAILURE);
303 goto err; 302 goto err;
304 } 303 }
305 CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL); 304 CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
306 if (!X509_STORE_CTX_init(ctx, store, signer, certs)) { 305 if (!X509_STORE_CTX_init(ctx, store, signer, certs)) {
307 CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, CMS_R_STORE_INIT_ERROR); 306 CMSerror(CMS_R_STORE_INIT_ERROR);
308 goto err; 307 goto err;
309 } 308 }
310 X509_STORE_CTX_set_default(ctx, "smime_sign"); 309 X509_STORE_CTX_set_default(ctx, "smime_sign");
@@ -314,8 +313,7 @@ cms_signerinfo_verify_cert(CMS_SignerInfo *si, X509_STORE *store,
314 i = X509_verify_cert(ctx); 313 i = X509_verify_cert(ctx);
315 if (i <= 0) { 314 if (i <= 0) {
316 j = X509_STORE_CTX_get_error(ctx); 315 j = X509_STORE_CTX_get_error(ctx);
317 CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, 316 CMSerror(CMS_R_CERTIFICATE_VERIFY_ERROR);
318 CMS_R_CERTIFICATE_VERIFY_ERROR);
319 ERR_add_error_data(2, "Verify error:", 317 ERR_add_error_data(2, "Verify error:",
320 X509_verify_cert_error_string(j)); 318 X509_verify_cert_error_string(j));
321 goto err; 319 goto err;
@@ -352,7 +350,7 @@ CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
352 350
353 sinfos = CMS_get0_SignerInfos(cms); 351 sinfos = CMS_get0_SignerInfos(cms);
354 if (sk_CMS_SignerInfo_num(sinfos) <= 0) { 352 if (sk_CMS_SignerInfo_num(sinfos) <= 0) {
355 CMSerr(CMS_F_CMS_VERIFY, CMS_R_NO_SIGNERS); 353 CMSerror(CMS_R_NO_SIGNERS);
356 goto err; 354 goto err;
357 } 355 }
358 356
@@ -367,7 +365,7 @@ CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
367 scount += CMS_set1_signers_certs(cms, certs, flags); 365 scount += CMS_set1_signers_certs(cms, certs, flags);
368 366
369 if (scount != sk_CMS_SignerInfo_num(sinfos)) { 367 if (scount != sk_CMS_SignerInfo_num(sinfos)) {
370 CMSerr(CMS_F_CMS_VERIFY, CMS_R_SIGNER_CERTIFICATE_NOT_FOUND); 368 CMSerror(CMS_R_SIGNER_CERTIFICATE_NOT_FOUND);
371 goto err; 369 goto err;
372 } 370 }
373 371
@@ -410,7 +408,7 @@ CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
410 len = BIO_get_mem_data(dcont, &ptr); 408 len = BIO_get_mem_data(dcont, &ptr);
411 tmpin = BIO_new_mem_buf(ptr, len); 409 tmpin = BIO_new_mem_buf(ptr, len);
412 if (tmpin == NULL) { 410 if (tmpin == NULL) {
413 CMSerr(CMS_F_CMS_VERIFY, ERR_R_MALLOC_FAILURE); 411 CMSerror(ERR_R_MALLOC_FAILURE);
414 goto err2; 412 goto err2;
415 } 413 }
416 } else 414 } else
@@ -427,7 +425,7 @@ CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
427 */ 425 */
428 tmpout = cms_get_text_bio(out, flags); 426 tmpout = cms_get_text_bio(out, flags);
429 if (!tmpout) { 427 if (!tmpout) {
430 CMSerr(CMS_F_CMS_VERIFY, ERR_R_MALLOC_FAILURE); 428 CMSerror(ERR_R_MALLOC_FAILURE);
431 goto err; 429 goto err;
432 } 430 }
433 cmsbio = CMS_dataInit(cms, tmpout); 431 cmsbio = CMS_dataInit(cms, tmpout);
@@ -441,7 +439,7 @@ CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
441 439
442 if (flags & CMS_TEXT) { 440 if (flags & CMS_TEXT) {
443 if (!SMIME_text(tmpout, out)) { 441 if (!SMIME_text(tmpout, out)) {
444 CMSerr(CMS_F_CMS_VERIFY, CMS_R_SMIME_TEXT_ERROR); 442 CMSerror(CMS_R_SMIME_TEXT_ERROR);
445 goto err; 443 goto err;
446 } 444 }
447 } 445 }
@@ -458,7 +456,7 @@ CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
458 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { 456 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
459 si = sk_CMS_SignerInfo_value(sinfos, i); 457 si = sk_CMS_SignerInfo_value(sinfos, i);
460 if (CMS_SignerInfo_verify_content(si, cmsbio) <= 0) { 458 if (CMS_SignerInfo_verify_content(si, cmsbio) <= 0) {
461 CMSerr(CMS_F_CMS_VERIFY, CMS_R_CONTENT_VERIFY_ERROR); 459 CMSerror(CMS_R_CONTENT_VERIFY_ERROR);
462 goto err; 460 goto err;
463 } 461 }
464 } 462 }
@@ -517,7 +515,7 @@ CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data,
517 goto err; 515 goto err;
518 516
519 if (pkey && !CMS_add1_signer(cms, signcert, pkey, NULL, flags)) { 517 if (pkey && !CMS_add1_signer(cms, signcert, pkey, NULL, flags)) {
520 CMSerr(CMS_F_CMS_SIGN, CMS_R_ADD_SIGNER_ERROR); 518 CMSerror(CMS_R_ADD_SIGNER_ERROR);
521 goto err; 519 goto err;
522 } 520 }
523 521
@@ -537,7 +535,7 @@ CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data,
537 goto err; 535 goto err;
538 536
539 merr: 537 merr:
540 CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE); 538 CMSerror(ERR_R_MALLOC_FAILURE);
541 539
542 err: 540 err:
543 CMS_ContentInfo_free(cms); 541 CMS_ContentInfo_free(cms);
@@ -559,7 +557,7 @@ CMS_sign_receipt(CMS_SignerInfo *si, X509 *signcert, EVP_PKEY *pkey,
559 /* Not really detached but avoids content being allocated */ 557 /* Not really detached but avoids content being allocated */
560 flags |= CMS_PARTIAL | CMS_BINARY | CMS_DETACHED; 558 flags |= CMS_PARTIAL | CMS_BINARY | CMS_DETACHED;
561 if (!pkey || !signcert) { 559 if (!pkey || !signcert) {
562 CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_NO_KEY_OR_CERT); 560 CMSerror(CMS_R_NO_KEY_OR_CERT);
563 return NULL; 561 return NULL;
564 } 562 }
565 563
@@ -575,7 +573,7 @@ CMS_sign_receipt(CMS_SignerInfo *si, X509 *signcert, EVP_PKEY *pkey,
575 573
576 rct_si = CMS_add1_signer(cms, signcert, pkey, NULL, flags); 574 rct_si = CMS_add1_signer(cms, signcert, pkey, NULL, flags);
577 if (!rct_si) { 575 if (!rct_si) {
578 CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_ADD_SIGNER_ERROR); 576 CMSerror(CMS_R_ADD_SIGNER_ERROR);
579 goto err; 577 goto err;
580 } 578 }
581 579
@@ -626,7 +624,7 @@ CMS_encrypt(STACK_OF(X509) *certs, BIO *data, const EVP_CIPHER *cipher,
626 for (i = 0; i < sk_X509_num(certs); i++) { 624 for (i = 0; i < sk_X509_num(certs); i++) {
627 recip = sk_X509_value(certs, i); 625 recip = sk_X509_value(certs, i);
628 if (!CMS_add1_recipient_cert(cms, recip, flags)) { 626 if (!CMS_add1_recipient_cert(cms, recip, flags)) {
629 CMSerr(CMS_F_CMS_ENCRYPT, CMS_R_RECIPIENT_ERROR); 627 CMSerror(CMS_R_RECIPIENT_ERROR);
630 goto err; 628 goto err;
631 } 629 }
632 } 630 }
@@ -641,7 +639,7 @@ CMS_encrypt(STACK_OF(X509) *certs, BIO *data, const EVP_CIPHER *cipher,
641 goto err; 639 goto err;
642 640
643 merr: 641 merr:
644 CMSerr(CMS_F_CMS_ENCRYPT, ERR_R_MALLOC_FAILURE); 642 CMSerror(ERR_R_MALLOC_FAILURE);
645 err: 643 err:
646 CMS_ContentInfo_free(cms); 644 CMS_ContentInfo_free(cms);
647 645
@@ -687,8 +685,7 @@ CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
687 debug = cms->d.envelopedData->encryptedContentInfo->debug; 685 debug = cms->d.envelopedData->encryptedContentInfo->debug;
688 ri_type = cms_pkey_get_ri_type(pk); 686 ri_type = cms_pkey_get_ri_type(pk);
689 if (ri_type == CMS_RECIPINFO_NONE) { 687 if (ri_type == CMS_RECIPINFO_NONE) {
690 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, 688 CMSerror(CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
691 CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
692 return 0; 689 return 0;
693 } 690 }
694 691
@@ -724,7 +721,7 @@ CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
724 } 721 }
725 if (r > 0) 722 if (r > 0)
726 return 1; 723 return 1;
727 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, CMS_R_DECRYPT_ERROR); 724 CMSerror(CMS_R_DECRYPT_ERROR);
728 return 0; 725 return 0;
729 } 726 }
730 /* 727 /*
@@ -742,7 +739,7 @@ CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
742 return 1; 739 return 1;
743 } 740 }
744 741
745 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, CMS_R_NO_MATCHING_RECIPIENT); 742 CMSerror(CMS_R_NO_MATCHING_RECIPIENT);
746 743
747 return 0; 744 return 0;
748} 745}
@@ -772,14 +769,14 @@ CMS_decrypt_set1_key(CMS_ContentInfo *cms, unsigned char *key, size_t keylen,
772 if (r > 0) 769 if (r > 0)
773 return 1; 770 return 1;
774 if (id) { 771 if (id) {
775 CMSerr(CMS_F_CMS_DECRYPT_SET1_KEY, CMS_R_DECRYPT_ERROR); 772 CMSerror(CMS_R_DECRYPT_ERROR);
776 return 0; 773 return 0;
777 } 774 }
778 ERR_clear_error(); 775 ERR_clear_error();
779 } 776 }
780 } 777 }
781 778
782 CMSerr(CMS_F_CMS_DECRYPT_SET1_KEY, CMS_R_NO_MATCHING_RECIPIENT); 779 CMSerror(CMS_R_NO_MATCHING_RECIPIENT);
783 780
784 return 0; 781 return 0;
785} 782}
@@ -804,7 +801,7 @@ CMS_decrypt_set1_password(CMS_ContentInfo *cms, unsigned char *pass,
804 return 1; 801 return 1;
805 } 802 }
806 803
807 CMSerr(CMS_F_CMS_DECRYPT_SET1_PASSWORD, CMS_R_NO_MATCHING_RECIPIENT); 804 CMSerror(CMS_R_NO_MATCHING_RECIPIENT);
808 805
809 return 0; 806 return 0;
810} 807}
@@ -817,7 +814,7 @@ CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert, BIO *dcont,
817 BIO *cont; 814 BIO *cont;
818 815
819 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_enveloped) { 816 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_enveloped) {
820 CMSerr(CMS_F_CMS_DECRYPT, CMS_R_TYPE_NOT_ENVELOPED_DATA); 817 CMSerror(CMS_R_TYPE_NOT_ENVELOPED_DATA);
821 return 0; 818 return 0;
822 } 819 }
823 if (!dcont && !check_content(cms)) 820 if (!dcont && !check_content(cms))
@@ -846,7 +843,7 @@ CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags)
846 int ret = 0; 843 int ret = 0;
847 844
848 if ((cmsbio = CMS_dataInit(cms, dcont)) == NULL) { 845 if ((cmsbio = CMS_dataInit(cms, dcont)) == NULL) {
849 CMSerr(CMS_F_CMS_FINAL, CMS_R_CMS_LIB); 846 CMSerror(CMS_R_CMS_LIB);
850 return 0; 847 return 0;
851 } 848 }
852 849
@@ -855,7 +852,7 @@ CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags)
855 (void)BIO_flush(cmsbio); 852 (void)BIO_flush(cmsbio);
856 853
857 if (!CMS_dataFinal(cms, cmsbio)) { 854 if (!CMS_dataFinal(cms, cmsbio)) {
858 CMSerr(CMS_F_CMS_FINAL, CMS_R_CMS_DATAFINAL_ERROR); 855 CMSerror(CMS_R_CMS_DATAFINAL_ERROR);
859 goto err; 856 goto err;
860 } 857 }
861 858
@@ -876,7 +873,7 @@ CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, unsigned int flags)
876 int r; 873 int r;
877 874
878 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_id_smime_ct_compressedData) { 875 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_id_smime_ct_compressedData) {
879 CMSerr(CMS_F_CMS_UNCOMPRESS, CMS_R_TYPE_NOT_COMPRESSED_DATA); 876 CMSerror(CMS_R_TYPE_NOT_COMPRESSED_DATA);
880 return 0; 877 return 0;
881 } 878 }
882 879
@@ -919,14 +916,14 @@ CMS_compress(BIO *in, int comp_nid, unsigned int flags)
919int 916int
920CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, unsigned int flags) 917CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, unsigned int flags)
921{ 918{
922 CMSerr(CMS_F_CMS_UNCOMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); 919 CMSerror(CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
923 return 0; 920 return 0;
924} 921}
925 922
926CMS_ContentInfo * 923CMS_ContentInfo *
927CMS_compress(BIO *in, int comp_nid, unsigned int flags) 924CMS_compress(BIO *in, int comp_nid, unsigned int flags)
928{ 925{
929 CMSerr(CMS_F_CMS_COMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); 926 CMSerror(CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
930 return NULL; 927 return NULL;
931} 928}
932 929