summaryrefslogtreecommitdiff
path: root/debian/patches
diff options
context:
space:
mode:
Diffstat (limited to 'debian/patches')
-rw-r--r--debian/patches/auth-log-verbosity.patch133
-rw-r--r--debian/patches/authorized-keys-man-symlink.patch26
-rw-r--r--debian/patches/consolekit.patch742
-rw-r--r--debian/patches/debian-banner.patch111
-rw-r--r--debian/patches/debian-config.patch159
-rw-r--r--debian/patches/dnssec-sshfp.patch94
-rw-r--r--debian/patches/doc-hash-tab-completion.patch28
-rw-r--r--debian/patches/doc-upstart.patch29
-rw-r--r--debian/patches/gnome-ssh-askpass2-icon.patch26
-rw-r--r--debian/patches/gssapi.patch3135
-rw-r--r--debian/patches/helpful-wait-terminate.patch26
-rw-r--r--debian/patches/keepalive-extensions.patch135
-rw-r--r--debian/patches/lintian-symlink-pickiness.patch32
-rw-r--r--debian/patches/mention-ssh-keygen-on-keychange.patch41
-rw-r--r--debian/patches/no-openssl-version-check.patch41
-rw-r--r--debian/patches/openbsd-docs.patch148
-rw-r--r--debian/patches/package-versioning.patch65
-rw-r--r--debian/patches/quieter-signals.patch40
-rw-r--r--debian/patches/scp-quoting.patch41
-rw-r--r--debian/patches/selinux-role.patch504
-rw-r--r--debian/patches/series28
-rw-r--r--debian/patches/shell-path.patch39
-rw-r--r--debian/patches/sigstop.patch28
-rw-r--r--debian/patches/ssh-agent-setgid.patch40
-rw-r--r--debian/patches/ssh-argv0.patch31
-rw-r--r--debian/patches/ssh-vulnkey.patch1419
-rw-r--r--debian/patches/ssh1-keepalive.patch74
-rw-r--r--debian/patches/syslog-level-silent.patch47
-rw-r--r--debian/patches/user-group-modes.patch266
29 files changed, 7528 insertions, 0 deletions
diff --git a/debian/patches/auth-log-verbosity.patch b/debian/patches/auth-log-verbosity.patch
new file mode 100644
index 000000000..5d98b81a2
--- /dev/null
+++ b/debian/patches/auth-log-verbosity.patch
@@ -0,0 +1,133 @@
1From ec5991d73abdc0b3c43ea9f8a0e99da045e7beb1 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:02 +0000
4Subject: Quieten logs when multiple from= restrictions are used
5
6Bug-Debian: http://bugs.debian.org/630606
7Forwarded: no
8Last-Update: 2013-09-14
9
10Patch-Name: auth-log-verbosity.patch
11---
12 auth-options.c | 35 ++++++++++++++++++++++++++---------
13 auth-options.h | 1 +
14 auth-rsa.c | 2 ++
15 auth2-pubkey.c | 3 +++
16 4 files changed, 32 insertions(+), 9 deletions(-)
17
18diff --git a/auth-options.c b/auth-options.c
19index 12e2e1d..15c00d0 100644
20--- a/auth-options.c
21+++ b/auth-options.c
22@@ -58,9 +58,20 @@ int forced_tun_device = -1;
23 /* "principals=" option. */
24 char *authorized_principals = NULL;
25
26+/* Throttle log messages. */
27+int logged_from_hostip = 0;
28+int logged_cert_hostip = 0;
29+
30 extern ServerOptions options;
31
32 void
33+auth_start_parse_options(void)
34+{
35+ logged_from_hostip = 0;
36+ logged_cert_hostip = 0;
37+}
38+
39+void
40 auth_clear_options(void)
41 {
42 no_agent_forwarding_flag = 0;
43@@ -288,10 +299,13 @@ auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
44 /* FALLTHROUGH */
45 case 0:
46 free(patterns);
47- logit("Authentication tried for %.100s with "
48- "correct key but not from a permitted "
49- "host (host=%.200s, ip=%.200s).",
50- pw->pw_name, remote_host, remote_ip);
51+ if (!logged_from_hostip) {
52+ logit("Authentication tried for %.100s with "
53+ "correct key but not from a permitted "
54+ "host (host=%.200s, ip=%.200s).",
55+ pw->pw_name, remote_host, remote_ip);
56+ logged_from_hostip = 1;
57+ }
58 auth_debug_add("Your host '%.200s' is not "
59 "permitted to use this key for login.",
60 remote_host);
61@@ -513,11 +527,14 @@ parse_option_list(u_char *optblob, size_t optblob_len, struct passwd *pw,
62 break;
63 case 0:
64 /* no match */
65- logit("Authentication tried for %.100s "
66- "with valid certificate but not "
67- "from a permitted host "
68- "(ip=%.200s).", pw->pw_name,
69- remote_ip);
70+ if (!logged_cert_hostip) {
71+ logit("Authentication tried for %.100s "
72+ "with valid certificate but not "
73+ "from a permitted host "
74+ "(ip=%.200s).", pw->pw_name,
75+ remote_ip);
76+ logged_cert_hostip = 1;
77+ }
78 auth_debug_add("Your address '%.200s' "
79 "is not permitted to use this "
80 "certificate for login.",
81diff --git a/auth-options.h b/auth-options.h
82index 7455c94..a3f0a02 100644
83--- a/auth-options.h
84+++ b/auth-options.h
85@@ -33,6 +33,7 @@ extern int forced_tun_device;
86 extern int key_is_cert_authority;
87 extern char *authorized_principals;
88
89+void auth_start_parse_options(void);
90 int auth_parse_options(struct passwd *, char *, char *, u_long);
91 void auth_clear_options(void);
92 int auth_cert_options(Key *, struct passwd *);
93diff --git a/auth-rsa.c b/auth-rsa.c
94index 6ed152c..9b139c9 100644
95--- a/auth-rsa.c
96+++ b/auth-rsa.c
97@@ -174,6 +174,8 @@ rsa_key_allowed_in_file(struct passwd *pw, char *file,
98 if ((f = auth_openkeyfile(file, pw, options.strict_modes)) == NULL)
99 return 0;
100
101+ auth_start_parse_options();
102+
103 /*
104 * Go though the accepted keys, looking for the current key. If
105 * found, perform a challenge-response dialog to verify that the
106diff --git a/auth2-pubkey.c b/auth2-pubkey.c
107index 12eb8a6..7c0ceee 100644
108--- a/auth2-pubkey.c
109+++ b/auth2-pubkey.c
110@@ -257,6 +257,7 @@ match_principals_file(char *file, struct passwd *pw, struct KeyCert *cert)
111 restore_uid();
112 return 0;
113 }
114+ auth_start_parse_options();
115 while (read_keyfile_line(f, file, line, sizeof(line), &linenum) != -1) {
116 /* Skip leading whitespace. */
117 for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
118@@ -318,6 +319,7 @@ check_authkeys_file(FILE *f, char *file, Key* key, struct passwd *pw)
119 found_key = 0;
120
121 found = NULL;
122+ auth_start_parse_options();
123 while (read_keyfile_line(f, file, line, sizeof(line), &linenum) != -1) {
124 char *cp, *key_options = NULL;
125 if (found != NULL)
126@@ -453,6 +455,7 @@ user_cert_trusted_ca(struct passwd *pw, Key *key)
127 if (key_cert_check_authority(key, 0, 1,
128 principals_file == NULL ? pw->pw_name : NULL, &reason) != 0)
129 goto fail_reason;
130+ auth_start_parse_options();
131 if (auth_cert_options(key, pw) != 0)
132 goto out;
133
diff --git a/debian/patches/authorized-keys-man-symlink.patch b/debian/patches/authorized-keys-man-symlink.patch
new file mode 100644
index 000000000..751ba841c
--- /dev/null
+++ b/debian/patches/authorized-keys-man-symlink.patch
@@ -0,0 +1,26 @@
1From 6342b4c70310da7f73e1d54ddae0edde990d95d8 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 ca6eee5..7cd3a08 100644
17--- a/Makefile.in
18+++ b/Makefile.in
19@@ -289,6 +289,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/consolekit.patch b/debian/patches/consolekit.patch
new file mode 100644
index 000000000..f43e78500
--- /dev/null
+++ b/debian/patches/consolekit.patch
@@ -0,0 +1,742 @@
1From cfae2bfa1e95cbb6c7a9799f13b82e8e804ca869 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@ubuntu.com>
3Date: Sun, 9 Feb 2014 16:09:57 +0000
4Subject: Add support for registering ConsoleKit sessions on login
5
6Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1450
7Last-Updated: 2013-09-14
8
9Patch-Name: consolekit.patch
10---
11 Makefile.in | 3 +-
12 configure | 132 +++++++++++++++++++++++++++++++
13 configure.ac | 25 ++++++
14 consolekit.c | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15 consolekit.h | 24 ++++++
16 monitor.c | 43 +++++++++++
17 monitor.h | 2 +
18 monitor_wrap.c | 31 ++++++++
19 monitor_wrap.h | 4 +
20 session.c | 13 ++++
21 session.h | 6 ++
22 11 files changed, 522 insertions(+), 1 deletion(-)
23 create mode 100644 consolekit.c
24 create mode 100644 consolekit.h
25
26diff --git a/Makefile.in b/Makefile.in
27index b8f5099..ca6eee5 100644
28--- a/Makefile.in
29+++ b/Makefile.in
30@@ -96,7 +96,8 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \
31 sftp-server.o sftp-common.o \
32 roaming_common.o roaming_serv.o \
33 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \
34- sandbox-seccomp-filter.o
35+ sandbox-seccomp-filter.o \
36+ consolekit.o
37
38 MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out ssh-vulnkey.1.out sshd_config.5.out ssh_config.5.out
39 MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 ssh-vulnkey.1 sshd_config.5 ssh_config.5
40diff --git a/configure b/configure
41index ceb1b5d..78bbcd0 100755
42--- a/configure
43+++ b/configure
44@@ -738,6 +738,7 @@ with_privsep_user
45 with_sandbox
46 with_selinux
47 with_kerberos5
48+with_consolekit
49 with_privsep_path
50 with_xauth
51 enable_strip
52@@ -1428,6 +1429,7 @@ Optional Packages:
53 --with-sandbox=style Specify privilege separation sandbox (no, darwin, rlimit, systrace, seccomp_filter)
54 --with-selinux Enable SELinux support
55 --with-kerberos5=PATH Enable Kerberos 5 support
56+ --with-consolekit Enable ConsoleKit support
57 --with-privsep-path=xxx Path for privilege separation chroot (default=/var/empty)
58 --with-xauth=PATH Specify path to xauth program
59 --with-maildir=/path/to/mail Specify your system mail directory
60@@ -16375,6 +16377,135 @@ fi
61
62
63
64+# Check whether user wants ConsoleKit support
65+CONSOLEKIT_MSG="no"
66+LIBCK_CONNECTOR=""
67+
68+# Check whether --with-consolekit was given.
69+if test "${with_consolekit+set}" = set; then :
70+ withval=$with_consolekit; if test "x$withval" != "xno" ; then
71+ if test -n "$ac_tool_prefix"; then
72+ # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
73+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
74+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
75+$as_echo_n "checking for $ac_word... " >&6; }
76+if ${ac_cv_path_PKGCONFIG+:} false; then :
77+ $as_echo_n "(cached) " >&6
78+else
79+ case $PKGCONFIG in
80+ [\\/]* | ?:[\\/]*)
81+ ac_cv_path_PKGCONFIG="$PKGCONFIG" # Let the user override the test with a path.
82+ ;;
83+ *)
84+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
85+for as_dir in $PATH
86+do
87+ IFS=$as_save_IFS
88+ test -z "$as_dir" && as_dir=.
89+ for ac_exec_ext in '' $ac_executable_extensions; do
90+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
91+ ac_cv_path_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
92+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
93+ break 2
94+ fi
95+done
96+ done
97+IFS=$as_save_IFS
98+
99+ ;;
100+esac
101+fi
102+PKGCONFIG=$ac_cv_path_PKGCONFIG
103+if test -n "$PKGCONFIG"; then
104+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKGCONFIG" >&5
105+$as_echo "$PKGCONFIG" >&6; }
106+else
107+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
108+$as_echo "no" >&6; }
109+fi
110+
111+
112+fi
113+if test -z "$ac_cv_path_PKGCONFIG"; then
114+ ac_pt_PKGCONFIG=$PKGCONFIG
115+ # Extract the first word of "pkg-config", so it can be a program name with args.
116+set dummy pkg-config; ac_word=$2
117+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
118+$as_echo_n "checking for $ac_word... " >&6; }
119+if ${ac_cv_path_ac_pt_PKGCONFIG+:} false; then :
120+ $as_echo_n "(cached) " >&6
121+else
122+ case $ac_pt_PKGCONFIG in
123+ [\\/]* | ?:[\\/]*)
124+ ac_cv_path_ac_pt_PKGCONFIG="$ac_pt_PKGCONFIG" # Let the user override the test with a path.
125+ ;;
126+ *)
127+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
128+for as_dir in $PATH
129+do
130+ IFS=$as_save_IFS
131+ test -z "$as_dir" && as_dir=.
132+ for ac_exec_ext in '' $ac_executable_extensions; do
133+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
134+ ac_cv_path_ac_pt_PKGCONFIG="$as_dir/$ac_word$ac_exec_ext"
135+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
136+ break 2
137+ fi
138+done
139+ done
140+IFS=$as_save_IFS
141+
142+ ;;
143+esac
144+fi
145+ac_pt_PKGCONFIG=$ac_cv_path_ac_pt_PKGCONFIG
146+if test -n "$ac_pt_PKGCONFIG"; then
147+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKGCONFIG" >&5
148+$as_echo "$ac_pt_PKGCONFIG" >&6; }
149+else
150+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
151+$as_echo "no" >&6; }
152+fi
153+
154+ if test "x$ac_pt_PKGCONFIG" = x; then
155+ PKGCONFIG="no"
156+ else
157+ case $cross_compiling:$ac_tool_warned in
158+yes:)
159+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
160+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
161+ac_tool_warned=yes ;;
162+esac
163+ PKGCONFIG=$ac_pt_PKGCONFIG
164+ fi
165+else
166+ PKGCONFIG="$ac_cv_path_PKGCONFIG"
167+fi
168+
169+ if test "$PKGCONFIG" != "no"; then
170+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ck-connector" >&5
171+$as_echo_n "checking for ck-connector... " >&6; }
172+ if $PKGCONFIG --exists ck-connector; then
173+ CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
174+ CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
175+ CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
176+ SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
177+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
178+$as_echo "yes" >&6; }
179+
180+$as_echo "#define USE_CONSOLEKIT 1" >>confdefs.h
181+
182+ CONSOLEKIT_MSG="yes"
183+ else
184+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
185+$as_echo "no" >&6; }
186+ fi
187+ fi
188+ fi
189+
190+fi
191+
192+
193 # Looking for programs, paths and files
194
195 PRIVSEP_PATH=/var/empty
196@@ -18902,6 +19033,7 @@ echo " MD5 password support: $MD5_MSG"
197 echo " libedit support: $LIBEDIT_MSG"
198 echo " Solaris process contract support: $SPC_MSG"
199 echo " Solaris project support: $SP_MSG"
200+echo " ConsoleKit support: $CONSOLEKIT_MSG"
201 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
202 echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
203 echo " BSD Auth support: $BSD_AUTH_MSG"
204diff --git a/configure.ac b/configure.ac
205index 4c1a658..d7d500a 100644
206--- a/configure.ac
207+++ b/configure.ac
208@@ -3841,6 +3841,30 @@ AC_ARG_WITH([kerberos5],
209 AC_SUBST([GSSLIBS])
210 AC_SUBST([K5LIBS])
211
212+# Check whether user wants ConsoleKit support
213+CONSOLEKIT_MSG="no"
214+LIBCK_CONNECTOR=""
215+AC_ARG_WITH(consolekit,
216+ [ --with-consolekit Enable ConsoleKit support],
217+ [ if test "x$withval" != "xno" ; then
218+ AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
219+ if test "$PKGCONFIG" != "no"; then
220+ AC_MSG_CHECKING([for ck-connector])
221+ if $PKGCONFIG --exists ck-connector; then
222+ CKCON_CFLAGS=`$PKGCONFIG --cflags ck-connector`
223+ CKCON_LIBS=`$PKGCONFIG --libs ck-connector`
224+ CPPFLAGS="$CPPFLAGS $CKCON_CFLAGS"
225+ SSHDLIBS="$SSHDLIBS $CKCON_LIBS"
226+ AC_MSG_RESULT([yes])
227+ AC_DEFINE(USE_CONSOLEKIT, 1, [Define if you want ConsoleKit support.])
228+ CONSOLEKIT_MSG="yes"
229+ else
230+ AC_MSG_RESULT([no])
231+ fi
232+ fi
233+ fi ]
234+)
235+
236 # Looking for programs, paths and files
237
238 PRIVSEP_PATH=/var/empty
239@@ -4641,6 +4665,7 @@ echo " MD5 password support: $MD5_MSG"
240 echo " libedit support: $LIBEDIT_MSG"
241 echo " Solaris process contract support: $SPC_MSG"
242 echo " Solaris project support: $SP_MSG"
243+echo " ConsoleKit support: $CONSOLEKIT_MSG"
244 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
245 echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
246 echo " BSD Auth support: $BSD_AUTH_MSG"
247diff --git a/consolekit.c b/consolekit.c
248new file mode 100644
249index 0000000..f1039e6
250--- /dev/null
251+++ b/consolekit.c
252@@ -0,0 +1,240 @@
253+/*
254+ * Copyright (c) 2008 Colin Watson. All rights reserved.
255+ *
256+ * Permission to use, copy, modify, and distribute this software for any
257+ * purpose with or without fee is hereby granted, provided that the above
258+ * copyright notice and this permission notice appear in all copies.
259+ *
260+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
261+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
262+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
263+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
264+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
265+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
266+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
267+ */
268+/*
269+ * Loosely based on pam-ck-connector, which is:
270+ *
271+ * Copyright (c) 2007 David Zeuthen <davidz@redhat.com>
272+ *
273+ * Permission is hereby granted, free of charge, to any person
274+ * obtaining a copy of this software and associated documentation
275+ * files (the "Software"), to deal in the Software without
276+ * restriction, including without limitation the rights to use,
277+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
278+ * copies of the Software, and to permit persons to whom the
279+ * Software is furnished to do so, subject to the following
280+ * conditions:
281+ *
282+ * The above copyright notice and this permission notice shall be
283+ * included in all copies or substantial portions of the Software.
284+ *
285+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
286+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
287+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
288+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
289+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
290+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
291+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
292+ * OTHER DEALINGS IN THE SOFTWARE.
293+ */
294+
295+#include "includes.h"
296+
297+#ifdef USE_CONSOLEKIT
298+
299+#include <ck-connector.h>
300+
301+#include "openbsd-compat/sys-queue.h"
302+#include "xmalloc.h"
303+#include "channels.h"
304+#include "key.h"
305+#include "hostfile.h"
306+#include "auth.h"
307+#include "log.h"
308+#include "servconf.h"
309+#include "canohost.h"
310+#include "session.h"
311+#include "consolekit.h"
312+
313+extern ServerOptions options;
314+extern u_int utmp_len;
315+
316+void
317+set_active(const char *cookie)
318+{
319+ DBusError err;
320+ DBusConnection *connection;
321+ DBusMessage *message = NULL, *reply = NULL;
322+ char *sid;
323+ DBusMessageIter iter, subiter;
324+ const char *interface, *property;
325+ dbus_bool_t active;
326+
327+ dbus_error_init(&err);
328+ connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
329+ if (!connection) {
330+ if (dbus_error_is_set(&err)) {
331+ error("unable to open DBus connection: %s",
332+ err.message);
333+ dbus_error_free(&err);
334+ }
335+ goto out;
336+ }
337+ dbus_connection_set_exit_on_disconnect(connection, FALSE);
338+
339+ message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
340+ "/org/freedesktop/ConsoleKit/Manager",
341+ "org.freedesktop.ConsoleKit.Manager",
342+ "GetSessionForCookie");
343+ if (!message)
344+ goto out;
345+ if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &cookie,
346+ DBUS_TYPE_INVALID)) {
347+ if (dbus_error_is_set(&err)) {
348+ error("unable to get current session: %s",
349+ err.message);
350+ dbus_error_free(&err);
351+ }
352+ goto out;
353+ }
354+
355+ dbus_error_init(&err);
356+ reply = dbus_connection_send_with_reply_and_block(connection, message,
357+ -1, &err);
358+ if (!reply) {
359+ if (dbus_error_is_set(&err)) {
360+ error("unable to get current session: %s",
361+ err.message);
362+ dbus_error_free(&err);
363+ }
364+ goto out;
365+ }
366+
367+ dbus_error_init(&err);
368+ if (!dbus_message_get_args(reply, &err,
369+ DBUS_TYPE_OBJECT_PATH, &sid,
370+ DBUS_TYPE_INVALID)) {
371+ if (dbus_error_is_set(&err)) {
372+ error("unable to get current session: %s",
373+ err.message);
374+ dbus_error_free(&err);
375+ }
376+ goto out;
377+ }
378+ dbus_message_unref(reply);
379+ dbus_message_unref(message);
380+ message = reply = NULL;
381+
382+ message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
383+ sid, "org.freedesktop.DBus.Properties", "Set");
384+ if (!message)
385+ goto out;
386+ interface = "org.freedesktop.ConsoleKit.Session";
387+ property = "active";
388+ if (!dbus_message_append_args(message,
389+ DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property,
390+ DBUS_TYPE_INVALID))
391+ goto out;
392+ dbus_message_iter_init_append(message, &iter);
393+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
394+ DBUS_TYPE_BOOLEAN_AS_STRING, &subiter))
395+ goto out;
396+ active = TRUE;
397+ if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_BOOLEAN,
398+ &active))
399+ goto out;
400+ if (!dbus_message_iter_close_container(&iter, &subiter))
401+ goto out;
402+
403+ dbus_error_init(&err);
404+ reply = dbus_connection_send_with_reply_and_block(connection, message,
405+ -1, &err);
406+ if (!reply) {
407+ if (dbus_error_is_set(&err)) {
408+ error("unable to make current session active: %s",
409+ err.message);
410+ dbus_error_free(&err);
411+ }
412+ goto out;
413+ }
414+
415+out:
416+ if (reply)
417+ dbus_message_unref(reply);
418+ if (message)
419+ dbus_message_unref(message);
420+}
421+
422+/*
423+ * We pass display separately rather than using s->display because the
424+ * latter is not available in the monitor when using privsep.
425+ */
426+
427+char *
428+consolekit_register(Session *s, const char *display)
429+{
430+ DBusError err;
431+ const char *tty = s->tty;
432+ const char *remote_host_name;
433+ dbus_bool_t is_local = FALSE;
434+ const char *cookie = NULL;
435+
436+ if (s->ckc) {
437+ debug("already registered with ConsoleKit");
438+ return xstrdup(ck_connector_get_cookie(s->ckc));
439+ }
440+
441+ s->ckc = ck_connector_new();
442+ if (!s->ckc) {
443+ error("ck_connector_new failed");
444+ return NULL;
445+ }
446+
447+ if (!tty)
448+ tty = "";
449+ if (!display)
450+ display = "";
451+ remote_host_name = get_remote_name_or_ip(utmp_len, options.use_dns);
452+ if (!remote_host_name)
453+ remote_host_name = "";
454+
455+ dbus_error_init(&err);
456+ if (!ck_connector_open_session_with_parameters(s->ckc, &err,
457+ "unix-user", &s->pw->pw_uid,
458+ "display-device", &tty,
459+ "x11-display", &display,
460+ "remote-host-name", &remote_host_name,
461+ "is-local", &is_local,
462+ NULL)) {
463+ if (dbus_error_is_set(&err)) {
464+ debug("%s", err.message);
465+ dbus_error_free(&err);
466+ } else {
467+ debug("insufficient privileges or D-Bus / ConsoleKit "
468+ "not available");
469+ }
470+ return NULL;
471+ }
472+
473+ debug("registered uid=%d on tty='%s' with ConsoleKit",
474+ s->pw->pw_uid, s->tty);
475+
476+ cookie = ck_connector_get_cookie(s->ckc);
477+ set_active(cookie);
478+ return xstrdup(cookie);
479+}
480+
481+void
482+consolekit_unregister(Session *s)
483+{
484+ if (s->ckc) {
485+ debug("unregistering ConsoleKit session %s",
486+ ck_connector_get_cookie(s->ckc));
487+ ck_connector_unref(s->ckc);
488+ s->ckc = NULL;
489+ }
490+}
491+
492+#endif /* USE_CONSOLEKIT */
493diff --git a/consolekit.h b/consolekit.h
494new file mode 100644
495index 0000000..8ce3716
496--- /dev/null
497+++ b/consolekit.h
498@@ -0,0 +1,24 @@
499+/*
500+ * Copyright (c) 2008 Colin Watson. All rights reserved.
501+ *
502+ * Permission to use, copy, modify, and distribute this software for any
503+ * purpose with or without fee is hereby granted, provided that the above
504+ * copyright notice and this permission notice appear in all copies.
505+ *
506+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
507+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
508+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
509+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
510+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
511+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
512+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
513+ */
514+
515+#ifdef USE_CONSOLEKIT
516+
517+struct Session;
518+
519+char * consolekit_register(struct Session *, const char *);
520+void consolekit_unregister(struct Session *);
521+
522+#endif /* USE_CONSOLEKIT */
523diff --git a/monitor.c b/monitor.c
524index e8d63eb..9bc4f0b 100644
525--- a/monitor.c
526+++ b/monitor.c
527@@ -98,6 +98,9 @@
528 #include "jpake.h"
529 #include "roaming.h"
530 #include "authfd.h"
531+#ifdef USE_CONSOLEKIT
532+#include "consolekit.h"
533+#endif
534
535 #ifdef GSSAPI
536 static Gssctxt *gsscontext = NULL;
537@@ -193,6 +196,10 @@ int mm_answer_audit_command(int, Buffer *);
538
539 static int monitor_read_log(struct monitor *);
540
541+#ifdef USE_CONSOLEKIT
542+int mm_answer_consolekit_register(int, Buffer *);
543+#endif
544+
545 static Authctxt *authctxt;
546 static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
547
548@@ -285,6 +292,9 @@ struct mon_table mon_dispatch_postauth20[] = {
549 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
550 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
551 #endif
552+#ifdef USE_CONSOLEKIT
553+ {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
554+#endif
555 {0, 0, NULL}
556 };
557
558@@ -327,6 +337,9 @@ struct mon_table mon_dispatch_postauth15[] = {
559 {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
560 {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},
561 #endif
562+#ifdef USE_CONSOLEKIT
563+ {MONITOR_REQ_CONSOLEKIT_REGISTER, 0, mm_answer_consolekit_register},
564+#endif
565 {0, 0, NULL}
566 };
567
568@@ -514,6 +527,9 @@ monitor_child_postauth(struct monitor *pmonitor)
569 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
570 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
571 }
572+#ifdef USE_CONSOLEKIT
573+ monitor_permit(mon_dispatch, MONITOR_REQ_CONSOLEKIT_REGISTER, 1);
574+#endif
575
576 for (;;)
577 monitor_read(pmonitor, mon_dispatch, NULL);
578@@ -2492,3 +2508,30 @@ mm_answer_jpake_check_confirm(int sock, Buffer *m)
579 }
580
581 #endif /* JPAKE */
582+
583+#ifdef USE_CONSOLEKIT
584+int
585+mm_answer_consolekit_register(int sock, Buffer *m)
586+{
587+ Session *s;
588+ char *tty, *display;
589+ char *cookie = NULL;
590+
591+ debug3("%s entering", __func__);
592+
593+ tty = buffer_get_string(m, NULL);
594+ display = buffer_get_string(m, NULL);
595+ s = session_by_tty(tty);
596+ if (s != NULL)
597+ cookie = consolekit_register(s, display);
598+ buffer_clear(m);
599+ buffer_put_cstring(m, cookie != NULL ? cookie : "");
600+ mm_request_send(sock, MONITOR_ANS_CONSOLEKIT_REGISTER, m);
601+
602+ free(cookie);
603+ free(display);
604+ free(tty);
605+
606+ return (0);
607+}
608+#endif /* USE_CONSOLEKIT */
609diff --git a/monitor.h b/monitor.h
610index 3c13706..cd83428 100644
611--- a/monitor.h
612+++ b/monitor.h
613@@ -75,6 +75,8 @@ enum monitor_reqtype {
614
615 MONITOR_REQ_AUTHROLE = 154,
616
617+ MONITOR_REQ_CONSOLEKIT_REGISTER = 156, MONITOR_ANS_CONSOLEKIT_REGISTER = 157,
618+
619 };
620
621 struct mm_master;
622diff --git a/monitor_wrap.c b/monitor_wrap.c
623index 69bc324..670b62d 100644
624--- a/monitor_wrap.c
625+++ b/monitor_wrap.c
626@@ -1516,3 +1516,34 @@ mm_jpake_check_confirm(const BIGNUM *k,
627 return success;
628 }
629 #endif /* JPAKE */
630+
631+#ifdef USE_CONSOLEKIT
632+char *
633+mm_consolekit_register(Session *s, const char *display)
634+{
635+ Buffer m;
636+ char *cookie;
637+
638+ debug3("%s entering", __func__);
639+
640+ if (s->ttyfd == -1)
641+ return NULL;
642+ buffer_init(&m);
643+ buffer_put_cstring(&m, s->tty);
644+ buffer_put_cstring(&m, display != NULL ? display : "");
645+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_CONSOLEKIT_REGISTER, &m);
646+ buffer_clear(&m);
647+
648+ mm_request_receive_expect(pmonitor->m_recvfd,
649+ MONITOR_ANS_CONSOLEKIT_REGISTER, &m);
650+ cookie = buffer_get_string(&m, NULL);
651+ buffer_free(&m);
652+
653+ /* treat empty cookie as missing cookie */
654+ if (strlen(cookie) == 0) {
655+ free(cookie);
656+ cookie = NULL;
657+ }
658+ return (cookie);
659+}
660+#endif /* USE_CONSOLEKIT */
661diff --git a/monitor_wrap.h b/monitor_wrap.h
662index 4d12e29..360fb9f 100644
663--- a/monitor_wrap.h
664+++ b/monitor_wrap.h
665@@ -131,4 +131,8 @@ void *mm_zalloc(struct mm_master *, u_int, u_int);
666 void mm_zfree(struct mm_master *, void *);
667 void mm_init_compression(struct mm_master *);
668
669+#ifdef USE_CONSOLEKIT
670+char *mm_consolekit_register(struct Session *, const char *);
671+#endif /* USE_CONSOLEKIT */
672+
673 #endif /* _MM_WRAP_H_ */
674diff --git a/session.c b/session.c
675index b4d74d9..15bdb1b 100644
676--- a/session.c
677+++ b/session.c
678@@ -92,6 +92,7 @@
679 #include "kex.h"
680 #include "monitor_wrap.h"
681 #include "sftp.h"
682+#include "consolekit.h"
683
684 #if defined(KRB5) && defined(USE_AFS)
685 #include <kafs.h>
686@@ -1132,6 +1133,9 @@ do_setup_env(Session *s, const char *shell)
687 #if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN)
688 char *path = NULL;
689 #endif
690+#ifdef USE_CONSOLEKIT
691+ const char *ckcookie = NULL;
692+#endif /* USE_CONSOLEKIT */
693
694 /* Initialize the environment. */
695 envsize = 100;
696@@ -1276,6 +1280,11 @@ do_setup_env(Session *s, const char *shell)
697 child_set_env(&env, &envsize, "KRB5CCNAME",
698 s->authctxt->krb5_ccname);
699 #endif
700+#ifdef USE_CONSOLEKIT
701+ ckcookie = PRIVSEP(consolekit_register(s, s->display));
702+ if (ckcookie)
703+ child_set_env(&env, &envsize, "XDG_SESSION_COOKIE", ckcookie);
704+#endif /* USE_CONSOLEKIT */
705 #ifdef USE_PAM
706 /*
707 * Pull in any environment variables that may have
708@@ -2320,6 +2329,10 @@ session_pty_cleanup2(Session *s)
709
710 debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
711
712+#ifdef USE_CONSOLEKIT
713+ consolekit_unregister(s);
714+#endif /* USE_CONSOLEKIT */
715+
716 /* Record that the user has logged out. */
717 if (s->pid != 0)
718 record_logout(s->pid, s->tty, s->pw->pw_name);
719diff --git a/session.h b/session.h
720index cb4f196..7e51b6a 100644
721--- a/session.h
722+++ b/session.h
723@@ -26,6 +26,8 @@
724 #ifndef SESSION_H
725 #define SESSION_H
726
727+struct _CkConnector;
728+
729 #define TTYSZ 64
730 typedef struct Session Session;
731 struct Session {
732@@ -60,6 +62,10 @@ struct Session {
733 char *name;
734 char *val;
735 } *env;
736+
737+#ifdef USE_CONSOLEKIT
738+ struct _CkConnector *ckc;
739+#endif /* USE_CONSOLEKIT */
740 };
741
742 void do_authenticated(Authctxt *);
diff --git a/debian/patches/debian-banner.patch b/debian/patches/debian-banner.patch
new file mode 100644
index 000000000..d02e8ffcb
--- /dev/null
+++ b/debian/patches/debian-banner.patch
@@ -0,0 +1,111 @@
1From 8a75df792931443e868e574408ed1666208a28c2 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: 2013-09-14
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 9155a8b..a2928ff 100644
23--- a/servconf.c
24+++ b/servconf.c
25@@ -157,6 +157,7 @@ initialize_server_options(ServerOptions *options)
26 options->ip_qos_interactive = -1;
27 options->ip_qos_bulk = -1;
28 options->version_addendum = NULL;
29+ options->debian_banner = -1;
30 }
31
32 void
33@@ -310,6 +311,8 @@ fill_default_server_options(ServerOptions *options)
34 options->ip_qos_bulk = IPTOS_THROUGHPUT;
35 if (options->version_addendum == NULL)
36 options->version_addendum = xstrdup("");
37+ if (options->debian_banner == -1)
38+ options->debian_banner = 1;
39 /* Turn privilege separation on by default */
40 if (use_privsep == -1)
41 use_privsep = PRIVSEP_NOSANDBOX;
42@@ -360,6 +363,7 @@ typedef enum {
43 sKexAlgorithms, sIPQoS, sVersionAddendum,
44 sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
45 sAuthenticationMethods, sHostKeyAgent,
46+ sDebianBanner,
47 sDeprecated, sUnsupported
48 } ServerOpCodes;
49
50@@ -501,6 +505,7 @@ static struct {
51 { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
52 { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
53 { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
54+ { "debianbanner", sDebianBanner, SSHCFG_GLOBAL },
55 { NULL, sBadOption, 0 }
56 };
57
58@@ -1648,6 +1653,10 @@ process_server_config_line(ServerOptions *options, char *line,
59 }
60 return 0;
61
62+ case sDebianBanner:
63+ intptr = &options->debian_banner;
64+ goto parse_int;
65+
66 case sDeprecated:
67 logit("%s line %d: Deprecated option %s",
68 filename, linenum, arg);
69diff --git a/servconf.h b/servconf.h
70index f655c5b..fd72ce2 100644
71--- a/servconf.h
72+++ b/servconf.h
73@@ -188,6 +188,8 @@ typedef struct {
74
75 u_int num_auth_methods;
76 char *auth_methods[MAX_AUTH_METHODS];
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 7efa7ef..6b988fe 100644
84--- a/sshd.c
85+++ b/sshd.c
86@@ -440,7 +440,8 @@ sshd_exchange_identification(int sock_in, int sock_out)
87 }
88
89 xasprintf(&server_version_string, "SSH-%d.%d-%.100s%s%s%s",
90- major, minor, SSH_RELEASE,
91+ major, minor,
92+ options.debian_banner ? SSH_RELEASE : SSH_RELEASE_MINIMUM,
93 *options.version_addendum == '\0' ? "" : " ",
94 options.version_addendum, newline);
95
96diff --git a/sshd_config.5 b/sshd_config.5
97index 510cc7c..eaf8d01 100644
98--- a/sshd_config.5
99+++ b/sshd_config.5
100@@ -404,6 +404,11 @@ or
101 .Dq no .
102 The default is
103 .Dq delayed .
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+.Dq 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..e706b4a02
--- /dev/null
+++ b/debian/patches/debian-config.patch
@@ -0,0 +1,159 @@
1From bb5616c94d6d6b97890e90dd01a7ad07c663dc0b 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 and disable GSSAPIDelegateCredentials by
15default.
16
17sshd: Refer to /usr/share/doc/openssh-server/README.Debian.gz alongside
18PermitRootLogin default.
19
20Document all of this, along with several sshd defaults set in
21debian/openssh-server.postinst.
22
23Author: Russ Allbery <rra@debian.org>
24Forwarded: not-needed
25Last-Update: 2013-09-14
26
27Patch-Name: debian-config.patch
28---
29 readconf.c | 2 +-
30 ssh_config | 7 ++++++-
31 ssh_config.5 | 19 ++++++++++++++++++-
32 sshd_config | 1 +
33 sshd_config.5 | 27 +++++++++++++++++++++++++++
34 5 files changed, 53 insertions(+), 3 deletions(-)
35
36diff --git a/readconf.c b/readconf.c
37index 389de7d..2778176 100644
38--- a/readconf.c
39+++ b/readconf.c
40@@ -1298,7 +1298,7 @@ fill_default_options(Options * options)
41 if (options->forward_x11 == -1)
42 options->forward_x11 = 0;
43 if (options->forward_x11_trusted == -1)
44- options->forward_x11_trusted = 0;
45+ options->forward_x11_trusted = 1;
46 if (options->forward_x11_timeout == -1)
47 options->forward_x11_timeout = 1200;
48 if (options->exit_on_forward_failure == -1)
49diff --git a/ssh_config b/ssh_config
50index 3234321..064b593 100644
51--- a/ssh_config
52+++ b/ssh_config
53@@ -17,9 +17,10 @@
54 # list of available options, their meanings and defaults, please see the
55 # ssh_config(5) man page.
56
57-# Host *
58+Host *
59 # ForwardAgent no
60 # ForwardX11 no
61+# ForwardX11Trusted yes
62 # RhostsRSAAuthentication no
63 # RSAAuthentication yes
64 # PasswordAuthentication yes
65@@ -48,3 +49,7 @@
66 # VisualHostKey no
67 # ProxyCommand ssh -q -W %h:%p gateway.example.com
68 # RekeyLimit 1G 1h
69+ SendEnv LANG LC_*
70+ HashKnownHosts yes
71+ GSSAPIAuthentication yes
72+ GSSAPIDelegateCredentials no
73diff --git a/ssh_config.5 b/ssh_config.5
74index 5bca932..127540a 100644
75--- a/ssh_config.5
76+++ b/ssh_config.5
77@@ -71,6 +71,22 @@ Since the first obtained value for each parameter is used, more
78 host-specific declarations should be given near the beginning of the
79 file, and general defaults at the end.
80 .Pp
81+Note that the Debian
82+.Ic openssh-client
83+package sets several options as standard in
84+.Pa /etc/ssh/ssh_config
85+which are not the default in
86+.Xr ssh 1 :
87+.Pp
88+.Bl -bullet -offset indent -compact
89+.It
90+.Cm SendEnv No LANG LC_*
91+.It
92+.Cm HashKnownHosts No yes
93+.It
94+.Cm GSSAPIAuthentication No yes
95+.El
96+.Pp
97 The configuration file has the following format:
98 .Pp
99 Empty lines and lines starting with
100@@ -501,7 +517,8 @@ token used for the session will be set to expire after 20 minutes.
101 Remote clients will be refused access after this time.
102 .Pp
103 The default is
104-.Dq no .
105+.Dq yes
106+(Debian-specific).
107 .Pp
108 See the X11 SECURITY extension specification for full details on
109 the restrictions imposed on untrusted clients.
110diff --git a/sshd_config b/sshd_config
111index 9450141..9cfe28d 100644
112--- a/sshd_config
113+++ b/sshd_config
114@@ -40,6 +40,7 @@
115 # Authentication:
116
117 #LoginGraceTime 2m
118+# See /usr/share/doc/openssh-server/README.Debian.gz.
119 #PermitRootLogin yes
120 #StrictModes yes
121 #MaxAuthTries 6
122diff --git a/sshd_config.5 b/sshd_config.5
123index ec4851a..faf93fc 100644
124--- a/sshd_config.5
125+++ b/sshd_config.5
126@@ -57,6 +57,33 @@ Arguments may optionally be enclosed in double quotes
127 .Pq \&"
128 in order to represent arguments containing spaces.
129 .Pp
130+Note that the Debian
131+.Ic openssh-server
132+package sets several options as standard in
133+.Pa /etc/ssh/sshd_config
134+which are not the default in
135+.Xr sshd 8 .
136+The exact list depends on whether the package was installed fresh or
137+upgraded from various possible previous versions, but includes at least the
138+following:
139+.Pp
140+.Bl -bullet -offset indent -compact
141+.It
142+.Cm Protocol No 2
143+.It
144+.Cm ChallengeResponseAuthentication No no
145+.It
146+.Cm X11Forwarding No yes
147+.It
148+.Cm PrintMotd No no
149+.It
150+.Cm AcceptEnv No LANG LC_*
151+.It
152+.Cm Subsystem No sftp /usr/lib/openssh/sftp-server
153+.It
154+.Cm UsePAM No yes
155+.El
156+.Pp
157 The possible
158 keywords and their meanings are as follows (note that
159 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..3cb291e97
--- /dev/null
+++ b/debian/patches/dnssec-sshfp.patch
@@ -0,0 +1,94 @@
1From 145099bdca1b959e2ef3555cd6ce0bc44fb69ce8 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 630b97a..478c3d9 100644
22--- a/dns.c
23+++ b/dns.c
24@@ -196,6 +196,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@@ -219,8 +220,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 dc6fe05..e061a29 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 1283f55..dbbc85a 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..4f9de88ec
--- /dev/null
+++ b/debian/patches/doc-hash-tab-completion.patch
@@ -0,0 +1,28 @@
1From cee45b00a94730c9a49a52a967ec08b9c29b9ca2 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 1497cfc..5bca932 100644
17--- a/ssh_config.5
18+++ b/ssh_config.5
19@@ -587,6 +587,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/doc-upstart.patch b/debian/patches/doc-upstart.patch
new file mode 100644
index 000000000..cb24998a2
--- /dev/null
+++ b/debian/patches/doc-upstart.patch
@@ -0,0 +1,29 @@
1From c1e7260fe4ed36dddc317655a69a7d4a69b3170a Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@ubuntu.com>
3Date: Sun, 9 Feb 2014 16:10:12 +0000
4Subject: Refer to ssh's Upstart job as well as its init script
5
6Forwarded: not-needed
7Last-Update: 2013-09-14
8
9Patch-Name: doc-upstart.patch
10---
11 sshd.8 | 5 ++++-
12 1 file changed, 4 insertions(+), 1 deletion(-)
13
14diff --git a/sshd.8 b/sshd.8
15index 6bdd219..b91f08c 100644
16--- a/sshd.8
17+++ b/sshd.8
18@@ -70,7 +70,10 @@ over an insecure network.
19 .Nm
20 listens for connections from clients.
21 It is normally started at boot from
22-.Pa /etc/init.d/ssh .
23+.Pa /etc/init.d/ssh
24+(or
25+.Pa /etc/init/ssh.conf
26+on systems using the Upstart init daemon).
27 It forks a new
28 daemon for each incoming connection.
29 The forked daemons handle
diff --git a/debian/patches/gnome-ssh-askpass2-icon.patch b/debian/patches/gnome-ssh-askpass2-icon.patch
new file mode 100644
index 000000000..58966dd74
--- /dev/null
+++ b/debian/patches/gnome-ssh-askpass2-icon.patch
@@ -0,0 +1,26 @@
1From 52e810085e196c457dfda9cad08ce76191d11fe7 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 9d97c30..04b3a11 100644
16--- a/contrib/gnome-ssh-askpass2.c
17+++ b/contrib/gnome-ssh-askpass2.c
18@@ -209,6 +209,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..8a919382e
--- /dev/null
+++ b/debian/patches/gssapi.patch
@@ -0,0 +1,3135 @@
1From 950be7e1b1a01ee9b25e2a72726a6370b8acacb6 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: 2013-11-09
21
22Patch-Name: gssapi.patch
23---
24 ChangeLog.gssapi | 113 +++++++++++++++++++
25 Makefile.in | 3 +-
26 auth-krb5.c | 17 ++-
27 auth2-gss.c | 48 +++++++-
28 auth2.c | 2 +
29 clientloop.c | 13 +++
30 config.h.in | 6 +
31 configure | 57 ++++++++++
32 configure.ac | 24 ++++
33 gss-genr.c | 276 ++++++++++++++++++++++++++++++++++++++++++++-
34 gss-serv-krb5.c | 84 +++++++++++++-
35 gss-serv.c | 221 +++++++++++++++++++++++++++++++-----
36 kex.c | 16 +++
37 kex.h | 14 +++
38 kexgssc.c | 333 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
39 kexgsss.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++
40 key.c | 1 +
41 key.h | 1 +
42 monitor.c | 108 +++++++++++++++++-
43 monitor.h | 3 +
44 monitor_wrap.c | 47 +++++++-
45 monitor_wrap.h | 4 +-
46 readconf.c | 42 +++++++
47 readconf.h | 5 +
48 servconf.c | 38 ++++++-
49 servconf.h | 3 +
50 ssh-gss.h | 39 ++++++-
51 ssh_config | 2 +
52 ssh_config.5 | 34 +++++-
53 sshconnect2.c | 124 ++++++++++++++++++++-
54 sshd.c | 110 ++++++++++++++++++
55 sshd_config | 2 +
56 sshd_config.5 | 28 +++++
57 33 files changed, 2050 insertions(+), 57 deletions(-)
58 create mode 100644 ChangeLog.gssapi
59 create mode 100644 kexgssc.c
60 create mode 100644 kexgsss.c
61
62diff --git a/ChangeLog.gssapi b/ChangeLog.gssapi
63new file mode 100644
64index 0000000..f117a33
65--- /dev/null
66+++ b/ChangeLog.gssapi
67@@ -0,0 +1,113 @@
68+20110101
69+ - Finally update for OpenSSH 5.6p1
70+ - Add GSSAPIServerIdentity option from Jim Basney
71+
72+20100308
73+ - [ Makefile.in, key.c, key.h ]
74+ Updates for OpenSSH 5.4p1
75+ - [ servconf.c ]
76+ Include GSSAPI options in the sshd -T configuration dump, and flag
77+ some older configuration options as being unsupported. Thanks to Colin
78+ Watson.
79+ -
80+
81+20100124
82+ - [ sshconnect2.c ]
83+ Adapt to deal with additional element in Authmethod structure. Thanks to
84+ Colin Watson
85+
86+20090615
87+ - [ gss-genr.c gss-serv.c kexgssc.c kexgsss.c monitor.c sshconnect2.c
88+ sshd.c ]
89+ Fix issues identified by Greg Hudson following a code review
90+ Check return value of gss_indicate_mechs
91+ Protect GSSAPI calls in monitor, so they can only be used if enabled
92+ Check return values of bignum functions in key exchange
93+ Use BN_clear_free to clear other side's DH value
94+ Make ssh_gssapi_id_kex more robust
95+ Only configure kex table pointers if GSSAPI is enabled
96+ Don't leak mechanism list, or gss mechanism list
97+ Cast data.length before printing
98+ If serverkey isn't provided, use an empty string, rather than NULL
99+
100+20090201
101+ - [ gss-genr.c gss-serv.c kex.h kexgssc.c readconf.c readconf.h ssh-gss.h
102+ ssh_config.5 sshconnet2.c ]
103+ Add support for the GSSAPIClientIdentity option, which allows the user
104+ to specify which GSSAPI identity to use to contact a given server
105+
106+20080404
107+ - [ gss-serv.c ]
108+ Add code to actually implement GSSAPIStrictAcceptCheck, which had somehow
109+ been omitted from a previous version of this patch. Reported by Borislav
110+ Stoichkov
111+
112+20070317
113+ - [ gss-serv-krb5.c ]
114+ Remove C99ism, where new_ccname was being declared in the middle of a
115+ function
116+
117+20061220
118+ - [ servconf.c ]
119+ Make default for GSSAPIStrictAcceptorCheck be Yes, to match previous, and
120+ documented, behaviour. Reported by Dan Watson.
121+
122+20060910
123+ - [ gss-genr.c kexgssc.c kexgsss.c kex.h monitor.c sshconnect2.c sshd.c
124+ ssh-gss.h ]
125+ add support for gss-group14-sha1 key exchange mechanisms
126+ - [ gss-serv.c servconf.c servconf.h sshd_config sshd_config.5 ]
127+ Add GSSAPIStrictAcceptorCheck option to allow the disabling of
128+ acceptor principal checking on multi-homed machines.
129+ <Bugzilla #928>
130+ - [ sshd_config ssh_config ]
131+ Add settings for GSSAPIKeyExchange and GSSAPITrustDNS to the sample
132+ configuration files
133+ - [ kexgss.c kegsss.c sshconnect2.c sshd.c ]
134+ Code cleanup. Replace strlen/xmalloc/snprintf sequences with xasprintf()
135+ Limit length of error messages displayed by client
136+
137+20060909
138+ - [ gss-genr.c gss-serv.c ]
139+ move ssh_gssapi_acquire_cred() and ssh_gssapi_server_ctx to be server
140+ only, where they belong
141+ <Bugzilla #1225>
142+
143+20060829
144+ - [ gss-serv-krb5.c ]
145+ Fix CCAPI credentials cache name when creating KRB5CCNAME environment
146+ variable
147+
148+20060828
149+ - [ gss-genr.c ]
150+ Avoid Heimdal context freeing problem
151+ <Fixed upstream 20060829>
152+
153+20060818
154+ - [ gss-genr.c ssh-gss.h sshconnect2.c ]
155+ Make sure that SPENGO is disabled
156+ <Bugzilla #1218 - Fixed upstream 20060818>
157+
158+20060421
159+ - [ gssgenr.c, sshconnect2.c ]
160+ a few type changes (signed versus unsigned, int versus size_t) to
161+ fix compiler errors/warnings
162+ (from jbasney AT ncsa.uiuc.edu)
163+ - [ kexgssc.c, sshconnect2.c ]
164+ fix uninitialized variable warnings
165+ (from jbasney AT ncsa.uiuc.edu)
166+ - [ gssgenr.c ]
167+ pass oid to gss_display_status (helpful when using GSSAPI mechglue)
168+ (from jbasney AT ncsa.uiuc.edu)
169+ <Bugzilla #1220 >
170+ - [ gss-serv-krb5.c ]
171+ #ifdef HAVE_GSSAPI_KRB5 should be #ifdef HAVE_GSSAPI_KRB5_H
172+ (from jbasney AT ncsa.uiuc.edu)
173+ <Fixed upstream 20060304>
174+ - [ readconf.c, readconf.h, ssh_config.5, sshconnect2.c
175+ add client-side GssapiKeyExchange option
176+ (from jbasney AT ncsa.uiuc.edu)
177+ - [ sshconnect2.c ]
178+ add support for GssapiTrustDns option for gssapi-with-mic
179+ (from jbasney AT ncsa.uiuc.edu)
180+ <gssapi-with-mic support is Bugzilla #1008>
181diff --git a/Makefile.in b/Makefile.in
182index 92c95a9..f979926 100644
183--- a/Makefile.in
184+++ b/Makefile.in
185@@ -72,6 +72,7 @@ LIBSSH_OBJS=authfd.o authfile.o bufaux.o bufbn.o buffer.o \
186 atomicio.o key.o dispatch.o kex.o mac.o uidswap.o uuencode.o misc.o \
187 monitor_fdpass.o rijndael.o ssh-dss.o ssh-ecdsa.o ssh-rsa.o dh.o \
188 kexdh.o kexgex.o kexdhc.o kexgexc.o bufec.o kexecdh.o kexecdhc.o \
189+ kexgssc.o \
190 msg.o progressmeter.o dns.o entropy.o gss-genr.o umac.o umac128.o \
191 jpake.o schnorr.o ssh-pkcs11.o krl.o
192
193@@ -88,7 +89,7 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \
194 auth2-none.o auth2-passwd.o auth2-pubkey.o auth2-jpake.o \
195 monitor_mm.o monitor.o monitor_wrap.o kexdhs.o kexgexs.o kexecdhs.o \
196 auth-krb5.o \
197- auth2-gss.o gss-serv.o gss-serv-krb5.o \
198+ auth2-gss.o gss-serv.o gss-serv-krb5.o kexgsss.o\
199 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
200 sftp-server.o sftp-common.o \
201 roaming_common.o roaming_serv.o \
202diff --git a/auth-krb5.c b/auth-krb5.c
203index 7c83f59..5613b57 100644
204--- a/auth-krb5.c
205+++ b/auth-krb5.c
206@@ -181,8 +181,13 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
207
208 len = strlen(authctxt->krb5_ticket_file) + 6;
209 authctxt->krb5_ccname = xmalloc(len);
210+#ifdef USE_CCAPI
211+ snprintf(authctxt->krb5_ccname, len, "API:%s",
212+ authctxt->krb5_ticket_file);
213+#else
214 snprintf(authctxt->krb5_ccname, len, "FILE:%s",
215 authctxt->krb5_ticket_file);
216+#endif
217
218 #ifdef USE_PAM
219 if (options.use_pam)
220@@ -239,15 +244,22 @@ krb5_cleanup_proc(Authctxt *authctxt)
221 #ifndef HEIMDAL
222 krb5_error_code
223 ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
224- int tmpfd, ret, oerrno;
225+ int ret, oerrno;
226 char ccname[40];
227 mode_t old_umask;
228+#ifdef USE_CCAPI
229+ char cctemplate[] = "API:krb5cc_%d";
230+#else
231+ char cctemplate[] = "FILE:/tmp/krb5cc_%d_XXXXXXXXXX";
232+ int tmpfd;
233+#endif
234
235 ret = snprintf(ccname, sizeof(ccname),
236- "FILE:/tmp/krb5cc_%d_XXXXXXXXXX", geteuid());
237+ cctemplate, geteuid());
238 if (ret < 0 || (size_t)ret >= sizeof(ccname))
239 return ENOMEM;
240
241+#ifndef USE_CCAPI
242 old_umask = umask(0177);
243 tmpfd = mkstemp(ccname + strlen("FILE:"));
244 oerrno = errno;
245@@ -264,6 +276,7 @@ ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
246 return oerrno;
247 }
248 close(tmpfd);
249+#endif
250
251 return (krb5_cc_resolve(ctx, ccname, ccache));
252 }
253diff --git a/auth2-gss.c b/auth2-gss.c
254index 638d8f8..b8db820 100644
255--- a/auth2-gss.c
256+++ b/auth2-gss.c
257@@ -1,7 +1,7 @@
258 /* $OpenBSD: auth2-gss.c,v 1.20 2013/05/17 00:13:13 djm Exp $ */
259
260 /*
261- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
262+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
263 *
264 * Redistribution and use in source and binary forms, with or without
265 * modification, are permitted provided that the following conditions
266@@ -52,6 +52,40 @@ static void input_gssapi_mic(int type, u_int32_t plen, void *ctxt);
267 static void input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt);
268 static void input_gssapi_errtok(int, u_int32_t, void *);
269
270+/*
271+ * The 'gssapi_keyex' userauth mechanism.
272+ */
273+static int
274+userauth_gsskeyex(Authctxt *authctxt)
275+{
276+ int authenticated = 0;
277+ Buffer b;
278+ gss_buffer_desc mic, gssbuf;
279+ u_int len;
280+
281+ mic.value = packet_get_string(&len);
282+ mic.length = len;
283+
284+ packet_check_eom();
285+
286+ ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service,
287+ "gssapi-keyex");
288+
289+ gssbuf.value = buffer_ptr(&b);
290+ gssbuf.length = buffer_len(&b);
291+
292+ /* gss_kex_context is NULL with privsep, so we can't check it here */
293+ if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gss_kex_context,
294+ &gssbuf, &mic))))
295+ authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
296+ authctxt->pw));
297+
298+ buffer_free(&b);
299+ free(mic.value);
300+
301+ return (authenticated);
302+}
303+
304 /*
305 * We only support those mechanisms that we know about (ie ones that we know
306 * how to check local user kuserok and the like)
307@@ -240,7 +274,8 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt)
308
309 packet_check_eom();
310
311- authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
312+ authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
313+ authctxt->pw));
314
315 authctxt->postponed = 0;
316 dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
317@@ -275,7 +310,8 @@ input_gssapi_mic(int type, u_int32_t plen, void *ctxt)
318 gssbuf.length = buffer_len(&b);
319
320 if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic))))
321- authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
322+ authenticated =
323+ PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw));
324 else
325 logit("GSSAPI MIC check failed");
326
327@@ -290,6 +326,12 @@ input_gssapi_mic(int type, u_int32_t plen, void *ctxt)
328 userauth_finish(authctxt, authenticated, "gssapi-with-mic", NULL);
329 }
330
331+Authmethod method_gsskeyex = {
332+ "gssapi-keyex",
333+ userauth_gsskeyex,
334+ &options.gss_authentication
335+};
336+
337 Authmethod method_gssapi = {
338 "gssapi-with-mic",
339 userauth_gssapi,
340diff --git a/auth2.c b/auth2.c
341index f0cab8c..6ed8f04 100644
342--- a/auth2.c
343+++ b/auth2.c
344@@ -69,6 +69,7 @@ extern Authmethod method_passwd;
345 extern Authmethod method_kbdint;
346 extern Authmethod method_hostbased;
347 #ifdef GSSAPI
348+extern Authmethod method_gsskeyex;
349 extern Authmethod method_gssapi;
350 #endif
351 #ifdef JPAKE
352@@ -79,6 +80,7 @@ Authmethod *authmethods[] = {
353 &method_none,
354 &method_pubkey,
355 #ifdef GSSAPI
356+ &method_gsskeyex,
357 &method_gssapi,
358 #endif
359 #ifdef JPAKE
360diff --git a/clientloop.c b/clientloop.c
361index 23c2f23..311dc13 100644
362--- a/clientloop.c
363+++ b/clientloop.c
364@@ -111,6 +111,10 @@
365 #include "msg.h"
366 #include "roaming.h"
367
368+#ifdef GSSAPI
369+#include "ssh-gss.h"
370+#endif
371+
372 /* import options */
373 extern Options options;
374
375@@ -1608,6 +1612,15 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
376 /* Do channel operations unless rekeying in progress. */
377 if (!rekeying) {
378 channel_after_select(readset, writeset);
379+
380+#ifdef GSSAPI
381+ if (options.gss_renewal_rekey &&
382+ ssh_gssapi_credentials_updated(GSS_C_NO_CONTEXT)) {
383+ debug("credentials updated - forcing rekey");
384+ need_rekeying = 1;
385+ }
386+#endif
387+
388 if (need_rekeying || packet_need_rekeying()) {
389 debug("need rekeying");
390 xxx_kex->done = 0;
391diff --git a/config.h.in b/config.h.in
392index b75e501..34f1c9c 100644
393--- a/config.h.in
394+++ b/config.h.in
395@@ -1546,6 +1546,9 @@
396 /* Use btmp to log bad logins */
397 #undef USE_BTMP
398
399+/* platform uses an in-memory credentials cache */
400+#undef USE_CCAPI
401+
402 /* Use libedit for sftp */
403 #undef USE_LIBEDIT
404
405@@ -1561,6 +1564,9 @@
406 /* Use PIPES instead of a socketpair() */
407 #undef USE_PIPES
408
409+/* platform has the Security Authorization Session API */
410+#undef USE_SECURITY_SESSION_API
411+
412 /* Define if you have Solaris process contracts */
413 #undef USE_SOLARIS_PROCESS_CONTRACTS
414
415diff --git a/configure b/configure
416index 0d6fad5..ceb1b5d 100755
417--- a/configure
418+++ b/configure
419@@ -6780,6 +6780,63 @@ $as_echo "#define SSH_TUN_COMPAT_AF 1" >>confdefs.h
420
421 $as_echo "#define SSH_TUN_PREPEND_AF 1" >>confdefs.h
422
423+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we have the Security Authorization Session API" >&5
424+$as_echo_n "checking if we have the Security Authorization Session API... " >&6; }
425+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
426+/* end confdefs.h. */
427+#include <Security/AuthSession.h>
428+int
429+main ()
430+{
431+SessionCreate(0, 0);
432+ ;
433+ return 0;
434+}
435+_ACEOF
436+if ac_fn_c_try_compile "$LINENO"; then :
437+ ac_cv_use_security_session_api="yes"
438+
439+$as_echo "#define USE_SECURITY_SESSION_API 1" >>confdefs.h
440+
441+ LIBS="$LIBS -framework Security"
442+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
443+$as_echo "yes" >&6; }
444+else
445+ ac_cv_use_security_session_api="no"
446+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
447+$as_echo "no" >&6; }
448+fi
449+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
450+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we have an in-memory credentials cache" >&5
451+$as_echo_n "checking if we have an in-memory credentials cache... " >&6; }
452+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
453+/* end confdefs.h. */
454+#include <Kerberos/Kerberos.h>
455+int
456+main ()
457+{
458+cc_context_t c;
459+ (void) cc_initialize (&c, 0, NULL, NULL);
460+ ;
461+ return 0;
462+}
463+_ACEOF
464+if ac_fn_c_try_compile "$LINENO"; then :
465+
466+$as_echo "#define USE_CCAPI 1" >>confdefs.h
467+
468+ LIBS="$LIBS -framework Security"
469+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
470+$as_echo "yes" >&6; }
471+ if test "x$ac_cv_use_security_session_api" = "xno"; then
472+ as_fn_error $? "*** Need a security framework to use the credentials cache API ***" "$LINENO" 5
473+ fi
474+else
475+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
476+$as_echo "no" >&6; }
477+
478+fi
479+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
480
481 ac_fn_c_check_decl "$LINENO" "AU_IPv4" "ac_cv_have_decl_AU_IPv4" "$ac_includes_default"
482 if test "x$ac_cv_have_decl_AU_IPv4" = xyes; then :
483diff --git a/configure.ac b/configure.ac
484index 4a1b503..4c1a658 100644
485--- a/configure.ac
486+++ b/configure.ac
487@@ -548,6 +548,30 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
488 [Use tunnel device compatibility to OpenBSD])
489 AC_DEFINE([SSH_TUN_PREPEND_AF], [1],
490 [Prepend the address family to IP tunnel traffic])
491+ AC_MSG_CHECKING([if we have the Security Authorization Session API])
492+ AC_TRY_COMPILE([#include <Security/AuthSession.h>],
493+ [SessionCreate(0, 0);],
494+ [ac_cv_use_security_session_api="yes"
495+ AC_DEFINE([USE_SECURITY_SESSION_API], [1],
496+ [platform has the Security Authorization Session API])
497+ LIBS="$LIBS -framework Security"
498+ AC_MSG_RESULT([yes])],
499+ [ac_cv_use_security_session_api="no"
500+ AC_MSG_RESULT([no])])
501+ AC_MSG_CHECKING([if we have an in-memory credentials cache])
502+ AC_TRY_COMPILE(
503+ [#include <Kerberos/Kerberos.h>],
504+ [cc_context_t c;
505+ (void) cc_initialize (&c, 0, NULL, NULL);],
506+ [AC_DEFINE([USE_CCAPI], [1],
507+ [platform uses an in-memory credentials cache])
508+ LIBS="$LIBS -framework Security"
509+ AC_MSG_RESULT([yes])
510+ if test "x$ac_cv_use_security_session_api" = "xno"; then
511+ AC_MSG_ERROR([*** Need a security framework to use the credentials cache API ***])
512+ fi],
513+ [AC_MSG_RESULT([no])]
514+ )
515 m4_pattern_allow([AU_IPv])
516 AC_CHECK_DECL([AU_IPv4], [],
517 AC_DEFINE([AU_IPv4], [0], [System only supports IPv4 audit records])
518diff --git a/gss-genr.c b/gss-genr.c
519index b39281b..b7d1b7d 100644
520--- a/gss-genr.c
521+++ b/gss-genr.c
522@@ -1,7 +1,7 @@
523 /* $OpenBSD: gss-genr.c,v 1.22 2013/11/08 00:39:15 djm Exp $ */
524
525 /*
526- * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
527+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
528 *
529 * Redistribution and use in source and binary forms, with or without
530 * modification, are permitted provided that the following conditions
531@@ -39,12 +39,167 @@
532 #include "buffer.h"
533 #include "log.h"
534 #include "ssh2.h"
535+#include "cipher.h"
536+#include "key.h"
537+#include "kex.h"
538+#include <openssl/evp.h>
539
540 #include "ssh-gss.h"
541
542 extern u_char *session_id2;
543 extern u_int session_id2_len;
544
545+typedef struct {
546+ char *encoded;
547+ gss_OID oid;
548+} ssh_gss_kex_mapping;
549+
550+/*
551+ * XXX - It would be nice to find a more elegant way of handling the
552+ * XXX passing of the key exchange context to the userauth routines
553+ */
554+
555+Gssctxt *gss_kex_context = NULL;
556+
557+static ssh_gss_kex_mapping *gss_enc2oid = NULL;
558+
559+int
560+ssh_gssapi_oid_table_ok() {
561+ return (gss_enc2oid != NULL);
562+}
563+
564+/*
565+ * Return a list of the gss-group1-sha1 mechanisms supported by this program
566+ *
567+ * We test mechanisms to ensure that we can use them, to avoid starting
568+ * a key exchange with a bad mechanism
569+ */
570+
571+char *
572+ssh_gssapi_client_mechanisms(const char *host, const char *client) {
573+ gss_OID_set gss_supported;
574+ OM_uint32 min_status;
575+
576+ if (GSS_ERROR(gss_indicate_mechs(&min_status, &gss_supported)))
577+ return NULL;
578+
579+ return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism,
580+ host, client));
581+}
582+
583+char *
584+ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
585+ const char *host, const char *client) {
586+ Buffer buf;
587+ size_t i;
588+ int oidpos, enclen;
589+ char *mechs, *encoded;
590+ u_char digest[EVP_MAX_MD_SIZE];
591+ char deroid[2];
592+ const EVP_MD *evp_md = EVP_md5();
593+ EVP_MD_CTX md;
594+
595+ if (gss_enc2oid != NULL) {
596+ for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
597+ free(gss_enc2oid[i].encoded);
598+ free(gss_enc2oid);
599+ }
600+
601+ gss_enc2oid = xmalloc(sizeof(ssh_gss_kex_mapping) *
602+ (gss_supported->count + 1));
603+
604+ buffer_init(&buf);
605+
606+ oidpos = 0;
607+ for (i = 0; i < gss_supported->count; i++) {
608+ if (gss_supported->elements[i].length < 128 &&
609+ (*check)(NULL, &(gss_supported->elements[i]), host, client)) {
610+
611+ deroid[0] = SSH_GSS_OIDTYPE;
612+ deroid[1] = gss_supported->elements[i].length;
613+
614+ EVP_DigestInit(&md, evp_md);
615+ EVP_DigestUpdate(&md, deroid, 2);
616+ EVP_DigestUpdate(&md,
617+ gss_supported->elements[i].elements,
618+ gss_supported->elements[i].length);
619+ EVP_DigestFinal(&md, digest, NULL);
620+
621+ encoded = xmalloc(EVP_MD_size(evp_md) * 2);
622+ enclen = __b64_ntop(digest, EVP_MD_size(evp_md),
623+ encoded, EVP_MD_size(evp_md) * 2);
624+
625+ if (oidpos != 0)
626+ buffer_put_char(&buf, ',');
627+
628+ buffer_append(&buf, KEX_GSS_GEX_SHA1_ID,
629+ sizeof(KEX_GSS_GEX_SHA1_ID) - 1);
630+ buffer_append(&buf, encoded, enclen);
631+ buffer_put_char(&buf, ',');
632+ buffer_append(&buf, KEX_GSS_GRP1_SHA1_ID,
633+ sizeof(KEX_GSS_GRP1_SHA1_ID) - 1);
634+ buffer_append(&buf, encoded, enclen);
635+ buffer_put_char(&buf, ',');
636+ buffer_append(&buf, KEX_GSS_GRP14_SHA1_ID,
637+ sizeof(KEX_GSS_GRP14_SHA1_ID) - 1);
638+ buffer_append(&buf, encoded, enclen);
639+
640+ gss_enc2oid[oidpos].oid = &(gss_supported->elements[i]);
641+ gss_enc2oid[oidpos].encoded = encoded;
642+ oidpos++;
643+ }
644+ }
645+ gss_enc2oid[oidpos].oid = NULL;
646+ gss_enc2oid[oidpos].encoded = NULL;
647+
648+ buffer_put_char(&buf, '\0');
649+
650+ mechs = xmalloc(buffer_len(&buf));
651+ buffer_get(&buf, mechs, buffer_len(&buf));
652+ buffer_free(&buf);
653+
654+ if (strlen(mechs) == 0) {
655+ free(mechs);
656+ mechs = NULL;
657+ }
658+
659+ return (mechs);
660+}
661+
662+gss_OID
663+ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
664+ int i = 0;
665+
666+ switch (kex_type) {
667+ case KEX_GSS_GRP1_SHA1:
668+ if (strlen(name) < sizeof(KEX_GSS_GRP1_SHA1_ID))
669+ return GSS_C_NO_OID;
670+ name += sizeof(KEX_GSS_GRP1_SHA1_ID) - 1;
671+ break;
672+ case KEX_GSS_GRP14_SHA1:
673+ if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA1_ID))
674+ return GSS_C_NO_OID;
675+ name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1;
676+ break;
677+ case KEX_GSS_GEX_SHA1:
678+ if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID))
679+ return GSS_C_NO_OID;
680+ name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1;
681+ break;
682+ default:
683+ return GSS_C_NO_OID;
684+ }
685+
686+ while (gss_enc2oid[i].encoded != NULL &&
687+ strcmp(name, gss_enc2oid[i].encoded) != 0)
688+ i++;
689+
690+ if (gss_enc2oid[i].oid != NULL && ctx != NULL)
691+ ssh_gssapi_set_oid(ctx, gss_enc2oid[i].oid);
692+
693+ return gss_enc2oid[i].oid;
694+}
695+
696 /* Check that the OID in a data stream matches that in the context */
697 int
698 ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len)
699@@ -197,7 +352,7 @@ ssh_gssapi_init_ctx(Gssctxt *ctx, int deleg_creds, gss_buffer_desc *recv_tok,
700 }
701
702 ctx->major = gss_init_sec_context(&ctx->minor,
703- GSS_C_NO_CREDENTIAL, &ctx->context, ctx->name, ctx->oid,
704+ ctx->client_creds, &ctx->context, ctx->name, ctx->oid,
705 GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag,
706 0, NULL, recv_tok, NULL, send_tok, flags, NULL);
707
708@@ -227,8 +382,42 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host)
709 }
710
711 OM_uint32
712+ssh_gssapi_client_identity(Gssctxt *ctx, const char *name)
713+{
714+ gss_buffer_desc gssbuf;
715+ gss_name_t gssname;
716+ OM_uint32 status;
717+ gss_OID_set oidset;
718+
719+ gssbuf.value = (void *) name;
720+ gssbuf.length = strlen(gssbuf.value);
721+
722+ gss_create_empty_oid_set(&status, &oidset);
723+ gss_add_oid_set_member(&status, ctx->oid, &oidset);
724+
725+ ctx->major = gss_import_name(&ctx->minor, &gssbuf,
726+ GSS_C_NT_USER_NAME, &gssname);
727+
728+ if (!ctx->major)
729+ ctx->major = gss_acquire_cred(&ctx->minor,
730+ gssname, 0, oidset, GSS_C_INITIATE,
731+ &ctx->client_creds, NULL, NULL);
732+
733+ gss_release_name(&status, &gssname);
734+ gss_release_oid_set(&status, &oidset);
735+
736+ if (ctx->major)
737+ ssh_gssapi_error(ctx);
738+
739+ return(ctx->major);
740+}
741+
742+OM_uint32
743 ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
744 {
745+ if (ctx == NULL)
746+ return -1;
747+
748 if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context,
749 GSS_C_QOP_DEFAULT, buffer, hash)))
750 ssh_gssapi_error(ctx);
751@@ -236,6 +425,19 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
752 return (ctx->major);
753 }
754
755+/* Priviledged when used by server */
756+OM_uint32
757+ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
758+{
759+ if (ctx == NULL)
760+ return -1;
761+
762+ ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
763+ gssbuf, gssmic, NULL);
764+
765+ return (ctx->major);
766+}
767+
768 void
769 ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service,
770 const char *context)
771@@ -249,11 +451,16 @@ ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service,
772 }
773
774 int
775-ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
776+ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host,
777+ const char *client)
778 {
779 gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
780 OM_uint32 major, minor;
781 gss_OID_desc spnego_oid = {6, (void *)"\x2B\x06\x01\x05\x05\x02"};
782+ Gssctxt *intctx = NULL;
783+
784+ if (ctx == NULL)
785+ ctx = &intctx;
786
787 /* RFC 4462 says we MUST NOT do SPNEGO */
788 if (oid->length == spnego_oid.length &&
789@@ -263,6 +470,10 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
790 ssh_gssapi_build_ctx(ctx);
791 ssh_gssapi_set_oid(*ctx, oid);
792 major = ssh_gssapi_import_name(*ctx, host);
793+
794+ if (!GSS_ERROR(major) && client)
795+ major = ssh_gssapi_client_identity(*ctx, client);
796+
797 if (!GSS_ERROR(major)) {
798 major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token,
799 NULL);
800@@ -272,10 +483,67 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
801 GSS_C_NO_BUFFER);
802 }
803
804- if (GSS_ERROR(major))
805+ if (GSS_ERROR(major) || intctx != NULL)
806 ssh_gssapi_delete_ctx(ctx);
807
808 return (!GSS_ERROR(major));
809 }
810
811+int
812+ssh_gssapi_credentials_updated(Gssctxt *ctxt) {
813+ static gss_name_t saved_name = GSS_C_NO_NAME;
814+ static OM_uint32 saved_lifetime = 0;
815+ static gss_OID saved_mech = GSS_C_NO_OID;
816+ static gss_name_t name;
817+ static OM_uint32 last_call = 0;
818+ OM_uint32 lifetime, now, major, minor;
819+ int equal;
820+ gss_cred_usage_t usage = GSS_C_INITIATE;
821+
822+ now = time(NULL);
823+
824+ if (ctxt) {
825+ debug("Rekey has happened - updating saved versions");
826+
827+ if (saved_name != GSS_C_NO_NAME)
828+ gss_release_name(&minor, &saved_name);
829+
830+ major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
831+ &saved_name, &saved_lifetime, NULL, NULL);
832+
833+ if (!GSS_ERROR(major)) {
834+ saved_mech = ctxt->oid;
835+ saved_lifetime+= now;
836+ } else {
837+ /* Handle the error */
838+ }
839+ return 0;
840+ }
841+
842+ if (now - last_call < 10)
843+ return 0;
844+
845+ last_call = now;
846+
847+ if (saved_mech == GSS_C_NO_OID)
848+ return 0;
849+
850+ major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
851+ &name, &lifetime, NULL, NULL);
852+ if (major == GSS_S_CREDENTIALS_EXPIRED)
853+ return 0;
854+ else if (GSS_ERROR(major))
855+ return 0;
856+
857+ major = gss_compare_name(&minor, saved_name, name, &equal);
858+ gss_release_name(&minor, &name);
859+ if (GSS_ERROR(major))
860+ return 0;
861+
862+ if (equal && (saved_lifetime < lifetime + now - 10))
863+ return 1;
864+
865+ return 0;
866+}
867+
868 #endif /* GSSAPI */
869diff --git a/gss-serv-krb5.c b/gss-serv-krb5.c
870index 87f2683..c55446a 100644
871--- a/gss-serv-krb5.c
872+++ b/gss-serv-krb5.c
873@@ -1,7 +1,7 @@
874 /* $OpenBSD: gss-serv-krb5.c,v 1.8 2013/07/20 01:55:13 djm Exp $ */
875
876 /*
877- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
878+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
879 *
880 * Redistribution and use in source and binary forms, with or without
881 * modification, are permitted provided that the following conditions
882@@ -122,6 +122,7 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
883 OM_uint32 maj_status, min_status;
884 int len;
885 const char *errmsg;
886+ const char *new_ccname;
887
888 if (client->creds == NULL) {
889 debug("No credentials stored");
890@@ -174,11 +175,16 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
891 return;
892 }
893
894- client->store.filename = xstrdup(krb5_cc_get_name(krb_context, ccache));
895+ new_ccname = krb5_cc_get_name(krb_context, ccache);
896+
897 client->store.envvar = "KRB5CCNAME";
898- len = strlen(client->store.filename) + 6;
899- client->store.envval = xmalloc(len);
900- snprintf(client->store.envval, len, "FILE:%s", client->store.filename);
901+#ifdef USE_CCAPI
902+ xasprintf(&client->store.envval, "API:%s", new_ccname);
903+ client->store.filename = NULL;
904+#else
905+ xasprintf(&client->store.envval, "FILE:%s", new_ccname);
906+ client->store.filename = xstrdup(new_ccname);
907+#endif
908
909 #ifdef USE_PAM
910 if (options.use_pam)
911@@ -190,6 +196,71 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
912 return;
913 }
914
915+int
916+ssh_gssapi_krb5_updatecreds(ssh_gssapi_ccache *store,
917+ ssh_gssapi_client *client)
918+{
919+ krb5_ccache ccache = NULL;
920+ krb5_principal principal = NULL;
921+ char *name = NULL;
922+ krb5_error_code problem;
923+ OM_uint32 maj_status, min_status;
924+
925+ if ((problem = krb5_cc_resolve(krb_context, store->envval, &ccache))) {
926+ logit("krb5_cc_resolve(): %.100s",
927+ krb5_get_err_text(krb_context, problem));
928+ return 0;
929+ }
930+
931+ /* Find out who the principal in this cache is */
932+ if ((problem = krb5_cc_get_principal(krb_context, ccache,
933+ &principal))) {
934+ logit("krb5_cc_get_principal(): %.100s",
935+ krb5_get_err_text(krb_context, problem));
936+ krb5_cc_close(krb_context, ccache);
937+ return 0;
938+ }
939+
940+ if ((problem = krb5_unparse_name(krb_context, principal, &name))) {
941+ logit("krb5_unparse_name(): %.100s",
942+ krb5_get_err_text(krb_context, problem));
943+ krb5_free_principal(krb_context, principal);
944+ krb5_cc_close(krb_context, ccache);
945+ return 0;
946+ }
947+
948+
949+ if (strcmp(name,client->exportedname.value)!=0) {
950+ debug("Name in local credentials cache differs. Not storing");
951+ krb5_free_principal(krb_context, principal);
952+ krb5_cc_close(krb_context, ccache);
953+ krb5_free_unparsed_name(krb_context, name);
954+ return 0;
955+ }
956+ krb5_free_unparsed_name(krb_context, name);
957+
958+ /* Name matches, so lets get on with it! */
959+
960+ if ((problem = krb5_cc_initialize(krb_context, ccache, principal))) {
961+ logit("krb5_cc_initialize(): %.100s",
962+ krb5_get_err_text(krb_context, problem));
963+ krb5_free_principal(krb_context, principal);
964+ krb5_cc_close(krb_context, ccache);
965+ return 0;
966+ }
967+
968+ krb5_free_principal(krb_context, principal);
969+
970+ if ((maj_status = gss_krb5_copy_ccache(&min_status, client->creds,
971+ ccache))) {
972+ logit("gss_krb5_copy_ccache() failed. Sorry!");
973+ krb5_cc_close(krb_context, ccache);
974+ return 0;
975+ }
976+
977+ return 1;
978+}
979+
980 ssh_gssapi_mech gssapi_kerberos_mech = {
981 "toWM5Slw5Ew8Mqkay+al2g==",
982 "Kerberos",
983@@ -197,7 +268,8 @@ ssh_gssapi_mech gssapi_kerberos_mech = {
984 NULL,
985 &ssh_gssapi_krb5_userok,
986 NULL,
987- &ssh_gssapi_krb5_storecreds
988+ &ssh_gssapi_krb5_storecreds,
989+ &ssh_gssapi_krb5_updatecreds
990 };
991
992 #endif /* KRB5 */
993diff --git a/gss-serv.c b/gss-serv.c
994index 95348e2..97f366f 100644
995--- a/gss-serv.c
996+++ b/gss-serv.c
997@@ -1,7 +1,7 @@
998 /* $OpenBSD: gss-serv.c,v 1.24 2013/07/20 01:55:13 djm Exp $ */
999
1000 /*
1001- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
1002+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1003 *
1004 * Redistribution and use in source and binary forms, with or without
1005 * modification, are permitted provided that the following conditions
1006@@ -45,15 +45,21 @@
1007 #include "channels.h"
1008 #include "session.h"
1009 #include "misc.h"
1010+#include "servconf.h"
1011+#include "uidswap.h"
1012
1013 #include "ssh-gss.h"
1014+#include "monitor_wrap.h"
1015+
1016+extern ServerOptions options;
1017
1018 static ssh_gssapi_client gssapi_client =
1019 { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER,
1020- GSS_C_NO_CREDENTIAL, NULL, {NULL, NULL, NULL, NULL}};
1021+ GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME, NULL,
1022+ {NULL, NULL, NULL, NULL, NULL}, 0, 0};
1023
1024 ssh_gssapi_mech gssapi_null_mech =
1025- { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL};
1026+ { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL, NULL};
1027
1028 #ifdef KRB5
1029 extern ssh_gssapi_mech gssapi_kerberos_mech;
1030@@ -81,25 +87,32 @@ ssh_gssapi_acquire_cred(Gssctxt *ctx)
1031 char lname[MAXHOSTNAMELEN];
1032 gss_OID_set oidset;
1033
1034- gss_create_empty_oid_set(&status, &oidset);
1035- gss_add_oid_set_member(&status, ctx->oid, &oidset);
1036+ if (options.gss_strict_acceptor) {
1037+ gss_create_empty_oid_set(&status, &oidset);
1038+ gss_add_oid_set_member(&status, ctx->oid, &oidset);
1039
1040- if (gethostname(lname, MAXHOSTNAMELEN)) {
1041- gss_release_oid_set(&status, &oidset);
1042- return (-1);
1043- }
1044+ if (gethostname(lname, MAXHOSTNAMELEN)) {
1045+ gss_release_oid_set(&status, &oidset);
1046+ return (-1);
1047+ }
1048+
1049+ if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
1050+ gss_release_oid_set(&status, &oidset);
1051+ return (ctx->major);
1052+ }
1053+
1054+ if ((ctx->major = gss_acquire_cred(&ctx->minor,
1055+ ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds,
1056+ NULL, NULL)))
1057+ ssh_gssapi_error(ctx);
1058
1059- if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
1060 gss_release_oid_set(&status, &oidset);
1061 return (ctx->major);
1062+ } else {
1063+ ctx->name = GSS_C_NO_NAME;
1064+ ctx->creds = GSS_C_NO_CREDENTIAL;
1065 }
1066-
1067- if ((ctx->major = gss_acquire_cred(&ctx->minor,
1068- ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds, NULL, NULL)))
1069- ssh_gssapi_error(ctx);
1070-
1071- gss_release_oid_set(&status, &oidset);
1072- return (ctx->major);
1073+ return GSS_S_COMPLETE;
1074 }
1075
1076 /* Privileged */
1077@@ -114,6 +127,29 @@ ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID oid)
1078 }
1079
1080 /* Unprivileged */
1081+char *
1082+ssh_gssapi_server_mechanisms() {
1083+ gss_OID_set supported;
1084+
1085+ ssh_gssapi_supported_oids(&supported);
1086+ return (ssh_gssapi_kex_mechs(supported, &ssh_gssapi_server_check_mech,
1087+ NULL, NULL));
1088+}
1089+
1090+/* Unprivileged */
1091+int
1092+ssh_gssapi_server_check_mech(Gssctxt **dum, gss_OID oid, const char *data,
1093+ const char *dummy) {
1094+ Gssctxt *ctx = NULL;
1095+ int res;
1096+
1097+ res = !GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctx, oid)));
1098+ ssh_gssapi_delete_ctx(&ctx);
1099+
1100+ return (res);
1101+}
1102+
1103+/* Unprivileged */
1104 void
1105 ssh_gssapi_supported_oids(gss_OID_set *oidset)
1106 {
1107@@ -123,7 +159,9 @@ ssh_gssapi_supported_oids(gss_OID_set *oidset)
1108 gss_OID_set supported;
1109
1110 gss_create_empty_oid_set(&min_status, oidset);
1111- gss_indicate_mechs(&min_status, &supported);
1112+
1113+ if (GSS_ERROR(gss_indicate_mechs(&min_status, &supported)))
1114+ return;
1115
1116 while (supported_mechs[i]->name != NULL) {
1117 if (GSS_ERROR(gss_test_oid_set_member(&min_status,
1118@@ -249,8 +287,48 @@ OM_uint32
1119 ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1120 {
1121 int i = 0;
1122+ int equal = 0;
1123+ gss_name_t new_name = GSS_C_NO_NAME;
1124+ gss_buffer_desc ename = GSS_C_EMPTY_BUFFER;
1125+
1126+ if (options.gss_store_rekey && client->used && ctx->client_creds) {
1127+ if (client->mech->oid.length != ctx->oid->length ||
1128+ (memcmp(client->mech->oid.elements,
1129+ ctx->oid->elements, ctx->oid->length) !=0)) {
1130+ debug("Rekeyed credentials have different mechanism");
1131+ return GSS_S_COMPLETE;
1132+ }
1133+
1134+ if ((ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
1135+ ctx->client_creds, ctx->oid, &new_name,
1136+ NULL, NULL, NULL))) {
1137+ ssh_gssapi_error(ctx);
1138+ return (ctx->major);
1139+ }
1140+
1141+ ctx->major = gss_compare_name(&ctx->minor, client->name,
1142+ new_name, &equal);
1143
1144- gss_buffer_desc ename;
1145+ if (GSS_ERROR(ctx->major)) {
1146+ ssh_gssapi_error(ctx);
1147+ return (ctx->major);
1148+ }
1149+
1150+ if (!equal) {
1151+ debug("Rekeyed credentials have different name");
1152+ return GSS_S_COMPLETE;
1153+ }
1154+
1155+ debug("Marking rekeyed credentials for export");
1156+
1157+ gss_release_name(&ctx->minor, &client->name);
1158+ gss_release_cred(&ctx->minor, &client->creds);
1159+ client->name = new_name;
1160+ client->creds = ctx->client_creds;
1161+ ctx->client_creds = GSS_C_NO_CREDENTIAL;
1162+ client->updated = 1;
1163+ return GSS_S_COMPLETE;
1164+ }
1165
1166 client->mech = NULL;
1167
1168@@ -265,6 +343,13 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1169 if (client->mech == NULL)
1170 return GSS_S_FAILURE;
1171
1172+ if (ctx->client_creds &&
1173+ (ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
1174+ ctx->client_creds, ctx->oid, &client->name, NULL, NULL, NULL))) {
1175+ ssh_gssapi_error(ctx);
1176+ return (ctx->major);
1177+ }
1178+
1179 if ((ctx->major = gss_display_name(&ctx->minor, ctx->client,
1180 &client->displayname, NULL))) {
1181 ssh_gssapi_error(ctx);
1182@@ -282,6 +367,8 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1183 return (ctx->major);
1184 }
1185
1186+ gss_release_buffer(&ctx->minor, &ename);
1187+
1188 /* We can't copy this structure, so we just move the pointer to it */
1189 client->creds = ctx->client_creds;
1190 ctx->client_creds = GSS_C_NO_CREDENTIAL;
1191@@ -329,7 +416,7 @@ ssh_gssapi_do_child(char ***envp, u_int *envsizep)
1192
1193 /* Privileged */
1194 int
1195-ssh_gssapi_userok(char *user)
1196+ssh_gssapi_userok(char *user, struct passwd *pw)
1197 {
1198 OM_uint32 lmin;
1199
1200@@ -339,9 +426,11 @@ ssh_gssapi_userok(char *user)
1201 return 0;
1202 }
1203 if (gssapi_client.mech && gssapi_client.mech->userok)
1204- if ((*gssapi_client.mech->userok)(&gssapi_client, user))
1205+ if ((*gssapi_client.mech->userok)(&gssapi_client, user)) {
1206+ gssapi_client.used = 1;
1207+ gssapi_client.store.owner = pw;
1208 return 1;
1209- else {
1210+ } else {
1211 /* Destroy delegated credentials if userok fails */
1212 gss_release_buffer(&lmin, &gssapi_client.displayname);
1213 gss_release_buffer(&lmin, &gssapi_client.exportedname);
1214@@ -354,14 +443,90 @@ ssh_gssapi_userok(char *user)
1215 return (0);
1216 }
1217
1218-/* Privileged */
1219-OM_uint32
1220-ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
1221+/* These bits are only used for rekeying. The unpriviledged child is running
1222+ * as the user, the monitor is root.
1223+ *
1224+ * In the child, we want to :
1225+ * *) Ask the monitor to store our credentials into the store we specify
1226+ * *) If it succeeds, maybe do a PAM update
1227+ */
1228+
1229+/* Stuff for PAM */
1230+
1231+#ifdef USE_PAM
1232+static int ssh_gssapi_simple_conv(int n, const struct pam_message **msg,
1233+ struct pam_response **resp, void *data)
1234 {
1235- ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
1236- gssbuf, gssmic, NULL);
1237+ return (PAM_CONV_ERR);
1238+}
1239+#endif
1240
1241- return (ctx->major);
1242+void
1243+ssh_gssapi_rekey_creds() {
1244+ int ok;
1245+ int ret;
1246+#ifdef USE_PAM
1247+ pam_handle_t *pamh = NULL;
1248+ struct pam_conv pamconv = {ssh_gssapi_simple_conv, NULL};
1249+ char *envstr;
1250+#endif
1251+
1252+ if (gssapi_client.store.filename == NULL &&
1253+ gssapi_client.store.envval == NULL &&
1254+ gssapi_client.store.envvar == NULL)
1255+ return;
1256+
1257+ ok = PRIVSEP(ssh_gssapi_update_creds(&gssapi_client.store));
1258+
1259+ if (!ok)
1260+ return;
1261+
1262+ debug("Rekeyed credentials stored successfully");
1263+
1264+ /* Actually managing to play with the ssh pam stack from here will
1265+ * be next to impossible. In any case, we may want different options
1266+ * for rekeying. So, use our own :)
1267+ */
1268+#ifdef USE_PAM
1269+ if (!use_privsep) {
1270+ debug("Not even going to try and do PAM with privsep disabled");
1271+ return;
1272+ }
1273+
1274+ ret = pam_start("sshd-rekey", gssapi_client.store.owner->pw_name,
1275+ &pamconv, &pamh);
1276+ if (ret)
1277+ return;
1278+
1279+ xasprintf(&envstr, "%s=%s", gssapi_client.store.envvar,
1280+ gssapi_client.store.envval);
1281+
1282+ ret = pam_putenv(pamh, envstr);
1283+ if (!ret)
1284+ pam_setcred(pamh, PAM_REINITIALIZE_CRED);
1285+ pam_end(pamh, PAM_SUCCESS);
1286+#endif
1287+}
1288+
1289+int
1290+ssh_gssapi_update_creds(ssh_gssapi_ccache *store) {
1291+ int ok = 0;
1292+
1293+ /* Check we've got credentials to store */
1294+ if (!gssapi_client.updated)
1295+ return 0;
1296+
1297+ gssapi_client.updated = 0;
1298+
1299+ temporarily_use_uid(gssapi_client.store.owner);
1300+ if (gssapi_client.mech && gssapi_client.mech->updatecreds)
1301+ ok = (*gssapi_client.mech->updatecreds)(store, &gssapi_client);
1302+ else
1303+ debug("No update function for this mechanism");
1304+
1305+ restore_uid();
1306+
1307+ return ok;
1308 }
1309
1310 #endif
1311diff --git a/kex.c b/kex.c
1312index 54bd1a4..1ec2782 100644
1313--- a/kex.c
1314+++ b/kex.c
1315@@ -50,6 +50,10 @@
1316 #include "monitor.h"
1317 #include "roaming.h"
1318
1319+#ifdef GSSAPI
1320+#include "ssh-gss.h"
1321+#endif
1322+
1323 #if OPENSSL_VERSION_NUMBER >= 0x00907000L
1324 # if defined(HAVE_EVP_SHA256)
1325 # define evp_ssh_sha256 EVP_sha256
1326@@ -82,6 +86,14 @@ static const struct kexalg kexalgs[] = {
1327 #endif
1328 { NULL, -1, -1, NULL},
1329 };
1330+static const struct kexalg kexalg_prefixes[] = {
1331+#ifdef GSSAPI
1332+ { KEX_GSS_GEX_SHA1_ID, KEX_GSS_GEX_SHA1, 0, EVP_sha1 },
1333+ { KEX_GSS_GRP1_SHA1_ID, KEX_GSS_GRP1_SHA1, 0, EVP_sha1 },
1334+ { KEX_GSS_GRP14_SHA1_ID, KEX_GSS_GRP14_SHA1, 0, EVP_sha1 },
1335+#endif
1336+ { NULL, -1, -1, NULL },
1337+};
1338
1339 char *
1340 kex_alg_list(void)
1341@@ -110,6 +122,10 @@ kex_alg_by_name(const char *name)
1342 if (strcmp(k->name, name) == 0)
1343 return k;
1344 }
1345+ for (k = kexalg_prefixes; k->name != NULL; k++) {
1346+ if (strncmp(k->name, name, strlen(k->name)) == 0)
1347+ return k;
1348+ }
1349 return NULL;
1350 }
1351
1352diff --git a/kex.h b/kex.h
1353index 9f1e1ad..d5046c6 100644
1354--- a/kex.h
1355+++ b/kex.h
1356@@ -74,6 +74,9 @@ enum kex_exchange {
1357 KEX_DH_GEX_SHA1,
1358 KEX_DH_GEX_SHA256,
1359 KEX_ECDH_SHA2,
1360+ KEX_GSS_GRP1_SHA1,
1361+ KEX_GSS_GRP14_SHA1,
1362+ KEX_GSS_GEX_SHA1,
1363 KEX_MAX
1364 };
1365
1366@@ -133,6 +136,12 @@ struct Kex {
1367 int flags;
1368 const EVP_MD *evp_md;
1369 int ec_nid;
1370+#ifdef GSSAPI
1371+ int gss_deleg_creds;
1372+ int gss_trust_dns;
1373+ char *gss_host;
1374+ char *gss_client;
1375+#endif
1376 char *client_version_string;
1377 char *server_version_string;
1378 int (*verify_host_key)(Key *);
1379@@ -162,6 +171,11 @@ void kexgex_server(Kex *);
1380 void kexecdh_client(Kex *);
1381 void kexecdh_server(Kex *);
1382
1383+#ifdef GSSAPI
1384+void kexgss_client(Kex *);
1385+void kexgss_server(Kex *);
1386+#endif
1387+
1388 void
1389 kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
1390 BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *);
1391diff --git a/kexgssc.c b/kexgssc.c
1392new file mode 100644
1393index 0000000..616893c
1394--- /dev/null
1395+++ b/kexgssc.c
1396@@ -0,0 +1,333 @@
1397+/*
1398+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1399+ *
1400+ * Redistribution and use in source and binary forms, with or without
1401+ * modification, are permitted provided that the following conditions
1402+ * are met:
1403+ * 1. Redistributions of source code must retain the above copyright
1404+ * notice, this list of conditions and the following disclaimer.
1405+ * 2. Redistributions in binary form must reproduce the above copyright
1406+ * notice, this list of conditions and the following disclaimer in the
1407+ * documentation and/or other materials provided with the distribution.
1408+ *
1409+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1410+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1411+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1412+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1413+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1414+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1415+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1416+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1417+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1418+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1419+ */
1420+
1421+#include "includes.h"
1422+
1423+#ifdef GSSAPI
1424+
1425+#include "includes.h"
1426+
1427+#include <openssl/crypto.h>
1428+#include <openssl/bn.h>
1429+
1430+#include <string.h>
1431+
1432+#include "xmalloc.h"
1433+#include "buffer.h"
1434+#include "ssh2.h"
1435+#include "key.h"
1436+#include "cipher.h"
1437+#include "kex.h"
1438+#include "log.h"
1439+#include "packet.h"
1440+#include "dh.h"
1441+
1442+#include "ssh-gss.h"
1443+
1444+void
1445+kexgss_client(Kex *kex) {
1446+ gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
1447+ gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
1448+ Gssctxt *ctxt;
1449+ OM_uint32 maj_status, min_status, ret_flags;
1450+ u_int klen, kout, slen = 0, hashlen, strlen;
1451+ DH *dh;
1452+ BIGNUM *dh_server_pub = NULL;
1453+ BIGNUM *shared_secret = NULL;
1454+ BIGNUM *p = NULL;
1455+ BIGNUM *g = NULL;
1456+ u_char *kbuf, *hash;
1457+ u_char *serverhostkey = NULL;
1458+ u_char *empty = "";
1459+ char *msg;
1460+ char *lang;
1461+ int type = 0;
1462+ int first = 1;
1463+ int nbits = 0, min = DH_GRP_MIN, max = DH_GRP_MAX;
1464+
1465+ /* Initialise our GSSAPI world */
1466+ ssh_gssapi_build_ctx(&ctxt);
1467+ if (ssh_gssapi_id_kex(ctxt, kex->name, kex->kex_type)
1468+ == GSS_C_NO_OID)
1469+ fatal("Couldn't identify host exchange");
1470+
1471+ if (ssh_gssapi_import_name(ctxt, kex->gss_host))
1472+ fatal("Couldn't import hostname");
1473+
1474+ if (kex->gss_client &&
1475+ ssh_gssapi_client_identity(ctxt, kex->gss_client))
1476+ fatal("Couldn't acquire client credentials");
1477+
1478+ switch (kex->kex_type) {
1479+ case KEX_GSS_GRP1_SHA1:
1480+ dh = dh_new_group1();
1481+ break;
1482+ case KEX_GSS_GRP14_SHA1:
1483+ dh = dh_new_group14();
1484+ break;
1485+ case KEX_GSS_GEX_SHA1:
1486+ debug("Doing group exchange\n");
1487+ nbits = dh_estimate(kex->we_need * 8);
1488+ packet_start(SSH2_MSG_KEXGSS_GROUPREQ);
1489+ packet_put_int(min);
1490+ packet_put_int(nbits);
1491+ packet_put_int(max);
1492+
1493+ packet_send();
1494+
1495+ packet_read_expect(SSH2_MSG_KEXGSS_GROUP);
1496+
1497+ if ((p = BN_new()) == NULL)
1498+ fatal("BN_new() failed");
1499+ packet_get_bignum2(p);
1500+ if ((g = BN_new()) == NULL)
1501+ fatal("BN_new() failed");
1502+ packet_get_bignum2(g);
1503+ packet_check_eom();
1504+
1505+ if (BN_num_bits(p) < min || BN_num_bits(p) > max)
1506+ fatal("GSSGRP_GEX group out of range: %d !< %d !< %d",
1507+ min, BN_num_bits(p), max);
1508+
1509+ dh = dh_new_group(g, p);
1510+ break;
1511+ default:
1512+ fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
1513+ }
1514+
1515+ /* Step 1 - e is dh->pub_key */
1516+ dh_gen_key(dh, kex->we_need * 8);
1517+
1518+ /* This is f, we initialise it now to make life easier */
1519+ dh_server_pub = BN_new();
1520+ if (dh_server_pub == NULL)
1521+ fatal("dh_server_pub == NULL");
1522+
1523+ token_ptr = GSS_C_NO_BUFFER;
1524+
1525+ do {
1526+ debug("Calling gss_init_sec_context");
1527+
1528+ maj_status = ssh_gssapi_init_ctx(ctxt,
1529+ kex->gss_deleg_creds, token_ptr, &send_tok,
1530+ &ret_flags);
1531+
1532+ if (GSS_ERROR(maj_status)) {
1533+ if (send_tok.length != 0) {
1534+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1535+ packet_put_string(send_tok.value,
1536+ send_tok.length);
1537+ }
1538+ fatal("gss_init_context failed");
1539+ }
1540+
1541+ /* If we've got an old receive buffer get rid of it */
1542+ if (token_ptr != GSS_C_NO_BUFFER)
1543+ free(recv_tok.value);
1544+
1545+ if (maj_status == GSS_S_COMPLETE) {
1546+ /* If mutual state flag is not true, kex fails */
1547+ if (!(ret_flags & GSS_C_MUTUAL_FLAG))
1548+ fatal("Mutual authentication failed");
1549+
1550+ /* If integ avail flag is not true kex fails */
1551+ if (!(ret_flags & GSS_C_INTEG_FLAG))
1552+ fatal("Integrity check failed");
1553+ }
1554+
1555+ /*
1556+ * If we have data to send, then the last message that we
1557+ * received cannot have been a 'complete'.
1558+ */
1559+ if (send_tok.length != 0) {
1560+ if (first) {
1561+ packet_start(SSH2_MSG_KEXGSS_INIT);
1562+ packet_put_string(send_tok.value,
1563+ send_tok.length);
1564+ packet_put_bignum2(dh->pub_key);
1565+ first = 0;
1566+ } else {
1567+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1568+ packet_put_string(send_tok.value,
1569+ send_tok.length);
1570+ }
1571+ packet_send();
1572+ gss_release_buffer(&min_status, &send_tok);
1573+
1574+ /* If we've sent them data, they should reply */
1575+ do {
1576+ type = packet_read();
1577+ if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
1578+ debug("Received KEXGSS_HOSTKEY");
1579+ if (serverhostkey)
1580+ fatal("Server host key received more than once");
1581+ serverhostkey =
1582+ packet_get_string(&slen);
1583+ }
1584+ } while (type == SSH2_MSG_KEXGSS_HOSTKEY);
1585+
1586+ switch (type) {
1587+ case SSH2_MSG_KEXGSS_CONTINUE:
1588+ debug("Received GSSAPI_CONTINUE");
1589+ if (maj_status == GSS_S_COMPLETE)
1590+ fatal("GSSAPI Continue received from server when complete");
1591+ recv_tok.value = packet_get_string(&strlen);
1592+ recv_tok.length = strlen;
1593+ break;
1594+ case SSH2_MSG_KEXGSS_COMPLETE:
1595+ debug("Received GSSAPI_COMPLETE");
1596+ packet_get_bignum2(dh_server_pub);
1597+ msg_tok.value = packet_get_string(&strlen);
1598+ msg_tok.length = strlen;
1599+
1600+ /* Is there a token included? */
1601+ if (packet_get_char()) {
1602+ recv_tok.value=
1603+ packet_get_string(&strlen);
1604+ recv_tok.length = strlen;
1605+ /* If we're already complete - protocol error */
1606+ if (maj_status == GSS_S_COMPLETE)
1607+ packet_disconnect("Protocol error: received token when complete");
1608+ } else {
1609+ /* No token included */
1610+ if (maj_status != GSS_S_COMPLETE)
1611+ packet_disconnect("Protocol error: did not receive final token");
1612+ }
1613+ break;
1614+ case SSH2_MSG_KEXGSS_ERROR:
1615+ debug("Received Error");
1616+ maj_status = packet_get_int();
1617+ min_status = packet_get_int();
1618+ msg = packet_get_string(NULL);
1619+ lang = packet_get_string(NULL);
1620+ fatal("GSSAPI Error: \n%.400s",msg);
1621+ default:
1622+ packet_disconnect("Protocol error: didn't expect packet type %d",
1623+ type);
1624+ }
1625+ token_ptr = &recv_tok;
1626+ } else {
1627+ /* No data, and not complete */
1628+ if (maj_status != GSS_S_COMPLETE)
1629+ fatal("Not complete, and no token output");
1630+ }
1631+ } while (maj_status & GSS_S_CONTINUE_NEEDED);
1632+
1633+ /*
1634+ * We _must_ have received a COMPLETE message in reply from the
1635+ * server, which will have set dh_server_pub and msg_tok
1636+ */
1637+
1638+ if (type != SSH2_MSG_KEXGSS_COMPLETE)
1639+ fatal("Didn't receive a SSH2_MSG_KEXGSS_COMPLETE when I expected it");
1640+
1641+ /* Check f in range [1, p-1] */
1642+ if (!dh_pub_is_valid(dh, dh_server_pub))
1643+ packet_disconnect("bad server public DH value");
1644+
1645+ /* compute K=f^x mod p */
1646+ klen = DH_size(dh);
1647+ kbuf = xmalloc(klen);
1648+ kout = DH_compute_key(kbuf, dh_server_pub, dh);
1649+ if (kout < 0)
1650+ fatal("DH_compute_key: failed");
1651+
1652+ shared_secret = BN_new();
1653+ if (shared_secret == NULL)
1654+ fatal("kexgss_client: BN_new failed");
1655+
1656+ if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
1657+ fatal("kexdh_client: BN_bin2bn failed");
1658+
1659+ memset(kbuf, 0, klen);
1660+ free(kbuf);
1661+
1662+ switch (kex->kex_type) {
1663+ case KEX_GSS_GRP1_SHA1:
1664+ case KEX_GSS_GRP14_SHA1:
1665+ kex_dh_hash( kex->client_version_string,
1666+ kex->server_version_string,
1667+ buffer_ptr(&kex->my), buffer_len(&kex->my),
1668+ buffer_ptr(&kex->peer), buffer_len(&kex->peer),
1669+ (serverhostkey ? serverhostkey : empty), slen,
1670+ dh->pub_key, /* e */
1671+ dh_server_pub, /* f */
1672+ shared_secret, /* K */
1673+ &hash, &hashlen
1674+ );
1675+ break;
1676+ case KEX_GSS_GEX_SHA1:
1677+ kexgex_hash(
1678+ kex->evp_md,
1679+ kex->client_version_string,
1680+ kex->server_version_string,
1681+ buffer_ptr(&kex->my), buffer_len(&kex->my),
1682+ buffer_ptr(&kex->peer), buffer_len(&kex->peer),
1683+ (serverhostkey ? serverhostkey : empty), slen,
1684+ min, nbits, max,
1685+ dh->p, dh->g,
1686+ dh->pub_key,
1687+ dh_server_pub,
1688+ shared_secret,
1689+ &hash, &hashlen
1690+ );
1691+ break;
1692+ default:
1693+ fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
1694+ }
1695+
1696+ gssbuf.value = hash;
1697+ gssbuf.length = hashlen;
1698+
1699+ /* Verify that the hash matches the MIC we just got. */
1700+ if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
1701+ packet_disconnect("Hash's MIC didn't verify");
1702+
1703+ free(msg_tok.value);
1704+
1705+ DH_free(dh);
1706+ free(serverhostkey);
1707+ BN_clear_free(dh_server_pub);
1708+
1709+ /* save session id */
1710+ if (kex->session_id == NULL) {
1711+ kex->session_id_len = hashlen;
1712+ kex->session_id = xmalloc(kex->session_id_len);
1713+ memcpy(kex->session_id, hash, kex->session_id_len);
1714+ }
1715+
1716+ if (kex->gss_deleg_creds)
1717+ ssh_gssapi_credentials_updated(ctxt);
1718+
1719+ if (gss_kex_context == NULL)
1720+ gss_kex_context = ctxt;
1721+ else
1722+ ssh_gssapi_delete_ctx(&ctxt);
1723+
1724+ kex_derive_keys(kex, hash, hashlen, shared_secret);
1725+ BN_clear_free(shared_secret);
1726+ kex_finish(kex);
1727+}
1728+
1729+#endif /* GSSAPI */
1730diff --git a/kexgsss.c b/kexgsss.c
1731new file mode 100644
1732index 0000000..18b065b
1733--- /dev/null
1734+++ b/kexgsss.c
1735@@ -0,0 +1,289 @@
1736+/*
1737+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1738+ *
1739+ * Redistribution and use in source and binary forms, with or without
1740+ * modification, are permitted provided that the following conditions
1741+ * are met:
1742+ * 1. Redistributions of source code must retain the above copyright
1743+ * notice, this list of conditions and the following disclaimer.
1744+ * 2. Redistributions in binary form must reproduce the above copyright
1745+ * notice, this list of conditions and the following disclaimer in the
1746+ * documentation and/or other materials provided with the distribution.
1747+ *
1748+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1749+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1750+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1751+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1752+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1753+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1754+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1755+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1756+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1757+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1758+ */
1759+
1760+#include "includes.h"
1761+
1762+#ifdef GSSAPI
1763+
1764+#include <string.h>
1765+
1766+#include <openssl/crypto.h>
1767+#include <openssl/bn.h>
1768+
1769+#include "xmalloc.h"
1770+#include "buffer.h"
1771+#include "ssh2.h"
1772+#include "key.h"
1773+#include "cipher.h"
1774+#include "kex.h"
1775+#include "log.h"
1776+#include "packet.h"
1777+#include "dh.h"
1778+#include "ssh-gss.h"
1779+#include "monitor_wrap.h"
1780+#include "servconf.h"
1781+
1782+extern ServerOptions options;
1783+
1784+void
1785+kexgss_server(Kex *kex)
1786+{
1787+ OM_uint32 maj_status, min_status;
1788+
1789+ /*
1790+ * Some GSSAPI implementations use the input value of ret_flags (an
1791+ * output variable) as a means of triggering mechanism specific
1792+ * features. Initializing it to zero avoids inadvertently
1793+ * activating this non-standard behaviour.
1794+ */
1795+
1796+ OM_uint32 ret_flags = 0;
1797+ gss_buffer_desc gssbuf, recv_tok, msg_tok;
1798+ gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
1799+ Gssctxt *ctxt = NULL;
1800+ u_int slen, klen, kout, hashlen;
1801+ u_char *kbuf, *hash;
1802+ DH *dh;
1803+ int min = -1, max = -1, nbits = -1;
1804+ BIGNUM *shared_secret = NULL;
1805+ BIGNUM *dh_client_pub = NULL;
1806+ int type = 0;
1807+ gss_OID oid;
1808+ char *mechs;
1809+
1810+ /* Initialise GSSAPI */
1811+
1812+ /* If we're rekeying, privsep means that some of the private structures
1813+ * in the GSSAPI code are no longer available. This kludges them back
1814+ * into life
1815+ */
1816+ if (!ssh_gssapi_oid_table_ok()) {
1817+ mechs = ssh_gssapi_server_mechanisms();
1818+ free(mechs);
1819+ }
1820+
1821+ debug2("%s: Identifying %s", __func__, kex->name);
1822+ oid = ssh_gssapi_id_kex(NULL, kex->name, kex->kex_type);
1823+ if (oid == GSS_C_NO_OID)
1824+ fatal("Unknown gssapi mechanism");
1825+
1826+ debug2("%s: Acquiring credentials", __func__);
1827+
1828+ if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid))))
1829+ fatal("Unable to acquire credentials for the server");
1830+
1831+ switch (kex->kex_type) {
1832+ case KEX_GSS_GRP1_SHA1:
1833+ dh = dh_new_group1();
1834+ break;
1835+ case KEX_GSS_GRP14_SHA1:
1836+ dh = dh_new_group14();
1837+ break;
1838+ case KEX_GSS_GEX_SHA1:
1839+ debug("Doing group exchange");
1840+ packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ);
1841+ min = packet_get_int();
1842+ nbits = packet_get_int();
1843+ max = packet_get_int();
1844+ min = MAX(DH_GRP_MIN, min);
1845+ max = MIN(DH_GRP_MAX, max);
1846+ packet_check_eom();
1847+ if (max < min || nbits < min || max < nbits)
1848+ fatal("GSS_GEX, bad parameters: %d !< %d !< %d",
1849+ min, nbits, max);
1850+ dh = PRIVSEP(choose_dh(min, nbits, max));
1851+ if (dh == NULL)
1852+ packet_disconnect("Protocol error: no matching group found");
1853+
1854+ packet_start(SSH2_MSG_KEXGSS_GROUP);
1855+ packet_put_bignum2(dh->p);
1856+ packet_put_bignum2(dh->g);
1857+ packet_send();
1858+
1859+ packet_write_wait();
1860+ break;
1861+ default:
1862+ fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
1863+ }
1864+
1865+ dh_gen_key(dh, kex->we_need * 8);
1866+
1867+ do {
1868+ debug("Wait SSH2_MSG_GSSAPI_INIT");
1869+ type = packet_read();
1870+ switch(type) {
1871+ case SSH2_MSG_KEXGSS_INIT:
1872+ if (dh_client_pub != NULL)
1873+ fatal("Received KEXGSS_INIT after initialising");
1874+ recv_tok.value = packet_get_string(&slen);
1875+ recv_tok.length = slen;
1876+
1877+ if ((dh_client_pub = BN_new()) == NULL)
1878+ fatal("dh_client_pub == NULL");
1879+
1880+ packet_get_bignum2(dh_client_pub);
1881+
1882+ /* Send SSH_MSG_KEXGSS_HOSTKEY here, if we want */
1883+ break;
1884+ case SSH2_MSG_KEXGSS_CONTINUE:
1885+ recv_tok.value = packet_get_string(&slen);
1886+ recv_tok.length = slen;
1887+ break;
1888+ default:
1889+ packet_disconnect(
1890+ "Protocol error: didn't expect packet type %d",
1891+ type);
1892+ }
1893+
1894+ maj_status = PRIVSEP(ssh_gssapi_accept_ctx(ctxt, &recv_tok,
1895+ &send_tok, &ret_flags));
1896+
1897+ free(recv_tok.value);
1898+
1899+ if (maj_status != GSS_S_COMPLETE && send_tok.length == 0)
1900+ fatal("Zero length token output when incomplete");
1901+
1902+ if (dh_client_pub == NULL)
1903+ fatal("No client public key");
1904+
1905+ if (maj_status & GSS_S_CONTINUE_NEEDED) {
1906+ debug("Sending GSSAPI_CONTINUE");
1907+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1908+ packet_put_string(send_tok.value, send_tok.length);
1909+ packet_send();
1910+ gss_release_buffer(&min_status, &send_tok);
1911+ }
1912+ } while (maj_status & GSS_S_CONTINUE_NEEDED);
1913+
1914+ if (GSS_ERROR(maj_status)) {
1915+ if (send_tok.length > 0) {
1916+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1917+ packet_put_string(send_tok.value, send_tok.length);
1918+ packet_send();
1919+ }
1920+ fatal("accept_ctx died");
1921+ }
1922+
1923+ if (!(ret_flags & GSS_C_MUTUAL_FLAG))
1924+ fatal("Mutual Authentication flag wasn't set");
1925+
1926+ if (!(ret_flags & GSS_C_INTEG_FLAG))
1927+ fatal("Integrity flag wasn't set");
1928+
1929+ if (!dh_pub_is_valid(dh, dh_client_pub))
1930+ packet_disconnect("bad client public DH value");
1931+
1932+ klen = DH_size(dh);
1933+ kbuf = xmalloc(klen);
1934+ kout = DH_compute_key(kbuf, dh_client_pub, dh);
1935+ if (kout < 0)
1936+ fatal("DH_compute_key: failed");
1937+
1938+ shared_secret = BN_new();
1939+ if (shared_secret == NULL)
1940+ fatal("kexgss_server: BN_new failed");
1941+
1942+ if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
1943+ fatal("kexgss_server: BN_bin2bn failed");
1944+
1945+ memset(kbuf, 0, klen);
1946+ free(kbuf);
1947+
1948+ switch (kex->kex_type) {
1949+ case KEX_GSS_GRP1_SHA1:
1950+ case KEX_GSS_GRP14_SHA1:
1951+ kex_dh_hash(
1952+ kex->client_version_string, kex->server_version_string,
1953+ buffer_ptr(&kex->peer), buffer_len(&kex->peer),
1954+ buffer_ptr(&kex->my), buffer_len(&kex->my),
1955+ NULL, 0, /* Change this if we start sending host keys */
1956+ dh_client_pub, dh->pub_key, shared_secret,
1957+ &hash, &hashlen
1958+ );
1959+ break;
1960+ case KEX_GSS_GEX_SHA1:
1961+ kexgex_hash(
1962+ kex->evp_md,
1963+ kex->client_version_string, kex->server_version_string,
1964+ buffer_ptr(&kex->peer), buffer_len(&kex->peer),
1965+ buffer_ptr(&kex->my), buffer_len(&kex->my),
1966+ NULL, 0,
1967+ min, nbits, max,
1968+ dh->p, dh->g,
1969+ dh_client_pub,
1970+ dh->pub_key,
1971+ shared_secret,
1972+ &hash, &hashlen
1973+ );
1974+ break;
1975+ default:
1976+ fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
1977+ }
1978+
1979+ BN_clear_free(dh_client_pub);
1980+
1981+ if (kex->session_id == NULL) {
1982+ kex->session_id_len = hashlen;
1983+ kex->session_id = xmalloc(kex->session_id_len);
1984+ memcpy(kex->session_id, hash, kex->session_id_len);
1985+ }
1986+
1987+ gssbuf.value = hash;
1988+ gssbuf.length = hashlen;
1989+
1990+ if (GSS_ERROR(PRIVSEP(ssh_gssapi_sign(ctxt,&gssbuf,&msg_tok))))
1991+ fatal("Couldn't get MIC");
1992+
1993+ packet_start(SSH2_MSG_KEXGSS_COMPLETE);
1994+ packet_put_bignum2(dh->pub_key);
1995+ packet_put_string(msg_tok.value,msg_tok.length);
1996+
1997+ if (send_tok.length != 0) {
1998+ packet_put_char(1); /* true */
1999+ packet_put_string(send_tok.value, send_tok.length);
2000+ } else {
2001+ packet_put_char(0); /* false */
2002+ }
2003+ packet_send();
2004+
2005+ gss_release_buffer(&min_status, &send_tok);
2006+ gss_release_buffer(&min_status, &msg_tok);
2007+
2008+ if (gss_kex_context == NULL)
2009+ gss_kex_context = ctxt;
2010+ else
2011+ ssh_gssapi_delete_ctx(&ctxt);
2012+
2013+ DH_free(dh);
2014+
2015+ kex_derive_keys(kex, hash, hashlen, shared_secret);
2016+ BN_clear_free(shared_secret);
2017+ kex_finish(kex);
2018+
2019+ /* If this was a rekey, then save out any delegated credentials we
2020+ * just exchanged. */
2021+ if (options.gss_store_rekey)
2022+ ssh_gssapi_rekey_creds();
2023+}
2024+#endif /* GSSAPI */
2025diff --git a/key.c b/key.c
2026index 55ee789..2591635 100644
2027--- a/key.c
2028+++ b/key.c
2029@@ -933,6 +933,7 @@ static const struct keytype keytypes[] = {
2030 KEY_RSA_CERT_V00, 0, 1 },
2031 { "ssh-dss-cert-v00@openssh.com", "DSA-CERT-V00",
2032 KEY_DSA_CERT_V00, 0, 1 },
2033+ { "null", "null", KEY_NULL, 0, 0 },
2034 { NULL, NULL, -1, -1, 0 }
2035 };
2036
2037diff --git a/key.h b/key.h
2038index 17358ae..b57d6a4 100644
2039--- a/key.h
2040+++ b/key.h
2041@@ -44,6 +44,7 @@ enum types {
2042 KEY_ECDSA_CERT,
2043 KEY_RSA_CERT_V00,
2044 KEY_DSA_CERT_V00,
2045+ KEY_NULL,
2046 KEY_UNSPEC
2047 };
2048 enum fp_type {
2049diff --git a/monitor.c b/monitor.c
2050index 44dff98..9079c97 100644
2051--- a/monitor.c
2052+++ b/monitor.c
2053@@ -181,6 +181,8 @@ int mm_answer_gss_setup_ctx(int, Buffer *);
2054 int mm_answer_gss_accept_ctx(int, Buffer *);
2055 int mm_answer_gss_userok(int, Buffer *);
2056 int mm_answer_gss_checkmic(int, Buffer *);
2057+int mm_answer_gss_sign(int, Buffer *);
2058+int mm_answer_gss_updatecreds(int, Buffer *);
2059 #endif
2060
2061 #ifdef SSH_AUDIT_EVENTS
2062@@ -253,6 +255,7 @@ struct mon_table mon_dispatch_proto20[] = {
2063 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
2064 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
2065 {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic},
2066+ {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
2067 #endif
2068 #ifdef JPAKE
2069 {MONITOR_REQ_JPAKE_GET_PWDATA, MON_ONCE, mm_answer_jpake_get_pwdata},
2070@@ -265,6 +268,12 @@ struct mon_table mon_dispatch_proto20[] = {
2071 };
2072
2073 struct mon_table mon_dispatch_postauth20[] = {
2074+#ifdef GSSAPI
2075+ {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
2076+ {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
2077+ {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
2078+ {MONITOR_REQ_GSSUPCREDS, 0, mm_answer_gss_updatecreds},
2079+#endif
2080 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
2081 {MONITOR_REQ_SIGN, 0, mm_answer_sign},
2082 {MONITOR_REQ_PTY, 0, mm_answer_pty},
2083@@ -373,6 +382,10 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
2084 /* Permit requests for moduli and signatures */
2085 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
2086 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
2087+#ifdef GSSAPI
2088+ /* and for the GSSAPI key exchange */
2089+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
2090+#endif
2091 } else {
2092 mon_dispatch = mon_dispatch_proto15;
2093
2094@@ -487,6 +500,10 @@ monitor_child_postauth(struct monitor *pmonitor)
2095 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
2096 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
2097 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
2098+#ifdef GSSAPI
2099+ /* and for the GSSAPI key exchange */
2100+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
2101+#endif
2102 } else {
2103 mon_dispatch = mon_dispatch_postauth15;
2104 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
2105@@ -1855,6 +1872,13 @@ mm_get_kex(Buffer *m)
2106 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
2107 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
2108 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
2109+#ifdef GSSAPI
2110+ if (options.gss_keyex) {
2111+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
2112+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
2113+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
2114+ }
2115+#endif
2116 kex->server = 1;
2117 kex->hostkey_type = buffer_get_int(m);
2118 kex->kex_type = buffer_get_int(m);
2119@@ -2062,6 +2086,9 @@ mm_answer_gss_setup_ctx(int sock, Buffer *m)
2120 OM_uint32 major;
2121 u_int len;
2122
2123+ if (!options.gss_authentication && !options.gss_keyex)
2124+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2125+
2126 goid.elements = buffer_get_string(m, &len);
2127 goid.length = len;
2128
2129@@ -2089,6 +2116,9 @@ mm_answer_gss_accept_ctx(int sock, Buffer *m)
2130 OM_uint32 flags = 0; /* GSI needs this */
2131 u_int len;
2132
2133+ if (!options.gss_authentication && !options.gss_keyex)
2134+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2135+
2136 in.value = buffer_get_string(m, &len);
2137 in.length = len;
2138 major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags);
2139@@ -2106,6 +2136,7 @@ mm_answer_gss_accept_ctx(int sock, Buffer *m)
2140 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
2141 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
2142 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1);
2143+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1);
2144 }
2145 return (0);
2146 }
2147@@ -2117,6 +2148,9 @@ mm_answer_gss_checkmic(int sock, Buffer *m)
2148 OM_uint32 ret;
2149 u_int len;
2150
2151+ if (!options.gss_authentication && !options.gss_keyex)
2152+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2153+
2154 gssbuf.value = buffer_get_string(m, &len);
2155 gssbuf.length = len;
2156 mic.value = buffer_get_string(m, &len);
2157@@ -2143,7 +2177,11 @@ mm_answer_gss_userok(int sock, Buffer *m)
2158 {
2159 int authenticated;
2160
2161- authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
2162+ if (!options.gss_authentication && !options.gss_keyex)
2163+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2164+
2165+ authenticated = authctxt->valid &&
2166+ ssh_gssapi_userok(authctxt->user, authctxt->pw);
2167
2168 buffer_clear(m);
2169 buffer_put_int(m, authenticated);
2170@@ -2156,6 +2194,74 @@ mm_answer_gss_userok(int sock, Buffer *m)
2171 /* Monitor loop will terminate if authenticated */
2172 return (authenticated);
2173 }
2174+
2175+int
2176+mm_answer_gss_sign(int socket, Buffer *m)
2177+{
2178+ gss_buffer_desc data;
2179+ gss_buffer_desc hash = GSS_C_EMPTY_BUFFER;
2180+ OM_uint32 major, minor;
2181+ u_int len;
2182+
2183+ if (!options.gss_authentication && !options.gss_keyex)
2184+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2185+
2186+ data.value = buffer_get_string(m, &len);
2187+ data.length = len;
2188+ if (data.length != 20)
2189+ fatal("%s: data length incorrect: %d", __func__,
2190+ (int) data.length);
2191+
2192+ /* Save the session ID on the first time around */
2193+ if (session_id2_len == 0) {
2194+ session_id2_len = data.length;
2195+ session_id2 = xmalloc(session_id2_len);
2196+ memcpy(session_id2, data.value, session_id2_len);
2197+ }
2198+ major = ssh_gssapi_sign(gsscontext, &data, &hash);
2199+
2200+ free(data.value);
2201+
2202+ buffer_clear(m);
2203+ buffer_put_int(m, major);
2204+ buffer_put_string(m, hash.value, hash.length);
2205+
2206+ mm_request_send(socket, MONITOR_ANS_GSSSIGN, m);
2207+
2208+ gss_release_buffer(&minor, &hash);
2209+
2210+ /* Turn on getpwnam permissions */
2211+ monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
2212+
2213+ /* And credential updating, for when rekeying */
2214+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSUPCREDS, 1);
2215+
2216+ return (0);
2217+}
2218+
2219+int
2220+mm_answer_gss_updatecreds(int socket, Buffer *m) {
2221+ ssh_gssapi_ccache store;
2222+ int ok;
2223+
2224+ store.filename = buffer_get_string(m, NULL);
2225+ store.envvar = buffer_get_string(m, NULL);
2226+ store.envval = buffer_get_string(m, NULL);
2227+
2228+ ok = ssh_gssapi_update_creds(&store);
2229+
2230+ free(store.filename);
2231+ free(store.envvar);
2232+ free(store.envval);
2233+
2234+ buffer_clear(m);
2235+ buffer_put_int(m, ok);
2236+
2237+ mm_request_send(socket, MONITOR_ANS_GSSUPCREDS, m);
2238+
2239+ return(0);
2240+}
2241+
2242 #endif /* GSSAPI */
2243
2244 #ifdef JPAKE
2245diff --git a/monitor.h b/monitor.h
2246index 2caa469..315ef99 100644
2247--- a/monitor.h
2248+++ b/monitor.h
2249@@ -70,6 +70,9 @@ enum monitor_reqtype {
2250 MONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111,
2251 MONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113,
2252
2253+ MONITOR_REQ_GSSSIGN = 150, MONITOR_ANS_GSSSIGN = 151,
2254+ MONITOR_REQ_GSSUPCREDS = 152, MONITOR_ANS_GSSUPCREDS = 153,
2255+
2256 };
2257
2258 struct mm_master;
2259diff --git a/monitor_wrap.c b/monitor_wrap.c
2260index 4ce4696..44019f3 100644
2261--- a/monitor_wrap.c
2262+++ b/monitor_wrap.c
2263@@ -1273,7 +1273,7 @@ mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
2264 }
2265
2266 int
2267-mm_ssh_gssapi_userok(char *user)
2268+mm_ssh_gssapi_userok(char *user, struct passwd *pw)
2269 {
2270 Buffer m;
2271 int authenticated = 0;
2272@@ -1290,6 +1290,51 @@ mm_ssh_gssapi_userok(char *user)
2273 debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
2274 return (authenticated);
2275 }
2276+
2277+OM_uint32
2278+mm_ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_desc *data, gss_buffer_desc *hash)
2279+{
2280+ Buffer m;
2281+ OM_uint32 major;
2282+ u_int len;
2283+
2284+ buffer_init(&m);
2285+ buffer_put_string(&m, data->value, data->length);
2286+
2287+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSIGN, &m);
2288+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSIGN, &m);
2289+
2290+ major = buffer_get_int(&m);
2291+ hash->value = buffer_get_string(&m, &len);
2292+ hash->length = len;
2293+
2294+ buffer_free(&m);
2295+
2296+ return(major);
2297+}
2298+
2299+int
2300+mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
2301+{
2302+ Buffer m;
2303+ int ok;
2304+
2305+ buffer_init(&m);
2306+
2307+ buffer_put_cstring(&m, store->filename ? store->filename : "");
2308+ buffer_put_cstring(&m, store->envvar ? store->envvar : "");
2309+ buffer_put_cstring(&m, store->envval ? store->envval : "");
2310+
2311+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUPCREDS, &m);
2312+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUPCREDS, &m);
2313+
2314+ ok = buffer_get_int(&m);
2315+
2316+ buffer_free(&m);
2317+
2318+ return (ok);
2319+}
2320+
2321 #endif /* GSSAPI */
2322
2323 #ifdef JPAKE
2324diff --git a/monitor_wrap.h b/monitor_wrap.h
2325index 0c7f2e3..ec9b9b1 100644
2326--- a/monitor_wrap.h
2327+++ b/monitor_wrap.h
2328@@ -58,8 +58,10 @@ BIGNUM *mm_auth_rsa_generate_challenge(Key *);
2329 OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
2330 OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *,
2331 gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *);
2332-int mm_ssh_gssapi_userok(char *user);
2333+int mm_ssh_gssapi_userok(char *user, struct passwd *);
2334 OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
2335+OM_uint32 mm_ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
2336+int mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *);
2337 #endif
2338
2339 #ifdef USE_PAM
2340diff --git a/readconf.c b/readconf.c
2341index 1464430..2695fd6 100644
2342--- a/readconf.c
2343+++ b/readconf.c
2344@@ -132,6 +132,8 @@ typedef enum {
2345 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
2346 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
2347 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
2348+ oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey,
2349+ oGssServerIdentity,
2350 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
2351 oSendEnv, oControlPath, oControlMaster, oControlPersist,
2352 oHashKnownHosts,
2353@@ -172,10 +174,19 @@ static struct {
2354 { "afstokenpassing", oUnsupported },
2355 #if defined(GSSAPI)
2356 { "gssapiauthentication", oGssAuthentication },
2357+ { "gssapikeyexchange", oGssKeyEx },
2358 { "gssapidelegatecredentials", oGssDelegateCreds },
2359+ { "gssapitrustdns", oGssTrustDns },
2360+ { "gssapiclientidentity", oGssClientIdentity },
2361+ { "gssapiserveridentity", oGssServerIdentity },
2362+ { "gssapirenewalforcesrekey", oGssRenewalRekey },
2363 #else
2364 { "gssapiauthentication", oUnsupported },
2365+ { "gssapikeyexchange", oUnsupported },
2366 { "gssapidelegatecredentials", oUnsupported },
2367+ { "gssapitrustdns", oUnsupported },
2368+ { "gssapiclientidentity", oUnsupported },
2369+ { "gssapirenewalforcesrekey", oUnsupported },
2370 #endif
2371 { "fallbacktorsh", oDeprecated },
2372 { "usersh", oDeprecated },
2373@@ -516,10 +527,30 @@ parse_flag:
2374 intptr = &options->gss_authentication;
2375 goto parse_flag;
2376
2377+ case oGssKeyEx:
2378+ intptr = &options->gss_keyex;
2379+ goto parse_flag;
2380+
2381 case oGssDelegateCreds:
2382 intptr = &options->gss_deleg_creds;
2383 goto parse_flag;
2384
2385+ case oGssTrustDns:
2386+ intptr = &options->gss_trust_dns;
2387+ goto parse_flag;
2388+
2389+ case oGssClientIdentity:
2390+ charptr = &options->gss_client_identity;
2391+ goto parse_string;
2392+
2393+ case oGssServerIdentity:
2394+ charptr = &options->gss_server_identity;
2395+ goto parse_string;
2396+
2397+ case oGssRenewalRekey:
2398+ intptr = &options->gss_renewal_rekey;
2399+ goto parse_flag;
2400+
2401 case oBatchMode:
2402 intptr = &options->batch_mode;
2403 goto parse_flag;
2404@@ -1168,7 +1199,12 @@ initialize_options(Options * options)
2405 options->pubkey_authentication = -1;
2406 options->challenge_response_authentication = -1;
2407 options->gss_authentication = -1;
2408+ options->gss_keyex = -1;
2409 options->gss_deleg_creds = -1;
2410+ options->gss_trust_dns = -1;
2411+ options->gss_renewal_rekey = -1;
2412+ options->gss_client_identity = NULL;
2413+ options->gss_server_identity = NULL;
2414 options->password_authentication = -1;
2415 options->kbd_interactive_authentication = -1;
2416 options->kbd_interactive_devices = NULL;
2417@@ -1268,8 +1304,14 @@ fill_default_options(Options * options)
2418 options->challenge_response_authentication = 1;
2419 if (options->gss_authentication == -1)
2420 options->gss_authentication = 0;
2421+ if (options->gss_keyex == -1)
2422+ options->gss_keyex = 0;
2423 if (options->gss_deleg_creds == -1)
2424 options->gss_deleg_creds = 0;
2425+ if (options->gss_trust_dns == -1)
2426+ options->gss_trust_dns = 0;
2427+ if (options->gss_renewal_rekey == -1)
2428+ options->gss_renewal_rekey = 0;
2429 if (options->password_authentication == -1)
2430 options->password_authentication = 1;
2431 if (options->kbd_interactive_authentication == -1)
2432diff --git a/readconf.h b/readconf.h
2433index 23fc500..675b35d 100644
2434--- a/readconf.h
2435+++ b/readconf.h
2436@@ -48,7 +48,12 @@ typedef struct {
2437 int challenge_response_authentication;
2438 /* Try S/Key or TIS, authentication. */
2439 int gss_authentication; /* Try GSS authentication */
2440+ int gss_keyex; /* Try GSS key exchange */
2441 int gss_deleg_creds; /* Delegate GSS credentials */
2442+ int gss_trust_dns; /* Trust DNS for GSS canonicalization */
2443+ int gss_renewal_rekey; /* Credential renewal forces rekey */
2444+ char *gss_client_identity; /* Principal to initiate GSSAPI with */
2445+ char *gss_server_identity; /* GSSAPI target principal */
2446 int password_authentication; /* Try password
2447 * authentication. */
2448 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
2449diff --git a/servconf.c b/servconf.c
2450index 747edde..c938ae3 100644
2451--- a/servconf.c
2452+++ b/servconf.c
2453@@ -107,7 +107,10 @@ initialize_server_options(ServerOptions *options)
2454 options->kerberos_ticket_cleanup = -1;
2455 options->kerberos_get_afs_token = -1;
2456 options->gss_authentication=-1;
2457+ options->gss_keyex = -1;
2458 options->gss_cleanup_creds = -1;
2459+ options->gss_strict_acceptor = -1;
2460+ options->gss_store_rekey = -1;
2461 options->password_authentication = -1;
2462 options->kbd_interactive_authentication = -1;
2463 options->challenge_response_authentication = -1;
2464@@ -240,8 +243,14 @@ fill_default_server_options(ServerOptions *options)
2465 options->kerberos_get_afs_token = 0;
2466 if (options->gss_authentication == -1)
2467 options->gss_authentication = 0;
2468+ if (options->gss_keyex == -1)
2469+ options->gss_keyex = 0;
2470 if (options->gss_cleanup_creds == -1)
2471 options->gss_cleanup_creds = 1;
2472+ if (options->gss_strict_acceptor == -1)
2473+ options->gss_strict_acceptor = 1;
2474+ if (options->gss_store_rekey == -1)
2475+ options->gss_store_rekey = 0;
2476 if (options->password_authentication == -1)
2477 options->password_authentication = 1;
2478 if (options->kbd_interactive_authentication == -1)
2479@@ -338,7 +347,9 @@ typedef enum {
2480 sBanner, sUseDNS, sHostbasedAuthentication,
2481 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
2482 sClientAliveCountMax, sAuthorizedKeysFile,
2483- sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
2484+ sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
2485+ sGssKeyEx, sGssStoreRekey,
2486+ sAcceptEnv, sPermitTunnel,
2487 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
2488 sUsePrivilegeSeparation, sAllowAgentForwarding,
2489 sZeroKnowledgePasswordAuthentication, sHostCertificate,
2490@@ -405,10 +416,20 @@ static struct {
2491 #ifdef GSSAPI
2492 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
2493 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
2494+ { "gssapicleanupcreds", sGssCleanupCreds, SSHCFG_GLOBAL },
2495+ { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
2496+ { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
2497+ { "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
2498 #else
2499 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
2500 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
2501+ { "gssapicleanupcreds", sUnsupported, SSHCFG_GLOBAL },
2502+ { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
2503+ { "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
2504+ { "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
2505 #endif
2506+ { "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL },
2507+ { "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL },
2508 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
2509 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
2510 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
2511@@ -1073,10 +1094,22 @@ process_server_config_line(ServerOptions *options, char *line,
2512 intptr = &options->gss_authentication;
2513 goto parse_flag;
2514
2515+ case sGssKeyEx:
2516+ intptr = &options->gss_keyex;
2517+ goto parse_flag;
2518+
2519 case sGssCleanupCreds:
2520 intptr = &options->gss_cleanup_creds;
2521 goto parse_flag;
2522
2523+ case sGssStrictAcceptor:
2524+ intptr = &options->gss_strict_acceptor;
2525+ goto parse_flag;
2526+
2527+ case sGssStoreRekey:
2528+ intptr = &options->gss_store_rekey;
2529+ goto parse_flag;
2530+
2531 case sPasswordAuthentication:
2532 intptr = &options->password_authentication;
2533 goto parse_flag;
2534@@ -1983,7 +2016,10 @@ dump_config(ServerOptions *o)
2535 #endif
2536 #ifdef GSSAPI
2537 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2538+ dump_cfg_fmtint(sGssKeyEx, o->gss_keyex);
2539 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
2540+ dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor);
2541+ dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey);
2542 #endif
2543 #ifdef JPAKE
2544 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
2545diff --git a/servconf.h b/servconf.h
2546index 98aad8b..ab6e346 100644
2547--- a/servconf.h
2548+++ b/servconf.h
2549@@ -111,7 +111,10 @@ typedef struct {
2550 int kerberos_get_afs_token; /* If true, try to get AFS token if
2551 * authenticated with Kerberos. */
2552 int gss_authentication; /* If true, permit GSSAPI authentication */
2553+ int gss_keyex; /* If true, permit GSSAPI key exchange */
2554 int gss_cleanup_creds; /* If true, destroy cred cache on logout */
2555+ int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */
2556+ int gss_store_rekey;
2557 int password_authentication; /* If true, permit password
2558 * authentication. */
2559 int kbd_interactive_authentication; /* If true, permit */
2560diff --git a/ssh-gss.h b/ssh-gss.h
2561index 077e13c..bc6e8f9 100644
2562--- a/ssh-gss.h
2563+++ b/ssh-gss.h
2564@@ -1,6 +1,6 @@
2565 /* $OpenBSD: ssh-gss.h,v 1.10 2007/06/12 08:20:00 djm Exp $ */
2566 /*
2567- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
2568+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
2569 *
2570 * Redistribution and use in source and binary forms, with or without
2571 * modification, are permitted provided that the following conditions
2572@@ -61,10 +61,22 @@
2573
2574 #define SSH_GSS_OIDTYPE 0x06
2575
2576+#define SSH2_MSG_KEXGSS_INIT 30
2577+#define SSH2_MSG_KEXGSS_CONTINUE 31
2578+#define SSH2_MSG_KEXGSS_COMPLETE 32
2579+#define SSH2_MSG_KEXGSS_HOSTKEY 33
2580+#define SSH2_MSG_KEXGSS_ERROR 34
2581+#define SSH2_MSG_KEXGSS_GROUPREQ 40
2582+#define SSH2_MSG_KEXGSS_GROUP 41
2583+#define KEX_GSS_GRP1_SHA1_ID "gss-group1-sha1-"
2584+#define KEX_GSS_GRP14_SHA1_ID "gss-group14-sha1-"
2585+#define KEX_GSS_GEX_SHA1_ID "gss-gex-sha1-"
2586+
2587 typedef struct {
2588 char *filename;
2589 char *envvar;
2590 char *envval;
2591+ struct passwd *owner;
2592 void *data;
2593 } ssh_gssapi_ccache;
2594
2595@@ -72,8 +84,11 @@ typedef struct {
2596 gss_buffer_desc displayname;
2597 gss_buffer_desc exportedname;
2598 gss_cred_id_t creds;
2599+ gss_name_t name;
2600 struct ssh_gssapi_mech_struct *mech;
2601 ssh_gssapi_ccache store;
2602+ int used;
2603+ int updated;
2604 } ssh_gssapi_client;
2605
2606 typedef struct ssh_gssapi_mech_struct {
2607@@ -84,6 +99,7 @@ typedef struct ssh_gssapi_mech_struct {
2608 int (*userok) (ssh_gssapi_client *, char *);
2609 int (*localname) (ssh_gssapi_client *, char **);
2610 void (*storecreds) (ssh_gssapi_client *);
2611+ int (*updatecreds) (ssh_gssapi_ccache *, ssh_gssapi_client *);
2612 } ssh_gssapi_mech;
2613
2614 typedef struct {
2615@@ -94,10 +110,11 @@ typedef struct {
2616 gss_OID oid; /* client */
2617 gss_cred_id_t creds; /* server */
2618 gss_name_t client; /* server */
2619- gss_cred_id_t client_creds; /* server */
2620+ gss_cred_id_t client_creds; /* both */
2621 } Gssctxt;
2622
2623 extern ssh_gssapi_mech *supported_mechs[];
2624+extern Gssctxt *gss_kex_context;
2625
2626 int ssh_gssapi_check_oid(Gssctxt *, void *, size_t);
2627 void ssh_gssapi_set_oid_data(Gssctxt *, void *, size_t);
2628@@ -117,16 +134,30 @@ void ssh_gssapi_build_ctx(Gssctxt **);
2629 void ssh_gssapi_delete_ctx(Gssctxt **);
2630 OM_uint32 ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
2631 void ssh_gssapi_buildmic(Buffer *, const char *, const char *, const char *);
2632-int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *);
2633+int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *, const char *);
2634+OM_uint32 ssh_gssapi_client_identity(Gssctxt *, const char *);
2635+int ssh_gssapi_credentials_updated(Gssctxt *);
2636
2637 /* In the server */
2638+typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *,
2639+ const char *);
2640+char *ssh_gssapi_client_mechanisms(const char *, const char *);
2641+char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *,
2642+ const char *);
2643+gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
2644+int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *,
2645+ const char *);
2646 OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
2647-int ssh_gssapi_userok(char *name);
2648+int ssh_gssapi_userok(char *name, struct passwd *);
2649 OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
2650 void ssh_gssapi_do_child(char ***, u_int *);
2651 void ssh_gssapi_cleanup_creds(void);
2652 void ssh_gssapi_storecreds(void);
2653
2654+char *ssh_gssapi_server_mechanisms(void);
2655+int ssh_gssapi_oid_table_ok();
2656+
2657+int ssh_gssapi_update_creds(ssh_gssapi_ccache *store);
2658 #endif /* GSSAPI */
2659
2660 #endif /* _SSH_GSS_H */
2661diff --git a/ssh_config b/ssh_config
2662index bb40819..3234321 100644
2663--- a/ssh_config
2664+++ b/ssh_config
2665@@ -26,6 +26,8 @@
2666 # HostbasedAuthentication no
2667 # GSSAPIAuthentication no
2668 # GSSAPIDelegateCredentials no
2669+# GSSAPIKeyExchange no
2670+# GSSAPITrustDNS no
2671 # BatchMode no
2672 # CheckHostIP yes
2673 # AddressFamily any
2674diff --git a/ssh_config.5 b/ssh_config.5
2675index 5d76c6d..e72919a 100644
2676--- a/ssh_config.5
2677+++ b/ssh_config.5
2678@@ -529,11 +529,43 @@ Specifies whether user authentication based on GSSAPI is allowed.
2679 The default is
2680 .Dq no .
2681 Note that this option applies to protocol version 2 only.
2682+.It Cm GSSAPIKeyExchange
2683+Specifies whether key exchange based on GSSAPI may be used. When using
2684+GSSAPI key exchange the server need not have a host key.
2685+The default is
2686+.Dq no .
2687+Note that this option applies to protocol version 2 only.
2688+.It Cm GSSAPIClientIdentity
2689+If set, specifies the GSSAPI client identity that ssh should use when
2690+connecting to the server. The default is unset, which means that the default
2691+identity will be used.
2692+.It Cm GSSAPIServerIdentity
2693+If set, specifies the GSSAPI server identity that ssh should expect when
2694+connecting to the server. The default is unset, which means that the
2695+expected GSSAPI server identity will be determined from the target
2696+hostname.
2697 .It Cm GSSAPIDelegateCredentials
2698 Forward (delegate) credentials to the server.
2699 The default is
2700 .Dq no .
2701-Note that this option applies to protocol version 2 only.
2702+Note that this option applies to protocol version 2 connections using GSSAPI.
2703+.It Cm GSSAPIRenewalForcesRekey
2704+If set to
2705+.Dq yes
2706+then renewal of the client's GSSAPI credentials will force the rekeying of the
2707+ssh connection. With a compatible server, this can delegate the renewed
2708+credentials to a session on the server.
2709+The default is
2710+.Dq no .
2711+.It Cm GSSAPITrustDns
2712+Set to
2713+.Dq yes to indicate that the DNS is trusted to securely canonicalize
2714+the name of the host being connected to. If
2715+.Dq no, the hostname entered on the
2716+command line will be passed untouched to the GSSAPI library.
2717+The default is
2718+.Dq no .
2719+This option only applies to protocol version 2 connections using GSSAPI.
2720 .It Cm HashKnownHosts
2721 Indicates that
2722 .Xr ssh 1
2723diff --git a/sshconnect2.c b/sshconnect2.c
2724index 70e3cd8..0b13530 100644
2725--- a/sshconnect2.c
2726+++ b/sshconnect2.c
2727@@ -160,9 +160,34 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2728 {
2729 Kex *kex;
2730
2731+#ifdef GSSAPI
2732+ char *orig = NULL, *gss = NULL;
2733+ char *gss_host = NULL;
2734+#endif
2735+
2736 xxx_host = host;
2737 xxx_hostaddr = hostaddr;
2738
2739+#ifdef GSSAPI
2740+ if (options.gss_keyex) {
2741+ /* Add the GSSAPI mechanisms currently supported on this
2742+ * client to the key exchange algorithm proposal */
2743+ orig = myproposal[PROPOSAL_KEX_ALGS];
2744+
2745+ if (options.gss_trust_dns)
2746+ gss_host = (char *)get_canonical_hostname(1);
2747+ else
2748+ gss_host = host;
2749+
2750+ gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
2751+ if (gss) {
2752+ debug("Offering GSSAPI proposal: %s", gss);
2753+ xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
2754+ "%s,%s", gss, orig);
2755+ }
2756+ }
2757+#endif
2758+
2759 if (options.ciphers == (char *)-1) {
2760 logit("No valid ciphers for protocol version 2 given, using defaults.");
2761 options.ciphers = NULL;
2762@@ -197,6 +222,17 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2763 if (options.kex_algorithms != NULL)
2764 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
2765
2766+#ifdef GSSAPI
2767+ /* If we've got GSSAPI algorithms, then we also support the
2768+ * 'null' hostkey, as a last resort */
2769+ if (options.gss_keyex && gss) {
2770+ orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
2771+ xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
2772+ "%s,null", orig);
2773+ free(gss);
2774+ }
2775+#endif
2776+
2777 if (options.rekey_limit || options.rekey_interval)
2778 packet_set_rekey_limits((u_int32_t)options.rekey_limit,
2779 (time_t)options.rekey_interval);
2780@@ -208,10 +244,30 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2781 kex->kex[KEX_DH_GEX_SHA1] = kexgex_client;
2782 kex->kex[KEX_DH_GEX_SHA256] = kexgex_client;
2783 kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
2784+#ifdef GSSAPI
2785+ if (options.gss_keyex) {
2786+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client;
2787+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client;
2788+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
2789+ }
2790+#endif
2791 kex->client_version_string=client_version_string;
2792 kex->server_version_string=server_version_string;
2793 kex->verify_host_key=&verify_host_key_callback;
2794
2795+#ifdef GSSAPI
2796+ if (options.gss_keyex) {
2797+ kex->gss_deleg_creds = options.gss_deleg_creds;
2798+ kex->gss_trust_dns = options.gss_trust_dns;
2799+ kex->gss_client = options.gss_client_identity;
2800+ if (options.gss_server_identity) {
2801+ kex->gss_host = options.gss_server_identity;
2802+ } else {
2803+ kex->gss_host = gss_host;
2804+ }
2805+ }
2806+#endif
2807+
2808 xxx_kex = kex;
2809
2810 dispatch_run(DISPATCH_BLOCK, &kex->done, kex);
2811@@ -307,6 +363,7 @@ void input_gssapi_token(int type, u_int32_t, void *);
2812 void input_gssapi_hash(int type, u_int32_t, void *);
2813 void input_gssapi_error(int, u_int32_t, void *);
2814 void input_gssapi_errtok(int, u_int32_t, void *);
2815+int userauth_gsskeyex(Authctxt *authctxt);
2816 #endif
2817
2818 void userauth(Authctxt *, char *);
2819@@ -322,6 +379,11 @@ static char *authmethods_get(void);
2820
2821 Authmethod authmethods[] = {
2822 #ifdef GSSAPI
2823+ {"gssapi-keyex",
2824+ userauth_gsskeyex,
2825+ NULL,
2826+ &options.gss_authentication,
2827+ NULL},
2828 {"gssapi-with-mic",
2829 userauth_gssapi,
2830 NULL,
2831@@ -625,19 +687,31 @@ userauth_gssapi(Authctxt *authctxt)
2832 static u_int mech = 0;
2833 OM_uint32 min;
2834 int ok = 0;
2835+ const char *gss_host;
2836+
2837+ if (options.gss_server_identity)
2838+ gss_host = options.gss_server_identity;
2839+ else if (options.gss_trust_dns)
2840+ gss_host = get_canonical_hostname(1);
2841+ else
2842+ gss_host = authctxt->host;
2843
2844 /* Try one GSSAPI method at a time, rather than sending them all at
2845 * once. */
2846
2847 if (gss_supported == NULL)
2848- gss_indicate_mechs(&min, &gss_supported);
2849+ if (GSS_ERROR(gss_indicate_mechs(&min, &gss_supported))) {
2850+ gss_supported = NULL;
2851+ return 0;
2852+ }
2853
2854 /* Check to see if the mechanism is usable before we offer it */
2855 while (mech < gss_supported->count && !ok) {
2856 /* My DER encoding requires length<128 */
2857 if (gss_supported->elements[mech].length < 128 &&
2858 ssh_gssapi_check_mechanism(&gssctxt,
2859- &gss_supported->elements[mech], authctxt->host)) {
2860+ &gss_supported->elements[mech], gss_host,
2861+ options.gss_client_identity)) {
2862 ok = 1; /* Mechanism works */
2863 } else {
2864 mech++;
2865@@ -734,8 +808,8 @@ input_gssapi_response(int type, u_int32_t plen, void *ctxt)
2866 {
2867 Authctxt *authctxt = ctxt;
2868 Gssctxt *gssctxt;
2869- int oidlen;
2870- char *oidv;
2871+ u_int oidlen;
2872+ u_char *oidv;
2873
2874 if (authctxt == NULL)
2875 fatal("input_gssapi_response: no authentication context");
2876@@ -844,6 +918,48 @@ input_gssapi_error(int type, u_int32_t plen, void *ctxt)
2877 free(msg);
2878 free(lang);
2879 }
2880+
2881+int
2882+userauth_gsskeyex(Authctxt *authctxt)
2883+{
2884+ Buffer b;
2885+ gss_buffer_desc gssbuf;
2886+ gss_buffer_desc mic = GSS_C_EMPTY_BUFFER;
2887+ OM_uint32 ms;
2888+
2889+ static int attempt = 0;
2890+ if (attempt++ >= 1)
2891+ return (0);
2892+
2893+ if (gss_kex_context == NULL) {
2894+ debug("No valid Key exchange context");
2895+ return (0);
2896+ }
2897+
2898+ ssh_gssapi_buildmic(&b, authctxt->server_user, authctxt->service,
2899+ "gssapi-keyex");
2900+
2901+ gssbuf.value = buffer_ptr(&b);
2902+ gssbuf.length = buffer_len(&b);
2903+
2904+ if (GSS_ERROR(ssh_gssapi_sign(gss_kex_context, &gssbuf, &mic))) {
2905+ buffer_free(&b);
2906+ return (0);
2907+ }
2908+
2909+ packet_start(SSH2_MSG_USERAUTH_REQUEST);
2910+ packet_put_cstring(authctxt->server_user);
2911+ packet_put_cstring(authctxt->service);
2912+ packet_put_cstring(authctxt->method->name);
2913+ packet_put_string(mic.value, mic.length);
2914+ packet_send();
2915+
2916+ buffer_free(&b);
2917+ gss_release_buffer(&ms, &mic);
2918+
2919+ return (1);
2920+}
2921+
2922 #endif /* GSSAPI */
2923
2924 int
2925diff --git a/sshd.c b/sshd.c
2926index 174cc7a..4eddeb8 100644
2927--- a/sshd.c
2928+++ b/sshd.c
2929@@ -122,6 +122,10 @@
2930 #include "ssh-sandbox.h"
2931 #include "version.h"
2932
2933+#ifdef USE_SECURITY_SESSION_API
2934+#include <Security/AuthSession.h>
2935+#endif
2936+
2937 #ifdef LIBWRAP
2938 #include <tcpd.h>
2939 #include <syslog.h>
2940@@ -1703,10 +1707,13 @@ main(int ac, char **av)
2941 logit("Disabling protocol version 1. Could not load host key");
2942 options.protocol &= ~SSH_PROTO_1;
2943 }
2944+#ifndef GSSAPI
2945+ /* The GSSAPI key exchange can run without a host key */
2946 if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) {
2947 logit("Disabling protocol version 2. Could not load host key");
2948 options.protocol &= ~SSH_PROTO_2;
2949 }
2950+#endif
2951 if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) {
2952 logit("sshd: no hostkeys available -- exiting.");
2953 exit(1);
2954@@ -2035,6 +2042,60 @@ main(int ac, char **av)
2955 /* Log the connection. */
2956 verbose("Connection from %.500s port %d", remote_ip, remote_port);
2957
2958+#ifdef USE_SECURITY_SESSION_API
2959+ /*
2960+ * Create a new security session for use by the new user login if
2961+ * the current session is the root session or we are not launched
2962+ * by inetd (eg: debugging mode or server mode). We do not
2963+ * necessarily need to create a session if we are launched from
2964+ * inetd because Panther xinetd will create a session for us.
2965+ *
2966+ * The only case where this logic will fail is if there is an
2967+ * inetd running in a non-root session which is not creating
2968+ * new sessions for us. Then all the users will end up in the
2969+ * same session (bad).
2970+ *
2971+ * When the client exits, the session will be destroyed for us
2972+ * automatically.
2973+ *
2974+ * We must create the session before any credentials are stored
2975+ * (including AFS pags, which happens a few lines below).
2976+ */
2977+ {
2978+ OSStatus err = 0;
2979+ SecuritySessionId sid = 0;
2980+ SessionAttributeBits sattrs = 0;
2981+
2982+ err = SessionGetInfo(callerSecuritySession, &sid, &sattrs);
2983+ if (err)
2984+ error("SessionGetInfo() failed with error %.8X",
2985+ (unsigned) err);
2986+ else
2987+ debug("Current Session ID is %.8X / Session Attributes are %.8X",
2988+ (unsigned) sid, (unsigned) sattrs);
2989+
2990+ if (inetd_flag && !(sattrs & sessionIsRoot))
2991+ debug("Running in inetd mode in a non-root session... "
2992+ "assuming inetd created the session for us.");
2993+ else {
2994+ debug("Creating new security session...");
2995+ err = SessionCreate(0, sessionHasTTY | sessionIsRemote);
2996+ if (err)
2997+ error("SessionCreate() failed with error %.8X",
2998+ (unsigned) err);
2999+
3000+ err = SessionGetInfo(callerSecuritySession, &sid,
3001+ &sattrs);
3002+ if (err)
3003+ error("SessionGetInfo() failed with error %.8X",
3004+ (unsigned) err);
3005+ else
3006+ debug("New Session ID is %.8X / Session Attributes are %.8X",
3007+ (unsigned) sid, (unsigned) sattrs);
3008+ }
3009+ }
3010+#endif
3011+
3012 /*
3013 * We don't want to listen forever unless the other side
3014 * successfully authenticates itself. So we set up an alarm which is
3015@@ -2439,6 +2500,48 @@ do_ssh2_kex(void)
3016
3017 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types();
3018
3019+#ifdef GSSAPI
3020+ {
3021+ char *orig;
3022+ char *gss = NULL;
3023+ char *newstr = NULL;
3024+ orig = myproposal[PROPOSAL_KEX_ALGS];
3025+
3026+ /*
3027+ * If we don't have a host key, then there's no point advertising
3028+ * the other key exchange algorithms
3029+ */
3030+
3031+ if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
3032+ orig = NULL;
3033+
3034+ if (options.gss_keyex)
3035+ gss = ssh_gssapi_server_mechanisms();
3036+ else
3037+ gss = NULL;
3038+
3039+ if (gss && orig)
3040+ xasprintf(&newstr, "%s,%s", gss, orig);
3041+ else if (gss)
3042+ newstr = gss;
3043+ else if (orig)
3044+ newstr = orig;
3045+
3046+ /*
3047+ * If we've got GSSAPI mechanisms, then we've got the 'null' host
3048+ * key alg, but we can't tell people about it unless its the only
3049+ * host key algorithm we support
3050+ */
3051+ if (gss && (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS])) == 0)
3052+ myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = "null";
3053+
3054+ if (newstr)
3055+ myproposal[PROPOSAL_KEX_ALGS] = newstr;
3056+ else
3057+ fatal("No supported key exchange algorithms");
3058+ }
3059+#endif
3060+
3061 /* start key exchange */
3062 kex = kex_setup(myproposal);
3063 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
3064@@ -2446,6 +2549,13 @@ do_ssh2_kex(void)
3065 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
3066 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
3067 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
3068+#ifdef GSSAPI
3069+ if (options.gss_keyex) {
3070+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
3071+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
3072+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
3073+ }
3074+#endif
3075 kex->server = 1;
3076 kex->client_version_string=client_version_string;
3077 kex->server_version_string=server_version_string;
3078diff --git a/sshd_config b/sshd_config
3079index b786361..9450141 100644
3080--- a/sshd_config
3081+++ b/sshd_config
3082@@ -83,6 +83,8 @@ AuthorizedKeysFile .ssh/authorized_keys
3083 # GSSAPI options
3084 #GSSAPIAuthentication no
3085 #GSSAPICleanupCredentials yes
3086+#GSSAPIStrictAcceptorCheck yes
3087+#GSSAPIKeyExchange no
3088
3089 # Set this to 'yes' to enable PAM authentication, account processing,
3090 # and session processing. If this is enabled, PAM authentication will
3091diff --git a/sshd_config.5 b/sshd_config.5
3092index 3abac6c..525d9c8 100644
3093--- a/sshd_config.5
3094+++ b/sshd_config.5
3095@@ -484,12 +484,40 @@ Specifies whether user authentication based on GSSAPI is allowed.
3096 The default is
3097 .Dq no .
3098 Note that this option applies to protocol version 2 only.
3099+.It Cm GSSAPIKeyExchange
3100+Specifies whether key exchange based on GSSAPI is allowed. GSSAPI key exchange
3101+doesn't rely on ssh keys to verify host identity.
3102+The default is
3103+.Dq no .
3104+Note that this option applies to protocol version 2 only.
3105 .It Cm GSSAPICleanupCredentials
3106 Specifies whether to automatically destroy the user's credentials cache
3107 on logout.
3108 The default is
3109 .Dq yes .
3110 Note that this option applies to protocol version 2 only.
3111+.It Cm GSSAPIStrictAcceptorCheck
3112+Determines whether to be strict about the identity of the GSSAPI acceptor
3113+a client authenticates against. If
3114+.Dq yes
3115+then the client must authenticate against the
3116+.Pa host
3117+service on the current hostname. If
3118+.Dq no
3119+then the client may authenticate against any service key stored in the
3120+machine's default store. This facility is provided to assist with operation
3121+on multi homed machines.
3122+The default is
3123+.Dq yes .
3124+Note that this option applies only to protocol version 2 GSSAPI connections,
3125+and setting it to
3126+.Dq no
3127+may only work with recent Kerberos GSSAPI libraries.
3128+.It Cm GSSAPIStoreCredentialsOnRekey
3129+Controls whether the user's GSSAPI credentials should be updated following a
3130+successful connection rekeying. This option can be used to accepted renewed
3131+or updated credentials from a compatible client. The default is
3132+.Dq no .
3133 .It Cm HostbasedAuthentication
3134 Specifies whether rhosts or /etc/hosts.equiv authentication together
3135 with successful public key client host authentication is allowed
diff --git a/debian/patches/helpful-wait-terminate.patch b/debian/patches/helpful-wait-terminate.patch
new file mode 100644
index 000000000..66a59a053
--- /dev/null
+++ b/debian/patches/helpful-wait-terminate.patch
@@ -0,0 +1,26 @@
1From ea2e0af0bc3a683edb32b508c03eb793617f6f31 Mon Sep 17 00:00:00 2001
2From: Matthew Vernon <matthew@debian.org>
3Date: Sun, 9 Feb 2014 16:09:56 +0000
4Subject: Mention ~& when waiting for forwarded connections to terminate
5
6Bug-Debian: http://bugs.debian.org/50308
7Last-Update: 2010-02-27
8
9Patch-Name: helpful-wait-terminate.patch
10---
11 serverloop.c | 2 +-
12 1 file changed, 1 insertion(+), 1 deletion(-)
13
14diff --git a/serverloop.c b/serverloop.c
15index ccbad61..5f22df3 100644
16--- a/serverloop.c
17+++ b/serverloop.c
18@@ -686,7 +686,7 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
19 if (!channel_still_open())
20 break;
21 if (!waiting_termination) {
22- const char *s = "Waiting for forwarded connections to terminate...\r\n";
23+ const char *s = "Waiting for forwarded connections to terminate... (press ~& to background)\r\n";
24 char *cp;
25 waiting_termination = 1;
26 buffer_append(&stderr_buffer, s, strlen(s));
diff --git a/debian/patches/keepalive-extensions.patch b/debian/patches/keepalive-extensions.patch
new file mode 100644
index 000000000..61389cc44
--- /dev/null
+++ b/debian/patches/keepalive-extensions.patch
@@ -0,0 +1,135 @@
1From affb41e3cf23b79a3d165ae0d97689a46a965b6f 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: 2013-09-14
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 22e5a3a..2dcbf31 100644
30--- a/readconf.c
31+++ b/readconf.c
32@@ -141,6 +141,7 @@ typedef enum {
33 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
34 oVisualHostKey, oUseRoaming, oZeroKnowledgePasswordAuthentication,
35 oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown,
36+ oProtocolKeepAlives, oSetupTimeOut,
37 oIgnoredUnknownOption, oDeprecated, oUnsupported
38 } OpCodes;
39
40@@ -263,6 +264,8 @@ static struct {
41 { "ipqos", oIPQoS },
42 { "requesttty", oRequestTTY },
43 { "ignoreunknown", oIgnoreUnknown },
44+ { "protocolkeepalives", oProtocolKeepAlives },
45+ { "setuptimeout", oSetupTimeOut },
46
47 { NULL, oBadOption }
48 };
49@@ -939,6 +942,8 @@ parse_int:
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@@ -1404,8 +1409,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 89b25cd..135d833 100644
76--- a/ssh_config.5
77+++ b/ssh_config.5
78@@ -136,8 +136,12 @@ Valid arguments are
79 If set to
80 .Dq 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.
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 .Dq yes
91 or
92@@ -1141,8 +1145,15 @@ 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.
101 This option applies to protocol version 2 only.
102+.Cm ProtocolKeepAlives
103+and
104+.Cm SetupTimeOut
105+are Debian-specific compatibility aliases for this option.
106 .It Cm StrictHostKeyChecking
107 If this flag is set to
108 .Dq yes ,
109@@ -1181,6 +1192,12 @@ Specifies whether the system should send TCP keepalive messages to the
110 other side.
111 If they are sent, death of the connection or crash of one
112 of the machines will be properly noticed.
113+This option only uses TCP keepalives (as opposed to using ssh level
114+keepalives), so takes a long time to notice when the connection dies.
115+As such, you probably want
116+the
117+.Cm ServerAliveInterval
118+option as well.
119 However, this means that
120 connections will die if the route is down temporarily, and some people
121 find it annoying.
122diff --git a/sshd_config.5 b/sshd_config.5
123index 18ec81f..510cc7c 100644
124--- a/sshd_config.5
125+++ b/sshd_config.5
126@@ -1161,6 +1161,9 @@ This avoids infinitely hanging sessions.
127 .Pp
128 To disable TCP keepalive messages, the value should be set to
129 .Dq no .
130+.Pp
131+This option was formerly called
132+.Cm KeepAlive .
133 .It Cm TrustedUserCAKeys
134 Specifies a file containing public keys of certificate authorities that are
135 trusted to sign user certificates for authentication.
diff --git a/debian/patches/lintian-symlink-pickiness.patch b/debian/patches/lintian-symlink-pickiness.patch
new file mode 100644
index 000000000..b3b549cc8
--- /dev/null
+++ b/debian/patches/lintian-symlink-pickiness.patch
@@ -0,0 +1,32 @@
1From 6d50dc6d561af1bcf41eaf1dc69e7920abe5aa4b Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:08 +0000
4Subject: Fix picky lintian errors about slogin symlinks
5
6Apparently this breaks some SVR4 packaging systems, so upstream can't win
7either way and opted to keep the status quo. We need this patch anyway.
8
9Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1728
10Last-Update: 2013-09-14
11
12Patch-Name: lintian-symlink-pickiness.patch
13---
14 Makefile.in | 4 ++--
15 1 file changed, 2 insertions(+), 2 deletions(-)
16
17diff --git a/Makefile.in b/Makefile.in
18index 7cd3a08..839abbd 100644
19--- a/Makefile.in
20+++ b/Makefile.in
21@@ -296,9 +296,9 @@ install-files:
22 $(INSTALL) -m 644 ssh-pkcs11-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8
23 $(INSTALL) -m 644 ssh-vulnkey.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-vulnkey.1
24 -rm -f $(DESTDIR)$(bindir)/slogin
25- ln -s ./ssh$(EXEEXT) $(DESTDIR)$(bindir)/slogin
26+ ln -s ssh$(EXEEXT) $(DESTDIR)$(bindir)/slogin
27 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1
28- ln -s ./ssh.1 $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1
29+ ln -s ssh.1 $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1
30
31 install-sysconf:
32 if [ ! -d $(DESTDIR)$(sysconfdir) ]; then \
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..07682155c
--- /dev/null
+++ b/debian/patches/mention-ssh-keygen-on-keychange.patch
@@ -0,0 +1,41 @@
1From 7a20ce0712e7b7174a0c079e84568a9e8321c42b 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
6Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1843
7Bug-Ubuntu: https://bugs.launchpad.net/bugs/686607
8Last-Update: 2013-09-14
9
10Patch-Name: mention-ssh-keygen-on-keychange.patch
11---
12 sshconnect.c | 7 ++++++-
13 1 file changed, 6 insertions(+), 1 deletion(-)
14
15diff --git a/sshconnect.c b/sshconnect.c
16index 91fd59a..bda83b2 100644
17--- a/sshconnect.c
18+++ b/sshconnect.c
19@@ -981,9 +981,12 @@ check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port,
20 error("%s. This could either mean that", key_msg);
21 error("DNS SPOOFING is happening or the IP address for the host");
22 error("and its host key have changed at the same time.");
23- if (ip_status != HOST_NEW)
24+ if (ip_status != HOST_NEW) {
25 error("Offending key for IP in %s:%lu",
26 ip_found->file, ip_found->line);
27+ error(" remove with: ssh-keygen -f \"%s\" -R %s",
28+ ip_found->file, ip);
29+ }
30 }
31 /* The host key has changed. */
32 warn_changed_key(host_key);
33@@ -991,6 +994,8 @@ check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port,
34 user_hostfiles[0]);
35 error("Offending %s key in %s:%lu", key_type(host_found->key),
36 host_found->file, host_found->line);
37+ error(" remove with: ssh-keygen -f \"%s\" -R %s",
38+ host_found->file, host);
39
40 /*
41 * If strict host key checking is in use, the user will have
diff --git a/debian/patches/no-openssl-version-check.patch b/debian/patches/no-openssl-version-check.patch
new file mode 100644
index 000000000..f45e2b959
--- /dev/null
+++ b/debian/patches/no-openssl-version-check.patch
@@ -0,0 +1,41 @@
1From bc87a22e258193138419d6615c0e92e4124dbe90 Mon Sep 17 00:00:00 2001
2From: Philip Hands <phil@hands.com>
3Date: Sun, 9 Feb 2014 16:10:14 +0000
4Subject: Disable OpenSSL version check
5
6OpenSSL's SONAME is sufficient nowadays.
7
8Author: Colin Watson <cjwatson@debian.org>
9Bug-Debian: http://bugs.debian.org/93581
10Bug-Debian: http://bugs.debian.org/664383
11Forwarded: not-needed
12Last-Update: 2013-12-23
13
14Patch-Name: no-openssl-version-check.patch
15---
16 entropy.c | 12 ------------
17 1 file changed, 12 deletions(-)
18
19diff --git a/entropy.c b/entropy.c
20index 2d483b3..2aee2d9 100644
21--- a/entropy.c
22+++ b/entropy.c
23@@ -209,18 +209,6 @@ seed_rng(void)
24 #ifndef OPENSSL_PRNG_ONLY
25 unsigned char buf[RANDOM_SEED_SIZE];
26 #endif
27- /*
28- * OpenSSL version numbers: MNNFFPPS: major minor fix patch status
29- * We match major, minor, fix and status (not patch) for <1.0.0.
30- * After that, we acceptable compatible fix versions (so we
31- * allow 1.0.1 to work with 1.0.0). Going backwards is only allowed
32- * within a patch series.
33- */
34- u_long version_mask = SSLeay() >= 0x1000000f ? ~0xffff0L : ~0xff0L;
35- if (((SSLeay() ^ OPENSSL_VERSION_NUMBER) & version_mask) ||
36- (SSLeay() >> 12) < (OPENSSL_VERSION_NUMBER >> 12))
37- fatal("OpenSSL version mismatch. Built against %lx, you "
38- "have %lx", (u_long)OPENSSL_VERSION_NUMBER, SSLeay());
39
40 #ifndef OPENSSL_PRNG_ONLY
41 if (RAND_status() == 1) {
diff --git a/debian/patches/openbsd-docs.patch b/debian/patches/openbsd-docs.patch
new file mode 100644
index 000000000..afc1fe306
--- /dev/null
+++ b/debian/patches/openbsd-docs.patch
@@ -0,0 +1,148 @@
1From 98517b1b99dceff74e4a1e50d5a345f5b569ad6f 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: 2013-09-14
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 ef0de08..149846c 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 144be7d..753cc62 100644
48--- a/ssh-keygen.1
49+++ b/ssh-keygen.1
50@@ -171,9 +171,7 @@ key in
51 .Pa ~/.ssh/id_dsa
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@@ -219,9 +217,7 @@ The options are as follows:
62 For each of the key types (rsa1, rsa, dsa and ecdsa) for which host keys
63 do not exist, generate the host keys with the default key file path,
64 an empty passphrase, default bits for the key type, and default comment.
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 trials
70 Specifies the number of primality tests to perform when screening DH-GEX
71 candidates using the
72@@ -605,7 +601,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@@ -800,7 +796,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 0b38ae1..b3c3924 100644
92--- a/ssh.1
93+++ b/ssh.1
94@@ -756,6 +756,10 @@ Protocol 1 is restricted to using only RSA keys,
95 but protocol 2 may use any.
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 a604429..6bdd219 100644
107--- a/sshd.8
108+++ b/sshd.8
109@@ -70,7 +70,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@@ -859,7 +859,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 The file format is described in
126 .Xr moduli 5 .
127@@ -957,7 +957,6 @@ The content of this file is not sensitive; it can be world-readable.
128 .Xr ssh-vulnkey 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 eaf8d01..ec4851a 100644
137--- a/sshd_config.5
138+++ b/sshd_config.5
139@@ -283,8 +283,7 @@ This option is only available for protocol version 2.
140 By default, no banner is displayed.
141 .It Cm ChallengeResponseAuthentication
142 Specifies whether challenge-response authentication is allowed (e.g. via
143-PAM or though authentication styles supported in
144-.Xr login.conf 5 )
145+PAM).
146 The default is
147 .Dq 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..df97fa40f
--- /dev/null
+++ b/debian/patches/package-versioning.patch
@@ -0,0 +1,65 @@
1From da3ff9786c4c03b2aac4936b28f06b3c152e230d 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: 2013-09-14
13
14Patch-Name: package-versioning.patch
15---
16 sshconnect.c | 4 ++--
17 sshd.c | 2 +-
18 version.h | 7 ++++++-
19 3 files changed, 9 insertions(+), 4 deletions(-)
20
21diff --git a/sshconnect.c b/sshconnect.c
22index bda83b2..ad960fd 100644
23--- a/sshconnect.c
24+++ b/sshconnect.c
25@@ -442,10 +442,10 @@ send_client_banner(int connection_out, int minor1)
26 /* Send our own protocol version identification. */
27 if (compat20) {
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 } else {
32 xasprintf(&client_version_string, "SSH-%d.%d-%.100s\n",
33- PROTOCOL_MAJOR_1, minor1, SSH_VERSION);
34+ PROTOCOL_MAJOR_1, minor1, SSH_RELEASE);
35 }
36 if (roaming_atomicio(vwrite, connection_out, client_version_string,
37 strlen(client_version_string)) != strlen(client_version_string))
38diff --git a/sshd.c b/sshd.c
39index fbe3284..7efa7ef 100644
40--- a/sshd.c
41+++ b/sshd.c
42@@ -440,7 +440,7 @@ sshd_exchange_identification(int sock_in, int sock_out)
43 }
44
45 xasprintf(&server_version_string, "SSH-%d.%d-%.100s%s%s%s",
46- major, minor, SSH_VERSION,
47+ major, minor, SSH_RELEASE,
48 *options.version_addendum == '\0' ? "" : " ",
49 options.version_addendum, newline);
50
51diff --git a/version.h b/version.h
52index 39033ed..036277d 100644
53--- a/version.h
54+++ b/version.h
55@@ -3,4 +3,9 @@
56 #define SSH_VERSION "OpenSSH_6.4"
57
58 #define SSH_PORTABLE "p1"
59-#define SSH_RELEASE SSH_VERSION SSH_PORTABLE
60+#define SSH_RELEASE_MINIMUM SSH_VERSION SSH_PORTABLE
61+#ifdef SSH_EXTRAVERSION
62+#define SSH_RELEASE SSH_RELEASE_MINIMUM " " SSH_EXTRAVERSION
63+#else
64+#define SSH_RELEASE SSH_RELEASE_MINIMUM
65+#endif
diff --git a/debian/patches/quieter-signals.patch b/debian/patches/quieter-signals.patch
new file mode 100644
index 000000000..5cb0146d8
--- /dev/null
+++ b/debian/patches/quieter-signals.patch
@@ -0,0 +1,40 @@
1From da5b4ce7296ada332d70133a9ec02ba71c742b7d Mon Sep 17 00:00:00 2001
2From: Peter Samuelson <peter@p12n.org>
3Date: Sun, 9 Feb 2014 16:09:55 +0000
4Subject: Reduce severity of "Killed by signal %d"
5
6This produces irritating messages when using ProxyCommand or other programs
7that use ssh under the covers (e.g. Subversion). These messages are more
8normally printed by the calling program, such as the shell.
9
10According to the upstream bug, the right way to avoid this is to use the -q
11option, so we may drop this patch after further investigation into whether
12any software in Debian is still relying on it.
13
14Author: Colin Watson <cjwatson@debian.org>
15Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1118
16Bug-Debian: http://bugs.debian.org/313371
17Last-Update: 2013-09-14
18
19Patch-Name: quieter-signals.patch
20---
21 clientloop.c | 6 ++++--
22 1 file changed, 4 insertions(+), 2 deletions(-)
23
24diff --git a/clientloop.c b/clientloop.c
25index dc76d69..f2f474e 100644
26--- a/clientloop.c
27+++ b/clientloop.c
28@@ -1717,8 +1717,10 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
29 exit_status = 0;
30 }
31
32- if (received_signal)
33- fatal("Killed by signal %d.", (int) received_signal);
34+ if (received_signal) {
35+ debug("Killed by signal %d.", (int) received_signal);
36+ cleanup_exit((int) received_signal + 128);
37+ }
38
39 /*
40 * In interactive mode (with pseudo tty) display a message indicating
diff --git a/debian/patches/scp-quoting.patch b/debian/patches/scp-quoting.patch
new file mode 100644
index 000000000..887164beb
--- /dev/null
+++ b/debian/patches/scp-quoting.patch
@@ -0,0 +1,41 @@
1From 7531f41888f9e40be95a319fb325f6f05dd50751 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 28ded5e..b7a17ab 100644
21--- a/scp.c
22+++ b/scp.c
23@@ -189,8 +189,16 @@ do_local_cmd(arglist *a)
24
25 if (verbose_mode) {
26 fprintf(stderr, "Executing:");
27- for (i = 0; i < a->num; i++)
28- fprintf(stderr, " %s", a->list[i]);
29+ for (i = 0; i < a->num; i++) {
30+ if (i == 0)
31+ fprintf(stderr, " %s", a->list[i]);
32+ else
33+ /*
34+ * TODO: misbehaves if a->list[i] contains a
35+ * single quote
36+ */
37+ fprintf(stderr, " '%s'", a->list[i]);
38+ }
39 fprintf(stderr, "\n");
40 }
41 if ((pid = fork()) == -1)
diff --git a/debian/patches/selinux-role.patch b/debian/patches/selinux-role.patch
new file mode 100644
index 000000000..8aa8f614e
--- /dev/null
+++ b/debian/patches/selinux-role.patch
@@ -0,0 +1,504 @@
1From 07f2a771c490bd68cd5c5ea9c535705e93bd94f3 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: 2013-09-14
13
14Patch-Name: selinux-role.patch
15---
16 auth.h | 1 +
17 auth1.c | 8 +++++++-
18 auth2.c | 10 ++++++++--
19 monitor.c | 32 +++++++++++++++++++++++++++++---
20 monitor.h | 2 ++
21 monitor_wrap.c | 22 ++++++++++++++++++++--
22 monitor_wrap.h | 3 ++-
23 openbsd-compat/port-linux.c | 27 ++++++++++++++++++++-------
24 openbsd-compat/port-linux.h | 4 ++--
25 platform.c | 4 ++--
26 platform.h | 2 +-
27 session.c | 10 +++++-----
28 session.h | 2 +-
29 sshd.c | 2 +-
30 sshpty.c | 4 ++--
31 sshpty.h | 2 +-
32 16 files changed, 104 insertions(+), 31 deletions(-)
33
34diff --git a/auth.h b/auth.h
35index 80f0898..5b6824f 100644
36--- a/auth.h
37+++ b/auth.h
38@@ -59,6 +59,7 @@ struct Authctxt {
39 char *service;
40 struct passwd *pw; /* set if 'valid' */
41 char *style;
42+ char *role;
43 void *kbdintctxt;
44 char *info; /* Extra info for next auth_log */
45 void *jpake_ctx;
46diff --git a/auth1.c b/auth1.c
47index f1ac598..2803a3c 100644
48--- a/auth1.c
49+++ b/auth1.c
50@@ -380,7 +380,7 @@ void
51 do_authentication(Authctxt *authctxt)
52 {
53 u_int ulen;
54- char *user, *style = NULL;
55+ char *user, *style = NULL, *role = NULL;
56
57 /* Get the name of the user that we wish to log in as. */
58 packet_read_expect(SSH_CMSG_USER);
59@@ -389,11 +389,17 @@ do_authentication(Authctxt *authctxt)
60 user = packet_get_cstring(&ulen);
61 packet_check_eom();
62
63+ if ((role = strchr(user, '/')) != NULL)
64+ *role++ = '\0';
65+
66 if ((style = strchr(user, ':')) != NULL)
67 *style++ = '\0';
68+ else if (role && (style = strchr(role, ':')) != NULL)
69+ *style++ = '\0';
70
71 authctxt->user = user;
72 authctxt->style = style;
73+ authctxt->role = role;
74
75 /* Verify that the user is a valid user. */
76 if ((authctxt->pw = PRIVSEP(getpwnamallow(user))) != NULL)
77diff --git a/auth2.c b/auth2.c
78index 6ed8f04..b55bbcd 100644
79--- a/auth2.c
80+++ b/auth2.c
81@@ -222,7 +222,7 @@ input_userauth_request(int type, u_int32_t seq, void *ctxt)
82 {
83 Authctxt *authctxt = ctxt;
84 Authmethod *m = NULL;
85- char *user, *service, *method, *style = NULL;
86+ char *user, *service, *method, *style = NULL, *role = NULL;
87 int authenticated = 0;
88
89 if (authctxt == NULL)
90@@ -234,8 +234,13 @@ input_userauth_request(int type, u_int32_t seq, void *ctxt)
91 debug("userauth-request for user %s service %s method %s", user, service, method);
92 debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
93
94+ if ((role = strchr(user, '/')) != NULL)
95+ *role++ = 0;
96+
97 if ((style = strchr(user, ':')) != NULL)
98 *style++ = 0;
99+ else if (role && (style = strchr(role, ':')) != NULL)
100+ *style++ = '\0';
101
102 if (authctxt->attempt++ == 0) {
103 /* setup auth context */
104@@ -259,8 +264,9 @@ input_userauth_request(int type, u_int32_t seq, void *ctxt)
105 use_privsep ? " [net]" : "");
106 authctxt->service = xstrdup(service);
107 authctxt->style = style ? xstrdup(style) : NULL;
108+ authctxt->role = role ? xstrdup(role) : NULL;
109 if (use_privsep)
110- mm_inform_authserv(service, style);
111+ mm_inform_authserv(service, style, role);
112 userauth_banner();
113 if (auth2_setup_methods_lists(authctxt) != 0)
114 packet_disconnect("no authentication methods enabled");
115diff --git a/monitor.c b/monitor.c
116index 9079c97..e8d63eb 100644
117--- a/monitor.c
118+++ b/monitor.c
119@@ -146,6 +146,7 @@ int mm_answer_sign(int, Buffer *);
120 int mm_answer_pwnamallow(int, Buffer *);
121 int mm_answer_auth2_read_banner(int, Buffer *);
122 int mm_answer_authserv(int, Buffer *);
123+int mm_answer_authrole(int, Buffer *);
124 int mm_answer_authpassword(int, Buffer *);
125 int mm_answer_bsdauthquery(int, Buffer *);
126 int mm_answer_bsdauthrespond(int, Buffer *);
127@@ -227,6 +228,7 @@ struct mon_table mon_dispatch_proto20[] = {
128 {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
129 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
130 {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
131+ {MONITOR_REQ_AUTHROLE, MON_ONCE, mm_answer_authrole},
132 {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
133 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
134 #ifdef USE_PAM
135@@ -844,6 +846,7 @@ mm_answer_pwnamallow(int sock, Buffer *m)
136 else {
137 /* Allow service/style information on the auth context */
138 monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
139+ monitor_permit(mon_dispatch, MONITOR_REQ_AUTHROLE, 1);
140 monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
141 }
142 #ifdef USE_PAM
143@@ -874,14 +877,37 @@ mm_answer_authserv(int sock, Buffer *m)
144
145 authctxt->service = buffer_get_string(m, NULL);
146 authctxt->style = buffer_get_string(m, NULL);
147- debug3("%s: service=%s, style=%s",
148- __func__, authctxt->service, authctxt->style);
149+ authctxt->role = buffer_get_string(m, NULL);
150+ debug3("%s: service=%s, style=%s, role=%s",
151+ __func__, authctxt->service, authctxt->style, authctxt->role);
152
153 if (strlen(authctxt->style) == 0) {
154 free(authctxt->style);
155 authctxt->style = NULL;
156 }
157
158+ if (strlen(authctxt->role) == 0) {
159+ free(authctxt->role);
160+ authctxt->role = NULL;
161+ }
162+
163+ return (0);
164+}
165+
166+int
167+mm_answer_authrole(int sock, Buffer *m)
168+{
169+ monitor_permit_authentications(1);
170+
171+ authctxt->role = buffer_get_string(m, NULL);
172+ debug3("%s: role=%s",
173+ __func__, authctxt->role);
174+
175+ if (strlen(authctxt->role) == 0) {
176+ free(authctxt->role);
177+ authctxt->role = NULL;
178+ }
179+
180 return (0);
181 }
182
183@@ -1486,7 +1512,7 @@ mm_answer_pty(int sock, Buffer *m)
184 res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty));
185 if (res == 0)
186 goto error;
187- pty_setowner(authctxt->pw, s->tty);
188+ pty_setowner(authctxt->pw, s->tty, authctxt->role);
189
190 buffer_put_int(m, 1);
191 buffer_put_cstring(m, s->tty);
192diff --git a/monitor.h b/monitor.h
193index 315ef99..3c13706 100644
194--- a/monitor.h
195+++ b/monitor.h
196@@ -73,6 +73,8 @@ enum monitor_reqtype {
197 MONITOR_REQ_GSSSIGN = 150, MONITOR_ANS_GSSSIGN = 151,
198 MONITOR_REQ_GSSUPCREDS = 152, MONITOR_ANS_GSSUPCREDS = 153,
199
200+ MONITOR_REQ_AUTHROLE = 154,
201+
202 };
203
204 struct mm_master;
205diff --git a/monitor_wrap.c b/monitor_wrap.c
206index 44019f3..69bc324 100644
207--- a/monitor_wrap.c
208+++ b/monitor_wrap.c
209@@ -320,10 +320,10 @@ mm_auth2_read_banner(void)
210 return (banner);
211 }
212
213-/* Inform the privileged process about service and style */
214+/* Inform the privileged process about service, style, and role */
215
216 void
217-mm_inform_authserv(char *service, char *style)
218+mm_inform_authserv(char *service, char *style, char *role)
219 {
220 Buffer m;
221
222@@ -332,12 +332,30 @@ mm_inform_authserv(char *service, char *style)
223 buffer_init(&m);
224 buffer_put_cstring(&m, service);
225 buffer_put_cstring(&m, style ? style : "");
226+ buffer_put_cstring(&m, role ? role : "");
227
228 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m);
229
230 buffer_free(&m);
231 }
232
233+/* Inform the privileged process about role */
234+
235+void
236+mm_inform_authrole(char *role)
237+{
238+ Buffer m;
239+
240+ debug3("%s entering", __func__);
241+
242+ buffer_init(&m);
243+ buffer_put_cstring(&m, role ? role : "");
244+
245+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHROLE, &m);
246+
247+ buffer_free(&m);
248+}
249+
250 /* Do the password authentication */
251 int
252 mm_auth_password(Authctxt *authctxt, char *password)
253diff --git a/monitor_wrap.h b/monitor_wrap.h
254index ec9b9b1..4d12e29 100644
255--- a/monitor_wrap.h
256+++ b/monitor_wrap.h
257@@ -41,7 +41,8 @@ void mm_log_handler(LogLevel, const char *, void *);
258 int mm_is_monitor(void);
259 DH *mm_choose_dh(int, int, int);
260 int mm_key_sign(Key *, u_char **, u_int *, u_char *, u_int);
261-void mm_inform_authserv(char *, char *);
262+void mm_inform_authserv(char *, char *, char *);
263+void mm_inform_authrole(char *);
264 struct passwd *mm_getpwnamallow(const char *);
265 char *mm_auth2_read_banner(void);
266 int mm_auth_password(struct Authctxt *, char *);
267diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c
268index 4637a7a..de6ad3f 100644
269--- a/openbsd-compat/port-linux.c
270+++ b/openbsd-compat/port-linux.c
271@@ -29,6 +29,12 @@
272 #include <string.h>
273 #include <stdio.h>
274
275+#ifdef WITH_SELINUX
276+#include "key.h"
277+#include "hostfile.h"
278+#include "auth.h"
279+#endif
280+
281 #include "log.h"
282 #include "xmalloc.h"
283 #include "port-linux.h"
284@@ -58,7 +64,7 @@ ssh_selinux_enabled(void)
285
286 /* Return the default security context for the given username */
287 static security_context_t
288-ssh_selinux_getctxbyname(char *pwname)
289+ssh_selinux_getctxbyname(char *pwname, const char *role)
290 {
291 security_context_t sc = NULL;
292 char *sename = NULL, *lvl = NULL;
293@@ -73,9 +79,16 @@ ssh_selinux_getctxbyname(char *pwname)
294 #endif
295
296 #ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
297- r = get_default_context_with_level(sename, lvl, NULL, &sc);
298+ if (role != NULL && role[0])
299+ r = get_default_context_with_rolelevel(sename, role, lvl, NULL,
300+ &sc);
301+ else
302+ r = get_default_context_with_level(sename, lvl, NULL, &sc);
303 #else
304- r = get_default_context(sename, NULL, &sc);
305+ if (role != NULL && role[0])
306+ r = get_default_context_with_role(sename, role, NULL, &sc);
307+ else
308+ r = get_default_context(sename, NULL, &sc);
309 #endif
310
311 if (r != 0) {
312@@ -105,7 +118,7 @@ ssh_selinux_getctxbyname(char *pwname)
313
314 /* Set the execution context to the default for the specified user */
315 void
316-ssh_selinux_setup_exec_context(char *pwname)
317+ssh_selinux_setup_exec_context(char *pwname, const char *role)
318 {
319 security_context_t user_ctx = NULL;
320
321@@ -114,7 +127,7 @@ ssh_selinux_setup_exec_context(char *pwname)
322
323 debug3("%s: setting execution context", __func__);
324
325- user_ctx = ssh_selinux_getctxbyname(pwname);
326+ user_ctx = ssh_selinux_getctxbyname(pwname, role);
327 if (setexeccon(user_ctx) != 0) {
328 switch (security_getenforce()) {
329 case -1:
330@@ -136,7 +149,7 @@ ssh_selinux_setup_exec_context(char *pwname)
331
332 /* Set the TTY context for the specified user */
333 void
334-ssh_selinux_setup_pty(char *pwname, const char *tty)
335+ssh_selinux_setup_pty(char *pwname, const char *tty, const char *role)
336 {
337 security_context_t new_tty_ctx = NULL;
338 security_context_t user_ctx = NULL;
339@@ -147,7 +160,7 @@ ssh_selinux_setup_pty(char *pwname, const char *tty)
340
341 debug3("%s: setting TTY context on %s", __func__, tty);
342
343- user_ctx = ssh_selinux_getctxbyname(pwname);
344+ user_ctx = ssh_selinux_getctxbyname(pwname, role);
345
346 /* XXX: should these calls fatal() upon failure in enforcing mode? */
347
348diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h
349index e3d1004..80ce13a 100644
350--- a/openbsd-compat/port-linux.h
351+++ b/openbsd-compat/port-linux.h
352@@ -21,8 +21,8 @@
353
354 #ifdef WITH_SELINUX
355 int ssh_selinux_enabled(void);
356-void ssh_selinux_setup_pty(char *, const char *);
357-void ssh_selinux_setup_exec_context(char *);
358+void ssh_selinux_setup_pty(char *, const char *, const char *);
359+void ssh_selinux_setup_exec_context(char *, const char *);
360 void ssh_selinux_change_context(const char *);
361 void ssh_selinux_setfscreatecon(const char *);
362 #endif
363diff --git a/platform.c b/platform.c
364index 3262b24..a962f15 100644
365--- a/platform.c
366+++ b/platform.c
367@@ -134,7 +134,7 @@ platform_setusercontext(struct passwd *pw)
368 * called if sshd is running as root.
369 */
370 void
371-platform_setusercontext_post_groups(struct passwd *pw)
372+platform_setusercontext_post_groups(struct passwd *pw, const char *role)
373 {
374 #if !defined(HAVE_LOGIN_CAP) && defined(USE_PAM)
375 /*
376@@ -181,7 +181,7 @@ platform_setusercontext_post_groups(struct passwd *pw)
377 }
378 #endif /* HAVE_SETPCRED */
379 #ifdef WITH_SELINUX
380- ssh_selinux_setup_exec_context(pw->pw_name);
381+ ssh_selinux_setup_exec_context(pw->pw_name, role);
382 #endif
383 }
384
385diff --git a/platform.h b/platform.h
386index 19f6bfd..3188a3d 100644
387--- a/platform.h
388+++ b/platform.h
389@@ -26,7 +26,7 @@ void platform_post_fork_parent(pid_t child_pid);
390 void platform_post_fork_child(void);
391 int platform_privileged_uidswap(void);
392 void platform_setusercontext(struct passwd *);
393-void platform_setusercontext_post_groups(struct passwd *);
394+void platform_setusercontext_post_groups(struct passwd *, const char *);
395 char *platform_get_krb5_client(const char *);
396 char *platform_krb5_get_principal_name(const char *);
397 int platform_sys_dir_uid(uid_t);
398diff --git a/session.c b/session.c
399index d4b57bd..b4d74d9 100644
400--- a/session.c
401+++ b/session.c
402@@ -1474,7 +1474,7 @@ safely_chroot(const char *path, uid_t uid)
403
404 /* Set login name, uid, gid, and groups. */
405 void
406-do_setusercontext(struct passwd *pw)
407+do_setusercontext(struct passwd *pw, const char *role)
408 {
409 char *chroot_path, *tmp;
410
411@@ -1502,7 +1502,7 @@ do_setusercontext(struct passwd *pw)
412 endgrent();
413 #endif
414
415- platform_setusercontext_post_groups(pw);
416+ platform_setusercontext_post_groups(pw, role);
417
418 if (options.chroot_directory != NULL &&
419 strcasecmp(options.chroot_directory, "none") != 0) {
420@@ -1646,7 +1646,7 @@ do_child(Session *s, const char *command)
421
422 /* Force a password change */
423 if (s->authctxt->force_pwchange) {
424- do_setusercontext(pw);
425+ do_setusercontext(pw, s->authctxt->role);
426 child_close_fds();
427 do_pwchange(s);
428 exit(1);
429@@ -1673,7 +1673,7 @@ do_child(Session *s, const char *command)
430 /* When PAM is enabled we rely on it to do the nologin check */
431 if (!options.use_pam)
432 do_nologin(pw);
433- do_setusercontext(pw);
434+ do_setusercontext(pw, s->authctxt->role);
435 /*
436 * PAM session modules in do_setusercontext may have
437 * generated messages, so if this in an interactive
438@@ -2084,7 +2084,7 @@ session_pty_req(Session *s)
439 tty_parse_modes(s->ttyfd, &n_bytes);
440
441 if (!use_privsep)
442- pty_setowner(s->pw, s->tty);
443+ pty_setowner(s->pw, s->tty, s->authctxt->role);
444
445 /* Set window size from the packet. */
446 pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
447diff --git a/session.h b/session.h
448index cbb8e3a..cb4f196 100644
449--- a/session.h
450+++ b/session.h
451@@ -76,7 +76,7 @@ void session_pty_cleanup2(Session *);
452 Session *session_new(void);
453 Session *session_by_tty(char *);
454 void session_close(Session *);
455-void do_setusercontext(struct passwd *);
456+void do_setusercontext(struct passwd *, const char *);
457 void child_set_env(char ***envp, u_int *envsizep, const char *name,
458 const char *value);
459
460diff --git a/sshd.c b/sshd.c
461index 4eddeb8..e5c9835 100644
462--- a/sshd.c
463+++ b/sshd.c
464@@ -753,7 +753,7 @@ privsep_postauth(Authctxt *authctxt)
465 RAND_seed(rnd, sizeof(rnd));
466
467 /* Drop privileges */
468- do_setusercontext(authctxt->pw);
469+ do_setusercontext(authctxt->pw, authctxt->role);
470
471 skip:
472 /* It is safe now to apply the key state */
473diff --git a/sshpty.c b/sshpty.c
474index bbbc0fe..8cc26a2 100644
475--- a/sshpty.c
476+++ b/sshpty.c
477@@ -200,7 +200,7 @@ pty_change_window_size(int ptyfd, u_int row, u_int col,
478 }
479
480 void
481-pty_setowner(struct passwd *pw, const char *tty)
482+pty_setowner(struct passwd *pw, const char *tty, const char *role)
483 {
484 struct group *grp;
485 gid_t gid;
486@@ -227,7 +227,7 @@ pty_setowner(struct passwd *pw, const char *tty)
487 strerror(errno));
488
489 #ifdef WITH_SELINUX
490- ssh_selinux_setup_pty(pw->pw_name, tty);
491+ ssh_selinux_setup_pty(pw->pw_name, tty, role);
492 #endif
493
494 if (st.st_uid != pw->pw_uid || st.st_gid != gid) {
495diff --git a/sshpty.h b/sshpty.h
496index cfa3224..edf2436 100644
497--- a/sshpty.h
498+++ b/sshpty.h
499@@ -24,4 +24,4 @@ int pty_allocate(int *, int *, char *, size_t);
500 void pty_release(const char *);
501 void pty_make_controlling_tty(int *, const char *);
502 void pty_change_window_size(int, u_int, u_int, u_int, u_int);
503-void pty_setowner(struct passwd *, const char *);
504+void pty_setowner(struct passwd *, const char *, const char *);
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 000000000..ced2bbd1e
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1,28 @@
1gssapi.patch
2selinux-role.patch
3ssh-vulnkey.patch
4ssh1-keepalive.patch
5keepalive-extensions.patch
6syslog-level-silent.patch
7quieter-signals.patch
8helpful-wait-terminate.patch
9consolekit.patch
10user-group-modes.patch
11scp-quoting.patch
12shell-path.patch
13dnssec-sshfp.patch
14auth-log-verbosity.patch
15mention-ssh-keygen-on-keychange.patch
16package-versioning.patch
17debian-banner.patch
18authorized-keys-man-symlink.patch
19lintian-symlink-pickiness.patch
20openbsd-docs.patch
21ssh-argv0.patch
22doc-hash-tab-completion.patch
23doc-upstart.patch
24ssh-agent-setgid.patch
25no-openssl-version-check.patch
26gnome-ssh-askpass2-icon.patch
27sigstop.patch
28debian-config.patch
diff --git a/debian/patches/shell-path.patch b/debian/patches/shell-path.patch
new file mode 100644
index 000000000..8f09b936a
--- /dev/null
+++ b/debian/patches/shell-path.patch
@@ -0,0 +1,39 @@
1From b5f3be892e6d7150e7885133228fd03af69a11bc 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 483eb85..91fd59a 100644
20--- a/sshconnect.c
21+++ b/sshconnect.c
22@@ -151,7 +151,7 @@ ssh_proxy_connect(const char *host, u_short port, const char *proxy_command)
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@@ -1298,7 +1298,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/sigstop.patch b/debian/patches/sigstop.patch
new file mode 100644
index 000000000..febcbc86a
--- /dev/null
+++ b/debian/patches/sigstop.patch
@@ -0,0 +1,28 @@
1From 6fba9b85d3529fd3e1ca03dff3e457f04b3e39dd Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:10:17 +0000
4Subject: Support synchronisation with service supervisor using SIGSTOP
5
6Forwarded: no
7Last-Update: 2013-09-14
8
9Patch-Name: sigstop.patch
10---
11 sshd.c | 4 ++++
12 1 file changed, 4 insertions(+)
13
14diff --git a/sshd.c b/sshd.c
15index 6b988fe..72e9eaf 100644
16--- a/sshd.c
17+++ b/sshd.c
18@@ -1914,6 +1914,10 @@ main(int ac, char **av)
19 }
20 }
21
22+ if (getenv("SSH_SIGSTOP"))
23+ /* Tell service supervisor that we are ready. */
24+ kill(getpid(), SIGSTOP);
25+
26 /* Accept a connection and return in a forked child */
27 server_accept_loop(&sock_in, &sock_out,
28 &newsock, config_s);
diff --git a/debian/patches/ssh-agent-setgid.patch b/debian/patches/ssh-agent-setgid.patch
new file mode 100644
index 000000000..3760e8c14
--- /dev/null
+++ b/debian/patches/ssh-agent-setgid.patch
@@ -0,0 +1,40 @@
1From 92a81c0caf44c15d3a07cf1f36470ca05c11ff1e 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 bb801c9..d370531 100644
17--- a/ssh-agent.1
18+++ b/ssh-agent.1
19@@ -182,6 +182,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 ~/.ssh/identity
diff --git a/debian/patches/ssh-argv0.patch b/debian/patches/ssh-argv0.patch
new file mode 100644
index 000000000..b15f251ef
--- /dev/null
+++ b/debian/patches/ssh-argv0.patch
@@ -0,0 +1,31 @@
1From b339802cbe8c304541273029a1c9c3c639725643 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 b3c3924..c0cc12f 100644
22--- a/ssh.1
23+++ b/ssh.1
24@@ -1451,6 +1451,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 ssh-vulnkey 1 ,
diff --git a/debian/patches/ssh-vulnkey.patch b/debian/patches/ssh-vulnkey.patch
new file mode 100644
index 000000000..ae262083d
--- /dev/null
+++ b/debian/patches/ssh-vulnkey.patch
@@ -0,0 +1,1419 @@
1From 8909ff0e3cd07d1b042d1be1c8b8828dbf6c9a83 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@ubuntu.com>
3Date: Sun, 9 Feb 2014 16:09:50 +0000
4Subject: Reject vulnerable keys to mitigate Debian OpenSSL flaw
5
6In 2008, Debian (and derived distributions such as Ubuntu) shipped an
7OpenSSL package with a flawed random number generator, causing OpenSSH to
8generate only a very limited set of keys which were subject to private half
9precomputation. To mitigate this, this patch checks key authentications
10against a blacklist of known-vulnerable keys, and adds a new ssh-vulnkey
11program which can be used to explicitly check keys against that blacklist.
12See CVE-2008-0166.
13
14Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1469
15Last-Update: 2013-09-14
16
17Patch-Name: ssh-vulnkey.patch
18---
19 Makefile.in | 17 ++-
20 auth-rh-rsa.c | 2 +-
21 auth-rsa.c | 2 +-
22 auth.c | 27 +++-
23 auth.h | 2 +-
24 auth2-hostbased.c | 2 +-
25 auth2-pubkey.c | 5 +-
26 authfile.c | 136 +++++++++++++++++++
27 authfile.h | 2 +
28 pathnames.h | 7 +
29 readconf.c | 9 ++
30 readconf.h | 1 +
31 servconf.c | 11 +-
32 servconf.h | 1 +
33 ssh-add.1 | 5 +
34 ssh-add.c | 10 +-
35 ssh-keygen.1 | 1 +
36 ssh-vulnkey.1 | 242 ++++++++++++++++++++++++++++++++++
37 ssh-vulnkey.c | 386 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
38 ssh.1 | 1 +
39 ssh.c | 18 ++-
40 ssh_config.5 | 17 +++
41 sshconnect2.c | 4 +-
42 sshd.8 | 1 +
43 sshd.c | 5 +
44 sshd_config.5 | 14 ++
45 26 files changed, 913 insertions(+), 15 deletions(-)
46 create mode 100644 ssh-vulnkey.1
47 create mode 100644 ssh-vulnkey.c
48
49diff --git a/Makefile.in b/Makefile.in
50index f979926..b8f5099 100644
51--- a/Makefile.in
52+++ b/Makefile.in
53@@ -26,6 +26,7 @@ ASKPASS_PROGRAM=$(libexecdir)/ssh-askpass
54 SFTP_SERVER=$(libexecdir)/sftp-server
55 SSH_KEYSIGN=$(libexecdir)/ssh-keysign
56 SSH_PKCS11_HELPER=$(libexecdir)/ssh-pkcs11-helper
57+SSH_DATADIR=$(datadir)/ssh
58 PRIVSEP_PATH=@PRIVSEP_PATH@
59 SSH_PRIVSEP_USER=@SSH_PRIVSEP_USER@
60 STRIP_OPT=@STRIP_OPT@
61@@ -37,7 +38,8 @@ PATHS= -DSSHDIR=\"$(sysconfdir)\" \
62 -D_PATH_SSH_KEY_SIGN=\"$(SSH_KEYSIGN)\" \
63 -D_PATH_SSH_PKCS11_HELPER=\"$(SSH_PKCS11_HELPER)\" \
64 -D_PATH_SSH_PIDDIR=\"$(piddir)\" \
65- -D_PATH_PRIVSEP_CHROOT_DIR=\"$(PRIVSEP_PATH)\"
66+ -D_PATH_PRIVSEP_CHROOT_DIR=\"$(PRIVSEP_PATH)\" \
67+ -D_PATH_SSH_DATADIR=\"$(SSH_DATADIR)\"
68
69 CC=@CC@
70 LD=@LD@
71@@ -61,7 +63,7 @@ LDFLAGS=-L. -Lopenbsd-compat/ @LDFLAGS@
72 EXEEXT=@EXEEXT@
73 MANFMT=@MANFMT@
74
75-TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT)
76+TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-vulnkey$(EXEEXT)
77
78 LIBSSH_OBJS=authfd.o authfile.o bufaux.o bufbn.o buffer.o \
79 canohost.o channels.o cipher.o cipher-aes.o \
80@@ -96,8 +98,8 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \
81 sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \
82 sandbox-seccomp-filter.o
83
84-MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out
85-MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5
86+MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out ssh-vulnkey.1.out sshd_config.5.out ssh_config.5.out
87+MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 ssh-vulnkey.1 sshd_config.5 ssh_config.5
88 MANTYPE = @MANTYPE@
89
90 CONFIGFILES=sshd_config.out ssh_config.out moduli.out
91@@ -176,6 +178,9 @@ sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o s
92 sftp$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-client.o sftp-common.o sftp-glob.o progressmeter.o
93 $(LD) -o $@ progressmeter.o sftp.o sftp-client.o sftp-common.o sftp-glob.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) $(LIBEDIT)
94
95+ssh-vulnkey$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-vulnkey.o
96+ $(LD) -o $@ ssh-vulnkey.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
97+
98 # test driver for the loginrec code - not built by default
99 logintest: logintest.o $(LIBCOMPAT) libssh.a loginrec.o
100 $(LD) -o $@ logintest.o $(LDFLAGS) loginrec.o -lopenbsd-compat -lssh $(LIBS)
101@@ -272,6 +277,7 @@ install-files:
102 $(INSTALL) -m 0755 $(STRIP_OPT) ssh-pkcs11-helper$(EXEEXT) $(DESTDIR)$(SSH_PKCS11_HELPER)$(EXEEXT)
103 $(INSTALL) -m 0755 $(STRIP_OPT) sftp$(EXEEXT) $(DESTDIR)$(bindir)/sftp$(EXEEXT)
104 $(INSTALL) -m 0755 $(STRIP_OPT) sftp-server$(EXEEXT) $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
105+ $(INSTALL) -m 0755 $(STRIP_OPT) ssh-vulnkey$(EXEEXT) $(DESTDIR)$(bindir)/ssh-vulnkey$(EXEEXT)
106 $(INSTALL) -m 644 ssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1
107 $(INSTALL) -m 644 scp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/scp.1
108 $(INSTALL) -m 644 ssh-add.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-add.1
109@@ -286,6 +292,7 @@ install-files:
110 $(INSTALL) -m 644 sftp-server.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8
111 $(INSTALL) -m 644 ssh-keysign.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8
112 $(INSTALL) -m 644 ssh-pkcs11-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8
113+ $(INSTALL) -m 644 ssh-vulnkey.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-vulnkey.1
114 -rm -f $(DESTDIR)$(bindir)/slogin
115 ln -s ./ssh$(EXEEXT) $(DESTDIR)$(bindir)/slogin
116 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1
117@@ -367,6 +374,7 @@ uninstall:
118 -rm -f $(DESTDIR)$(bindir)/ssh-agent$(EXEEXT)
119 -rm -f $(DESTDIR)$(bindir)/ssh-keygen$(EXEEXT)
120 -rm -f $(DESTDIR)$(bindir)/ssh-keyscan$(EXEEXT)
121+ -rm -f $(DESTDIR)$(bindir)/ssh-vulnkey$(EXEEXT)
122 -rm -f $(DESTDIR)$(bindir)/sftp$(EXEEXT)
123 -rm -f $(DESTDIR)$(sbindir)/sshd$(EXEEXT)
124 -rm -r $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
125@@ -379,6 +387,7 @@ uninstall:
126 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keygen.1
127 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1
128 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1
129+ -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-vulnkey.1
130 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8
131 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8
132 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8
133diff --git a/auth-rh-rsa.c b/auth-rh-rsa.c
134index b21a0f4..891ec32 100644
135--- a/auth-rh-rsa.c
136+++ b/auth-rh-rsa.c
137@@ -44,7 +44,7 @@ auth_rhosts_rsa_key_allowed(struct passwd *pw, char *cuser, char *chost,
138 {
139 HostStatus host_status;
140
141- if (auth_key_is_revoked(client_host_key))
142+ if (auth_key_is_revoked(client_host_key, 0))
143 return 0;
144
145 /* Check if we would accept it using rhosts authentication. */
146diff --git a/auth-rsa.c b/auth-rsa.c
147index 545aa49..6ed152c 100644
148--- a/auth-rsa.c
149+++ b/auth-rsa.c
150@@ -237,7 +237,7 @@ rsa_key_allowed_in_file(struct passwd *pw, char *file,
151 free(fp);
152
153 /* Never accept a revoked key */
154- if (auth_key_is_revoked(key))
155+ if (auth_key_is_revoked(key, 0))
156 break;
157
158 /* We have found the desired key. */
159diff --git a/auth.c b/auth.c
160index 9a36f1d..6662e9a 100644
161--- a/auth.c
162+++ b/auth.c
163@@ -59,6 +59,7 @@
164 #include "servconf.h"
165 #include "key.h"
166 #include "hostfile.h"
167+#include "authfile.h"
168 #include "auth.h"
169 #include "auth-options.h"
170 #include "canohost.h"
171@@ -657,10 +658,34 @@ getpwnamallow(const char *user)
172
173 /* Returns 1 if key is revoked by revoked_keys_file, 0 otherwise */
174 int
175-auth_key_is_revoked(Key *key)
176+auth_key_is_revoked(Key *key, int hostkey)
177 {
178 char *key_fp;
179
180+ if (blacklisted_key(key, &key_fp) == 1) {
181+ if (options.permit_blacklisted_keys) {
182+ if (hostkey)
183+ error("Host key %s blacklisted (see "
184+ "ssh-vulnkey(1)); continuing anyway",
185+ key_fp);
186+ else
187+ logit("Public key %s from %s blacklisted (see "
188+ "ssh-vulnkey(1)); continuing anyway",
189+ key_fp, get_remote_ipaddr());
190+ free(key_fp);
191+ } else {
192+ if (hostkey)
193+ error("Host key %s blacklisted (see "
194+ "ssh-vulnkey(1))", key_fp);
195+ else
196+ logit("Public key %s from %s blacklisted (see "
197+ "ssh-vulnkey(1))",
198+ key_fp, get_remote_ipaddr());
199+ free(key_fp);
200+ return 1;
201+ }
202+ }
203+
204 if (options.revoked_keys_file == NULL)
205 return 0;
206 switch (ssh_krl_file_contains_key(options.revoked_keys_file, key)) {
207diff --git a/auth.h b/auth.h
208index 5b6824f..ec95460 100644
209--- a/auth.h
210+++ b/auth.h
211@@ -191,7 +191,7 @@ char *authorized_principals_file(struct passwd *);
212
213 FILE *auth_openkeyfile(const char *, struct passwd *, int);
214 FILE *auth_openprincipals(const char *, struct passwd *, int);
215-int auth_key_is_revoked(Key *);
216+int auth_key_is_revoked(Key *, int);
217
218 HostStatus
219 check_key_in_hostfiles(struct passwd *, Key *, const char *,
220diff --git a/auth2-hostbased.c b/auth2-hostbased.c
221index a344dcc..3a17f1b 100644
222--- a/auth2-hostbased.c
223+++ b/auth2-hostbased.c
224@@ -150,7 +150,7 @@ hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost,
225 int len;
226 char *fp;
227
228- if (auth_key_is_revoked(key))
229+ if (auth_key_is_revoked(key, 0))
230 return 0;
231
232 resolvedname = get_canonical_hostname(options.use_dns);
233diff --git a/auth2-pubkey.c b/auth2-pubkey.c
234index 2b3ecb1..12eb8a6 100644
235--- a/auth2-pubkey.c
236+++ b/auth2-pubkey.c
237@@ -647,9 +647,10 @@ user_key_allowed(struct passwd *pw, Key *key)
238 u_int success, i;
239 char *file;
240
241- if (auth_key_is_revoked(key))
242+ if (auth_key_is_revoked(key, 0))
243 return 0;
244- if (key_is_cert(key) && auth_key_is_revoked(key->cert->signature_key))
245+ if (key_is_cert(key) &&
246+ auth_key_is_revoked(key->cert->signature_key, 0))
247 return 0;
248
249 success = user_cert_trusted_ca(pw, key);
250diff --git a/authfile.c b/authfile.c
251index 63ae16b..9833591 100644
252--- a/authfile.c
253+++ b/authfile.c
254@@ -68,6 +68,7 @@
255 #include "rsa.h"
256 #include "misc.h"
257 #include "atomicio.h"
258+#include "pathnames.h"
259
260 #define MAX_KEY_FILE_SIZE (1024 * 1024)
261
262@@ -944,3 +945,138 @@ key_in_file(Key *key, const char *filename, int strict_type)
263 return ret;
264 }
265
266+/* Scan a blacklist of known-vulnerable keys in blacklist_file. */
267+static int
268+blacklisted_key_in_file(Key *key, const char *blacklist_file, char **fp)
269+{
270+ int fd = -1;
271+ char *dgst_hex = NULL;
272+ char *dgst_packed = NULL, *p;
273+ int i;
274+ size_t line_len;
275+ struct stat st;
276+ char buf[256];
277+ off_t start, lower, upper;
278+ int ret = 0;
279+
280+ debug("Checking blacklist file %s", blacklist_file);
281+ fd = open(blacklist_file, O_RDONLY);
282+ if (fd < 0) {
283+ ret = -1;
284+ goto out;
285+ }
286+
287+ dgst_hex = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
288+ /* Remove all colons */
289+ dgst_packed = xcalloc(1, strlen(dgst_hex) + 1);
290+ for (i = 0, p = dgst_packed; dgst_hex[i]; i++)
291+ if (dgst_hex[i] != ':')
292+ *p++ = dgst_hex[i];
293+ /* Only compare least-significant 80 bits (to keep the blacklist
294+ * size down)
295+ */
296+ line_len = strlen(dgst_packed + 12);
297+ if (line_len > 32)
298+ goto out;
299+
300+ /* Skip leading comments */
301+ start = 0;
302+ for (;;) {
303+ ssize_t r;
304+ char *newline;
305+
306+ r = atomicio(read, fd, buf, sizeof(buf));
307+ if (r <= 0)
308+ goto out;
309+ if (buf[0] != '#')
310+ break;
311+
312+ newline = memchr(buf, '\n', sizeof(buf));
313+ if (!newline)
314+ goto out;
315+ start += newline + 1 - buf;
316+ if (lseek(fd, start, SEEK_SET) < 0)
317+ goto out;
318+ }
319+
320+ /* Initialise binary search record numbers */
321+ if (fstat(fd, &st) < 0)
322+ goto out;
323+ lower = 0;
324+ upper = (st.st_size - start) / (line_len + 1);
325+
326+ while (lower != upper) {
327+ off_t cur;
328+ int cmp;
329+
330+ cur = lower + (upper - lower) / 2;
331+
332+ /* Read this line and compare to digest; this is
333+ * overflow-safe since cur < max(off_t) / (line_len + 1) */
334+ if (lseek(fd, start + cur * (line_len + 1), SEEK_SET) < 0)
335+ break;
336+ if (atomicio(read, fd, buf, line_len) != line_len)
337+ break;
338+ cmp = memcmp(buf, dgst_packed + 12, line_len);
339+ if (cmp < 0) {
340+ if (cur == lower)
341+ break;
342+ lower = cur;
343+ } else if (cmp > 0) {
344+ if (cur == upper)
345+ break;
346+ upper = cur;
347+ } else {
348+ debug("Found %s in blacklist", dgst_hex);
349+ ret = 1;
350+ break;
351+ }
352+ }
353+
354+out:
355+ free(dgst_packed);
356+ if (ret != 1 && dgst_hex) {
357+ free(dgst_hex);
358+ dgst_hex = NULL;
359+ }
360+ if (fp)
361+ *fp = dgst_hex;
362+ if (fd >= 0)
363+ close(fd);
364+ return ret;
365+}
366+
367+/*
368+ * Scan blacklists of known-vulnerable keys. If a vulnerable key is found,
369+ * its fingerprint is returned in *fp, unless fp is NULL.
370+ */
371+int
372+blacklisted_key(Key *key, char **fp)
373+{
374+ Key *public;
375+ char *blacklist_file;
376+ int ret, ret2;
377+
378+ public = key_demote(key);
379+ if (public->type == KEY_RSA1)
380+ public->type = KEY_RSA;
381+
382+ xasprintf(&blacklist_file, "%s.%s-%u",
383+ _PATH_BLACKLIST, key_type(public), key_size(public));
384+ ret = blacklisted_key_in_file(public, blacklist_file, fp);
385+ free(blacklist_file);
386+ if (ret > 0) {
387+ key_free(public);
388+ return ret;
389+ }
390+
391+ xasprintf(&blacklist_file, "%s.%s-%u",
392+ _PATH_BLACKLIST_CONFIG, key_type(public), key_size(public));
393+ ret2 = blacklisted_key_in_file(public, blacklist_file, fp);
394+ free(blacklist_file);
395+ if (ret2 > ret)
396+ ret = ret2;
397+
398+ key_free(public);
399+ return ret;
400+}
401diff --git a/authfile.h b/authfile.h
402index 78349be..3f2bdcb 100644
403--- a/authfile.h
404+++ b/authfile.h
405@@ -28,4 +28,6 @@ Key *key_load_private_pem(int, int, const char *, char **);
406 int key_perm_ok(int, const char *);
407 int key_in_file(Key *, const char *, int);
408
409+int blacklisted_key(Key *key, char **fp);
410+
411 #endif
412diff --git a/pathnames.h b/pathnames.h
413index 5027fba..47f7867 100644
414--- a/pathnames.h
415+++ b/pathnames.h
416@@ -18,6 +18,10 @@
417 #define SSHDIR ETCDIR "/ssh"
418 #endif
419
420+#ifndef _PATH_SSH_DATADIR
421+#define _PATH_SSH_DATADIR "/usr/share/ssh"
422+#endif
423+
424 #ifndef _PATH_SSH_PIDDIR
425 #define _PATH_SSH_PIDDIR "/var/run"
426 #endif
427@@ -44,6 +48,9 @@
428 /* Backwards compatibility */
429 #define _PATH_DH_PRIMES SSHDIR "/primes"
430
431+#define _PATH_BLACKLIST _PATH_SSH_DATADIR "/blacklist"
432+#define _PATH_BLACKLIST_CONFIG SSHDIR "/blacklist"
433+
434 #ifndef _PATH_SSH_PROGRAM
435 #define _PATH_SSH_PROGRAM "/usr/bin/ssh"
436 #endif
437diff --git a/readconf.c b/readconf.c
438index 2695fd6..22e5a3a 100644
439--- a/readconf.c
440+++ b/readconf.c
441@@ -128,6 +128,7 @@ typedef enum {
442 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
443 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
444 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
445+ oUseBlacklistedKeys,
446 oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
447 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
448 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
449@@ -161,6 +162,7 @@ static struct {
450 { "passwordauthentication", oPasswordAuthentication },
451 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
452 { "kbdinteractivedevices", oKbdInteractiveDevices },
453+ { "useblacklistedkeys", oUseBlacklistedKeys },
454 { "rsaauthentication", oRSAAuthentication },
455 { "pubkeyauthentication", oPubkeyAuthentication },
456 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
457@@ -523,6 +525,10 @@ parse_flag:
458 intptr = &options->challenge_response_authentication;
459 goto parse_flag;
460
461+ case oUseBlacklistedKeys:
462+ intptr = &options->use_blacklisted_keys;
463+ goto parse_flag;
464+
465 case oGssAuthentication:
466 intptr = &options->gss_authentication;
467 goto parse_flag;
468@@ -1210,6 +1216,7 @@ initialize_options(Options * options)
469 options->kbd_interactive_devices = NULL;
470 options->rhosts_rsa_authentication = -1;
471 options->hostbased_authentication = -1;
472+ options->use_blacklisted_keys = -1;
473 options->batch_mode = -1;
474 options->check_host_ip = -1;
475 options->strict_host_key_checking = -1;
476@@ -1320,6 +1327,8 @@ fill_default_options(Options * options)
477 options->rhosts_rsa_authentication = 0;
478 if (options->hostbased_authentication == -1)
479 options->hostbased_authentication = 0;
480+ if (options->use_blacklisted_keys == -1)
481+ options->use_blacklisted_keys = 0;
482 if (options->batch_mode == -1)
483 options->batch_mode = 0;
484 if (options->check_host_ip == -1)
485diff --git a/readconf.h b/readconf.h
486index 675b35d..a508151 100644
487--- a/readconf.h
488+++ b/readconf.h
489@@ -59,6 +59,7 @@ typedef struct {
490 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
491 char *kbd_interactive_devices; /* Keyboard-interactive auth devices. */
492 int zero_knowledge_password_authentication; /* Try jpake */
493+ int use_blacklisted_keys; /* If true, send */
494 int batch_mode; /* Batch mode: do not ask for passwords. */
495 int check_host_ip; /* Also keep track of keys for IP address */
496 int strict_host_key_checking; /* Strict host key checking. */
497diff --git a/servconf.c b/servconf.c
498index c938ae3..9155a8b 100644
499--- a/servconf.c
500+++ b/servconf.c
501@@ -114,6 +114,7 @@ initialize_server_options(ServerOptions *options)
502 options->password_authentication = -1;
503 options->kbd_interactive_authentication = -1;
504 options->challenge_response_authentication = -1;
505+ options->permit_blacklisted_keys = -1;
506 options->permit_empty_passwd = -1;
507 options->permit_user_env = -1;
508 options->use_login = -1;
509@@ -257,6 +258,8 @@ fill_default_server_options(ServerOptions *options)
510 options->kbd_interactive_authentication = 0;
511 if (options->challenge_response_authentication == -1)
512 options->challenge_response_authentication = 1;
513+ if (options->permit_blacklisted_keys == -1)
514+ options->permit_blacklisted_keys = 0;
515 if (options->permit_empty_passwd == -1)
516 options->permit_empty_passwd = 0;
517 if (options->permit_user_env == -1)
518@@ -338,7 +341,7 @@ typedef enum {
519 sListenAddress, sAddressFamily,
520 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
521 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
522- sStrictModes, sEmptyPasswd, sTCPKeepAlive,
523+ sStrictModes, sPermitBlacklistedKeys, sEmptyPasswd, sTCPKeepAlive,
524 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
525 sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
526 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
527@@ -451,6 +454,7 @@ static struct {
528 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
529 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
530 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
531+ { "permitblacklistedkeys", sPermitBlacklistedKeys, SSHCFG_GLOBAL },
532 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
533 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
534 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
535@@ -1158,6 +1162,10 @@ process_server_config_line(ServerOptions *options, char *line,
536 intptr = &options->tcp_keep_alive;
537 goto parse_flag;
538
539+ case sPermitBlacklistedKeys:
540+ intptr = &options->permit_blacklisted_keys;
541+ goto parse_flag;
542+
543 case sEmptyPasswd:
544 intptr = &options->permit_empty_passwd;
545 goto parse_flag;
546@@ -2036,6 +2044,7 @@ dump_config(ServerOptions *o)
547 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
548 dump_cfg_fmtint(sStrictModes, o->strict_modes);
549 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
550+ dump_cfg_fmtint(sPermitBlacklistedKeys, o->permit_blacklisted_keys);
551 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
552 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
553 dump_cfg_fmtint(sUseLogin, o->use_login);
554diff --git a/servconf.h b/servconf.h
555index ab6e346..f655c5b 100644
556--- a/servconf.h
557+++ b/servconf.h
558@@ -121,6 +121,7 @@ typedef struct {
559 int challenge_response_authentication;
560 int zero_knowledge_password_authentication;
561 /* If true, permit jpake auth */
562+ int permit_blacklisted_keys; /* If true, permit */
563 int permit_empty_passwd; /* If false, do not permit empty
564 * passwords. */
565 int permit_user_env; /* If true, read ~/.ssh/environment */
566diff --git a/ssh-add.1 b/ssh-add.1
567index 44846b6..d394b26 100644
568--- a/ssh-add.1
569+++ b/ssh-add.1
570@@ -81,6 +81,10 @@ environment variable must contain the name of its socket for
571 .Nm
572 to work.
573 .Pp
574+Any keys recorded in the blacklist of known-compromised keys (see
575+.Xr ssh-vulnkey 1 )
576+will be refused.
577+.Pp
578 The options are as follows:
579 .Bl -tag -width Ds
580 .It Fl c
581@@ -186,6 +190,7 @@ is unable to contact the authentication agent.
582 .Xr ssh 1 ,
583 .Xr ssh-agent 1 ,
584 .Xr ssh-keygen 1 ,
585+.Xr ssh-vulnkey 1 ,
586 .Xr sshd 8
587 .Sh AUTHORS
588 OpenSSH is a derivative of the original and free
589diff --git a/ssh-add.c b/ssh-add.c
590index 5e8166f..b309582 100644
591--- a/ssh-add.c
592+++ b/ssh-add.c
593@@ -167,7 +167,7 @@ static int
594 add_file(AuthenticationConnection *ac, const char *filename, int key_only)
595 {
596 Key *private, *cert;
597- char *comment = NULL;
598+ char *comment = NULL, *fp;
599 char msg[1024], *certpath = NULL;
600 int fd, perms_ok, ret = -1;
601 Buffer keyblob;
602@@ -243,6 +243,14 @@ add_file(AuthenticationConnection *ac, const char *filename, int key_only)
603 } else {
604 fprintf(stderr, "Could not add identity: %s\n", filename);
605 }
606+ if (blacklisted_key(private, &fp) == 1) {
607+ fprintf(stderr, "Public key %s blacklisted (see "
608+ "ssh-vulnkey(1)); refusing to add it\n", fp);
609+ free(fp);
610+ key_free(private);
611+ free(comment);
612+ return -1;
613+ }
614
615 /* Skip trying to load the cert if requested */
616 if (key_only)
617diff --git a/ssh-keygen.1 b/ssh-keygen.1
618index 0d55854..144be7d 100644
619--- a/ssh-keygen.1
620+++ b/ssh-keygen.1
621@@ -809,6 +809,7 @@ The file format is described in
622 .Xr ssh 1 ,
623 .Xr ssh-add 1 ,
624 .Xr ssh-agent 1 ,
625+.Xr ssh-vulnkey 1 ,
626 .Xr moduli 5 ,
627 .Xr sshd 8
628 .Rs
629diff --git a/ssh-vulnkey.1 b/ssh-vulnkey.1
630new file mode 100644
631index 0000000..bcb9d31
632--- /dev/null
633+++ b/ssh-vulnkey.1
634@@ -0,0 +1,242 @@
635+.\" Copyright (c) 2008 Canonical Ltd. All rights reserved.
636+.\"
637+.\" Redistribution and use in source and binary forms, with or without
638+.\" modification, are permitted provided that the following conditions
639+.\" are met:
640+.\" 1. Redistributions of source code must retain the above copyright
641+.\" notice, this list of conditions and the following disclaimer.
642+.\" 2. Redistributions in binary form must reproduce the above copyright
643+.\" notice, this list of conditions and the following disclaimer in the
644+.\" documentation and/or other materials provided with the distribution.
645+.\"
646+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
647+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
648+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
649+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
650+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
651+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
652+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
653+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
654+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
655+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
656+.\"
657+.Dd $Mdocdate: May 12 2008 $
658+.Dt SSH-VULNKEY 1
659+.Os
660+.Sh NAME
661+.Nm ssh-vulnkey
662+.Nd check blacklist of compromised keys
663+.Sh SYNOPSIS
664+.Nm
665+.Op Fl q | Fl v
666+.Ar file ...
667+.Nm
668+.Fl a
669+.Sh DESCRIPTION
670+.Nm
671+checks a key against a blacklist of compromised keys.
672+.Pp
673+A substantial number of keys are known to have been generated using a broken
674+version of OpenSSL distributed by Debian which failed to seed its random
675+number generator correctly.
676+Keys generated using these OpenSSL versions should be assumed to be
677+compromised.
678+This tool may be useful in checking for such keys.
679+.Pp
680+Keys that are compromised cannot be repaired; replacements must be generated
681+using
682+.Xr ssh-keygen 1 .
683+Make sure to update
684+.Pa authorized_keys
685+files on all systems where compromised keys were permitted to authenticate.
686+.Pp
687+The argument list will be interpreted as a list of paths to public key files
688+or
689+.Pa authorized_keys
690+files.
691+If no suitable file is found at a given path,
692+.Nm
693+will append
694+.Pa .pub
695+and retry, in case it was given a private key file.
696+If no files are given as arguments,
697+.Nm
698+will check
699+.Pa ~/.ssh/id_rsa ,
700+.Pa ~/.ssh/id_dsa ,
701+.Pa ~/.ssh/identity ,
702+.Pa ~/.ssh/authorized_keys
703+and
704+.Pa ~/.ssh/authorized_keys2 ,
705+as well as the system's host keys if readable.
706+.Pp
707+If
708+.Dq -
709+is given as an argument,
710+.Nm
711+will read from standard input.
712+This can be used to process output from
713+.Xr ssh-keyscan 1 ,
714+for example:
715+.Pp
716+.Dl $ ssh-keyscan -t rsa remote.example.org | ssh-vulnkey -
717+.Pp
718+Unless the
719+.Cm PermitBlacklistedKeys
720+option is used,
721+.Xr sshd 8
722+will reject attempts to authenticate with keys in the compromised list.
723+.Pp
724+The output from
725+.Nm
726+looks like this:
727+.Pp
728+.Bd -literal -offset indent
729+/etc/ssh/ssh_host_key:1: COMPROMISED: RSA1 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx root@host
730+/home/user/.ssh/id_dsa:1: Not blacklisted: DSA 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx /home/user/.ssh/id_dsa.pub
731+/home/user/.ssh/authorized_keys:3: Unknown (blacklist file not installed): RSA 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx user@host
732+.Ed
733+.Pp
734+Each line is of the following format (any lines beginning with
735+.Dq #
736+should be ignored by scripts):
737+.Pp
738+.Dl Ar filename : Ns Ar line : Ar status : Ar type Ar size Ar fingerprint Ar comment
739+.Pp
740+It is important to distinguish between the possible values of
741+.Ar status :
742+.Pp
743+.Bl -tag -width Ds
744+.It COMPROMISED
745+These keys are listed in a blacklist file, normally because their
746+corresponding private keys are well-known.
747+Replacements must be generated using
748+.Xr ssh-keygen 1 .
749+.It Not blacklisted
750+A blacklist file exists for this key type and size, but this key is not
751+listed in it.
752+Unless there is some particular reason to believe otherwise, this key
753+may be used safely.
754+(Note that DSA keys used with the broken version of OpenSSL distributed
755+by Debian may be compromised in the event that anyone captured a network
756+trace, even if they were generated with a secure version of OpenSSL.)
757+.It Unknown (blacklist file not installed)
758+No blacklist file exists for this key type and size.
759+You should find a suitable published blacklist and install it before
760+deciding whether this key is safe to use.
761+.El
762+.Pp
763+The options are as follows:
764+.Bl -tag -width Ds
765+.It Fl a
766+Check keys of all users on the system.
767+You will typically need to run
768+.Nm
769+as root to use this option.
770+For each user,
771+.Nm
772+will check
773+.Pa ~/.ssh/id_rsa ,
774+.Pa ~/.ssh/id_dsa ,
775+.Pa ~/.ssh/identity ,
776+.Pa ~/.ssh/authorized_keys
777+and
778+.Pa ~/.ssh/authorized_keys2 .
779+It will also check the system's host keys.
780+.It Fl q
781+Quiet mode.
782+Normally,
783+.Nm
784+outputs the fingerprint of each key scanned, with a description of its
785+status.
786+This option suppresses that output.
787+.It Fl v
788+Verbose mode.
789+Normally,
790+.Nm
791+does not output anything for keys that are not listed in their corresponding
792+blacklist file (although it still produces output for keys for which there
793+is no blacklist file, since their status is unknown).
794+This option causes
795+.Nm
796+to produce output for all keys.
797+.El
798+.Sh EXIT STATUS
799+.Nm
800+will exit zero if any of the given keys were in the compromised list,
801+otherwise non-zero.
802+.Sh BLACKLIST FILE FORMAT
803+The blacklist file may start with comments, on lines starting with
804+.Dq # .
805+After these initial comments, it must follow a strict format:
806+.Pp
807+.Bl -bullet -offset indent -compact
808+.It
809+All the lines must be exactly the same length (20 characters followed by a
810+newline) and must be in sorted order.
811+.It
812+Each line must consist of the lower-case hexadecimal MD5 key fingerprint,
813+without colons, and with the first 12 characters removed (that is, the least
814+significant 80 bits of the fingerprint).
815+.El
816+.Pp
817+The key fingerprint may be generated using
818+.Xr ssh-keygen 1 :
819+.Pp
820+.Dl $ ssh-keygen -l -f /path/to/key
821+.Pp
822+This strict format is necessary to allow the blacklist file to be checked
823+quickly, using a binary-search algorithm.
824+.Sh FILES
825+.Bl -tag -width Ds
826+.It Pa ~/.ssh/id_rsa
827+If present, contains the protocol version 2 RSA authentication identity of
828+the user.
829+.It Pa ~/.ssh/id_dsa
830+If present, contains the protocol version 2 DSA authentication identity of
831+the user.
832+.It Pa ~/.ssh/identity
833+If present, contains the protocol version 1 RSA authentication identity of
834+the user.
835+.It Pa ~/.ssh/authorized_keys
836+If present, lists the public keys (RSA/DSA) that can be used for logging in
837+as this user.
838+.It Pa ~/.ssh/authorized_keys2
839+Obsolete name for
840+.Pa ~/.ssh/authorized_keys .
841+This file may still be present on some old systems, but should not be
842+created if it is missing.
843+.It Pa /etc/ssh/ssh_host_rsa_key
844+If present, contains the protocol version 2 RSA identity of the system.
845+.It Pa /etc/ssh/ssh_host_dsa_key
846+If present, contains the protocol version 2 DSA identity of the system.
847+.It Pa /etc/ssh/ssh_host_key
848+If present, contains the protocol version 1 RSA identity of the system.
849+.It Pa /usr/share/ssh/blacklist. Ns Ar TYPE Ns Pa - Ns Ar LENGTH
850+If present, lists the blacklisted keys of type
851+.Ar TYPE
852+.Pf ( Dq RSA
853+or
854+.Dq DSA )
855+and bit length
856+.Ar LENGTH .
857+The format of this file is described above.
858+RSA1 keys are converted to RSA before being checked in the blacklist.
859+Note that the fingerprints of RSA1 keys are computed differently, so you
860+will not be able to find them in the blacklist by hand.
861+.It Pa /etc/ssh/blacklist. Ns Ar TYPE Ns Pa - Ns Ar LENGTH
862+Same as
863+.Pa /usr/share/ssh/blacklist. Ns Ar TYPE Ns Pa - Ns Ar LENGTH ,
864+but may be edited by the system administrator to add new blacklist entries.
865+.El
866+.Sh SEE ALSO
867+.Xr ssh-keygen 1 ,
868+.Xr sshd 8
869+.Sh AUTHORS
870+.An -nosplit
871+.An Colin Watson Aq cjwatson@ubuntu.com
872+.Pp
873+Florian Weimer suggested the option to check keys of all users, and the idea
874+of processing
875+.Xr ssh-keyscan 1
876+output.
877diff --git a/ssh-vulnkey.c b/ssh-vulnkey.c
878new file mode 100644
879index 0000000..ca1a5be
880--- /dev/null
881+++ b/ssh-vulnkey.c
882@@ -0,0 +1,386 @@
883+/*
884+ * Copyright (c) 2008 Canonical Ltd. All rights reserved.
885+ *
886+ * Redistribution and use in source and binary forms, with or without
887+ * modification, are permitted provided that the following conditions
888+ * are met:
889+ * 1. Redistributions of source code must retain the above copyright
890+ * notice, this list of conditions and the following disclaimer.
891+ * 2. Redistributions in binary form must reproduce the above copyright
892+ * notice, this list of conditions and the following disclaimer in the
893+ * documentation and/or other materials provided with the distribution.
894+ *
895+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
896+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
897+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
898+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
899+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
900+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
901+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
902+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
903+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
904+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
905+ */
906+
907+#include "includes.h"
908+
909+#include <sys/types.h>
910+#include <sys/stat.h>
911+
912+#include <errno.h>
913+#include <string.h>
914+#include <stdio.h>
915+#include <fcntl.h>
916+#include <unistd.h>
917+
918+#include <openssl/evp.h>
919+
920+#include "xmalloc.h"
921+#include "ssh.h"
922+#include "log.h"
923+#include "key.h"
924+#include "authfile.h"
925+#include "pathnames.h"
926+#include "uidswap.h"
927+#include "misc.h"
928+
929+extern char *__progname;
930+
931+/* Default files to check */
932+static char *default_host_files[] = {
933+ _PATH_HOST_RSA_KEY_FILE,
934+ _PATH_HOST_DSA_KEY_FILE,
935+ _PATH_HOST_KEY_FILE,
936+ NULL
937+};
938+static char *default_files[] = {
939+ _PATH_SSH_CLIENT_ID_RSA,
940+ _PATH_SSH_CLIENT_ID_DSA,
941+ _PATH_SSH_CLIENT_IDENTITY,
942+ _PATH_SSH_USER_PERMITTED_KEYS,
943+ _PATH_SSH_USER_PERMITTED_KEYS2,
944+ NULL
945+};
946+
947+static int verbosity = 0;
948+
949+static int some_keys = 0;
950+static int some_unknown = 0;
951+static int some_compromised = 0;
952+
953+static void
954+usage(void)
955+{
956+ fprintf(stderr, "usage: %s [-aqv] [file ...]\n", __progname);
957+ fprintf(stderr, "Options:\n");
958+ fprintf(stderr, " -a Check keys of all users.\n");
959+ fprintf(stderr, " -q Quiet mode.\n");
960+ fprintf(stderr, " -v Verbose mode.\n");
961+ exit(1);
962+}
963+
964+static void
965+describe_key(const char *filename, u_long linenum, const char *msg,
966+ Key *key, const char *comment, int min_verbosity)
967+{
968+ char *fp;
969+
970+ fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
971+ if (verbosity >= min_verbosity) {
972+ if (strchr(filename, ':'))
973+ printf("\"%s\"", filename);
974+ else
975+ printf("%s", filename);
976+ printf(":%lu: %s: %s %u %s %s\n", linenum, msg,
977+ key_type(key), key_size(key), fp, comment);
978+ }
979+ free(fp);
980+}
981+
982+static int
983+do_key(const char *filename, u_long linenum,
984+ Key *key, const char *comment)
985+{
986+ Key *public;
987+ int blacklist_status;
988+ int ret = 1;
989+
990+ some_keys = 1;
991+
992+ public = key_demote(key);
993+ if (public->type == KEY_RSA1)
994+ public->type = KEY_RSA;
995+
996+ blacklist_status = blacklisted_key(public, NULL);
997+ if (blacklist_status == -1) {
998+ describe_key(filename, linenum,
999+ "Unknown (blacklist file not installed)", key, comment, 0);
1000+ some_unknown = 1;
1001+ } else if (blacklist_status == 1) {
1002+ describe_key(filename, linenum,
1003+ "COMPROMISED", key, comment, 0);
1004+ some_compromised = 1;
1005+ ret = 0;
1006+ } else
1007+ describe_key(filename, linenum,
1008+ "Not blacklisted", key, comment, 1);
1009+
1010+ key_free(public);
1011+
1012+ return ret;
1013+}
1014+
1015+static int
1016+do_filename(const char *filename, int quiet_open)
1017+{
1018+ FILE *f;
1019+ char line[SSH_MAX_PUBKEY_BYTES];
1020+ char *cp;
1021+ u_long linenum = 0;
1022+ Key *key;
1023+ char *comment = NULL;
1024+ int found = 0, ret = 1;
1025+
1026+ /* Copy much of key_load_public's logic here so that we can read
1027+ * several keys from a single file (e.g. authorized_keys).
1028+ */
1029+
1030+ if (strcmp(filename, "-") != 0) {
1031+ int save_errno;
1032+ f = fopen(filename, "r");
1033+ save_errno = errno;
1034+ if (!f) {
1035+ char pubfile[MAXPATHLEN];
1036+ if (strlcpy(pubfile, filename, sizeof pubfile) <
1037+ sizeof(pubfile) &&
1038+ strlcat(pubfile, ".pub", sizeof pubfile) <
1039+ sizeof(pubfile))
1040+ f = fopen(pubfile, "r");
1041+ }
1042+ errno = save_errno; /* earlier errno is more useful */
1043+ if (!f) {
1044+ if (!quiet_open)
1045+ perror(filename);
1046+ return -1;
1047+ }
1048+ if (verbosity > 0)
1049+ printf("# %s\n", filename);
1050+ } else
1051+ f = stdin;
1052+ while (read_keyfile_line(f, filename, line, sizeof(line),
1053+ &linenum) != -1) {
1054+ int i;
1055+ char *space;
1056+ int type;
1057+ char *end;
1058+
1059+ /* Chop trailing newline. */
1060+ i = strlen(line) - 1;
1061+ if (line[i] == '\n')
1062+ line[i] = '\0';
1063+
1064+ /* Skip leading whitespace, empty and comment lines. */
1065+ for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
1066+ ;
1067+ if (!*cp || *cp == '\n' || *cp == '#')
1068+ continue;
1069+
1070+ /* Cope with ssh-keyscan output and options in
1071+ * authorized_keys files.
1072+ */
1073+ space = strchr(cp, ' ');
1074+ if (!space)
1075+ continue;
1076+ *space = '\0';
1077+ type = key_type_from_name(cp);
1078+ *space = ' ';
1079+ /* Leading number (RSA1) or valid type (RSA/DSA) indicates
1080+ * that we have no host name or options to skip.
1081+ */
1082+ if ((strtol(cp, &end, 10) == 0 || *end != ' ') &&
1083+ type == KEY_UNSPEC) {
1084+ int quoted = 0;
1085+
1086+ for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
1087+ if (*cp == '\\' && cp[1] == '"')
1088+ cp++; /* Skip both */
1089+ else if (*cp == '"')
1090+ quoted = !quoted;
1091+ }
1092+ /* Skip remaining whitespace. */
1093+ for (; *cp == ' ' || *cp == '\t'; cp++)
1094+ ;
1095+ if (!*cp)
1096+ continue;
1097+ }
1098+
1099+ /* Read and process the key itself. */
1100+ key = key_new(KEY_RSA1);
1101+ if (key_read(key, &cp) == 1) {
1102+ while (*cp == ' ' || *cp == '\t')
1103+ cp++;
1104+ if (!do_key(filename, linenum,
1105+ key, *cp ? cp : filename))
1106+ ret = 0;
1107+ found = 1;
1108+ } else {
1109+ key_free(key);
1110+ key = key_new(KEY_UNSPEC);
1111+ if (key_read(key, &cp) == 1) {
1112+ while (*cp == ' ' || *cp == '\t')
1113+ cp++;
1114+ if (!do_key(filename, linenum,
1115+ key, *cp ? cp : filename))
1116+ ret = 0;
1117+ found = 1;
1118+ }
1119+ }
1120+ key_free(key);
1121+ }
1122+ if (f != stdin)
1123+ fclose(f);
1124+
1125+ if (!found && filename) {
1126+ key = key_load_public(filename, &comment);
1127+ if (key) {
1128+ if (!do_key(filename, 1, key, comment))
1129+ ret = 0;
1130+ found = 1;
1131+ }
1132+ free(comment);
1133+ }
1134+
1135+ return ret;
1136+}
1137+
1138+static int
1139+do_host(int quiet_open)
1140+{
1141+ int i;
1142+ struct stat st;
1143+ int ret = 1;
1144+
1145+ for (i = 0; default_host_files[i]; i++) {
1146+ if (stat(default_host_files[i], &st) < 0 && errno == ENOENT)
1147+ continue;
1148+ if (!do_filename(default_host_files[i], quiet_open))
1149+ ret = 0;
1150+ }
1151+
1152+ return ret;
1153+}
1154+
1155+static int
1156+do_user(const char *dir)
1157+{
1158+ int i;
1159+ char *file;
1160+ struct stat st;
1161+ int ret = 1;
1162+
1163+ for (i = 0; default_files[i]; i++) {
1164+ xasprintf(&file, "%s/%s", dir, default_files[i]);
1165+ if (stat(file, &st) < 0 && errno == ENOENT) {
1166+ free(file);
1167+ continue;
1168+ }
1169+ if (!do_filename(file, 0))
1170+ ret = 0;
1171+ free(file);
1172+ }
1173+
1174+ return ret;
1175+}
1176+
1177+int
1178+main(int argc, char **argv)
1179+{
1180+ int opt, all_users = 0;
1181+ int ret = 1;
1182+ extern int optind;
1183+
1184+ /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
1185+ sanitise_stdfd();
1186+
1187+ __progname = ssh_get_progname(argv[0]);
1188+
1189+ SSLeay_add_all_algorithms();
1190+ log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1);
1191+
1192+ /* We don't need the RNG ourselves, but symbol references here allow
1193+ * ld to link us properly.
1194+ */
1195+ seed_rng();
1196+
1197+ while ((opt = getopt(argc, argv, "ahqv")) != -1) {
1198+ switch (opt) {
1199+ case 'a':
1200+ all_users = 1;
1201+ break;
1202+ case 'q':
1203+ verbosity--;
1204+ break;
1205+ case 'v':
1206+ verbosity++;
1207+ break;
1208+ case 'h':
1209+ default:
1210+ usage();
1211+ }
1212+ }
1213+
1214+ if (all_users) {
1215+ struct passwd *pw;
1216+
1217+ if (!do_host(0))
1218+ ret = 0;
1219+
1220+ while ((pw = getpwent()) != NULL) {
1221+ if (pw->pw_dir) {
1222+ temporarily_use_uid(pw);
1223+ if (!do_user(pw->pw_dir))
1224+ ret = 0;
1225+ restore_uid();
1226+ }
1227+ }
1228+ } else if (optind == argc) {
1229+ struct passwd *pw;
1230+
1231+ if (!do_host(1))
1232+ ret = 0;
1233+
1234+ if ((pw = getpwuid(geteuid())) == NULL)
1235+ fprintf(stderr, "No user found with uid %u\n",
1236+ (u_int)geteuid());
1237+ else {
1238+ if (!do_user(pw->pw_dir))
1239+ ret = 0;
1240+ }
1241+ } else {
1242+ while (optind < argc)
1243+ if (!do_filename(argv[optind++], 0))
1244+ ret = 0;
1245+ }
1246+
1247+ if (verbosity >= 0) {
1248+ if (some_unknown) {
1249+ printf("#\n");
1250+ printf("# The status of some keys on your system is unknown.\n");
1251+ printf("# You may need to install additional blacklist files.\n");
1252+ }
1253+ if (some_compromised) {
1254+ printf("#\n");
1255+ printf("# Some keys on your system have been compromised!\n");
1256+ printf("# You must replace them using ssh-keygen(1).\n");
1257+ }
1258+ if (some_unknown || some_compromised) {
1259+ printf("#\n");
1260+ printf("# See the ssh-vulnkey(1) manual page for further advice.\n");
1261+ } else if (some_keys && verbosity > 0) {
1262+ printf("#\n");
1263+ printf("# No blacklisted keys!\n");
1264+ }
1265+ }
1266+
1267+ return ret;
1268+}
1269diff --git a/ssh.1 b/ssh.1
1270index 62292cc..66a7007 100644
1271--- a/ssh.1
1272+++ b/ssh.1
1273@@ -1447,6 +1447,7 @@ if an error occurred.
1274 .Xr ssh-agent 1 ,
1275 .Xr ssh-keygen 1 ,
1276 .Xr ssh-keyscan 1 ,
1277+.Xr ssh-vulnkey 1 ,
1278 .Xr tun 4 ,
1279 .Xr hosts.equiv 5 ,
1280 .Xr ssh_config 5 ,
1281diff --git a/ssh.c b/ssh.c
1282index 87233bc..567248d 100644
1283--- a/ssh.c
1284+++ b/ssh.c
1285@@ -1525,7 +1525,7 @@ ssh_session2(void)
1286 static void
1287 load_public_identity_files(void)
1288 {
1289- char *filename, *cp, thishost[NI_MAXHOST];
1290+ char *filename, *cp, thishost[NI_MAXHOST], *fp;
1291 char *pwdir = NULL, *pwname = NULL;
1292 int i = 0;
1293 Key *public;
1294@@ -1583,6 +1583,22 @@ load_public_identity_files(void)
1295 public = key_load_public(filename, NULL);
1296 debug("identity file %s type %d", filename,
1297 public ? public->type : -1);
1298+ if (public && blacklisted_key(public, &fp) == 1) {
1299+ if (options.use_blacklisted_keys)
1300+ logit("Public key %s blacklisted (see "
1301+ "ssh-vulnkey(1)); continuing anyway", fp);
1302+ else
1303+ logit("Public key %s blacklisted (see "
1304+ "ssh-vulnkey(1)); refusing to send it",
1305+ fp);
1306+ free(fp);
1307+ if (!options.use_blacklisted_keys) {
1308+ key_free(public);
1309+ free(filename);
1310+ filename = NULL;
1311+ public = NULL;
1312+ }
1313+ }
1314 free(options.identity_files[i]);
1315 identity_files[n_ids] = filename;
1316 identity_keys[n_ids] = public;
1317diff --git a/ssh_config.5 b/ssh_config.5
1318index e72919a..8d806c7 100644
1319--- a/ssh_config.5
1320+++ b/ssh_config.5
1321@@ -1229,6 +1229,23 @@ is not specified, it defaults to
1322 .Dq any .
1323 The default is
1324 .Dq any:any .
1325+.It Cm UseBlacklistedKeys
1326+Specifies whether
1327+.Xr ssh 1
1328+should use keys recorded in its blacklist of known-compromised keys (see
1329+.Xr ssh-vulnkey 1 )
1330+for authentication.
1331+If
1332+.Dq yes ,
1333+then attempts to use compromised keys for authentication will be logged but
1334+accepted.
1335+It is strongly recommended that this be used only to install new authorized
1336+keys on the remote system, and even then only with the utmost care.
1337+If
1338+.Dq no ,
1339+then attempts to use compromised keys for authentication will be prevented.
1340+The default is
1341+.Dq no .
1342 .It Cm UsePrivilegedPort
1343 Specifies whether to use a privileged port for outgoing connections.
1344 The argument must be
1345diff --git a/sshconnect2.c b/sshconnect2.c
1346index 0b13530..93818c9 100644
1347--- a/sshconnect2.c
1348+++ b/sshconnect2.c
1349@@ -1491,6 +1491,8 @@ pubkey_prepare(Authctxt *authctxt)
1350
1351 /* list of keys stored in the filesystem and PKCS#11 */
1352 for (i = 0; i < options.num_identity_files; i++) {
1353+ if (options.identity_files[i] == NULL)
1354+ continue;
1355 key = options.identity_keys[i];
1356 if (key && key->type == KEY_RSA1)
1357 continue;
1358@@ -1608,7 +1610,7 @@ userauth_pubkey(Authctxt *authctxt)
1359 debug("Offering %s public key: %s", key_type(id->key),
1360 id->filename);
1361 sent = send_pubkey_test(authctxt, id);
1362- } else if (id->key == NULL) {
1363+ } else if (id->key == NULL && id->filename) {
1364 debug("Trying private key: %s", id->filename);
1365 id->key = load_identity_file(id->filename,
1366 id->userprovided);
1367diff --git a/sshd.8 b/sshd.8
1368index b0c7ab6..a604429 100644
1369--- a/sshd.8
1370+++ b/sshd.8
1371@@ -954,6 +954,7 @@ The content of this file is not sensitive; it can be world-readable.
1372 .Xr ssh-agent 1 ,
1373 .Xr ssh-keygen 1 ,
1374 .Xr ssh-keyscan 1 ,
1375+.Xr ssh-vulnkey 1 ,
1376 .Xr chroot 2 ,
1377 .Xr hosts_access 5 ,
1378 .Xr login.conf 5 ,
1379diff --git a/sshd.c b/sshd.c
1380index e5c9835..fbe3284 100644
1381--- a/sshd.c
1382+++ b/sshd.c
1383@@ -1688,6 +1688,11 @@ main(int ac, char **av)
1384 sensitive_data.host_pubkeys[i] = NULL;
1385 continue;
1386 }
1387+ if (auth_key_is_revoked(key != NULL ? key : pubkey, 1)) {
1388+ sensitive_data.host_keys[i] = NULL;
1389+ sensitive_data.host_pubkeys[i] = NULL;
1390+ continue;
1391+ }
1392
1393 switch (keytype) {
1394 case KEY_RSA1:
1395diff --git a/sshd_config.5 b/sshd_config.5
1396index 525d9c8..18ec81f 100644
1397--- a/sshd_config.5
1398+++ b/sshd_config.5
1399@@ -885,6 +885,20 @@ are refused if the number of unauthenticated connections reaches
1400 Specifies whether password authentication is allowed.
1401 The default is
1402 .Dq yes .
1403+.It Cm PermitBlacklistedKeys
1404+Specifies whether
1405+.Xr sshd 8
1406+should allow keys recorded in its blacklist of known-compromised keys (see
1407+.Xr ssh-vulnkey 1 ) .
1408+If
1409+.Dq yes ,
1410+then attempts to authenticate with compromised keys will be logged but
1411+accepted.
1412+If
1413+.Dq no ,
1414+then attempts to authenticate with compromised keys will be rejected.
1415+The default is
1416+.Dq no .
1417 .It Cm PermitEmptyPasswords
1418 When password authentication is allowed, it specifies whether the
1419 server allows login to accounts with empty password strings.
diff --git a/debian/patches/ssh1-keepalive.patch b/debian/patches/ssh1-keepalive.patch
new file mode 100644
index 000000000..e563bda7c
--- /dev/null
+++ b/debian/patches/ssh1-keepalive.patch
@@ -0,0 +1,74 @@
1From 4c7ed5c80e5f67277620ac973317cc516b67d0e7 Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Sun, 9 Feb 2014 16:09:51 +0000
4Subject: Partial server keep-alive implementation for SSH1
5
6Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1712
7Last-Update: 2013-09-14
8
9Patch-Name: ssh1-keepalive.patch
10---
11 clientloop.c | 25 +++++++++++++++----------
12 ssh_config.5 | 5 ++++-
13 2 files changed, 19 insertions(+), 11 deletions(-)
14
15diff --git a/clientloop.c b/clientloop.c
16index 311dc13..dc76d69 100644
17--- a/clientloop.c
18+++ b/clientloop.c
19@@ -563,16 +563,21 @@ client_global_request_reply(int type, u_int32_t seq, void *ctxt)
20 static void
21 server_alive_check(void)
22 {
23- if (packet_inc_alive_timeouts() > options.server_alive_count_max) {
24- logit("Timeout, server %s not responding.", host);
25- cleanup_exit(255);
26+ if (compat20) {
27+ if (packet_inc_alive_timeouts() > options.server_alive_count_max) {
28+ logit("Timeout, server %s not responding.", host);
29+ cleanup_exit(255);
30+ }
31+ packet_start(SSH2_MSG_GLOBAL_REQUEST);
32+ packet_put_cstring("keepalive@openssh.com");
33+ packet_put_char(1); /* boolean: want reply */
34+ packet_send();
35+ /* Insert an empty placeholder to maintain ordering */
36+ client_register_global_confirm(NULL, NULL);
37+ } else {
38+ packet_send_ignore(0);
39+ packet_send();
40 }
41- packet_start(SSH2_MSG_GLOBAL_REQUEST);
42- packet_put_cstring("keepalive@openssh.com");
43- packet_put_char(1); /* boolean: want reply */
44- packet_send();
45- /* Insert an empty placeholder to maintain ordering */
46- client_register_global_confirm(NULL, NULL);
47 }
48
49 /*
50@@ -634,7 +639,7 @@ client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp,
51 */
52
53 timeout_secs = INT_MAX; /* we use INT_MAX to mean no timeout */
54- if (options.server_alive_interval > 0 && compat20) {
55+ if (options.server_alive_interval > 0) {
56 timeout_secs = options.server_alive_interval;
57 server_alive_time = now + options.server_alive_interval;
58 }
59diff --git a/ssh_config.5 b/ssh_config.5
60index 8d806c7..89b25cd 100644
61--- a/ssh_config.5
62+++ b/ssh_config.5
63@@ -1130,7 +1130,10 @@ If, for example,
64 .Cm ServerAliveCountMax
65 is left at the default, if the server becomes unresponsive,
66 ssh will disconnect after approximately 45 seconds.
67-This option applies to protocol version 2 only.
68+This option applies to protocol version 2 only; in protocol version
69+1 there is no mechanism to request a response from the server to the
70+server alive messages, so disconnection is the responsibility of the TCP
71+stack.
72 .It Cm ServerAliveInterval
73 Sets a timeout interval in seconds after which if no data has been received
74 from the server,
diff --git a/debian/patches/syslog-level-silent.patch b/debian/patches/syslog-level-silent.patch
new file mode 100644
index 000000000..a1eaa7513
--- /dev/null
+++ b/debian/patches/syslog-level-silent.patch
@@ -0,0 +1,47 @@
1From bbddcd71a027a33919f859f35dae800335a2de6a 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 32e1d2e..53e7b65 100644
25--- a/log.c
26+++ b/log.c
27@@ -94,6 +94,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 567248d..219a466 100644
37--- a/ssh.c
38+++ b/ssh.c
39@@ -740,7 +740,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/user-group-modes.patch b/debian/patches/user-group-modes.patch
new file mode 100644
index 000000000..9382d5086
--- /dev/null
+++ b/debian/patches/user-group-modes.patch
@@ -0,0 +1,266 @@
1From 7016a7e8a6b854833132db253fd5e392984bd4ea 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: 2013-09-14
17
18Patch-Name: user-group-modes.patch
19---
20 auth-rhosts.c | 6 ++----
21 auth.c | 9 +++-----
22 misc.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
23 misc.h | 2 ++
24 platform.c | 16 --------------
25 readconf.c | 5 +++--
26 ssh.1 | 2 ++
27 ssh_config.5 | 2 ++
28 8 files changed, 82 insertions(+), 29 deletions(-)
29
30diff --git a/auth-rhosts.c b/auth-rhosts.c
31index 06ae7f0..f202787 100644
32--- a/auth-rhosts.c
33+++ b/auth-rhosts.c
34@@ -256,8 +256,7 @@ auth_rhosts2_raw(struct passwd *pw, const char *client_user, const char *hostnam
35 return 0;
36 }
37 if (options.strict_modes &&
38- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
39- (st.st_mode & 022) != 0)) {
40+ !secure_permissions(&st, pw->pw_uid)) {
41 logit("Rhosts authentication refused for %.100s: "
42 "bad ownership or modes for home directory.", pw->pw_name);
43 auth_debug_add("Rhosts authentication refused for %.100s: "
44@@ -283,8 +282,7 @@ auth_rhosts2_raw(struct passwd *pw, const char *client_user, const char *hostnam
45 * allowing access to their account by anyone.
46 */
47 if (options.strict_modes &&
48- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
49- (st.st_mode & 022) != 0)) {
50+ !secure_permissions(&st, pw->pw_uid)) {
51 logit("Rhosts authentication refused for %.100s: bad modes for %.200s",
52 pw->pw_name, buf);
53 auth_debug_add("Bad file modes for %.200s", buf);
54diff --git a/auth.c b/auth.c
55index 6662e9a..7f6c6c8 100644
56--- a/auth.c
57+++ b/auth.c
58@@ -408,8 +408,7 @@ check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host,
59 user_hostfile = tilde_expand_filename(userfile, pw->pw_uid);
60 if (options.strict_modes &&
61 (stat(user_hostfile, &st) == 0) &&
62- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
63- (st.st_mode & 022) != 0)) {
64+ !secure_permissions(&st, pw->pw_uid)) {
65 logit("Authentication refused for %.100s: "
66 "bad owner or modes for %.200s",
67 pw->pw_name, user_hostfile);
68@@ -471,8 +470,7 @@ auth_secure_path(const char *name, struct stat *stp, const char *pw_dir,
69 snprintf(err, errlen, "%s is not a regular file", buf);
70 return -1;
71 }
72- if ((!platform_sys_dir_uid(stp->st_uid) && stp->st_uid != uid) ||
73- (stp->st_mode & 022) != 0) {
74+ if (!secure_permissions(stp, uid)) {
75 snprintf(err, errlen, "bad ownership or modes for file %s",
76 buf);
77 return -1;
78@@ -487,8 +485,7 @@ auth_secure_path(const char *name, struct stat *stp, const char *pw_dir,
79 strlcpy(buf, cp, sizeof(buf));
80
81 if (stat(buf, &st) < 0 ||
82- (!platform_sys_dir_uid(st.st_uid) && st.st_uid != uid) ||
83- (st.st_mode & 022) != 0) {
84+ !secure_permissions(&st, uid)) {
85 snprintf(err, errlen,
86 "bad ownership or modes for directory %s", buf);
87 return -1;
88diff --git a/misc.c b/misc.c
89index c3c8099..eb57bfc 100644
90--- a/misc.c
91+++ b/misc.c
92@@ -48,8 +48,9 @@
93 #include <netdb.h>
94 #ifdef HAVE_PATHS_H
95 # include <paths.h>
96-#include <pwd.h>
97 #endif
98+#include <pwd.h>
99+#include <grp.h>
100 #ifdef SSH_TUN_OPENBSD
101 #include <net/if.h>
102 #endif
103@@ -58,6 +59,7 @@
104 #include "misc.h"
105 #include "log.h"
106 #include "ssh.h"
107+#include "platform.h"
108
109 /* remove newline at end of string */
110 char *
111@@ -642,6 +644,71 @@ read_keyfile_line(FILE *f, const char *filename, char *buf, size_t bufsz,
112 return -1;
113 }
114
115+/*
116+ * return 1 if the specified uid is a uid that may own a system directory
117+ * otherwise 0.
118+ */
119+int
120+platform_sys_dir_uid(uid_t uid)
121+{
122+ if (uid == 0)
123+ return 1;
124+#ifdef PLATFORM_SYS_DIR_UID
125+ if (uid == PLATFORM_SYS_DIR_UID)
126+ return 1;
127+#endif
128+ return 0;
129+}
130+
131+int
132+secure_permissions(struct stat *st, uid_t uid)
133+{
134+ if (!platform_sys_dir_uid(st->st_uid) && st->st_uid != uid)
135+ return 0;
136+ if ((st->st_mode & 002) != 0)
137+ return 0;
138+ if ((st->st_mode & 020) != 0) {
139+ /* If the file is group-writable, the group in question must
140+ * have exactly one member, namely the file's owner.
141+ * (Zero-member groups are typically used by setgid
142+ * binaries, and are unlikely to be suitable.)
143+ */
144+ struct passwd *pw;
145+ struct group *gr;
146+ int members = 0;
147+
148+ gr = getgrgid(st->st_gid);
149+ if (!gr)
150+ return 0;
151+
152+ /* Check primary group memberships. */
153+ while ((pw = getpwent()) != NULL) {
154+ if (pw->pw_gid == gr->gr_gid) {
155+ ++members;
156+ if (pw->pw_uid != uid)
157+ return 0;
158+ }
159+ }
160+ endpwent();
161+
162+ pw = getpwuid(st->st_uid);
163+ if (!pw)
164+ return 0;
165+
166+ /* Check supplementary group memberships. */
167+ if (gr->gr_mem[0]) {
168+ ++members;
169+ if (strcmp(pw->pw_name, gr->gr_mem[0]) ||
170+ gr->gr_mem[1])
171+ return 0;
172+ }
173+
174+ if (!members)
175+ return 0;
176+ }
177+ return 1;
178+}
179+
180 int
181 tun_open(int tun, int mode)
182 {
183diff --git a/misc.h b/misc.h
184index fceb306..51ba182 100644
185--- a/misc.h
186+++ b/misc.h
187@@ -104,4 +104,6 @@ char *read_passphrase(const char *, int);
188 int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2)));
189 int read_keyfile_line(FILE *, const char *, char *, size_t, u_long *);
190
191+int secure_permissions(struct stat *st, uid_t uid);
192+
193 #endif /* _MISC_H */
194diff --git a/platform.c b/platform.c
195index a962f15..0b3bee1 100644
196--- a/platform.c
197+++ b/platform.c
198@@ -194,19 +194,3 @@ platform_krb5_get_principal_name(const char *pw_name)
199 return NULL;
200 #endif
201 }
202-
203-/*
204- * return 1 if the specified uid is a uid that may own a system directory
205- * otherwise 0.
206- */
207-int
208-platform_sys_dir_uid(uid_t uid)
209-{
210- if (uid == 0)
211- return 1;
212-#ifdef PLATFORM_SYS_DIR_UID
213- if (uid == PLATFORM_SYS_DIR_UID)
214- return 1;
215-#endif
216- return 0;
217-}
218diff --git a/readconf.c b/readconf.c
219index 2dcbf31..389de7d 100644
220--- a/readconf.c
221+++ b/readconf.c
222@@ -30,6 +30,8 @@
223 #include <stdio.h>
224 #include <string.h>
225 #include <unistd.h>
226+#include <pwd.h>
227+#include <grp.h>
228 #ifdef HAVE_UTIL_H
229 #include <util.h>
230 #endif
231@@ -1160,8 +1162,7 @@ read_config_file(const char *filename, const char *host, Options *options,
232
233 if (fstat(fileno(f), &sb) == -1)
234 fatal("fstat %s: %s", filename, strerror(errno));
235- if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
236- (sb.st_mode & 022) != 0))
237+ if (!secure_permissions(&sb, getuid()))
238 fatal("Bad owner or permissions on %s", filename);
239 }
240
241diff --git a/ssh.1 b/ssh.1
242index 66a7007..0b38ae1 100644
243--- a/ssh.1
244+++ b/ssh.1
245@@ -1338,6 +1338,8 @@ The file format and configuration options are described in
246 .Xr ssh_config 5 .
247 Because of the potential for abuse, this file must have strict permissions:
248 read/write for the user, and not writable by others.
249+It may be group-writable provided that the group in question contains only
250+the user.
251 .Pp
252 .It Pa ~/.ssh/environment
253 Contains additional definitions for environment variables; see
254diff --git a/ssh_config.5 b/ssh_config.5
255index 135d833..1497cfc 100644
256--- a/ssh_config.5
257+++ b/ssh_config.5
258@@ -1382,6 +1382,8 @@ The format of this file is described above.
259 This file is used by the SSH client.
260 Because of the potential for abuse, this file must have strict permissions:
261 read/write for the user, and not accessible by others.
262+It may be group-writable provided that the group in question contains only
263+the user.
264 .It Pa /etc/ssh/ssh_config
265 Systemwide configuration file.
266 This file provides defaults for those