summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kex.c18
-rw-r--r--kex.h3
-rw-r--r--kexc25519c.c17
-rw-r--r--kexdhc.c16
-rw-r--r--kexecdhc.c16
-rw-r--r--kexgexc.c16
6 files changed, 27 insertions, 59 deletions
diff --git a/kex.c b/kex.c
index a0d13a880..d8c71bb3e 100644
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.c,v 1.145 2019/01/21 10:05:09 djm Exp $ */ 1/* $OpenBSD: kex.c,v 1.146 2019/01/21 10:07:22 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -1071,6 +1071,22 @@ kex_load_hostkey(struct ssh *ssh, struct sshkey **pubp, struct sshkey **prvp)
1071 return 0; 1071 return 0;
1072} 1072}
1073 1073
1074int
1075kex_verify_host_key(struct ssh *ssh, struct sshkey *server_host_key)
1076{
1077 struct kex *kex = ssh->kex;
1078
1079 if (kex->verify_host_key == NULL)
1080 return SSH_ERR_INVALID_ARGUMENT;
1081 if (server_host_key->type != kex->hostkey_type ||
1082 (kex->hostkey_type == KEY_ECDSA &&
1083 server_host_key->ecdsa_nid != kex->hostkey_nid))
1084 return SSH_ERR_KEY_TYPE_MISMATCH;
1085 if (kex->verify_host_key(server_host_key, ssh) == -1)
1086 return SSH_ERR_SIGNATURE_INVALID;
1087 return 0;
1088}
1089
1074#if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) || defined(DEBUG_KEXECDH) 1090#if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) || defined(DEBUG_KEXECDH)
1075void 1091void
1076dump_digest(char *msg, u_char *digest, int len) 1092dump_digest(char *msg, u_char *digest, int len)
diff --git a/kex.h b/kex.h
index fa65b8657..e404d0365 100644
--- a/kex.h
+++ b/kex.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.h,v 1.97 2019/01/21 10:05:09 djm Exp $ */ 1/* $OpenBSD: kex.h,v 1.98 2019/01/21 10:07:22 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
@@ -185,6 +185,7 @@ int kex_buf2prop(struct sshbuf *, int *, char ***);
185int kex_prop2buf(struct sshbuf *, char *proposal[PROPOSAL_MAX]); 185int kex_prop2buf(struct sshbuf *, char *proposal[PROPOSAL_MAX]);
186void kex_prop_free(char **); 186void kex_prop_free(char **);
187int kex_load_hostkey(struct ssh *, struct sshkey **, struct sshkey **); 187int kex_load_hostkey(struct ssh *, struct sshkey **, struct sshkey **);
188int kex_verify_host_key(struct ssh *, struct sshkey *);
188 189
189int kex_send_kexinit(struct ssh *); 190int kex_send_kexinit(struct ssh *);
190int kex_input_kexinit(int, u_int32_t, struct ssh *); 191int kex_input_kexinit(int, u_int32_t, struct ssh *);
diff --git a/kexc25519c.c b/kexc25519c.c
index 59b4e4cc0..1c7f79000 100644
--- a/kexc25519c.c
+++ b/kexc25519c.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexc25519c.c,v 1.11 2019/01/21 09:55:52 djm Exp $ */ 1/* $OpenBSD: kexc25519c.c,v 1.12 2019/01/21 10:07:22 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved. 4 * Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -80,27 +80,14 @@ input_kex_c25519_reply(int type, u_int32_t seq, struct ssh *ssh)
80 size_t slen, pklen, sbloblen, hashlen; 80 size_t slen, pklen, sbloblen, hashlen;
81 int r; 81 int r;
82 82
83 if (kex->verify_host_key == NULL) {
84 r = SSH_ERR_INVALID_ARGUMENT;
85 goto out;
86 }
87
88 /* hostkey */ 83 /* hostkey */
89 if ((r = sshpkt_get_string(ssh, &server_host_key_blob, 84 if ((r = sshpkt_get_string(ssh, &server_host_key_blob,
90 &sbloblen)) != 0 || 85 &sbloblen)) != 0 ||
91 (r = sshkey_from_blob(server_host_key_blob, sbloblen, 86 (r = sshkey_from_blob(server_host_key_blob, sbloblen,
92 &server_host_key)) != 0) 87 &server_host_key)) != 0)
93 goto out; 88 goto out;
94 if (server_host_key->type != kex->hostkey_type || 89 if ((r = kex_verify_host_key(ssh, server_host_key)) != 0)
95 (kex->hostkey_type == KEY_ECDSA &&
96 server_host_key->ecdsa_nid != kex->hostkey_nid)) {
97 r = SSH_ERR_KEY_TYPE_MISMATCH;
98 goto out; 90 goto out;
99 }
100 if (kex->verify_host_key(server_host_key, ssh) == -1) {
101 r = SSH_ERR_SIGNATURE_INVALID;
102 goto out;
103 }
104 91
105 /* Q_S, server public key */ 92 /* Q_S, server public key */
106 /* signed H */ 93 /* signed H */
diff --git a/kexdhc.c b/kexdhc.c
index 2e26f22ea..a2af8cb08 100644
--- a/kexdhc.c
+++ b/kexdhc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexdhc.c,v 1.28 2019/01/21 10:03:37 djm Exp $ */ 1/* $OpenBSD: kexdhc.c,v 1.29 2019/01/21 10:07:22 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -95,26 +95,14 @@ input_kex_dh(int type, u_int32_t seq, struct ssh *ssh)
95 size_t slen, sbloblen, hashlen; 95 size_t slen, sbloblen, hashlen;
96 int r; 96 int r;
97 97
98 if (kex->verify_host_key == NULL) {
99 r = SSH_ERR_INVALID_ARGUMENT;
100 goto out;
101 }
102 /* key, cert */ 98 /* key, cert */
103 if ((r = sshpkt_get_string(ssh, &server_host_key_blob, 99 if ((r = sshpkt_get_string(ssh, &server_host_key_blob,
104 &sbloblen)) != 0 || 100 &sbloblen)) != 0 ||
105 (r = sshkey_from_blob(server_host_key_blob, sbloblen, 101 (r = sshkey_from_blob(server_host_key_blob, sbloblen,
106 &server_host_key)) != 0) 102 &server_host_key)) != 0)
107 goto out; 103 goto out;
108 if (server_host_key->type != kex->hostkey_type || 104 if ((r = kex_verify_host_key(ssh, server_host_key)) != 0)
109 (kex->hostkey_type == KEY_ECDSA &&
110 server_host_key->ecdsa_nid != kex->hostkey_nid)) {
111 r = SSH_ERR_KEY_TYPE_MISMATCH;
112 goto out; 105 goto out;
113 }
114 if (kex->verify_host_key(server_host_key, ssh) == -1) {
115 r = SSH_ERR_SIGNATURE_INVALID;
116 goto out;
117 }
118 /* DH parameter f, server public DH key, signed H */ 106 /* DH parameter f, server public DH key, signed H */
119 if ((r = sshpkt_get_bignum2(ssh, &dh_server_pub)) != 0 || 107 if ((r = sshpkt_get_bignum2(ssh, &dh_server_pub)) != 0 ||
120 (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 || 108 (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 ||
diff --git a/kexecdhc.c b/kexecdhc.c
index 2cff34347..bfb9f4707 100644
--- a/kexecdhc.c
+++ b/kexecdhc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexecdhc.c,v 1.15 2019/01/21 09:55:52 djm Exp $ */ 1/* $OpenBSD: kexecdhc.c,v 1.16 2019/01/21 10:07:22 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved. 4 * Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -109,10 +109,6 @@ input_kex_ecdh_reply(int type, u_int32_t seq, struct ssh *ssh)
109 size_t klen = 0, hashlen; 109 size_t klen = 0, hashlen;
110 int r; 110 int r;
111 111
112 if (kex->verify_host_key == NULL) {
113 r = SSH_ERR_INVALID_ARGUMENT;
114 goto out;
115 }
116 group = kex->ec_group; 112 group = kex->ec_group;
117 client_key = kex->ec_client_key; 113 client_key = kex->ec_client_key;
118 114
@@ -122,16 +118,8 @@ input_kex_ecdh_reply(int type, u_int32_t seq, struct ssh *ssh)
122 (r = sshkey_from_blob(server_host_key_blob, sbloblen, 118 (r = sshkey_from_blob(server_host_key_blob, sbloblen,
123 &server_host_key)) != 0) 119 &server_host_key)) != 0)
124 goto out; 120 goto out;
125 if (server_host_key->type != kex->hostkey_type || 121 if ((r = kex_verify_host_key(ssh, server_host_key)) != 0)
126 (kex->hostkey_type == KEY_ECDSA &&
127 server_host_key->ecdsa_nid != kex->hostkey_nid)) {
128 r = SSH_ERR_KEY_TYPE_MISMATCH;
129 goto out; 122 goto out;
130 }
131 if (kex->verify_host_key(server_host_key, ssh) == -1) {
132 r = SSH_ERR_SIGNATURE_INVALID;
133 goto out;
134 }
135 123
136 /* Q_S, server public key */ 124 /* Q_S, server public key */
137 /* signed H */ 125 /* signed H */
diff --git a/kexgexc.c b/kexgexc.c
index 600d91acc..ac42127af 100644
--- a/kexgexc.c
+++ b/kexgexc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexgexc.c,v 1.32 2019/01/21 10:03:37 djm Exp $ */ 1/* $OpenBSD: kexgexc.c,v 1.33 2019/01/21 10:07:22 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2001 Markus Friedl. All rights reserved.
@@ -153,26 +153,14 @@ input_kex_dh_gex_reply(int type, u_int32_t seq, struct ssh *ssh)
153 int r; 153 int r;
154 154
155 debug("got SSH2_MSG_KEX_DH_GEX_REPLY"); 155 debug("got SSH2_MSG_KEX_DH_GEX_REPLY");
156 if (kex->verify_host_key == NULL) {
157 r = SSH_ERR_INVALID_ARGUMENT;
158 goto out;
159 }
160 /* key, cert */ 156 /* key, cert */
161 if ((r = sshpkt_get_string(ssh, &server_host_key_blob, 157 if ((r = sshpkt_get_string(ssh, &server_host_key_blob,
162 &sbloblen)) != 0 || 158 &sbloblen)) != 0 ||
163 (r = sshkey_from_blob(server_host_key_blob, sbloblen, 159 (r = sshkey_from_blob(server_host_key_blob, sbloblen,
164 &server_host_key)) != 0) 160 &server_host_key)) != 0)
165 goto out; 161 goto out;
166 if (server_host_key->type != kex->hostkey_type || 162 if ((r = kex_verify_host_key(ssh, server_host_key)) != 0)
167 (kex->hostkey_type == KEY_ECDSA &&
168 server_host_key->ecdsa_nid != kex->hostkey_nid)) {
169 r = SSH_ERR_KEY_TYPE_MISMATCH;
170 goto out; 163 goto out;
171 }
172 if (kex->verify_host_key(server_host_key, ssh) == -1) {
173 r = SSH_ERR_SIGNATURE_INVALID;
174 goto out;
175 }
176 /* DH parameter f, server public DH key, signed H */ 164 /* DH parameter f, server public DH key, signed H */
177 if ((r = sshpkt_get_bignum2(ssh, &dh_server_pub)) != 0 || 165 if ((r = sshpkt_get_bignum2(ssh, &dh_server_pub)) != 0 ||
178 (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 || 166 (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 ||