summaryrefslogtreecommitdiff
path: root/kex.c
diff options
context:
space:
mode:
Diffstat (limited to 'kex.c')
-rw-r--r--kex.c66
1 files changed, 63 insertions, 3 deletions
diff --git a/kex.c b/kex.c
index 34808b5c3..a2a4794e8 100644
--- a/kex.c
+++ b/kex.c
@@ -55,11 +55,16 @@
55#include "misc.h" 55#include "misc.h"
56#include "dispatch.h" 56#include "dispatch.h"
57#include "monitor.h" 57#include "monitor.h"
58#include "xmalloc.h"
58 59
59#include "ssherr.h" 60#include "ssherr.h"
60#include "sshbuf.h" 61#include "sshbuf.h"
61#include "digest.h" 62#include "digest.h"
62 63
64#ifdef GSSAPI
65#include "ssh-gss.h"
66#endif
67
63/* prototype */ 68/* prototype */
64static int kex_choose_conf(struct ssh *); 69static int kex_choose_conf(struct ssh *);
65static int kex_input_newkeys(int, u_int32_t, struct ssh *); 70static int kex_input_newkeys(int, u_int32_t, struct ssh *);
@@ -113,15 +118,28 @@ static const struct kexalg kexalgs[] = {
113#endif /* HAVE_EVP_SHA256 || !WITH_OPENSSL */ 118#endif /* HAVE_EVP_SHA256 || !WITH_OPENSSL */
114 { NULL, -1, -1, -1}, 119 { NULL, -1, -1, -1},
115}; 120};
121static const struct kexalg gss_kexalgs[] = {
122#ifdef GSSAPI
123 { KEX_GSS_GEX_SHA1_ID, KEX_GSS_GEX_SHA1, 0, SSH_DIGEST_SHA1 },
124 { KEX_GSS_GRP1_SHA1_ID, KEX_GSS_GRP1_SHA1, 0, SSH_DIGEST_SHA1 },
125 { KEX_GSS_GRP14_SHA1_ID, KEX_GSS_GRP14_SHA1, 0, SSH_DIGEST_SHA1 },
126 { KEX_GSS_GRP14_SHA256_ID, KEX_GSS_GRP14_SHA256, 0, SSH_DIGEST_SHA256 },
127 { KEX_GSS_GRP16_SHA512_ID, KEX_GSS_GRP16_SHA512, 0, SSH_DIGEST_SHA512 },
128 { KEX_GSS_NISTP256_SHA256_ID, KEX_GSS_NISTP256_SHA256,
129 NID_X9_62_prime256v1, SSH_DIGEST_SHA256 },
130 { KEX_GSS_C25519_SHA256_ID, KEX_GSS_C25519_SHA256, 0, SSH_DIGEST_SHA256 },
131#endif
132 { NULL, -1, -1, -1 },
133};
116 134
117char * 135static char *
118kex_alg_list(char sep) 136kex_alg_list_internal(char sep, const struct kexalg *algs)
119{ 137{
120 char *ret = NULL, *tmp; 138 char *ret = NULL, *tmp;
121 size_t nlen, rlen = 0; 139 size_t nlen, rlen = 0;
122 const struct kexalg *k; 140 const struct kexalg *k;
123 141
124 for (k = kexalgs; k->name != NULL; k++) { 142 for (k = algs; k->name != NULL; k++) {
125 if (ret != NULL) 143 if (ret != NULL)
126 ret[rlen++] = sep; 144 ret[rlen++] = sep;
127 nlen = strlen(k->name); 145 nlen = strlen(k->name);
@@ -136,6 +154,18 @@ kex_alg_list(char sep)
136 return ret; 154 return ret;
137} 155}
138 156
157char *
158kex_alg_list(char sep)
159{
160 return kex_alg_list_internal(sep, kexalgs);
161}
162
163char *
164kex_gss_alg_list(char sep)
165{
166 return kex_alg_list_internal(sep, gss_kexalgs);
167}
168
139static const struct kexalg * 169static const struct kexalg *
140kex_alg_by_name(const char *name) 170kex_alg_by_name(const char *name)
141{ 171{
@@ -145,6 +175,10 @@ kex_alg_by_name(const char *name)
145 if (strcmp(k->name, name) == 0) 175 if (strcmp(k->name, name) == 0)
146 return k; 176 return k;
147 } 177 }
178 for (k = gss_kexalgs; k->name != NULL; k++) {
179 if (strncmp(k->name, name, strlen(k->name)) == 0)
180 return k;
181 }
148 return NULL; 182 return NULL;
149} 183}
150 184
@@ -301,6 +335,29 @@ kex_assemble_names(char **listp, const char *def, const char *all)
301 return r; 335 return r;
302} 336}
303 337
338/* Validate GSS KEX method name list */
339int
340kex_gss_names_valid(const char *names)
341{
342 char *s, *cp, *p;
343
344 if (names == NULL || *names == '\0')
345 return 0;
346 s = cp = xstrdup(names);
347 for ((p = strsep(&cp, ",")); p && *p != '\0';
348 (p = strsep(&cp, ","))) {
349 if (strncmp(p, "gss-", 4) != 0
350 || kex_alg_by_name(p) == NULL) {
351 error("Unsupported KEX algorithm \"%.100s\"", p);
352 free(s);
353 return 0;
354 }
355 }
356 debug3("gss kex names ok: [%s]", names);
357 free(s);
358 return 1;
359}
360
304/* put algorithm proposal into buffer */ 361/* put algorithm proposal into buffer */
305int 362int
306kex_prop2buf(struct sshbuf *b, char *proposal[PROPOSAL_MAX]) 363kex_prop2buf(struct sshbuf *b, char *proposal[PROPOSAL_MAX])
@@ -657,6 +714,9 @@ kex_free(struct kex *kex)
657 sshbuf_free(kex->server_version); 714 sshbuf_free(kex->server_version);
658 sshbuf_free(kex->client_pub); 715 sshbuf_free(kex->client_pub);
659 free(kex->session_id); 716 free(kex->session_id);
717#ifdef GSSAPI
718 free(kex->gss_host);
719#endif /* GSSAPI */
660 free(kex->failed_choice); 720 free(kex->failed_choice);
661 free(kex->hostkey_alg); 721 free(kex->hostkey_alg);
662 free(kex->name); 722 free(kex->name);