summaryrefslogtreecommitdiff
path: root/debian/patches/gssapi.patch
diff options
context:
space:
mode:
Diffstat (limited to 'debian/patches/gssapi.patch')
-rw-r--r--debian/patches/gssapi.patch252
1 files changed, 142 insertions, 110 deletions
diff --git a/debian/patches/gssapi.patch b/debian/patches/gssapi.patch
index 25edd5cbe..f62bf6672 100644
--- a/debian/patches/gssapi.patch
+++ b/debian/patches/gssapi.patch
@@ -1,4 +1,4 @@
1From e6c7c11ac2576ac62334616bd4408bf64140bba7 Mon Sep 17 00:00:00 2001 1From 72b1d308e6400194ef6e4e7dd45bfa48fa39b5e6 Mon Sep 17 00:00:00 2001
2From: Simon Wilkinson <simon@sxw.org.uk> 2From: Simon Wilkinson <simon@sxw.org.uk>
3Date: Sun, 9 Feb 2014 16:09:48 +0000 3Date: Sun, 9 Feb 2014 16:09:48 +0000
4Subject: GSSAPI key exchange support 4Subject: GSSAPI key exchange support
@@ -17,14 +17,14 @@ have it merged into the main openssh package rather than having separate
17security history. 17security history.
18 18
19Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1242 19Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1242
20Last-Updated: 2018-08-24 20Last-Updated: 2018-10-20
21 21
22Patch-Name: gssapi.patch 22Patch-Name: gssapi.patch
23--- 23---
24 ChangeLog.gssapi | 113 ++++++++++++++++ 24 ChangeLog.gssapi | 113 ++++++++++++++++
25 Makefile.in | 3 +- 25 Makefile.in | 3 +-
26 auth-krb5.c | 17 ++- 26 auth-krb5.c | 17 ++-
27 auth.c | 96 +------------- 27 auth.c | 96 +------------
28 auth2-gss.c | 54 +++++++- 28 auth2-gss.c | 54 +++++++-
29 auth2.c | 2 + 29 auth2.c | 2 +
30 canohost.c | 93 +++++++++++++ 30 canohost.c | 93 +++++++++++++
@@ -32,17 +32,19 @@ Patch-Name: gssapi.patch
32 clientloop.c | 15 ++- 32 clientloop.c | 15 ++-
33 config.h.in | 6 + 33 config.h.in | 6 +
34 configure.ac | 24 ++++ 34 configure.ac | 24 ++++
35 gss-genr.c | 277 +++++++++++++++++++++++++++++++++++++- 35 gss-genr.c | 280 +++++++++++++++++++++++++++++++++++++-
36 gss-serv-krb5.c | 85 +++++++++++- 36 gss-serv-krb5.c | 85 +++++++++++-
37 gss-serv.c | 184 ++++++++++++++++++++++++-- 37 gss-serv.c | 184 +++++++++++++++++++++++--
38 kex.c | 19 +++ 38 kex.c | 19 +++
39 kex.h | 14 ++ 39 kex.h | 14 ++
40 kexgssc.c | 338 +++++++++++++++++++++++++++++++++++++++++++++++ 40 kexgssc.c | 341 +++++++++++++++++++++++++++++++++++++++++++++++
41 kexgsss.c | 295 +++++++++++++++++++++++++++++++++++++++++ 41 kexgsss.c | 300 +++++++++++++++++++++++++++++++++++++++++
42 monitor.c | 122 +++++++++++++++-- 42 monitor.c | 122 +++++++++++++++--
43 monitor.h | 3 + 43 monitor.h | 3 +
44 monitor_wrap.c | 53 +++++++- 44 monitor_wrap.c | 53 +++++++-
45 monitor_wrap.h | 4 +- 45 monitor_wrap.h | 4 +-
46 opacket.c | 2 +-
47 opacket.h | 2 +-
46 readconf.c | 43 ++++++ 48 readconf.c | 43 ++++++
47 readconf.h | 5 + 49 readconf.h | 5 +
48 servconf.c | 26 ++++ 50 servconf.c | 26 ++++
@@ -50,13 +52,13 @@ Patch-Name: gssapi.patch
50 ssh-gss.h | 41 +++++- 52 ssh-gss.h | 41 +++++-
51 ssh_config | 2 + 53 ssh_config | 2 +
52 ssh_config.5 | 32 +++++ 54 ssh_config.5 | 32 +++++
53 sshconnect2.c | 133 ++++++++++++++++++- 55 sshconnect2.c | 133 +++++++++++++++++-
54 sshd.c | 112 +++++++++++++++- 56 sshd.c | 110 +++++++++++++++
55 sshd_config | 2 + 57 sshd_config | 2 +
56 sshd_config.5 | 10 ++ 58 sshd_config.5 | 10 ++
57 sshkey.c | 3 +- 59 sshkey.c | 3 +-
58 sshkey.h | 1 + 60 sshkey.h | 1 +
59 35 files changed, 2087 insertions(+), 145 deletions(-) 61 37 files changed, 2099 insertions(+), 146 deletions(-)
60 create mode 100644 ChangeLog.gssapi 62 create mode 100644 ChangeLog.gssapi
61 create mode 100644 kexgssc.c 63 create mode 100644 kexgssc.c
62 create mode 100644 kexgsss.c 64 create mode 100644 kexgsss.c
@@ -181,7 +183,7 @@ index 000000000..f117a336a
181+ (from jbasney AT ncsa.uiuc.edu) 183+ (from jbasney AT ncsa.uiuc.edu)
182+ <gssapi-with-mic support is Bugzilla #1008> 184+ <gssapi-with-mic support is Bugzilla #1008>
183diff --git a/Makefile.in b/Makefile.in 185diff --git a/Makefile.in b/Makefile.in
184index 2385c62a8..6175c6063 100644 186index 126b2c742..70050ffb6 100644
185--- a/Makefile.in 187--- a/Makefile.in
186+++ b/Makefile.in 188+++ b/Makefile.in
187@@ -100,6 +100,7 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \ 189@@ -100,6 +100,7 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
@@ -253,10 +255,10 @@ index 3096f1c8e..204752e1b 100644
253 return (krb5_cc_resolve(ctx, ccname, ccache)); 255 return (krb5_cc_resolve(ctx, ccname, ccache));
254 } 256 }
255diff --git a/auth.c b/auth.c 257diff --git a/auth.c b/auth.c
256index 9a3bc96f1..80eb78c48 100644 258index 3ca3762cc..d8e6b4a3d 100644
257--- a/auth.c 259--- a/auth.c
258+++ b/auth.c 260+++ b/auth.c
259@@ -395,7 +395,8 @@ auth_root_allowed(struct ssh *ssh, const char *method) 261@@ -399,7 +399,8 @@ auth_root_allowed(struct ssh *ssh, const char *method)
260 case PERMIT_NO_PASSWD: 262 case PERMIT_NO_PASSWD:
261 if (strcmp(method, "publickey") == 0 || 263 if (strcmp(method, "publickey") == 0 ||
262 strcmp(method, "hostbased") == 0 || 264 strcmp(method, "hostbased") == 0 ||
@@ -266,7 +268,7 @@ index 9a3bc96f1..80eb78c48 100644
266 return 1; 268 return 1;
267 break; 269 break;
268 case PERMIT_FORCED_ONLY: 270 case PERMIT_FORCED_ONLY:
269@@ -733,99 +734,6 @@ fakepw(void) 271@@ -737,99 +738,6 @@ fakepw(void)
270 return (&fake); 272 return (&fake);
271 } 273 }
272 274
@@ -460,7 +462,7 @@ index 9351e0428..1f12bb113 100644
460 "gssapi-with-mic", 462 "gssapi-with-mic",
461 userauth_gssapi, 463 userauth_gssapi,
462diff --git a/auth2.c b/auth2.c 464diff --git a/auth2.c b/auth2.c
463index ab8795895..96efe164c 100644 465index 4d19957a6..a77742819 100644
464--- a/auth2.c 466--- a/auth2.c
465+++ b/auth2.c 467+++ b/auth2.c
466@@ -74,6 +74,7 @@ extern Authmethod method_passwd; 468@@ -74,6 +74,7 @@ extern Authmethod method_passwd;
@@ -598,7 +600,7 @@ index 26d62855a..0cadc9f18 100644
598 int get_peer_port(int); 600 int get_peer_port(int);
599 char *get_local_ipaddr(int); 601 char *get_local_ipaddr(int);
600diff --git a/clientloop.c b/clientloop.c 602diff --git a/clientloop.c b/clientloop.c
601index ad35cb7ba..e69c5141f 100644 603index 8d312cdaa..1464634b0 100644
602--- a/clientloop.c 604--- a/clientloop.c
603+++ b/clientloop.c 605+++ b/clientloop.c
604@@ -112,6 +112,10 @@ 606@@ -112,6 +112,10 @@
@@ -612,7 +614,7 @@ index ad35cb7ba..e69c5141f 100644
612 /* import options */ 614 /* import options */
613 extern Options options; 615 extern Options options;
614 616
615@@ -1357,9 +1361,18 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, 617@@ -1370,9 +1374,18 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
616 break; 618 break;
617 619
618 /* Do channel operations unless rekeying in progress. */ 620 /* Do channel operations unless rekeying in progress. */
@@ -633,10 +635,10 @@ index ad35cb7ba..e69c5141f 100644
633 client_process_net_input(readset); 635 client_process_net_input(readset);
634 636
635diff --git a/config.h.in b/config.h.in 637diff --git a/config.h.in b/config.h.in
636index 7940b4c86..93295da07 100644 638index 91b65db8f..209760c7c 100644
637--- a/config.h.in 639--- a/config.h.in
638+++ b/config.h.in 640+++ b/config.h.in
639@@ -1749,6 +1749,9 @@ 641@@ -1845,6 +1845,9 @@
640 /* Use btmp to log bad logins */ 642 /* Use btmp to log bad logins */
641 #undef USE_BTMP 643 #undef USE_BTMP
642 644
@@ -646,7 +648,7 @@ index 7940b4c86..93295da07 100644
646 /* Use libedit for sftp */ 648 /* Use libedit for sftp */
647 #undef USE_LIBEDIT 649 #undef USE_LIBEDIT
648 650
649@@ -1764,6 +1767,9 @@ 651@@ -1860,6 +1863,9 @@
650 /* Use PIPES instead of a socketpair() */ 652 /* Use PIPES instead of a socketpair() */
651 #undef USE_PIPES 653 #undef USE_PIPES
652 654
@@ -657,10 +659,10 @@ index 7940b4c86..93295da07 100644
657 #undef USE_SOLARIS_PRIVS 659 #undef USE_SOLARIS_PRIVS
658 660
659diff --git a/configure.ac b/configure.ac 661diff --git a/configure.ac b/configure.ac
660index 83e530750..82428b241 100644 662index 7379ab358..023e7cc55 100644
661--- a/configure.ac 663--- a/configure.ac
662+++ b/configure.ac 664+++ b/configure.ac
663@@ -673,6 +673,30 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16)) 665@@ -664,6 +664,30 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
664 [Use tunnel device compatibility to OpenBSD]) 666 [Use tunnel device compatibility to OpenBSD])
665 AC_DEFINE([SSH_TUN_PREPEND_AF], [1], 667 AC_DEFINE([SSH_TUN_PREPEND_AF], [1],
666 [Prepend the address family to IP tunnel traffic]) 668 [Prepend the address family to IP tunnel traffic])
@@ -692,7 +694,7 @@ index 83e530750..82428b241 100644
692 AC_CHECK_DECL([AU_IPv4], [], 694 AC_CHECK_DECL([AU_IPv4], [],
693 AC_DEFINE([AU_IPv4], [0], [System only supports IPv4 audit records]) 695 AC_DEFINE([AU_IPv4], [0], [System only supports IPv4 audit records])
694diff --git a/gss-genr.c b/gss-genr.c 696diff --git a/gss-genr.c b/gss-genr.c
695index d56257b4a..285fc29a5 100644 697index d56257b4a..491e62cee 100644
696--- a/gss-genr.c 698--- a/gss-genr.c
697+++ b/gss-genr.c 699+++ b/gss-genr.c
698@@ -1,7 +1,7 @@ 700@@ -1,7 +1,7 @@
@@ -704,13 +706,16 @@ index d56257b4a..285fc29a5 100644
704 * 706 *
705 * Redistribution and use in source and binary forms, with or without 707 * Redistribution and use in source and binary forms, with or without
706 * modification, are permitted provided that the following conditions 708 * modification, are permitted provided that the following conditions
707@@ -41,12 +41,34 @@ 709@@ -39,14 +39,37 @@
710 #include "xmalloc.h"
711 #include "ssherr.h"
708 #include "sshbuf.h" 712 #include "sshbuf.h"
713+#include "sshkey.h"
709 #include "log.h" 714 #include "log.h"
710 #include "ssh2.h" 715 #include "ssh2.h"
711+#include "cipher.h" 716+#include "cipher.h"
712+#include "kex.h" 717+#include "kex.h"
713+#include <openssl/evp.h> 718+#include "digest.h"
714 719
715 #include "ssh-gss.h" 720 #include "ssh-gss.h"
716 721
@@ -739,7 +744,7 @@ index d56257b4a..285fc29a5 100644
739 /* sshbuf_get for gss_buffer_desc */ 744 /* sshbuf_get for gss_buffer_desc */
740 int 745 int
741 ssh_gssapi_get_buffer_desc(struct sshbuf *b, gss_buffer_desc *g) 746 ssh_gssapi_get_buffer_desc(struct sshbuf *b, gss_buffer_desc *g)
742@@ -62,6 +84,141 @@ ssh_gssapi_get_buffer_desc(struct sshbuf *b, gss_buffer_desc *g) 747@@ -62,6 +85,143 @@ ssh_gssapi_get_buffer_desc(struct sshbuf *b, gss_buffer_desc *g)
743 return 0; 748 return 0;
744 } 749 }
745 750
@@ -769,10 +774,9 @@ index d56257b4a..285fc29a5 100644
769+ size_t i; 774+ size_t i;
770+ int r, oidpos, enclen; 775+ int r, oidpos, enclen;
771+ char *mechs, *encoded; 776+ char *mechs, *encoded;
772+ u_char digest[EVP_MAX_MD_SIZE]; 777+ u_char digest[SSH_DIGEST_MAX_LENGTH];
773+ char deroid[2]; 778+ char deroid[2];
774+ const EVP_MD *evp_md = EVP_md5(); 779+ struct ssh_digest_ctx *md;
775+ EVP_MD_CTX md;
776+ 780+
777+ if (gss_enc2oid != NULL) { 781+ if (gss_enc2oid != NULL) {
778+ for (i = 0; gss_enc2oid[i].encoded != NULL; i++) 782+ for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
@@ -794,16 +798,19 @@ index d56257b4a..285fc29a5 100644
794+ deroid[0] = SSH_GSS_OIDTYPE; 798+ deroid[0] = SSH_GSS_OIDTYPE;
795+ deroid[1] = gss_supported->elements[i].length; 799+ deroid[1] = gss_supported->elements[i].length;
796+ 800+
797+ EVP_DigestInit(&md, evp_md); 801+ if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL ||
798+ EVP_DigestUpdate(&md, deroid, 2); 802+ ssh_digest_update(md, deroid, 2) != 0 ||
799+ EVP_DigestUpdate(&md, 803+ ssh_digest_update(md,
800+ gss_supported->elements[i].elements, 804+ gss_supported->elements[i].elements,
801+ gss_supported->elements[i].length); 805+ gss_supported->elements[i].length) != 0 ||
802+ EVP_DigestFinal(&md, digest, NULL); 806+ ssh_digest_final(md, digest, sizeof(digest)) != 0)
807+ fatal("%s: digest failed", __func__);
803+ 808+
804+ encoded = xmalloc(EVP_MD_size(evp_md) * 2); 809+ encoded = xmalloc(ssh_digest_bytes(SSH_DIGEST_MD5)
805+ enclen = __b64_ntop(digest, EVP_MD_size(evp_md), 810+ * 2);
806+ encoded, EVP_MD_size(evp_md) * 2); 811+ enclen = __b64_ntop(digest,
812+ ssh_digest_bytes(SSH_DIGEST_MD5), encoded,
813+ ssh_digest_bytes(SSH_DIGEST_MD5) * 2);
807+ 814+
808+ if (oidpos != 0) { 815+ if (oidpos != 0) {
809+ if ((r = sshbuf_put_u8(buf, ',')) != 0) 816+ if ((r = sshbuf_put_u8(buf, ',')) != 0)
@@ -881,7 +888,7 @@ index d56257b4a..285fc29a5 100644
881 /* Check that the OID in a data stream matches that in the context */ 888 /* Check that the OID in a data stream matches that in the context */
882 int 889 int
883 ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len) 890 ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len)
884@@ -218,7 +375,7 @@ ssh_gssapi_init_ctx(Gssctxt *ctx, int deleg_creds, gss_buffer_desc *recv_tok, 891@@ -218,7 +378,7 @@ ssh_gssapi_init_ctx(Gssctxt *ctx, int deleg_creds, gss_buffer_desc *recv_tok,
885 } 892 }
886 893
887 ctx->major = gss_init_sec_context(&ctx->minor, 894 ctx->major = gss_init_sec_context(&ctx->minor,
@@ -890,7 +897,7 @@ index d56257b4a..285fc29a5 100644
890 GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag, 897 GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag,
891 0, NULL, recv_tok, NULL, send_tok, flags, NULL); 898 0, NULL, recv_tok, NULL, send_tok, flags, NULL);
892 899
893@@ -247,9 +404,43 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host) 900@@ -247,9 +407,43 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host)
894 return (ctx->major); 901 return (ctx->major);
895 } 902 }
896 903
@@ -934,7 +941,7 @@ index d56257b4a..285fc29a5 100644
934 if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context, 941 if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context,
935 GSS_C_QOP_DEFAULT, buffer, hash))) 942 GSS_C_QOP_DEFAULT, buffer, hash)))
936 ssh_gssapi_error(ctx); 943 ssh_gssapi_error(ctx);
937@@ -257,6 +448,19 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash) 944@@ -257,6 +451,19 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
938 return (ctx->major); 945 return (ctx->major);
939 } 946 }
940 947
@@ -954,7 +961,7 @@ index d56257b4a..285fc29a5 100644
954 void 961 void
955 ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service, 962 ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service,
956 const char *context) 963 const char *context)
957@@ -273,11 +477,16 @@ ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service, 964@@ -273,11 +480,16 @@ ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service,
958 } 965 }
959 966
960 int 967 int
@@ -972,7 +979,7 @@ index d56257b4a..285fc29a5 100644
972 979
973 /* RFC 4462 says we MUST NOT do SPNEGO */ 980 /* RFC 4462 says we MUST NOT do SPNEGO */
974 if (oid->length == spnego_oid.length && 981 if (oid->length == spnego_oid.length &&
975@@ -287,6 +496,10 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host) 982@@ -287,6 +499,10 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
976 ssh_gssapi_build_ctx(ctx); 983 ssh_gssapi_build_ctx(ctx);
977 ssh_gssapi_set_oid(*ctx, oid); 984 ssh_gssapi_set_oid(*ctx, oid);
978 major = ssh_gssapi_import_name(*ctx, host); 985 major = ssh_gssapi_import_name(*ctx, host);
@@ -983,7 +990,7 @@ index d56257b4a..285fc29a5 100644
983 if (!GSS_ERROR(major)) { 990 if (!GSS_ERROR(major)) {
984 major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token, 991 major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token,
985 NULL); 992 NULL);
986@@ -296,10 +509,66 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host) 993@@ -296,10 +512,66 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
987 GSS_C_NO_BUFFER); 994 GSS_C_NO_BUFFER);
988 } 995 }
989 996
@@ -1540,10 +1547,10 @@ index 593de1208..4e5ead839 100644
1540 const BIGNUM *, const BIGNUM *, const BIGNUM *, u_char *, size_t *); 1547 const BIGNUM *, const BIGNUM *, const BIGNUM *, u_char *, size_t *);
1541diff --git a/kexgssc.c b/kexgssc.c 1548diff --git a/kexgssc.c b/kexgssc.c
1542new file mode 100644 1549new file mode 100644
1543index 000000000..953c0a248 1550index 000000000..3c8ae08dd
1544--- /dev/null 1551--- /dev/null
1545+++ b/kexgssc.c 1552+++ b/kexgssc.c
1546@@ -0,0 +1,338 @@ 1553@@ -0,0 +1,341 @@
1547+/* 1554+/*
1548+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved. 1555+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1549+ * 1556+ *
@@ -1602,6 +1609,7 @@ index 000000000..953c0a248
1602+ DH *dh; 1609+ DH *dh;
1603+ BIGNUM *dh_server_pub = NULL; 1610+ BIGNUM *dh_server_pub = NULL;
1604+ BIGNUM *shared_secret = NULL; 1611+ BIGNUM *shared_secret = NULL;
1612+ const BIGNUM *pub_key, *dh_p, *dh_g;
1605+ BIGNUM *p = NULL; 1613+ BIGNUM *p = NULL;
1606+ BIGNUM *g = NULL; 1614+ BIGNUM *g = NULL;
1607+ u_char *kbuf; 1615+ u_char *kbuf;
@@ -1666,6 +1674,8 @@ index 000000000..953c0a248
1666+ 1674+
1667+ /* Step 1 - e is dh->pub_key */ 1675+ /* Step 1 - e is dh->pub_key */
1668+ dh_gen_key(dh, ssh->kex->we_need * 8); 1676+ dh_gen_key(dh, ssh->kex->we_need * 8);
1677+ DH_get0_key(dh, &pub_key, NULL);
1678+ DH_get0_pqg(dh, &dh_p, NULL, &dh_g);
1669+ 1679+
1670+ /* This is f, we initialise it now to make life easier */ 1680+ /* This is f, we initialise it now to make life easier */
1671+ dh_server_pub = BN_new(); 1681+ dh_server_pub = BN_new();
@@ -1713,7 +1723,7 @@ index 000000000..953c0a248
1713+ packet_start(SSH2_MSG_KEXGSS_INIT); 1723+ packet_start(SSH2_MSG_KEXGSS_INIT);
1714+ packet_put_string(send_tok.value, 1724+ packet_put_string(send_tok.value,
1715+ send_tok.length); 1725+ send_tok.length);
1716+ packet_put_bignum2(dh->pub_key); 1726+ packet_put_bignum2(pub_key);
1717+ first = 0; 1727+ first = 0;
1718+ } else { 1728+ } else {
1719+ packet_start(SSH2_MSG_KEXGSS_CONTINUE); 1729+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
@@ -1822,7 +1832,7 @@ index 000000000..953c0a248
1822+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my), 1832+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
1823+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer), 1833+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
1824+ (serverhostkey ? serverhostkey : empty), slen, 1834+ (serverhostkey ? serverhostkey : empty), slen,
1825+ dh->pub_key, /* e */ 1835+ pub_key, /* e */
1826+ dh_server_pub, /* f */ 1836+ dh_server_pub, /* f */
1827+ shared_secret, /* K */ 1837+ shared_secret, /* K */
1828+ hash, &hashlen 1838+ hash, &hashlen
@@ -1837,8 +1847,8 @@ index 000000000..953c0a248
1837+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer), 1847+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
1838+ (serverhostkey ? serverhostkey : empty), slen, 1848+ (serverhostkey ? serverhostkey : empty), slen,
1839+ min, nbits, max, 1849+ min, nbits, max,
1840+ dh->p, dh->g, 1850+ dh_p, dh_g,
1841+ dh->pub_key, 1851+ pub_key,
1842+ dh_server_pub, 1852+ dh_server_pub,
1843+ shared_secret, 1853+ shared_secret,
1844+ hash, &hashlen 1854+ hash, &hashlen
@@ -1884,10 +1894,10 @@ index 000000000..953c0a248
1884+#endif /* GSSAPI */ 1894+#endif /* GSSAPI */
1885diff --git a/kexgsss.c b/kexgsss.c 1895diff --git a/kexgsss.c b/kexgsss.c
1886new file mode 100644 1896new file mode 100644
1887index 000000000..31ec6a890 1897index 000000000..18070f1d7
1888--- /dev/null 1898--- /dev/null
1889+++ b/kexgsss.c 1899+++ b/kexgsss.c
1890@@ -0,0 +1,295 @@ 1900@@ -0,0 +1,300 @@
1891+/* 1901+/*
1892+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved. 1902+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1893+ * 1903+ *
@@ -1958,6 +1968,7 @@ index 000000000..31ec6a890
1958+ u_char *kbuf; 1968+ u_char *kbuf;
1959+ DH *dh; 1969+ DH *dh;
1960+ int min = -1, max = -1, nbits = -1; 1970+ int min = -1, max = -1, nbits = -1;
1971+ const BIGNUM *pub_key, *dh_p, *dh_g;
1961+ BIGNUM *shared_secret = NULL; 1972+ BIGNUM *shared_secret = NULL;
1962+ BIGNUM *dh_client_pub = NULL; 1973+ BIGNUM *dh_client_pub = NULL;
1963+ int type = 0; 1974+ int type = 0;
@@ -2008,10 +2019,11 @@ index 000000000..31ec6a890
2008+ nbits, MIN(DH_GRP_MAX, max))); 2019+ nbits, MIN(DH_GRP_MAX, max)));
2009+ if (dh == NULL) 2020+ if (dh == NULL)
2010+ packet_disconnect("Protocol error: no matching group found"); 2021+ packet_disconnect("Protocol error: no matching group found");
2022+ DH_get0_pqg(dh, &dh_p, NULL, &dh_g);
2011+ 2023+
2012+ packet_start(SSH2_MSG_KEXGSS_GROUP); 2024+ packet_start(SSH2_MSG_KEXGSS_GROUP);
2013+ packet_put_bignum2(dh->p); 2025+ packet_put_bignum2(dh_p);
2014+ packet_put_bignum2(dh->g); 2026+ packet_put_bignum2(dh_g);
2015+ packet_send(); 2027+ packet_send();
2016+ 2028+
2017+ packet_write_wait(); 2029+ packet_write_wait();
@@ -2103,6 +2115,9 @@ index 000000000..31ec6a890
2103+ memset(kbuf, 0, klen); 2115+ memset(kbuf, 0, klen);
2104+ free(kbuf); 2116+ free(kbuf);
2105+ 2117+
2118+ DH_get0_key(dh, &pub_key, NULL);
2119+ DH_get0_pqg(dh, &dh_p, NULL, &dh_g);
2120+
2106+ hashlen = sizeof(hash); 2121+ hashlen = sizeof(hash);
2107+ switch (ssh->kex->kex_type) { 2122+ switch (ssh->kex->kex_type) {
2108+ case KEX_GSS_GRP1_SHA1: 2123+ case KEX_GSS_GRP1_SHA1:
@@ -2113,7 +2128,7 @@ index 000000000..31ec6a890
2113+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer), 2128+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
2114+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my), 2129+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
2115+ NULL, 0, /* Change this if we start sending host keys */ 2130+ NULL, 0, /* Change this if we start sending host keys */
2116+ dh_client_pub, dh->pub_key, shared_secret, 2131+ dh_client_pub, pub_key, shared_secret,
2117+ hash, &hashlen 2132+ hash, &hashlen
2118+ ); 2133+ );
2119+ break; 2134+ break;
@@ -2125,9 +2140,9 @@ index 000000000..31ec6a890
2125+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my), 2140+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
2126+ NULL, 0, 2141+ NULL, 0,
2127+ min, nbits, max, 2142+ min, nbits, max,
2128+ dh->p, dh->g, 2143+ dh_p, dh_g,
2129+ dh_client_pub, 2144+ dh_client_pub,
2130+ dh->pub_key, 2145+ pub_key,
2131+ shared_secret, 2146+ shared_secret,
2132+ hash, &hashlen 2147+ hash, &hashlen
2133+ ); 2148+ );
@@ -2151,7 +2166,7 @@ index 000000000..31ec6a890
2151+ fatal("Couldn't get MIC"); 2166+ fatal("Couldn't get MIC");
2152+ 2167+
2153+ packet_start(SSH2_MSG_KEXGSS_COMPLETE); 2168+ packet_start(SSH2_MSG_KEXGSS_COMPLETE);
2154+ packet_put_bignum2(dh->pub_key); 2169+ packet_put_bignum2(pub_key);
2155+ packet_put_string(msg_tok.value,msg_tok.length); 2170+ packet_put_string(msg_tok.value,msg_tok.length);
2156+ 2171+
2157+ if (send_tok.length != 0) { 2172+ if (send_tok.length != 0) {
@@ -2184,10 +2199,10 @@ index 000000000..31ec6a890
2184+} 2199+}
2185+#endif /* GSSAPI */ 2200+#endif /* GSSAPI */
2186diff --git a/monitor.c b/monitor.c 2201diff --git a/monitor.c b/monitor.c
2187index d4b4b0471..4e574a2ae 100644 2202index 531b2993a..eabc1e89b 100644
2188--- a/monitor.c 2203--- a/monitor.c
2189+++ b/monitor.c 2204+++ b/monitor.c
2190@@ -143,6 +143,8 @@ int mm_answer_gss_setup_ctx(int, struct sshbuf *); 2205@@ -145,6 +145,8 @@ int mm_answer_gss_setup_ctx(int, struct sshbuf *);
2191 int mm_answer_gss_accept_ctx(int, struct sshbuf *); 2206 int mm_answer_gss_accept_ctx(int, struct sshbuf *);
2192 int mm_answer_gss_userok(int, struct sshbuf *); 2207 int mm_answer_gss_userok(int, struct sshbuf *);
2193 int mm_answer_gss_checkmic(int, struct sshbuf *); 2208 int mm_answer_gss_checkmic(int, struct sshbuf *);
@@ -2196,7 +2211,7 @@ index d4b4b0471..4e574a2ae 100644
2196 #endif 2211 #endif
2197 2212
2198 #ifdef SSH_AUDIT_EVENTS 2213 #ifdef SSH_AUDIT_EVENTS
2199@@ -213,11 +215,18 @@ struct mon_table mon_dispatch_proto20[] = { 2214@@ -215,11 +217,18 @@ struct mon_table mon_dispatch_proto20[] = {
2200 {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx}, 2215 {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
2201 {MONITOR_REQ_GSSUSEROK, MON_ONCE|MON_AUTHDECIDE, mm_answer_gss_userok}, 2216 {MONITOR_REQ_GSSUSEROK, MON_ONCE|MON_AUTHDECIDE, mm_answer_gss_userok},
2202 {MONITOR_REQ_GSSCHECKMIC, MON_ONCE, mm_answer_gss_checkmic}, 2217 {MONITOR_REQ_GSSCHECKMIC, MON_ONCE, mm_answer_gss_checkmic},
@@ -2215,7 +2230,7 @@ index d4b4b0471..4e574a2ae 100644
2215 #ifdef WITH_OPENSSL 2230 #ifdef WITH_OPENSSL
2216 {MONITOR_REQ_MODULI, 0, mm_answer_moduli}, 2231 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
2217 #endif 2232 #endif
2218@@ -287,6 +296,10 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor) 2233@@ -289,6 +298,10 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
2219 /* Permit requests for moduli and signatures */ 2234 /* Permit requests for moduli and signatures */
2220 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); 2235 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
2221 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); 2236 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
@@ -2226,7 +2241,7 @@ index d4b4b0471..4e574a2ae 100644
2226 2241
2227 /* The first few requests do not require asynchronous access */ 2242 /* The first few requests do not require asynchronous access */
2228 while (!authenticated) { 2243 while (!authenticated) {
2229@@ -399,6 +412,10 @@ monitor_child_postauth(struct monitor *pmonitor) 2244@@ -401,6 +414,10 @@ monitor_child_postauth(struct monitor *pmonitor)
2230 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); 2245 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
2231 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); 2246 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
2232 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1); 2247 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
@@ -2237,7 +2252,7 @@ index d4b4b0471..4e574a2ae 100644
2237 2252
2238 if (auth_opts->permit_pty_flag) { 2253 if (auth_opts->permit_pty_flag) {
2239 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1); 2254 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
2240@@ -1662,6 +1679,13 @@ monitor_apply_keystate(struct monitor *pmonitor) 2255@@ -1666,6 +1683,13 @@ monitor_apply_keystate(struct monitor *pmonitor)
2241 # endif 2256 # endif
2242 #endif /* WITH_OPENSSL */ 2257 #endif /* WITH_OPENSSL */
2243 kex->kex[KEX_C25519_SHA256] = kexc25519_server; 2258 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
@@ -2251,7 +2266,7 @@ index d4b4b0471..4e574a2ae 100644
2251 kex->load_host_public_key=&get_hostkey_public_by_type; 2266 kex->load_host_public_key=&get_hostkey_public_by_type;
2252 kex->load_host_private_key=&get_hostkey_private_by_type; 2267 kex->load_host_private_key=&get_hostkey_private_by_type;
2253 kex->host_key_index=&get_hostkey_index; 2268 kex->host_key_index=&get_hostkey_index;
2254@@ -1752,8 +1776,8 @@ mm_answer_gss_setup_ctx(int sock, struct sshbuf *m) 2269@@ -1756,8 +1780,8 @@ mm_answer_gss_setup_ctx(int sock, struct sshbuf *m)
2255 u_char *p; 2270 u_char *p;
2256 int r; 2271 int r;
2257 2272
@@ -2262,7 +2277,7 @@ index d4b4b0471..4e574a2ae 100644
2262 2277
2263 if ((r = sshbuf_get_string(m, &p, &len)) != 0) 2278 if ((r = sshbuf_get_string(m, &p, &len)) != 0)
2264 fatal("%s: buffer error: %s", __func__, ssh_err(r)); 2279 fatal("%s: buffer error: %s", __func__, ssh_err(r));
2265@@ -1785,8 +1809,8 @@ mm_answer_gss_accept_ctx(int sock, struct sshbuf *m) 2280@@ -1789,8 +1813,8 @@ mm_answer_gss_accept_ctx(int sock, struct sshbuf *m)
2266 OM_uint32 flags = 0; /* GSI needs this */ 2281 OM_uint32 flags = 0; /* GSI needs this */
2267 int r; 2282 int r;
2268 2283
@@ -2273,7 +2288,7 @@ index d4b4b0471..4e574a2ae 100644
2273 2288
2274 if ((r = ssh_gssapi_get_buffer_desc(m, &in)) != 0) 2289 if ((r = ssh_gssapi_get_buffer_desc(m, &in)) != 0)
2275 fatal("%s: buffer error: %s", __func__, ssh_err(r)); 2290 fatal("%s: buffer error: %s", __func__, ssh_err(r));
2276@@ -1806,6 +1830,7 @@ mm_answer_gss_accept_ctx(int sock, struct sshbuf *m) 2291@@ -1810,6 +1834,7 @@ mm_answer_gss_accept_ctx(int sock, struct sshbuf *m)
2277 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0); 2292 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
2278 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1); 2293 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
2279 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1); 2294 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1);
@@ -2281,7 +2296,7 @@ index d4b4b0471..4e574a2ae 100644
2281 } 2296 }
2282 return (0); 2297 return (0);
2283 } 2298 }
2284@@ -1817,8 +1842,8 @@ mm_answer_gss_checkmic(int sock, struct sshbuf *m) 2299@@ -1821,8 +1846,8 @@ mm_answer_gss_checkmic(int sock, struct sshbuf *m)
2285 OM_uint32 ret; 2300 OM_uint32 ret;
2286 int r; 2301 int r;
2287 2302
@@ -2292,7 +2307,7 @@ index d4b4b0471..4e574a2ae 100644
2292 2307
2293 if ((r = ssh_gssapi_get_buffer_desc(m, &gssbuf)) != 0 || 2308 if ((r = ssh_gssapi_get_buffer_desc(m, &gssbuf)) != 0 ||
2294 (r = ssh_gssapi_get_buffer_desc(m, &mic)) != 0) 2309 (r = ssh_gssapi_get_buffer_desc(m, &mic)) != 0)
2295@@ -1847,10 +1872,11 @@ mm_answer_gss_userok(int sock, struct sshbuf *m) 2310@@ -1851,10 +1876,11 @@ mm_answer_gss_userok(int sock, struct sshbuf *m)
2296 int r, authenticated; 2311 int r, authenticated;
2297 const char *displayname; 2312 const char *displayname;
2298 2313
@@ -2307,7 +2322,7 @@ index d4b4b0471..4e574a2ae 100644
2307 2322
2308 sshbuf_reset(m); 2323 sshbuf_reset(m);
2309 if ((r = sshbuf_put_u32(m, authenticated)) != 0) 2324 if ((r = sshbuf_put_u32(m, authenticated)) != 0)
2310@@ -1867,5 +1893,83 @@ mm_answer_gss_userok(int sock, struct sshbuf *m) 2325@@ -1871,5 +1897,83 @@ mm_answer_gss_userok(int sock, struct sshbuf *m)
2311 /* Monitor loop will terminate if authenticated */ 2326 /* Monitor loop will terminate if authenticated */
2312 return (authenticated); 2327 return (authenticated);
2313 } 2328 }
@@ -2490,8 +2505,34 @@ index 644da081d..7f93144ff 100644
2490 #endif 2505 #endif
2491 2506
2492 #ifdef USE_PAM 2507 #ifdef USE_PAM
2508diff --git a/opacket.c b/opacket.c
2509index e637d7a71..7672c0b59 100644
2510--- a/opacket.c
2511+++ b/opacket.c
2512@@ -80,7 +80,7 @@ ssh_packet_put_raw(struct ssh *ssh, const void *buf, u_int len)
2513
2514 #ifdef WITH_OPENSSL
2515 void
2516-ssh_packet_put_bignum2(struct ssh *ssh, BIGNUM * value)
2517+ssh_packet_put_bignum2(struct ssh *ssh, const BIGNUM * value)
2518 {
2519 int r;
2520
2521diff --git a/opacket.h b/opacket.h
2522index f92fe586e..1cf66a2d3 100644
2523--- a/opacket.h
2524+++ b/opacket.h
2525@@ -7,7 +7,7 @@ void ssh_packet_start(struct ssh *, u_char);
2526 void ssh_packet_put_char(struct ssh *, int ch);
2527 void ssh_packet_put_int(struct ssh *, u_int value);
2528 void ssh_packet_put_int64(struct ssh *, u_int64_t value);
2529-void ssh_packet_put_bignum2(struct ssh *, BIGNUM * value);
2530+void ssh_packet_put_bignum2(struct ssh *, const BIGNUM * value);
2531 void ssh_packet_put_ecpoint(struct ssh *, const EC_GROUP *, const EC_POINT *);
2532 void ssh_packet_put_string(struct ssh *, const void *buf, u_int len);
2533 void ssh_packet_put_cstring(struct ssh *, const char *str);
2493diff --git a/readconf.c b/readconf.c 2534diff --git a/readconf.c b/readconf.c
2494index db5f2d547..4ad3c75fe 100644 2535index 433811521..36bc5e59a 100644
2495--- a/readconf.c 2536--- a/readconf.c
2496+++ b/readconf.c 2537+++ b/readconf.c
2497@@ -161,6 +161,8 @@ typedef enum { 2538@@ -161,6 +161,8 @@ typedef enum {
@@ -2524,7 +2565,7 @@ index db5f2d547..4ad3c75fe 100644
2524 #endif 2565 #endif
2525 #ifdef ENABLE_PKCS11 2566 #ifdef ENABLE_PKCS11
2526 { "smartcarddevice", oPKCS11Provider }, 2567 { "smartcarddevice", oPKCS11Provider },
2527@@ -973,10 +985,30 @@ parse_time: 2568@@ -974,10 +986,30 @@ parse_time:
2528 intptr = &options->gss_authentication; 2569 intptr = &options->gss_authentication;
2529 goto parse_flag; 2570 goto parse_flag;
2530 2571
@@ -2555,7 +2596,7 @@ index db5f2d547..4ad3c75fe 100644
2555 case oBatchMode: 2596 case oBatchMode:
2556 intptr = &options->batch_mode; 2597 intptr = &options->batch_mode;
2557 goto parse_flag; 2598 goto parse_flag;
2558@@ -1817,7 +1849,12 @@ initialize_options(Options * options) 2599@@ -1842,7 +1874,12 @@ initialize_options(Options * options)
2559 options->pubkey_authentication = -1; 2600 options->pubkey_authentication = -1;
2560 options->challenge_response_authentication = -1; 2601 options->challenge_response_authentication = -1;
2561 options->gss_authentication = -1; 2602 options->gss_authentication = -1;
@@ -2568,7 +2609,7 @@ index db5f2d547..4ad3c75fe 100644
2568 options->password_authentication = -1; 2609 options->password_authentication = -1;
2569 options->kbd_interactive_authentication = -1; 2610 options->kbd_interactive_authentication = -1;
2570 options->kbd_interactive_devices = NULL; 2611 options->kbd_interactive_devices = NULL;
2571@@ -1962,8 +1999,14 @@ fill_default_options(Options * options) 2612@@ -1988,8 +2025,14 @@ fill_default_options(Options * options)
2572 options->challenge_response_authentication = 1; 2613 options->challenge_response_authentication = 1;
2573 if (options->gss_authentication == -1) 2614 if (options->gss_authentication == -1)
2574 options->gss_authentication = 0; 2615 options->gss_authentication = 0;
@@ -2584,7 +2625,7 @@ index db5f2d547..4ad3c75fe 100644
2584 options->password_authentication = 1; 2625 options->password_authentication = 1;
2585 if (options->kbd_interactive_authentication == -1) 2626 if (options->kbd_interactive_authentication == -1)
2586diff --git a/readconf.h b/readconf.h 2627diff --git a/readconf.h b/readconf.h
2587index c56887816..5ea0c296b 100644 2628index fc7e38251..8e4900d01 100644
2588--- a/readconf.h 2629--- a/readconf.h
2589+++ b/readconf.h 2630+++ b/readconf.h
2590@@ -40,7 +40,12 @@ typedef struct { 2631@@ -40,7 +40,12 @@ typedef struct {
@@ -2601,7 +2642,7 @@ index c56887816..5ea0c296b 100644
2601 * authentication. */ 2642 * authentication. */
2602 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */ 2643 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
2603diff --git a/servconf.c b/servconf.c 2644diff --git a/servconf.c b/servconf.c
2604index c0f6af0be..e1ae07fb7 100644 2645index 932d363bb..4668b8a45 100644
2605--- a/servconf.c 2646--- a/servconf.c
2606+++ b/servconf.c 2647+++ b/servconf.c
2607@@ -124,8 +124,10 @@ initialize_server_options(ServerOptions *options) 2648@@ -124,8 +124,10 @@ initialize_server_options(ServerOptions *options)
@@ -2615,7 +2656,7 @@ index c0f6af0be..e1ae07fb7 100644
2615 options->password_authentication = -1; 2656 options->password_authentication = -1;
2616 options->kbd_interactive_authentication = -1; 2657 options->kbd_interactive_authentication = -1;
2617 options->challenge_response_authentication = -1; 2658 options->challenge_response_authentication = -1;
2618@@ -333,10 +335,14 @@ fill_default_server_options(ServerOptions *options) 2659@@ -337,10 +339,14 @@ fill_default_server_options(ServerOptions *options)
2619 options->kerberos_get_afs_token = 0; 2660 options->kerberos_get_afs_token = 0;
2620 if (options->gss_authentication == -1) 2661 if (options->gss_authentication == -1)
2621 options->gss_authentication = 0; 2662 options->gss_authentication = 0;
@@ -2630,7 +2671,7 @@ index c0f6af0be..e1ae07fb7 100644
2630 if (options->password_authentication == -1) 2671 if (options->password_authentication == -1)
2631 options->password_authentication = 1; 2672 options->password_authentication = 1;
2632 if (options->kbd_interactive_authentication == -1) 2673 if (options->kbd_interactive_authentication == -1)
2633@@ -481,6 +487,7 @@ typedef enum { 2674@@ -485,6 +491,7 @@ typedef enum {
2634 sHostKeyAlgorithms, 2675 sHostKeyAlgorithms,
2635 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile, 2676 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
2636 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor, 2677 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
@@ -2638,7 +2679,7 @@ index c0f6af0be..e1ae07fb7 100644
2638 sAcceptEnv, sSetEnv, sPermitTunnel, 2679 sAcceptEnv, sSetEnv, sPermitTunnel,
2639 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory, 2680 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
2640 sUsePrivilegeSeparation, sAllowAgentForwarding, 2681 sUsePrivilegeSeparation, sAllowAgentForwarding,
2641@@ -555,12 +562,20 @@ static struct { 2682@@ -559,12 +566,20 @@ static struct {
2642 #ifdef GSSAPI 2683 #ifdef GSSAPI
2643 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL }, 2684 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
2644 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL }, 2685 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
@@ -2659,7 +2700,7 @@ index c0f6af0be..e1ae07fb7 100644
2659 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL }, 2700 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
2660 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL }, 2701 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
2661 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, 2702 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
2662@@ -1459,6 +1474,10 @@ process_server_config_line(ServerOptions *options, char *line, 2703@@ -1468,6 +1483,10 @@ process_server_config_line(ServerOptions *options, char *line,
2663 intptr = &options->gss_authentication; 2704 intptr = &options->gss_authentication;
2664 goto parse_flag; 2705 goto parse_flag;
2665 2706
@@ -2670,7 +2711,7 @@ index c0f6af0be..e1ae07fb7 100644
2670 case sGssCleanupCreds: 2711 case sGssCleanupCreds:
2671 intptr = &options->gss_cleanup_creds; 2712 intptr = &options->gss_cleanup_creds;
2672 goto parse_flag; 2713 goto parse_flag;
2673@@ -1467,6 +1486,10 @@ process_server_config_line(ServerOptions *options, char *line, 2714@@ -1476,6 +1495,10 @@ process_server_config_line(ServerOptions *options, char *line,
2674 intptr = &options->gss_strict_acceptor; 2715 intptr = &options->gss_strict_acceptor;
2675 goto parse_flag; 2716 goto parse_flag;
2676 2717
@@ -2681,7 +2722,7 @@ index c0f6af0be..e1ae07fb7 100644
2681 case sPasswordAuthentication: 2722 case sPasswordAuthentication:
2682 intptr = &options->password_authentication; 2723 intptr = &options->password_authentication;
2683 goto parse_flag; 2724 goto parse_flag;
2684@@ -2551,7 +2574,10 @@ dump_config(ServerOptions *o) 2725@@ -2560,7 +2583,10 @@ dump_config(ServerOptions *o)
2685 #endif 2726 #endif
2686 #ifdef GSSAPI 2727 #ifdef GSSAPI
2687 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication); 2728 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
@@ -2693,10 +2734,10 @@ index c0f6af0be..e1ae07fb7 100644
2693 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication); 2734 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2694 dump_cfg_fmtint(sKbdInteractiveAuthentication, 2735 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2695diff --git a/servconf.h b/servconf.h 2736diff --git a/servconf.h b/servconf.h
2696index 557521d73..9b117fe27 100644 2737index 0175e00e8..3b76da816 100644
2697--- a/servconf.h 2738--- a/servconf.h
2698+++ b/servconf.h 2739+++ b/servconf.h
2699@@ -124,8 +124,10 @@ typedef struct { 2740@@ -125,8 +125,10 @@ typedef struct {
2700 int kerberos_get_afs_token; /* If true, try to get AFS token if 2741 int kerberos_get_afs_token; /* If true, try to get AFS token if
2701 * authenticated with Kerberos. */ 2742 * authenticated with Kerberos. */
2702 int gss_authentication; /* If true, permit GSSAPI authentication */ 2743 int gss_authentication; /* If true, permit GSSAPI authentication */
@@ -2825,10 +2866,10 @@ index c12f5ef52..bcb9f153d 100644
2825 # CheckHostIP yes 2866 # CheckHostIP yes
2826 # AddressFamily any 2867 # AddressFamily any
2827diff --git a/ssh_config.5 b/ssh_config.5 2868diff --git a/ssh_config.5 b/ssh_config.5
2828index f499396a3..5b99921b4 100644 2869index 4d5b01d3e..16c79368a 100644
2829--- a/ssh_config.5 2870--- a/ssh_config.5
2830+++ b/ssh_config.5 2871+++ b/ssh_config.5
2831@@ -718,10 +718,42 @@ The default is 2872@@ -736,10 +736,42 @@ The default is
2832 Specifies whether user authentication based on GSSAPI is allowed. 2873 Specifies whether user authentication based on GSSAPI is allowed.
2833 The default is 2874 The default is
2834 .Cm no . 2875 .Cm no .
@@ -2872,7 +2913,7 @@ index f499396a3..5b99921b4 100644
2872 Indicates that 2913 Indicates that
2873 .Xr ssh 1 2914 .Xr ssh 1
2874diff --git a/sshconnect2.c b/sshconnect2.c 2915diff --git a/sshconnect2.c b/sshconnect2.c
2875index 10e4f0a08..c6a1b1271 100644 2916index 1675f3935..8c872a4fb 100644
2876--- a/sshconnect2.c 2917--- a/sshconnect2.c
2877+++ b/sshconnect2.c 2918+++ b/sshconnect2.c
2878@@ -162,6 +162,11 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port) 2919@@ -162,6 +162,11 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
@@ -2985,7 +3026,7 @@ index 10e4f0a08..c6a1b1271 100644
2985 {"gssapi-with-mic", 3026 {"gssapi-with-mic",
2986 userauth_gssapi, 3027 userauth_gssapi,
2987 NULL, 3028 NULL,
2988@@ -657,25 +723,40 @@ userauth_gssapi(Authctxt *authctxt) 3029@@ -686,25 +752,40 @@ userauth_gssapi(Authctxt *authctxt)
2989 static u_int mech = 0; 3030 static u_int mech = 0;
2990 OM_uint32 min; 3031 OM_uint32 min;
2991 int r, ok = 0; 3032 int r, ok = 0;
@@ -3028,7 +3069,7 @@ index 10e4f0a08..c6a1b1271 100644
3028 if (!ok) 3069 if (!ok)
3029 return 0; 3070 return 0;
3030 3071
3031@@ -906,6 +987,54 @@ input_gssapi_error(int type, u_int32_t plen, struct ssh *ssh) 3072@@ -935,6 +1016,54 @@ input_gssapi_error(int type, u_int32_t plen, struct ssh *ssh)
3032 free(lang); 3073 free(lang);
3033 return r; 3074 return r;
3034 } 3075 }
@@ -3084,7 +3125,7 @@ index 10e4f0a08..c6a1b1271 100644
3084 3125
3085 int 3126 int
3086diff --git a/sshd.c b/sshd.c 3127diff --git a/sshd.c b/sshd.c
3087index a738c3ab6..2e453cdf8 100644 3128index ba26287ba..539a000fd 100644
3088--- a/sshd.c 3129--- a/sshd.c
3089+++ b/sshd.c 3130+++ b/sshd.c
3090@@ -123,6 +123,10 @@ 3131@@ -123,6 +123,10 @@
@@ -3098,16 +3139,7 @@ index a738c3ab6..2e453cdf8 100644
3098 /* Re-exec fds */ 3139 /* Re-exec fds */
3099 #define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1) 3140 #define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1)
3100 #define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2) 3141 #define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2)
3101@@ -536,7 +540,7 @@ privsep_preauth_child(void) 3142@@ -1810,10 +1814,13 @@ main(int ac, char **av)
3102
3103 #ifdef GSSAPI
3104 /* Cache supported mechanism OIDs for later use */
3105- if (options.gss_authentication)
3106+ if (options.gss_authentication || options.gss_keyex)
3107 ssh_gssapi_prepare_supported_oids();
3108 #endif
3109
3110@@ -1811,10 +1815,13 @@ main(int ac, char **av)
3111 free(fp); 3143 free(fp);
3112 } 3144 }
3113 accumulate_host_timing_secret(cfg, NULL); 3145 accumulate_host_timing_secret(cfg, NULL);
@@ -3121,7 +3153,7 @@ index a738c3ab6..2e453cdf8 100644
3121 3153
3122 /* 3154 /*
3123 * Load certificates. They are stored in an array at identical 3155 * Load certificates. They are stored in an array at identical
3124@@ -2105,6 +2112,60 @@ main(int ac, char **av) 3156@@ -2104,6 +2111,60 @@ main(int ac, char **av)
3125 rdomain == NULL ? "" : "\""); 3157 rdomain == NULL ? "" : "\"");
3126 free(laddr); 3158 free(laddr);
3127 3159
@@ -3182,7 +3214,7 @@ index a738c3ab6..2e453cdf8 100644
3182 /* 3214 /*
3183 * We don't want to listen forever unless the other side 3215 * We don't want to listen forever unless the other side
3184 * successfully authenticates itself. So we set up an alarm which is 3216 * successfully authenticates itself. So we set up an alarm which is
3185@@ -2288,6 +2349,48 @@ do_ssh2_kex(void) 3217@@ -2287,6 +2348,48 @@ do_ssh2_kex(void)
3186 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal( 3218 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal(
3187 list_hostkey_types()); 3219 list_hostkey_types());
3188 3220
@@ -3231,7 +3263,7 @@ index a738c3ab6..2e453cdf8 100644
3231 /* start key exchange */ 3263 /* start key exchange */
3232 if ((r = kex_setup(active_state, myproposal)) != 0) 3264 if ((r = kex_setup(active_state, myproposal)) != 0)
3233 fatal("kex_setup: %s", ssh_err(r)); 3265 fatal("kex_setup: %s", ssh_err(r));
3234@@ -2305,6 +2408,13 @@ do_ssh2_kex(void) 3266@@ -2304,6 +2407,13 @@ do_ssh2_kex(void)
3235 # endif 3267 # endif
3236 #endif 3268 #endif
3237 kex->kex[KEX_C25519_SHA256] = kexc25519_server; 3269 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
@@ -3259,10 +3291,10 @@ index 19b7c91a1..2c48105f8 100644
3259 # Set this to 'yes' to enable PAM authentication, account processing, 3291 # Set this to 'yes' to enable PAM authentication, account processing,
3260 # and session processing. If this is enabled, PAM authentication will 3292 # and session processing. If this is enabled, PAM authentication will
3261diff --git a/sshd_config.5 b/sshd_config.5 3293diff --git a/sshd_config.5 b/sshd_config.5
3262index e1b54ba20..a0ac717c7 100644 3294index c6484370b..985eef5a2 100644
3263--- a/sshd_config.5 3295--- a/sshd_config.5
3264+++ b/sshd_config.5 3296+++ b/sshd_config.5
3265@@ -637,6 +637,11 @@ The default is 3297@@ -648,6 +648,11 @@ The default is
3266 Specifies whether user authentication based on GSSAPI is allowed. 3298 Specifies whether user authentication based on GSSAPI is allowed.
3267 The default is 3299 The default is
3268 .Cm no . 3300 .Cm no .
@@ -3274,7 +3306,7 @@ index e1b54ba20..a0ac717c7 100644
3274 .It Cm GSSAPICleanupCredentials 3306 .It Cm GSSAPICleanupCredentials
3275 Specifies whether to automatically destroy the user's credentials cache 3307 Specifies whether to automatically destroy the user's credentials cache
3276 on logout. 3308 on logout.
3277@@ -656,6 +661,11 @@ machine's default store. 3309@@ -667,6 +672,11 @@ machine's default store.
3278 This facility is provided to assist with operation on multi homed machines. 3310 This facility is provided to assist with operation on multi homed machines.
3279 The default is 3311 The default is
3280 .Cm yes . 3312 .Cm yes .
@@ -3287,10 +3319,10 @@ index e1b54ba20..a0ac717c7 100644
3287 Specifies the key types that will be accepted for hostbased authentication 3319 Specifies the key types that will be accepted for hostbased authentication
3288 as a list of comma-separated patterns. 3320 as a list of comma-separated patterns.
3289diff --git a/sshkey.c b/sshkey.c 3321diff --git a/sshkey.c b/sshkey.c
3290index 72c08c7e0..91e99a262 100644 3322index 6555c5ef8..a85c185fc 100644
3291--- a/sshkey.c 3323--- a/sshkey.c
3292+++ b/sshkey.c 3324+++ b/sshkey.c
3293@@ -140,6 +140,7 @@ static const struct keytype keytypes[] = { 3325@@ -135,6 +135,7 @@ static const struct keytype keytypes[] = {
3294 # endif /* OPENSSL_HAS_NISTP521 */ 3326 # endif /* OPENSSL_HAS_NISTP521 */
3295 # endif /* OPENSSL_HAS_ECC */ 3327 # endif /* OPENSSL_HAS_ECC */
3296 #endif /* WITH_OPENSSL */ 3328 #endif /* WITH_OPENSSL */
@@ -3298,7 +3330,7 @@ index 72c08c7e0..91e99a262 100644
3298 { NULL, NULL, NULL, -1, -1, 0, 0 } 3330 { NULL, NULL, NULL, -1, -1, 0, 0 }
3299 }; 3331 };
3300 3332
3301@@ -228,7 +229,7 @@ sshkey_alg_list(int certs_only, int plain_only, int include_sigonly, char sep) 3333@@ -223,7 +224,7 @@ sshkey_alg_list(int certs_only, int plain_only, int include_sigonly, char sep)
3302 const struct keytype *kt; 3334 const struct keytype *kt;
3303 3335
3304 for (kt = keytypes; kt->type != -1; kt++) { 3336 for (kt = keytypes; kt->type != -1; kt++) {
@@ -3308,10 +3340,10 @@ index 72c08c7e0..91e99a262 100644
3308 if (!include_sigonly && kt->sigonly) 3340 if (!include_sigonly && kt->sigonly)
3309 continue; 3341 continue;
3310diff --git a/sshkey.h b/sshkey.h 3342diff --git a/sshkey.h b/sshkey.h
3311index 9060b2ecb..0cbdcfd74 100644 3343index f6a007fdf..f54deb0c0 100644
3312--- a/sshkey.h 3344--- a/sshkey.h
3313+++ b/sshkey.h 3345+++ b/sshkey.h
3314@@ -63,6 +63,7 @@ enum sshkey_types { 3346@@ -64,6 +64,7 @@ enum sshkey_types {
3315 KEY_ED25519_CERT, 3347 KEY_ED25519_CERT,
3316 KEY_XMSS, 3348 KEY_XMSS,
3317 KEY_XMSS_CERT, 3349 KEY_XMSS_CERT,