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