summaryrefslogtreecommitdiff
path: root/serverloop.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-12-18 23:16:23 +0000
committerDamien Miller <djm@mindrot.org>2017-12-19 15:21:37 +1100
commit7860731ef190b52119fa480f8064ab03c44a120a (patch)
tree758274280fa590762fac827aae5b9aa3ee56c946 /serverloop.c
parent966ef478339ad5e631fb684d2a8effe846ce3fd4 (diff)
upstream commit
unbreak hostkey rotation; attempting to sign with a desired signature algorithm of kex->hostkey_alg is incorrect when the key type isn't capable of making those signatures. ok markus@ OpenBSD-Commit-ID: 35ae46864e1f5859831ec0d115ee5ea50953a906
Diffstat (limited to 'serverloop.c')
-rw-r--r--serverloop.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/serverloop.c b/serverloop.c
index fb2980568..615921c38 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: serverloop.c,v 1.201 2017/12/18 02:25:15 djm Exp $ */ 1/* $OpenBSD: serverloop.c,v 1.202 2017/12/18 23:16:24 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -671,7 +671,7 @@ server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
671 struct sshbuf *resp = NULL; 671 struct sshbuf *resp = NULL;
672 struct sshbuf *sigbuf = NULL; 672 struct sshbuf *sigbuf = NULL;
673 struct sshkey *key = NULL, *key_pub = NULL, *key_prv = NULL; 673 struct sshkey *key = NULL, *key_pub = NULL, *key_prv = NULL;
674 int r, ndx, success = 0; 674 int r, ndx, kexsigtype, use_kexsigtype, success = 0;
675 const u_char *blob; 675 const u_char *blob;
676 u_char *sig = 0; 676 u_char *sig = 0;
677 size_t blen, slen; 677 size_t blen, slen;
@@ -679,6 +679,8 @@ server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
679 if ((resp = sshbuf_new()) == NULL || (sigbuf = sshbuf_new()) == NULL) 679 if ((resp = sshbuf_new()) == NULL || (sigbuf = sshbuf_new()) == NULL)
680 fatal("%s: sshbuf_new", __func__); 680 fatal("%s: sshbuf_new", __func__);
681 681
682 kexsigtype = sshkey_type_plain(
683 sshkey_type_from_name(ssh->kex->hostkey_alg));
682 while (ssh_packet_remaining(ssh) > 0) { 684 while (ssh_packet_remaining(ssh) > 0) {
683 sshkey_free(key); 685 sshkey_free(key);
684 key = NULL; 686 key = NULL;
@@ -709,6 +711,12 @@ server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
709 sshbuf_reset(sigbuf); 711 sshbuf_reset(sigbuf);
710 free(sig); 712 free(sig);
711 sig = NULL; 713 sig = NULL;
714 /*
715 * For RSA keys, prefer to use the signature type negotiated
716 * during KEX to the default (SHA1).
717 */
718 use_kexsigtype = kexsigtype == KEY_RSA &&
719 sshkey_type_plain(key->type) == KEY_RSA;
712 if ((r = sshbuf_put_cstring(sigbuf, 720 if ((r = sshbuf_put_cstring(sigbuf,
713 "hostkeys-prove-00@openssh.com")) != 0 || 721 "hostkeys-prove-00@openssh.com")) != 0 ||
714 (r = sshbuf_put_string(sigbuf, 722 (r = sshbuf_put_string(sigbuf,
@@ -716,7 +724,7 @@ server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
716 (r = sshkey_puts(key, sigbuf)) != 0 || 724 (r = sshkey_puts(key, sigbuf)) != 0 ||
717 (r = ssh->kex->sign(key_prv, key_pub, &sig, &slen, 725 (r = ssh->kex->sign(key_prv, key_pub, &sig, &slen,
718 sshbuf_ptr(sigbuf), sshbuf_len(sigbuf), 726 sshbuf_ptr(sigbuf), sshbuf_len(sigbuf),
719 ssh->kex->hostkey_alg, 0)) != 0 || 727 use_kexsigtype ? ssh->kex->hostkey_alg : NULL, 0)) != 0 ||
720 (r = sshbuf_put_string(resp, sig, slen)) != 0) { 728 (r = sshbuf_put_string(resp, sig, slen)) != 0) {
721 error("%s: couldn't prepare signature: %s", 729 error("%s: couldn't prepare signature: %s",
722 __func__, ssh_err(r)); 730 __func__, ssh_err(r));