summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-09-13 02:08:33 +0000
committerDamien Miller <djm@mindrot.org>2018-09-13 12:12:33 +1000
commit482d23bcacdd3664f21cc82a5135f66fc598275f (patch)
tree362f697a94da0a765d1dabcfbf33370b2a4df121 /ssh-keygen.c
parentd70d061828730a56636ab6f1f24fe4a8ccefcfc1 (diff)
upstream: hold our collective noses and use the openssl-1.1.x API in
OpenSSH; feedback and ok tb@ jsing@ markus@ OpenBSD-Commit-ID: cacbcac87ce5da0d3ca7ef1b38a6f7fb349e4417
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c61
1 files changed, 46 insertions, 15 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 748ce37d7..a70fd1f88 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -450,7 +450,10 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
450 u_int magic, i1, i2, i3, i4; 450 u_int magic, i1, i2, i3, i4;
451 size_t slen; 451 size_t slen;
452 u_long e; 452 u_long e;
453 453 BIGNUM *dsa_p = NULL, *dsa_q = NULL, *dsa_g = NULL;
454 BIGNUM *dsa_pub_key = NULL, *dsa_priv_key = NULL;
455 BIGNUM *rsa_n = NULL, *rsa_e = NULL, *rsa_d = NULL;
456 BIGNUM *rsa_p = NULL, *rsa_q = NULL, *rsa_iqmp = NULL;
454 if ((b = sshbuf_from(blob, blen)) == NULL) 457 if ((b = sshbuf_from(blob, blen)) == NULL)
455 fatal("%s: sshbuf_from failed", __func__); 458 fatal("%s: sshbuf_from failed", __func__);
456 if ((r = sshbuf_get_u32(b, &magic)) != 0) 459 if ((r = sshbuf_get_u32(b, &magic)) != 0)
@@ -494,11 +497,23 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
494 497
495 switch (key->type) { 498 switch (key->type) {
496 case KEY_DSA: 499 case KEY_DSA:
497 buffer_get_bignum_bits(b, key->dsa->p); 500 if ((dsa_p = BN_new()) == NULL ||
498 buffer_get_bignum_bits(b, key->dsa->g); 501 (dsa_q = BN_new()) == NULL ||
499 buffer_get_bignum_bits(b, key->dsa->q); 502 (dsa_g = BN_new()) == NULL ||
500 buffer_get_bignum_bits(b, key->dsa->pub_key); 503 (dsa_pub_key = BN_new()) == NULL ||
501 buffer_get_bignum_bits(b, key->dsa->priv_key); 504 (dsa_priv_key = BN_new()) == NULL)
505 fatal("%s: BN_new", __func__);
506 buffer_get_bignum_bits(b, dsa_p);
507 buffer_get_bignum_bits(b, dsa_g);
508 buffer_get_bignum_bits(b, dsa_q);
509 buffer_get_bignum_bits(b, dsa_pub_key);
510 buffer_get_bignum_bits(b, dsa_priv_key);
511 if (!DSA_set0_pqg(key->dsa, dsa_p, dsa_q, dsa_g))
512 fatal("%s: DSA_set0_pqg failed", __func__);
513 dsa_p = dsa_q = dsa_g = NULL; /* transferred */
514 if (!DSA_set0_key(key->dsa, dsa_pub_key, dsa_priv_key))
515 fatal("%s: DSA_set0_key failed", __func__);
516 dsa_pub_key = dsa_priv_key = NULL; /* transferred */
502 break; 517 break;
503 case KEY_RSA: 518 case KEY_RSA:
504 if ((r = sshbuf_get_u8(b, &e1)) != 0 || 519 if ((r = sshbuf_get_u8(b, &e1)) != 0 ||
@@ -515,18 +530,34 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
515 e += e3; 530 e += e3;
516 debug("e %lx", e); 531 debug("e %lx", e);
517 } 532 }
518 if (!BN_set_word(key->rsa->e, e)) { 533 if ((rsa_e = BN_new()) == NULL)
534 fatal("%s: BN_new", __func__);
535 if (!BN_set_word(rsa_e, e)) {
536 BN_clear_free(rsa_e);
519 sshbuf_free(b); 537 sshbuf_free(b);
520 sshkey_free(key); 538 sshkey_free(key);
521 return NULL; 539 return NULL;
522 } 540 }
523 buffer_get_bignum_bits(b, key->rsa->d); 541 if ((rsa_n = BN_new()) == NULL ||
524 buffer_get_bignum_bits(b, key->rsa->n); 542 (rsa_d = BN_new()) == NULL ||
525 buffer_get_bignum_bits(b, key->rsa->iqmp); 543 (rsa_p = BN_new()) == NULL ||
526 buffer_get_bignum_bits(b, key->rsa->q); 544 (rsa_q = BN_new()) == NULL ||
527 buffer_get_bignum_bits(b, key->rsa->p); 545 (rsa_iqmp = BN_new()) == NULL)
528 if ((r = ssh_rsa_generate_additional_parameters(key)) != 0) 546 fatal("%s: BN_new", __func__);
547 buffer_get_bignum_bits(b, rsa_d);
548 buffer_get_bignum_bits(b, rsa_n);
549 buffer_get_bignum_bits(b, rsa_iqmp);
550 buffer_get_bignum_bits(b, rsa_q);
551 buffer_get_bignum_bits(b, rsa_p);
552 if (!RSA_set0_key(key->rsa, rsa_n, rsa_e, rsa_d))
553 fatal("%s: RSA_set0_key failed", __func__);
554 rsa_n = rsa_e = rsa_d = NULL; /* transferred */
555 if (!RSA_set0_factors(key->rsa, rsa_p, rsa_q))
556 fatal("%s: RSA_set0_factors failed", __func__);
557 rsa_p = rsa_q = NULL; /* transferred */
558 if ((r = ssh_rsa_complete_crt_parameters(key, rsa_iqmp)) != 0)
529 fatal("generate RSA parameters failed: %s", ssh_err(r)); 559 fatal("generate RSA parameters failed: %s", ssh_err(r));
560 BN_clear_free(rsa_iqmp);
530 break; 561 break;
531 } 562 }
532 rlen = sshbuf_len(b); 563 rlen = sshbuf_len(b);
@@ -634,7 +665,7 @@ do_convert_from_pkcs8(struct sshkey **k, int *private)
634 identity_file); 665 identity_file);
635 } 666 }
636 fclose(fp); 667 fclose(fp);
637 switch (EVP_PKEY_type(pubkey->type)) { 668 switch (EVP_PKEY_base_id(pubkey)) {
638 case EVP_PKEY_RSA: 669 case EVP_PKEY_RSA:
639 if ((*k = sshkey_new(KEY_UNSPEC)) == NULL) 670 if ((*k = sshkey_new(KEY_UNSPEC)) == NULL)
640 fatal("sshkey_new failed"); 671 fatal("sshkey_new failed");
@@ -658,7 +689,7 @@ do_convert_from_pkcs8(struct sshkey **k, int *private)
658#endif 689#endif
659 default: 690 default:
660 fatal("%s: unsupported pubkey type %d", __func__, 691 fatal("%s: unsupported pubkey type %d", __func__,
661 EVP_PKEY_type(pubkey->type)); 692 EVP_PKEY_base_id(pubkey));
662 } 693 }
663 EVP_PKEY_free(pubkey); 694 EVP_PKEY_free(pubkey);
664 return; 695 return;