summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/req.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/usr.bin/openssl/req.c66
1 files changed, 10 insertions, 56 deletions
diff --git a/src/usr.bin/openssl/req.c b/src/usr.bin/openssl/req.c
index 4e1a4757dd..5ed658bfb1 100644
--- a/src/usr.bin/openssl/req.c
+++ b/src/usr.bin/openssl/req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: req.c,v 1.6 2015/08/22 16:36:05 jsing Exp $ */ 1/* $OpenBSD: req.c,v 1.7 2015/09/11 14:30:23 bcook Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -140,15 +140,13 @@ static int genpkey_cb(EVP_PKEY_CTX * ctx);
140static int req_check_len(int len, int n_min, int n_max); 140static int req_check_len(int len, int n_min, int n_max);
141static int check_end(const char *str, const char *end); 141static int check_end(const char *str, const char *end);
142static EVP_PKEY_CTX *set_keygen_ctx(BIO * err, const char *gstr, int *pkey_type, 142static EVP_PKEY_CTX *set_keygen_ctx(BIO * err, const char *gstr, int *pkey_type,
143 long *pkeylen, char **palgnam, 143 long *pkeylen, char **palgnam);
144 ENGINE * keygen_engine);
145static CONF *req_conf = NULL; 144static CONF *req_conf = NULL;
146static int batch = 0; 145static int batch = 0;
147 146
148int 147int
149req_main(int argc, char **argv) 148req_main(int argc, char **argv)
150{ 149{
151 ENGINE *e = NULL, *gen_eng = NULL;
152 unsigned long nmflag = 0, reqflag = 0; 150 unsigned long nmflag = 0, reqflag = 0;
153 int ex = 1, x509 = 0, days = 30; 151 int ex = 1, x509 = 0, days = 30;
154 X509 *x509ss = NULL; 152 X509 *x509ss = NULL;
@@ -165,9 +163,6 @@ req_main(int argc, char **argv)
165 int nodes = 0, kludge = 0, newhdr = 0, subject = 0, pubkey = 0; 163 int nodes = 0, kludge = 0, newhdr = 0, subject = 0, pubkey = 0;
166 char *infile, *outfile, *prog, *keyfile = NULL, *template = NULL, 164 char *infile, *outfile, *prog, *keyfile = NULL, *template = NULL,
167 *keyout = NULL; 165 *keyout = NULL;
168#ifndef OPENSSL_NO_ENGINE
169 char *engine = NULL;
170#endif
171 char *extensions = NULL; 166 char *extensions = NULL;
172 char *req_exts = NULL; 167 char *req_exts = NULL;
173 const EVP_CIPHER *cipher = NULL; 168 const EVP_CIPHER *cipher = NULL;
@@ -203,21 +198,6 @@ req_main(int argc, char **argv)
203 goto bad; 198 goto bad;
204 outformat = str2fmt(*(++argv)); 199 outformat = str2fmt(*(++argv));
205 } 200 }
206#ifndef OPENSSL_NO_ENGINE
207 else if (strcmp(*argv, "-engine") == 0) {
208 if (--argc < 1)
209 goto bad;
210 engine = *(++argv);
211 } else if (strcmp(*argv, "-keygen_engine") == 0) {
212 if (--argc < 1)
213 goto bad;
214 gen_eng = ENGINE_by_id(*(++argv));
215 if (gen_eng == NULL) {
216 BIO_printf(bio_err, "Can't find keygen engine %s\n", *argv);
217 goto end;
218 }
219 }
220#endif
221 else if (strcmp(*argv, "-key") == 0) { 201 else if (strcmp(*argv, "-key") == 0) {
222 if (--argc < 1) 202 if (--argc < 1)
223 goto bad; 203 goto bad;
@@ -366,9 +346,6 @@ bad:
366 BIO_printf(bio_err, " -verify verify signature on REQ\n"); 346 BIO_printf(bio_err, " -verify verify signature on REQ\n");
367 BIO_printf(bio_err, " -modulus RSA modulus\n"); 347 BIO_printf(bio_err, " -modulus RSA modulus\n");
368 BIO_printf(bio_err, " -nodes don't encrypt the output key\n"); 348 BIO_printf(bio_err, " -nodes don't encrypt the output key\n");
369#ifndef OPENSSL_NO_ENGINE
370 BIO_printf(bio_err, " -engine e use engine e, possibly a hardware device\n");
371#endif
372 BIO_printf(bio_err, " -subject output the request's subject\n"); 349 BIO_printf(bio_err, " -subject output the request's subject\n");
373 BIO_printf(bio_err, " -passin private key password source\n"); 350 BIO_printf(bio_err, " -passin private key password source\n");
374 BIO_printf(bio_err, " -key file use the private key contained in file\n"); 351 BIO_printf(bio_err, " -key file use the private key contained in file\n");
@@ -520,12 +497,8 @@ bad:
520 if ((in == NULL) || (out == NULL)) 497 if ((in == NULL) || (out == NULL))
521 goto end; 498 goto end;
522 499
523#ifndef OPENSSL_NO_ENGINE
524 e = setup_engine(bio_err, engine, 0);
525#endif
526
527 if (keyfile != NULL) { 500 if (keyfile != NULL) {
528 pkey = load_key(bio_err, keyfile, keyform, 0, passin, e, 501 pkey = load_key(bio_err, keyfile, keyform, 0, passin,
529 "Private Key"); 502 "Private Key");
530 if (!pkey) { 503 if (!pkey) {
531 /* 504 /*
@@ -541,7 +514,7 @@ bad:
541 } 514 }
542 if (keyalg) { 515 if (keyalg) {
543 genctx = set_keygen_ctx(bio_err, keyalg, &pkey_type, &newkey, 516 genctx = set_keygen_ctx(bio_err, keyalg, &pkey_type, &newkey,
544 &keyalgstr, gen_eng); 517 &keyalgstr);
545 if (!genctx) 518 if (!genctx)
546 goto end; 519 goto end;
547 } 520 }
@@ -552,7 +525,7 @@ bad:
552 } 525 }
553 if (!genctx) { 526 if (!genctx) {
554 genctx = set_keygen_ctx(bio_err, NULL, &pkey_type, &newkey, 527 genctx = set_keygen_ctx(bio_err, NULL, &pkey_type, &newkey,
555 &keyalgstr, gen_eng); 528 &keyalgstr);
556 if (!genctx) 529 if (!genctx)
557 goto end; 530 goto end;
558 } 531 }
@@ -893,10 +866,6 @@ end:
893 sk_OPENSSL_STRING_free(pkeyopts); 866 sk_OPENSSL_STRING_free(pkeyopts);
894 if (sigopts) 867 if (sigopts)
895 sk_OPENSSL_STRING_free(sigopts); 868 sk_OPENSSL_STRING_free(sigopts);
896#ifndef OPENSSL_NO_ENGINE
897 if (gen_eng)
898 ENGINE_free(gen_eng);
899#endif
900 free(keyalgstr); 869 free(keyalgstr);
901 X509_REQ_free(req); 870 X509_REQ_free(req);
902 X509_free(x509ss); 871 X509_free(x509ss);
@@ -1370,8 +1339,7 @@ check_end(const char *str, const char *end)
1370 1339
1371static EVP_PKEY_CTX * 1340static EVP_PKEY_CTX *
1372set_keygen_ctx(BIO * err, const char *gstr, int *pkey_type, 1341set_keygen_ctx(BIO * err, const char *gstr, int *pkey_type,
1373 long *pkeylen, char **palgnam, 1342 long *pkeylen, char **palgnam)
1374 ENGINE * keygen_engine)
1375{ 1343{
1376 EVP_PKEY_CTX *gctx = NULL; 1344 EVP_PKEY_CTX *gctx = NULL;
1377 EVP_PKEY *param = NULL; 1345 EVP_PKEY *param = NULL;
@@ -1396,19 +1364,14 @@ set_keygen_ctx(BIO * err, const char *gstr, int *pkey_type,
1396 else { 1364 else {
1397 const char *p = strchr(gstr, ':'); 1365 const char *p = strchr(gstr, ':');
1398 int len; 1366 int len;
1399 ENGINE *tmpeng;
1400 const EVP_PKEY_ASN1_METHOD *ameth; 1367 const EVP_PKEY_ASN1_METHOD *ameth;
1401 1368
1402 if (p) 1369 if (p)
1403 len = p - gstr; 1370 len = p - gstr;
1404 else 1371 else
1405 len = strlen(gstr); 1372 len = strlen(gstr);
1406 /*
1407 * The lookup of a the string will cover all engines so keep
1408 * a note of the implementation.
1409 */
1410 1373
1411 ameth = EVP_PKEY_asn1_find_str(&tmpeng, gstr, len); 1374 ameth = EVP_PKEY_asn1_find_str(NULL, gstr, len);
1412 1375
1413 if (!ameth) { 1376 if (!ameth) {
1414 BIO_printf(err, "Unknown algorithm %.*s\n", len, gstr); 1377 BIO_printf(err, "Unknown algorithm %.*s\n", len, gstr);
@@ -1416,10 +1379,6 @@ set_keygen_ctx(BIO * err, const char *gstr, int *pkey_type,
1416 } 1379 }
1417 EVP_PKEY_asn1_get0_info(NULL, pkey_type, NULL, NULL, NULL, 1380 EVP_PKEY_asn1_get0_info(NULL, pkey_type, NULL, NULL, NULL,
1418 ameth); 1381 ameth);
1419#ifndef OPENSSL_NO_ENGINE
1420 if (tmpeng)
1421 ENGINE_finish(tmpeng);
1422#endif
1423 if (*pkey_type == EVP_PKEY_RSA) { 1382 if (*pkey_type == EVP_PKEY_RSA) {
1424 if (p) { 1383 if (p) {
1425 keylen = strtonum(p + 1, 0, LONG_MAX, &errstr); 1384 keylen = strtonum(p + 1, 0, LONG_MAX, &errstr);
@@ -1470,26 +1429,21 @@ set_keygen_ctx(BIO * err, const char *gstr, int *pkey_type,
1470 } 1429 }
1471 if (palgnam) { 1430 if (palgnam) {
1472 const EVP_PKEY_ASN1_METHOD *ameth; 1431 const EVP_PKEY_ASN1_METHOD *ameth;
1473 ENGINE *tmpeng;
1474 const char *anam; 1432 const char *anam;
1475 ameth = EVP_PKEY_asn1_find(&tmpeng, *pkey_type); 1433 ameth = EVP_PKEY_asn1_find(NULL, *pkey_type);
1476 if (!ameth) { 1434 if (!ameth) {
1477 BIO_puts(err, "Internal error: can't find key algorithm\n"); 1435 BIO_puts(err, "Internal error: can't find key algorithm\n");
1478 return NULL; 1436 return NULL;
1479 } 1437 }
1480 EVP_PKEY_asn1_get0_info(NULL, NULL, NULL, NULL, &anam, ameth); 1438 EVP_PKEY_asn1_get0_info(NULL, NULL, NULL, NULL, &anam, ameth);
1481 *palgnam = strdup(anam); 1439 *palgnam = strdup(anam);
1482#ifndef OPENSSL_NO_ENGINE
1483 if (tmpeng)
1484 ENGINE_finish(tmpeng);
1485#endif
1486 } 1440 }
1487 if (param) { 1441 if (param) {
1488 gctx = EVP_PKEY_CTX_new(param, keygen_engine); 1442 gctx = EVP_PKEY_CTX_new(param, NULL);
1489 *pkeylen = EVP_PKEY_bits(param); 1443 *pkeylen = EVP_PKEY_bits(param);
1490 EVP_PKEY_free(param); 1444 EVP_PKEY_free(param);
1491 } else 1445 } else
1492 gctx = EVP_PKEY_CTX_new_id(*pkey_type, keygen_engine); 1446 gctx = EVP_PKEY_CTX_new_id(*pkey_type, NULL);
1493 1447
1494 if (!gctx) { 1448 if (!gctx) {
1495 BIO_puts(err, "Error allocating keygen context\n"); 1449 BIO_puts(err, "Error allocating keygen context\n");