diff options
-rw-r--r-- | src/usr.bin/openssl/cms.c | 149 |
1 files changed, 75 insertions, 74 deletions
diff --git a/src/usr.bin/openssl/cms.c b/src/usr.bin/openssl/cms.c index 58fcb4b656..7eb87322c8 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.21 2022/01/05 10:33:36 inoguchi Exp $ */ | 1 | /* $OpenBSD: cms.c,v 1.22 2022/01/05 11:38:19 inoguchi 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 | */ |
@@ -1177,25 +1177,25 @@ cms_main(int argc, char **argv) | |||
1177 | args = argv + argsused; | 1177 | args = argv + argsused; |
1178 | ret = 1; | 1178 | ret = 1; |
1179 | 1179 | ||
1180 | if (((cms_config.rr_allorfirst != -1) || cms_config.rr_from) && !cms_config.rr_to) { | 1180 | if (((cms_config.rr_allorfirst != -1) || cms_config.rr_from != NULL) && cms_config.rr_to == NULL) { |
1181 | BIO_puts(bio_err, "No Signed Receipts Recipients\n"); | 1181 | BIO_puts(bio_err, "No Signed Receipts Recipients\n"); |
1182 | goto argerr; | 1182 | goto argerr; |
1183 | } | 1183 | } |
1184 | if (!(cms_config.operation & SMIME_SIGNERS) && (cms_config.rr_to || cms_config.rr_from)) { | 1184 | if (!(cms_config.operation & SMIME_SIGNERS) && (cms_config.rr_to != NULL || cms_config.rr_from != NULL)) { |
1185 | BIO_puts(bio_err, "Signed receipts only allowed with -sign\n"); | 1185 | BIO_puts(bio_err, "Signed receipts only allowed with -sign\n"); |
1186 | goto argerr; | 1186 | goto argerr; |
1187 | } | 1187 | } |
1188 | if (!(cms_config.operation & SMIME_SIGNERS) && (cms_config.skkeys || cms_config.sksigners)) { | 1188 | if (!(cms_config.operation & SMIME_SIGNERS) && (cms_config.skkeys != NULL || cms_config.sksigners != NULL)) { |
1189 | BIO_puts(bio_err, "Multiple signers or keys not allowed\n"); | 1189 | BIO_puts(bio_err, "Multiple signers or keys not allowed\n"); |
1190 | goto argerr; | 1190 | goto argerr; |
1191 | } | 1191 | } |
1192 | if (cms_config.operation & SMIME_SIGNERS) { | 1192 | if (cms_config.operation & SMIME_SIGNERS) { |
1193 | if (cms_config.keyfile && !cms_config.signerfile) { | 1193 | if (cms_config.keyfile != NULL && cms_config.signerfile == NULL) { |
1194 | BIO_puts(bio_err, "Illegal -inkey without -signer\n"); | 1194 | BIO_puts(bio_err, "Illegal -inkey without -signer\n"); |
1195 | goto argerr; | 1195 | goto argerr; |
1196 | } | 1196 | } |
1197 | /* Check to see if any final signer needs to be appended */ | 1197 | /* Check to see if any final signer needs to be appended */ |
1198 | if (cms_config.signerfile) { | 1198 | if (cms_config.signerfile != NULL) { |
1199 | if (cms_config.sksigners == NULL && | 1199 | if (cms_config.sksigners == NULL && |
1200 | (cms_config.sksigners = sk_OPENSSL_STRING_new_null()) == NULL) | 1200 | (cms_config.sksigners = sk_OPENSSL_STRING_new_null()) == NULL) |
1201 | goto end; | 1201 | goto end; |
@@ -1204,12 +1204,12 @@ cms_main(int argc, char **argv) | |||
1204 | if (cms_config.skkeys == NULL && | 1204 | if (cms_config.skkeys == NULL && |
1205 | (cms_config.skkeys = sk_OPENSSL_STRING_new_null()) == NULL) | 1205 | (cms_config.skkeys = sk_OPENSSL_STRING_new_null()) == NULL) |
1206 | goto end; | 1206 | goto end; |
1207 | if (!cms_config.keyfile) | 1207 | if (cms_config.keyfile == NULL) |
1208 | cms_config.keyfile = cms_config.signerfile; | 1208 | cms_config.keyfile = cms_config.signerfile; |
1209 | if (!sk_OPENSSL_STRING_push(cms_config.skkeys, cms_config.keyfile)) | 1209 | if (!sk_OPENSSL_STRING_push(cms_config.skkeys, cms_config.keyfile)) |
1210 | goto end; | 1210 | goto end; |
1211 | } | 1211 | } |
1212 | if (!cms_config.sksigners) { | 1212 | if (cms_config.sksigners == NULL) { |
1213 | BIO_printf(bio_err, | 1213 | BIO_printf(bio_err, |
1214 | "No signer certificate specified\n"); | 1214 | "No signer certificate specified\n"); |
1215 | badarg = 1; | 1215 | badarg = 1; |
@@ -1217,13 +1217,13 @@ cms_main(int argc, char **argv) | |||
1217 | cms_config.signerfile = NULL; | 1217 | cms_config.signerfile = NULL; |
1218 | cms_config.keyfile = NULL; | 1218 | cms_config.keyfile = NULL; |
1219 | } else if (cms_config.operation == SMIME_DECRYPT) { | 1219 | } else if (cms_config.operation == SMIME_DECRYPT) { |
1220 | if (!cms_config.recipfile && !cms_config.keyfile && !cms_config.secret_key && !cms_config.pwri_pass) { | 1220 | if (cms_config.recipfile == NULL && cms_config.keyfile == NULL && cms_config.secret_key == NULL && cms_config.pwri_pass == NULL) { |
1221 | BIO_printf(bio_err, | 1221 | BIO_printf(bio_err, |
1222 | "No recipient certificate or key specified\n"); | 1222 | "No recipient certificate or key specified\n"); |
1223 | badarg = 1; | 1223 | badarg = 1; |
1224 | } | 1224 | } |
1225 | } else if (cms_config.operation == SMIME_ENCRYPT) { | 1225 | } else if (cms_config.operation == SMIME_ENCRYPT) { |
1226 | if (!*args && !cms_config.secret_key && !cms_config.pwri_pass && !cms_config.encerts) { | 1226 | if (*args == NULL && cms_config.secret_key == NULL && cms_config.pwri_pass == NULL && cms_config.encerts == NULL) { |
1227 | BIO_printf(bio_err, | 1227 | BIO_printf(bio_err, |
1228 | "No recipient(s) certificate(s) specified\n"); | 1228 | "No recipient(s) certificate(s) specified\n"); |
1229 | badarg = 1; | 1229 | badarg = 1; |
@@ -1263,7 +1263,7 @@ cms_main(int argc, char **argv) | |||
1263 | } | 1263 | } |
1264 | 1264 | ||
1265 | if (cms_config.operation == SMIME_ENCRYPT) { | 1265 | if (cms_config.operation == SMIME_ENCRYPT) { |
1266 | if (!cms_config.cipher) { | 1266 | if (cms_config.cipher == NULL) { |
1267 | #ifndef OPENSSL_NO_DES | 1267 | #ifndef OPENSSL_NO_DES |
1268 | cms_config.cipher = EVP_des_ede3_cbc(); | 1268 | cms_config.cipher = EVP_des_ede3_cbc(); |
1269 | #else | 1269 | #else |
@@ -1271,16 +1271,16 @@ cms_main(int argc, char **argv) | |||
1271 | goto end; | 1271 | goto end; |
1272 | #endif | 1272 | #endif |
1273 | } | 1273 | } |
1274 | if (cms_config.secret_key && !cms_config.secret_keyid) { | 1274 | if (cms_config.secret_key != NULL && cms_config.secret_keyid == NULL) { |
1275 | BIO_printf(bio_err, "No secret key id\n"); | 1275 | BIO_printf(bio_err, "No secret key id\n"); |
1276 | goto end; | 1276 | goto end; |
1277 | } | 1277 | } |
1278 | if (*args && cms_config.encerts == NULL) | 1278 | if (*args != NULL && cms_config.encerts == NULL) |
1279 | if ((cms_config.encerts = sk_X509_new_null()) == NULL) | 1279 | if ((cms_config.encerts = sk_X509_new_null()) == NULL) |
1280 | goto end; | 1280 | goto end; |
1281 | while (*args) { | 1281 | while (*args) { |
1282 | if (!(cms_config.cert = load_cert(bio_err, *args, FORMAT_PEM, | 1282 | if ((cms_config.cert = load_cert(bio_err, *args, FORMAT_PEM, |
1283 | NULL, "recipient certificate file"))) | 1283 | NULL, "recipient certificate file")) == NULL) |
1284 | goto end; | 1284 | goto end; |
1285 | if (!sk_X509_push(cms_config.encerts, cms_config.cert)) | 1285 | if (!sk_X509_push(cms_config.encerts, cms_config.cert)) |
1286 | goto end; | 1286 | goto end; |
@@ -1288,45 +1288,45 @@ cms_main(int argc, char **argv) | |||
1288 | args++; | 1288 | args++; |
1289 | } | 1289 | } |
1290 | } | 1290 | } |
1291 | if (cms_config.certfile) { | 1291 | if (cms_config.certfile != NULL) { |
1292 | if (!(other = load_certs(bio_err, cms_config.certfile, FORMAT_PEM, NULL, | 1292 | if ((other = load_certs(bio_err, cms_config.certfile, FORMAT_PEM, NULL, |
1293 | "certificate file"))) { | 1293 | "certificate file")) == NULL) { |
1294 | ERR_print_errors(bio_err); | 1294 | ERR_print_errors(bio_err); |
1295 | goto end; | 1295 | goto end; |
1296 | } | 1296 | } |
1297 | } | 1297 | } |
1298 | if (cms_config.recipfile && (cms_config.operation == SMIME_DECRYPT)) { | 1298 | if (cms_config.recipfile != NULL && (cms_config.operation == SMIME_DECRYPT)) { |
1299 | if (!(recip = load_cert(bio_err, cms_config.recipfile, FORMAT_PEM, NULL, | 1299 | if ((recip = load_cert(bio_err, cms_config.recipfile, FORMAT_PEM, NULL, |
1300 | "recipient certificate file"))) { | 1300 | "recipient certificate file")) == NULL) { |
1301 | ERR_print_errors(bio_err); | 1301 | ERR_print_errors(bio_err); |
1302 | goto end; | 1302 | goto end; |
1303 | } | 1303 | } |
1304 | } | 1304 | } |
1305 | if (cms_config.operation == SMIME_SIGN_RECEIPT) { | 1305 | if (cms_config.operation == SMIME_SIGN_RECEIPT) { |
1306 | if (!(signer = load_cert(bio_err, cms_config.signerfile, FORMAT_PEM, NULL, | 1306 | if ((signer = load_cert(bio_err, cms_config.signerfile, FORMAT_PEM, NULL, |
1307 | "receipt signer certificate file"))) { | 1307 | "receipt signer certificate file")) == NULL) { |
1308 | ERR_print_errors(bio_err); | 1308 | ERR_print_errors(bio_err); |
1309 | goto end; | 1309 | goto end; |
1310 | } | 1310 | } |
1311 | } | 1311 | } |
1312 | if (cms_config.operation == SMIME_DECRYPT) { | 1312 | if (cms_config.operation == SMIME_DECRYPT) { |
1313 | if (!cms_config.keyfile) | 1313 | if (cms_config.keyfile == NULL) |
1314 | cms_config.keyfile = cms_config.recipfile; | 1314 | cms_config.keyfile = cms_config.recipfile; |
1315 | } else if ((cms_config.operation == SMIME_SIGN) || | 1315 | } else if ((cms_config.operation == SMIME_SIGN) || |
1316 | (cms_config.operation == SMIME_SIGN_RECEIPT)) { | 1316 | (cms_config.operation == SMIME_SIGN_RECEIPT)) { |
1317 | if (!cms_config.keyfile) | 1317 | if (cms_config.keyfile == NULL) |
1318 | cms_config.keyfile = cms_config.signerfile; | 1318 | cms_config.keyfile = cms_config.signerfile; |
1319 | } else | 1319 | } else |
1320 | cms_config.keyfile = NULL; | 1320 | cms_config.keyfile = NULL; |
1321 | 1321 | ||
1322 | if (cms_config.keyfile) { | 1322 | if (cms_config.keyfile != NULL) { |
1323 | key = load_key(bio_err, cms_config.keyfile, cms_config.keyform, 0, passin, | 1323 | key = load_key(bio_err, cms_config.keyfile, cms_config.keyform, 0, passin, |
1324 | "signing key file"); | 1324 | "signing key file"); |
1325 | if (!key) | 1325 | if (key == NULL) |
1326 | goto end; | 1326 | goto end; |
1327 | } | 1327 | } |
1328 | if (cms_config.infile) { | 1328 | if (cms_config.infile != NULL) { |
1329 | if (!(in = BIO_new_file(cms_config.infile, inmode))) { | 1329 | if ((in = BIO_new_file(cms_config.infile, inmode)) == NULL) { |
1330 | BIO_printf(bio_err, | 1330 | BIO_printf(bio_err, |
1331 | "Can't open input file %s\n", cms_config.infile); | 1331 | "Can't open input file %s\n", cms_config.infile); |
1332 | goto end; | 1332 | goto end; |
@@ -1346,19 +1346,19 @@ cms_main(int argc, char **argv) | |||
1346 | goto end; | 1346 | goto end; |
1347 | } | 1347 | } |
1348 | 1348 | ||
1349 | if (!cms) { | 1349 | if (cms == NULL) { |
1350 | BIO_printf(bio_err, "Error reading S/MIME message\n"); | 1350 | BIO_printf(bio_err, "Error reading S/MIME message\n"); |
1351 | goto end; | 1351 | goto end; |
1352 | } | 1352 | } |
1353 | if (cms_config.contfile) { | 1353 | if (cms_config.contfile != NULL) { |
1354 | BIO_free(indata); | 1354 | BIO_free(indata); |
1355 | if (!(indata = BIO_new_file(cms_config.contfile, "rb"))) { | 1355 | if ((indata = BIO_new_file(cms_config.contfile, "rb")) == NULL) { |
1356 | BIO_printf(bio_err, | 1356 | BIO_printf(bio_err, |
1357 | "Can't read content file %s\n", cms_config.contfile); | 1357 | "Can't read content file %s\n", cms_config.contfile); |
1358 | goto end; | 1358 | goto end; |
1359 | } | 1359 | } |
1360 | } | 1360 | } |
1361 | if (cms_config.certsoutfile) { | 1361 | if (cms_config.certsoutfile != NULL) { |
1362 | STACK_OF(X509) *allcerts; | 1362 | STACK_OF(X509) *allcerts; |
1363 | if ((allcerts = CMS_get1_certs(cms)) == NULL) | 1363 | if ((allcerts = CMS_get1_certs(cms)) == NULL) |
1364 | goto end; | 1364 | goto end; |
@@ -1372,9 +1372,9 @@ cms_main(int argc, char **argv) | |||
1372 | sk_X509_pop_free(allcerts, X509_free); | 1372 | sk_X509_pop_free(allcerts, X509_free); |
1373 | } | 1373 | } |
1374 | } | 1374 | } |
1375 | if (cms_config.rctfile) { | 1375 | if (cms_config.rctfile != NULL) { |
1376 | char *rctmode = (cms_config.rctformat == FORMAT_ASN1) ? "rb" : "r"; | 1376 | char *rctmode = (cms_config.rctformat == FORMAT_ASN1) ? "rb" : "r"; |
1377 | if (!(rctin = BIO_new_file(cms_config.rctfile, rctmode))) { | 1377 | if ((rctin = BIO_new_file(cms_config.rctfile, rctmode)) == NULL) { |
1378 | BIO_printf(bio_err, | 1378 | BIO_printf(bio_err, |
1379 | "Can't open receipt file %s\n", cms_config.rctfile); | 1379 | "Can't open receipt file %s\n", cms_config.rctfile); |
1380 | goto end; | 1380 | goto end; |
@@ -1390,13 +1390,13 @@ cms_main(int argc, char **argv) | |||
1390 | goto end; | 1390 | goto end; |
1391 | } | 1391 | } |
1392 | 1392 | ||
1393 | if (!rcms) { | 1393 | if (rcms == NULL) { |
1394 | BIO_printf(bio_err, "Error reading receipt\n"); | 1394 | BIO_printf(bio_err, "Error reading receipt\n"); |
1395 | goto end; | 1395 | goto end; |
1396 | } | 1396 | } |
1397 | } | 1397 | } |
1398 | if (cms_config.outfile) { | 1398 | if (cms_config.outfile != NULL) { |
1399 | if (!(out = BIO_new_file(cms_config.outfile, outmode))) { | 1399 | if ((out = BIO_new_file(cms_config.outfile, outmode)) == NULL) { |
1400 | BIO_printf(bio_err, | 1400 | BIO_printf(bio_err, |
1401 | "Can't open output file %s\n", cms_config.outfile); | 1401 | "Can't open output file %s\n", cms_config.outfile); |
1402 | goto end; | 1402 | goto end; |
@@ -1407,10 +1407,10 @@ cms_main(int argc, char **argv) | |||
1407 | 1407 | ||
1408 | if ((cms_config.operation == SMIME_VERIFY) || | 1408 | if ((cms_config.operation == SMIME_VERIFY) || |
1409 | (cms_config.operation == SMIME_VERIFY_RECEIPT)) { | 1409 | (cms_config.operation == SMIME_VERIFY_RECEIPT)) { |
1410 | if (!(store = setup_verify(bio_err, cms_config.CAfile, cms_config.CApath))) | 1410 | if ((store = setup_verify(bio_err, cms_config.CAfile, cms_config.CApath)) == NULL) |
1411 | goto end; | 1411 | goto end; |
1412 | X509_STORE_set_verify_cb(store, cms_cb); | 1412 | X509_STORE_set_verify_cb(store, cms_cb); |
1413 | if (cms_config.vpm) | 1413 | if (cms_config.vpm != NULL) |
1414 | X509_STORE_set1_param(store, cms_config.vpm); | 1414 | X509_STORE_set1_param(store, cms_config.vpm); |
1415 | } | 1415 | } |
1416 | ret = 3; | 1416 | ret = 3; |
@@ -1450,21 +1450,21 @@ cms_main(int argc, char **argv) | |||
1450 | } | 1450 | } |
1451 | } | 1451 | } |
1452 | 1452 | ||
1453 | if (cms_config.secret_key) { | 1453 | if (cms_config.secret_key != NULL) { |
1454 | if (!CMS_add0_recipient_key(cms, NID_undef, cms_config.secret_key, | 1454 | if (CMS_add0_recipient_key(cms, NID_undef, cms_config.secret_key, |
1455 | cms_config.secret_keylen, cms_config.secret_keyid, cms_config.secret_keyidlen, | 1455 | cms_config.secret_keylen, cms_config.secret_keyid, cms_config.secret_keyidlen, |
1456 | NULL, NULL, NULL)) | 1456 | NULL, NULL, NULL) == NULL) |
1457 | goto end; | 1457 | goto end; |
1458 | /* NULL these because call absorbs them */ | 1458 | /* NULL these because call absorbs them */ |
1459 | cms_config.secret_key = NULL; | 1459 | cms_config.secret_key = NULL; |
1460 | cms_config.secret_keyid = NULL; | 1460 | cms_config.secret_keyid = NULL; |
1461 | } | 1461 | } |
1462 | if (cms_config.pwri_pass) { | 1462 | if (cms_config.pwri_pass != NULL) { |
1463 | pwri_tmp = strdup(cms_config.pwri_pass); | 1463 | pwri_tmp = strdup(cms_config.pwri_pass); |
1464 | if (!pwri_tmp) | 1464 | if (pwri_tmp == NULL) |
1465 | goto end; | 1465 | goto end; |
1466 | if (!CMS_add0_recipient_password(cms, -1, NID_undef, | 1466 | if (CMS_add0_recipient_password(cms, -1, NID_undef, |
1467 | NID_undef, pwri_tmp, -1, NULL)) | 1467 | NID_undef, pwri_tmp, -1, NULL) == NULL) |
1468 | goto end; | 1468 | goto end; |
1469 | pwri_tmp = NULL; | 1469 | pwri_tmp = NULL; |
1470 | } | 1470 | } |
@@ -1481,11 +1481,11 @@ cms_main(int argc, char **argv) | |||
1481 | STACK_OF(CMS_SignerInfo) *sis; | 1481 | STACK_OF(CMS_SignerInfo) *sis; |
1482 | CMS_SignerInfo *si; | 1482 | CMS_SignerInfo *si; |
1483 | sis = CMS_get0_SignerInfos(cms); | 1483 | sis = CMS_get0_SignerInfos(cms); |
1484 | if (!sis) | 1484 | if (sis == NULL) |
1485 | goto end; | 1485 | goto end; |
1486 | si = sk_CMS_SignerInfo_value(sis, 0); | 1486 | si = sk_CMS_SignerInfo_value(sis, 0); |
1487 | srcms = CMS_sign_receipt(si, signer, key, other, cms_config.flags); | 1487 | srcms = CMS_sign_receipt(si, signer, key, other, cms_config.flags); |
1488 | if (!srcms) | 1488 | if (srcms == NULL) |
1489 | goto end; | 1489 | goto end; |
1490 | CMS_ContentInfo_free(cms); | 1490 | CMS_ContentInfo_free(cms); |
1491 | cms = srcms; | 1491 | cms = srcms; |
@@ -1503,16 +1503,16 @@ cms_main(int argc, char **argv) | |||
1503 | } | 1503 | } |
1504 | cms_config.flags |= CMS_PARTIAL; | 1504 | cms_config.flags |= CMS_PARTIAL; |
1505 | cms = CMS_sign(NULL, NULL, other, in, cms_config.flags); | 1505 | cms = CMS_sign(NULL, NULL, other, in, cms_config.flags); |
1506 | if (!cms) | 1506 | if (cms == NULL) |
1507 | goto end; | 1507 | goto end; |
1508 | if (cms_config.econtent_type) | 1508 | if (cms_config.econtent_type != NULL) |
1509 | if (!CMS_set1_eContentType(cms, cms_config.econtent_type)) | 1509 | if (!CMS_set1_eContentType(cms, cms_config.econtent_type)) |
1510 | goto end; | 1510 | goto end; |
1511 | 1511 | ||
1512 | if (cms_config.rr_to) { | 1512 | if (cms_config.rr_to != NULL) { |
1513 | rr = make_receipt_request(cms_config.rr_to, cms_config.rr_allorfirst, | 1513 | rr = make_receipt_request(cms_config.rr_to, cms_config.rr_allorfirst, |
1514 | cms_config.rr_from); | 1514 | cms_config.rr_from); |
1515 | if (!rr) { | 1515 | if (rr == NULL) { |
1516 | BIO_puts(bio_err, | 1516 | BIO_puts(bio_err, |
1517 | "Signed Receipt Request Creation Error\n"); | 1517 | "Signed Receipt Request Creation Error\n"); |
1518 | goto end; | 1518 | goto end; |
@@ -1529,13 +1529,13 @@ cms_main(int argc, char **argv) | |||
1529 | 1529 | ||
1530 | signer = load_cert(bio_err, cms_config.signerfile, FORMAT_PEM, | 1530 | signer = load_cert(bio_err, cms_config.signerfile, FORMAT_PEM, |
1531 | NULL, "signer certificate"); | 1531 | NULL, "signer certificate"); |
1532 | if (!signer) | 1532 | if (signer == NULL) |
1533 | goto end; | 1533 | goto end; |
1534 | key = load_key(bio_err, cms_config.keyfile, cms_config.keyform, 0, passin, | 1534 | key = load_key(bio_err, cms_config.keyfile, cms_config.keyform, 0, passin, |
1535 | "signing key file"); | 1535 | "signing key file"); |
1536 | if (!key) | 1536 | if (key == NULL) |
1537 | goto end; | 1537 | goto end; |
1538 | for (kparam = cms_config.key_first; kparam; kparam = kparam->next) { | 1538 | for (kparam = cms_config.key_first; kparam != NULL; kparam = kparam->next) { |
1539 | if (kparam->idx == i) { | 1539 | if (kparam->idx == i) { |
1540 | tflags |= CMS_KEY_PARAM; | 1540 | tflags |= CMS_KEY_PARAM; |
1541 | break; | 1541 | break; |
@@ -1551,7 +1551,7 @@ cms_main(int argc, char **argv) | |||
1551 | if (!cms_set_pkey_param(pctx, kparam->param)) | 1551 | if (!cms_set_pkey_param(pctx, kparam->param)) |
1552 | goto end; | 1552 | goto end; |
1553 | } | 1553 | } |
1554 | if (rr && !CMS_add1_ReceiptRequest(si, rr)) | 1554 | if (rr != NULL && !CMS_add1_ReceiptRequest(si, rr)) |
1555 | goto end; | 1555 | goto end; |
1556 | X509_free(signer); | 1556 | X509_free(signer); |
1557 | signer = NULL; | 1557 | signer = NULL; |
@@ -1564,7 +1564,7 @@ cms_main(int argc, char **argv) | |||
1564 | goto end; | 1564 | goto end; |
1565 | } | 1565 | } |
1566 | } | 1566 | } |
1567 | if (!cms) { | 1567 | if (cms == NULL) { |
1568 | BIO_printf(bio_err, "Error creating CMS structure\n"); | 1568 | BIO_printf(bio_err, "Error creating CMS structure\n"); |
1569 | goto end; | 1569 | goto end; |
1570 | } | 1570 | } |
@@ -1573,7 +1573,7 @@ cms_main(int argc, char **argv) | |||
1573 | if (cms_config.flags & CMS_DEBUG_DECRYPT) | 1573 | if (cms_config.flags & CMS_DEBUG_DECRYPT) |
1574 | CMS_decrypt(cms, NULL, NULL, NULL, NULL, cms_config.flags); | 1574 | CMS_decrypt(cms, NULL, NULL, NULL, NULL, cms_config.flags); |
1575 | 1575 | ||
1576 | if (cms_config.secret_key) { | 1576 | if (cms_config.secret_key != NULL) { |
1577 | if (!CMS_decrypt_set1_key(cms, cms_config.secret_key, | 1577 | if (!CMS_decrypt_set1_key(cms, cms_config.secret_key, |
1578 | cms_config.secret_keylen, cms_config.secret_keyid, cms_config.secret_keyidlen)) { | 1578 | cms_config.secret_keylen, cms_config.secret_keyid, cms_config.secret_keyidlen)) { |
1579 | BIO_puts(bio_err, | 1579 | BIO_puts(bio_err, |
@@ -1581,14 +1581,14 @@ cms_main(int argc, char **argv) | |||
1581 | goto end; | 1581 | goto end; |
1582 | } | 1582 | } |
1583 | } | 1583 | } |
1584 | if (key) { | 1584 | if (key != NULL) { |
1585 | if (!CMS_decrypt_set1_pkey(cms, key, recip)) { | 1585 | if (!CMS_decrypt_set1_pkey(cms, key, recip)) { |
1586 | BIO_puts(bio_err, | 1586 | BIO_puts(bio_err, |
1587 | "Error decrypting CMS using private key\n"); | 1587 | "Error decrypting CMS using private key\n"); |
1588 | goto end; | 1588 | goto end; |
1589 | } | 1589 | } |
1590 | } | 1590 | } |
1591 | if (cms_config.pwri_pass) { | 1591 | if (cms_config.pwri_pass != NULL) { |
1592 | if (!CMS_decrypt_set1_password(cms, cms_config.pwri_pass, -1)) { | 1592 | if (!CMS_decrypt_set1_password(cms, cms_config.pwri_pass, -1)) { |
1593 | BIO_puts(bio_err, | 1593 | BIO_puts(bio_err, |
1594 | "Error decrypting CMS using password\n"); | 1594 | "Error decrypting CMS using password\n"); |
@@ -1625,7 +1625,7 @@ cms_main(int argc, char **argv) | |||
1625 | ret = verify_err + 32; | 1625 | ret = verify_err + 32; |
1626 | goto end; | 1626 | goto end; |
1627 | } | 1627 | } |
1628 | if (cms_config.signerfile) { | 1628 | if (cms_config.signerfile != NULL) { |
1629 | STACK_OF(X509) *signers; | 1629 | STACK_OF(X509) *signers; |
1630 | if ((signers = CMS_get0_signers(cms)) == NULL) | 1630 | if ((signers = CMS_get0_signers(cms)) == NULL) |
1631 | goto end; | 1631 | goto end; |
@@ -1654,11 +1654,11 @@ cms_main(int argc, char **argv) | |||
1654 | !CMS_ContentInfo_print_ctx(out, cms, 0, NULL)) | 1654 | !CMS_ContentInfo_print_ctx(out, cms, 0, NULL)) |
1655 | goto end; | 1655 | goto end; |
1656 | } else if (cms_config.outformat == FORMAT_SMIME) { | 1656 | } else if (cms_config.outformat == FORMAT_SMIME) { |
1657 | if (cms_config.to) | 1657 | if (cms_config.to != NULL) |
1658 | BIO_printf(out, "To: %s\n", cms_config.to); | 1658 | BIO_printf(out, "To: %s\n", cms_config.to); |
1659 | if (cms_config.from) | 1659 | if (cms_config.from != NULL) |
1660 | BIO_printf(out, "From: %s\n", cms_config.from); | 1660 | BIO_printf(out, "From: %s\n", cms_config.from); |
1661 | if (cms_config.subject) | 1661 | if (cms_config.subject != NULL) |
1662 | BIO_printf(out, "Subject: %s\n", cms_config.subject); | 1662 | BIO_printf(out, "Subject: %s\n", cms_config.subject); |
1663 | if (cms_config.operation == SMIME_RESIGN) | 1663 | if (cms_config.operation == SMIME_RESIGN) |
1664 | ret = SMIME_write_CMS(out, cms, indata, cms_config.flags); | 1664 | ret = SMIME_write_CMS(out, cms, indata, cms_config.flags); |
@@ -1724,10 +1724,10 @@ save_certs(char *signerfile, STACK_OF(X509) *signers) | |||
1724 | int i; | 1724 | int i; |
1725 | BIO *tmp; | 1725 | BIO *tmp; |
1726 | 1726 | ||
1727 | if (!signerfile) | 1727 | if (signerfile == NULL) |
1728 | return 1; | 1728 | return 1; |
1729 | tmp = BIO_new_file(signerfile, "w"); | 1729 | tmp = BIO_new_file(signerfile, "w"); |
1730 | if (!tmp) | 1730 | if (tmp == NULL) |
1731 | return 0; | 1731 | return 0; |
1732 | for (i = 0; i < sk_X509_num(signers); i++) | 1732 | for (i = 0; i < sk_X509_num(signers); i++) |
1733 | PEM_write_bio_X509(tmp, sk_X509_value(signers, i)); | 1733 | PEM_write_bio_X509(tmp, sk_X509_value(signers, i)); |
@@ -1806,7 +1806,7 @@ receipt_request_print(BIO *out, CMS_ContentInfo *cms) | |||
1806 | id = (char *) ASN1_STRING_data(scid); | 1806 | id = (char *) ASN1_STRING_data(scid); |
1807 | BIO_dump_indent(out, id, idlen, 4); | 1807 | BIO_dump_indent(out, id, idlen, 4); |
1808 | BIO_puts(out, " Receipts From"); | 1808 | BIO_puts(out, " Receipts From"); |
1809 | if (rlist) { | 1809 | if (rlist != NULL) { |
1810 | BIO_puts(out, " List:\n"); | 1810 | BIO_puts(out, " List:\n"); |
1811 | gnames_stack_print(out, rlist); | 1811 | gnames_stack_print(out, rlist); |
1812 | } else if (allorfirst == 1) | 1812 | } else if (allorfirst == 1) |
@@ -1818,7 +1818,7 @@ receipt_request_print(BIO *out, CMS_ContentInfo *cms) | |||
1818 | BIO_puts(out, " Receipts To:\n"); | 1818 | BIO_puts(out, " Receipts To:\n"); |
1819 | gnames_stack_print(out, rto); | 1819 | gnames_stack_print(out, rto); |
1820 | } | 1820 | } |
1821 | if (rr) | 1821 | if (rr != NULL) |
1822 | CMS_ReceiptRequest_free(rr); | 1822 | CMS_ReceiptRequest_free(rr); |
1823 | } | 1823 | } |
1824 | } | 1824 | } |
@@ -1830,15 +1830,16 @@ make_names_stack(STACK_OF(OPENSSL_STRING) *ns) | |||
1830 | STACK_OF(GENERAL_NAMES) *ret; | 1830 | STACK_OF(GENERAL_NAMES) *ret; |
1831 | GENERAL_NAMES *gens = NULL; | 1831 | GENERAL_NAMES *gens = NULL; |
1832 | GENERAL_NAME *gen = NULL; | 1832 | GENERAL_NAME *gen = NULL; |
1833 | |||
1833 | if ((ret = sk_GENERAL_NAMES_new_null()) == NULL) | 1834 | if ((ret = sk_GENERAL_NAMES_new_null()) == NULL) |
1834 | goto err; | 1835 | goto err; |
1835 | for (i = 0; i < sk_OPENSSL_STRING_num(ns); i++) { | 1836 | for (i = 0; i < sk_OPENSSL_STRING_num(ns); i++) { |
1836 | char *str = sk_OPENSSL_STRING_value(ns, i); | 1837 | char *str = sk_OPENSSL_STRING_value(ns, i); |
1837 | gen = a2i_GENERAL_NAME(NULL, NULL, NULL, GEN_EMAIL, str, 0); | 1838 | gen = a2i_GENERAL_NAME(NULL, NULL, NULL, GEN_EMAIL, str, 0); |
1838 | if (!gen) | 1839 | if (gen == NULL) |
1839 | goto err; | 1840 | goto err; |
1840 | gens = GENERAL_NAMES_new(); | 1841 | gens = GENERAL_NAMES_new(); |
1841 | if (!gens) | 1842 | if (gens == NULL) |
1842 | goto err; | 1843 | goto err; |
1843 | if (!sk_GENERAL_NAME_push(gens, gen)) | 1844 | if (!sk_GENERAL_NAME_push(gens, gen)) |
1844 | goto err; | 1845 | goto err; |
@@ -1867,11 +1868,11 @@ make_receipt_request(STACK_OF(OPENSSL_STRING) *rr_to, int rr_allorfirst, | |||
1867 | CMS_ReceiptRequest *rr; | 1868 | CMS_ReceiptRequest *rr; |
1868 | 1869 | ||
1869 | rct_to = make_names_stack(rr_to); | 1870 | rct_to = make_names_stack(rr_to); |
1870 | if (!rct_to) | 1871 | if (rct_to == NULL) |
1871 | goto err; | 1872 | goto err; |
1872 | if (rr_from) { | 1873 | if (rr_from != NULL) { |
1873 | rct_from = make_names_stack(rr_from); | 1874 | rct_from = make_names_stack(rr_from); |
1874 | if (!rct_from) | 1875 | if (rct_from == NULL) |
1875 | goto err; | 1876 | goto err; |
1876 | } else | 1877 | } else |
1877 | rct_from = NULL; | 1878 | rct_from = NULL; |