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/debian-banner.patch111
-rw-r--r--debian/patches/debian-config.patch195
-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.patch3030
-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.patch42
-rw-r--r--debian/patches/no-openssl-version-status.patch62
-rw-r--r--debian/patches/openbsd-docs.patch148
-rw-r--r--debian/patches/package-versioning.patch65
-rw-r--r--debian/patches/quieter-signals.patch40
-rw-r--r--debian/patches/restore-tcp-wrappers.patch172
-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.patch35
-rw-r--r--debian/patches/ssh-agent-setgid.patch40
-rw-r--r--debian/patches/ssh-argv0.patch31
-rw-r--r--debian/patches/ssh-vulnkey-compat.patch42
-rw-r--r--debian/patches/syslog-level-silent.patch47
-rw-r--r--debian/patches/systemd-readiness.patch84
-rw-r--r--debian/patches/user-group-modes.patch266
29 files changed, 5551 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..3635e50ad
--- /dev/null
+++ b/debian/patches/auth-log-verbosity.patch
@@ -0,0 +1,133 @@
1From a791d607756f04e41153c2297e5f9a608daa7335 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 e387697..f1e3ddf 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@@ -293,10 +304,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@@ -519,11 +533,14 @@ parse_option_list(struct sshbuf *oblob, 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 34852e5..1653855 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(struct sshkey *, struct passwd *);
93diff --git a/auth-rsa.c b/auth-rsa.c
94index cbd971b..4cf2163 100644
95--- a/auth-rsa.c
96+++ b/auth-rsa.c
97@@ -181,6 +181,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 5aa319c..1eee161 100644
108--- a/auth2-pubkey.c
109+++ b/auth2-pubkey.c
110@@ -561,6 +561,7 @@ process_principals(FILE *f, char *file, struct passwd *pw,
111 u_long linenum = 0;
112 u_int i;
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@@ -726,6 +727,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@@ -872,6 +874,7 @@ user_cert_trusted_ca(struct passwd *pw, Key *key)
127 if (key_cert_check_authority(key, 0, 1,
128 use_authorized_principals ? NULL : pw->pw_name, &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..2b1bd05f7
--- /dev/null
+++ b/debian/patches/authorized-keys-man-symlink.patch
@@ -0,0 +1,26 @@
1From 9769daa27369920a909debed3ee297c32f0c3ef7 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 3d2a328..915c740 100644
17--- a/Makefile.in
18+++ b/Makefile.in
19@@ -324,6 +324,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/debian-banner.patch b/debian/patches/debian-banner.patch
new file mode 100644
index 000000000..eceac3ccf
--- /dev/null
+++ b/debian/patches/debian-banner.patch
@@ -0,0 +1,111 @@
1From 1cbbbb90ae1a4f88f8090e1fdecee007b8d360f8 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: 2015-11-29
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 ed3a88d..a778f44 100644
23--- a/servconf.c
24+++ b/servconf.c
25@@ -171,6 +171,7 @@ initialize_server_options(ServerOptions *options)
26 options->ip_qos_bulk = -1;
27 options->version_addendum = NULL;
28 options->fingerprint_hash = -1;
29+ options->debian_banner = -1;
30 }
31
32 /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
33@@ -347,6 +348,8 @@ fill_default_server_options(ServerOptions *options)
34 options->fwd_opts.streamlocal_bind_unlink = 0;
35 if (options->fingerprint_hash == -1)
36 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
37+ if (options->debian_banner == -1)
38+ options->debian_banner = 1;
39
40 if (kex_assemble_names(KEX_SERVER_ENCRYPT, &options->ciphers) != 0 ||
41 kex_assemble_names(KEX_SERVER_MAC, &options->macs) != 0 ||
42@@ -430,6 +433,7 @@ typedef enum {
43 sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
44 sStreamLocalBindMask, sStreamLocalBindUnlink,
45 sAllowStreamLocalForwarding, sFingerprintHash,
46+ sDebianBanner,
47 sDeprecated, sUnsupported
48 } ServerOpCodes;
49
50@@ -577,6 +581,7 @@ static struct {
51 { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
52 { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
53 { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
54+ { "debianbanner", sDebianBanner, SSHCFG_GLOBAL },
55 { NULL, sBadOption, 0 }
56 };
57
58@@ -1867,6 +1872,10 @@ process_server_config_line(ServerOptions *options, char *line,
59 options->fingerprint_hash = value;
60 break;
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 778ba17..161fa37 100644
71--- a/servconf.h
72+++ b/servconf.h
73@@ -197,6 +197,8 @@ typedef struct {
74 char *auth_methods[MAX_AUTH_METHODS];
75
76 int fingerprint_hash;
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 189d34a..8d17521 100644
84--- a/sshd.c
85+++ b/sshd.c
86@@ -443,7 +443,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 c8ee35d..b149bd3 100644
98--- a/sshd_config.5
99+++ b/sshd_config.5
100@@ -533,6 +533,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..0a5e2cd39
--- /dev/null
+++ b/debian/patches/debian-config.patch
@@ -0,0 +1,195 @@
1From 003a875a474100d250b6643270ef3874da6591d8 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
17Document all of this, along with several sshd defaults set in
18debian/openssh-server.postinst.
19
20Author: Russ Allbery <rra@debian.org>
21Forwarded: not-needed
22Last-Update: 2015-12-07
23
24Patch-Name: debian-config.patch
25---
26 readconf.c | 2 +-
27 ssh.1 | 21 +++++++++++++++++++++
28 ssh_config | 7 ++++++-
29 ssh_config.5 | 19 ++++++++++++++++++-
30 sshd_config | 2 +-
31 sshd_config.5 | 25 +++++++++++++++++++++++++
32 6 files changed, 72 insertions(+), 4 deletions(-)
33
34diff --git a/readconf.c b/readconf.c
35index b9442fd..ee46ad6 100644
36--- a/readconf.c
37+++ b/readconf.c
38@@ -1749,7 +1749,7 @@ fill_default_options(Options * options)
39 if (options->forward_x11 == -1)
40 options->forward_x11 = 0;
41 if (options->forward_x11_trusted == -1)
42- options->forward_x11_trusted = 0;
43+ options->forward_x11_trusted = 1;
44 if (options->forward_x11_timeout == -1)
45 options->forward_x11_timeout = 1200;
46 if (options->exit_on_forward_failure == -1)
47diff --git a/ssh.1 b/ssh.1
48index 05b7f10..649d6c3 100644
49--- a/ssh.1
50+++ b/ssh.1
51@@ -755,6 +755,16 @@ directive in
52 .Xr ssh_config 5
53 for more information.
54 .Pp
55+(Debian-specific: X11 forwarding is not subjected to X11 SECURITY extension
56+restrictions by default, because too many programs currently crash in this
57+mode.
58+Set the
59+.Cm ForwardX11Trusted
60+option to
61+.Dq no
62+to restore the upstream behaviour.
63+This may change in future depending on client-side improvements.)
64+.Pp
65 .It Fl x
66 Disables X11 forwarding.
67 .Pp
68@@ -763,6 +773,17 @@ Enables trusted X11 forwarding.
69 Trusted X11 forwardings are not subjected to the X11 SECURITY extension
70 controls.
71 .Pp
72+(Debian-specific: This option does nothing in the default configuration: it
73+is equivalent to
74+.Dq Cm ForwardX11Trusted No yes ,
75+which is the default as described above.
76+Set the
77+.Cm ForwardX11Trusted
78+option to
79+.Dq no
80+to restore the upstream behaviour.
81+This may change in future depending on client-side improvements.)
82+.Pp
83 .It Fl y
84 Send log information using the
85 .Xr syslog 3
86diff --git a/ssh_config b/ssh_config
87index 228e5ab..c9386aa 100644
88--- a/ssh_config
89+++ b/ssh_config
90@@ -17,9 +17,10 @@
91 # list of available options, their meanings and defaults, please see the
92 # ssh_config(5) man page.
93
94-# Host *
95+Host *
96 # ForwardAgent no
97 # ForwardX11 no
98+# ForwardX11Trusted yes
99 # RhostsRSAAuthentication no
100 # RSAAuthentication yes
101 # PasswordAuthentication yes
102@@ -48,3 +49,7 @@
103 # VisualHostKey no
104 # ProxyCommand ssh -q -W %h:%p gateway.example.com
105 # RekeyLimit 1G 1h
106+ SendEnv LANG LC_*
107+ HashKnownHosts yes
108+ GSSAPIAuthentication yes
109+ GSSAPIDelegateCredentials no
110diff --git a/ssh_config.5 b/ssh_config.5
111index d4928b8..81b9b74 100644
112--- a/ssh_config.5
113+++ b/ssh_config.5
114@@ -74,6 +74,22 @@ Since the first obtained value for each parameter is used, more
115 host-specific declarations should be given near the beginning of the
116 file, and general defaults at the end.
117 .Pp
118+Note that the Debian
119+.Ic openssh-client
120+package sets several options as standard in
121+.Pa /etc/ssh/ssh_config
122+which are not the default in
123+.Xr ssh 1 :
124+.Pp
125+.Bl -bullet -offset indent -compact
126+.It
127+.Cm SendEnv No LANG LC_*
128+.It
129+.Cm HashKnownHosts No yes
130+.It
131+.Cm GSSAPIAuthentication No yes
132+.El
133+.Pp
134 The configuration file has the following format:
135 .Pp
136 Empty lines and lines starting with
137@@ -721,7 +737,8 @@ token used for the session will be set to expire after 20 minutes.
138 Remote clients will be refused access after this time.
139 .Pp
140 The default is
141-.Dq no .
142+.Dq yes
143+(Debian-specific).
144 .Pp
145 See the X11 SECURITY extension specification for full details on
146 the restrictions imposed on untrusted clients.
147diff --git a/sshd_config b/sshd_config
148index 64786c9..d8338db 100644
149--- a/sshd_config
150+++ b/sshd_config
151@@ -125,7 +125,7 @@ UsePrivilegeSeparation sandbox # Default for new installations.
152 #Banner none
153
154 # override default of no subsystems
155-Subsystem sftp /usr/libexec/sftp-server
156+Subsystem sftp /usr/lib/openssh/sftp-server
157
158 # Example of overriding settings on a per-user basis
159 #Match User anoncvs
160diff --git a/sshd_config.5 b/sshd_config.5
161index 0828592..0be7250 100644
162--- a/sshd_config.5
163+++ b/sshd_config.5
164@@ -57,6 +57,31 @@ Arguments may optionally be enclosed in double quotes
165 .Pq \&"
166 in order to represent arguments containing spaces.
167 .Pp
168+Note that the Debian
169+.Ic openssh-server
170+package sets several options as standard in
171+.Pa /etc/ssh/sshd_config
172+which are not the default in
173+.Xr sshd 8 .
174+The exact list depends on whether the package was installed fresh or
175+upgraded from various possible previous versions, but includes at least the
176+following:
177+.Pp
178+.Bl -bullet -offset indent -compact
179+.It
180+.Cm ChallengeResponseAuthentication No no
181+.It
182+.Cm X11Forwarding No yes
183+.It
184+.Cm PrintMotd No no
185+.It
186+.Cm AcceptEnv No LANG LC_*
187+.It
188+.Cm Subsystem No sftp /usr/lib/openssh/sftp-server
189+.It
190+.Cm UsePAM No yes
191+.El
192+.Pp
193 The possible
194 keywords and their meanings are as follows (note that
195 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..725d26e81
--- /dev/null
+++ b/debian/patches/dnssec-sshfp.patch
@@ -0,0 +1,94 @@
1From 54d62ce82775d6a6f556cef7b1ff61412d2d0581 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 e813afe..fce2e30 100644
22--- a/dns.c
23+++ b/dns.c
24@@ -206,6 +206,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@@ -229,8 +230,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..646716fe5
--- /dev/null
+++ b/debian/patches/doc-hash-tab-completion.patch
@@ -0,0 +1,28 @@
1From 6f8b6ab94f4c4351e49598f08abc6da16fe29740 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 1e9c058..d4928b8 100644
17--- a/ssh_config.5
18+++ b/ssh_config.5
19@@ -809,6 +809,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..b7a072414
--- /dev/null
+++ b/debian/patches/doc-upstart.patch
@@ -0,0 +1,29 @@
1From 17063f049ca0f00cb455eed0852405bc9abe6213 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 42ba596..17b917c 100644
16--- a/sshd.8
17+++ b/sshd.8
18@@ -67,7 +67,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..c3b601c76
--- /dev/null
+++ b/debian/patches/gnome-ssh-askpass2-icon.patch
@@ -0,0 +1,26 @@
1From a1913369b4abfcebec320706e561591c1ed8640c 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..8bc83cace
--- /dev/null
+++ b/debian/patches/gssapi.patch
@@ -0,0 +1,3030 @@
1From 6a0a4b2f79889c9b0d5e2478a6ee5f51be38dcc9 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: 2016-01-04
21
22Patch-Name: gssapi.patch
23---
24 ChangeLog.gssapi | 113 +++++++++++++++++++
25 Makefile.in | 5 +-
26 auth-krb5.c | 17 ++-
27 auth.c | 3 +-
28 auth2-gss.c | 48 +++++++-
29 auth2.c | 2 +
30 clientloop.c | 13 +++
31 config.h.in | 6 +
32 configure.ac | 24 ++++
33 gss-genr.c | 275 ++++++++++++++++++++++++++++++++++++++++++++-
34 gss-serv-krb5.c | 85 ++++++++++++--
35 gss-serv.c | 185 +++++++++++++++++++++++++++---
36 kex.c | 16 +++
37 kex.h | 14 +++
38 kexgssc.c | 336 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
39 kexgsss.c | 295 ++++++++++++++++++++++++++++++++++++++++++++++++
40 monitor.c | 108 +++++++++++++++++-
41 monitor.h | 3 +
42 monitor_wrap.c | 47 +++++++-
43 monitor_wrap.h | 4 +-
44 readconf.c | 42 +++++++
45 readconf.h | 5 +
46 servconf.c | 28 ++++-
47 servconf.h | 2 +
48 ssh-gss.h | 41 ++++++-
49 ssh_config | 2 +
50 ssh_config.5 | 36 +++++-
51 sshconnect2.c | 120 +++++++++++++++++++-
52 sshd.c | 110 ++++++++++++++++++
53 sshd_config | 2 +
54 sshd_config.5 | 11 ++
55 sshkey.c | 3 +-
56 sshkey.h | 1 +
57 33 files changed, 1955 insertions(+), 47 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 40cc7aa..3d2a328 100644
183--- a/Makefile.in
184+++ b/Makefile.in
185@@ -91,7 +91,8 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
186 sc25519.o ge25519.o fe25519.o ed25519.o verify.o hash.o blocks.o \
187 kex.o kexdh.o kexgex.o kexecdh.o kexc25519.o \
188 kexdhc.o kexgexc.o kexecdhc.o kexc25519c.o \
189- kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o
190+ kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o \
191+ kexgssc.o
192
193 SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
194 sshconnect.o sshconnect1.o sshconnect2.o mux.o \
195@@ -105,7 +106,7 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \
196 auth-skey.o auth-bsdauth.o auth2-hostbased.o auth2-kbdint.o \
197 auth2-none.o auth2-passwd.o auth2-pubkey.o \
198 monitor_mm.o monitor.o monitor_wrap.o auth-krb5.o \
199- auth2-gss.o gss-serv.o gss-serv-krb5.o \
200+ auth2-gss.o gss-serv.o gss-serv-krb5.o kexgsss.o \
201 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
202 sftp-server.o sftp-common.o \
203 roaming_common.o roaming_serv.o \
204diff --git a/auth-krb5.c b/auth-krb5.c
205index 0089b18..ec47869 100644
206--- a/auth-krb5.c
207+++ b/auth-krb5.c
208@@ -183,8 +183,13 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
209
210 len = strlen(authctxt->krb5_ticket_file) + 6;
211 authctxt->krb5_ccname = xmalloc(len);
212+#ifdef USE_CCAPI
213+ snprintf(authctxt->krb5_ccname, len, "API:%s",
214+ authctxt->krb5_ticket_file);
215+#else
216 snprintf(authctxt->krb5_ccname, len, "FILE:%s",
217 authctxt->krb5_ticket_file);
218+#endif
219
220 #ifdef USE_PAM
221 if (options.use_pam)
222@@ -241,15 +246,22 @@ krb5_cleanup_proc(Authctxt *authctxt)
223 #ifndef HEIMDAL
224 krb5_error_code
225 ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
226- int tmpfd, ret, oerrno;
227+ int ret, oerrno;
228 char ccname[40];
229 mode_t old_umask;
230+#ifdef USE_CCAPI
231+ char cctemplate[] = "API:krb5cc_%d";
232+#else
233+ char cctemplate[] = "FILE:/tmp/krb5cc_%d_XXXXXXXXXX";
234+ int tmpfd;
235+#endif
236
237 ret = snprintf(ccname, sizeof(ccname),
238- "FILE:/tmp/krb5cc_%d_XXXXXXXXXX", geteuid());
239+ cctemplate, geteuid());
240 if (ret < 0 || (size_t)ret >= sizeof(ccname))
241 return ENOMEM;
242
243+#ifndef USE_CCAPI
244 old_umask = umask(0177);
245 tmpfd = mkstemp(ccname + strlen("FILE:"));
246 oerrno = errno;
247@@ -266,6 +278,7 @@ ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
248 return oerrno;
249 }
250 close(tmpfd);
251+#endif
252
253 return (krb5_cc_resolve(ctx, ccname, ccache));
254 }
255diff --git a/auth.c b/auth.c
256index 214c2c7..bd6a026 100644
257--- a/auth.c
258+++ b/auth.c
259@@ -354,7 +354,8 @@ auth_root_allowed(const char *method)
260 case PERMIT_NO_PASSWD:
261 if (strcmp(method, "publickey") == 0 ||
262 strcmp(method, "hostbased") == 0 ||
263- strcmp(method, "gssapi-with-mic") == 0)
264+ strcmp(method, "gssapi-with-mic") == 0 ||
265+ strcmp(method, "gssapi-keyex") == 0)
266 return 1;
267 break;
268 case PERMIT_FORCED_ONLY:
269diff --git a/auth2-gss.c b/auth2-gss.c
270index 1ca8357..3b5036d 100644
271--- a/auth2-gss.c
272+++ b/auth2-gss.c
273@@ -1,7 +1,7 @@
274 /* $OpenBSD: auth2-gss.c,v 1.22 2015/01/19 20:07:45 markus Exp $ */
275
276 /*
277- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
278+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
279 *
280 * Redistribution and use in source and binary forms, with or without
281 * modification, are permitted provided that the following conditions
282@@ -53,6 +53,40 @@ static int input_gssapi_mic(int type, u_int32_t plen, void *ctxt);
283 static int input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt);
284 static int input_gssapi_errtok(int, u_int32_t, void *);
285
286+/*
287+ * The 'gssapi_keyex' userauth mechanism.
288+ */
289+static int
290+userauth_gsskeyex(Authctxt *authctxt)
291+{
292+ int authenticated = 0;
293+ Buffer b;
294+ gss_buffer_desc mic, gssbuf;
295+ u_int len;
296+
297+ mic.value = packet_get_string(&len);
298+ mic.length = len;
299+
300+ packet_check_eom();
301+
302+ ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service,
303+ "gssapi-keyex");
304+
305+ gssbuf.value = buffer_ptr(&b);
306+ gssbuf.length = buffer_len(&b);
307+
308+ /* gss_kex_context is NULL with privsep, so we can't check it here */
309+ if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gss_kex_context,
310+ &gssbuf, &mic))))
311+ authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
312+ authctxt->pw));
313+
314+ buffer_free(&b);
315+ free(mic.value);
316+
317+ return (authenticated);
318+}
319+
320 /*
321 * We only support those mechanisms that we know about (ie ones that we know
322 * how to check local user kuserok and the like)
323@@ -238,7 +272,8 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt)
324
325 packet_check_eom();
326
327- authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
328+ authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
329+ authctxt->pw));
330
331 authctxt->postponed = 0;
332 dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
333@@ -274,7 +309,8 @@ input_gssapi_mic(int type, u_int32_t plen, void *ctxt)
334 gssbuf.length = buffer_len(&b);
335
336 if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic))))
337- authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
338+ authenticated =
339+ PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw));
340 else
341 logit("GSSAPI MIC check failed");
342
343@@ -290,6 +326,12 @@ input_gssapi_mic(int type, u_int32_t plen, void *ctxt)
344 return 0;
345 }
346
347+Authmethod method_gsskeyex = {
348+ "gssapi-keyex",
349+ userauth_gsskeyex,
350+ &options.gss_authentication
351+};
352+
353 Authmethod method_gssapi = {
354 "gssapi-with-mic",
355 userauth_gssapi,
356diff --git a/auth2.c b/auth2.c
357index 7177962..3f49bdc 100644
358--- a/auth2.c
359+++ b/auth2.c
360@@ -70,6 +70,7 @@ extern Authmethod method_passwd;
361 extern Authmethod method_kbdint;
362 extern Authmethod method_hostbased;
363 #ifdef GSSAPI
364+extern Authmethod method_gsskeyex;
365 extern Authmethod method_gssapi;
366 #endif
367
368@@ -77,6 +78,7 @@ Authmethod *authmethods[] = {
369 &method_none,
370 &method_pubkey,
371 #ifdef GSSAPI
372+ &method_gsskeyex,
373 &method_gssapi,
374 #endif
375 &method_passwd,
376diff --git a/clientloop.c b/clientloop.c
377index 87ceb3d..fba1b54 100644
378--- a/clientloop.c
379+++ b/clientloop.c
380@@ -115,6 +115,10 @@
381 #include "ssherr.h"
382 #include "hostfile.h"
383
384+#ifdef GSSAPI
385+#include "ssh-gss.h"
386+#endif
387+
388 /* import options */
389 extern Options options;
390
391@@ -1610,6 +1614,15 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
392 /* Do channel operations unless rekeying in progress. */
393 if (!rekeying) {
394 channel_after_select(readset, writeset);
395+
396+#ifdef GSSAPI
397+ if (options.gss_renewal_rekey &&
398+ ssh_gssapi_credentials_updated(NULL)) {
399+ debug("credentials updated - forcing rekey");
400+ need_rekeying = 1;
401+ }
402+#endif
403+
404 if (need_rekeying || packet_need_rekeying()) {
405 debug("need rekeying");
406 active_state->kex->done = 0;
407diff --git a/config.h.in b/config.h.in
408index 7500df5..97accd8 100644
409--- a/config.h.in
410+++ b/config.h.in
411@@ -1623,6 +1623,9 @@
412 /* Use btmp to log bad logins */
413 #undef USE_BTMP
414
415+/* platform uses an in-memory credentials cache */
416+#undef USE_CCAPI
417+
418 /* Use libedit for sftp */
419 #undef USE_LIBEDIT
420
421@@ -1638,6 +1641,9 @@
422 /* Use PIPES instead of a socketpair() */
423 #undef USE_PIPES
424
425+/* platform has the Security Authorization Session API */
426+#undef USE_SECURITY_SESSION_API
427+
428 /* Define if you have Solaris process contracts */
429 #undef USE_SOLARIS_PROCESS_CONTRACTS
430
431diff --git a/configure.ac b/configure.ac
432index 9b05c30..7a25603 100644
433--- a/configure.ac
434+++ b/configure.ac
435@@ -625,6 +625,30 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
436 [Use tunnel device compatibility to OpenBSD])
437 AC_DEFINE([SSH_TUN_PREPEND_AF], [1],
438 [Prepend the address family to IP tunnel traffic])
439+ AC_MSG_CHECKING([if we have the Security Authorization Session API])
440+ AC_TRY_COMPILE([#include <Security/AuthSession.h>],
441+ [SessionCreate(0, 0);],
442+ [ac_cv_use_security_session_api="yes"
443+ AC_DEFINE([USE_SECURITY_SESSION_API], [1],
444+ [platform has the Security Authorization Session API])
445+ LIBS="$LIBS -framework Security"
446+ AC_MSG_RESULT([yes])],
447+ [ac_cv_use_security_session_api="no"
448+ AC_MSG_RESULT([no])])
449+ AC_MSG_CHECKING([if we have an in-memory credentials cache])
450+ AC_TRY_COMPILE(
451+ [#include <Kerberos/Kerberos.h>],
452+ [cc_context_t c;
453+ (void) cc_initialize (&c, 0, NULL, NULL);],
454+ [AC_DEFINE([USE_CCAPI], [1],
455+ [platform uses an in-memory credentials cache])
456+ LIBS="$LIBS -framework Security"
457+ AC_MSG_RESULT([yes])
458+ if test "x$ac_cv_use_security_session_api" = "xno"; then
459+ AC_MSG_ERROR([*** Need a security framework to use the credentials cache API ***])
460+ fi],
461+ [AC_MSG_RESULT([no])]
462+ )
463 m4_pattern_allow([AU_IPv])
464 AC_CHECK_DECL([AU_IPv4], [],
465 AC_DEFINE([AU_IPv4], [0], [System only supports IPv4 audit records])
466diff --git a/gss-genr.c b/gss-genr.c
467index d617d60..b4eca3f 100644
468--- a/gss-genr.c
469+++ b/gss-genr.c
470@@ -1,7 +1,7 @@
471 /* $OpenBSD: gss-genr.c,v 1.23 2015/01/20 23:14:00 deraadt Exp $ */
472
473 /*
474- * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
475+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
476 *
477 * Redistribution and use in source and binary forms, with or without
478 * modification, are permitted provided that the following conditions
479@@ -41,12 +41,167 @@
480 #include "buffer.h"
481 #include "log.h"
482 #include "ssh2.h"
483+#include "cipher.h"
484+#include "key.h"
485+#include "kex.h"
486+#include <openssl/evp.h>
487
488 #include "ssh-gss.h"
489
490 extern u_char *session_id2;
491 extern u_int session_id2_len;
492
493+typedef struct {
494+ char *encoded;
495+ gss_OID oid;
496+} ssh_gss_kex_mapping;
497+
498+/*
499+ * XXX - It would be nice to find a more elegant way of handling the
500+ * XXX passing of the key exchange context to the userauth routines
501+ */
502+
503+Gssctxt *gss_kex_context = NULL;
504+
505+static ssh_gss_kex_mapping *gss_enc2oid = NULL;
506+
507+int
508+ssh_gssapi_oid_table_ok(void) {
509+ return (gss_enc2oid != NULL);
510+}
511+
512+/*
513+ * Return a list of the gss-group1-sha1 mechanisms supported by this program
514+ *
515+ * We test mechanisms to ensure that we can use them, to avoid starting
516+ * a key exchange with a bad mechanism
517+ */
518+
519+char *
520+ssh_gssapi_client_mechanisms(const char *host, const char *client) {
521+ gss_OID_set gss_supported;
522+ OM_uint32 min_status;
523+
524+ if (GSS_ERROR(gss_indicate_mechs(&min_status, &gss_supported)))
525+ return NULL;
526+
527+ return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism,
528+ host, client));
529+}
530+
531+char *
532+ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
533+ const char *host, const char *client) {
534+ Buffer buf;
535+ size_t i;
536+ int oidpos, enclen;
537+ char *mechs, *encoded;
538+ u_char digest[EVP_MAX_MD_SIZE];
539+ char deroid[2];
540+ const EVP_MD *evp_md = EVP_md5();
541+ EVP_MD_CTX md;
542+
543+ if (gss_enc2oid != NULL) {
544+ for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
545+ free(gss_enc2oid[i].encoded);
546+ free(gss_enc2oid);
547+ }
548+
549+ gss_enc2oid = xmalloc(sizeof(ssh_gss_kex_mapping) *
550+ (gss_supported->count + 1));
551+
552+ buffer_init(&buf);
553+
554+ oidpos = 0;
555+ for (i = 0; i < gss_supported->count; i++) {
556+ if (gss_supported->elements[i].length < 128 &&
557+ (*check)(NULL, &(gss_supported->elements[i]), host, client)) {
558+
559+ deroid[0] = SSH_GSS_OIDTYPE;
560+ deroid[1] = gss_supported->elements[i].length;
561+
562+ EVP_DigestInit(&md, evp_md);
563+ EVP_DigestUpdate(&md, deroid, 2);
564+ EVP_DigestUpdate(&md,
565+ gss_supported->elements[i].elements,
566+ gss_supported->elements[i].length);
567+ EVP_DigestFinal(&md, digest, NULL);
568+
569+ encoded = xmalloc(EVP_MD_size(evp_md) * 2);
570+ enclen = __b64_ntop(digest, EVP_MD_size(evp_md),
571+ encoded, EVP_MD_size(evp_md) * 2);
572+
573+ if (oidpos != 0)
574+ buffer_put_char(&buf, ',');
575+
576+ buffer_append(&buf, KEX_GSS_GEX_SHA1_ID,
577+ sizeof(KEX_GSS_GEX_SHA1_ID) - 1);
578+ buffer_append(&buf, encoded, enclen);
579+ buffer_put_char(&buf, ',');
580+ buffer_append(&buf, KEX_GSS_GRP1_SHA1_ID,
581+ sizeof(KEX_GSS_GRP1_SHA1_ID) - 1);
582+ buffer_append(&buf, encoded, enclen);
583+ buffer_put_char(&buf, ',');
584+ buffer_append(&buf, KEX_GSS_GRP14_SHA1_ID,
585+ sizeof(KEX_GSS_GRP14_SHA1_ID) - 1);
586+ buffer_append(&buf, encoded, enclen);
587+
588+ gss_enc2oid[oidpos].oid = &(gss_supported->elements[i]);
589+ gss_enc2oid[oidpos].encoded = encoded;
590+ oidpos++;
591+ }
592+ }
593+ gss_enc2oid[oidpos].oid = NULL;
594+ gss_enc2oid[oidpos].encoded = NULL;
595+
596+ buffer_put_char(&buf, '\0');
597+
598+ mechs = xmalloc(buffer_len(&buf));
599+ buffer_get(&buf, mechs, buffer_len(&buf));
600+ buffer_free(&buf);
601+
602+ if (strlen(mechs) == 0) {
603+ free(mechs);
604+ mechs = NULL;
605+ }
606+
607+ return (mechs);
608+}
609+
610+gss_OID
611+ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
612+ int i = 0;
613+
614+ switch (kex_type) {
615+ case KEX_GSS_GRP1_SHA1:
616+ if (strlen(name) < sizeof(KEX_GSS_GRP1_SHA1_ID))
617+ return GSS_C_NO_OID;
618+ name += sizeof(KEX_GSS_GRP1_SHA1_ID) - 1;
619+ break;
620+ case KEX_GSS_GRP14_SHA1:
621+ if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA1_ID))
622+ return GSS_C_NO_OID;
623+ name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1;
624+ break;
625+ case KEX_GSS_GEX_SHA1:
626+ if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID))
627+ return GSS_C_NO_OID;
628+ name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1;
629+ break;
630+ default:
631+ return GSS_C_NO_OID;
632+ }
633+
634+ while (gss_enc2oid[i].encoded != NULL &&
635+ strcmp(name, gss_enc2oid[i].encoded) != 0)
636+ i++;
637+
638+ if (gss_enc2oid[i].oid != NULL && ctx != NULL)
639+ ssh_gssapi_set_oid(ctx, gss_enc2oid[i].oid);
640+
641+ return gss_enc2oid[i].oid;
642+}
643+
644 /* Check that the OID in a data stream matches that in the context */
645 int
646 ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len)
647@@ -199,7 +354,7 @@ ssh_gssapi_init_ctx(Gssctxt *ctx, int deleg_creds, gss_buffer_desc *recv_tok,
648 }
649
650 ctx->major = gss_init_sec_context(&ctx->minor,
651- GSS_C_NO_CREDENTIAL, &ctx->context, ctx->name, ctx->oid,
652+ ctx->client_creds, &ctx->context, ctx->name, ctx->oid,
653 GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag,
654 0, NULL, recv_tok, NULL, send_tok, flags, NULL);
655
656@@ -229,8 +384,42 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host)
657 }
658
659 OM_uint32
660+ssh_gssapi_client_identity(Gssctxt *ctx, const char *name)
661+{
662+ gss_buffer_desc gssbuf;
663+ gss_name_t gssname;
664+ OM_uint32 status;
665+ gss_OID_set oidset;
666+
667+ gssbuf.value = (void *) name;
668+ gssbuf.length = strlen(gssbuf.value);
669+
670+ gss_create_empty_oid_set(&status, &oidset);
671+ gss_add_oid_set_member(&status, ctx->oid, &oidset);
672+
673+ ctx->major = gss_import_name(&ctx->minor, &gssbuf,
674+ GSS_C_NT_USER_NAME, &gssname);
675+
676+ if (!ctx->major)
677+ ctx->major = gss_acquire_cred(&ctx->minor,
678+ gssname, 0, oidset, GSS_C_INITIATE,
679+ &ctx->client_creds, NULL, NULL);
680+
681+ gss_release_name(&status, &gssname);
682+ gss_release_oid_set(&status, &oidset);
683+
684+ if (ctx->major)
685+ ssh_gssapi_error(ctx);
686+
687+ return(ctx->major);
688+}
689+
690+OM_uint32
691 ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
692 {
693+ if (ctx == NULL)
694+ return -1;
695+
696 if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context,
697 GSS_C_QOP_DEFAULT, buffer, hash)))
698 ssh_gssapi_error(ctx);
699@@ -238,6 +427,19 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
700 return (ctx->major);
701 }
702
703+/* Priviledged when used by server */
704+OM_uint32
705+ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
706+{
707+ if (ctx == NULL)
708+ return -1;
709+
710+ ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
711+ gssbuf, gssmic, NULL);
712+
713+ return (ctx->major);
714+}
715+
716 void
717 ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service,
718 const char *context)
719@@ -251,11 +453,16 @@ ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service,
720 }
721
722 int
723-ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
724+ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host,
725+ const char *client)
726 {
727 gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
728 OM_uint32 major, minor;
729 gss_OID_desc spnego_oid = {6, (void *)"\x2B\x06\x01\x05\x05\x02"};
730+ Gssctxt *intctx = NULL;
731+
732+ if (ctx == NULL)
733+ ctx = &intctx;
734
735 /* RFC 4462 says we MUST NOT do SPNEGO */
736 if (oid->length == spnego_oid.length &&
737@@ -265,6 +472,10 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
738 ssh_gssapi_build_ctx(ctx);
739 ssh_gssapi_set_oid(*ctx, oid);
740 major = ssh_gssapi_import_name(*ctx, host);
741+
742+ if (!GSS_ERROR(major) && client)
743+ major = ssh_gssapi_client_identity(*ctx, client);
744+
745 if (!GSS_ERROR(major)) {
746 major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token,
747 NULL);
748@@ -274,10 +485,66 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
749 GSS_C_NO_BUFFER);
750 }
751
752- if (GSS_ERROR(major))
753+ if (GSS_ERROR(major) || intctx != NULL)
754 ssh_gssapi_delete_ctx(ctx);
755
756 return (!GSS_ERROR(major));
757 }
758
759+int
760+ssh_gssapi_credentials_updated(Gssctxt *ctxt) {
761+ static gss_name_t saved_name = GSS_C_NO_NAME;
762+ static OM_uint32 saved_lifetime = 0;
763+ static gss_OID saved_mech = GSS_C_NO_OID;
764+ static gss_name_t name;
765+ static OM_uint32 last_call = 0;
766+ OM_uint32 lifetime, now, major, minor;
767+ int equal;
768+
769+ now = time(NULL);
770+
771+ if (ctxt) {
772+ debug("Rekey has happened - updating saved versions");
773+
774+ if (saved_name != GSS_C_NO_NAME)
775+ gss_release_name(&minor, &saved_name);
776+
777+ major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
778+ &saved_name, &saved_lifetime, NULL, NULL);
779+
780+ if (!GSS_ERROR(major)) {
781+ saved_mech = ctxt->oid;
782+ saved_lifetime+= now;
783+ } else {
784+ /* Handle the error */
785+ }
786+ return 0;
787+ }
788+
789+ if (now - last_call < 10)
790+ return 0;
791+
792+ last_call = now;
793+
794+ if (saved_mech == GSS_C_NO_OID)
795+ return 0;
796+
797+ major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
798+ &name, &lifetime, NULL, NULL);
799+ if (major == GSS_S_CREDENTIALS_EXPIRED)
800+ return 0;
801+ else if (GSS_ERROR(major))
802+ return 0;
803+
804+ major = gss_compare_name(&minor, saved_name, name, &equal);
805+ gss_release_name(&minor, &name);
806+ if (GSS_ERROR(major))
807+ return 0;
808+
809+ if (equal && (saved_lifetime < lifetime + now - 10))
810+ return 1;
811+
812+ return 0;
813+}
814+
815 #endif /* GSSAPI */
816diff --git a/gss-serv-krb5.c b/gss-serv-krb5.c
817index 795992d..fd8b371 100644
818--- a/gss-serv-krb5.c
819+++ b/gss-serv-krb5.c
820@@ -1,7 +1,7 @@
821 /* $OpenBSD: gss-serv-krb5.c,v 1.8 2013/07/20 01:55:13 djm Exp $ */
822
823 /*
824- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
825+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
826 *
827 * Redistribution and use in source and binary forms, with or without
828 * modification, are permitted provided that the following conditions
829@@ -121,8 +121,8 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
830 krb5_error_code problem;
831 krb5_principal princ;
832 OM_uint32 maj_status, min_status;
833- int len;
834 const char *errmsg;
835+ const char *new_ccname;
836
837 if (client->creds == NULL) {
838 debug("No credentials stored");
839@@ -181,11 +181,16 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
840 return;
841 }
842
843- client->store.filename = xstrdup(krb5_cc_get_name(krb_context, ccache));
844+ new_ccname = krb5_cc_get_name(krb_context, ccache);
845+
846 client->store.envvar = "KRB5CCNAME";
847- len = strlen(client->store.filename) + 6;
848- client->store.envval = xmalloc(len);
849- snprintf(client->store.envval, len, "FILE:%s", client->store.filename);
850+#ifdef USE_CCAPI
851+ xasprintf(&client->store.envval, "API:%s", new_ccname);
852+ client->store.filename = NULL;
853+#else
854+ xasprintf(&client->store.envval, "FILE:%s", new_ccname);
855+ client->store.filename = xstrdup(new_ccname);
856+#endif
857
858 #ifdef USE_PAM
859 if (options.use_pam)
860@@ -197,6 +202,71 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
861 return;
862 }
863
864+int
865+ssh_gssapi_krb5_updatecreds(ssh_gssapi_ccache *store,
866+ ssh_gssapi_client *client)
867+{
868+ krb5_ccache ccache = NULL;
869+ krb5_principal principal = NULL;
870+ char *name = NULL;
871+ krb5_error_code problem;
872+ OM_uint32 maj_status, min_status;
873+
874+ if ((problem = krb5_cc_resolve(krb_context, store->envval, &ccache))) {
875+ logit("krb5_cc_resolve(): %.100s",
876+ krb5_get_err_text(krb_context, problem));
877+ return 0;
878+ }
879+
880+ /* Find out who the principal in this cache is */
881+ if ((problem = krb5_cc_get_principal(krb_context, ccache,
882+ &principal))) {
883+ logit("krb5_cc_get_principal(): %.100s",
884+ krb5_get_err_text(krb_context, problem));
885+ krb5_cc_close(krb_context, ccache);
886+ return 0;
887+ }
888+
889+ if ((problem = krb5_unparse_name(krb_context, principal, &name))) {
890+ logit("krb5_unparse_name(): %.100s",
891+ krb5_get_err_text(krb_context, problem));
892+ krb5_free_principal(krb_context, principal);
893+ krb5_cc_close(krb_context, ccache);
894+ return 0;
895+ }
896+
897+
898+ if (strcmp(name,client->exportedname.value)!=0) {
899+ debug("Name in local credentials cache differs. Not storing");
900+ krb5_free_principal(krb_context, principal);
901+ krb5_cc_close(krb_context, ccache);
902+ krb5_free_unparsed_name(krb_context, name);
903+ return 0;
904+ }
905+ krb5_free_unparsed_name(krb_context, name);
906+
907+ /* Name matches, so lets get on with it! */
908+
909+ if ((problem = krb5_cc_initialize(krb_context, ccache, principal))) {
910+ logit("krb5_cc_initialize(): %.100s",
911+ krb5_get_err_text(krb_context, problem));
912+ krb5_free_principal(krb_context, principal);
913+ krb5_cc_close(krb_context, ccache);
914+ return 0;
915+ }
916+
917+ krb5_free_principal(krb_context, principal);
918+
919+ if ((maj_status = gss_krb5_copy_ccache(&min_status, client->creds,
920+ ccache))) {
921+ logit("gss_krb5_copy_ccache() failed. Sorry!");
922+ krb5_cc_close(krb_context, ccache);
923+ return 0;
924+ }
925+
926+ return 1;
927+}
928+
929 ssh_gssapi_mech gssapi_kerberos_mech = {
930 "toWM5Slw5Ew8Mqkay+al2g==",
931 "Kerberos",
932@@ -204,7 +274,8 @@ ssh_gssapi_mech gssapi_kerberos_mech = {
933 NULL,
934 &ssh_gssapi_krb5_userok,
935 NULL,
936- &ssh_gssapi_krb5_storecreds
937+ &ssh_gssapi_krb5_storecreds,
938+ &ssh_gssapi_krb5_updatecreds
939 };
940
941 #endif /* KRB5 */
942diff --git a/gss-serv.c b/gss-serv.c
943index 53993d6..2f6baf7 100644
944--- a/gss-serv.c
945+++ b/gss-serv.c
946@@ -1,7 +1,7 @@
947 /* $OpenBSD: gss-serv.c,v 1.29 2015/05/22 03:50:02 djm Exp $ */
948
949 /*
950- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
951+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
952 *
953 * Redistribution and use in source and binary forms, with or without
954 * modification, are permitted provided that the following conditions
955@@ -45,17 +45,22 @@
956 #include "session.h"
957 #include "misc.h"
958 #include "servconf.h"
959+#include "uidswap.h"
960
961 #include "ssh-gss.h"
962+#include "monitor_wrap.h"
963+
964+extern ServerOptions options;
965
966 extern ServerOptions options;
967
968 static ssh_gssapi_client gssapi_client =
969 { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER,
970- GSS_C_NO_CREDENTIAL, NULL, {NULL, NULL, NULL, NULL}};
971+ GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME, NULL,
972+ {NULL, NULL, NULL, NULL, NULL}, 0, 0};
973
974 ssh_gssapi_mech gssapi_null_mech =
975- { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL};
976+ { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL, NULL};
977
978 #ifdef KRB5
979 extern ssh_gssapi_mech gssapi_kerberos_mech;
980@@ -142,6 +147,29 @@ ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID oid)
981 }
982
983 /* Unprivileged */
984+char *
985+ssh_gssapi_server_mechanisms(void) {
986+ gss_OID_set supported;
987+
988+ ssh_gssapi_supported_oids(&supported);
989+ return (ssh_gssapi_kex_mechs(supported, &ssh_gssapi_server_check_mech,
990+ NULL, NULL));
991+}
992+
993+/* Unprivileged */
994+int
995+ssh_gssapi_server_check_mech(Gssctxt **dum, gss_OID oid, const char *data,
996+ const char *dummy) {
997+ Gssctxt *ctx = NULL;
998+ int res;
999+
1000+ res = !GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctx, oid)));
1001+ ssh_gssapi_delete_ctx(&ctx);
1002+
1003+ return (res);
1004+}
1005+
1006+/* Unprivileged */
1007 void
1008 ssh_gssapi_supported_oids(gss_OID_set *oidset)
1009 {
1010@@ -151,7 +179,9 @@ ssh_gssapi_supported_oids(gss_OID_set *oidset)
1011 gss_OID_set supported;
1012
1013 gss_create_empty_oid_set(&min_status, oidset);
1014- gss_indicate_mechs(&min_status, &supported);
1015+
1016+ if (GSS_ERROR(gss_indicate_mechs(&min_status, &supported)))
1017+ return;
1018
1019 while (supported_mechs[i]->name != NULL) {
1020 if (GSS_ERROR(gss_test_oid_set_member(&min_status,
1021@@ -277,8 +307,48 @@ OM_uint32
1022 ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1023 {
1024 int i = 0;
1025+ int equal = 0;
1026+ gss_name_t new_name = GSS_C_NO_NAME;
1027+ gss_buffer_desc ename = GSS_C_EMPTY_BUFFER;
1028+
1029+ if (options.gss_store_rekey && client->used && ctx->client_creds) {
1030+ if (client->mech->oid.length != ctx->oid->length ||
1031+ (memcmp(client->mech->oid.elements,
1032+ ctx->oid->elements, ctx->oid->length) !=0)) {
1033+ debug("Rekeyed credentials have different mechanism");
1034+ return GSS_S_COMPLETE;
1035+ }
1036+
1037+ if ((ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
1038+ ctx->client_creds, ctx->oid, &new_name,
1039+ NULL, NULL, NULL))) {
1040+ ssh_gssapi_error(ctx);
1041+ return (ctx->major);
1042+ }
1043+
1044+ ctx->major = gss_compare_name(&ctx->minor, client->name,
1045+ new_name, &equal);
1046+
1047+ if (GSS_ERROR(ctx->major)) {
1048+ ssh_gssapi_error(ctx);
1049+ return (ctx->major);
1050+ }
1051+
1052+ if (!equal) {
1053+ debug("Rekeyed credentials have different name");
1054+ return GSS_S_COMPLETE;
1055+ }
1056
1057- gss_buffer_desc ename;
1058+ debug("Marking rekeyed credentials for export");
1059+
1060+ gss_release_name(&ctx->minor, &client->name);
1061+ gss_release_cred(&ctx->minor, &client->creds);
1062+ client->name = new_name;
1063+ client->creds = ctx->client_creds;
1064+ ctx->client_creds = GSS_C_NO_CREDENTIAL;
1065+ client->updated = 1;
1066+ return GSS_S_COMPLETE;
1067+ }
1068
1069 client->mech = NULL;
1070
1071@@ -293,6 +363,13 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1072 if (client->mech == NULL)
1073 return GSS_S_FAILURE;
1074
1075+ if (ctx->client_creds &&
1076+ (ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
1077+ ctx->client_creds, ctx->oid, &client->name, NULL, NULL, NULL))) {
1078+ ssh_gssapi_error(ctx);
1079+ return (ctx->major);
1080+ }
1081+
1082 if ((ctx->major = gss_display_name(&ctx->minor, ctx->client,
1083 &client->displayname, NULL))) {
1084 ssh_gssapi_error(ctx);
1085@@ -310,6 +387,8 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1086 return (ctx->major);
1087 }
1088
1089+ gss_release_buffer(&ctx->minor, &ename);
1090+
1091 /* We can't copy this structure, so we just move the pointer to it */
1092 client->creds = ctx->client_creds;
1093 ctx->client_creds = GSS_C_NO_CREDENTIAL;
1094@@ -357,7 +436,7 @@ ssh_gssapi_do_child(char ***envp, u_int *envsizep)
1095
1096 /* Privileged */
1097 int
1098-ssh_gssapi_userok(char *user)
1099+ssh_gssapi_userok(char *user, struct passwd *pw)
1100 {
1101 OM_uint32 lmin;
1102
1103@@ -367,9 +446,11 @@ ssh_gssapi_userok(char *user)
1104 return 0;
1105 }
1106 if (gssapi_client.mech && gssapi_client.mech->userok)
1107- if ((*gssapi_client.mech->userok)(&gssapi_client, user))
1108+ if ((*gssapi_client.mech->userok)(&gssapi_client, user)) {
1109+ gssapi_client.used = 1;
1110+ gssapi_client.store.owner = pw;
1111 return 1;
1112- else {
1113+ } else {
1114 /* Destroy delegated credentials if userok fails */
1115 gss_release_buffer(&lmin, &gssapi_client.displayname);
1116 gss_release_buffer(&lmin, &gssapi_client.exportedname);
1117@@ -383,14 +464,90 @@ ssh_gssapi_userok(char *user)
1118 return (0);
1119 }
1120
1121-/* Privileged */
1122-OM_uint32
1123-ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
1124+/* These bits are only used for rekeying. The unpriviledged child is running
1125+ * as the user, the monitor is root.
1126+ *
1127+ * In the child, we want to :
1128+ * *) Ask the monitor to store our credentials into the store we specify
1129+ * *) If it succeeds, maybe do a PAM update
1130+ */
1131+
1132+/* Stuff for PAM */
1133+
1134+#ifdef USE_PAM
1135+static int ssh_gssapi_simple_conv(int n, const struct pam_message **msg,
1136+ struct pam_response **resp, void *data)
1137 {
1138- ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
1139- gssbuf, gssmic, NULL);
1140+ return (PAM_CONV_ERR);
1141+}
1142+#endif
1143
1144- return (ctx->major);
1145+void
1146+ssh_gssapi_rekey_creds(void) {
1147+ int ok;
1148+ int ret;
1149+#ifdef USE_PAM
1150+ pam_handle_t *pamh = NULL;
1151+ struct pam_conv pamconv = {ssh_gssapi_simple_conv, NULL};
1152+ char *envstr;
1153+#endif
1154+
1155+ if (gssapi_client.store.filename == NULL &&
1156+ gssapi_client.store.envval == NULL &&
1157+ gssapi_client.store.envvar == NULL)
1158+ return;
1159+
1160+ ok = PRIVSEP(ssh_gssapi_update_creds(&gssapi_client.store));
1161+
1162+ if (!ok)
1163+ return;
1164+
1165+ debug("Rekeyed credentials stored successfully");
1166+
1167+ /* Actually managing to play with the ssh pam stack from here will
1168+ * be next to impossible. In any case, we may want different options
1169+ * for rekeying. So, use our own :)
1170+ */
1171+#ifdef USE_PAM
1172+ if (!use_privsep) {
1173+ debug("Not even going to try and do PAM with privsep disabled");
1174+ return;
1175+ }
1176+
1177+ ret = pam_start("sshd-rekey", gssapi_client.store.owner->pw_name,
1178+ &pamconv, &pamh);
1179+ if (ret)
1180+ return;
1181+
1182+ xasprintf(&envstr, "%s=%s", gssapi_client.store.envvar,
1183+ gssapi_client.store.envval);
1184+
1185+ ret = pam_putenv(pamh, envstr);
1186+ if (!ret)
1187+ pam_setcred(pamh, PAM_REINITIALIZE_CRED);
1188+ pam_end(pamh, PAM_SUCCESS);
1189+#endif
1190+}
1191+
1192+int
1193+ssh_gssapi_update_creds(ssh_gssapi_ccache *store) {
1194+ int ok = 0;
1195+
1196+ /* Check we've got credentials to store */
1197+ if (!gssapi_client.updated)
1198+ return 0;
1199+
1200+ gssapi_client.updated = 0;
1201+
1202+ temporarily_use_uid(gssapi_client.store.owner);
1203+ if (gssapi_client.mech && gssapi_client.mech->updatecreds)
1204+ ok = (*gssapi_client.mech->updatecreds)(store, &gssapi_client);
1205+ else
1206+ debug("No update function for this mechanism");
1207+
1208+ restore_uid();
1209+
1210+ return ok;
1211 }
1212
1213 #endif
1214diff --git a/kex.c b/kex.c
1215index b777b7d..390bb69 100644
1216--- a/kex.c
1217+++ b/kex.c
1218@@ -55,6 +55,10 @@
1219 #include "sshbuf.h"
1220 #include "digest.h"
1221
1222+#ifdef GSSAPI
1223+#include "ssh-gss.h"
1224+#endif
1225+
1226 #if OPENSSL_VERSION_NUMBER >= 0x00907000L
1227 # if defined(HAVE_EVP_SHA256)
1228 # define evp_ssh_sha256 EVP_sha256
1229@@ -97,6 +101,14 @@ static const struct kexalg kexalgs[] = {
1230 #endif /* HAVE_EVP_SHA256 || !WITH_OPENSSL */
1231 { NULL, -1, -1, -1},
1232 };
1233+static const struct kexalg kexalg_prefixes[] = {
1234+#ifdef GSSAPI
1235+ { KEX_GSS_GEX_SHA1_ID, KEX_GSS_GEX_SHA1, 0, SSH_DIGEST_SHA1 },
1236+ { KEX_GSS_GRP1_SHA1_ID, KEX_GSS_GRP1_SHA1, 0, SSH_DIGEST_SHA1 },
1237+ { KEX_GSS_GRP14_SHA1_ID, KEX_GSS_GRP14_SHA1, 0, SSH_DIGEST_SHA1 },
1238+#endif
1239+ { NULL, -1, -1, -1 },
1240+};
1241
1242 char *
1243 kex_alg_list(char sep)
1244@@ -129,6 +141,10 @@ kex_alg_by_name(const char *name)
1245 if (strcmp(k->name, name) == 0)
1246 return k;
1247 }
1248+ for (k = kexalg_prefixes; k->name != NULL; k++) {
1249+ if (strncmp(k->name, name, strlen(k->name)) == 0)
1250+ return k;
1251+ }
1252 return NULL;
1253 }
1254
1255diff --git a/kex.h b/kex.h
1256index d71b532..ee46815 100644
1257--- a/kex.h
1258+++ b/kex.h
1259@@ -93,6 +93,9 @@ enum kex_exchange {
1260 KEX_DH_GEX_SHA256,
1261 KEX_ECDH_SHA2,
1262 KEX_C25519_SHA256,
1263+ KEX_GSS_GRP1_SHA1,
1264+ KEX_GSS_GRP14_SHA1,
1265+ KEX_GSS_GEX_SHA1,
1266 KEX_MAX
1267 };
1268
1269@@ -139,6 +142,12 @@ struct kex {
1270 u_int flags;
1271 int hash_alg;
1272 int ec_nid;
1273+#ifdef GSSAPI
1274+ int gss_deleg_creds;
1275+ int gss_trust_dns;
1276+ char *gss_host;
1277+ char *gss_client;
1278+#endif
1279 char *client_version_string;
1280 char *server_version_string;
1281 char *failed_choice;
1282@@ -187,6 +196,11 @@ int kexecdh_server(struct ssh *);
1283 int kexc25519_client(struct ssh *);
1284 int kexc25519_server(struct ssh *);
1285
1286+#ifdef GSSAPI
1287+int kexgss_client(struct ssh *);
1288+int kexgss_server(struct ssh *);
1289+#endif
1290+
1291 int kex_dh_hash(const char *, const char *,
1292 const u_char *, size_t, const u_char *, size_t, const u_char *, size_t,
1293 const BIGNUM *, const BIGNUM *, const BIGNUM *, u_char *, size_t *);
1294diff --git a/kexgssc.c b/kexgssc.c
1295new file mode 100644
1296index 0000000..a49bac2
1297--- /dev/null
1298+++ b/kexgssc.c
1299@@ -0,0 +1,336 @@
1300+/*
1301+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1302+ *
1303+ * Redistribution and use in source and binary forms, with or without
1304+ * modification, are permitted provided that the following conditions
1305+ * are met:
1306+ * 1. Redistributions of source code must retain the above copyright
1307+ * notice, this list of conditions and the following disclaimer.
1308+ * 2. Redistributions in binary form must reproduce the above copyright
1309+ * notice, this list of conditions and the following disclaimer in the
1310+ * documentation and/or other materials provided with the distribution.
1311+ *
1312+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1313+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1314+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1315+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1316+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1317+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1318+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1319+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1320+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1321+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1322+ */
1323+
1324+#include "includes.h"
1325+
1326+#ifdef GSSAPI
1327+
1328+#include "includes.h"
1329+
1330+#include <openssl/crypto.h>
1331+#include <openssl/bn.h>
1332+
1333+#include <string.h>
1334+
1335+#include "xmalloc.h"
1336+#include "buffer.h"
1337+#include "ssh2.h"
1338+#include "key.h"
1339+#include "cipher.h"
1340+#include "kex.h"
1341+#include "log.h"
1342+#include "packet.h"
1343+#include "dh.h"
1344+#include "digest.h"
1345+
1346+#include "ssh-gss.h"
1347+
1348+int
1349+kexgss_client(struct ssh *ssh) {
1350+ gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
1351+ gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
1352+ Gssctxt *ctxt;
1353+ OM_uint32 maj_status, min_status, ret_flags;
1354+ u_int klen, kout, slen = 0, strlen;
1355+ DH *dh;
1356+ BIGNUM *dh_server_pub = NULL;
1357+ BIGNUM *shared_secret = NULL;
1358+ BIGNUM *p = NULL;
1359+ BIGNUM *g = NULL;
1360+ u_char *kbuf;
1361+ u_char *serverhostkey = NULL;
1362+ u_char *empty = "";
1363+ char *msg;
1364+ int type = 0;
1365+ int first = 1;
1366+ int nbits = 0, min = DH_GRP_MIN, max = DH_GRP_MAX;
1367+ u_char hash[SSH_DIGEST_MAX_LENGTH];
1368+ size_t hashlen;
1369+
1370+ /* Initialise our GSSAPI world */
1371+ ssh_gssapi_build_ctx(&ctxt);
1372+ if (ssh_gssapi_id_kex(ctxt, ssh->kex->name, ssh->kex->kex_type)
1373+ == GSS_C_NO_OID)
1374+ fatal("Couldn't identify host exchange");
1375+
1376+ if (ssh_gssapi_import_name(ctxt, ssh->kex->gss_host))
1377+ fatal("Couldn't import hostname");
1378+
1379+ if (ssh->kex->gss_client &&
1380+ ssh_gssapi_client_identity(ctxt, ssh->kex->gss_client))
1381+ fatal("Couldn't acquire client credentials");
1382+
1383+ switch (ssh->kex->kex_type) {
1384+ case KEX_GSS_GRP1_SHA1:
1385+ dh = dh_new_group1();
1386+ break;
1387+ case KEX_GSS_GRP14_SHA1:
1388+ dh = dh_new_group14();
1389+ break;
1390+ case KEX_GSS_GEX_SHA1:
1391+ debug("Doing group exchange\n");
1392+ nbits = dh_estimate(ssh->kex->we_need * 8);
1393+ packet_start(SSH2_MSG_KEXGSS_GROUPREQ);
1394+ packet_put_int(min);
1395+ packet_put_int(nbits);
1396+ packet_put_int(max);
1397+
1398+ packet_send();
1399+
1400+ packet_read_expect(SSH2_MSG_KEXGSS_GROUP);
1401+
1402+ if ((p = BN_new()) == NULL)
1403+ fatal("BN_new() failed");
1404+ packet_get_bignum2(p);
1405+ if ((g = BN_new()) == NULL)
1406+ fatal("BN_new() failed");
1407+ packet_get_bignum2(g);
1408+ packet_check_eom();
1409+
1410+ if (BN_num_bits(p) < min || BN_num_bits(p) > max)
1411+ fatal("GSSGRP_GEX group out of range: %d !< %d !< %d",
1412+ min, BN_num_bits(p), max);
1413+
1414+ dh = dh_new_group(g, p);
1415+ break;
1416+ default:
1417+ fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type);
1418+ }
1419+
1420+ /* Step 1 - e is dh->pub_key */
1421+ dh_gen_key(dh, ssh->kex->we_need * 8);
1422+
1423+ /* This is f, we initialise it now to make life easier */
1424+ dh_server_pub = BN_new();
1425+ if (dh_server_pub == NULL)
1426+ fatal("dh_server_pub == NULL");
1427+
1428+ token_ptr = GSS_C_NO_BUFFER;
1429+
1430+ do {
1431+ debug("Calling gss_init_sec_context");
1432+
1433+ maj_status = ssh_gssapi_init_ctx(ctxt,
1434+ ssh->kex->gss_deleg_creds, token_ptr, &send_tok,
1435+ &ret_flags);
1436+
1437+ if (GSS_ERROR(maj_status)) {
1438+ if (send_tok.length != 0) {
1439+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1440+ packet_put_string(send_tok.value,
1441+ send_tok.length);
1442+ }
1443+ fatal("gss_init_context failed");
1444+ }
1445+
1446+ /* If we've got an old receive buffer get rid of it */
1447+ if (token_ptr != GSS_C_NO_BUFFER)
1448+ free(recv_tok.value);
1449+
1450+ if (maj_status == GSS_S_COMPLETE) {
1451+ /* If mutual state flag is not true, kex fails */
1452+ if (!(ret_flags & GSS_C_MUTUAL_FLAG))
1453+ fatal("Mutual authentication failed");
1454+
1455+ /* If integ avail flag is not true kex fails */
1456+ if (!(ret_flags & GSS_C_INTEG_FLAG))
1457+ fatal("Integrity check failed");
1458+ }
1459+
1460+ /*
1461+ * If we have data to send, then the last message that we
1462+ * received cannot have been a 'complete'.
1463+ */
1464+ if (send_tok.length != 0) {
1465+ if (first) {
1466+ packet_start(SSH2_MSG_KEXGSS_INIT);
1467+ packet_put_string(send_tok.value,
1468+ send_tok.length);
1469+ packet_put_bignum2(dh->pub_key);
1470+ first = 0;
1471+ } else {
1472+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1473+ packet_put_string(send_tok.value,
1474+ send_tok.length);
1475+ }
1476+ packet_send();
1477+ gss_release_buffer(&min_status, &send_tok);
1478+
1479+ /* If we've sent them data, they should reply */
1480+ do {
1481+ type = packet_read();
1482+ if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
1483+ debug("Received KEXGSS_HOSTKEY");
1484+ if (serverhostkey)
1485+ fatal("Server host key received more than once");
1486+ serverhostkey =
1487+ packet_get_string(&slen);
1488+ }
1489+ } while (type == SSH2_MSG_KEXGSS_HOSTKEY);
1490+
1491+ switch (type) {
1492+ case SSH2_MSG_KEXGSS_CONTINUE:
1493+ debug("Received GSSAPI_CONTINUE");
1494+ if (maj_status == GSS_S_COMPLETE)
1495+ fatal("GSSAPI Continue received from server when complete");
1496+ recv_tok.value = packet_get_string(&strlen);
1497+ recv_tok.length = strlen;
1498+ break;
1499+ case SSH2_MSG_KEXGSS_COMPLETE:
1500+ debug("Received GSSAPI_COMPLETE");
1501+ packet_get_bignum2(dh_server_pub);
1502+ msg_tok.value = packet_get_string(&strlen);
1503+ msg_tok.length = strlen;
1504+
1505+ /* Is there a token included? */
1506+ if (packet_get_char()) {
1507+ recv_tok.value=
1508+ packet_get_string(&strlen);
1509+ recv_tok.length = strlen;
1510+ /* If we're already complete - protocol error */
1511+ if (maj_status == GSS_S_COMPLETE)
1512+ packet_disconnect("Protocol error: received token when complete");
1513+ } else {
1514+ /* No token included */
1515+ if (maj_status != GSS_S_COMPLETE)
1516+ packet_disconnect("Protocol error: did not receive final token");
1517+ }
1518+ break;
1519+ case SSH2_MSG_KEXGSS_ERROR:
1520+ debug("Received Error");
1521+ maj_status = packet_get_int();
1522+ min_status = packet_get_int();
1523+ msg = packet_get_string(NULL);
1524+ (void) packet_get_string_ptr(NULL);
1525+ fatal("GSSAPI Error: \n%.400s",msg);
1526+ default:
1527+ packet_disconnect("Protocol error: didn't expect packet type %d",
1528+ type);
1529+ }
1530+ token_ptr = &recv_tok;
1531+ } else {
1532+ /* No data, and not complete */
1533+ if (maj_status != GSS_S_COMPLETE)
1534+ fatal("Not complete, and no token output");
1535+ }
1536+ } while (maj_status & GSS_S_CONTINUE_NEEDED);
1537+
1538+ /*
1539+ * We _must_ have received a COMPLETE message in reply from the
1540+ * server, which will have set dh_server_pub and msg_tok
1541+ */
1542+
1543+ if (type != SSH2_MSG_KEXGSS_COMPLETE)
1544+ fatal("Didn't receive a SSH2_MSG_KEXGSS_COMPLETE when I expected it");
1545+
1546+ /* Check f in range [1, p-1] */
1547+ if (!dh_pub_is_valid(dh, dh_server_pub))
1548+ packet_disconnect("bad server public DH value");
1549+
1550+ /* compute K=f^x mod p */
1551+ klen = DH_size(dh);
1552+ kbuf = xmalloc(klen);
1553+ kout = DH_compute_key(kbuf, dh_server_pub, dh);
1554+ if (kout < 0)
1555+ fatal("DH_compute_key: failed");
1556+
1557+ shared_secret = BN_new();
1558+ if (shared_secret == NULL)
1559+ fatal("kexgss_client: BN_new failed");
1560+
1561+ if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
1562+ fatal("kexdh_client: BN_bin2bn failed");
1563+
1564+ memset(kbuf, 0, klen);
1565+ free(kbuf);
1566+
1567+ hashlen = sizeof(hash);
1568+ switch (ssh->kex->kex_type) {
1569+ case KEX_GSS_GRP1_SHA1:
1570+ case KEX_GSS_GRP14_SHA1:
1571+ kex_dh_hash( ssh->kex->client_version_string,
1572+ ssh->kex->server_version_string,
1573+ buffer_ptr(ssh->kex->my), buffer_len(ssh->kex->my),
1574+ buffer_ptr(ssh->kex->peer), buffer_len(ssh->kex->peer),
1575+ (serverhostkey ? serverhostkey : empty), slen,
1576+ dh->pub_key, /* e */
1577+ dh_server_pub, /* f */
1578+ shared_secret, /* K */
1579+ hash, &hashlen
1580+ );
1581+ break;
1582+ case KEX_GSS_GEX_SHA1:
1583+ kexgex_hash(
1584+ ssh->kex->hash_alg,
1585+ ssh->kex->client_version_string,
1586+ ssh->kex->server_version_string,
1587+ buffer_ptr(ssh->kex->my), buffer_len(ssh->kex->my),
1588+ buffer_ptr(ssh->kex->peer), buffer_len(ssh->kex->peer),
1589+ (serverhostkey ? serverhostkey : empty), slen,
1590+ min, nbits, max,
1591+ dh->p, dh->g,
1592+ dh->pub_key,
1593+ dh_server_pub,
1594+ shared_secret,
1595+ hash, &hashlen
1596+ );
1597+ break;
1598+ default:
1599+ fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type);
1600+ }
1601+
1602+ gssbuf.value = hash;
1603+ gssbuf.length = hashlen;
1604+
1605+ /* Verify that the hash matches the MIC we just got. */
1606+ if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
1607+ packet_disconnect("Hash's MIC didn't verify");
1608+
1609+ free(msg_tok.value);
1610+
1611+ DH_free(dh);
1612+ free(serverhostkey);
1613+ BN_clear_free(dh_server_pub);
1614+
1615+ /* save session id */
1616+ if (ssh->kex->session_id == NULL) {
1617+ ssh->kex->session_id_len = hashlen;
1618+ ssh->kex->session_id = xmalloc(ssh->kex->session_id_len);
1619+ memcpy(ssh->kex->session_id, hash, ssh->kex->session_id_len);
1620+ }
1621+
1622+ if (ssh->kex->gss_deleg_creds)
1623+ ssh_gssapi_credentials_updated(ctxt);
1624+
1625+ if (gss_kex_context == NULL)
1626+ gss_kex_context = ctxt;
1627+ else
1628+ ssh_gssapi_delete_ctx(&ctxt);
1629+
1630+ kex_derive_keys_bn(ssh, hash, hashlen, shared_secret);
1631+ BN_clear_free(shared_secret);
1632+ return kex_send_newkeys(ssh);
1633+}
1634+
1635+#endif /* GSSAPI */
1636diff --git a/kexgsss.c b/kexgsss.c
1637new file mode 100644
1638index 0000000..0847469
1639--- /dev/null
1640+++ b/kexgsss.c
1641@@ -0,0 +1,295 @@
1642+/*
1643+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1644+ *
1645+ * Redistribution and use in source and binary forms, with or without
1646+ * modification, are permitted provided that the following conditions
1647+ * are met:
1648+ * 1. Redistributions of source code must retain the above copyright
1649+ * notice, this list of conditions and the following disclaimer.
1650+ * 2. Redistributions in binary form must reproduce the above copyright
1651+ * notice, this list of conditions and the following disclaimer in the
1652+ * documentation and/or other materials provided with the distribution.
1653+ *
1654+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1655+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1656+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1657+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1658+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1659+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1660+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1661+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1662+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1663+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1664+ */
1665+
1666+#include "includes.h"
1667+
1668+#ifdef GSSAPI
1669+
1670+#include <string.h>
1671+
1672+#include <openssl/crypto.h>
1673+#include <openssl/bn.h>
1674+
1675+#include "xmalloc.h"
1676+#include "buffer.h"
1677+#include "ssh2.h"
1678+#include "key.h"
1679+#include "cipher.h"
1680+#include "kex.h"
1681+#include "log.h"
1682+#include "packet.h"
1683+#include "dh.h"
1684+#include "ssh-gss.h"
1685+#include "monitor_wrap.h"
1686+#include "misc.h"
1687+#include "servconf.h"
1688+#include "digest.h"
1689+
1690+extern ServerOptions options;
1691+
1692+int
1693+kexgss_server(struct ssh *ssh)
1694+{
1695+ OM_uint32 maj_status, min_status;
1696+
1697+ /*
1698+ * Some GSSAPI implementations use the input value of ret_flags (an
1699+ * output variable) as a means of triggering mechanism specific
1700+ * features. Initializing it to zero avoids inadvertently
1701+ * activating this non-standard behaviour.
1702+ */
1703+
1704+ OM_uint32 ret_flags = 0;
1705+ gss_buffer_desc gssbuf, recv_tok, msg_tok;
1706+ gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
1707+ Gssctxt *ctxt = NULL;
1708+ u_int slen, klen, kout;
1709+ u_char *kbuf;
1710+ DH *dh;
1711+ int min = -1, max = -1, nbits = -1;
1712+ BIGNUM *shared_secret = NULL;
1713+ BIGNUM *dh_client_pub = NULL;
1714+ int type = 0;
1715+ gss_OID oid;
1716+ char *mechs;
1717+ u_char hash[SSH_DIGEST_MAX_LENGTH];
1718+ size_t hashlen;
1719+
1720+ /* Initialise GSSAPI */
1721+
1722+ /* If we're rekeying, privsep means that some of the private structures
1723+ * in the GSSAPI code are no longer available. This kludges them back
1724+ * into life
1725+ */
1726+ if (!ssh_gssapi_oid_table_ok()) {
1727+ mechs = ssh_gssapi_server_mechanisms();
1728+ free(mechs);
1729+ }
1730+
1731+ debug2("%s: Identifying %s", __func__, ssh->kex->name);
1732+ oid = ssh_gssapi_id_kex(NULL, ssh->kex->name, ssh->kex->kex_type);
1733+ if (oid == GSS_C_NO_OID)
1734+ fatal("Unknown gssapi mechanism");
1735+
1736+ debug2("%s: Acquiring credentials", __func__);
1737+
1738+ if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid))))
1739+ fatal("Unable to acquire credentials for the server");
1740+
1741+ switch (ssh->kex->kex_type) {
1742+ case KEX_GSS_GRP1_SHA1:
1743+ dh = dh_new_group1();
1744+ break;
1745+ case KEX_GSS_GRP14_SHA1:
1746+ dh = dh_new_group14();
1747+ break;
1748+ case KEX_GSS_GEX_SHA1:
1749+ debug("Doing group exchange");
1750+ packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ);
1751+ min = packet_get_int();
1752+ nbits = packet_get_int();
1753+ max = packet_get_int();
1754+ min = MAX(DH_GRP_MIN, min);
1755+ max = MIN(DH_GRP_MAX, max);
1756+ packet_check_eom();
1757+ if (max < min || nbits < min || max < nbits)
1758+ fatal("GSS_GEX, bad parameters: %d !< %d !< %d",
1759+ min, nbits, max);
1760+ dh = PRIVSEP(choose_dh(min, nbits, max));
1761+ if (dh == NULL)
1762+ packet_disconnect("Protocol error: no matching group found");
1763+
1764+ packet_start(SSH2_MSG_KEXGSS_GROUP);
1765+ packet_put_bignum2(dh->p);
1766+ packet_put_bignum2(dh->g);
1767+ packet_send();
1768+
1769+ packet_write_wait();
1770+ break;
1771+ default:
1772+ fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type);
1773+ }
1774+
1775+ dh_gen_key(dh, ssh->kex->we_need * 8);
1776+
1777+ do {
1778+ debug("Wait SSH2_MSG_GSSAPI_INIT");
1779+ type = packet_read();
1780+ switch(type) {
1781+ case SSH2_MSG_KEXGSS_INIT:
1782+ if (dh_client_pub != NULL)
1783+ fatal("Received KEXGSS_INIT after initialising");
1784+ recv_tok.value = packet_get_string(&slen);
1785+ recv_tok.length = slen;
1786+
1787+ if ((dh_client_pub = BN_new()) == NULL)
1788+ fatal("dh_client_pub == NULL");
1789+
1790+ packet_get_bignum2(dh_client_pub);
1791+
1792+ /* Send SSH_MSG_KEXGSS_HOSTKEY here, if we want */
1793+ break;
1794+ case SSH2_MSG_KEXGSS_CONTINUE:
1795+ recv_tok.value = packet_get_string(&slen);
1796+ recv_tok.length = slen;
1797+ break;
1798+ default:
1799+ packet_disconnect(
1800+ "Protocol error: didn't expect packet type %d",
1801+ type);
1802+ }
1803+
1804+ maj_status = PRIVSEP(ssh_gssapi_accept_ctx(ctxt, &recv_tok,
1805+ &send_tok, &ret_flags));
1806+
1807+ free(recv_tok.value);
1808+
1809+ if (maj_status != GSS_S_COMPLETE && send_tok.length == 0)
1810+ fatal("Zero length token output when incomplete");
1811+
1812+ if (dh_client_pub == NULL)
1813+ fatal("No client public key");
1814+
1815+ if (maj_status & GSS_S_CONTINUE_NEEDED) {
1816+ debug("Sending GSSAPI_CONTINUE");
1817+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1818+ packet_put_string(send_tok.value, send_tok.length);
1819+ packet_send();
1820+ gss_release_buffer(&min_status, &send_tok);
1821+ }
1822+ } while (maj_status & GSS_S_CONTINUE_NEEDED);
1823+
1824+ if (GSS_ERROR(maj_status)) {
1825+ if (send_tok.length > 0) {
1826+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1827+ packet_put_string(send_tok.value, send_tok.length);
1828+ packet_send();
1829+ }
1830+ fatal("accept_ctx died");
1831+ }
1832+
1833+ if (!(ret_flags & GSS_C_MUTUAL_FLAG))
1834+ fatal("Mutual Authentication flag wasn't set");
1835+
1836+ if (!(ret_flags & GSS_C_INTEG_FLAG))
1837+ fatal("Integrity flag wasn't set");
1838+
1839+ if (!dh_pub_is_valid(dh, dh_client_pub))
1840+ packet_disconnect("bad client public DH value");
1841+
1842+ klen = DH_size(dh);
1843+ kbuf = xmalloc(klen);
1844+ kout = DH_compute_key(kbuf, dh_client_pub, dh);
1845+ if (kout < 0)
1846+ fatal("DH_compute_key: failed");
1847+
1848+ shared_secret = BN_new();
1849+ if (shared_secret == NULL)
1850+ fatal("kexgss_server: BN_new failed");
1851+
1852+ if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
1853+ fatal("kexgss_server: BN_bin2bn failed");
1854+
1855+ memset(kbuf, 0, klen);
1856+ free(kbuf);
1857+
1858+ hashlen = sizeof(hash);
1859+ switch (ssh->kex->kex_type) {
1860+ case KEX_GSS_GRP1_SHA1:
1861+ case KEX_GSS_GRP14_SHA1:
1862+ kex_dh_hash(
1863+ ssh->kex->client_version_string, ssh->kex->server_version_string,
1864+ buffer_ptr(ssh->kex->peer), buffer_len(ssh->kex->peer),
1865+ buffer_ptr(ssh->kex->my), buffer_len(ssh->kex->my),
1866+ NULL, 0, /* Change this if we start sending host keys */
1867+ dh_client_pub, dh->pub_key, shared_secret,
1868+ hash, &hashlen
1869+ );
1870+ break;
1871+ case KEX_GSS_GEX_SHA1:
1872+ kexgex_hash(
1873+ ssh->kex->hash_alg,
1874+ ssh->kex->client_version_string, ssh->kex->server_version_string,
1875+ buffer_ptr(ssh->kex->peer), buffer_len(ssh->kex->peer),
1876+ buffer_ptr(ssh->kex->my), buffer_len(ssh->kex->my),
1877+ NULL, 0,
1878+ min, nbits, max,
1879+ dh->p, dh->g,
1880+ dh_client_pub,
1881+ dh->pub_key,
1882+ shared_secret,
1883+ hash, &hashlen
1884+ );
1885+ break;
1886+ default:
1887+ fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type);
1888+ }
1889+
1890+ BN_clear_free(dh_client_pub);
1891+
1892+ if (ssh->kex->session_id == NULL) {
1893+ ssh->kex->session_id_len = hashlen;
1894+ ssh->kex->session_id = xmalloc(ssh->kex->session_id_len);
1895+ memcpy(ssh->kex->session_id, hash, ssh->kex->session_id_len);
1896+ }
1897+
1898+ gssbuf.value = hash;
1899+ gssbuf.length = hashlen;
1900+
1901+ if (GSS_ERROR(PRIVSEP(ssh_gssapi_sign(ctxt,&gssbuf,&msg_tok))))
1902+ fatal("Couldn't get MIC");
1903+
1904+ packet_start(SSH2_MSG_KEXGSS_COMPLETE);
1905+ packet_put_bignum2(dh->pub_key);
1906+ packet_put_string(msg_tok.value,msg_tok.length);
1907+
1908+ if (send_tok.length != 0) {
1909+ packet_put_char(1); /* true */
1910+ packet_put_string(send_tok.value, send_tok.length);
1911+ } else {
1912+ packet_put_char(0); /* false */
1913+ }
1914+ packet_send();
1915+
1916+ gss_release_buffer(&min_status, &send_tok);
1917+ gss_release_buffer(&min_status, &msg_tok);
1918+
1919+ if (gss_kex_context == NULL)
1920+ gss_kex_context = ctxt;
1921+ else
1922+ ssh_gssapi_delete_ctx(&ctxt);
1923+
1924+ DH_free(dh);
1925+
1926+ kex_derive_keys_bn(ssh, hash, hashlen, shared_secret);
1927+ BN_clear_free(shared_secret);
1928+ kex_send_newkeys(ssh);
1929+
1930+ /* If this was a rekey, then save out any delegated credentials we
1931+ * just exchanged. */
1932+ if (options.gss_store_rekey)
1933+ ssh_gssapi_rekey_creds();
1934+ return 0;
1935+}
1936+#endif /* GSSAPI */
1937diff --git a/monitor.c b/monitor.c
1938index a914209..2658aaa 100644
1939--- a/monitor.c
1940+++ b/monitor.c
1941@@ -157,6 +157,8 @@ int mm_answer_gss_setup_ctx(int, Buffer *);
1942 int mm_answer_gss_accept_ctx(int, Buffer *);
1943 int mm_answer_gss_userok(int, Buffer *);
1944 int mm_answer_gss_checkmic(int, Buffer *);
1945+int mm_answer_gss_sign(int, Buffer *);
1946+int mm_answer_gss_updatecreds(int, Buffer *);
1947 #endif
1948
1949 #ifdef SSH_AUDIT_EVENTS
1950@@ -234,11 +236,18 @@ struct mon_table mon_dispatch_proto20[] = {
1951 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
1952 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
1953 {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic},
1954+ {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
1955 #endif
1956 {0, 0, NULL}
1957 };
1958
1959 struct mon_table mon_dispatch_postauth20[] = {
1960+#ifdef GSSAPI
1961+ {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
1962+ {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
1963+ {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
1964+ {MONITOR_REQ_GSSUPCREDS, 0, mm_answer_gss_updatecreds},
1965+#endif
1966 #ifdef WITH_OPENSSL
1967 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
1968 #endif
1969@@ -353,6 +362,10 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
1970 /* Permit requests for moduli and signatures */
1971 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
1972 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
1973+#ifdef GSSAPI
1974+ /* and for the GSSAPI key exchange */
1975+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
1976+#endif
1977 } else {
1978 mon_dispatch = mon_dispatch_proto15;
1979
1980@@ -461,6 +474,10 @@ monitor_child_postauth(struct monitor *pmonitor)
1981 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
1982 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
1983 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
1984+#ifdef GSSAPI
1985+ /* and for the GSSAPI key exchange */
1986+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
1987+#endif
1988 } else {
1989 mon_dispatch = mon_dispatch_postauth15;
1990 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
1991@@ -1864,6 +1881,13 @@ monitor_apply_keystate(struct monitor *pmonitor)
1992 # endif
1993 #endif /* WITH_OPENSSL */
1994 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
1995+#ifdef GSSAPI
1996+ if (options.gss_keyex) {
1997+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
1998+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
1999+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
2000+ }
2001+#endif
2002 kex->load_host_public_key=&get_hostkey_public_by_type;
2003 kex->load_host_private_key=&get_hostkey_private_by_type;
2004 kex->host_key_index=&get_hostkey_index;
2005@@ -1963,6 +1987,9 @@ mm_answer_gss_setup_ctx(int sock, Buffer *m)
2006 OM_uint32 major;
2007 u_int len;
2008
2009+ if (!options.gss_authentication && !options.gss_keyex)
2010+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2011+
2012 goid.elements = buffer_get_string(m, &len);
2013 goid.length = len;
2014
2015@@ -1990,6 +2017,9 @@ mm_answer_gss_accept_ctx(int sock, Buffer *m)
2016 OM_uint32 flags = 0; /* GSI needs this */
2017 u_int len;
2018
2019+ if (!options.gss_authentication && !options.gss_keyex)
2020+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2021+
2022 in.value = buffer_get_string(m, &len);
2023 in.length = len;
2024 major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags);
2025@@ -2007,6 +2037,7 @@ mm_answer_gss_accept_ctx(int sock, Buffer *m)
2026 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
2027 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
2028 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1);
2029+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1);
2030 }
2031 return (0);
2032 }
2033@@ -2018,6 +2049,9 @@ mm_answer_gss_checkmic(int sock, Buffer *m)
2034 OM_uint32 ret;
2035 u_int len;
2036
2037+ if (!options.gss_authentication && !options.gss_keyex)
2038+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2039+
2040 gssbuf.value = buffer_get_string(m, &len);
2041 gssbuf.length = len;
2042 mic.value = buffer_get_string(m, &len);
2043@@ -2044,7 +2078,11 @@ mm_answer_gss_userok(int sock, Buffer *m)
2044 {
2045 int authenticated;
2046
2047- authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
2048+ if (!options.gss_authentication && !options.gss_keyex)
2049+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2050+
2051+ authenticated = authctxt->valid &&
2052+ ssh_gssapi_userok(authctxt->user, authctxt->pw);
2053
2054 buffer_clear(m);
2055 buffer_put_int(m, authenticated);
2056@@ -2057,5 +2095,73 @@ mm_answer_gss_userok(int sock, Buffer *m)
2057 /* Monitor loop will terminate if authenticated */
2058 return (authenticated);
2059 }
2060+
2061+int
2062+mm_answer_gss_sign(int socket, Buffer *m)
2063+{
2064+ gss_buffer_desc data;
2065+ gss_buffer_desc hash = GSS_C_EMPTY_BUFFER;
2066+ OM_uint32 major, minor;
2067+ u_int len;
2068+
2069+ if (!options.gss_authentication && !options.gss_keyex)
2070+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2071+
2072+ data.value = buffer_get_string(m, &len);
2073+ data.length = len;
2074+ if (data.length != 20)
2075+ fatal("%s: data length incorrect: %d", __func__,
2076+ (int) data.length);
2077+
2078+ /* Save the session ID on the first time around */
2079+ if (session_id2_len == 0) {
2080+ session_id2_len = data.length;
2081+ session_id2 = xmalloc(session_id2_len);
2082+ memcpy(session_id2, data.value, session_id2_len);
2083+ }
2084+ major = ssh_gssapi_sign(gsscontext, &data, &hash);
2085+
2086+ free(data.value);
2087+
2088+ buffer_clear(m);
2089+ buffer_put_int(m, major);
2090+ buffer_put_string(m, hash.value, hash.length);
2091+
2092+ mm_request_send(socket, MONITOR_ANS_GSSSIGN, m);
2093+
2094+ gss_release_buffer(&minor, &hash);
2095+
2096+ /* Turn on getpwnam permissions */
2097+ monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
2098+
2099+ /* And credential updating, for when rekeying */
2100+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSUPCREDS, 1);
2101+
2102+ return (0);
2103+}
2104+
2105+int
2106+mm_answer_gss_updatecreds(int socket, Buffer *m) {
2107+ ssh_gssapi_ccache store;
2108+ int ok;
2109+
2110+ store.filename = buffer_get_string(m, NULL);
2111+ store.envvar = buffer_get_string(m, NULL);
2112+ store.envval = buffer_get_string(m, NULL);
2113+
2114+ ok = ssh_gssapi_update_creds(&store);
2115+
2116+ free(store.filename);
2117+ free(store.envvar);
2118+ free(store.envval);
2119+
2120+ buffer_clear(m);
2121+ buffer_put_int(m, ok);
2122+
2123+ mm_request_send(socket, MONITOR_ANS_GSSUPCREDS, m);
2124+
2125+ return(0);
2126+}
2127+
2128 #endif /* GSSAPI */
2129
2130diff --git a/monitor.h b/monitor.h
2131index 93b8b66..bc50ade 100644
2132--- a/monitor.h
2133+++ b/monitor.h
2134@@ -65,6 +65,9 @@ enum monitor_reqtype {
2135 MONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111,
2136 MONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113,
2137
2138+ MONITOR_REQ_GSSSIGN = 150, MONITOR_ANS_GSSSIGN = 151,
2139+ MONITOR_REQ_GSSUPCREDS = 152, MONITOR_ANS_GSSUPCREDS = 153,
2140+
2141 };
2142
2143 struct mm_master;
2144diff --git a/monitor_wrap.c b/monitor_wrap.c
2145index eac421b..81ceddb 100644
2146--- a/monitor_wrap.c
2147+++ b/monitor_wrap.c
2148@@ -1068,7 +1068,7 @@ mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
2149 }
2150
2151 int
2152-mm_ssh_gssapi_userok(char *user)
2153+mm_ssh_gssapi_userok(char *user, struct passwd *pw)
2154 {
2155 Buffer m;
2156 int authenticated = 0;
2157@@ -1085,5 +1085,50 @@ mm_ssh_gssapi_userok(char *user)
2158 debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
2159 return (authenticated);
2160 }
2161+
2162+OM_uint32
2163+mm_ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_desc *data, gss_buffer_desc *hash)
2164+{
2165+ Buffer m;
2166+ OM_uint32 major;
2167+ u_int len;
2168+
2169+ buffer_init(&m);
2170+ buffer_put_string(&m, data->value, data->length);
2171+
2172+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSIGN, &m);
2173+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSIGN, &m);
2174+
2175+ major = buffer_get_int(&m);
2176+ hash->value = buffer_get_string(&m, &len);
2177+ hash->length = len;
2178+
2179+ buffer_free(&m);
2180+
2181+ return(major);
2182+}
2183+
2184+int
2185+mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
2186+{
2187+ Buffer m;
2188+ int ok;
2189+
2190+ buffer_init(&m);
2191+
2192+ buffer_put_cstring(&m, store->filename ? store->filename : "");
2193+ buffer_put_cstring(&m, store->envvar ? store->envvar : "");
2194+ buffer_put_cstring(&m, store->envval ? store->envval : "");
2195+
2196+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUPCREDS, &m);
2197+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUPCREDS, &m);
2198+
2199+ ok = buffer_get_int(&m);
2200+
2201+ buffer_free(&m);
2202+
2203+ return (ok);
2204+}
2205+
2206 #endif /* GSSAPI */
2207
2208diff --git a/monitor_wrap.h b/monitor_wrap.h
2209index de4a08f..9758290 100644
2210--- a/monitor_wrap.h
2211+++ b/monitor_wrap.h
2212@@ -58,8 +58,10 @@ BIGNUM *mm_auth_rsa_generate_challenge(Key *);
2213 OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
2214 OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *,
2215 gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *);
2216-int mm_ssh_gssapi_userok(char *user);
2217+int mm_ssh_gssapi_userok(char *user, struct passwd *);
2218 OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
2219+OM_uint32 mm_ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
2220+int mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *);
2221 #endif
2222
2223 #ifdef USE_PAM
2224diff --git a/readconf.c b/readconf.c
2225index cd01482..56e0f44 100644
2226--- a/readconf.c
2227+++ b/readconf.c
2228@@ -147,6 +147,8 @@ typedef enum {
2229 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
2230 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
2231 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
2232+ oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey,
2233+ oGssServerIdentity,
2234 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
2235 oSendEnv, oControlPath, oControlMaster, oControlPersist,
2236 oHashKnownHosts,
2237@@ -192,10 +194,19 @@ static struct {
2238 { "afstokenpassing", oUnsupported },
2239 #if defined(GSSAPI)
2240 { "gssapiauthentication", oGssAuthentication },
2241+ { "gssapikeyexchange", oGssKeyEx },
2242 { "gssapidelegatecredentials", oGssDelegateCreds },
2243+ { "gssapitrustdns", oGssTrustDns },
2244+ { "gssapiclientidentity", oGssClientIdentity },
2245+ { "gssapiserveridentity", oGssServerIdentity },
2246+ { "gssapirenewalforcesrekey", oGssRenewalRekey },
2247 #else
2248 { "gssapiauthentication", oUnsupported },
2249+ { "gssapikeyexchange", oUnsupported },
2250 { "gssapidelegatecredentials", oUnsupported },
2251+ { "gssapitrustdns", oUnsupported },
2252+ { "gssapiclientidentity", oUnsupported },
2253+ { "gssapirenewalforcesrekey", oUnsupported },
2254 #endif
2255 { "fallbacktorsh", oDeprecated },
2256 { "usersh", oDeprecated },
2257@@ -894,10 +905,30 @@ parse_time:
2258 intptr = &options->gss_authentication;
2259 goto parse_flag;
2260
2261+ case oGssKeyEx:
2262+ intptr = &options->gss_keyex;
2263+ goto parse_flag;
2264+
2265 case oGssDelegateCreds:
2266 intptr = &options->gss_deleg_creds;
2267 goto parse_flag;
2268
2269+ case oGssTrustDns:
2270+ intptr = &options->gss_trust_dns;
2271+ goto parse_flag;
2272+
2273+ case oGssClientIdentity:
2274+ charptr = &options->gss_client_identity;
2275+ goto parse_string;
2276+
2277+ case oGssServerIdentity:
2278+ charptr = &options->gss_server_identity;
2279+ goto parse_string;
2280+
2281+ case oGssRenewalRekey:
2282+ intptr = &options->gss_renewal_rekey;
2283+ goto parse_flag;
2284+
2285 case oBatchMode:
2286 intptr = &options->batch_mode;
2287 goto parse_flag;
2288@@ -1601,7 +1632,12 @@ initialize_options(Options * options)
2289 options->pubkey_authentication = -1;
2290 options->challenge_response_authentication = -1;
2291 options->gss_authentication = -1;
2292+ options->gss_keyex = -1;
2293 options->gss_deleg_creds = -1;
2294+ options->gss_trust_dns = -1;
2295+ options->gss_renewal_rekey = -1;
2296+ options->gss_client_identity = NULL;
2297+ options->gss_server_identity = NULL;
2298 options->password_authentication = -1;
2299 options->kbd_interactive_authentication = -1;
2300 options->kbd_interactive_devices = NULL;
2301@@ -1729,8 +1765,14 @@ fill_default_options(Options * options)
2302 options->challenge_response_authentication = 1;
2303 if (options->gss_authentication == -1)
2304 options->gss_authentication = 0;
2305+ if (options->gss_keyex == -1)
2306+ options->gss_keyex = 0;
2307 if (options->gss_deleg_creds == -1)
2308 options->gss_deleg_creds = 0;
2309+ if (options->gss_trust_dns == -1)
2310+ options->gss_trust_dns = 0;
2311+ if (options->gss_renewal_rekey == -1)
2312+ options->gss_renewal_rekey = 0;
2313 if (options->password_authentication == -1)
2314 options->password_authentication = 1;
2315 if (options->kbd_interactive_authentication == -1)
2316diff --git a/readconf.h b/readconf.h
2317index bb2d552..e7e80c3 100644
2318--- a/readconf.h
2319+++ b/readconf.h
2320@@ -45,7 +45,12 @@ typedef struct {
2321 int challenge_response_authentication;
2322 /* Try S/Key or TIS, authentication. */
2323 int gss_authentication; /* Try GSS authentication */
2324+ int gss_keyex; /* Try GSS key exchange */
2325 int gss_deleg_creds; /* Delegate GSS credentials */
2326+ int gss_trust_dns; /* Trust DNS for GSS canonicalization */
2327+ int gss_renewal_rekey; /* Credential renewal forces rekey */
2328+ char *gss_client_identity; /* Principal to initiate GSSAPI with */
2329+ char *gss_server_identity; /* GSSAPI target principal */
2330 int password_authentication; /* Try password
2331 * authentication. */
2332 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
2333diff --git a/servconf.c b/servconf.c
2334index 6c7a91e..cfe7029 100644
2335--- a/servconf.c
2336+++ b/servconf.c
2337@@ -117,8 +117,10 @@ initialize_server_options(ServerOptions *options)
2338 options->kerberos_ticket_cleanup = -1;
2339 options->kerberos_get_afs_token = -1;
2340 options->gss_authentication=-1;
2341+ options->gss_keyex = -1;
2342 options->gss_cleanup_creds = -1;
2343 options->gss_strict_acceptor = -1;
2344+ options->gss_store_rekey = -1;
2345 options->password_authentication = -1;
2346 options->kbd_interactive_authentication = -1;
2347 options->challenge_response_authentication = -1;
2348@@ -275,10 +277,14 @@ fill_default_server_options(ServerOptions *options)
2349 options->kerberos_get_afs_token = 0;
2350 if (options->gss_authentication == -1)
2351 options->gss_authentication = 0;
2352+ if (options->gss_keyex == -1)
2353+ options->gss_keyex = 0;
2354 if (options->gss_cleanup_creds == -1)
2355 options->gss_cleanup_creds = 1;
2356 if (options->gss_strict_acceptor == -1)
2357- options->gss_strict_acceptor = 0;
2358+ options->gss_strict_acceptor = 1;
2359+ if (options->gss_store_rekey == -1)
2360+ options->gss_store_rekey = 0;
2361 if (options->password_authentication == -1)
2362 options->password_authentication = 1;
2363 if (options->kbd_interactive_authentication == -1)
2364@@ -412,6 +418,7 @@ typedef enum {
2365 sHostKeyAlgorithms,
2366 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
2367 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
2368+ sGssKeyEx, sGssStoreRekey,
2369 sAcceptEnv, sPermitTunnel,
2370 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
2371 sUsePrivilegeSeparation, sAllowAgentForwarding,
2372@@ -485,12 +492,20 @@ static struct {
2373 #ifdef GSSAPI
2374 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
2375 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
2376+ { "gssapicleanupcreds", sGssCleanupCreds, SSHCFG_GLOBAL },
2377 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
2378+ { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
2379+ { "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
2380 #else
2381 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
2382 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
2383+ { "gssapicleanupcreds", sUnsupported, SSHCFG_GLOBAL },
2384 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
2385+ { "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
2386+ { "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
2387 #endif
2388+ { "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL },
2389+ { "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL },
2390 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
2391 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
2392 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
2393@@ -1231,6 +1246,10 @@ process_server_config_line(ServerOptions *options, char *line,
2394 intptr = &options->gss_authentication;
2395 goto parse_flag;
2396
2397+ case sGssKeyEx:
2398+ intptr = &options->gss_keyex;
2399+ goto parse_flag;
2400+
2401 case sGssCleanupCreds:
2402 intptr = &options->gss_cleanup_creds;
2403 goto parse_flag;
2404@@ -1239,6 +1258,10 @@ process_server_config_line(ServerOptions *options, char *line,
2405 intptr = &options->gss_strict_acceptor;
2406 goto parse_flag;
2407
2408+ case sGssStoreRekey:
2409+ intptr = &options->gss_store_rekey;
2410+ goto parse_flag;
2411+
2412 case sPasswordAuthentication:
2413 intptr = &options->password_authentication;
2414 goto parse_flag;
2415@@ -2246,7 +2269,10 @@ dump_config(ServerOptions *o)
2416 #endif
2417 #ifdef GSSAPI
2418 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2419+ dump_cfg_fmtint(sGssKeyEx, o->gss_keyex);
2420 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
2421+ dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor);
2422+ dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey);
2423 #endif
2424 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2425 dump_cfg_fmtint(sKbdInteractiveAuthentication,
2426diff --git a/servconf.h b/servconf.h
2427index f4137af..778ba17 100644
2428--- a/servconf.h
2429+++ b/servconf.h
2430@@ -118,8 +118,10 @@ typedef struct {
2431 int kerberos_get_afs_token; /* If true, try to get AFS token if
2432 * authenticated with Kerberos. */
2433 int gss_authentication; /* If true, permit GSSAPI authentication */
2434+ int gss_keyex; /* If true, permit GSSAPI key exchange */
2435 int gss_cleanup_creds; /* If true, destroy cred cache on logout */
2436 int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */
2437+ int gss_store_rekey;
2438 int password_authentication; /* If true, permit password
2439 * authentication. */
2440 int kbd_interactive_authentication; /* If true, permit */
2441diff --git a/ssh-gss.h b/ssh-gss.h
2442index a99d7f0..914701b 100644
2443--- a/ssh-gss.h
2444+++ b/ssh-gss.h
2445@@ -1,6 +1,6 @@
2446 /* $OpenBSD: ssh-gss.h,v 1.11 2014/02/26 20:28:44 djm Exp $ */
2447 /*
2448- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
2449+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
2450 *
2451 * Redistribution and use in source and binary forms, with or without
2452 * modification, are permitted provided that the following conditions
2453@@ -61,10 +61,22 @@
2454
2455 #define SSH_GSS_OIDTYPE 0x06
2456
2457+#define SSH2_MSG_KEXGSS_INIT 30
2458+#define SSH2_MSG_KEXGSS_CONTINUE 31
2459+#define SSH2_MSG_KEXGSS_COMPLETE 32
2460+#define SSH2_MSG_KEXGSS_HOSTKEY 33
2461+#define SSH2_MSG_KEXGSS_ERROR 34
2462+#define SSH2_MSG_KEXGSS_GROUPREQ 40
2463+#define SSH2_MSG_KEXGSS_GROUP 41
2464+#define KEX_GSS_GRP1_SHA1_ID "gss-group1-sha1-"
2465+#define KEX_GSS_GRP14_SHA1_ID "gss-group14-sha1-"
2466+#define KEX_GSS_GEX_SHA1_ID "gss-gex-sha1-"
2467+
2468 typedef struct {
2469 char *filename;
2470 char *envvar;
2471 char *envval;
2472+ struct passwd *owner;
2473 void *data;
2474 } ssh_gssapi_ccache;
2475
2476@@ -72,8 +84,11 @@ typedef struct {
2477 gss_buffer_desc displayname;
2478 gss_buffer_desc exportedname;
2479 gss_cred_id_t creds;
2480+ gss_name_t name;
2481 struct ssh_gssapi_mech_struct *mech;
2482 ssh_gssapi_ccache store;
2483+ int used;
2484+ int updated;
2485 } ssh_gssapi_client;
2486
2487 typedef struct ssh_gssapi_mech_struct {
2488@@ -84,6 +99,7 @@ typedef struct ssh_gssapi_mech_struct {
2489 int (*userok) (ssh_gssapi_client *, char *);
2490 int (*localname) (ssh_gssapi_client *, char **);
2491 void (*storecreds) (ssh_gssapi_client *);
2492+ int (*updatecreds) (ssh_gssapi_ccache *, ssh_gssapi_client *);
2493 } ssh_gssapi_mech;
2494
2495 typedef struct {
2496@@ -94,10 +110,11 @@ typedef struct {
2497 gss_OID oid; /* client */
2498 gss_cred_id_t creds; /* server */
2499 gss_name_t client; /* server */
2500- gss_cred_id_t client_creds; /* server */
2501+ gss_cred_id_t client_creds; /* both */
2502 } Gssctxt;
2503
2504 extern ssh_gssapi_mech *supported_mechs[];
2505+extern Gssctxt *gss_kex_context;
2506
2507 int ssh_gssapi_check_oid(Gssctxt *, void *, size_t);
2508 void ssh_gssapi_set_oid_data(Gssctxt *, void *, size_t);
2509@@ -119,16 +136,32 @@ void ssh_gssapi_build_ctx(Gssctxt **);
2510 void ssh_gssapi_delete_ctx(Gssctxt **);
2511 OM_uint32 ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
2512 void ssh_gssapi_buildmic(Buffer *, const char *, const char *, const char *);
2513-int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *);
2514+int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *, const char *);
2515+OM_uint32 ssh_gssapi_client_identity(Gssctxt *, const char *);
2516+int ssh_gssapi_credentials_updated(Gssctxt *);
2517
2518 /* In the server */
2519+typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *,
2520+ const char *);
2521+char *ssh_gssapi_client_mechanisms(const char *, const char *);
2522+char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *,
2523+ const char *);
2524+gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
2525+int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *,
2526+ const char *);
2527 OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
2528-int ssh_gssapi_userok(char *name);
2529+int ssh_gssapi_userok(char *name, struct passwd *);
2530 OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
2531 void ssh_gssapi_do_child(char ***, u_int *);
2532 void ssh_gssapi_cleanup_creds(void);
2533 void ssh_gssapi_storecreds(void);
2534
2535+char *ssh_gssapi_server_mechanisms(void);
2536+int ssh_gssapi_oid_table_ok(void);
2537+
2538+int ssh_gssapi_update_creds(ssh_gssapi_ccache *store);
2539+void ssh_gssapi_rekey_creds(void);
2540+
2541 #endif /* GSSAPI */
2542
2543 #endif /* _SSH_GSS_H */
2544diff --git a/ssh_config b/ssh_config
2545index 03a228f..228e5ab 100644
2546--- a/ssh_config
2547+++ b/ssh_config
2548@@ -26,6 +26,8 @@
2549 # HostbasedAuthentication no
2550 # GSSAPIAuthentication no
2551 # GSSAPIDelegateCredentials no
2552+# GSSAPIKeyExchange no
2553+# GSSAPITrustDNS no
2554 # BatchMode no
2555 # CheckHostIP yes
2556 # AddressFamily any
2557diff --git a/ssh_config.5 b/ssh_config.5
2558index a47f3ca..cac8cda 100644
2559--- a/ssh_config.5
2560+++ b/ssh_config.5
2561@@ -749,11 +749,45 @@ Specifies whether user authentication based on GSSAPI is allowed.
2562 The default is
2563 .Dq no .
2564 Note that this option applies to protocol version 2 only.
2565+.It Cm GSSAPIKeyExchange
2566+Specifies whether key exchange based on GSSAPI may be used. When using
2567+GSSAPI key exchange the server need not have a host key.
2568+The default is
2569+.Dq no .
2570+Note that this option applies to protocol version 2 only.
2571+.It Cm GSSAPIClientIdentity
2572+If set, specifies the GSSAPI client identity that ssh should use when
2573+connecting to the server. The default is unset, which means that the default
2574+identity will be used.
2575+.It Cm GSSAPIServerIdentity
2576+If set, specifies the GSSAPI server identity that ssh should expect when
2577+connecting to the server. The default is unset, which means that the
2578+expected GSSAPI server identity will be determined from the target
2579+hostname.
2580 .It Cm GSSAPIDelegateCredentials
2581 Forward (delegate) credentials to the server.
2582 The default is
2583 .Dq no .
2584-Note that this option applies to protocol version 2 only.
2585+Note that this option applies to protocol version 2 connections using GSSAPI.
2586+.It Cm GSSAPIRenewalForcesRekey
2587+If set to
2588+.Dq yes
2589+then renewal of the client's GSSAPI credentials will force the rekeying of the
2590+ssh connection. With a compatible server, this can delegate the renewed
2591+credentials to a session on the server.
2592+The default is
2593+.Dq no .
2594+.It Cm GSSAPITrustDns
2595+Set to
2596+.Dq yes
2597+to indicate that the DNS is trusted to securely canonicalize
2598+the name of the host being connected to. If
2599+.Dq no ,
2600+the hostname entered on the
2601+command line will be passed untouched to the GSSAPI library.
2602+The default is
2603+.Dq no .
2604+This option only applies to protocol version 2 connections using GSSAPI.
2605 .It Cm HashKnownHosts
2606 Indicates that
2607 .Xr ssh 1
2608diff --git a/sshconnect2.c b/sshconnect2.c
2609index 7751031..32e9b0d 100644
2610--- a/sshconnect2.c
2611+++ b/sshconnect2.c
2612@@ -160,6 +160,11 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2613 struct kex *kex;
2614 int r;
2615
2616+#ifdef GSSAPI
2617+ char *orig = NULL, *gss = NULL;
2618+ char *gss_host = NULL;
2619+#endif
2620+
2621 xxx_host = host;
2622 xxx_hostaddr = hostaddr;
2623
2624@@ -193,6 +198,33 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2625 order_hostkeyalgs(host, hostaddr, port));
2626 }
2627
2628+#ifdef GSSAPI
2629+ if (options.gss_keyex) {
2630+ /* Add the GSSAPI mechanisms currently supported on this
2631+ * client to the key exchange algorithm proposal */
2632+ orig = myproposal[PROPOSAL_KEX_ALGS];
2633+
2634+ if (options.gss_trust_dns)
2635+ gss_host = (char *)get_canonical_hostname(1);
2636+ else
2637+ gss_host = host;
2638+
2639+ gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
2640+ if (gss) {
2641+ debug("Offering GSSAPI proposal: %s", gss);
2642+ xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
2643+ "%s,%s", gss, orig);
2644+
2645+ /* If we've got GSSAPI algorithms, then we also
2646+ * support the 'null' hostkey, as a last resort */
2647+ orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
2648+ xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
2649+ "%s,null", orig);
2650+ free(gss);
2651+ }
2652+ }
2653+#endif
2654+
2655 if (options.rekey_limit || options.rekey_interval)
2656 packet_set_rekey_limits((u_int32_t)options.rekey_limit,
2657 (time_t)options.rekey_interval);
2658@@ -211,10 +243,30 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
2659 # endif
2660 #endif
2661 kex->kex[KEX_C25519_SHA256] = kexc25519_client;
2662+#ifdef GSSAPI
2663+ if (options.gss_keyex) {
2664+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client;
2665+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client;
2666+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
2667+ }
2668+#endif
2669 kex->client_version_string=client_version_string;
2670 kex->server_version_string=server_version_string;
2671 kex->verify_host_key=&verify_host_key_callback;
2672
2673+#ifdef GSSAPI
2674+ if (options.gss_keyex) {
2675+ kex->gss_deleg_creds = options.gss_deleg_creds;
2676+ kex->gss_trust_dns = options.gss_trust_dns;
2677+ kex->gss_client = options.gss_client_identity;
2678+ if (options.gss_server_identity) {
2679+ kex->gss_host = options.gss_server_identity;
2680+ } else {
2681+ kex->gss_host = gss_host;
2682+ }
2683+ }
2684+#endif
2685+
2686 dispatch_run(DISPATCH_BLOCK, &kex->done, active_state);
2687
2688 if (options.use_roaming && !kex->roaming) {
2689@@ -306,6 +358,7 @@ int input_gssapi_token(int type, u_int32_t, void *);
2690 int input_gssapi_hash(int type, u_int32_t, void *);
2691 int input_gssapi_error(int, u_int32_t, void *);
2692 int input_gssapi_errtok(int, u_int32_t, void *);
2693+int userauth_gsskeyex(Authctxt *authctxt);
2694 #endif
2695
2696 void userauth(Authctxt *, char *);
2697@@ -321,6 +374,11 @@ static char *authmethods_get(void);
2698
2699 Authmethod authmethods[] = {
2700 #ifdef GSSAPI
2701+ {"gssapi-keyex",
2702+ userauth_gsskeyex,
2703+ NULL,
2704+ &options.gss_authentication,
2705+ NULL},
2706 {"gssapi-with-mic",
2707 userauth_gssapi,
2708 NULL,
2709@@ -627,19 +685,31 @@ userauth_gssapi(Authctxt *authctxt)
2710 static u_int mech = 0;
2711 OM_uint32 min;
2712 int ok = 0;
2713+ const char *gss_host;
2714+
2715+ if (options.gss_server_identity)
2716+ gss_host = options.gss_server_identity;
2717+ else if (options.gss_trust_dns)
2718+ gss_host = get_canonical_hostname(1);
2719+ else
2720+ gss_host = authctxt->host;
2721
2722 /* Try one GSSAPI method at a time, rather than sending them all at
2723 * once. */
2724
2725 if (gss_supported == NULL)
2726- gss_indicate_mechs(&min, &gss_supported);
2727+ if (GSS_ERROR(gss_indicate_mechs(&min, &gss_supported))) {
2728+ gss_supported = NULL;
2729+ return 0;
2730+ }
2731
2732 /* Check to see if the mechanism is usable before we offer it */
2733 while (mech < gss_supported->count && !ok) {
2734 /* My DER encoding requires length<128 */
2735 if (gss_supported->elements[mech].length < 128 &&
2736 ssh_gssapi_check_mechanism(&gssctxt,
2737- &gss_supported->elements[mech], authctxt->host)) {
2738+ &gss_supported->elements[mech], gss_host,
2739+ options.gss_client_identity)) {
2740 ok = 1; /* Mechanism works */
2741 } else {
2742 mech++;
2743@@ -736,8 +806,8 @@ input_gssapi_response(int type, u_int32_t plen, void *ctxt)
2744 {
2745 Authctxt *authctxt = ctxt;
2746 Gssctxt *gssctxt;
2747- int oidlen;
2748- char *oidv;
2749+ u_int oidlen;
2750+ u_char *oidv;
2751
2752 if (authctxt == NULL)
2753 fatal("input_gssapi_response: no authentication context");
2754@@ -850,6 +920,48 @@ input_gssapi_error(int type, u_int32_t plen, void *ctxt)
2755 free(lang);
2756 return 0;
2757 }
2758+
2759+int
2760+userauth_gsskeyex(Authctxt *authctxt)
2761+{
2762+ Buffer b;
2763+ gss_buffer_desc gssbuf;
2764+ gss_buffer_desc mic = GSS_C_EMPTY_BUFFER;
2765+ OM_uint32 ms;
2766+
2767+ static int attempt = 0;
2768+ if (attempt++ >= 1)
2769+ return (0);
2770+
2771+ if (gss_kex_context == NULL) {
2772+ debug("No valid Key exchange context");
2773+ return (0);
2774+ }
2775+
2776+ ssh_gssapi_buildmic(&b, authctxt->server_user, authctxt->service,
2777+ "gssapi-keyex");
2778+
2779+ gssbuf.value = buffer_ptr(&b);
2780+ gssbuf.length = buffer_len(&b);
2781+
2782+ if (GSS_ERROR(ssh_gssapi_sign(gss_kex_context, &gssbuf, &mic))) {
2783+ buffer_free(&b);
2784+ return (0);
2785+ }
2786+
2787+ packet_start(SSH2_MSG_USERAUTH_REQUEST);
2788+ packet_put_cstring(authctxt->server_user);
2789+ packet_put_cstring(authctxt->service);
2790+ packet_put_cstring(authctxt->method->name);
2791+ packet_put_string(mic.value, mic.length);
2792+ packet_send();
2793+
2794+ buffer_free(&b);
2795+ gss_release_buffer(&ms, &mic);
2796+
2797+ return (1);
2798+}
2799+
2800 #endif /* GSSAPI */
2801
2802 int
2803diff --git a/sshd.c b/sshd.c
2804index 43d4650..d659a68 100644
2805--- a/sshd.c
2806+++ b/sshd.c
2807@@ -126,6 +126,10 @@
2808 #include "version.h"
2809 #include "ssherr.h"
2810
2811+#ifdef USE_SECURITY_SESSION_API
2812+#include <Security/AuthSession.h>
2813+#endif
2814+
2815 #ifndef O_NOCTTY
2816 #define O_NOCTTY 0
2817 #endif
2818@@ -1833,10 +1837,13 @@ main(int ac, char **av)
2819 logit("Disabling protocol version 1. Could not load host key");
2820 options.protocol &= ~SSH_PROTO_1;
2821 }
2822+#ifndef GSSAPI
2823+ /* The GSSAPI key exchange can run without a host key */
2824 if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) {
2825 logit("Disabling protocol version 2. Could not load host key");
2826 options.protocol &= ~SSH_PROTO_2;
2827 }
2828+#endif
2829 if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) {
2830 logit("sshd: no hostkeys available -- exiting.");
2831 exit(1);
2832@@ -2151,6 +2158,60 @@ main(int ac, char **av)
2833 remote_ip, remote_port, laddr, get_local_port());
2834 free(laddr);
2835
2836+#ifdef USE_SECURITY_SESSION_API
2837+ /*
2838+ * Create a new security session for use by the new user login if
2839+ * the current session is the root session or we are not launched
2840+ * by inetd (eg: debugging mode or server mode). We do not
2841+ * necessarily need to create a session if we are launched from
2842+ * inetd because Panther xinetd will create a session for us.
2843+ *
2844+ * The only case where this logic will fail is if there is an
2845+ * inetd running in a non-root session which is not creating
2846+ * new sessions for us. Then all the users will end up in the
2847+ * same session (bad).
2848+ *
2849+ * When the client exits, the session will be destroyed for us
2850+ * automatically.
2851+ *
2852+ * We must create the session before any credentials are stored
2853+ * (including AFS pags, which happens a few lines below).
2854+ */
2855+ {
2856+ OSStatus err = 0;
2857+ SecuritySessionId sid = 0;
2858+ SessionAttributeBits sattrs = 0;
2859+
2860+ err = SessionGetInfo(callerSecuritySession, &sid, &sattrs);
2861+ if (err)
2862+ error("SessionGetInfo() failed with error %.8X",
2863+ (unsigned) err);
2864+ else
2865+ debug("Current Session ID is %.8X / Session Attributes are %.8X",
2866+ (unsigned) sid, (unsigned) sattrs);
2867+
2868+ if (inetd_flag && !(sattrs & sessionIsRoot))
2869+ debug("Running in inetd mode in a non-root session... "
2870+ "assuming inetd created the session for us.");
2871+ else {
2872+ debug("Creating new security session...");
2873+ err = SessionCreate(0, sessionHasTTY | sessionIsRemote);
2874+ if (err)
2875+ error("SessionCreate() failed with error %.8X",
2876+ (unsigned) err);
2877+
2878+ err = SessionGetInfo(callerSecuritySession, &sid,
2879+ &sattrs);
2880+ if (err)
2881+ error("SessionGetInfo() failed with error %.8X",
2882+ (unsigned) err);
2883+ else
2884+ debug("New Session ID is %.8X / Session Attributes are %.8X",
2885+ (unsigned) sid, (unsigned) sattrs);
2886+ }
2887+ }
2888+#endif
2889+
2890 /*
2891 * We don't want to listen forever unless the other side
2892 * successfully authenticates itself. So we set up an alarm which is
2893@@ -2569,6 +2630,48 @@ do_ssh2_kex(void)
2894 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal(
2895 list_hostkey_types());
2896
2897+#ifdef GSSAPI
2898+ {
2899+ char *orig;
2900+ char *gss = NULL;
2901+ char *newstr = NULL;
2902+ orig = myproposal[PROPOSAL_KEX_ALGS];
2903+
2904+ /*
2905+ * If we don't have a host key, then there's no point advertising
2906+ * the other key exchange algorithms
2907+ */
2908+
2909+ if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
2910+ orig = NULL;
2911+
2912+ if (options.gss_keyex)
2913+ gss = ssh_gssapi_server_mechanisms();
2914+ else
2915+ gss = NULL;
2916+
2917+ if (gss && orig)
2918+ xasprintf(&newstr, "%s,%s", gss, orig);
2919+ else if (gss)
2920+ newstr = gss;
2921+ else if (orig)
2922+ newstr = orig;
2923+
2924+ /*
2925+ * If we've got GSSAPI mechanisms, then we've got the 'null' host
2926+ * key alg, but we can't tell people about it unless its the only
2927+ * host key algorithm we support
2928+ */
2929+ if (gss && (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS])) == 0)
2930+ myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = "null";
2931+
2932+ if (newstr)
2933+ myproposal[PROPOSAL_KEX_ALGS] = newstr;
2934+ else
2935+ fatal("No supported key exchange algorithms");
2936+ }
2937+#endif
2938+
2939 /* start key exchange */
2940 if ((r = kex_setup(active_state, myproposal)) != 0)
2941 fatal("kex_setup: %s", ssh_err(r));
2942@@ -2583,6 +2686,13 @@ do_ssh2_kex(void)
2943 # endif
2944 #endif
2945 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
2946+#ifdef GSSAPI
2947+ if (options.gss_keyex) {
2948+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
2949+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
2950+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
2951+ }
2952+#endif
2953 kex->server = 1;
2954 kex->client_version_string=client_version_string;
2955 kex->server_version_string=server_version_string;
2956diff --git a/sshd_config b/sshd_config
2957index 4d77f05..64786c9 100644
2958--- a/sshd_config
2959+++ b/sshd_config
2960@@ -84,6 +84,8 @@ AuthorizedKeysFile .ssh/authorized_keys
2961 # GSSAPI options
2962 #GSSAPIAuthentication no
2963 #GSSAPICleanupCredentials yes
2964+#GSSAPIStrictAcceptorCheck yes
2965+#GSSAPIKeyExchange no
2966
2967 # Set this to 'yes' to enable PAM authentication, account processing,
2968 # and session processing. If this is enabled, PAM authentication will
2969diff --git a/sshd_config.5 b/sshd_config.5
2970index b18d340..5491c89 100644
2971--- a/sshd_config.5
2972+++ b/sshd_config.5
2973@@ -621,6 +621,12 @@ Specifies whether user authentication based on GSSAPI is allowed.
2974 The default is
2975 .Dq no .
2976 Note that this option applies to protocol version 2 only.
2977+.It Cm GSSAPIKeyExchange
2978+Specifies whether key exchange based on GSSAPI is allowed. GSSAPI key exchange
2979+doesn't rely on ssh keys to verify host identity.
2980+The default is
2981+.Dq no .
2982+Note that this option applies to protocol version 2 only.
2983 .It Cm GSSAPICleanupCredentials
2984 Specifies whether to automatically destroy the user's credentials cache
2985 on logout.
2986@@ -642,6 +648,11 @@ machine's default store.
2987 This facility is provided to assist with operation on multi homed machines.
2988 The default is
2989 .Dq yes .
2990+.It Cm GSSAPIStoreCredentialsOnRekey
2991+Controls whether the user's GSSAPI credentials should be updated following a
2992+successful connection rekeying. This option can be used to accepted renewed
2993+or updated credentials from a compatible client. The default is
2994+.Dq no .
2995 .It Cm HostbasedAcceptedKeyTypes
2996 Specifies the key types that will be accepted for hostbased authentication
2997 as a comma-separated pattern list.
2998diff --git a/sshkey.c b/sshkey.c
2999index 32dd8f2..5368e7c 100644
3000--- a/sshkey.c
3001+++ b/sshkey.c
3002@@ -112,6 +112,7 @@ static const struct keytype keytypes[] = {
3003 # endif /* OPENSSL_HAS_NISTP521 */
3004 # endif /* OPENSSL_HAS_ECC */
3005 #endif /* WITH_OPENSSL */
3006+ { "null", "null", KEY_NULL, 0, 0 },
3007 { NULL, NULL, -1, -1, 0 }
3008 };
3009
3010@@ -200,7 +201,7 @@ key_alg_list(int certs_only, int plain_only)
3011 const struct keytype *kt;
3012
3013 for (kt = keytypes; kt->type != -1; kt++) {
3014- if (kt->name == NULL)
3015+ if (kt->name == NULL || kt->type == KEY_NULL)
3016 continue;
3017 if ((certs_only && !kt->cert) || (plain_only && kt->cert))
3018 continue;
3019diff --git a/sshkey.h b/sshkey.h
3020index c8d3cdd..5cf4e5d 100644
3021--- a/sshkey.h
3022+++ b/sshkey.h
3023@@ -62,6 +62,7 @@ enum sshkey_types {
3024 KEY_DSA_CERT,
3025 KEY_ECDSA_CERT,
3026 KEY_ED25519_CERT,
3027+ KEY_NULL,
3028 KEY_UNSPEC
3029 };
3030
diff --git a/debian/patches/helpful-wait-terminate.patch b/debian/patches/helpful-wait-terminate.patch
new file mode 100644
index 000000000..a19fe6c6d
--- /dev/null
+++ b/debian/patches/helpful-wait-terminate.patch
@@ -0,0 +1,26 @@
1From 0a3d1df1344642161b1ee001a3885a1ee8ebc03b 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 306ac36..68f0251 100644
16--- a/serverloop.c
17+++ b/serverloop.c
18@@ -687,7 +687,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..9b5d38271
--- /dev/null
+++ b/debian/patches/keepalive-extensions.patch
@@ -0,0 +1,135 @@
1From ea47a6eba9fce31a1b4cd909b7ba19541c9d9c9b 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: 2015-11-29
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 831072f..83582e3 100644
30--- a/readconf.c
31+++ b/readconf.c
32@@ -160,6 +160,7 @@ typedef enum {
33 oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
34 oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
35 oPubkeyAcceptedKeyTypes,
36+ oProtocolKeepAlives, oSetupTimeOut,
37 oIgnoredUnknownOption, oDeprecated, oUnsupported
38 } OpCodes;
39
40@@ -290,6 +291,8 @@ static struct {
41 { "hostbasedkeytypes", oHostbasedKeyTypes },
42 { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
43 { "ignoreunknown", oIgnoreUnknown },
44+ { "protocolkeepalives", oProtocolKeepAlives },
45+ { "setuptimeout", oSetupTimeOut },
46
47 { NULL, oBadOption }
48 };
49@@ -1304,6 +1307,8 @@ parse_keytypes:
50 goto parse_flag;
51
52 case oServerAliveInterval:
53+ case oProtocolKeepAlives: /* Debian-specific compatibility alias */
54+ case oSetupTimeOut: /* Debian-specific compatibility alias */
55 intptr = &options->server_alive_interval;
56 goto parse_time;
57
58@@ -1856,8 +1861,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 cac8cda..78e918a 100644
76--- a/ssh_config.5
77+++ b/ssh_config.5
78@@ -233,8 +233,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@@ -1476,8 +1480,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 StreamLocalBindMask
107 Sets the octal file creation mode mask
108 .Pq umask
109@@ -1543,6 +1554,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 5491c89..c8ee35d 100644
124--- a/sshd_config.5
125+++ b/sshd_config.5
126@@ -1510,6 +1510,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, or
diff --git a/debian/patches/lintian-symlink-pickiness.patch b/debian/patches/lintian-symlink-pickiness.patch
new file mode 100644
index 000000000..a2a440fae
--- /dev/null
+++ b/debian/patches/lintian-symlink-pickiness.patch
@@ -0,0 +1,32 @@
1From c685ea67334abf73c014aa6ab9f833e9d28fdab8 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 915c740..e161d0e 100644
19--- a/Makefile.in
20+++ b/Makefile.in
21@@ -330,9 +330,9 @@ install-files:
22 $(INSTALL) -m 644 ssh-keysign.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8
23 $(INSTALL) -m 644 ssh-pkcs11-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8
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..a9c4cb7fc
--- /dev/null
+++ b/debian/patches/mention-ssh-keygen-on-keychange.patch
@@ -0,0 +1,42 @@
1From 89f2729da6734f2d5e3a31d2a75e817750f6cd95 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: 2015-09-08
9
10Patch-Name: mention-ssh-keygen-on-keychange.patch
11---
12 sshconnect.c | 8 +++++++-
13 1 file changed, 7 insertions(+), 1 deletion(-)
14
15diff --git a/sshconnect.c b/sshconnect.c
16index cd467fd..bbde8af 100644
17--- a/sshconnect.c
18+++ b/sshconnect.c
19@@ -1078,9 +1078,13 @@ 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:");
28+ error(" ssh-keygen -f \"%s\" -R %s",
29+ ip_found->file, ip);
30+ }
31 }
32 /* The host key has changed. */
33 warn_changed_key(host_key);
34@@ -1088,6 +1092,8 @@ check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port,
35 user_hostfiles[0]);
36 error("Offending %s key in %s:%lu", key_type(host_found->key),
37 host_found->file, host_found->line);
38+ error(" remove with:");
39+ error(" ssh-keygen -f \"%s\" -R %s", host_found->file, host);
40
41 /*
42 * If strict host key checking is in use, the user will have
diff --git a/debian/patches/no-openssl-version-status.patch b/debian/patches/no-openssl-version-status.patch
new file mode 100644
index 000000000..194100f56
--- /dev/null
+++ b/debian/patches/no-openssl-version-status.patch
@@ -0,0 +1,62 @@
1From dcc3ce03144d1560d878db8290c9f19dc0511f6f Mon Sep 17 00:00:00 2001
2From: Kurt Roeckx <kurt@roeckx.be>
3Date: Sun, 9 Feb 2014 16:10:14 +0000
4Subject: Don't check the status field of the OpenSSL version
5
6There is no reason to check the version of OpenSSL (in Debian). If it's
7not compatible the soname will change. OpenSSH seems to want to do a
8check for the soname based on the version number, but wants to keep the
9status of the release the same. Remove that check on the status since
10it doesn't tell you anything about how compatible that version is.
11
12Author: Colin Watson <cjwatson@debian.org>
13Bug-Debian: https://bugs.debian.org/93581
14Bug-Debian: https://bugs.debian.org/664383
15Bug-Debian: https://bugs.debian.org/732940
16Forwarded: not-needed
17Last-Update: 2014-10-07
18
19Patch-Name: no-openssl-version-status.patch
20---
21 openbsd-compat/openssl-compat.c | 6 +++---
22 openbsd-compat/regress/opensslvertest.c | 1 +
23 2 files changed, 4 insertions(+), 3 deletions(-)
24
25diff --git a/openbsd-compat/openssl-compat.c b/openbsd-compat/openssl-compat.c
26index 63a660c..3f62403 100644
27--- a/openbsd-compat/openssl-compat.c
28+++ b/openbsd-compat/openssl-compat.c
29@@ -36,7 +36,7 @@
30 /*
31 * OpenSSL version numbers: MNNFFPPS: major minor fix patch status
32 * We match major, minor, fix and status (not patch) for <1.0.0.
33- * After that, we acceptable compatible fix versions (so we
34+ * After that, we accept compatible fix and status versions (so we
35 * allow 1.0.1 to work with 1.0.0). Going backwards is only allowed
36 * within a patch series.
37 */
38@@ -57,10 +57,10 @@ ssh_compatible_openssl(long headerver, long libver)
39 }
40
41 /*
42- * For versions >= 1.0.0, major,minor,status must match and library
43+ * For versions >= 1.0.0, major,minor must match and library
44 * fix version must be equal to or newer than the header.
45 */
46- mask = 0xfff0000fL; /* major,minor,status */
47+ mask = 0xfff00000L; /* major,minor */
48 hfix = (headerver & 0x000ff000) >> 12;
49 lfix = (libver & 0x000ff000) >> 12;
50 if ( (headerver & mask) == (libver & mask) && lfix >= hfix)
51diff --git a/openbsd-compat/regress/opensslvertest.c b/openbsd-compat/regress/opensslvertest.c
52index 5d019b5..5847487 100644
53--- a/openbsd-compat/regress/opensslvertest.c
54+++ b/openbsd-compat/regress/opensslvertest.c
55@@ -35,6 +35,7 @@ struct version_test {
56
57 /* built with 1.0.1b release headers */
58 { 0x1000101fL, 0x1000101fL, 1},/* exact match */
59+ { 0x1000101fL, 0x10001010L, 1}, /* different status: ok */
60 { 0x1000101fL, 0x1000102fL, 1}, /* newer library patch version: ok */
61 { 0x1000101fL, 0x1000100fL, 1}, /* older library patch version: ok */
62 { 0x1000101fL, 0x1000201fL, 1}, /* newer library fix version: ok */
diff --git a/debian/patches/openbsd-docs.patch b/debian/patches/openbsd-docs.patch
new file mode 100644
index 000000000..9b1c38bfc
--- /dev/null
+++ b/debian/patches/openbsd-docs.patch
@@ -0,0 +1,148 @@
1From eb8141e6ac12c0714e0951598fe44634327bfde7 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: 2014-10-07
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 ed17a08..c560179 100644
48--- a/ssh-keygen.1
49+++ b/ssh-keygen.1
50@@ -174,9 +174,7 @@ key in
51 .Pa ~/.ssh/id_ed25519
52 or
53 .Pa ~/.ssh/id_rsa .
54-Additionally, the system administrator may use this to generate host keys,
55-as seen in
56-.Pa /etc/rc .
57+Additionally, the system administrator may use this to generate host keys.
58 .Pp
59 Normally this program generates the key and asks for a file in which
60 to store the private key.
61@@ -223,9 +221,7 @@ For each of the key types (rsa1, rsa, dsa, ecdsa and ed25519)
62 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 rounds
70 When saving a new-format private key (i.e. an ed25519 key or any SSH protocol
71 2 key when the
72@@ -638,7 +634,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@@ -837,7 +833,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 ff80022..4fba77f 100644
92--- a/ssh.1
93+++ b/ssh.1
94@@ -853,6 +853,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 2105979..42ba596 100644
107--- a/sshd.8
108+++ b/sshd.8
109@@ -67,7 +67,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@@ -861,7 +861,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@@ -960,7 +960,6 @@ The content of this file is not sensitive; it can be world-readable.
128 .Xr ssh-keyscan 1 ,
129 .Xr chroot 2 ,
130 .Xr hosts_access 5 ,
131-.Xr login.conf 5 ,
132 .Xr moduli 5 ,
133 .Xr sshd_config 5 ,
134 .Xr inetd 8 ,
135diff --git a/sshd_config.5 b/sshd_config.5
136index b149bd3..0828592 100644
137--- a/sshd_config.5
138+++ b/sshd_config.5
139@@ -374,8 +374,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 through 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..fb7724f58
--- /dev/null
+++ b/debian/patches/package-versioning.patch
@@ -0,0 +1,65 @@
1From 3e38e90de2e2ead094624f4f140568574c40cae6 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 bbde8af..0ec1e54 100644
23--- a/sshconnect.c
24+++ b/sshconnect.c
25@@ -524,10 +524,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 1b49b26..189d34a 100644
40--- a/sshd.c
41+++ b/sshd.c
42@@ -443,7 +443,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 41e1ea9..2969570 100644
53--- a/version.h
54+++ b/version.h
55@@ -3,4 +3,9 @@
56 #define SSH_VERSION "OpenSSH_7.1"
57
58 #define SSH_PORTABLE "p2"
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..0dc3f1c32
--- /dev/null
+++ b/debian/patches/quieter-signals.patch
@@ -0,0 +1,40 @@
1From 72aec10a082f61d9a601b03ec57e0053e03397dd 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 fba1b54..5653cc4 100644
26--- a/clientloop.c
27+++ b/clientloop.c
28@@ -1716,8 +1716,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/restore-tcp-wrappers.patch b/debian/patches/restore-tcp-wrappers.patch
new file mode 100644
index 000000000..13090ff06
--- /dev/null
+++ b/debian/patches/restore-tcp-wrappers.patch
@@ -0,0 +1,172 @@
1From f1fe58341ea22a6f07e5e1de79aa0385c0ee0c6a Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@debian.org>
3Date: Tue, 7 Oct 2014 13:22:41 +0100
4Subject: Restore TCP wrappers support
5
6Support for TCP wrappers was dropped in OpenSSH 6.7. See this message
7and thread:
8
9 https://lists.mindrot.org/pipermail/openssh-unix-dev/2014-April/032497.html
10
11It is true that this reduces preauth attack surface in sshd. On the
12other hand, this support seems to be quite widely used, and abruptly
13dropping it (from the perspective of users who don't read
14openssh-unix-dev) could easily cause more serious problems in practice.
15
16It's not entirely clear what the right long-term answer for Debian is,
17but it at least probably doesn't involve dropping this feature shortly
18before a freeze.
19
20Forwarded: not-needed
21Last-Update: 2014-10-07
22
23Patch-Name: restore-tcp-wrappers.patch
24---
25 configure.ac | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26 sshd.8 | 7 +++++++
27 sshd.c | 25 +++++++++++++++++++++++++
28 3 files changed, 89 insertions(+)
29
30diff --git a/configure.ac b/configure.ac
31index 7a25603..128889a 100644
32--- a/configure.ac
33+++ b/configure.ac
34@@ -1448,6 +1448,62 @@ AC_ARG_WITH([skey],
35 ]
36 )
37
38+# Check whether user wants TCP wrappers support
39+TCPW_MSG="no"
40+AC_ARG_WITH([tcp-wrappers],
41+ [ --with-tcp-wrappers[[=PATH]] Enable tcpwrappers support (optionally in PATH)],
42+ [
43+ if test "x$withval" != "xno" ; then
44+ saved_LIBS="$LIBS"
45+ saved_LDFLAGS="$LDFLAGS"
46+ saved_CPPFLAGS="$CPPFLAGS"
47+ if test -n "${withval}" && \
48+ test "x${withval}" != "xyes"; then
49+ if test -d "${withval}/lib"; then
50+ if test -n "${need_dash_r}"; then
51+ LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
52+ else
53+ LDFLAGS="-L${withval}/lib ${LDFLAGS}"
54+ fi
55+ else
56+ if test -n "${need_dash_r}"; then
57+ LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
58+ else
59+ LDFLAGS="-L${withval} ${LDFLAGS}"
60+ fi
61+ fi
62+ if test -d "${withval}/include"; then
63+ CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
64+ else
65+ CPPFLAGS="-I${withval} ${CPPFLAGS}"
66+ fi
67+ fi
68+ LIBS="-lwrap $LIBS"
69+ AC_MSG_CHECKING([for libwrap])
70+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
71+#include <sys/types.h>
72+#include <sys/socket.h>
73+#include <netinet/in.h>
74+#include <tcpd.h>
75+int deny_severity = 0, allow_severity = 0;
76+ ]], [[
77+ hosts_access(0);
78+ ]])], [
79+ AC_MSG_RESULT([yes])
80+ AC_DEFINE([LIBWRAP], [1],
81+ [Define if you want
82+ TCP Wrappers support])
83+ SSHDLIBS="$SSHDLIBS -lwrap"
84+ TCPW_MSG="yes"
85+ ], [
86+ AC_MSG_ERROR([*** libwrap missing])
87+
88+ ])
89+ LIBS="$saved_LIBS"
90+ fi
91+ ]
92+)
93+
94 # Check whether user wants to use ldns
95 LDNS_MSG="no"
96 AC_ARG_WITH(ldns,
97@@ -4953,6 +5009,7 @@ echo " KerberosV support: $KRB5_MSG"
98 echo " SELinux support: $SELINUX_MSG"
99 echo " Smartcard support: $SCARD_MSG"
100 echo " S/KEY support: $SKEY_MSG"
101+echo " TCP Wrappers support: $TCPW_MSG"
102 echo " MD5 password support: $MD5_MSG"
103 echo " libedit support: $LIBEDIT_MSG"
104 echo " Solaris process contract support: $SPC_MSG"
105diff --git a/sshd.8 b/sshd.8
106index 213b5fc..2105979 100644
107--- a/sshd.8
108+++ b/sshd.8
109@@ -850,6 +850,12 @@ the user's home directory becomes accessible.
110 This file should be writable only by the user, and need not be
111 readable by anyone else.
112 .Pp
113+.It Pa /etc/hosts.allow
114+.It Pa /etc/hosts.deny
115+Access controls that should be enforced by tcp-wrappers are defined here.
116+Further details are described in
117+.Xr hosts_access 5 .
118+.Pp
119 .It Pa /etc/hosts.equiv
120 This file is for host-based authentication (see
121 .Xr ssh 1 ) .
122@@ -953,6 +959,7 @@ The content of this file is not sensitive; it can be world-readable.
123 .Xr ssh-keygen 1 ,
124 .Xr ssh-keyscan 1 ,
125 .Xr chroot 2 ,
126+.Xr hosts_access 5 ,
127 .Xr login.conf 5 ,
128 .Xr moduli 5 ,
129 .Xr sshd_config 5 ,
130diff --git a/sshd.c b/sshd.c
131index d659a68..9275e0b 100644
132--- a/sshd.c
133+++ b/sshd.c
134@@ -130,6 +130,13 @@
135 #include <Security/AuthSession.h>
136 #endif
137
138+#ifdef LIBWRAP
139+#include <tcpd.h>
140+#include <syslog.h>
141+int allow_severity;
142+int deny_severity;
143+#endif /* LIBWRAP */
144+
145 #ifndef O_NOCTTY
146 #define O_NOCTTY 0
147 #endif
148@@ -2151,6 +2158,24 @@ main(int ac, char **av)
149 #ifdef SSH_AUDIT_EVENTS
150 audit_connection_from(remote_ip, remote_port);
151 #endif
152+#ifdef LIBWRAP
153+ allow_severity = options.log_facility|LOG_INFO;
154+ deny_severity = options.log_facility|LOG_WARNING;
155+ /* Check whether logins are denied from this host. */
156+ if (packet_connection_is_on_socket()) {
157+ struct request_info req;
158+
159+ request_init(&req, RQ_DAEMON, __progname, RQ_FILE, sock_in, 0);
160+ fromhost(&req);
161+
162+ if (!hosts_access(&req)) {
163+ debug("Connection refused by tcp wrapper");
164+ refuse(&req);
165+ /* NOTREACHED */
166+ fatal("libwrap refuse returns");
167+ }
168+ }
169+#endif /* LIBWRAP */
170
171 /* Log the connection. */
172 laddr = get_local_ipaddr(sock_in);
diff --git a/debian/patches/scp-quoting.patch b/debian/patches/scp-quoting.patch
new file mode 100644
index 000000000..e8049d902
--- /dev/null
+++ b/debian/patches/scp-quoting.patch
@@ -0,0 +1,41 @@
1From efd79b5b880f473ef06d4659cf279b07a65de208 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 593fe89..e39294e 100644
21--- a/scp.c
22+++ b/scp.c
23@@ -190,8 +190,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..5fec9eae0
--- /dev/null
+++ b/debian/patches/selinux-role.patch
@@ -0,0 +1,504 @@
1From 701eb985309b1c9fce617949298659843fce723d 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: 2015-08-19
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 8b27575..3c2222f 100644
36--- a/auth.h
37+++ b/auth.h
38@@ -62,6 +62,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 #ifdef BSD_AUTH
46diff --git a/auth1.c b/auth1.c
47index 5073c49..dd00648 100644
48--- a/auth1.c
49+++ b/auth1.c
50@@ -383,7 +383,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@@ -392,11 +392,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 3f49bdc..6eb3cc7 100644
79--- a/auth2.c
80+++ b/auth2.c
81@@ -216,7 +216,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@@ -228,8 +228,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@@ -253,8 +258,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 2658aaa..c063ad1 100644
117--- a/monitor.c
118+++ b/monitor.c
119@@ -127,6 +127,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@@ -208,6 +209,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@@ -879,6 +881,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@@ -909,14 +912,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@@ -1544,7 +1570,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 bc50ade..2d82b8b 100644
194--- a/monitor.h
195+++ b/monitor.h
196@@ -68,6 +68,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 81ceddb..6799911 100644
207--- a/monitor_wrap.c
208+++ b/monitor_wrap.c
209@@ -327,10 +327,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@@ -339,12 +339,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 9758290..57e740f 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 *, const 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 f36999d..f9cdc15 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 ee313da..f35ec39 100644
365--- a/platform.c
366+++ b/platform.c
367@@ -143,7 +143,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@@ -184,7 +184,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 1c7a45d..436ae7c 100644
387--- a/platform.h
388+++ b/platform.h
389@@ -27,7 +27,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 5a64715..afac4a5 100644
400--- a/session.c
401+++ b/session.c
402@@ -1487,7 +1487,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 #ifdef USE_LIBIAF
411@@ -1518,7 +1518,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@@ -1677,7 +1677,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@@ -1704,7 +1704,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@@ -2115,7 +2115,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 6a2f35e..ef6593c 100644
449--- a/session.h
450+++ b/session.h
451@@ -77,7 +77,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 9275e0b..1b49b26 100644
462--- a/sshd.c
463+++ b/sshd.c
464@@ -786,7 +786,7 @@ privsep_postauth(Authctxt *authctxt)
465 explicit_bzero(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 15da8c6..e89efb7 100644
475--- a/sshpty.c
476+++ b/sshpty.c
477@@ -187,7 +187,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@@ -209,7 +209,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..e612e0554
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1,28 @@
1gssapi.patch
2restore-tcp-wrappers.patch
3selinux-role.patch
4ssh-vulnkey-compat.patch
5keepalive-extensions.patch
6syslog-level-silent.patch
7quieter-signals.patch
8helpful-wait-terminate.patch
9user-group-modes.patch
10scp-quoting.patch
11shell-path.patch
12dnssec-sshfp.patch
13auth-log-verbosity.patch
14mention-ssh-keygen-on-keychange.patch
15package-versioning.patch
16debian-banner.patch
17authorized-keys-man-symlink.patch
18lintian-symlink-pickiness.patch
19openbsd-docs.patch
20ssh-argv0.patch
21doc-hash-tab-completion.patch
22doc-upstart.patch
23ssh-agent-setgid.patch
24no-openssl-version-status.patch
25gnome-ssh-askpass2-icon.patch
26sigstop.patch
27systemd-readiness.patch
28debian-config.patch
diff --git a/debian/patches/shell-path.patch b/debian/patches/shell-path.patch
new file mode 100644
index 000000000..e60dfc4d3
--- /dev/null
+++ b/debian/patches/shell-path.patch
@@ -0,0 +1,39 @@
1From ccc03dd81a15fa91155bbdfa6b84a0d6e37c43e4 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 17fbe39..cd467fd 100644
20--- a/sshconnect.c
21+++ b/sshconnect.c
22@@ -231,7 +231,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@@ -1471,7 +1471,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..0cf814455
--- /dev/null
+++ b/debian/patches/sigstop.patch
@@ -0,0 +1,35 @@
1From 5af03fab96e1d53019d1c50282eb21ce3e581895 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
6Author: Robie Basak <robie.basak@ubuntu.com>
7Forwarded: no
8Last-Update: 2014-04-14
9
10Patch-Name: sigstop.patch
11---
12 sshd.c | 10 ++++++++++
13 1 file changed, 10 insertions(+)
14
15diff --git a/sshd.c b/sshd.c
16index 8d17521..5ccf175 100644
17--- a/sshd.c
18+++ b/sshd.c
19@@ -2048,6 +2048,16 @@ main(int ac, char **av)
20 }
21 }
22
23+ if (getenv("SSH_SIGSTOP")) {
24+ /* Tell service supervisor that we are ready. */
25+ kill(getpid(), SIGSTOP);
26+ /* The service supervisor only ever expects a single
27+ * STOP signal, so do not ever signal it again, even
28+ * in the case of a re-exec or future children.
29+ */
30+ unsetenv("SSH_SIGSTOP");
31+ }
32+
33 /* Accept a connection and return in a forked child */
34 server_accept_loop(&sock_in, &sock_out,
35 &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..ffab898c7
--- /dev/null
+++ b/debian/patches/ssh-agent-setgid.patch
@@ -0,0 +1,40 @@
1From 7566d3563c174cc339da8b72833e66614cfc1458 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 d0aa712..2a940d9 100644
17--- a/ssh-agent.1
18+++ b/ssh-agent.1
19@@ -186,6 +186,21 @@ environment variable holds the agent's process ID.
20 .Pp
21 The agent exits automatically when the command given on the command
22 line terminates.
23+.Pp
24+In Debian,
25+.Nm
26+is installed with the set-group-id bit set, to prevent
27+.Xr ptrace 2
28+attacks retrieving private key material.
29+This has the side-effect of causing the run-time linker to remove certain
30+environment variables which might have security implications for set-id
31+programs, including
32+.Ev LD_PRELOAD ,
33+.Ev LD_LIBRARY_PATH ,
34+and
35+.Ev TMPDIR .
36+If you need to set any of these environment variables, you will need to do
37+so in the program executed by ssh-agent.
38 .Sh FILES
39 .Bl -tag -width Ds
40 .It Pa $TMPDIR/ssh-XXXXXXXXXX/agent.\*(Ltppid\*(Gt
diff --git a/debian/patches/ssh-argv0.patch b/debian/patches/ssh-argv0.patch
new file mode 100644
index 000000000..d3097fe10
--- /dev/null
+++ b/debian/patches/ssh-argv0.patch
@@ -0,0 +1,31 @@
1From 078b7a5e7b89d20ce867e2c9839096be673b6ae0 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 4fba77f..05b7f10 100644
22--- a/ssh.1
23+++ b/ssh.1
24@@ -1574,6 +1574,7 @@ if an error occurred.
25 .Xr sftp 1 ,
26 .Xr ssh-add 1 ,
27 .Xr ssh-agent 1 ,
28+.Xr ssh-argv0 1 ,
29 .Xr ssh-keygen 1 ,
30 .Xr ssh-keyscan 1 ,
31 .Xr tun 4 ,
diff --git a/debian/patches/ssh-vulnkey-compat.patch b/debian/patches/ssh-vulnkey-compat.patch
new file mode 100644
index 000000000..be725e357
--- /dev/null
+++ b/debian/patches/ssh-vulnkey-compat.patch
@@ -0,0 +1,42 @@
1From 7f0a4ecb6694298414e6d84c0aa49c35b19cad1b Mon Sep 17 00:00:00 2001
2From: Colin Watson <cjwatson@ubuntu.com>
3Date: Sun, 9 Feb 2014 16:09:50 +0000
4Subject: Accept obsolete ssh-vulnkey configuration options
5
6These options were used as part of Debian's response to CVE-2008-0166.
7Nearly six years later, we no longer need to continue carrying the bulk
8of that patch, but we do need to avoid failing when the associated
9configuration options are still present.
10
11Last-Update: 2014-02-09
12
13Patch-Name: ssh-vulnkey-compat.patch
14---
15 readconf.c | 1 +
16 servconf.c | 1 +
17 2 files changed, 2 insertions(+)
18
19diff --git a/readconf.c b/readconf.c
20index 56e0f44..831072f 100644
21--- a/readconf.c
22+++ b/readconf.c
23@@ -181,6 +181,7 @@ static struct {
24 { "passwordauthentication", oPasswordAuthentication },
25 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
26 { "kbdinteractivedevices", oKbdInteractiveDevices },
27+ { "useblacklistedkeys", oDeprecated },
28 { "rsaauthentication", oRSAAuthentication },
29 { "pubkeyauthentication", oPubkeyAuthentication },
30 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
31diff --git a/servconf.c b/servconf.c
32index cfe7029..ed3a88d 100644
33--- a/servconf.c
34+++ b/servconf.c
35@@ -522,6 +522,7 @@ static struct {
36 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
37 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
38 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
39+ { "permitblacklistedkeys", sDeprecated, SSHCFG_GLOBAL },
40 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
41 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
42 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
diff --git a/debian/patches/syslog-level-silent.patch b/debian/patches/syslog-level-silent.patch
new file mode 100644
index 000000000..255395666
--- /dev/null
+++ b/debian/patches/syslog-level-silent.patch
@@ -0,0 +1,47 @@
1From 25ead9080a3f98eafc64a9a9c4b6650d922a19fa 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 ad12930..e68b84a 100644
25--- a/log.c
26+++ b/log.c
27@@ -93,6 +93,7 @@ static struct {
28 LogLevel val;
29 } log_levels[] =
30 {
31+ { "SILENT", SYSLOG_LEVEL_QUIET }, /* compatibility */
32 { "QUIET", SYSLOG_LEVEL_QUIET },
33 { "FATAL", SYSLOG_LEVEL_FATAL },
34 { "ERROR", SYSLOG_LEVEL_ERROR },
35diff --git a/ssh.c b/ssh.c
36index 67c1ebf..eb73903 100644
37--- a/ssh.c
38+++ b/ssh.c
39@@ -1106,7 +1106,7 @@ main(int ac, char **av)
40 /* Do not allocate a tty if stdin is not a tty. */
41 if ((!isatty(fileno(stdin)) || stdin_null_flag) &&
42 options.request_tty != REQUEST_TTY_FORCE) {
43- if (tty_flag)
44+ if (tty_flag && options.log_level != SYSLOG_LEVEL_QUIET)
45 logit("Pseudo-terminal will not be allocated because "
46 "stdin is not a terminal.");
47 tty_flag = 0;
diff --git a/debian/patches/systemd-readiness.patch b/debian/patches/systemd-readiness.patch
new file mode 100644
index 000000000..62ca0f284
--- /dev/null
+++ b/debian/patches/systemd-readiness.patch
@@ -0,0 +1,84 @@
1From 9d88bc29443745ebf30004136ac18ced47292833 Mon Sep 17 00:00:00 2001
2From: Michael Biebl <biebl@debian.org>
3Date: Mon, 21 Dec 2015 16:08:47 +0000
4Subject: Add systemd readiness notification support
5
6Bug-Debian: https://bugs.debian.org/778913
7Forwarded: no
8Last-Update: 2016-01-04
9
10Patch-Name: systemd-readiness.patch
11---
12 configure.ac | 24 ++++++++++++++++++++++++
13 sshd.c | 9 +++++++++
14 2 files changed, 33 insertions(+)
15
16diff --git a/configure.ac b/configure.ac
17index 128889a..eec2b72 100644
18--- a/configure.ac
19+++ b/configure.ac
20@@ -4213,6 +4213,29 @@ AC_ARG_WITH([kerberos5],
21 AC_SUBST([GSSLIBS])
22 AC_SUBST([K5LIBS])
23
24+# Check whether user wants systemd support
25+SYSTEMD_MSG="no"
26+AC_ARG_WITH(systemd,
27+ [ --with-systemd Enable systemd support],
28+ [ if test "x$withval" != "xno" ; then
29+ AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
30+ if test "$PKGCONFIG" != "no"; then
31+ AC_MSG_CHECKING([for libsystemd])
32+ if $PKGCONFIG --exists libsystemd; then
33+ SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
34+ SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
35+ CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
36+ SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
37+ AC_MSG_RESULT([yes])
38+ AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
39+ SYSTEMD_MSG="yes"
40+ else
41+ AC_MSG_RESULT([no])
42+ fi
43+ fi
44+ fi ]
45+)
46+
47 # Looking for programs, paths and files
48
49 PRIVSEP_PATH=/var/empty
50@@ -5014,6 +5037,7 @@ echo " MD5 password support: $MD5_MSG"
51 echo " libedit support: $LIBEDIT_MSG"
52 echo " Solaris process contract support: $SPC_MSG"
53 echo " Solaris project support: $SP_MSG"
54+echo " systemd support: $SYSTEMD_MSG"
55 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
56 echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
57 echo " BSD Auth support: $BSD_AUTH_MSG"
58diff --git a/sshd.c b/sshd.c
59index 5ccf175..366ae92 100644
60--- a/sshd.c
61+++ b/sshd.c
62@@ -85,6 +85,10 @@
63 #include <prot.h>
64 #endif
65
66+#ifdef HAVE_SYSTEMD
67+#include <systemd/sd-daemon.h>
68+#endif
69+
70 #include "xmalloc.h"
71 #include "ssh.h"
72 #include "ssh1.h"
73@@ -2058,6 +2062,11 @@ main(int ac, char **av)
74 unsetenv("SSH_SIGSTOP");
75 }
76
77+#ifdef HAVE_SYSTEMD
78+ /* Signal systemd that we are ready to accept connections */
79+ sd_notify(0, "READY=1");
80+#endif
81+
82 /* Accept a connection and return in a forked child */
83 server_accept_loop(&sock_in, &sock_out,
84 &newsock, config_s);
diff --git a/debian/patches/user-group-modes.patch b/debian/patches/user-group-modes.patch
new file mode 100644
index 000000000..c2dbdcd7a
--- /dev/null
+++ b/debian/patches/user-group-modes.patch
@@ -0,0 +1,266 @@
1From a1010980d6906a140307825466934a21c3d4d228 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 ee9e827..2ff2cff 100644
32--- a/auth-rhosts.c
33+++ b/auth-rhosts.c
34@@ -271,8 +271,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@@ -298,8 +297,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 bd6a026..782b7f8 100644
56--- a/auth.c
57+++ b/auth.c
58@@ -425,8 +425,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@@ -488,8 +487,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@@ -504,8 +502,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 ddd2b2d..1c063ea 100644
90--- a/misc.c
91+++ b/misc.c
92@@ -50,8 +50,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@@ -60,6 +61,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@@ -644,6 +646,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 374c33c..89e1f75 100644
185--- a/misc.h
186+++ b/misc.h
187@@ -135,4 +135,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 f35ec39..9a23e6e 100644
196--- a/platform.c
197+++ b/platform.c
198@@ -197,19 +197,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 83582e3..b9442fd 100644
220--- a/readconf.c
221+++ b/readconf.c
222@@ -39,6 +39,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@@ -1579,8 +1581,7 @@ read_config_file(const char *filename, struct passwd *pw, const char *host,
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 2ea0a20..ff80022 100644
243--- a/ssh.1
244+++ b/ssh.1
245@@ -1458,6 +1458,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 78e918a..1e9c058 100644
256--- a/ssh_config.5
257+++ b/ssh_config.5
258@@ -1757,6 +1757,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