summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.gssapi113
-rw-r--r--Makefile.in3
-rw-r--r--auth-krb5.c17
-rw-r--r--auth2-gss.c48
-rw-r--r--auth2.c2
-rw-r--r--clientloop.c13
-rw-r--r--config.h.in6
-rwxr-xr-xconfigure57
-rw-r--r--configure.ac24
-rw-r--r--gss-genr.c276
-rw-r--r--gss-serv-krb5.c84
-rw-r--r--gss-serv.c220
-rw-r--r--kex.c18
-rw-r--r--kex.h14
-rw-r--r--kexgssc.c334
-rw-r--r--kexgsss.c288
-rw-r--r--key.c4
-rw-r--r--key.h1
-rw-r--r--monitor.c108
-rw-r--r--monitor.h2
-rw-r--r--monitor_wrap.c47
-rw-r--r--monitor_wrap.h4
-rw-r--r--readconf.c42
-rw-r--r--readconf.h5
-rw-r--r--servconf.c38
-rw-r--r--servconf.h3
-rw-r--r--ssh-gss.h39
-rw-r--r--ssh_config2
-rw-r--r--ssh_config.534
-rw-r--r--sshconnect2.c124
-rw-r--r--sshd.c110
-rw-r--r--sshd_config2
-rw-r--r--sshd_config.528
33 files changed, 2053 insertions, 57 deletions
diff --git a/ChangeLog.gssapi b/ChangeLog.gssapi
new file mode 100644
index 000000000..f117a336a
--- /dev/null
+++ b/ChangeLog.gssapi
@@ -0,0 +1,113 @@
120110101
2 - Finally update for OpenSSH 5.6p1
3 - Add GSSAPIServerIdentity option from Jim Basney
4
520100308
6 - [ Makefile.in, key.c, key.h ]
7 Updates for OpenSSH 5.4p1
8 - [ servconf.c ]
9 Include GSSAPI options in the sshd -T configuration dump, and flag
10 some older configuration options as being unsupported. Thanks to Colin
11 Watson.
12 -
13
1420100124
15 - [ sshconnect2.c ]
16 Adapt to deal with additional element in Authmethod structure. Thanks to
17 Colin Watson
18
1920090615
20 - [ gss-genr.c gss-serv.c kexgssc.c kexgsss.c monitor.c sshconnect2.c
21 sshd.c ]
22 Fix issues identified by Greg Hudson following a code review
23 Check return value of gss_indicate_mechs
24 Protect GSSAPI calls in monitor, so they can only be used if enabled
25 Check return values of bignum functions in key exchange
26 Use BN_clear_free to clear other side's DH value
27 Make ssh_gssapi_id_kex more robust
28 Only configure kex table pointers if GSSAPI is enabled
29 Don't leak mechanism list, or gss mechanism list
30 Cast data.length before printing
31 If serverkey isn't provided, use an empty string, rather than NULL
32
3320090201
34 - [ gss-genr.c gss-serv.c kex.h kexgssc.c readconf.c readconf.h ssh-gss.h
35 ssh_config.5 sshconnet2.c ]
36 Add support for the GSSAPIClientIdentity option, which allows the user
37 to specify which GSSAPI identity to use to contact a given server
38
3920080404
40 - [ gss-serv.c ]
41 Add code to actually implement GSSAPIStrictAcceptCheck, which had somehow
42 been omitted from a previous version of this patch. Reported by Borislav
43 Stoichkov
44
4520070317
46 - [ gss-serv-krb5.c ]
47 Remove C99ism, where new_ccname was being declared in the middle of a
48 function
49
5020061220
51 - [ servconf.c ]
52 Make default for GSSAPIStrictAcceptorCheck be Yes, to match previous, and
53 documented, behaviour. Reported by Dan Watson.
54
5520060910
56 - [ gss-genr.c kexgssc.c kexgsss.c kex.h monitor.c sshconnect2.c sshd.c
57 ssh-gss.h ]
58 add support for gss-group14-sha1 key exchange mechanisms
59 - [ gss-serv.c servconf.c servconf.h sshd_config sshd_config.5 ]
60 Add GSSAPIStrictAcceptorCheck option to allow the disabling of
61 acceptor principal checking on multi-homed machines.
62 <Bugzilla #928>
63 - [ sshd_config ssh_config ]
64 Add settings for GSSAPIKeyExchange and GSSAPITrustDNS to the sample
65 configuration files
66 - [ kexgss.c kegsss.c sshconnect2.c sshd.c ]
67 Code cleanup. Replace strlen/xmalloc/snprintf sequences with xasprintf()
68 Limit length of error messages displayed by client
69
7020060909
71 - [ gss-genr.c gss-serv.c ]
72 move ssh_gssapi_acquire_cred() and ssh_gssapi_server_ctx to be server
73 only, where they belong
74 <Bugzilla #1225>
75
7620060829
77 - [ gss-serv-krb5.c ]
78 Fix CCAPI credentials cache name when creating KRB5CCNAME environment
79 variable
80
8120060828
82 - [ gss-genr.c ]
83 Avoid Heimdal context freeing problem
84 <Fixed upstream 20060829>
85
8620060818
87 - [ gss-genr.c ssh-gss.h sshconnect2.c ]
88 Make sure that SPENGO is disabled
89 <Bugzilla #1218 - Fixed upstream 20060818>
90
9120060421
92 - [ gssgenr.c, sshconnect2.c ]
93 a few type changes (signed versus unsigned, int versus size_t) to
94 fix compiler errors/warnings
95 (from jbasney AT ncsa.uiuc.edu)
96 - [ kexgssc.c, sshconnect2.c ]
97 fix uninitialized variable warnings
98 (from jbasney AT ncsa.uiuc.edu)
99 - [ gssgenr.c ]
100 pass oid to gss_display_status (helpful when using GSSAPI mechglue)
101 (from jbasney AT ncsa.uiuc.edu)
102 <Bugzilla #1220 >
103 - [ gss-serv-krb5.c ]
104 #ifdef HAVE_GSSAPI_KRB5 should be #ifdef HAVE_GSSAPI_KRB5_H
105 (from jbasney AT ncsa.uiuc.edu)
106 <Fixed upstream 20060304>
107 - [ readconf.c, readconf.h, ssh_config.5, sshconnect2.c
108 add client-side GssapiKeyExchange option
109 (from jbasney AT ncsa.uiuc.edu)
110 - [ sshconnect2.c ]
111 add support for GssapiTrustDns option for gssapi-with-mic
112 (from jbasney AT ncsa.uiuc.edu)
113 <gssapi-with-mic support is Bugzilla #1008>
diff --git a/Makefile.in b/Makefile.in
index 566f58fe6..5081c4bf3 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -70,6 +70,7 @@ LIBSSH_OBJS=acss.o authfd.o authfile.o bufaux.o bufbn.o buffer.o \
70 atomicio.o key.o dispatch.o kex.o mac.o uidswap.o uuencode.o misc.o \ 70 atomicio.o key.o dispatch.o kex.o mac.o uidswap.o uuencode.o misc.o \
71 monitor_fdpass.o rijndael.o ssh-dss.o ssh-ecdsa.o ssh-rsa.o dh.o \ 71 monitor_fdpass.o rijndael.o ssh-dss.o ssh-ecdsa.o ssh-rsa.o dh.o \
72 kexdh.o kexgex.o kexdhc.o kexgexc.o bufec.o kexecdh.o kexecdhc.o \ 72 kexdh.o kexgex.o kexdhc.o kexgexc.o bufec.o kexecdh.o kexecdhc.o \
73 kexgssc.o \
73 msg.o progressmeter.o dns.o entropy.o gss-genr.o umac.o jpake.o \ 74 msg.o progressmeter.o dns.o entropy.o gss-genr.o umac.o jpake.o \
74 schnorr.o ssh-pkcs11.o 75 schnorr.o ssh-pkcs11.o
75 76
@@ -86,7 +87,7 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \
86 auth2-none.o auth2-passwd.o auth2-pubkey.o auth2-jpake.o \ 87 auth2-none.o auth2-passwd.o auth2-pubkey.o auth2-jpake.o \
87 monitor_mm.o monitor.o monitor_wrap.o kexdhs.o kexgexs.o kexecdhs.o \ 88 monitor_mm.o monitor.o monitor_wrap.o kexdhs.o kexgexs.o kexecdhs.o \
88 auth-krb5.o \ 89 auth-krb5.o \
89 auth2-gss.o gss-serv.o gss-serv-krb5.o \ 90 auth2-gss.o gss-serv.o gss-serv-krb5.o kexgsss.o\
90 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \ 91 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
91 sftp-server.o sftp-common.o \ 92 sftp-server.o sftp-common.o \
92 roaming_common.o roaming_serv.o \ 93 roaming_common.o roaming_serv.o \
diff --git a/auth-krb5.c b/auth-krb5.c
index 922c66c66..4c2375462 100644
--- a/auth-krb5.c
+++ b/auth-krb5.c
@@ -170,8 +170,13 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
170 170
171 len = strlen(authctxt->krb5_ticket_file) + 6; 171 len = strlen(authctxt->krb5_ticket_file) + 6;
172 authctxt->krb5_ccname = xmalloc(len); 172 authctxt->krb5_ccname = xmalloc(len);
173#ifdef USE_CCAPI
174 snprintf(authctxt->krb5_ccname, len, "API:%s",
175 authctxt->krb5_ticket_file);
176#else
173 snprintf(authctxt->krb5_ccname, len, "FILE:%s", 177 snprintf(authctxt->krb5_ccname, len, "FILE:%s",
174 authctxt->krb5_ticket_file); 178 authctxt->krb5_ticket_file);
179#endif
175 180
176#ifdef USE_PAM 181#ifdef USE_PAM
177 if (options.use_pam) 182 if (options.use_pam)
@@ -226,15 +231,22 @@ krb5_cleanup_proc(Authctxt *authctxt)
226#ifndef HEIMDAL 231#ifndef HEIMDAL
227krb5_error_code 232krb5_error_code
228ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) { 233ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
229 int tmpfd, ret, oerrno; 234 int ret, oerrno;
230 char ccname[40]; 235 char ccname[40];
231 mode_t old_umask; 236 mode_t old_umask;
237#ifdef USE_CCAPI
238 char cctemplate[] = "API:krb5cc_%d";
239#else
240 char cctemplate[] = "FILE:/tmp/krb5cc_%d_XXXXXXXXXX";
241 int tmpfd;
242#endif
232 243
233 ret = snprintf(ccname, sizeof(ccname), 244 ret = snprintf(ccname, sizeof(ccname),
234 "FILE:/tmp/krb5cc_%d_XXXXXXXXXX", geteuid()); 245 cctemplate, geteuid());
235 if (ret < 0 || (size_t)ret >= sizeof(ccname)) 246 if (ret < 0 || (size_t)ret >= sizeof(ccname))
236 return ENOMEM; 247 return ENOMEM;
237 248
249#ifndef USE_CCAPI
238 old_umask = umask(0177); 250 old_umask = umask(0177);
239 tmpfd = mkstemp(ccname + strlen("FILE:")); 251 tmpfd = mkstemp(ccname + strlen("FILE:"));
240 oerrno = errno; 252 oerrno = errno;
@@ -251,6 +263,7 @@ ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
251 return oerrno; 263 return oerrno;
252 } 264 }
253 close(tmpfd); 265 close(tmpfd);
266#endif
254 267
255 return (krb5_cc_resolve(ctx, ccname, ccache)); 268 return (krb5_cc_resolve(ctx, ccname, ccache));
256} 269}
diff --git a/auth2-gss.c b/auth2-gss.c
index 0d59b2177..7dc87dba4 100644
--- a/auth2-gss.c
+++ b/auth2-gss.c
@@ -1,7 +1,7 @@
1/* $OpenBSD: auth2-gss.c,v 1.17 2011/03/10 02:52:57 djm Exp $ */ 1/* $OpenBSD: auth2-gss.c,v 1.17 2011/03/10 02:52:57 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. 4 * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
@@ -52,6 +52,40 @@ static void input_gssapi_mic(int type, u_int32_t plen, void *ctxt);
52static void input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt); 52static void input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt);
53static void input_gssapi_errtok(int, u_int32_t, void *); 53static void input_gssapi_errtok(int, u_int32_t, void *);
54 54
55/*
56 * The 'gssapi_keyex' userauth mechanism.
57 */
58static int
59userauth_gsskeyex(Authctxt *authctxt)
60{
61 int authenticated = 0;
62 Buffer b;
63 gss_buffer_desc mic, gssbuf;
64 u_int len;
65
66 mic.value = packet_get_string(&len);
67 mic.length = len;
68
69 packet_check_eom();
70
71 ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service,
72 "gssapi-keyex");
73
74 gssbuf.value = buffer_ptr(&b);
75 gssbuf.length = buffer_len(&b);
76
77 /* gss_kex_context is NULL with privsep, so we can't check it here */
78 if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gss_kex_context,
79 &gssbuf, &mic))))
80 authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
81 authctxt->pw));
82
83 buffer_free(&b);
84 xfree(mic.value);
85
86 return (authenticated);
87}
88
55/* 89/*
56 * We only support those mechanisms that we know about (ie ones that we know 90 * We only support those mechanisms that we know about (ie ones that we know
57 * how to check local user kuserok and the like) 91 * how to check local user kuserok and the like)
@@ -244,7 +278,8 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt)
244 278
245 packet_check_eom(); 279 packet_check_eom();
246 280
247 authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user)); 281 authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
282 authctxt->pw));
248 283
249 authctxt->postponed = 0; 284 authctxt->postponed = 0;
250 dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); 285 dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
@@ -279,7 +314,8 @@ input_gssapi_mic(int type, u_int32_t plen, void *ctxt)
279 gssbuf.length = buffer_len(&b); 314 gssbuf.length = buffer_len(&b);
280 315
281 if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic)))) 316 if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic))))
282 authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user)); 317 authenticated =
318 PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw));
283 else 319 else
284 logit("GSSAPI MIC check failed"); 320 logit("GSSAPI MIC check failed");
285 321
@@ -294,6 +330,12 @@ input_gssapi_mic(int type, u_int32_t plen, void *ctxt)
294 userauth_finish(authctxt, authenticated, "gssapi-with-mic"); 330 userauth_finish(authctxt, authenticated, "gssapi-with-mic");
295} 331}
296 332
333Authmethod method_gsskeyex = {
334 "gssapi-keyex",
335 userauth_gsskeyex,
336 &options.gss_authentication
337};
338
297Authmethod method_gssapi = { 339Authmethod method_gssapi = {
298 "gssapi-with-mic", 340 "gssapi-with-mic",
299 userauth_gssapi, 341 userauth_gssapi,
diff --git a/auth2.c b/auth2.c
index b66bef64c..4313e9f26 100644
--- a/auth2.c
+++ b/auth2.c
@@ -69,6 +69,7 @@ extern Authmethod method_passwd;
69extern Authmethod method_kbdint; 69extern Authmethod method_kbdint;
70extern Authmethod method_hostbased; 70extern Authmethod method_hostbased;
71#ifdef GSSAPI 71#ifdef GSSAPI
72extern Authmethod method_gsskeyex;
72extern Authmethod method_gssapi; 73extern Authmethod method_gssapi;
73#endif 74#endif
74#ifdef JPAKE 75#ifdef JPAKE
@@ -79,6 +80,7 @@ Authmethod *authmethods[] = {
79 &method_none, 80 &method_none,
80 &method_pubkey, 81 &method_pubkey,
81#ifdef GSSAPI 82#ifdef GSSAPI
83 &method_gsskeyex,
82 &method_gssapi, 84 &method_gssapi,
83#endif 85#endif
84#ifdef JPAKE 86#ifdef JPAKE
diff --git a/clientloop.c b/clientloop.c
index 1c1a77088..7bb63c73b 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -111,6 +111,10 @@
111#include "msg.h" 111#include "msg.h"
112#include "roaming.h" 112#include "roaming.h"
113 113
114#ifdef GSSAPI
115#include "ssh-gss.h"
116#endif
117
114/* import options */ 118/* import options */
115extern Options options; 119extern Options options;
116 120
@@ -1544,6 +1548,15 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
1544 /* Do channel operations unless rekeying in progress. */ 1548 /* Do channel operations unless rekeying in progress. */
1545 if (!rekeying) { 1549 if (!rekeying) {
1546 channel_after_select(readset, writeset); 1550 channel_after_select(readset, writeset);
1551
1552#ifdef GSSAPI
1553 if (options.gss_renewal_rekey &&
1554 ssh_gssapi_credentials_updated(GSS_C_NO_CONTEXT)) {
1555 debug("credentials updated - forcing rekey");
1556 need_rekeying = 1;
1557 }
1558#endif
1559
1547 if (need_rekeying || packet_need_rekeying()) { 1560 if (need_rekeying || packet_need_rekeying()) {
1548 debug("need rekeying"); 1561 debug("need rekeying");
1549 xxx_kex->done = 0; 1562 xxx_kex->done = 0;
diff --git a/config.h.in b/config.h.in
index 2834a473d..6c4f2272a 100644
--- a/config.h.in
+++ b/config.h.in
@@ -1471,6 +1471,9 @@
1471/* Use btmp to log bad logins */ 1471/* Use btmp to log bad logins */
1472#undef USE_BTMP 1472#undef USE_BTMP
1473 1473
1474/* platform uses an in-memory credentials cache */
1475#undef USE_CCAPI
1476
1474/* Use libedit for sftp */ 1477/* Use libedit for sftp */
1475#undef USE_LIBEDIT 1478#undef USE_LIBEDIT
1476 1479
@@ -1486,6 +1489,9 @@
1486/* Use PIPES instead of a socketpair() */ 1489/* Use PIPES instead of a socketpair() */
1487#undef USE_PIPES 1490#undef USE_PIPES
1488 1491
1492/* platform has the Security Authorization Session API */
1493#undef USE_SECURITY_SESSION_API
1494
1489/* Define if you have Solaris process contracts */ 1495/* Define if you have Solaris process contracts */
1490#undef USE_SOLARIS_PROCESS_CONTRACTS 1496#undef USE_SOLARIS_PROCESS_CONTRACTS
1491 1497
diff --git a/configure b/configure
index 4eeaa4e56..5e473371d 100755
--- a/configure
+++ b/configure
@@ -6608,6 +6608,63 @@ $as_echo "#define SSH_TUN_COMPAT_AF 1" >>confdefs.h
6608 6608
6609$as_echo "#define SSH_TUN_PREPEND_AF 1" >>confdefs.h 6609$as_echo "#define SSH_TUN_PREPEND_AF 1" >>confdefs.h
6610 6610
6611 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we have the Security Authorization Session API" >&5
6612$as_echo_n "checking if we have the Security Authorization Session API... " >&6; }
6613 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6614/* end confdefs.h. */
6615#include <Security/AuthSession.h>
6616int
6617main ()
6618{
6619SessionCreate(0, 0);
6620 ;
6621 return 0;
6622}
6623_ACEOF
6624if ac_fn_c_try_compile "$LINENO"; then :
6625 ac_cv_use_security_session_api="yes"
6626
6627$as_echo "#define USE_SECURITY_SESSION_API 1" >>confdefs.h
6628
6629 LIBS="$LIBS -framework Security"
6630 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6631$as_echo "yes" >&6; }
6632else
6633 ac_cv_use_security_session_api="no"
6634 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6635$as_echo "no" >&6; }
6636fi
6637rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
6638 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we have an in-memory credentials cache" >&5
6639$as_echo_n "checking if we have an in-memory credentials cache... " >&6; }
6640 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6641/* end confdefs.h. */
6642#include <Kerberos/Kerberos.h>
6643int
6644main ()
6645{
6646cc_context_t c;
6647 (void) cc_initialize (&c, 0, NULL, NULL);
6648 ;
6649 return 0;
6650}
6651_ACEOF
6652if ac_fn_c_try_compile "$LINENO"; then :
6653
6654$as_echo "#define USE_CCAPI 1" >>confdefs.h
6655
6656 LIBS="$LIBS -framework Security"
6657 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6658$as_echo "yes" >&6; }
6659 if test "x$ac_cv_use_security_session_api" = "xno"; then
6660 as_fn_error $? "*** Need a security framework to use the credentials cache API ***" "$LINENO" 5
6661 fi
6662else
6663 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6664$as_echo "no" >&6; }
6665
6666fi
6667rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
6611 6668
6612 ac_fn_c_check_decl "$LINENO" "AU_IPv4" "ac_cv_have_decl_AU_IPv4" "$ac_includes_default" 6669 ac_fn_c_check_decl "$LINENO" "AU_IPv4" "ac_cv_have_decl_AU_IPv4" "$ac_includes_default"
6613if test "x$ac_cv_have_decl_AU_IPv4" = xyes; then : 6670if test "x$ac_cv_have_decl_AU_IPv4" = xyes; then :
diff --git a/configure.ac b/configure.ac
index a704fc7ff..f3718537f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -545,6 +545,30 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
545 [Use tunnel device compatibility to OpenBSD]) 545 [Use tunnel device compatibility to OpenBSD])
546 AC_DEFINE([SSH_TUN_PREPEND_AF], [1], 546 AC_DEFINE([SSH_TUN_PREPEND_AF], [1],
547 [Prepend the address family to IP tunnel traffic]) 547 [Prepend the address family to IP tunnel traffic])
548 AC_MSG_CHECKING([if we have the Security Authorization Session API])
549 AC_TRY_COMPILE([#include <Security/AuthSession.h>],
550 [SessionCreate(0, 0);],
551 [ac_cv_use_security_session_api="yes"
552 AC_DEFINE([USE_SECURITY_SESSION_API], [1],
553 [platform has the Security Authorization Session API])
554 LIBS="$LIBS -framework Security"
555 AC_MSG_RESULT([yes])],
556 [ac_cv_use_security_session_api="no"
557 AC_MSG_RESULT([no])])
558 AC_MSG_CHECKING([if we have an in-memory credentials cache])
559 AC_TRY_COMPILE(
560 [#include <Kerberos/Kerberos.h>],
561 [cc_context_t c;
562 (void) cc_initialize (&c, 0, NULL, NULL);],
563 [AC_DEFINE([USE_CCAPI], [1],
564 [platform uses an in-memory credentials cache])
565 LIBS="$LIBS -framework Security"
566 AC_MSG_RESULT([yes])
567 if test "x$ac_cv_use_security_session_api" = "xno"; then
568 AC_MSG_ERROR([*** Need a security framework to use the credentials cache API ***])
569 fi],
570 [AC_MSG_RESULT([no])]
571 )
548 m4_pattern_allow([AU_IPv]) 572 m4_pattern_allow([AU_IPv])
549 AC_CHECK_DECL([AU_IPv4], [], 573 AC_CHECK_DECL([AU_IPv4], [],
550 AC_DEFINE([AU_IPv4], [0], [System only supports IPv4 audit records]) 574 AC_DEFINE([AU_IPv4], [0], [System only supports IPv4 audit records])
diff --git a/gss-genr.c b/gss-genr.c
index 842f38582..f9b39cfd5 100644
--- a/gss-genr.c
+++ b/gss-genr.c
@@ -1,7 +1,7 @@
1/* $OpenBSD: gss-genr.c,v 1.20 2009/06/22 05:39:28 dtucker Exp $ */ 1/* $OpenBSD: gss-genr.c,v 1.20 2009/06/22 05:39:28 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. 4 * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
@@ -39,12 +39,167 @@
39#include "buffer.h" 39#include "buffer.h"
40#include "log.h" 40#include "log.h"
41#include "ssh2.h" 41#include "ssh2.h"
42#include "cipher.h"
43#include "key.h"
44#include "kex.h"
45#include <openssl/evp.h>
42 46
43#include "ssh-gss.h" 47#include "ssh-gss.h"
44 48
45extern u_char *session_id2; 49extern u_char *session_id2;
46extern u_int session_id2_len; 50extern u_int session_id2_len;
47 51
52typedef struct {
53 char *encoded;
54 gss_OID oid;
55} ssh_gss_kex_mapping;
56
57/*
58 * XXX - It would be nice to find a more elegant way of handling the
59 * XXX passing of the key exchange context to the userauth routines
60 */
61
62Gssctxt *gss_kex_context = NULL;
63
64static ssh_gss_kex_mapping *gss_enc2oid = NULL;
65
66int
67ssh_gssapi_oid_table_ok() {
68 return (gss_enc2oid != NULL);
69}
70
71/*
72 * Return a list of the gss-group1-sha1 mechanisms supported by this program
73 *
74 * We test mechanisms to ensure that we can use them, to avoid starting
75 * a key exchange with a bad mechanism
76 */
77
78char *
79ssh_gssapi_client_mechanisms(const char *host, const char *client) {
80 gss_OID_set gss_supported;
81 OM_uint32 min_status;
82
83 if (GSS_ERROR(gss_indicate_mechs(&min_status, &gss_supported)))
84 return NULL;
85
86 return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism,
87 host, client));
88}
89
90char *
91ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
92 const char *host, const char *client) {
93 Buffer buf;
94 size_t i;
95 int oidpos, enclen;
96 char *mechs, *encoded;
97 u_char digest[EVP_MAX_MD_SIZE];
98 char deroid[2];
99 const EVP_MD *evp_md = EVP_md5();
100 EVP_MD_CTX md;
101
102 if (gss_enc2oid != NULL) {
103 for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
104 xfree(gss_enc2oid[i].encoded);
105 xfree(gss_enc2oid);
106 }
107
108 gss_enc2oid = xmalloc(sizeof(ssh_gss_kex_mapping) *
109 (gss_supported->count + 1));
110
111 buffer_init(&buf);
112
113 oidpos = 0;
114 for (i = 0; i < gss_supported->count; i++) {
115 if (gss_supported->elements[i].length < 128 &&
116 (*check)(NULL, &(gss_supported->elements[i]), host, client)) {
117
118 deroid[0] = SSH_GSS_OIDTYPE;
119 deroid[1] = gss_supported->elements[i].length;
120
121 EVP_DigestInit(&md, evp_md);
122 EVP_DigestUpdate(&md, deroid, 2);
123 EVP_DigestUpdate(&md,
124 gss_supported->elements[i].elements,
125 gss_supported->elements[i].length);
126 EVP_DigestFinal(&md, digest, NULL);
127
128 encoded = xmalloc(EVP_MD_size(evp_md) * 2);
129 enclen = __b64_ntop(digest, EVP_MD_size(evp_md),
130 encoded, EVP_MD_size(evp_md) * 2);
131
132 if (oidpos != 0)
133 buffer_put_char(&buf, ',');
134
135 buffer_append(&buf, KEX_GSS_GEX_SHA1_ID,
136 sizeof(KEX_GSS_GEX_SHA1_ID) - 1);
137 buffer_append(&buf, encoded, enclen);
138 buffer_put_char(&buf, ',');
139 buffer_append(&buf, KEX_GSS_GRP1_SHA1_ID,
140 sizeof(KEX_GSS_GRP1_SHA1_ID) - 1);
141 buffer_append(&buf, encoded, enclen);
142 buffer_put_char(&buf, ',');
143 buffer_append(&buf, KEX_GSS_GRP14_SHA1_ID,
144 sizeof(KEX_GSS_GRP14_SHA1_ID) - 1);
145 buffer_append(&buf, encoded, enclen);
146
147 gss_enc2oid[oidpos].oid = &(gss_supported->elements[i]);
148 gss_enc2oid[oidpos].encoded = encoded;
149 oidpos++;
150 }
151 }
152 gss_enc2oid[oidpos].oid = NULL;
153 gss_enc2oid[oidpos].encoded = NULL;
154
155 buffer_put_char(&buf, '\0');
156
157 mechs = xmalloc(buffer_len(&buf));
158 buffer_get(&buf, mechs, buffer_len(&buf));
159 buffer_free(&buf);
160
161 if (strlen(mechs) == 0) {
162 xfree(mechs);
163 mechs = NULL;
164 }
165
166 return (mechs);
167}
168
169gss_OID
170ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
171 int i = 0;
172
173 switch (kex_type) {
174 case KEX_GSS_GRP1_SHA1:
175 if (strlen(name) < sizeof(KEX_GSS_GRP1_SHA1_ID))
176 return GSS_C_NO_OID;
177 name += sizeof(KEX_GSS_GRP1_SHA1_ID) - 1;
178 break;
179 case KEX_GSS_GRP14_SHA1:
180 if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA1_ID))
181 return GSS_C_NO_OID;
182 name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1;
183 break;
184 case KEX_GSS_GEX_SHA1:
185 if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID))
186 return GSS_C_NO_OID;
187 name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1;
188 break;
189 default:
190 return GSS_C_NO_OID;
191 }
192
193 while (gss_enc2oid[i].encoded != NULL &&
194 strcmp(name, gss_enc2oid[i].encoded) != 0)
195 i++;
196
197 if (gss_enc2oid[i].oid != NULL && ctx != NULL)
198 ssh_gssapi_set_oid(ctx, gss_enc2oid[i].oid);
199
200 return gss_enc2oid[i].oid;
201}
202
48/* Check that the OID in a data stream matches that in the context */ 203/* Check that the OID in a data stream matches that in the context */
49int 204int
50ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len) 205ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len)
@@ -197,7 +352,7 @@ ssh_gssapi_init_ctx(Gssctxt *ctx, int deleg_creds, gss_buffer_desc *recv_tok,
197 } 352 }
198 353
199 ctx->major = gss_init_sec_context(&ctx->minor, 354 ctx->major = gss_init_sec_context(&ctx->minor,
200 GSS_C_NO_CREDENTIAL, &ctx->context, ctx->name, ctx->oid, 355 ctx->client_creds, &ctx->context, ctx->name, ctx->oid,
201 GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag, 356 GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag,
202 0, NULL, recv_tok, NULL, send_tok, flags, NULL); 357 0, NULL, recv_tok, NULL, send_tok, flags, NULL);
203 358
@@ -227,8 +382,42 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host)
227} 382}
228 383
229OM_uint32 384OM_uint32
385ssh_gssapi_client_identity(Gssctxt *ctx, const char *name)
386{
387 gss_buffer_desc gssbuf;
388 gss_name_t gssname;
389 OM_uint32 status;
390 gss_OID_set oidset;
391
392 gssbuf.value = (void *) name;
393 gssbuf.length = strlen(gssbuf.value);
394
395 gss_create_empty_oid_set(&status, &oidset);
396 gss_add_oid_set_member(&status, ctx->oid, &oidset);
397
398 ctx->major = gss_import_name(&ctx->minor, &gssbuf,
399 GSS_C_NT_USER_NAME, &gssname);
400
401 if (!ctx->major)
402 ctx->major = gss_acquire_cred(&ctx->minor,
403 gssname, 0, oidset, GSS_C_INITIATE,
404 &ctx->client_creds, NULL, NULL);
405
406 gss_release_name(&status, &gssname);
407 gss_release_oid_set(&status, &oidset);
408
409 if (ctx->major)
410 ssh_gssapi_error(ctx);
411
412 return(ctx->major);
413}
414
415OM_uint32
230ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash) 416ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
231{ 417{
418 if (ctx == NULL)
419 return -1;
420
232 if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context, 421 if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context,
233 GSS_C_QOP_DEFAULT, buffer, hash))) 422 GSS_C_QOP_DEFAULT, buffer, hash)))
234 ssh_gssapi_error(ctx); 423 ssh_gssapi_error(ctx);
@@ -236,6 +425,19 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
236 return (ctx->major); 425 return (ctx->major);
237} 426}
238 427
428/* Priviledged when used by server */
429OM_uint32
430ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
431{
432 if (ctx == NULL)
433 return -1;
434
435 ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
436 gssbuf, gssmic, NULL);
437
438 return (ctx->major);
439}
440
239void 441void
240ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service, 442ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service,
241 const char *context) 443 const char *context)
@@ -249,11 +451,16 @@ ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service,
249} 451}
250 452
251int 453int
252ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host) 454ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host,
455 const char *client)
253{ 456{
254 gss_buffer_desc token = GSS_C_EMPTY_BUFFER; 457 gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
255 OM_uint32 major, minor; 458 OM_uint32 major, minor;
256 gss_OID_desc spnego_oid = {6, (void *)"\x2B\x06\x01\x05\x05\x02"}; 459 gss_OID_desc spnego_oid = {6, (void *)"\x2B\x06\x01\x05\x05\x02"};
460 Gssctxt *intctx = NULL;
461
462 if (ctx == NULL)
463 ctx = &intctx;
257 464
258 /* RFC 4462 says we MUST NOT do SPNEGO */ 465 /* RFC 4462 says we MUST NOT do SPNEGO */
259 if (oid->length == spnego_oid.length && 466 if (oid->length == spnego_oid.length &&
@@ -263,6 +470,10 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
263 ssh_gssapi_build_ctx(ctx); 470 ssh_gssapi_build_ctx(ctx);
264 ssh_gssapi_set_oid(*ctx, oid); 471 ssh_gssapi_set_oid(*ctx, oid);
265 major = ssh_gssapi_import_name(*ctx, host); 472 major = ssh_gssapi_import_name(*ctx, host);
473
474 if (!GSS_ERROR(major) && client)
475 major = ssh_gssapi_client_identity(*ctx, client);
476
266 if (!GSS_ERROR(major)) { 477 if (!GSS_ERROR(major)) {
267 major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token, 478 major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token,
268 NULL); 479 NULL);
@@ -272,10 +483,67 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
272 GSS_C_NO_BUFFER); 483 GSS_C_NO_BUFFER);
273 } 484 }
274 485
275 if (GSS_ERROR(major)) 486 if (GSS_ERROR(major) || intctx != NULL)
276 ssh_gssapi_delete_ctx(ctx); 487 ssh_gssapi_delete_ctx(ctx);
277 488
278 return (!GSS_ERROR(major)); 489 return (!GSS_ERROR(major));
279} 490}
280 491
492int
493ssh_gssapi_credentials_updated(Gssctxt *ctxt) {
494 static gss_name_t saved_name = GSS_C_NO_NAME;
495 static OM_uint32 saved_lifetime = 0;
496 static gss_OID saved_mech = GSS_C_NO_OID;
497 static gss_name_t name;
498 static OM_uint32 last_call = 0;
499 OM_uint32 lifetime, now, major, minor;
500 int equal;
501 gss_cred_usage_t usage = GSS_C_INITIATE;
502
503 now = time(NULL);
504
505 if (ctxt) {
506 debug("Rekey has happened - updating saved versions");
507
508 if (saved_name != GSS_C_NO_NAME)
509 gss_release_name(&minor, &saved_name);
510
511 major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
512 &saved_name, &saved_lifetime, NULL, NULL);
513
514 if (!GSS_ERROR(major)) {
515 saved_mech = ctxt->oid;
516 saved_lifetime+= now;
517 } else {
518 /* Handle the error */
519 }
520 return 0;
521 }
522
523 if (now - last_call < 10)
524 return 0;
525
526 last_call = now;
527
528 if (saved_mech == GSS_C_NO_OID)
529 return 0;
530
531 major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
532 &name, &lifetime, NULL, NULL);
533 if (major == GSS_S_CREDENTIALS_EXPIRED)
534 return 0;
535 else if (GSS_ERROR(major))
536 return 0;
537
538 major = gss_compare_name(&minor, saved_name, name, &equal);
539 gss_release_name(&minor, &name);
540 if (GSS_ERROR(major))
541 return 0;
542
543 if (equal && (saved_lifetime < lifetime + now - 10))
544 return 1;
545
546 return 0;
547}
548
281#endif /* GSSAPI */ 549#endif /* GSSAPI */
diff --git a/gss-serv-krb5.c b/gss-serv-krb5.c
index 5a625acb8..e7170ee41 100644
--- a/gss-serv-krb5.c
+++ b/gss-serv-krb5.c
@@ -1,7 +1,7 @@
1/* $OpenBSD: gss-serv-krb5.c,v 1.7 2006/08/03 03:34:42 deraadt Exp $ */ 1/* $OpenBSD: gss-serv-krb5.c,v 1.7 2006/08/03 03:34:42 deraadt Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. 4 * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
@@ -120,6 +120,7 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
120 krb5_principal princ; 120 krb5_principal princ;
121 OM_uint32 maj_status, min_status; 121 OM_uint32 maj_status, min_status;
122 int len; 122 int len;
123 const char *new_ccname;
123 124
124 if (client->creds == NULL) { 125 if (client->creds == NULL) {
125 debug("No credentials stored"); 126 debug("No credentials stored");
@@ -168,11 +169,16 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
168 return; 169 return;
169 } 170 }
170 171
171 client->store.filename = xstrdup(krb5_cc_get_name(krb_context, ccache)); 172 new_ccname = krb5_cc_get_name(krb_context, ccache);
173
172 client->store.envvar = "KRB5CCNAME"; 174 client->store.envvar = "KRB5CCNAME";
173 len = strlen(client->store.filename) + 6; 175#ifdef USE_CCAPI
174 client->store.envval = xmalloc(len); 176 xasprintf(&client->store.envval, "API:%s", new_ccname);
175 snprintf(client->store.envval, len, "FILE:%s", client->store.filename); 177 client->store.filename = NULL;
178#else
179 xasprintf(&client->store.envval, "FILE:%s", new_ccname);
180 client->store.filename = xstrdup(new_ccname);
181#endif
176 182
177#ifdef USE_PAM 183#ifdef USE_PAM
178 if (options.use_pam) 184 if (options.use_pam)
@@ -184,6 +190,71 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
184 return; 190 return;
185} 191}
186 192
193int
194ssh_gssapi_krb5_updatecreds(ssh_gssapi_ccache *store,
195 ssh_gssapi_client *client)
196{
197 krb5_ccache ccache = NULL;
198 krb5_principal principal = NULL;
199 char *name = NULL;
200 krb5_error_code problem;
201 OM_uint32 maj_status, min_status;
202
203 if ((problem = krb5_cc_resolve(krb_context, store->envval, &ccache))) {
204 logit("krb5_cc_resolve(): %.100s",
205 krb5_get_err_text(krb_context, problem));
206 return 0;
207 }
208
209 /* Find out who the principal in this cache is */
210 if ((problem = krb5_cc_get_principal(krb_context, ccache,
211 &principal))) {
212 logit("krb5_cc_get_principal(): %.100s",
213 krb5_get_err_text(krb_context, problem));
214 krb5_cc_close(krb_context, ccache);
215 return 0;
216 }
217
218 if ((problem = krb5_unparse_name(krb_context, principal, &name))) {
219 logit("krb5_unparse_name(): %.100s",
220 krb5_get_err_text(krb_context, problem));
221 krb5_free_principal(krb_context, principal);
222 krb5_cc_close(krb_context, ccache);
223 return 0;
224 }
225
226
227 if (strcmp(name,client->exportedname.value)!=0) {
228 debug("Name in local credentials cache differs. Not storing");
229 krb5_free_principal(krb_context, principal);
230 krb5_cc_close(krb_context, ccache);
231 krb5_free_unparsed_name(krb_context, name);
232 return 0;
233 }
234 krb5_free_unparsed_name(krb_context, name);
235
236 /* Name matches, so lets get on with it! */
237
238 if ((problem = krb5_cc_initialize(krb_context, ccache, principal))) {
239 logit("krb5_cc_initialize(): %.100s",
240 krb5_get_err_text(krb_context, problem));
241 krb5_free_principal(krb_context, principal);
242 krb5_cc_close(krb_context, ccache);
243 return 0;
244 }
245
246 krb5_free_principal(krb_context, principal);
247
248 if ((maj_status = gss_krb5_copy_ccache(&min_status, client->creds,
249 ccache))) {
250 logit("gss_krb5_copy_ccache() failed. Sorry!");
251 krb5_cc_close(krb_context, ccache);
252 return 0;
253 }
254
255 return 1;
256}
257
187ssh_gssapi_mech gssapi_kerberos_mech = { 258ssh_gssapi_mech gssapi_kerberos_mech = {
188 "toWM5Slw5Ew8Mqkay+al2g==", 259 "toWM5Slw5Ew8Mqkay+al2g==",
189 "Kerberos", 260 "Kerberos",
@@ -191,7 +262,8 @@ ssh_gssapi_mech gssapi_kerberos_mech = {
191 NULL, 262 NULL,
192 &ssh_gssapi_krb5_userok, 263 &ssh_gssapi_krb5_userok,
193 NULL, 264 NULL,
194 &ssh_gssapi_krb5_storecreds 265 &ssh_gssapi_krb5_storecreds,
266 &ssh_gssapi_krb5_updatecreds
195}; 267};
196 268
197#endif /* KRB5 */ 269#endif /* KRB5 */
diff --git a/gss-serv.c b/gss-serv.c
index c719c1306..380895ea5 100644
--- a/gss-serv.c
+++ b/gss-serv.c
@@ -1,7 +1,7 @@
1/* $OpenBSD: gss-serv.c,v 1.23 2011/08/01 19:18:15 markus Exp $ */ 1/* $OpenBSD: gss-serv.c,v 1.23 2011/08/01 19:18:15 markus Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. 4 * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
@@ -45,15 +45,20 @@
45#include "channels.h" 45#include "channels.h"
46#include "session.h" 46#include "session.h"
47#include "misc.h" 47#include "misc.h"
48#include "servconf.h"
49#include "uidswap.h"
48 50
49#include "ssh-gss.h" 51#include "ssh-gss.h"
52#include "monitor_wrap.h"
53
54extern ServerOptions options;
50 55
51static ssh_gssapi_client gssapi_client = 56static ssh_gssapi_client gssapi_client =
52 { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER, 57 { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER,
53 GSS_C_NO_CREDENTIAL, NULL, {NULL, NULL, NULL}}; 58 GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME, NULL, {NULL, NULL, NULL}, 0, 0};
54 59
55ssh_gssapi_mech gssapi_null_mech = 60ssh_gssapi_mech gssapi_null_mech =
56 { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL}; 61 { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL, NULL};
57 62
58#ifdef KRB5 63#ifdef KRB5
59extern ssh_gssapi_mech gssapi_kerberos_mech; 64extern ssh_gssapi_mech gssapi_kerberos_mech;
@@ -81,25 +86,32 @@ ssh_gssapi_acquire_cred(Gssctxt *ctx)
81 char lname[MAXHOSTNAMELEN]; 86 char lname[MAXHOSTNAMELEN];
82 gss_OID_set oidset; 87 gss_OID_set oidset;
83 88
84 gss_create_empty_oid_set(&status, &oidset); 89 if (options.gss_strict_acceptor) {
85 gss_add_oid_set_member(&status, ctx->oid, &oidset); 90 gss_create_empty_oid_set(&status, &oidset);
91 gss_add_oid_set_member(&status, ctx->oid, &oidset);
86 92
87 if (gethostname(lname, MAXHOSTNAMELEN)) { 93 if (gethostname(lname, MAXHOSTNAMELEN)) {
88 gss_release_oid_set(&status, &oidset); 94 gss_release_oid_set(&status, &oidset);
89 return (-1); 95 return (-1);
90 } 96 }
97
98 if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
99 gss_release_oid_set(&status, &oidset);
100 return (ctx->major);
101 }
102
103 if ((ctx->major = gss_acquire_cred(&ctx->minor,
104 ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds,
105 NULL, NULL)))
106 ssh_gssapi_error(ctx);
91 107
92 if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
93 gss_release_oid_set(&status, &oidset); 108 gss_release_oid_set(&status, &oidset);
94 return (ctx->major); 109 return (ctx->major);
110 } else {
111 ctx->name = GSS_C_NO_NAME;
112 ctx->creds = GSS_C_NO_CREDENTIAL;
95 } 113 }
96 114 return GSS_S_COMPLETE;
97 if ((ctx->major = gss_acquire_cred(&ctx->minor,
98 ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds, NULL, NULL)))
99 ssh_gssapi_error(ctx);
100
101 gss_release_oid_set(&status, &oidset);
102 return (ctx->major);
103} 115}
104 116
105/* Privileged */ 117/* Privileged */
@@ -114,6 +126,29 @@ ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID oid)
114} 126}
115 127
116/* Unprivileged */ 128/* Unprivileged */
129char *
130ssh_gssapi_server_mechanisms() {
131 gss_OID_set supported;
132
133 ssh_gssapi_supported_oids(&supported);
134 return (ssh_gssapi_kex_mechs(supported, &ssh_gssapi_server_check_mech,
135 NULL, NULL));
136}
137
138/* Unprivileged */
139int
140ssh_gssapi_server_check_mech(Gssctxt **dum, gss_OID oid, const char *data,
141 const char *dummy) {
142 Gssctxt *ctx = NULL;
143 int res;
144
145 res = !GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctx, oid)));
146 ssh_gssapi_delete_ctx(&ctx);
147
148 return (res);
149}
150
151/* Unprivileged */
117void 152void
118ssh_gssapi_supported_oids(gss_OID_set *oidset) 153ssh_gssapi_supported_oids(gss_OID_set *oidset)
119{ 154{
@@ -123,7 +158,9 @@ ssh_gssapi_supported_oids(gss_OID_set *oidset)
123 gss_OID_set supported; 158 gss_OID_set supported;
124 159
125 gss_create_empty_oid_set(&min_status, oidset); 160 gss_create_empty_oid_set(&min_status, oidset);
126 gss_indicate_mechs(&min_status, &supported); 161
162 if (GSS_ERROR(gss_indicate_mechs(&min_status, &supported)))
163 return;
127 164
128 while (supported_mechs[i]->name != NULL) { 165 while (supported_mechs[i]->name != NULL) {
129 if (GSS_ERROR(gss_test_oid_set_member(&min_status, 166 if (GSS_ERROR(gss_test_oid_set_member(&min_status,
@@ -249,8 +286,48 @@ OM_uint32
249ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client) 286ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
250{ 287{
251 int i = 0; 288 int i = 0;
289 int equal = 0;
290 gss_name_t new_name = GSS_C_NO_NAME;
291 gss_buffer_desc ename = GSS_C_EMPTY_BUFFER;
292
293 if (options.gss_store_rekey && client->used && ctx->client_creds) {
294 if (client->mech->oid.length != ctx->oid->length ||
295 (memcmp(client->mech->oid.elements,
296 ctx->oid->elements, ctx->oid->length) !=0)) {
297 debug("Rekeyed credentials have different mechanism");
298 return GSS_S_COMPLETE;
299 }
300
301 if ((ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
302 ctx->client_creds, ctx->oid, &new_name,
303 NULL, NULL, NULL))) {
304 ssh_gssapi_error(ctx);
305 return (ctx->major);
306 }
307
308 ctx->major = gss_compare_name(&ctx->minor, client->name,
309 new_name, &equal);
252 310
253 gss_buffer_desc ename; 311 if (GSS_ERROR(ctx->major)) {
312 ssh_gssapi_error(ctx);
313 return (ctx->major);
314 }
315
316 if (!equal) {
317 debug("Rekeyed credentials have different name");
318 return GSS_S_COMPLETE;
319 }
320
321 debug("Marking rekeyed credentials for export");
322
323 gss_release_name(&ctx->minor, &client->name);
324 gss_release_cred(&ctx->minor, &client->creds);
325 client->name = new_name;
326 client->creds = ctx->client_creds;
327 ctx->client_creds = GSS_C_NO_CREDENTIAL;
328 client->updated = 1;
329 return GSS_S_COMPLETE;
330 }
254 331
255 client->mech = NULL; 332 client->mech = NULL;
256 333
@@ -265,6 +342,13 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
265 if (client->mech == NULL) 342 if (client->mech == NULL)
266 return GSS_S_FAILURE; 343 return GSS_S_FAILURE;
267 344
345 if (ctx->client_creds &&
346 (ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
347 ctx->client_creds, ctx->oid, &client->name, NULL, NULL, NULL))) {
348 ssh_gssapi_error(ctx);
349 return (ctx->major);
350 }
351
268 if ((ctx->major = gss_display_name(&ctx->minor, ctx->client, 352 if ((ctx->major = gss_display_name(&ctx->minor, ctx->client,
269 &client->displayname, NULL))) { 353 &client->displayname, NULL))) {
270 ssh_gssapi_error(ctx); 354 ssh_gssapi_error(ctx);
@@ -282,6 +366,8 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
282 return (ctx->major); 366 return (ctx->major);
283 } 367 }
284 368
369 gss_release_buffer(&ctx->minor, &ename);
370
285 /* We can't copy this structure, so we just move the pointer to it */ 371 /* We can't copy this structure, so we just move the pointer to it */
286 client->creds = ctx->client_creds; 372 client->creds = ctx->client_creds;
287 ctx->client_creds = GSS_C_NO_CREDENTIAL; 373 ctx->client_creds = GSS_C_NO_CREDENTIAL;
@@ -329,7 +415,7 @@ ssh_gssapi_do_child(char ***envp, u_int *envsizep)
329 415
330/* Privileged */ 416/* Privileged */
331int 417int
332ssh_gssapi_userok(char *user) 418ssh_gssapi_userok(char *user, struct passwd *pw)
333{ 419{
334 OM_uint32 lmin; 420 OM_uint32 lmin;
335 421
@@ -339,9 +425,11 @@ ssh_gssapi_userok(char *user)
339 return 0; 425 return 0;
340 } 426 }
341 if (gssapi_client.mech && gssapi_client.mech->userok) 427 if (gssapi_client.mech && gssapi_client.mech->userok)
342 if ((*gssapi_client.mech->userok)(&gssapi_client, user)) 428 if ((*gssapi_client.mech->userok)(&gssapi_client, user)) {
429 gssapi_client.used = 1;
430 gssapi_client.store.owner = pw;
343 return 1; 431 return 1;
344 else { 432 } else {
345 /* Destroy delegated credentials if userok fails */ 433 /* Destroy delegated credentials if userok fails */
346 gss_release_buffer(&lmin, &gssapi_client.displayname); 434 gss_release_buffer(&lmin, &gssapi_client.displayname);
347 gss_release_buffer(&lmin, &gssapi_client.exportedname); 435 gss_release_buffer(&lmin, &gssapi_client.exportedname);
@@ -354,14 +442,90 @@ ssh_gssapi_userok(char *user)
354 return (0); 442 return (0);
355} 443}
356 444
357/* Privileged */ 445/* These bits are only used for rekeying. The unpriviledged child is running
358OM_uint32 446 * as the user, the monitor is root.
359ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic) 447 *
448 * In the child, we want to :
449 * *) Ask the monitor to store our credentials into the store we specify
450 * *) If it succeeds, maybe do a PAM update
451 */
452
453/* Stuff for PAM */
454
455#ifdef USE_PAM
456static int ssh_gssapi_simple_conv(int n, const struct pam_message **msg,
457 struct pam_response **resp, void *data)
360{ 458{
361 ctx->major = gss_verify_mic(&ctx->minor, ctx->context, 459 return (PAM_CONV_ERR);
362 gssbuf, gssmic, NULL); 460}
461#endif
363 462
364 return (ctx->major); 463void
464ssh_gssapi_rekey_creds() {
465 int ok;
466 int ret;
467#ifdef USE_PAM
468 pam_handle_t *pamh = NULL;
469 struct pam_conv pamconv = {ssh_gssapi_simple_conv, NULL};
470 char *envstr;
471#endif
472
473 if (gssapi_client.store.filename == NULL &&
474 gssapi_client.store.envval == NULL &&
475 gssapi_client.store.envvar == NULL)
476 return;
477
478 ok = PRIVSEP(ssh_gssapi_update_creds(&gssapi_client.store));
479
480 if (!ok)
481 return;
482
483 debug("Rekeyed credentials stored successfully");
484
485 /* Actually managing to play with the ssh pam stack from here will
486 * be next to impossible. In any case, we may want different options
487 * for rekeying. So, use our own :)
488 */
489#ifdef USE_PAM
490 if (!use_privsep) {
491 debug("Not even going to try and do PAM with privsep disabled");
492 return;
493 }
494
495 ret = pam_start("sshd-rekey", gssapi_client.store.owner->pw_name,
496 &pamconv, &pamh);
497 if (ret)
498 return;
499
500 xasprintf(&envstr, "%s=%s", gssapi_client.store.envvar,
501 gssapi_client.store.envval);
502
503 ret = pam_putenv(pamh, envstr);
504 if (!ret)
505 pam_setcred(pamh, PAM_REINITIALIZE_CRED);
506 pam_end(pamh, PAM_SUCCESS);
507#endif
508}
509
510int
511ssh_gssapi_update_creds(ssh_gssapi_ccache *store) {
512 int ok = 0;
513
514 /* Check we've got credentials to store */
515 if (!gssapi_client.updated)
516 return 0;
517
518 gssapi_client.updated = 0;
519
520 temporarily_use_uid(gssapi_client.store.owner);
521 if (gssapi_client.mech && gssapi_client.mech->updatecreds)
522 ok = (*gssapi_client.mech->updatecreds)(store, &gssapi_client);
523 else
524 debug("No update function for this mechanism");
525
526 restore_uid();
527
528 return ok;
365} 529}
366 530
367#endif 531#endif
diff --git a/kex.c b/kex.c
index c65e28f94..58349fc19 100644
--- a/kex.c
+++ b/kex.c
@@ -50,6 +50,10 @@
50#include "monitor.h" 50#include "monitor.h"
51#include "roaming.h" 51#include "roaming.h"
52 52
53#ifdef GSSAPI
54#include "ssh-gss.h"
55#endif
56
53#if OPENSSL_VERSION_NUMBER >= 0x00907000L 57#if OPENSSL_VERSION_NUMBER >= 0x00907000L
54# if defined(HAVE_EVP_SHA256) 58# if defined(HAVE_EVP_SHA256)
55# define evp_ssh_sha256 EVP_sha256 59# define evp_ssh_sha256 EVP_sha256
@@ -358,6 +362,20 @@ choose_kex(Kex *k, char *client, char *server)
358 k->kex_type = KEX_ECDH_SHA2; 362 k->kex_type = KEX_ECDH_SHA2;
359 k->evp_md = kex_ecdh_name_to_evpmd(k->name); 363 k->evp_md = kex_ecdh_name_to_evpmd(k->name);
360#endif 364#endif
365#ifdef GSSAPI
366 } else if (strncmp(k->name, KEX_GSS_GEX_SHA1_ID,
367 sizeof(KEX_GSS_GEX_SHA1_ID) - 1) == 0) {
368 k->kex_type = KEX_GSS_GEX_SHA1;
369 k->evp_md = EVP_sha1();
370 } else if (strncmp(k->name, KEX_GSS_GRP1_SHA1_ID,
371 sizeof(KEX_GSS_GRP1_SHA1_ID) - 1) == 0) {
372 k->kex_type = KEX_GSS_GRP1_SHA1;
373 k->evp_md = EVP_sha1();
374 } else if (strncmp(k->name, KEX_GSS_GRP14_SHA1_ID,
375 sizeof(KEX_GSS_GRP14_SHA1_ID) - 1) == 0) {
376 k->kex_type = KEX_GSS_GRP14_SHA1;
377 k->evp_md = EVP_sha1();
378#endif
361 } else 379 } else
362 fatal("bad kex alg %s", k->name); 380 fatal("bad kex alg %s", k->name);
363} 381}
diff --git a/kex.h b/kex.h
index 7373d3c78..fa50b2ccb 100644
--- a/kex.h
+++ b/kex.h
@@ -73,6 +73,9 @@ enum kex_exchange {
73 KEX_DH_GEX_SHA1, 73 KEX_DH_GEX_SHA1,
74 KEX_DH_GEX_SHA256, 74 KEX_DH_GEX_SHA256,
75 KEX_ECDH_SHA2, 75 KEX_ECDH_SHA2,
76 KEX_GSS_GRP1_SHA1,
77 KEX_GSS_GRP14_SHA1,
78 KEX_GSS_GEX_SHA1,
76 KEX_MAX 79 KEX_MAX
77}; 80};
78 81
@@ -129,6 +132,12 @@ struct Kex {
129 sig_atomic_t done; 132 sig_atomic_t done;
130 int flags; 133 int flags;
131 const EVP_MD *evp_md; 134 const EVP_MD *evp_md;
135#ifdef GSSAPI
136 int gss_deleg_creds;
137 int gss_trust_dns;
138 char *gss_host;
139 char *gss_client;
140#endif
132 char *client_version_string; 141 char *client_version_string;
133 char *server_version_string; 142 char *server_version_string;
134 int (*verify_host_key)(Key *); 143 int (*verify_host_key)(Key *);
@@ -156,6 +165,11 @@ void kexgex_server(Kex *);
156void kexecdh_client(Kex *); 165void kexecdh_client(Kex *);
157void kexecdh_server(Kex *); 166void kexecdh_server(Kex *);
158 167
168#ifdef GSSAPI
169void kexgss_client(Kex *);
170void kexgss_server(Kex *);
171#endif
172
159void 173void
160kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int, 174kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
161 BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *); 175 BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *);
diff --git a/kexgssc.c b/kexgssc.c
new file mode 100644
index 000000000..39be40531
--- /dev/null
+++ b/kexgssc.c
@@ -0,0 +1,334 @@
1/*
2 * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
26
27#ifdef GSSAPI
28
29#include "includes.h"
30
31#include <openssl/crypto.h>
32#include <openssl/bn.h>
33
34#include <string.h>
35
36#include "xmalloc.h"
37#include "buffer.h"
38#include "ssh2.h"
39#include "key.h"
40#include "cipher.h"
41#include "kex.h"
42#include "log.h"
43#include "packet.h"
44#include "dh.h"
45
46#include "ssh-gss.h"
47
48void
49kexgss_client(Kex *kex) {
50 gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
51 gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
52 Gssctxt *ctxt;
53 OM_uint32 maj_status, min_status, ret_flags;
54 u_int klen, kout, slen = 0, hashlen, strlen;
55 DH *dh;
56 BIGNUM *dh_server_pub = NULL;
57 BIGNUM *shared_secret = NULL;
58 BIGNUM *p = NULL;
59 BIGNUM *g = NULL;
60 u_char *kbuf, *hash;
61 u_char *serverhostkey = NULL;
62 u_char *empty = "";
63 char *msg;
64 char *lang;
65 int type = 0;
66 int first = 1;
67 int nbits = 0, min = DH_GRP_MIN, max = DH_GRP_MAX;
68
69 /* Initialise our GSSAPI world */
70 ssh_gssapi_build_ctx(&ctxt);
71 if (ssh_gssapi_id_kex(ctxt, kex->name, kex->kex_type)
72 == GSS_C_NO_OID)
73 fatal("Couldn't identify host exchange");
74
75 if (ssh_gssapi_import_name(ctxt, kex->gss_host))
76 fatal("Couldn't import hostname");
77
78 if (kex->gss_client &&
79 ssh_gssapi_client_identity(ctxt, kex->gss_client))
80 fatal("Couldn't acquire client credentials");
81
82 switch (kex->kex_type) {
83 case KEX_GSS_GRP1_SHA1:
84 dh = dh_new_group1();
85 break;
86 case KEX_GSS_GRP14_SHA1:
87 dh = dh_new_group14();
88 break;
89 case KEX_GSS_GEX_SHA1:
90 debug("Doing group exchange\n");
91 nbits = dh_estimate(kex->we_need * 8);
92 packet_start(SSH2_MSG_KEXGSS_GROUPREQ);
93 packet_put_int(min);
94 packet_put_int(nbits);
95 packet_put_int(max);
96
97 packet_send();
98
99 packet_read_expect(SSH2_MSG_KEXGSS_GROUP);
100
101 if ((p = BN_new()) == NULL)
102 fatal("BN_new() failed");
103 packet_get_bignum2(p);
104 if ((g = BN_new()) == NULL)
105 fatal("BN_new() failed");
106 packet_get_bignum2(g);
107 packet_check_eom();
108
109 if (BN_num_bits(p) < min || BN_num_bits(p) > max)
110 fatal("GSSGRP_GEX group out of range: %d !< %d !< %d",
111 min, BN_num_bits(p), max);
112
113 dh = dh_new_group(g, p);
114 break;
115 default:
116 fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
117 }
118
119 /* Step 1 - e is dh->pub_key */
120 dh_gen_key(dh, kex->we_need * 8);
121
122 /* This is f, we initialise it now to make life easier */
123 dh_server_pub = BN_new();
124 if (dh_server_pub == NULL)
125 fatal("dh_server_pub == NULL");
126
127 token_ptr = GSS_C_NO_BUFFER;
128
129 do {
130 debug("Calling gss_init_sec_context");
131
132 maj_status = ssh_gssapi_init_ctx(ctxt,
133 kex->gss_deleg_creds, token_ptr, &send_tok,
134 &ret_flags);
135
136 if (GSS_ERROR(maj_status)) {
137 if (send_tok.length != 0) {
138 packet_start(SSH2_MSG_KEXGSS_CONTINUE);
139 packet_put_string(send_tok.value,
140 send_tok.length);
141 }
142 fatal("gss_init_context failed");
143 }
144
145 /* If we've got an old receive buffer get rid of it */
146 if (token_ptr != GSS_C_NO_BUFFER)
147 xfree(recv_tok.value);
148
149 if (maj_status == GSS_S_COMPLETE) {
150 /* If mutual state flag is not true, kex fails */
151 if (!(ret_flags & GSS_C_MUTUAL_FLAG))
152 fatal("Mutual authentication failed");
153
154 /* If integ avail flag is not true kex fails */
155 if (!(ret_flags & GSS_C_INTEG_FLAG))
156 fatal("Integrity check failed");
157 }
158
159 /*
160 * If we have data to send, then the last message that we
161 * received cannot have been a 'complete'.
162 */
163 if (send_tok.length != 0) {
164 if (first) {
165 packet_start(SSH2_MSG_KEXGSS_INIT);
166 packet_put_string(send_tok.value,
167 send_tok.length);
168 packet_put_bignum2(dh->pub_key);
169 first = 0;
170 } else {
171 packet_start(SSH2_MSG_KEXGSS_CONTINUE);
172 packet_put_string(send_tok.value,
173 send_tok.length);
174 }
175 packet_send();
176 gss_release_buffer(&min_status, &send_tok);
177
178 /* If we've sent them data, they should reply */
179 do {
180 type = packet_read();
181 if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
182 debug("Received KEXGSS_HOSTKEY");
183 if (serverhostkey)
184 fatal("Server host key received more than once");
185 serverhostkey =
186 packet_get_string(&slen);
187 }
188 } while (type == SSH2_MSG_KEXGSS_HOSTKEY);
189
190 switch (type) {
191 case SSH2_MSG_KEXGSS_CONTINUE:
192 debug("Received GSSAPI_CONTINUE");
193 if (maj_status == GSS_S_COMPLETE)
194 fatal("GSSAPI Continue received from server when complete");
195 recv_tok.value = packet_get_string(&strlen);
196 recv_tok.length = strlen;
197 break;
198 case SSH2_MSG_KEXGSS_COMPLETE:
199 debug("Received GSSAPI_COMPLETE");
200 packet_get_bignum2(dh_server_pub);
201 msg_tok.value = packet_get_string(&strlen);
202 msg_tok.length = strlen;
203
204 /* Is there a token included? */
205 if (packet_get_char()) {
206 recv_tok.value=
207 packet_get_string(&strlen);
208 recv_tok.length = strlen;
209 /* If we're already complete - protocol error */
210 if (maj_status == GSS_S_COMPLETE)
211 packet_disconnect("Protocol error: received token when complete");
212 } else {
213 /* No token included */
214 if (maj_status != GSS_S_COMPLETE)
215 packet_disconnect("Protocol error: did not receive final token");
216 }
217 break;
218 case SSH2_MSG_KEXGSS_ERROR:
219 debug("Received Error");
220 maj_status = packet_get_int();
221 min_status = packet_get_int();
222 msg = packet_get_string(NULL);
223 lang = packet_get_string(NULL);
224 fatal("GSSAPI Error: \n%.400s",msg);
225 default:
226 packet_disconnect("Protocol error: didn't expect packet type %d",
227 type);
228 }
229 token_ptr = &recv_tok;
230 } else {
231 /* No data, and not complete */
232 if (maj_status != GSS_S_COMPLETE)
233 fatal("Not complete, and no token output");
234 }
235 } while (maj_status & GSS_S_CONTINUE_NEEDED);
236
237 /*
238 * We _must_ have received a COMPLETE message in reply from the
239 * server, which will have set dh_server_pub and msg_tok
240 */
241
242 if (type != SSH2_MSG_KEXGSS_COMPLETE)
243 fatal("Didn't receive a SSH2_MSG_KEXGSS_COMPLETE when I expected it");
244
245 /* Check f in range [1, p-1] */
246 if (!dh_pub_is_valid(dh, dh_server_pub))
247 packet_disconnect("bad server public DH value");
248
249 /* compute K=f^x mod p */
250 klen = DH_size(dh);
251 kbuf = xmalloc(klen);
252 kout = DH_compute_key(kbuf, dh_server_pub, dh);
253 if (kout < 0)
254 fatal("DH_compute_key: failed");
255
256 shared_secret = BN_new();
257 if (shared_secret == NULL)
258 fatal("kexgss_client: BN_new failed");
259
260 if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
261 fatal("kexdh_client: BN_bin2bn failed");
262
263 memset(kbuf, 0, klen);
264 xfree(kbuf);
265
266 switch (kex->kex_type) {
267 case KEX_GSS_GRP1_SHA1:
268 case KEX_GSS_GRP14_SHA1:
269 kex_dh_hash( kex->client_version_string,
270 kex->server_version_string,
271 buffer_ptr(&kex->my), buffer_len(&kex->my),
272 buffer_ptr(&kex->peer), buffer_len(&kex->peer),
273 (serverhostkey ? serverhostkey : empty), slen,
274 dh->pub_key, /* e */
275 dh_server_pub, /* f */
276 shared_secret, /* K */
277 &hash, &hashlen
278 );
279 break;
280 case KEX_GSS_GEX_SHA1:
281 kexgex_hash(
282 kex->evp_md,
283 kex->client_version_string,
284 kex->server_version_string,
285 buffer_ptr(&kex->my), buffer_len(&kex->my),
286 buffer_ptr(&kex->peer), buffer_len(&kex->peer),
287 (serverhostkey ? serverhostkey : empty), slen,
288 min, nbits, max,
289 dh->p, dh->g,
290 dh->pub_key,
291 dh_server_pub,
292 shared_secret,
293 &hash, &hashlen
294 );
295 break;
296 default:
297 fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
298 }
299
300 gssbuf.value = hash;
301 gssbuf.length = hashlen;
302
303 /* Verify that the hash matches the MIC we just got. */
304 if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
305 packet_disconnect("Hash's MIC didn't verify");
306
307 xfree(msg_tok.value);
308
309 DH_free(dh);
310 if (serverhostkey)
311 xfree(serverhostkey);
312 BN_clear_free(dh_server_pub);
313
314 /* save session id */
315 if (kex->session_id == NULL) {
316 kex->session_id_len = hashlen;
317 kex->session_id = xmalloc(kex->session_id_len);
318 memcpy(kex->session_id, hash, kex->session_id_len);
319 }
320
321 if (kex->gss_deleg_creds)
322 ssh_gssapi_credentials_updated(ctxt);
323
324 if (gss_kex_context == NULL)
325 gss_kex_context = ctxt;
326 else
327 ssh_gssapi_delete_ctx(&ctxt);
328
329 kex_derive_keys(kex, hash, hashlen, shared_secret);
330 BN_clear_free(shared_secret);
331 kex_finish(kex);
332}
333
334#endif /* GSSAPI */
diff --git a/kexgsss.c b/kexgsss.c
new file mode 100644
index 000000000..0c3eeaa63
--- /dev/null
+++ b/kexgsss.c
@@ -0,0 +1,288 @@
1/*
2 * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
26
27#ifdef GSSAPI
28
29#include <string.h>
30
31#include <openssl/crypto.h>
32#include <openssl/bn.h>
33
34#include "xmalloc.h"
35#include "buffer.h"
36#include "ssh2.h"
37#include "key.h"
38#include "cipher.h"
39#include "kex.h"
40#include "log.h"
41#include "packet.h"
42#include "dh.h"
43#include "ssh-gss.h"
44#include "monitor_wrap.h"
45#include "servconf.h"
46
47extern ServerOptions options;
48
49void
50kexgss_server(Kex *kex)
51{
52 OM_uint32 maj_status, min_status;
53
54 /*
55 * Some GSSAPI implementations use the input value of ret_flags (an
56 * output variable) as a means of triggering mechanism specific
57 * features. Initializing it to zero avoids inadvertently
58 * activating this non-standard behaviour.
59 */
60
61 OM_uint32 ret_flags = 0;
62 gss_buffer_desc gssbuf, recv_tok, msg_tok;
63 gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
64 Gssctxt *ctxt = NULL;
65 u_int slen, klen, kout, hashlen;
66 u_char *kbuf, *hash;
67 DH *dh;
68 int min = -1, max = -1, nbits = -1;
69 BIGNUM *shared_secret = NULL;
70 BIGNUM *dh_client_pub = NULL;
71 int type = 0;
72 gss_OID oid;
73 char *mechs;
74
75 /* Initialise GSSAPI */
76
77 /* If we're rekeying, privsep means that some of the private structures
78 * in the GSSAPI code are no longer available. This kludges them back
79 * into life
80 */
81 if (!ssh_gssapi_oid_table_ok())
82 if ((mechs = ssh_gssapi_server_mechanisms()))
83 xfree(mechs);
84
85 debug2("%s: Identifying %s", __func__, kex->name);
86 oid = ssh_gssapi_id_kex(NULL, kex->name, kex->kex_type);
87 if (oid == GSS_C_NO_OID)
88 fatal("Unknown gssapi mechanism");
89
90 debug2("%s: Acquiring credentials", __func__);
91
92 if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid))))
93 fatal("Unable to acquire credentials for the server");
94
95 switch (kex->kex_type) {
96 case KEX_GSS_GRP1_SHA1:
97 dh = dh_new_group1();
98 break;
99 case KEX_GSS_GRP14_SHA1:
100 dh = dh_new_group14();
101 break;
102 case KEX_GSS_GEX_SHA1:
103 debug("Doing group exchange");
104 packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ);
105 min = packet_get_int();
106 nbits = packet_get_int();
107 max = packet_get_int();
108 min = MAX(DH_GRP_MIN, min);
109 max = MIN(DH_GRP_MAX, max);
110 packet_check_eom();
111 if (max < min || nbits < min || max < nbits)
112 fatal("GSS_GEX, bad parameters: %d !< %d !< %d",
113 min, nbits, max);
114 dh = PRIVSEP(choose_dh(min, nbits, max));
115 if (dh == NULL)
116 packet_disconnect("Protocol error: no matching group found");
117
118 packet_start(SSH2_MSG_KEXGSS_GROUP);
119 packet_put_bignum2(dh->p);
120 packet_put_bignum2(dh->g);
121 packet_send();
122
123 packet_write_wait();
124 break;
125 default:
126 fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
127 }
128
129 dh_gen_key(dh, kex->we_need * 8);
130
131 do {
132 debug("Wait SSH2_MSG_GSSAPI_INIT");
133 type = packet_read();
134 switch(type) {
135 case SSH2_MSG_KEXGSS_INIT:
136 if (dh_client_pub != NULL)
137 fatal("Received KEXGSS_INIT after initialising");
138 recv_tok.value = packet_get_string(&slen);
139 recv_tok.length = slen;
140
141 if ((dh_client_pub = BN_new()) == NULL)
142 fatal("dh_client_pub == NULL");
143
144 packet_get_bignum2(dh_client_pub);
145
146 /* Send SSH_MSG_KEXGSS_HOSTKEY here, if we want */
147 break;
148 case SSH2_MSG_KEXGSS_CONTINUE:
149 recv_tok.value = packet_get_string(&slen);
150 recv_tok.length = slen;
151 break;
152 default:
153 packet_disconnect(
154 "Protocol error: didn't expect packet type %d",
155 type);
156 }
157
158 maj_status = PRIVSEP(ssh_gssapi_accept_ctx(ctxt, &recv_tok,
159 &send_tok, &ret_flags));
160
161 xfree(recv_tok.value);
162
163 if (maj_status != GSS_S_COMPLETE && send_tok.length == 0)
164 fatal("Zero length token output when incomplete");
165
166 if (dh_client_pub == NULL)
167 fatal("No client public key");
168
169 if (maj_status & GSS_S_CONTINUE_NEEDED) {
170 debug("Sending GSSAPI_CONTINUE");
171 packet_start(SSH2_MSG_KEXGSS_CONTINUE);
172 packet_put_string(send_tok.value, send_tok.length);
173 packet_send();
174 gss_release_buffer(&min_status, &send_tok);
175 }
176 } while (maj_status & GSS_S_CONTINUE_NEEDED);
177
178 if (GSS_ERROR(maj_status)) {
179 if (send_tok.length > 0) {
180 packet_start(SSH2_MSG_KEXGSS_CONTINUE);
181 packet_put_string(send_tok.value, send_tok.length);
182 packet_send();
183 }
184 fatal("accept_ctx died");
185 }
186
187 if (!(ret_flags & GSS_C_MUTUAL_FLAG))
188 fatal("Mutual Authentication flag wasn't set");
189
190 if (!(ret_flags & GSS_C_INTEG_FLAG))
191 fatal("Integrity flag wasn't set");
192
193 if (!dh_pub_is_valid(dh, dh_client_pub))
194 packet_disconnect("bad client public DH value");
195
196 klen = DH_size(dh);
197 kbuf = xmalloc(klen);
198 kout = DH_compute_key(kbuf, dh_client_pub, dh);
199 if (kout < 0)
200 fatal("DH_compute_key: failed");
201
202 shared_secret = BN_new();
203 if (shared_secret == NULL)
204 fatal("kexgss_server: BN_new failed");
205
206 if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
207 fatal("kexgss_server: BN_bin2bn failed");
208
209 memset(kbuf, 0, klen);
210 xfree(kbuf);
211
212 switch (kex->kex_type) {
213 case KEX_GSS_GRP1_SHA1:
214 case KEX_GSS_GRP14_SHA1:
215 kex_dh_hash(
216 kex->client_version_string, kex->server_version_string,
217 buffer_ptr(&kex->peer), buffer_len(&kex->peer),
218 buffer_ptr(&kex->my), buffer_len(&kex->my),
219 NULL, 0, /* Change this if we start sending host keys */
220 dh_client_pub, dh->pub_key, shared_secret,
221 &hash, &hashlen
222 );
223 break;
224 case KEX_GSS_GEX_SHA1:
225 kexgex_hash(
226 kex->evp_md,
227 kex->client_version_string, kex->server_version_string,
228 buffer_ptr(&kex->peer), buffer_len(&kex->peer),
229 buffer_ptr(&kex->my), buffer_len(&kex->my),
230 NULL, 0,
231 min, nbits, max,
232 dh->p, dh->g,
233 dh_client_pub,
234 dh->pub_key,
235 shared_secret,
236 &hash, &hashlen
237 );
238 break;
239 default:
240 fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
241 }
242
243 BN_clear_free(dh_client_pub);
244
245 if (kex->session_id == NULL) {
246 kex->session_id_len = hashlen;
247 kex->session_id = xmalloc(kex->session_id_len);
248 memcpy(kex->session_id, hash, kex->session_id_len);
249 }
250
251 gssbuf.value = hash;
252 gssbuf.length = hashlen;
253
254 if (GSS_ERROR(PRIVSEP(ssh_gssapi_sign(ctxt,&gssbuf,&msg_tok))))
255 fatal("Couldn't get MIC");
256
257 packet_start(SSH2_MSG_KEXGSS_COMPLETE);
258 packet_put_bignum2(dh->pub_key);
259 packet_put_string(msg_tok.value,msg_tok.length);
260
261 if (send_tok.length != 0) {
262 packet_put_char(1); /* true */
263 packet_put_string(send_tok.value, send_tok.length);
264 } else {
265 packet_put_char(0); /* false */
266 }
267 packet_send();
268
269 gss_release_buffer(&min_status, &send_tok);
270 gss_release_buffer(&min_status, &msg_tok);
271
272 if (gss_kex_context == NULL)
273 gss_kex_context = ctxt;
274 else
275 ssh_gssapi_delete_ctx(&ctxt);
276
277 DH_free(dh);
278
279 kex_derive_keys(kex, hash, hashlen, shared_secret);
280 BN_clear_free(shared_secret);
281 kex_finish(kex);
282
283 /* If this was a rekey, then save out any delegated credentials we
284 * just exchanged. */
285 if (options.gss_store_rekey)
286 ssh_gssapi_rekey_creds();
287}
288#endif /* GSSAPI */
diff --git a/key.c b/key.c
index 7e9099703..2a16b25b9 100644
--- a/key.c
+++ b/key.c
@@ -976,6 +976,8 @@ key_ssh_name_from_type_nid(int type, int nid)
976 } 976 }
977 break; 977 break;
978#endif /* OPENSSL_HAS_ECC */ 978#endif /* OPENSSL_HAS_ECC */
979 case KEY_NULL:
980 return "null";
979 } 981 }
980 return "ssh-unknown"; 982 return "ssh-unknown";
981} 983}
@@ -1281,6 +1283,8 @@ key_type_from_name(char *name)
1281 strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) { 1283 strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
1282 return KEY_ECDSA_CERT; 1284 return KEY_ECDSA_CERT;
1283#endif 1285#endif
1286 } else if (strcmp(name, "null") == 0) {
1287 return KEY_NULL;
1284 } 1288 }
1285 1289
1286 debug2("key_type_from_name: unknown key type '%s'", name); 1290 debug2("key_type_from_name: unknown key type '%s'", name);
diff --git a/key.h b/key.h
index 39e5577f6..ca56b4271 100644
--- a/key.h
+++ b/key.h
@@ -44,6 +44,7 @@ enum types {
44 KEY_ECDSA_CERT, 44 KEY_ECDSA_CERT,
45 KEY_RSA_CERT_V00, 45 KEY_RSA_CERT_V00,
46 KEY_DSA_CERT_V00, 46 KEY_DSA_CERT_V00,
47 KEY_NULL,
47 KEY_UNSPEC 48 KEY_UNSPEC
48}; 49};
49enum fp_type { 50enum fp_type {
diff --git a/monitor.c b/monitor.c
index e9802a3fd..ed598ce35 100644
--- a/monitor.c
+++ b/monitor.c
@@ -180,6 +180,8 @@ int mm_answer_gss_setup_ctx(int, Buffer *);
180int mm_answer_gss_accept_ctx(int, Buffer *); 180int mm_answer_gss_accept_ctx(int, Buffer *);
181int mm_answer_gss_userok(int, Buffer *); 181int mm_answer_gss_userok(int, Buffer *);
182int mm_answer_gss_checkmic(int, Buffer *); 182int mm_answer_gss_checkmic(int, Buffer *);
183int mm_answer_gss_sign(int, Buffer *);
184int mm_answer_gss_updatecreds(int, Buffer *);
183#endif 185#endif
184 186
185#ifdef SSH_AUDIT_EVENTS 187#ifdef SSH_AUDIT_EVENTS
@@ -251,6 +253,7 @@ struct mon_table mon_dispatch_proto20[] = {
251 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx}, 253 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
252 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok}, 254 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
253 {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic}, 255 {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic},
256 {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
254#endif 257#endif
255#ifdef JPAKE 258#ifdef JPAKE
256 {MONITOR_REQ_JPAKE_GET_PWDATA, MON_ONCE, mm_answer_jpake_get_pwdata}, 259 {MONITOR_REQ_JPAKE_GET_PWDATA, MON_ONCE, mm_answer_jpake_get_pwdata},
@@ -263,6 +266,12 @@ struct mon_table mon_dispatch_proto20[] = {
263}; 266};
264 267
265struct mon_table mon_dispatch_postauth20[] = { 268struct mon_table mon_dispatch_postauth20[] = {
269#ifdef GSSAPI
270 {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
271 {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
272 {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
273 {MONITOR_REQ_GSSUPCREDS, 0, mm_answer_gss_updatecreds},
274#endif
266 {MONITOR_REQ_MODULI, 0, mm_answer_moduli}, 275 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
267 {MONITOR_REQ_SIGN, 0, mm_answer_sign}, 276 {MONITOR_REQ_SIGN, 0, mm_answer_sign},
268 {MONITOR_REQ_PTY, 0, mm_answer_pty}, 277 {MONITOR_REQ_PTY, 0, mm_answer_pty},
@@ -371,6 +380,10 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
371 /* Permit requests for moduli and signatures */ 380 /* Permit requests for moduli and signatures */
372 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); 381 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
373 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); 382 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
383#ifdef GSSAPI
384 /* and for the GSSAPI key exchange */
385 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
386#endif
374 } else { 387 } else {
375 mon_dispatch = mon_dispatch_proto15; 388 mon_dispatch = mon_dispatch_proto15;
376 389
@@ -468,6 +481,10 @@ monitor_child_postauth(struct monitor *pmonitor)
468 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); 481 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
469 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); 482 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
470 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1); 483 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
484#ifdef GSSAPI
485 /* and for the GSSAPI key exchange */
486 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
487#endif
471 } else { 488 } else {
472 mon_dispatch = mon_dispatch_postauth15; 489 mon_dispatch = mon_dispatch_postauth15;
473 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1); 490 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
@@ -1800,6 +1817,13 @@ mm_get_kex(Buffer *m)
1800 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; 1817 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
1801 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; 1818 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
1802 kex->kex[KEX_ECDH_SHA2] = kexecdh_server; 1819 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
1820#ifdef GSSAPI
1821 if (options.gss_keyex) {
1822 kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
1823 kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
1824 kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
1825 }
1826#endif
1803 kex->server = 1; 1827 kex->server = 1;
1804 kex->hostkey_type = buffer_get_int(m); 1828 kex->hostkey_type = buffer_get_int(m);
1805 kex->kex_type = buffer_get_int(m); 1829 kex->kex_type = buffer_get_int(m);
@@ -2006,6 +2030,9 @@ mm_answer_gss_setup_ctx(int sock, Buffer *m)
2006 OM_uint32 major; 2030 OM_uint32 major;
2007 u_int len; 2031 u_int len;
2008 2032
2033 if (!options.gss_authentication && !options.gss_keyex)
2034 fatal("In GSSAPI monitor when GSSAPI is disabled");
2035
2009 goid.elements = buffer_get_string(m, &len); 2036 goid.elements = buffer_get_string(m, &len);
2010 goid.length = len; 2037 goid.length = len;
2011 2038
@@ -2033,6 +2060,9 @@ mm_answer_gss_accept_ctx(int sock, Buffer *m)
2033 OM_uint32 flags = 0; /* GSI needs this */ 2060 OM_uint32 flags = 0; /* GSI needs this */
2034 u_int len; 2061 u_int len;
2035 2062
2063 if (!options.gss_authentication && !options.gss_keyex)
2064 fatal("In GSSAPI monitor when GSSAPI is disabled");
2065
2036 in.value = buffer_get_string(m, &len); 2066 in.value = buffer_get_string(m, &len);
2037 in.length = len; 2067 in.length = len;
2038 major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags); 2068 major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags);
@@ -2050,6 +2080,7 @@ mm_answer_gss_accept_ctx(int sock, Buffer *m)
2050 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0); 2080 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
2051 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1); 2081 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
2052 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1); 2082 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1);
2083 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1);
2053 } 2084 }
2054 return (0); 2085 return (0);
2055} 2086}
@@ -2061,6 +2092,9 @@ mm_answer_gss_checkmic(int sock, Buffer *m)
2061 OM_uint32 ret; 2092 OM_uint32 ret;
2062 u_int len; 2093 u_int len;
2063 2094
2095 if (!options.gss_authentication && !options.gss_keyex)
2096 fatal("In GSSAPI monitor when GSSAPI is disabled");
2097
2064 gssbuf.value = buffer_get_string(m, &len); 2098 gssbuf.value = buffer_get_string(m, &len);
2065 gssbuf.length = len; 2099 gssbuf.length = len;
2066 mic.value = buffer_get_string(m, &len); 2100 mic.value = buffer_get_string(m, &len);
@@ -2087,7 +2121,11 @@ mm_answer_gss_userok(int sock, Buffer *m)
2087{ 2121{
2088 int authenticated; 2122 int authenticated;
2089 2123
2090 authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user); 2124 if (!options.gss_authentication && !options.gss_keyex)
2125 fatal("In GSSAPI monitor when GSSAPI is disabled");
2126
2127 authenticated = authctxt->valid &&
2128 ssh_gssapi_userok(authctxt->user, authctxt->pw);
2091 2129
2092 buffer_clear(m); 2130 buffer_clear(m);
2093 buffer_put_int(m, authenticated); 2131 buffer_put_int(m, authenticated);
@@ -2100,6 +2138,74 @@ mm_answer_gss_userok(int sock, Buffer *m)
2100 /* Monitor loop will terminate if authenticated */ 2138 /* Monitor loop will terminate if authenticated */
2101 return (authenticated); 2139 return (authenticated);
2102} 2140}
2141
2142int
2143mm_answer_gss_sign(int socket, Buffer *m)
2144{
2145 gss_buffer_desc data;
2146 gss_buffer_desc hash = GSS_C_EMPTY_BUFFER;
2147 OM_uint32 major, minor;
2148 u_int len;
2149
2150 if (!options.gss_authentication && !options.gss_keyex)
2151 fatal("In GSSAPI monitor when GSSAPI is disabled");
2152
2153 data.value = buffer_get_string(m, &len);
2154 data.length = len;
2155 if (data.length != 20)
2156 fatal("%s: data length incorrect: %d", __func__,
2157 (int) data.length);
2158
2159 /* Save the session ID on the first time around */
2160 if (session_id2_len == 0) {
2161 session_id2_len = data.length;
2162 session_id2 = xmalloc(session_id2_len);
2163 memcpy(session_id2, data.value, session_id2_len);
2164 }
2165 major = ssh_gssapi_sign(gsscontext, &data, &hash);
2166
2167 xfree(data.value);
2168
2169 buffer_clear(m);
2170 buffer_put_int(m, major);
2171 buffer_put_string(m, hash.value, hash.length);
2172
2173 mm_request_send(socket, MONITOR_ANS_GSSSIGN, m);
2174
2175 gss_release_buffer(&minor, &hash);
2176
2177 /* Turn on getpwnam permissions */
2178 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
2179
2180 /* And credential updating, for when rekeying */
2181 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUPCREDS, 1);
2182
2183 return (0);
2184}
2185
2186int
2187mm_answer_gss_updatecreds(int socket, Buffer *m) {
2188 ssh_gssapi_ccache store;
2189 int ok;
2190
2191 store.filename = buffer_get_string(m, NULL);
2192 store.envvar = buffer_get_string(m, NULL);
2193 store.envval = buffer_get_string(m, NULL);
2194
2195 ok = ssh_gssapi_update_creds(&store);
2196
2197 xfree(store.filename);
2198 xfree(store.envvar);
2199 xfree(store.envval);
2200
2201 buffer_clear(m);
2202 buffer_put_int(m, ok);
2203
2204 mm_request_send(socket, MONITOR_ANS_GSSUPCREDS, m);
2205
2206 return(0);
2207}
2208
2103#endif /* GSSAPI */ 2209#endif /* GSSAPI */
2104 2210
2105#ifdef JPAKE 2211#ifdef JPAKE
diff --git a/monitor.h b/monitor.h
index 5e7d552fb..db0443fec 100644
--- a/monitor.h
+++ b/monitor.h
@@ -53,6 +53,8 @@ enum monitor_reqtype {
53 MONITOR_REQ_GSSSTEP, MONITOR_ANS_GSSSTEP, 53 MONITOR_REQ_GSSSTEP, MONITOR_ANS_GSSSTEP,
54 MONITOR_REQ_GSSUSEROK, MONITOR_ANS_GSSUSEROK, 54 MONITOR_REQ_GSSUSEROK, MONITOR_ANS_GSSUSEROK,
55 MONITOR_REQ_GSSCHECKMIC, MONITOR_ANS_GSSCHECKMIC, 55 MONITOR_REQ_GSSCHECKMIC, MONITOR_ANS_GSSCHECKMIC,
56 MONITOR_REQ_GSSSIGN, MONITOR_ANS_GSSSIGN,
57 MONITOR_REQ_GSSUPCREDS, MONITOR_ANS_GSSUPCREDS,
56 MONITOR_REQ_PAM_START, 58 MONITOR_REQ_PAM_START,
57 MONITOR_REQ_PAM_ACCOUNT, MONITOR_ANS_PAM_ACCOUNT, 59 MONITOR_REQ_PAM_ACCOUNT, MONITOR_ANS_PAM_ACCOUNT,
58 MONITOR_REQ_PAM_INIT_CTX, MONITOR_ANS_PAM_INIT_CTX, 60 MONITOR_REQ_PAM_INIT_CTX, MONITOR_ANS_PAM_INIT_CTX,
diff --git a/monitor_wrap.c b/monitor_wrap.c
index 1f60658e9..fc6bbcd2e 100644
--- a/monitor_wrap.c
+++ b/monitor_wrap.c
@@ -1270,7 +1270,7 @@ mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
1270} 1270}
1271 1271
1272int 1272int
1273mm_ssh_gssapi_userok(char *user) 1273mm_ssh_gssapi_userok(char *user, struct passwd *pw)
1274{ 1274{
1275 Buffer m; 1275 Buffer m;
1276 int authenticated = 0; 1276 int authenticated = 0;
@@ -1287,6 +1287,51 @@ mm_ssh_gssapi_userok(char *user)
1287 debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not "); 1287 debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
1288 return (authenticated); 1288 return (authenticated);
1289} 1289}
1290
1291OM_uint32
1292mm_ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_desc *data, gss_buffer_desc *hash)
1293{
1294 Buffer m;
1295 OM_uint32 major;
1296 u_int len;
1297
1298 buffer_init(&m);
1299 buffer_put_string(&m, data->value, data->length);
1300
1301 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSIGN, &m);
1302 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSIGN, &m);
1303
1304 major = buffer_get_int(&m);
1305 hash->value = buffer_get_string(&m, &len);
1306 hash->length = len;
1307
1308 buffer_free(&m);
1309
1310 return(major);
1311}
1312
1313int
1314mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
1315{
1316 Buffer m;
1317 int ok;
1318
1319 buffer_init(&m);
1320
1321 buffer_put_cstring(&m, store->filename ? store->filename : "");
1322 buffer_put_cstring(&m, store->envvar ? store->envvar : "");
1323 buffer_put_cstring(&m, store->envval ? store->envval : "");
1324
1325 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUPCREDS, &m);
1326 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUPCREDS, &m);
1327
1328 ok = buffer_get_int(&m);
1329
1330 buffer_free(&m);
1331
1332 return (ok);
1333}
1334
1290#endif /* GSSAPI */ 1335#endif /* GSSAPI */
1291 1336
1292#ifdef JPAKE 1337#ifdef JPAKE
diff --git a/monitor_wrap.h b/monitor_wrap.h
index 0c7f2e384..ec9b9b1c3 100644
--- a/monitor_wrap.h
+++ b/monitor_wrap.h
@@ -58,8 +58,10 @@ BIGNUM *mm_auth_rsa_generate_challenge(Key *);
58OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID); 58OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
59OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *, 59OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *,
60 gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *); 60 gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *);
61int mm_ssh_gssapi_userok(char *user); 61int mm_ssh_gssapi_userok(char *user, struct passwd *);
62OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t); 62OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
63OM_uint32 mm_ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
64int mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *);
63#endif 65#endif
64 66
65#ifdef USE_PAM 67#ifdef USE_PAM
diff --git a/readconf.c b/readconf.c
index 097bb0515..99c04a9de 100644
--- a/readconf.c
+++ b/readconf.c
@@ -129,6 +129,8 @@ typedef enum {
129 oClearAllForwardings, oNoHostAuthenticationForLocalhost, 129 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
130 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout, 130 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
131 oAddressFamily, oGssAuthentication, oGssDelegateCreds, 131 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
132 oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey,
133 oGssServerIdentity,
132 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly, 134 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
133 oSendEnv, oControlPath, oControlMaster, oControlPersist, 135 oSendEnv, oControlPath, oControlMaster, oControlPersist,
134 oHashKnownHosts, 136 oHashKnownHosts,
@@ -169,10 +171,19 @@ static struct {
169 { "afstokenpassing", oUnsupported }, 171 { "afstokenpassing", oUnsupported },
170#if defined(GSSAPI) 172#if defined(GSSAPI)
171 { "gssapiauthentication", oGssAuthentication }, 173 { "gssapiauthentication", oGssAuthentication },
174 { "gssapikeyexchange", oGssKeyEx },
172 { "gssapidelegatecredentials", oGssDelegateCreds }, 175 { "gssapidelegatecredentials", oGssDelegateCreds },
176 { "gssapitrustdns", oGssTrustDns },
177 { "gssapiclientidentity", oGssClientIdentity },
178 { "gssapiserveridentity", oGssServerIdentity },
179 { "gssapirenewalforcesrekey", oGssRenewalRekey },
173#else 180#else
174 { "gssapiauthentication", oUnsupported }, 181 { "gssapiauthentication", oUnsupported },
182 { "gssapikeyexchange", oUnsupported },
175 { "gssapidelegatecredentials", oUnsupported }, 183 { "gssapidelegatecredentials", oUnsupported },
184 { "gssapitrustdns", oUnsupported },
185 { "gssapiclientidentity", oUnsupported },
186 { "gssapirenewalforcesrekey", oUnsupported },
176#endif 187#endif
177 { "fallbacktorsh", oDeprecated }, 188 { "fallbacktorsh", oDeprecated },
178 { "usersh", oDeprecated }, 189 { "usersh", oDeprecated },
@@ -483,10 +494,30 @@ parse_flag:
483 intptr = &options->gss_authentication; 494 intptr = &options->gss_authentication;
484 goto parse_flag; 495 goto parse_flag;
485 496
497 case oGssKeyEx:
498 intptr = &options->gss_keyex;
499 goto parse_flag;
500
486 case oGssDelegateCreds: 501 case oGssDelegateCreds:
487 intptr = &options->gss_deleg_creds; 502 intptr = &options->gss_deleg_creds;
488 goto parse_flag; 503 goto parse_flag;
489 504
505 case oGssTrustDns:
506 intptr = &options->gss_trust_dns;
507 goto parse_flag;
508
509 case oGssClientIdentity:
510 charptr = &options->gss_client_identity;
511 goto parse_string;
512
513 case oGssServerIdentity:
514 charptr = &options->gss_server_identity;
515 goto parse_string;
516
517 case oGssRenewalRekey:
518 intptr = &options->gss_renewal_rekey;
519 goto parse_flag;
520
490 case oBatchMode: 521 case oBatchMode:
491 intptr = &options->batch_mode; 522 intptr = &options->batch_mode;
492 goto parse_flag; 523 goto parse_flag;
@@ -1139,7 +1170,12 @@ initialize_options(Options * options)
1139 options->pubkey_authentication = -1; 1170 options->pubkey_authentication = -1;
1140 options->challenge_response_authentication = -1; 1171 options->challenge_response_authentication = -1;
1141 options->gss_authentication = -1; 1172 options->gss_authentication = -1;
1173 options->gss_keyex = -1;
1142 options->gss_deleg_creds = -1; 1174 options->gss_deleg_creds = -1;
1175 options->gss_trust_dns = -1;
1176 options->gss_renewal_rekey = -1;
1177 options->gss_client_identity = NULL;
1178 options->gss_server_identity = NULL;
1143 options->password_authentication = -1; 1179 options->password_authentication = -1;
1144 options->kbd_interactive_authentication = -1; 1180 options->kbd_interactive_authentication = -1;
1145 options->kbd_interactive_devices = NULL; 1181 options->kbd_interactive_devices = NULL;
@@ -1239,8 +1275,14 @@ fill_default_options(Options * options)
1239 options->challenge_response_authentication = 1; 1275 options->challenge_response_authentication = 1;
1240 if (options->gss_authentication == -1) 1276 if (options->gss_authentication == -1)
1241 options->gss_authentication = 0; 1277 options->gss_authentication = 0;
1278 if (options->gss_keyex == -1)
1279 options->gss_keyex = 0;
1242 if (options->gss_deleg_creds == -1) 1280 if (options->gss_deleg_creds == -1)
1243 options->gss_deleg_creds = 0; 1281 options->gss_deleg_creds = 0;
1282 if (options->gss_trust_dns == -1)
1283 options->gss_trust_dns = 0;
1284 if (options->gss_renewal_rekey == -1)
1285 options->gss_renewal_rekey = 0;
1244 if (options->password_authentication == -1) 1286 if (options->password_authentication == -1)
1245 options->password_authentication = 1; 1287 options->password_authentication = 1;
1246 if (options->kbd_interactive_authentication == -1) 1288 if (options->kbd_interactive_authentication == -1)
diff --git a/readconf.h b/readconf.h
index be30ee0e1..41f1befae 100644
--- a/readconf.h
+++ b/readconf.h
@@ -48,7 +48,12 @@ typedef struct {
48 int challenge_response_authentication; 48 int challenge_response_authentication;
49 /* Try S/Key or TIS, authentication. */ 49 /* Try S/Key or TIS, authentication. */
50 int gss_authentication; /* Try GSS authentication */ 50 int gss_authentication; /* Try GSS authentication */
51 int gss_keyex; /* Try GSS key exchange */
51 int gss_deleg_creds; /* Delegate GSS credentials */ 52 int gss_deleg_creds; /* Delegate GSS credentials */
53 int gss_trust_dns; /* Trust DNS for GSS canonicalization */
54 int gss_renewal_rekey; /* Credential renewal forces rekey */
55 char *gss_client_identity; /* Principal to initiate GSSAPI with */
56 char *gss_server_identity; /* GSSAPI target principal */
52 int password_authentication; /* Try password 57 int password_authentication; /* Try password
53 * authentication. */ 58 * authentication. */
54 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */ 59 int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
diff --git a/servconf.c b/servconf.c
index ee2e531a0..5be0c7bbf 100644
--- a/servconf.c
+++ b/servconf.c
@@ -100,7 +100,10 @@ initialize_server_options(ServerOptions *options)
100 options->kerberos_ticket_cleanup = -1; 100 options->kerberos_ticket_cleanup = -1;
101 options->kerberos_get_afs_token = -1; 101 options->kerberos_get_afs_token = -1;
102 options->gss_authentication=-1; 102 options->gss_authentication=-1;
103 options->gss_keyex = -1;
103 options->gss_cleanup_creds = -1; 104 options->gss_cleanup_creds = -1;
105 options->gss_strict_acceptor = -1;
106 options->gss_store_rekey = -1;
104 options->password_authentication = -1; 107 options->password_authentication = -1;
105 options->kbd_interactive_authentication = -1; 108 options->kbd_interactive_authentication = -1;
106 options->challenge_response_authentication = -1; 109 options->challenge_response_authentication = -1;
@@ -229,8 +232,14 @@ fill_default_server_options(ServerOptions *options)
229 options->kerberos_get_afs_token = 0; 232 options->kerberos_get_afs_token = 0;
230 if (options->gss_authentication == -1) 233 if (options->gss_authentication == -1)
231 options->gss_authentication = 0; 234 options->gss_authentication = 0;
235 if (options->gss_keyex == -1)
236 options->gss_keyex = 0;
232 if (options->gss_cleanup_creds == -1) 237 if (options->gss_cleanup_creds == -1)
233 options->gss_cleanup_creds = 1; 238 options->gss_cleanup_creds = 1;
239 if (options->gss_strict_acceptor == -1)
240 options->gss_strict_acceptor = 1;
241 if (options->gss_store_rekey == -1)
242 options->gss_store_rekey = 0;
234 if (options->password_authentication == -1) 243 if (options->password_authentication == -1)
235 options->password_authentication = 1; 244 options->password_authentication = 1;
236 if (options->kbd_interactive_authentication == -1) 245 if (options->kbd_interactive_authentication == -1)
@@ -323,7 +332,9 @@ typedef enum {
323 sBanner, sUseDNS, sHostbasedAuthentication, 332 sBanner, sUseDNS, sHostbasedAuthentication,
324 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval, 333 sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
325 sClientAliveCountMax, sAuthorizedKeysFile, 334 sClientAliveCountMax, sAuthorizedKeysFile,
326 sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel, 335 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
336 sGssKeyEx, sGssStoreRekey,
337 sAcceptEnv, sPermitTunnel,
327 sMatch, sPermitOpen, sForceCommand, sChrootDirectory, 338 sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
328 sUsePrivilegeSeparation, sAllowAgentForwarding, 339 sUsePrivilegeSeparation, sAllowAgentForwarding,
329 sZeroKnowledgePasswordAuthentication, sHostCertificate, 340 sZeroKnowledgePasswordAuthentication, sHostCertificate,
@@ -387,10 +398,20 @@ static struct {
387#ifdef GSSAPI 398#ifdef GSSAPI
388 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL }, 399 { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
389 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL }, 400 { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
401 { "gssapicleanupcreds", sGssCleanupCreds, SSHCFG_GLOBAL },
402 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
403 { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
404 { "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
390#else 405#else
391 { "gssapiauthentication", sUnsupported, SSHCFG_ALL }, 406 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
392 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL }, 407 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
408 { "gssapicleanupcreds", sUnsupported, SSHCFG_GLOBAL },
409 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
410 { "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
411 { "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
393#endif 412#endif
413 { "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL },
414 { "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL },
394 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL }, 415 { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
395 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL }, 416 { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
396 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, 417 { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
@@ -1031,10 +1052,22 @@ process_server_config_line(ServerOptions *options, char *line,
1031 intptr = &options->gss_authentication; 1052 intptr = &options->gss_authentication;
1032 goto parse_flag; 1053 goto parse_flag;
1033 1054
1055 case sGssKeyEx:
1056 intptr = &options->gss_keyex;
1057 goto parse_flag;
1058
1034 case sGssCleanupCreds: 1059 case sGssCleanupCreds:
1035 intptr = &options->gss_cleanup_creds; 1060 intptr = &options->gss_cleanup_creds;
1036 goto parse_flag; 1061 goto parse_flag;
1037 1062
1063 case sGssStrictAcceptor:
1064 intptr = &options->gss_strict_acceptor;
1065 goto parse_flag;
1066
1067 case sGssStoreRekey:
1068 intptr = &options->gss_store_rekey;
1069 goto parse_flag;
1070
1038 case sPasswordAuthentication: 1071 case sPasswordAuthentication:
1039 intptr = &options->password_authentication; 1072 intptr = &options->password_authentication;
1040 goto parse_flag; 1073 goto parse_flag;
@@ -1868,7 +1901,10 @@ dump_config(ServerOptions *o)
1868#endif 1901#endif
1869#ifdef GSSAPI 1902#ifdef GSSAPI
1870 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication); 1903 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
1904 dump_cfg_fmtint(sGssKeyEx, o->gss_keyex);
1871 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds); 1905 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1906 dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor);
1907 dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey);
1872#endif 1908#endif
1873#ifdef JPAKE 1909#ifdef JPAKE
1874 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication, 1910 dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
diff --git a/servconf.h b/servconf.h
index 096d596d7..2ccf4d0f2 100644
--- a/servconf.h
+++ b/servconf.h
@@ -103,7 +103,10 @@ typedef struct {
103 int kerberos_get_afs_token; /* If true, try to get AFS token if 103 int kerberos_get_afs_token; /* If true, try to get AFS token if
104 * authenticated with Kerberos. */ 104 * authenticated with Kerberos. */
105 int gss_authentication; /* If true, permit GSSAPI authentication */ 105 int gss_authentication; /* If true, permit GSSAPI authentication */
106 int gss_keyex; /* If true, permit GSSAPI key exchange */
106 int gss_cleanup_creds; /* If true, destroy cred cache on logout */ 107 int gss_cleanup_creds; /* If true, destroy cred cache on logout */
108 int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */
109 int gss_store_rekey;
107 int password_authentication; /* If true, permit password 110 int password_authentication; /* If true, permit password
108 * authentication. */ 111 * authentication. */
109 int kbd_interactive_authentication; /* If true, permit */ 112 int kbd_interactive_authentication; /* If true, permit */
diff --git a/ssh-gss.h b/ssh-gss.h
index c29a1b7e7..31d5a0835 100644
--- a/ssh-gss.h
+++ b/ssh-gss.h
@@ -1,6 +1,6 @@
1/* $OpenBSD: ssh-gss.h,v 1.10 2007/06/12 08:20:00 djm Exp $ */ 1/* $OpenBSD: ssh-gss.h,v 1.10 2007/06/12 08:20:00 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. 3 * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -60,10 +60,22 @@
60 60
61#define SSH_GSS_OIDTYPE 0x06 61#define SSH_GSS_OIDTYPE 0x06
62 62
63#define SSH2_MSG_KEXGSS_INIT 30
64#define SSH2_MSG_KEXGSS_CONTINUE 31
65#define SSH2_MSG_KEXGSS_COMPLETE 32
66#define SSH2_MSG_KEXGSS_HOSTKEY 33
67#define SSH2_MSG_KEXGSS_ERROR 34
68#define SSH2_MSG_KEXGSS_GROUPREQ 40
69#define SSH2_MSG_KEXGSS_GROUP 41
70#define KEX_GSS_GRP1_SHA1_ID "gss-group1-sha1-"
71#define KEX_GSS_GRP14_SHA1_ID "gss-group14-sha1-"
72#define KEX_GSS_GEX_SHA1_ID "gss-gex-sha1-"
73
63typedef struct { 74typedef struct {
64 char *filename; 75 char *filename;
65 char *envvar; 76 char *envvar;
66 char *envval; 77 char *envval;
78 struct passwd *owner;
67 void *data; 79 void *data;
68} ssh_gssapi_ccache; 80} ssh_gssapi_ccache;
69 81
@@ -71,8 +83,11 @@ typedef struct {
71 gss_buffer_desc displayname; 83 gss_buffer_desc displayname;
72 gss_buffer_desc exportedname; 84 gss_buffer_desc exportedname;
73 gss_cred_id_t creds; 85 gss_cred_id_t creds;
86 gss_name_t name;
74 struct ssh_gssapi_mech_struct *mech; 87 struct ssh_gssapi_mech_struct *mech;
75 ssh_gssapi_ccache store; 88 ssh_gssapi_ccache store;
89 int used;
90 int updated;
76} ssh_gssapi_client; 91} ssh_gssapi_client;
77 92
78typedef struct ssh_gssapi_mech_struct { 93typedef struct ssh_gssapi_mech_struct {
@@ -83,6 +98,7 @@ typedef struct ssh_gssapi_mech_struct {
83 int (*userok) (ssh_gssapi_client *, char *); 98 int (*userok) (ssh_gssapi_client *, char *);
84 int (*localname) (ssh_gssapi_client *, char **); 99 int (*localname) (ssh_gssapi_client *, char **);
85 void (*storecreds) (ssh_gssapi_client *); 100 void (*storecreds) (ssh_gssapi_client *);
101 int (*updatecreds) (ssh_gssapi_ccache *, ssh_gssapi_client *);
86} ssh_gssapi_mech; 102} ssh_gssapi_mech;
87 103
88typedef struct { 104typedef struct {
@@ -93,10 +109,11 @@ typedef struct {
93 gss_OID oid; /* client */ 109 gss_OID oid; /* client */
94 gss_cred_id_t creds; /* server */ 110 gss_cred_id_t creds; /* server */
95 gss_name_t client; /* server */ 111 gss_name_t client; /* server */
96 gss_cred_id_t client_creds; /* server */ 112 gss_cred_id_t client_creds; /* both */
97} Gssctxt; 113} Gssctxt;
98 114
99extern ssh_gssapi_mech *supported_mechs[]; 115extern ssh_gssapi_mech *supported_mechs[];
116extern Gssctxt *gss_kex_context;
100 117
101int ssh_gssapi_check_oid(Gssctxt *, void *, size_t); 118int ssh_gssapi_check_oid(Gssctxt *, void *, size_t);
102void ssh_gssapi_set_oid_data(Gssctxt *, void *, size_t); 119void ssh_gssapi_set_oid_data(Gssctxt *, void *, size_t);
@@ -116,16 +133,30 @@ void ssh_gssapi_build_ctx(Gssctxt **);
116void ssh_gssapi_delete_ctx(Gssctxt **); 133void ssh_gssapi_delete_ctx(Gssctxt **);
117OM_uint32 ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t); 134OM_uint32 ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
118void ssh_gssapi_buildmic(Buffer *, const char *, const char *, const char *); 135void ssh_gssapi_buildmic(Buffer *, const char *, const char *, const char *);
119int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *); 136int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *, const char *);
137OM_uint32 ssh_gssapi_client_identity(Gssctxt *, const char *);
138int ssh_gssapi_credentials_updated(Gssctxt *);
120 139
121/* In the server */ 140/* In the server */
141typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *,
142 const char *);
143char *ssh_gssapi_client_mechanisms(const char *, const char *);
144char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *,
145 const char *);
146gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
147int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *,
148 const char *);
122OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID); 149OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
123int ssh_gssapi_userok(char *name); 150int ssh_gssapi_userok(char *name, struct passwd *);
124OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t); 151OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
125void ssh_gssapi_do_child(char ***, u_int *); 152void ssh_gssapi_do_child(char ***, u_int *);
126void ssh_gssapi_cleanup_creds(void); 153void ssh_gssapi_cleanup_creds(void);
127void ssh_gssapi_storecreds(void); 154void ssh_gssapi_storecreds(void);
128 155
156char *ssh_gssapi_server_mechanisms(void);
157int ssh_gssapi_oid_table_ok();
158
159int ssh_gssapi_update_creds(ssh_gssapi_ccache *store);
129#endif /* GSSAPI */ 160#endif /* GSSAPI */
130 161
131#endif /* _SSH_GSS_H */ 162#endif /* _SSH_GSS_H */
diff --git a/ssh_config b/ssh_config
index 18936740f..2c06ba707 100644
--- a/ssh_config
+++ b/ssh_config
@@ -26,6 +26,8 @@
26# HostbasedAuthentication no 26# HostbasedAuthentication no
27# GSSAPIAuthentication no 27# GSSAPIAuthentication no
28# GSSAPIDelegateCredentials no 28# GSSAPIDelegateCredentials no
29# GSSAPIKeyExchange no
30# GSSAPITrustDNS no
29# BatchMode no 31# BatchMode no
30# CheckHostIP yes 32# CheckHostIP yes
31# AddressFamily any 33# AddressFamily any
diff --git a/ssh_config.5 b/ssh_config.5
index 36b1af195..1c118eefc 100644
--- a/ssh_config.5
+++ b/ssh_config.5
@@ -527,11 +527,43 @@ Specifies whether user authentication based on GSSAPI is allowed.
527The default is 527The default is
528.Dq no . 528.Dq no .
529Note that this option applies to protocol version 2 only. 529Note that this option applies to protocol version 2 only.
530.It Cm GSSAPIKeyExchange
531Specifies whether key exchange based on GSSAPI may be used. When using
532GSSAPI key exchange the server need not have a host key.
533The default is
534.Dq no .
535Note that this option applies to protocol version 2 only.
536.It Cm GSSAPIClientIdentity
537If set, specifies the GSSAPI client identity that ssh should use when
538connecting to the server. The default is unset, which means that the default
539identity will be used.
540.It Cm GSSAPIServerIdentity
541If set, specifies the GSSAPI server identity that ssh should expect when
542connecting to the server. The default is unset, which means that the
543expected GSSAPI server identity will be determined from the target
544hostname.
530.It Cm GSSAPIDelegateCredentials 545.It Cm GSSAPIDelegateCredentials
531Forward (delegate) credentials to the server. 546Forward (delegate) credentials to the server.
532The default is 547The default is
533.Dq no . 548.Dq no .
534Note that this option applies to protocol version 2 only. 549Note that this option applies to protocol version 2 connections using GSSAPI.
550.It Cm GSSAPIRenewalForcesRekey
551If set to
552.Dq yes
553then renewal of the client's GSSAPI credentials will force the rekeying of the
554ssh connection. With a compatible server, this can delegate the renewed
555credentials to a session on the server.
556The default is
557.Dq no .
558.It Cm GSSAPITrustDns
559Set to
560.Dq yes to indicate that the DNS is trusted to securely canonicalize
561the name of the host being connected to. If
562.Dq no, the hostname entered on the
563command line will be passed untouched to the GSSAPI library.
564The default is
565.Dq no .
566This option only applies to protocol version 2 connections using GSSAPI.
535.It Cm HashKnownHosts 567.It Cm HashKnownHosts
536Indicates that 568Indicates that
537.Xr ssh 1 569.Xr ssh 1
diff --git a/sshconnect2.c b/sshconnect2.c
index 7c369d743..11dd3e720 100644
--- a/sshconnect2.c
+++ b/sshconnect2.c
@@ -160,9 +160,34 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
160{ 160{
161 Kex *kex; 161 Kex *kex;
162 162
163#ifdef GSSAPI
164 char *orig = NULL, *gss = NULL;
165 char *gss_host = NULL;
166#endif
167
163 xxx_host = host; 168 xxx_host = host;
164 xxx_hostaddr = hostaddr; 169 xxx_hostaddr = hostaddr;
165 170
171#ifdef GSSAPI
172 if (options.gss_keyex) {
173 /* Add the GSSAPI mechanisms currently supported on this
174 * client to the key exchange algorithm proposal */
175 orig = myproposal[PROPOSAL_KEX_ALGS];
176
177 if (options.gss_trust_dns)
178 gss_host = (char *)get_canonical_hostname(1);
179 else
180 gss_host = host;
181
182 gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
183 if (gss) {
184 debug("Offering GSSAPI proposal: %s", gss);
185 xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
186 "%s,%s", gss, orig);
187 }
188 }
189#endif
190
166 if (options.ciphers == (char *)-1) { 191 if (options.ciphers == (char *)-1) {
167 logit("No valid ciphers for protocol version 2 given, using defaults."); 192 logit("No valid ciphers for protocol version 2 given, using defaults.");
168 options.ciphers = NULL; 193 options.ciphers = NULL;
@@ -197,6 +222,17 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
197 if (options.kex_algorithms != NULL) 222 if (options.kex_algorithms != NULL)
198 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms; 223 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
199 224
225#ifdef GSSAPI
226 /* If we've got GSSAPI algorithms, then we also support the
227 * 'null' hostkey, as a last resort */
228 if (options.gss_keyex && gss) {
229 orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
230 xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
231 "%s,null", orig);
232 xfree(gss);
233 }
234#endif
235
200 if (options.rekey_limit) 236 if (options.rekey_limit)
201 packet_set_rekey_limit((u_int32_t)options.rekey_limit); 237 packet_set_rekey_limit((u_int32_t)options.rekey_limit);
202 238
@@ -207,10 +243,30 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
207 kex->kex[KEX_DH_GEX_SHA1] = kexgex_client; 243 kex->kex[KEX_DH_GEX_SHA1] = kexgex_client;
208 kex->kex[KEX_DH_GEX_SHA256] = kexgex_client; 244 kex->kex[KEX_DH_GEX_SHA256] = kexgex_client;
209 kex->kex[KEX_ECDH_SHA2] = kexecdh_client; 245 kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
246#ifdef GSSAPI
247 if (options.gss_keyex) {
248 kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client;
249 kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client;
250 kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
251 }
252#endif
210 kex->client_version_string=client_version_string; 253 kex->client_version_string=client_version_string;
211 kex->server_version_string=server_version_string; 254 kex->server_version_string=server_version_string;
212 kex->verify_host_key=&verify_host_key_callback; 255 kex->verify_host_key=&verify_host_key_callback;
213 256
257#ifdef GSSAPI
258 if (options.gss_keyex) {
259 kex->gss_deleg_creds = options.gss_deleg_creds;
260 kex->gss_trust_dns = options.gss_trust_dns;
261 kex->gss_client = options.gss_client_identity;
262 if (options.gss_server_identity) {
263 kex->gss_host = options.gss_server_identity;
264 } else {
265 kex->gss_host = gss_host;
266 }
267 }
268#endif
269
214 xxx_kex = kex; 270 xxx_kex = kex;
215 271
216 dispatch_run(DISPATCH_BLOCK, &kex->done, kex); 272 dispatch_run(DISPATCH_BLOCK, &kex->done, kex);
@@ -305,6 +361,7 @@ void input_gssapi_token(int type, u_int32_t, void *);
305void input_gssapi_hash(int type, u_int32_t, void *); 361void input_gssapi_hash(int type, u_int32_t, void *);
306void input_gssapi_error(int, u_int32_t, void *); 362void input_gssapi_error(int, u_int32_t, void *);
307void input_gssapi_errtok(int, u_int32_t, void *); 363void input_gssapi_errtok(int, u_int32_t, void *);
364int userauth_gsskeyex(Authctxt *authctxt);
308#endif 365#endif
309 366
310void userauth(Authctxt *, char *); 367void userauth(Authctxt *, char *);
@@ -320,6 +377,11 @@ static char *authmethods_get(void);
320 377
321Authmethod authmethods[] = { 378Authmethod authmethods[] = {
322#ifdef GSSAPI 379#ifdef GSSAPI
380 {"gssapi-keyex",
381 userauth_gsskeyex,
382 NULL,
383 &options.gss_authentication,
384 NULL},
323 {"gssapi-with-mic", 385 {"gssapi-with-mic",
324 userauth_gssapi, 386 userauth_gssapi,
325 NULL, 387 NULL,
@@ -626,19 +688,31 @@ userauth_gssapi(Authctxt *authctxt)
626 static u_int mech = 0; 688 static u_int mech = 0;
627 OM_uint32 min; 689 OM_uint32 min;
628 int ok = 0; 690 int ok = 0;
691 const char *gss_host;
692
693 if (options.gss_server_identity)
694 gss_host = options.gss_server_identity;
695 else if (options.gss_trust_dns)
696 gss_host = get_canonical_hostname(1);
697 else
698 gss_host = authctxt->host;
629 699
630 /* Try one GSSAPI method at a time, rather than sending them all at 700 /* Try one GSSAPI method at a time, rather than sending them all at
631 * once. */ 701 * once. */
632 702
633 if (gss_supported == NULL) 703 if (gss_supported == NULL)
634 gss_indicate_mechs(&min, &gss_supported); 704 if (GSS_ERROR(gss_indicate_mechs(&min, &gss_supported))) {
705 gss_supported = NULL;
706 return 0;
707 }
635 708
636 /* Check to see if the mechanism is usable before we offer it */ 709 /* Check to see if the mechanism is usable before we offer it */
637 while (mech < gss_supported->count && !ok) { 710 while (mech < gss_supported->count && !ok) {
638 /* My DER encoding requires length<128 */ 711 /* My DER encoding requires length<128 */
639 if (gss_supported->elements[mech].length < 128 && 712 if (gss_supported->elements[mech].length < 128 &&
640 ssh_gssapi_check_mechanism(&gssctxt, 713 ssh_gssapi_check_mechanism(&gssctxt,
641 &gss_supported->elements[mech], authctxt->host)) { 714 &gss_supported->elements[mech], gss_host,
715 options.gss_client_identity)) {
642 ok = 1; /* Mechanism works */ 716 ok = 1; /* Mechanism works */
643 } else { 717 } else {
644 mech++; 718 mech++;
@@ -735,8 +809,8 @@ input_gssapi_response(int type, u_int32_t plen, void *ctxt)
735{ 809{
736 Authctxt *authctxt = ctxt; 810 Authctxt *authctxt = ctxt;
737 Gssctxt *gssctxt; 811 Gssctxt *gssctxt;
738 int oidlen; 812 u_int oidlen;
739 char *oidv; 813 u_char *oidv;
740 814
741 if (authctxt == NULL) 815 if (authctxt == NULL)
742 fatal("input_gssapi_response: no authentication context"); 816 fatal("input_gssapi_response: no authentication context");
@@ -846,6 +920,48 @@ input_gssapi_error(int type, u_int32_t plen, void *ctxt)
846 xfree(msg); 920 xfree(msg);
847 xfree(lang); 921 xfree(lang);
848} 922}
923
924int
925userauth_gsskeyex(Authctxt *authctxt)
926{
927 Buffer b;
928 gss_buffer_desc gssbuf;
929 gss_buffer_desc mic = GSS_C_EMPTY_BUFFER;
930 OM_uint32 ms;
931
932 static int attempt = 0;
933 if (attempt++ >= 1)
934 return (0);
935
936 if (gss_kex_context == NULL) {
937 debug("No valid Key exchange context");
938 return (0);
939 }
940
941 ssh_gssapi_buildmic(&b, authctxt->server_user, authctxt->service,
942 "gssapi-keyex");
943
944 gssbuf.value = buffer_ptr(&b);
945 gssbuf.length = buffer_len(&b);
946
947 if (GSS_ERROR(ssh_gssapi_sign(gss_kex_context, &gssbuf, &mic))) {
948 buffer_free(&b);
949 return (0);
950 }
951
952 packet_start(SSH2_MSG_USERAUTH_REQUEST);
953 packet_put_cstring(authctxt->server_user);
954 packet_put_cstring(authctxt->service);
955 packet_put_cstring(authctxt->method->name);
956 packet_put_string(mic.value, mic.length);
957 packet_send();
958
959 buffer_free(&b);
960 gss_release_buffer(&ms, &mic);
961
962 return (1);
963}
964
849#endif /* GSSAPI */ 965#endif /* GSSAPI */
850 966
851int 967int
diff --git a/sshd.c b/sshd.c
index 9aff5e8af..6b2f59220 100644
--- a/sshd.c
+++ b/sshd.c
@@ -121,6 +121,10 @@
121#include "ssh-sandbox.h" 121#include "ssh-sandbox.h"
122#include "version.h" 122#include "version.h"
123 123
124#ifdef USE_SECURITY_SESSION_API
125#include <Security/AuthSession.h>
126#endif
127
124#ifdef LIBWRAP 128#ifdef LIBWRAP
125#include <tcpd.h> 129#include <tcpd.h>
126#include <syslog.h> 130#include <syslog.h>
@@ -1607,10 +1611,13 @@ main(int ac, char **av)
1607 logit("Disabling protocol version 1. Could not load host key"); 1611 logit("Disabling protocol version 1. Could not load host key");
1608 options.protocol &= ~SSH_PROTO_1; 1612 options.protocol &= ~SSH_PROTO_1;
1609 } 1613 }
1614#ifndef GSSAPI
1615 /* The GSSAPI key exchange can run without a host key */
1610 if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) { 1616 if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) {
1611 logit("Disabling protocol version 2. Could not load host key"); 1617 logit("Disabling protocol version 2. Could not load host key");
1612 options.protocol &= ~SSH_PROTO_2; 1618 options.protocol &= ~SSH_PROTO_2;
1613 } 1619 }
1620#endif
1614 if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) { 1621 if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) {
1615 logit("sshd: no hostkeys available -- exiting."); 1622 logit("sshd: no hostkeys available -- exiting.");
1616 exit(1); 1623 exit(1);
@@ -1938,6 +1945,60 @@ main(int ac, char **av)
1938 /* Log the connection. */ 1945 /* Log the connection. */
1939 verbose("Connection from %.500s port %d", remote_ip, remote_port); 1946 verbose("Connection from %.500s port %d", remote_ip, remote_port);
1940 1947
1948#ifdef USE_SECURITY_SESSION_API
1949 /*
1950 * Create a new security session for use by the new user login if
1951 * the current session is the root session or we are not launched
1952 * by inetd (eg: debugging mode or server mode). We do not
1953 * necessarily need to create a session if we are launched from
1954 * inetd because Panther xinetd will create a session for us.
1955 *
1956 * The only case where this logic will fail is if there is an
1957 * inetd running in a non-root session which is not creating
1958 * new sessions for us. Then all the users will end up in the
1959 * same session (bad).
1960 *
1961 * When the client exits, the session will be destroyed for us
1962 * automatically.
1963 *
1964 * We must create the session before any credentials are stored
1965 * (including AFS pags, which happens a few lines below).
1966 */
1967 {
1968 OSStatus err = 0;
1969 SecuritySessionId sid = 0;
1970 SessionAttributeBits sattrs = 0;
1971
1972 err = SessionGetInfo(callerSecuritySession, &sid, &sattrs);
1973 if (err)
1974 error("SessionGetInfo() failed with error %.8X",
1975 (unsigned) err);
1976 else
1977 debug("Current Session ID is %.8X / Session Attributes are %.8X",
1978 (unsigned) sid, (unsigned) sattrs);
1979
1980 if (inetd_flag && !(sattrs & sessionIsRoot))
1981 debug("Running in inetd mode in a non-root session... "
1982 "assuming inetd created the session for us.");
1983 else {
1984 debug("Creating new security session...");
1985 err = SessionCreate(0, sessionHasTTY | sessionIsRemote);
1986 if (err)
1987 error("SessionCreate() failed with error %.8X",
1988 (unsigned) err);
1989
1990 err = SessionGetInfo(callerSecuritySession, &sid,
1991 &sattrs);
1992 if (err)
1993 error("SessionGetInfo() failed with error %.8X",
1994 (unsigned) err);
1995 else
1996 debug("New Session ID is %.8X / Session Attributes are %.8X",
1997 (unsigned) sid, (unsigned) sattrs);
1998 }
1999 }
2000#endif
2001
1941 /* 2002 /*
1942 * We don't want to listen forever unless the other side 2003 * We don't want to listen forever unless the other side
1943 * successfully authenticates itself. So we set up an alarm which is 2004 * successfully authenticates itself. So we set up an alarm which is
@@ -2319,6 +2380,48 @@ do_ssh2_kex(void)
2319 2380
2320 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types(); 2381 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types();
2321 2382
2383#ifdef GSSAPI
2384 {
2385 char *orig;
2386 char *gss = NULL;
2387 char *newstr = NULL;
2388 orig = myproposal[PROPOSAL_KEX_ALGS];
2389
2390 /*
2391 * If we don't have a host key, then there's no point advertising
2392 * the other key exchange algorithms
2393 */
2394
2395 if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
2396 orig = NULL;
2397
2398 if (options.gss_keyex)
2399 gss = ssh_gssapi_server_mechanisms();
2400 else
2401 gss = NULL;
2402
2403 if (gss && orig)
2404 xasprintf(&newstr, "%s,%s", gss, orig);
2405 else if (gss)
2406 newstr = gss;
2407 else if (orig)
2408 newstr = orig;
2409
2410 /*
2411 * If we've got GSSAPI mechanisms, then we've got the 'null' host
2412 * key alg, but we can't tell people about it unless its the only
2413 * host key algorithm we support
2414 */
2415 if (gss && (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS])) == 0)
2416 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = "null";
2417
2418 if (newstr)
2419 myproposal[PROPOSAL_KEX_ALGS] = newstr;
2420 else
2421 fatal("No supported key exchange algorithms");
2422 }
2423#endif
2424
2322 /* start key exchange */ 2425 /* start key exchange */
2323 kex = kex_setup(myproposal); 2426 kex = kex_setup(myproposal);
2324 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server; 2427 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
@@ -2326,6 +2429,13 @@ do_ssh2_kex(void)
2326 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; 2429 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
2327 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; 2430 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
2328 kex->kex[KEX_ECDH_SHA2] = kexecdh_server; 2431 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
2432#ifdef GSSAPI
2433 if (options.gss_keyex) {
2434 kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
2435 kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
2436 kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
2437 }
2438#endif
2329 kex->server = 1; 2439 kex->server = 1;
2330 kex->client_version_string=client_version_string; 2440 kex->client_version_string=client_version_string;
2331 kex->server_version_string=server_version_string; 2441 kex->server_version_string=server_version_string;
diff --git a/sshd_config b/sshd_config
index 9424ee2c6..2e3cca499 100644
--- a/sshd_config
+++ b/sshd_config
@@ -77,6 +77,8 @@ AuthorizedKeysFile .ssh/authorized_keys
77# GSSAPI options 77# GSSAPI options
78#GSSAPIAuthentication no 78#GSSAPIAuthentication no
79#GSSAPICleanupCredentials yes 79#GSSAPICleanupCredentials yes
80#GSSAPIStrictAcceptorCheck yes
81#GSSAPIKeyExchange no
80 82
81# Set this to 'yes' to enable PAM authentication, account processing, 83# Set this to 'yes' to enable PAM authentication, account processing,
82# and session processing. If this is enabled, PAM authentication will 84# and session processing. If this is enabled, PAM authentication will
diff --git a/sshd_config.5 b/sshd_config.5
index 314ecfb0e..ef4164edd 100644
--- a/sshd_config.5
+++ b/sshd_config.5
@@ -426,12 +426,40 @@ Specifies whether user authentication based on GSSAPI is allowed.
426The default is 426The default is
427.Dq no . 427.Dq no .
428Note that this option applies to protocol version 2 only. 428Note that this option applies to protocol version 2 only.
429.It Cm GSSAPIKeyExchange
430Specifies whether key exchange based on GSSAPI is allowed. GSSAPI key exchange
431doesn't rely on ssh keys to verify host identity.
432The default is
433.Dq no .
434Note that this option applies to protocol version 2 only.
429.It Cm GSSAPICleanupCredentials 435.It Cm GSSAPICleanupCredentials
430Specifies whether to automatically destroy the user's credentials cache 436Specifies whether to automatically destroy the user's credentials cache
431on logout. 437on logout.
432The default is 438The default is
433.Dq yes . 439.Dq yes .
434Note that this option applies to protocol version 2 only. 440Note that this option applies to protocol version 2 only.
441.It Cm GSSAPIStrictAcceptorCheck
442Determines whether to be strict about the identity of the GSSAPI acceptor
443a client authenticates against. If
444.Dq yes
445then the client must authenticate against the
446.Pa host
447service on the current hostname. If
448.Dq no
449then the client may authenticate against any service key stored in the
450machine's default store. This facility is provided to assist with operation
451on multi homed machines.
452The default is
453.Dq yes .
454Note that this option applies only to protocol version 2 GSSAPI connections,
455and setting it to
456.Dq no
457may only work with recent Kerberos GSSAPI libraries.
458.It Cm GSSAPIStoreCredentialsOnRekey
459Controls whether the user's GSSAPI credentials should be updated following a
460successful connection rekeying. This option can be used to accepted renewed
461or updated credentials from a compatible client. The default is
462.Dq no .
435.It Cm HostbasedAuthentication 463.It Cm HostbasedAuthentication
436Specifies whether rhosts or /etc/hosts.equiv authentication together 464Specifies whether rhosts or /etc/hosts.equiv authentication together
437with successful public key client host authentication is allowed 465with successful public key client host authentication is allowed