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