summaryrefslogtreecommitdiff
path: root/debian/patches
diff options
context:
space:
mode:
Diffstat (limited to 'debian/patches')
-rw-r--r--debian/patches/authorized-keys-man-symlink.patch18
-rw-r--r--debian/patches/debian-banner.patch99
-rw-r--r--debian/patches/debian-config.patch146
-rw-r--r--debian/patches/dnssec-sshfp.patch82
-rw-r--r--debian/patches/doc-hash-tab-completion.patch20
-rw-r--r--debian/patches/gnome-ssh-askpass2-icon.patch18
-rw-r--r--debian/patches/gssapi-autoconf.patch29
-rw-r--r--debian/patches/gssapi.patch3046
-rw-r--r--debian/patches/helpful-wait-terminate.patch18
-rw-r--r--debian/patches/keepalive-extensions.patch124
-rw-r--r--debian/patches/lintian-symlink-pickiness.patch23
-rw-r--r--debian/patches/openbsd-docs.patch117
-rw-r--r--debian/patches/package-versioning.patch50
-rw-r--r--debian/patches/quieter-signals.patch31
-rw-r--r--debian/patches/scp-quoting.patch32
-rw-r--r--debian/patches/selinux-role.patch292
-rw-r--r--debian/patches/series41
-rw-r--r--debian/patches/shell-path.patch30
-rw-r--r--debian/patches/ssh-argv0.patch21
-rw-r--r--debian/patches/ssh-vulnkey.patch1385
-rw-r--r--debian/patches/ssh1-keepalive.patch65
-rw-r--r--debian/patches/syslog-level-silent.patch37
-rw-r--r--debian/patches/user-group-modes.patch202
23 files changed, 5926 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..891b934ab
--- /dev/null
+++ b/debian/patches/authorized-keys-man-symlink.patch
@@ -0,0 +1,18 @@
1Description: Install authorized_keys(5) as a symlink to sshd(8)
2Author: Tomas Pospisek <tpo_deb@sourcepole.ch>
3Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1720
4Bug-Debian: http://bugs.debian.org/441817
5Last-Update: 2010-03-01
6
7Index: b/Makefile.in
8===================================================================
9--- a/Makefile.in
10+++ b/Makefile.in
11@@ -287,6 +287,7 @@
12 $(INSTALL) -m 644 sshd_config.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/sshd_config.5
13 $(INSTALL) -m 644 ssh_config.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/ssh_config.5
14 $(INSTALL) -m 644 sshd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8
15+ ln -s ../$(mansubdir)8/sshd.8 $(DESTDIR)$(mandir)/$(mansubdir)5/authorized_keys.5
16 if [ ! -z "$(INSTALL_SSH_RAND_HELPER)" ]; then \
17 $(INSTALL) -m 644 ssh-rand-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-rand-helper.8 ; \
18 fi
diff --git a/debian/patches/debian-banner.patch b/debian/patches/debian-banner.patch
new file mode 100644
index 000000000..32251397d
--- /dev/null
+++ b/debian/patches/debian-banner.patch
@@ -0,0 +1,99 @@
1Description: Add DebianBanner server configuration option
2 Setting this to "no" causes sshd to omit the Debian revision from its
3 initial protocol handshake, for those scared by package-versioning.patch.
4Author: Kees Cook <kees@debian.org>
5Bug-Debian: http://bugs.debian.org/562048
6Forwarded: not-needed
7Last-Update: 2010-02-28
8
9Index: b/servconf.c
10===================================================================
11--- a/servconf.c
12+++ b/servconf.c
13@@ -143,6 +143,7 @@
14 options->authorized_principals_file = NULL;
15 options->ip_qos_interactive = -1;
16 options->ip_qos_bulk = -1;
17+ options->debian_banner = -1;
18 }
19
20 void
21@@ -293,6 +294,8 @@
22 options->ip_qos_interactive = IPTOS_LOWDELAY;
23 if (options->ip_qos_bulk == -1)
24 options->ip_qos_bulk = IPTOS_THROUGHPUT;
25+ if (options->debian_banner == -1)
26+ options->debian_banner = 1;
27
28 /* Turn privilege separation on by default */
29 if (use_privsep == -1)
30@@ -342,6 +345,7 @@
31 sZeroKnowledgePasswordAuthentication, sHostCertificate,
32 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
33 sKexAlgorithms, sIPQoS,
34+ sDebianBanner,
35 sDeprecated, sUnsupported
36 } ServerOpCodes;
37
38@@ -477,6 +481,7 @@
39 { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
40 { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
41 { "ipqos", sIPQoS, SSHCFG_ALL },
42+ { "debianbanner", sDebianBanner, SSHCFG_GLOBAL },
43 { NULL, sBadOption, 0 }
44 };
45
46@@ -1439,6 +1444,10 @@
47 }
48 break;
49
50+ case sDebianBanner:
51+ intptr = &options->debian_banner;
52+ goto parse_int;
53+
54 case sDeprecated:
55 logit("%s line %d: Deprecated option %s",
56 filename, linenum, arg);
57Index: b/servconf.h
58===================================================================
59--- a/servconf.h
60+++ b/servconf.h
61@@ -160,6 +160,8 @@
62
63 int num_permitted_opens;
64
65+ int debian_banner;
66+
67 char *chroot_directory;
68 char *revoked_keys_file;
69 char *trusted_user_ca_keys;
70Index: b/sshd.c
71===================================================================
72--- a/sshd.c
73+++ b/sshd.c
74@@ -422,7 +422,8 @@
75 minor = PROTOCOL_MINOR_1;
76 }
77 snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s%s", major, minor,
78- SSH_RELEASE, newline);
79+ options.debian_banner ? SSH_RELEASE : SSH_RELEASE_MINIMUM,
80+ newline);
81 server_version_string = xstrdup(buf);
82
83 /* Send our protocol version identification. */
84Index: b/sshd_config.5
85===================================================================
86--- a/sshd_config.5
87+++ b/sshd_config.5
88@@ -339,6 +339,11 @@
89 .Dq no .
90 The default is
91 .Dq delayed .
92+.It Cm DebianBanner
93+Specifies whether the distribution-specified extra version suffix is
94+included during initial protocol handshake.
95+The default is
96+.Dq yes .
97 .It Cm DenyGroups
98 This keyword can be followed by a list of group name patterns, separated
99 by spaces.
diff --git a/debian/patches/debian-config.patch b/debian/patches/debian-config.patch
new file mode 100644
index 000000000..e804aa526
--- /dev/null
+++ b/debian/patches/debian-config.patch
@@ -0,0 +1,146 @@
1Description: Various Debian-specific configuration changes
2 ssh: Enable ForwardX11Trusted, returning to earlier semantics which cause
3 fewer problems with existing setups (http://bugs.debian.org/237021).
4 .
5 ssh: Set 'SendEnv LANG LC_*' by default (http://bugs.debian.org/264024).
6 .
7 ssh: Enable HashKnownHosts by default to try to limit the spread of ssh
8 worms.
9 .
10 ssh: Enable GSSAPIAuthentication and disable GSSAPIDelegateCredentials by
11 default.
12 .
13 sshd: Refer to /usr/share/doc/openssh-server/README.Debian.gz alongside
14 PermitRootLogin default.
15 .
16 Document all of this, along with several sshd defaults set in
17 debian/openssh-server.postinst.
18Author: Colin Watson <cjwatson@debian.org>
19Author: Russ Allbery <rra@debian.org>
20Forwarded: not-needed
21Last-Update: 2010-02-28
22
23Index: b/readconf.c
24===================================================================
25--- a/readconf.c
26+++ b/readconf.c
27@@ -1223,7 +1223,7 @@
28 if (options->forward_x11 == -1)
29 options->forward_x11 = 0;
30 if (options->forward_x11_trusted == -1)
31- options->forward_x11_trusted = 0;
32+ options->forward_x11_trusted = 1;
33 if (options->forward_x11_timeout == -1)
34 options->forward_x11_timeout = 1200;
35 if (options->exit_on_forward_failure == -1)
36Index: b/ssh_config
37===================================================================
38--- a/ssh_config
39+++ b/ssh_config
40@@ -17,9 +17,10 @@
41 # list of available options, their meanings and defaults, please see the
42 # ssh_config(5) man page.
43
44-# Host *
45+Host *
46 # ForwardAgent no
47 # ForwardX11 no
48+# ForwardX11Trusted yes
49 # RhostsRSAAuthentication no
50 # RSAAuthentication yes
51 # PasswordAuthentication yes
52@@ -47,3 +48,7 @@
53 # PermitLocalCommand no
54 # VisualHostKey no
55 # ProxyCommand ssh -q -W %h:%p gateway.example.com
56+ SendEnv LANG LC_*
57+ HashKnownHosts yes
58+ GSSAPIAuthentication yes
59+ GSSAPIDelegateCredentials no
60Index: b/ssh_config.5
61===================================================================
62--- a/ssh_config.5
63+++ b/ssh_config.5
64@@ -71,6 +71,22 @@
65 host-specific declarations should be given near the beginning of the
66 file, and general defaults at the end.
67 .Pp
68+Note that the Debian
69+.Ic openssh-client
70+package sets several options as standard in
71+.Pa /etc/ssh/ssh_config
72+which are not the default in
73+.Xr ssh 1 :
74+.Pp
75+.Bl -bullet -offset indent -compact
76+.It
77+.Cm SendEnv No LANG LC_*
78+.It
79+.Cm HashKnownHosts No yes
80+.It
81+.Cm GSSAPIAuthentication No yes
82+.El
83+.Pp
84 The configuration file has the following format:
85 .Pp
86 Empty lines and lines starting with
87@@ -482,7 +498,8 @@
88 Remote clients will be refused access after this time.
89 .Pp
90 The default is
91-.Dq no .
92+.Dq yes
93+(Debian-specific).
94 .Pp
95 See the X11 SECURITY extension specification for full details on
96 the restrictions imposed on untrusted clients.
97Index: b/sshd_config
98===================================================================
99--- a/sshd_config
100+++ b/sshd_config
101@@ -37,6 +37,7 @@
102 # Authentication:
103
104 #LoginGraceTime 2m
105+# See /usr/share/doc/openssh-server/README.Debian.gz.
106 #PermitRootLogin yes
107 #StrictModes yes
108 #MaxAuthTries 6
109Index: b/sshd_config.5
110===================================================================
111--- a/sshd_config.5
112+++ b/sshd_config.5
113@@ -57,6 +57,33 @@
114 .Pq \&"
115 in order to represent arguments containing spaces.
116 .Pp
117+Note that the Debian
118+.Ic openssh-server
119+package sets several options as standard in
120+.Pa /etc/ssh/sshd_config
121+which are not the default in
122+.Xr sshd 8 .
123+The exact list depends on whether the package was installed fresh or
124+upgraded from various possible previous versions, but includes at least the
125+following:
126+.Pp
127+.Bl -bullet -offset indent -compact
128+.It
129+.Cm Protocol No 2
130+.It
131+.Cm ChallengeResponseAuthentication No no
132+.It
133+.Cm X11Forwarding No yes
134+.It
135+.Cm PrintMotd No no
136+.It
137+.Cm AcceptEnv No LANG LC_*
138+.It
139+.Cm Subsystem No sftp /usr/lib/openssh/sftp-server
140+.It
141+.Cm UsePAM No yes
142+.El
143+.Pp
144 The possible
145 keywords and their meanings are as follows (note that
146 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..8e8285a1f
--- /dev/null
+++ b/debian/patches/dnssec-sshfp.patch
@@ -0,0 +1,82 @@
1Description: Force use of DNSSEC even if "options edns0" isn't in resolv.conf
2 This allows SSHFP DNS records to be verified if glibc 2.11 is installed.
3Origin: vendor, https://cvs.fedoraproject.org/viewvc/F-12/openssh/openssh-5.2p1-edns.patch?revision=1.1&view=markup
4Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572049
5Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572049
6Last-Update: 2010-04-06
7
8Index: b/dns.c
9===================================================================
10--- a/dns.c
11+++ b/dns.c
12@@ -177,6 +177,7 @@
13 {
14 u_int counter;
15 int result;
16+ unsigned int rrset_flags = 0;
17 struct rrsetinfo *fingerprints = NULL;
18
19 u_int8_t hostkey_algorithm;
20@@ -200,8 +201,19 @@
21 return -1;
22 }
23
24+ /*
25+ * Original getrrsetbyname function, found on OpenBSD for example,
26+ * doesn't accept any flag and prerequisite for obtaining AD bit in
27+ * DNS response is set by "options edns0" in resolv.conf.
28+ *
29+ * Our version is more clever and use RRSET_FORCE_EDNS0 flag.
30+ */
31+#ifndef HAVE_GETRRSETBYNAME
32+ rrset_flags |= RRSET_FORCE_EDNS0;
33+#endif
34 result = getrrsetbyname(hostname, DNS_RDATACLASS_IN,
35- DNS_RDATATYPE_SSHFP, 0, &fingerprints);
36+ DNS_RDATATYPE_SSHFP, rrset_flags, &fingerprints);
37+
38 if (result) {
39 verbose("DNS lookup error: %s", dns_result_totext(result));
40 return -1;
41Index: b/openbsd-compat/getrrsetbyname.c
42===================================================================
43--- a/openbsd-compat/getrrsetbyname.c
44+++ b/openbsd-compat/getrrsetbyname.c
45@@ -209,8 +209,8 @@
46 goto fail;
47 }
48
49- /* don't allow flags yet, unimplemented */
50- if (flags) {
51+ /* Allow RRSET_FORCE_EDNS0 flag only. */
52+ if ((flags & !RRSET_FORCE_EDNS0) != 0) {
53 result = ERRSET_INVAL;
54 goto fail;
55 }
56@@ -226,9 +226,9 @@
57 #endif /* DEBUG */
58
59 #ifdef RES_USE_DNSSEC
60- /* turn on DNSSEC if EDNS0 is configured */
61- if (_resp->options & RES_USE_EDNS0)
62- _resp->options |= RES_USE_DNSSEC;
63+ /* turn on DNSSEC if required */
64+ if (flags & RRSET_FORCE_EDNS0)
65+ _resp->options |= (RES_USE_EDNS0|RES_USE_DNSSEC);
66 #endif /* RES_USE_DNSEC */
67
68 /* make query */
69Index: b/openbsd-compat/getrrsetbyname.h
70===================================================================
71--- a/openbsd-compat/getrrsetbyname.h
72+++ b/openbsd-compat/getrrsetbyname.h
73@@ -72,6 +72,9 @@
74 #ifndef RRSET_VALIDATED
75 # define RRSET_VALIDATED 1
76 #endif
77+#ifndef RRSET_FORCE_EDNS0
78+# define RRSET_FORCE_EDNS0 0x0001
79+#endif
80
81 /*
82 * 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..5cf8aa46b
--- /dev/null
+++ b/debian/patches/doc-hash-tab-completion.patch
@@ -0,0 +1,20 @@
1Description: Document that HashKnownHosts may break tab-completion
2Author: Colin Watson <cjwatson@debian.org>
3Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1727
4Bug-Debian: http://bugs.debian.org/430154
5Last-Update: 2010-03-01
6
7Index: b/ssh_config.5
8===================================================================
9--- a/ssh_config.5
10+++ b/ssh_config.5
11@@ -566,6 +566,9 @@
12 will not be converted automatically,
13 but may be manually hashed using
14 .Xr ssh-keygen 1 .
15+Use of this option may break facilities such as tab-completion that rely
16+on being able to read unhashed host names from
17+.Pa ~/.ssh/known_hosts .
18 .It Cm HostbasedAuthentication
19 Specifies whether to try rhosts based authentication with public key
20 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..96bbf3a09
--- /dev/null
+++ b/debian/patches/gnome-ssh-askpass2-icon.patch
@@ -0,0 +1,18 @@
1Description: Give the ssh-askpass-gnome window a default icon
2Author: Vincent Untz <vuntz@ubuntu.com>
3Bug-Ubuntu: https://bugs.launchpad.net/bugs/27152
4Last-Update: 2010-02-28
5
6Index: b/contrib/gnome-ssh-askpass2.c
7===================================================================
8--- a/contrib/gnome-ssh-askpass2.c
9+++ b/contrib/gnome-ssh-askpass2.c
10@@ -209,6 +209,8 @@
11
12 gtk_init(&argc, &argv);
13
14+ gtk_window_set_default_icon_from_file ("/usr/share/pixmaps/ssh-askpass-gnome.png", NULL);
15+
16 if (argc > 1) {
17 message = g_strjoinv(" ", argv + 1);
18 } else {
diff --git a/debian/patches/gssapi-autoconf.patch b/debian/patches/gssapi-autoconf.patch
new file mode 100644
index 000000000..51d8a8e72
--- /dev/null
+++ b/debian/patches/gssapi-autoconf.patch
@@ -0,0 +1,29 @@
1Description: Update config.h.in following GSSAPI patch
2Author: Colin Watson <cjwatson@debian.org>
3Forwarded: not-needed
4Last-Updated: 2010-02-27
5
6Index: b/config.h.in
7===================================================================
8--- a/config.h.in
9+++ b/config.h.in
10@@ -1417,6 +1417,9 @@
11 /* Use btmp to log bad logins */
12 #undef USE_BTMP
13
14+/* platform uses an in-memory credentials cache */
15+#undef USE_CCAPI
16+
17 /* Use libedit for sftp */
18 #undef USE_LIBEDIT
19
20@@ -1432,6 +1435,9 @@
21 /* Use PIPES instead of a socketpair() */
22 #undef USE_PIPES
23
24+/* platform has the Security Authorization Session API */
25+#undef USE_SECURITY_SESSION_API
26+
27 /* Define if you have Solaris process contracts */
28 #undef USE_SOLARIS_PROCESS_CONTRACTS
29
diff --git a/debian/patches/gssapi.patch b/debian/patches/gssapi.patch
new file mode 100644
index 000000000..692437142
--- /dev/null
+++ b/debian/patches/gssapi.patch
@@ -0,0 +1,3046 @@
1Description: GSSAPI key exchange support
2 This patch has been rejected upstream: "None of the OpenSSH developers are
3 in favour of adding this, and this situation has not changed for several
4 years. This is not a slight on Simon's patch, which is of fine quality,
5 but just that a) we don't trust GSSAPI implementations that much and b) we
6 don't like adding new KEX since they are pre-auth attack surface. This one
7 is particularly scary, since it requires hooks out to typically root-owned
8 system resources."
9 .
10 However, quite a lot of people rely on this in Debian, and it's better to
11 have it merged into the main openssh package rather than having separate
12 -krb5 packages (as we used to have). It seems to have a generally good
13 security history.
14Author: Simon Wilkinson <simon@sxw.org.uk>
15Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1242
16Last-Updated: 2010-02-27
17
18Index: b/ChangeLog.gssapi
19===================================================================
20--- /dev/null
21+++ b/ChangeLog.gssapi
22@@ -0,0 +1,113 @@
23+20110101
24+ - Finally update for OpenSSH 5.6p1
25+ - Add GSSAPIServerIdentity option from Jim Basney
26+
27+20100308
28+ - [ Makefile.in, key.c, key.h ]
29+ Updates for OpenSSH 5.4p1
30+ - [ servconf.c ]
31+ Include GSSAPI options in the sshd -T configuration dump, and flag
32+ some older configuration options as being unsupported. Thanks to Colin
33+ Watson.
34+ -
35+
36+20100124
37+ - [ sshconnect2.c ]
38+ Adapt to deal with additional element in Authmethod structure. Thanks to
39+ Colin Watson
40+
41+20090615
42+ - [ gss-genr.c gss-serv.c kexgssc.c kexgsss.c monitor.c sshconnect2.c
43+ sshd.c ]
44+ Fix issues identified by Greg Hudson following a code review
45+ Check return value of gss_indicate_mechs
46+ Protect GSSAPI calls in monitor, so they can only be used if enabled
47+ Check return values of bignum functions in key exchange
48+ Use BN_clear_free to clear other side's DH value
49+ Make ssh_gssapi_id_kex more robust
50+ Only configure kex table pointers if GSSAPI is enabled
51+ Don't leak mechanism list, or gss mechanism list
52+ Cast data.length before printing
53+ If serverkey isn't provided, use an empty string, rather than NULL
54+
55+20090201
56+ - [ gss-genr.c gss-serv.c kex.h kexgssc.c readconf.c readconf.h ssh-gss.h
57+ ssh_config.5 sshconnet2.c ]
58+ Add support for the GSSAPIClientIdentity option, which allows the user
59+ to specify which GSSAPI identity to use to contact a given server
60+
61+20080404
62+ - [ gss-serv.c ]
63+ Add code to actually implement GSSAPIStrictAcceptCheck, which had somehow
64+ been omitted from a previous version of this patch. Reported by Borislav
65+ Stoichkov
66+
67+20070317
68+ - [ gss-serv-krb5.c ]
69+ Remove C99ism, where new_ccname was being declared in the middle of a
70+ function
71+
72+20061220
73+ - [ servconf.c ]
74+ Make default for GSSAPIStrictAcceptorCheck be Yes, to match previous, and
75+ documented, behaviour. Reported by Dan Watson.
76+
77+20060910
78+ - [ gss-genr.c kexgssc.c kexgsss.c kex.h monitor.c sshconnect2.c sshd.c
79+ ssh-gss.h ]
80+ add support for gss-group14-sha1 key exchange mechanisms
81+ - [ gss-serv.c servconf.c servconf.h sshd_config sshd_config.5 ]
82+ Add GSSAPIStrictAcceptorCheck option to allow the disabling of
83+ acceptor principal checking on multi-homed machines.
84+ <Bugzilla #928>
85+ - [ sshd_config ssh_config ]
86+ Add settings for GSSAPIKeyExchange and GSSAPITrustDNS to the sample
87+ configuration files
88+ - [ kexgss.c kegsss.c sshconnect2.c sshd.c ]
89+ Code cleanup. Replace strlen/xmalloc/snprintf sequences with xasprintf()
90+ Limit length of error messages displayed by client
91+
92+20060909
93+ - [ gss-genr.c gss-serv.c ]
94+ move ssh_gssapi_acquire_cred() and ssh_gssapi_server_ctx to be server
95+ only, where they belong
96+ <Bugzilla #1225>
97+
98+20060829
99+ - [ gss-serv-krb5.c ]
100+ Fix CCAPI credentials cache name when creating KRB5CCNAME environment
101+ variable
102+
103+20060828
104+ - [ gss-genr.c ]
105+ Avoid Heimdal context freeing problem
106+ <Fixed upstream 20060829>
107+
108+20060818
109+ - [ gss-genr.c ssh-gss.h sshconnect2.c ]
110+ Make sure that SPENGO is disabled
111+ <Bugzilla #1218 - Fixed upstream 20060818>
112+
113+20060421
114+ - [ gssgenr.c, sshconnect2.c ]
115+ a few type changes (signed versus unsigned, int versus size_t) to
116+ fix compiler errors/warnings
117+ (from jbasney AT ncsa.uiuc.edu)
118+ - [ kexgssc.c, sshconnect2.c ]
119+ fix uninitialized variable warnings
120+ (from jbasney AT ncsa.uiuc.edu)
121+ - [ gssgenr.c ]
122+ pass oid to gss_display_status (helpful when using GSSAPI mechglue)
123+ (from jbasney AT ncsa.uiuc.edu)
124+ <Bugzilla #1220 >
125+ - [ gss-serv-krb5.c ]
126+ #ifdef HAVE_GSSAPI_KRB5 should be #ifdef HAVE_GSSAPI_KRB5_H
127+ (from jbasney AT ncsa.uiuc.edu)
128+ <Fixed upstream 20060304>
129+ - [ readconf.c, readconf.h, ssh_config.5, sshconnect2.c
130+ add client-side GssapiKeyExchange option
131+ (from jbasney AT ncsa.uiuc.edu)
132+ - [ sshconnect2.c ]
133+ add support for GssapiTrustDns option for gssapi-with-mic
134+ (from jbasney AT ncsa.uiuc.edu)
135+ <gssapi-with-mic support is Bugzilla #1008>
136Index: b/Makefile.in
137===================================================================
138--- a/Makefile.in
139+++ b/Makefile.in
140@@ -75,7 +75,7 @@
141 monitor_fdpass.o rijndael.o ssh-dss.o ssh-ecdsa.o ssh-rsa.o dh.o \
142 kexdh.o kexgex.o kexdhc.o kexgexc.o bufec.o kexecdh.o kexecdhc.o \
143 msg.o progressmeter.o dns.o entropy.o gss-genr.o umac.o jpake.o \
144- schnorr.o ssh-pkcs11.o
145+ schnorr.o kexgssc.o ssh-pkcs11.o
146
147 SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
148 sshconnect.o sshconnect1.o sshconnect2.o mux.o \
149@@ -90,7 +90,7 @@
150 auth2-none.o auth2-passwd.o auth2-pubkey.o auth2-jpake.o \
151 monitor_mm.o monitor.o monitor_wrap.o kexdhs.o kexgexs.o kexecdhs.o \
152 auth-krb5.o \
153- auth2-gss.o gss-serv.o gss-serv-krb5.o \
154+ auth2-gss.o gss-serv.o gss-serv-krb5.o kexgsss.o\
155 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
156 sftp-server.o sftp-common.o \
157 roaming_common.o roaming_serv.o
158Index: b/auth-krb5.c
159===================================================================
160--- a/auth-krb5.c
161+++ b/auth-krb5.c
162@@ -170,8 +170,13 @@
163
164 len = strlen(authctxt->krb5_ticket_file) + 6;
165 authctxt->krb5_ccname = xmalloc(len);
166+#ifdef USE_CCAPI
167+ snprintf(authctxt->krb5_ccname, len, "API:%s",
168+ authctxt->krb5_ticket_file);
169+#else
170 snprintf(authctxt->krb5_ccname, len, "FILE:%s",
171 authctxt->krb5_ticket_file);
172+#endif
173
174 #ifdef USE_PAM
175 if (options.use_pam)
176@@ -226,15 +231,22 @@
177 #ifndef HEIMDAL
178 krb5_error_code
179 ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
180- int tmpfd, ret;
181+ int ret;
182 char ccname[40];
183 mode_t old_umask;
184+#ifdef USE_CCAPI
185+ char cctemplate[] = "API:krb5cc_%d";
186+#else
187+ char cctemplate[] = "FILE:/tmp/krb5cc_%d_XXXXXXXXXX";
188+ int tmpfd;
189+#endif
190
191 ret = snprintf(ccname, sizeof(ccname),
192- "FILE:/tmp/krb5cc_%d_XXXXXXXXXX", geteuid());
193+ cctemplate, geteuid());
194 if (ret < 0 || (size_t)ret >= sizeof(ccname))
195 return ENOMEM;
196
197+#ifndef USE_CCAPI
198 old_umask = umask(0177);
199 tmpfd = mkstemp(ccname + strlen("FILE:"));
200 umask(old_umask);
201@@ -249,6 +261,7 @@
202 return errno;
203 }
204 close(tmpfd);
205+#endif
206
207 return (krb5_cc_resolve(ctx, ccname, ccache));
208 }
209Index: b/auth.h
210===================================================================
211--- a/auth.h
212+++ b/auth.h
213@@ -53,6 +53,7 @@
214 int valid; /* user exists and is allowed to login */
215 int attempt;
216 int failures;
217+ int server_caused_failure;
218 int force_pwchange;
219 char *user; /* username sent by the client */
220 char *service;
221Index: b/auth2-gss.c
222===================================================================
223--- a/auth2-gss.c
224+++ b/auth2-gss.c
225@@ -1,7 +1,7 @@
226 /* $OpenBSD: auth2-gss.c,v 1.16 2007/10/29 00:52:45 dtucker Exp $ */
227
228 /*
229- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
230+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
231 *
232 * Redistribution and use in source and binary forms, with or without
233 * modification, are permitted provided that the following conditions
234@@ -52,6 +52,40 @@
235 static void input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt);
236 static void input_gssapi_errtok(int, u_int32_t, void *);
237
238+/*
239+ * The 'gssapi_keyex' userauth mechanism.
240+ */
241+static int
242+userauth_gsskeyex(Authctxt *authctxt)
243+{
244+ int authenticated = 0;
245+ Buffer b;
246+ gss_buffer_desc mic, gssbuf;
247+ u_int len;
248+
249+ mic.value = packet_get_string(&len);
250+ mic.length = len;
251+
252+ packet_check_eom();
253+
254+ ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service,
255+ "gssapi-keyex");
256+
257+ gssbuf.value = buffer_ptr(&b);
258+ gssbuf.length = buffer_len(&b);
259+
260+ /* gss_kex_context is NULL with privsep, so we can't check it here */
261+ if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gss_kex_context,
262+ &gssbuf, &mic))))
263+ authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
264+ authctxt->pw));
265+
266+ buffer_free(&b);
267+ xfree(mic.value);
268+
269+ return (authenticated);
270+}
271+
272 /*
273 * We only support those mechanisms that we know about (ie ones that we know
274 * how to check local user kuserok and the like)
275@@ -102,6 +136,7 @@
276
277 if (!present) {
278 xfree(doid);
279+ authctxt->server_caused_failure = 1;
280 return (0);
281 }
282
283@@ -109,6 +144,7 @@
284 if (ctxt != NULL)
285 ssh_gssapi_delete_ctx(&ctxt);
286 xfree(doid);
287+ authctxt->server_caused_failure = 1;
288 return (0);
289 }
290
291@@ -242,7 +278,8 @@
292
293 packet_check_eom();
294
295- authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
296+ authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
297+ authctxt->pw));
298
299 authctxt->postponed = 0;
300 dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
301@@ -277,7 +314,8 @@
302 gssbuf.length = buffer_len(&b);
303
304 if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic))))
305- authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
306+ authenticated =
307+ PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw));
308 else
309 logit("GSSAPI MIC check failed");
310
311@@ -292,6 +330,12 @@
312 userauth_finish(authctxt, authenticated, "gssapi-with-mic");
313 }
314
315+Authmethod method_gsskeyex = {
316+ "gssapi-keyex",
317+ userauth_gsskeyex,
318+ &options.gss_authentication
319+};
320+
321 Authmethod method_gssapi = {
322 "gssapi-with-mic",
323 userauth_gssapi,
324Index: b/auth2.c
325===================================================================
326--- a/auth2.c
327+++ b/auth2.c
328@@ -69,6 +69,7 @@
329 extern Authmethod method_kbdint;
330 extern Authmethod method_hostbased;
331 #ifdef GSSAPI
332+extern Authmethod method_gsskeyex;
333 extern Authmethod method_gssapi;
334 #endif
335 #ifdef JPAKE
336@@ -79,6 +80,7 @@
337 &method_none,
338 &method_pubkey,
339 #ifdef GSSAPI
340+ &method_gsskeyex,
341 &method_gssapi,
342 #endif
343 #ifdef JPAKE
344@@ -274,6 +276,7 @@
345 #endif
346
347 authctxt->postponed = 0;
348+ authctxt->server_caused_failure = 0;
349
350 /* try to authenticate user */
351 m = authmethod_lookup(method);
352@@ -346,7 +349,8 @@
353 } else {
354
355 /* Allow initial try of "none" auth without failure penalty */
356- if (authctxt->attempt > 1 || strcmp(method, "none") != 0)
357+ if (!authctxt->server_caused_failure &&
358+ (authctxt->attempt > 1 || strcmp(method, "none") != 0))
359 authctxt->failures++;
360 if (authctxt->failures >= options.max_authtries) {
361 #ifdef SSH_AUDIT_EVENTS
362Index: b/clientloop.c
363===================================================================
364--- a/clientloop.c
365+++ b/clientloop.c
366@@ -111,6 +111,10 @@
367 #include "msg.h"
368 #include "roaming.h"
369
370+#ifdef GSSAPI
371+#include "ssh-gss.h"
372+#endif
373+
374 /* import options */
375 extern Options options;
376
377@@ -1483,6 +1487,15 @@
378 /* Do channel operations unless rekeying in progress. */
379 if (!rekeying) {
380 channel_after_select(readset, writeset);
381+
382+#ifdef GSSAPI
383+ if (options.gss_renewal_rekey &&
384+ ssh_gssapi_credentials_updated(GSS_C_NO_CONTEXT)) {
385+ debug("credentials updated - forcing rekey");
386+ need_rekeying = 1;
387+ }
388+#endif
389+
390 if (need_rekeying || packet_need_rekeying()) {
391 debug("need rekeying");
392 xxx_kex->done = 0;
393Index: b/configure.ac
394===================================================================
395--- a/configure.ac
396+++ b/configure.ac
397@@ -514,6 +514,30 @@
398 [Use tunnel device compatibility to OpenBSD])
399 AC_DEFINE(SSH_TUN_PREPEND_AF, 1,
400 [Prepend the address family to IP tunnel traffic])
401+ AC_MSG_CHECKING(if we have the Security Authorization Session API)
402+ AC_TRY_COMPILE([#include <Security/AuthSession.h>],
403+ [SessionCreate(0, 0);],
404+ [ac_cv_use_security_session_api="yes"
405+ AC_DEFINE(USE_SECURITY_SESSION_API, 1,
406+ [platform has the Security Authorization Session API])
407+ LIBS="$LIBS -framework Security"
408+ AC_MSG_RESULT(yes)],
409+ [ac_cv_use_security_session_api="no"
410+ AC_MSG_RESULT(no)])
411+ AC_MSG_CHECKING(if we have an in-memory credentials cache)
412+ AC_TRY_COMPILE(
413+ [#include <Kerberos/Kerberos.h>],
414+ [cc_context_t c;
415+ (void) cc_initialize (&c, 0, NULL, NULL);],
416+ [AC_DEFINE(USE_CCAPI, 1,
417+ [platform uses an in-memory credentials cache])
418+ LIBS="$LIBS -framework Security"
419+ AC_MSG_RESULT(yes)
420+ if test "x$ac_cv_use_security_session_api" = "xno"; then
421+ AC_MSG_ERROR(*** Need a security framework to use the credentials cache API ***)
422+ fi],
423+ [AC_MSG_RESULT(no)]
424+ )
425 m4_pattern_allow(AU_IPv)
426 AC_CHECK_DECL(AU_IPv4, [],
427 AC_DEFINE(AU_IPv4, 0, [System only supports IPv4 audit records])
428Index: b/gss-genr.c
429===================================================================
430--- a/gss-genr.c
431+++ b/gss-genr.c
432@@ -1,7 +1,7 @@
433 /* $OpenBSD: gss-genr.c,v 1.20 2009/06/22 05:39:28 dtucker Exp $ */
434
435 /*
436- * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
437+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
438 *
439 * Redistribution and use in source and binary forms, with or without
440 * modification, are permitted provided that the following conditions
441@@ -39,12 +39,167 @@
442 #include "buffer.h"
443 #include "log.h"
444 #include "ssh2.h"
445+#include "cipher.h"
446+#include "key.h"
447+#include "kex.h"
448+#include <openssl/evp.h>
449
450 #include "ssh-gss.h"
451
452 extern u_char *session_id2;
453 extern u_int session_id2_len;
454
455+typedef struct {
456+ char *encoded;
457+ gss_OID oid;
458+} ssh_gss_kex_mapping;
459+
460+/*
461+ * XXX - It would be nice to find a more elegant way of handling the
462+ * XXX passing of the key exchange context to the userauth routines
463+ */
464+
465+Gssctxt *gss_kex_context = NULL;
466+
467+static ssh_gss_kex_mapping *gss_enc2oid = NULL;
468+
469+int
470+ssh_gssapi_oid_table_ok() {
471+ return (gss_enc2oid != NULL);
472+}
473+
474+/*
475+ * Return a list of the gss-group1-sha1 mechanisms supported by this program
476+ *
477+ * We test mechanisms to ensure that we can use them, to avoid starting
478+ * a key exchange with a bad mechanism
479+ */
480+
481+char *
482+ssh_gssapi_client_mechanisms(const char *host, const char *client) {
483+ gss_OID_set gss_supported;
484+ OM_uint32 min_status;
485+
486+ if (GSS_ERROR(gss_indicate_mechs(&min_status, &gss_supported)))
487+ return NULL;
488+
489+ return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism,
490+ host, client));
491+}
492+
493+char *
494+ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
495+ const char *host, const char *client) {
496+ Buffer buf;
497+ size_t i;
498+ int oidpos, enclen;
499+ char *mechs, *encoded;
500+ u_char digest[EVP_MAX_MD_SIZE];
501+ char deroid[2];
502+ const EVP_MD *evp_md = EVP_md5();
503+ EVP_MD_CTX md;
504+
505+ if (gss_enc2oid != NULL) {
506+ for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
507+ xfree(gss_enc2oid[i].encoded);
508+ xfree(gss_enc2oid);
509+ }
510+
511+ gss_enc2oid = xmalloc(sizeof(ssh_gss_kex_mapping) *
512+ (gss_supported->count + 1));
513+
514+ buffer_init(&buf);
515+
516+ oidpos = 0;
517+ for (i = 0; i < gss_supported->count; i++) {
518+ if (gss_supported->elements[i].length < 128 &&
519+ (*check)(NULL, &(gss_supported->elements[i]), host, client)) {
520+
521+ deroid[0] = SSH_GSS_OIDTYPE;
522+ deroid[1] = gss_supported->elements[i].length;
523+
524+ EVP_DigestInit(&md, evp_md);
525+ EVP_DigestUpdate(&md, deroid, 2);
526+ EVP_DigestUpdate(&md,
527+ gss_supported->elements[i].elements,
528+ gss_supported->elements[i].length);
529+ EVP_DigestFinal(&md, digest, NULL);
530+
531+ encoded = xmalloc(EVP_MD_size(evp_md) * 2);
532+ enclen = __b64_ntop(digest, EVP_MD_size(evp_md),
533+ encoded, EVP_MD_size(evp_md) * 2);
534+
535+ if (oidpos != 0)
536+ buffer_put_char(&buf, ',');
537+
538+ buffer_append(&buf, KEX_GSS_GEX_SHA1_ID,
539+ sizeof(KEX_GSS_GEX_SHA1_ID) - 1);
540+ buffer_append(&buf, encoded, enclen);
541+ buffer_put_char(&buf, ',');
542+ buffer_append(&buf, KEX_GSS_GRP1_SHA1_ID,
543+ sizeof(KEX_GSS_GRP1_SHA1_ID) - 1);
544+ buffer_append(&buf, encoded, enclen);
545+ buffer_put_char(&buf, ',');
546+ buffer_append(&buf, KEX_GSS_GRP14_SHA1_ID,
547+ sizeof(KEX_GSS_GRP14_SHA1_ID) - 1);
548+ buffer_append(&buf, encoded, enclen);
549+
550+ gss_enc2oid[oidpos].oid = &(gss_supported->elements[i]);
551+ gss_enc2oid[oidpos].encoded = encoded;
552+ oidpos++;
553+ }
554+ }
555+ gss_enc2oid[oidpos].oid = NULL;
556+ gss_enc2oid[oidpos].encoded = NULL;
557+
558+ buffer_put_char(&buf, '\0');
559+
560+ mechs = xmalloc(buffer_len(&buf));
561+ buffer_get(&buf, mechs, buffer_len(&buf));
562+ buffer_free(&buf);
563+
564+ if (strlen(mechs) == 0) {
565+ xfree(mechs);
566+ mechs = NULL;
567+ }
568+
569+ return (mechs);
570+}
571+
572+gss_OID
573+ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
574+ int i = 0;
575+
576+ switch (kex_type) {
577+ case KEX_GSS_GRP1_SHA1:
578+ if (strlen(name) < sizeof(KEX_GSS_GRP1_SHA1_ID))
579+ return GSS_C_NO_OID;
580+ name += sizeof(KEX_GSS_GRP1_SHA1_ID) - 1;
581+ break;
582+ case KEX_GSS_GRP14_SHA1:
583+ if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA1_ID))
584+ return GSS_C_NO_OID;
585+ name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1;
586+ break;
587+ case KEX_GSS_GEX_SHA1:
588+ if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID))
589+ return GSS_C_NO_OID;
590+ name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1;
591+ break;
592+ default:
593+ return GSS_C_NO_OID;
594+ }
595+
596+ while (gss_enc2oid[i].encoded != NULL &&
597+ strcmp(name, gss_enc2oid[i].encoded) != 0)
598+ i++;
599+
600+ if (gss_enc2oid[i].oid != NULL && ctx != NULL)
601+ ssh_gssapi_set_oid(ctx, gss_enc2oid[i].oid);
602+
603+ return gss_enc2oid[i].oid;
604+}
605+
606 /* Check that the OID in a data stream matches that in the context */
607 int
608 ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len)
609@@ -197,7 +352,7 @@
610 }
611
612 ctx->major = gss_init_sec_context(&ctx->minor,
613- GSS_C_NO_CREDENTIAL, &ctx->context, ctx->name, ctx->oid,
614+ ctx->client_creds, &ctx->context, ctx->name, ctx->oid,
615 GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag,
616 0, NULL, recv_tok, NULL, send_tok, flags, NULL);
617
618@@ -227,8 +382,42 @@
619 }
620
621 OM_uint32
622+ssh_gssapi_client_identity(Gssctxt *ctx, const char *name)
623+{
624+ gss_buffer_desc gssbuf;
625+ gss_name_t gssname;
626+ OM_uint32 status;
627+ gss_OID_set oidset;
628+
629+ gssbuf.value = (void *) name;
630+ gssbuf.length = strlen(gssbuf.value);
631+
632+ gss_create_empty_oid_set(&status, &oidset);
633+ gss_add_oid_set_member(&status, ctx->oid, &oidset);
634+
635+ ctx->major = gss_import_name(&ctx->minor, &gssbuf,
636+ GSS_C_NT_USER_NAME, &gssname);
637+
638+ if (!ctx->major)
639+ ctx->major = gss_acquire_cred(&ctx->minor,
640+ gssname, 0, oidset, GSS_C_INITIATE,
641+ &ctx->client_creds, NULL, NULL);
642+
643+ gss_release_name(&status, &gssname);
644+ gss_release_oid_set(&status, &oidset);
645+
646+ if (ctx->major)
647+ ssh_gssapi_error(ctx);
648+
649+ return(ctx->major);
650+}
651+
652+OM_uint32
653 ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
654 {
655+ if (ctx == NULL)
656+ return -1;
657+
658 if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context,
659 GSS_C_QOP_DEFAULT, buffer, hash)))
660 ssh_gssapi_error(ctx);
661@@ -236,6 +425,19 @@
662 return (ctx->major);
663 }
664
665+/* Priviledged when used by server */
666+OM_uint32
667+ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
668+{
669+ if (ctx == NULL)
670+ return -1;
671+
672+ ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
673+ gssbuf, gssmic, NULL);
674+
675+ return (ctx->major);
676+}
677+
678 void
679 ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service,
680 const char *context)
681@@ -249,11 +451,16 @@
682 }
683
684 int
685-ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
686+ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host,
687+ const char *client)
688 {
689 gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
690 OM_uint32 major, minor;
691 gss_OID_desc spnego_oid = {6, (void *)"\x2B\x06\x01\x05\x05\x02"};
692+ Gssctxt *intctx = NULL;
693+
694+ if (ctx == NULL)
695+ ctx = &intctx;
696
697 /* RFC 4462 says we MUST NOT do SPNEGO */
698 if (oid->length == spnego_oid.length &&
699@@ -263,6 +470,10 @@
700 ssh_gssapi_build_ctx(ctx);
701 ssh_gssapi_set_oid(*ctx, oid);
702 major = ssh_gssapi_import_name(*ctx, host);
703+
704+ if (!GSS_ERROR(major) && client)
705+ major = ssh_gssapi_client_identity(*ctx, client);
706+
707 if (!GSS_ERROR(major)) {
708 major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token,
709 NULL);
710@@ -272,10 +483,67 @@
711 GSS_C_NO_BUFFER);
712 }
713
714- if (GSS_ERROR(major))
715+ if (GSS_ERROR(major) || intctx != NULL)
716 ssh_gssapi_delete_ctx(ctx);
717
718 return (!GSS_ERROR(major));
719 }
720
721+int
722+ssh_gssapi_credentials_updated(Gssctxt *ctxt) {
723+ static gss_name_t saved_name = GSS_C_NO_NAME;
724+ static OM_uint32 saved_lifetime = 0;
725+ static gss_OID saved_mech = GSS_C_NO_OID;
726+ static gss_name_t name;
727+ static OM_uint32 last_call = 0;
728+ OM_uint32 lifetime, now, major, minor;
729+ int equal;
730+ gss_cred_usage_t usage = GSS_C_INITIATE;
731+
732+ now = time(NULL);
733+
734+ if (ctxt) {
735+ debug("Rekey has happened - updating saved versions");
736+
737+ if (saved_name != GSS_C_NO_NAME)
738+ gss_release_name(&minor, &saved_name);
739+
740+ major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
741+ &saved_name, &saved_lifetime, NULL, NULL);
742+
743+ if (!GSS_ERROR(major)) {
744+ saved_mech = ctxt->oid;
745+ saved_lifetime+= now;
746+ } else {
747+ /* Handle the error */
748+ }
749+ return 0;
750+ }
751+
752+ if (now - last_call < 10)
753+ return 0;
754+
755+ last_call = now;
756+
757+ if (saved_mech == GSS_C_NO_OID)
758+ return 0;
759+
760+ major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
761+ &name, &lifetime, NULL, NULL);
762+ if (major == GSS_S_CREDENTIALS_EXPIRED)
763+ return 0;
764+ else if (GSS_ERROR(major))
765+ return 0;
766+
767+ major = gss_compare_name(&minor, saved_name, name, &equal);
768+ gss_release_name(&minor, &name);
769+ if (GSS_ERROR(major))
770+ return 0;
771+
772+ if (equal && (saved_lifetime < lifetime + now - 10))
773+ return 1;
774+
775+ return 0;
776+}
777+
778 #endif /* GSSAPI */
779Index: b/gss-serv-krb5.c
780===================================================================
781--- a/gss-serv-krb5.c
782+++ b/gss-serv-krb5.c
783@@ -1,7 +1,7 @@
784 /* $OpenBSD: gss-serv-krb5.c,v 1.7 2006/08/03 03:34:42 deraadt Exp $ */
785
786 /*
787- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
788+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
789 *
790 * Redistribution and use in source and binary forms, with or without
791 * modification, are permitted provided that the following conditions
792@@ -120,6 +120,7 @@
793 krb5_principal princ;
794 OM_uint32 maj_status, min_status;
795 int len;
796+ const char *new_ccname;
797
798 if (client->creds == NULL) {
799 debug("No credentials stored");
800@@ -168,11 +169,16 @@
801 return;
802 }
803
804- client->store.filename = xstrdup(krb5_cc_get_name(krb_context, ccache));
805+ new_ccname = krb5_cc_get_name(krb_context, ccache);
806+
807 client->store.envvar = "KRB5CCNAME";
808- len = strlen(client->store.filename) + 6;
809- client->store.envval = xmalloc(len);
810- snprintf(client->store.envval, len, "FILE:%s", client->store.filename);
811+#ifdef USE_CCAPI
812+ xasprintf(&client->store.envval, "API:%s", new_ccname);
813+ client->store.filename = NULL;
814+#else
815+ xasprintf(&client->store.envval, "FILE:%s", new_ccname);
816+ client->store.filename = xstrdup(new_ccname);
817+#endif
818
819 #ifdef USE_PAM
820 if (options.use_pam)
821@@ -184,6 +190,71 @@
822 return;
823 }
824
825+int
826+ssh_gssapi_krb5_updatecreds(ssh_gssapi_ccache *store,
827+ ssh_gssapi_client *client)
828+{
829+ krb5_ccache ccache = NULL;
830+ krb5_principal principal = NULL;
831+ char *name = NULL;
832+ krb5_error_code problem;
833+ OM_uint32 maj_status, min_status;
834+
835+ if ((problem = krb5_cc_resolve(krb_context, store->envval, &ccache))) {
836+ logit("krb5_cc_resolve(): %.100s",
837+ krb5_get_err_text(krb_context, problem));
838+ return 0;
839+ }
840+
841+ /* Find out who the principal in this cache is */
842+ if ((problem = krb5_cc_get_principal(krb_context, ccache,
843+ &principal))) {
844+ logit("krb5_cc_get_principal(): %.100s",
845+ krb5_get_err_text(krb_context, problem));
846+ krb5_cc_close(krb_context, ccache);
847+ return 0;
848+ }
849+
850+ if ((problem = krb5_unparse_name(krb_context, principal, &name))) {
851+ logit("krb5_unparse_name(): %.100s",
852+ krb5_get_err_text(krb_context, problem));
853+ krb5_free_principal(krb_context, principal);
854+ krb5_cc_close(krb_context, ccache);
855+ return 0;
856+ }
857+
858+
859+ if (strcmp(name,client->exportedname.value)!=0) {
860+ debug("Name in local credentials cache differs. Not storing");
861+ krb5_free_principal(krb_context, principal);
862+ krb5_cc_close(krb_context, ccache);
863+ krb5_free_unparsed_name(krb_context, name);
864+ return 0;
865+ }
866+ krb5_free_unparsed_name(krb_context, name);
867+
868+ /* Name matches, so lets get on with it! */
869+
870+ if ((problem = krb5_cc_initialize(krb_context, ccache, principal))) {
871+ logit("krb5_cc_initialize(): %.100s",
872+ krb5_get_err_text(krb_context, problem));
873+ krb5_free_principal(krb_context, principal);
874+ krb5_cc_close(krb_context, ccache);
875+ return 0;
876+ }
877+
878+ krb5_free_principal(krb_context, principal);
879+
880+ if ((maj_status = gss_krb5_copy_ccache(&min_status, client->creds,
881+ ccache))) {
882+ logit("gss_krb5_copy_ccache() failed. Sorry!");
883+ krb5_cc_close(krb_context, ccache);
884+ return 0;
885+ }
886+
887+ return 1;
888+}
889+
890 ssh_gssapi_mech gssapi_kerberos_mech = {
891 "toWM5Slw5Ew8Mqkay+al2g==",
892 "Kerberos",
893@@ -191,7 +262,8 @@
894 NULL,
895 &ssh_gssapi_krb5_userok,
896 NULL,
897- &ssh_gssapi_krb5_storecreds
898+ &ssh_gssapi_krb5_storecreds,
899+ &ssh_gssapi_krb5_updatecreds
900 };
901
902 #endif /* KRB5 */
903Index: b/gss-serv.c
904===================================================================
905--- a/gss-serv.c
906+++ b/gss-serv.c
907@@ -1,7 +1,7 @@
908 /* $OpenBSD: gss-serv.c,v 1.22 2008/05/08 12:02:23 djm Exp $ */
909
910 /*
911- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
912+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
913 *
914 * Redistribution and use in source and binary forms, with or without
915 * modification, are permitted provided that the following conditions
916@@ -45,15 +45,20 @@
917 #include "channels.h"
918 #include "session.h"
919 #include "misc.h"
920+#include "servconf.h"
921+#include "uidswap.h"
922
923 #include "ssh-gss.h"
924+#include "monitor_wrap.h"
925+
926+extern ServerOptions options;
927
928 static ssh_gssapi_client gssapi_client =
929 { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER,
930- GSS_C_NO_CREDENTIAL, NULL, {NULL, NULL, NULL}};
931+ GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME, NULL, {NULL, NULL, NULL}, 0, 0};
932
933 ssh_gssapi_mech gssapi_null_mech =
934- { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL};
935+ { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL, NULL};
936
937 #ifdef KRB5
938 extern ssh_gssapi_mech gssapi_kerberos_mech;
939@@ -81,25 +86,32 @@
940 char lname[MAXHOSTNAMELEN];
941 gss_OID_set oidset;
942
943- gss_create_empty_oid_set(&status, &oidset);
944- gss_add_oid_set_member(&status, ctx->oid, &oidset);
945+ if (options.gss_strict_acceptor) {
946+ gss_create_empty_oid_set(&status, &oidset);
947+ gss_add_oid_set_member(&status, ctx->oid, &oidset);
948+
949+ if (gethostname(lname, MAXHOSTNAMELEN)) {
950+ gss_release_oid_set(&status, &oidset);
951+ return (-1);
952+ }
953
954- if (gethostname(lname, MAXHOSTNAMELEN)) {
955- gss_release_oid_set(&status, &oidset);
956- return (-1);
957- }
958+ if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
959+ gss_release_oid_set(&status, &oidset);
960+ return (ctx->major);
961+ }
962+
963+ if ((ctx->major = gss_acquire_cred(&ctx->minor,
964+ ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds,
965+ NULL, NULL)))
966+ ssh_gssapi_error(ctx);
967
968- if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
969 gss_release_oid_set(&status, &oidset);
970 return (ctx->major);
971+ } else {
972+ ctx->name = GSS_C_NO_NAME;
973+ ctx->creds = GSS_C_NO_CREDENTIAL;
974 }
975-
976- if ((ctx->major = gss_acquire_cred(&ctx->minor,
977- ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds, NULL, NULL)))
978- ssh_gssapi_error(ctx);
979-
980- gss_release_oid_set(&status, &oidset);
981- return (ctx->major);
982+ return GSS_S_COMPLETE;
983 }
984
985 /* Privileged */
986@@ -114,6 +126,29 @@
987 }
988
989 /* Unprivileged */
990+char *
991+ssh_gssapi_server_mechanisms() {
992+ gss_OID_set supported;
993+
994+ ssh_gssapi_supported_oids(&supported);
995+ return (ssh_gssapi_kex_mechs(supported, &ssh_gssapi_server_check_mech,
996+ NULL, NULL));
997+}
998+
999+/* Unprivileged */
1000+int
1001+ssh_gssapi_server_check_mech(Gssctxt **dum, gss_OID oid, const char *data,
1002+ const char *dummy) {
1003+ Gssctxt *ctx = NULL;
1004+ int res;
1005+
1006+ res = !GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctx, oid)));
1007+ ssh_gssapi_delete_ctx(&ctx);
1008+
1009+ return (res);
1010+}
1011+
1012+/* Unprivileged */
1013 void
1014 ssh_gssapi_supported_oids(gss_OID_set *oidset)
1015 {
1016@@ -123,7 +158,9 @@
1017 gss_OID_set supported;
1018
1019 gss_create_empty_oid_set(&min_status, oidset);
1020- gss_indicate_mechs(&min_status, &supported);
1021+
1022+ if (GSS_ERROR(gss_indicate_mechs(&min_status, &supported)))
1023+ return;
1024
1025 while (supported_mechs[i]->name != NULL) {
1026 if (GSS_ERROR(gss_test_oid_set_member(&min_status,
1027@@ -247,8 +284,48 @@
1028 ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
1029 {
1030 int i = 0;
1031+ int equal = 0;
1032+ gss_name_t new_name = GSS_C_NO_NAME;
1033+ gss_buffer_desc ename = GSS_C_EMPTY_BUFFER;
1034+
1035+ if (options.gss_store_rekey && client->used && ctx->client_creds) {
1036+ if (client->mech->oid.length != ctx->oid->length ||
1037+ (memcmp(client->mech->oid.elements,
1038+ ctx->oid->elements, ctx->oid->length) !=0)) {
1039+ debug("Rekeyed credentials have different mechanism");
1040+ return GSS_S_COMPLETE;
1041+ }
1042+
1043+ if ((ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
1044+ ctx->client_creds, ctx->oid, &new_name,
1045+ NULL, NULL, NULL))) {
1046+ ssh_gssapi_error(ctx);
1047+ return (ctx->major);
1048+ }
1049+
1050+ ctx->major = gss_compare_name(&ctx->minor, client->name,
1051+ new_name, &equal);
1052
1053- gss_buffer_desc ename;
1054+ if (GSS_ERROR(ctx->major)) {
1055+ ssh_gssapi_error(ctx);
1056+ return (ctx->major);
1057+ }
1058+
1059+ if (!equal) {
1060+ debug("Rekeyed credentials have different name");
1061+ return GSS_S_COMPLETE;
1062+ }
1063+
1064+ debug("Marking rekeyed credentials for export");
1065+
1066+ gss_release_name(&ctx->minor, &client->name);
1067+ gss_release_cred(&ctx->minor, &client->creds);
1068+ client->name = new_name;
1069+ client->creds = ctx->client_creds;
1070+ ctx->client_creds = GSS_C_NO_CREDENTIAL;
1071+ client->updated = 1;
1072+ return GSS_S_COMPLETE;
1073+ }
1074
1075 client->mech = NULL;
1076
1077@@ -263,6 +340,13 @@
1078 if (client->mech == NULL)
1079 return GSS_S_FAILURE;
1080
1081+ if (ctx->client_creds &&
1082+ (ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
1083+ ctx->client_creds, ctx->oid, &client->name, NULL, NULL, NULL))) {
1084+ ssh_gssapi_error(ctx);
1085+ return (ctx->major);
1086+ }
1087+
1088 if ((ctx->major = gss_display_name(&ctx->minor, ctx->client,
1089 &client->displayname, NULL))) {
1090 ssh_gssapi_error(ctx);
1091@@ -280,6 +364,8 @@
1092 return (ctx->major);
1093 }
1094
1095+ gss_release_buffer(&ctx->minor, &ename);
1096+
1097 /* We can't copy this structure, so we just move the pointer to it */
1098 client->creds = ctx->client_creds;
1099 ctx->client_creds = GSS_C_NO_CREDENTIAL;
1100@@ -327,7 +413,7 @@
1101
1102 /* Privileged */
1103 int
1104-ssh_gssapi_userok(char *user)
1105+ssh_gssapi_userok(char *user, struct passwd *pw)
1106 {
1107 OM_uint32 lmin;
1108
1109@@ -337,9 +423,11 @@
1110 return 0;
1111 }
1112 if (gssapi_client.mech && gssapi_client.mech->userok)
1113- if ((*gssapi_client.mech->userok)(&gssapi_client, user))
1114+ if ((*gssapi_client.mech->userok)(&gssapi_client, user)) {
1115+ gssapi_client.used = 1;
1116+ gssapi_client.store.owner = pw;
1117 return 1;
1118- else {
1119+ } else {
1120 /* Destroy delegated credentials if userok fails */
1121 gss_release_buffer(&lmin, &gssapi_client.displayname);
1122 gss_release_buffer(&lmin, &gssapi_client.exportedname);
1123@@ -352,14 +440,90 @@
1124 return (0);
1125 }
1126
1127-/* Privileged */
1128-OM_uint32
1129-ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
1130+/* These bits are only used for rekeying. The unpriviledged child is running
1131+ * as the user, the monitor is root.
1132+ *
1133+ * In the child, we want to :
1134+ * *) Ask the monitor to store our credentials into the store we specify
1135+ * *) If it succeeds, maybe do a PAM update
1136+ */
1137+
1138+/* Stuff for PAM */
1139+
1140+#ifdef USE_PAM
1141+static int ssh_gssapi_simple_conv(int n, const struct pam_message **msg,
1142+ struct pam_response **resp, void *data)
1143 {
1144- ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
1145- gssbuf, gssmic, NULL);
1146+ return (PAM_CONV_ERR);
1147+}
1148+#endif
1149
1150- return (ctx->major);
1151+void
1152+ssh_gssapi_rekey_creds() {
1153+ int ok;
1154+ int ret;
1155+#ifdef USE_PAM
1156+ pam_handle_t *pamh = NULL;
1157+ struct pam_conv pamconv = {ssh_gssapi_simple_conv, NULL};
1158+ char *envstr;
1159+#endif
1160+
1161+ if (gssapi_client.store.filename == NULL &&
1162+ gssapi_client.store.envval == NULL &&
1163+ gssapi_client.store.envvar == NULL)
1164+ return;
1165+
1166+ ok = PRIVSEP(ssh_gssapi_update_creds(&gssapi_client.store));
1167+
1168+ if (!ok)
1169+ return;
1170+
1171+ debug("Rekeyed credentials stored successfully");
1172+
1173+ /* Actually managing to play with the ssh pam stack from here will
1174+ * be next to impossible. In any case, we may want different options
1175+ * for rekeying. So, use our own :)
1176+ */
1177+#ifdef USE_PAM
1178+ if (!use_privsep) {
1179+ debug("Not even going to try and do PAM with privsep disabled");
1180+ return;
1181+ }
1182+
1183+ ret = pam_start("sshd-rekey", gssapi_client.store.owner->pw_name,
1184+ &pamconv, &pamh);
1185+ if (ret)
1186+ return;
1187+
1188+ xasprintf(&envstr, "%s=%s", gssapi_client.store.envvar,
1189+ gssapi_client.store.envval);
1190+
1191+ ret = pam_putenv(pamh, envstr);
1192+ if (!ret)
1193+ pam_setcred(pamh, PAM_REINITIALIZE_CRED);
1194+ pam_end(pamh, PAM_SUCCESS);
1195+#endif
1196+}
1197+
1198+int
1199+ssh_gssapi_update_creds(ssh_gssapi_ccache *store) {
1200+ int ok = 0;
1201+
1202+ /* Check we've got credentials to store */
1203+ if (!gssapi_client.updated)
1204+ return 0;
1205+
1206+ gssapi_client.updated = 0;
1207+
1208+ temporarily_use_uid(gssapi_client.store.owner);
1209+ if (gssapi_client.mech && gssapi_client.mech->updatecreds)
1210+ ok = (*gssapi_client.mech->updatecreds)(store, &gssapi_client);
1211+ else
1212+ debug("No update function for this mechanism");
1213+
1214+ restore_uid();
1215+
1216+ return ok;
1217 }
1218
1219 #endif
1220Index: b/kex.c
1221===================================================================
1222--- a/kex.c
1223+++ b/kex.c
1224@@ -50,6 +50,10 @@
1225 #include "monitor.h"
1226 #include "roaming.h"
1227
1228+#ifdef GSSAPI
1229+#include "ssh-gss.h"
1230+#endif
1231+
1232 #if OPENSSL_VERSION_NUMBER >= 0x00907000L
1233 # if defined(HAVE_EVP_SHA256)
1234 # define evp_ssh_sha256 EVP_sha256
1235@@ -358,6 +362,20 @@
1236 k->kex_type = KEX_ECDH_SHA2;
1237 k->evp_md = kex_ecdh_name_to_evpmd(k->name);
1238 #endif
1239+#ifdef GSSAPI
1240+ } else if (strncmp(k->name, KEX_GSS_GEX_SHA1_ID,
1241+ sizeof(KEX_GSS_GEX_SHA1_ID) - 1) == 0) {
1242+ k->kex_type = KEX_GSS_GEX_SHA1;
1243+ k->evp_md = EVP_sha1();
1244+ } else if (strncmp(k->name, KEX_GSS_GRP1_SHA1_ID,
1245+ sizeof(KEX_GSS_GRP1_SHA1_ID) - 1) == 0) {
1246+ k->kex_type = KEX_GSS_GRP1_SHA1;
1247+ k->evp_md = EVP_sha1();
1248+ } else if (strncmp(k->name, KEX_GSS_GRP14_SHA1_ID,
1249+ sizeof(KEX_GSS_GRP14_SHA1_ID) - 1) == 0) {
1250+ k->kex_type = KEX_GSS_GRP14_SHA1;
1251+ k->evp_md = EVP_sha1();
1252+#endif
1253 } else
1254 fatal("bad kex alg %s", k->name);
1255 }
1256Index: b/kex.h
1257===================================================================
1258--- a/kex.h
1259+++ b/kex.h
1260@@ -73,6 +73,9 @@
1261 KEX_DH_GEX_SHA1,
1262 KEX_DH_GEX_SHA256,
1263 KEX_ECDH_SHA2,
1264+ KEX_GSS_GRP1_SHA1,
1265+ KEX_GSS_GRP14_SHA1,
1266+ KEX_GSS_GEX_SHA1,
1267 KEX_MAX
1268 };
1269
1270@@ -129,6 +132,12 @@
1271 sig_atomic_t done;
1272 int flags;
1273 const EVP_MD *evp_md;
1274+#ifdef GSSAPI
1275+ int gss_deleg_creds;
1276+ int gss_trust_dns;
1277+ char *gss_host;
1278+ char *gss_client;
1279+#endif
1280 char *client_version_string;
1281 char *server_version_string;
1282 int (*verify_host_key)(Key *);
1283@@ -156,6 +165,11 @@
1284 void kexecdh_client(Kex *);
1285 void kexecdh_server(Kex *);
1286
1287+#ifdef GSSAPI
1288+void kexgss_client(Kex *);
1289+void kexgss_server(Kex *);
1290+#endif
1291+
1292 void
1293 kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
1294 BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *);
1295Index: b/kexgssc.c
1296===================================================================
1297--- /dev/null
1298+++ b/kexgssc.c
1299@@ -0,0 +1,334 @@
1300+/*
1301+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1302+ *
1303+ * Redistribution and use in source and binary forms, with or without
1304+ * modification, are permitted provided that the following conditions
1305+ * are met:
1306+ * 1. Redistributions of source code must retain the above copyright
1307+ * notice, this list of conditions and the following disclaimer.
1308+ * 2. Redistributions in binary form must reproduce the above copyright
1309+ * notice, this list of conditions and the following disclaimer in the
1310+ * documentation and/or other materials provided with the distribution.
1311+ *
1312+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1313+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1314+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1315+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1316+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1317+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1318+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1319+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1320+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1321+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1322+ */
1323+
1324+#include "includes.h"
1325+
1326+#ifdef GSSAPI
1327+
1328+#include "includes.h"
1329+
1330+#include <openssl/crypto.h>
1331+#include <openssl/bn.h>
1332+
1333+#include <string.h>
1334+
1335+#include "xmalloc.h"
1336+#include "buffer.h"
1337+#include "ssh2.h"
1338+#include "key.h"
1339+#include "cipher.h"
1340+#include "kex.h"
1341+#include "log.h"
1342+#include "packet.h"
1343+#include "dh.h"
1344+
1345+#include "ssh-gss.h"
1346+
1347+void
1348+kexgss_client(Kex *kex) {
1349+ gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
1350+ gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
1351+ Gssctxt *ctxt;
1352+ OM_uint32 maj_status, min_status, ret_flags;
1353+ u_int klen, kout, slen = 0, hashlen, strlen;
1354+ DH *dh;
1355+ BIGNUM *dh_server_pub = NULL;
1356+ BIGNUM *shared_secret = NULL;
1357+ BIGNUM *p = NULL;
1358+ BIGNUM *g = NULL;
1359+ u_char *kbuf, *hash;
1360+ u_char *serverhostkey = NULL;
1361+ u_char *empty = "";
1362+ char *msg;
1363+ char *lang;
1364+ int type = 0;
1365+ int first = 1;
1366+ int nbits = 0, min = DH_GRP_MIN, max = DH_GRP_MAX;
1367+
1368+ /* Initialise our GSSAPI world */
1369+ ssh_gssapi_build_ctx(&ctxt);
1370+ if (ssh_gssapi_id_kex(ctxt, kex->name, kex->kex_type)
1371+ == GSS_C_NO_OID)
1372+ fatal("Couldn't identify host exchange");
1373+
1374+ if (ssh_gssapi_import_name(ctxt, kex->gss_host))
1375+ fatal("Couldn't import hostname");
1376+
1377+ if (kex->gss_client &&
1378+ ssh_gssapi_client_identity(ctxt, kex->gss_client))
1379+ fatal("Couldn't acquire client credentials");
1380+
1381+ switch (kex->kex_type) {
1382+ case KEX_GSS_GRP1_SHA1:
1383+ dh = dh_new_group1();
1384+ break;
1385+ case KEX_GSS_GRP14_SHA1:
1386+ dh = dh_new_group14();
1387+ break;
1388+ case KEX_GSS_GEX_SHA1:
1389+ debug("Doing group exchange\n");
1390+ nbits = dh_estimate(kex->we_need * 8);
1391+ packet_start(SSH2_MSG_KEXGSS_GROUPREQ);
1392+ packet_put_int(min);
1393+ packet_put_int(nbits);
1394+ packet_put_int(max);
1395+
1396+ packet_send();
1397+
1398+ packet_read_expect(SSH2_MSG_KEXGSS_GROUP);
1399+
1400+ if ((p = BN_new()) == NULL)
1401+ fatal("BN_new() failed");
1402+ packet_get_bignum2(p);
1403+ if ((g = BN_new()) == NULL)
1404+ fatal("BN_new() failed");
1405+ packet_get_bignum2(g);
1406+ packet_check_eom();
1407+
1408+ if (BN_num_bits(p) < min || BN_num_bits(p) > max)
1409+ fatal("GSSGRP_GEX group out of range: %d !< %d !< %d",
1410+ min, BN_num_bits(p), max);
1411+
1412+ dh = dh_new_group(g, p);
1413+ break;
1414+ default:
1415+ fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
1416+ }
1417+
1418+ /* Step 1 - e is dh->pub_key */
1419+ dh_gen_key(dh, kex->we_need * 8);
1420+
1421+ /* This is f, we initialise it now to make life easier */
1422+ dh_server_pub = BN_new();
1423+ if (dh_server_pub == NULL)
1424+ fatal("dh_server_pub == NULL");
1425+
1426+ token_ptr = GSS_C_NO_BUFFER;
1427+
1428+ do {
1429+ debug("Calling gss_init_sec_context");
1430+
1431+ maj_status = ssh_gssapi_init_ctx(ctxt,
1432+ kex->gss_deleg_creds, token_ptr, &send_tok,
1433+ &ret_flags);
1434+
1435+ if (GSS_ERROR(maj_status)) {
1436+ if (send_tok.length != 0) {
1437+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1438+ packet_put_string(send_tok.value,
1439+ send_tok.length);
1440+ }
1441+ fatal("gss_init_context failed");
1442+ }
1443+
1444+ /* If we've got an old receive buffer get rid of it */
1445+ if (token_ptr != GSS_C_NO_BUFFER)
1446+ xfree(recv_tok.value);
1447+
1448+ if (maj_status == GSS_S_COMPLETE) {
1449+ /* If mutual state flag is not true, kex fails */
1450+ if (!(ret_flags & GSS_C_MUTUAL_FLAG))
1451+ fatal("Mutual authentication failed");
1452+
1453+ /* If integ avail flag is not true kex fails */
1454+ if (!(ret_flags & GSS_C_INTEG_FLAG))
1455+ fatal("Integrity check failed");
1456+ }
1457+
1458+ /*
1459+ * If we have data to send, then the last message that we
1460+ * received cannot have been a 'complete'.
1461+ */
1462+ if (send_tok.length != 0) {
1463+ if (first) {
1464+ packet_start(SSH2_MSG_KEXGSS_INIT);
1465+ packet_put_string(send_tok.value,
1466+ send_tok.length);
1467+ packet_put_bignum2(dh->pub_key);
1468+ first = 0;
1469+ } else {
1470+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1471+ packet_put_string(send_tok.value,
1472+ send_tok.length);
1473+ }
1474+ packet_send();
1475+ gss_release_buffer(&min_status, &send_tok);
1476+
1477+ /* If we've sent them data, they should reply */
1478+ do {
1479+ type = packet_read();
1480+ if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
1481+ debug("Received KEXGSS_HOSTKEY");
1482+ if (serverhostkey)
1483+ fatal("Server host key received more than once");
1484+ serverhostkey =
1485+ packet_get_string(&slen);
1486+ }
1487+ } while (type == SSH2_MSG_KEXGSS_HOSTKEY);
1488+
1489+ switch (type) {
1490+ case SSH2_MSG_KEXGSS_CONTINUE:
1491+ debug("Received GSSAPI_CONTINUE");
1492+ if (maj_status == GSS_S_COMPLETE)
1493+ fatal("GSSAPI Continue received from server when complete");
1494+ recv_tok.value = packet_get_string(&strlen);
1495+ recv_tok.length = strlen;
1496+ break;
1497+ case SSH2_MSG_KEXGSS_COMPLETE:
1498+ debug("Received GSSAPI_COMPLETE");
1499+ packet_get_bignum2(dh_server_pub);
1500+ msg_tok.value = packet_get_string(&strlen);
1501+ msg_tok.length = strlen;
1502+
1503+ /* Is there a token included? */
1504+ if (packet_get_char()) {
1505+ recv_tok.value=
1506+ packet_get_string(&strlen);
1507+ recv_tok.length = strlen;
1508+ /* If we're already complete - protocol error */
1509+ if (maj_status == GSS_S_COMPLETE)
1510+ packet_disconnect("Protocol error: received token when complete");
1511+ } else {
1512+ /* No token included */
1513+ if (maj_status != GSS_S_COMPLETE)
1514+ packet_disconnect("Protocol error: did not receive final token");
1515+ }
1516+ break;
1517+ case SSH2_MSG_KEXGSS_ERROR:
1518+ debug("Received Error");
1519+ maj_status = packet_get_int();
1520+ min_status = packet_get_int();
1521+ msg = packet_get_string(NULL);
1522+ lang = packet_get_string(NULL);
1523+ fatal("GSSAPI Error: \n%.400s",msg);
1524+ default:
1525+ packet_disconnect("Protocol error: didn't expect packet type %d",
1526+ type);
1527+ }
1528+ token_ptr = &recv_tok;
1529+ } else {
1530+ /* No data, and not complete */
1531+ if (maj_status != GSS_S_COMPLETE)
1532+ fatal("Not complete, and no token output");
1533+ }
1534+ } while (maj_status & GSS_S_CONTINUE_NEEDED);
1535+
1536+ /*
1537+ * We _must_ have received a COMPLETE message in reply from the
1538+ * server, which will have set dh_server_pub and msg_tok
1539+ */
1540+
1541+ if (type != SSH2_MSG_KEXGSS_COMPLETE)
1542+ fatal("Didn't receive a SSH2_MSG_KEXGSS_COMPLETE when I expected it");
1543+
1544+ /* Check f in range [1, p-1] */
1545+ if (!dh_pub_is_valid(dh, dh_server_pub))
1546+ packet_disconnect("bad server public DH value");
1547+
1548+ /* compute K=f^x mod p */
1549+ klen = DH_size(dh);
1550+ kbuf = xmalloc(klen);
1551+ kout = DH_compute_key(kbuf, dh_server_pub, dh);
1552+ if (kout < 0)
1553+ fatal("DH_compute_key: failed");
1554+
1555+ shared_secret = BN_new();
1556+ if (shared_secret == NULL)
1557+ fatal("kexgss_client: BN_new failed");
1558+
1559+ if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
1560+ fatal("kexdh_client: BN_bin2bn failed");
1561+
1562+ memset(kbuf, 0, klen);
1563+ xfree(kbuf);
1564+
1565+ switch (kex->kex_type) {
1566+ case KEX_GSS_GRP1_SHA1:
1567+ case KEX_GSS_GRP14_SHA1:
1568+ kex_dh_hash( kex->client_version_string,
1569+ kex->server_version_string,
1570+ buffer_ptr(&kex->my), buffer_len(&kex->my),
1571+ buffer_ptr(&kex->peer), buffer_len(&kex->peer),
1572+ (serverhostkey ? serverhostkey : empty), slen,
1573+ dh->pub_key, /* e */
1574+ dh_server_pub, /* f */
1575+ shared_secret, /* K */
1576+ &hash, &hashlen
1577+ );
1578+ break;
1579+ case KEX_GSS_GEX_SHA1:
1580+ kexgex_hash(
1581+ kex->evp_md,
1582+ kex->client_version_string,
1583+ kex->server_version_string,
1584+ buffer_ptr(&kex->my), buffer_len(&kex->my),
1585+ buffer_ptr(&kex->peer), buffer_len(&kex->peer),
1586+ (serverhostkey ? serverhostkey : empty), slen,
1587+ min, nbits, max,
1588+ dh->p, dh->g,
1589+ dh->pub_key,
1590+ dh_server_pub,
1591+ shared_secret,
1592+ &hash, &hashlen
1593+ );
1594+ break;
1595+ default:
1596+ fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
1597+ }
1598+
1599+ gssbuf.value = hash;
1600+ gssbuf.length = hashlen;
1601+
1602+ /* Verify that the hash matches the MIC we just got. */
1603+ if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
1604+ packet_disconnect("Hash's MIC didn't verify");
1605+
1606+ xfree(msg_tok.value);
1607+
1608+ DH_free(dh);
1609+ if (serverhostkey)
1610+ xfree(serverhostkey);
1611+ BN_clear_free(dh_server_pub);
1612+
1613+ /* save session id */
1614+ if (kex->session_id == NULL) {
1615+ kex->session_id_len = hashlen;
1616+ kex->session_id = xmalloc(kex->session_id_len);
1617+ memcpy(kex->session_id, hash, kex->session_id_len);
1618+ }
1619+
1620+ if (kex->gss_deleg_creds)
1621+ ssh_gssapi_credentials_updated(ctxt);
1622+
1623+ if (gss_kex_context == NULL)
1624+ gss_kex_context = ctxt;
1625+ else
1626+ ssh_gssapi_delete_ctx(&ctxt);
1627+
1628+ kex_derive_keys(kex, hash, hashlen, shared_secret);
1629+ BN_clear_free(shared_secret);
1630+ kex_finish(kex);
1631+}
1632+
1633+#endif /* GSSAPI */
1634Index: b/kexgsss.c
1635===================================================================
1636--- /dev/null
1637+++ b/kexgsss.c
1638@@ -0,0 +1,288 @@
1639+/*
1640+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
1641+ *
1642+ * Redistribution and use in source and binary forms, with or without
1643+ * modification, are permitted provided that the following conditions
1644+ * are met:
1645+ * 1. Redistributions of source code must retain the above copyright
1646+ * notice, this list of conditions and the following disclaimer.
1647+ * 2. Redistributions in binary form must reproduce the above copyright
1648+ * notice, this list of conditions and the following disclaimer in the
1649+ * documentation and/or other materials provided with the distribution.
1650+ *
1651+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
1652+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1653+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1654+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1655+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1656+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1657+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1658+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1659+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1660+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1661+ */
1662+
1663+#include "includes.h"
1664+
1665+#ifdef GSSAPI
1666+
1667+#include <string.h>
1668+
1669+#include <openssl/crypto.h>
1670+#include <openssl/bn.h>
1671+
1672+#include "xmalloc.h"
1673+#include "buffer.h"
1674+#include "ssh2.h"
1675+#include "key.h"
1676+#include "cipher.h"
1677+#include "kex.h"
1678+#include "log.h"
1679+#include "packet.h"
1680+#include "dh.h"
1681+#include "ssh-gss.h"
1682+#include "monitor_wrap.h"
1683+#include "servconf.h"
1684+
1685+extern ServerOptions options;
1686+
1687+void
1688+kexgss_server(Kex *kex)
1689+{
1690+ OM_uint32 maj_status, min_status;
1691+
1692+ /*
1693+ * Some GSSAPI implementations use the input value of ret_flags (an
1694+ * output variable) as a means of triggering mechanism specific
1695+ * features. Initializing it to zero avoids inadvertently
1696+ * activating this non-standard behaviour.
1697+ */
1698+
1699+ OM_uint32 ret_flags = 0;
1700+ gss_buffer_desc gssbuf, recv_tok, msg_tok;
1701+ gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
1702+ Gssctxt *ctxt = NULL;
1703+ u_int slen, klen, kout, hashlen;
1704+ u_char *kbuf, *hash;
1705+ DH *dh;
1706+ int min = -1, max = -1, nbits = -1;
1707+ BIGNUM *shared_secret = NULL;
1708+ BIGNUM *dh_client_pub = NULL;
1709+ int type = 0;
1710+ gss_OID oid;
1711+ char *mechs;
1712+
1713+ /* Initialise GSSAPI */
1714+
1715+ /* If we're rekeying, privsep means that some of the private structures
1716+ * in the GSSAPI code are no longer available. This kludges them back
1717+ * into life
1718+ */
1719+ if (!ssh_gssapi_oid_table_ok())
1720+ if ((mechs = ssh_gssapi_server_mechanisms()))
1721+ xfree(mechs);
1722+
1723+ debug2("%s: Identifying %s", __func__, kex->name);
1724+ oid = ssh_gssapi_id_kex(NULL, kex->name, kex->kex_type);
1725+ if (oid == GSS_C_NO_OID)
1726+ fatal("Unknown gssapi mechanism");
1727+
1728+ debug2("%s: Acquiring credentials", __func__);
1729+
1730+ if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid))))
1731+ fatal("Unable to acquire credentials for the server");
1732+
1733+ switch (kex->kex_type) {
1734+ case KEX_GSS_GRP1_SHA1:
1735+ dh = dh_new_group1();
1736+ break;
1737+ case KEX_GSS_GRP14_SHA1:
1738+ dh = dh_new_group14();
1739+ break;
1740+ case KEX_GSS_GEX_SHA1:
1741+ debug("Doing group exchange");
1742+ packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ);
1743+ min = packet_get_int();
1744+ nbits = packet_get_int();
1745+ max = packet_get_int();
1746+ min = MAX(DH_GRP_MIN, min);
1747+ max = MIN(DH_GRP_MAX, max);
1748+ packet_check_eom();
1749+ if (max < min || nbits < min || max < nbits)
1750+ fatal("GSS_GEX, bad parameters: %d !< %d !< %d",
1751+ min, nbits, max);
1752+ dh = PRIVSEP(choose_dh(min, nbits, max));
1753+ if (dh == NULL)
1754+ packet_disconnect("Protocol error: no matching group found");
1755+
1756+ packet_start(SSH2_MSG_KEXGSS_GROUP);
1757+ packet_put_bignum2(dh->p);
1758+ packet_put_bignum2(dh->g);
1759+ packet_send();
1760+
1761+ packet_write_wait();
1762+ break;
1763+ default:
1764+ fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
1765+ }
1766+
1767+ dh_gen_key(dh, kex->we_need * 8);
1768+
1769+ do {
1770+ debug("Wait SSH2_MSG_GSSAPI_INIT");
1771+ type = packet_read();
1772+ switch(type) {
1773+ case SSH2_MSG_KEXGSS_INIT:
1774+ if (dh_client_pub != NULL)
1775+ fatal("Received KEXGSS_INIT after initialising");
1776+ recv_tok.value = packet_get_string(&slen);
1777+ recv_tok.length = slen;
1778+
1779+ if ((dh_client_pub = BN_new()) == NULL)
1780+ fatal("dh_client_pub == NULL");
1781+
1782+ packet_get_bignum2(dh_client_pub);
1783+
1784+ /* Send SSH_MSG_KEXGSS_HOSTKEY here, if we want */
1785+ break;
1786+ case SSH2_MSG_KEXGSS_CONTINUE:
1787+ recv_tok.value = packet_get_string(&slen);
1788+ recv_tok.length = slen;
1789+ break;
1790+ default:
1791+ packet_disconnect(
1792+ "Protocol error: didn't expect packet type %d",
1793+ type);
1794+ }
1795+
1796+ maj_status = PRIVSEP(ssh_gssapi_accept_ctx(ctxt, &recv_tok,
1797+ &send_tok, &ret_flags));
1798+
1799+ xfree(recv_tok.value);
1800+
1801+ if (maj_status != GSS_S_COMPLETE && send_tok.length == 0)
1802+ fatal("Zero length token output when incomplete");
1803+
1804+ if (dh_client_pub == NULL)
1805+ fatal("No client public key");
1806+
1807+ if (maj_status & GSS_S_CONTINUE_NEEDED) {
1808+ debug("Sending GSSAPI_CONTINUE");
1809+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1810+ packet_put_string(send_tok.value, send_tok.length);
1811+ packet_send();
1812+ gss_release_buffer(&min_status, &send_tok);
1813+ }
1814+ } while (maj_status & GSS_S_CONTINUE_NEEDED);
1815+
1816+ if (GSS_ERROR(maj_status)) {
1817+ if (send_tok.length > 0) {
1818+ packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1819+ packet_put_string(send_tok.value, send_tok.length);
1820+ packet_send();
1821+ }
1822+ fatal("accept_ctx died");
1823+ }
1824+
1825+ if (!(ret_flags & GSS_C_MUTUAL_FLAG))
1826+ fatal("Mutual Authentication flag wasn't set");
1827+
1828+ if (!(ret_flags & GSS_C_INTEG_FLAG))
1829+ fatal("Integrity flag wasn't set");
1830+
1831+ if (!dh_pub_is_valid(dh, dh_client_pub))
1832+ packet_disconnect("bad client public DH value");
1833+
1834+ klen = DH_size(dh);
1835+ kbuf = xmalloc(klen);
1836+ kout = DH_compute_key(kbuf, dh_client_pub, dh);
1837+ if (kout < 0)
1838+ fatal("DH_compute_key: failed");
1839+
1840+ shared_secret = BN_new();
1841+ if (shared_secret == NULL)
1842+ fatal("kexgss_server: BN_new failed");
1843+
1844+ if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
1845+ fatal("kexgss_server: BN_bin2bn failed");
1846+
1847+ memset(kbuf, 0, klen);
1848+ xfree(kbuf);
1849+
1850+ switch (kex->kex_type) {
1851+ case KEX_GSS_GRP1_SHA1:
1852+ case KEX_GSS_GRP14_SHA1:
1853+ kex_dh_hash(
1854+ kex->client_version_string, kex->server_version_string,
1855+ buffer_ptr(&kex->peer), buffer_len(&kex->peer),
1856+ buffer_ptr(&kex->my), buffer_len(&kex->my),
1857+ NULL, 0, /* Change this if we start sending host keys */
1858+ dh_client_pub, dh->pub_key, shared_secret,
1859+ &hash, &hashlen
1860+ );
1861+ break;
1862+ case KEX_GSS_GEX_SHA1:
1863+ kexgex_hash(
1864+ kex->evp_md,
1865+ kex->client_version_string, kex->server_version_string,
1866+ buffer_ptr(&kex->peer), buffer_len(&kex->peer),
1867+ buffer_ptr(&kex->my), buffer_len(&kex->my),
1868+ NULL, 0,
1869+ min, nbits, max,
1870+ dh->p, dh->g,
1871+ dh_client_pub,
1872+ dh->pub_key,
1873+ shared_secret,
1874+ &hash, &hashlen
1875+ );
1876+ break;
1877+ default:
1878+ fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
1879+ }
1880+
1881+ BN_clear_free(dh_client_pub);
1882+
1883+ if (kex->session_id == NULL) {
1884+ kex->session_id_len = hashlen;
1885+ kex->session_id = xmalloc(kex->session_id_len);
1886+ memcpy(kex->session_id, hash, kex->session_id_len);
1887+ }
1888+
1889+ gssbuf.value = hash;
1890+ gssbuf.length = hashlen;
1891+
1892+ if (GSS_ERROR(PRIVSEP(ssh_gssapi_sign(ctxt,&gssbuf,&msg_tok))))
1893+ fatal("Couldn't get MIC");
1894+
1895+ packet_start(SSH2_MSG_KEXGSS_COMPLETE);
1896+ packet_put_bignum2(dh->pub_key);
1897+ packet_put_string(msg_tok.value,msg_tok.length);
1898+
1899+ if (send_tok.length != 0) {
1900+ packet_put_char(1); /* true */
1901+ packet_put_string(send_tok.value, send_tok.length);
1902+ } else {
1903+ packet_put_char(0); /* false */
1904+ }
1905+ packet_send();
1906+
1907+ gss_release_buffer(&min_status, &send_tok);
1908+ gss_release_buffer(&min_status, &msg_tok);
1909+
1910+ if (gss_kex_context == NULL)
1911+ gss_kex_context = ctxt;
1912+ else
1913+ ssh_gssapi_delete_ctx(&ctxt);
1914+
1915+ DH_free(dh);
1916+
1917+ kex_derive_keys(kex, hash, hashlen, shared_secret);
1918+ BN_clear_free(shared_secret);
1919+ kex_finish(kex);
1920+
1921+ /* If this was a rekey, then save out any delegated credentials we
1922+ * just exchanged. */
1923+ if (options.gss_store_rekey)
1924+ ssh_gssapi_rekey_creds();
1925+}
1926+#endif /* GSSAPI */
1927Index: b/key.c
1928===================================================================
1929--- a/key.c
1930+++ b/key.c
1931@@ -971,6 +971,8 @@
1932 }
1933 break;
1934 #endif /* OPENSSL_HAS_ECC */
1935+ case KEY_NULL:
1936+ return "null";
1937 }
1938 return "ssh-unknown";
1939 }
1940@@ -1276,6 +1278,8 @@
1941 strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
1942 return KEY_ECDSA_CERT;
1943 #endif
1944+ } else if (strcmp(name, "null") == 0) {
1945+ return KEY_NULL;
1946 }
1947
1948 debug2("key_type_from_name: unknown key type '%s'", name);
1949Index: b/key.h
1950===================================================================
1951--- a/key.h
1952+++ b/key.h
1953@@ -44,6 +44,7 @@
1954 KEY_ECDSA_CERT,
1955 KEY_RSA_CERT_V00,
1956 KEY_DSA_CERT_V00,
1957+ KEY_NULL,
1958 KEY_UNSPEC
1959 };
1960 enum fp_type {
1961Index: b/monitor.c
1962===================================================================
1963--- a/monitor.c
1964+++ b/monitor.c
1965@@ -172,6 +172,8 @@
1966 int mm_answer_gss_accept_ctx(int, Buffer *);
1967 int mm_answer_gss_userok(int, Buffer *);
1968 int mm_answer_gss_checkmic(int, Buffer *);
1969+int mm_answer_gss_sign(int, Buffer *);
1970+int mm_answer_gss_updatecreds(int, Buffer *);
1971 #endif
1972
1973 #ifdef SSH_AUDIT_EVENTS
1974@@ -241,6 +243,7 @@
1975 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
1976 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
1977 {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic},
1978+ {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
1979 #endif
1980 #ifdef JPAKE
1981 {MONITOR_REQ_JPAKE_GET_PWDATA, MON_ONCE, mm_answer_jpake_get_pwdata},
1982@@ -253,6 +256,12 @@
1983 };
1984
1985 struct mon_table mon_dispatch_postauth20[] = {
1986+#ifdef GSSAPI
1987+ {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
1988+ {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
1989+ {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
1990+ {MONITOR_REQ_GSSUPCREDS, 0, mm_answer_gss_updatecreds},
1991+#endif
1992 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
1993 {MONITOR_REQ_SIGN, 0, mm_answer_sign},
1994 {MONITOR_REQ_PTY, 0, mm_answer_pty},
1995@@ -357,6 +366,10 @@
1996 /* Permit requests for moduli and signatures */
1997 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
1998 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
1999+#ifdef GSSAPI
2000+ /* and for the GSSAPI key exchange */
2001+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
2002+#endif
2003 } else {
2004 mon_dispatch = mon_dispatch_proto15;
2005
2006@@ -443,6 +456,10 @@
2007 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
2008 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
2009 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
2010+#ifdef GSSAPI
2011+ /* and for the GSSAPI key exchange */
2012+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
2013+#endif
2014 } else {
2015 mon_dispatch = mon_dispatch_postauth15;
2016 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
2017@@ -1692,6 +1709,13 @@
2018 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
2019 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
2020 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
2021+#ifdef GSSAPI
2022+ if (options.gss_keyex) {
2023+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
2024+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
2025+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
2026+ }
2027+#endif
2028 kex->server = 1;
2029 kex->hostkey_type = buffer_get_int(m);
2030 kex->kex_type = buffer_get_int(m);
2031@@ -1898,6 +1922,9 @@
2032 OM_uint32 major;
2033 u_int len;
2034
2035+ if (!options.gss_authentication && !options.gss_keyex)
2036+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2037+
2038 goid.elements = buffer_get_string(m, &len);
2039 goid.length = len;
2040
2041@@ -1925,6 +1952,9 @@
2042 OM_uint32 flags = 0; /* GSI needs this */
2043 u_int len;
2044
2045+ if (!options.gss_authentication && !options.gss_keyex)
2046+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2047+
2048 in.value = buffer_get_string(m, &len);
2049 in.length = len;
2050 major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags);
2051@@ -1942,6 +1972,7 @@
2052 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
2053 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
2054 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1);
2055+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1);
2056 }
2057 return (0);
2058 }
2059@@ -1953,6 +1984,9 @@
2060 OM_uint32 ret;
2061 u_int len;
2062
2063+ if (!options.gss_authentication && !options.gss_keyex)
2064+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2065+
2066 gssbuf.value = buffer_get_string(m, &len);
2067 gssbuf.length = len;
2068 mic.value = buffer_get_string(m, &len);
2069@@ -1979,7 +2013,11 @@
2070 {
2071 int authenticated;
2072
2073- authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
2074+ if (!options.gss_authentication && !options.gss_keyex)
2075+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2076+
2077+ authenticated = authctxt->valid &&
2078+ ssh_gssapi_userok(authctxt->user, authctxt->pw);
2079
2080 buffer_clear(m);
2081 buffer_put_int(m, authenticated);
2082@@ -1992,6 +2030,74 @@
2083 /* Monitor loop will terminate if authenticated */
2084 return (authenticated);
2085 }
2086+
2087+int
2088+mm_answer_gss_sign(int socket, Buffer *m)
2089+{
2090+ gss_buffer_desc data;
2091+ gss_buffer_desc hash = GSS_C_EMPTY_BUFFER;
2092+ OM_uint32 major, minor;
2093+ u_int len;
2094+
2095+ if (!options.gss_authentication && !options.gss_keyex)
2096+ fatal("In GSSAPI monitor when GSSAPI is disabled");
2097+
2098+ data.value = buffer_get_string(m, &len);
2099+ data.length = len;
2100+ if (data.length != 20)
2101+ fatal("%s: data length incorrect: %d", __func__,
2102+ (int) data.length);
2103+
2104+ /* Save the session ID on the first time around */
2105+ if (session_id2_len == 0) {
2106+ session_id2_len = data.length;
2107+ session_id2 = xmalloc(session_id2_len);
2108+ memcpy(session_id2, data.value, session_id2_len);
2109+ }
2110+ major = ssh_gssapi_sign(gsscontext, &data, &hash);
2111+
2112+ xfree(data.value);
2113+
2114+ buffer_clear(m);
2115+ buffer_put_int(m, major);
2116+ buffer_put_string(m, hash.value, hash.length);
2117+
2118+ mm_request_send(socket, MONITOR_ANS_GSSSIGN, m);
2119+
2120+ gss_release_buffer(&minor, &hash);
2121+
2122+ /* Turn on getpwnam permissions */
2123+ monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
2124+
2125+ /* And credential updating, for when rekeying */
2126+ monitor_permit(mon_dispatch, MONITOR_REQ_GSSUPCREDS, 1);
2127+
2128+ return (0);
2129+}
2130+
2131+int
2132+mm_answer_gss_updatecreds(int socket, Buffer *m) {
2133+ ssh_gssapi_ccache store;
2134+ int ok;
2135+
2136+ store.filename = buffer_get_string(m, NULL);
2137+ store.envvar = buffer_get_string(m, NULL);
2138+ store.envval = buffer_get_string(m, NULL);
2139+
2140+ ok = ssh_gssapi_update_creds(&store);
2141+
2142+ xfree(store.filename);
2143+ xfree(store.envvar);
2144+ xfree(store.envval);
2145+
2146+ buffer_clear(m);
2147+ buffer_put_int(m, ok);
2148+
2149+ mm_request_send(socket, MONITOR_ANS_GSSUPCREDS, m);
2150+
2151+ return(0);
2152+}
2153+
2154 #endif /* GSSAPI */
2155
2156 #ifdef JPAKE
2157Index: b/monitor.h
2158===================================================================
2159--- a/monitor.h
2160+++ b/monitor.h
2161@@ -53,6 +53,8 @@
2162 MONITOR_REQ_GSSSTEP, MONITOR_ANS_GSSSTEP,
2163 MONITOR_REQ_GSSUSEROK, MONITOR_ANS_GSSUSEROK,
2164 MONITOR_REQ_GSSCHECKMIC, MONITOR_ANS_GSSCHECKMIC,
2165+ MONITOR_REQ_GSSSIGN, MONITOR_ANS_GSSSIGN,
2166+ MONITOR_REQ_GSSUPCREDS, MONITOR_ANS_GSSUPCREDS,
2167 MONITOR_REQ_PAM_START,
2168 MONITOR_REQ_PAM_ACCOUNT, MONITOR_ANS_PAM_ACCOUNT,
2169 MONITOR_REQ_PAM_INIT_CTX, MONITOR_ANS_PAM_INIT_CTX,
2170Index: b/monitor_wrap.c
2171===================================================================
2172--- a/monitor_wrap.c
2173+++ b/monitor_wrap.c
2174@@ -1232,7 +1232,7 @@
2175 }
2176
2177 int
2178-mm_ssh_gssapi_userok(char *user)
2179+mm_ssh_gssapi_userok(char *user, struct passwd *pw)
2180 {
2181 Buffer m;
2182 int authenticated = 0;
2183@@ -1249,6 +1249,51 @@
2184 debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
2185 return (authenticated);
2186 }
2187+
2188+OM_uint32
2189+mm_ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_desc *data, gss_buffer_desc *hash)
2190+{
2191+ Buffer m;
2192+ OM_uint32 major;
2193+ u_int len;
2194+
2195+ buffer_init(&m);
2196+ buffer_put_string(&m, data->value, data->length);
2197+
2198+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSIGN, &m);
2199+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSIGN, &m);
2200+
2201+ major = buffer_get_int(&m);
2202+ hash->value = buffer_get_string(&m, &len);
2203+ hash->length = len;
2204+
2205+ buffer_free(&m);
2206+
2207+ return(major);
2208+}
2209+
2210+int
2211+mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
2212+{
2213+ Buffer m;
2214+ int ok;
2215+
2216+ buffer_init(&m);
2217+
2218+ buffer_put_cstring(&m, store->filename ? store->filename : "");
2219+ buffer_put_cstring(&m, store->envvar ? store->envvar : "");
2220+ buffer_put_cstring(&m, store->envval ? store->envval : "");
2221+
2222+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUPCREDS, &m);
2223+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUPCREDS, &m);
2224+
2225+ ok = buffer_get_int(&m);
2226+
2227+ buffer_free(&m);
2228+
2229+ return (ok);
2230+}
2231+
2232 #endif /* GSSAPI */
2233
2234 #ifdef JPAKE
2235Index: b/monitor_wrap.h
2236===================================================================
2237--- a/monitor_wrap.h
2238+++ b/monitor_wrap.h
2239@@ -57,8 +57,10 @@
2240 OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
2241 OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *,
2242 gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *);
2243-int mm_ssh_gssapi_userok(char *user);
2244+int mm_ssh_gssapi_userok(char *user, struct passwd *);
2245 OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
2246+OM_uint32 mm_ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
2247+int mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *);
2248 #endif
2249
2250 #ifdef USE_PAM
2251Index: b/readconf.c
2252===================================================================
2253--- a/readconf.c
2254+++ b/readconf.c
2255@@ -129,6 +129,8 @@
2256 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
2257 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
2258 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
2259+ oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey,
2260+ oGssServerIdentity,
2261 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
2262 oSendEnv, oControlPath, oControlMaster, oControlPersist,
2263 oHashKnownHosts,
2264@@ -169,10 +171,19 @@
2265 { "afstokenpassing", oUnsupported },
2266 #if defined(GSSAPI)
2267 { "gssapiauthentication", oGssAuthentication },
2268+ { "gssapikeyexchange", oGssKeyEx },
2269 { "gssapidelegatecredentials", oGssDelegateCreds },
2270+ { "gssapitrustdns", oGssTrustDns },
2271+ { "gssapiclientidentity", oGssClientIdentity },
2272+ { "gssapiserveridentity", oGssServerIdentity },
2273+ { "gssapirenewalforcesrekey", oGssRenewalRekey },
2274 #else
2275 { "gssapiauthentication", oUnsupported },
2276+ { "gssapikeyexchange", oUnsupported },
2277 { "gssapidelegatecredentials", oUnsupported },
2278+ { "gssapitrustdns", oUnsupported },
2279+ { "gssapiclientidentity", oUnsupported },
2280+ { "gssapirenewalforcesrekey", oUnsupported },
2281 #endif
2282 { "fallbacktorsh", oDeprecated },
2283 { "usersh", oDeprecated },
2284@@ -479,10 +490,30 @@
2285 intptr = &options->gss_authentication;
2286 goto parse_flag;
2287
2288+ case oGssKeyEx:
2289+ intptr = &options->gss_keyex;
2290+ goto parse_flag;
2291+
2292 case oGssDelegateCreds:
2293 intptr = &options->gss_deleg_creds;
2294 goto parse_flag;
2295
2296+ case oGssTrustDns:
2297+ intptr = &options->gss_trust_dns;
2298+ goto parse_flag;
2299+
2300+ case oGssClientIdentity:
2301+ charptr = &options->gss_client_identity;
2302+ goto parse_string;
2303+
2304+ case oGssServerIdentity:
2305+ charptr = &options->gss_server_identity;
2306+ goto parse_string;
2307+
2308+ case oGssRenewalRekey:
2309+ intptr = &options->gss_renewal_rekey;
2310+ goto parse_flag;
2311+
2312 case oBatchMode:
2313 intptr = &options->batch_mode;
2314 goto parse_flag;
2315@@ -1092,7 +1123,12 @@
2316 options->pubkey_authentication = -1;
2317 options->challenge_response_authentication = -1;
2318 options->gss_authentication = -1;
2319+ options->gss_keyex = -1;
2320 options->gss_deleg_creds = -1;
2321+ options->gss_trust_dns = -1;
2322+ options->gss_renewal_rekey = -1;
2323+ options->gss_client_identity = NULL;
2324+ options->gss_server_identity = NULL;
2325 options->password_authentication = -1;
2326 options->kbd_interactive_authentication = -1;
2327 options->kbd_interactive_devices = NULL;
2328@@ -1193,8 +1229,14 @@
2329 options->challenge_response_authentication = 1;
2330 if (options->gss_authentication == -1)
2331 options->gss_authentication = 0;
2332+ if (options->gss_keyex == -1)
2333+ options->gss_keyex = 0;
2334 if (options->gss_deleg_creds == -1)
2335 options->gss_deleg_creds = 0;
2336+ if (options->gss_trust_dns == -1)
2337+ options->gss_trust_dns = 0;
2338+ if (options->gss_renewal_rekey == -1)
2339+ options->gss_renewal_rekey = 0;
2340 if (options->password_authentication == -1)
2341 options->password_authentication = 1;
2342 if (options->kbd_interactive_authentication == -1)
2343Index: b/readconf.h
2344===================================================================
2345--- a/readconf.h
2346+++ b/readconf.h
2347@@ -46,7 +46,12 @@
2348 int challenge_response_authentication;
2349 /* Try S/Key or TIS, authentication. */
2350 int gss_authentication; /* Try GSS authentication */
2351+ int gss_keyex; /* Try GSS key exchange */
2352 int gss_deleg_creds; /* Delegate GSS credentials */
2353+ int gss_trust_dns; /* Trust DNS for GSS canonicalization */
2354+ int gss_renewal_rekey; /* Credential renewal forces rekey */
2355+ char *gss_client_identity; /* Principal to initiate GSSAPI with */
2356+ char *gss_server_identity; /* GSSAPI target principal */
2357 int password_authentication; /* Try password
2358 * authentication. */
2359 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
2360Index: b/servconf.c
2361===================================================================
2362--- a/servconf.c
2363+++ b/servconf.c
2364@@ -97,7 +97,10 @@
2365 options->kerberos_ticket_cleanup = -1;
2366 options->kerberos_get_afs_token = -1;
2367 options->gss_authentication=-1;
2368+ options->gss_keyex = -1;
2369 options->gss_cleanup_creds = -1;
2370+ options->gss_strict_acceptor = -1;
2371+ options->gss_store_rekey = -1;
2372 options->password_authentication = -1;
2373 options->kbd_interactive_authentication = -1;
2374 options->challenge_response_authentication = -1;
2375@@ -226,8 +229,14 @@
2376 options->kerberos_get_afs_token = 0;
2377 if (options->gss_authentication == -1)
2378 options->gss_authentication = 0;
2379+ if (options->gss_keyex == -1)
2380+ options->gss_keyex = 0;
2381 if (options->gss_cleanup_creds == -1)
2382 options->gss_cleanup_creds = 1;
2383+ if (options->gss_strict_acceptor == -1)
2384+ options->gss_strict_acceptor = 1;
2385+ if (options->gss_store_rekey == -1)
2386+ options->gss_store_rekey = 0;
2387 if (options->password_authentication == -1)
2388 options->password_authentication = 1;
2389 if (options->kbd_interactive_authentication == -1)
2390@@ -322,7 +331,9 @@
2391 sBanner, sUseDNS, sHostbasedAuthentication,
2392 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
2393 sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
2394- sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
2395+ sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
2396+ sGssKeyEx, sGssStoreRekey,
2397+ sAcceptEnv, sPermitTunnel,
2398 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
2399 sUsePrivilegeSeparation, sAllowAgentForwarding,
2400 sZeroKnowledgePasswordAuthentication, sHostCertificate,
2401@@ -386,10 +397,20 @@
2402 #ifdef GSSAPI
2403 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
2404 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
2405+ { "gssapicleanupcreds", sGssCleanupCreds, SSHCFG_GLOBAL },
2406+ { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
2407+ { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
2408+ { "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
2409 #else
2410 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
2411 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
2412+ { "gssapicleanupcreds", sUnsupported, SSHCFG_GLOBAL },
2413+ { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
2414+ { "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
2415+ { "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
2416 #endif
2417+ { "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL },
2418+ { "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL },
2419 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
2420 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
2421 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
2422@@ -944,10 +965,22 @@
2423 intptr = &options->gss_authentication;
2424 goto parse_flag;
2425
2426+ case sGssKeyEx:
2427+ intptr = &options->gss_keyex;
2428+ goto parse_flag;
2429+
2430 case sGssCleanupCreds:
2431 intptr = &options->gss_cleanup_creds;
2432 goto parse_flag;
2433
2434+ case sGssStrictAcceptor:
2435+ intptr = &options->gss_strict_acceptor;
2436+ goto parse_flag;
2437+
2438+ case sGssStoreRekey:
2439+ intptr = &options->gss_store_rekey;
2440+ goto parse_flag;
2441+
2442 case sPasswordAuthentication:
2443 intptr = &options->password_authentication;
2444 goto parse_flag;
2445@@ -1704,7 +1737,10 @@
2446 #endif
2447 #ifdef GSSAPI
2448 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2449+ dump_cfg_fmtint(sGssKeyEx, o->gss_keyex);
2450 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
2451+ dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor);
2452+ dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey);
2453 #endif
2454 #ifdef JPAKE
2455 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
2456Index: b/servconf.h
2457===================================================================
2458--- a/servconf.h
2459+++ b/servconf.h
2460@@ -97,7 +97,10 @@
2461 int kerberos_get_afs_token; /* If true, try to get AFS token if
2462 * authenticated with Kerberos. */
2463 int gss_authentication; /* If true, permit GSSAPI authentication */
2464+ int gss_keyex; /* If true, permit GSSAPI key exchange */
2465 int gss_cleanup_creds; /* If true, destroy cred cache on logout */
2466+ int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */
2467+ int gss_store_rekey;
2468 int password_authentication; /* If true, permit password
2469 * authentication. */
2470 int kbd_interactive_authentication; /* If true, permit */
2471Index: b/ssh-gss.h
2472===================================================================
2473--- a/ssh-gss.h
2474+++ b/ssh-gss.h
2475@@ -1,6 +1,6 @@
2476 /* $OpenBSD: ssh-gss.h,v 1.10 2007/06/12 08:20:00 djm Exp $ */
2477 /*
2478- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
2479+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
2480 *
2481 * Redistribution and use in source and binary forms, with or without
2482 * modification, are permitted provided that the following conditions
2483@@ -60,10 +60,22 @@
2484
2485 #define SSH_GSS_OIDTYPE 0x06
2486
2487+#define SSH2_MSG_KEXGSS_INIT 30
2488+#define SSH2_MSG_KEXGSS_CONTINUE 31
2489+#define SSH2_MSG_KEXGSS_COMPLETE 32
2490+#define SSH2_MSG_KEXGSS_HOSTKEY 33
2491+#define SSH2_MSG_KEXGSS_ERROR 34
2492+#define SSH2_MSG_KEXGSS_GROUPREQ 40
2493+#define SSH2_MSG_KEXGSS_GROUP 41
2494+#define KEX_GSS_GRP1_SHA1_ID "gss-group1-sha1-"
2495+#define KEX_GSS_GRP14_SHA1_ID "gss-group14-sha1-"
2496+#define KEX_GSS_GEX_SHA1_ID "gss-gex-sha1-"
2497+
2498 typedef struct {
2499 char *filename;
2500 char *envvar;
2501 char *envval;
2502+ struct passwd *owner;
2503 void *data;
2504 } ssh_gssapi_ccache;
2505
2506@@ -71,8 +83,11 @@
2507 gss_buffer_desc displayname;
2508 gss_buffer_desc exportedname;
2509 gss_cred_id_t creds;
2510+ gss_name_t name;
2511 struct ssh_gssapi_mech_struct *mech;
2512 ssh_gssapi_ccache store;
2513+ int used;
2514+ int updated;
2515 } ssh_gssapi_client;
2516
2517 typedef struct ssh_gssapi_mech_struct {
2518@@ -83,6 +98,7 @@
2519 int (*userok) (ssh_gssapi_client *, char *);
2520 int (*localname) (ssh_gssapi_client *, char **);
2521 void (*storecreds) (ssh_gssapi_client *);
2522+ int (*updatecreds) (ssh_gssapi_ccache *, ssh_gssapi_client *);
2523 } ssh_gssapi_mech;
2524
2525 typedef struct {
2526@@ -93,10 +109,11 @@
2527 gss_OID oid; /* client */
2528 gss_cred_id_t creds; /* server */
2529 gss_name_t client; /* server */
2530- gss_cred_id_t client_creds; /* server */
2531+ gss_cred_id_t client_creds; /* both */
2532 } Gssctxt;
2533
2534 extern ssh_gssapi_mech *supported_mechs[];
2535+extern Gssctxt *gss_kex_context;
2536
2537 int ssh_gssapi_check_oid(Gssctxt *, void *, size_t);
2538 void ssh_gssapi_set_oid_data(Gssctxt *, void *, size_t);
2539@@ -116,16 +133,30 @@
2540 void ssh_gssapi_delete_ctx(Gssctxt **);
2541 OM_uint32 ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
2542 void ssh_gssapi_buildmic(Buffer *, const char *, const char *, const char *);
2543-int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *);
2544+int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *, const char *);
2545+OM_uint32 ssh_gssapi_client_identity(Gssctxt *, const char *);
2546+int ssh_gssapi_credentials_updated(Gssctxt *);
2547
2548 /* In the server */
2549+typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *,
2550+ const char *);
2551+char *ssh_gssapi_client_mechanisms(const char *, const char *);
2552+char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *,
2553+ const char *);
2554+gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
2555+int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *,
2556+ const char *);
2557 OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
2558-int ssh_gssapi_userok(char *name);
2559+int ssh_gssapi_userok(char *name, struct passwd *);
2560 OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
2561 void ssh_gssapi_do_child(char ***, u_int *);
2562 void ssh_gssapi_cleanup_creds(void);
2563 void ssh_gssapi_storecreds(void);
2564
2565+char *ssh_gssapi_server_mechanisms(void);
2566+int ssh_gssapi_oid_table_ok();
2567+
2568+int ssh_gssapi_update_creds(ssh_gssapi_ccache *store);
2569 #endif /* GSSAPI */
2570
2571 #endif /* _SSH_GSS_H */
2572Index: b/ssh_config
2573===================================================================
2574--- a/ssh_config
2575+++ b/ssh_config
2576@@ -26,6 +26,8 @@
2577 # HostbasedAuthentication no
2578 # GSSAPIAuthentication no
2579 # GSSAPIDelegateCredentials no
2580+# GSSAPIKeyExchange no
2581+# GSSAPITrustDNS no
2582 # BatchMode no
2583 # CheckHostIP yes
2584 # AddressFamily any
2585Index: b/ssh_config.5
2586===================================================================
2587--- a/ssh_config.5
2588+++ b/ssh_config.5
2589@@ -508,11 +508,43 @@
2590 The default is
2591 .Dq no .
2592 Note that this option applies to protocol version 2 only.
2593+.It Cm GSSAPIKeyExchange
2594+Specifies whether key exchange based on GSSAPI may be used. When using
2595+GSSAPI key exchange the server need not have a host key.
2596+The default is
2597+.Dq no .
2598+Note that this option applies to protocol version 2 only.
2599+.It Cm GSSAPIClientIdentity
2600+If set, specifies the GSSAPI client identity that ssh should use when
2601+connecting to the server. The default is unset, which means that the default
2602+identity will be used.
2603+.It Cm GSSAPIServerIdentity
2604+If set, specifies the GSSAPI server identity that ssh should expect when
2605+connecting to the server. The default is unset, which means that the
2606+expected GSSAPI server identity will be determined from the target
2607+hostname.
2608 .It Cm GSSAPIDelegateCredentials
2609 Forward (delegate) credentials to the server.
2610 The default is
2611 .Dq no .
2612-Note that this option applies to protocol version 2 only.
2613+Note that this option applies to protocol version 2 connections using GSSAPI.
2614+.It Cm GSSAPIRenewalForcesRekey
2615+If set to
2616+.Dq yes
2617+then renewal of the client's GSSAPI credentials will force the rekeying of the
2618+ssh connection. With a compatible server, this can delegate the renewed
2619+credentials to a session on the server.
2620+The default is
2621+.Dq no .
2622+.It Cm GSSAPITrustDns
2623+Set to
2624+.Dq yes to indicate that the DNS is trusted to securely canonicalize
2625+the name of the host being connected to. If
2626+.Dq no, the hostname entered on the
2627+command line will be passed untouched to the GSSAPI library.
2628+The default is
2629+.Dq no .
2630+This option only applies to protocol version 2 connections using GSSAPI.
2631 .It Cm HashKnownHosts
2632 Indicates that
2633 .Xr ssh 1
2634Index: b/sshconnect2.c
2635===================================================================
2636--- a/sshconnect2.c
2637+++ b/sshconnect2.c
2638@@ -159,9 +159,34 @@
2639 {
2640 Kex *kex;
2641
2642+#ifdef GSSAPI
2643+ char *orig = NULL, *gss = NULL;
2644+ char *gss_host = NULL;
2645+#endif
2646+
2647 xxx_host = host;
2648 xxx_hostaddr = hostaddr;
2649
2650+#ifdef GSSAPI
2651+ if (options.gss_keyex) {
2652+ /* Add the GSSAPI mechanisms currently supported on this
2653+ * client to the key exchange algorithm proposal */
2654+ orig = myproposal[PROPOSAL_KEX_ALGS];
2655+
2656+ if (options.gss_trust_dns)
2657+ gss_host = (char *)get_canonical_hostname(1);
2658+ else
2659+ gss_host = host;
2660+
2661+ gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
2662+ if (gss) {
2663+ debug("Offering GSSAPI proposal: %s", gss);
2664+ xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
2665+ "%s,%s", gss, orig);
2666+ }
2667+ }
2668+#endif
2669+
2670 if (options.ciphers == (char *)-1) {
2671 logit("No valid ciphers for protocol version 2 given, using defaults.");
2672 options.ciphers = NULL;
2673@@ -196,6 +221,17 @@
2674 if (options.kex_algorithms != NULL)
2675 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
2676
2677+#ifdef GSSAPI
2678+ /* If we've got GSSAPI algorithms, then we also support the
2679+ * 'null' hostkey, as a last resort */
2680+ if (options.gss_keyex && gss) {
2681+ orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
2682+ xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
2683+ "%s,null", orig);
2684+ xfree(gss);
2685+ }
2686+#endif
2687+
2688 if (options.rekey_limit)
2689 packet_set_rekey_limit((u_int32_t)options.rekey_limit);
2690
2691@@ -206,10 +242,30 @@
2692 kex->kex[KEX_DH_GEX_SHA1] = kexgex_client;
2693 kex->kex[KEX_DH_GEX_SHA256] = kexgex_client;
2694 kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
2695+#ifdef GSSAPI
2696+ if (options.gss_keyex) {
2697+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client;
2698+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client;
2699+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
2700+ }
2701+#endif
2702 kex->client_version_string=client_version_string;
2703 kex->server_version_string=server_version_string;
2704 kex->verify_host_key=&verify_host_key_callback;
2705
2706+#ifdef GSSAPI
2707+ if (options.gss_keyex) {
2708+ kex->gss_deleg_creds = options.gss_deleg_creds;
2709+ kex->gss_trust_dns = options.gss_trust_dns;
2710+ kex->gss_client = options.gss_client_identity;
2711+ if (options.gss_server_identity) {
2712+ kex->gss_host = options.gss_server_identity;
2713+ } else {
2714+ kex->gss_host = gss_host;
2715+ }
2716+ }
2717+#endif
2718+
2719 xxx_kex = kex;
2720
2721 dispatch_run(DISPATCH_BLOCK, &kex->done, kex);
2722@@ -304,6 +360,7 @@
2723 void input_gssapi_hash(int type, u_int32_t, void *);
2724 void input_gssapi_error(int, u_int32_t, void *);
2725 void input_gssapi_errtok(int, u_int32_t, void *);
2726+int userauth_gsskeyex(Authctxt *authctxt);
2727 #endif
2728
2729 void userauth(Authctxt *, char *);
2730@@ -319,6 +376,11 @@
2731
2732 Authmethod authmethods[] = {
2733 #ifdef GSSAPI
2734+ {"gssapi-keyex",
2735+ userauth_gsskeyex,
2736+ NULL,
2737+ &options.gss_authentication,
2738+ NULL},
2739 {"gssapi-with-mic",
2740 userauth_gssapi,
2741 NULL,
2742@@ -625,19 +687,31 @@
2743 static u_int mech = 0;
2744 OM_uint32 min;
2745 int ok = 0;
2746+ const char *gss_host;
2747+
2748+ if (options.gss_server_identity)
2749+ gss_host = options.gss_server_identity;
2750+ else if (options.gss_trust_dns)
2751+ gss_host = get_canonical_hostname(1);
2752+ else
2753+ gss_host = authctxt->host;
2754
2755 /* Try one GSSAPI method at a time, rather than sending them all at
2756 * once. */
2757
2758 if (gss_supported == NULL)
2759- gss_indicate_mechs(&min, &gss_supported);
2760+ if (GSS_ERROR(gss_indicate_mechs(&min, &gss_supported))) {
2761+ gss_supported = NULL;
2762+ return 0;
2763+ }
2764
2765 /* Check to see if the mechanism is usable before we offer it */
2766 while (mech < gss_supported->count && !ok) {
2767 /* My DER encoding requires length<128 */
2768 if (gss_supported->elements[mech].length < 128 &&
2769 ssh_gssapi_check_mechanism(&gssctxt,
2770- &gss_supported->elements[mech], authctxt->host)) {
2771+ &gss_supported->elements[mech], gss_host,
2772+ options.gss_client_identity)) {
2773 ok = 1; /* Mechanism works */
2774 } else {
2775 mech++;
2776@@ -734,8 +808,8 @@
2777 {
2778 Authctxt *authctxt = ctxt;
2779 Gssctxt *gssctxt;
2780- int oidlen;
2781- char *oidv;
2782+ u_int oidlen;
2783+ u_char *oidv;
2784
2785 if (authctxt == NULL)
2786 fatal("input_gssapi_response: no authentication context");
2787@@ -845,6 +919,48 @@
2788 xfree(msg);
2789 xfree(lang);
2790 }
2791+
2792+int
2793+userauth_gsskeyex(Authctxt *authctxt)
2794+{
2795+ Buffer b;
2796+ gss_buffer_desc gssbuf;
2797+ gss_buffer_desc mic = GSS_C_EMPTY_BUFFER;
2798+ OM_uint32 ms;
2799+
2800+ static int attempt = 0;
2801+ if (attempt++ >= 1)
2802+ return (0);
2803+
2804+ if (gss_kex_context == NULL) {
2805+ debug("No valid Key exchange context");
2806+ return (0);
2807+ }
2808+
2809+ ssh_gssapi_buildmic(&b, authctxt->server_user, authctxt->service,
2810+ "gssapi-keyex");
2811+
2812+ gssbuf.value = buffer_ptr(&b);
2813+ gssbuf.length = buffer_len(&b);
2814+
2815+ if (GSS_ERROR(ssh_gssapi_sign(gss_kex_context, &gssbuf, &mic))) {
2816+ buffer_free(&b);
2817+ return (0);
2818+ }
2819+
2820+ packet_start(SSH2_MSG_USERAUTH_REQUEST);
2821+ packet_put_cstring(authctxt->server_user);
2822+ packet_put_cstring(authctxt->service);
2823+ packet_put_cstring(authctxt->method->name);
2824+ packet_put_string(mic.value, mic.length);
2825+ packet_send();
2826+
2827+ buffer_free(&b);
2828+ gss_release_buffer(&ms, &mic);
2829+
2830+ return (1);
2831+}
2832+
2833 #endif /* GSSAPI */
2834
2835 int
2836Index: b/sshd.c
2837===================================================================
2838--- a/sshd.c
2839+++ b/sshd.c
2840@@ -120,6 +120,10 @@
2841 #include "roaming.h"
2842 #include "version.h"
2843
2844+#ifdef USE_SECURITY_SESSION_API
2845+#include <Security/AuthSession.h>
2846+#endif
2847+
2848 #ifdef LIBWRAP
2849 #include <tcpd.h>
2850 #include <syslog.h>
2851@@ -1590,10 +1594,13 @@
2852 logit("Disabling protocol version 1. Could not load host key");
2853 options.protocol &= ~SSH_PROTO_1;
2854 }
2855+#ifndef GSSAPI
2856+ /* The GSSAPI key exchange can run without a host key */
2857 if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) {
2858 logit("Disabling protocol version 2. Could not load host key");
2859 options.protocol &= ~SSH_PROTO_2;
2860 }
2861+#endif
2862 if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) {
2863 logit("sshd: no hostkeys available -- exiting.");
2864 exit(1);
2865@@ -1922,6 +1929,60 @@
2866 /* Log the connection. */
2867 verbose("Connection from %.500s port %d", remote_ip, remote_port);
2868
2869+#ifdef USE_SECURITY_SESSION_API
2870+ /*
2871+ * Create a new security session for use by the new user login if
2872+ * the current session is the root session or we are not launched
2873+ * by inetd (eg: debugging mode or server mode). We do not
2874+ * necessarily need to create a session if we are launched from
2875+ * inetd because Panther xinetd will create a session for us.
2876+ *
2877+ * The only case where this logic will fail is if there is an
2878+ * inetd running in a non-root session which is not creating
2879+ * new sessions for us. Then all the users will end up in the
2880+ * same session (bad).
2881+ *
2882+ * When the client exits, the session will be destroyed for us
2883+ * automatically.
2884+ *
2885+ * We must create the session before any credentials are stored
2886+ * (including AFS pags, which happens a few lines below).
2887+ */
2888+ {
2889+ OSStatus err = 0;
2890+ SecuritySessionId sid = 0;
2891+ SessionAttributeBits sattrs = 0;
2892+
2893+ err = SessionGetInfo(callerSecuritySession, &sid, &sattrs);
2894+ if (err)
2895+ error("SessionGetInfo() failed with error %.8X",
2896+ (unsigned) err);
2897+ else
2898+ debug("Current Session ID is %.8X / Session Attributes are %.8X",
2899+ (unsigned) sid, (unsigned) sattrs);
2900+
2901+ if (inetd_flag && !(sattrs & sessionIsRoot))
2902+ debug("Running in inetd mode in a non-root session... "
2903+ "assuming inetd created the session for us.");
2904+ else {
2905+ debug("Creating new security session...");
2906+ err = SessionCreate(0, sessionHasTTY | sessionIsRemote);
2907+ if (err)
2908+ error("SessionCreate() failed with error %.8X",
2909+ (unsigned) err);
2910+
2911+ err = SessionGetInfo(callerSecuritySession, &sid,
2912+ &sattrs);
2913+ if (err)
2914+ error("SessionGetInfo() failed with error %.8X",
2915+ (unsigned) err);
2916+ else
2917+ debug("New Session ID is %.8X / Session Attributes are %.8X",
2918+ (unsigned) sid, (unsigned) sattrs);
2919+ }
2920+ }
2921+#endif
2922+
2923 /*
2924 * We don't want to listen forever unless the other side
2925 * successfully authenticates itself. So we set up an alarm which is
2926@@ -2303,6 +2364,48 @@
2927
2928 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types();
2929
2930+#ifdef GSSAPI
2931+ {
2932+ char *orig;
2933+ char *gss = NULL;
2934+ char *newstr = NULL;
2935+ orig = myproposal[PROPOSAL_KEX_ALGS];
2936+
2937+ /*
2938+ * If we don't have a host key, then there's no point advertising
2939+ * the other key exchange algorithms
2940+ */
2941+
2942+ if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
2943+ orig = NULL;
2944+
2945+ if (options.gss_keyex)
2946+ gss = ssh_gssapi_server_mechanisms();
2947+ else
2948+ gss = NULL;
2949+
2950+ if (gss && orig)
2951+ xasprintf(&newstr, "%s,%s", gss, orig);
2952+ else if (gss)
2953+ newstr = gss;
2954+ else if (orig)
2955+ newstr = orig;
2956+
2957+ /*
2958+ * If we've got GSSAPI mechanisms, then we've got the 'null' host
2959+ * key alg, but we can't tell people about it unless its the only
2960+ * host key algorithm we support
2961+ */
2962+ if (gss && (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS])) == 0)
2963+ myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = "null";
2964+
2965+ if (newstr)
2966+ myproposal[PROPOSAL_KEX_ALGS] = newstr;
2967+ else
2968+ fatal("No supported key exchange algorithms");
2969+ }
2970+#endif
2971+
2972 /* start key exchange */
2973 kex = kex_setup(myproposal);
2974 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
2975@@ -2310,6 +2413,13 @@
2976 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
2977 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
2978 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
2979+#ifdef GSSAPI
2980+ if (options.gss_keyex) {
2981+ kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
2982+ kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
2983+ kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
2984+ }
2985+#endif
2986 kex->server = 1;
2987 kex->client_version_string=client_version_string;
2988 kex->server_version_string=server_version_string;
2989Index: b/sshd_config
2990===================================================================
2991--- a/sshd_config
2992+++ b/sshd_config
2993@@ -72,6 +72,8 @@
2994 # GSSAPI options
2995 #GSSAPIAuthentication no
2996 #GSSAPICleanupCredentials yes
2997+#GSSAPIStrictAcceptorCheck yes
2998+#GSSAPIKeyExchange no
2999
3000 # Set this to 'yes' to enable PAM authentication, account processing,
3001 # and session processing. If this is enabled, PAM authentication will
3002Index: b/sshd_config.5
3003===================================================================
3004--- a/sshd_config.5
3005+++ b/sshd_config.5
3006@@ -423,12 +423,40 @@
3007 The default is
3008 .Dq no .
3009 Note that this option applies to protocol version 2 only.
3010+.It Cm GSSAPIKeyExchange
3011+Specifies whether key exchange based on GSSAPI is allowed. GSSAPI key exchange
3012+doesn't rely on ssh keys to verify host identity.
3013+The default is
3014+.Dq no .
3015+Note that this option applies to protocol version 2 only.
3016 .It Cm GSSAPICleanupCredentials
3017 Specifies whether to automatically destroy the user's credentials cache
3018 on logout.
3019 The default is
3020 .Dq yes .
3021 Note that this option applies to protocol version 2 only.
3022+.It Cm GSSAPIStrictAcceptorCheck
3023+Determines whether to be strict about the identity of the GSSAPI acceptor
3024+a client authenticates against. If
3025+.Dq yes
3026+then the client must authenticate against the
3027+.Pa host
3028+service on the current hostname. If
3029+.Dq no
3030+then the client may authenticate against any service key stored in the
3031+machine's default store. This facility is provided to assist with operation
3032+on multi homed machines.
3033+The default is
3034+.Dq yes .
3035+Note that this option applies only to protocol version 2 GSSAPI connections,
3036+and setting it to
3037+.Dq no
3038+may only work with recent Kerberos GSSAPI libraries.
3039+.It Cm GSSAPIStoreCredentialsOnRekey
3040+Controls whether the user's GSSAPI credentials should be updated following a
3041+successful connection rekeying. This option can be used to accepted renewed
3042+or updated credentials from a compatible client. The default is
3043+.Dq no .
3044 .It Cm HostbasedAuthentication
3045 Specifies whether rhosts or /etc/hosts.equiv authentication together
3046 with successful public key client host authentication is allowed
diff --git a/debian/patches/helpful-wait-terminate.patch b/debian/patches/helpful-wait-terminate.patch
new file mode 100644
index 000000000..857f86456
--- /dev/null
+++ b/debian/patches/helpful-wait-terminate.patch
@@ -0,0 +1,18 @@
1Description: Mention ~& when waiting for forwarded connections to terminate
2Author: Matthew Vernon <matthew@debian.org>
3Bug-Debian: http://bugs.debian.org/50308
4Last-Update: 2010-02-27
5
6Index: b/serverloop.c
7===================================================================
8--- a/serverloop.c
9+++ b/serverloop.c
10@@ -680,7 +680,7 @@
11 if (!channel_still_open())
12 break;
13 if (!waiting_termination) {
14- const char *s = "Waiting for forwarded connections to terminate...\r\n";
15+ const char *s = "Waiting for forwarded connections to terminate... (press ~& to background)\r\n";
16 char *cp;
17 waiting_termination = 1;
18 buffer_append(&stderr_buffer, s, strlen(s));
diff --git a/debian/patches/keepalive-extensions.patch b/debian/patches/keepalive-extensions.patch
new file mode 100644
index 000000000..89011cfb7
--- /dev/null
+++ b/debian/patches/keepalive-extensions.patch
@@ -0,0 +1,124 @@
1Description: Various keepalive extensions
2 Add compatibility aliases for ProtocolKeepAlives and SetupTimeOut,
3 supported in previous versions of Debian's OpenSSH package but since
4 superseded by ServerAliveInterval. (We're probably stuck with this bit for
5 compatibility.)
6 .
7 In batch mode, default ServerAliveInterval to five minutes.
8 .
9 Adjust documentation to match and to give some more advice on use of
10 keepalives.
11Author: Richard Kettlewell <rjk@greenend.org.uk>
12Author: Ian Jackson <ian@chiark.greenend.org.uk>
13Author: Matthew Vernon <matthew@debian.org>
14Author: Colin Watson <cjwatson@debian.org>
15Last-Update: 2010-02-27
16
17Index: b/readconf.c
18===================================================================
19--- a/readconf.c
20+++ b/readconf.c
21@@ -138,6 +138,7 @@
22 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
23 oVisualHostKey, oUseRoaming, oZeroKnowledgePasswordAuthentication,
24 oKexAlgorithms, oIPQoS,
25+ oProtocolKeepAlives, oSetupTimeOut,
26 oDeprecated, oUnsupported
27 } OpCodes;
28
29@@ -258,6 +259,8 @@
30 #endif
31 { "kexalgorithms", oKexAlgorithms },
32 { "ipqos", oIPQoS },
33+ { "protocolkeepalives", oProtocolKeepAlives },
34+ { "setuptimeout", oSetupTimeOut },
35
36 { NULL, oBadOption }
37 };
38@@ -888,6 +891,8 @@
39 goto parse_flag;
40
41 case oServerAliveInterval:
42+ case oProtocolKeepAlives: /* Debian-specific compatibility alias */
43+ case oSetupTimeOut: /* Debian-specific compatibility alias */
44 intptr = &options->server_alive_interval;
45 goto parse_time;
46
47@@ -1336,8 +1341,13 @@
48 options->rekey_limit = 0;
49 if (options->verify_host_key_dns == -1)
50 options->verify_host_key_dns = 0;
51- if (options->server_alive_interval == -1)
52- options->server_alive_interval = 0;
53+ if (options->server_alive_interval == -1) {
54+ /* in batch mode, default is 5mins */
55+ if (options->batch_mode == 1)
56+ options->server_alive_interval = 300;
57+ else
58+ options->server_alive_interval = 0;
59+ }
60 if (options->server_alive_count_max == -1)
61 options->server_alive_count_max = 3;
62 if (options->control_master == -1)
63Index: b/ssh_config.5
64===================================================================
65--- a/ssh_config.5
66+++ b/ssh_config.5
67@@ -127,8 +127,12 @@
68 If set to
69 .Dq yes ,
70 passphrase/password querying will be disabled.
71+In addition, the
72+.Cm ServerAliveInterval
73+option will be set to 300 seconds by default.
74 This option is useful in scripts and other batch jobs where no user
75-is present to supply the password.
76+is present to supply the password,
77+and where it is desirable to detect a broken network swiftly.
78 The argument must be
79 .Dq yes
80 or
81@@ -1058,8 +1062,15 @@
82 will send a message through the encrypted
83 channel to request a response from the server.
84 The default
85-is 0, indicating that these messages will not be sent to the server.
86+is 0, indicating that these messages will not be sent to the server,
87+or 300 if the
88+.Cm BatchMode
89+option is set.
90 This option applies to protocol version 2 only.
91+.Cm ProtocolKeepAlives
92+and
93+.Cm SetupTimeOut
94+are Debian-specific compatibility aliases for this option.
95 .It Cm StrictHostKeyChecking
96 If this flag is set to
97 .Dq yes ,
98@@ -1098,6 +1109,12 @@
99 other side.
100 If they are sent, death of the connection or crash of one
101 of the machines will be properly noticed.
102+This option only uses TCP keepalives (as opposed to using ssh level
103+keepalives), so takes a long time to notice when the connection dies.
104+As such, you probably want
105+the
106+.Cm ServerAliveInterval
107+option as well.
108 However, this means that
109 connections will die if the route is down temporarily, and some people
110 find it annoying.
111Index: b/sshd_config.5
112===================================================================
113--- a/sshd_config.5
114+++ b/sshd_config.5
115@@ -1034,6 +1034,9 @@
116 .Pp
117 To disable TCP keepalive messages, the value should be set to
118 .Dq no .
119+.Pp
120+This option was formerly called
121+.Cm KeepAlive .
122 .It Cm TrustedUserCAKeys
123 Specifies a file containing public keys of certificate authorities that are
124 trusted to sign user certificates for authentication.
diff --git a/debian/patches/lintian-symlink-pickiness.patch b/debian/patches/lintian-symlink-pickiness.patch
new file mode 100644
index 000000000..f5ac00814
--- /dev/null
+++ b/debian/patches/lintian-symlink-pickiness.patch
@@ -0,0 +1,23 @@
1Description: Fix picky lintian errors about slogin symlinks
2 Apparently this breaks some SVR4 packaging systems, so upstream can't win
3 either way and opted to keep the status quo. We need this patch anyway.
4Author: Colin Watson <cjwatson@debian.org>
5Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1728
6Last-Update: 2010-04-10
7
8Index: b/Makefile.in
9===================================================================
10--- a/Makefile.in
11+++ b/Makefile.in
12@@ -297,9 +297,9 @@
13 $(INSTALL) -m 644 ssh-pkcs11-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8
14 $(INSTALL) -m 644 ssh-vulnkey.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-vulnkey.1
15 -rm -f $(DESTDIR)$(bindir)/slogin
16- ln -s ./ssh$(EXEEXT) $(DESTDIR)$(bindir)/slogin
17+ ln -s ssh$(EXEEXT) $(DESTDIR)$(bindir)/slogin
18 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1
19- ln -s ./ssh.1 $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1
20+ ln -s ssh.1 $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1
21
22 install-sysconf:
23 if [ ! -d $(DESTDIR)$(sysconfdir) ]; then \
diff --git a/debian/patches/openbsd-docs.patch b/debian/patches/openbsd-docs.patch
new file mode 100644
index 000000000..fc07e8861
--- /dev/null
+++ b/debian/patches/openbsd-docs.patch
@@ -0,0 +1,117 @@
1Description: Adjust various OpenBSD-specific references in manual pages
2 No single bug reference for this patch, but history includes:
3 http://bugs.debian.org/154434 (login.conf(5))
4 http://bugs.debian.org/513417 (/etc/rc)
5 http://bugs.debian.org/530692 (ssl(8))
6 https://bugs.launchpad.net/bugs/456660 (ssl(8))
7Author: Colin Watson <cjwatson@debian.org>
8Forwarded: not-needed
9Last-Update: 2010-02-28
10
11Index: b/moduli.5
12===================================================================
13--- a/moduli.5
14+++ b/moduli.5
15@@ -21,7 +21,7 @@
16 .Nd Diffie Hellman moduli
17 .Sh DESCRIPTION
18 The
19-.Pa /etc/moduli
20+.Pa /etc/ssh/moduli
21 file contains prime numbers and generators for use by
22 .Xr sshd 8
23 in the Diffie-Hellman Group Exchange key exchange method.
24@@ -111,7 +111,7 @@
25 Diffie Hellman output to sufficiently key the selected symmetric cipher.
26 .Xr sshd 8
27 then randomly selects a modulus from
28-.Fa /etc/moduli
29+.Fa /etc/ssh/moduli
30 that best meets the size requirement.
31 .Pp
32 .Sh SEE ALSO
33Index: b/ssh-keygen.1
34===================================================================
35--- a/ssh-keygen.1
36+++ b/ssh-keygen.1
37@@ -147,9 +147,7 @@
38 .Pa ~/.ssh/id_dsa
39 or
40 .Pa ~/.ssh/id_rsa .
41-Additionally, the system administrator may use this to generate host keys,
42-as seen in
43-.Pa /etc/rc .
44+Additionally, the system administrator may use this to generate host keys.
45 .Pp
46 Normally this program generates the key and asks for a file in which
47 to store the private key.
48@@ -393,9 +391,7 @@
49 .It Fl q
50 Silence
51 .Nm ssh-keygen .
52-Used by
53-.Pa /etc/rc
54-when creating a new key.
55+Used by system administration scripts when creating a new key.
56 .It Fl R Ar hostname
57 Removes all keys belonging to
58 .Ar hostname
59Index: b/ssh.1
60===================================================================
61--- a/ssh.1
62+++ b/ssh.1
63@@ -726,6 +726,10 @@
64 .Sx HISTORY
65 section of
66 .Xr ssl 8
67+(on non-OpenBSD systems, see
68+.nh
69+http://www.openbsd.org/cgi\-bin/man.cgi?query=ssl&sektion=8#HISTORY)
70+.hy
71 contains a brief discussion of the DSA and RSA algorithms.
72 .Pp
73 The file
74Index: b/sshd.8
75===================================================================
76--- a/sshd.8
77+++ b/sshd.8
78@@ -69,7 +69,7 @@
79 .Nm
80 listens for connections from clients.
81 It is normally started at boot from
82-.Pa /etc/rc .
83+.Pa /etc/init.d/ssh .
84 It forks a new
85 daemon for each incoming connection.
86 The forked daemons handle
87@@ -850,7 +850,7 @@
88 .Xr ssh 1 ) .
89 It should only be writable by root.
90 .Pp
91-.It Pa /etc/moduli
92+.It Pa /etc/ssh/moduli
93 Contains Diffie-Hellman groups used for the "Diffie-Hellman Group Exchange".
94 The file format is described in
95 .Xr moduli 5 .
96@@ -948,7 +948,6 @@
97 .Xr ssh-vulnkey 1 ,
98 .Xr chroot 2 ,
99 .Xr hosts_access 5 ,
100-.Xr login.conf 5 ,
101 .Xr moduli 5 ,
102 .Xr sshd_config 5 ,
103 .Xr inetd 8 ,
104Index: b/sshd_config.5
105===================================================================
106--- a/sshd_config.5
107+++ b/sshd_config.5
108@@ -221,8 +221,7 @@
109 By default, no banner is displayed.
110 .It Cm ChallengeResponseAuthentication
111 Specifies whether challenge-response authentication is allowed (e.g. via
112-PAM or though authentication styles supported in
113-.Xr login.conf 5 )
114+PAM).
115 The default is
116 .Dq yes .
117 .It Cm ChrootDirectory
diff --git a/debian/patches/package-versioning.patch b/debian/patches/package-versioning.patch
new file mode 100644
index 000000000..ffd416d98
--- /dev/null
+++ b/debian/patches/package-versioning.patch
@@ -0,0 +1,50 @@
1Description: Include the Debian version in our identification
2 This makes it easier to audit networks for versions patched against
3 security vulnerabilities. It has little detrimental effect, as attackers
4 will generally just try attacks rather than bothering to scan for
5 vulnerable-looking version strings. (However, see debian-banner.patch.)
6Author: Matthew Vernon <matthew@debian.org>
7Forwarded: not-needed
8Last-Update: 2010-02-28
9
10Index: b/sshconnect.c
11===================================================================
12--- a/sshconnect.c
13+++ b/sshconnect.c
14@@ -556,7 +556,7 @@
15 snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s%s",
16 compat20 ? PROTOCOL_MAJOR_2 : PROTOCOL_MAJOR_1,
17 compat20 ? PROTOCOL_MINOR_2 : minor1,
18- SSH_VERSION, compat20 ? "\r\n" : "\n");
19+ SSH_RELEASE, compat20 ? "\r\n" : "\n");
20 if (roaming_atomicio(vwrite, connection_out, buf, strlen(buf))
21 != strlen(buf))
22 fatal("write: %.100s", strerror(errno));
23Index: b/sshd.c
24===================================================================
25--- a/sshd.c
26+++ b/sshd.c
27@@ -422,7 +422,7 @@
28 minor = PROTOCOL_MINOR_1;
29 }
30 snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s%s", major, minor,
31- SSH_VERSION, newline);
32+ SSH_RELEASE, newline);
33 server_version_string = xstrdup(buf);
34
35 /* Send our protocol version identification. */
36Index: b/version.h
37===================================================================
38--- a/version.h
39+++ b/version.h
40@@ -3,4 +3,9 @@
41 #define SSH_VERSION "OpenSSH_5.7"
42
43 #define SSH_PORTABLE "p1"
44-#define SSH_RELEASE SSH_VERSION SSH_PORTABLE
45+#define SSH_RELEASE_MINIMUM SSH_VERSION SSH_PORTABLE
46+#ifdef SSH_EXTRAVERSION
47+#define SSH_RELEASE SSH_RELEASE_MINIMUM " " SSH_EXTRAVERSION
48+#else
49+#define SSH_RELEASE SSH_RELEASE_MINIMUM
50+#endif
diff --git a/debian/patches/quieter-signals.patch b/debian/patches/quieter-signals.patch
new file mode 100644
index 000000000..f8bc5fd4e
--- /dev/null
+++ b/debian/patches/quieter-signals.patch
@@ -0,0 +1,31 @@
1Description: Reduce severity of "Killed by signal %d"
2 This produces irritating messages when using ProxyCommand or other programs
3 that use ssh under the covers (e.g. Subversion). These messages are more
4 normally printed by the calling program, such as the shell.
5 .
6 According to the upstream bug, the right way to avoid this is to use the -q
7 option, so we may drop this patch after further investigation into whether
8 any software in Debian is still relying on it.
9Author: Peter Samuelson <peter@p12n.org>
10Author: Colin Watson <cjwatson@debian.org>
11Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1118
12Bug-Debian: http://bugs.debian.org/313371
13Last-Update: 2010-02-27
14
15Index: b/clientloop.c
16===================================================================
17--- a/clientloop.c
18+++ b/clientloop.c
19@@ -1594,8 +1594,10 @@
20 exit_status = 0;
21 }
22
23- if (received_signal)
24- fatal("Killed by signal %d.", (int) received_signal);
25+ if (received_signal) {
26+ debug("Killed by signal %d.", (int) received_signal);
27+ cleanup_exit((int) received_signal + 128);
28+ }
29
30 /*
31 * In interactive mode (with pseudo tty) display a message indicating
diff --git a/debian/patches/scp-quoting.patch b/debian/patches/scp-quoting.patch
new file mode 100644
index 000000000..239c1b599
--- /dev/null
+++ b/debian/patches/scp-quoting.patch
@@ -0,0 +1,32 @@
1Description: Adjust scp quoting in verbose mode
2 Tweak scp's reporting of filenames in verbose mode to be a bit less
3 confusing with spaces.
4 .
5 This should be revised to mimic real shell quoting.
6Author: Nicolas Valcárcel <nvalcarcel@ubuntu.com>
7Bug-Ubuntu: https://bugs.launchpad.net/bugs/89945
8Last-Update: 2010-02-27
9
10Index: b/scp.c
11===================================================================
12--- a/scp.c
13+++ b/scp.c
14@@ -189,8 +189,16 @@
15
16 if (verbose_mode) {
17 fprintf(stderr, "Executing:");
18- for (i = 0; i < a->num; i++)
19- fprintf(stderr, " %s", a->list[i]);
20+ for (i = 0; i < a->num; i++) {
21+ if (i == 0)
22+ fprintf(stderr, " %s", a->list[i]);
23+ else
24+ /*
25+ * TODO: misbehaves if a->list[i] contains a
26+ * single quote
27+ */
28+ fprintf(stderr, " '%s'", a->list[i]);
29+ }
30 fprintf(stderr, "\n");
31 }
32 if ((pid = fork()) == -1)
diff --git a/debian/patches/selinux-role.patch b/debian/patches/selinux-role.patch
new file mode 100644
index 000000000..74cd06201
--- /dev/null
+++ b/debian/patches/selinux-role.patch
@@ -0,0 +1,292 @@
1Description: Handle SELinux authorisation roles
2 Rejected upstream due to discomfort with magic usernames; a better approach
3 will need an SSH protocol change. In the meantime, this came from Debian's
4 SELinux maintainer, so we'll keep it until we have something better.
5Author: Manoj Srivastava <srivasta@debian.org>
6Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1641
7Bug-Debian: http://bugs.debian.org/394795
8Last-Update: 2010-02-27
9
10Index: b/auth.h
11===================================================================
12--- a/auth.h
13+++ b/auth.h
14@@ -59,6 +59,7 @@
15 char *service;
16 struct passwd *pw; /* set if 'valid' */
17 char *style;
18+ char *role;
19 void *kbdintctxt;
20 void *jpake_ctx;
21 #ifdef BSD_AUTH
22Index: b/auth1.c
23===================================================================
24--- a/auth1.c
25+++ b/auth1.c
26@@ -383,7 +383,7 @@
27 do_authentication(Authctxt *authctxt)
28 {
29 u_int ulen;
30- char *user, *style = NULL;
31+ char *user, *style = NULL, *role = NULL;
32
33 /* Get the name of the user that we wish to log in as. */
34 packet_read_expect(SSH_CMSG_USER);
35@@ -392,11 +392,17 @@
36 user = packet_get_cstring(&ulen);
37 packet_check_eom();
38
39+ if ((role = strchr(user, '/')) != NULL)
40+ *role++ = '\0';
41+
42 if ((style = strchr(user, ':')) != NULL)
43 *style++ = '\0';
44+ else if (role && (style = strchr(role, ':')) != NULL)
45+ *style++ = '\0';
46
47 authctxt->user = user;
48 authctxt->style = style;
49+ authctxt->role = role;
50
51 /* Verify that the user is a valid user. */
52 if ((authctxt->pw = PRIVSEP(getpwnamallow(user))) != NULL)
53Index: b/auth2.c
54===================================================================
55--- a/auth2.c
56+++ b/auth2.c
57@@ -217,7 +217,7 @@
58 {
59 Authctxt *authctxt = ctxt;
60 Authmethod *m = NULL;
61- char *user, *service, *method, *style = NULL;
62+ char *user, *service, *method, *style = NULL, *role = NULL;
63 int authenticated = 0;
64
65 if (authctxt == NULL)
66@@ -229,8 +229,13 @@
67 debug("userauth-request for user %s service %s method %s", user, service, method);
68 debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
69
70+ if ((role = strchr(user, '/')) != NULL)
71+ *role++ = 0;
72+
73 if ((style = strchr(user, ':')) != NULL)
74 *style++ = 0;
75+ else if (role && (style = strchr(role, ':')) != NULL)
76+ *style++ = '\0';
77
78 if (authctxt->attempt++ == 0) {
79 /* setup auth context */
80@@ -254,8 +259,9 @@
81 use_privsep ? " [net]" : "");
82 authctxt->service = xstrdup(service);
83 authctxt->style = style ? xstrdup(style) : NULL;
84+ authctxt->role = role ? xstrdup(role) : NULL;
85 if (use_privsep)
86- mm_inform_authserv(service, style);
87+ mm_inform_authserv(service, style, role);
88 userauth_banner();
89 } else if (strcmp(user, authctxt->user) != 0 ||
90 strcmp(service, authctxt->service) != 0) {
91Index: b/monitor.c
92===================================================================
93--- a/monitor.c
94+++ b/monitor.c
95@@ -137,6 +137,7 @@
96 int mm_answer_pwnamallow(int, Buffer *);
97 int mm_answer_auth2_read_banner(int, Buffer *);
98 int mm_answer_authserv(int, Buffer *);
99+int mm_answer_authrole(int, Buffer *);
100 int mm_answer_authpassword(int, Buffer *);
101 int mm_answer_bsdauthquery(int, Buffer *);
102 int mm_answer_bsdauthrespond(int, Buffer *);
103@@ -215,6 +216,7 @@
104 {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
105 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
106 {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
107+ {MONITOR_REQ_AUTHROLE, MON_ONCE, mm_answer_authrole},
108 {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
109 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
110 #ifdef USE_PAM
111@@ -699,6 +701,7 @@
112 else {
113 /* Allow service/style information on the auth context */
114 monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
115+ monitor_permit(mon_dispatch, MONITOR_REQ_AUTHROLE, 1);
116 monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
117 }
118
119@@ -732,14 +735,37 @@
120
121 authctxt->service = buffer_get_string(m, NULL);
122 authctxt->style = buffer_get_string(m, NULL);
123- debug3("%s: service=%s, style=%s",
124- __func__, authctxt->service, authctxt->style);
125+ authctxt->role = buffer_get_string(m, NULL);
126+ debug3("%s: service=%s, style=%s, role=%s",
127+ __func__, authctxt->service, authctxt->style, authctxt->role);
128
129 if (strlen(authctxt->style) == 0) {
130 xfree(authctxt->style);
131 authctxt->style = NULL;
132 }
133
134+ if (strlen(authctxt->role) == 0) {
135+ xfree(authctxt->role);
136+ authctxt->role = NULL;
137+ }
138+
139+ return (0);
140+}
141+
142+int
143+mm_answer_authrole(int sock, Buffer *m)
144+{
145+ monitor_permit_authentications(1);
146+
147+ authctxt->role = buffer_get_string(m, NULL);
148+ debug3("%s: role=%s",
149+ __func__, authctxt->role);
150+
151+ if (strlen(authctxt->role) == 0) {
152+ xfree(authctxt->role);
153+ authctxt->role = NULL;
154+ }
155+
156 return (0);
157 }
158
159Index: b/monitor.h
160===================================================================
161--- a/monitor.h
162+++ b/monitor.h
163@@ -30,7 +30,7 @@
164
165 enum monitor_reqtype {
166 MONITOR_REQ_MODULI, MONITOR_ANS_MODULI,
167- MONITOR_REQ_FREE, MONITOR_REQ_AUTHSERV,
168+ MONITOR_REQ_FREE, MONITOR_REQ_AUTHSERV, MONITOR_REQ_AUTHROLE,
169 MONITOR_REQ_SIGN, MONITOR_ANS_SIGN,
170 MONITOR_REQ_PWNAM, MONITOR_ANS_PWNAM,
171 MONITOR_REQ_AUTH2_READ_BANNER, MONITOR_ANS_AUTH2_READ_BANNER,
172Index: b/monitor_wrap.c
173===================================================================
174--- a/monitor_wrap.c
175+++ b/monitor_wrap.c
176@@ -280,10 +280,10 @@
177 return (banner);
178 }
179
180-/* Inform the privileged process about service and style */
181+/* Inform the privileged process about service, style, and role */
182
183 void
184-mm_inform_authserv(char *service, char *style)
185+mm_inform_authserv(char *service, char *style, char *role)
186 {
187 Buffer m;
188
189@@ -292,11 +292,29 @@
190 buffer_init(&m);
191 buffer_put_cstring(&m, service);
192 buffer_put_cstring(&m, style ? style : "");
193+ buffer_put_cstring(&m, role ? role : "");
194
195 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m);
196
197 buffer_free(&m);
198 }
199+
200+/* Inform the privileged process about role */
201+
202+void
203+mm_inform_authrole(char *role)
204+{
205+ Buffer m;
206+
207+ debug3("%s entering", __func__);
208+
209+ buffer_init(&m);
210+ buffer_put_cstring(&m, role ? role : "");
211+
212+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHROLE, &m);
213+
214+ buffer_free(&m);
215+}
216
217 /* Do the password authentication */
218 int
219Index: b/monitor_wrap.h
220===================================================================
221--- a/monitor_wrap.h
222+++ b/monitor_wrap.h
223@@ -40,7 +40,8 @@
224 int mm_is_monitor(void);
225 DH *mm_choose_dh(int, int, int);
226 int mm_key_sign(Key *, u_char **, u_int *, u_char *, u_int);
227-void mm_inform_authserv(char *, char *);
228+void mm_inform_authserv(char *, char *, char *);
229+void mm_inform_authrole(char *);
230 struct passwd *mm_getpwnamallow(const char *);
231 char *mm_auth2_read_banner(void);
232 int mm_auth_password(struct Authctxt *, char *);
233Index: b/openbsd-compat/port-linux.c
234===================================================================
235--- a/openbsd-compat/port-linux.c
236+++ b/openbsd-compat/port-linux.c
237@@ -29,6 +29,12 @@
238 #include <string.h>
239 #include <stdio.h>
240
241+#ifdef WITH_SELINUX
242+#include "key.h"
243+#include "hostfile.h"
244+#include "auth.h"
245+#endif
246+
247 #include "log.h"
248 #include "xmalloc.h"
249 #include "port-linux.h"
250@@ -38,6 +44,8 @@
251 #include <selinux/flask.h>
252 #include <selinux/get_context_list.h>
253
254+extern Authctxt *the_authctxt;
255+
256 /* Wrapper around is_selinux_enabled() to log its return value once only */
257 int
258 ssh_selinux_enabled(void)
259@@ -56,8 +64,8 @@
260 static security_context_t
261 ssh_selinux_getctxbyname(char *pwname)
262 {
263- security_context_t sc;
264- char *sename = NULL, *lvl = NULL;
265+ security_context_t sc = NULL;
266+ char *sename = NULL, *role = NULL, *lvl = NULL;
267 int r;
268
269 #ifdef HAVE_GETSEUSERBYNAME
270@@ -67,11 +75,20 @@
271 sename = pwname;
272 lvl = NULL;
273 #endif
274+ if (the_authctxt)
275+ role = the_authctxt->role;
276
277 #ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
278- r = get_default_context_with_level(sename, lvl, NULL, &sc);
279+ if (role != NULL && role[0])
280+ r = get_default_context_with_rolelevel(sename, role, lvl, NULL,
281+ &sc);
282+ else
283+ r = get_default_context_with_level(sename, lvl, NULL, &sc);
284 #else
285- r = get_default_context(sename, NULL, &sc);
286+ if (role != NULL && role[0])
287+ r = get_default_context_with_role(sename, role, NULL, &sc);
288+ else
289+ r = get_default_context(sename, NULL, &sc);
290 #endif
291
292 if (r != 0) {
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 000000000..751a9868c
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1,41 @@
1# GSSAPI
2gssapi.patch
3gssapi-autoconf.patch
4
5# SELinux
6selinux-role.patch
7
8# Key blacklisting
9ssh-vulnkey.patch
10
11# Keepalive handling
12ssh1-keepalive.patch
13keepalive-extensions.patch
14
15# Message adjustments
16syslog-level-silent.patch
17quieter-signals.patch
18helpful-wait-terminate.patch
19
20# Miscellaneous bug fixes
21user-group-modes.patch
22scp-quoting.patch
23shell-path.patch
24dnssec-sshfp.patch
25
26# Versioning
27package-versioning.patch
28debian-banner.patch
29
30# File system layout
31authorized-keys-man-symlink.patch
32lintian-symlink-pickiness.patch
33
34# Documentation
35openbsd-docs.patch
36ssh-argv0.patch
37doc-hash-tab-completion.patch
38
39# Debian-specific configuration
40gnome-ssh-askpass2-icon.patch
41debian-config.patch
diff --git a/debian/patches/shell-path.patch b/debian/patches/shell-path.patch
new file mode 100644
index 000000000..5100d8ec7
--- /dev/null
+++ b/debian/patches/shell-path.patch
@@ -0,0 +1,30 @@
1Description: Look for $SHELL on the path for ProxyCommand/LocalCommand
2 There's some debate on the upstream bug about whether POSIX requires this.
3 I (Colin Watson) agree with Vincent and think it does.
4Author: Colin Watson <cjwatson@debian.org>
5Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1494
6Bug-Debian: http://bugs.debian.org/492728
7Last-Update: 2010-02-27
8
9Index: b/sshconnect.c
10===================================================================
11--- a/sshconnect.c
12+++ b/sshconnect.c
13@@ -144,7 +144,7 @@
14 /* Execute the proxy command. Note that we gave up any
15 extra privileges above. */
16 signal(SIGPIPE, SIG_DFL);
17- execv(argv[0], argv);
18+ execvp(argv[0], argv);
19 perror(argv[0]);
20 exit(1);
21 }
22@@ -1274,7 +1274,7 @@
23 if (pid == 0) {
24 signal(SIGPIPE, SIG_DFL);
25 debug3("Executing %s -c \"%s\"", shell, args);
26- execl(shell, shell, "-c", args, (char *)NULL);
27+ execlp(shell, shell, "-c", args, (char *)NULL);
28 error("Couldn't execute %s -c \"%s\": %s",
29 shell, args, strerror(errno));
30 _exit(1);
diff --git a/debian/patches/ssh-argv0.patch b/debian/patches/ssh-argv0.patch
new file mode 100644
index 000000000..43d9d4d44
--- /dev/null
+++ b/debian/patches/ssh-argv0.patch
@@ -0,0 +1,21 @@
1Description: ssh(1): Refer to ssh-argv0(1)
2 Old versions of OpenSSH (up to 2.5 or thereabouts) allowed creating
3 symlinks to ssh with the name of the host you want to connect to. Debian
4 ships an ssh-argv0 script restoring this feature; this patch refers to its
5 manual page from ssh(1).
6Bug-Debian: http://bugs.debian.org/111341
7Forwarded: not-needed
8Last-Update: 2010-02-28
9
10Index: b/ssh.1
11===================================================================
12--- a/ssh.1
13+++ b/ssh.1
14@@ -1406,6 +1406,7 @@
15 .Xr sftp 1 ,
16 .Xr ssh-add 1 ,
17 .Xr ssh-agent 1 ,
18+.Xr ssh-argv0 1 ,
19 .Xr ssh-keygen 1 ,
20 .Xr ssh-keyscan 1 ,
21 .Xr ssh-vulnkey 1 ,
diff --git a/debian/patches/ssh-vulnkey.patch b/debian/patches/ssh-vulnkey.patch
new file mode 100644
index 000000000..444aef251
--- /dev/null
+++ b/debian/patches/ssh-vulnkey.patch
@@ -0,0 +1,1385 @@
1Description: Reject vulnerable keys to mitigate Debian OpenSSL flaw
2 In 2008, Debian (and derived distributions such as Ubuntu) shipped an
3 OpenSSL package with a flawed random number generator, causing OpenSSH to
4 generate only a very limited set of keys which were subject to private half
5 precomputation. To mitigate this, this patch checks key authentications
6 against a blacklist of known-vulnerable keys, and adds a new ssh-vulnkey
7 program which can be used to explicitly check keys against that blacklist.
8 See CVE-2008-0166.
9Author: Colin Watson <cjwatson@ubuntu.com>
10Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1469
11Last-Update: 2010-02-27
12
13Index: b/Makefile.in
14===================================================================
15--- a/Makefile.in
16+++ b/Makefile.in
17@@ -27,6 +27,7 @@
18 SSH_KEYSIGN=$(libexecdir)/ssh-keysign
19 SSH_PKCS11_HELPER=$(libexecdir)/ssh-pkcs11-helper
20 RAND_HELPER=$(libexecdir)/ssh-rand-helper
21+SSH_DATADIR=$(datadir)/ssh
22 PRIVSEP_PATH=@PRIVSEP_PATH@
23 SSH_PRIVSEP_USER=@SSH_PRIVSEP_USER@
24 STRIP_OPT=@STRIP_OPT@
25@@ -39,7 +40,8 @@
26 -D_PATH_SSH_PKCS11_HELPER=\"$(SSH_PKCS11_HELPER)\" \
27 -D_PATH_SSH_PIDDIR=\"$(piddir)\" \
28 -D_PATH_PRIVSEP_CHROOT_DIR=\"$(PRIVSEP_PATH)\" \
29- -DSSH_RAND_HELPER=\"$(RAND_HELPER)\"
30+ -DSSH_RAND_HELPER=\"$(RAND_HELPER)\" \
31+ -D_PATH_SSH_DATADIR=\"$(SSH_DATADIR)\"
32
33 CC=@CC@
34 LD=@LD@
35@@ -63,7 +65,7 @@
36 INSTALL_SSH_PRNG_CMDS=@INSTALL_SSH_PRNG_CMDS@
37 INSTALL_SSH_RAND_HELPER=@INSTALL_SSH_RAND_HELPER@
38
39-TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) ssh-rand-helper${EXEEXT} sftp-server$(EXEEXT) sftp$(EXEEXT)
40+TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) ssh-rand-helper${EXEEXT} sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-vulnkey$(EXEEXT)
41
42 LIBSSH_OBJS=acss.o authfd.o authfile.o bufaux.o bufbn.o buffer.o \
43 canohost.o channels.o cipher.o cipher-acss.o cipher-aes.o \
44@@ -95,8 +97,8 @@
45 sftp-server.o sftp-common.o \
46 roaming_common.o roaming_serv.o
47
48-MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-rand-helper.8.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out
49-MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-rand-helper.8 ssh-keysign.8 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5
50+MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-rand-helper.8.out ssh-keysign.8.out ssh-pkcs11-helper.8.out ssh-vulnkey.1.out sshd_config.5.out ssh_config.5.out
51+MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-rand-helper.8 ssh-keysign.8 ssh-pkcs11-helper.8 ssh-vulnkey.1 sshd_config.5 ssh_config.5
52 MANTYPE = @MANTYPE@
53
54 CONFIGFILES=sshd_config.out ssh_config.out moduli.out
55@@ -177,6 +179,9 @@
56 ssh-rand-helper${EXEEXT}: $(LIBCOMPAT) libssh.a ssh-rand-helper.o
57 $(LD) -o $@ ssh-rand-helper.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
58
59+ssh-vulnkey$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-vulnkey.o
60+ $(LD) -o $@ ssh-vulnkey.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
61+
62 # test driver for the loginrec code - not built by default
63 logintest: logintest.o $(LIBCOMPAT) libssh.a loginrec.o
64 $(LD) -o $@ logintest.o $(LDFLAGS) loginrec.o -lopenbsd-compat -lssh $(LIBS)
65@@ -271,6 +276,7 @@
66 $(INSTALL) -m 0755 $(STRIP_OPT) ssh-pkcs11-helper$(EXEEXT) $(DESTDIR)$(SSH_PKCS11_HELPER)$(EXEEXT)
67 $(INSTALL) -m 0755 $(STRIP_OPT) sftp$(EXEEXT) $(DESTDIR)$(bindir)/sftp$(EXEEXT)
68 $(INSTALL) -m 0755 $(STRIP_OPT) sftp-server$(EXEEXT) $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
69+ $(INSTALL) -m 0755 $(STRIP_OPT) ssh-vulnkey$(EXEEXT) $(DESTDIR)$(bindir)/ssh-vulnkey$(EXEEXT)
70 $(INSTALL) -m 644 ssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1
71 $(INSTALL) -m 644 scp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/scp.1
72 $(INSTALL) -m 644 ssh-add.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-add.1
73@@ -288,6 +294,7 @@
74 $(INSTALL) -m 644 sftp-server.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8
75 $(INSTALL) -m 644 ssh-keysign.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8
76 $(INSTALL) -m 644 ssh-pkcs11-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8
77+ $(INSTALL) -m 644 ssh-vulnkey.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-vulnkey.1
78 -rm -f $(DESTDIR)$(bindir)/slogin
79 ln -s ./ssh$(EXEEXT) $(DESTDIR)$(bindir)/slogin
80 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1
81@@ -377,6 +384,7 @@
82 -rm -f $(DESTDIR)$(bindir)/ssh-agent$(EXEEXT)
83 -rm -f $(DESTDIR)$(bindir)/ssh-keygen$(EXEEXT)
84 -rm -f $(DESTDIR)$(bindir)/ssh-keyscan$(EXEEXT)
85+ -rm -f $(DESTDIR)$(bindir)/ssh-vulnkey$(EXEEXT)
86 -rm -f $(DESTDIR)$(bindir)/sftp$(EXEEXT)
87 -rm -f $(DESTDIR)$(sbindir)/sshd$(EXEEXT)
88 -rm -r $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
89@@ -390,6 +398,7 @@
90 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keygen.1
91 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1
92 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1
93+ -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-vulnkey.1
94 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8
95 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-rand-helper.8
96 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8
97Index: b/auth-rh-rsa.c
98===================================================================
99--- a/auth-rh-rsa.c
100+++ b/auth-rh-rsa.c
101@@ -44,7 +44,7 @@
102 {
103 HostStatus host_status;
104
105- if (auth_key_is_revoked(client_host_key))
106+ if (auth_key_is_revoked(client_host_key, 0))
107 return 0;
108
109 /* Check if we would accept it using rhosts authentication. */
110Index: b/auth-rsa.c
111===================================================================
112--- a/auth-rsa.c
113+++ b/auth-rsa.c
114@@ -247,7 +247,7 @@
115 file, linenum, BN_num_bits(key->rsa->n), bits);
116
117 /* Never accept a revoked key */
118- if (auth_key_is_revoked(key))
119+ if (auth_key_is_revoked(key, 0))
120 break;
121
122 /* We have found the desired key. */
123Index: b/auth.c
124===================================================================
125--- a/auth.c
126+++ b/auth.c
127@@ -59,6 +59,7 @@
128 #include "servconf.h"
129 #include "key.h"
130 #include "hostfile.h"
131+#include "authfile.h"
132 #include "auth.h"
133 #include "auth-options.h"
134 #include "canohost.h"
135@@ -621,10 +622,34 @@
136
137 /* Returns 1 if key is revoked by revoked_keys_file, 0 otherwise */
138 int
139-auth_key_is_revoked(Key *key)
140+auth_key_is_revoked(Key *key, int hostkey)
141 {
142 char *key_fp;
143
144+ if (blacklisted_key(key, &key_fp) == 1) {
145+ if (options.permit_blacklisted_keys) {
146+ if (hostkey)
147+ error("Host key %s blacklisted (see "
148+ "ssh-vulnkey(1)); continuing anyway",
149+ key_fp);
150+ else
151+ logit("Public key %s from %s blacklisted (see "
152+ "ssh-vulnkey(1)); continuing anyway",
153+ key_fp, get_remote_ipaddr());
154+ xfree(key_fp);
155+ } else {
156+ if (hostkey)
157+ error("Host key %s blacklisted (see "
158+ "ssh-vulnkey(1))", key_fp);
159+ else
160+ logit("Public key %s from %s blacklisted (see "
161+ "ssh-vulnkey(1))",
162+ key_fp, get_remote_ipaddr());
163+ xfree(key_fp);
164+ return 1;
165+ }
166+ }
167+
168 if (options.revoked_keys_file == NULL)
169 return 0;
170
171Index: b/auth.h
172===================================================================
173--- a/auth.h
174+++ b/auth.h
175@@ -175,7 +175,7 @@
176
177 FILE *auth_openkeyfile(const char *, struct passwd *, int);
178 FILE *auth_openprincipals(const char *, struct passwd *, int);
179-int auth_key_is_revoked(Key *);
180+int auth_key_is_revoked(Key *, int);
181
182 HostStatus
183 check_key_in_hostfiles(struct passwd *, Key *, const char *,
184Index: b/auth2-hostbased.c
185===================================================================
186--- a/auth2-hostbased.c
187+++ b/auth2-hostbased.c
188@@ -146,7 +146,7 @@
189 int len;
190 char *fp;
191
192- if (auth_key_is_revoked(key))
193+ if (auth_key_is_revoked(key, 0))
194 return 0;
195
196 resolvedname = get_canonical_hostname(options.use_dns);
197Index: b/auth2-pubkey.c
198===================================================================
199--- a/auth2-pubkey.c
200+++ b/auth2-pubkey.c
201@@ -439,9 +439,10 @@
202 int success;
203 char *file;
204
205- if (auth_key_is_revoked(key))
206+ if (auth_key_is_revoked(key, 0))
207 return 0;
208- if (key_is_cert(key) && auth_key_is_revoked(key->cert->signature_key))
209+ if (key_is_cert(key) &&
210+ auth_key_is_revoked(key->cert->signature_key, 0))
211 return 0;
212
213 success = user_cert_trusted_ca(pw, key);
214Index: b/authfile.c
215===================================================================
216--- a/authfile.c
217+++ b/authfile.c
218@@ -68,6 +68,7 @@
219 #include "rsa.h"
220 #include "misc.h"
221 #include "atomicio.h"
222+#include "pathnames.h"
223
224 /* Version identification string for SSH v1 identity files. */
225 static const char authfile_id_string[] =
226@@ -906,3 +907,140 @@
227 return ret;
228 }
229
230+/* Scan a blacklist of known-vulnerable keys in blacklist_file. */
231+static int
232+blacklisted_key_in_file(Key *key, const char *blacklist_file, char **fp)
233+{
234+ int fd = -1;
235+ char *dgst_hex = NULL;
236+ char *dgst_packed = NULL, *p;
237+ int i;
238+ size_t line_len;
239+ struct stat st;
240+ char buf[256];
241+ off_t start, lower, upper;
242+ int ret = 0;
243+
244+ debug("Checking blacklist file %s", blacklist_file);
245+ fd = open(blacklist_file, O_RDONLY);
246+ if (fd < 0) {
247+ ret = -1;
248+ goto out;
249+ }
250+
251+ dgst_hex = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
252+ /* Remove all colons */
253+ dgst_packed = xcalloc(1, strlen(dgst_hex) + 1);
254+ for (i = 0, p = dgst_packed; dgst_hex[i]; i++)
255+ if (dgst_hex[i] != ':')
256+ *p++ = dgst_hex[i];
257+ /* Only compare least-significant 80 bits (to keep the blacklist
258+ * size down)
259+ */
260+ line_len = strlen(dgst_packed + 12);
261+ if (line_len > 32)
262+ goto out;
263+
264+ /* Skip leading comments */
265+ start = 0;
266+ for (;;) {
267+ ssize_t r;
268+ char *newline;
269+
270+ r = atomicio(read, fd, buf, sizeof(buf));
271+ if (r <= 0)
272+ goto out;
273+ if (buf[0] != '#')
274+ break;
275+
276+ newline = memchr(buf, '\n', sizeof(buf));
277+ if (!newline)
278+ goto out;
279+ start += newline + 1 - buf;
280+ if (lseek(fd, start, SEEK_SET) < 0)
281+ goto out;
282+ }
283+
284+ /* Initialise binary search record numbers */
285+ if (fstat(fd, &st) < 0)
286+ goto out;
287+ lower = 0;
288+ upper = (st.st_size - start) / (line_len + 1);
289+
290+ while (lower != upper) {
291+ off_t cur;
292+ int cmp;
293+
294+ cur = lower + (upper - lower) / 2;
295+
296+ /* Read this line and compare to digest; this is
297+ * overflow-safe since cur < max(off_t) / (line_len + 1) */
298+ if (lseek(fd, start + cur * (line_len + 1), SEEK_SET) < 0)
299+ break;
300+ if (atomicio(read, fd, buf, line_len) != line_len)
301+ break;
302+ cmp = memcmp(buf, dgst_packed + 12, line_len);
303+ if (cmp < 0) {
304+ if (cur == lower)
305+ break;
306+ lower = cur;
307+ } else if (cmp > 0) {
308+ if (cur == upper)
309+ break;
310+ upper = cur;
311+ } else {
312+ debug("Found %s in blacklist", dgst_hex);
313+ ret = 1;
314+ break;
315+ }
316+ }
317+
318+out:
319+ if (dgst_packed)
320+ xfree(dgst_packed);
321+ if (ret != 1 && dgst_hex) {
322+ xfree(dgst_hex);
323+ dgst_hex = NULL;
324+ }
325+ if (fp)
326+ *fp = dgst_hex;
327+ if (fd >= 0)
328+ close(fd);
329+ return ret;
330+}
331+
332+/*
333+ * Scan blacklists of known-vulnerable keys. If a vulnerable key is found,
334+ * its fingerprint is returned in *fp, unless fp is NULL.
335+ */
336+int
337+blacklisted_key(Key *key, char **fp)
338+{
339+ Key *public;
340+ char *blacklist_file;
341+ int ret, ret2;
342+
343+ public = key_demote(key);
344+ if (public->type == KEY_RSA1)
345+ public->type = KEY_RSA;
346+
347+ xasprintf(&blacklist_file, "%s.%s-%u",
348+ _PATH_BLACKLIST, key_type(public), key_size(public));
349+ ret = blacklisted_key_in_file(public, blacklist_file, fp);
350+ xfree(blacklist_file);
351+ if (ret > 0) {
352+ key_free(public);
353+ return ret;
354+ }
355+
356+ xasprintf(&blacklist_file, "%s.%s-%u",
357+ _PATH_BLACKLIST_CONFIG, key_type(public), key_size(public));
358+ ret2 = blacklisted_key_in_file(public, blacklist_file, fp);
359+ xfree(blacklist_file);
360+ if (ret2 > ret)
361+ ret = ret2;
362+
363+ key_free(public);
364+ return ret;
365+}
366+
367Index: b/authfile.h
368===================================================================
369--- a/authfile.h
370+++ b/authfile.h
371@@ -26,4 +26,6 @@
372 int key_perm_ok(int, const char *);
373 int key_in_file(Key *, const char *, int);
374
375+int blacklisted_key(Key *key, char **fp);
376+
377 #endif
378Index: b/pathnames.h
379===================================================================
380--- a/pathnames.h
381+++ b/pathnames.h
382@@ -18,6 +18,10 @@
383 #define SSHDIR ETCDIR "/ssh"
384 #endif
385
386+#ifndef _PATH_SSH_DATADIR
387+#define _PATH_SSH_DATADIR "/usr/share/ssh"
388+#endif
389+
390 #ifndef _PATH_SSH_PIDDIR
391 #define _PATH_SSH_PIDDIR "/var/run"
392 #endif
393@@ -44,6 +48,9 @@
394 /* Backwards compatibility */
395 #define _PATH_DH_PRIMES SSHDIR "/primes"
396
397+#define _PATH_BLACKLIST _PATH_SSH_DATADIR "/blacklist"
398+#define _PATH_BLACKLIST_CONFIG SSHDIR "/blacklist"
399+
400 #ifndef _PATH_SSH_PROGRAM
401 #define _PATH_SSH_PROGRAM "/usr/bin/ssh"
402 #endif
403Index: b/readconf.c
404===================================================================
405--- a/readconf.c
406+++ b/readconf.c
407@@ -125,6 +125,7 @@
408 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
409 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
410 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
411+ oUseBlacklistedKeys,
412 oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
413 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
414 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
415@@ -158,6 +159,7 @@
416 { "passwordauthentication", oPasswordAuthentication },
417 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
418 { "kbdinteractivedevices", oKbdInteractiveDevices },
419+ { "useblacklistedkeys", oUseBlacklistedKeys },
420 { "rsaauthentication", oRSAAuthentication },
421 { "pubkeyauthentication", oPubkeyAuthentication },
422 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
423@@ -486,6 +488,10 @@
424 intptr = &options->challenge_response_authentication;
425 goto parse_flag;
426
427+ case oUseBlacklistedKeys:
428+ intptr = &options->use_blacklisted_keys;
429+ goto parse_flag;
430+
431 case oGssAuthentication:
432 intptr = &options->gss_authentication;
433 goto parse_flag;
434@@ -1134,6 +1140,7 @@
435 options->kbd_interactive_devices = NULL;
436 options->rhosts_rsa_authentication = -1;
437 options->hostbased_authentication = -1;
438+ options->use_blacklisted_keys = -1;
439 options->batch_mode = -1;
440 options->check_host_ip = -1;
441 options->strict_host_key_checking = -1;
442@@ -1245,6 +1252,8 @@
443 options->rhosts_rsa_authentication = 0;
444 if (options->hostbased_authentication == -1)
445 options->hostbased_authentication = 0;
446+ if (options->use_blacklisted_keys == -1)
447+ options->use_blacklisted_keys = 0;
448 if (options->batch_mode == -1)
449 options->batch_mode = 0;
450 if (options->check_host_ip == -1)
451Index: b/readconf.h
452===================================================================
453--- a/readconf.h
454+++ b/readconf.h
455@@ -57,6 +57,7 @@
456 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
457 char *kbd_interactive_devices; /* Keyboard-interactive auth devices. */
458 int zero_knowledge_password_authentication; /* Try jpake */
459+ int use_blacklisted_keys; /* If true, send */
460 int batch_mode; /* Batch mode: do not ask for passwords. */
461 int check_host_ip; /* Also keep track of keys for IP address */
462 int strict_host_key_checking; /* Strict host key checking. */
463Index: b/servconf.c
464===================================================================
465--- a/servconf.c
466+++ b/servconf.c
467@@ -104,6 +104,7 @@
468 options->password_authentication = -1;
469 options->kbd_interactive_authentication = -1;
470 options->challenge_response_authentication = -1;
471+ options->permit_blacklisted_keys = -1;
472 options->permit_empty_passwd = -1;
473 options->permit_user_env = -1;
474 options->use_login = -1;
475@@ -243,6 +244,8 @@
476 options->kbd_interactive_authentication = 0;
477 if (options->challenge_response_authentication == -1)
478 options->challenge_response_authentication = 1;
479+ if (options->permit_blacklisted_keys == -1)
480+ options->permit_blacklisted_keys = 0;
481 if (options->permit_empty_passwd == -1)
482 options->permit_empty_passwd = 0;
483 if (options->permit_user_env == -1)
484@@ -322,7 +325,7 @@
485 sListenAddress, sAddressFamily,
486 sPrintMotd, sPrintLastLog, sIgnoreRhosts,
487 sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
488- sStrictModes, sEmptyPasswd, sTCPKeepAlive,
489+ sStrictModes, sPermitBlacklistedKeys, sEmptyPasswd, sTCPKeepAlive,
490 sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
491 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
492 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
493@@ -432,6 +435,7 @@
494 { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
495 { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
496 { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
497+ { "permitblacklistedkeys", sPermitBlacklistedKeys, SSHCFG_GLOBAL },
498 { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
499 { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
500 { "uselogin", sUseLogin, SSHCFG_GLOBAL },
501@@ -1029,6 +1033,10 @@
502 intptr = &options->tcp_keep_alive;
503 goto parse_flag;
504
505+ case sPermitBlacklistedKeys:
506+ intptr = &options->permit_blacklisted_keys;
507+ goto parse_flag;
508+
509 case sEmptyPasswd:
510 intptr = &options->permit_empty_passwd;
511 goto parse_flag;
512@@ -1757,6 +1765,7 @@
513 dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
514 dump_cfg_fmtint(sStrictModes, o->strict_modes);
515 dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
516+ dump_cfg_fmtint(sPermitBlacklistedKeys, o->permit_blacklisted_keys);
517 dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
518 dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
519 dump_cfg_fmtint(sUseLogin, o->use_login);
520Index: b/servconf.h
521===================================================================
522--- a/servconf.h
523+++ b/servconf.h
524@@ -107,6 +107,7 @@
525 int challenge_response_authentication;
526 int zero_knowledge_password_authentication;
527 /* If true, permit jpake auth */
528+ int permit_blacklisted_keys; /* If true, permit */
529 int permit_empty_passwd; /* If false, do not permit empty
530 * passwords. */
531 int permit_user_env; /* If true, read ~/.ssh/environment */
532Index: b/ssh-add.1
533===================================================================
534--- a/ssh-add.1
535+++ b/ssh-add.1
536@@ -81,6 +81,10 @@
537 .Nm
538 to work.
539 .Pp
540+Any keys recorded in the blacklist of known-compromised keys (see
541+.Xr ssh-vulnkey 1 )
542+will be refused.
543+.Pp
544 The options are as follows:
545 .Bl -tag -width Ds
546 .It Fl c
547@@ -183,6 +187,7 @@
548 .Xr ssh 1 ,
549 .Xr ssh-agent 1 ,
550 .Xr ssh-keygen 1 ,
551+.Xr ssh-vulnkey 1 ,
552 .Xr sshd 8
553 .Sh AUTHORS
554 OpenSSH is a derivative of the original and free
555Index: b/ssh-add.c
556===================================================================
557--- a/ssh-add.c
558+++ b/ssh-add.c
559@@ -142,7 +142,7 @@
560 add_file(AuthenticationConnection *ac, const char *filename)
561 {
562 Key *private, *cert;
563- char *comment = NULL;
564+ char *comment = NULL, *fp;
565 char msg[1024], *certpath;
566 int fd, perms_ok, ret = -1;
567
568@@ -187,6 +187,14 @@
569 "Bad passphrase, try again for %.200s: ", comment);
570 }
571 }
572+ if (blacklisted_key(private, &fp) == 1) {
573+ fprintf(stderr, "Public key %s blacklisted (see "
574+ "ssh-vulnkey(1)); refusing to add it\n", fp);
575+ xfree(fp);
576+ key_free(private);
577+ xfree(comment);
578+ return -1;
579+ }
580
581 if (ssh_add_identity_constrained(ac, private, comment, lifetime,
582 confirm)) {
583Index: b/ssh-keygen.1
584===================================================================
585--- a/ssh-keygen.1
586+++ b/ssh-keygen.1
587@@ -659,6 +659,7 @@
588 .Xr ssh 1 ,
589 .Xr ssh-add 1 ,
590 .Xr ssh-agent 1 ,
591+.Xr ssh-vulnkey 1 ,
592 .Xr moduli 5 ,
593 .Xr sshd 8
594 .Rs
595Index: b/ssh-vulnkey.1
596===================================================================
597--- /dev/null
598+++ b/ssh-vulnkey.1
599@@ -0,0 +1,242 @@
600+.\" Copyright (c) 2008 Canonical Ltd. All rights reserved.
601+.\"
602+.\" Redistribution and use in source and binary forms, with or without
603+.\" modification, are permitted provided that the following conditions
604+.\" are met:
605+.\" 1. Redistributions of source code must retain the above copyright
606+.\" notice, this list of conditions and the following disclaimer.
607+.\" 2. Redistributions in binary form must reproduce the above copyright
608+.\" notice, this list of conditions and the following disclaimer in the
609+.\" documentation and/or other materials provided with the distribution.
610+.\"
611+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
612+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
613+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
614+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
615+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
616+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
617+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
618+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
619+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
620+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
621+.\"
622+.Dd $Mdocdate: May 12 2008 $
623+.Dt SSH-VULNKEY 1
624+.Os
625+.Sh NAME
626+.Nm ssh-vulnkey
627+.Nd check blacklist of compromised keys
628+.Sh SYNOPSIS
629+.Nm
630+.Op Fl q | Fl v
631+.Ar file ...
632+.Nm
633+.Fl a
634+.Sh DESCRIPTION
635+.Nm
636+checks a key against a blacklist of compromised keys.
637+.Pp
638+A substantial number of keys are known to have been generated using a broken
639+version of OpenSSL distributed by Debian which failed to seed its random
640+number generator correctly.
641+Keys generated using these OpenSSL versions should be assumed to be
642+compromised.
643+This tool may be useful in checking for such keys.
644+.Pp
645+Keys that are compromised cannot be repaired; replacements must be generated
646+using
647+.Xr ssh-keygen 1 .
648+Make sure to update
649+.Pa authorized_keys
650+files on all systems where compromised keys were permitted to authenticate.
651+.Pp
652+The argument list will be interpreted as a list of paths to public key files
653+or
654+.Pa authorized_keys
655+files.
656+If no suitable file is found at a given path,
657+.Nm
658+will append
659+.Pa .pub
660+and retry, in case it was given a private key file.
661+If no files are given as arguments,
662+.Nm
663+will check
664+.Pa ~/.ssh/id_rsa ,
665+.Pa ~/.ssh/id_dsa ,
666+.Pa ~/.ssh/identity ,
667+.Pa ~/.ssh/authorized_keys
668+and
669+.Pa ~/.ssh/authorized_keys2 ,
670+as well as the system's host keys if readable.
671+.Pp
672+If
673+.Dq -
674+is given as an argument,
675+.Nm
676+will read from standard input.
677+This can be used to process output from
678+.Xr ssh-keyscan 1 ,
679+for example:
680+.Pp
681+.Dl $ ssh-keyscan -t rsa remote.example.org | ssh-vulnkey -
682+.Pp
683+Unless the
684+.Cm PermitBlacklistedKeys
685+option is used,
686+.Xr sshd 8
687+will reject attempts to authenticate with keys in the compromised list.
688+.Pp
689+The output from
690+.Nm
691+looks like this:
692+.Pp
693+.Bd -literal -offset indent
694+/etc/ssh/ssh_host_key:1: COMPROMISED: RSA1 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx root@host
695+/home/user/.ssh/id_dsa:1: Not blacklisted: DSA 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx /home/user/.ssh/id_dsa.pub
696+/home/user/.ssh/authorized_keys:3: Unknown (blacklist file not installed): RSA 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx user@host
697+.Ed
698+.Pp
699+Each line is of the following format (any lines beginning with
700+.Dq #
701+should be ignored by scripts):
702+.Pp
703+.Dl Ar filename : Ns Ar line : Ar status : Ar type Ar size Ar fingerprint Ar comment
704+.Pp
705+It is important to distinguish between the possible values of
706+.Ar status :
707+.Pp
708+.Bl -tag -width Ds
709+.It COMPROMISED
710+These keys are listed in a blacklist file, normally because their
711+corresponding private keys are well-known.
712+Replacements must be generated using
713+.Xr ssh-keygen 1 .
714+.It Not blacklisted
715+A blacklist file exists for this key type and size, but this key is not
716+listed in it.
717+Unless there is some particular reason to believe otherwise, this key
718+may be used safely.
719+(Note that DSA keys used with the broken version of OpenSSL distributed
720+by Debian may be compromised in the event that anyone captured a network
721+trace, even if they were generated with a secure version of OpenSSL.)
722+.It Unknown (blacklist file not installed)
723+No blacklist file exists for this key type and size.
724+You should find a suitable published blacklist and install it before
725+deciding whether this key is safe to use.
726+.El
727+.Pp
728+The options are as follows:
729+.Bl -tag -width Ds
730+.It Fl a
731+Check keys of all users on the system.
732+You will typically need to run
733+.Nm
734+as root to use this option.
735+For each user,
736+.Nm
737+will check
738+.Pa ~/.ssh/id_rsa ,
739+.Pa ~/.ssh/id_dsa ,
740+.Pa ~/.ssh/identity ,
741+.Pa ~/.ssh/authorized_keys
742+and
743+.Pa ~/.ssh/authorized_keys2 .
744+It will also check the system's host keys.
745+.It Fl q
746+Quiet mode.
747+Normally,
748+.Nm
749+outputs the fingerprint of each key scanned, with a description of its
750+status.
751+This option suppresses that output.
752+.It Fl v
753+Verbose mode.
754+Normally,
755+.Nm
756+does not output anything for keys that are not listed in their corresponding
757+blacklist file (although it still produces output for keys for which there
758+is no blacklist file, since their status is unknown).
759+This option causes
760+.Nm
761+to produce output for all keys.
762+.El
763+.Sh EXIT STATUS
764+.Nm
765+will exit zero if any of the given keys were in the compromised list,
766+otherwise non-zero.
767+.Sh BLACKLIST FILE FORMAT
768+The blacklist file may start with comments, on lines starting with
769+.Dq # .
770+After these initial comments, it must follow a strict format:
771+.Pp
772+.Bl -bullet -offset indent -compact
773+.It
774+All the lines must be exactly the same length (20 characters followed by a
775+newline) and must be in sorted order.
776+.It
777+Each line must consist of the lower-case hexadecimal MD5 key fingerprint,
778+without colons, and with the first 12 characters removed (that is, the least
779+significant 80 bits of the fingerprint).
780+.El
781+.Pp
782+The key fingerprint may be generated using
783+.Xr ssh-keygen 1 :
784+.Pp
785+.Dl $ ssh-keygen -l -f /path/to/key
786+.Pp
787+This strict format is necessary to allow the blacklist file to be checked
788+quickly, using a binary-search algorithm.
789+.Sh FILES
790+.Bl -tag -width Ds
791+.It Pa ~/.ssh/id_rsa
792+If present, contains the protocol version 2 RSA authentication identity of
793+the user.
794+.It Pa ~/.ssh/id_dsa
795+If present, contains the protocol version 2 DSA authentication identity of
796+the user.
797+.It Pa ~/.ssh/identity
798+If present, contains the protocol version 1 RSA authentication identity of
799+the user.
800+.It Pa ~/.ssh/authorized_keys
801+If present, lists the public keys (RSA/DSA) that can be used for logging in
802+as this user.
803+.It Pa ~/.ssh/authorized_keys2
804+Obsolete name for
805+.Pa ~/.ssh/authorized_keys .
806+This file may still be present on some old systems, but should not be
807+created if it is missing.
808+.It Pa /etc/ssh/ssh_host_rsa_key
809+If present, contains the protocol version 2 RSA identity of the system.
810+.It Pa /etc/ssh/ssh_host_dsa_key
811+If present, contains the protocol version 2 DSA identity of the system.
812+.It Pa /etc/ssh/ssh_host_key
813+If present, contains the protocol version 1 RSA identity of the system.
814+.It Pa /usr/share/ssh/blacklist. Ns Ar TYPE Ns Pa - Ns Ar LENGTH
815+If present, lists the blacklisted keys of type
816+.Ar TYPE
817+.Pf ( Dq RSA
818+or
819+.Dq DSA )
820+and bit length
821+.Ar LENGTH .
822+The format of this file is described above.
823+RSA1 keys are converted to RSA before being checked in the blacklist.
824+Note that the fingerprints of RSA1 keys are computed differently, so you
825+will not be able to find them in the blacklist by hand.
826+.It Pa /etc/ssh/blacklist. Ns Ar TYPE Ns Pa - Ns Ar LENGTH
827+Same as
828+.Pa /usr/share/ssh/blacklist. Ns Ar TYPE Ns Pa - Ns Ar LENGTH ,
829+but may be edited by the system administrator to add new blacklist entries.
830+.El
831+.Sh SEE ALSO
832+.Xr ssh-keygen 1 ,
833+.Xr sshd 8
834+.Sh AUTHORS
835+.An -nosplit
836+.An Colin Watson Aq cjwatson@ubuntu.com
837+.Pp
838+Florian Weimer suggested the option to check keys of all users, and the idea
839+of processing
840+.Xr ssh-keyscan 1
841+output.
842Index: b/ssh-vulnkey.c
843===================================================================
844--- /dev/null
845+++ b/ssh-vulnkey.c
846@@ -0,0 +1,388 @@
847+/*
848+ * Copyright (c) 2008 Canonical Ltd. All rights reserved.
849+ *
850+ * Redistribution and use in source and binary forms, with or without
851+ * modification, are permitted provided that the following conditions
852+ * are met:
853+ * 1. Redistributions of source code must retain the above copyright
854+ * notice, this list of conditions and the following disclaimer.
855+ * 2. Redistributions in binary form must reproduce the above copyright
856+ * notice, this list of conditions and the following disclaimer in the
857+ * documentation and/or other materials provided with the distribution.
858+ *
859+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
860+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
861+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
862+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
863+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
864+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
865+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
866+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
867+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
868+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
869+ */
870+
871+#include "includes.h"
872+
873+#include <sys/types.h>
874+#include <sys/stat.h>
875+
876+#include <errno.h>
877+#include <string.h>
878+#include <stdio.h>
879+#include <fcntl.h>
880+#include <unistd.h>
881+
882+#include <openssl/evp.h>
883+
884+#include "xmalloc.h"
885+#include "ssh.h"
886+#include "log.h"
887+#include "key.h"
888+#include "authfile.h"
889+#include "pathnames.h"
890+#include "uidswap.h"
891+#include "misc.h"
892+
893+extern char *__progname;
894+
895+/* Default files to check */
896+static char *default_host_files[] = {
897+ _PATH_HOST_RSA_KEY_FILE,
898+ _PATH_HOST_DSA_KEY_FILE,
899+ _PATH_HOST_KEY_FILE,
900+ NULL
901+};
902+static char *default_files[] = {
903+ _PATH_SSH_CLIENT_ID_RSA,
904+ _PATH_SSH_CLIENT_ID_DSA,
905+ _PATH_SSH_CLIENT_IDENTITY,
906+ _PATH_SSH_USER_PERMITTED_KEYS,
907+ _PATH_SSH_USER_PERMITTED_KEYS2,
908+ NULL
909+};
910+
911+static int verbosity = 0;
912+
913+static int some_keys = 0;
914+static int some_unknown = 0;
915+static int some_compromised = 0;
916+
917+static void
918+usage(void)
919+{
920+ fprintf(stderr, "usage: %s [-aqv] [file ...]\n", __progname);
921+ fprintf(stderr, "Options:\n");
922+ fprintf(stderr, " -a Check keys of all users.\n");
923+ fprintf(stderr, " -q Quiet mode.\n");
924+ fprintf(stderr, " -v Verbose mode.\n");
925+ exit(1);
926+}
927+
928+static void
929+describe_key(const char *filename, u_long linenum, const char *msg,
930+ Key *key, const char *comment, int min_verbosity)
931+{
932+ char *fp;
933+
934+ fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
935+ if (verbosity >= min_verbosity) {
936+ if (strchr(filename, ':'))
937+ printf("\"%s\"", filename);
938+ else
939+ printf("%s", filename);
940+ printf(":%lu: %s: %s %u %s %s\n", linenum, msg,
941+ key_type(key), key_size(key), fp, comment);
942+ }
943+ xfree(fp);
944+}
945+
946+static int
947+do_key(const char *filename, u_long linenum,
948+ Key *key, const char *comment)
949+{
950+ Key *public;
951+ int blacklist_status;
952+ int ret = 1;
953+
954+ some_keys = 1;
955+
956+ public = key_demote(key);
957+ if (public->type == KEY_RSA1)
958+ public->type = KEY_RSA;
959+
960+ blacklist_status = blacklisted_key(public, NULL);
961+ if (blacklist_status == -1) {
962+ describe_key(filename, linenum,
963+ "Unknown (blacklist file not installed)", key, comment, 0);
964+ some_unknown = 1;
965+ } else if (blacklist_status == 1) {
966+ describe_key(filename, linenum,
967+ "COMPROMISED", key, comment, 0);
968+ some_compromised = 1;
969+ ret = 0;
970+ } else
971+ describe_key(filename, linenum,
972+ "Not blacklisted", key, comment, 1);
973+
974+ key_free(public);
975+
976+ return ret;
977+}
978+
979+static int
980+do_filename(const char *filename, int quiet_open)
981+{
982+ FILE *f;
983+ char line[SSH_MAX_PUBKEY_BYTES];
984+ char *cp;
985+ u_long linenum = 0;
986+ Key *key;
987+ char *comment = NULL;
988+ int found = 0, ret = 1;
989+
990+ /* Copy much of key_load_public's logic here so that we can read
991+ * several keys from a single file (e.g. authorized_keys).
992+ */
993+
994+ if (strcmp(filename, "-") != 0) {
995+ int save_errno;
996+ f = fopen(filename, "r");
997+ save_errno = errno;
998+ if (!f) {
999+ char pubfile[MAXPATHLEN];
1000+ if (strlcpy(pubfile, filename, sizeof pubfile) <
1001+ sizeof(pubfile) &&
1002+ strlcat(pubfile, ".pub", sizeof pubfile) <
1003+ sizeof(pubfile))
1004+ f = fopen(pubfile, "r");
1005+ }
1006+ errno = save_errno; /* earlier errno is more useful */
1007+ if (!f) {
1008+ if (!quiet_open)
1009+ perror(filename);
1010+ return -1;
1011+ }
1012+ if (verbosity > 0)
1013+ printf("# %s\n", filename);
1014+ } else
1015+ f = stdin;
1016+ while (read_keyfile_line(f, filename, line, sizeof(line),
1017+ &linenum) != -1) {
1018+ int i;
1019+ char *space;
1020+ int type;
1021+ char *end;
1022+
1023+ /* Chop trailing newline. */
1024+ i = strlen(line) - 1;
1025+ if (line[i] == '\n')
1026+ line[i] = '\0';
1027+
1028+ /* Skip leading whitespace, empty and comment lines. */
1029+ for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
1030+ ;
1031+ if (!*cp || *cp == '\n' || *cp == '#')
1032+ continue;
1033+
1034+ /* Cope with ssh-keyscan output and options in
1035+ * authorized_keys files.
1036+ */
1037+ space = strchr(cp, ' ');
1038+ if (!space)
1039+ continue;
1040+ *space = '\0';
1041+ type = key_type_from_name(cp);
1042+ *space = ' ';
1043+ /* Leading number (RSA1) or valid type (RSA/DSA) indicates
1044+ * that we have no host name or options to skip.
1045+ */
1046+ if ((strtol(cp, &end, 10) == 0 || *end != ' ') &&
1047+ type == KEY_UNSPEC) {
1048+ int quoted = 0;
1049+
1050+ for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
1051+ if (*cp == '\\' && cp[1] == '"')
1052+ cp++; /* Skip both */
1053+ else if (*cp == '"')
1054+ quoted = !quoted;
1055+ }
1056+ /* Skip remaining whitespace. */
1057+ for (; *cp == ' ' || *cp == '\t'; cp++)
1058+ ;
1059+ if (!*cp)
1060+ continue;
1061+ }
1062+
1063+ /* Read and process the key itself. */
1064+ key = key_new(KEY_RSA1);
1065+ if (key_read(key, &cp) == 1) {
1066+ while (*cp == ' ' || *cp == '\t')
1067+ cp++;
1068+ if (!do_key(filename, linenum,
1069+ key, *cp ? cp : filename))
1070+ ret = 0;
1071+ found = 1;
1072+ } else {
1073+ key_free(key);
1074+ key = key_new(KEY_UNSPEC);
1075+ if (key_read(key, &cp) == 1) {
1076+ while (*cp == ' ' || *cp == '\t')
1077+ cp++;
1078+ if (!do_key(filename, linenum,
1079+ key, *cp ? cp : filename))
1080+ ret = 0;
1081+ found = 1;
1082+ }
1083+ }
1084+ key_free(key);
1085+ }
1086+ if (f != stdin)
1087+ fclose(f);
1088+
1089+ if (!found && filename) {
1090+ key = key_load_public(filename, &comment);
1091+ if (key) {
1092+ if (!do_key(filename, 1, key, comment))
1093+ ret = 0;
1094+ found = 1;
1095+ }
1096+ if (comment)
1097+ xfree(comment);
1098+ }
1099+
1100+ return ret;
1101+}
1102+
1103+static int
1104+do_host(int quiet_open)
1105+{
1106+ int i;
1107+ struct stat st;
1108+ int ret = 1;
1109+
1110+ for (i = 0; default_host_files[i]; i++) {
1111+ if (stat(default_host_files[i], &st) < 0 && errno == ENOENT)
1112+ continue;
1113+ if (!do_filename(default_host_files[i], quiet_open))
1114+ ret = 0;
1115+ }
1116+
1117+ return ret;
1118+}
1119+
1120+static int
1121+do_user(const char *dir)
1122+{
1123+ int i;
1124+ char *file;
1125+ struct stat st;
1126+ int ret = 1;
1127+
1128+ for (i = 0; default_files[i]; i++) {
1129+ xasprintf(&file, "%s/%s", dir, default_files[i]);
1130+ if (stat(file, &st) < 0 && errno == ENOENT) {
1131+ xfree(file);
1132+ continue;
1133+ }
1134+ if (!do_filename(file, 0))
1135+ ret = 0;
1136+ xfree(file);
1137+ }
1138+
1139+ return ret;
1140+}
1141+
1142+int
1143+main(int argc, char **argv)
1144+{
1145+ int opt, all_users = 0;
1146+ int ret = 1;
1147+ extern int optind;
1148+
1149+ /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
1150+ sanitise_stdfd();
1151+
1152+ __progname = ssh_get_progname(argv[0]);
1153+
1154+ SSLeay_add_all_algorithms();
1155+ log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1);
1156+
1157+ /* We don't need the RNG ourselves, but symbol references here allow
1158+ * ld to link us properly.
1159+ */
1160+ init_rng();
1161+ seed_rng();
1162+
1163+ while ((opt = getopt(argc, argv, "ahqv")) != -1) {
1164+ switch (opt) {
1165+ case 'a':
1166+ all_users = 1;
1167+ break;
1168+ case 'q':
1169+ verbosity--;
1170+ break;
1171+ case 'v':
1172+ verbosity++;
1173+ break;
1174+ case 'h':
1175+ default:
1176+ usage();
1177+ }
1178+ }
1179+
1180+ if (all_users) {
1181+ struct passwd *pw;
1182+
1183+ if (!do_host(0))
1184+ ret = 0;
1185+
1186+ while ((pw = getpwent()) != NULL) {
1187+ if (pw->pw_dir) {
1188+ temporarily_use_uid(pw);
1189+ if (!do_user(pw->pw_dir))
1190+ ret = 0;
1191+ restore_uid();
1192+ }
1193+ }
1194+ } else if (optind == argc) {
1195+ struct passwd *pw;
1196+
1197+ if (!do_host(1))
1198+ ret = 0;
1199+
1200+ if ((pw = getpwuid(geteuid())) == NULL)
1201+ fprintf(stderr, "No user found with uid %u\n",
1202+ (u_int)geteuid());
1203+ else {
1204+ if (!do_user(pw->pw_dir))
1205+ ret = 0;
1206+ }
1207+ } else {
1208+ while (optind < argc)
1209+ if (!do_filename(argv[optind++], 0))
1210+ ret = 0;
1211+ }
1212+
1213+ if (verbosity >= 0) {
1214+ if (some_unknown) {
1215+ printf("#\n");
1216+ printf("# The status of some keys on your system is unknown.\n");
1217+ printf("# You may need to install additional blacklist files.\n");
1218+ }
1219+ if (some_compromised) {
1220+ printf("#\n");
1221+ printf("# Some keys on your system have been compromised!\n");
1222+ printf("# You must replace them using ssh-keygen(1).\n");
1223+ }
1224+ if (some_unknown || some_compromised) {
1225+ printf("#\n");
1226+ printf("# See the ssh-vulnkey(1) manual page for further advice.\n");
1227+ } else if (some_keys && verbosity > 0) {
1228+ printf("#\n");
1229+ printf("# No blacklisted keys!\n");
1230+ }
1231+ }
1232+
1233+ return ret;
1234+}
1235Index: b/ssh.1
1236===================================================================
1237--- a/ssh.1
1238+++ b/ssh.1
1239@@ -1402,6 +1402,7 @@
1240 .Xr ssh-agent 1 ,
1241 .Xr ssh-keygen 1 ,
1242 .Xr ssh-keyscan 1 ,
1243+.Xr ssh-vulnkey 1 ,
1244 .Xr tun 4 ,
1245 .Xr hosts.equiv 5 ,
1246 .Xr ssh_config 5 ,
1247Index: b/ssh.c
1248===================================================================
1249--- a/ssh.c
1250+++ b/ssh.c
1251@@ -1448,7 +1448,7 @@
1252 static void
1253 load_public_identity_files(void)
1254 {
1255- char *filename, *cp, thishost[NI_MAXHOST];
1256+ char *filename, *cp, thishost[NI_MAXHOST], *fp;
1257 char *pwdir = NULL, *pwname = NULL;
1258 int i = 0;
1259 Key *public;
1260@@ -1505,6 +1505,22 @@
1261 public = key_load_public(filename, NULL);
1262 debug("identity file %s type %d", filename,
1263 public ? public->type : -1);
1264+ if (public && blacklisted_key(public, &fp) == 1) {
1265+ if (options.use_blacklisted_keys)
1266+ logit("Public key %s blacklisted (see "
1267+ "ssh-vulnkey(1)); continuing anyway", fp);
1268+ else
1269+ logit("Public key %s blacklisted (see "
1270+ "ssh-vulnkey(1)); refusing to send it",
1271+ fp);
1272+ xfree(fp);
1273+ if (!options.use_blacklisted_keys) {
1274+ key_free(public);
1275+ xfree(filename);
1276+ filename = NULL;
1277+ public = NULL;
1278+ }
1279+ }
1280 xfree(options.identity_files[i]);
1281 identity_files[n_ids] = filename;
1282 identity_keys[n_ids] = public;
1283Index: b/ssh_config.5
1284===================================================================
1285--- a/ssh_config.5
1286+++ b/ssh_config.5
1287@@ -1146,6 +1146,23 @@
1288 .Dq any .
1289 The default is
1290 .Dq any:any .
1291+.It Cm UseBlacklistedKeys
1292+Specifies whether
1293+.Xr ssh 1
1294+should use keys recorded in its blacklist of known-compromised keys (see
1295+.Xr ssh-vulnkey 1 )
1296+for authentication.
1297+If
1298+.Dq yes ,
1299+then attempts to use compromised keys for authentication will be logged but
1300+accepted.
1301+It is strongly recommended that this be used only to install new authorized
1302+keys on the remote system, and even then only with the utmost care.
1303+If
1304+.Dq no ,
1305+then attempts to use compromised keys for authentication will be prevented.
1306+The default is
1307+.Dq no .
1308 .It Cm UsePrivilegedPort
1309 Specifies whether to use a privileged port for outgoing connections.
1310 The argument must be
1311Index: b/sshconnect2.c
1312===================================================================
1313--- a/sshconnect2.c
1314+++ b/sshconnect2.c
1315@@ -1488,6 +1488,8 @@
1316
1317 /* list of keys stored in the filesystem */
1318 for (i = 0; i < options.num_identity_files; i++) {
1319+ if (options.identity_files[i] == NULL)
1320+ continue;
1321 key = options.identity_keys[i];
1322 if (key && key->type == KEY_RSA1)
1323 continue;
1324@@ -1581,7 +1583,7 @@
1325 debug("Offering %s public key: %s", key_type(id->key),
1326 id->filename);
1327 sent = send_pubkey_test(authctxt, id);
1328- } else if (id->key == NULL) {
1329+ } else if (id->key == NULL && id->filename) {
1330 debug("Trying private key: %s", id->filename);
1331 id->key = load_identity_file(id->filename);
1332 if (id->key != NULL) {
1333Index: b/sshd.8
1334===================================================================
1335--- a/sshd.8
1336+++ b/sshd.8
1337@@ -945,6 +945,7 @@
1338 .Xr ssh-agent 1 ,
1339 .Xr ssh-keygen 1 ,
1340 .Xr ssh-keyscan 1 ,
1341+.Xr ssh-vulnkey 1 ,
1342 .Xr chroot 2 ,
1343 .Xr hosts_access 5 ,
1344 .Xr login.conf 5 ,
1345Index: b/sshd.c
1346===================================================================
1347--- a/sshd.c
1348+++ b/sshd.c
1349@@ -1576,6 +1576,11 @@
1350 sensitive_data.host_keys[i] = NULL;
1351 continue;
1352 }
1353+ if (auth_key_is_revoked(key, 1)) {
1354+ key_free(key);
1355+ sensitive_data.host_keys[i] = NULL;
1356+ continue;
1357+ }
1358 switch (key->type) {
1359 case KEY_RSA1:
1360 sensitive_data.ssh1_host_key = key;
1361Index: b/sshd_config.5
1362===================================================================
1363--- a/sshd_config.5
1364+++ b/sshd_config.5
1365@@ -792,6 +792,20 @@
1366 Specifies whether password authentication is allowed.
1367 The default is
1368 .Dq yes .
1369+.It Cm PermitBlacklistedKeys
1370+Specifies whether
1371+.Xr sshd 8
1372+should allow keys recorded in its blacklist of known-compromised keys (see
1373+.Xr ssh-vulnkey 1 ) .
1374+If
1375+.Dq yes ,
1376+then attempts to authenticate with compromised keys will be logged but
1377+accepted.
1378+If
1379+.Dq no ,
1380+then attempts to authenticate with compromised keys will be rejected.
1381+The default is
1382+.Dq no .
1383 .It Cm PermitEmptyPasswords
1384 When password authentication is allowed, it specifies whether the
1385 server allows login to accounts with empty password strings.
diff --git a/debian/patches/ssh1-keepalive.patch b/debian/patches/ssh1-keepalive.patch
new file mode 100644
index 000000000..5f1caddc9
--- /dev/null
+++ b/debian/patches/ssh1-keepalive.patch
@@ -0,0 +1,65 @@
1Description: Partial server keep-alive implementation for SSH1
2Author: Colin Watson <cjwatson@debian.org>
3Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1712
4Last-Update: 2010-02-27
5
6Index: b/clientloop.c
7===================================================================
8--- a/clientloop.c
9+++ b/clientloop.c
10@@ -547,16 +547,21 @@
11 static void
12 server_alive_check(void)
13 {
14- if (packet_inc_alive_timeouts() > options.server_alive_count_max) {
15- logit("Timeout, server %s not responding.", host);
16- cleanup_exit(255);
17+ if (compat20) {
18+ if (packet_inc_alive_timeouts() > options.server_alive_count_max) {
19+ logit("Timeout, server %s not responding.", host);
20+ cleanup_exit(255);
21+ }
22+ packet_start(SSH2_MSG_GLOBAL_REQUEST);
23+ packet_put_cstring("keepalive@openssh.com");
24+ packet_put_char(1); /* boolean: want reply */
25+ packet_send();
26+ /* Insert an empty placeholder to maintain ordering */
27+ client_register_global_confirm(NULL, NULL);
28+ } else {
29+ packet_send_ignore(0);
30+ packet_send();
31 }
32- packet_start(SSH2_MSG_GLOBAL_REQUEST);
33- packet_put_cstring("keepalive@openssh.com");
34- packet_put_char(1); /* boolean: want reply */
35- packet_send();
36- /* Insert an empty placeholder to maintain ordering */
37- client_register_global_confirm(NULL, NULL);
38 }
39
40 /*
41@@ -616,7 +621,7 @@
42 */
43
44 timeout_secs = INT_MAX; /* we use INT_MAX to mean no timeout */
45- if (options.server_alive_interval > 0 && compat20)
46+ if (options.server_alive_interval > 0)
47 timeout_secs = options.server_alive_interval;
48 set_control_persist_exit_time();
49 if (control_persist_exit_time > 0) {
50Index: b/ssh_config.5
51===================================================================
52--- a/ssh_config.5
53+++ b/ssh_config.5
54@@ -1047,7 +1047,10 @@
55 .Cm ServerAliveCountMax
56 is left at the default, if the server becomes unresponsive,
57 ssh will disconnect after approximately 45 seconds.
58-This option applies to protocol version 2 only.
59+This option applies to protocol version 2 only; in protocol version
60+1 there is no mechanism to request a response from the server to the
61+server alive messages, so disconnection is the responsibility of the TCP
62+stack.
63 .It Cm ServerAliveInterval
64 Sets a timeout interval in seconds after which if no data has been received
65 from the server,
diff --git a/debian/patches/syslog-level-silent.patch b/debian/patches/syslog-level-silent.patch
new file mode 100644
index 000000000..9b560217f
--- /dev/null
+++ b/debian/patches/syslog-level-silent.patch
@@ -0,0 +1,37 @@
1Description: "LogLevel SILENT" compatibility
2 "LogLevel SILENT" (-qq) was introduced in Debian openssh 1:3.0.1p1-1 to
3 match the behaviour of non-free SSH, in which -q does not suppress fatal
4 errors. However, this was unintentionally broken in 1:4.6p1-2 and nobody
5 complained, so we've dropped most of it. The parts that remain are basic
6 configuration file compatibility, and an adjustment to "Pseudo-terminal
7 will not be allocated ..." which should be split out into a separate patch.
8Author: Jonathan David Amery <jdamery@ysolde.ucam.org>
9Author: Matthew Vernon <matthew@debian.org>
10Author: Colin Watson <cjwatson@debian.org>
11Last-Update: 2010-03-31
12
13Index: b/log.c
14===================================================================
15--- a/log.c
16+++ b/log.c
17@@ -90,6 +90,7 @@
18 LogLevel val;
19 } log_levels[] =
20 {
21+ { "SILENT", SYSLOG_LEVEL_QUIET }, /* compatibility */
22 { "QUIET", SYSLOG_LEVEL_QUIET },
23 { "FATAL", SYSLOG_LEVEL_FATAL },
24 { "ERROR", SYSLOG_LEVEL_ERROR },
25Index: b/ssh.c
26===================================================================
27--- a/ssh.c
28+++ b/ssh.c
29@@ -641,7 +641,7 @@
30 tty_flag = 0;
31 /* Do not allocate a tty if stdin is not a tty. */
32 if ((!isatty(fileno(stdin)) || stdin_null_flag) && !force_tty_flag) {
33- if (tty_flag)
34+ if (tty_flag && options.log_level != SYSLOG_LEVEL_QUIET)
35 logit("Pseudo-terminal will not be allocated because "
36 "stdin is not a terminal.");
37 tty_flag = 0;
diff --git a/debian/patches/user-group-modes.patch b/debian/patches/user-group-modes.patch
new file mode 100644
index 000000000..fe2d99be0
--- /dev/null
+++ b/debian/patches/user-group-modes.patch
@@ -0,0 +1,202 @@
1Description: Allow harmless group-writability
2 Allow secure files (~/.ssh/config, ~/.ssh/authorized_keys, etc.) to be
3 group-writable, provided that the group in question contains only the
4 file's owner. Rejected upstream for IMO incorrect reasons (e.g. a
5 misunderstanding about the contents of gr->gr_mem). Given that
6 per-user groups and umask 002 are the default setup in Debian (for good
7 reasons - this makes operating in setgid directories with other groups
8 much easier), we need to permit this by default.
9Author: Colin Watson <cjwatson@debian.org>
10Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1060
11Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=314347
12Last-Update: 2010-02-27
13
14Index: b/readconf.c
15===================================================================
16--- a/readconf.c
17+++ b/readconf.c
18@@ -30,6 +30,8 @@
19 #include <stdio.h>
20 #include <string.h>
21 #include <unistd.h>
22+#include <pwd.h>
23+#include <grp.h>
24
25 #include "xmalloc.h"
26 #include "ssh.h"
27@@ -1085,8 +1087,7 @@
28
29 if (fstat(fileno(f), &sb) == -1)
30 fatal("fstat %s: %s", filename, strerror(errno));
31- if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
32- (sb.st_mode & 022) != 0))
33+ if (!secure_permissions(&sb, getuid()))
34 fatal("Bad owner or permissions on %s", filename);
35 }
36
37Index: b/ssh.1
38===================================================================
39--- a/ssh.1
40+++ b/ssh.1
41@@ -1293,6 +1293,8 @@
42 .Xr ssh_config 5 .
43 Because of the potential for abuse, this file must have strict permissions:
44 read/write for the user, and not accessible by others.
45+It may be group-writable provided that the group in question contains only
46+the user.
47 .Pp
48 .It Pa ~/.ssh/environment
49 Contains additional definitions for environment variables; see
50Index: b/ssh_config.5
51===================================================================
52--- a/ssh_config.5
53+++ b/ssh_config.5
54@@ -1299,6 +1299,8 @@
55 This file is used by the SSH client.
56 Because of the potential for abuse, this file must have strict permissions:
57 read/write for the user, and not accessible by others.
58+It may be group-writable provided that the group in question contains only
59+the user.
60 .It Pa /etc/ssh/ssh_config
61 Systemwide configuration file.
62 This file provides defaults for those
63Index: b/auth.c
64===================================================================
65--- a/auth.c
66+++ b/auth.c
67@@ -392,8 +392,7 @@
68 user_hostfile = tilde_expand_filename(userfile, pw->pw_uid);
69 if (options.strict_modes &&
70 (stat(user_hostfile, &st) == 0) &&
71- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
72- (st.st_mode & 022) != 0)) {
73+ !secure_permissions(&st, pw->pw_uid)) {
74 logit("Authentication refused for %.100s: "
75 "bad owner or modes for %.200s",
76 pw->pw_name, user_hostfile);
77@@ -454,8 +453,7 @@
78
79 /* check the open file to avoid races */
80 if (fstat(fileno(f), &st) < 0 ||
81- (st.st_uid != 0 && st.st_uid != uid) ||
82- (st.st_mode & 022) != 0) {
83+ !secure_permissions(&st, uid)) {
84 snprintf(err, errlen, "bad ownership or modes for file %s",
85 buf);
86 return -1;
87@@ -471,8 +469,7 @@
88
89 debug3("secure_filename: checking '%s'", buf);
90 if (stat(buf, &st) < 0 ||
91- (st.st_uid != 0 && st.st_uid != uid) ||
92- (st.st_mode & 022) != 0) {
93+ !secure_permissions(&st, uid)) {
94 snprintf(err, errlen,
95 "bad ownership or modes for directory %s", buf);
96 return -1;
97Index: b/misc.c
98===================================================================
99--- a/misc.c
100+++ b/misc.c
101@@ -48,8 +48,9 @@
102 #include <netdb.h>
103 #ifdef HAVE_PATHS_H
104 # include <paths.h>
105-#include <pwd.h>
106 #endif
107+#include <pwd.h>
108+#include <grp.h>
109 #ifdef SSH_TUN_OPENBSD
110 #include <net/if.h>
111 #endif
112@@ -642,6 +643,55 @@
113 }
114
115 int
116+secure_permissions(struct stat *st, uid_t uid)
117+{
118+ if (st->st_uid != 0 && st->st_uid != uid)
119+ return 0;
120+ if ((st->st_mode & 002) != 0)
121+ return 0;
122+ if ((st->st_mode & 020) != 0) {
123+ /* If the file is group-writable, the group in question must
124+ * have exactly one member, namely the file's owner.
125+ * (Zero-member groups are typically used by setgid
126+ * binaries, and are unlikely to be suitable.)
127+ */
128+ struct passwd *pw;
129+ struct group *gr;
130+ int members = 0;
131+
132+ gr = getgrgid(st->st_gid);
133+ if (!gr)
134+ return 0;
135+
136+ /* Check primary group memberships. */
137+ while ((pw = getpwent()) != NULL) {
138+ if (pw->pw_gid == gr->gr_gid) {
139+ ++members;
140+ if (pw->pw_uid != uid)
141+ return 0;
142+ }
143+ }
144+ endpwent();
145+
146+ pw = getpwuid(st->st_uid);
147+ if (!pw)
148+ return 0;
149+
150+ /* Check supplementary group memberships. */
151+ if (gr->gr_mem[0]) {
152+ ++members;
153+ if (strcmp(pw->pw_name, gr->gr_mem[0]) ||
154+ gr->gr_mem[1])
155+ return 0;
156+ }
157+
158+ if (!members)
159+ return 0;
160+ }
161+ return 1;
162+}
163+
164+int
165 tun_open(int tun, int mode)
166 {
167 #if defined(CUSTOM_SYS_TUN_OPEN)
168Index: b/misc.h
169===================================================================
170--- a/misc.h
171+++ b/misc.h
172@@ -102,4 +102,6 @@
173 int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2)));
174 int read_keyfile_line(FILE *, const char *, char *, size_t, u_long *);
175
176+int secure_permissions(struct stat *st, uid_t uid);
177+
178 #endif /* _MISC_H */
179Index: b/auth-rhosts.c
180===================================================================
181--- a/auth-rhosts.c
182+++ b/auth-rhosts.c
183@@ -256,8 +256,7 @@
184 return 0;
185 }
186 if (options.strict_modes &&
187- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
188- (st.st_mode & 022) != 0)) {
189+ !secure_permissions(&st, pw->pw_uid)) {
190 logit("Rhosts authentication refused for %.100s: "
191 "bad ownership or modes for home directory.", pw->pw_name);
192 auth_debug_add("Rhosts authentication refused for %.100s: "
193@@ -283,8 +282,7 @@
194 * allowing access to their account by anyone.
195 */
196 if (options.strict_modes &&
197- ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
198- (st.st_mode & 022) != 0)) {
199+ !secure_permissions(&st, pw->pw_uid)) {
200 logit("Rhosts authentication refused for %.100s: bad modes for %.200s",
201 pw->pw_name, buf);
202 auth_debug_add("Bad file modes for %.200s", buf);