summaryrefslogtreecommitdiff
path: root/debian/patches
diff options
context:
space:
mode:
Diffstat (limited to 'debian/patches')
-rw-r--r--debian/patches/authorized-keys-man-symlink.patch26
-rw-r--r--debian/patches/check-filenames-in-scp-client.patch187
-rw-r--r--debian/patches/conch-old-privkey-format.patch71
-rw-r--r--debian/patches/debian-banner.patch111
-rw-r--r--debian/patches/debian-config.patch238
-rw-r--r--debian/patches/dnssec-sshfp.patch94
-rw-r--r--debian/patches/doc-hash-tab-completion.patch28
-rw-r--r--debian/patches/fix-key-type-check.patch88
-rw-r--r--debian/patches/gnome-ssh-askpass2-icon.patch26
-rw-r--r--debian/patches/gssapi.patch3353
-rw-r--r--debian/patches/have-progressmeter-force-update-at-beginning-and-end-transfer.patch120
-rw-r--r--debian/patches/keepalive-extensions.patch134
-rw-r--r--debian/patches/mention-ssh-keygen-on-keychange.patch44
-rw-r--r--debian/patches/no-openssl-version-status.patch62
-rw-r--r--debian/patches/openbsd-docs.patch148
-rw-r--r--debian/patches/package-versioning.patch61
-rw-r--r--debian/patches/request-rsa-sha2-cert-signatures.patch39
-rw-r--r--debian/patches/restore-authorized_keys2.patch35
-rw-r--r--debian/patches/restore-tcp-wrappers.patch172
-rw-r--r--debian/patches/revert-ipqos-defaults.patch93
-rw-r--r--debian/patches/sanitize-scp-filenames-via-snmprintf.patch276
-rw-r--r--debian/patches/scp-disallow-dot-or-empty-filename.patch32
-rw-r--r--debian/patches/scp-handle-braces.patch353
-rw-r--r--debian/patches/scp-quoting.patch41
-rw-r--r--debian/patches/seccomp-s390-flock-ipc.patch47
-rw-r--r--debian/patches/seccomp-s390-ioctl-ep11-crypto.patch33
-rw-r--r--debian/patches/selinux-role.patch472
-rw-r--r--debian/patches/series34
-rw-r--r--debian/patches/shell-path.patch39
-rw-r--r--debian/patches/ssh-agent-setgid.patch40
-rw-r--r--debian/patches/ssh-argv0.patch31
-rw-r--r--debian/patches/ssh-vulnkey-compat.patch42
-rw-r--r--debian/patches/syslog-level-silent.patch47
-rw-r--r--debian/patches/systemd-readiness.patch84
-rw-r--r--debian/patches/user-group-modes.patch210
35 files changed, 6911 insertions, 0 deletions
diff --git a/debian/patches/authorized-keys-man-symlink.patch b/debian/patches/authorized-keys-man-symlink.patch
new file mode 100644
index 000000000..c895e63db
--- /dev/null
+++ b/debian/patches/authorized-keys-man-symlink.patch
@@ -0,0 +1,26 @@
1From 67a6cbb29f77920718884e783238f4a00fe64001 Mon Sep 17 00:00:00 2001
2From: Tomas Pospisek <tpo_deb@sourcepole.ch>
3Date: Sun, 9 Feb 2014 16:10:07 +0000
4Subject: Install authorized_keys(5) as a symlink to sshd(8)
5
6Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1720
7Bug-Debian: http://bugs.debian.org/441817
8Last-Update: 2013-09-14
9
10Patch-Name: authorized-keys-man-symlink.patch
11---
12 Makefile.in | 1 +
13 1 file changed, 1 insertion(+)
14
15diff --git a/Makefile.in b/Makefile.in
16index 70050ffb6..ee166114d 100644
17--- a/Makefile.in
18+++ b/Makefile.in
19@@ -356,6 +356,7 @@ install-files:
20 $(INSTALL) -m 644 sshd_config.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/sshd_config.5
21 $(INSTALL) -m 644 ssh_config.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/ssh_config.5
22 $(INSTALL) -m 644 sshd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8
23+ ln -s ../$(mansubdir)8/sshd.8 $(DESTDIR)$(mandir)/$(mansubdir)5/authorized_keys.5
24 $(INSTALL) -m 644 sftp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1
25 $(INSTALL) -m 644 sftp-server.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8
26 $(INSTALL) -m 644 ssh-keysign.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8
diff --git a/debian/patches/check-filenames-in-scp-client.patch b/debian/patches/check-filenames-in-scp-client.patch
new file mode 100644
index 000000000..519358ce6
--- /dev/null
+++ b/debian/patches/check-filenames-in-scp-client.patch
@@ -0,0 +1,187 @@
1From 125924e47db3713a85a70e0f8d6c23818d2ea054 Mon Sep 17 00:00:00 2001
2From: "djm@openbsd.org" <djm@openbsd.org>
3Date: Sat, 26 Jan 2019 22:41:28 +0000
4Subject: upstream: check in scp client that filenames sent during
5
6remote->local directory copies satisfy the wildcard specified by the user.
7
8This checking provides some protection against a malicious server
9sending unexpected filenames, but it comes at a risk of rejecting wanted
10files due to differences between client and server wildcard expansion rules.
11
12For this reason, this also adds a new -T flag to disable the check.
13
14reported by Harry Sintonen
15fix approach suggested by markus@;
16has been in snaps for ~1wk courtesy deraadt@
17
18OpenBSD-Commit-ID: 00f44b50d2be8e321973f3c6d014260f8f7a8eda
19
20CVE-2019-6111
21
22Origin: backport, https://anongit.mindrot.org/openssh.git/commit/?id=391ffc4b9d31fa1f4ad566499fef9176ff8a07dc
23Last-Update: 2019-02-08
24
25Patch-Name: check-filenames-in-scp-client.patch
26---
27 scp.1 | 12 +++++++++++-
28 scp.c | 37 +++++++++++++++++++++++++++++--------
29 2 files changed, 40 insertions(+), 9 deletions(-)
30
31diff --git a/scp.1 b/scp.1
32index 0e5cc1b2d..397e77091 100644
33--- a/scp.1
34+++ b/scp.1
35@@ -18,7 +18,7 @@
36 .Nd secure copy (remote file copy program)
37 .Sh SYNOPSIS
38 .Nm scp
39-.Op Fl 346BCpqrv
40+.Op Fl 346BCpqrTv
41 .Op Fl c Ar cipher
42 .Op Fl F Ar ssh_config
43 .Op Fl i Ar identity_file
44@@ -208,6 +208,16 @@ to use for the encrypted connection.
45 The program must understand
46 .Xr ssh 1
47 options.
48+.It Fl T
49+Disable strict filename checking.
50+By default when copying files from a remote host to a local directory
51+.Nm
52+checks that the received filenames match those requested on the command-line
53+to prevent the remote end from sending unexpected or unwanted files.
54+Because of differences in how various operating systems and shells interpret
55+filename wildcards, these checks may cause wanted files to be rejected.
56+This option disables these checks at the expense of fully trusting that
57+the server will not send unexpected filenames.
58 .It Fl v
59 Verbose mode.
60 Causes
61diff --git a/scp.c b/scp.c
62index 1971c80cd..035037bcc 100644
63--- a/scp.c
64+++ b/scp.c
65@@ -94,6 +94,7 @@
66 #include <dirent.h>
67 #include <errno.h>
68 #include <fcntl.h>
69+#include <fnmatch.h>
70 #include <limits.h>
71 #include <locale.h>
72 #include <pwd.h>
73@@ -383,14 +384,14 @@ void verifydir(char *);
74 struct passwd *pwd;
75 uid_t userid;
76 int errs, remin, remout;
77-int pflag, iamremote, iamrecursive, targetshouldbedirectory;
78+int Tflag, pflag, iamremote, iamrecursive, targetshouldbedirectory;
79
80 #define CMDNEEDS 64
81 char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
82
83 int response(void);
84 void rsource(char *, struct stat *);
85-void sink(int, char *[]);
86+void sink(int, char *[], const char *);
87 void source(int, char *[]);
88 void tolocal(int, char *[]);
89 void toremote(int, char *[]);
90@@ -429,8 +430,9 @@ main(int argc, char **argv)
91 addargs(&args, "-oRemoteCommand=none");
92 addargs(&args, "-oRequestTTY=no");
93
94- fflag = tflag = 0;
95- while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q12346S:o:F:")) != -1)
96+ fflag = Tflag = tflag = 0;
97+ while ((ch = getopt(argc, argv,
98+ "dfl:prtTvBCc:i:P:q12346S:o:F:")) != -1) {
99 switch (ch) {
100 /* User-visible flags. */
101 case '1':
102@@ -509,9 +511,13 @@ main(int argc, char **argv)
103 setmode(0, O_BINARY);
104 #endif
105 break;
106+ case 'T':
107+ Tflag = 1;
108+ break;
109 default:
110 usage();
111 }
112+ }
113 argc -= optind;
114 argv += optind;
115
116@@ -542,7 +548,7 @@ main(int argc, char **argv)
117 }
118 if (tflag) {
119 /* Receive data. */
120- sink(argc, argv);
121+ sink(argc, argv, NULL);
122 exit(errs != 0);
123 }
124 if (argc < 2)
125@@ -800,7 +806,7 @@ tolocal(int argc, char **argv)
126 continue;
127 }
128 free(bp);
129- sink(1, argv + argc - 1);
130+ sink(1, argv + argc - 1, src);
131 (void) close(remin);
132 remin = remout = -1;
133 }
134@@ -976,7 +982,7 @@ rsource(char *name, struct stat *statp)
135 (sizeof(type) != 4 && sizeof(type) != 8))
136
137 void
138-sink(int argc, char **argv)
139+sink(int argc, char **argv, const char *src)
140 {
141 static BUF buffer;
142 struct stat stb;
143@@ -992,6 +998,7 @@ sink(int argc, char **argv)
144 unsigned long long ull;
145 int setimes, targisdir, wrerrno = 0;
146 char ch, *cp, *np, *targ, *why, *vect[1], buf[2048], visbuf[2048];
147+ char *src_copy = NULL, *restrict_pattern = NULL;
148 struct timeval tv[2];
149
150 #define atime tv[0]
151@@ -1016,6 +1023,17 @@ sink(int argc, char **argv)
152 (void) atomicio(vwrite, remout, "", 1);
153 if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
154 targisdir = 1;
155+ if (src != NULL && !iamrecursive && !Tflag) {
156+ /*
157+ * Prepare to try to restrict incoming filenames to match
158+ * the requested destination file glob.
159+ */
160+ if ((src_copy = strdup(src)) == NULL)
161+ fatal("strdup failed");
162+ if ((restrict_pattern = strrchr(src_copy, '/')) != NULL) {
163+ *restrict_pattern++ = '\0';
164+ }
165+ }
166 for (first = 1;; first = 0) {
167 cp = buf;
168 if (atomicio(read, remin, cp, 1) != 1)
169@@ -1120,6 +1138,9 @@ sink(int argc, char **argv)
170 run_err("error: unexpected filename: %s", cp);
171 exit(1);
172 }
173+ if (restrict_pattern != NULL &&
174+ fnmatch(restrict_pattern, cp, 0) != 0)
175+ SCREWUP("filename does not match request");
176 if (targisdir) {
177 static char *namebuf;
178 static size_t cursize;
179@@ -1157,7 +1178,7 @@ sink(int argc, char **argv)
180 goto bad;
181 }
182 vect[0] = xstrdup(np);
183- sink(1, vect);
184+ sink(1, vect, src);
185 if (setimes) {
186 setimes = 0;
187 if (utimes(vect[0], tv) < 0)
diff --git a/debian/patches/conch-old-privkey-format.patch b/debian/patches/conch-old-privkey-format.patch
new file mode 100644
index 000000000..90bb3e995
--- /dev/null
+++ b/debian/patches/conch-old-privkey-format.patch
@@ -0,0 +1,71 @@
1From 1d2a55436d4b556269f42ad5f7e16608b5a8ed74 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Thu, 30 Aug 2018 00:58:56 +0100
4Subject: Work around conch interoperability failure
5
6Twisted Conch fails to read private keys in the new format
7(https://twistedmatrix.com/trac/ticket/9515). Work around this until it
8can be fixed in Twisted.
9
10Forwarded: not-needed
11Last-Update: 2018-08-30
12
13Patch-Name: conch-old-privkey-format.patch
14---
15 regress/Makefile | 5 +++--
16 regress/conch-ciphers.sh | 2 +-
17 regress/test-exec.sh | 12 ++++++++++++
18 3 files changed, 16 insertions(+), 3 deletions(-)
19
20diff --git a/regress/Makefile b/regress/Makefile
21index 647b4a049..6e462a4f6 100644
22--- a/regress/Makefile
23+++ b/regress/Makefile
24@@ -110,8 +110,9 @@ CLEANFILES= *.core actual agent-key.* authorized_keys_${USERNAME} \
25 modpipe netcat no_identity_config \
26 pidfile putty.rsa2 ready regress.log \
27 remote_pid revoked-* rsa rsa-agent rsa-agent.pub rsa.pub \
28- rsa1 rsa1-agent rsa1-agent.pub rsa1.pub rsa_ssh2_cr.prv \
29- rsa_ssh2_crnl.prv scp-ssh-wrapper.exe \
30+ rsa1 rsa1-agent rsa1-agent.pub rsa1.pub \
31+ rsa_oldfmt rsa_oldfmt.pub \
32+ rsa_ssh2_cr.prv rsa_ssh2_crnl.prv scp-ssh-wrapper.exe \
33 scp-ssh-wrapper.scp setuid-allowed sftp-server.log \
34 sftp-server.sh sftp.log ssh-log-wrapper.sh ssh.log \
35 ssh_config ssh_config.* ssh_proxy ssh_proxy_bak \
36diff --git a/regress/conch-ciphers.sh b/regress/conch-ciphers.sh
37index 199d863a0..c7df19fd4 100644
38--- a/regress/conch-ciphers.sh
39+++ b/regress/conch-ciphers.sh
40@@ -16,7 +16,7 @@ for c in aes256-ctr aes256-cbc aes192-ctr aes192-cbc aes128-ctr aes128-cbc \
41 rm -f ${COPY}
42 # XXX the 2nd "cat" seems to be needed because of buggy FD handling
43 # in conch
44- ${CONCH} --identity $OBJ/rsa --port $PORT --user $USER -e none \
45+ ${CONCH} --identity $OBJ/rsa_oldfmt --port $PORT --user $USER -e none \
46 --known-hosts $OBJ/known_hosts --notty --noagent --nox11 -n \
47 127.0.0.1 "cat ${DATA}" 2>/dev/null | cat > ${COPY}
48 if [ $? -ne 0 ]; then
49diff --git a/regress/test-exec.sh b/regress/test-exec.sh
50index 40d46e3cd..1bbd47f25 100644
51--- a/regress/test-exec.sh
52+++ b/regress/test-exec.sh
53@@ -504,6 +504,18 @@ REGRESS_INTEROP_CONCH=no
54 if test -x "$CONCH" ; then
55 REGRESS_INTEROP_CONCH=yes
56 fi
57+case "$SCRIPT" in
58+*conch*) ;;
59+*) REGRESS_INTEROP_CONCH=no
60+esac
61+
62+if test "$REGRESS_INTEROP_CONCH" = "yes" ; then
63+ # Convert rsa key to old format to work around
64+ # https://twistedmatrix.com/trac/ticket/9515
65+ cp $OBJ/rsa $OBJ/rsa_oldfmt
66+ cp $OBJ/rsa.pub $OBJ/rsa_oldfmt.pub
67+ ${SSHKEYGEN} -p -N '' -m PEM -f $OBJ/rsa_oldfmt >/dev/null
68+fi
69
70 # If PuTTY is present and we are running a PuTTY test, prepare keys and
71 # configuration
diff --git a/debian/patches/debian-banner.patch b/debian/patches/debian-banner.patch
new file mode 100644
index 000000000..7963b03ed
--- /dev/null
+++ b/debian/patches/debian-banner.patch
@@ -0,0 +1,111 @@
1From a18385c6866da4d69f46b64626ae5d60b4cf4a66 Mon Sep 17 00:00:00 2001
2From: Kees Cook <kees@debian.org>
3Date: Sun, 9 Feb 2014 16:10:06 +0000
4Subject: Add DebianBanner server configuration option
5
6Setting this to "no" causes sshd to omit the Debian revision from its
7initial protocol handshake, for those scared by package-versioning.patch.
8
9Bug-Debian: http://bugs.debian.org/562048
10Forwarded: not-needed
11Last-Update: 2018-10-19
12
13Patch-Name: debian-banner.patch
14---
15 servconf.c | 9 +++++++++
16 servconf.h | 2 ++
17 sshd.c | 3 ++-
18 sshd_config.5 | 5 +++++
19 4 files changed, 18 insertions(+), 1 deletion(-)
20
21diff --git a/servconf.c b/servconf.c
22index 6caf1db38..c5dd617ef 100644
23--- a/servconf.c
24+++ b/servconf.c
25@@ -182,6 +182,7 @@ initialize_server_options(ServerOptions *options)
26 options->fingerprint_hash = -1;
27 options->disable_forwarding = -1;
28 options->expose_userauth_info = -1;
29+ options->debian_banner = -1;
30 }
31
32 /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
33@@ -417,6 +418,8 @@ fill_default_server_options(ServerOptions *options)
34 options->disable_forwarding = 0;
35 if (options->expose_userauth_info == -1)
36 options->expose_userauth_info = 0;
37+ if (options->debian_banner == -1)
38+ options->debian_banner = 1;
39
40 assemble_algorithms(options);
41
42@@ -504,6 +507,7 @@ typedef enum {
43 sStreamLocalBindMask, sStreamLocalBindUnlink,
44 sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
45 sExposeAuthInfo, sRDomain,
46+ sDebianBanner,
47 sDeprecated, sIgnore, sUnsupported
48 } ServerOpCodes;
49
50@@ -661,6 +665,7 @@ static struct {
51 { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
52 { "rdomain", sRDomain, SSHCFG_ALL },
53 { "casignaturealgorithms", sCASignatureAlgorithms, SSHCFG_ALL },
54+ { "debianbanner", sDebianBanner, SSHCFG_GLOBAL },
55 { NULL, sBadOption, 0 }
56 };
57
58@@ -2173,6 +2178,10 @@ process_server_config_line(ServerOptions *options, char *line,
59 *charptr = xstrdup(arg);
60 break;
61
62+ case sDebianBanner:
63+ intptr = &options->debian_banner;
64+ goto parse_flag;
65+
66 case sDeprecated:
67 case sIgnore:
68 case sUnsupported:
69diff --git a/servconf.h b/servconf.h
70index 3b76da816..4e3c54042 100644
71--- a/servconf.h
72+++ b/servconf.h
73@@ -212,6 +212,8 @@ typedef struct {
74 int fingerprint_hash;
75 int expose_userauth_info;
76 u_int64_t timing_secret;
77+
78+ int debian_banner;
79 } ServerOptions;
80
81 /* Information about the incoming connection as used by Match */
82diff --git a/sshd.c b/sshd.c
83index 9481272fc..d7e77d343 100644
84--- a/sshd.c
85+++ b/sshd.c
86@@ -384,7 +384,8 @@ sshd_exchange_identification(struct ssh *ssh, int sock_in, int sock_out)
87 char remote_version[256]; /* Must be at least as big as buf. */
88
89 xasprintf(&server_version_string, "SSH-%d.%d-%.100s%s%s\r\n",
90- PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_RELEASE,
91+ PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2,
92+ options.debian_banner ? SSH_RELEASE : SSH_RELEASE_MINIMUM,
93 *options.version_addendum == '\0' ? "" : " ",
94 options.version_addendum);
95
96diff --git a/sshd_config.5 b/sshd_config.5
97index e7e55dd71..37e6be38f 100644
98--- a/sshd_config.5
99+++ b/sshd_config.5
100@@ -543,6 +543,11 @@ or
101 .Cm no .
102 The default is
103 .Cm yes .
104+.It Cm DebianBanner
105+Specifies whether the distribution-specified extra version suffix is
106+included during initial protocol handshake.
107+The default is
108+.Cm yes .
109 .It Cm DenyGroups
110 This keyword can be followed by a list of group name patterns, separated
111 by spaces.
diff --git a/debian/patches/debian-config.patch b/debian/patches/debian-config.patch
new file mode 100644
index 000000000..4866d52ad
--- /dev/null
+++ b/debian/patches/debian-config.patch
@@ -0,0 +1,238 @@
1From a433d9baa031d7136a8cf3e3807ebff83a3a8634 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:18 +0000
4Subject: Various Debian-specific configuration changes
5
6ssh: Enable ForwardX11Trusted, returning to earlier semantics which cause
7fewer problems with existing setups (http://bugs.debian.org/237021).
8
9ssh: Set 'SendEnv LANG LC_*' by default (http://bugs.debian.org/264024).
10
11ssh: Enable HashKnownHosts by default to try to limit the spread of ssh
12worms.
13
14ssh: Enable GSSAPIAuthentication by default.
15
16sshd: Enable PAM, disable ChallengeResponseAuthentication, and disable
17PrintMotd.
18
19sshd: Enable X11Forwarding.
20
21sshd: Set 'AcceptEnv LANG LC_*' by default.
22
23sshd: Change sftp subsystem path to /usr/lib/openssh/sftp-server.
24
25Document all of this.
26
27Author: Russ Allbery <rra@debian.org>
28Forwarded: not-needed
29Last-Update: 2017-10-04
30
31Patch-Name: debian-config.patch
32---
33 readconf.c | 2 +-
34 ssh.1 | 21 +++++++++++++++++++++
35 ssh_config | 6 +++++-
36 ssh_config.5 | 19 ++++++++++++++++++-
37 sshd_config | 16 ++++++++++------
38 sshd_config.5 | 22 ++++++++++++++++++++++
39 6 files changed, 77 insertions(+), 9 deletions(-)
40
41diff --git a/readconf.c b/readconf.c
42index 6b01f20d2..661b8bf40 100644
43--- a/readconf.c
44+++ b/readconf.c
45@@ -2000,7 +2000,7 @@ fill_default_options(Options * options)
46 if (options->forward_x11 == -1)
47 options->forward_x11 = 0;
48 if (options->forward_x11_trusted == -1)
49- options->forward_x11_trusted = 0;
50+ options->forward_x11_trusted = 1;
51 if (options->forward_x11_timeout == -1)
52 options->forward_x11_timeout = 1200;
53 /*
54diff --git a/ssh.1 b/ssh.1
55index ad1ed0f86..1bcc8edab 100644
56--- a/ssh.1
57+++ b/ssh.1
58@@ -782,6 +782,16 @@ directive in
59 .Xr ssh_config 5
60 for more information.
61 .Pp
62+(Debian-specific: X11 forwarding is not subjected to X11 SECURITY extension
63+restrictions by default, because too many programs currently crash in this
64+mode.
65+Set the
66+.Cm ForwardX11Trusted
67+option to
68+.Dq no
69+to restore the upstream behaviour.
70+This may change in future depending on client-side improvements.)
71+.Pp
72 .It Fl x
73 Disables X11 forwarding.
74 .Pp
75@@ -790,6 +800,17 @@ Enables trusted X11 forwarding.
76 Trusted X11 forwardings are not subjected to the X11 SECURITY extension
77 controls.
78 .Pp
79+(Debian-specific: This option does nothing in the default configuration: it
80+is equivalent to
81+.Dq Cm ForwardX11Trusted No yes ,
82+which is the default as described above.
83+Set the
84+.Cm ForwardX11Trusted
85+option to
86+.Dq no
87+to restore the upstream behaviour.
88+This may change in future depending on client-side improvements.)
89+.Pp
90 .It Fl y
91 Send log information using the
92 .Xr syslog 3
93diff --git a/ssh_config b/ssh_config
94index bcb9f153d..1b676fb2c 100644
95--- a/ssh_config
96+++ b/ssh_config
97@@ -17,9 +17,10 @@
98 # list of available options, their meanings and defaults, please see the
99 # ssh_config(5) man page.
100
101-# Host *
102+Host *
103 # ForwardAgent no
104 # ForwardX11 no
105+# ForwardX11Trusted yes
106 # PasswordAuthentication yes
107 # HostbasedAuthentication no
108 # GSSAPIAuthentication no
109@@ -46,3 +47,6 @@
110 # VisualHostKey no
111 # ProxyCommand ssh -q -W %h:%p gateway.example.com
112 # RekeyLimit 1G 1h
113+ SendEnv LANG LC_*
114+ HashKnownHosts yes
115+ GSSAPIAuthentication yes
116diff --git a/ssh_config.5 b/ssh_config.5
117index a91355726..1a8e24bd1 100644
118--- a/ssh_config.5
119+++ b/ssh_config.5
120@@ -71,6 +71,22 @@ Since the first obtained value for each parameter is used, more
121 host-specific declarations should be given near the beginning of the
122 file, and general defaults at the end.
123 .Pp
124+Note that the Debian
125+.Ic openssh-client
126+package sets several options as standard in
127+.Pa /etc/ssh/ssh_config
128+which are not the default in
129+.Xr ssh 1 :
130+.Pp
131+.Bl -bullet -offset indent -compact
132+.It
133+.Cm SendEnv No LANG LC_*
134+.It
135+.Cm HashKnownHosts No yes
136+.It
137+.Cm GSSAPIAuthentication No yes
138+.El
139+.Pp
140 The file contains keyword-argument pairs, one per line.
141 Lines starting with
142 .Ql #
143@@ -699,11 +715,12 @@ elapsed.
144 .It Cm ForwardX11Trusted
145 If this option is set to
146 .Cm yes ,
147+(the Debian-specific default),
148 remote X11 clients will have full access to the original X11 display.
149 .Pp
150 If this option is set to
151 .Cm no
152-(the default),
153+(the upstream default),
154 remote X11 clients will be considered untrusted and prevented
155 from stealing or tampering with data belonging to trusted X11
156 clients.
157diff --git a/sshd_config b/sshd_config
158index 2c48105f8..ed8272f6d 100644
159--- a/sshd_config
160+++ b/sshd_config
161@@ -57,8 +57,9 @@ AuthorizedKeysFile .ssh/authorized_keys
162 #PasswordAuthentication yes
163 #PermitEmptyPasswords no
164
165-# Change to no to disable s/key passwords
166-#ChallengeResponseAuthentication yes
167+# Change to yes to enable challenge-response passwords (beware issues with
168+# some PAM modules and threads)
169+ChallengeResponseAuthentication no
170
171 # Kerberos options
172 #KerberosAuthentication no
173@@ -81,16 +82,16 @@ AuthorizedKeysFile .ssh/authorized_keys
174 # If you just want the PAM account and session checks to run without
175 # PAM authentication, then enable this but set PasswordAuthentication
176 # and ChallengeResponseAuthentication to 'no'.
177-#UsePAM no
178+UsePAM yes
179
180 #AllowAgentForwarding yes
181 #AllowTcpForwarding yes
182 #GatewayPorts no
183-#X11Forwarding no
184+X11Forwarding yes
185 #X11DisplayOffset 10
186 #X11UseLocalhost yes
187 #PermitTTY yes
188-#PrintMotd yes
189+PrintMotd no
190 #PrintLastLog yes
191 #TCPKeepAlive yes
192 #PermitUserEnvironment no
193@@ -107,8 +108,11 @@ AuthorizedKeysFile .ssh/authorized_keys
194 # no default banner path
195 #Banner none
196
197+# Allow client to pass locale environment variables
198+AcceptEnv LANG LC_*
199+
200 # override default of no subsystems
201-Subsystem sftp /usr/libexec/sftp-server
202+Subsystem sftp /usr/lib/openssh/sftp-server
203
204 # Example of overriding settings on a per-user basis
205 #Match User anoncvs
206diff --git a/sshd_config.5 b/sshd_config.5
207index 23f71fd1d..ba50a30f1 100644
208--- a/sshd_config.5
209+++ b/sshd_config.5
210@@ -56,6 +56,28 @@ Arguments may optionally be enclosed in double quotes
211 .Pq \&"
212 in order to represent arguments containing spaces.
213 .Pp
214+Note that the Debian
215+.Ic openssh-server
216+package sets several options as standard in
217+.Pa /etc/ssh/sshd_config
218+which are not the default in
219+.Xr sshd 8 :
220+.Pp
221+.Bl -bullet -offset indent -compact
222+.It
223+.Cm ChallengeResponseAuthentication No no
224+.It
225+.Cm X11Forwarding No yes
226+.It
227+.Cm PrintMotd No no
228+.It
229+.Cm AcceptEnv No LANG LC_*
230+.It
231+.Cm Subsystem No sftp /usr/lib/openssh/sftp-server
232+.It
233+.Cm UsePAM No yes
234+.El
235+.Pp
236 The possible
237 keywords and their meanings are as follows (note that
238 keywords are case-insensitive and arguments are case-sensitive):
diff --git a/debian/patches/dnssec-sshfp.patch b/debian/patches/dnssec-sshfp.patch
new file mode 100644
index 000000000..e2acdf1a2
--- /dev/null
+++ b/debian/patches/dnssec-sshfp.patch
@@ -0,0 +1,94 @@
1From 0ee33d93c5c7a5fbb8b027aa24e7c9668125fda9 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:01 +0000
4Subject: Force use of DNSSEC even if "options edns0" isn't in resolv.conf
5
6This allows SSHFP DNS records to be verified if glibc 2.11 is installed.
7
8Origin: vendor, https://cvs.fedoraproject.org/viewvc/F-12/openssh/openssh-5.2p1-edns.patch?revision=1.1&view=markup
9Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572049
10Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572049
11Last-Update: 2010-04-06
12
13Patch-Name: dnssec-sshfp.patch
14---
15 dns.c | 14 +++++++++++++-
16 openbsd-compat/getrrsetbyname.c | 10 +++++-----
17 openbsd-compat/getrrsetbyname.h | 3 +++
18 3 files changed, 21 insertions(+), 6 deletions(-)
19
20diff --git a/dns.c b/dns.c
21index ff1a2c41c..82ec97199 100644
22--- a/dns.c
23+++ b/dns.c
24@@ -211,6 +211,7 @@ verify_host_key_dns(const char *hostname, struct sockaddr *address,
25 {
26 u_int counter;
27 int result;
28+ unsigned int rrset_flags = 0;
29 struct rrsetinfo *fingerprints = NULL;
30
31 u_int8_t hostkey_algorithm;
32@@ -234,8 +235,19 @@ verify_host_key_dns(const char *hostname, struct sockaddr *address,
33 return -1;
34 }
35
36+ /*
37+ * Original getrrsetbyname function, found on OpenBSD for example,
38+ * doesn't accept any flag and prerequisite for obtaining AD bit in
39+ * DNS response is set by "options edns0" in resolv.conf.
40+ *
41+ * Our version is more clever and use RRSET_FORCE_EDNS0 flag.
42+ */
43+#ifndef HAVE_GETRRSETBYNAME
44+ rrset_flags |= RRSET_FORCE_EDNS0;
45+#endif
46 result = getrrsetbyname(hostname, DNS_RDATACLASS_IN,
47- DNS_RDATATYPE_SSHFP, 0, &fingerprints);
48+ DNS_RDATATYPE_SSHFP, rrset_flags, &fingerprints);
49+
50 if (result) {
51 verbose("DNS lookup error: %s", dns_result_totext(result));
52 return -1;
53diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c
54index dc6fe0533..e061a290a 100644
55--- a/openbsd-compat/getrrsetbyname.c
56+++ b/openbsd-compat/getrrsetbyname.c
57@@ -209,8 +209,8 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
58 goto fail;
59 }
60
61- /* don't allow flags yet, unimplemented */
62- if (flags) {
63+ /* Allow RRSET_FORCE_EDNS0 flag only. */
64+ if ((flags & !RRSET_FORCE_EDNS0) != 0) {
65 result = ERRSET_INVAL;
66 goto fail;
67 }
68@@ -226,9 +226,9 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
69 #endif /* DEBUG */
70
71 #ifdef RES_USE_DNSSEC
72- /* turn on DNSSEC if EDNS0 is configured */
73- if (_resp->options & RES_USE_EDNS0)
74- _resp->options |= RES_USE_DNSSEC;
75+ /* turn on DNSSEC if required */
76+ if (flags & RRSET_FORCE_EDNS0)
77+ _resp->options |= (RES_USE_EDNS0|RES_USE_DNSSEC);
78 #endif /* RES_USE_DNSEC */
79
80 /* make query */
81diff --git a/openbsd-compat/getrrsetbyname.h b/openbsd-compat/getrrsetbyname.h
82index 1283f5506..dbbc85a2a 100644
83--- a/openbsd-compat/getrrsetbyname.h
84+++ b/openbsd-compat/getrrsetbyname.h
85@@ -72,6 +72,9 @@
86 #ifndef RRSET_VALIDATED
87 # define RRSET_VALIDATED 1
88 #endif
89+#ifndef RRSET_FORCE_EDNS0
90+# define RRSET_FORCE_EDNS0 0x0001
91+#endif
92
93 /*
94 * Return codes for getrrsetbyname()
diff --git a/debian/patches/doc-hash-tab-completion.patch b/debian/patches/doc-hash-tab-completion.patch
new file mode 100644
index 000000000..c6bc43299
--- /dev/null
+++ b/debian/patches/doc-hash-tab-completion.patch
@@ -0,0 +1,28 @@
1From 1d0c41a7e0b2426733ddb598248d0488c9c00a8b Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:11 +0000
4Subject: Document that HashKnownHosts may break tab-completion
5
6Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1727
7Bug-Debian: http://bugs.debian.org/430154
8Last-Update: 2013-09-14
9
10Patch-Name: doc-hash-tab-completion.patch
11---
12 ssh_config.5 | 3 +++
13 1 file changed, 3 insertions(+)
14
15diff --git a/ssh_config.5 b/ssh_config.5
16index 7d55fa820..a91355726 100644
17--- a/ssh_config.5
18+++ b/ssh_config.5
19@@ -793,6 +793,9 @@ Note that existing names and addresses in known hosts files
20 will not be converted automatically,
21 but may be manually hashed using
22 .Xr ssh-keygen 1 .
23+Use of this option may break facilities such as tab-completion that rely
24+on being able to read unhashed host names from
25+.Pa ~/.ssh/known_hosts .
26 .It Cm HostbasedAuthentication
27 Specifies whether to try rhosts based authentication with public key
28 authentication.
diff --git a/debian/patches/fix-key-type-check.patch b/debian/patches/fix-key-type-check.patch
new file mode 100644
index 000000000..846df5768
--- /dev/null
+++ b/debian/patches/fix-key-type-check.patch
@@ -0,0 +1,88 @@
1From 5e021158aa22cc64da4fca1618ee0bfd2d031049 Mon Sep 17 00:00:00 2001
2From: "djm@openbsd.org" <djm@openbsd.org>
3Date: Fri, 16 Nov 2018 02:43:56 +0000
4Subject: upstream: fix bug in HostbasedAcceptedKeyTypes and
5
6PubkeyAcceptedKeyTypes options. If only RSA-SHA2 siganture types were
7specified, then authentication would always fail for RSA keys as the monitor
8checks only the base key (not the signature algorithm) type against
9*AcceptedKeyTypes. bz#2746; reported by Jakub Jelen; ok dtucker
10
11OpenBSD-Commit-ID: 117bc3dc54578dbdb515a1d3732988cb5b00461b
12
13Origin: upstream, https://anongit.mindrot.org/openssh.git/commit/?id=cd9467318b56e6e93ff9575c906ff8350af9b8a2
14Last-Update: 2019-02-28
15
16Patch-Name: fix-key-type-check.patch
17---
18 monitor.c | 39 ++++++++++++++++++++++++++++++++++-----
19 1 file changed, 34 insertions(+), 5 deletions(-)
20
21diff --git a/monitor.c b/monitor.c
22index 08fddabd7..037d6d333 100644
23--- a/monitor.c
24+++ b/monitor.c
25@@ -1,4 +1,4 @@
26-/* $OpenBSD: monitor.c,v 1.186 2018/07/20 03:46:34 djm Exp $ */
27+/* $OpenBSD: monitor.c,v 1.188 2018/11/16 02:43:56 djm Exp $ */
28 /*
29 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
30 * Copyright 2002 Markus Friedl <markus@openbsd.org>
31@@ -892,6 +892,35 @@ mm_answer_authrole(int sock, struct sshbuf *m)
32 return (0);
33 }
34
35+/*
36+ * Check that the key type appears in the supplied pattern list, ignoring
37+ * mismatches in the signature algorithm. (Signature algorithm checks are
38+ * performed in the unprivileged authentication code).
39+ * Returns 1 on success, 0 otherwise.
40+ */
41+static int
42+key_base_type_match(const char *method, const struct sshkey *key,
43+ const char *list)
44+{
45+ char *s, *l, *ol = xstrdup(list);
46+ int found = 0;
47+
48+ l = ol;
49+ for ((s = strsep(&l, ",")); s && *s != '\0'; (s = strsep(&l, ","))) {
50+ if (sshkey_type_from_name(s) == key->type) {
51+ found = 1;
52+ break;
53+ }
54+ }
55+ if (!found) {
56+ error("%s key type %s is not in permitted list %s", method,
57+ sshkey_ssh_name(key), list);
58+ }
59+
60+ free(ol);
61+ return found;
62+}
63+
64 int
65 mm_answer_authpassword(int sock, struct sshbuf *m)
66 {
67@@ -1197,8 +1226,8 @@ mm_answer_keyallowed(int sock, struct sshbuf *m)
68 break;
69 if (auth2_key_already_used(authctxt, key))
70 break;
71- if (match_pattern_list(sshkey_ssh_name(key),
72- options.pubkey_key_types, 0) != 1)
73+ if (!key_base_type_match(auth_method, key,
74+ options.pubkey_key_types))
75 break;
76 allowed = user_key_allowed(ssh, authctxt->pw, key,
77 pubkey_auth_attempt, &opts);
78@@ -1209,8 +1238,8 @@ mm_answer_keyallowed(int sock, struct sshbuf *m)
79 break;
80 if (auth2_key_already_used(authctxt, key))
81 break;
82- if (match_pattern_list(sshkey_ssh_name(key),
83- options.hostbased_key_types, 0) != 1)
84+ if (!key_base_type_match(auth_method, key,
85+ options.hostbased_key_types))
86 break;
87 allowed = hostbased_key_allowed(authctxt->pw,
88 cuser, chost, key);
diff --git a/debian/patches/gnome-ssh-askpass2-icon.patch b/debian/patches/gnome-ssh-askpass2-icon.patch
new file mode 100644
index 000000000..b6d4f1239
--- /dev/null
+++ b/debian/patches/gnome-ssh-askpass2-icon.patch
@@ -0,0 +1,26 @@
1From df56506f727e37c13346259bdcd5975e257a259d Mon Sep 17 00:00:00 2001
2From: Vincent Untz <vuntz@ubuntu.com>
3Date: Sun, 9 Feb 2014 16:10:16 +0000
4Subject: Give the ssh-askpass-gnome window a default icon
5
6Bug-Ubuntu: https://bugs.launchpad.net/bugs/27152
7Last-Update: 2010-02-28
8
9Patch-Name: gnome-ssh-askpass2-icon.patch
10---
11 contrib/gnome-ssh-askpass2.c | 2 ++
12 1 file changed, 2 insertions(+)
13
14diff --git a/contrib/gnome-ssh-askpass2.c b/contrib/gnome-ssh-askpass2.c
15index 535a69274..e37a13382 100644
16--- a/contrib/gnome-ssh-askpass2.c
17+++ b/contrib/gnome-ssh-askpass2.c
18@@ -211,6 +211,8 @@ main(int argc, char **argv)
19
20 gtk_init(&argc, &argv);
21
22+ gtk_window_set_default_icon_from_file ("/usr/share/pixmaps/ssh-askpass-gnome.png", NULL);
23+
24 if (argc > 1) {
25 message = g_strjoinv(" ", argv + 1);
26 } else {
diff --git a/debian/patches/gssapi.patch b/debian/patches/gssapi.patch
new file mode 100644
index 000000000..f62bf6672
--- /dev/null
+++ b/debian/patches/gssapi.patch
@@ -0,0 +1,3353 @@
1From 72b1d308e6400194ef6e4e7dd45bfa48fa39b5e6 Mon Sep 17 00:00:00 2001
2From: Simon Wilkinson <simon@sxw.org.uk>
3Date: Sun, 9 Feb 2014 16:09:48 +0000
4Subject: GSSAPI key exchange support
5
6This patch has been rejected upstream: "None of the OpenSSH developers are
7in favour of adding this, and this situation has not changed for several
8years. This is not a slight on Simon's patch, which is of fine quality, but
9just that a) we don't trust GSSAPI implementations that much and b) we don't
10like adding new KEX since they are pre-auth attack surface. This one is
11particularly scary, since it requires hooks out to typically root-owned
12system resources."
13
14However, quite a lot of people rely on this in Debian, and it's better to
15have it merged into the main openssh package rather than having separate
16-krb5 packages (as we used to have). It seems to have a generally good
17security history.
18
19Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1242
20Last-Updated: 2018-10-20
21
22Patch-Name: gssapi.patch
23---
24 ChangeLog.gssapi | 113 ++++++++++++++++
25 Makefile.in | 3 +-
26 auth-krb5.c | 17 ++-
27 auth.c | 96 +------------
28 auth2-gss.c | 54 +++++++-
29 auth2.c | 2 +
30 canohost.c | 93 +++++++++++++
31 canohost.h | 3 +
32 clientloop.c | 15 ++-
33 config.h.in | 6 +
34 configure.ac | 24 ++++
35 gss-genr.c | 280 +++++++++++++++++++++++++++++++++++++-
36 gss-serv-krb5.c | 85 +++++++++++-
37 gss-serv.c | 184 +++++++++++++++++++++++--
38 kex.c | 19 +++
39 kex.h | 14 ++
40 kexgssc.c | 341 +++++++++++++++++++++++++++++++++++++++++++++++
41 kexgsss.c | 300 +++++++++++++++++++++++++++++++++++++++++
42 monitor.c | 122 +++++++++++++++--
43 monitor.h | 3 +
44 monitor_wrap.c | 53 +++++++-
45 monitor_wrap.h | 4 +-
46 opacket.c | 2 +-
47 opacket.h | 2 +-
48 readconf.c | 43 ++++++
49 readconf.h | 5 +
50 servconf.c | 26 ++++
51 servconf.h | 2 +
52 ssh-gss.h | 41 +++++-
53 ssh_config | 2 +
54 ssh_config.5 | 32 +++++
55 sshconnect2.c | 133 +++++++++++++++++-
56 sshd.c | 110 +++++++++++++++
57 sshd_config | 2 +
58 sshd_config.5 | 10 ++
59 sshkey.c | 3 +-
60 sshkey.h | 1 +
61 37 files changed, 2099 insertions(+), 146 deletions(-)
62 create mode 100644 ChangeLog.gssapi
63 create mode 100644 kexgssc.c
64 create mode 100644 kexgsss.c
65
66diff --git a/ChangeLog.gssapi b/ChangeLog.gssapi
67new file mode 100644
68index 000000000..f117a336a
69--- /dev/null
70+++ b/ChangeLog.gssapi
71@@ -0,0 +1,113 @@
72+20110101
73+ - Finally update for OpenSSH 5.6p1
74+ - Add GSSAPIServerIdentity option from Jim Basney
75+
76+20100308
77+ - [ Makefile.in, key.c, key.h ]
78+ Updates for OpenSSH 5.4p1
79+ - [ servconf.c ]
80+ Include GSSAPI options in the sshd -T configuration dump, and flag
81+ some older configuration options as being unsupported. Thanks to Colin
82+ Watson.
83+ -
84+
85+20100124
86+ - [ sshconnect2.c ]
87+ Adapt to deal with additional element in Authmethod structure. Thanks to
88+ Colin Watson
89+
90+20090615
91+ - [ gss-genr.c gss-serv.c kexgssc.c kexgsss.c monitor.c sshconnect2.c
92+ sshd.c ]
93+ Fix issues identified by Greg Hudson following a code review
94+ Check return value of gss_indicate_mechs
95+ Protect GSSAPI calls in monitor, so they can only be used if enabled
96+ Check return values of bignum functions in key exchange
97+ Use BN_clear_free to clear other side's DH value
98+ Make ssh_gssapi_id_kex more robust
99+ Only configure kex table pointers if GSSAPI is enabled
100+ Don't leak mechanism list, or gss mechanism list
101+ Cast data.length before printing
102+ If serverkey isn't provided, use an empty string, rather than NULL
103+
104+20090201
105+ - [ gss-genr.c gss-serv.c kex.h kexgssc.c readconf.c readconf.h ssh-gss.h
106+ ssh_config.5 sshconnet2.c ]
107+ Add support for the GSSAPIClientIdentity option, which allows the user
108+ to specify which GSSAPI identity to use to contact a given server
109+
110+20080404
111+ - [ gss-serv.c ]
112+ Add code to actually implement GSSAPIStrictAcceptCheck, which had somehow
113+ been omitted from a previous version of this patch. Reported by Borislav
114+ Stoichkov
115+
116+20070317
117+ - [ gss-serv-krb5.c ]
118+ Remove C99ism, where new_ccname was being declared in the middle of a
119+ function
120+
121+20061220
122+ - [ servconf.c ]
123+ Make default for GSSAPIStrictAcceptorCheck be Yes, to match previous, and
124+ documented, behaviour. Reported by Dan Watson.
125+
126+20060910
127+ - [ gss-genr.c kexgssc.c kexgsss.c kex.h monitor.c sshconnect2.c sshd.c
128+ ssh-gss.h ]
129+ add support for gss-group14-sha1 key exchange mechanisms
130+ - [ gss-serv.c servconf.c servconf.h sshd_config sshd_config.5 ]
131+ Add GSSAPIStrictAcceptorCheck option to allow the disabling of
132+ acceptor principal checking on multi-homed machines.
133+ <Bugzilla #928>
134+ - [ sshd_config ssh_config ]
135+ Add settings for GSSAPIKeyExchange and GSSAPITrustDNS to the sample
136+ configuration files
137+ - [ kexgss.c kegsss.c sshconnect2.c sshd.c ]
138+ Code cleanup. Replace strlen/xmalloc/snprintf sequences with xasprintf()
139+ Limit length of error messages displayed by client
140+
141+20060909
142+ - [ gss-genr.c gss-serv.c ]
143+ move ssh_gssapi_acquire_cred() and ssh_gssapi_server_ctx to be server
144+ only, where they belong
145+ <Bugzilla #1225>
146+
147+20060829
148+ - [ gss-serv-krb5.c ]
149+ Fix CCAPI credentials cache name when creating KRB5CCNAME environment
150+ variable
151+
152+20060828
153+ - [ gss-genr.c ]
154+ Avoid Heimdal context freeing problem
155+ <Fixed upstream 20060829>
156+
157+20060818
158+ - [ gss-genr.c ssh-gss.h sshconnect2.c ]
159+ Make sure that SPENGO is disabled
160+ <Bugzilla #1218 - Fixed upstream 20060818>
161+
162+20060421
163+ - [ gssgenr.c, sshconnect2.c ]
164+ a few type changes (signed versus unsigned, int versus size_t) to
165+ fix compiler errors/warnings
166+ (from jbasney AT ncsa.uiuc.edu)
167+ - [ kexgssc.c, sshconnect2.c ]
168+ fix uninitialized variable warnings
169+ (from jbasney AT ncsa.uiuc.edu)
170+ - [ gssgenr.c ]
171+ pass oid to gss_display_status (helpful when using GSSAPI mechglue)
172+ (from jbasney AT ncsa.uiuc.edu)
173+ <Bugzilla #1220 >
174+ - [ gss-serv-krb5.c ]
175+ #ifdef HAVE_GSSAPI_KRB5 should be #ifdef HAVE_GSSAPI_KRB5_H
176+ (from jbasney AT ncsa.uiuc.edu)
177+ <Fixed upstream 20060304>
178+ - [ readconf.c, readconf.h, ssh_config.5, sshconnect2.c
179+ add client-side GssapiKeyExchange option
180+ (from jbasney AT ncsa.uiuc.edu)
181+ - [ sshconnect2.c ]
182+ add support for GssapiTrustDns option for gssapi-with-mic
183+ (from jbasney AT ncsa.uiuc.edu)
184+ <gssapi-with-mic support is Bugzilla #1008>
185diff --git a/Makefile.in b/Makefile.in
186index 126b2c742..70050ffb6 100644
187--- a/Makefile.in
188+++ b/Makefile.in
189@@ -100,6 +100,7 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
190 kex.o kexdh.o kexgex.o kexecdh.o kexc25519.o \
191 kexdhc.o kexgexc.o kexecdhc.o kexc25519c.o \
192 kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o \
193+ kexgssc.o \
194 platform-pledge.o platform-tracing.o platform-misc.o
195
196 SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
197@@ -113,7 +114,7 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o \
198 auth-bsdauth.o auth2-hostbased.o auth2-kbdint.o \
199 auth2-none.o auth2-passwd.o auth2-pubkey.o \
200 monitor.o monitor_wrap.o auth-krb5.o \
201- auth2-gss.o gss-serv.o gss-serv-krb5.o \
202+ auth2-gss.o gss-serv.o gss-serv-krb5.o kexgsss.o \
203 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
204 sftp-server.o sftp-common.o \
205 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \
206diff --git a/auth-krb5.c b/auth-krb5.c
207index 3096f1c8e..204752e1b 100644
208--- a/auth-krb5.c
209+++ b/auth-krb5.c
210@@ -182,8 +182,13 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
211
212 len = strlen(authctxt->krb5_ticket_file) + 6;
213 authctxt->krb5_ccname = xmalloc(len);
214+#ifdef USE_CCAPI
215+ snprintf(authctxt->krb5_ccname, len, "API:%s",
216+ authctxt->krb5_ticket_file);
217+#else
218 snprintf(authctxt->krb5_ccname, len, "FILE:%s",
219 authctxt->krb5_ticket_file);
220+#endif
221
222 #ifdef USE_PAM
223 if (options.use_pam)
224@@ -240,15 +245,22 @@ krb5_cleanup_proc(Authctxt *authctxt)
225 #ifndef HEIMDAL
226 krb5_error_code
227 ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
228- int tmpfd, ret, oerrno;
229+ int ret, oerrno;
230 char ccname[40];
231 mode_t old_umask;
232+#ifdef USE_CCAPI
233+ char cctemplate[] = "API:krb5cc_%d";
234+#else
235+ char cctemplate[] = "FILE:/tmp/krb5cc_%d_XXXXXXXXXX";
236+ int tmpfd;
237+#endif
238
239 ret = snprintf(ccname, sizeof(ccname),
240- "FILE:/tmp/krb5cc_%d_XXXXXXXXXX", geteuid());
241+ cctemplate, geteuid());
242 if (ret < 0 || (size_t)ret >= sizeof(ccname))
243 return ENOMEM;
244
245+#ifndef USE_CCAPI
246 old_umask = umask(0177);
247 tmpfd = mkstemp(ccname + strlen("FILE:"));
248 oerrno = errno;
249@@ -265,6 +277,7 @@ ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
250 return oerrno;
251 }
252 close(tmpfd);
253+#endif
254
255 return (krb5_cc_resolve(ctx, ccname, ccache));
256 }
257diff --git a/auth.c b/auth.c
258index 3ca3762cc..d8e6b4a3d 100644
259--- a/auth.c
260+++ b/auth.c
261@@ -399,7 +399,8 @@ auth_root_allowed(struct ssh *ssh, const char *method)
262 case PERMIT_NO_PASSWD:
263 if (strcmp(method, "publickey") == 0 ||
264 strcmp(method, "hostbased") == 0 ||
265- strcmp(method, "gssapi-with-mic") == 0)
266+ strcmp(method, "gssapi-with-mic") == 0 ||
267+ strcmp(method, "gssapi-keyex") == 0)
268 return 1;
269 break;
270 case PERMIT_FORCED_ONLY:
271@@ -737,99 +738,6 @@ fakepw(void)
272 return (&fake);
273 }
274
275-/*
276- * Returns the remote DNS hostname as a string. The returned string must not
277- * be freed. NB. this will usually trigger a DNS query the first time it is
278- * called.
279- * This function does additional checks on the hostname to mitigate some
280- * attacks on legacy rhosts-style authentication.
281- * XXX is RhostsRSAAuthentication vulnerable to these?
282- * XXX Can we remove these checks? (or if not, remove RhostsRSAAuthentication?)
283- */
284-
285-static char *
286-remote_hostname(struct ssh *ssh)
287-{
288- struct sockaddr_storage from;
289- socklen_t fromlen;
290- struct addrinfo hints, *ai, *aitop;
291- char name[NI_MAXHOST], ntop2[NI_MAXHOST];
292- const char *ntop = ssh_remote_ipaddr(ssh);
293-
294- /* Get IP address of client. */
295- fromlen = sizeof(from);
296- memset(&from, 0, sizeof(from));
297- if (getpeername(ssh_packet_get_connection_in(ssh),
298- (struct sockaddr *)&from, &fromlen) < 0) {
299- debug("getpeername failed: %.100s", strerror(errno));
300- return strdup(ntop);
301- }
302-
303- ipv64_normalise_mapped(&from, &fromlen);
304- if (from.ss_family == AF_INET6)
305- fromlen = sizeof(struct sockaddr_in6);
306-
307- debug3("Trying to reverse map address %.100s.", ntop);
308- /* Map the IP address to a host name. */
309- if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
310- NULL, 0, NI_NAMEREQD) != 0) {
311- /* Host name not found. Use ip address. */
312- return strdup(ntop);
313- }
314-
315- /*
316- * if reverse lookup result looks like a numeric hostname,
317- * someone is trying to trick us by PTR record like following:
318- * 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5
319- */
320- memset(&hints, 0, sizeof(hints));
321- hints.ai_socktype = SOCK_DGRAM; /*dummy*/
322- hints.ai_flags = AI_NUMERICHOST;
323- if (getaddrinfo(name, NULL, &hints, &ai) == 0) {
324- logit("Nasty PTR record \"%s\" is set up for %s, ignoring",
325- name, ntop);
326- freeaddrinfo(ai);
327- return strdup(ntop);
328- }
329-
330- /* Names are stored in lowercase. */
331- lowercase(name);
332-
333- /*
334- * Map it back to an IP address and check that the given
335- * address actually is an address of this host. This is
336- * necessary because anyone with access to a name server can
337- * define arbitrary names for an IP address. Mapping from
338- * name to IP address can be trusted better (but can still be
339- * fooled if the intruder has access to the name server of
340- * the domain).
341- */
342- memset(&hints, 0, sizeof(hints));
343- hints.ai_family = from.ss_family;
344- hints.ai_socktype = SOCK_STREAM;
345- if (getaddrinfo(name, NULL, &hints, &aitop) != 0) {
346- logit("reverse mapping checking getaddrinfo for %.700s "
347- "[%s] failed.", name, ntop);
348- return strdup(ntop);
349- }
350- /* Look for the address from the list of addresses. */
351- for (ai = aitop; ai; ai = ai->ai_next) {
352- if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop2,
353- sizeof(ntop2), NULL, 0, NI_NUMERICHOST) == 0 &&
354- (strcmp(ntop, ntop2) == 0))
355- break;
356- }
357- freeaddrinfo(aitop);
358- /* If we reached the end of the list, the address was not there. */
359- if (ai == NULL) {
360- /* Address not found for the host name. */
361- logit("Address %.100s maps to %.600s, but this does not "
362- "map back to the address.", ntop, name);
363- return strdup(ntop);
364- }
365- return strdup(name);
366-}
367-
368 /*
369 * Return the canonical name of the host in the other side of the current
370 * connection. The host name is cached, so it is efficient to call this
371diff --git a/auth2-gss.c b/auth2-gss.c
372index 9351e0428..1f12bb113 100644
373--- a/auth2-gss.c
374+++ b/auth2-gss.c
375@@ -1,7 +1,7 @@
376 /* $OpenBSD: auth2-gss.c,v 1.29 2018/07/31 03:10:27 djm Exp $ */
377
378 /*
379- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
380+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
381 *
382 * Redistribution and use in source and binary forms, with or without
383 * modification, are permitted provided that the following conditions
384@@ -54,6 +54,46 @@ static int input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh);
385 static int input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh);
386 static int input_gssapi_errtok(int, u_int32_t, struct ssh *);
387
388+/*
389+ * The 'gssapi_keyex' userauth mechanism.
390+ */
391+static int
392+userauth_gsskeyex(struct ssh *ssh)
393+{
394+ Authctxt *authctxt = ssh->authctxt;
395+ int r, authenticated = 0;
396+ struct sshbuf *b;
397+ gss_buffer_desc mic, gssbuf;
398+ u_char *p;
399+ size_t len;
400+
401+ if ((r = sshpkt_get_string(ssh, &p, &len)) != 0 ||
402+ (r = sshpkt_get_end(ssh)) != 0)
403+ fatal("%s: %s", __func__, ssh_err(r));
404+ if ((b = sshbuf_new()) == NULL)
405+ fatal("%s: sshbuf_new failed", __func__);
406+ mic.value = p;
407+ mic.length = len;
408+
409+ ssh_gssapi_buildmic(b, authctxt->user, authctxt->service,
410+ "gssapi-keyex");
411+
412+ if ((gssbuf.value = sshbuf_mutable_ptr(b)) == NULL)
413+ fatal("%s: sshbuf_mutable_ptr failed", __func__);
414+ gssbuf.length = sshbuf_len(b);
415+
416+ /* gss_kex_context is NULL with privsep, so we can't check it here */
417+ if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gss_kex_context,
418+ &gssbuf, &mic))))
419+ authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
420+ authctxt->pw));
421+
422+ sshbuf_free(b);
423+ free(mic.value);
424+
425+ return (authenticated);
426+}
427+
428 /*
429 * We only support those mechanisms that we know about (ie ones that we know
430 * how to check local user kuserok and the like)
431@@ -260,7 +300,8 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh)
432 if ((r = sshpkt_get_end(ssh)) != 0)
433 fatal("%s: %s", __func__, ssh_err(r));
434
435- authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
436+ authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
437+ authctxt->pw));
438
439 if ((!use_privsep || mm_is_monitor()) &&
440 (displayname = ssh_gssapi_displayname()) != NULL)
441@@ -306,7 +347,8 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh)
442 gssbuf.length = sshbuf_len(b);
443
444 if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic))))
445- authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
446+ authenticated =
447+ PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw));
448 else
449 logit("GSSAPI MIC check failed");
450
451@@ -326,6 +368,12 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh)
452 return 0;
453 }
454
455+Authmethod method_gsskeyex = {
456+ "gssapi-keyex",
457+ userauth_gsskeyex,
458+ &options.gss_authentication
459+};
460+
461 Authmethod method_gssapi = {
462 "gssapi-with-mic",
463 userauth_gssapi,
464diff --git a/auth2.c b/auth2.c
465index 4d19957a6..a77742819 100644
466--- a/auth2.c
467+++ b/auth2.c
468@@ -74,6 +74,7 @@ extern Authmethod method_passwd;
469 extern Authmethod method_kbdint;
470 extern Authmethod method_hostbased;
471 #ifdef GSSAPI
472+extern Authmethod method_gsskeyex;
473 extern Authmethod method_gssapi;
474 #endif
475
476@@ -81,6 +82,7 @@ Authmethod *authmethods[] = {
477 &method_none,
478 &method_pubkey,
479 #ifdef GSSAPI
480+ &method_gsskeyex,
481 &method_gssapi,
482 #endif
483 &method_passwd,
484diff --git a/canohost.c b/canohost.c
485index f71a08568..404731d24 100644
486--- a/canohost.c
487+++ b/canohost.c
488@@ -35,6 +35,99 @@
489 #include "canohost.h"
490 #include "misc.h"
491
492+/*
493+ * Returns the remote DNS hostname as a string. The returned string must not
494+ * be freed. NB. this will usually trigger a DNS query the first time it is
495+ * called.
496+ * This function does additional checks on the hostname to mitigate some
497+ * attacks on legacy rhosts-style authentication.
498+ * XXX is RhostsRSAAuthentication vulnerable to these?
499+ * XXX Can we remove these checks? (or if not, remove RhostsRSAAuthentication?)
500+ */
501+
502+char *
503+remote_hostname(struct ssh *ssh)
504+{
505+ struct sockaddr_storage from;
506+ socklen_t fromlen;
507+ struct addrinfo hints, *ai, *aitop;
508+ char name[NI_MAXHOST], ntop2[NI_MAXHOST];
509+ const char *ntop = ssh_remote_ipaddr(ssh);
510+
511+ /* Get IP address of client. */
512+ fromlen = sizeof(from);
513+ memset(&from, 0, sizeof(from));
514+ if (getpeername(ssh_packet_get_connection_in(ssh),
515+ (struct sockaddr *)&from, &fromlen) < 0) {
516+ debug("getpeername failed: %.100s", strerror(errno));
517+ return strdup(ntop);
518+ }
519+
520+ ipv64_normalise_mapped(&from, &fromlen);
521+ if (from.ss_family == AF_INET6)
522+ fromlen = sizeof(struct sockaddr_in6);
523+
524+ debug3("Trying to reverse map address %.100s.", ntop);
525+ /* Map the IP address to a host name. */
526+ if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
527+ NULL, 0, NI_NAMEREQD) != 0) {
528+ /* Host name not found. Use ip address. */
529+ return strdup(ntop);
530+ }
531+
532+ /*
533+ * if reverse lookup result looks like a numeric hostname,
534+ * someone is trying to trick us by PTR record like following:
535+ * 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5
536+ */
537+ memset(&hints, 0, sizeof(hints));
538+ hints.ai_socktype = SOCK_DGRAM; /*dummy*/
539+ hints.ai_flags = AI_NUMERICHOST;
540+ if (getaddrinfo(name, NULL, &hints, &ai) == 0) {
541+ logit("Nasty PTR record \"%s\" is set up for %s, ignoring",
542+ name, ntop);
543+ freeaddrinfo(ai);
544+ return strdup(ntop);
545+ }
546+
547+ /* Names are stored in lowercase. */
548+ lowercase(name);
549+
550+ /*
551+ * Map it back to an IP address and check that the given
552+ * address actually is an address of this host. This is
553+ * necessary because anyone with access to a name server can
554+ * define arbitrary names for an IP address. Mapping from
555+ * name to IP address can be trusted better (but can still be
556+ * fooled if the intruder has access to the name server of
557+ * the domain).
558+ */
559+ memset(&hints, 0, sizeof(hints));
560+ hints.ai_family = from.ss_family;
561+ hints.ai_socktype = SOCK_STREAM;
562+ if (getaddrinfo(name, NULL, &hints, &aitop) != 0) {
563+ logit("reverse mapping checking getaddrinfo for %.700s "
564+ "[%s] failed.", name, ntop);
565+ return strdup(ntop);
566+ }
567+ /* Look for the address from the list of addresses. */
568+ for (ai = aitop; ai; ai = ai->ai_next) {
569+ if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop2,
570+ sizeof(ntop2), NULL, 0, NI_NUMERICHOST) == 0 &&
571+ (strcmp(ntop, ntop2) == 0))
572+ break;
573+ }
574+ freeaddrinfo(aitop);
575+ /* If we reached the end of the list, the address was not there. */
576+ if (ai == NULL) {
577+ /* Address not found for the host name. */
578+ logit("Address %.100s maps to %.600s, but this does not "
579+ "map back to the address.", ntop, name);
580+ return strdup(ntop);
581+ }
582+ return strdup(name);
583+}
584+
585 void
586 ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len)
587 {
588diff --git a/canohost.h b/canohost.h
589index 26d62855a..0cadc9f18 100644
590--- a/canohost.h
591+++ b/canohost.h
592@@ -15,6 +15,9 @@
593 #ifndef _CANOHOST_H
594 #define _CANOHOST_H
595
596+struct ssh;
597+
598+char *remote_hostname(struct ssh *);
599 char *get_peer_ipaddr(int);
600 int get_peer_port(int);
601 char *get_local_ipaddr(int);
602diff --git a/clientloop.c b/clientloop.c
603index 8d312cdaa..1464634b0 100644
604--- a/clientloop.c
605+++ b/clientloop.c
606@@ -112,6 +112,10 @@
607 #include "ssherr.h"
608 #include "hostfile.h"
609
610+#ifdef GSSAPI
611+#include "ssh-gss.h"
612+#endif
613+
614 /* import options */
615 extern Options options;
616
617@@ -1370,9 +1374,18 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
618 break;
619
620 /* Do channel operations unless rekeying in progress. */
621- if (!ssh_packet_is_rekeying(ssh))
622+ if (!ssh_packet_is_rekeying(ssh)) {
623 channel_after_select(ssh, readset, writeset);
624
625+#ifdef GSSAPI
626+ if (options.gss_renewal_rekey &&
627+ ssh_gssapi_credentials_updated(NULL)) {
628+ debug("credentials updated - forcing rekey");
629+ need_rekeying = 1;
630+ }
631+#endif
632+ }
633+
634 /* Buffer input from the connection. */
635 client_process_net_input(readset);
636
637diff --git a/config.h.in b/config.h.in
638index 91b65db8f..209760c7c 100644
639--- a/config.h.in
640+++ b/config.h.in
641@@ -1845,6 +1845,9 @@
642 /* Use btmp to log bad logins */
643 #undef USE_BTMP
644
645+/* platform uses an in-memory credentials cache */
646+#undef USE_CCAPI
647+
648 /* Use libedit for sftp */
649 #undef USE_LIBEDIT
650
651@@ -1860,6 +1863,9 @@
652 /* Use PIPES instead of a socketpair() */
653 #undef USE_PIPES
654
655+/* platform has the Security Authorization Session API */
656+#undef USE_SECURITY_SESSION_API
657+
658 /* Define if you have Solaris privileges */
659 #undef USE_SOLARIS_PRIVS
660
661diff --git a/configure.ac b/configure.ac
662index 7379ab358..023e7cc55 100644
663--- a/configure.ac
664+++ b/configure.ac
665@@ -664,6 +664,30 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
666 [Use tunnel device compatibility to OpenBSD])
667 AC_DEFINE([SSH_TUN_PREPEND_AF], [1],
668 [Prepend the address family to IP tunnel traffic])
669+ AC_MSG_CHECKING([if we have the Security Authorization Session API])
670+ AC_TRY_COMPILE([#include <Security/AuthSession.h>],
671+ [SessionCreate(0, 0);],
672+ [ac_cv_use_security_session_api="yes"
673+ AC_DEFINE([USE_SECURITY_SESSION_API], [1],
674+ [platform has the Security Authorization Session API])
675+ LIBS="$LIBS -framework Security"
676+ AC_MSG_RESULT([yes])],
677+ [ac_cv_use_security_session_api="no"
678+ AC_MSG_RESULT([no])])
679+ AC_MSG_CHECKING([if we have an in-memory credentials cache])
680+ AC_TRY_COMPILE(
681+ [#include <Kerberos/Kerberos.h>],
682+ [cc_context_t c;
683+ (void) cc_initialize (&c, 0, NULL, NULL);],
684+ [AC_DEFINE([USE_CCAPI], [1],
685+ [platform uses an in-memory credentials cache])
686+ LIBS="$LIBS -framework Security"
687+ AC_MSG_RESULT([yes])
688+ if test "x$ac_cv_use_security_session_api" = "xno"; then
689+ AC_MSG_ERROR([*** Need a security framework to use the credentials cache API ***])
690+ fi],
691+ [AC_MSG_RESULT([no])]
692+ )
693 m4_pattern_allow([AU_IPv])
694 AC_CHECK_DECL([AU_IPv4], [],
695 AC_DEFINE([AU_IPv4], [0], [System only supports IPv4 audit records])
696diff --git a/gss-genr.c b/gss-genr.c
697index d56257b4a..491e62cee 100644
698--- a/gss-genr.c
699+++ b/gss-genr.c
700@@ -1,7 +1,7 @@
701 /* $OpenBSD: gss-genr.c,v 1.26 2018/07/10 09:13:30 djm Exp $ */
702
703 /*
704- * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
705+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
706 *
707 * Redistribution and use in source and binary forms, with or without
708 * modification, are permitted provided that the following conditions
709@@ -39,14 +39,37 @@
710 #include "xmalloc.h"
711 #include "ssherr.h"
712 #include "sshbuf.h"
713+#include "sshkey.h"
714 #include "log.h"
715 #include "ssh2.h"
716+#include "cipher.h"
717+#include "kex.h"
718+#include "digest.h"
719
720 #include "ssh-gss.h"
721
722 extern u_char *session_id2;
723 extern u_int session_id2_len;
724
725+typedef struct {
726+ char *encoded;
727+ gss_OID oid;
728+} ssh_gss_kex_mapping;
729+
730+/*
731+ * XXX - It would be nice to find a more elegant way of handling the
732+ * XXX passing of the key exchange context to the userauth routines
733+ */
734+
735+Gssctxt *gss_kex_context = NULL;
736+
737+static ssh_gss_kex_mapping *gss_enc2oid = NULL;
738+
739+int
740+ssh_gssapi_oid_table_ok(void) {
741+ return (gss_enc2oid != NULL);
742+}
743+
744 /* sshbuf_get for gss_buffer_desc */
745 int
746 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)
748 return 0;
749 }
750
751+/*
752+ * Return a list of the gss-group1-sha1 mechanisms supported by this program
753+ *
754+ * We test mechanisms to ensure that we can use them, to avoid starting
755+ * a key exchange with a bad mechanism
756+ */
757+
758+char *
759+ssh_gssapi_client_mechanisms(const char *host, const char *client) {
760+ gss_OID_set gss_supported;
761+ OM_uint32 min_status;
762+
763+ if (GSS_ERROR(gss_indicate_mechs(&min_status, &gss_supported)))
764+ return NULL;
765+
766+ return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism,
767+ host, client));
768+}
769+
770+char *
771+ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
772+ const char *host, const char *client) {
773+ struct sshbuf *buf;
774+ size_t i;
775+ int r, oidpos, enclen;
776+ char *mechs, *encoded;
777+ u_char digest[SSH_DIGEST_MAX_LENGTH];
778+ char deroid[2];
779+ struct ssh_digest_ctx *md;
780+
781+ if (gss_enc2oid != NULL) {
782+ for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
783+ free(gss_enc2oid[i].encoded);
784+ free(gss_enc2oid);
785+ }
786+
787+ gss_enc2oid = xmalloc(sizeof(ssh_gss_kex_mapping) *
788+ (gss_supported->count + 1));
789+
790+ if ((buf = sshbuf_new()) == NULL)
791+ fatal("%s: sshbuf_new failed", __func__);
792+
793+ oidpos = 0;
794+ for (i = 0; i < gss_supported->count; i++) {
795+ if (gss_supported->elements[i].length < 128 &&
796+ (*check)(NULL, &(gss_supported->elements[i]), host, client)) {
797+
798+ deroid[0] = SSH_GSS_OIDTYPE;
799+ deroid[1] = gss_supported->elements[i].length;
800+
801+ if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL ||
802+ ssh_digest_update(md, deroid, 2) != 0 ||
803+ ssh_digest_update(md,
804+ gss_supported->elements[i].elements,
805+ gss_supported->elements[i].length) != 0 ||
806+ ssh_digest_final(md, digest, sizeof(digest)) != 0)
807+ fatal("%s: digest failed", __func__);
808+
809+ encoded = xmalloc(ssh_digest_bytes(SSH_DIGEST_MD5)
810+ * 2);
811+ enclen = __b64_ntop(digest,
812+ ssh_digest_bytes(SSH_DIGEST_MD5), encoded,
813+ ssh_digest_bytes(SSH_DIGEST_MD5) * 2);
814+
815+ if (oidpos != 0) {
816+ if ((r = sshbuf_put_u8(buf, ',')) != 0)
817+ fatal("%s: buffer error: %s",
818+ __func__, ssh_err(r));
819+ }
820+
821+ if ((r = sshbuf_put(buf, KEX_GSS_GEX_SHA1_ID,
822+ sizeof(KEX_GSS_GEX_SHA1_ID) - 1)) != 0 ||
823+ (r = sshbuf_put(buf, encoded, enclen)) != 0 ||
824+ (r = sshbuf_put_u8(buf, ',')) != 0 ||
825+ (r = sshbuf_put(buf, KEX_GSS_GRP1_SHA1_ID,
826+ sizeof(KEX_GSS_GRP1_SHA1_ID) - 1)) != 0 ||
827+ (r = sshbuf_put(buf, encoded, enclen)) != 0 ||
828+ (r = sshbuf_put_u8(buf, ',')) != 0 ||
829+ (r = sshbuf_put(buf, KEX_GSS_GRP14_SHA1_ID,
830+ sizeof(KEX_GSS_GRP14_SHA1_ID) - 1)) != 0 ||
831+ (r = sshbuf_put(buf, encoded, enclen)) != 0)
832+ fatal("%s: buffer error: %s",
833+ __func__, ssh_err(r));
834+
835+ gss_enc2oid[oidpos].oid = &(gss_supported->elements[i]);
836+ gss_enc2oid[oidpos].encoded = encoded;
837+ oidpos++;
838+ }
839+ }
840+ gss_enc2oid[oidpos].oid = NULL;
841+ gss_enc2oid[oidpos].encoded = NULL;
842+
843+ if ((mechs = sshbuf_dup_string(buf)) == NULL)
844+ fatal("%s: sshbuf_dup_string failed", __func__);
845+
846+ if (strlen(mechs) == 0) {
847+ free(mechs);
848+ mechs = NULL;
849+ }
850+
851+ return (mechs);
852+}
853+
854+gss_OID
855+ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
856+ int i = 0;
857+
858+ switch (kex_type) {
859+ case KEX_GSS_GRP1_SHA1:
860+ if (strlen(name) < sizeof(KEX_GSS_GRP1_SHA1_ID))
861+ return GSS_C_NO_OID;
862+ name += sizeof(KEX_GSS_GRP1_SHA1_ID) - 1;
863+ break;
864+ case KEX_GSS_GRP14_SHA1:
865+ if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA1_ID))
866+ return GSS_C_NO_OID;
867+ name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1;
868+ break;
869+ case KEX_GSS_GEX_SHA1:
870+ if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID))
871+ return GSS_C_NO_OID;
872+ name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1;
873+ break;
874+ default:
875+ return GSS_C_NO_OID;
876+ }
877+
878+ while (gss_enc2oid[i].encoded != NULL &&
879+ strcmp(name, gss_enc2oid[i].encoded) != 0)
880+ i++;
881+
882+ if (gss_enc2oid[i].oid != NULL && ctx != NULL)
883+ ssh_gssapi_set_oid(ctx, gss_enc2oid[i].oid);
884+
885+ return gss_enc2oid[i].oid;
886+}
887+
888 /* Check that the OID in a data stream matches that in the context */
889 int
890 ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len)
891@@ -218,7 +378,7 @@ ssh_gssapi_init_ctx(Gssctxt *ctx, int deleg_creds, gss_buffer_desc *recv_tok,
892 }
893
894 ctx->major = gss_init_sec_context(&ctx->minor,
895- GSS_C_NO_CREDENTIAL, &ctx->context, ctx->name, ctx->oid,
896+ ctx->client_creds, &ctx->context, ctx->name, ctx->oid,
897 GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag,
898 0, NULL, recv_tok, NULL, send_tok, flags, NULL);
899
900@@ -247,9 +407,43 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host)
901 return (ctx->major);
902 }
903
904+OM_uint32
905+ssh_gssapi_client_identity(Gssctxt *ctx, const char *name)
906+{
907+ gss_buffer_desc gssbuf;
908+ gss_name_t gssname;
909+ OM_uint32 status;
910+ gss_OID_set oidset;
911+
912+ gssbuf.value = (void *) name;
913+ gssbuf.length = strlen(gssbuf.value);
914+
915+ gss_create_empty_oid_set(&status, &oidset);
916+ gss_add_oid_set_member(&status, ctx->oid, &oidset);
917+
918+ ctx->major = gss_import_name(&ctx->minor, &gssbuf,
919+ GSS_C_NT_USER_NAME, &gssname);
920+
921+ if (!ctx->major)
922+ ctx->major = gss_acquire_cred(&ctx->minor,
923+ gssname, 0, oidset, GSS_C_INITIATE,
924+ &ctx->client_creds, NULL, NULL);
925+
926+ gss_release_name(&status, &gssname);
927+ gss_release_oid_set(&status, &oidset);
928+
929+ if (ctx->major)
930+ ssh_gssapi_error(ctx);
931+
932+ return(ctx->major);
933+}
934+
935 OM_uint32
936 ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
937 {
938+ if (ctx == NULL)
939+ return -1;
940+
941 if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context,
942 GSS_C_QOP_DEFAULT, buffer, hash)))
943 ssh_gssapi_error(ctx);
944@@ -257,6 +451,19 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
945 return (ctx->major);
946 }
947
948+/* Priviledged when used by server */
949+OM_uint32
950+ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
951+{
952+ if (ctx == NULL)
953+ return -1;
954+
955+ ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
956+ gssbuf, gssmic, NULL);
957+
958+ return (ctx->major);
959+}
960+
961 void
962 ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service,
963 const char *context)
964@@ -273,11 +480,16 @@ ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service,
965 }
966
967 int
968-ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
969+ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host,
970+ const char *client)
971 {
972 gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
973 OM_uint32 major, minor;
974 gss_OID_desc spnego_oid = {6, (void *)"\x2B\x06\x01\x05\x05\x02"};
975+ Gssctxt *intctx = NULL;
976+
977+ if (ctx == NULL)
978+ ctx = &intctx;
979
980 /* RFC 4462 says we MUST NOT do SPNEGO */
981 if (oid->length == spnego_oid.length &&
982@@ -287,6 +499,10 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
983 ssh_gssapi_build_ctx(ctx);
984 ssh_gssapi_set_oid(*ctx, oid);
985 major = ssh_gssapi_import_name(*ctx, host);
986+
987+ if (!GSS_ERROR(major) && client)
988+ major = ssh_gssapi_client_identity(*ctx, client);
989+
990 if (!GSS_ERROR(major)) {
991 major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token,
992 NULL);
993@@ -296,10 +512,66 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
994 GSS_C_NO_BUFFER);
995 }
996
997- if (GSS_ERROR(major))
998+ if (GSS_ERROR(major) || intctx != NULL)
999 ssh_gssapi_delete_ctx(ctx);
1000
1001 return (!GSS_ERROR(major));
1002 }
1003
1004+int
1005+ssh_gssapi_credentials_updated(Gssctxt *ctxt) {
1006+ static gss_name_t saved_name = GSS_C_NO_NAME;
1007+ static OM_uint32 saved_lifetime = 0;
1008+ static gss_OID saved_mech = GSS_C_NO_OID;
1009+ static gss_name_t name;
1010+ static OM_uint32 last_call = 0;
1011+ OM_uint32 lifetime, now, major, minor;
1012+ int equal;
1013+
1014+ now = time(NULL);
1015+
1016+ if (ctxt) {
1017+ debug("Rekey has happened - updating saved versions");
1018+
1019+ if (saved_name != GSS_C_NO_NAME)
1020+ gss_release_name(&minor, &saved_name);
1021+
1022+ major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
1023+ &saved_name, &saved_lifetime, NULL, NULL);
1024+
1025+ if (!GSS_ERROR(major)) {
1026+ saved_mech = ctxt->oid;
1027+ saved_lifetime+= now;
1028+ } else {
1029+ /* Handle the error */
1030+ }
1031+ return 0;
1032+ }
1033+
1034+ if (now - last_call < 10)
1035+ return 0;
1036+
1037+ last_call = now;
1038+
1039+ if (saved_mech == GSS_C_NO_OID)
1040+ return 0;
1041+
1042+ major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
1043+ &name, &lifetime, NULL, NULL);
1044+ if (major == GSS_S_CREDENTIALS_EXPIRED)
1045+ return 0;
1046+ else if (GSS_ERROR(major))
1047+ return 0;
1048+
1049+ major = gss_compare_name(&minor, saved_name, name, &equal);
1050+ gss_release_name(&minor, &name);
1051+ if (GSS_ERROR(major))
1052+ return 0;
1053+
1054+ if (equal && (saved_lifetime < lifetime + now - 10))
1055+ return 1;
1056+
1057+ return 0;
1058+}
1059+
1060 #endif /* GSSAPI */
1061diff --git a/gss-serv-krb5.c b/gss-serv-krb5.c
1062index a151bc1e4..90f8692f5 100644
1063--- a/gss-serv-krb5.c
1064+++ b/gss-serv-krb5.c
1065@@ -1,7 +1,7 @@
1066 /* $OpenBSD: gss-serv-krb5.c,v 1.9 2018/07/09 21:37:55 markus Exp $ */
1067
1068 /*
1069- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
1070+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
1071 *
1072 * Redistribution and use in source and binary forms, with or without
1073 * modification, are permitted provided that the following conditions
1074@@ -120,8 +120,8 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
1075 krb5_error_code problem;
1076 krb5_principal princ;
1077 OM_uint32 maj_status, min_status;
1078- int len;
1079 const char *errmsg;
1080+ const char *new_ccname;
1081
1082 if (client->creds == NULL) {
1083 debug("No credentials stored");
1084@@ -180,11 +180,16 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
1085 return;
1086 }
1087
1088- client->store.filename = xstrdup(krb5_cc_get_name(krb_context, ccache));
1089+ new_ccname = krb5_cc_get_name(krb_context, ccache);
1090+
1091 client->store.envvar = "KRB5CCNAME";
1092- len = strlen(client->store.filename) + 6;
1093- client->store.envval = xmalloc(len);
1094- snprintf(client->store.envval, len, "FILE:%s", client->store.filename);
1095+#ifdef USE_CCAPI
1096+ xasprintf(&client->store.envval, "API:%s", new_ccname);
1097+ client->store.filename = NULL;
1098+#else
1099+ xasprintf(&client->store.envval, "FILE:%s", new_ccname);
1100+ client->store.filename = xstrdup(new_ccname);
1101+#endif
1102
1103 #ifdef USE_PAM
1104 if (options.use_pam)
1105@@ -196,6 +201,71 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
1106 return;
1107 }
1108
1109+int
1110+ssh_gssapi_krb5_updatecreds(ssh_gssapi_ccache *store,
1111+ ssh_gssapi_client *client)
1112+{
1113+ krb5_ccache ccache = NULL;
1114+ krb5_principal principal = NULL;
1115+ char *name = NULL;
1116+ krb5_error_code problem;
1117+ OM_uint32 maj_status, min_status;
1118+
1119+ if ((problem = krb5_cc_resolve(krb_context, store->envval, &ccache))) {
1120+ logit("krb5_cc_resolve(): %.100s",
1121+ krb5_get_err_text(krb_context, problem));
1122+ return 0;
1123+ }
1124+
1125+ /* Find out who the principal in this cache is */
1126+ if ((problem = krb5_cc_get_principal(krb_context, ccache,
1127+ &principal))) {
1128+ logit("krb5_cc_get_principal(): %.100s",
1129+ krb5_get_err_text(krb_context, problem));
1130+ krb5_cc_close(krb_context, ccache);
1131+ return 0;
1132+ }
1133+
1134+ if ((problem = krb5_unparse_name(krb_context, principal, &name))) {
1135+ logit("krb5_unparse_name(): %.100s",
1136+ krb5_get_err_text(krb_context, problem));
1137+ krb5_free_principal(krb_context, principal);
1138+ krb5_cc_close(krb_context, ccache);
1139+ return 0;
1140+ }
1141+
1142+
1143+ if (strcmp(name,client->exportedname.value)!=0) {
1144+ debug("Name in local credentials cache differs. Not storing");
1145+ krb5_free_principal(krb_context, principal);
1146+ krb5_cc_close(krb_context, ccache);
1147+ krb5_free_unparsed_name(krb_context, name);
1148+ return 0;
1149+ }
1150+ krb5_free_unparsed_name(krb_context, name);
1151+
1152+ /* Name matches, so lets get on with it! */
1153+
1154+ if ((problem = krb5_cc_initialize(krb_context, ccache, principal))) {
1155+ logit("krb5_cc_initialize(): %.100s",
1156+ krb5_get_err_text(krb_context, problem));
1157+ krb5_free_principal(krb_context, principal);
1158+ krb5_cc_close(krb_context, ccache);
1159+ return 0;
1160+ }
1161+
1162+ krb5_free_principal(krb_context, principal);
1163+
1164+ if ((maj_status = gss_krb5_copy_ccache(&min_status, client->creds,
1165+ ccache))) {
1166+ logit("gss_krb5_copy_ccache() failed. Sorry!");
1167+ krb5_cc_close(krb_context, ccache);
1168+ return 0;
1169+ }
1170+
1171+ return 1;
1172+}
1173+
1174 ssh_gssapi_mech gssapi_kerberos_mech = {
1175 "toWM5Slw5Ew8Mqkay+al2g==",
1176 "Kerberos",
1177@@ -203,7 +273,8 @@ ssh_gssapi_mech gssapi_kerberos_mech = {
1178 NULL,
1179 &ssh_gssapi_krb5_userok,
1180 NULL,
1181- &ssh_gssapi_krb5_storecreds
1182+ &ssh_gssapi_krb5_storecreds,
1183+ &ssh_gssapi_krb5_updatecreds
1184 };
1185
1186 #endif /* KRB5 */
1187diff --git a/gss-serv.c b/gss-serv.c
1188index ab3a15f0f..6c087a1b1 100644
1189--- a/gss-serv.c
1190+++ b/gss-serv.c
1191@@ -1,7 +1,7 @@
1192 /* $OpenBSD: gss-serv.c,v 1.31 2018/07/09 21:37:55 markus Exp $ */
1193
1194 /*
1195- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
1196+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1197 *
1198 * Redistribution and use in source and binary forms, with or without
1199 * modification, are permitted provided that the following conditions
1200@@ -44,17 +44,22 @@
1201 #include "session.h"
1202 #include "misc.h"
1203 #include "servconf.h"
1204+#include "uidswap.h"
1205
1206 #include "ssh-gss.h"
1207+#include "monitor_wrap.h"
1208+
1209+extern ServerOptions options;
1210
1211 extern ServerOptions options;
1212
1213 static ssh_gssapi_client gssapi_client =
1214 { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER,
1215- GSS_C_NO_CREDENTIAL, NULL, {NULL, NULL, NULL, NULL}};
1216+ GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME, NULL,
1217+ {NULL, NULL, NULL, NULL, NULL}, 0, 0};
1218
1219 ssh_gssapi_mech gssapi_null_mech =
1220- { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL};
1221+ { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL, NULL};
1222
1223 #ifdef KRB5
1224 extern ssh_gssapi_mech gssapi_kerberos_mech;
1225@@ -140,6 +145,28 @@ ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID oid)
1226 return (ssh_gssapi_acquire_cred(*ctx));
1227 }
1228
1229+/* Unprivileged */
1230+char *
1231+ssh_gssapi_server_mechanisms(void) {
1232+ if (supported_oids == NULL)
1233+ ssh_gssapi_prepare_supported_oids();
1234+ return (ssh_gssapi_kex_mechs(supported_oids,
1235+ &ssh_gssapi_server_check_mech, NULL, NULL));
1236+}
1237+
1238+/* Unprivileged */
1239+int
1240+ssh_gssapi_server_check_mech(Gssctxt **dum, gss_OID oid, const char *data,
1241+ const char *dummy) {
1242+ Gssctxt *ctx = NULL;
1243+ int res;
1244+
1245+ res = !GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctx, oid)));
1246+ ssh_gssapi_delete_ctx(&ctx);
1247+
1248+ return (res);
1249+}
1250+
1251 /* Unprivileged */
1252 void
1253 ssh_gssapi_supported_oids(gss_OID_set *oidset)
1254@@ -150,7 +177,9 @@ ssh_gssapi_supported_oids(gss_OID_set *oidset)
1255 gss_OID_set supported;
1256
1257 gss_create_empty_oid_set(&min_status, oidset);
1258- gss_indicate_mechs(&min_status, &supported);
1259+
1260+ if (GSS_ERROR(gss_indicate_mechs(&min_status, &supported)))
1261+ return;
1262
1263 while (supported_mechs[i]->name != NULL) {
1264 if (GSS_ERROR(gss_test_oid_set_member(&min_status,
1265@@ -276,8 +305,48 @@ OM_uint32
1266 ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1267 {
1268 int i = 0;
1269+ int equal = 0;
1270+ gss_name_t new_name = GSS_C_NO_NAME;
1271+ gss_buffer_desc ename = GSS_C_EMPTY_BUFFER;
1272+
1273+ if (options.gss_store_rekey && client->used && ctx->client_creds) {
1274+ if (client->mech->oid.length != ctx->oid->length ||
1275+ (memcmp(client->mech->oid.elements,
1276+ ctx->oid->elements, ctx->oid->length) !=0)) {
1277+ debug("Rekeyed credentials have different mechanism");
1278+ return GSS_S_COMPLETE;
1279+ }
1280+
1281+ if ((ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
1282+ ctx->client_creds, ctx->oid, &new_name,
1283+ NULL, NULL, NULL))) {
1284+ ssh_gssapi_error(ctx);
1285+ return (ctx->major);
1286+ }
1287+
1288+ ctx->major = gss_compare_name(&ctx->minor, client->name,
1289+ new_name, &equal);
1290+
1291+ if (GSS_ERROR(ctx->major)) {
1292+ ssh_gssapi_error(ctx);
1293+ return (ctx->major);
1294+ }
1295+
1296+ if (!equal) {
1297+ debug("Rekeyed credentials have different name");
1298+ return GSS_S_COMPLETE;
1299+ }
1300
1301- gss_buffer_desc ename;
1302+ debug("Marking rekeyed credentials for export");
1303+
1304+ gss_release_name(&ctx->minor, &client->name);
1305+ gss_release_cred(&ctx->minor, &client->creds);
1306+ client->name = new_name;
1307+ client->creds = ctx->client_creds;
1308+ ctx->client_creds = GSS_C_NO_CREDENTIAL;
1309+ client->updated = 1;
1310+ return GSS_S_COMPLETE;
1311+ }
1312
1313 client->mech = NULL;
1314
1315@@ -292,6 +361,13 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1316 if (client->mech == NULL)
1317 return GSS_S_FAILURE;
1318
1319+ if (ctx->client_creds &&
1320+ (ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
1321+ ctx->client_creds, ctx->oid, &client->name, NULL, NULL, NULL))) {
1322+ ssh_gssapi_error(ctx);
1323+ return (ctx->major);
1324+ }
1325+
1326 if ((ctx->major = gss_display_name(&ctx->minor, ctx->client,
1327 &client->displayname, NULL))) {
1328 ssh_gssapi_error(ctx);
1329@@ -309,6 +385,8 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1330 return (ctx->major);
1331 }
1332
1333+ gss_release_buffer(&ctx->minor, &ename);
1334+
1335 /* We can't copy this structure, so we just move the pointer to it */
1336 client->creds = ctx->client_creds;
1337 ctx->client_creds = GSS_C_NO_CREDENTIAL;
1338@@ -356,7 +434,7 @@ ssh_gssapi_do_child(char ***envp, u_int *envsizep)
1339
1340 /* Privileged */
1341 int
1342-ssh_gssapi_userok(char *user)
1343+ssh_gssapi_userok(char *user, struct passwd *pw)
1344 {
1345 OM_uint32 lmin;
1346
1347@@ -366,9 +444,11 @@ ssh_gssapi_userok(char *user)
1348 return 0;
1349 }
1350 if (gssapi_client.mech && gssapi_client.mech->userok)
1351- if ((*gssapi_client.mech->userok)(&gssapi_client, user))
1352+ if ((*gssapi_client.mech->userok)(&gssapi_client, user)) {
1353+ gssapi_client.used = 1;
1354+ gssapi_client.store.owner = pw;
1355 return 1;
1356- else {
1357+ } else {
1358 /* Destroy delegated credentials if userok fails */
1359 gss_release_buffer(&lmin, &gssapi_client.displayname);
1360 gss_release_buffer(&lmin, &gssapi_client.exportedname);
1361@@ -382,14 +462,90 @@ ssh_gssapi_userok(char *user)
1362 return (0);
1363 }
1364
1365-/* Privileged */
1366-OM_uint32
1367-ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
1368+/* These bits are only used for rekeying. The unpriviledged child is running
1369+ * as the user, the monitor is root.
1370+ *
1371+ * In the child, we want to :
1372+ * *) Ask the monitor to store our credentials into the store we specify
1373+ * *) If it succeeds, maybe do a PAM update
1374+ */
1375+
1376+/* Stuff for PAM */
1377+
1378+#ifdef USE_PAM
1379+static int ssh_gssapi_simple_conv(int n, const struct pam_message **msg,
1380+ struct pam_response **resp, void *data)
1381 {
1382- ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
1383- gssbuf, gssmic, NULL);
1384+ return (PAM_CONV_ERR);
1385+}
1386+#endif
1387
1388- return (ctx->major);
1389+void
1390+ssh_gssapi_rekey_creds(void) {
1391+ int ok;
1392+ int ret;
1393+#ifdef USE_PAM
1394+ pam_handle_t *pamh = NULL;
1395+ struct pam_conv pamconv = {ssh_gssapi_simple_conv, NULL};
1396+ char *envstr;
1397+#endif
1398+
1399+ if (gssapi_client.store.filename == NULL &&
1400+ gssapi_client.store.envval == NULL &&
1401+ gssapi_client.store.envvar == NULL)
1402+ return;
1403+
1404+ ok = PRIVSEP(ssh_gssapi_update_creds(&gssapi_client.store));
1405+
1406+ if (!ok)
1407+ return;
1408+
1409+ debug("Rekeyed credentials stored successfully");
1410+
1411+ /* Actually managing to play with the ssh pam stack from here will
1412+ * be next to impossible. In any case, we may want different options
1413+ * for rekeying. So, use our own :)
1414+ */
1415+#ifdef USE_PAM
1416+ if (!use_privsep) {
1417+ debug("Not even going to try and do PAM with privsep disabled");
1418+ return;
1419+ }
1420+
1421+ ret = pam_start("sshd-rekey", gssapi_client.store.owner->pw_name,
1422+ &pamconv, &pamh);
1423+ if (ret)
1424+ return;
1425+
1426+ xasprintf(&envstr, "%s=%s", gssapi_client.store.envvar,
1427+ gssapi_client.store.envval);
1428+
1429+ ret = pam_putenv(pamh, envstr);
1430+ if (!ret)
1431+ pam_setcred(pamh, PAM_REINITIALIZE_CRED);
1432+ pam_end(pamh, PAM_SUCCESS);
1433+#endif
1434+}
1435+
1436+int
1437+ssh_gssapi_update_creds(ssh_gssapi_ccache *store) {
1438+ int ok = 0;
1439+
1440+ /* Check we've got credentials to store */
1441+ if (!gssapi_client.updated)
1442+ return 0;
1443+
1444+ gssapi_client.updated = 0;
1445+
1446+ temporarily_use_uid(gssapi_client.store.owner);
1447+ if (gssapi_client.mech && gssapi_client.mech->updatecreds)
1448+ ok = (*gssapi_client.mech->updatecreds)(store, &gssapi_client);
1449+ else
1450+ debug("No update function for this mechanism");
1451+
1452+ restore_uid();
1453+
1454+ return ok;
1455 }
1456
1457 /* Privileged */
1458diff --git a/kex.c b/kex.c
1459index 25f9f66f6..fb5bfaea5 100644
1460--- a/kex.c
1461+++ b/kex.c
1462@@ -54,6 +54,10 @@
1463 #include "sshbuf.h"
1464 #include "digest.h"
1465
1466+#ifdef GSSAPI
1467+#include "ssh-gss.h"
1468+#endif
1469+
1470 /* prototype */
1471 static int kex_choose_conf(struct ssh *);
1472 static int kex_input_newkeys(int, u_int32_t, struct ssh *);
1473@@ -105,6 +109,14 @@ static const struct kexalg kexalgs[] = {
1474 #endif /* HAVE_EVP_SHA256 || !WITH_OPENSSL */
1475 { NULL, -1, -1, -1},
1476 };
1477+static const struct kexalg kexalg_prefixes[] = {
1478+#ifdef GSSAPI
1479+ { KEX_GSS_GEX_SHA1_ID, KEX_GSS_GEX_SHA1, 0, SSH_DIGEST_SHA1 },
1480+ { KEX_GSS_GRP1_SHA1_ID, KEX_GSS_GRP1_SHA1, 0, SSH_DIGEST_SHA1 },
1481+ { KEX_GSS_GRP14_SHA1_ID, KEX_GSS_GRP14_SHA1, 0, SSH_DIGEST_SHA1 },
1482+#endif
1483+ { NULL, -1, -1, -1 },
1484+};
1485
1486 char *
1487 kex_alg_list(char sep)
1488@@ -137,6 +149,10 @@ kex_alg_by_name(const char *name)
1489 if (strcmp(k->name, name) == 0)
1490 return k;
1491 }
1492+ for (k = kexalg_prefixes; k->name != NULL; k++) {
1493+ if (strncmp(k->name, name, strlen(k->name)) == 0)
1494+ return k;
1495+ }
1496 return NULL;
1497 }
1498
1499@@ -653,6 +669,9 @@ kex_free(struct kex *kex)
1500 sshbuf_free(kex->peer);
1501 sshbuf_free(kex->my);
1502 free(kex->session_id);
1503+#ifdef GSSAPI
1504+ free(kex->gss_host);
1505+#endif /* GSSAPI */
1506 free(kex->client_version_string);
1507 free(kex->server_version_string);
1508 free(kex->failed_choice);
1509diff --git a/kex.h b/kex.h
1510index 593de1208..4e5ead839 100644
1511--- a/kex.h
1512+++ b/kex.h
1513@@ -100,6 +100,9 @@ enum kex_exchange {
1514 KEX_DH_GEX_SHA256,
1515 KEX_ECDH_SHA2,
1516 KEX_C25519_SHA256,
1517+ KEX_GSS_GRP1_SHA1,
1518+ KEX_GSS_GRP14_SHA1,
1519+ KEX_GSS_GEX_SHA1,
1520 KEX_MAX
1521 };
1522
1523@@ -148,6 +151,12 @@ struct kex {
1524 u_int flags;
1525 int hash_alg;
1526 int ec_nid;
1527+#ifdef GSSAPI
1528+ int gss_deleg_creds;
1529+ int gss_trust_dns;
1530+ char *gss_host;
1531+ char *gss_client;
1532+#endif
1533 char *client_version_string;
1534 char *server_version_string;
1535 char *failed_choice;
1536@@ -198,6 +207,11 @@ int kexecdh_server(struct ssh *);
1537 int kexc25519_client(struct ssh *);
1538 int kexc25519_server(struct ssh *);
1539
1540+#ifdef GSSAPI
1541+int kexgss_client(struct ssh *);
1542+int kexgss_server(struct ssh *);
1543+#endif
1544+
1545 int kex_dh_hash(int, const char *, const char *,
1546 const u_char *, size_t, const u_char *, size_t, const u_char *, size_t,
1547 const BIGNUM *, const BIGNUM *, const BIGNUM *, u_char *, size_t *);
1548diff --git a/kexgssc.c b/kexgssc.c
1549new file mode 100644
1550index 000000000..3c8ae08dd
1551--- /dev/null
1552+++ b/kexgssc.c
1553@@ -0,0 +1,341 @@
1554+/*
1555+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1556+ *
1557+ * Redistribution and use in source and binary forms, with or without
1558+ * modification, are permitted provided that the following conditions
1559+ * are met:
1560+ * 1. Redistributions of source code must retain the above copyright
1561+ * notice, this list of conditions and the following disclaimer.
1562+ * 2. Redistributions in binary form must reproduce the above copyright
1563+ * notice, this list of conditions and the following disclaimer in the
1564+ * documentation and/or other materials provided with the distribution.
1565+ *
1566+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1567+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1568+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1569+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1570+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1571+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1572+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1573+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1574+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1575+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1576+ */
1577+
1578+#include "includes.h"
1579+
1580+#ifdef GSSAPI
1581+
1582+#include "includes.h"
1583+
1584+#include <openssl/crypto.h>
1585+#include <openssl/bn.h>
1586+
1587+#include <string.h>
1588+
1589+#include "xmalloc.h"
1590+#include "sshbuf.h"
1591+#include "ssh2.h"
1592+#include "sshkey.h"
1593+#include "cipher.h"
1594+#include "kex.h"
1595+#include "log.h"
1596+#include "packet.h"
1597+#include "dh.h"
1598+#include "digest.h"
1599+
1600+#include "ssh-gss.h"
1601+
1602+int
1603+kexgss_client(struct ssh *ssh) {
1604+ gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
1605+ gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
1606+ Gssctxt *ctxt;
1607+ OM_uint32 maj_status, min_status, ret_flags;
1608+ u_int klen, kout, slen = 0, strlen;
1609+ DH *dh;
1610+ BIGNUM *dh_server_pub = NULL;
1611+ BIGNUM *shared_secret = NULL;
1612+ const BIGNUM *pub_key, *dh_p, *dh_g;
1613+ BIGNUM *p = NULL;
1614+ BIGNUM *g = NULL;
1615+ u_char *kbuf;
1616+ u_char *serverhostkey = NULL;
1617+ u_char *empty = "";
1618+ char *msg;
1619+ int type = 0;
1620+ int first = 1;
1621+ int nbits = 0, min = DH_GRP_MIN, max = DH_GRP_MAX;
1622+ u_char hash[SSH_DIGEST_MAX_LENGTH];
1623+ size_t hashlen;
1624+
1625+ /* Initialise our GSSAPI world */
1626+ ssh_gssapi_build_ctx(&ctxt);
1627+ if (ssh_gssapi_id_kex(ctxt, ssh->kex->name, ssh->kex->kex_type)
1628+ == GSS_C_NO_OID)
1629+ fatal("Couldn't identify host exchange");
1630+
1631+ if (ssh_gssapi_import_name(ctxt, ssh->kex->gss_host))
1632+ fatal("Couldn't import hostname");
1633+
1634+ if (ssh->kex->gss_client &&
1635+ ssh_gssapi_client_identity(ctxt, ssh->kex->gss_client))
1636+ fatal("Couldn't acquire client credentials");
1637+
1638+ switch (ssh->kex->kex_type) {
1639+ case KEX_GSS_GRP1_SHA1:
1640+ dh = dh_new_group1();
1641+ break;
1642+ case KEX_GSS_GRP14_SHA1:
1643+ dh = dh_new_group14();
1644+ break;
1645+ case KEX_GSS_GEX_SHA1:
1646+ debug("Doing group exchange\n");
1647+ nbits = dh_estimate(ssh->kex->we_need * 8);
1648+ packet_start(SSH2_MSG_KEXGSS_GROUPREQ);
1649+ packet_put_int(min);
1650+ packet_put_int(nbits);
1651+ packet_put_int(max);
1652+
1653+ packet_send();
1654+
1655+ packet_read_expect(SSH2_MSG_KEXGSS_GROUP);
1656+
1657+ if ((p = BN_new()) == NULL)
1658+ fatal("BN_new() failed");
1659+ packet_get_bignum2(p);
1660+ if ((g = BN_new()) == NULL)
1661+ fatal("BN_new() failed");
1662+ packet_get_bignum2(g);
1663+ packet_check_eom();
1664+
1665+ if (BN_num_bits(p) < min || BN_num_bits(p) > max)
1666+ fatal("GSSGRP_GEX group out of range: %d !< %d !< %d",
1667+ min, BN_num_bits(p), max);
1668+
1669+ dh = dh_new_group(g, p);
1670+ break;
1671+ default:
1672+ fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type);
1673+ }
1674+
1675+ /* Step 1 - e is dh->pub_key */
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);
1679+
1680+ /* This is f, we initialise it now to make life easier */
1681+ dh_server_pub = BN_new();
1682+ if (dh_server_pub == NULL)
1683+ fatal("dh_server_pub == NULL");
1684+
1685+ token_ptr = GSS_C_NO_BUFFER;
1686+
1687+ do {
1688+ debug("Calling gss_init_sec_context");
1689+
1690+ maj_status = ssh_gssapi_init_ctx(ctxt,
1691+ ssh->kex->gss_deleg_creds, token_ptr, &send_tok,
1692+ &ret_flags);
1693+
1694+ if (GSS_ERROR(maj_status)) {
1695+ if (send_tok.length != 0) {
1696+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1697+ packet_put_string(send_tok.value,
1698+ send_tok.length);
1699+ }
1700+ fatal("gss_init_context failed");
1701+ }
1702+
1703+ /* If we've got an old receive buffer get rid of it */
1704+ if (token_ptr != GSS_C_NO_BUFFER)
1705+ free(recv_tok.value);
1706+
1707+ if (maj_status == GSS_S_COMPLETE) {
1708+ /* If mutual state flag is not true, kex fails */
1709+ if (!(ret_flags & GSS_C_MUTUAL_FLAG))
1710+ fatal("Mutual authentication failed");
1711+
1712+ /* If integ avail flag is not true kex fails */
1713+ if (!(ret_flags & GSS_C_INTEG_FLAG))
1714+ fatal("Integrity check failed");
1715+ }
1716+
1717+ /*
1718+ * If we have data to send, then the last message that we
1719+ * received cannot have been a 'complete'.
1720+ */
1721+ if (send_tok.length != 0) {
1722+ if (first) {
1723+ packet_start(SSH2_MSG_KEXGSS_INIT);
1724+ packet_put_string(send_tok.value,
1725+ send_tok.length);
1726+ packet_put_bignum2(pub_key);
1727+ first = 0;
1728+ } else {
1729+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1730+ packet_put_string(send_tok.value,
1731+ send_tok.length);
1732+ }
1733+ packet_send();
1734+ gss_release_buffer(&min_status, &send_tok);
1735+
1736+ /* If we've sent them data, they should reply */
1737+ do {
1738+ type = packet_read();
1739+ if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
1740+ debug("Received KEXGSS_HOSTKEY");
1741+ if (serverhostkey)
1742+ fatal("Server host key received more than once");
1743+ serverhostkey =
1744+ packet_get_string(&slen);
1745+ }
1746+ } while (type == SSH2_MSG_KEXGSS_HOSTKEY);
1747+
1748+ switch (type) {
1749+ case SSH2_MSG_KEXGSS_CONTINUE:
1750+ debug("Received GSSAPI_CONTINUE");
1751+ if (maj_status == GSS_S_COMPLETE)
1752+ fatal("GSSAPI Continue received from server when complete");
1753+ recv_tok.value = packet_get_string(&strlen);
1754+ recv_tok.length = strlen;
1755+ break;
1756+ case SSH2_MSG_KEXGSS_COMPLETE:
1757+ debug("Received GSSAPI_COMPLETE");
1758+ packet_get_bignum2(dh_server_pub);
1759+ msg_tok.value = packet_get_string(&strlen);
1760+ msg_tok.length = strlen;
1761+
1762+ /* Is there a token included? */
1763+ if (packet_get_char()) {
1764+ recv_tok.value=
1765+ packet_get_string(&strlen);
1766+ recv_tok.length = strlen;
1767+ /* If we're already complete - protocol error */
1768+ if (maj_status == GSS_S_COMPLETE)
1769+ packet_disconnect("Protocol error: received token when complete");
1770+ } else {
1771+ /* No token included */
1772+ if (maj_status != GSS_S_COMPLETE)
1773+ packet_disconnect("Protocol error: did not receive final token");
1774+ }
1775+ break;
1776+ case SSH2_MSG_KEXGSS_ERROR:
1777+ debug("Received Error");
1778+ maj_status = packet_get_int();
1779+ min_status = packet_get_int();
1780+ msg = packet_get_string(NULL);
1781+ (void) packet_get_string_ptr(NULL);
1782+ fatal("GSSAPI Error: \n%.400s",msg);
1783+ default:
1784+ packet_disconnect("Protocol error: didn't expect packet type %d",
1785+ type);
1786+ }
1787+ token_ptr = &recv_tok;
1788+ } else {
1789+ /* No data, and not complete */
1790+ if (maj_status != GSS_S_COMPLETE)
1791+ fatal("Not complete, and no token output");
1792+ }
1793+ } while (maj_status & GSS_S_CONTINUE_NEEDED);
1794+
1795+ /*
1796+ * We _must_ have received a COMPLETE message in reply from the
1797+ * server, which will have set dh_server_pub and msg_tok
1798+ */
1799+
1800+ if (type != SSH2_MSG_KEXGSS_COMPLETE)
1801+ fatal("Didn't receive a SSH2_MSG_KEXGSS_COMPLETE when I expected it");
1802+
1803+ /* Check f in range [1, p-1] */
1804+ if (!dh_pub_is_valid(dh, dh_server_pub))
1805+ packet_disconnect("bad server public DH value");
1806+
1807+ /* compute K=f^x mod p */
1808+ klen = DH_size(dh);
1809+ kbuf = xmalloc(klen);
1810+ kout = DH_compute_key(kbuf, dh_server_pub, dh);
1811+ if (kout < 0)
1812+ fatal("DH_compute_key: failed");
1813+
1814+ shared_secret = BN_new();
1815+ if (shared_secret == NULL)
1816+ fatal("kexgss_client: BN_new failed");
1817+
1818+ if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
1819+ fatal("kexdh_client: BN_bin2bn failed");
1820+
1821+ memset(kbuf, 0, klen);
1822+ free(kbuf);
1823+
1824+ hashlen = sizeof(hash);
1825+ switch (ssh->kex->kex_type) {
1826+ case KEX_GSS_GRP1_SHA1:
1827+ case KEX_GSS_GRP14_SHA1:
1828+ kex_dh_hash(
1829+ ssh->kex->hash_alg,
1830+ ssh->kex->client_version_string,
1831+ ssh->kex->server_version_string,
1832+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
1833+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
1834+ (serverhostkey ? serverhostkey : empty), slen,
1835+ pub_key, /* e */
1836+ dh_server_pub, /* f */
1837+ shared_secret, /* K */
1838+ hash, &hashlen
1839+ );
1840+ break;
1841+ case KEX_GSS_GEX_SHA1:
1842+ kexgex_hash(
1843+ ssh->kex->hash_alg,
1844+ ssh->kex->client_version_string,
1845+ ssh->kex->server_version_string,
1846+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
1847+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
1848+ (serverhostkey ? serverhostkey : empty), slen,
1849+ min, nbits, max,
1850+ dh_p, dh_g,
1851+ pub_key,
1852+ dh_server_pub,
1853+ shared_secret,
1854+ hash, &hashlen
1855+ );
1856+ break;
1857+ default:
1858+ fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type);
1859+ }
1860+
1861+ gssbuf.value = hash;
1862+ gssbuf.length = hashlen;
1863+
1864+ /* Verify that the hash matches the MIC we just got. */
1865+ if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
1866+ packet_disconnect("Hash's MIC didn't verify");
1867+
1868+ free(msg_tok.value);
1869+
1870+ DH_free(dh);
1871+ free(serverhostkey);
1872+ BN_clear_free(dh_server_pub);
1873+
1874+ /* save session id */
1875+ if (ssh->kex->session_id == NULL) {
1876+ ssh->kex->session_id_len = hashlen;
1877+ ssh->kex->session_id = xmalloc(ssh->kex->session_id_len);
1878+ memcpy(ssh->kex->session_id, hash, ssh->kex->session_id_len);
1879+ }
1880+
1881+ if (ssh->kex->gss_deleg_creds)
1882+ ssh_gssapi_credentials_updated(ctxt);
1883+
1884+ if (gss_kex_context == NULL)
1885+ gss_kex_context = ctxt;
1886+ else
1887+ ssh_gssapi_delete_ctx(&ctxt);
1888+
1889+ kex_derive_keys_bn(ssh, hash, hashlen, shared_secret);
1890+ BN_clear_free(shared_secret);
1891+ return kex_send_newkeys(ssh);
1892+}
1893+
1894+#endif /* GSSAPI */
1895diff --git a/kexgsss.c b/kexgsss.c
1896new file mode 100644
1897index 000000000..18070f1d7
1898--- /dev/null
1899+++ b/kexgsss.c
1900@@ -0,0 +1,300 @@
1901+/*
1902+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1903+ *
1904+ * Redistribution and use in source and binary forms, with or without
1905+ * modification, are permitted provided that the following conditions
1906+ * are met:
1907+ * 1. Redistributions of source code must retain the above copyright
1908+ * notice, this list of conditions and the following disclaimer.
1909+ * 2. Redistributions in binary form must reproduce the above copyright
1910+ * notice, this list of conditions and the following disclaimer in the
1911+ * documentation and/or other materials provided with the distribution.
1912+ *
1913+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1914+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1915+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1916+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1917+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1918+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1919+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1920+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1921+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1922+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1923+ */
1924+
1925+#include "includes.h"
1926+
1927+#ifdef GSSAPI
1928+
1929+#include <string.h>
1930+
1931+#include <openssl/crypto.h>
1932+#include <openssl/bn.h>
1933+
1934+#include "xmalloc.h"
1935+#include "sshbuf.h"
1936+#include "ssh2.h"
1937+#include "sshkey.h"
1938+#include "cipher.h"
1939+#include "kex.h"
1940+#include "log.h"
1941+#include "packet.h"
1942+#include "dh.h"
1943+#include "ssh-gss.h"
1944+#include "monitor_wrap.h"
1945+#include "misc.h"
1946+#include "servconf.h"
1947+#include "digest.h"
1948+
1949+extern ServerOptions options;
1950+
1951+int
1952+kexgss_server(struct ssh *ssh)
1953+{
1954+ OM_uint32 maj_status, min_status;
1955+
1956+ /*
1957+ * Some GSSAPI implementations use the input value of ret_flags (an
1958+ * output variable) as a means of triggering mechanism specific
1959+ * features. Initializing it to zero avoids inadvertently
1960+ * activating this non-standard behaviour.
1961+ */
1962+
1963+ OM_uint32 ret_flags = 0;
1964+ gss_buffer_desc gssbuf, recv_tok, msg_tok;
1965+ gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
1966+ Gssctxt *ctxt = NULL;
1967+ u_int slen, klen, kout;
1968+ u_char *kbuf;
1969+ DH *dh;
1970+ int min = -1, max = -1, nbits = -1;
1971+ const BIGNUM *pub_key, *dh_p, *dh_g;
1972+ BIGNUM *shared_secret = NULL;
1973+ BIGNUM *dh_client_pub = NULL;
1974+ int type = 0;
1975+ gss_OID oid;
1976+ char *mechs;
1977+ u_char hash[SSH_DIGEST_MAX_LENGTH];
1978+ size_t hashlen;
1979+
1980+ /* Initialise GSSAPI */
1981+
1982+ /* If we're rekeying, privsep means that some of the private structures
1983+ * in the GSSAPI code are no longer available. This kludges them back
1984+ * into life
1985+ */
1986+ if (!ssh_gssapi_oid_table_ok()) {
1987+ mechs = ssh_gssapi_server_mechanisms();
1988+ free(mechs);
1989+ }
1990+
1991+ debug2("%s: Identifying %s", __func__, ssh->kex->name);
1992+ oid = ssh_gssapi_id_kex(NULL, ssh->kex->name, ssh->kex->kex_type);
1993+ if (oid == GSS_C_NO_OID)
1994+ fatal("Unknown gssapi mechanism");
1995+
1996+ debug2("%s: Acquiring credentials", __func__);
1997+
1998+ if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid))))
1999+ fatal("Unable to acquire credentials for the server");
2000+
2001+ switch (ssh->kex->kex_type) {
2002+ case KEX_GSS_GRP1_SHA1:
2003+ dh = dh_new_group1();
2004+ break;
2005+ case KEX_GSS_GRP14_SHA1:
2006+ dh = dh_new_group14();
2007+ break;
2008+ case KEX_GSS_GEX_SHA1:
2009+ debug("Doing group exchange");
2010+ packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ);
2011+ min = packet_get_int();
2012+ nbits = packet_get_int();
2013+ max = packet_get_int();
2014+ packet_check_eom();
2015+ if (max < min || nbits < min || max < nbits)
2016+ fatal("GSS_GEX, bad parameters: %d !< %d !< %d",
2017+ min, nbits, max);
2018+ dh = PRIVSEP(choose_dh(MAX(DH_GRP_MIN, min),
2019+ nbits, MIN(DH_GRP_MAX, max)));
2020+ if (dh == NULL)
2021+ packet_disconnect("Protocol error: no matching group found");
2022+ DH_get0_pqg(dh, &dh_p, NULL, &dh_g);
2023+
2024+ packet_start(SSH2_MSG_KEXGSS_GROUP);
2025+ packet_put_bignum2(dh_p);
2026+ packet_put_bignum2(dh_g);
2027+ packet_send();
2028+
2029+ packet_write_wait();
2030+ break;
2031+ default:
2032+ fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type);
2033+ }
2034+
2035+ dh_gen_key(dh, ssh->kex->we_need * 8);
2036+
2037+ do {
2038+ debug("Wait SSH2_MSG_GSSAPI_INIT");
2039+ type = packet_read();
2040+ switch(type) {
2041+ case SSH2_MSG_KEXGSS_INIT:
2042+ if (dh_client_pub != NULL)
2043+ fatal("Received KEXGSS_INIT after initialising");
2044+ recv_tok.value = packet_get_string(&slen);
2045+ recv_tok.length = slen;
2046+
2047+ if ((dh_client_pub = BN_new()) == NULL)
2048+ fatal("dh_client_pub == NULL");
2049+
2050+ packet_get_bignum2(dh_client_pub);
2051+
2052+ /* Send SSH_MSG_KEXGSS_HOSTKEY here, if we want */
2053+ break;
2054+ case SSH2_MSG_KEXGSS_CONTINUE:
2055+ recv_tok.value = packet_get_string(&slen);
2056+ recv_tok.length = slen;
2057+ break;
2058+ default:
2059+ packet_disconnect(
2060+ "Protocol error: didn't expect packet type %d",
2061+ type);
2062+ }
2063+
2064+ maj_status = PRIVSEP(ssh_gssapi_accept_ctx(ctxt, &recv_tok,
2065+ &send_tok, &ret_flags));
2066+
2067+ free(recv_tok.value);
2068+
2069+ if (maj_status != GSS_S_COMPLETE && send_tok.length == 0)
2070+ fatal("Zero length token output when incomplete");
2071+
2072+ if (dh_client_pub == NULL)
2073+ fatal("No client public key");
2074+
2075+ if (maj_status & GSS_S_CONTINUE_NEEDED) {
2076+ debug("Sending GSSAPI_CONTINUE");
2077+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
2078+ packet_put_string(send_tok.value, send_tok.length);
2079+ packet_send();
2080+ gss_release_buffer(&min_status, &send_tok);
2081+ }
2082+ } while (maj_status & GSS_S_CONTINUE_NEEDED);
2083+
2084+ if (GSS_ERROR(maj_status)) {
2085+ if (send_tok.length > 0) {
2086+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
2087+ packet_put_string(send_tok.value, send_tok.length);
2088+ packet_send();
2089+ }
2090+ fatal("accept_ctx died");
2091+ }
2092+
2093+ if (!(ret_flags & GSS_C_MUTUAL_FLAG))
2094+ fatal("Mutual Authentication flag wasn't set");
2095+
2096+ if (!(ret_flags & GSS_C_INTEG_FLAG))
2097+ fatal("Integrity flag wasn't set");
2098+
2099+ if (!dh_pub_is_valid(dh, dh_client_pub))
2100+ packet_disconnect("bad client public DH value");
2101+
2102+ klen = DH_size(dh);
2103+ kbuf = xmalloc(klen);
2104+ kout = DH_compute_key(kbuf, dh_client_pub, dh);
2105+ if (kout < 0)
2106+ fatal("DH_compute_key: failed");
2107+
2108+ shared_secret = BN_new();
2109+ if (shared_secret == NULL)
2110+ fatal("kexgss_server: BN_new failed");
2111+
2112+ if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
2113+ fatal("kexgss_server: BN_bin2bn failed");
2114+
2115+ memset(kbuf, 0, klen);
2116+ free(kbuf);
2117+
2118+ DH_get0_key(dh, &pub_key, NULL);
2119+ DH_get0_pqg(dh, &dh_p, NULL, &dh_g);
2120+
2121+ hashlen = sizeof(hash);
2122+ switch (ssh->kex->kex_type) {
2123+ case KEX_GSS_GRP1_SHA1:
2124+ case KEX_GSS_GRP14_SHA1:
2125+ kex_dh_hash(
2126+ ssh->kex->hash_alg,
2127+ ssh->kex->client_version_string, ssh->kex->server_version_string,
2128+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
2129+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
2130+ NULL, 0, /* Change this if we start sending host keys */
2131+ dh_client_pub, pub_key, shared_secret,
2132+ hash, &hashlen
2133+ );
2134+ break;
2135+ case KEX_GSS_GEX_SHA1:
2136+ kexgex_hash(
2137+ ssh->kex->hash_alg,
2138+ ssh->kex->client_version_string, ssh->kex->server_version_string,
2139+ sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
2140+ sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
2141+ NULL, 0,
2142+ min, nbits, max,
2143+ dh_p, dh_g,
2144+ dh_client_pub,
2145+ pub_key,
2146+ shared_secret,
2147+ hash, &hashlen
2148+ );
2149+ break;
2150+ default:
2151+ fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type);
2152+ }
2153+
2154+ BN_clear_free(dh_client_pub);
2155+
2156+ if (ssh->kex->session_id == NULL) {
2157+ ssh->kex->session_id_len = hashlen;
2158+ ssh->kex->session_id = xmalloc(ssh->kex->session_id_len);
2159+ memcpy(ssh->kex->session_id, hash, ssh->kex->session_id_len);
2160+ }
2161+
2162+ gssbuf.value = hash;
2163+ gssbuf.length = hashlen;
2164+
2165+ if (GSS_ERROR(PRIVSEP(ssh_gssapi_sign(ctxt,&gssbuf,&msg_tok))))
2166+ fatal("Couldn't get MIC");
2167+
2168+ packet_start(SSH2_MSG_KEXGSS_COMPLETE);
2169+ packet_put_bignum2(pub_key);
2170+ packet_put_string(msg_tok.value,msg_tok.length);
2171+
2172+ if (send_tok.length != 0) {
2173+ packet_put_char(1); /* true */
2174+ packet_put_string(send_tok.value, send_tok.length);
2175+ } else {
2176+ packet_put_char(0); /* false */
2177+ }
2178+ packet_send();
2179+
2180+ gss_release_buffer(&min_status, &send_tok);
2181+ gss_release_buffer(&min_status, &msg_tok);
2182+
2183+ if (gss_kex_context == NULL)
2184+ gss_kex_context = ctxt;
2185+ else
2186+ ssh_gssapi_delete_ctx(&ctxt);
2187+
2188+ DH_free(dh);
2189+
2190+ kex_derive_keys_bn(ssh, hash, hashlen, shared_secret);
2191+ BN_clear_free(shared_secret);
2192+ kex_send_newkeys(ssh);
2193+
2194+ /* If this was a rekey, then save out any delegated credentials we
2195+ * just exchanged. */
2196+ if (options.gss_store_rekey)
2197+ ssh_gssapi_rekey_creds();
2198+ return 0;
2199+}
2200+#endif /* GSSAPI */
2201diff --git a/monitor.c b/monitor.c
2202index 531b2993a..eabc1e89b 100644
2203--- a/monitor.c
2204+++ b/monitor.c
2205@@ -145,6 +145,8 @@ int mm_answer_gss_setup_ctx(int, struct sshbuf *);
2206 int mm_answer_gss_accept_ctx(int, struct sshbuf *);
2207 int mm_answer_gss_userok(int, struct sshbuf *);
2208 int mm_answer_gss_checkmic(int, struct sshbuf *);
2209+int mm_answer_gss_sign(int, struct sshbuf *);
2210+int mm_answer_gss_updatecreds(int, struct sshbuf *);
2211 #endif
2212
2213 #ifdef SSH_AUDIT_EVENTS
2214@@ -215,11 +217,18 @@ struct mon_table mon_dispatch_proto20[] = {
2215 {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
2216 {MONITOR_REQ_GSSUSEROK, MON_ONCE|MON_AUTHDECIDE, mm_answer_gss_userok},
2217 {MONITOR_REQ_GSSCHECKMIC, MON_ONCE, mm_answer_gss_checkmic},
2218+ {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
2219 #endif
2220 {0, 0, NULL}
2221 };
2222
2223 struct mon_table mon_dispatch_postauth20[] = {
2224+#ifdef GSSAPI
2225+ {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
2226+ {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
2227+ {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
2228+ {MONITOR_REQ_GSSUPCREDS, 0, mm_answer_gss_updatecreds},
2229+#endif
2230 #ifdef WITH_OPENSSL
2231 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
2232 #endif
2233@@ -289,6 +298,10 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
2234 /* Permit requests for moduli and signatures */
2235 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
2236 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
2237+#ifdef GSSAPI
2238+ /* and for the GSSAPI key exchange */
2239+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
2240+#endif
2241
2242 /* The first few requests do not require asynchronous access */
2243 while (!authenticated) {
2244@@ -401,6 +414,10 @@ monitor_child_postauth(struct monitor *pmonitor)
2245 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
2246 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
2247 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
2248+#ifdef GSSAPI
2249+ /* and for the GSSAPI key exchange */
2250+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
2251+#endif
2252
2253 if (auth_opts->permit_pty_flag) {
2254 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
2255@@ -1666,6 +1683,13 @@ monitor_apply_keystate(struct monitor *pmonitor)
2256 # endif
2257 #endif /* WITH_OPENSSL */
2258 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
2259+#ifdef GSSAPI
2260+ if (options.gss_keyex) {
2261+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
2262+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
2263+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
2264+ }
2265+#endif
2266 kex->load_host_public_key=&get_hostkey_public_by_type;
2267 kex->load_host_private_key=&get_hostkey_private_by_type;
2268 kex->host_key_index=&get_hostkey_index;
2269@@ -1756,8 +1780,8 @@ mm_answer_gss_setup_ctx(int sock, struct sshbuf *m)
2270 u_char *p;
2271 int r;
2272
2273- if (!options.gss_authentication)
2274- fatal("%s: GSSAPI authentication not enabled", __func__);
2275+ if (!options.gss_authentication && !options.gss_keyex)
2276+ fatal("%s: GSSAPI not enabled", __func__);
2277
2278 if ((r = sshbuf_get_string(m, &p, &len)) != 0)
2279 fatal("%s: buffer error: %s", __func__, ssh_err(r));
2280@@ -1789,8 +1813,8 @@ mm_answer_gss_accept_ctx(int sock, struct sshbuf *m)
2281 OM_uint32 flags = 0; /* GSI needs this */
2282 int r;
2283
2284- if (!options.gss_authentication)
2285- fatal("%s: GSSAPI authentication not enabled", __func__);
2286+ if (!options.gss_authentication && !options.gss_keyex)
2287+ fatal("%s: GSSAPI not enabled", __func__);
2288
2289 if ((r = ssh_gssapi_get_buffer_desc(m, &in)) != 0)
2290 fatal("%s: buffer error: %s", __func__, ssh_err(r));
2291@@ -1810,6 +1834,7 @@ mm_answer_gss_accept_ctx(int sock, struct sshbuf *m)
2292 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
2293 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
2294 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1);
2295+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1);
2296 }
2297 return (0);
2298 }
2299@@ -1821,8 +1846,8 @@ mm_answer_gss_checkmic(int sock, struct sshbuf *m)
2300 OM_uint32 ret;
2301 int r;
2302
2303- if (!options.gss_authentication)
2304- fatal("%s: GSSAPI authentication not enabled", __func__);
2305+ if (!options.gss_authentication && !options.gss_keyex)
2306+ fatal("%s: GSSAPI not enabled", __func__);
2307
2308 if ((r = ssh_gssapi_get_buffer_desc(m, &gssbuf)) != 0 ||
2309 (r = ssh_gssapi_get_buffer_desc(m, &mic)) != 0)
2310@@ -1851,10 +1876,11 @@ mm_answer_gss_userok(int sock, struct sshbuf *m)
2311 int r, authenticated;
2312 const char *displayname;
2313
2314- if (!options.gss_authentication)
2315- fatal("%s: GSSAPI authentication not enabled", __func__);
2316+ if (!options.gss_authentication && !options.gss_keyex)
2317+ fatal("%s: GSSAPI not enabled", __func__);
2318
2319- authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
2320+ authenticated = authctxt->valid &&
2321+ ssh_gssapi_userok(authctxt->user, authctxt->pw);
2322
2323 sshbuf_reset(m);
2324 if ((r = sshbuf_put_u32(m, authenticated)) != 0)
2325@@ -1871,5 +1897,83 @@ mm_answer_gss_userok(int sock, struct sshbuf *m)
2326 /* Monitor loop will terminate if authenticated */
2327 return (authenticated);
2328 }
2329+
2330+int
2331+mm_answer_gss_sign(int socket, struct sshbuf *m)
2332+{
2333+ gss_buffer_desc data;
2334+ gss_buffer_desc hash = GSS_C_EMPTY_BUFFER;
2335+ OM_uint32 major, minor;
2336+ size_t len;
2337+ u_char *p;
2338+ int r;
2339+
2340+ if (!options.gss_authentication && !options.gss_keyex)
2341+ fatal("%s: GSSAPI not enabled", __func__);
2342+
2343+ if ((r = sshbuf_get_string(m, &p, &len)) != 0)
2344+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
2345+ data.value = p;
2346+ data.length = len;
2347+ if (data.length != 20)
2348+ fatal("%s: data length incorrect: %d", __func__,
2349+ (int) data.length);
2350+
2351+ /* Save the session ID on the first time around */
2352+ if (session_id2_len == 0) {
2353+ session_id2_len = data.length;
2354+ session_id2 = xmalloc(session_id2_len);
2355+ memcpy(session_id2, data.value, session_id2_len);
2356+ }
2357+ major = ssh_gssapi_sign(gsscontext, &data, &hash);
2358+
2359+ free(data.value);
2360+
2361+ sshbuf_reset(m);
2362+ if ((r = sshbuf_put_u32(m, major)) != 0 ||
2363+ (r = sshbuf_put_string(m, hash.value, hash.length)) != 0)
2364+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
2365+
2366+ mm_request_send(socket, MONITOR_ANS_GSSSIGN, m);
2367+
2368+ gss_release_buffer(&minor, &hash);
2369+
2370+ /* Turn on getpwnam permissions */
2371+ monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
2372+
2373+ /* And credential updating, for when rekeying */
2374+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSUPCREDS, 1);
2375+
2376+ return (0);
2377+}
2378+
2379+int
2380+mm_answer_gss_updatecreds(int socket, struct sshbuf *m) {
2381+ ssh_gssapi_ccache store;
2382+ int r, ok;
2383+
2384+ if (!options.gss_authentication && !options.gss_keyex)
2385+ fatal("%s: GSSAPI not enabled", __func__);
2386+
2387+ if ((r = sshbuf_get_cstring(m, &store.filename, NULL)) != 0 ||
2388+ (r = sshbuf_get_cstring(m, &store.envvar, NULL)) != 0 ||
2389+ (r = sshbuf_get_cstring(m, &store.envval, NULL)) != 0)
2390+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
2391+
2392+ ok = ssh_gssapi_update_creds(&store);
2393+
2394+ free(store.filename);
2395+ free(store.envvar);
2396+ free(store.envval);
2397+
2398+ sshbuf_reset(m);
2399+ if ((r = sshbuf_put_u32(m, ok)) != 0)
2400+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
2401+
2402+ mm_request_send(socket, MONITOR_ANS_GSSUPCREDS, m);
2403+
2404+ return(0);
2405+}
2406+
2407 #endif /* GSSAPI */
2408
2409diff --git a/monitor.h b/monitor.h
2410index 16047299f..44fbed589 100644
2411--- a/monitor.h
2412+++ b/monitor.h
2413@@ -63,6 +63,9 @@ enum monitor_reqtype {
2414 MONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111,
2415 MONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113,
2416
2417+ MONITOR_REQ_GSSSIGN = 150, MONITOR_ANS_GSSSIGN = 151,
2418+ MONITOR_REQ_GSSUPCREDS = 152, MONITOR_ANS_GSSUPCREDS = 153,
2419+
2420 };
2421
2422 struct monitor {
2423diff --git a/monitor_wrap.c b/monitor_wrap.c
2424index 732fb3476..1865a122a 100644
2425--- a/monitor_wrap.c
2426+++ b/monitor_wrap.c
2427@@ -984,7 +984,7 @@ mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
2428 }
2429
2430 int
2431-mm_ssh_gssapi_userok(char *user)
2432+mm_ssh_gssapi_userok(char *user, struct passwd *pw)
2433 {
2434 struct sshbuf *m;
2435 int r, authenticated = 0;
2436@@ -1003,4 +1003,55 @@ mm_ssh_gssapi_userok(char *user)
2437 debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
2438 return (authenticated);
2439 }
2440+
2441+OM_uint32
2442+mm_ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_desc *data, gss_buffer_desc *hash)
2443+{
2444+ struct sshbuf *m;
2445+ OM_uint32 major;
2446+ int r;
2447+
2448+ if ((m = sshbuf_new()) == NULL)
2449+ fatal("%s: sshbuf_new failed", __func__);
2450+ if ((r = sshbuf_put_string(m, data->value, data->length)) != 0)
2451+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
2452+
2453+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSIGN, m);
2454+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSIGN, m);
2455+
2456+ if ((r = sshbuf_get_u32(m, &major)) != 0 ||
2457+ (r = ssh_gssapi_get_buffer_desc(m, hash)) != 0)
2458+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
2459+
2460+ sshbuf_free(m);
2461+
2462+ return(major);
2463+}
2464+
2465+int
2466+mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
2467+{
2468+ struct sshbuf *m;
2469+ int r, ok;
2470+
2471+ if ((m = sshbuf_new()) == NULL)
2472+ fatal("%s: sshbuf_new failed", __func__);
2473+ if ((r = sshbuf_put_cstring(m,
2474+ store->filename ? store->filename : "")) != 0 ||
2475+ (r = sshbuf_put_cstring(m,
2476+ store->envvar ? store->envvar : "")) != 0 ||
2477+ (r = sshbuf_put_cstring(m,
2478+ store->envval ? store->envval : "")) != 0)
2479+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
2480+
2481+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUPCREDS, m);
2482+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUPCREDS, m);
2483+
2484+ if ((r = sshbuf_get_u32(m, &ok)) != 0)
2485+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
2486+ sshbuf_free(m);
2487+
2488+ return (ok);
2489+}
2490+
2491 #endif /* GSSAPI */
2492diff --git a/monitor_wrap.h b/monitor_wrap.h
2493index 644da081d..7f93144ff 100644
2494--- a/monitor_wrap.h
2495+++ b/monitor_wrap.h
2496@@ -60,8 +60,10 @@ int mm_sshkey_verify(const struct sshkey *, const u_char *, size_t,
2497 OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
2498 OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *,
2499 gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *);
2500-int mm_ssh_gssapi_userok(char *user);
2501+int mm_ssh_gssapi_userok(char *user, struct passwd *);
2502 OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
2503+OM_uint32 mm_ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
2504+int mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *);
2505 #endif
2506
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);
2534diff --git a/readconf.c b/readconf.c
2535index 433811521..36bc5e59a 100644
2536--- a/readconf.c
2537+++ b/readconf.c
2538@@ -161,6 +161,8 @@ typedef enum {
2539 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
2540 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
2541 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
2542+ oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey,
2543+ oGssServerIdentity,
2544 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
2545 oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist,
2546 oHashKnownHosts,
2547@@ -201,10 +203,20 @@ static struct {
2548 /* Sometimes-unsupported options */
2549 #if defined(GSSAPI)
2550 { "gssapiauthentication", oGssAuthentication },
2551+ { "gssapikeyexchange", oGssKeyEx },
2552 { "gssapidelegatecredentials", oGssDelegateCreds },
2553+ { "gssapitrustdns", oGssTrustDns },
2554+ { "gssapiclientidentity", oGssClientIdentity },
2555+ { "gssapiserveridentity", oGssServerIdentity },
2556+ { "gssapirenewalforcesrekey", oGssRenewalRekey },
2557 # else
2558 { "gssapiauthentication", oUnsupported },
2559+ { "gssapikeyexchange", oUnsupported },
2560 { "gssapidelegatecredentials", oUnsupported },
2561+ { "gssapitrustdns", oUnsupported },
2562+ { "gssapiclientidentity", oUnsupported },
2563+ { "gssapiserveridentity", oUnsupported },
2564+ { "gssapirenewalforcesrekey", oUnsupported },
2565 #endif
2566 #ifdef ENABLE_PKCS11
2567 { "smartcarddevice", oPKCS11Provider },
2568@@ -974,10 +986,30 @@ parse_time:
2569 intptr = &options->gss_authentication;
2570 goto parse_flag;
2571
2572+ case oGssKeyEx:
2573+ intptr = &options->gss_keyex;
2574+ goto parse_flag;
2575+
2576 case oGssDelegateCreds:
2577 intptr = &options->gss_deleg_creds;
2578 goto parse_flag;
2579
2580+ case oGssTrustDns:
2581+ intptr = &options->gss_trust_dns;
2582+ goto parse_flag;
2583+
2584+ case oGssClientIdentity:
2585+ charptr = &options->gss_client_identity;
2586+ goto parse_string;
2587+
2588+ case oGssServerIdentity:
2589+ charptr = &options->gss_server_identity;
2590+ goto parse_string;
2591+
2592+ case oGssRenewalRekey:
2593+ intptr = &options->gss_renewal_rekey;
2594+ goto parse_flag;
2595+
2596 case oBatchMode:
2597 intptr = &options->batch_mode;
2598 goto parse_flag;
2599@@ -1842,7 +1874,12 @@ initialize_options(Options * options)
2600 options->pubkey_authentication = -1;
2601 options->challenge_response_authentication = -1;
2602 options->gss_authentication = -1;
2603+ options->gss_keyex = -1;
2604 options->gss_deleg_creds = -1;
2605+ options->gss_trust_dns = -1;
2606+ options->gss_renewal_rekey = -1;
2607+ options->gss_client_identity = NULL;
2608+ options->gss_server_identity = NULL;
2609 options->password_authentication = -1;
2610 options->kbd_interactive_authentication = -1;
2611 options->kbd_interactive_devices = NULL;
2612@@ -1988,8 +2025,14 @@ fill_default_options(Options * options)
2613 options->challenge_response_authentication = 1;
2614 if (options->gss_authentication == -1)
2615 options->gss_authentication = 0;
2616+ if (options->gss_keyex == -1)
2617+ options->gss_keyex = 0;
2618 if (options->gss_deleg_creds == -1)
2619 options->gss_deleg_creds = 0;
2620+ if (options->gss_trust_dns == -1)
2621+ options->gss_trust_dns = 0;
2622+ if (options->gss_renewal_rekey == -1)
2623+ options->gss_renewal_rekey = 0;
2624 if (options->password_authentication == -1)
2625 options->password_authentication = 1;
2626 if (options->kbd_interactive_authentication == -1)
2627diff --git a/readconf.h b/readconf.h
2628index fc7e38251..8e4900d01 100644
2629--- a/readconf.h
2630+++ b/readconf.h
2631@@ -40,7 +40,12 @@ typedef struct {
2632 int challenge_response_authentication;
2633 /* Try S/Key or TIS, authentication. */
2634 int gss_authentication; /* Try GSS authentication */
2635+ int gss_keyex; /* Try GSS key exchange */
2636 int gss_deleg_creds; /* Delegate GSS credentials */
2637+ int gss_trust_dns; /* Trust DNS for GSS canonicalization */
2638+ int gss_renewal_rekey; /* Credential renewal forces rekey */
2639+ char *gss_client_identity; /* Principal to initiate GSSAPI with */
2640+ char *gss_server_identity; /* GSSAPI target principal */
2641 int password_authentication; /* Try password
2642 * authentication. */
2643 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
2644diff --git a/servconf.c b/servconf.c
2645index 932d363bb..4668b8a45 100644
2646--- a/servconf.c
2647+++ b/servconf.c
2648@@ -124,8 +124,10 @@ initialize_server_options(ServerOptions *options)
2649 options->kerberos_ticket_cleanup = -1;
2650 options->kerberos_get_afs_token = -1;
2651 options->gss_authentication=-1;
2652+ options->gss_keyex = -1;
2653 options->gss_cleanup_creds = -1;
2654 options->gss_strict_acceptor = -1;
2655+ options->gss_store_rekey = -1;
2656 options->password_authentication = -1;
2657 options->kbd_interactive_authentication = -1;
2658 options->challenge_response_authentication = -1;
2659@@ -337,10 +339,14 @@ fill_default_server_options(ServerOptions *options)
2660 options->kerberos_get_afs_token = 0;
2661 if (options->gss_authentication == -1)
2662 options->gss_authentication = 0;
2663+ if (options->gss_keyex == -1)
2664+ options->gss_keyex = 0;
2665 if (options->gss_cleanup_creds == -1)
2666 options->gss_cleanup_creds = 1;
2667 if (options->gss_strict_acceptor == -1)
2668 options->gss_strict_acceptor = 1;
2669+ if (options->gss_store_rekey == -1)
2670+ options->gss_store_rekey = 0;
2671 if (options->password_authentication == -1)
2672 options->password_authentication = 1;
2673 if (options->kbd_interactive_authentication == -1)
2674@@ -485,6 +491,7 @@ typedef enum {
2675 sHostKeyAlgorithms,
2676 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
2677 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
2678+ sGssKeyEx, sGssStoreRekey,
2679 sAcceptEnv, sSetEnv, sPermitTunnel,
2680 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
2681 sUsePrivilegeSeparation, sAllowAgentForwarding,
2682@@ -559,12 +566,20 @@ static struct {
2683 #ifdef GSSAPI
2684 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
2685 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
2686+ { "gssapicleanupcreds", sGssCleanupCreds, SSHCFG_GLOBAL },
2687 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
2688+ { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
2689+ { "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
2690 #else
2691 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
2692 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
2693+ { "gssapicleanupcreds", sUnsupported, SSHCFG_GLOBAL },
2694 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
2695+ { "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
2696+ { "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
2697 #endif
2698+ { "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL },
2699+ { "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL },
2700 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
2701 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
2702 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
2703@@ -1468,6 +1483,10 @@ process_server_config_line(ServerOptions *options, char *line,
2704 intptr = &options->gss_authentication;
2705 goto parse_flag;
2706
2707+ case sGssKeyEx:
2708+ intptr = &options->gss_keyex;
2709+ goto parse_flag;
2710+
2711 case sGssCleanupCreds:
2712 intptr = &options->gss_cleanup_creds;
2713 goto parse_flag;
2714@@ -1476,6 +1495,10 @@ process_server_config_line(ServerOptions *options, char *line,
2715 intptr = &options->gss_strict_acceptor;
2716 goto parse_flag;
2717
2718+ case sGssStoreRekey:
2719+ intptr = &options->gss_store_rekey;
2720+ goto parse_flag;
2721+
2722 case sPasswordAuthentication:
2723 intptr = &options->password_authentication;
2724 goto parse_flag;
2725@@ -2560,7 +2583,10 @@ dump_config(ServerOptions *o)
2726 #endif
2727 #ifdef GSSAPI
2728 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2729+ dump_cfg_fmtint(sGssKeyEx, o->gss_keyex);
2730 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
2731+ dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor);
2732+ dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey);
2733 #endif
2734 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2735 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2736diff --git a/servconf.h b/servconf.h
2737index 0175e00e8..3b76da816 100644
2738--- a/servconf.h
2739+++ b/servconf.h
2740@@ -125,8 +125,10 @@ typedef struct {
2741 int kerberos_get_afs_token; /* If true, try to get AFS token if
2742 * authenticated with Kerberos. */
2743 int gss_authentication; /* If true, permit GSSAPI authentication */
2744+ int gss_keyex; /* If true, permit GSSAPI key exchange */
2745 int gss_cleanup_creds; /* If true, destroy cred cache on logout */
2746 int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */
2747+ int gss_store_rekey;
2748 int password_authentication; /* If true, permit password
2749 * authentication. */
2750 int kbd_interactive_authentication; /* If true, permit */
2751diff --git a/ssh-gss.h b/ssh-gss.h
2752index 36180d07a..350ce7882 100644
2753--- a/ssh-gss.h
2754+++ b/ssh-gss.h
2755@@ -1,6 +1,6 @@
2756 /* $OpenBSD: ssh-gss.h,v 1.14 2018/07/10 09:13:30 djm Exp $ */
2757 /*
2758- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
2759+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
2760 *
2761 * Redistribution and use in source and binary forms, with or without
2762 * modification, are permitted provided that the following conditions
2763@@ -61,10 +61,22 @@
2764
2765 #define SSH_GSS_OIDTYPE 0x06
2766
2767+#define SSH2_MSG_KEXGSS_INIT 30
2768+#define SSH2_MSG_KEXGSS_CONTINUE 31
2769+#define SSH2_MSG_KEXGSS_COMPLETE 32
2770+#define SSH2_MSG_KEXGSS_HOSTKEY 33
2771+#define SSH2_MSG_KEXGSS_ERROR 34
2772+#define SSH2_MSG_KEXGSS_GROUPREQ 40
2773+#define SSH2_MSG_KEXGSS_GROUP 41
2774+#define KEX_GSS_GRP1_SHA1_ID "gss-group1-sha1-"
2775+#define KEX_GSS_GRP14_SHA1_ID "gss-group14-sha1-"
2776+#define KEX_GSS_GEX_SHA1_ID "gss-gex-sha1-"
2777+
2778 typedef struct {
2779 char *filename;
2780 char *envvar;
2781 char *envval;
2782+ struct passwd *owner;
2783 void *data;
2784 } ssh_gssapi_ccache;
2785
2786@@ -72,8 +84,11 @@ typedef struct {
2787 gss_buffer_desc displayname;
2788 gss_buffer_desc exportedname;
2789 gss_cred_id_t creds;
2790+ gss_name_t name;
2791 struct ssh_gssapi_mech_struct *mech;
2792 ssh_gssapi_ccache store;
2793+ int used;
2794+ int updated;
2795 } ssh_gssapi_client;
2796
2797 typedef struct ssh_gssapi_mech_struct {
2798@@ -84,6 +99,7 @@ typedef struct ssh_gssapi_mech_struct {
2799 int (*userok) (ssh_gssapi_client *, char *);
2800 int (*localname) (ssh_gssapi_client *, char **);
2801 void (*storecreds) (ssh_gssapi_client *);
2802+ int (*updatecreds) (ssh_gssapi_ccache *, ssh_gssapi_client *);
2803 } ssh_gssapi_mech;
2804
2805 typedef struct {
2806@@ -94,10 +110,11 @@ typedef struct {
2807 gss_OID oid; /* client */
2808 gss_cred_id_t creds; /* server */
2809 gss_name_t client; /* server */
2810- gss_cred_id_t client_creds; /* server */
2811+ gss_cred_id_t client_creds; /* both */
2812 } Gssctxt;
2813
2814 extern ssh_gssapi_mech *supported_mechs[];
2815+extern Gssctxt *gss_kex_context;
2816
2817 int ssh_gssapi_check_oid(Gssctxt *, void *, size_t);
2818 void ssh_gssapi_set_oid_data(Gssctxt *, void *, size_t);
2819@@ -123,17 +140,33 @@ void ssh_gssapi_delete_ctx(Gssctxt **);
2820 OM_uint32 ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
2821 void ssh_gssapi_buildmic(struct sshbuf *, const char *,
2822 const char *, const char *);
2823-int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *);
2824+int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *, const char *);
2825+OM_uint32 ssh_gssapi_client_identity(Gssctxt *, const char *);
2826+int ssh_gssapi_credentials_updated(Gssctxt *);
2827
2828 /* In the server */
2829+typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *,
2830+ const char *);
2831+char *ssh_gssapi_client_mechanisms(const char *, const char *);
2832+char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *,
2833+ const char *);
2834+gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
2835+int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *,
2836+ const char *);
2837 OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
2838-int ssh_gssapi_userok(char *name);
2839+int ssh_gssapi_userok(char *name, struct passwd *);
2840 OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
2841 void ssh_gssapi_do_child(char ***, u_int *);
2842 void ssh_gssapi_cleanup_creds(void);
2843 void ssh_gssapi_storecreds(void);
2844 const char *ssh_gssapi_displayname(void);
2845
2846+char *ssh_gssapi_server_mechanisms(void);
2847+int ssh_gssapi_oid_table_ok(void);
2848+
2849+int ssh_gssapi_update_creds(ssh_gssapi_ccache *store);
2850+void ssh_gssapi_rekey_creds(void);
2851+
2852 #endif /* GSSAPI */
2853
2854 #endif /* _SSH_GSS_H */
2855diff --git a/ssh_config b/ssh_config
2856index c12f5ef52..bcb9f153d 100644
2857--- a/ssh_config
2858+++ b/ssh_config
2859@@ -24,6 +24,8 @@
2860 # HostbasedAuthentication no
2861 # GSSAPIAuthentication no
2862 # GSSAPIDelegateCredentials no
2863+# GSSAPIKeyExchange no
2864+# GSSAPITrustDNS no
2865 # BatchMode no
2866 # CheckHostIP yes
2867 # AddressFamily any
2868diff --git a/ssh_config.5 b/ssh_config.5
2869index 4d5b01d3e..16c79368a 100644
2870--- a/ssh_config.5
2871+++ b/ssh_config.5
2872@@ -736,10 +736,42 @@ The default is
2873 Specifies whether user authentication based on GSSAPI is allowed.
2874 The default is
2875 .Cm no .
2876+.It Cm GSSAPIKeyExchange
2877+Specifies whether key exchange based on GSSAPI may be used. When using
2878+GSSAPI key exchange the server need not have a host key.
2879+The default is
2880+.Cm no .
2881+.It Cm GSSAPIClientIdentity
2882+If set, specifies the GSSAPI client identity that ssh should use when
2883+connecting to the server. The default is unset, which means that the default
2884+identity will be used.
2885+.It Cm GSSAPIServerIdentity
2886+If set, specifies the GSSAPI server identity that ssh should expect when
2887+connecting to the server. The default is unset, which means that the
2888+expected GSSAPI server identity will be determined from the target
2889+hostname.
2890 .It Cm GSSAPIDelegateCredentials
2891 Forward (delegate) credentials to the server.
2892 The default is
2893 .Cm no .
2894+.It Cm GSSAPIRenewalForcesRekey
2895+If set to
2896+.Cm yes
2897+then renewal of the client's GSSAPI credentials will force the rekeying of the
2898+ssh connection. With a compatible server, this can delegate the renewed
2899+credentials to a session on the server.
2900+The default is
2901+.Cm no .
2902+.It Cm GSSAPITrustDns
2903+Set to
2904+.Cm yes
2905+to indicate that the DNS is trusted to securely canonicalize
2906+the name of the host being connected to. If
2907+.Cm no ,
2908+the hostname entered on the
2909+command line will be passed untouched to the GSSAPI library.
2910+The default is
2911+.Cm no .
2912 .It Cm HashKnownHosts
2913 Indicates that
2914 .Xr ssh 1
2915diff --git a/sshconnect2.c b/sshconnect2.c
2916index 1675f3935..8c872a4fb 100644
2917--- a/sshconnect2.c
2918+++ b/sshconnect2.c
2919@@ -162,6 +162,11 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2920 struct kex *kex;
2921 int r;
2922
2923+#ifdef GSSAPI
2924+ char *orig = NULL, *gss = NULL;
2925+ char *gss_host = NULL;
2926+#endif
2927+
2928 xxx_host = host;
2929 xxx_hostaddr = hostaddr;
2930
2931@@ -194,6 +199,35 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2932 order_hostkeyalgs(host, hostaddr, port));
2933 }
2934
2935+#ifdef GSSAPI
2936+ if (options.gss_keyex) {
2937+ /* Add the GSSAPI mechanisms currently supported on this
2938+ * client to the key exchange algorithm proposal */
2939+ orig = myproposal[PROPOSAL_KEX_ALGS];
2940+
2941+ if (options.gss_server_identity)
2942+ gss_host = xstrdup(options.gss_server_identity);
2943+ else if (options.gss_trust_dns)
2944+ gss_host = remote_hostname(active_state);
2945+ else
2946+ gss_host = xstrdup(host);
2947+
2948+ gss = ssh_gssapi_client_mechanisms(gss_host,
2949+ options.gss_client_identity);
2950+ if (gss) {
2951+ debug("Offering GSSAPI proposal: %s", gss);
2952+ xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
2953+ "%s,%s", gss, orig);
2954+
2955+ /* If we've got GSSAPI algorithms, then we also
2956+ * support the 'null' hostkey, as a last resort */
2957+ orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
2958+ xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
2959+ "%s,null", orig);
2960+ }
2961+ }
2962+#endif
2963+
2964 if (options.rekey_limit || options.rekey_interval)
2965 packet_set_rekey_limits(options.rekey_limit,
2966 options.rekey_interval);
2967@@ -215,15 +249,41 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2968 # endif
2969 #endif
2970 kex->kex[KEX_C25519_SHA256] = kexc25519_client;
2971+#ifdef GSSAPI
2972+ if (options.gss_keyex) {
2973+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client;
2974+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client;
2975+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
2976+ }
2977+#endif
2978 kex->client_version_string=client_version_string;
2979 kex->server_version_string=server_version_string;
2980 kex->verify_host_key=&verify_host_key_callback;
2981
2982+#ifdef GSSAPI
2983+ if (options.gss_keyex) {
2984+ kex->gss_deleg_creds = options.gss_deleg_creds;
2985+ kex->gss_trust_dns = options.gss_trust_dns;
2986+ kex->gss_client = options.gss_client_identity;
2987+ kex->gss_host = gss_host;
2988+ }
2989+#endif
2990+
2991 ssh_dispatch_run_fatal(active_state, DISPATCH_BLOCK, &kex->done);
2992
2993 /* remove ext-info from the KEX proposals for rekeying */
2994 myproposal[PROPOSAL_KEX_ALGS] =
2995 compat_kex_proposal(options.kex_algorithms);
2996+#ifdef GSSAPI
2997+ /* repair myproposal after it was crumpled by the */
2998+ /* ext-info removal above */
2999+ if (gss) {
3000+ orig = myproposal[PROPOSAL_KEX_ALGS];
3001+ xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
3002+ "%s,%s", gss, orig);
3003+ free(gss);
3004+ }
3005+#endif
3006 if ((r = kex_prop2buf(kex->my, myproposal)) != 0)
3007 fatal("kex_prop2buf: %s", ssh_err(r));
3008
3009@@ -314,6 +374,7 @@ int input_gssapi_token(int type, u_int32_t, struct ssh *);
3010 int input_gssapi_hash(int type, u_int32_t, struct ssh *);
3011 int input_gssapi_error(int, u_int32_t, struct ssh *);
3012 int input_gssapi_errtok(int, u_int32_t, struct ssh *);
3013+int userauth_gsskeyex(Authctxt *authctxt);
3014 #endif
3015
3016 void userauth(Authctxt *, char *);
3017@@ -330,6 +391,11 @@ static char *authmethods_get(void);
3018
3019 Authmethod authmethods[] = {
3020 #ifdef GSSAPI
3021+ {"gssapi-keyex",
3022+ userauth_gsskeyex,
3023+ NULL,
3024+ &options.gss_authentication,
3025+ NULL},
3026 {"gssapi-with-mic",
3027 userauth_gssapi,
3028 NULL,
3029@@ -686,25 +752,40 @@ userauth_gssapi(Authctxt *authctxt)
3030 static u_int mech = 0;
3031 OM_uint32 min;
3032 int r, ok = 0;
3033+ char *gss_host;
3034+
3035+ if (options.gss_server_identity)
3036+ gss_host = xstrdup(options.gss_server_identity);
3037+ else if (options.gss_trust_dns)
3038+ gss_host = remote_hostname(active_state);
3039+ else
3040+ gss_host = xstrdup(authctxt->host);
3041
3042 /* Try one GSSAPI method at a time, rather than sending them all at
3043 * once. */
3044
3045 if (gss_supported == NULL)
3046- gss_indicate_mechs(&min, &gss_supported);
3047+ if (GSS_ERROR(gss_indicate_mechs(&min, &gss_supported))) {
3048+ gss_supported = NULL;
3049+ free(gss_host);
3050+ return 0;
3051+ }
3052
3053 /* Check to see if the mechanism is usable before we offer it */
3054 while (mech < gss_supported->count && !ok) {
3055 /* My DER encoding requires length<128 */
3056 if (gss_supported->elements[mech].length < 128 &&
3057 ssh_gssapi_check_mechanism(&gssctxt,
3058- &gss_supported->elements[mech], authctxt->host)) {
3059+ &gss_supported->elements[mech], gss_host,
3060+ options.gss_client_identity)) {
3061 ok = 1; /* Mechanism works */
3062 } else {
3063 mech++;
3064 }
3065 }
3066
3067+ free(gss_host);
3068+
3069 if (!ok)
3070 return 0;
3071
3072@@ -935,6 +1016,54 @@ input_gssapi_error(int type, u_int32_t plen, struct ssh *ssh)
3073 free(lang);
3074 return r;
3075 }
3076+
3077+int
3078+userauth_gsskeyex(Authctxt *authctxt)
3079+{
3080+ struct ssh *ssh = active_state; /* XXX */
3081+ struct sshbuf *b;
3082+ gss_buffer_desc gssbuf;
3083+ gss_buffer_desc mic = GSS_C_EMPTY_BUFFER;
3084+ OM_uint32 ms;
3085+ int r;
3086+
3087+ static int attempt = 0;
3088+ if (attempt++ >= 1)
3089+ return (0);
3090+
3091+ if (gss_kex_context == NULL) {
3092+ debug("No valid Key exchange context");
3093+ return (0);
3094+ }
3095+
3096+ if ((b = sshbuf_new()) == NULL)
3097+ fatal("%s: sshbuf_new failed", __func__);
3098+ ssh_gssapi_buildmic(b, authctxt->server_user, authctxt->service,
3099+ "gssapi-keyex");
3100+
3101+ if ((gssbuf.value = sshbuf_mutable_ptr(b)) == NULL)
3102+ fatal("%s: sshbuf_mutable_ptr failed", __func__);
3103+ gssbuf.length = sshbuf_len(b);
3104+
3105+ if (GSS_ERROR(ssh_gssapi_sign(gss_kex_context, &gssbuf, &mic))) {
3106+ sshbuf_free(b);
3107+ return (0);
3108+ }
3109+
3110+ if ((r = sshpkt_start(ssh, SSH2_MSG_USERAUTH_REQUEST)) != 0 ||
3111+ (r = sshpkt_put_cstring(ssh, authctxt->server_user)) != 0 ||
3112+ (r = sshpkt_put_cstring(ssh, authctxt->service)) != 0 ||
3113+ (r = sshpkt_put_cstring(ssh, authctxt->method->name)) != 0 ||
3114+ (r = sshpkt_put_string(ssh, mic.value, mic.length)) != 0 ||
3115+ (r = sshpkt_send(ssh)) != 0)
3116+ fatal("%s: %s", __func__, ssh_err(r));
3117+
3118+ sshbuf_free(b);
3119+ gss_release_buffer(&ms, &mic);
3120+
3121+ return (1);
3122+}
3123+
3124 #endif /* GSSAPI */
3125
3126 int
3127diff --git a/sshd.c b/sshd.c
3128index ba26287ba..539a000fd 100644
3129--- a/sshd.c
3130+++ b/sshd.c
3131@@ -123,6 +123,10 @@
3132 #include "version.h"
3133 #include "ssherr.h"
3134
3135+#ifdef USE_SECURITY_SESSION_API
3136+#include <Security/AuthSession.h>
3137+#endif
3138+
3139 /* Re-exec fds */
3140 #define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1)
3141 #define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2)
3142@@ -1810,10 +1814,13 @@ main(int ac, char **av)
3143 free(fp);
3144 }
3145 accumulate_host_timing_secret(cfg, NULL);
3146+#ifndef GSSAPI
3147+ /* The GSSAPI key exchange can run without a host key */
3148 if (!sensitive_data.have_ssh2_key) {
3149 logit("sshd: no hostkeys available -- exiting.");
3150 exit(1);
3151 }
3152+#endif
3153
3154 /*
3155 * Load certificates. They are stored in an array at identical
3156@@ -2104,6 +2111,60 @@ main(int ac, char **av)
3157 rdomain == NULL ? "" : "\"");
3158 free(laddr);
3159
3160+#ifdef USE_SECURITY_SESSION_API
3161+ /*
3162+ * Create a new security session for use by the new user login if
3163+ * the current session is the root session or we are not launched
3164+ * by inetd (eg: debugging mode or server mode). We do not
3165+ * necessarily need to create a session if we are launched from
3166+ * inetd because Panther xinetd will create a session for us.
3167+ *
3168+ * The only case where this logic will fail is if there is an
3169+ * inetd running in a non-root session which is not creating
3170+ * new sessions for us. Then all the users will end up in the
3171+ * same session (bad).
3172+ *
3173+ * When the client exits, the session will be destroyed for us
3174+ * automatically.
3175+ *
3176+ * We must create the session before any credentials are stored
3177+ * (including AFS pags, which happens a few lines below).
3178+ */
3179+ {
3180+ OSStatus err = 0;
3181+ SecuritySessionId sid = 0;
3182+ SessionAttributeBits sattrs = 0;
3183+
3184+ err = SessionGetInfo(callerSecuritySession, &sid, &sattrs);
3185+ if (err)
3186+ error("SessionGetInfo() failed with error %.8X",
3187+ (unsigned) err);
3188+ else
3189+ debug("Current Session ID is %.8X / Session Attributes are %.8X",
3190+ (unsigned) sid, (unsigned) sattrs);
3191+
3192+ if (inetd_flag && !(sattrs & sessionIsRoot))
3193+ debug("Running in inetd mode in a non-root session... "
3194+ "assuming inetd created the session for us.");
3195+ else {
3196+ debug("Creating new security session...");
3197+ err = SessionCreate(0, sessionHasTTY | sessionIsRemote);
3198+ if (err)
3199+ error("SessionCreate() failed with error %.8X",
3200+ (unsigned) err);
3201+
3202+ err = SessionGetInfo(callerSecuritySession, &sid,
3203+ &sattrs);
3204+ if (err)
3205+ error("SessionGetInfo() failed with error %.8X",
3206+ (unsigned) err);
3207+ else
3208+ debug("New Session ID is %.8X / Session Attributes are %.8X",
3209+ (unsigned) sid, (unsigned) sattrs);
3210+ }
3211+ }
3212+#endif
3213+
3214 /*
3215 * We don't want to listen forever unless the other side
3216 * successfully authenticates itself. So we set up an alarm which is
3217@@ -2287,6 +2348,48 @@ do_ssh2_kex(void)
3218 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal(
3219 list_hostkey_types());
3220
3221+#ifdef GSSAPI
3222+ {
3223+ char *orig;
3224+ char *gss = NULL;
3225+ char *newstr = NULL;
3226+ orig = myproposal[PROPOSAL_KEX_ALGS];
3227+
3228+ /*
3229+ * If we don't have a host key, then there's no point advertising
3230+ * the other key exchange algorithms
3231+ */
3232+
3233+ if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
3234+ orig = NULL;
3235+
3236+ if (options.gss_keyex)
3237+ gss = ssh_gssapi_server_mechanisms();
3238+ else
3239+ gss = NULL;
3240+
3241+ if (gss && orig)
3242+ xasprintf(&newstr, "%s,%s", gss, orig);
3243+ else if (gss)
3244+ newstr = gss;
3245+ else if (orig)
3246+ newstr = orig;
3247+
3248+ /*
3249+ * If we've got GSSAPI mechanisms, then we've got the 'null' host
3250+ * key alg, but we can't tell people about it unless its the only
3251+ * host key algorithm we support
3252+ */
3253+ if (gss && (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS])) == 0)
3254+ myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = "null";
3255+
3256+ if (newstr)
3257+ myproposal[PROPOSAL_KEX_ALGS] = newstr;
3258+ else
3259+ fatal("No supported key exchange algorithms");
3260+ }
3261+#endif
3262+
3263 /* start key exchange */
3264 if ((r = kex_setup(active_state, myproposal)) != 0)
3265 fatal("kex_setup: %s", ssh_err(r));
3266@@ -2304,6 +2407,13 @@ do_ssh2_kex(void)
3267 # endif
3268 #endif
3269 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
3270+#ifdef GSSAPI
3271+ if (options.gss_keyex) {
3272+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
3273+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
3274+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
3275+ }
3276+#endif
3277 kex->server = 1;
3278 kex->client_version_string=client_version_string;
3279 kex->server_version_string=server_version_string;
3280diff --git a/sshd_config b/sshd_config
3281index 19b7c91a1..2c48105f8 100644
3282--- a/sshd_config
3283+++ b/sshd_config
3284@@ -69,6 +69,8 @@ AuthorizedKeysFile .ssh/authorized_keys
3285 # GSSAPI options
3286 #GSSAPIAuthentication no
3287 #GSSAPICleanupCredentials yes
3288+#GSSAPIStrictAcceptorCheck yes
3289+#GSSAPIKeyExchange no
3290
3291 # Set this to 'yes' to enable PAM authentication, account processing,
3292 # and session processing. If this is enabled, PAM authentication will
3293diff --git a/sshd_config.5 b/sshd_config.5
3294index c6484370b..985eef5a2 100644
3295--- a/sshd_config.5
3296+++ b/sshd_config.5
3297@@ -648,6 +648,11 @@ The default is
3298 Specifies whether user authentication based on GSSAPI is allowed.
3299 The default is
3300 .Cm no .
3301+.It Cm GSSAPIKeyExchange
3302+Specifies whether key exchange based on GSSAPI is allowed. GSSAPI key exchange
3303+doesn't rely on ssh keys to verify host identity.
3304+The default is
3305+.Cm no .
3306 .It Cm GSSAPICleanupCredentials
3307 Specifies whether to automatically destroy the user's credentials cache
3308 on logout.
3309@@ -667,6 +672,11 @@ machine's default store.
3310 This facility is provided to assist with operation on multi homed machines.
3311 The default is
3312 .Cm yes .
3313+.It Cm GSSAPIStoreCredentialsOnRekey
3314+Controls whether the user's GSSAPI credentials should be updated following a
3315+successful connection rekeying. This option can be used to accepted renewed
3316+or updated credentials from a compatible client. The default is
3317+.Cm no .
3318 .It Cm HostbasedAcceptedKeyTypes
3319 Specifies the key types that will be accepted for hostbased authentication
3320 as a list of comma-separated patterns.
3321diff --git a/sshkey.c b/sshkey.c
3322index 6555c5ef8..a85c185fc 100644
3323--- a/sshkey.c
3324+++ b/sshkey.c
3325@@ -135,6 +135,7 @@ static const struct keytype keytypes[] = {
3326 # endif /* OPENSSL_HAS_NISTP521 */
3327 # endif /* OPENSSL_HAS_ECC */
3328 #endif /* WITH_OPENSSL */
3329+ { "null", "null", NULL, KEY_NULL, 0, 0, 0 },
3330 { NULL, NULL, NULL, -1, -1, 0, 0 }
3331 };
3332
3333@@ -223,7 +224,7 @@ sshkey_alg_list(int certs_only, int plain_only, int include_sigonly, char sep)
3334 const struct keytype *kt;
3335
3336 for (kt = keytypes; kt->type != -1; kt++) {
3337- if (kt->name == NULL)
3338+ if (kt->name == NULL || kt->type == KEY_NULL)
3339 continue;
3340 if (!include_sigonly && kt->sigonly)
3341 continue;
3342diff --git a/sshkey.h b/sshkey.h
3343index f6a007fdf..f54deb0c0 100644
3344--- a/sshkey.h
3345+++ b/sshkey.h
3346@@ -64,6 +64,7 @@ enum sshkey_types {
3347 KEY_ED25519_CERT,
3348 KEY_XMSS,
3349 KEY_XMSS_CERT,
3350+ KEY_NULL,
3351 KEY_UNSPEC
3352 };
3353
diff --git a/debian/patches/have-progressmeter-force-update-at-beginning-and-end-transfer.patch b/debian/patches/have-progressmeter-force-update-at-beginning-and-end-transfer.patch
new file mode 100644
index 000000000..767dbf2b5
--- /dev/null
+++ b/debian/patches/have-progressmeter-force-update-at-beginning-and-end-transfer.patch
@@ -0,0 +1,120 @@
1From 2a8f710447442e9a03e71c022859112ec2d77d17 Mon Sep 17 00:00:00 2001
2From: "dtucker@openbsd.org" <dtucker@openbsd.org>
3Date: Thu, 24 Jan 2019 16:52:17 +0000
4Subject: upstream: Have progressmeter force an update at the beginning and
5
6end of each transfer. Fixes the problem recently introduces where very quick
7transfers do not display the progressmeter at all. Spotted by naddy@
8
9OpenBSD-Commit-ID: 68dc46c259e8fdd4f5db3ec2a130f8e4590a7a9a
10
11Origin: upstream, https://anongit.mindrot.org/openssh.git/commit/?id=bdc6c63c80b55bcbaa66b5fde31c1cb1d09a41eb
12Last-Update: 2019-02-08
13
14Patch-Name: have-progressmeter-force-update-at-beginning-and-end-transfer.patch
15---
16 progressmeter.c | 13 +++++--------
17 progressmeter.h | 4 ++--
18 scp.c | 2 +-
19 sftp-client.c | 2 +-
20 4 files changed, 9 insertions(+), 12 deletions(-)
21
22diff --git a/progressmeter.c b/progressmeter.c
23index add462dde..e385c1254 100644
24--- a/progressmeter.c
25+++ b/progressmeter.c
26@@ -1,4 +1,4 @@
27-/* $OpenBSD: progressmeter.c,v 1.46 2019/01/23 08:01:46 dtucker Exp $ */
28+/* $OpenBSD: progressmeter.c,v 1.47 2019/01/24 16:52:17 dtucker Exp $ */
29 /*
30 * Copyright (c) 2003 Nils Nordman. All rights reserved.
31 *
32@@ -59,9 +59,6 @@ static void format_rate(char *, int, off_t);
33 static void sig_winch(int);
34 static void setscreensize(void);
35
36-/* updates the progressmeter to reflect the current state of the transfer */
37-void refresh_progress_meter(void);
38-
39 /* signal handler for updating the progress meter */
40 static void sig_alarm(int);
41
42@@ -120,7 +117,7 @@ format_size(char *buf, int size, off_t bytes)
43 }
44
45 void
46-refresh_progress_meter(void)
47+refresh_progress_meter(int force_update)
48 {
49 char buf[MAX_WINSIZE + 1];
50 off_t transferred;
51@@ -131,7 +128,7 @@ refresh_progress_meter(void)
52 int hours, minutes, seconds;
53 int file_len;
54
55- if ((!alarm_fired && !win_resized) || !can_output())
56+ if ((!force_update && !alarm_fired && !win_resized) || !can_output())
57 return;
58 alarm_fired = 0;
59
60@@ -254,7 +251,7 @@ start_progress_meter(const char *f, off_t filesize, off_t *ctr)
61 bytes_per_second = 0;
62
63 setscreensize();
64- refresh_progress_meter();
65+ refresh_progress_meter(1);
66
67 signal(SIGALRM, sig_alarm);
68 signal(SIGWINCH, sig_winch);
69@@ -271,7 +268,7 @@ stop_progress_meter(void)
70
71 /* Ensure we complete the progress */
72 if (cur_pos != end_pos)
73- refresh_progress_meter();
74+ refresh_progress_meter(1);
75
76 atomicio(vwrite, STDOUT_FILENO, "\n", 1);
77 }
78diff --git a/progressmeter.h b/progressmeter.h
79index 8f6678060..1703ea75b 100644
80--- a/progressmeter.h
81+++ b/progressmeter.h
82@@ -1,4 +1,4 @@
83-/* $OpenBSD: progressmeter.h,v 1.4 2019/01/23 08:01:46 dtucker Exp $ */
84+/* $OpenBSD: progressmeter.h,v 1.5 2019/01/24 16:52:17 dtucker Exp $ */
85 /*
86 * Copyright (c) 2002 Nils Nordman. All rights reserved.
87 *
88@@ -24,5 +24,5 @@
89 */
90
91 void start_progress_meter(const char *, off_t, off_t *);
92-void refresh_progress_meter(void);
93+void refresh_progress_meter(int);
94 void stop_progress_meter(void);
95diff --git a/scp.c b/scp.c
96index 80308573c..1971c80cd 100644
97--- a/scp.c
98+++ b/scp.c
99@@ -593,7 +593,7 @@ scpio(void *_cnt, size_t s)
100 off_t *cnt = (off_t *)_cnt;
101
102 *cnt += s;
103- refresh_progress_meter();
104+ refresh_progress_meter(0);
105 if (limit_kbps > 0)
106 bandwidth_limit(&bwlimit, s);
107 return 0;
108diff --git a/sftp-client.c b/sftp-client.c
109index 2bc698f86..cf2887a40 100644
110--- a/sftp-client.c
111+++ b/sftp-client.c
112@@ -101,7 +101,7 @@ sftpio(void *_bwlimit, size_t amount)
113 {
114 struct bwlimit *bwlimit = (struct bwlimit *)_bwlimit;
115
116- refresh_progress_meter();
117+ refresh_progress_meter(0);
118 if (bwlimit != NULL)
119 bandwidth_limit(bwlimit, amount);
120 return 0;
diff --git a/debian/patches/keepalive-extensions.patch b/debian/patches/keepalive-extensions.patch
new file mode 100644
index 000000000..4207302c3
--- /dev/null
+++ b/debian/patches/keepalive-extensions.patch
@@ -0,0 +1,134 @@
1From 7ba31c6ff505278fb9f33b695605ca3a093caba2 Mon Sep 17 00:00:00 2001
2From: Richard Kettlewell <rjk@greenend.org.uk>
3Date: Sun, 9 Feb 2014 16:09:52 +0000
4Subject: Various keepalive extensions
5
6Add compatibility aliases for ProtocolKeepAlives and SetupTimeOut, supported
7in previous versions of Debian's OpenSSH package but since superseded by
8ServerAliveInterval. (We're probably stuck with this bit for
9compatibility.)
10
11In batch mode, default ServerAliveInterval to five minutes.
12
13Adjust documentation to match and to give some more advice on use of
14keepalives.
15
16Author: Ian Jackson <ian@chiark.greenend.org.uk>
17Author: Matthew Vernon <matthew@debian.org>
18Author: Colin Watson <cjwatson@debian.org>
19Last-Update: 2018-10-19
20
21Patch-Name: keepalive-extensions.patch
22---
23 readconf.c | 14 ++++++++++++--
24 ssh_config.5 | 21 +++++++++++++++++++--
25 sshd_config.5 | 3 +++
26 3 files changed, 34 insertions(+), 4 deletions(-)
27
28diff --git a/readconf.c b/readconf.c
29index 5e655e924..052d4b1ac 100644
30--- a/readconf.c
31+++ b/readconf.c
32@@ -175,6 +175,7 @@ typedef enum {
33 oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
34 oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
35 oPubkeyAcceptedKeyTypes, oCASignatureAlgorithms, oProxyJump,
36+ oProtocolKeepAlives, oSetupTimeOut,
37 oIgnore, oIgnoredUnknownOption, oDeprecated, oUnsupported
38 } OpCodes;
39
40@@ -322,6 +323,8 @@ static struct {
41 { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
42 { "ignoreunknown", oIgnoreUnknown },
43 { "proxyjump", oProxyJump },
44+ { "protocolkeepalives", oProtocolKeepAlives },
45+ { "setuptimeout", oSetupTimeOut },
46
47 { NULL, oBadOption }
48 };
49@@ -1415,6 +1418,8 @@ parse_keytypes:
50 goto parse_flag;
51
52 case oServerAliveInterval:
53+ case oProtocolKeepAlives: /* Debian-specific compatibility alias */
54+ case oSetupTimeOut: /* Debian-specific compatibility alias */
55 intptr = &options->server_alive_interval;
56 goto parse_time;
57
58@@ -2101,8 +2106,13 @@ fill_default_options(Options * options)
59 options->rekey_interval = 0;
60 if (options->verify_host_key_dns == -1)
61 options->verify_host_key_dns = 0;
62- if (options->server_alive_interval == -1)
63- options->server_alive_interval = 0;
64+ if (options->server_alive_interval == -1) {
65+ /* in batch mode, default is 5mins */
66+ if (options->batch_mode == 1)
67+ options->server_alive_interval = 300;
68+ else
69+ options->server_alive_interval = 0;
70+ }
71 if (options->server_alive_count_max == -1)
72 options->server_alive_count_max = 3;
73 if (options->control_master == -1)
74diff --git a/ssh_config.5 b/ssh_config.5
75index 16c79368a..54e143c93 100644
76--- a/ssh_config.5
77+++ b/ssh_config.5
78@@ -247,8 +247,12 @@ Valid arguments are
79 If set to
80 .Cm yes ,
81 passphrase/password querying will be disabled.
82+In addition, the
83+.Cm ServerAliveInterval
84+option will be set to 300 seconds by default (Debian-specific).
85 This option is useful in scripts and other batch jobs where no user
86-is present to supply the password.
87+is present to supply the password,
88+and where it is desirable to detect a broken network swiftly.
89 The argument must be
90 .Cm yes
91 or
92@@ -1485,7 +1489,14 @@ from the server,
93 will send a message through the encrypted
94 channel to request a response from the server.
95 The default
96-is 0, indicating that these messages will not be sent to the server.
97+is 0, indicating that these messages will not be sent to the server,
98+or 300 if the
99+.Cm BatchMode
100+option is set (Debian-specific).
101+.Cm ProtocolKeepAlives
102+and
103+.Cm SetupTimeOut
104+are Debian-specific compatibility aliases for this option.
105 .It Cm SetEnv
106 Directly specify one or more environment variables and their contents to
107 be sent to the server.
108@@ -1565,6 +1576,12 @@ Specifies whether the system should send TCP keepalive messages to the
109 other side.
110 If they are sent, death of the connection or crash of one
111 of the machines will be properly noticed.
112+This option only uses TCP keepalives (as opposed to using ssh level
113+keepalives), so takes a long time to notice when the connection dies.
114+As such, you probably want
115+the
116+.Cm ServerAliveInterval
117+option as well.
118 However, this means that
119 connections will die if the route is down temporarily, and some people
120 find it annoying.
121diff --git a/sshd_config.5 b/sshd_config.5
122index 985eef5a2..e7e55dd71 100644
123--- a/sshd_config.5
124+++ b/sshd_config.5
125@@ -1577,6 +1577,9 @@ This avoids infinitely hanging sessions.
126 .Pp
127 To disable TCP keepalive messages, the value should be set to
128 .Cm no .
129+.Pp
130+This option was formerly called
131+.Cm KeepAlive .
132 .It Cm TrustedUserCAKeys
133 Specifies a file containing public keys of certificate authorities that are
134 trusted to sign user certificates for authentication, or
diff --git a/debian/patches/mention-ssh-keygen-on-keychange.patch b/debian/patches/mention-ssh-keygen-on-keychange.patch
new file mode 100644
index 000000000..75ed46db7
--- /dev/null
+++ b/debian/patches/mention-ssh-keygen-on-keychange.patch
@@ -0,0 +1,44 @@
1From bb8bb2621914ad600202e38d5b9b4f4544b191e5 Mon Sep 17 00:00:00 2001
2From: Scott Moser <smoser@ubuntu.com>
3Date: Sun, 9 Feb 2014 16:10:03 +0000
4Subject: Mention ssh-keygen in ssh fingerprint changed warning
5
6Author: Chris Lamb <lamby@debian.org>
7Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1843
8Bug-Ubuntu: https://bugs.launchpad.net/bugs/686607
9Last-Update: 2017-08-22
10
11Patch-Name: mention-ssh-keygen-on-keychange.patch
12---
13 sshconnect.c | 9 ++++++++-
14 1 file changed, 8 insertions(+), 1 deletion(-)
15
16diff --git a/sshconnect.c b/sshconnect.c
17index 700ea6c3c..158e8146f 100644
18--- a/sshconnect.c
19+++ b/sshconnect.c
20@@ -1121,9 +1121,13 @@ check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port,
21 error("%s. This could either mean that", key_msg);
22 error("DNS SPOOFING is happening or the IP address for the host");
23 error("and its host key have changed at the same time.");
24- if (ip_status != HOST_NEW)
25+ if (ip_status != HOST_NEW) {
26 error("Offending key for IP in %s:%lu",
27 ip_found->file, ip_found->line);
28+ error(" remove with:");
29+ error(" ssh-keygen -f \"%s\" -R \"%s\"",
30+ ip_found->file, ip);
31+ }
32 }
33 /* The host key has changed. */
34 warn_changed_key(host_key);
35@@ -1132,6 +1136,9 @@ check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port,
36 error("Offending %s key in %s:%lu",
37 sshkey_type(host_found->key),
38 host_found->file, host_found->line);
39+ error(" remove with:");
40+ error(" ssh-keygen -f \"%s\" -R \"%s\"",
41+ host_found->file, host);
42
43 /*
44 * If strict host key checking is in use, the user will have
diff --git a/debian/patches/no-openssl-version-status.patch b/debian/patches/no-openssl-version-status.patch
new file mode 100644
index 000000000..3b2e05e58
--- /dev/null
+++ b/debian/patches/no-openssl-version-status.patch
@@ -0,0 +1,62 @@
1From 690051b3aa4ff72af57e4a82d640858357eef820 Mon Sep 17 00:00:00 2001
2From: Kurt Roeckx <kurt@roeckx.be>
3Date: Sun, 9 Feb 2014 16:10:14 +0000
4Subject: Don't check the status field of the OpenSSL version
5
6There is no reason to check the version of OpenSSL (in Debian). If it's
7not compatible the soname will change. OpenSSH seems to want to do a
8check for the soname based on the version number, but wants to keep the
9status of the release the same. Remove that check on the status since
10it doesn't tell you anything about how compatible that version is.
11
12Author: Colin Watson <cjwatson@debian.org>
13Bug-Debian: https://bugs.debian.org/93581
14Bug-Debian: https://bugs.debian.org/664383
15Bug-Debian: https://bugs.debian.org/732940
16Forwarded: not-needed
17Last-Update: 2014-10-07
18
19Patch-Name: no-openssl-version-status.patch
20---
21 openbsd-compat/openssl-compat.c | 6 +++---
22 openbsd-compat/regress/opensslvertest.c | 1 +
23 2 files changed, 4 insertions(+), 3 deletions(-)
24
25diff --git a/openbsd-compat/openssl-compat.c b/openbsd-compat/openssl-compat.c
26index 8b4a36274..ea0b0c9fb 100644
27--- a/openbsd-compat/openssl-compat.c
28+++ b/openbsd-compat/openssl-compat.c
29@@ -34,7 +34,7 @@
30 /*
31 * OpenSSL version numbers: MNNFFPPS: major minor fix patch status
32 * We match major, minor, fix and status (not patch) for <1.0.0.
33- * After that, we acceptable compatible fix versions (so we
34+ * After that, we accept compatible fix and status versions (so we
35 * allow 1.0.1 to work with 1.0.0). Going backwards is only allowed
36 * within a patch series.
37 */
38@@ -55,10 +55,10 @@ ssh_compatible_openssl(long headerver, long libver)
39 }
40
41 /*
42- * For versions >= 1.0.0, major,minor,status must match and library
43+ * For versions >= 1.0.0, major,minor must match and library
44 * fix version must be equal to or newer than the header.
45 */
46- mask = 0xfff0000fL; /* major,minor,status */
47+ mask = 0xfff00000L; /* major,minor */
48 hfix = (headerver & 0x000ff000) >> 12;
49 lfix = (libver & 0x000ff000) >> 12;
50 if ( (headerver & mask) == (libver & mask) && lfix >= hfix)
51diff --git a/openbsd-compat/regress/opensslvertest.c b/openbsd-compat/regress/opensslvertest.c
52index 5d019b598..58474873d 100644
53--- a/openbsd-compat/regress/opensslvertest.c
54+++ b/openbsd-compat/regress/opensslvertest.c
55@@ -35,6 +35,7 @@ struct version_test {
56
57 /* built with 1.0.1b release headers */
58 { 0x1000101fL, 0x1000101fL, 1},/* exact match */
59+ { 0x1000101fL, 0x10001010L, 1}, /* different status: ok */
60 { 0x1000101fL, 0x1000102fL, 1}, /* newer library patch version: ok */
61 { 0x1000101fL, 0x1000100fL, 1}, /* older library patch version: ok */
62 { 0x1000101fL, 0x1000201fL, 1}, /* newer library fix version: ok */
diff --git a/debian/patches/openbsd-docs.patch b/debian/patches/openbsd-docs.patch
new file mode 100644
index 000000000..cdb905b2e
--- /dev/null
+++ b/debian/patches/openbsd-docs.patch
@@ -0,0 +1,148 @@
1From 96c85e746d4f94c7d2748a200e5817ad8a987918 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:09 +0000
4Subject: Adjust various OpenBSD-specific references in manual pages
5
6No single bug reference for this patch, but history includes:
7 http://bugs.debian.org/154434 (login.conf(5))
8 http://bugs.debian.org/513417 (/etc/rc)
9 http://bugs.debian.org/530692 (ssl(8))
10 https://bugs.launchpad.net/bugs/456660 (ssl(8))
11
12Forwarded: not-needed
13Last-Update: 2017-10-04
14
15Patch-Name: openbsd-docs.patch
16---
17 moduli.5 | 4 ++--
18 ssh-keygen.1 | 12 ++++--------
19 ssh.1 | 4 ++++
20 sshd.8 | 5 ++---
21 sshd_config.5 | 3 +--
22 5 files changed, 13 insertions(+), 15 deletions(-)
23
24diff --git a/moduli.5 b/moduli.5
25index ef0de0850..149846c8c 100644
26--- a/moduli.5
27+++ b/moduli.5
28@@ -21,7 +21,7 @@
29 .Nd Diffie-Hellman moduli
30 .Sh DESCRIPTION
31 The
32-.Pa /etc/moduli
33+.Pa /etc/ssh/moduli
34 file contains prime numbers and generators for use by
35 .Xr sshd 8
36 in the Diffie-Hellman Group Exchange key exchange method.
37@@ -110,7 +110,7 @@ first estimates the size of the modulus required to produce enough
38 Diffie-Hellman output to sufficiently key the selected symmetric cipher.
39 .Xr sshd 8
40 then randomly selects a modulus from
41-.Fa /etc/moduli
42+.Fa /etc/ssh/moduli
43 that best meets the size requirement.
44 .Sh SEE ALSO
45 .Xr ssh-keygen 1 ,
46diff --git a/ssh-keygen.1 b/ssh-keygen.1
47index bfa2eb5f3..da6b5ed76 100644
48--- a/ssh-keygen.1
49+++ b/ssh-keygen.1
50@@ -176,9 +176,7 @@ key in
51 .Pa ~/.ssh/id_ed25519
52 or
53 .Pa ~/.ssh/id_rsa .
54-Additionally, the system administrator may use this to generate host keys,
55-as seen in
56-.Pa /etc/rc .
57+Additionally, the system administrator may use this to generate host keys.
58 .Pp
59 Normally this program generates the key and asks for a file in which
60 to store the private key.
61@@ -229,9 +227,7 @@ If
62 .Fl f
63 has also been specified, its argument is used as a prefix to the
64 default path for the resulting host key files.
65-This is used by
66-.Pa /etc/rc
67-to generate new host keys.
68+This is used by system administration scripts to generate new host keys.
69 .It Fl a Ar rounds
70 When saving a private key this option specifies the number of KDF
71 (key derivation function) rounds used.
72@@ -677,7 +673,7 @@ option.
73 Valid generator values are 2, 3, and 5.
74 .Pp
75 Screened DH groups may be installed in
76-.Pa /etc/moduli .
77+.Pa /etc/ssh/moduli .
78 It is important that this file contains moduli of a range of bit lengths and
79 that both ends of a connection share common moduli.
80 .Sh CERTIFICATES
81@@ -877,7 +873,7 @@ on all machines
82 where the user wishes to log in using public key authentication.
83 There is no need to keep the contents of this file secret.
84 .Pp
85-.It Pa /etc/moduli
86+.It Pa /etc/ssh/moduli
87 Contains Diffie-Hellman groups used for DH-GEX.
88 The file format is described in
89 .Xr moduli 5 .
90diff --git a/ssh.1 b/ssh.1
91index 81f29af43..5dfad6daa 100644
92--- a/ssh.1
93+++ b/ssh.1
94@@ -860,6 +860,10 @@ implements public key authentication protocol automatically,
95 using one of the DSA, ECDSA, Ed25519 or RSA algorithms.
96 The HISTORY section of
97 .Xr ssl 8
98+(on non-OpenBSD systems, see
99+.nh
100+http://www.openbsd.org/cgi\-bin/man.cgi?query=ssl&sektion=8#HISTORY)
101+.hy
102 contains a brief discussion of the DSA and RSA algorithms.
103 .Pp
104 The file
105diff --git a/sshd.8 b/sshd.8
106index 57a7fd66b..4abc01d66 100644
107--- a/sshd.8
108+++ b/sshd.8
109@@ -65,7 +65,7 @@ over an insecure network.
110 .Nm
111 listens for connections from clients.
112 It is normally started at boot from
113-.Pa /etc/rc .
114+.Pa /etc/init.d/ssh .
115 It forks a new
116 daemon for each incoming connection.
117 The forked daemons handle
118@@ -884,7 +884,7 @@ This file is for host-based authentication (see
119 .Xr ssh 1 ) .
120 It should only be writable by root.
121 .Pp
122-.It Pa /etc/moduli
123+.It Pa /etc/ssh/moduli
124 Contains Diffie-Hellman groups used for the "Diffie-Hellman Group Exchange"
125 key exchange method.
126 The file format is described in
127@@ -982,7 +982,6 @@ The content of this file is not sensitive; it can be world-readable.
128 .Xr ssh-keyscan 1 ,
129 .Xr chroot 2 ,
130 .Xr hosts_access 5 ,
131-.Xr login.conf 5 ,
132 .Xr moduli 5 ,
133 .Xr sshd_config 5 ,
134 .Xr inetd 8 ,
135diff --git a/sshd_config.5 b/sshd_config.5
136index 37e6be38f..23f71fd1d 100644
137--- a/sshd_config.5
138+++ b/sshd_config.5
139@@ -395,8 +395,7 @@ Certificates signed using other algorithms will not be accepted for
140 public key or host-based authentication.
141 .It Cm ChallengeResponseAuthentication
142 Specifies whether challenge-response authentication is allowed (e.g. via
143-PAM or through authentication styles supported in
144-.Xr login.conf 5 )
145+PAM).
146 The default is
147 .Cm yes .
148 .It Cm ChrootDirectory
diff --git a/debian/patches/package-versioning.patch b/debian/patches/package-versioning.patch
new file mode 100644
index 000000000..809c78846
--- /dev/null
+++ b/debian/patches/package-versioning.patch
@@ -0,0 +1,61 @@
1From b258a00bedcf29200b394c671c6deb1e53157f32 Mon Sep 17 00:00:00 2001
2From: Matthew Vernon <matthew@debian.org>
3Date: Sun, 9 Feb 2014 16:10:05 +0000
4Subject: Include the Debian version in our identification
5
6This makes it easier to audit networks for versions patched against security
7vulnerabilities. It has little detrimental effect, as attackers will
8generally just try attacks rather than bothering to scan for
9vulnerable-looking version strings. (However, see debian-banner.patch.)
10
11Forwarded: not-needed
12Last-Update: 2017-10-04
13
14Patch-Name: package-versioning.patch
15---
16 sshconnect.c | 2 +-
17 sshd.c | 2 +-
18 version.h | 7 ++++++-
19 3 files changed, 8 insertions(+), 3 deletions(-)
20
21diff --git a/sshconnect.c b/sshconnect.c
22index 158e8146f..b9418e277 100644
23--- a/sshconnect.c
24+++ b/sshconnect.c
25@@ -609,7 +609,7 @@ send_client_banner(int connection_out, int minor1)
26 {
27 /* Send our own protocol version identification. */
28 xasprintf(&client_version_string, "SSH-%d.%d-%.100s\r\n",
29- PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION);
30+ PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_RELEASE);
31 if (atomicio(vwrite, connection_out, client_version_string,
32 strlen(client_version_string)) != strlen(client_version_string))
33 fatal("write: %.100s", strerror(errno));
34diff --git a/sshd.c b/sshd.c
35index 2bc6679e5..9481272fc 100644
36--- a/sshd.c
37+++ b/sshd.c
38@@ -384,7 +384,7 @@ sshd_exchange_identification(struct ssh *ssh, int sock_in, int sock_out)
39 char remote_version[256]; /* Must be at least as big as buf. */
40
41 xasprintf(&server_version_string, "SSH-%d.%d-%.100s%s%s\r\n",
42- PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION,
43+ PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_RELEASE,
44 *options.version_addendum == '\0' ? "" : " ",
45 options.version_addendum);
46
47diff --git a/version.h b/version.h
48index 422dfbc3a..5e1ce0426 100644
49--- a/version.h
50+++ b/version.h
51@@ -3,4 +3,9 @@
52 #define SSH_VERSION "OpenSSH_7.9"
53
54 #define SSH_PORTABLE "p1"
55-#define SSH_RELEASE SSH_VERSION SSH_PORTABLE
56+#define SSH_RELEASE_MINIMUM SSH_VERSION SSH_PORTABLE
57+#ifdef SSH_EXTRAVERSION
58+#define SSH_RELEASE SSH_RELEASE_MINIMUM " " SSH_EXTRAVERSION
59+#else
60+#define SSH_RELEASE SSH_RELEASE_MINIMUM
61+#endif
diff --git a/debian/patches/request-rsa-sha2-cert-signatures.patch b/debian/patches/request-rsa-sha2-cert-signatures.patch
new file mode 100644
index 000000000..2c876be31
--- /dev/null
+++ b/debian/patches/request-rsa-sha2-cert-signatures.patch
@@ -0,0 +1,39 @@
1From d94226d4fcefbc398c5583e12b5d07ca33884ba4 Mon Sep 17 00:00:00 2001
2From: "djm@openbsd.org" <djm@openbsd.org>
3Date: Thu, 27 Dec 2018 23:02:11 +0000
4Subject: upstream: Request RSA-SHA2 signatures for
5
6rsa-sha2-{256|512}-cert-v01@openssh.com cert algorithms; ok markus@
7
8OpenBSD-Commit-ID: afc6f7ca216ccd821656d1c911d2a3deed685033
9
10Origin: upstream, https://anongit.mindrot.org/openssh.git/commit/?id=f429c1b2ef631f2855e51a790cf71761d752bbca
11Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=2944
12Bug-Debian: https://bugs.debian.org/923419
13Last-Update: 2019-02-28
14
15Patch-Name: request-rsa-sha2-cert-signatures.patch
16---
17 authfd.c | 8 +++++---
18 1 file changed, 5 insertions(+), 3 deletions(-)
19
20diff --git a/authfd.c b/authfd.c
21index ecdd869ab..62cbf8c19 100644
22--- a/authfd.c
23+++ b/authfd.c
24@@ -327,10 +327,12 @@ ssh_free_identitylist(struct ssh_identitylist *idl)
25 static u_int
26 agent_encode_alg(const struct sshkey *key, const char *alg)
27 {
28- if (alg != NULL && key->type == KEY_RSA) {
29- if (strcmp(alg, "rsa-sha2-256") == 0)
30+ if (alg != NULL && sshkey_type_plain(key->type) == KEY_RSA) {
31+ if (strcmp(alg, "rsa-sha2-256") == 0 ||
32+ strcmp(alg, "rsa-sha2-256-cert-v01@openssh.com") == 0)
33 return SSH_AGENT_RSA_SHA2_256;
34- else if (strcmp(alg, "rsa-sha2-512") == 0)
35+ if (strcmp(alg, "rsa-sha2-512") == 0 ||
36+ strcmp(alg, "rsa-sha2-512-cert-v01@openssh.com") == 0)
37 return SSH_AGENT_RSA_SHA2_512;
38 }
39 return 0;
diff --git a/debian/patches/restore-authorized_keys2.patch b/debian/patches/restore-authorized_keys2.patch
new file mode 100644
index 000000000..fcb1ac7e3
--- /dev/null
+++ b/debian/patches/restore-authorized_keys2.patch
@@ -0,0 +1,35 @@
1From cebe4b82b280810172877a7f3d489c506c9a0691 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 5 Mar 2017 02:02:11 +0000
4Subject: Restore reading authorized_keys2 by default
5
6Upstream seems to intend to gradually phase this out, so don't assume
7that this will remain the default forever. However, we were late in
8adopting the upstream sshd_config changes, so it makes sense to extend
9the grace period.
10
11Bug-Debian: https://bugs.debian.org/852320
12Forwarded: not-needed
13Last-Update: 2017-03-05
14
15Patch-Name: restore-authorized_keys2.patch
16---
17 sshd_config | 5 ++---
18 1 file changed, 2 insertions(+), 3 deletions(-)
19
20diff --git a/sshd_config b/sshd_config
21index ed8272f6d..ee9629102 100644
22--- a/sshd_config
23+++ b/sshd_config
24@@ -36,9 +36,8 @@
25
26 #PubkeyAuthentication yes
27
28-# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
29-# but this is overridden so installations will only check .ssh/authorized_keys
30-AuthorizedKeysFile .ssh/authorized_keys
31+# Expect .ssh/authorized_keys2 to be disregarded by default in future.
32+#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
33
34 #AuthorizedPrincipalsFile none
35
diff --git a/debian/patches/restore-tcp-wrappers.patch b/debian/patches/restore-tcp-wrappers.patch
new file mode 100644
index 000000000..fdc6cf18a
--- /dev/null
+++ b/debian/patches/restore-tcp-wrappers.patch
@@ -0,0 +1,172 @@
1From 389e16d0109d8c49a761cd7c267438b05c9ab984 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Tue, 7 Oct 2014 13:22:41 +0100
4Subject: Restore TCP wrappers support
5
6Support for TCP wrappers was dropped in OpenSSH 6.7. See this message
7and thread:
8
9 https://lists.mindrot.org/pipermail/openssh-unix-dev/2014-April/032497.html
10
11It is true that this reduces preauth attack surface in sshd. On the
12other hand, this support seems to be quite widely used, and abruptly
13dropping it (from the perspective of users who don't read
14openssh-unix-dev) could easily cause more serious problems in practice.
15
16It's not entirely clear what the right long-term answer for Debian is,
17but it at least probably doesn't involve dropping this feature shortly
18before a freeze.
19
20Forwarded: not-needed
21Last-Update: 2018-08-24
22
23Patch-Name: restore-tcp-wrappers.patch
24---
25 configure.ac | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
26 sshd.8 | 7 +++++++
27 sshd.c | 25 +++++++++++++++++++++++
28 3 files changed, 89 insertions(+)
29
30diff --git a/configure.ac b/configure.ac
31index 023e7cc55..917300b43 100644
32--- a/configure.ac
33+++ b/configure.ac
34@@ -1517,6 +1517,62 @@ else
35 AC_MSG_RESULT([no])
36 fi
37
38+# Check whether user wants TCP wrappers support
39+TCPW_MSG="no"
40+AC_ARG_WITH([tcp-wrappers],
41+ [ --with-tcp-wrappers[[=PATH]] Enable tcpwrappers support (optionally in PATH)],
42+ [
43+ if test "x$withval" != "xno" ; then
44+ saved_LIBS="$LIBS"
45+ saved_LDFLAGS="$LDFLAGS"
46+ saved_CPPFLAGS="$CPPFLAGS"
47+ if test -n "${withval}" && \
48+ test "x${withval}" != "xyes"; then
49+ if test -d "${withval}/lib"; then
50+ if test -n "${need_dash_r}"; then
51+ LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
52+ else
53+ LDFLAGS="-L${withval}/lib ${LDFLAGS}"
54+ fi
55+ else
56+ if test -n "${need_dash_r}"; then
57+ LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
58+ else
59+ LDFLAGS="-L${withval} ${LDFLAGS}"
60+ fi
61+ fi
62+ if test -d "${withval}/include"; then
63+ CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
64+ else
65+ CPPFLAGS="-I${withval} ${CPPFLAGS}"
66+ fi
67+ fi
68+ LIBS="-lwrap $LIBS"
69+ AC_MSG_CHECKING([for libwrap])
70+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
71+#include <sys/types.h>
72+#include <sys/socket.h>
73+#include <netinet/in.h>
74+#include <tcpd.h>
75+int deny_severity = 0, allow_severity = 0;
76+ ]], [[
77+ hosts_access(0);
78+ ]])], [
79+ AC_MSG_RESULT([yes])
80+ AC_DEFINE([LIBWRAP], [1],
81+ [Define if you want
82+ TCP Wrappers support])
83+ SSHDLIBS="$SSHDLIBS -lwrap"
84+ TCPW_MSG="yes"
85+ ], [
86+ AC_MSG_ERROR([*** libwrap missing])
87+
88+ ])
89+ LIBS="$saved_LIBS"
90+ fi
91+ ]
92+)
93+
94 # Check whether user wants to use ldns
95 LDNS_MSG="no"
96 AC_ARG_WITH(ldns,
97@@ -5329,6 +5385,7 @@ echo " PAM support: $PAM_MSG"
98 echo " OSF SIA support: $SIA_MSG"
99 echo " KerberosV support: $KRB5_MSG"
100 echo " SELinux support: $SELINUX_MSG"
101+echo " TCP Wrappers support: $TCPW_MSG"
102 echo " MD5 password support: $MD5_MSG"
103 echo " libedit support: $LIBEDIT_MSG"
104 echo " libldns support: $LDNS_MSG"
105diff --git a/sshd.8 b/sshd.8
106index fb133c14b..57a7fd66b 100644
107--- a/sshd.8
108+++ b/sshd.8
109@@ -873,6 +873,12 @@ the user's home directory becomes accessible.
110 This file should be writable only by the user, and need not be
111 readable by anyone else.
112 .Pp
113+.It Pa /etc/hosts.allow
114+.It Pa /etc/hosts.deny
115+Access controls that should be enforced by tcp-wrappers are defined here.
116+Further details are described in
117+.Xr hosts_access 5 .
118+.Pp
119 .It Pa /etc/hosts.equiv
120 This file is for host-based authentication (see
121 .Xr ssh 1 ) .
122@@ -975,6 +981,7 @@ The content of this file is not sensitive; it can be world-readable.
123 .Xr ssh-keygen 1 ,
124 .Xr ssh-keyscan 1 ,
125 .Xr chroot 2 ,
126+.Xr hosts_access 5 ,
127 .Xr login.conf 5 ,
128 .Xr moduli 5 ,
129 .Xr sshd_config 5 ,
130diff --git a/sshd.c b/sshd.c
131index 539a000fd..673db87f6 100644
132--- a/sshd.c
133+++ b/sshd.c
134@@ -127,6 +127,13 @@
135 #include <Security/AuthSession.h>
136 #endif
137
138+#ifdef LIBWRAP
139+#include <tcpd.h>
140+#include <syslog.h>
141+int allow_severity;
142+int deny_severity;
143+#endif /* LIBWRAP */
144+
145 /* Re-exec fds */
146 #define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1)
147 #define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2)
148@@ -2099,6 +2106,24 @@ main(int ac, char **av)
149 #ifdef SSH_AUDIT_EVENTS
150 audit_connection_from(remote_ip, remote_port);
151 #endif
152+#ifdef LIBWRAP
153+ allow_severity = options.log_facility|LOG_INFO;
154+ deny_severity = options.log_facility|LOG_WARNING;
155+ /* Check whether logins are denied from this host. */
156+ if (packet_connection_is_on_socket()) {
157+ struct request_info req;
158+
159+ request_init(&req, RQ_DAEMON, __progname, RQ_FILE, sock_in, 0);
160+ fromhost(&req);
161+
162+ if (!hosts_access(&req)) {
163+ debug("Connection refused by tcp wrapper");
164+ refuse(&req);
165+ /* NOTREACHED */
166+ fatal("libwrap refuse returns");
167+ }
168+ }
169+#endif /* LIBWRAP */
170
171 rdomain = ssh_packet_rdomain_in(ssh);
172
diff --git a/debian/patches/revert-ipqos-defaults.patch b/debian/patches/revert-ipqos-defaults.patch
new file mode 100644
index 000000000..a329b9be1
--- /dev/null
+++ b/debian/patches/revert-ipqos-defaults.patch
@@ -0,0 +1,93 @@
1From 6b56cd57db9061296231f14d537f1ebaf25e8877 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Mon, 8 Apr 2019 10:46:29 +0100
4Subject: Revert "upstream: Update default IPQoS in ssh(1), sshd(8) to DSCP
5 AF21 for"
6
7This reverts commit 5ee8448ad7c306f05a9f56769f95336a8269f379.
8
9The IPQoS default changes have some unfortunate interactions with
10iptables (see https://bugs.debian.org/923880) and VMware, so I'm
11temporarily reverting them until those have been fixed.
12
13Bug-Debian: https://bugs.debian.org/923879
14Bug-Debian: https://bugs.debian.org/926229
15Bug-Ubuntu: https://bugs.launchpad.net/1822370
16Last-Update: 2019-04-08
17
18Patch-Name: revert-ipqos-defaults.patch
19---
20 readconf.c | 4 ++--
21 servconf.c | 4 ++--
22 ssh_config.5 | 6 ++----
23 sshd_config.5 | 6 ++----
24 4 files changed, 8 insertions(+), 12 deletions(-)
25
26diff --git a/readconf.c b/readconf.c
27index 661b8bf40..6d046f063 100644
28--- a/readconf.c
29+++ b/readconf.c
30@@ -2133,9 +2133,9 @@ fill_default_options(Options * options)
31 if (options->visual_host_key == -1)
32 options->visual_host_key = 0;
33 if (options->ip_qos_interactive == -1)
34- options->ip_qos_interactive = IPTOS_DSCP_AF21;
35+ options->ip_qos_interactive = IPTOS_LOWDELAY;
36 if (options->ip_qos_bulk == -1)
37- options->ip_qos_bulk = IPTOS_DSCP_CS1;
38+ options->ip_qos_bulk = IPTOS_THROUGHPUT;
39 if (options->request_tty == -1)
40 options->request_tty = REQUEST_TTY_AUTO;
41 if (options->proxy_use_fdpass == -1)
42diff --git a/servconf.c b/servconf.c
43index c5dd617ef..bf2669147 100644
44--- a/servconf.c
45+++ b/servconf.c
46@@ -403,9 +403,9 @@ fill_default_server_options(ServerOptions *options)
47 if (options->permit_tun == -1)
48 options->permit_tun = SSH_TUNMODE_NO;
49 if (options->ip_qos_interactive == -1)
50- options->ip_qos_interactive = IPTOS_DSCP_AF21;
51+ options->ip_qos_interactive = IPTOS_LOWDELAY;
52 if (options->ip_qos_bulk == -1)
53- options->ip_qos_bulk = IPTOS_DSCP_CS1;
54+ options->ip_qos_bulk = IPTOS_THROUGHPUT;
55 if (options->version_addendum == NULL)
56 options->version_addendum = xstrdup("");
57 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
58diff --git a/ssh_config.5 b/ssh_config.5
59index 1a8e24bd1..f6c1b3b33 100644
60--- a/ssh_config.5
61+++ b/ssh_config.5
62@@ -1055,11 +1055,9 @@ If one argument is specified, it is used as the packet class unconditionally.
63 If two values are specified, the first is automatically selected for
64 interactive sessions and the second for non-interactive sessions.
65 The default is
66-.Cm af21
67-(Low-Latency Data)
68+.Cm lowdelay
69 for interactive sessions and
70-.Cm cs1
71-(Lower Effort)
72+.Cm throughput
73 for non-interactive sessions.
74 .It Cm KbdInteractiveAuthentication
75 Specifies whether to use keyboard-interactive authentication.
76diff --git a/sshd_config.5 b/sshd_config.5
77index ba50a30f1..03f813e72 100644
78--- a/sshd_config.5
79+++ b/sshd_config.5
80@@ -866,11 +866,9 @@ If one argument is specified, it is used as the packet class unconditionally.
81 If two values are specified, the first is automatically selected for
82 interactive sessions and the second for non-interactive sessions.
83 The default is
84-.Cm af21
85-(Low-Latency Data)
86+.Cm lowdelay
87 for interactive sessions and
88-.Cm cs1
89-(Lower Effort)
90+.Cm throughput
91 for non-interactive sessions.
92 .It Cm KbdInteractiveAuthentication
93 Specifies whether to allow keyboard-interactive authentication.
diff --git a/debian/patches/sanitize-scp-filenames-via-snmprintf.patch b/debian/patches/sanitize-scp-filenames-via-snmprintf.patch
new file mode 100644
index 000000000..e58b8b1bd
--- /dev/null
+++ b/debian/patches/sanitize-scp-filenames-via-snmprintf.patch
@@ -0,0 +1,276 @@
1From 11b88754cadcad0ba79b4ffcc127223248dccb54 Mon Sep 17 00:00:00 2001
2From: "dtucker@openbsd.org" <dtucker@openbsd.org>
3Date: Wed, 23 Jan 2019 08:01:46 +0000
4Subject: upstream: Sanitize scp filenames via snmprintf. To do this we move
5
6the progressmeter formatting outside of signal handler context and have the
7atomicio callback called for EINTR too. bz#2434 with contributions from djm
8and jjelen at redhat.com, ok djm@
9
10OpenBSD-Commit-ID: 1af61c1f70e4f3bd8ab140b9f1fa699481db57d8
11
12CVE-2019-6109
13
14Origin: backport, https://anongit.mindrot.org/openssh.git/commit/?id=8976f1c4b2721c26e878151f52bdf346dfe2d54c
15Bug-Debian: https://bugs.debian.org/793412
16Last-Update: 2019-02-08
17
18Patch-Name: sanitize-scp-filenames-via-snmprintf.patch
19---
20 atomicio.c | 20 ++++++++++++++-----
21 progressmeter.c | 53 ++++++++++++++++++++++---------------------------
22 progressmeter.h | 3 ++-
23 scp.c | 1 +
24 sftp-client.c | 16 ++++++++-------
25 5 files changed, 51 insertions(+), 42 deletions(-)
26
27diff --git a/atomicio.c b/atomicio.c
28index f854a06f5..d91bd7621 100644
29--- a/atomicio.c
30+++ b/atomicio.c
31@@ -1,4 +1,4 @@
32-/* $OpenBSD: atomicio.c,v 1.28 2016/07/27 23:18:12 djm Exp $ */
33+/* $OpenBSD: atomicio.c,v 1.29 2019/01/23 08:01:46 dtucker Exp $ */
34 /*
35 * Copyright (c) 2006 Damien Miller. All rights reserved.
36 * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
37@@ -65,9 +65,14 @@ atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n,
38 res = (f) (fd, s + pos, n - pos);
39 switch (res) {
40 case -1:
41- if (errno == EINTR)
42+ if (errno == EINTR) {
43+ /* possible SIGALARM, update callback */
44+ if (cb != NULL && cb(cb_arg, 0) == -1) {
45+ errno = EINTR;
46+ return pos;
47+ }
48 continue;
49- if (errno == EAGAIN || errno == EWOULDBLOCK) {
50+ } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
51 #ifndef BROKEN_READ_COMPARISON
52 (void)poll(&pfd, 1, -1);
53 #endif
54@@ -122,9 +127,14 @@ atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
55 res = (f) (fd, iov, iovcnt);
56 switch (res) {
57 case -1:
58- if (errno == EINTR)
59+ if (errno == EINTR) {
60+ /* possible SIGALARM, update callback */
61+ if (cb != NULL && cb(cb_arg, 0) == -1) {
62+ errno = EINTR;
63+ return pos;
64+ }
65 continue;
66- if (errno == EAGAIN || errno == EWOULDBLOCK) {
67+ } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
68 #ifndef BROKEN_READV_COMPARISON
69 (void)poll(&pfd, 1, -1);
70 #endif
71diff --git a/progressmeter.c b/progressmeter.c
72index fe9bf52e4..add462dde 100644
73--- a/progressmeter.c
74+++ b/progressmeter.c
75@@ -1,4 +1,4 @@
76-/* $OpenBSD: progressmeter.c,v 1.45 2016/06/30 05:17:05 dtucker Exp $ */
77+/* $OpenBSD: progressmeter.c,v 1.46 2019/01/23 08:01:46 dtucker Exp $ */
78 /*
79 * Copyright (c) 2003 Nils Nordman. All rights reserved.
80 *
81@@ -31,6 +31,7 @@
82
83 #include <errno.h>
84 #include <signal.h>
85+#include <stdarg.h>
86 #include <stdio.h>
87 #include <string.h>
88 #include <time.h>
89@@ -39,6 +40,7 @@
90 #include "progressmeter.h"
91 #include "atomicio.h"
92 #include "misc.h"
93+#include "utf8.h"
94
95 #define DEFAULT_WINSIZE 80
96 #define MAX_WINSIZE 512
97@@ -61,7 +63,7 @@ static void setscreensize(void);
98 void refresh_progress_meter(void);
99
100 /* signal handler for updating the progress meter */
101-static void update_progress_meter(int);
102+static void sig_alarm(int);
103
104 static double start; /* start progress */
105 static double last_update; /* last progress update */
106@@ -74,6 +76,7 @@ static long stalled; /* how long we have been stalled */
107 static int bytes_per_second; /* current speed in bytes per second */
108 static int win_size; /* terminal window size */
109 static volatile sig_atomic_t win_resized; /* for window resizing */
110+static volatile sig_atomic_t alarm_fired;
111
112 /* units for format_size */
113 static const char unit[] = " KMGT";
114@@ -126,9 +129,17 @@ refresh_progress_meter(void)
115 off_t bytes_left;
116 int cur_speed;
117 int hours, minutes, seconds;
118- int i, len;
119 int file_len;
120
121+ if ((!alarm_fired && !win_resized) || !can_output())
122+ return;
123+ alarm_fired = 0;
124+
125+ if (win_resized) {
126+ setscreensize();
127+ win_resized = 0;
128+ }
129+
130 transferred = *counter - (cur_pos ? cur_pos : start_pos);
131 cur_pos = *counter;
132 now = monotime_double();
133@@ -158,16 +169,11 @@ refresh_progress_meter(void)
134
135 /* filename */
136 buf[0] = '\0';
137- file_len = win_size - 35;
138+ file_len = win_size - 36;
139 if (file_len > 0) {
140- len = snprintf(buf, file_len + 1, "\r%s", file);
141- if (len < 0)
142- len = 0;
143- if (len >= file_len + 1)
144- len = file_len;
145- for (i = len; i < file_len; i++)
146- buf[i] = ' ';
147- buf[file_len] = '\0';
148+ buf[0] = '\r';
149+ snmprintf(buf+1, sizeof(buf)-1 , &file_len, "%*s",
150+ file_len * -1, file);
151 }
152
153 /* percent of transfer done */
154@@ -228,22 +234,11 @@ refresh_progress_meter(void)
155
156 /*ARGSUSED*/
157 static void
158-update_progress_meter(int ignore)
159+sig_alarm(int ignore)
160 {
161- int save_errno;
162-
163- save_errno = errno;
164-
165- if (win_resized) {
166- setscreensize();
167- win_resized = 0;
168- }
169- if (can_output())
170- refresh_progress_meter();
171-
172- signal(SIGALRM, update_progress_meter);
173+ signal(SIGALRM, sig_alarm);
174+ alarm_fired = 1;
175 alarm(UPDATE_INTERVAL);
176- errno = save_errno;
177 }
178
179 void
180@@ -259,10 +254,9 @@ start_progress_meter(const char *f, off_t filesize, off_t *ctr)
181 bytes_per_second = 0;
182
183 setscreensize();
184- if (can_output())
185- refresh_progress_meter();
186+ refresh_progress_meter();
187
188- signal(SIGALRM, update_progress_meter);
189+ signal(SIGALRM, sig_alarm);
190 signal(SIGWINCH, sig_winch);
191 alarm(UPDATE_INTERVAL);
192 }
193@@ -286,6 +280,7 @@ stop_progress_meter(void)
194 static void
195 sig_winch(int sig)
196 {
197+ signal(SIGWINCH, sig_winch);
198 win_resized = 1;
199 }
200
201diff --git a/progressmeter.h b/progressmeter.h
202index bf179dca6..8f6678060 100644
203--- a/progressmeter.h
204+++ b/progressmeter.h
205@@ -1,4 +1,4 @@
206-/* $OpenBSD: progressmeter.h,v 1.3 2015/01/14 13:54:13 djm Exp $ */
207+/* $OpenBSD: progressmeter.h,v 1.4 2019/01/23 08:01:46 dtucker Exp $ */
208 /*
209 * Copyright (c) 2002 Nils Nordman. All rights reserved.
210 *
211@@ -24,4 +24,5 @@
212 */
213
214 void start_progress_meter(const char *, off_t, off_t *);
215+void refresh_progress_meter(void);
216 void stop_progress_meter(void);
217diff --git a/scp.c b/scp.c
218index 7163d33dc..80308573c 100644
219--- a/scp.c
220+++ b/scp.c
221@@ -593,6 +593,7 @@ scpio(void *_cnt, size_t s)
222 off_t *cnt = (off_t *)_cnt;
223
224 *cnt += s;
225+ refresh_progress_meter();
226 if (limit_kbps > 0)
227 bandwidth_limit(&bwlimit, s);
228 return 0;
229diff --git a/sftp-client.c b/sftp-client.c
230index 4986d6d8d..2bc698f86 100644
231--- a/sftp-client.c
232+++ b/sftp-client.c
233@@ -101,7 +101,9 @@ sftpio(void *_bwlimit, size_t amount)
234 {
235 struct bwlimit *bwlimit = (struct bwlimit *)_bwlimit;
236
237- bandwidth_limit(bwlimit, amount);
238+ refresh_progress_meter();
239+ if (bwlimit != NULL)
240+ bandwidth_limit(bwlimit, amount);
241 return 0;
242 }
243
244@@ -121,8 +123,8 @@ send_msg(struct sftp_conn *conn, struct sshbuf *m)
245 iov[1].iov_base = (u_char *)sshbuf_ptr(m);
246 iov[1].iov_len = sshbuf_len(m);
247
248- if (atomiciov6(writev, conn->fd_out, iov, 2,
249- conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_out) !=
250+ if (atomiciov6(writev, conn->fd_out, iov, 2, sftpio,
251+ conn->limit_kbps > 0 ? &conn->bwlimit_out : NULL) !=
252 sshbuf_len(m) + sizeof(mlen))
253 fatal("Couldn't send packet: %s", strerror(errno));
254
255@@ -138,8 +140,8 @@ get_msg_extended(struct sftp_conn *conn, struct sshbuf *m, int initial)
256
257 if ((r = sshbuf_reserve(m, 4, &p)) != 0)
258 fatal("%s: buffer error: %s", __func__, ssh_err(r));
259- if (atomicio6(read, conn->fd_in, p, 4,
260- conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in) != 4) {
261+ if (atomicio6(read, conn->fd_in, p, 4, sftpio,
262+ conn->limit_kbps > 0 ? &conn->bwlimit_in : NULL) != 4) {
263 if (errno == EPIPE || errno == ECONNRESET)
264 fatal("Connection closed");
265 else
266@@ -157,8 +159,8 @@ get_msg_extended(struct sftp_conn *conn, struct sshbuf *m, int initial)
267
268 if ((r = sshbuf_reserve(m, msg_len, &p)) != 0)
269 fatal("%s: buffer error: %s", __func__, ssh_err(r));
270- if (atomicio6(read, conn->fd_in, p, msg_len,
271- conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in)
272+ if (atomicio6(read, conn->fd_in, p, msg_len, sftpio,
273+ conn->limit_kbps > 0 ? &conn->bwlimit_in : NULL)
274 != msg_len) {
275 if (errno == EPIPE)
276 fatal("Connection closed");
diff --git a/debian/patches/scp-disallow-dot-or-empty-filename.patch b/debian/patches/scp-disallow-dot-or-empty-filename.patch
new file mode 100644
index 000000000..716f2ffa8
--- /dev/null
+++ b/debian/patches/scp-disallow-dot-or-empty-filename.patch
@@ -0,0 +1,32 @@
1From dee21e97428e69d30e2d15c71f3e7cc08bf8e4f8 Mon Sep 17 00:00:00 2001
2From: "djm@openbsd.org" <djm@openbsd.org>
3Date: Fri, 16 Nov 2018 03:03:10 +0000
4Subject: upstream: disallow empty incoming filename or ones that refer to the
5
6current directory; based on report/patch from Harry Sintonen
7
8OpenBSD-Commit-ID: f27651b30eaee2df49540ab68d030865c04f6de9
9
10Origin: upstream, https://anongit.mindrot.org/openssh.git/commit/?id=6010c0303a422a9c5fa8860c061bf7105eb7f8b2
11Bug-Debian: https://bugs.debian.org/919101
12Last-Update: 2019-01-12
13
14Patch-Name: scp-disallow-dot-or-empty-filename.patch
15---
16 scp.c | 3 ++-
17 1 file changed, 2 insertions(+), 1 deletion(-)
18
19diff --git a/scp.c b/scp.c
20index ed2864250..7163d33dc 100644
21--- a/scp.c
22+++ b/scp.c
23@@ -1114,7 +1114,8 @@ sink(int argc, char **argv)
24 SCREWUP("size out of range");
25 size = (off_t)ull;
26
27- if ((strchr(cp, '/') != NULL) || (strcmp(cp, "..") == 0)) {
28+ if (*cp == '\0' || strchr(cp, '/') != NULL ||
29+ strcmp(cp, ".") == 0 || strcmp(cp, "..") == 0) {
30 run_err("error: unexpected filename: %s", cp);
31 exit(1);
32 }
diff --git a/debian/patches/scp-handle-braces.patch b/debian/patches/scp-handle-braces.patch
new file mode 100644
index 000000000..0cbdcfdc0
--- /dev/null
+++ b/debian/patches/scp-handle-braces.patch
@@ -0,0 +1,353 @@
1From 7a3fa37583d4abf128f7f4c6eb1e7ffc90115eab Mon Sep 17 00:00:00 2001
2From: "djm@openbsd.org" <djm@openbsd.org>
3Date: Sun, 10 Feb 2019 11:15:52 +0000
4Subject: upstream: when checking that filenames sent by the server side
5
6match what the client requested, be prepared to handle shell-style brace
7alternations, e.g. "{foo,bar}".
8
9"looks good to me" millert@ + in snaps for the last week courtesy
10deraadt@
11
12OpenBSD-Commit-ID: 3b1ce7639b0b25b2248e3a30f561a548f6815f3e
13
14Origin: upstream, https://anongit.mindrot.org/openssh.git/commit/?id=3d896c157c722bc47adca51a58dca859225b5874
15Bug-Debian: https://bugs.debian.org/923486
16Last-Update: 2019-03-01
17
18Patch-Name: scp-handle-braces.patch
19---
20 scp.c | 280 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
21 1 file changed, 269 insertions(+), 11 deletions(-)
22
23diff --git a/scp.c b/scp.c
24index 035037bcc..3888baab0 100644
25--- a/scp.c
26+++ b/scp.c
27@@ -635,6 +635,253 @@ parse_scp_uri(const char *uri, char **userp, char **hostp, int *portp,
28 return r;
29 }
30
31+/* Appends a string to an array; returns 0 on success, -1 on alloc failure */
32+static int
33+append(char *cp, char ***ap, size_t *np)
34+{
35+ char **tmp;
36+
37+ if ((tmp = reallocarray(*ap, *np + 1, sizeof(*tmp))) == NULL)
38+ return -1;
39+ tmp[(*np)] = cp;
40+ (*np)++;
41+ *ap = tmp;
42+ return 0;
43+}
44+
45+/*
46+ * Finds the start and end of the first brace pair in the pattern.
47+ * returns 0 on success or -1 for invalid patterns.
48+ */
49+static int
50+find_brace(const char *pattern, int *startp, int *endp)
51+{
52+ int i;
53+ int in_bracket, brace_level;
54+
55+ *startp = *endp = -1;
56+ in_bracket = brace_level = 0;
57+ for (i = 0; i < INT_MAX && *endp < 0 && pattern[i] != '\0'; i++) {
58+ switch (pattern[i]) {
59+ case '\\':
60+ /* skip next character */
61+ if (pattern[i + 1] != '\0')
62+ i++;
63+ break;
64+ case '[':
65+ in_bracket = 1;
66+ break;
67+ case ']':
68+ in_bracket = 0;
69+ break;
70+ case '{':
71+ if (in_bracket)
72+ break;
73+ if (pattern[i + 1] == '}') {
74+ /* Protect a single {}, for find(1), like csh */
75+ i++; /* skip */
76+ break;
77+ }
78+ if (*startp == -1)
79+ *startp = i;
80+ brace_level++;
81+ break;
82+ case '}':
83+ if (in_bracket)
84+ break;
85+ if (*startp < 0) {
86+ /* Unbalanced brace */
87+ return -1;
88+ }
89+ if (--brace_level <= 0)
90+ *endp = i;
91+ break;
92+ }
93+ }
94+ /* unbalanced brackets/braces */
95+ if (*endp < 0 && (*startp >= 0 || in_bracket))
96+ return -1;
97+ return 0;
98+}
99+
100+/*
101+ * Assembles and records a successfully-expanded pattern, returns -1 on
102+ * alloc failure.
103+ */
104+static int
105+emit_expansion(const char *pattern, int brace_start, int brace_end,
106+ int sel_start, int sel_end, char ***patternsp, size_t *npatternsp)
107+{
108+ char *cp;
109+ int o = 0, tail_len = strlen(pattern + brace_end + 1);
110+
111+ if ((cp = malloc(brace_start + (sel_end - sel_start) +
112+ tail_len + 1)) == NULL)
113+ return -1;
114+
115+ /* Pattern before initial brace */
116+ if (brace_start > 0) {
117+ memcpy(cp, pattern, brace_start);
118+ o = brace_start;
119+ }
120+ /* Current braced selection */
121+ if (sel_end - sel_start > 0) {
122+ memcpy(cp + o, pattern + sel_start,
123+ sel_end - sel_start);
124+ o += sel_end - sel_start;
125+ }
126+ /* Remainder of pattern after closing brace */
127+ if (tail_len > 0) {
128+ memcpy(cp + o, pattern + brace_end + 1, tail_len);
129+ o += tail_len;
130+ }
131+ cp[o] = '\0';
132+ if (append(cp, patternsp, npatternsp) != 0) {
133+ free(cp);
134+ return -1;
135+ }
136+ return 0;
137+}
138+
139+/*
140+ * Expand the first encountered brace in pattern, appending the expanded
141+ * patterns it yielded to the *patternsp array.
142+ *
143+ * Returns 0 on success or -1 on allocation failure.
144+ *
145+ * Signals whether expansion was performed via *expanded and whether
146+ * pattern was invalid via *invalid.
147+ */
148+static int
149+brace_expand_one(const char *pattern, char ***patternsp, size_t *npatternsp,
150+ int *expanded, int *invalid)
151+{
152+ int i;
153+ int in_bracket, brace_start, brace_end, brace_level;
154+ int sel_start, sel_end;
155+
156+ *invalid = *expanded = 0;
157+
158+ if (find_brace(pattern, &brace_start, &brace_end) != 0) {
159+ *invalid = 1;
160+ return 0;
161+ } else if (brace_start == -1)
162+ return 0;
163+
164+ in_bracket = brace_level = 0;
165+ for (i = sel_start = brace_start + 1; i < brace_end; i++) {
166+ switch (pattern[i]) {
167+ case '{':
168+ if (in_bracket)
169+ break;
170+ brace_level++;
171+ break;
172+ case '}':
173+ if (in_bracket)
174+ break;
175+ brace_level--;
176+ break;
177+ case '[':
178+ in_bracket = 1;
179+ break;
180+ case ']':
181+ in_bracket = 0;
182+ break;
183+ case '\\':
184+ if (i < brace_end - 1)
185+ i++; /* skip */
186+ break;
187+ }
188+ if (pattern[i] == ',' || i == brace_end - 1) {
189+ if (in_bracket || brace_level > 0)
190+ continue;
191+ /* End of a selection, emit an expanded pattern */
192+
193+ /* Adjust end index for last selection */
194+ sel_end = (i == brace_end - 1) ? brace_end : i;
195+ if (emit_expansion(pattern, brace_start, brace_end,
196+ sel_start, sel_end, patternsp, npatternsp) != 0)
197+ return -1;
198+ /* move on to the next selection */
199+ sel_start = i + 1;
200+ continue;
201+ }
202+ }
203+ if (in_bracket || brace_level > 0) {
204+ *invalid = 1;
205+ return 0;
206+ }
207+ /* success */
208+ *expanded = 1;
209+ return 0;
210+}
211+
212+/* Expand braces from pattern. Returns 0 on success, -1 on failure */
213+static int
214+brace_expand(const char *pattern, char ***patternsp, size_t *npatternsp)
215+{
216+ char *cp, *cp2, **active = NULL, **done = NULL;
217+ size_t i, nactive = 0, ndone = 0;
218+ int ret = -1, invalid = 0, expanded = 0;
219+
220+ *patternsp = NULL;
221+ *npatternsp = 0;
222+
223+ /* Start the worklist with the original pattern */
224+ if ((cp = strdup(pattern)) == NULL)
225+ return -1;
226+ if (append(cp, &active, &nactive) != 0) {
227+ free(cp);
228+ return -1;
229+ }
230+ while (nactive > 0) {
231+ cp = active[nactive - 1];
232+ nactive--;
233+ if (brace_expand_one(cp, &active, &nactive,
234+ &expanded, &invalid) == -1) {
235+ free(cp);
236+ goto fail;
237+ }
238+ if (invalid)
239+ fatal("%s: invalid brace pattern \"%s\"", __func__, cp);
240+ if (expanded) {
241+ /*
242+ * Current entry expanded to new entries on the
243+ * active list; discard the progenitor pattern.
244+ */
245+ free(cp);
246+ continue;
247+ }
248+ /*
249+ * Pattern did not expand; append the finename component to
250+ * the completed list
251+ */
252+ if ((cp2 = strrchr(cp, '/')) != NULL)
253+ *cp2++ = '\0';
254+ else
255+ cp2 = cp;
256+ if (append(xstrdup(cp2), &done, &ndone) != 0) {
257+ free(cp);
258+ goto fail;
259+ }
260+ free(cp);
261+ }
262+ /* success */
263+ *patternsp = done;
264+ *npatternsp = ndone;
265+ done = NULL;
266+ ndone = 0;
267+ ret = 0;
268+ fail:
269+ for (i = 0; i < nactive; i++)
270+ free(active[i]);
271+ free(active);
272+ for (i = 0; i < ndone; i++)
273+ free(done[i]);
274+ free(done);
275+ return ret;
276+}
277+
278 void
279 toremote(int argc, char **argv)
280 {
281@@ -998,7 +1245,8 @@ sink(int argc, char **argv, const char *src)
282 unsigned long long ull;
283 int setimes, targisdir, wrerrno = 0;
284 char ch, *cp, *np, *targ, *why, *vect[1], buf[2048], visbuf[2048];
285- char *src_copy = NULL, *restrict_pattern = NULL;
286+ char **patterns = NULL;
287+ size_t n, npatterns = 0;
288 struct timeval tv[2];
289
290 #define atime tv[0]
291@@ -1028,16 +1276,13 @@ sink(int argc, char **argv, const char *src)
292 * Prepare to try to restrict incoming filenames to match
293 * the requested destination file glob.
294 */
295- if ((src_copy = strdup(src)) == NULL)
296- fatal("strdup failed");
297- if ((restrict_pattern = strrchr(src_copy, '/')) != NULL) {
298- *restrict_pattern++ = '\0';
299- }
300+ if (brace_expand(src, &patterns, &npatterns) != 0)
301+ fatal("%s: could not expand pattern", __func__);
302 }
303 for (first = 1;; first = 0) {
304 cp = buf;
305 if (atomicio(read, remin, cp, 1) != 1)
306- return;
307+ goto done;
308 if (*cp++ == '\n')
309 SCREWUP("unexpected <newline>");
310 do {
311@@ -1063,7 +1308,7 @@ sink(int argc, char **argv, const char *src)
312 }
313 if (buf[0] == 'E') {
314 (void) atomicio(vwrite, remout, "", 1);
315- return;
316+ goto done;
317 }
318 if (ch == '\n')
319 *--cp = 0;
320@@ -1138,9 +1383,14 @@ sink(int argc, char **argv, const char *src)
321 run_err("error: unexpected filename: %s", cp);
322 exit(1);
323 }
324- if (restrict_pattern != NULL &&
325- fnmatch(restrict_pattern, cp, 0) != 0)
326- SCREWUP("filename does not match request");
327+ if (npatterns > 0) {
328+ for (n = 0; n < npatterns; n++) {
329+ if (fnmatch(patterns[n], cp, 0) == 0)
330+ break;
331+ }
332+ if (n >= npatterns)
333+ SCREWUP("filename does not match request");
334+ }
335 if (targisdir) {
336 static char *namebuf;
337 static size_t cursize;
338@@ -1299,7 +1549,15 @@ bad: run_err("%s: %s", np, strerror(errno));
339 break;
340 }
341 }
342+done:
343+ for (n = 0; n < npatterns; n++)
344+ free(patterns[n]);
345+ free(patterns);
346+ return;
347 screwup:
348+ for (n = 0; n < npatterns; n++)
349+ free(patterns[n]);
350+ free(patterns);
351 run_err("protocol error: %s", why);
352 exit(1);
353 }
diff --git a/debian/patches/scp-quoting.patch b/debian/patches/scp-quoting.patch
new file mode 100644
index 000000000..d054b2a82
--- /dev/null
+++ b/debian/patches/scp-quoting.patch
@@ -0,0 +1,41 @@
1From eefdc7046766b52e39f1b6eafcde22c1e013ce9f Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Nicolas=20Valc=C3=A1rcel?= <nvalcarcel@ubuntu.com>
3Date: Sun, 9 Feb 2014 16:09:59 +0000
4Subject: Adjust scp quoting in verbose mode
5
6Tweak scp's reporting of filenames in verbose mode to be a bit less
7confusing with spaces.
8
9This should be revised to mimic real shell quoting.
10
11Bug-Ubuntu: https://bugs.launchpad.net/bugs/89945
12Last-Update: 2010-02-27
13
14Patch-Name: scp-quoting.patch
15---
16 scp.c | 12 ++++++++++--
17 1 file changed, 10 insertions(+), 2 deletions(-)
18
19diff --git a/scp.c b/scp.c
20index 60682c687..ed2864250 100644
21--- a/scp.c
22+++ b/scp.c
23@@ -198,8 +198,16 @@ do_local_cmd(arglist *a)
24
25 if (verbose_mode) {
26 fprintf(stderr, "Executing:");
27- for (i = 0; i < a->num; i++)
28- fmprintf(stderr, " %s", a->list[i]);
29+ for (i = 0; i < a->num; i++) {
30+ if (i == 0)
31+ fmprintf(stderr, " %s", a->list[i]);
32+ else
33+ /*
34+ * TODO: misbehaves if a->list[i] contains a
35+ * single quote
36+ */
37+ fmprintf(stderr, " '%s'", a->list[i]);
38+ }
39 fprintf(stderr, "\n");
40 }
41 if ((pid = fork()) == -1)
diff --git a/debian/patches/seccomp-s390-flock-ipc.patch b/debian/patches/seccomp-s390-flock-ipc.patch
new file mode 100644
index 000000000..e864427bd
--- /dev/null
+++ b/debian/patches/seccomp-s390-flock-ipc.patch
@@ -0,0 +1,47 @@
1From 690939ba320d93e6f3ab5266bea94d8fb06c8bae Mon Sep 17 00:00:00 2001
2From: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
3Date: Tue, 9 May 2017 10:53:04 -0300
4Subject: Allow flock and ipc syscall for s390 architecture
5
6In order to use the OpenSSL-ibmpkcs11 engine it is needed to allow flock
7and ipc calls, because this engine calls OpenCryptoki (a PKCS#11
8implementation) which calls the libraries that will communicate with the
9crypto cards. OpenCryptoki makes use of flock and ipc and, as of now,
10this is only need on s390 architecture.
11
12Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
13
14Origin: other, https://bugzilla.mindrot.org/show_bug.cgi?id=2752
15Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=2752
16Bug-Ubuntu: https://bugs.launchpad.net/bugs/1686618
17Last-Update: 2018-10-19
18
19Patch-Name: seccomp-s390-flock-ipc.patch
20---
21 sandbox-seccomp-filter.c | 6 ++++++
22 1 file changed, 6 insertions(+)
23
24diff --git a/sandbox-seccomp-filter.c b/sandbox-seccomp-filter.c
25index 5edbc6946..d4bc20828 100644
26--- a/sandbox-seccomp-filter.c
27+++ b/sandbox-seccomp-filter.c
28@@ -166,6 +166,9 @@ static const struct sock_filter preauth_insns[] = {
29 #ifdef __NR_exit_group
30 SC_ALLOW(__NR_exit_group),
31 #endif
32+#if defined(__NR_flock) && defined(__s390__)
33+ SC_ALLOW(__NR_flock),
34+#endif
35 #ifdef __NR_futex
36 SC_ALLOW(__NR_futex),
37 #endif
38@@ -193,6 +196,9 @@ static const struct sock_filter preauth_insns[] = {
39 #ifdef __NR_getuid32
40 SC_ALLOW(__NR_getuid32),
41 #endif
42+#if defined(__NR_ipc) && defined(__s390__)
43+ SC_ALLOW(__NR_ipc),
44+#endif
45 #ifdef __NR_madvise
46 SC_ALLOW(__NR_madvise),
47 #endif
diff --git a/debian/patches/seccomp-s390-ioctl-ep11-crypto.patch b/debian/patches/seccomp-s390-ioctl-ep11-crypto.patch
new file mode 100644
index 000000000..ecbe1d142
--- /dev/null
+++ b/debian/patches/seccomp-s390-ioctl-ep11-crypto.patch
@@ -0,0 +1,33 @@
1From 9ce189b9f22890421b7f8d3f49a39186d3ce3e14 Mon Sep 17 00:00:00 2001
2From: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
3Date: Tue, 9 May 2017 13:33:30 -0300
4Subject: Enable specific ioctl call for EP11 crypto card (s390)
5
6The EP11 crypto card needs to make an ioctl call, which receives an
7specific argument. This crypto card is for s390 only.
8
9Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
10
11Origin: other, https://bugzilla.mindrot.org/show_bug.cgi?id=2752
12Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=2752
13Bug-Ubuntu: https://bugs.launchpad.net/bugs/1686618
14Last-Update: 2017-08-28
15
16Patch-Name: seccomp-s390-ioctl-ep11-crypto.patch
17---
18 sandbox-seccomp-filter.c | 2 ++
19 1 file changed, 2 insertions(+)
20
21diff --git a/sandbox-seccomp-filter.c b/sandbox-seccomp-filter.c
22index d4bc20828..ef4de8c65 100644
23--- a/sandbox-seccomp-filter.c
24+++ b/sandbox-seccomp-filter.c
25@@ -256,6 +256,8 @@ static const struct sock_filter preauth_insns[] = {
26 SC_ALLOW_ARG(__NR_ioctl, 1, Z90STAT_STATUS_MASK),
27 SC_ALLOW_ARG(__NR_ioctl, 1, ICARSAMODEXPO),
28 SC_ALLOW_ARG(__NR_ioctl, 1, ICARSACRT),
29+ /* Allow ioctls for EP11 crypto card on s390 */
30+ SC_ALLOW_ARG(__NR_ioctl, 1, ZSENDEP11CPRB),
31 #endif
32 #if defined(__x86_64__) && defined(__ILP32__) && defined(__X32_SYSCALL_BIT)
33 /*
diff --git a/debian/patches/selinux-role.patch b/debian/patches/selinux-role.patch
new file mode 100644
index 000000000..269a87c76
--- /dev/null
+++ b/debian/patches/selinux-role.patch
@@ -0,0 +1,472 @@
1From cf3f6ac19812e4d32874304b3854b055831c2124 Mon Sep 17 00:00:00 2001
2From: Manoj Srivastava <srivasta@debian.org>
3Date: Sun, 9 Feb 2014 16:09:49 +0000
4Subject: Handle SELinux authorisation roles
5
6Rejected upstream due to discomfort with magic usernames; a better approach
7will need an SSH protocol change. In the meantime, this came from Debian's
8SELinux maintainer, so we'll keep it until we have something better.
9
10Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1641
11Bug-Debian: http://bugs.debian.org/394795
12Last-Update: 2018-08-24
13
14Patch-Name: selinux-role.patch
15---
16 auth.h | 1 +
17 auth2.c | 10 ++++++++--
18 monitor.c | 37 +++++++++++++++++++++++++++++++++----
19 monitor.h | 2 ++
20 monitor_wrap.c | 27 ++++++++++++++++++++++++---
21 monitor_wrap.h | 3 ++-
22 openbsd-compat/port-linux.c | 21 ++++++++++++++-------
23 openbsd-compat/port-linux.h | 4 ++--
24 platform.c | 4 ++--
25 platform.h | 2 +-
26 session.c | 10 +++++-----
27 session.h | 2 +-
28 sshd.c | 2 +-
29 sshpty.c | 4 ++--
30 sshpty.h | 2 +-
31 15 files changed, 99 insertions(+), 32 deletions(-)
32
33diff --git a/auth.h b/auth.h
34index 977562f0a..90802a5eb 100644
35--- a/auth.h
36+++ b/auth.h
37@@ -65,6 +65,7 @@ struct Authctxt {
38 char *service;
39 struct passwd *pw; /* set if 'valid' */
40 char *style;
41+ char *role;
42
43 /* Method lists for multiple authentication */
44 char **auth_methods; /* modified from server config */
45diff --git a/auth2.c b/auth2.c
46index a77742819..3035926ba 100644
47--- a/auth2.c
48+++ b/auth2.c
49@@ -257,7 +257,7 @@ input_userauth_request(int type, u_int32_t seq, struct ssh *ssh)
50 {
51 Authctxt *authctxt = ssh->authctxt;
52 Authmethod *m = NULL;
53- char *user, *service, *method, *style = NULL;
54+ char *user, *service, *method, *style = NULL, *role = NULL;
55 int authenticated = 0;
56 double tstart = monotime_double();
57
58@@ -270,8 +270,13 @@ input_userauth_request(int type, u_int32_t seq, struct ssh *ssh)
59 debug("userauth-request for user %s service %s method %s", user, service, method);
60 debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
61
62+ if ((role = strchr(user, '/')) != NULL)
63+ *role++ = 0;
64+
65 if ((style = strchr(user, ':')) != NULL)
66 *style++ = 0;
67+ else if (role && (style = strchr(role, ':')) != NULL)
68+ *style++ = '\0';
69
70 if (authctxt->attempt++ == 0) {
71 /* setup auth context */
72@@ -298,8 +303,9 @@ input_userauth_request(int type, u_int32_t seq, struct ssh *ssh)
73 use_privsep ? " [net]" : "");
74 authctxt->service = xstrdup(service);
75 authctxt->style = style ? xstrdup(style) : NULL;
76+ authctxt->role = role ? xstrdup(role) : NULL;
77 if (use_privsep)
78- mm_inform_authserv(service, style);
79+ mm_inform_authserv(service, style, role);
80 userauth_banner();
81 if (auth2_setup_methods_lists(authctxt) != 0)
82 packet_disconnect("no authentication methods enabled");
83diff --git a/monitor.c b/monitor.c
84index eabc1e89b..08fddabd7 100644
85--- a/monitor.c
86+++ b/monitor.c
87@@ -117,6 +117,7 @@ int mm_answer_sign(int, struct sshbuf *);
88 int mm_answer_pwnamallow(int, struct sshbuf *);
89 int mm_answer_auth2_read_banner(int, struct sshbuf *);
90 int mm_answer_authserv(int, struct sshbuf *);
91+int mm_answer_authrole(int, struct sshbuf *);
92 int mm_answer_authpassword(int, struct sshbuf *);
93 int mm_answer_bsdauthquery(int, struct sshbuf *);
94 int mm_answer_bsdauthrespond(int, struct sshbuf *);
95@@ -193,6 +194,7 @@ struct mon_table mon_dispatch_proto20[] = {
96 {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
97 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
98 {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
99+ {MONITOR_REQ_AUTHROLE, MON_ONCE, mm_answer_authrole},
100 {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
101 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
102 #ifdef USE_PAM
103@@ -817,6 +819,7 @@ mm_answer_pwnamallow(int sock, struct sshbuf *m)
104
105 /* Allow service/style information on the auth context */
106 monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
107+ monitor_permit(mon_dispatch, MONITOR_REQ_AUTHROLE, 1);
108 monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
109
110 #ifdef USE_PAM
111@@ -850,16 +853,42 @@ mm_answer_authserv(int sock, struct sshbuf *m)
112 monitor_permit_authentications(1);
113
114 if ((r = sshbuf_get_cstring(m, &authctxt->service, NULL)) != 0 ||
115- (r = sshbuf_get_cstring(m, &authctxt->style, NULL)) != 0)
116+ (r = sshbuf_get_cstring(m, &authctxt->style, NULL)) != 0 ||
117+ (r = sshbuf_get_cstring(m, &authctxt->role, NULL)) != 0)
118 fatal("%s: buffer error: %s", __func__, ssh_err(r));
119- debug3("%s: service=%s, style=%s",
120- __func__, authctxt->service, authctxt->style);
121+ debug3("%s: service=%s, style=%s, role=%s",
122+ __func__, authctxt->service, authctxt->style, authctxt->role);
123
124 if (strlen(authctxt->style) == 0) {
125 free(authctxt->style);
126 authctxt->style = NULL;
127 }
128
129+ if (strlen(authctxt->role) == 0) {
130+ free(authctxt->role);
131+ authctxt->role = NULL;
132+ }
133+
134+ return (0);
135+}
136+
137+int
138+mm_answer_authrole(int sock, struct sshbuf *m)
139+{
140+ int r;
141+
142+ monitor_permit_authentications(1);
143+
144+ if ((r = sshbuf_get_cstring(m, &authctxt->role, NULL)) != 0)
145+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
146+ debug3("%s: role=%s",
147+ __func__, authctxt->role);
148+
149+ if (strlen(authctxt->role) == 0) {
150+ free(authctxt->role);
151+ authctxt->role = NULL;
152+ }
153+
154 return (0);
155 }
156
157@@ -1501,7 +1530,7 @@ mm_answer_pty(int sock, struct sshbuf *m)
158 res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty));
159 if (res == 0)
160 goto error;
161- pty_setowner(authctxt->pw, s->tty);
162+ pty_setowner(authctxt->pw, s->tty, authctxt->role);
163
164 if ((r = sshbuf_put_u32(m, 1)) != 0 ||
165 (r = sshbuf_put_cstring(m, s->tty)) != 0)
166diff --git a/monitor.h b/monitor.h
167index 44fbed589..8f65e684d 100644
168--- a/monitor.h
169+++ b/monitor.h
170@@ -66,6 +66,8 @@ enum monitor_reqtype {
171 MONITOR_REQ_GSSSIGN = 150, MONITOR_ANS_GSSSIGN = 151,
172 MONITOR_REQ_GSSUPCREDS = 152, MONITOR_ANS_GSSUPCREDS = 153,
173
174+ MONITOR_REQ_AUTHROLE = 154,
175+
176 };
177
178 struct monitor {
179diff --git a/monitor_wrap.c b/monitor_wrap.c
180index 1865a122a..fd4d7eb3b 100644
181--- a/monitor_wrap.c
182+++ b/monitor_wrap.c
183@@ -369,10 +369,10 @@ mm_auth2_read_banner(void)
184 return (banner);
185 }
186
187-/* Inform the privileged process about service and style */
188+/* Inform the privileged process about service, style, and role */
189
190 void
191-mm_inform_authserv(char *service, char *style)
192+mm_inform_authserv(char *service, char *style, char *role)
193 {
194 struct sshbuf *m;
195 int r;
196@@ -382,7 +382,8 @@ mm_inform_authserv(char *service, char *style)
197 if ((m = sshbuf_new()) == NULL)
198 fatal("%s: sshbuf_new failed", __func__);
199 if ((r = sshbuf_put_cstring(m, service)) != 0 ||
200- (r = sshbuf_put_cstring(m, style ? style : "")) != 0)
201+ (r = sshbuf_put_cstring(m, style ? style : "")) != 0 ||
202+ (r = sshbuf_put_cstring(m, role ? role : "")) != 0)
203 fatal("%s: buffer error: %s", __func__, ssh_err(r));
204
205 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, m);
206@@ -390,6 +391,26 @@ mm_inform_authserv(char *service, char *style)
207 sshbuf_free(m);
208 }
209
210+/* Inform the privileged process about role */
211+
212+void
213+mm_inform_authrole(char *role)
214+{
215+ struct sshbuf *m;
216+ int r;
217+
218+ debug3("%s entering", __func__);
219+
220+ if ((m = sshbuf_new()) == NULL)
221+ fatal("%s: sshbuf_new failed", __func__);
222+ if ((r = sshbuf_put_cstring(m, role ? role : "")) != 0)
223+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
224+
225+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHROLE, m);
226+
227+ sshbuf_free(m);
228+}
229+
230 /* Do the password authentication */
231 int
232 mm_auth_password(struct ssh *ssh, char *password)
233diff --git a/monitor_wrap.h b/monitor_wrap.h
234index 7f93144ff..79e78cc90 100644
235--- a/monitor_wrap.h
236+++ b/monitor_wrap.h
237@@ -43,7 +43,8 @@ int mm_is_monitor(void);
238 DH *mm_choose_dh(int, int, int);
239 int mm_sshkey_sign(struct sshkey *, u_char **, size_t *, const u_char *, size_t,
240 const char *, u_int compat);
241-void mm_inform_authserv(char *, char *);
242+void mm_inform_authserv(char *, char *, char *);
243+void mm_inform_authrole(char *);
244 struct passwd *mm_getpwnamallow(const char *);
245 char *mm_auth2_read_banner(void);
246 int mm_auth_password(struct ssh *, char *);
247diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c
248index 622988822..3e6e07670 100644
249--- a/openbsd-compat/port-linux.c
250+++ b/openbsd-compat/port-linux.c
251@@ -56,7 +56,7 @@ ssh_selinux_enabled(void)
252
253 /* Return the default security context for the given username */
254 static security_context_t
255-ssh_selinux_getctxbyname(char *pwname)
256+ssh_selinux_getctxbyname(char *pwname, const char *role)
257 {
258 security_context_t sc = NULL;
259 char *sename = NULL, *lvl = NULL;
260@@ -71,9 +71,16 @@ ssh_selinux_getctxbyname(char *pwname)
261 #endif
262
263 #ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
264- r = get_default_context_with_level(sename, lvl, NULL, &sc);
265+ if (role != NULL && role[0])
266+ r = get_default_context_with_rolelevel(sename, role, lvl, NULL,
267+ &sc);
268+ else
269+ r = get_default_context_with_level(sename, lvl, NULL, &sc);
270 #else
271- r = get_default_context(sename, NULL, &sc);
272+ if (role != NULL && role[0])
273+ r = get_default_context_with_role(sename, role, NULL, &sc);
274+ else
275+ r = get_default_context(sename, NULL, &sc);
276 #endif
277
278 if (r != 0) {
279@@ -103,7 +110,7 @@ ssh_selinux_getctxbyname(char *pwname)
280
281 /* Set the execution context to the default for the specified user */
282 void
283-ssh_selinux_setup_exec_context(char *pwname)
284+ssh_selinux_setup_exec_context(char *pwname, const char *role)
285 {
286 security_context_t user_ctx = NULL;
287
288@@ -112,7 +119,7 @@ ssh_selinux_setup_exec_context(char *pwname)
289
290 debug3("%s: setting execution context", __func__);
291
292- user_ctx = ssh_selinux_getctxbyname(pwname);
293+ user_ctx = ssh_selinux_getctxbyname(pwname, role);
294 if (setexeccon(user_ctx) != 0) {
295 switch (security_getenforce()) {
296 case -1:
297@@ -134,7 +141,7 @@ ssh_selinux_setup_exec_context(char *pwname)
298
299 /* Set the TTY context for the specified user */
300 void
301-ssh_selinux_setup_pty(char *pwname, const char *tty)
302+ssh_selinux_setup_pty(char *pwname, const char *tty, const char *role)
303 {
304 security_context_t new_tty_ctx = NULL;
305 security_context_t user_ctx = NULL;
306@@ -146,7 +153,7 @@ ssh_selinux_setup_pty(char *pwname, const char *tty)
307
308 debug3("%s: setting TTY context on %s", __func__, tty);
309
310- user_ctx = ssh_selinux_getctxbyname(pwname);
311+ user_ctx = ssh_selinux_getctxbyname(pwname, role);
312
313 /* XXX: should these calls fatal() upon failure in enforcing mode? */
314
315diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h
316index 3c22a854d..c88129428 100644
317--- a/openbsd-compat/port-linux.h
318+++ b/openbsd-compat/port-linux.h
319@@ -19,8 +19,8 @@
320
321 #ifdef WITH_SELINUX
322 int ssh_selinux_enabled(void);
323-void ssh_selinux_setup_pty(char *, const char *);
324-void ssh_selinux_setup_exec_context(char *);
325+void ssh_selinux_setup_pty(char *, const char *, const char *);
326+void ssh_selinux_setup_exec_context(char *, const char *);
327 void ssh_selinux_change_context(const char *);
328 void ssh_selinux_setfscreatecon(const char *);
329 #endif
330diff --git a/platform.c b/platform.c
331index 41acc9370..35654ea51 100644
332--- a/platform.c
333+++ b/platform.c
334@@ -142,7 +142,7 @@ platform_setusercontext(struct passwd *pw)
335 * called if sshd is running as root.
336 */
337 void
338-platform_setusercontext_post_groups(struct passwd *pw)
339+platform_setusercontext_post_groups(struct passwd *pw, const char *role)
340 {
341 #if !defined(HAVE_LOGIN_CAP) && defined(USE_PAM)
342 /*
343@@ -183,7 +183,7 @@ platform_setusercontext_post_groups(struct passwd *pw)
344 }
345 #endif /* HAVE_SETPCRED */
346 #ifdef WITH_SELINUX
347- ssh_selinux_setup_exec_context(pw->pw_name);
348+ ssh_selinux_setup_exec_context(pw->pw_name, role);
349 #endif
350 }
351
352diff --git a/platform.h b/platform.h
353index ea4f9c584..60d72ffe7 100644
354--- a/platform.h
355+++ b/platform.h
356@@ -25,7 +25,7 @@ void platform_post_fork_parent(pid_t child_pid);
357 void platform_post_fork_child(void);
358 int platform_privileged_uidswap(void);
359 void platform_setusercontext(struct passwd *);
360-void platform_setusercontext_post_groups(struct passwd *);
361+void platform_setusercontext_post_groups(struct passwd *, const char *);
362 char *platform_get_krb5_client(const char *);
363 char *platform_krb5_get_principal_name(const char *);
364 int platform_sys_dir_uid(uid_t);
365diff --git a/session.c b/session.c
366index 2d0958d11..19f38637e 100644
367--- a/session.c
368+++ b/session.c
369@@ -1380,7 +1380,7 @@ safely_chroot(const char *path, uid_t uid)
370
371 /* Set login name, uid, gid, and groups. */
372 void
373-do_setusercontext(struct passwd *pw)
374+do_setusercontext(struct passwd *pw, const char *role)
375 {
376 char uidstr[32], *chroot_path, *tmp;
377
378@@ -1408,7 +1408,7 @@ do_setusercontext(struct passwd *pw)
379 endgrent();
380 #endif
381
382- platform_setusercontext_post_groups(pw);
383+ platform_setusercontext_post_groups(pw, role);
384
385 if (!in_chroot && options.chroot_directory != NULL &&
386 strcasecmp(options.chroot_directory, "none") != 0) {
387@@ -1547,7 +1547,7 @@ do_child(struct ssh *ssh, Session *s, const char *command)
388
389 /* Force a password change */
390 if (s->authctxt->force_pwchange) {
391- do_setusercontext(pw);
392+ do_setusercontext(pw, s->authctxt->role);
393 child_close_fds(ssh);
394 do_pwchange(s);
395 exit(1);
396@@ -1565,7 +1565,7 @@ do_child(struct ssh *ssh, Session *s, const char *command)
397 /* When PAM is enabled we rely on it to do the nologin check */
398 if (!options.use_pam)
399 do_nologin(pw);
400- do_setusercontext(pw);
401+ do_setusercontext(pw, s->authctxt->role);
402 /*
403 * PAM session modules in do_setusercontext may have
404 * generated messages, so if this in an interactive
405@@ -1955,7 +1955,7 @@ session_pty_req(struct ssh *ssh, Session *s)
406 ssh_tty_parse_modes(ssh, s->ttyfd);
407
408 if (!use_privsep)
409- pty_setowner(s->pw, s->tty);
410+ pty_setowner(s->pw, s->tty, s->authctxt->role);
411
412 /* Set window size from the packet. */
413 pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
414diff --git a/session.h b/session.h
415index ce59dabd9..675c91146 100644
416--- a/session.h
417+++ b/session.h
418@@ -77,7 +77,7 @@ void session_pty_cleanup2(Session *);
419 Session *session_new(void);
420 Session *session_by_tty(char *);
421 void session_close(struct ssh *, Session *);
422-void do_setusercontext(struct passwd *);
423+void do_setusercontext(struct passwd *, const char *);
424
425 const char *session_get_remote_name_or_ip(struct ssh *, u_int, int);
426
427diff --git a/sshd.c b/sshd.c
428index 673db87f6..2bc6679e5 100644
429--- a/sshd.c
430+++ b/sshd.c
431@@ -683,7 +683,7 @@ privsep_postauth(Authctxt *authctxt)
432 reseed_prngs();
433
434 /* Drop privileges */
435- do_setusercontext(authctxt->pw);
436+ do_setusercontext(authctxt->pw, authctxt->role);
437
438 skip:
439 /* It is safe now to apply the key state */
440diff --git a/sshpty.c b/sshpty.c
441index 4da84d05f..676ade50e 100644
442--- a/sshpty.c
443+++ b/sshpty.c
444@@ -162,7 +162,7 @@ pty_change_window_size(int ptyfd, u_int row, u_int col,
445 }
446
447 void
448-pty_setowner(struct passwd *pw, const char *tty)
449+pty_setowner(struct passwd *pw, const char *tty, const char *role)
450 {
451 struct group *grp;
452 gid_t gid;
453@@ -184,7 +184,7 @@ pty_setowner(struct passwd *pw, const char *tty)
454 strerror(errno));
455
456 #ifdef WITH_SELINUX
457- ssh_selinux_setup_pty(pw->pw_name, tty);
458+ ssh_selinux_setup_pty(pw->pw_name, tty, role);
459 #endif
460
461 if (st.st_uid != pw->pw_uid || st.st_gid != gid) {
462diff --git a/sshpty.h b/sshpty.h
463index 9ec7e9a15..de7e000ae 100644
464--- a/sshpty.h
465+++ b/sshpty.h
466@@ -24,5 +24,5 @@ int pty_allocate(int *, int *, char *, size_t);
467 void pty_release(const char *);
468 void pty_make_controlling_tty(int *, const char *);
469 void pty_change_window_size(int, u_int, u_int, u_int, u_int);
470-void pty_setowner(struct passwd *, const char *);
471+void pty_setowner(struct passwd *, const char *, const char *);
472 void disconnect_controlling_tty(void);
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 000000000..b0da97283
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1,34 @@
1gssapi.patch
2restore-tcp-wrappers.patch
3selinux-role.patch
4ssh-vulnkey-compat.patch
5keepalive-extensions.patch
6syslog-level-silent.patch
7user-group-modes.patch
8scp-quoting.patch
9shell-path.patch
10dnssec-sshfp.patch
11mention-ssh-keygen-on-keychange.patch
12package-versioning.patch
13debian-banner.patch
14authorized-keys-man-symlink.patch
15openbsd-docs.patch
16ssh-argv0.patch
17doc-hash-tab-completion.patch
18ssh-agent-setgid.patch
19no-openssl-version-status.patch
20gnome-ssh-askpass2-icon.patch
21systemd-readiness.patch
22debian-config.patch
23restore-authorized_keys2.patch
24seccomp-s390-flock-ipc.patch
25seccomp-s390-ioctl-ep11-crypto.patch
26conch-old-privkey-format.patch
27scp-disallow-dot-or-empty-filename.patch
28sanitize-scp-filenames-via-snmprintf.patch
29have-progressmeter-force-update-at-beginning-and-end-transfer.patch
30check-filenames-in-scp-client.patch
31fix-key-type-check.patch
32request-rsa-sha2-cert-signatures.patch
33scp-handle-braces.patch
34revert-ipqos-defaults.patch
diff --git a/debian/patches/shell-path.patch b/debian/patches/shell-path.patch
new file mode 100644
index 000000000..ad574e829
--- /dev/null
+++ b/debian/patches/shell-path.patch
@@ -0,0 +1,39 @@
1From cabad6b7182cd6eaa8b760718200a316e7f578ed Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:00 +0000
4Subject: Look for $SHELL on the path for ProxyCommand/LocalCommand
5
6There's some debate on the upstream bug about whether POSIX requires this.
7I (Colin Watson) agree with Vincent and think it does.
8
9Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1494
10Bug-Debian: http://bugs.debian.org/492728
11Last-Update: 2013-09-14
12
13Patch-Name: shell-path.patch
14---
15 sshconnect.c | 4 ++--
16 1 file changed, 2 insertions(+), 2 deletions(-)
17
18diff --git a/sshconnect.c b/sshconnect.c
19index 6d819279e..700ea6c3c 100644
20--- a/sshconnect.c
21+++ b/sshconnect.c
22@@ -229,7 +229,7 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
23 /* Execute the proxy command. Note that we gave up any
24 extra privileges above. */
25 signal(SIGPIPE, SIG_DFL);
26- execv(argv[0], argv);
27+ execvp(argv[0], argv);
28 perror(argv[0]);
29 exit(1);
30 }
31@@ -1534,7 +1534,7 @@ ssh_local_cmd(const char *args)
32 if (pid == 0) {
33 signal(SIGPIPE, SIG_DFL);
34 debug3("Executing %s -c \"%s\"", shell, args);
35- execl(shell, shell, "-c", args, (char *)NULL);
36+ execlp(shell, shell, "-c", args, (char *)NULL);
37 error("Couldn't execute %s -c \"%s\": %s",
38 shell, args, strerror(errno));
39 _exit(1);
diff --git a/debian/patches/ssh-agent-setgid.patch b/debian/patches/ssh-agent-setgid.patch
new file mode 100644
index 000000000..ed6ef3d46
--- /dev/null
+++ b/debian/patches/ssh-agent-setgid.patch
@@ -0,0 +1,40 @@
1From 6d4521d39a852dc5627187c045c933f4e1cb4601 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:13 +0000
4Subject: Document consequences of ssh-agent being setgid in ssh-agent(1)
5
6Bug-Debian: http://bugs.debian.org/711623
7Forwarded: no
8Last-Update: 2013-06-08
9
10Patch-Name: ssh-agent-setgid.patch
11---
12 ssh-agent.1 | 15 +++++++++++++++
13 1 file changed, 15 insertions(+)
14
15diff --git a/ssh-agent.1 b/ssh-agent.1
16index 83b2b41c8..7230704a3 100644
17--- a/ssh-agent.1
18+++ b/ssh-agent.1
19@@ -206,6 +206,21 @@ environment variable holds the agent's process ID.
20 .Pp
21 The agent exits automatically when the command given on the command
22 line terminates.
23+.Pp
24+In Debian,
25+.Nm
26+is installed with the set-group-id bit set, to prevent
27+.Xr ptrace 2
28+attacks retrieving private key material.
29+This has the side-effect of causing the run-time linker to remove certain
30+environment variables which might have security implications for set-id
31+programs, including
32+.Ev LD_PRELOAD ,
33+.Ev LD_LIBRARY_PATH ,
34+and
35+.Ev TMPDIR .
36+If you need to set any of these environment variables, you will need to do
37+so in the program executed by ssh-agent.
38 .Sh FILES
39 .Bl -tag -width Ds
40 .It Pa $TMPDIR/ssh-XXXXXXXXXX/agent.<ppid>
diff --git a/debian/patches/ssh-argv0.patch b/debian/patches/ssh-argv0.patch
new file mode 100644
index 000000000..bb1e10973
--- /dev/null
+++ b/debian/patches/ssh-argv0.patch
@@ -0,0 +1,31 @@
1From d1064c2689df8d0894a68ac9671d14ab125bc91b Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:10 +0000
4Subject: ssh(1): Refer to ssh-argv0(1)
5
6Old versions of OpenSSH (up to 2.5 or thereabouts) allowed creating symlinks
7to ssh with the name of the host you want to connect to. Debian ships an
8ssh-argv0 script restoring this feature; this patch refers to its manual
9page from ssh(1).
10
11Bug-Debian: http://bugs.debian.org/111341
12Forwarded: not-needed
13Last-Update: 2013-09-14
14
15Patch-Name: ssh-argv0.patch
16---
17 ssh.1 | 1 +
18 1 file changed, 1 insertion(+)
19
20diff --git a/ssh.1 b/ssh.1
21index 5dfad6daa..ad1ed0f86 100644
22--- a/ssh.1
23+++ b/ssh.1
24@@ -1585,6 +1585,7 @@ if an error occurred.
25 .Xr sftp 1 ,
26 .Xr ssh-add 1 ,
27 .Xr ssh-agent 1 ,
28+.Xr ssh-argv0 1 ,
29 .Xr ssh-keygen 1 ,
30 .Xr ssh-keyscan 1 ,
31 .Xr tun 4 ,
diff --git a/debian/patches/ssh-vulnkey-compat.patch b/debian/patches/ssh-vulnkey-compat.patch
new file mode 100644
index 000000000..ca3e090bd
--- /dev/null
+++ b/debian/patches/ssh-vulnkey-compat.patch
@@ -0,0 +1,42 @@
1From eccbd3637a2b8544fdcfdd5d1a00a9dfdac62aeb Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@ubuntu.com>
3Date: Sun, 9 Feb 2014 16:09:50 +0000
4Subject: Accept obsolete ssh-vulnkey configuration options
5
6These options were used as part of Debian's response to CVE-2008-0166.
7Nearly six years later, we no longer need to continue carrying the bulk
8of that patch, but we do need to avoid failing when the associated
9configuration options are still present.
10
11Last-Update: 2014-02-09
12
13Patch-Name: ssh-vulnkey-compat.patch
14---
15 readconf.c | 1 +
16 servconf.c | 1 +
17 2 files changed, 2 insertions(+)
18
19diff --git a/readconf.c b/readconf.c
20index 36bc5e59a..5e655e924 100644
21--- a/readconf.c
22+++ b/readconf.c
23@@ -190,6 +190,7 @@ static struct {
24 { "fallbacktorsh", oDeprecated },
25 { "globalknownhostsfile2", oDeprecated },
26 { "rhostsauthentication", oDeprecated },
27+ { "useblacklistedkeys", oDeprecated },
28 { "userknownhostsfile2", oDeprecated },
29 { "useroaming", oDeprecated },
30 { "usersh", oDeprecated },
31diff --git a/servconf.c b/servconf.c
32index 4668b8a45..6caf1db38 100644
33--- a/servconf.c
34+++ b/servconf.c
35@@ -600,6 +600,7 @@ static struct {
36 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
37 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
38 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
39+ { "permitblacklistedkeys", sDeprecated, SSHCFG_GLOBAL },
40 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
41 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
42 { "uselogin", sDeprecated, SSHCFG_GLOBAL },
diff --git a/debian/patches/syslog-level-silent.patch b/debian/patches/syslog-level-silent.patch
new file mode 100644
index 000000000..3093a41fb
--- /dev/null
+++ b/debian/patches/syslog-level-silent.patch
@@ -0,0 +1,47 @@
1From e755ec70d62bfb9b02159123f4e870b00010be77 Mon Sep 17 00:00:00 2001
2From: Jonathan David Amery <jdamery@ysolde.ucam.org>
3Date: Sun, 9 Feb 2014 16:09:54 +0000
4Subject: "LogLevel SILENT" compatibility
5
6"LogLevel SILENT" (-qq) was introduced in Debian openssh 1:3.0.1p1-1 to
7match the behaviour of non-free SSH, in which -q does not suppress fatal
8errors. However, this was unintentionally broken in 1:4.6p1-2 and nobody
9complained, so we've dropped most of it. The parts that remain are basic
10configuration file compatibility, and an adjustment to "Pseudo-terminal will
11not be allocated ..." which should be split out into a separate patch.
12
13Author: Matthew Vernon <matthew@debian.org>
14Author: Colin Watson <cjwatson@debian.org>
15Last-Update: 2013-09-14
16
17Patch-Name: syslog-level-silent.patch
18---
19 log.c | 1 +
20 ssh.c | 2 +-
21 2 files changed, 2 insertions(+), 1 deletion(-)
22
23diff --git a/log.c b/log.c
24index d9c2d136c..1749af6d1 100644
25--- a/log.c
26+++ b/log.c
27@@ -93,6 +93,7 @@ static struct {
28 LogLevel val;
29 } log_levels[] =
30 {
31+ { "SILENT", SYSLOG_LEVEL_QUIET }, /* compatibility */
32 { "QUIET", SYSLOG_LEVEL_QUIET },
33 { "FATAL", SYSLOG_LEVEL_FATAL },
34 { "ERROR", SYSLOG_LEVEL_ERROR },
35diff --git a/ssh.c b/ssh.c
36index 0777c31e4..3140fed4c 100644
37--- a/ssh.c
38+++ b/ssh.c
39@@ -1258,7 +1258,7 @@ main(int ac, char **av)
40 /* Do not allocate a tty if stdin is not a tty. */
41 if ((!isatty(fileno(stdin)) || stdin_null_flag) &&
42 options.request_tty != REQUEST_TTY_FORCE) {
43- if (tty_flag)
44+ if (tty_flag && options.log_level != SYSLOG_LEVEL_QUIET)
45 logit("Pseudo-terminal will not be allocated because "
46 "stdin is not a terminal.");
47 tty_flag = 0;
diff --git a/debian/patches/systemd-readiness.patch b/debian/patches/systemd-readiness.patch
new file mode 100644
index 000000000..c5dee41ad
--- /dev/null
+++ b/debian/patches/systemd-readiness.patch
@@ -0,0 +1,84 @@
1From da34947128351bee9d2530574432190548f5be58 Mon Sep 17 00:00:00 2001
2From: Michael Biebl <biebl@debian.org>
3Date: Mon, 21 Dec 2015 16:08:47 +0000
4Subject: Add systemd readiness notification support
5
6Bug-Debian: https://bugs.debian.org/778913
7Forwarded: no
8Last-Update: 2017-08-22
9
10Patch-Name: systemd-readiness.patch
11---
12 configure.ac | 24 ++++++++++++++++++++++++
13 sshd.c | 9 +++++++++
14 2 files changed, 33 insertions(+)
15
16diff --git a/configure.ac b/configure.ac
17index 917300b43..8a5db4cb5 100644
18--- a/configure.ac
19+++ b/configure.ac
20@@ -4586,6 +4586,29 @@ AC_ARG_WITH([kerberos5],
21 AC_SUBST([GSSLIBS])
22 AC_SUBST([K5LIBS])
23
24+# Check whether user wants systemd support
25+SYSTEMD_MSG="no"
26+AC_ARG_WITH(systemd,
27+ [ --with-systemd Enable systemd support],
28+ [ if test "x$withval" != "xno" ; then
29+ AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
30+ if test "$PKGCONFIG" != "no"; then
31+ AC_MSG_CHECKING([for libsystemd])
32+ if $PKGCONFIG --exists libsystemd; then
33+ SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
34+ SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
35+ CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
36+ SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
37+ AC_MSG_RESULT([yes])
38+ AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
39+ SYSTEMD_MSG="yes"
40+ else
41+ AC_MSG_RESULT([no])
42+ fi
43+ fi
44+ fi ]
45+)
46+
47 # Looking for programs, paths and files
48
49 PRIVSEP_PATH=/var/empty
50@@ -5392,6 +5415,7 @@ echo " libldns support: $LDNS_MSG"
51 echo " Solaris process contract support: $SPC_MSG"
52 echo " Solaris project support: $SP_MSG"
53 echo " Solaris privilege support: $SPP_MSG"
54+echo " systemd support: $SYSTEMD_MSG"
55 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
56 echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
57 echo " BSD Auth support: $BSD_AUTH_MSG"
58diff --git a/sshd.c b/sshd.c
59index d7e77d343..a1c3970b3 100644
60--- a/sshd.c
61+++ b/sshd.c
62@@ -85,6 +85,10 @@
63 #include <prot.h>
64 #endif
65
66+#ifdef HAVE_SYSTEMD
67+#include <systemd/sd-daemon.h>
68+#endif
69+
70 #include "xmalloc.h"
71 #include "ssh.h"
72 #include "ssh2.h"
73@@ -1990,6 +1994,11 @@ main(int ac, char **av)
74 }
75 }
76
77+#ifdef HAVE_SYSTEMD
78+ /* Signal systemd that we are ready to accept connections */
79+ sd_notify(0, "READY=1");
80+#endif
81+
82 /* Accept a connection and return in a forked child */
83 server_accept_loop(&sock_in, &sock_out,
84 &newsock, config_s);
diff --git a/debian/patches/user-group-modes.patch b/debian/patches/user-group-modes.patch
new file mode 100644
index 000000000..bc2390e06
--- /dev/null
+++ b/debian/patches/user-group-modes.patch
@@ -0,0 +1,210 @@
1From 7b931d36ad36a93d2b1811858ca29408ec44ecae Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:09:58 +0000
4Subject: Allow harmless group-writability
5
6Allow secure files (~/.ssh/config, ~/.ssh/authorized_keys, etc.) to be
7group-writable, provided that the group in question contains only the file's
8owner. Rejected upstream for IMO incorrect reasons (e.g. a misunderstanding
9about the contents of gr->gr_mem). Given that per-user groups and umask 002
10are the default setup in Debian (for good reasons - this makes operating in
11setgid directories with other groups much easier), we need to permit this by
12default.
13
14Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1060
15Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=314347
16Last-Update: 2017-10-04
17
18Patch-Name: user-group-modes.patch
19---
20 auth-rhosts.c | 6 ++----
21 auth.c | 3 +--
22 misc.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++-----
23 misc.h | 2 ++
24 readconf.c | 3 +--
25 ssh.1 | 2 ++
26 ssh_config.5 | 2 ++
27 7 files changed, 63 insertions(+), 13 deletions(-)
28
29diff --git a/auth-rhosts.c b/auth-rhosts.c
30index 57296e1f6..546aa0495 100644
31--- a/auth-rhosts.c
32+++ b/auth-rhosts.c
33@@ -261,8 +261,7 @@ auth_rhosts2(struct passwd *pw, const char *client_user, const char *hostname,
34 return 0;
35 }
36 if (options.strict_modes &&
37- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
38- (st.st_mode & 022) != 0)) {
39+ !secure_permissions(&st, pw->pw_uid)) {
40 logit("Rhosts authentication refused for %.100s: "
41 "bad ownership or modes for home directory.", pw->pw_name);
42 auth_debug_add("Rhosts authentication refused for %.100s: "
43@@ -288,8 +287,7 @@ auth_rhosts2(struct passwd *pw, const char *client_user, const char *hostname,
44 * allowing access to their account by anyone.
45 */
46 if (options.strict_modes &&
47- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
48- (st.st_mode & 022) != 0)) {
49+ !secure_permissions(&st, pw->pw_uid)) {
50 logit("Rhosts authentication refused for %.100s: bad modes for %.200s",
51 pw->pw_name, buf);
52 auth_debug_add("Bad file modes for %.200s", buf);
53diff --git a/auth.c b/auth.c
54index d8e6b4a3d..9d1d453f1 100644
55--- a/auth.c
56+++ b/auth.c
57@@ -473,8 +473,7 @@ check_key_in_hostfiles(struct passwd *pw, struct sshkey *key, const char *host,
58 user_hostfile = tilde_expand_filename(userfile, pw->pw_uid);
59 if (options.strict_modes &&
60 (stat(user_hostfile, &st) == 0) &&
61- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
62- (st.st_mode & 022) != 0)) {
63+ !secure_permissions(&st, pw->pw_uid)) {
64 logit("Authentication refused for %.100s: "
65 "bad owner or modes for %.200s",
66 pw->pw_name, user_hostfile);
67diff --git a/misc.c b/misc.c
68index bdc06fdb3..5159e6692 100644
69--- a/misc.c
70+++ b/misc.c
71@@ -58,8 +58,9 @@
72 #include <netdb.h>
73 #ifdef HAVE_PATHS_H
74 # include <paths.h>
75-#include <pwd.h>
76 #endif
77+#include <pwd.h>
78+#include <grp.h>
79 #ifdef SSH_TUN_OPENBSD
80 #include <net/if.h>
81 #endif
82@@ -1028,6 +1029,55 @@ percent_expand(const char *string, ...)
83 #undef EXPAND_MAX_KEYS
84 }
85
86+int
87+secure_permissions(struct stat *st, uid_t uid)
88+{
89+ if (!platform_sys_dir_uid(st->st_uid) && st->st_uid != uid)
90+ return 0;
91+ if ((st->st_mode & 002) != 0)
92+ return 0;
93+ if ((st->st_mode & 020) != 0) {
94+ /* If the file is group-writable, the group in question must
95+ * have exactly one member, namely the file's owner.
96+ * (Zero-member groups are typically used by setgid
97+ * binaries, and are unlikely to be suitable.)
98+ */
99+ struct passwd *pw;
100+ struct group *gr;
101+ int members = 0;
102+
103+ gr = getgrgid(st->st_gid);
104+ if (!gr)
105+ return 0;
106+
107+ /* Check primary group memberships. */
108+ while ((pw = getpwent()) != NULL) {
109+ if (pw->pw_gid == gr->gr_gid) {
110+ ++members;
111+ if (pw->pw_uid != uid)
112+ return 0;
113+ }
114+ }
115+ endpwent();
116+
117+ pw = getpwuid(st->st_uid);
118+ if (!pw)
119+ return 0;
120+
121+ /* Check supplementary group memberships. */
122+ if (gr->gr_mem[0]) {
123+ ++members;
124+ if (strcmp(pw->pw_name, gr->gr_mem[0]) ||
125+ gr->gr_mem[1])
126+ return 0;
127+ }
128+
129+ if (!members)
130+ return 0;
131+ }
132+ return 1;
133+}
134+
135 int
136 tun_open(int tun, int mode, char **ifname)
137 {
138@@ -1786,8 +1836,7 @@ safe_path(const char *name, struct stat *stp, const char *pw_dir,
139 snprintf(err, errlen, "%s is not a regular file", buf);
140 return -1;
141 }
142- if ((!platform_sys_dir_uid(stp->st_uid) && stp->st_uid != uid) ||
143- (stp->st_mode & 022) != 0) {
144+ if (!secure_permissions(stp, uid)) {
145 snprintf(err, errlen, "bad ownership or modes for file %s",
146 buf);
147 return -1;
148@@ -1802,8 +1851,7 @@ safe_path(const char *name, struct stat *stp, const char *pw_dir,
149 strlcpy(buf, cp, sizeof(buf));
150
151 if (stat(buf, &st) < 0 ||
152- (!platform_sys_dir_uid(st.st_uid) && st.st_uid != uid) ||
153- (st.st_mode & 022) != 0) {
154+ !secure_permissions(&st, uid)) {
155 snprintf(err, errlen,
156 "bad ownership or modes for directory %s", buf);
157 return -1;
158diff --git a/misc.h b/misc.h
159index 31b207a8d..aaf966e65 100644
160--- a/misc.h
161+++ b/misc.h
162@@ -168,6 +168,8 @@ int safe_path_fd(int, const char *, struct passwd *,
163 char *read_passphrase(const char *, int);
164 int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2)));
165
166+int secure_permissions(struct stat *st, uid_t uid);
167+
168 #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
169 #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
170 #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
171diff --git a/readconf.c b/readconf.c
172index 052d4b1ac..6b01f20d2 100644
173--- a/readconf.c
174+++ b/readconf.c
175@@ -1820,8 +1820,7 @@ read_config_file_depth(const char *filename, struct passwd *pw,
176
177 if (fstat(fileno(f), &sb) == -1)
178 fatal("fstat %s: %s", filename, strerror(errno));
179- if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
180- (sb.st_mode & 022) != 0))
181+ if (!secure_permissions(&sb, getuid()))
182 fatal("Bad owner or permissions on %s", filename);
183 }
184
185diff --git a/ssh.1 b/ssh.1
186index 7760c3075..81f29af43 100644
187--- a/ssh.1
188+++ b/ssh.1
189@@ -1485,6 +1485,8 @@ The file format and configuration options are described in
190 .Xr ssh_config 5 .
191 Because of the potential for abuse, this file must have strict permissions:
192 read/write for the user, and not writable by others.
193+It may be group-writable provided that the group in question contains only
194+the user.
195 .Pp
196 .It Pa ~/.ssh/environment
197 Contains additional definitions for environment variables; see
198diff --git a/ssh_config.5 b/ssh_config.5
199index 54e143c93..7d55fa820 100644
200--- a/ssh_config.5
201+++ b/ssh_config.5
202@@ -1835,6 +1835,8 @@ The format of this file is described above.
203 This file is used by the SSH client.
204 Because of the potential for abuse, this file must have strict permissions:
205 read/write for the user, and not accessible by others.
206+It may be group-writable provided that the group in question contains only
207+the user.
208 .It Pa /etc/ssh/ssh_config
209 Systemwide configuration file.
210 This file provides defaults for those