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