|
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 | 3 | * Author: Tatu Ylonen <[email protected]>
|
4 | 4 | * Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
|
@@ -671,14 +671,16 @@ server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
|
671 | 671 | struct sshbuf *resp = NULL;
|
672 | 672 | struct sshbuf *sigbuf = NULL;
|
673 | 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 | 675 | const u_char *blob;
|
676 | 676 | u_char *sig = 0;
|
677 | 677 | size_t blen, slen;
|
678 | 678 |
|
679 | 679 | if ((resp = sshbuf_new()) == NULL || (sigbuf = sshbuf_new()) == NULL)
|
680 | 680 | fatal("%s: sshbuf_new", __func__);
|
681 | 681 |
|
| 682 | + kexsigtype = sshkey_type_plain( |
| 683 | + sshkey_type_from_name(ssh->kex->hostkey_alg)); |
682 | 684 | while (ssh_packet_remaining(ssh) > 0) {
|
683 | 685 | sshkey_free(key);
|
684 | 686 | key = NULL;
|
@@ -709,14 +711,20 @@ server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
|
709 | 711 | sshbuf_reset(sigbuf);
|
710 | 712 | free(sig);
|
711 | 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 | 720 | if ((r = sshbuf_put_cstring(sigbuf,
|
713 | 721 |
|
714 | 722 | (r = sshbuf_put_string(sigbuf,
|
715 | 723 | ssh->kex->session_id, ssh->kex->session_id_len)) != 0 ||
|
716 | 724 | (r = sshkey_puts(key, sigbuf)) != 0 ||
|
717 | 725 | (r = ssh->kex->sign(key_prv, key_pub, &sig, &slen,
|
718 | 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 | 728 | (r = sshbuf_put_string(resp, sig, slen)) != 0) {
|
721 | 729 | error("%s: couldn't prepare signature: %s",
|
722 | 730 | __func__, ssh_err(r));
|
|
0 commit comments