diff options
Diffstat (limited to 'src/usr.bin/openssl/cms.c')
| -rw-r--r-- | src/usr.bin/openssl/cms.c | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/src/usr.bin/openssl/cms.c b/src/usr.bin/openssl/cms.c index 7420d0ab8c..7430f4c935 100644 --- a/src/usr.bin/openssl/cms.c +++ b/src/usr.bin/openssl/cms.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: cms.c,v 1.36 2024/08/12 15:34:58 job Exp $ */ | 1 | /* $OpenBSD: cms.c,v 1.40 2025/12/20 07:02:37 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project. | 3 | * project. |
| 4 | */ | 4 | */ |
| @@ -89,12 +89,10 @@ static int cms_set_pkey_param(EVP_PKEY_CTX *pctx, | |||
| 89 | #define SMIME_DATA_CREATE (8 | SMIME_OP) | 89 | #define SMIME_DATA_CREATE (8 | SMIME_OP) |
| 90 | #define SMIME_DIGEST_VERIFY (9 | SMIME_IP) | 90 | #define SMIME_DIGEST_VERIFY (9 | SMIME_IP) |
| 91 | #define SMIME_DIGEST_CREATE (10 | SMIME_OP) | 91 | #define SMIME_DIGEST_CREATE (10 | SMIME_OP) |
| 92 | #define SMIME_UNCOMPRESS (11 | SMIME_IP) | 92 | #define SMIME_ENCRYPTED_DECRYPT (11 | SMIME_IP) |
| 93 | #define SMIME_COMPRESS (12 | SMIME_OP) | 93 | #define SMIME_ENCRYPTED_ENCRYPT (12 | SMIME_OP) |
| 94 | #define SMIME_ENCRYPTED_DECRYPT (13 | SMIME_IP) | 94 | #define SMIME_SIGN_RECEIPT (13 | SMIME_IP | SMIME_OP) |
| 95 | #define SMIME_ENCRYPTED_ENCRYPT (14 | SMIME_OP) | 95 | #define SMIME_VERIFY_RECEIPT (14 | SMIME_IP) |
| 96 | #define SMIME_SIGN_RECEIPT (15 | SMIME_IP | SMIME_OP) | ||
| 97 | #define SMIME_VERIFY_RECEIPT (16 | SMIME_IP) | ||
| 98 | 96 | ||
| 99 | int verify_err = 0; | 97 | int verify_err = 0; |
| 100 | 98 | ||
| @@ -193,15 +191,33 @@ get_cipher_by_name(char *name) | |||
| 193 | static int | 191 | static int |
| 194 | cms_opt_cipher(int argc, char **argv, int *argsused) | 192 | cms_opt_cipher(int argc, char **argv, int *argsused) |
| 195 | { | 193 | { |
| 194 | const EVP_CIPHER *cipher; | ||
| 196 | char *name = argv[0]; | 195 | char *name = argv[0]; |
| 197 | 196 | ||
| 198 | if (*name++ != '-') | 197 | if (*name++ != '-') |
| 199 | return (1); | 198 | return (1); |
| 200 | 199 | ||
| 201 | if ((cfg.cipher = get_cipher_by_name(name)) == NULL) | 200 | if ((cipher = get_cipher_by_name(name)) == NULL) |
| 202 | if ((cfg.cipher = EVP_get_cipherbyname(name)) == NULL) | 201 | if ((cipher = EVP_get_cipherbyname(name)) == NULL) |
| 203 | return (1); | 202 | return (1); |
| 204 | 203 | ||
| 204 | /* | ||
| 205 | * XXX - this should really be done in CMS_{encrypt,decrypt}() until | ||
| 206 | * we have proper support for AuthEnvelopedData (RFC 5084), but this | ||
| 207 | * is good enough for now to avoid outputting garbage with this rusty | ||
| 208 | * swiss army knife. | ||
| 209 | */ | ||
| 210 | if ((EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) != 0) { | ||
| 211 | BIO_printf(bio_err, "AuthEnvelopedData is not supported\n"); | ||
| 212 | return (1); | ||
| 213 | } | ||
| 214 | if (EVP_CIPHER_mode(cipher) == EVP_CIPH_XTS_MODE) { | ||
| 215 | BIO_printf(bio_err, "XTS mode not supported\n"); | ||
| 216 | return (1); | ||
| 217 | } | ||
| 218 | |||
| 219 | cfg.cipher = cipher; | ||
| 220 | |||
| 205 | *argsused = 1; | 221 | *argsused = 1; |
| 206 | return (0); | 222 | return (0); |
| 207 | } | 223 | } |
| @@ -475,7 +491,7 @@ static const struct option cms_options[] = { | |||
| 475 | }, | 491 | }, |
| 476 | { | 492 | { |
| 477 | .name = "aes256", | 493 | .name = "aes256", |
| 478 | .desc = "Encrypt PEM output with CBC AES", | 494 | .desc = "Encrypt PEM output with CBC AES (default)", |
| 479 | .type = OPTION_ARGV_FUNC, | 495 | .type = OPTION_ARGV_FUNC, |
| 480 | .opt.argvfunc = cms_opt_cipher, | 496 | .opt.argvfunc = cms_opt_cipher, |
| 481 | }, | 497 | }, |
| @@ -509,7 +525,7 @@ static const struct option cms_options[] = { | |||
| 509 | }, | 525 | }, |
| 510 | { | 526 | { |
| 511 | .name = "des3", | 527 | .name = "des3", |
| 512 | .desc = "Encrypt with triple DES (default)", | 528 | .desc = "Encrypt with triple DES", |
| 513 | .type = OPTION_ARGV_FUNC, | 529 | .type = OPTION_ARGV_FUNC, |
| 514 | .opt.argvfunc = cms_opt_cipher, | 530 | .opt.argvfunc = cms_opt_cipher, |
| 515 | }, | 531 | }, |
| @@ -584,13 +600,6 @@ static const struct option cms_options[] = { | |||
| 584 | .value = SMIME_CMSOUT, | 600 | .value = SMIME_CMSOUT, |
| 585 | }, | 601 | }, |
| 586 | { | 602 | { |
| 587 | .name = "compress", | ||
| 588 | .desc = "Create CMS CompressedData type", | ||
| 589 | .type = OPTION_VALUE, | ||
| 590 | .opt.value = &cfg.operation, | ||
| 591 | .value = SMIME_COMPRESS, | ||
| 592 | }, | ||
| 593 | { | ||
| 594 | .name = "content", | 603 | .name = "content", |
| 595 | .argname = "file", | 604 | .argname = "file", |
| 596 | .desc = "Supply or override content for detached signature", | 605 | .desc = "Supply or override content for detached signature", |
| @@ -980,13 +989,6 @@ static const struct option cms_options[] = { | |||
| 980 | .opt.arg = &cfg.to, | 989 | .opt.arg = &cfg.to, |
| 981 | }, | 990 | }, |
| 982 | { | 991 | { |
| 983 | .name = "uncompress", | ||
| 984 | .desc = "Uncompress CMS CompressedData type", | ||
| 985 | .type = OPTION_VALUE, | ||
| 986 | .opt.value = &cfg.operation, | ||
| 987 | .value = SMIME_UNCOMPRESS, | ||
| 988 | }, | ||
| 989 | { | ||
| 990 | .name = "verify", | 992 | .name = "verify", |
| 991 | .desc = "Verify signed message", | 993 | .desc = "Verify signed message", |
| 992 | .type = OPTION_VALUE, | 994 | .type = OPTION_VALUE, |
| @@ -1120,7 +1122,7 @@ cms_usage(void) | |||
| 1120 | " -camellia192 | -camellia256 | -des | -des3 |\n" | 1122 | " -camellia192 | -camellia256 | -des | -des3 |\n" |
| 1121 | " -rc2-40 | -rc2-64 | -rc2-128] [-CAfile file]\n" | 1123 | " -rc2-40 | -rc2-64 | -rc2-128] [-CAfile file]\n" |
| 1122 | " [-CApath directory] [-CRLfile file] [-binary]\n" | 1124 | " [-CApath directory] [-CRLfile file] [-binary]\n" |
| 1123 | " [-certfile file] [-certsout file] [-cmsout] [-compress]\n" | 1125 | " [-certfile file] [-certsout file] [-cmsout]\n" |
| 1124 | " [-content file] [-crlfeol] [-data_create] [-data_out]\n" | 1126 | " [-content file] [-crlfeol] [-data_create] [-data_out]\n" |
| 1125 | " [-debug_decrypt] [-decrypt] [-digest_create] [-digest_verify]\n" | 1127 | " [-debug_decrypt] [-decrypt] [-digest_create] [-digest_verify]\n" |
| 1126 | " [-econtent_type type] [-encrypt] [-EncryptedData_decrypt]\n" | 1128 | " [-econtent_type type] [-encrypt] [-EncryptedData_decrypt]\n" |
| @@ -1138,7 +1140,7 @@ cms_usage(void) | |||
| 1138 | " [-receipt_request_to addr] [-recip file] [-resign]\n" | 1140 | " [-receipt_request_to addr] [-recip file] [-resign]\n" |
| 1139 | " [-secretkey key] [-secretkeyid id] [-sign] [-sign_receipt]\n" | 1141 | " [-secretkey key] [-secretkeyid id] [-sign] [-sign_receipt]\n" |
| 1140 | " [-signer file] [-stream | -indef | -noindef] [-subject s]\n" | 1142 | " [-signer file] [-stream | -indef | -noindef] [-subject s]\n" |
| 1141 | " [-text] [-to addr] [-uncompress] [-verify]\n" | 1143 | " [-text] [-to addr] [-verify]\n" |
| 1142 | " [-verify_receipt file] [-verify_retcode] [cert.pem ...]\n\n"); | 1144 | " [-verify_receipt file] [-verify_retcode] [cert.pem ...]\n\n"); |
| 1143 | 1145 | ||
| 1144 | options_usage(cms_options); | 1146 | options_usage(cms_options); |
| @@ -1291,14 +1293,8 @@ cms_main(int argc, char **argv) | |||
| 1291 | } | 1293 | } |
| 1292 | 1294 | ||
| 1293 | if (cfg.operation == SMIME_ENCRYPT) { | 1295 | if (cfg.operation == SMIME_ENCRYPT) { |
| 1294 | if (cfg.cipher == NULL) { | 1296 | if (cfg.cipher == NULL) |
| 1295 | #ifndef OPENSSL_NO_DES | 1297 | cfg.cipher = EVP_aes_256_cbc(); |
| 1296 | cfg.cipher = EVP_des_ede3_cbc(); | ||
| 1297 | #else | ||
| 1298 | BIO_printf(bio_err, "No cipher selected\n"); | ||
| 1299 | goto end; | ||
| 1300 | #endif | ||
| 1301 | } | ||
| 1302 | if (cfg.secret_key != NULL && | 1298 | if (cfg.secret_key != NULL && |
| 1303 | cfg.secret_keyid == NULL) { | 1299 | cfg.secret_keyid == NULL) { |
| 1304 | BIO_printf(bio_err, "No secret key id\n"); | 1300 | BIO_printf(bio_err, "No secret key id\n"); |
| @@ -1470,8 +1466,6 @@ cms_main(int argc, char **argv) | |||
| 1470 | } else if (cfg.operation == SMIME_DIGEST_CREATE) { | 1466 | } else if (cfg.operation == SMIME_DIGEST_CREATE) { |
| 1471 | cms = CMS_digest_create(in, cfg.sign_md, | 1467 | cms = CMS_digest_create(in, cfg.sign_md, |
| 1472 | cfg.flags); | 1468 | cfg.flags); |
| 1473 | } else if (cfg.operation == SMIME_COMPRESS) { | ||
| 1474 | cms = CMS_compress(in, -1, cfg.flags); | ||
| 1475 | } else if (cfg.operation == SMIME_ENCRYPT) { | 1469 | } else if (cfg.operation == SMIME_ENCRYPT) { |
| 1476 | int i; | 1470 | int i; |
| 1477 | cfg.flags |= CMS_PARTIAL; | 1471 | cfg.flags |= CMS_PARTIAL; |
| @@ -1679,9 +1673,6 @@ cms_main(int argc, char **argv) | |||
| 1679 | } else if (cfg.operation == SMIME_DATAOUT) { | 1673 | } else if (cfg.operation == SMIME_DATAOUT) { |
| 1680 | if (!CMS_data(cms, out, cfg.flags)) | 1674 | if (!CMS_data(cms, out, cfg.flags)) |
| 1681 | goto end; | 1675 | goto end; |
| 1682 | } else if (cfg.operation == SMIME_UNCOMPRESS) { | ||
| 1683 | if (!CMS_uncompress(cms, indata, out, cfg.flags)) | ||
| 1684 | goto end; | ||
| 1685 | } else if (cfg.operation == SMIME_DIGEST_VERIFY) { | 1676 | } else if (cfg.operation == SMIME_DIGEST_VERIFY) { |
| 1686 | if (CMS_digest_verify(cms, indata, out, cfg.flags) > 0) | 1677 | if (CMS_digest_verify(cms, indata, out, cfg.flags) > 0) |
| 1687 | BIO_printf(bio_err, "Verification successful\n"); | 1678 | BIO_printf(bio_err, "Verification successful\n"); |
| @@ -1872,14 +1863,14 @@ receipt_request_print(BIO *out, CMS_ContentInfo *cms) | |||
| 1872 | BIO_puts(bio_err, " Receipt Request Parse Error\n"); | 1863 | BIO_puts(bio_err, " Receipt Request Parse Error\n"); |
| 1873 | ERR_print_errors(bio_err); | 1864 | ERR_print_errors(bio_err); |
| 1874 | } else { | 1865 | } else { |
| 1875 | char *id; | 1866 | const char *id; |
| 1876 | int idlen; | 1867 | int idlen; |
| 1877 | 1868 | ||
| 1878 | CMS_ReceiptRequest_get0_values(rr, &scid, &allorfirst, | 1869 | CMS_ReceiptRequest_get0_values(rr, &scid, &allorfirst, |
| 1879 | &rlist, &rto); | 1870 | &rlist, &rto); |
| 1880 | BIO_puts(out, " Signed Content ID:\n"); | 1871 | BIO_puts(out, " Signed Content ID:\n"); |
| 1881 | idlen = ASN1_STRING_length(scid); | 1872 | idlen = ASN1_STRING_length(scid); |
| 1882 | id = (char *) ASN1_STRING_data(scid); | 1873 | id = (const char *) ASN1_STRING_get0_data(scid); |
| 1883 | BIO_dump_indent(out, id, idlen, 4); | 1874 | BIO_dump_indent(out, id, idlen, 4); |
| 1884 | BIO_puts(out, " Receipts From"); | 1875 | BIO_puts(out, " Receipts From"); |
| 1885 | if (rlist != NULL) { | 1876 | if (rlist != NULL) { |
