diff options
Diffstat (limited to 'debian/patches/gssapi.patch')
-rw-r--r-- | debian/patches/gssapi.patch | 3321 |
1 files changed, 3321 insertions, 0 deletions
diff --git a/debian/patches/gssapi.patch b/debian/patches/gssapi.patch new file mode 100644 index 000000000..25edd5cbe --- /dev/null +++ b/debian/patches/gssapi.patch | |||
@@ -0,0 +1,3321 @@ | |||
1 | From e6c7c11ac2576ac62334616bd4408bf64140bba7 Mon Sep 17 00:00:00 2001 | ||
2 | From: Simon Wilkinson <simon@sxw.org.uk> | ||
3 | Date: Sun, 9 Feb 2014 16:09:48 +0000 | ||
4 | Subject: GSSAPI key exchange support | ||
5 | |||
6 | This patch has been rejected upstream: "None of the OpenSSH developers are | ||
7 | in favour of adding this, and this situation has not changed for several | ||
8 | years. This is not a slight on Simon's patch, which is of fine quality, but | ||
9 | just that a) we don't trust GSSAPI implementations that much and b) we don't | ||
10 | like adding new KEX since they are pre-auth attack surface. This one is | ||
11 | particularly scary, since it requires hooks out to typically root-owned | ||
12 | system resources." | ||
13 | |||
14 | However, quite a lot of people rely on this in Debian, and it's better to | ||
15 | have it merged into the main openssh package rather than having separate | ||
16 | -krb5 packages (as we used to have). It seems to have a generally good | ||
17 | security history. | ||
18 | |||
19 | Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1242 | ||
20 | Last-Updated: 2018-08-24 | ||
21 | |||
22 | Patch-Name: gssapi.patch | ||
23 | --- | ||
24 | ChangeLog.gssapi | 113 ++++++++++++++++ | ||
25 | Makefile.in | 3 +- | ||
26 | auth-krb5.c | 17 ++- | ||
27 | auth.c | 96 +------------- | ||
28 | auth2-gss.c | 54 +++++++- | ||
29 | auth2.c | 2 + | ||
30 | canohost.c | 93 +++++++++++++ | ||
31 | canohost.h | 3 + | ||
32 | clientloop.c | 15 ++- | ||
33 | config.h.in | 6 + | ||
34 | configure.ac | 24 ++++ | ||
35 | gss-genr.c | 277 +++++++++++++++++++++++++++++++++++++- | ||
36 | gss-serv-krb5.c | 85 +++++++++++- | ||
37 | gss-serv.c | 184 ++++++++++++++++++++++++-- | ||
38 | kex.c | 19 +++ | ||
39 | kex.h | 14 ++ | ||
40 | kexgssc.c | 338 +++++++++++++++++++++++++++++++++++++++++++++++ | ||
41 | kexgsss.c | 295 +++++++++++++++++++++++++++++++++++++++++ | ||
42 | monitor.c | 122 +++++++++++++++-- | ||
43 | monitor.h | 3 + | ||
44 | monitor_wrap.c | 53 +++++++- | ||
45 | monitor_wrap.h | 4 +- | ||
46 | readconf.c | 43 ++++++ | ||
47 | readconf.h | 5 + | ||
48 | servconf.c | 26 ++++ | ||
49 | servconf.h | 2 + | ||
50 | ssh-gss.h | 41 +++++- | ||
51 | ssh_config | 2 + | ||
52 | ssh_config.5 | 32 +++++ | ||
53 | sshconnect2.c | 133 ++++++++++++++++++- | ||
54 | sshd.c | 112 +++++++++++++++- | ||
55 | sshd_config | 2 + | ||
56 | sshd_config.5 | 10 ++ | ||
57 | sshkey.c | 3 +- | ||
58 | sshkey.h | 1 + | ||
59 | 35 files changed, 2087 insertions(+), 145 deletions(-) | ||
60 | create mode 100644 ChangeLog.gssapi | ||
61 | create mode 100644 kexgssc.c | ||
62 | create mode 100644 kexgsss.c | ||
63 | |||
64 | diff --git a/ChangeLog.gssapi b/ChangeLog.gssapi | ||
65 | new file mode 100644 | ||
66 | index 000000000..f117a336a | ||
67 | --- /dev/null | ||
68 | +++ b/ChangeLog.gssapi | ||
69 | @@ -0,0 +1,113 @@ | ||
70 | +20110101 | ||
71 | + - Finally update for OpenSSH 5.6p1 | ||
72 | + - Add GSSAPIServerIdentity option from Jim Basney | ||
73 | + | ||
74 | +20100308 | ||
75 | + - [ Makefile.in, key.c, key.h ] | ||
76 | + Updates for OpenSSH 5.4p1 | ||
77 | + - [ servconf.c ] | ||
78 | + Include GSSAPI options in the sshd -T configuration dump, and flag | ||
79 | + some older configuration options as being unsupported. Thanks to Colin | ||
80 | + Watson. | ||
81 | + - | ||
82 | + | ||
83 | +20100124 | ||
84 | + - [ sshconnect2.c ] | ||
85 | + Adapt to deal with additional element in Authmethod structure. Thanks to | ||
86 | + Colin Watson | ||
87 | + | ||
88 | +20090615 | ||
89 | + - [ gss-genr.c gss-serv.c kexgssc.c kexgsss.c monitor.c sshconnect2.c | ||
90 | + sshd.c ] | ||
91 | + Fix issues identified by Greg Hudson following a code review | ||
92 | + Check return value of gss_indicate_mechs | ||
93 | + Protect GSSAPI calls in monitor, so they can only be used if enabled | ||
94 | + Check return values of bignum functions in key exchange | ||
95 | + Use BN_clear_free to clear other side's DH value | ||
96 | + Make ssh_gssapi_id_kex more robust | ||
97 | + Only configure kex table pointers if GSSAPI is enabled | ||
98 | + Don't leak mechanism list, or gss mechanism list | ||
99 | + Cast data.length before printing | ||
100 | + If serverkey isn't provided, use an empty string, rather than NULL | ||
101 | + | ||
102 | +20090201 | ||
103 | + - [ gss-genr.c gss-serv.c kex.h kexgssc.c readconf.c readconf.h ssh-gss.h | ||
104 | + ssh_config.5 sshconnet2.c ] | ||
105 | + Add support for the GSSAPIClientIdentity option, which allows the user | ||
106 | + to specify which GSSAPI identity to use to contact a given server | ||
107 | + | ||
108 | +20080404 | ||
109 | + - [ gss-serv.c ] | ||
110 | + Add code to actually implement GSSAPIStrictAcceptCheck, which had somehow | ||
111 | + been omitted from a previous version of this patch. Reported by Borislav | ||
112 | + Stoichkov | ||
113 | + | ||
114 | +20070317 | ||
115 | + - [ gss-serv-krb5.c ] | ||
116 | + Remove C99ism, where new_ccname was being declared in the middle of a | ||
117 | + function | ||
118 | + | ||
119 | +20061220 | ||
120 | + - [ servconf.c ] | ||
121 | + Make default for GSSAPIStrictAcceptorCheck be Yes, to match previous, and | ||
122 | + documented, behaviour. Reported by Dan Watson. | ||
123 | + | ||
124 | +20060910 | ||
125 | + - [ gss-genr.c kexgssc.c kexgsss.c kex.h monitor.c sshconnect2.c sshd.c | ||
126 | + ssh-gss.h ] | ||
127 | + add support for gss-group14-sha1 key exchange mechanisms | ||
128 | + - [ gss-serv.c servconf.c servconf.h sshd_config sshd_config.5 ] | ||
129 | + Add GSSAPIStrictAcceptorCheck option to allow the disabling of | ||
130 | + acceptor principal checking on multi-homed machines. | ||
131 | + <Bugzilla #928> | ||
132 | + - [ sshd_config ssh_config ] | ||
133 | + Add settings for GSSAPIKeyExchange and GSSAPITrustDNS to the sample | ||
134 | + configuration files | ||
135 | + - [ kexgss.c kegsss.c sshconnect2.c sshd.c ] | ||
136 | + Code cleanup. Replace strlen/xmalloc/snprintf sequences with xasprintf() | ||
137 | + Limit length of error messages displayed by client | ||
138 | + | ||
139 | +20060909 | ||
140 | + - [ gss-genr.c gss-serv.c ] | ||
141 | + move ssh_gssapi_acquire_cred() and ssh_gssapi_server_ctx to be server | ||
142 | + only, where they belong | ||
143 | + <Bugzilla #1225> | ||
144 | + | ||
145 | +20060829 | ||
146 | + - [ gss-serv-krb5.c ] | ||
147 | + Fix CCAPI credentials cache name when creating KRB5CCNAME environment | ||
148 | + variable | ||
149 | + | ||
150 | +20060828 | ||
151 | + - [ gss-genr.c ] | ||
152 | + Avoid Heimdal context freeing problem | ||
153 | + <Fixed upstream 20060829> | ||
154 | + | ||
155 | +20060818 | ||
156 | + - [ gss-genr.c ssh-gss.h sshconnect2.c ] | ||
157 | + Make sure that SPENGO is disabled | ||
158 | + <Bugzilla #1218 - Fixed upstream 20060818> | ||
159 | + | ||
160 | +20060421 | ||
161 | + - [ gssgenr.c, sshconnect2.c ] | ||
162 | + a few type changes (signed versus unsigned, int versus size_t) to | ||
163 | + fix compiler errors/warnings | ||
164 | + (from jbasney AT ncsa.uiuc.edu) | ||
165 | + - [ kexgssc.c, sshconnect2.c ] | ||
166 | + fix uninitialized variable warnings | ||
167 | + (from jbasney AT ncsa.uiuc.edu) | ||
168 | + - [ gssgenr.c ] | ||
169 | + pass oid to gss_display_status (helpful when using GSSAPI mechglue) | ||
170 | + (from jbasney AT ncsa.uiuc.edu) | ||
171 | + <Bugzilla #1220 > | ||
172 | + - [ gss-serv-krb5.c ] | ||
173 | + #ifdef HAVE_GSSAPI_KRB5 should be #ifdef HAVE_GSSAPI_KRB5_H | ||
174 | + (from jbasney AT ncsa.uiuc.edu) | ||
175 | + <Fixed upstream 20060304> | ||
176 | + - [ readconf.c, readconf.h, ssh_config.5, sshconnect2.c | ||
177 | + add client-side GssapiKeyExchange option | ||
178 | + (from jbasney AT ncsa.uiuc.edu) | ||
179 | + - [ sshconnect2.c ] | ||
180 | + add support for GssapiTrustDns option for gssapi-with-mic | ||
181 | + (from jbasney AT ncsa.uiuc.edu) | ||
182 | + <gssapi-with-mic support is Bugzilla #1008> | ||
183 | diff --git a/Makefile.in b/Makefile.in | ||
184 | index 2385c62a8..6175c6063 100644 | ||
185 | --- a/Makefile.in | ||
186 | +++ b/Makefile.in | ||
187 | @@ -100,6 +100,7 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \ | ||
188 | kex.o kexdh.o kexgex.o kexecdh.o kexc25519.o \ | ||
189 | kexdhc.o kexgexc.o kexecdhc.o kexc25519c.o \ | ||
190 | kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o \ | ||
191 | + kexgssc.o \ | ||
192 | platform-pledge.o platform-tracing.o platform-misc.o | ||
193 | |||
194 | SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \ | ||
195 | @@ -113,7 +114,7 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o \ | ||
196 | auth-bsdauth.o auth2-hostbased.o auth2-kbdint.o \ | ||
197 | auth2-none.o auth2-passwd.o auth2-pubkey.o \ | ||
198 | monitor.o monitor_wrap.o auth-krb5.o \ | ||
199 | - auth2-gss.o gss-serv.o gss-serv-krb5.o \ | ||
200 | + auth2-gss.o gss-serv.o gss-serv-krb5.o kexgsss.o \ | ||
201 | loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \ | ||
202 | sftp-server.o sftp-common.o \ | ||
203 | sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \ | ||
204 | diff --git a/auth-krb5.c b/auth-krb5.c | ||
205 | index 3096f1c8e..204752e1b 100644 | ||
206 | --- a/auth-krb5.c | ||
207 | +++ b/auth-krb5.c | ||
208 | @@ -182,8 +182,13 @@ auth_krb5_password(Authctxt *authctxt, const char *password) | ||
209 | |||
210 | len = strlen(authctxt->krb5_ticket_file) + 6; | ||
211 | authctxt->krb5_ccname = xmalloc(len); | ||
212 | +#ifdef USE_CCAPI | ||
213 | + snprintf(authctxt->krb5_ccname, len, "API:%s", | ||
214 | + authctxt->krb5_ticket_file); | ||
215 | +#else | ||
216 | snprintf(authctxt->krb5_ccname, len, "FILE:%s", | ||
217 | authctxt->krb5_ticket_file); | ||
218 | +#endif | ||
219 | |||
220 | #ifdef USE_PAM | ||
221 | if (options.use_pam) | ||
222 | @@ -240,15 +245,22 @@ krb5_cleanup_proc(Authctxt *authctxt) | ||
223 | #ifndef HEIMDAL | ||
224 | krb5_error_code | ||
225 | ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) { | ||
226 | - int tmpfd, ret, oerrno; | ||
227 | + int ret, oerrno; | ||
228 | char ccname[40]; | ||
229 | mode_t old_umask; | ||
230 | +#ifdef USE_CCAPI | ||
231 | + char cctemplate[] = "API:krb5cc_%d"; | ||
232 | +#else | ||
233 | + char cctemplate[] = "FILE:/tmp/krb5cc_%d_XXXXXXXXXX"; | ||
234 | + int tmpfd; | ||
235 | +#endif | ||
236 | |||
237 | ret = snprintf(ccname, sizeof(ccname), | ||
238 | - "FILE:/tmp/krb5cc_%d_XXXXXXXXXX", geteuid()); | ||
239 | + cctemplate, geteuid()); | ||
240 | if (ret < 0 || (size_t)ret >= sizeof(ccname)) | ||
241 | return ENOMEM; | ||
242 | |||
243 | +#ifndef USE_CCAPI | ||
244 | old_umask = umask(0177); | ||
245 | tmpfd = mkstemp(ccname + strlen("FILE:")); | ||
246 | oerrno = errno; | ||
247 | @@ -265,6 +277,7 @@ ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) { | ||
248 | return oerrno; | ||
249 | } | ||
250 | close(tmpfd); | ||
251 | +#endif | ||
252 | |||
253 | return (krb5_cc_resolve(ctx, ccname, ccache)); | ||
254 | } | ||
255 | diff --git a/auth.c b/auth.c | ||
256 | index 9a3bc96f1..80eb78c48 100644 | ||
257 | --- a/auth.c | ||
258 | +++ b/auth.c | ||
259 | @@ -395,7 +395,8 @@ auth_root_allowed(struct ssh *ssh, const char *method) | ||
260 | case PERMIT_NO_PASSWD: | ||
261 | if (strcmp(method, "publickey") == 0 || | ||
262 | strcmp(method, "hostbased") == 0 || | ||
263 | - strcmp(method, "gssapi-with-mic") == 0) | ||
264 | + strcmp(method, "gssapi-with-mic") == 0 || | ||
265 | + strcmp(method, "gssapi-keyex") == 0) | ||
266 | return 1; | ||
267 | break; | ||
268 | case PERMIT_FORCED_ONLY: | ||
269 | @@ -733,99 +734,6 @@ fakepw(void) | ||
270 | return (&fake); | ||
271 | } | ||
272 | |||
273 | -/* | ||
274 | - * Returns the remote DNS hostname as a string. The returned string must not | ||
275 | - * be freed. NB. this will usually trigger a DNS query the first time it is | ||
276 | - * called. | ||
277 | - * This function does additional checks on the hostname to mitigate some | ||
278 | - * attacks on legacy rhosts-style authentication. | ||
279 | - * XXX is RhostsRSAAuthentication vulnerable to these? | ||
280 | - * XXX Can we remove these checks? (or if not, remove RhostsRSAAuthentication?) | ||
281 | - */ | ||
282 | - | ||
283 | -static char * | ||
284 | -remote_hostname(struct ssh *ssh) | ||
285 | -{ | ||
286 | - struct sockaddr_storage from; | ||
287 | - socklen_t fromlen; | ||
288 | - struct addrinfo hints, *ai, *aitop; | ||
289 | - char name[NI_MAXHOST], ntop2[NI_MAXHOST]; | ||
290 | - const char *ntop = ssh_remote_ipaddr(ssh); | ||
291 | - | ||
292 | - /* Get IP address of client. */ | ||
293 | - fromlen = sizeof(from); | ||
294 | - memset(&from, 0, sizeof(from)); | ||
295 | - if (getpeername(ssh_packet_get_connection_in(ssh), | ||
296 | - (struct sockaddr *)&from, &fromlen) < 0) { | ||
297 | - debug("getpeername failed: %.100s", strerror(errno)); | ||
298 | - return strdup(ntop); | ||
299 | - } | ||
300 | - | ||
301 | - ipv64_normalise_mapped(&from, &fromlen); | ||
302 | - if (from.ss_family == AF_INET6) | ||
303 | - fromlen = sizeof(struct sockaddr_in6); | ||
304 | - | ||
305 | - debug3("Trying to reverse map address %.100s.", ntop); | ||
306 | - /* Map the IP address to a host name. */ | ||
307 | - if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name), | ||
308 | - NULL, 0, NI_NAMEREQD) != 0) { | ||
309 | - /* Host name not found. Use ip address. */ | ||
310 | - return strdup(ntop); | ||
311 | - } | ||
312 | - | ||
313 | - /* | ||
314 | - * if reverse lookup result looks like a numeric hostname, | ||
315 | - * someone is trying to trick us by PTR record like following: | ||
316 | - * 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5 | ||
317 | - */ | ||
318 | - memset(&hints, 0, sizeof(hints)); | ||
319 | - hints.ai_socktype = SOCK_DGRAM; /*dummy*/ | ||
320 | - hints.ai_flags = AI_NUMERICHOST; | ||
321 | - if (getaddrinfo(name, NULL, &hints, &ai) == 0) { | ||
322 | - logit("Nasty PTR record \"%s\" is set up for %s, ignoring", | ||
323 | - name, ntop); | ||
324 | - freeaddrinfo(ai); | ||
325 | - return strdup(ntop); | ||
326 | - } | ||
327 | - | ||
328 | - /* Names are stored in lowercase. */ | ||
329 | - lowercase(name); | ||
330 | - | ||
331 | - /* | ||
332 | - * Map it back to an IP address and check that the given | ||
333 | - * address actually is an address of this host. This is | ||
334 | - * necessary because anyone with access to a name server can | ||
335 | - * define arbitrary names for an IP address. Mapping from | ||
336 | - * name to IP address can be trusted better (but can still be | ||
337 | - * fooled if the intruder has access to the name server of | ||
338 | - * the domain). | ||
339 | - */ | ||
340 | - memset(&hints, 0, sizeof(hints)); | ||
341 | - hints.ai_family = from.ss_family; | ||
342 | - hints.ai_socktype = SOCK_STREAM; | ||
343 | - if (getaddrinfo(name, NULL, &hints, &aitop) != 0) { | ||
344 | - logit("reverse mapping checking getaddrinfo for %.700s " | ||
345 | - "[%s] failed.", name, ntop); | ||
346 | - return strdup(ntop); | ||
347 | - } | ||
348 | - /* Look for the address from the list of addresses. */ | ||
349 | - for (ai = aitop; ai; ai = ai->ai_next) { | ||
350 | - if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop2, | ||
351 | - sizeof(ntop2), NULL, 0, NI_NUMERICHOST) == 0 && | ||
352 | - (strcmp(ntop, ntop2) == 0)) | ||
353 | - break; | ||
354 | - } | ||
355 | - freeaddrinfo(aitop); | ||
356 | - /* If we reached the end of the list, the address was not there. */ | ||
357 | - if (ai == NULL) { | ||
358 | - /* Address not found for the host name. */ | ||
359 | - logit("Address %.100s maps to %.600s, but this does not " | ||
360 | - "map back to the address.", ntop, name); | ||
361 | - return strdup(ntop); | ||
362 | - } | ||
363 | - return strdup(name); | ||
364 | -} | ||
365 | - | ||
366 | /* | ||
367 | * Return the canonical name of the host in the other side of the current | ||
368 | * connection. The host name is cached, so it is efficient to call this | ||
369 | diff --git a/auth2-gss.c b/auth2-gss.c | ||
370 | index 9351e0428..1f12bb113 100644 | ||
371 | --- a/auth2-gss.c | ||
372 | +++ b/auth2-gss.c | ||
373 | @@ -1,7 +1,7 @@ | ||
374 | /* $OpenBSD: auth2-gss.c,v 1.29 2018/07/31 03:10:27 djm Exp $ */ | ||
375 | |||
376 | /* | ||
377 | - * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. | ||
378 | + * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. | ||
379 | * | ||
380 | * Redistribution and use in source and binary forms, with or without | ||
381 | * modification, are permitted provided that the following conditions | ||
382 | @@ -54,6 +54,46 @@ static int input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh); | ||
383 | static int input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh); | ||
384 | static int input_gssapi_errtok(int, u_int32_t, struct ssh *); | ||
385 | |||
386 | +/* | ||
387 | + * The 'gssapi_keyex' userauth mechanism. | ||
388 | + */ | ||
389 | +static int | ||
390 | +userauth_gsskeyex(struct ssh *ssh) | ||
391 | +{ | ||
392 | + Authctxt *authctxt = ssh->authctxt; | ||
393 | + int r, authenticated = 0; | ||
394 | + struct sshbuf *b; | ||
395 | + gss_buffer_desc mic, gssbuf; | ||
396 | + u_char *p; | ||
397 | + size_t len; | ||
398 | + | ||
399 | + if ((r = sshpkt_get_string(ssh, &p, &len)) != 0 || | ||
400 | + (r = sshpkt_get_end(ssh)) != 0) | ||
401 | + fatal("%s: %s", __func__, ssh_err(r)); | ||
402 | + if ((b = sshbuf_new()) == NULL) | ||
403 | + fatal("%s: sshbuf_new failed", __func__); | ||
404 | + mic.value = p; | ||
405 | + mic.length = len; | ||
406 | + | ||
407 | + ssh_gssapi_buildmic(b, authctxt->user, authctxt->service, | ||
408 | + "gssapi-keyex"); | ||
409 | + | ||
410 | + if ((gssbuf.value = sshbuf_mutable_ptr(b)) == NULL) | ||
411 | + fatal("%s: sshbuf_mutable_ptr failed", __func__); | ||
412 | + gssbuf.length = sshbuf_len(b); | ||
413 | + | ||
414 | + /* gss_kex_context is NULL with privsep, so we can't check it here */ | ||
415 | + if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gss_kex_context, | ||
416 | + &gssbuf, &mic)))) | ||
417 | + authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user, | ||
418 | + authctxt->pw)); | ||
419 | + | ||
420 | + sshbuf_free(b); | ||
421 | + free(mic.value); | ||
422 | + | ||
423 | + return (authenticated); | ||
424 | +} | ||
425 | + | ||
426 | /* | ||
427 | * We only support those mechanisms that we know about (ie ones that we know | ||
428 | * how to check local user kuserok and the like) | ||
429 | @@ -260,7 +300,8 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh) | ||
430 | if ((r = sshpkt_get_end(ssh)) != 0) | ||
431 | fatal("%s: %s", __func__, ssh_err(r)); | ||
432 | |||
433 | - authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user)); | ||
434 | + authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user, | ||
435 | + authctxt->pw)); | ||
436 | |||
437 | if ((!use_privsep || mm_is_monitor()) && | ||
438 | (displayname = ssh_gssapi_displayname()) != NULL) | ||
439 | @@ -306,7 +347,8 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh) | ||
440 | gssbuf.length = sshbuf_len(b); | ||
441 | |||
442 | if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic)))) | ||
443 | - authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user)); | ||
444 | + authenticated = | ||
445 | + PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw)); | ||
446 | else | ||
447 | logit("GSSAPI MIC check failed"); | ||
448 | |||
449 | @@ -326,6 +368,12 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh) | ||
450 | return 0; | ||
451 | } | ||
452 | |||
453 | +Authmethod method_gsskeyex = { | ||
454 | + "gssapi-keyex", | ||
455 | + userauth_gsskeyex, | ||
456 | + &options.gss_authentication | ||
457 | +}; | ||
458 | + | ||
459 | Authmethod method_gssapi = { | ||
460 | "gssapi-with-mic", | ||
461 | userauth_gssapi, | ||
462 | diff --git a/auth2.c b/auth2.c | ||
463 | index ab8795895..96efe164c 100644 | ||
464 | --- a/auth2.c | ||
465 | +++ b/auth2.c | ||
466 | @@ -74,6 +74,7 @@ extern Authmethod method_passwd; | ||
467 | extern Authmethod method_kbdint; | ||
468 | extern Authmethod method_hostbased; | ||
469 | #ifdef GSSAPI | ||
470 | +extern Authmethod method_gsskeyex; | ||
471 | extern Authmethod method_gssapi; | ||
472 | #endif | ||
473 | |||
474 | @@ -81,6 +82,7 @@ Authmethod *authmethods[] = { | ||
475 | &method_none, | ||
476 | &method_pubkey, | ||
477 | #ifdef GSSAPI | ||
478 | + &method_gsskeyex, | ||
479 | &method_gssapi, | ||
480 | #endif | ||
481 | &method_passwd, | ||
482 | diff --git a/canohost.c b/canohost.c | ||
483 | index f71a08568..404731d24 100644 | ||
484 | --- a/canohost.c | ||
485 | +++ b/canohost.c | ||
486 | @@ -35,6 +35,99 @@ | ||
487 | #include "canohost.h" | ||
488 | #include "misc.h" | ||
489 | |||
490 | +/* | ||
491 | + * Returns the remote DNS hostname as a string. The returned string must not | ||
492 | + * be freed. NB. this will usually trigger a DNS query the first time it is | ||
493 | + * called. | ||
494 | + * This function does additional checks on the hostname to mitigate some | ||
495 | + * attacks on legacy rhosts-style authentication. | ||
496 | + * XXX is RhostsRSAAuthentication vulnerable to these? | ||
497 | + * XXX Can we remove these checks? (or if not, remove RhostsRSAAuthentication?) | ||
498 | + */ | ||
499 | + | ||
500 | +char * | ||
501 | +remote_hostname(struct ssh *ssh) | ||
502 | +{ | ||
503 | + struct sockaddr_storage from; | ||
504 | + socklen_t fromlen; | ||
505 | + struct addrinfo hints, *ai, *aitop; | ||
506 | + char name[NI_MAXHOST], ntop2[NI_MAXHOST]; | ||
507 | + const char *ntop = ssh_remote_ipaddr(ssh); | ||
508 | + | ||
509 | + /* Get IP address of client. */ | ||
510 | + fromlen = sizeof(from); | ||
511 | + memset(&from, 0, sizeof(from)); | ||
512 | + if (getpeername(ssh_packet_get_connection_in(ssh), | ||
513 | + (struct sockaddr *)&from, &fromlen) < 0) { | ||
514 | + debug("getpeername failed: %.100s", strerror(errno)); | ||
515 | + return strdup(ntop); | ||
516 | + } | ||
517 | + | ||
518 | + ipv64_normalise_mapped(&from, &fromlen); | ||
519 | + if (from.ss_family == AF_INET6) | ||
520 | + fromlen = sizeof(struct sockaddr_in6); | ||
521 | + | ||
522 | + debug3("Trying to reverse map address %.100s.", ntop); | ||
523 | + /* Map the IP address to a host name. */ | ||
524 | + if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name), | ||
525 | + NULL, 0, NI_NAMEREQD) != 0) { | ||
526 | + /* Host name not found. Use ip address. */ | ||
527 | + return strdup(ntop); | ||
528 | + } | ||
529 | + | ||
530 | + /* | ||
531 | + * if reverse lookup result looks like a numeric hostname, | ||
532 | + * someone is trying to trick us by PTR record like following: | ||
533 | + * 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5 | ||
534 | + */ | ||
535 | + memset(&hints, 0, sizeof(hints)); | ||
536 | + hints.ai_socktype = SOCK_DGRAM; /*dummy*/ | ||
537 | + hints.ai_flags = AI_NUMERICHOST; | ||
538 | + if (getaddrinfo(name, NULL, &hints, &ai) == 0) { | ||
539 | + logit("Nasty PTR record \"%s\" is set up for %s, ignoring", | ||
540 | + name, ntop); | ||
541 | + freeaddrinfo(ai); | ||
542 | + return strdup(ntop); | ||
543 | + } | ||
544 | + | ||
545 | + /* Names are stored in lowercase. */ | ||
546 | + lowercase(name); | ||
547 | + | ||
548 | + /* | ||
549 | + * Map it back to an IP address and check that the given | ||
550 | + * address actually is an address of this host. This is | ||
551 | + * necessary because anyone with access to a name server can | ||
552 | + * define arbitrary names for an IP address. Mapping from | ||
553 | + * name to IP address can be trusted better (but can still be | ||
554 | + * fooled if the intruder has access to the name server of | ||
555 | + * the domain). | ||
556 | + */ | ||
557 | + memset(&hints, 0, sizeof(hints)); | ||
558 | + hints.ai_family = from.ss_family; | ||
559 | + hints.ai_socktype = SOCK_STREAM; | ||
560 | + if (getaddrinfo(name, NULL, &hints, &aitop) != 0) { | ||
561 | + logit("reverse mapping checking getaddrinfo for %.700s " | ||
562 | + "[%s] failed.", name, ntop); | ||
563 | + return strdup(ntop); | ||
564 | + } | ||
565 | + /* Look for the address from the list of addresses. */ | ||
566 | + for (ai = aitop; ai; ai = ai->ai_next) { | ||
567 | + if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop2, | ||
568 | + sizeof(ntop2), NULL, 0, NI_NUMERICHOST) == 0 && | ||
569 | + (strcmp(ntop, ntop2) == 0)) | ||
570 | + break; | ||
571 | + } | ||
572 | + freeaddrinfo(aitop); | ||
573 | + /* If we reached the end of the list, the address was not there. */ | ||
574 | + if (ai == NULL) { | ||
575 | + /* Address not found for the host name. */ | ||
576 | + logit("Address %.100s maps to %.600s, but this does not " | ||
577 | + "map back to the address.", ntop, name); | ||
578 | + return strdup(ntop); | ||
579 | + } | ||
580 | + return strdup(name); | ||
581 | +} | ||
582 | + | ||
583 | void | ||
584 | ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len) | ||
585 | { | ||
586 | diff --git a/canohost.h b/canohost.h | ||
587 | index 26d62855a..0cadc9f18 100644 | ||
588 | --- a/canohost.h | ||
589 | +++ b/canohost.h | ||
590 | @@ -15,6 +15,9 @@ | ||
591 | #ifndef _CANOHOST_H | ||
592 | #define _CANOHOST_H | ||
593 | |||
594 | +struct ssh; | ||
595 | + | ||
596 | +char *remote_hostname(struct ssh *); | ||
597 | char *get_peer_ipaddr(int); | ||
598 | int get_peer_port(int); | ||
599 | char *get_local_ipaddr(int); | ||
600 | diff --git a/clientloop.c b/clientloop.c | ||
601 | index ad35cb7ba..e69c5141f 100644 | ||
602 | --- a/clientloop.c | ||
603 | +++ b/clientloop.c | ||
604 | @@ -112,6 +112,10 @@ | ||
605 | #include "ssherr.h" | ||
606 | #include "hostfile.h" | ||
607 | |||
608 | +#ifdef GSSAPI | ||
609 | +#include "ssh-gss.h" | ||
610 | +#endif | ||
611 | + | ||
612 | /* import options */ | ||
613 | extern Options options; | ||
614 | |||
615 | @@ -1357,9 +1361,18 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, | ||
616 | break; | ||
617 | |||
618 | /* Do channel operations unless rekeying in progress. */ | ||
619 | - if (!ssh_packet_is_rekeying(ssh)) | ||
620 | + if (!ssh_packet_is_rekeying(ssh)) { | ||
621 | channel_after_select(ssh, readset, writeset); | ||
622 | |||
623 | +#ifdef GSSAPI | ||
624 | + if (options.gss_renewal_rekey && | ||
625 | + ssh_gssapi_credentials_updated(NULL)) { | ||
626 | + debug("credentials updated - forcing rekey"); | ||
627 | + need_rekeying = 1; | ||
628 | + } | ||
629 | +#endif | ||
630 | + } | ||
631 | + | ||
632 | /* Buffer input from the connection. */ | ||
633 | client_process_net_input(readset); | ||
634 | |||
635 | diff --git a/config.h.in b/config.h.in | ||
636 | index 7940b4c86..93295da07 100644 | ||
637 | --- a/config.h.in | ||
638 | +++ b/config.h.in | ||
639 | @@ -1749,6 +1749,9 @@ | ||
640 | /* Use btmp to log bad logins */ | ||
641 | #undef USE_BTMP | ||
642 | |||
643 | +/* platform uses an in-memory credentials cache */ | ||
644 | +#undef USE_CCAPI | ||
645 | + | ||
646 | /* Use libedit for sftp */ | ||
647 | #undef USE_LIBEDIT | ||
648 | |||
649 | @@ -1764,6 +1767,9 @@ | ||
650 | /* Use PIPES instead of a socketpair() */ | ||
651 | #undef USE_PIPES | ||
652 | |||
653 | +/* platform has the Security Authorization Session API */ | ||
654 | +#undef USE_SECURITY_SESSION_API | ||
655 | + | ||
656 | /* Define if you have Solaris privileges */ | ||
657 | #undef USE_SOLARIS_PRIVS | ||
658 | |||
659 | diff --git a/configure.ac b/configure.ac | ||
660 | index 83e530750..82428b241 100644 | ||
661 | --- a/configure.ac | ||
662 | +++ b/configure.ac | ||
663 | @@ -673,6 +673,30 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16)) | ||
664 | [Use tunnel device compatibility to OpenBSD]) | ||
665 | AC_DEFINE([SSH_TUN_PREPEND_AF], [1], | ||
666 | [Prepend the address family to IP tunnel traffic]) | ||
667 | + AC_MSG_CHECKING([if we have the Security Authorization Session API]) | ||
668 | + AC_TRY_COMPILE([#include <Security/AuthSession.h>], | ||
669 | + [SessionCreate(0, 0);], | ||
670 | + [ac_cv_use_security_session_api="yes" | ||
671 | + AC_DEFINE([USE_SECURITY_SESSION_API], [1], | ||
672 | + [platform has the Security Authorization Session API]) | ||
673 | + LIBS="$LIBS -framework Security" | ||
674 | + AC_MSG_RESULT([yes])], | ||
675 | + [ac_cv_use_security_session_api="no" | ||
676 | + AC_MSG_RESULT([no])]) | ||
677 | + AC_MSG_CHECKING([if we have an in-memory credentials cache]) | ||
678 | + AC_TRY_COMPILE( | ||
679 | + [#include <Kerberos/Kerberos.h>], | ||
680 | + [cc_context_t c; | ||
681 | + (void) cc_initialize (&c, 0, NULL, NULL);], | ||
682 | + [AC_DEFINE([USE_CCAPI], [1], | ||
683 | + [platform uses an in-memory credentials cache]) | ||
684 | + LIBS="$LIBS -framework Security" | ||
685 | + AC_MSG_RESULT([yes]) | ||
686 | + if test "x$ac_cv_use_security_session_api" = "xno"; then | ||
687 | + AC_MSG_ERROR([*** Need a security framework to use the credentials cache API ***]) | ||
688 | + fi], | ||
689 | + [AC_MSG_RESULT([no])] | ||
690 | + ) | ||
691 | m4_pattern_allow([AU_IPv]) | ||
692 | AC_CHECK_DECL([AU_IPv4], [], | ||
693 | AC_DEFINE([AU_IPv4], [0], [System only supports IPv4 audit records]) | ||
694 | diff --git a/gss-genr.c b/gss-genr.c | ||
695 | index d56257b4a..285fc29a5 100644 | ||
696 | --- a/gss-genr.c | ||
697 | +++ b/gss-genr.c | ||
698 | @@ -1,7 +1,7 @@ | ||
699 | /* $OpenBSD: gss-genr.c,v 1.26 2018/07/10 09:13:30 djm Exp $ */ | ||
700 | |||
701 | /* | ||
702 | - * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. | ||
703 | + * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved. | ||
704 | * | ||
705 | * Redistribution and use in source and binary forms, with or without | ||
706 | * modification, are permitted provided that the following conditions | ||
707 | @@ -41,12 +41,34 @@ | ||
708 | #include "sshbuf.h" | ||
709 | #include "log.h" | ||
710 | #include "ssh2.h" | ||
711 | +#include "cipher.h" | ||
712 | +#include "kex.h" | ||
713 | +#include <openssl/evp.h> | ||
714 | |||
715 | #include "ssh-gss.h" | ||
716 | |||
717 | extern u_char *session_id2; | ||
718 | extern u_int session_id2_len; | ||
719 | |||
720 | +typedef struct { | ||
721 | + char *encoded; | ||
722 | + gss_OID oid; | ||
723 | +} ssh_gss_kex_mapping; | ||
724 | + | ||
725 | +/* | ||
726 | + * XXX - It would be nice to find a more elegant way of handling the | ||
727 | + * XXX passing of the key exchange context to the userauth routines | ||
728 | + */ | ||
729 | + | ||
730 | +Gssctxt *gss_kex_context = NULL; | ||
731 | + | ||
732 | +static ssh_gss_kex_mapping *gss_enc2oid = NULL; | ||
733 | + | ||
734 | +int | ||
735 | +ssh_gssapi_oid_table_ok(void) { | ||
736 | + return (gss_enc2oid != NULL); | ||
737 | +} | ||
738 | + | ||
739 | /* sshbuf_get for gss_buffer_desc */ | ||
740 | int | ||
741 | ssh_gssapi_get_buffer_desc(struct sshbuf *b, gss_buffer_desc *g) | ||
742 | @@ -62,6 +84,141 @@ ssh_gssapi_get_buffer_desc(struct sshbuf *b, gss_buffer_desc *g) | ||
743 | return 0; | ||
744 | } | ||
745 | |||
746 | +/* | ||
747 | + * Return a list of the gss-group1-sha1 mechanisms supported by this program | ||
748 | + * | ||
749 | + * We test mechanisms to ensure that we can use them, to avoid starting | ||
750 | + * a key exchange with a bad mechanism | ||
751 | + */ | ||
752 | + | ||
753 | +char * | ||
754 | +ssh_gssapi_client_mechanisms(const char *host, const char *client) { | ||
755 | + gss_OID_set gss_supported; | ||
756 | + OM_uint32 min_status; | ||
757 | + | ||
758 | + if (GSS_ERROR(gss_indicate_mechs(&min_status, &gss_supported))) | ||
759 | + return NULL; | ||
760 | + | ||
761 | + return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism, | ||
762 | + host, client)); | ||
763 | +} | ||
764 | + | ||
765 | +char * | ||
766 | +ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check, | ||
767 | + const char *host, const char *client) { | ||
768 | + struct sshbuf *buf; | ||
769 | + size_t i; | ||
770 | + int r, oidpos, enclen; | ||
771 | + char *mechs, *encoded; | ||
772 | + u_char digest[EVP_MAX_MD_SIZE]; | ||
773 | + char deroid[2]; | ||
774 | + const EVP_MD *evp_md = EVP_md5(); | ||
775 | + EVP_MD_CTX md; | ||
776 | + | ||
777 | + if (gss_enc2oid != NULL) { | ||
778 | + for (i = 0; gss_enc2oid[i].encoded != NULL; i++) | ||
779 | + free(gss_enc2oid[i].encoded); | ||
780 | + free(gss_enc2oid); | ||
781 | + } | ||
782 | + | ||
783 | + gss_enc2oid = xmalloc(sizeof(ssh_gss_kex_mapping) * | ||
784 | + (gss_supported->count + 1)); | ||
785 | + | ||
786 | + if ((buf = sshbuf_new()) == NULL) | ||
787 | + fatal("%s: sshbuf_new failed", __func__); | ||
788 | + | ||
789 | + oidpos = 0; | ||
790 | + for (i = 0; i < gss_supported->count; i++) { | ||
791 | + if (gss_supported->elements[i].length < 128 && | ||
792 | + (*check)(NULL, &(gss_supported->elements[i]), host, client)) { | ||
793 | + | ||
794 | + deroid[0] = SSH_GSS_OIDTYPE; | ||
795 | + deroid[1] = gss_supported->elements[i].length; | ||
796 | + | ||
797 | + EVP_DigestInit(&md, evp_md); | ||
798 | + EVP_DigestUpdate(&md, deroid, 2); | ||
799 | + EVP_DigestUpdate(&md, | ||
800 | + gss_supported->elements[i].elements, | ||
801 | + gss_supported->elements[i].length); | ||
802 | + EVP_DigestFinal(&md, digest, NULL); | ||
803 | + | ||
804 | + encoded = xmalloc(EVP_MD_size(evp_md) * 2); | ||
805 | + enclen = __b64_ntop(digest, EVP_MD_size(evp_md), | ||
806 | + encoded, EVP_MD_size(evp_md) * 2); | ||
807 | + | ||
808 | + if (oidpos != 0) { | ||
809 | + if ((r = sshbuf_put_u8(buf, ',')) != 0) | ||
810 | + fatal("%s: buffer error: %s", | ||
811 | + __func__, ssh_err(r)); | ||
812 | + } | ||
813 | + | ||
814 | + if ((r = sshbuf_put(buf, KEX_GSS_GEX_SHA1_ID, | ||
815 | + sizeof(KEX_GSS_GEX_SHA1_ID) - 1)) != 0 || | ||
816 | + (r = sshbuf_put(buf, encoded, enclen)) != 0 || | ||
817 | + (r = sshbuf_put_u8(buf, ',')) != 0 || | ||
818 | + (r = sshbuf_put(buf, KEX_GSS_GRP1_SHA1_ID, | ||
819 | + sizeof(KEX_GSS_GRP1_SHA1_ID) - 1)) != 0 || | ||
820 | + (r = sshbuf_put(buf, encoded, enclen)) != 0 || | ||
821 | + (r = sshbuf_put_u8(buf, ',')) != 0 || | ||
822 | + (r = sshbuf_put(buf, KEX_GSS_GRP14_SHA1_ID, | ||
823 | + sizeof(KEX_GSS_GRP14_SHA1_ID) - 1)) != 0 || | ||
824 | + (r = sshbuf_put(buf, encoded, enclen)) != 0) | ||
825 | + fatal("%s: buffer error: %s", | ||
826 | + __func__, ssh_err(r)); | ||
827 | + | ||
828 | + gss_enc2oid[oidpos].oid = &(gss_supported->elements[i]); | ||
829 | + gss_enc2oid[oidpos].encoded = encoded; | ||
830 | + oidpos++; | ||
831 | + } | ||
832 | + } | ||
833 | + gss_enc2oid[oidpos].oid = NULL; | ||
834 | + gss_enc2oid[oidpos].encoded = NULL; | ||
835 | + | ||
836 | + if ((mechs = sshbuf_dup_string(buf)) == NULL) | ||
837 | + fatal("%s: sshbuf_dup_string failed", __func__); | ||
838 | + | ||
839 | + if (strlen(mechs) == 0) { | ||
840 | + free(mechs); | ||
841 | + mechs = NULL; | ||
842 | + } | ||
843 | + | ||
844 | + return (mechs); | ||
845 | +} | ||
846 | + | ||
847 | +gss_OID | ||
848 | +ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) { | ||
849 | + int i = 0; | ||
850 | + | ||
851 | + switch (kex_type) { | ||
852 | + case KEX_GSS_GRP1_SHA1: | ||
853 | + if (strlen(name) < sizeof(KEX_GSS_GRP1_SHA1_ID)) | ||
854 | + return GSS_C_NO_OID; | ||
855 | + name += sizeof(KEX_GSS_GRP1_SHA1_ID) - 1; | ||
856 | + break; | ||
857 | + case KEX_GSS_GRP14_SHA1: | ||
858 | + if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA1_ID)) | ||
859 | + return GSS_C_NO_OID; | ||
860 | + name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1; | ||
861 | + break; | ||
862 | + case KEX_GSS_GEX_SHA1: | ||
863 | + if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID)) | ||
864 | + return GSS_C_NO_OID; | ||
865 | + name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1; | ||
866 | + break; | ||
867 | + default: | ||
868 | + return GSS_C_NO_OID; | ||
869 | + } | ||
870 | + | ||
871 | + while (gss_enc2oid[i].encoded != NULL && | ||
872 | + strcmp(name, gss_enc2oid[i].encoded) != 0) | ||
873 | + i++; | ||
874 | + | ||
875 | + if (gss_enc2oid[i].oid != NULL && ctx != NULL) | ||
876 | + ssh_gssapi_set_oid(ctx, gss_enc2oid[i].oid); | ||
877 | + | ||
878 | + return gss_enc2oid[i].oid; | ||
879 | +} | ||
880 | + | ||
881 | /* Check that the OID in a data stream matches that in the context */ | ||
882 | int | ||
883 | ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len) | ||
884 | @@ -218,7 +375,7 @@ ssh_gssapi_init_ctx(Gssctxt *ctx, int deleg_creds, gss_buffer_desc *recv_tok, | ||
885 | } | ||
886 | |||
887 | ctx->major = gss_init_sec_context(&ctx->minor, | ||
888 | - GSS_C_NO_CREDENTIAL, &ctx->context, ctx->name, ctx->oid, | ||
889 | + ctx->client_creds, &ctx->context, ctx->name, ctx->oid, | ||
890 | GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag, | ||
891 | 0, NULL, recv_tok, NULL, send_tok, flags, NULL); | ||
892 | |||
893 | @@ -247,9 +404,43 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host) | ||
894 | return (ctx->major); | ||
895 | } | ||
896 | |||
897 | +OM_uint32 | ||
898 | +ssh_gssapi_client_identity(Gssctxt *ctx, const char *name) | ||
899 | +{ | ||
900 | + gss_buffer_desc gssbuf; | ||
901 | + gss_name_t gssname; | ||
902 | + OM_uint32 status; | ||
903 | + gss_OID_set oidset; | ||
904 | + | ||
905 | + gssbuf.value = (void *) name; | ||
906 | + gssbuf.length = strlen(gssbuf.value); | ||
907 | + | ||
908 | + gss_create_empty_oid_set(&status, &oidset); | ||
909 | + gss_add_oid_set_member(&status, ctx->oid, &oidset); | ||
910 | + | ||
911 | + ctx->major = gss_import_name(&ctx->minor, &gssbuf, | ||
912 | + GSS_C_NT_USER_NAME, &gssname); | ||
913 | + | ||
914 | + if (!ctx->major) | ||
915 | + ctx->major = gss_acquire_cred(&ctx->minor, | ||
916 | + gssname, 0, oidset, GSS_C_INITIATE, | ||
917 | + &ctx->client_creds, NULL, NULL); | ||
918 | + | ||
919 | + gss_release_name(&status, &gssname); | ||
920 | + gss_release_oid_set(&status, &oidset); | ||
921 | + | ||
922 | + if (ctx->major) | ||
923 | + ssh_gssapi_error(ctx); | ||
924 | + | ||
925 | + return(ctx->major); | ||
926 | +} | ||
927 | + | ||
928 | OM_uint32 | ||
929 | ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash) | ||
930 | { | ||
931 | + if (ctx == NULL) | ||
932 | + return -1; | ||
933 | + | ||
934 | if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context, | ||
935 | GSS_C_QOP_DEFAULT, buffer, hash))) | ||
936 | ssh_gssapi_error(ctx); | ||
937 | @@ -257,6 +448,19 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash) | ||
938 | return (ctx->major); | ||
939 | } | ||
940 | |||
941 | +/* Priviledged when used by server */ | ||
942 | +OM_uint32 | ||
943 | +ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic) | ||
944 | +{ | ||
945 | + if (ctx == NULL) | ||
946 | + return -1; | ||
947 | + | ||
948 | + ctx->major = gss_verify_mic(&ctx->minor, ctx->context, | ||
949 | + gssbuf, gssmic, NULL); | ||
950 | + | ||
951 | + return (ctx->major); | ||
952 | +} | ||
953 | + | ||
954 | void | ||
955 | ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service, | ||
956 | const char *context) | ||
957 | @@ -273,11 +477,16 @@ ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service, | ||
958 | } | ||
959 | |||
960 | int | ||
961 | -ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host) | ||
962 | +ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host, | ||
963 | + const char *client) | ||
964 | { | ||
965 | gss_buffer_desc token = GSS_C_EMPTY_BUFFER; | ||
966 | OM_uint32 major, minor; | ||
967 | gss_OID_desc spnego_oid = {6, (void *)"\x2B\x06\x01\x05\x05\x02"}; | ||
968 | + Gssctxt *intctx = NULL; | ||
969 | + | ||
970 | + if (ctx == NULL) | ||
971 | + ctx = &intctx; | ||
972 | |||
973 | /* RFC 4462 says we MUST NOT do SPNEGO */ | ||
974 | if (oid->length == spnego_oid.length && | ||
975 | @@ -287,6 +496,10 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host) | ||
976 | ssh_gssapi_build_ctx(ctx); | ||
977 | ssh_gssapi_set_oid(*ctx, oid); | ||
978 | major = ssh_gssapi_import_name(*ctx, host); | ||
979 | + | ||
980 | + if (!GSS_ERROR(major) && client) | ||
981 | + major = ssh_gssapi_client_identity(*ctx, client); | ||
982 | + | ||
983 | if (!GSS_ERROR(major)) { | ||
984 | major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token, | ||
985 | NULL); | ||
986 | @@ -296,10 +509,66 @@ ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host) | ||
987 | GSS_C_NO_BUFFER); | ||
988 | } | ||
989 | |||
990 | - if (GSS_ERROR(major)) | ||
991 | + if (GSS_ERROR(major) || intctx != NULL) | ||
992 | ssh_gssapi_delete_ctx(ctx); | ||
993 | |||
994 | return (!GSS_ERROR(major)); | ||
995 | } | ||
996 | |||
997 | +int | ||
998 | +ssh_gssapi_credentials_updated(Gssctxt *ctxt) { | ||
999 | + static gss_name_t saved_name = GSS_C_NO_NAME; | ||
1000 | + static OM_uint32 saved_lifetime = 0; | ||
1001 | + static gss_OID saved_mech = GSS_C_NO_OID; | ||
1002 | + static gss_name_t name; | ||
1003 | + static OM_uint32 last_call = 0; | ||
1004 | + OM_uint32 lifetime, now, major, minor; | ||
1005 | + int equal; | ||
1006 | + | ||
1007 | + now = time(NULL); | ||
1008 | + | ||
1009 | + if (ctxt) { | ||
1010 | + debug("Rekey has happened - updating saved versions"); | ||
1011 | + | ||
1012 | + if (saved_name != GSS_C_NO_NAME) | ||
1013 | + gss_release_name(&minor, &saved_name); | ||
1014 | + | ||
1015 | + major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL, | ||
1016 | + &saved_name, &saved_lifetime, NULL, NULL); | ||
1017 | + | ||
1018 | + if (!GSS_ERROR(major)) { | ||
1019 | + saved_mech = ctxt->oid; | ||
1020 | + saved_lifetime+= now; | ||
1021 | + } else { | ||
1022 | + /* Handle the error */ | ||
1023 | + } | ||
1024 | + return 0; | ||
1025 | + } | ||
1026 | + | ||
1027 | + if (now - last_call < 10) | ||
1028 | + return 0; | ||
1029 | + | ||
1030 | + last_call = now; | ||
1031 | + | ||
1032 | + if (saved_mech == GSS_C_NO_OID) | ||
1033 | + return 0; | ||
1034 | + | ||
1035 | + major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL, | ||
1036 | + &name, &lifetime, NULL, NULL); | ||
1037 | + if (major == GSS_S_CREDENTIALS_EXPIRED) | ||
1038 | + return 0; | ||
1039 | + else if (GSS_ERROR(major)) | ||
1040 | + return 0; | ||
1041 | + | ||
1042 | + major = gss_compare_name(&minor, saved_name, name, &equal); | ||
1043 | + gss_release_name(&minor, &name); | ||
1044 | + if (GSS_ERROR(major)) | ||
1045 | + return 0; | ||
1046 | + | ||
1047 | + if (equal && (saved_lifetime < lifetime + now - 10)) | ||
1048 | + return 1; | ||
1049 | + | ||
1050 | + return 0; | ||
1051 | +} | ||
1052 | + | ||
1053 | #endif /* GSSAPI */ | ||
1054 | diff --git a/gss-serv-krb5.c b/gss-serv-krb5.c | ||
1055 | index a151bc1e4..90f8692f5 100644 | ||
1056 | --- a/gss-serv-krb5.c | ||
1057 | +++ b/gss-serv-krb5.c | ||
1058 | @@ -1,7 +1,7 @@ | ||
1059 | /* $OpenBSD: gss-serv-krb5.c,v 1.9 2018/07/09 21:37:55 markus Exp $ */ | ||
1060 | |||
1061 | /* | ||
1062 | - * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. | ||
1063 | + * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. | ||
1064 | * | ||
1065 | * Redistribution and use in source and binary forms, with or without | ||
1066 | * modification, are permitted provided that the following conditions | ||
1067 | @@ -120,8 +120,8 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client) | ||
1068 | krb5_error_code problem; | ||
1069 | krb5_principal princ; | ||
1070 | OM_uint32 maj_status, min_status; | ||
1071 | - int len; | ||
1072 | const char *errmsg; | ||
1073 | + const char *new_ccname; | ||
1074 | |||
1075 | if (client->creds == NULL) { | ||
1076 | debug("No credentials stored"); | ||
1077 | @@ -180,11 +180,16 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client) | ||
1078 | return; | ||
1079 | } | ||
1080 | |||
1081 | - client->store.filename = xstrdup(krb5_cc_get_name(krb_context, ccache)); | ||
1082 | + new_ccname = krb5_cc_get_name(krb_context, ccache); | ||
1083 | + | ||
1084 | client->store.envvar = "KRB5CCNAME"; | ||
1085 | - len = strlen(client->store.filename) + 6; | ||
1086 | - client->store.envval = xmalloc(len); | ||
1087 | - snprintf(client->store.envval, len, "FILE:%s", client->store.filename); | ||
1088 | +#ifdef USE_CCAPI | ||
1089 | + xasprintf(&client->store.envval, "API:%s", new_ccname); | ||
1090 | + client->store.filename = NULL; | ||
1091 | +#else | ||
1092 | + xasprintf(&client->store.envval, "FILE:%s", new_ccname); | ||
1093 | + client->store.filename = xstrdup(new_ccname); | ||
1094 | +#endif | ||
1095 | |||
1096 | #ifdef USE_PAM | ||
1097 | if (options.use_pam) | ||
1098 | @@ -196,6 +201,71 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client) | ||
1099 | return; | ||
1100 | } | ||
1101 | |||
1102 | +int | ||
1103 | +ssh_gssapi_krb5_updatecreds(ssh_gssapi_ccache *store, | ||
1104 | + ssh_gssapi_client *client) | ||
1105 | +{ | ||
1106 | + krb5_ccache ccache = NULL; | ||
1107 | + krb5_principal principal = NULL; | ||
1108 | + char *name = NULL; | ||
1109 | + krb5_error_code problem; | ||
1110 | + OM_uint32 maj_status, min_status; | ||
1111 | + | ||
1112 | + if ((problem = krb5_cc_resolve(krb_context, store->envval, &ccache))) { | ||
1113 | + logit("krb5_cc_resolve(): %.100s", | ||
1114 | + krb5_get_err_text(krb_context, problem)); | ||
1115 | + return 0; | ||
1116 | + } | ||
1117 | + | ||
1118 | + /* Find out who the principal in this cache is */ | ||
1119 | + if ((problem = krb5_cc_get_principal(krb_context, ccache, | ||
1120 | + &principal))) { | ||
1121 | + logit("krb5_cc_get_principal(): %.100s", | ||
1122 | + krb5_get_err_text(krb_context, problem)); | ||
1123 | + krb5_cc_close(krb_context, ccache); | ||
1124 | + return 0; | ||
1125 | + } | ||
1126 | + | ||
1127 | + if ((problem = krb5_unparse_name(krb_context, principal, &name))) { | ||
1128 | + logit("krb5_unparse_name(): %.100s", | ||
1129 | + krb5_get_err_text(krb_context, problem)); | ||
1130 | + krb5_free_principal(krb_context, principal); | ||
1131 | + krb5_cc_close(krb_context, ccache); | ||
1132 | + return 0; | ||
1133 | + } | ||
1134 | + | ||
1135 | + | ||
1136 | + if (strcmp(name,client->exportedname.value)!=0) { | ||
1137 | + debug("Name in local credentials cache differs. Not storing"); | ||
1138 | + krb5_free_principal(krb_context, principal); | ||
1139 | + krb5_cc_close(krb_context, ccache); | ||
1140 | + krb5_free_unparsed_name(krb_context, name); | ||
1141 | + return 0; | ||
1142 | + } | ||
1143 | + krb5_free_unparsed_name(krb_context, name); | ||
1144 | + | ||
1145 | + /* Name matches, so lets get on with it! */ | ||
1146 | + | ||
1147 | + if ((problem = krb5_cc_initialize(krb_context, ccache, principal))) { | ||
1148 | + logit("krb5_cc_initialize(): %.100s", | ||
1149 | + krb5_get_err_text(krb_context, problem)); | ||
1150 | + krb5_free_principal(krb_context, principal); | ||
1151 | + krb5_cc_close(krb_context, ccache); | ||
1152 | + return 0; | ||
1153 | + } | ||
1154 | + | ||
1155 | + krb5_free_principal(krb_context, principal); | ||
1156 | + | ||
1157 | + if ((maj_status = gss_krb5_copy_ccache(&min_status, client->creds, | ||
1158 | + ccache))) { | ||
1159 | + logit("gss_krb5_copy_ccache() failed. Sorry!"); | ||
1160 | + krb5_cc_close(krb_context, ccache); | ||
1161 | + return 0; | ||
1162 | + } | ||
1163 | + | ||
1164 | + return 1; | ||
1165 | +} | ||
1166 | + | ||
1167 | ssh_gssapi_mech gssapi_kerberos_mech = { | ||
1168 | "toWM5Slw5Ew8Mqkay+al2g==", | ||
1169 | "Kerberos", | ||
1170 | @@ -203,7 +273,8 @@ ssh_gssapi_mech gssapi_kerberos_mech = { | ||
1171 | NULL, | ||
1172 | &ssh_gssapi_krb5_userok, | ||
1173 | NULL, | ||
1174 | - &ssh_gssapi_krb5_storecreds | ||
1175 | + &ssh_gssapi_krb5_storecreds, | ||
1176 | + &ssh_gssapi_krb5_updatecreds | ||
1177 | }; | ||
1178 | |||
1179 | #endif /* KRB5 */ | ||
1180 | diff --git a/gss-serv.c b/gss-serv.c | ||
1181 | index ab3a15f0f..6c087a1b1 100644 | ||
1182 | --- a/gss-serv.c | ||
1183 | +++ b/gss-serv.c | ||
1184 | @@ -1,7 +1,7 @@ | ||
1185 | /* $OpenBSD: gss-serv.c,v 1.31 2018/07/09 21:37:55 markus Exp $ */ | ||
1186 | |||
1187 | /* | ||
1188 | - * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. | ||
1189 | + * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved. | ||
1190 | * | ||
1191 | * Redistribution and use in source and binary forms, with or without | ||
1192 | * modification, are permitted provided that the following conditions | ||
1193 | @@ -44,17 +44,22 @@ | ||
1194 | #include "session.h" | ||
1195 | #include "misc.h" | ||
1196 | #include "servconf.h" | ||
1197 | +#include "uidswap.h" | ||
1198 | |||
1199 | #include "ssh-gss.h" | ||
1200 | +#include "monitor_wrap.h" | ||
1201 | + | ||
1202 | +extern ServerOptions options; | ||
1203 | |||
1204 | extern ServerOptions options; | ||
1205 | |||
1206 | static ssh_gssapi_client gssapi_client = | ||
1207 | { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER, | ||
1208 | - GSS_C_NO_CREDENTIAL, NULL, {NULL, NULL, NULL, NULL}}; | ||
1209 | + GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME, NULL, | ||
1210 | + {NULL, NULL, NULL, NULL, NULL}, 0, 0}; | ||
1211 | |||
1212 | ssh_gssapi_mech gssapi_null_mech = | ||
1213 | - { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL}; | ||
1214 | + { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL, NULL}; | ||
1215 | |||
1216 | #ifdef KRB5 | ||
1217 | extern ssh_gssapi_mech gssapi_kerberos_mech; | ||
1218 | @@ -140,6 +145,28 @@ ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID oid) | ||
1219 | return (ssh_gssapi_acquire_cred(*ctx)); | ||
1220 | } | ||
1221 | |||
1222 | +/* Unprivileged */ | ||
1223 | +char * | ||
1224 | +ssh_gssapi_server_mechanisms(void) { | ||
1225 | + if (supported_oids == NULL) | ||
1226 | + ssh_gssapi_prepare_supported_oids(); | ||
1227 | + return (ssh_gssapi_kex_mechs(supported_oids, | ||
1228 | + &ssh_gssapi_server_check_mech, NULL, NULL)); | ||
1229 | +} | ||
1230 | + | ||
1231 | +/* Unprivileged */ | ||
1232 | +int | ||
1233 | +ssh_gssapi_server_check_mech(Gssctxt **dum, gss_OID oid, const char *data, | ||
1234 | + const char *dummy) { | ||
1235 | + Gssctxt *ctx = NULL; | ||
1236 | + int res; | ||
1237 | + | ||
1238 | + res = !GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctx, oid))); | ||
1239 | + ssh_gssapi_delete_ctx(&ctx); | ||
1240 | + | ||
1241 | + return (res); | ||
1242 | +} | ||
1243 | + | ||
1244 | /* Unprivileged */ | ||
1245 | void | ||
1246 | ssh_gssapi_supported_oids(gss_OID_set *oidset) | ||
1247 | @@ -150,7 +177,9 @@ ssh_gssapi_supported_oids(gss_OID_set *oidset) | ||
1248 | gss_OID_set supported; | ||
1249 | |||
1250 | gss_create_empty_oid_set(&min_status, oidset); | ||
1251 | - gss_indicate_mechs(&min_status, &supported); | ||
1252 | + | ||
1253 | + if (GSS_ERROR(gss_indicate_mechs(&min_status, &supported))) | ||
1254 | + return; | ||
1255 | |||
1256 | while (supported_mechs[i]->name != NULL) { | ||
1257 | if (GSS_ERROR(gss_test_oid_set_member(&min_status, | ||
1258 | @@ -276,8 +305,48 @@ OM_uint32 | ||
1259 | ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client) | ||
1260 | { | ||
1261 | int i = 0; | ||
1262 | + int equal = 0; | ||
1263 | + gss_name_t new_name = GSS_C_NO_NAME; | ||
1264 | + gss_buffer_desc ename = GSS_C_EMPTY_BUFFER; | ||
1265 | + | ||
1266 | + if (options.gss_store_rekey && client->used && ctx->client_creds) { | ||
1267 | + if (client->mech->oid.length != ctx->oid->length || | ||
1268 | + (memcmp(client->mech->oid.elements, | ||
1269 | + ctx->oid->elements, ctx->oid->length) !=0)) { | ||
1270 | + debug("Rekeyed credentials have different mechanism"); | ||
1271 | + return GSS_S_COMPLETE; | ||
1272 | + } | ||
1273 | + | ||
1274 | + if ((ctx->major = gss_inquire_cred_by_mech(&ctx->minor, | ||
1275 | + ctx->client_creds, ctx->oid, &new_name, | ||
1276 | + NULL, NULL, NULL))) { | ||
1277 | + ssh_gssapi_error(ctx); | ||
1278 | + return (ctx->major); | ||
1279 | + } | ||
1280 | + | ||
1281 | + ctx->major = gss_compare_name(&ctx->minor, client->name, | ||
1282 | + new_name, &equal); | ||
1283 | + | ||
1284 | + if (GSS_ERROR(ctx->major)) { | ||
1285 | + ssh_gssapi_error(ctx); | ||
1286 | + return (ctx->major); | ||
1287 | + } | ||
1288 | + | ||
1289 | + if (!equal) { | ||
1290 | + debug("Rekeyed credentials have different name"); | ||
1291 | + return GSS_S_COMPLETE; | ||
1292 | + } | ||
1293 | |||
1294 | - gss_buffer_desc ename; | ||
1295 | + debug("Marking rekeyed credentials for export"); | ||
1296 | + | ||
1297 | + gss_release_name(&ctx->minor, &client->name); | ||
1298 | + gss_release_cred(&ctx->minor, &client->creds); | ||
1299 | + client->name = new_name; | ||
1300 | + client->creds = ctx->client_creds; | ||
1301 | + ctx->client_creds = GSS_C_NO_CREDENTIAL; | ||
1302 | + client->updated = 1; | ||
1303 | + return GSS_S_COMPLETE; | ||
1304 | + } | ||
1305 | |||
1306 | client->mech = NULL; | ||
1307 | |||
1308 | @@ -292,6 +361,13 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client) | ||
1309 | if (client->mech == NULL) | ||
1310 | return GSS_S_FAILURE; | ||
1311 | |||
1312 | + if (ctx->client_creds && | ||
1313 | + (ctx->major = gss_inquire_cred_by_mech(&ctx->minor, | ||
1314 | + ctx->client_creds, ctx->oid, &client->name, NULL, NULL, NULL))) { | ||
1315 | + ssh_gssapi_error(ctx); | ||
1316 | + return (ctx->major); | ||
1317 | + } | ||
1318 | + | ||
1319 | if ((ctx->major = gss_display_name(&ctx->minor, ctx->client, | ||
1320 | &client->displayname, NULL))) { | ||
1321 | ssh_gssapi_error(ctx); | ||
1322 | @@ -309,6 +385,8 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client) | ||
1323 | return (ctx->major); | ||
1324 | } | ||
1325 | |||
1326 | + gss_release_buffer(&ctx->minor, &ename); | ||
1327 | + | ||
1328 | /* We can't copy this structure, so we just move the pointer to it */ | ||
1329 | client->creds = ctx->client_creds; | ||
1330 | ctx->client_creds = GSS_C_NO_CREDENTIAL; | ||
1331 | @@ -356,7 +434,7 @@ ssh_gssapi_do_child(char ***envp, u_int *envsizep) | ||
1332 | |||
1333 | /* Privileged */ | ||
1334 | int | ||
1335 | -ssh_gssapi_userok(char *user) | ||
1336 | +ssh_gssapi_userok(char *user, struct passwd *pw) | ||
1337 | { | ||
1338 | OM_uint32 lmin; | ||
1339 | |||
1340 | @@ -366,9 +444,11 @@ ssh_gssapi_userok(char *user) | ||
1341 | return 0; | ||
1342 | } | ||
1343 | if (gssapi_client.mech && gssapi_client.mech->userok) | ||
1344 | - if ((*gssapi_client.mech->userok)(&gssapi_client, user)) | ||
1345 | + if ((*gssapi_client.mech->userok)(&gssapi_client, user)) { | ||
1346 | + gssapi_client.used = 1; | ||
1347 | + gssapi_client.store.owner = pw; | ||
1348 | return 1; | ||
1349 | - else { | ||
1350 | + } else { | ||
1351 | /* Destroy delegated credentials if userok fails */ | ||
1352 | gss_release_buffer(&lmin, &gssapi_client.displayname); | ||
1353 | gss_release_buffer(&lmin, &gssapi_client.exportedname); | ||
1354 | @@ -382,14 +462,90 @@ ssh_gssapi_userok(char *user) | ||
1355 | return (0); | ||
1356 | } | ||
1357 | |||
1358 | -/* Privileged */ | ||
1359 | -OM_uint32 | ||
1360 | -ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic) | ||
1361 | +/* These bits are only used for rekeying. The unpriviledged child is running | ||
1362 | + * as the user, the monitor is root. | ||
1363 | + * | ||
1364 | + * In the child, we want to : | ||
1365 | + * *) Ask the monitor to store our credentials into the store we specify | ||
1366 | + * *) If it succeeds, maybe do a PAM update | ||
1367 | + */ | ||
1368 | + | ||
1369 | +/* Stuff for PAM */ | ||
1370 | + | ||
1371 | +#ifdef USE_PAM | ||
1372 | +static int ssh_gssapi_simple_conv(int n, const struct pam_message **msg, | ||
1373 | + struct pam_response **resp, void *data) | ||
1374 | { | ||
1375 | - ctx->major = gss_verify_mic(&ctx->minor, ctx->context, | ||
1376 | - gssbuf, gssmic, NULL); | ||
1377 | + return (PAM_CONV_ERR); | ||
1378 | +} | ||
1379 | +#endif | ||
1380 | |||
1381 | - return (ctx->major); | ||
1382 | +void | ||
1383 | +ssh_gssapi_rekey_creds(void) { | ||
1384 | + int ok; | ||
1385 | + int ret; | ||
1386 | +#ifdef USE_PAM | ||
1387 | + pam_handle_t *pamh = NULL; | ||
1388 | + struct pam_conv pamconv = {ssh_gssapi_simple_conv, NULL}; | ||
1389 | + char *envstr; | ||
1390 | +#endif | ||
1391 | + | ||
1392 | + if (gssapi_client.store.filename == NULL && | ||
1393 | + gssapi_client.store.envval == NULL && | ||
1394 | + gssapi_client.store.envvar == NULL) | ||
1395 | + return; | ||
1396 | + | ||
1397 | + ok = PRIVSEP(ssh_gssapi_update_creds(&gssapi_client.store)); | ||
1398 | + | ||
1399 | + if (!ok) | ||
1400 | + return; | ||
1401 | + | ||
1402 | + debug("Rekeyed credentials stored successfully"); | ||
1403 | + | ||
1404 | + /* Actually managing to play with the ssh pam stack from here will | ||
1405 | + * be next to impossible. In any case, we may want different options | ||
1406 | + * for rekeying. So, use our own :) | ||
1407 | + */ | ||
1408 | +#ifdef USE_PAM | ||
1409 | + if (!use_privsep) { | ||
1410 | + debug("Not even going to try and do PAM with privsep disabled"); | ||
1411 | + return; | ||
1412 | + } | ||
1413 | + | ||
1414 | + ret = pam_start("sshd-rekey", gssapi_client.store.owner->pw_name, | ||
1415 | + &pamconv, &pamh); | ||
1416 | + if (ret) | ||
1417 | + return; | ||
1418 | + | ||
1419 | + xasprintf(&envstr, "%s=%s", gssapi_client.store.envvar, | ||
1420 | + gssapi_client.store.envval); | ||
1421 | + | ||
1422 | + ret = pam_putenv(pamh, envstr); | ||
1423 | + if (!ret) | ||
1424 | + pam_setcred(pamh, PAM_REINITIALIZE_CRED); | ||
1425 | + pam_end(pamh, PAM_SUCCESS); | ||
1426 | +#endif | ||
1427 | +} | ||
1428 | + | ||
1429 | +int | ||
1430 | +ssh_gssapi_update_creds(ssh_gssapi_ccache *store) { | ||
1431 | + int ok = 0; | ||
1432 | + | ||
1433 | + /* Check we've got credentials to store */ | ||
1434 | + if (!gssapi_client.updated) | ||
1435 | + return 0; | ||
1436 | + | ||
1437 | + gssapi_client.updated = 0; | ||
1438 | + | ||
1439 | + temporarily_use_uid(gssapi_client.store.owner); | ||
1440 | + if (gssapi_client.mech && gssapi_client.mech->updatecreds) | ||
1441 | + ok = (*gssapi_client.mech->updatecreds)(store, &gssapi_client); | ||
1442 | + else | ||
1443 | + debug("No update function for this mechanism"); | ||
1444 | + | ||
1445 | + restore_uid(); | ||
1446 | + | ||
1447 | + return ok; | ||
1448 | } | ||
1449 | |||
1450 | /* Privileged */ | ||
1451 | diff --git a/kex.c b/kex.c | ||
1452 | index 25f9f66f6..fb5bfaea5 100644 | ||
1453 | --- a/kex.c | ||
1454 | +++ b/kex.c | ||
1455 | @@ -54,6 +54,10 @@ | ||
1456 | #include "sshbuf.h" | ||
1457 | #include "digest.h" | ||
1458 | |||
1459 | +#ifdef GSSAPI | ||
1460 | +#include "ssh-gss.h" | ||
1461 | +#endif | ||
1462 | + | ||
1463 | /* prototype */ | ||
1464 | static int kex_choose_conf(struct ssh *); | ||
1465 | static int kex_input_newkeys(int, u_int32_t, struct ssh *); | ||
1466 | @@ -105,6 +109,14 @@ static const struct kexalg kexalgs[] = { | ||
1467 | #endif /* HAVE_EVP_SHA256 || !WITH_OPENSSL */ | ||
1468 | { NULL, -1, -1, -1}, | ||
1469 | }; | ||
1470 | +static const struct kexalg kexalg_prefixes[] = { | ||
1471 | +#ifdef GSSAPI | ||
1472 | + { KEX_GSS_GEX_SHA1_ID, KEX_GSS_GEX_SHA1, 0, SSH_DIGEST_SHA1 }, | ||
1473 | + { KEX_GSS_GRP1_SHA1_ID, KEX_GSS_GRP1_SHA1, 0, SSH_DIGEST_SHA1 }, | ||
1474 | + { KEX_GSS_GRP14_SHA1_ID, KEX_GSS_GRP14_SHA1, 0, SSH_DIGEST_SHA1 }, | ||
1475 | +#endif | ||
1476 | + { NULL, -1, -1, -1 }, | ||
1477 | +}; | ||
1478 | |||
1479 | char * | ||
1480 | kex_alg_list(char sep) | ||
1481 | @@ -137,6 +149,10 @@ kex_alg_by_name(const char *name) | ||
1482 | if (strcmp(k->name, name) == 0) | ||
1483 | return k; | ||
1484 | } | ||
1485 | + for (k = kexalg_prefixes; k->name != NULL; k++) { | ||
1486 | + if (strncmp(k->name, name, strlen(k->name)) == 0) | ||
1487 | + return k; | ||
1488 | + } | ||
1489 | return NULL; | ||
1490 | } | ||
1491 | |||
1492 | @@ -653,6 +669,9 @@ kex_free(struct kex *kex) | ||
1493 | sshbuf_free(kex->peer); | ||
1494 | sshbuf_free(kex->my); | ||
1495 | free(kex->session_id); | ||
1496 | +#ifdef GSSAPI | ||
1497 | + free(kex->gss_host); | ||
1498 | +#endif /* GSSAPI */ | ||
1499 | free(kex->client_version_string); | ||
1500 | free(kex->server_version_string); | ||
1501 | free(kex->failed_choice); | ||
1502 | diff --git a/kex.h b/kex.h | ||
1503 | index 593de1208..4e5ead839 100644 | ||
1504 | --- a/kex.h | ||
1505 | +++ b/kex.h | ||
1506 | @@ -100,6 +100,9 @@ enum kex_exchange { | ||
1507 | KEX_DH_GEX_SHA256, | ||
1508 | KEX_ECDH_SHA2, | ||
1509 | KEX_C25519_SHA256, | ||
1510 | + KEX_GSS_GRP1_SHA1, | ||
1511 | + KEX_GSS_GRP14_SHA1, | ||
1512 | + KEX_GSS_GEX_SHA1, | ||
1513 | KEX_MAX | ||
1514 | }; | ||
1515 | |||
1516 | @@ -148,6 +151,12 @@ struct kex { | ||
1517 | u_int flags; | ||
1518 | int hash_alg; | ||
1519 | int ec_nid; | ||
1520 | +#ifdef GSSAPI | ||
1521 | + int gss_deleg_creds; | ||
1522 | + int gss_trust_dns; | ||
1523 | + char *gss_host; | ||
1524 | + char *gss_client; | ||
1525 | +#endif | ||
1526 | char *client_version_string; | ||
1527 | char *server_version_string; | ||
1528 | char *failed_choice; | ||
1529 | @@ -198,6 +207,11 @@ int kexecdh_server(struct ssh *); | ||
1530 | int kexc25519_client(struct ssh *); | ||
1531 | int kexc25519_server(struct ssh *); | ||
1532 | |||
1533 | +#ifdef GSSAPI | ||
1534 | +int kexgss_client(struct ssh *); | ||
1535 | +int kexgss_server(struct ssh *); | ||
1536 | +#endif | ||
1537 | + | ||
1538 | int kex_dh_hash(int, const char *, const char *, | ||
1539 | const u_char *, size_t, const u_char *, size_t, const u_char *, size_t, | ||
1540 | const BIGNUM *, const BIGNUM *, const BIGNUM *, u_char *, size_t *); | ||
1541 | diff --git a/kexgssc.c b/kexgssc.c | ||
1542 | new file mode 100644 | ||
1543 | index 000000000..953c0a248 | ||
1544 | --- /dev/null | ||
1545 | +++ b/kexgssc.c | ||
1546 | @@ -0,0 +1,338 @@ | ||
1547 | +/* | ||
1548 | + * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved. | ||
1549 | + * | ||
1550 | + * Redistribution and use in source and binary forms, with or without | ||
1551 | + * modification, are permitted provided that the following conditions | ||
1552 | + * are met: | ||
1553 | + * 1. Redistributions of source code must retain the above copyright | ||
1554 | + * notice, this list of conditions and the following disclaimer. | ||
1555 | + * 2. Redistributions in binary form must reproduce the above copyright | ||
1556 | + * notice, this list of conditions and the following disclaimer in the | ||
1557 | + * documentation and/or other materials provided with the distribution. | ||
1558 | + * | ||
1559 | + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR | ||
1560 | + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
1561 | + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
1562 | + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
1563 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
1564 | + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
1565 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
1566 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
1567 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
1568 | + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
1569 | + */ | ||
1570 | + | ||
1571 | +#include "includes.h" | ||
1572 | + | ||
1573 | +#ifdef GSSAPI | ||
1574 | + | ||
1575 | +#include "includes.h" | ||
1576 | + | ||
1577 | +#include <openssl/crypto.h> | ||
1578 | +#include <openssl/bn.h> | ||
1579 | + | ||
1580 | +#include <string.h> | ||
1581 | + | ||
1582 | +#include "xmalloc.h" | ||
1583 | +#include "sshbuf.h" | ||
1584 | +#include "ssh2.h" | ||
1585 | +#include "sshkey.h" | ||
1586 | +#include "cipher.h" | ||
1587 | +#include "kex.h" | ||
1588 | +#include "log.h" | ||
1589 | +#include "packet.h" | ||
1590 | +#include "dh.h" | ||
1591 | +#include "digest.h" | ||
1592 | + | ||
1593 | +#include "ssh-gss.h" | ||
1594 | + | ||
1595 | +int | ||
1596 | +kexgss_client(struct ssh *ssh) { | ||
1597 | + gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER; | ||
1598 | + gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr; | ||
1599 | + Gssctxt *ctxt; | ||
1600 | + OM_uint32 maj_status, min_status, ret_flags; | ||
1601 | + u_int klen, kout, slen = 0, strlen; | ||
1602 | + DH *dh; | ||
1603 | + BIGNUM *dh_server_pub = NULL; | ||
1604 | + BIGNUM *shared_secret = NULL; | ||
1605 | + BIGNUM *p = NULL; | ||
1606 | + BIGNUM *g = NULL; | ||
1607 | + u_char *kbuf; | ||
1608 | + u_char *serverhostkey = NULL; | ||
1609 | + u_char *empty = ""; | ||
1610 | + char *msg; | ||
1611 | + int type = 0; | ||
1612 | + int first = 1; | ||
1613 | + int nbits = 0, min = DH_GRP_MIN, max = DH_GRP_MAX; | ||
1614 | + u_char hash[SSH_DIGEST_MAX_LENGTH]; | ||
1615 | + size_t hashlen; | ||
1616 | + | ||
1617 | + /* Initialise our GSSAPI world */ | ||
1618 | + ssh_gssapi_build_ctx(&ctxt); | ||
1619 | + if (ssh_gssapi_id_kex(ctxt, ssh->kex->name, ssh->kex->kex_type) | ||
1620 | + == GSS_C_NO_OID) | ||
1621 | + fatal("Couldn't identify host exchange"); | ||
1622 | + | ||
1623 | + if (ssh_gssapi_import_name(ctxt, ssh->kex->gss_host)) | ||
1624 | + fatal("Couldn't import hostname"); | ||
1625 | + | ||
1626 | + if (ssh->kex->gss_client && | ||
1627 | + ssh_gssapi_client_identity(ctxt, ssh->kex->gss_client)) | ||
1628 | + fatal("Couldn't acquire client credentials"); | ||
1629 | + | ||
1630 | + switch (ssh->kex->kex_type) { | ||
1631 | + case KEX_GSS_GRP1_SHA1: | ||
1632 | + dh = dh_new_group1(); | ||
1633 | + break; | ||
1634 | + case KEX_GSS_GRP14_SHA1: | ||
1635 | + dh = dh_new_group14(); | ||
1636 | + break; | ||
1637 | + case KEX_GSS_GEX_SHA1: | ||
1638 | + debug("Doing group exchange\n"); | ||
1639 | + nbits = dh_estimate(ssh->kex->we_need * 8); | ||
1640 | + packet_start(SSH2_MSG_KEXGSS_GROUPREQ); | ||
1641 | + packet_put_int(min); | ||
1642 | + packet_put_int(nbits); | ||
1643 | + packet_put_int(max); | ||
1644 | + | ||
1645 | + packet_send(); | ||
1646 | + | ||
1647 | + packet_read_expect(SSH2_MSG_KEXGSS_GROUP); | ||
1648 | + | ||
1649 | + if ((p = BN_new()) == NULL) | ||
1650 | + fatal("BN_new() failed"); | ||
1651 | + packet_get_bignum2(p); | ||
1652 | + if ((g = BN_new()) == NULL) | ||
1653 | + fatal("BN_new() failed"); | ||
1654 | + packet_get_bignum2(g); | ||
1655 | + packet_check_eom(); | ||
1656 | + | ||
1657 | + if (BN_num_bits(p) < min || BN_num_bits(p) > max) | ||
1658 | + fatal("GSSGRP_GEX group out of range: %d !< %d !< %d", | ||
1659 | + min, BN_num_bits(p), max); | ||
1660 | + | ||
1661 | + dh = dh_new_group(g, p); | ||
1662 | + break; | ||
1663 | + default: | ||
1664 | + fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type); | ||
1665 | + } | ||
1666 | + | ||
1667 | + /* Step 1 - e is dh->pub_key */ | ||
1668 | + dh_gen_key(dh, ssh->kex->we_need * 8); | ||
1669 | + | ||
1670 | + /* This is f, we initialise it now to make life easier */ | ||
1671 | + dh_server_pub = BN_new(); | ||
1672 | + if (dh_server_pub == NULL) | ||
1673 | + fatal("dh_server_pub == NULL"); | ||
1674 | + | ||
1675 | + token_ptr = GSS_C_NO_BUFFER; | ||
1676 | + | ||
1677 | + do { | ||
1678 | + debug("Calling gss_init_sec_context"); | ||
1679 | + | ||
1680 | + maj_status = ssh_gssapi_init_ctx(ctxt, | ||
1681 | + ssh->kex->gss_deleg_creds, token_ptr, &send_tok, | ||
1682 | + &ret_flags); | ||
1683 | + | ||
1684 | + if (GSS_ERROR(maj_status)) { | ||
1685 | + if (send_tok.length != 0) { | ||
1686 | + packet_start(SSH2_MSG_KEXGSS_CONTINUE); | ||
1687 | + packet_put_string(send_tok.value, | ||
1688 | + send_tok.length); | ||
1689 | + } | ||
1690 | + fatal("gss_init_context failed"); | ||
1691 | + } | ||
1692 | + | ||
1693 | + /* If we've got an old receive buffer get rid of it */ | ||
1694 | + if (token_ptr != GSS_C_NO_BUFFER) | ||
1695 | + free(recv_tok.value); | ||
1696 | + | ||
1697 | + if (maj_status == GSS_S_COMPLETE) { | ||
1698 | + /* If mutual state flag is not true, kex fails */ | ||
1699 | + if (!(ret_flags & GSS_C_MUTUAL_FLAG)) | ||
1700 | + fatal("Mutual authentication failed"); | ||
1701 | + | ||
1702 | + /* If integ avail flag is not true kex fails */ | ||
1703 | + if (!(ret_flags & GSS_C_INTEG_FLAG)) | ||
1704 | + fatal("Integrity check failed"); | ||
1705 | + } | ||
1706 | + | ||
1707 | + /* | ||
1708 | + * If we have data to send, then the last message that we | ||
1709 | + * received cannot have been a 'complete'. | ||
1710 | + */ | ||
1711 | + if (send_tok.length != 0) { | ||
1712 | + if (first) { | ||
1713 | + packet_start(SSH2_MSG_KEXGSS_INIT); | ||
1714 | + packet_put_string(send_tok.value, | ||
1715 | + send_tok.length); | ||
1716 | + packet_put_bignum2(dh->pub_key); | ||
1717 | + first = 0; | ||
1718 | + } else { | ||
1719 | + packet_start(SSH2_MSG_KEXGSS_CONTINUE); | ||
1720 | + packet_put_string(send_tok.value, | ||
1721 | + send_tok.length); | ||
1722 | + } | ||
1723 | + packet_send(); | ||
1724 | + gss_release_buffer(&min_status, &send_tok); | ||
1725 | + | ||
1726 | + /* If we've sent them data, they should reply */ | ||
1727 | + do { | ||
1728 | + type = packet_read(); | ||
1729 | + if (type == SSH2_MSG_KEXGSS_HOSTKEY) { | ||
1730 | + debug("Received KEXGSS_HOSTKEY"); | ||
1731 | + if (serverhostkey) | ||
1732 | + fatal("Server host key received more than once"); | ||
1733 | + serverhostkey = | ||
1734 | + packet_get_string(&slen); | ||
1735 | + } | ||
1736 | + } while (type == SSH2_MSG_KEXGSS_HOSTKEY); | ||
1737 | + | ||
1738 | + switch (type) { | ||
1739 | + case SSH2_MSG_KEXGSS_CONTINUE: | ||
1740 | + debug("Received GSSAPI_CONTINUE"); | ||
1741 | + if (maj_status == GSS_S_COMPLETE) | ||
1742 | + fatal("GSSAPI Continue received from server when complete"); | ||
1743 | + recv_tok.value = packet_get_string(&strlen); | ||
1744 | + recv_tok.length = strlen; | ||
1745 | + break; | ||
1746 | + case SSH2_MSG_KEXGSS_COMPLETE: | ||
1747 | + debug("Received GSSAPI_COMPLETE"); | ||
1748 | + packet_get_bignum2(dh_server_pub); | ||
1749 | + msg_tok.value = packet_get_string(&strlen); | ||
1750 | + msg_tok.length = strlen; | ||
1751 | + | ||
1752 | + /* Is there a token included? */ | ||
1753 | + if (packet_get_char()) { | ||
1754 | + recv_tok.value= | ||
1755 | + packet_get_string(&strlen); | ||
1756 | + recv_tok.length = strlen; | ||
1757 | + /* If we're already complete - protocol error */ | ||
1758 | + if (maj_status == GSS_S_COMPLETE) | ||
1759 | + packet_disconnect("Protocol error: received token when complete"); | ||
1760 | + } else { | ||
1761 | + /* No token included */ | ||
1762 | + if (maj_status != GSS_S_COMPLETE) | ||
1763 | + packet_disconnect("Protocol error: did not receive final token"); | ||
1764 | + } | ||
1765 | + break; | ||
1766 | + case SSH2_MSG_KEXGSS_ERROR: | ||
1767 | + debug("Received Error"); | ||
1768 | + maj_status = packet_get_int(); | ||
1769 | + min_status = packet_get_int(); | ||
1770 | + msg = packet_get_string(NULL); | ||
1771 | + (void) packet_get_string_ptr(NULL); | ||
1772 | + fatal("GSSAPI Error: \n%.400s",msg); | ||
1773 | + default: | ||
1774 | + packet_disconnect("Protocol error: didn't expect packet type %d", | ||
1775 | + type); | ||
1776 | + } | ||
1777 | + token_ptr = &recv_tok; | ||
1778 | + } else { | ||
1779 | + /* No data, and not complete */ | ||
1780 | + if (maj_status != GSS_S_COMPLETE) | ||
1781 | + fatal("Not complete, and no token output"); | ||
1782 | + } | ||
1783 | + } while (maj_status & GSS_S_CONTINUE_NEEDED); | ||
1784 | + | ||
1785 | + /* | ||
1786 | + * We _must_ have received a COMPLETE message in reply from the | ||
1787 | + * server, which will have set dh_server_pub and msg_tok | ||
1788 | + */ | ||
1789 | + | ||
1790 | + if (type != SSH2_MSG_KEXGSS_COMPLETE) | ||
1791 | + fatal("Didn't receive a SSH2_MSG_KEXGSS_COMPLETE when I expected it"); | ||
1792 | + | ||
1793 | + /* Check f in range [1, p-1] */ | ||
1794 | + if (!dh_pub_is_valid(dh, dh_server_pub)) | ||
1795 | + packet_disconnect("bad server public DH value"); | ||
1796 | + | ||
1797 | + /* compute K=f^x mod p */ | ||
1798 | + klen = DH_size(dh); | ||
1799 | + kbuf = xmalloc(klen); | ||
1800 | + kout = DH_compute_key(kbuf, dh_server_pub, dh); | ||
1801 | + if (kout < 0) | ||
1802 | + fatal("DH_compute_key: failed"); | ||
1803 | + | ||
1804 | + shared_secret = BN_new(); | ||
1805 | + if (shared_secret == NULL) | ||
1806 | + fatal("kexgss_client: BN_new failed"); | ||
1807 | + | ||
1808 | + if (BN_bin2bn(kbuf, kout, shared_secret) == NULL) | ||
1809 | + fatal("kexdh_client: BN_bin2bn failed"); | ||
1810 | + | ||
1811 | + memset(kbuf, 0, klen); | ||
1812 | + free(kbuf); | ||
1813 | + | ||
1814 | + hashlen = sizeof(hash); | ||
1815 | + switch (ssh->kex->kex_type) { | ||
1816 | + case KEX_GSS_GRP1_SHA1: | ||
1817 | + case KEX_GSS_GRP14_SHA1: | ||
1818 | + kex_dh_hash( | ||
1819 | + ssh->kex->hash_alg, | ||
1820 | + ssh->kex->client_version_string, | ||
1821 | + ssh->kex->server_version_string, | ||
1822 | + sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my), | ||
1823 | + sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer), | ||
1824 | + (serverhostkey ? serverhostkey : empty), slen, | ||
1825 | + dh->pub_key, /* e */ | ||
1826 | + dh_server_pub, /* f */ | ||
1827 | + shared_secret, /* K */ | ||
1828 | + hash, &hashlen | ||
1829 | + ); | ||
1830 | + break; | ||
1831 | + case KEX_GSS_GEX_SHA1: | ||
1832 | + kexgex_hash( | ||
1833 | + ssh->kex->hash_alg, | ||
1834 | + ssh->kex->client_version_string, | ||
1835 | + ssh->kex->server_version_string, | ||
1836 | + sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my), | ||
1837 | + sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer), | ||
1838 | + (serverhostkey ? serverhostkey : empty), slen, | ||
1839 | + min, nbits, max, | ||
1840 | + dh->p, dh->g, | ||
1841 | + dh->pub_key, | ||
1842 | + dh_server_pub, | ||
1843 | + shared_secret, | ||
1844 | + hash, &hashlen | ||
1845 | + ); | ||
1846 | + break; | ||
1847 | + default: | ||
1848 | + fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type); | ||
1849 | + } | ||
1850 | + | ||
1851 | + gssbuf.value = hash; | ||
1852 | + gssbuf.length = hashlen; | ||
1853 | + | ||
1854 | + /* Verify that the hash matches the MIC we just got. */ | ||
1855 | + if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok))) | ||
1856 | + packet_disconnect("Hash's MIC didn't verify"); | ||
1857 | + | ||
1858 | + free(msg_tok.value); | ||
1859 | + | ||
1860 | + DH_free(dh); | ||
1861 | + free(serverhostkey); | ||
1862 | + BN_clear_free(dh_server_pub); | ||
1863 | + | ||
1864 | + /* save session id */ | ||
1865 | + if (ssh->kex->session_id == NULL) { | ||
1866 | + ssh->kex->session_id_len = hashlen; | ||
1867 | + ssh->kex->session_id = xmalloc(ssh->kex->session_id_len); | ||
1868 | + memcpy(ssh->kex->session_id, hash, ssh->kex->session_id_len); | ||
1869 | + } | ||
1870 | + | ||
1871 | + if (ssh->kex->gss_deleg_creds) | ||
1872 | + ssh_gssapi_credentials_updated(ctxt); | ||
1873 | + | ||
1874 | + if (gss_kex_context == NULL) | ||
1875 | + gss_kex_context = ctxt; | ||
1876 | + else | ||
1877 | + ssh_gssapi_delete_ctx(&ctxt); | ||
1878 | + | ||
1879 | + kex_derive_keys_bn(ssh, hash, hashlen, shared_secret); | ||
1880 | + BN_clear_free(shared_secret); | ||
1881 | + return kex_send_newkeys(ssh); | ||
1882 | +} | ||
1883 | + | ||
1884 | +#endif /* GSSAPI */ | ||
1885 | diff --git a/kexgsss.c b/kexgsss.c | ||
1886 | new file mode 100644 | ||
1887 | index 000000000..31ec6a890 | ||
1888 | --- /dev/null | ||
1889 | +++ b/kexgsss.c | ||
1890 | @@ -0,0 +1,295 @@ | ||
1891 | +/* | ||
1892 | + * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved. | ||
1893 | + * | ||
1894 | + * Redistribution and use in source and binary forms, with or without | ||
1895 | + * modification, are permitted provided that the following conditions | ||
1896 | + * are met: | ||
1897 | + * 1. Redistributions of source code must retain the above copyright | ||
1898 | + * notice, this list of conditions and the following disclaimer. | ||
1899 | + * 2. Redistributions in binary form must reproduce the above copyright | ||
1900 | + * notice, this list of conditions and the following disclaimer in the | ||
1901 | + * documentation and/or other materials provided with the distribution. | ||
1902 | + * | ||
1903 | + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR | ||
1904 | + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
1905 | + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
1906 | + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
1907 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
1908 | + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
1909 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
1910 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
1911 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
1912 | + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
1913 | + */ | ||
1914 | + | ||
1915 | +#include "includes.h" | ||
1916 | + | ||
1917 | +#ifdef GSSAPI | ||
1918 | + | ||
1919 | +#include <string.h> | ||
1920 | + | ||
1921 | +#include <openssl/crypto.h> | ||
1922 | +#include <openssl/bn.h> | ||
1923 | + | ||
1924 | +#include "xmalloc.h" | ||
1925 | +#include "sshbuf.h" | ||
1926 | +#include "ssh2.h" | ||
1927 | +#include "sshkey.h" | ||
1928 | +#include "cipher.h" | ||
1929 | +#include "kex.h" | ||
1930 | +#include "log.h" | ||
1931 | +#include "packet.h" | ||
1932 | +#include "dh.h" | ||
1933 | +#include "ssh-gss.h" | ||
1934 | +#include "monitor_wrap.h" | ||
1935 | +#include "misc.h" | ||
1936 | +#include "servconf.h" | ||
1937 | +#include "digest.h" | ||
1938 | + | ||
1939 | +extern ServerOptions options; | ||
1940 | + | ||
1941 | +int | ||
1942 | +kexgss_server(struct ssh *ssh) | ||
1943 | +{ | ||
1944 | + OM_uint32 maj_status, min_status; | ||
1945 | + | ||
1946 | + /* | ||
1947 | + * Some GSSAPI implementations use the input value of ret_flags (an | ||
1948 | + * output variable) as a means of triggering mechanism specific | ||
1949 | + * features. Initializing it to zero avoids inadvertently | ||
1950 | + * activating this non-standard behaviour. | ||
1951 | + */ | ||
1952 | + | ||
1953 | + OM_uint32 ret_flags = 0; | ||
1954 | + gss_buffer_desc gssbuf, recv_tok, msg_tok; | ||
1955 | + gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER; | ||
1956 | + Gssctxt *ctxt = NULL; | ||
1957 | + u_int slen, klen, kout; | ||
1958 | + u_char *kbuf; | ||
1959 | + DH *dh; | ||
1960 | + int min = -1, max = -1, nbits = -1; | ||
1961 | + BIGNUM *shared_secret = NULL; | ||
1962 | + BIGNUM *dh_client_pub = NULL; | ||
1963 | + int type = 0; | ||
1964 | + gss_OID oid; | ||
1965 | + char *mechs; | ||
1966 | + u_char hash[SSH_DIGEST_MAX_LENGTH]; | ||
1967 | + size_t hashlen; | ||
1968 | + | ||
1969 | + /* Initialise GSSAPI */ | ||
1970 | + | ||
1971 | + /* If we're rekeying, privsep means that some of the private structures | ||
1972 | + * in the GSSAPI code are no longer available. This kludges them back | ||
1973 | + * into life | ||
1974 | + */ | ||
1975 | + if (!ssh_gssapi_oid_table_ok()) { | ||
1976 | + mechs = ssh_gssapi_server_mechanisms(); | ||
1977 | + free(mechs); | ||
1978 | + } | ||
1979 | + | ||
1980 | + debug2("%s: Identifying %s", __func__, ssh->kex->name); | ||
1981 | + oid = ssh_gssapi_id_kex(NULL, ssh->kex->name, ssh->kex->kex_type); | ||
1982 | + if (oid == GSS_C_NO_OID) | ||
1983 | + fatal("Unknown gssapi mechanism"); | ||
1984 | + | ||
1985 | + debug2("%s: Acquiring credentials", __func__); | ||
1986 | + | ||
1987 | + if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid)))) | ||
1988 | + fatal("Unable to acquire credentials for the server"); | ||
1989 | + | ||
1990 | + switch (ssh->kex->kex_type) { | ||
1991 | + case KEX_GSS_GRP1_SHA1: | ||
1992 | + dh = dh_new_group1(); | ||
1993 | + break; | ||
1994 | + case KEX_GSS_GRP14_SHA1: | ||
1995 | + dh = dh_new_group14(); | ||
1996 | + break; | ||
1997 | + case KEX_GSS_GEX_SHA1: | ||
1998 | + debug("Doing group exchange"); | ||
1999 | + packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ); | ||
2000 | + min = packet_get_int(); | ||
2001 | + nbits = packet_get_int(); | ||
2002 | + max = packet_get_int(); | ||
2003 | + packet_check_eom(); | ||
2004 | + if (max < min || nbits < min || max < nbits) | ||
2005 | + fatal("GSS_GEX, bad parameters: %d !< %d !< %d", | ||
2006 | + min, nbits, max); | ||
2007 | + dh = PRIVSEP(choose_dh(MAX(DH_GRP_MIN, min), | ||
2008 | + nbits, MIN(DH_GRP_MAX, max))); | ||
2009 | + if (dh == NULL) | ||
2010 | + packet_disconnect("Protocol error: no matching group found"); | ||
2011 | + | ||
2012 | + packet_start(SSH2_MSG_KEXGSS_GROUP); | ||
2013 | + packet_put_bignum2(dh->p); | ||
2014 | + packet_put_bignum2(dh->g); | ||
2015 | + packet_send(); | ||
2016 | + | ||
2017 | + packet_write_wait(); | ||
2018 | + break; | ||
2019 | + default: | ||
2020 | + fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type); | ||
2021 | + } | ||
2022 | + | ||
2023 | + dh_gen_key(dh, ssh->kex->we_need * 8); | ||
2024 | + | ||
2025 | + do { | ||
2026 | + debug("Wait SSH2_MSG_GSSAPI_INIT"); | ||
2027 | + type = packet_read(); | ||
2028 | + switch(type) { | ||
2029 | + case SSH2_MSG_KEXGSS_INIT: | ||
2030 | + if (dh_client_pub != NULL) | ||
2031 | + fatal("Received KEXGSS_INIT after initialising"); | ||
2032 | + recv_tok.value = packet_get_string(&slen); | ||
2033 | + recv_tok.length = slen; | ||
2034 | + | ||
2035 | + if ((dh_client_pub = BN_new()) == NULL) | ||
2036 | + fatal("dh_client_pub == NULL"); | ||
2037 | + | ||
2038 | + packet_get_bignum2(dh_client_pub); | ||
2039 | + | ||
2040 | + /* Send SSH_MSG_KEXGSS_HOSTKEY here, if we want */ | ||
2041 | + break; | ||
2042 | + case SSH2_MSG_KEXGSS_CONTINUE: | ||
2043 | + recv_tok.value = packet_get_string(&slen); | ||
2044 | + recv_tok.length = slen; | ||
2045 | + break; | ||
2046 | + default: | ||
2047 | + packet_disconnect( | ||
2048 | + "Protocol error: didn't expect packet type %d", | ||
2049 | + type); | ||
2050 | + } | ||
2051 | + | ||
2052 | + maj_status = PRIVSEP(ssh_gssapi_accept_ctx(ctxt, &recv_tok, | ||
2053 | + &send_tok, &ret_flags)); | ||
2054 | + | ||
2055 | + free(recv_tok.value); | ||
2056 | + | ||
2057 | + if (maj_status != GSS_S_COMPLETE && send_tok.length == 0) | ||
2058 | + fatal("Zero length token output when incomplete"); | ||
2059 | + | ||
2060 | + if (dh_client_pub == NULL) | ||
2061 | + fatal("No client public key"); | ||
2062 | + | ||
2063 | + if (maj_status & GSS_S_CONTINUE_NEEDED) { | ||
2064 | + debug("Sending GSSAPI_CONTINUE"); | ||
2065 | + packet_start(SSH2_MSG_KEXGSS_CONTINUE); | ||
2066 | + packet_put_string(send_tok.value, send_tok.length); | ||
2067 | + packet_send(); | ||
2068 | + gss_release_buffer(&min_status, &send_tok); | ||
2069 | + } | ||
2070 | + } while (maj_status & GSS_S_CONTINUE_NEEDED); | ||
2071 | + | ||
2072 | + if (GSS_ERROR(maj_status)) { | ||
2073 | + if (send_tok.length > 0) { | ||
2074 | + packet_start(SSH2_MSG_KEXGSS_CONTINUE); | ||
2075 | + packet_put_string(send_tok.value, send_tok.length); | ||
2076 | + packet_send(); | ||
2077 | + } | ||
2078 | + fatal("accept_ctx died"); | ||
2079 | + } | ||
2080 | + | ||
2081 | + if (!(ret_flags & GSS_C_MUTUAL_FLAG)) | ||
2082 | + fatal("Mutual Authentication flag wasn't set"); | ||
2083 | + | ||
2084 | + if (!(ret_flags & GSS_C_INTEG_FLAG)) | ||
2085 | + fatal("Integrity flag wasn't set"); | ||
2086 | + | ||
2087 | + if (!dh_pub_is_valid(dh, dh_client_pub)) | ||
2088 | + packet_disconnect("bad client public DH value"); | ||
2089 | + | ||
2090 | + klen = DH_size(dh); | ||
2091 | + kbuf = xmalloc(klen); | ||
2092 | + kout = DH_compute_key(kbuf, dh_client_pub, dh); | ||
2093 | + if (kout < 0) | ||
2094 | + fatal("DH_compute_key: failed"); | ||
2095 | + | ||
2096 | + shared_secret = BN_new(); | ||
2097 | + if (shared_secret == NULL) | ||
2098 | + fatal("kexgss_server: BN_new failed"); | ||
2099 | + | ||
2100 | + if (BN_bin2bn(kbuf, kout, shared_secret) == NULL) | ||
2101 | + fatal("kexgss_server: BN_bin2bn failed"); | ||
2102 | + | ||
2103 | + memset(kbuf, 0, klen); | ||
2104 | + free(kbuf); | ||
2105 | + | ||
2106 | + hashlen = sizeof(hash); | ||
2107 | + switch (ssh->kex->kex_type) { | ||
2108 | + case KEX_GSS_GRP1_SHA1: | ||
2109 | + case KEX_GSS_GRP14_SHA1: | ||
2110 | + kex_dh_hash( | ||
2111 | + ssh->kex->hash_alg, | ||
2112 | + ssh->kex->client_version_string, ssh->kex->server_version_string, | ||
2113 | + sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer), | ||
2114 | + sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my), | ||
2115 | + NULL, 0, /* Change this if we start sending host keys */ | ||
2116 | + dh_client_pub, dh->pub_key, shared_secret, | ||
2117 | + hash, &hashlen | ||
2118 | + ); | ||
2119 | + break; | ||
2120 | + case KEX_GSS_GEX_SHA1: | ||
2121 | + kexgex_hash( | ||
2122 | + ssh->kex->hash_alg, | ||
2123 | + ssh->kex->client_version_string, ssh->kex->server_version_string, | ||
2124 | + sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer), | ||
2125 | + sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my), | ||
2126 | + NULL, 0, | ||
2127 | + min, nbits, max, | ||
2128 | + dh->p, dh->g, | ||
2129 | + dh_client_pub, | ||
2130 | + dh->pub_key, | ||
2131 | + shared_secret, | ||
2132 | + hash, &hashlen | ||
2133 | + ); | ||
2134 | + break; | ||
2135 | + default: | ||
2136 | + fatal("%s: Unexpected KEX type %d", __func__, ssh->kex->kex_type); | ||
2137 | + } | ||
2138 | + | ||
2139 | + BN_clear_free(dh_client_pub); | ||
2140 | + | ||
2141 | + if (ssh->kex->session_id == NULL) { | ||
2142 | + ssh->kex->session_id_len = hashlen; | ||
2143 | + ssh->kex->session_id = xmalloc(ssh->kex->session_id_len); | ||
2144 | + memcpy(ssh->kex->session_id, hash, ssh->kex->session_id_len); | ||
2145 | + } | ||
2146 | + | ||
2147 | + gssbuf.value = hash; | ||
2148 | + gssbuf.length = hashlen; | ||
2149 | + | ||
2150 | + if (GSS_ERROR(PRIVSEP(ssh_gssapi_sign(ctxt,&gssbuf,&msg_tok)))) | ||
2151 | + fatal("Couldn't get MIC"); | ||
2152 | + | ||
2153 | + packet_start(SSH2_MSG_KEXGSS_COMPLETE); | ||
2154 | + packet_put_bignum2(dh->pub_key); | ||
2155 | + packet_put_string(msg_tok.value,msg_tok.length); | ||
2156 | + | ||
2157 | + if (send_tok.length != 0) { | ||
2158 | + packet_put_char(1); /* true */ | ||
2159 | + packet_put_string(send_tok.value, send_tok.length); | ||
2160 | + } else { | ||
2161 | + packet_put_char(0); /* false */ | ||
2162 | + } | ||
2163 | + packet_send(); | ||
2164 | + | ||
2165 | + gss_release_buffer(&min_status, &send_tok); | ||
2166 | + gss_release_buffer(&min_status, &msg_tok); | ||
2167 | + | ||
2168 | + if (gss_kex_context == NULL) | ||
2169 | + gss_kex_context = ctxt; | ||
2170 | + else | ||
2171 | + ssh_gssapi_delete_ctx(&ctxt); | ||
2172 | + | ||
2173 | + DH_free(dh); | ||
2174 | + | ||
2175 | + kex_derive_keys_bn(ssh, hash, hashlen, shared_secret); | ||
2176 | + BN_clear_free(shared_secret); | ||
2177 | + kex_send_newkeys(ssh); | ||
2178 | + | ||
2179 | + /* If this was a rekey, then save out any delegated credentials we | ||
2180 | + * just exchanged. */ | ||
2181 | + if (options.gss_store_rekey) | ||
2182 | + ssh_gssapi_rekey_creds(); | ||
2183 | + return 0; | ||
2184 | +} | ||
2185 | +#endif /* GSSAPI */ | ||
2186 | diff --git a/monitor.c b/monitor.c | ||
2187 | index d4b4b0471..4e574a2ae 100644 | ||
2188 | --- a/monitor.c | ||
2189 | +++ b/monitor.c | ||
2190 | @@ -143,6 +143,8 @@ int mm_answer_gss_setup_ctx(int, struct sshbuf *); | ||
2191 | int mm_answer_gss_accept_ctx(int, struct sshbuf *); | ||
2192 | int mm_answer_gss_userok(int, struct sshbuf *); | ||
2193 | int mm_answer_gss_checkmic(int, struct sshbuf *); | ||
2194 | +int mm_answer_gss_sign(int, struct sshbuf *); | ||
2195 | +int mm_answer_gss_updatecreds(int, struct sshbuf *); | ||
2196 | #endif | ||
2197 | |||
2198 | #ifdef SSH_AUDIT_EVENTS | ||
2199 | @@ -213,11 +215,18 @@ struct mon_table mon_dispatch_proto20[] = { | ||
2200 | {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx}, | ||
2201 | {MONITOR_REQ_GSSUSEROK, MON_ONCE|MON_AUTHDECIDE, mm_answer_gss_userok}, | ||
2202 | {MONITOR_REQ_GSSCHECKMIC, MON_ONCE, mm_answer_gss_checkmic}, | ||
2203 | + {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign}, | ||
2204 | #endif | ||
2205 | {0, 0, NULL} | ||
2206 | }; | ||
2207 | |||
2208 | struct mon_table mon_dispatch_postauth20[] = { | ||
2209 | +#ifdef GSSAPI | ||
2210 | + {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx}, | ||
2211 | + {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx}, | ||
2212 | + {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign}, | ||
2213 | + {MONITOR_REQ_GSSUPCREDS, 0, mm_answer_gss_updatecreds}, | ||
2214 | +#endif | ||
2215 | #ifdef WITH_OPENSSL | ||
2216 | {MONITOR_REQ_MODULI, 0, mm_answer_moduli}, | ||
2217 | #endif | ||
2218 | @@ -287,6 +296,10 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor) | ||
2219 | /* Permit requests for moduli and signatures */ | ||
2220 | monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); | ||
2221 | monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); | ||
2222 | +#ifdef GSSAPI | ||
2223 | + /* and for the GSSAPI key exchange */ | ||
2224 | + monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1); | ||
2225 | +#endif | ||
2226 | |||
2227 | /* The first few requests do not require asynchronous access */ | ||
2228 | while (!authenticated) { | ||
2229 | @@ -399,6 +412,10 @@ monitor_child_postauth(struct monitor *pmonitor) | ||
2230 | monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); | ||
2231 | monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); | ||
2232 | monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1); | ||
2233 | +#ifdef GSSAPI | ||
2234 | + /* and for the GSSAPI key exchange */ | ||
2235 | + monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1); | ||
2236 | +#endif | ||
2237 | |||
2238 | if (auth_opts->permit_pty_flag) { | ||
2239 | monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1); | ||
2240 | @@ -1662,6 +1679,13 @@ monitor_apply_keystate(struct monitor *pmonitor) | ||
2241 | # endif | ||
2242 | #endif /* WITH_OPENSSL */ | ||
2243 | kex->kex[KEX_C25519_SHA256] = kexc25519_server; | ||
2244 | +#ifdef GSSAPI | ||
2245 | + if (options.gss_keyex) { | ||
2246 | + kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server; | ||
2247 | + kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server; | ||
2248 | + kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server; | ||
2249 | + } | ||
2250 | +#endif | ||
2251 | kex->load_host_public_key=&get_hostkey_public_by_type; | ||
2252 | kex->load_host_private_key=&get_hostkey_private_by_type; | ||
2253 | kex->host_key_index=&get_hostkey_index; | ||
2254 | @@ -1752,8 +1776,8 @@ mm_answer_gss_setup_ctx(int sock, struct sshbuf *m) | ||
2255 | u_char *p; | ||
2256 | int r; | ||
2257 | |||
2258 | - if (!options.gss_authentication) | ||
2259 | - fatal("%s: GSSAPI authentication not enabled", __func__); | ||
2260 | + if (!options.gss_authentication && !options.gss_keyex) | ||
2261 | + fatal("%s: GSSAPI not enabled", __func__); | ||
2262 | |||
2263 | if ((r = sshbuf_get_string(m, &p, &len)) != 0) | ||
2264 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2265 | @@ -1785,8 +1809,8 @@ mm_answer_gss_accept_ctx(int sock, struct sshbuf *m) | ||
2266 | OM_uint32 flags = 0; /* GSI needs this */ | ||
2267 | int r; | ||
2268 | |||
2269 | - if (!options.gss_authentication) | ||
2270 | - fatal("%s: GSSAPI authentication not enabled", __func__); | ||
2271 | + if (!options.gss_authentication && !options.gss_keyex) | ||
2272 | + fatal("%s: GSSAPI not enabled", __func__); | ||
2273 | |||
2274 | if ((r = ssh_gssapi_get_buffer_desc(m, &in)) != 0) | ||
2275 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2276 | @@ -1806,6 +1830,7 @@ mm_answer_gss_accept_ctx(int sock, struct sshbuf *m) | ||
2277 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0); | ||
2278 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1); | ||
2279 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1); | ||
2280 | + monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1); | ||
2281 | } | ||
2282 | return (0); | ||
2283 | } | ||
2284 | @@ -1817,8 +1842,8 @@ mm_answer_gss_checkmic(int sock, struct sshbuf *m) | ||
2285 | OM_uint32 ret; | ||
2286 | int r; | ||
2287 | |||
2288 | - if (!options.gss_authentication) | ||
2289 | - fatal("%s: GSSAPI authentication not enabled", __func__); | ||
2290 | + if (!options.gss_authentication && !options.gss_keyex) | ||
2291 | + fatal("%s: GSSAPI not enabled", __func__); | ||
2292 | |||
2293 | if ((r = ssh_gssapi_get_buffer_desc(m, &gssbuf)) != 0 || | ||
2294 | (r = ssh_gssapi_get_buffer_desc(m, &mic)) != 0) | ||
2295 | @@ -1847,10 +1872,11 @@ mm_answer_gss_userok(int sock, struct sshbuf *m) | ||
2296 | int r, authenticated; | ||
2297 | const char *displayname; | ||
2298 | |||
2299 | - if (!options.gss_authentication) | ||
2300 | - fatal("%s: GSSAPI authentication not enabled", __func__); | ||
2301 | + if (!options.gss_authentication && !options.gss_keyex) | ||
2302 | + fatal("%s: GSSAPI not enabled", __func__); | ||
2303 | |||
2304 | - authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user); | ||
2305 | + authenticated = authctxt->valid && | ||
2306 | + ssh_gssapi_userok(authctxt->user, authctxt->pw); | ||
2307 | |||
2308 | sshbuf_reset(m); | ||
2309 | if ((r = sshbuf_put_u32(m, authenticated)) != 0) | ||
2310 | @@ -1867,5 +1893,83 @@ mm_answer_gss_userok(int sock, struct sshbuf *m) | ||
2311 | /* Monitor loop will terminate if authenticated */ | ||
2312 | return (authenticated); | ||
2313 | } | ||
2314 | + | ||
2315 | +int | ||
2316 | +mm_answer_gss_sign(int socket, struct sshbuf *m) | ||
2317 | +{ | ||
2318 | + gss_buffer_desc data; | ||
2319 | + gss_buffer_desc hash = GSS_C_EMPTY_BUFFER; | ||
2320 | + OM_uint32 major, minor; | ||
2321 | + size_t len; | ||
2322 | + u_char *p; | ||
2323 | + int r; | ||
2324 | + | ||
2325 | + if (!options.gss_authentication && !options.gss_keyex) | ||
2326 | + fatal("%s: GSSAPI not enabled", __func__); | ||
2327 | + | ||
2328 | + if ((r = sshbuf_get_string(m, &p, &len)) != 0) | ||
2329 | + fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2330 | + data.value = p; | ||
2331 | + data.length = len; | ||
2332 | + if (data.length != 20) | ||
2333 | + fatal("%s: data length incorrect: %d", __func__, | ||
2334 | + (int) data.length); | ||
2335 | + | ||
2336 | + /* Save the session ID on the first time around */ | ||
2337 | + if (session_id2_len == 0) { | ||
2338 | + session_id2_len = data.length; | ||
2339 | + session_id2 = xmalloc(session_id2_len); | ||
2340 | + memcpy(session_id2, data.value, session_id2_len); | ||
2341 | + } | ||
2342 | + major = ssh_gssapi_sign(gsscontext, &data, &hash); | ||
2343 | + | ||
2344 | + free(data.value); | ||
2345 | + | ||
2346 | + sshbuf_reset(m); | ||
2347 | + if ((r = sshbuf_put_u32(m, major)) != 0 || | ||
2348 | + (r = sshbuf_put_string(m, hash.value, hash.length)) != 0) | ||
2349 | + fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2350 | + | ||
2351 | + mm_request_send(socket, MONITOR_ANS_GSSSIGN, m); | ||
2352 | + | ||
2353 | + gss_release_buffer(&minor, &hash); | ||
2354 | + | ||
2355 | + /* Turn on getpwnam permissions */ | ||
2356 | + monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1); | ||
2357 | + | ||
2358 | + /* And credential updating, for when rekeying */ | ||
2359 | + monitor_permit(mon_dispatch, MONITOR_REQ_GSSUPCREDS, 1); | ||
2360 | + | ||
2361 | + return (0); | ||
2362 | +} | ||
2363 | + | ||
2364 | +int | ||
2365 | +mm_answer_gss_updatecreds(int socket, struct sshbuf *m) { | ||
2366 | + ssh_gssapi_ccache store; | ||
2367 | + int r, ok; | ||
2368 | + | ||
2369 | + if (!options.gss_authentication && !options.gss_keyex) | ||
2370 | + fatal("%s: GSSAPI not enabled", __func__); | ||
2371 | + | ||
2372 | + if ((r = sshbuf_get_cstring(m, &store.filename, NULL)) != 0 || | ||
2373 | + (r = sshbuf_get_cstring(m, &store.envvar, NULL)) != 0 || | ||
2374 | + (r = sshbuf_get_cstring(m, &store.envval, NULL)) != 0) | ||
2375 | + fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2376 | + | ||
2377 | + ok = ssh_gssapi_update_creds(&store); | ||
2378 | + | ||
2379 | + free(store.filename); | ||
2380 | + free(store.envvar); | ||
2381 | + free(store.envval); | ||
2382 | + | ||
2383 | + sshbuf_reset(m); | ||
2384 | + if ((r = sshbuf_put_u32(m, ok)) != 0) | ||
2385 | + fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2386 | + | ||
2387 | + mm_request_send(socket, MONITOR_ANS_GSSUPCREDS, m); | ||
2388 | + | ||
2389 | + return(0); | ||
2390 | +} | ||
2391 | + | ||
2392 | #endif /* GSSAPI */ | ||
2393 | |||
2394 | diff --git a/monitor.h b/monitor.h | ||
2395 | index 16047299f..44fbed589 100644 | ||
2396 | --- a/monitor.h | ||
2397 | +++ b/monitor.h | ||
2398 | @@ -63,6 +63,9 @@ enum monitor_reqtype { | ||
2399 | MONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111, | ||
2400 | MONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113, | ||
2401 | |||
2402 | + MONITOR_REQ_GSSSIGN = 150, MONITOR_ANS_GSSSIGN = 151, | ||
2403 | + MONITOR_REQ_GSSUPCREDS = 152, MONITOR_ANS_GSSUPCREDS = 153, | ||
2404 | + | ||
2405 | }; | ||
2406 | |||
2407 | struct monitor { | ||
2408 | diff --git a/monitor_wrap.c b/monitor_wrap.c | ||
2409 | index 732fb3476..1865a122a 100644 | ||
2410 | --- a/monitor_wrap.c | ||
2411 | +++ b/monitor_wrap.c | ||
2412 | @@ -984,7 +984,7 @@ mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic) | ||
2413 | } | ||
2414 | |||
2415 | int | ||
2416 | -mm_ssh_gssapi_userok(char *user) | ||
2417 | +mm_ssh_gssapi_userok(char *user, struct passwd *pw) | ||
2418 | { | ||
2419 | struct sshbuf *m; | ||
2420 | int r, authenticated = 0; | ||
2421 | @@ -1003,4 +1003,55 @@ mm_ssh_gssapi_userok(char *user) | ||
2422 | debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not "); | ||
2423 | return (authenticated); | ||
2424 | } | ||
2425 | + | ||
2426 | +OM_uint32 | ||
2427 | +mm_ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_desc *data, gss_buffer_desc *hash) | ||
2428 | +{ | ||
2429 | + struct sshbuf *m; | ||
2430 | + OM_uint32 major; | ||
2431 | + int r; | ||
2432 | + | ||
2433 | + if ((m = sshbuf_new()) == NULL) | ||
2434 | + fatal("%s: sshbuf_new failed", __func__); | ||
2435 | + if ((r = sshbuf_put_string(m, data->value, data->length)) != 0) | ||
2436 | + fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2437 | + | ||
2438 | + mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSIGN, m); | ||
2439 | + mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSIGN, m); | ||
2440 | + | ||
2441 | + if ((r = sshbuf_get_u32(m, &major)) != 0 || | ||
2442 | + (r = ssh_gssapi_get_buffer_desc(m, hash)) != 0) | ||
2443 | + fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2444 | + | ||
2445 | + sshbuf_free(m); | ||
2446 | + | ||
2447 | + return(major); | ||
2448 | +} | ||
2449 | + | ||
2450 | +int | ||
2451 | +mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store) | ||
2452 | +{ | ||
2453 | + struct sshbuf *m; | ||
2454 | + int r, ok; | ||
2455 | + | ||
2456 | + if ((m = sshbuf_new()) == NULL) | ||
2457 | + fatal("%s: sshbuf_new failed", __func__); | ||
2458 | + if ((r = sshbuf_put_cstring(m, | ||
2459 | + store->filename ? store->filename : "")) != 0 || | ||
2460 | + (r = sshbuf_put_cstring(m, | ||
2461 | + store->envvar ? store->envvar : "")) != 0 || | ||
2462 | + (r = sshbuf_put_cstring(m, | ||
2463 | + store->envval ? store->envval : "")) != 0) | ||
2464 | + fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2465 | + | ||
2466 | + mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUPCREDS, m); | ||
2467 | + mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUPCREDS, m); | ||
2468 | + | ||
2469 | + if ((r = sshbuf_get_u32(m, &ok)) != 0) | ||
2470 | + fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
2471 | + sshbuf_free(m); | ||
2472 | + | ||
2473 | + return (ok); | ||
2474 | +} | ||
2475 | + | ||
2476 | #endif /* GSSAPI */ | ||
2477 | diff --git a/monitor_wrap.h b/monitor_wrap.h | ||
2478 | index 644da081d..7f93144ff 100644 | ||
2479 | --- a/monitor_wrap.h | ||
2480 | +++ b/monitor_wrap.h | ||
2481 | @@ -60,8 +60,10 @@ int mm_sshkey_verify(const struct sshkey *, const u_char *, size_t, | ||
2482 | OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID); | ||
2483 | OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *, | ||
2484 | gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *); | ||
2485 | -int mm_ssh_gssapi_userok(char *user); | ||
2486 | +int mm_ssh_gssapi_userok(char *user, struct passwd *); | ||
2487 | OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t); | ||
2488 | +OM_uint32 mm_ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t); | ||
2489 | +int mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *); | ||
2490 | #endif | ||
2491 | |||
2492 | #ifdef USE_PAM | ||
2493 | diff --git a/readconf.c b/readconf.c | ||
2494 | index db5f2d547..4ad3c75fe 100644 | ||
2495 | --- a/readconf.c | ||
2496 | +++ b/readconf.c | ||
2497 | @@ -161,6 +161,8 @@ typedef enum { | ||
2498 | oClearAllForwardings, oNoHostAuthenticationForLocalhost, | ||
2499 | oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout, | ||
2500 | oAddressFamily, oGssAuthentication, oGssDelegateCreds, | ||
2501 | + oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey, | ||
2502 | + oGssServerIdentity, | ||
2503 | oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly, | ||
2504 | oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist, | ||
2505 | oHashKnownHosts, | ||
2506 | @@ -201,10 +203,20 @@ static struct { | ||
2507 | /* Sometimes-unsupported options */ | ||
2508 | #if defined(GSSAPI) | ||
2509 | { "gssapiauthentication", oGssAuthentication }, | ||
2510 | + { "gssapikeyexchange", oGssKeyEx }, | ||
2511 | { "gssapidelegatecredentials", oGssDelegateCreds }, | ||
2512 | + { "gssapitrustdns", oGssTrustDns }, | ||
2513 | + { "gssapiclientidentity", oGssClientIdentity }, | ||
2514 | + { "gssapiserveridentity", oGssServerIdentity }, | ||
2515 | + { "gssapirenewalforcesrekey", oGssRenewalRekey }, | ||
2516 | # else | ||
2517 | { "gssapiauthentication", oUnsupported }, | ||
2518 | + { "gssapikeyexchange", oUnsupported }, | ||
2519 | { "gssapidelegatecredentials", oUnsupported }, | ||
2520 | + { "gssapitrustdns", oUnsupported }, | ||
2521 | + { "gssapiclientidentity", oUnsupported }, | ||
2522 | + { "gssapiserveridentity", oUnsupported }, | ||
2523 | + { "gssapirenewalforcesrekey", oUnsupported }, | ||
2524 | #endif | ||
2525 | #ifdef ENABLE_PKCS11 | ||
2526 | { "smartcarddevice", oPKCS11Provider }, | ||
2527 | @@ -973,10 +985,30 @@ parse_time: | ||
2528 | intptr = &options->gss_authentication; | ||
2529 | goto parse_flag; | ||
2530 | |||
2531 | + case oGssKeyEx: | ||
2532 | + intptr = &options->gss_keyex; | ||
2533 | + goto parse_flag; | ||
2534 | + | ||
2535 | case oGssDelegateCreds: | ||
2536 | intptr = &options->gss_deleg_creds; | ||
2537 | goto parse_flag; | ||
2538 | |||
2539 | + case oGssTrustDns: | ||
2540 | + intptr = &options->gss_trust_dns; | ||
2541 | + goto parse_flag; | ||
2542 | + | ||
2543 | + case oGssClientIdentity: | ||
2544 | + charptr = &options->gss_client_identity; | ||
2545 | + goto parse_string; | ||
2546 | + | ||
2547 | + case oGssServerIdentity: | ||
2548 | + charptr = &options->gss_server_identity; | ||
2549 | + goto parse_string; | ||
2550 | + | ||
2551 | + case oGssRenewalRekey: | ||
2552 | + intptr = &options->gss_renewal_rekey; | ||
2553 | + goto parse_flag; | ||
2554 | + | ||
2555 | case oBatchMode: | ||
2556 | intptr = &options->batch_mode; | ||
2557 | goto parse_flag; | ||
2558 | @@ -1817,7 +1849,12 @@ initialize_options(Options * options) | ||
2559 | options->pubkey_authentication = -1; | ||
2560 | options->challenge_response_authentication = -1; | ||
2561 | options->gss_authentication = -1; | ||
2562 | + options->gss_keyex = -1; | ||
2563 | options->gss_deleg_creds = -1; | ||
2564 | + options->gss_trust_dns = -1; | ||
2565 | + options->gss_renewal_rekey = -1; | ||
2566 | + options->gss_client_identity = NULL; | ||
2567 | + options->gss_server_identity = NULL; | ||
2568 | options->password_authentication = -1; | ||
2569 | options->kbd_interactive_authentication = -1; | ||
2570 | options->kbd_interactive_devices = NULL; | ||
2571 | @@ -1962,8 +1999,14 @@ fill_default_options(Options * options) | ||
2572 | options->challenge_response_authentication = 1; | ||
2573 | if (options->gss_authentication == -1) | ||
2574 | options->gss_authentication = 0; | ||
2575 | + if (options->gss_keyex == -1) | ||
2576 | + options->gss_keyex = 0; | ||
2577 | if (options->gss_deleg_creds == -1) | ||
2578 | options->gss_deleg_creds = 0; | ||
2579 | + if (options->gss_trust_dns == -1) | ||
2580 | + options->gss_trust_dns = 0; | ||
2581 | + if (options->gss_renewal_rekey == -1) | ||
2582 | + options->gss_renewal_rekey = 0; | ||
2583 | if (options->password_authentication == -1) | ||
2584 | options->password_authentication = 1; | ||
2585 | if (options->kbd_interactive_authentication == -1) | ||
2586 | diff --git a/readconf.h b/readconf.h | ||
2587 | index c56887816..5ea0c296b 100644 | ||
2588 | --- a/readconf.h | ||
2589 | +++ b/readconf.h | ||
2590 | @@ -40,7 +40,12 @@ typedef struct { | ||
2591 | int challenge_response_authentication; | ||
2592 | /* Try S/Key or TIS, authentication. */ | ||
2593 | int gss_authentication; /* Try GSS authentication */ | ||
2594 | + int gss_keyex; /* Try GSS key exchange */ | ||
2595 | int gss_deleg_creds; /* Delegate GSS credentials */ | ||
2596 | + int gss_trust_dns; /* Trust DNS for GSS canonicalization */ | ||
2597 | + int gss_renewal_rekey; /* Credential renewal forces rekey */ | ||
2598 | + char *gss_client_identity; /* Principal to initiate GSSAPI with */ | ||
2599 | + char *gss_server_identity; /* GSSAPI target principal */ | ||
2600 | int password_authentication; /* Try password | ||
2601 | * authentication. */ | ||
2602 | int kbd_interactive_authentication; /* Try keyboard-interactive auth. */ | ||
2603 | diff --git a/servconf.c b/servconf.c | ||
2604 | index c0f6af0be..e1ae07fb7 100644 | ||
2605 | --- a/servconf.c | ||
2606 | +++ b/servconf.c | ||
2607 | @@ -124,8 +124,10 @@ initialize_server_options(ServerOptions *options) | ||
2608 | options->kerberos_ticket_cleanup = -1; | ||
2609 | options->kerberos_get_afs_token = -1; | ||
2610 | options->gss_authentication=-1; | ||
2611 | + options->gss_keyex = -1; | ||
2612 | options->gss_cleanup_creds = -1; | ||
2613 | options->gss_strict_acceptor = -1; | ||
2614 | + options->gss_store_rekey = -1; | ||
2615 | options->password_authentication = -1; | ||
2616 | options->kbd_interactive_authentication = -1; | ||
2617 | options->challenge_response_authentication = -1; | ||
2618 | @@ -333,10 +335,14 @@ fill_default_server_options(ServerOptions *options) | ||
2619 | options->kerberos_get_afs_token = 0; | ||
2620 | if (options->gss_authentication == -1) | ||
2621 | options->gss_authentication = 0; | ||
2622 | + if (options->gss_keyex == -1) | ||
2623 | + options->gss_keyex = 0; | ||
2624 | if (options->gss_cleanup_creds == -1) | ||
2625 | options->gss_cleanup_creds = 1; | ||
2626 | if (options->gss_strict_acceptor == -1) | ||
2627 | options->gss_strict_acceptor = 1; | ||
2628 | + if (options->gss_store_rekey == -1) | ||
2629 | + options->gss_store_rekey = 0; | ||
2630 | if (options->password_authentication == -1) | ||
2631 | options->password_authentication = 1; | ||
2632 | if (options->kbd_interactive_authentication == -1) | ||
2633 | @@ -481,6 +487,7 @@ typedef enum { | ||
2634 | sHostKeyAlgorithms, | ||
2635 | sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile, | ||
2636 | sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor, | ||
2637 | + sGssKeyEx, sGssStoreRekey, | ||
2638 | sAcceptEnv, sSetEnv, sPermitTunnel, | ||
2639 | sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory, | ||
2640 | sUsePrivilegeSeparation, sAllowAgentForwarding, | ||
2641 | @@ -555,12 +562,20 @@ static struct { | ||
2642 | #ifdef GSSAPI | ||
2643 | { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL }, | ||
2644 | { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL }, | ||
2645 | + { "gssapicleanupcreds", sGssCleanupCreds, SSHCFG_GLOBAL }, | ||
2646 | { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL }, | ||
2647 | + { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL }, | ||
2648 | + { "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL }, | ||
2649 | #else | ||
2650 | { "gssapiauthentication", sUnsupported, SSHCFG_ALL }, | ||
2651 | { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL }, | ||
2652 | + { "gssapicleanupcreds", sUnsupported, SSHCFG_GLOBAL }, | ||
2653 | { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL }, | ||
2654 | + { "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL }, | ||
2655 | + { "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL }, | ||
2656 | #endif | ||
2657 | + { "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL }, | ||
2658 | + { "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL }, | ||
2659 | { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL }, | ||
2660 | { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL }, | ||
2661 | { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, | ||
2662 | @@ -1459,6 +1474,10 @@ process_server_config_line(ServerOptions *options, char *line, | ||
2663 | intptr = &options->gss_authentication; | ||
2664 | goto parse_flag; | ||
2665 | |||
2666 | + case sGssKeyEx: | ||
2667 | + intptr = &options->gss_keyex; | ||
2668 | + goto parse_flag; | ||
2669 | + | ||
2670 | case sGssCleanupCreds: | ||
2671 | intptr = &options->gss_cleanup_creds; | ||
2672 | goto parse_flag; | ||
2673 | @@ -1467,6 +1486,10 @@ process_server_config_line(ServerOptions *options, char *line, | ||
2674 | intptr = &options->gss_strict_acceptor; | ||
2675 | goto parse_flag; | ||
2676 | |||
2677 | + case sGssStoreRekey: | ||
2678 | + intptr = &options->gss_store_rekey; | ||
2679 | + goto parse_flag; | ||
2680 | + | ||
2681 | case sPasswordAuthentication: | ||
2682 | intptr = &options->password_authentication; | ||
2683 | goto parse_flag; | ||
2684 | @@ -2551,7 +2574,10 @@ dump_config(ServerOptions *o) | ||
2685 | #endif | ||
2686 | #ifdef GSSAPI | ||
2687 | dump_cfg_fmtint(sGssAuthentication, o->gss_authentication); | ||
2688 | + dump_cfg_fmtint(sGssKeyEx, o->gss_keyex); | ||
2689 | dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds); | ||
2690 | + dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor); | ||
2691 | + dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey); | ||
2692 | #endif | ||
2693 | dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication); | ||
2694 | dump_cfg_fmtint(sKbdInteractiveAuthentication, | ||
2695 | diff --git a/servconf.h b/servconf.h | ||
2696 | index 557521d73..9b117fe27 100644 | ||
2697 | --- a/servconf.h | ||
2698 | +++ b/servconf.h | ||
2699 | @@ -124,8 +124,10 @@ typedef struct { | ||
2700 | int kerberos_get_afs_token; /* If true, try to get AFS token if | ||
2701 | * authenticated with Kerberos. */ | ||
2702 | int gss_authentication; /* If true, permit GSSAPI authentication */ | ||
2703 | + int gss_keyex; /* If true, permit GSSAPI key exchange */ | ||
2704 | int gss_cleanup_creds; /* If true, destroy cred cache on logout */ | ||
2705 | int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */ | ||
2706 | + int gss_store_rekey; | ||
2707 | int password_authentication; /* If true, permit password | ||
2708 | * authentication. */ | ||
2709 | int kbd_interactive_authentication; /* If true, permit */ | ||
2710 | diff --git a/ssh-gss.h b/ssh-gss.h | ||
2711 | index 36180d07a..350ce7882 100644 | ||
2712 | --- a/ssh-gss.h | ||
2713 | +++ b/ssh-gss.h | ||
2714 | @@ -1,6 +1,6 @@ | ||
2715 | /* $OpenBSD: ssh-gss.h,v 1.14 2018/07/10 09:13:30 djm Exp $ */ | ||
2716 | /* | ||
2717 | - * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. | ||
2718 | + * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved. | ||
2719 | * | ||
2720 | * Redistribution and use in source and binary forms, with or without | ||
2721 | * modification, are permitted provided that the following conditions | ||
2722 | @@ -61,10 +61,22 @@ | ||
2723 | |||
2724 | #define SSH_GSS_OIDTYPE 0x06 | ||
2725 | |||
2726 | +#define SSH2_MSG_KEXGSS_INIT 30 | ||
2727 | +#define SSH2_MSG_KEXGSS_CONTINUE 31 | ||
2728 | +#define SSH2_MSG_KEXGSS_COMPLETE 32 | ||
2729 | +#define SSH2_MSG_KEXGSS_HOSTKEY 33 | ||
2730 | +#define SSH2_MSG_KEXGSS_ERROR 34 | ||
2731 | +#define SSH2_MSG_KEXGSS_GROUPREQ 40 | ||
2732 | +#define SSH2_MSG_KEXGSS_GROUP 41 | ||
2733 | +#define KEX_GSS_GRP1_SHA1_ID "gss-group1-sha1-" | ||
2734 | +#define KEX_GSS_GRP14_SHA1_ID "gss-group14-sha1-" | ||
2735 | +#define KEX_GSS_GEX_SHA1_ID "gss-gex-sha1-" | ||
2736 | + | ||
2737 | typedef struct { | ||
2738 | char *filename; | ||
2739 | char *envvar; | ||
2740 | char *envval; | ||
2741 | + struct passwd *owner; | ||
2742 | void *data; | ||
2743 | } ssh_gssapi_ccache; | ||
2744 | |||
2745 | @@ -72,8 +84,11 @@ typedef struct { | ||
2746 | gss_buffer_desc displayname; | ||
2747 | gss_buffer_desc exportedname; | ||
2748 | gss_cred_id_t creds; | ||
2749 | + gss_name_t name; | ||
2750 | struct ssh_gssapi_mech_struct *mech; | ||
2751 | ssh_gssapi_ccache store; | ||
2752 | + int used; | ||
2753 | + int updated; | ||
2754 | } ssh_gssapi_client; | ||
2755 | |||
2756 | typedef struct ssh_gssapi_mech_struct { | ||
2757 | @@ -84,6 +99,7 @@ typedef struct ssh_gssapi_mech_struct { | ||
2758 | int (*userok) (ssh_gssapi_client *, char *); | ||
2759 | int (*localname) (ssh_gssapi_client *, char **); | ||
2760 | void (*storecreds) (ssh_gssapi_client *); | ||
2761 | + int (*updatecreds) (ssh_gssapi_ccache *, ssh_gssapi_client *); | ||
2762 | } ssh_gssapi_mech; | ||
2763 | |||
2764 | typedef struct { | ||
2765 | @@ -94,10 +110,11 @@ typedef struct { | ||
2766 | gss_OID oid; /* client */ | ||
2767 | gss_cred_id_t creds; /* server */ | ||
2768 | gss_name_t client; /* server */ | ||
2769 | - gss_cred_id_t client_creds; /* server */ | ||
2770 | + gss_cred_id_t client_creds; /* both */ | ||
2771 | } Gssctxt; | ||
2772 | |||
2773 | extern ssh_gssapi_mech *supported_mechs[]; | ||
2774 | +extern Gssctxt *gss_kex_context; | ||
2775 | |||
2776 | int ssh_gssapi_check_oid(Gssctxt *, void *, size_t); | ||
2777 | void ssh_gssapi_set_oid_data(Gssctxt *, void *, size_t); | ||
2778 | @@ -123,17 +140,33 @@ void ssh_gssapi_delete_ctx(Gssctxt **); | ||
2779 | OM_uint32 ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t); | ||
2780 | void ssh_gssapi_buildmic(struct sshbuf *, const char *, | ||
2781 | const char *, const char *); | ||
2782 | -int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *); | ||
2783 | +int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *, const char *); | ||
2784 | +OM_uint32 ssh_gssapi_client_identity(Gssctxt *, const char *); | ||
2785 | +int ssh_gssapi_credentials_updated(Gssctxt *); | ||
2786 | |||
2787 | /* In the server */ | ||
2788 | +typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *, | ||
2789 | + const char *); | ||
2790 | +char *ssh_gssapi_client_mechanisms(const char *, const char *); | ||
2791 | +char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *, | ||
2792 | + const char *); | ||
2793 | +gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int); | ||
2794 | +int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *, | ||
2795 | + const char *); | ||
2796 | OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID); | ||
2797 | -int ssh_gssapi_userok(char *name); | ||
2798 | +int ssh_gssapi_userok(char *name, struct passwd *); | ||
2799 | OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t); | ||
2800 | void ssh_gssapi_do_child(char ***, u_int *); | ||
2801 | void ssh_gssapi_cleanup_creds(void); | ||
2802 | void ssh_gssapi_storecreds(void); | ||
2803 | const char *ssh_gssapi_displayname(void); | ||
2804 | |||
2805 | +char *ssh_gssapi_server_mechanisms(void); | ||
2806 | +int ssh_gssapi_oid_table_ok(void); | ||
2807 | + | ||
2808 | +int ssh_gssapi_update_creds(ssh_gssapi_ccache *store); | ||
2809 | +void ssh_gssapi_rekey_creds(void); | ||
2810 | + | ||
2811 | #endif /* GSSAPI */ | ||
2812 | |||
2813 | #endif /* _SSH_GSS_H */ | ||
2814 | diff --git a/ssh_config b/ssh_config | ||
2815 | index c12f5ef52..bcb9f153d 100644 | ||
2816 | --- a/ssh_config | ||
2817 | +++ b/ssh_config | ||
2818 | @@ -24,6 +24,8 @@ | ||
2819 | # HostbasedAuthentication no | ||
2820 | # GSSAPIAuthentication no | ||
2821 | # GSSAPIDelegateCredentials no | ||
2822 | +# GSSAPIKeyExchange no | ||
2823 | +# GSSAPITrustDNS no | ||
2824 | # BatchMode no | ||
2825 | # CheckHostIP yes | ||
2826 | # AddressFamily any | ||
2827 | diff --git a/ssh_config.5 b/ssh_config.5 | ||
2828 | index f499396a3..5b99921b4 100644 | ||
2829 | --- a/ssh_config.5 | ||
2830 | +++ b/ssh_config.5 | ||
2831 | @@ -718,10 +718,42 @@ The default is | ||
2832 | Specifies whether user authentication based on GSSAPI is allowed. | ||
2833 | The default is | ||
2834 | .Cm no . | ||
2835 | +.It Cm GSSAPIKeyExchange | ||
2836 | +Specifies whether key exchange based on GSSAPI may be used. When using | ||
2837 | +GSSAPI key exchange the server need not have a host key. | ||
2838 | +The default is | ||
2839 | +.Cm no . | ||
2840 | +.It Cm GSSAPIClientIdentity | ||
2841 | +If set, specifies the GSSAPI client identity that ssh should use when | ||
2842 | +connecting to the server. The default is unset, which means that the default | ||
2843 | +identity will be used. | ||
2844 | +.It Cm GSSAPIServerIdentity | ||
2845 | +If set, specifies the GSSAPI server identity that ssh should expect when | ||
2846 | +connecting to the server. The default is unset, which means that the | ||
2847 | +expected GSSAPI server identity will be determined from the target | ||
2848 | +hostname. | ||
2849 | .It Cm GSSAPIDelegateCredentials | ||
2850 | Forward (delegate) credentials to the server. | ||
2851 | The default is | ||
2852 | .Cm no . | ||
2853 | +.It Cm GSSAPIRenewalForcesRekey | ||
2854 | +If set to | ||
2855 | +.Cm yes | ||
2856 | +then renewal of the client's GSSAPI credentials will force the rekeying of the | ||
2857 | +ssh connection. With a compatible server, this can delegate the renewed | ||
2858 | +credentials to a session on the server. | ||
2859 | +The default is | ||
2860 | +.Cm no . | ||
2861 | +.It Cm GSSAPITrustDns | ||
2862 | +Set to | ||
2863 | +.Cm yes | ||
2864 | +to indicate that the DNS is trusted to securely canonicalize | ||
2865 | +the name of the host being connected to. If | ||
2866 | +.Cm no , | ||
2867 | +the hostname entered on the | ||
2868 | +command line will be passed untouched to the GSSAPI library. | ||
2869 | +The default is | ||
2870 | +.Cm no . | ||
2871 | .It Cm HashKnownHosts | ||
2872 | Indicates that | ||
2873 | .Xr ssh 1 | ||
2874 | diff --git a/sshconnect2.c b/sshconnect2.c | ||
2875 | index 10e4f0a08..c6a1b1271 100644 | ||
2876 | --- a/sshconnect2.c | ||
2877 | +++ b/sshconnect2.c | ||
2878 | @@ -162,6 +162,11 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port) | ||
2879 | struct kex *kex; | ||
2880 | int r; | ||
2881 | |||
2882 | +#ifdef GSSAPI | ||
2883 | + char *orig = NULL, *gss = NULL; | ||
2884 | + char *gss_host = NULL; | ||
2885 | +#endif | ||
2886 | + | ||
2887 | xxx_host = host; | ||
2888 | xxx_hostaddr = hostaddr; | ||
2889 | |||
2890 | @@ -194,6 +199,35 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port) | ||
2891 | order_hostkeyalgs(host, hostaddr, port)); | ||
2892 | } | ||
2893 | |||
2894 | +#ifdef GSSAPI | ||
2895 | + if (options.gss_keyex) { | ||
2896 | + /* Add the GSSAPI mechanisms currently supported on this | ||
2897 | + * client to the key exchange algorithm proposal */ | ||
2898 | + orig = myproposal[PROPOSAL_KEX_ALGS]; | ||
2899 | + | ||
2900 | + if (options.gss_server_identity) | ||
2901 | + gss_host = xstrdup(options.gss_server_identity); | ||
2902 | + else if (options.gss_trust_dns) | ||
2903 | + gss_host = remote_hostname(active_state); | ||
2904 | + else | ||
2905 | + gss_host = xstrdup(host); | ||
2906 | + | ||
2907 | + gss = ssh_gssapi_client_mechanisms(gss_host, | ||
2908 | + options.gss_client_identity); | ||
2909 | + if (gss) { | ||
2910 | + debug("Offering GSSAPI proposal: %s", gss); | ||
2911 | + xasprintf(&myproposal[PROPOSAL_KEX_ALGS], | ||
2912 | + "%s,%s", gss, orig); | ||
2913 | + | ||
2914 | + /* If we've got GSSAPI algorithms, then we also | ||
2915 | + * support the 'null' hostkey, as a last resort */ | ||
2916 | + orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]; | ||
2917 | + xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS], | ||
2918 | + "%s,null", orig); | ||
2919 | + } | ||
2920 | + } | ||
2921 | +#endif | ||
2922 | + | ||
2923 | if (options.rekey_limit || options.rekey_interval) | ||
2924 | packet_set_rekey_limits(options.rekey_limit, | ||
2925 | options.rekey_interval); | ||
2926 | @@ -215,15 +249,41 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port) | ||
2927 | # endif | ||
2928 | #endif | ||
2929 | kex->kex[KEX_C25519_SHA256] = kexc25519_client; | ||
2930 | +#ifdef GSSAPI | ||
2931 | + if (options.gss_keyex) { | ||
2932 | + kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client; | ||
2933 | + kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client; | ||
2934 | + kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client; | ||
2935 | + } | ||
2936 | +#endif | ||
2937 | kex->client_version_string=client_version_string; | ||
2938 | kex->server_version_string=server_version_string; | ||
2939 | kex->verify_host_key=&verify_host_key_callback; | ||
2940 | |||
2941 | +#ifdef GSSAPI | ||
2942 | + if (options.gss_keyex) { | ||
2943 | + kex->gss_deleg_creds = options.gss_deleg_creds; | ||
2944 | + kex->gss_trust_dns = options.gss_trust_dns; | ||
2945 | + kex->gss_client = options.gss_client_identity; | ||
2946 | + kex->gss_host = gss_host; | ||
2947 | + } | ||
2948 | +#endif | ||
2949 | + | ||
2950 | ssh_dispatch_run_fatal(active_state, DISPATCH_BLOCK, &kex->done); | ||
2951 | |||
2952 | /* remove ext-info from the KEX proposals for rekeying */ | ||
2953 | myproposal[PROPOSAL_KEX_ALGS] = | ||
2954 | compat_kex_proposal(options.kex_algorithms); | ||
2955 | +#ifdef GSSAPI | ||
2956 | + /* repair myproposal after it was crumpled by the */ | ||
2957 | + /* ext-info removal above */ | ||
2958 | + if (gss) { | ||
2959 | + orig = myproposal[PROPOSAL_KEX_ALGS]; | ||
2960 | + xasprintf(&myproposal[PROPOSAL_KEX_ALGS], | ||
2961 | + "%s,%s", gss, orig); | ||
2962 | + free(gss); | ||
2963 | + } | ||
2964 | +#endif | ||
2965 | if ((r = kex_prop2buf(kex->my, myproposal)) != 0) | ||
2966 | fatal("kex_prop2buf: %s", ssh_err(r)); | ||
2967 | |||
2968 | @@ -314,6 +374,7 @@ int input_gssapi_token(int type, u_int32_t, struct ssh *); | ||
2969 | int input_gssapi_hash(int type, u_int32_t, struct ssh *); | ||
2970 | int input_gssapi_error(int, u_int32_t, struct ssh *); | ||
2971 | int input_gssapi_errtok(int, u_int32_t, struct ssh *); | ||
2972 | +int userauth_gsskeyex(Authctxt *authctxt); | ||
2973 | #endif | ||
2974 | |||
2975 | void userauth(Authctxt *, char *); | ||
2976 | @@ -330,6 +391,11 @@ static char *authmethods_get(void); | ||
2977 | |||
2978 | Authmethod authmethods[] = { | ||
2979 | #ifdef GSSAPI | ||
2980 | + {"gssapi-keyex", | ||
2981 | + userauth_gsskeyex, | ||
2982 | + NULL, | ||
2983 | + &options.gss_authentication, | ||
2984 | + NULL}, | ||
2985 | {"gssapi-with-mic", | ||
2986 | userauth_gssapi, | ||
2987 | NULL, | ||
2988 | @@ -657,25 +723,40 @@ userauth_gssapi(Authctxt *authctxt) | ||
2989 | static u_int mech = 0; | ||
2990 | OM_uint32 min; | ||
2991 | int r, ok = 0; | ||
2992 | + char *gss_host; | ||
2993 | + | ||
2994 | + if (options.gss_server_identity) | ||
2995 | + gss_host = xstrdup(options.gss_server_identity); | ||
2996 | + else if (options.gss_trust_dns) | ||
2997 | + gss_host = remote_hostname(active_state); | ||
2998 | + else | ||
2999 | + gss_host = xstrdup(authctxt->host); | ||
3000 | |||
3001 | /* Try one GSSAPI method at a time, rather than sending them all at | ||
3002 | * once. */ | ||
3003 | |||
3004 | if (gss_supported == NULL) | ||
3005 | - gss_indicate_mechs(&min, &gss_supported); | ||
3006 | + if (GSS_ERROR(gss_indicate_mechs(&min, &gss_supported))) { | ||
3007 | + gss_supported = NULL; | ||
3008 | + free(gss_host); | ||
3009 | + return 0; | ||
3010 | + } | ||
3011 | |||
3012 | /* Check to see if the mechanism is usable before we offer it */ | ||
3013 | while (mech < gss_supported->count && !ok) { | ||
3014 | /* My DER encoding requires length<128 */ | ||
3015 | if (gss_supported->elements[mech].length < 128 && | ||
3016 | ssh_gssapi_check_mechanism(&gssctxt, | ||
3017 | - &gss_supported->elements[mech], authctxt->host)) { | ||
3018 | + &gss_supported->elements[mech], gss_host, | ||
3019 | + options.gss_client_identity)) { | ||
3020 | ok = 1; /* Mechanism works */ | ||
3021 | } else { | ||
3022 | mech++; | ||
3023 | } | ||
3024 | } | ||
3025 | |||
3026 | + free(gss_host); | ||
3027 | + | ||
3028 | if (!ok) | ||
3029 | return 0; | ||
3030 | |||
3031 | @@ -906,6 +987,54 @@ input_gssapi_error(int type, u_int32_t plen, struct ssh *ssh) | ||
3032 | free(lang); | ||
3033 | return r; | ||
3034 | } | ||
3035 | + | ||
3036 | +int | ||
3037 | +userauth_gsskeyex(Authctxt *authctxt) | ||
3038 | +{ | ||
3039 | + struct ssh *ssh = active_state; /* XXX */ | ||
3040 | + struct sshbuf *b; | ||
3041 | + gss_buffer_desc gssbuf; | ||
3042 | + gss_buffer_desc mic = GSS_C_EMPTY_BUFFER; | ||
3043 | + OM_uint32 ms; | ||
3044 | + int r; | ||
3045 | + | ||
3046 | + static int attempt = 0; | ||
3047 | + if (attempt++ >= 1) | ||
3048 | + return (0); | ||
3049 | + | ||
3050 | + if (gss_kex_context == NULL) { | ||
3051 | + debug("No valid Key exchange context"); | ||
3052 | + return (0); | ||
3053 | + } | ||
3054 | + | ||
3055 | + if ((b = sshbuf_new()) == NULL) | ||
3056 | + fatal("%s: sshbuf_new failed", __func__); | ||
3057 | + ssh_gssapi_buildmic(b, authctxt->server_user, authctxt->service, | ||
3058 | + "gssapi-keyex"); | ||
3059 | + | ||
3060 | + if ((gssbuf.value = sshbuf_mutable_ptr(b)) == NULL) | ||
3061 | + fatal("%s: sshbuf_mutable_ptr failed", __func__); | ||
3062 | + gssbuf.length = sshbuf_len(b); | ||
3063 | + | ||
3064 | + if (GSS_ERROR(ssh_gssapi_sign(gss_kex_context, &gssbuf, &mic))) { | ||
3065 | + sshbuf_free(b); | ||
3066 | + return (0); | ||
3067 | + } | ||
3068 | + | ||
3069 | + if ((r = sshpkt_start(ssh, SSH2_MSG_USERAUTH_REQUEST)) != 0 || | ||
3070 | + (r = sshpkt_put_cstring(ssh, authctxt->server_user)) != 0 || | ||
3071 | + (r = sshpkt_put_cstring(ssh, authctxt->service)) != 0 || | ||
3072 | + (r = sshpkt_put_cstring(ssh, authctxt->method->name)) != 0 || | ||
3073 | + (r = sshpkt_put_string(ssh, mic.value, mic.length)) != 0 || | ||
3074 | + (r = sshpkt_send(ssh)) != 0) | ||
3075 | + fatal("%s: %s", __func__, ssh_err(r)); | ||
3076 | + | ||
3077 | + sshbuf_free(b); | ||
3078 | + gss_release_buffer(&ms, &mic); | ||
3079 | + | ||
3080 | + return (1); | ||
3081 | +} | ||
3082 | + | ||
3083 | #endif /* GSSAPI */ | ||
3084 | |||
3085 | int | ||
3086 | diff --git a/sshd.c b/sshd.c | ||
3087 | index a738c3ab6..2e453cdf8 100644 | ||
3088 | --- a/sshd.c | ||
3089 | +++ b/sshd.c | ||
3090 | @@ -123,6 +123,10 @@ | ||
3091 | #include "version.h" | ||
3092 | #include "ssherr.h" | ||
3093 | |||
3094 | +#ifdef USE_SECURITY_SESSION_API | ||
3095 | +#include <Security/AuthSession.h> | ||
3096 | +#endif | ||
3097 | + | ||
3098 | /* Re-exec fds */ | ||
3099 | #define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1) | ||
3100 | #define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2) | ||
3101 | @@ -536,7 +540,7 @@ privsep_preauth_child(void) | ||
3102 | |||
3103 | #ifdef GSSAPI | ||
3104 | /* Cache supported mechanism OIDs for later use */ | ||
3105 | - if (options.gss_authentication) | ||
3106 | + if (options.gss_authentication || options.gss_keyex) | ||
3107 | ssh_gssapi_prepare_supported_oids(); | ||
3108 | #endif | ||
3109 | |||
3110 | @@ -1811,10 +1815,13 @@ main(int ac, char **av) | ||
3111 | free(fp); | ||
3112 | } | ||
3113 | accumulate_host_timing_secret(cfg, NULL); | ||
3114 | +#ifndef GSSAPI | ||
3115 | + /* The GSSAPI key exchange can run without a host key */ | ||
3116 | if (!sensitive_data.have_ssh2_key) { | ||
3117 | logit("sshd: no hostkeys available -- exiting."); | ||
3118 | exit(1); | ||
3119 | } | ||
3120 | +#endif | ||
3121 | |||
3122 | /* | ||
3123 | * Load certificates. They are stored in an array at identical | ||
3124 | @@ -2105,6 +2112,60 @@ main(int ac, char **av) | ||
3125 | rdomain == NULL ? "" : "\""); | ||
3126 | free(laddr); | ||
3127 | |||
3128 | +#ifdef USE_SECURITY_SESSION_API | ||
3129 | + /* | ||
3130 | + * Create a new security session for use by the new user login if | ||
3131 | + * the current session is the root session or we are not launched | ||
3132 | + * by inetd (eg: debugging mode or server mode). We do not | ||
3133 | + * necessarily need to create a session if we are launched from | ||
3134 | + * inetd because Panther xinetd will create a session for us. | ||
3135 | + * | ||
3136 | + * The only case where this logic will fail is if there is an | ||
3137 | + * inetd running in a non-root session which is not creating | ||
3138 | + * new sessions for us. Then all the users will end up in the | ||
3139 | + * same session (bad). | ||
3140 | + * | ||
3141 | + * When the client exits, the session will be destroyed for us | ||
3142 | + * automatically. | ||
3143 | + * | ||
3144 | + * We must create the session before any credentials are stored | ||
3145 | + * (including AFS pags, which happens a few lines below). | ||
3146 | + */ | ||
3147 | + { | ||
3148 | + OSStatus err = 0; | ||
3149 | + SecuritySessionId sid = 0; | ||
3150 | + SessionAttributeBits sattrs = 0; | ||
3151 | + | ||
3152 | + err = SessionGetInfo(callerSecuritySession, &sid, &sattrs); | ||
3153 | + if (err) | ||
3154 | + error("SessionGetInfo() failed with error %.8X", | ||
3155 | + (unsigned) err); | ||
3156 | + else | ||
3157 | + debug("Current Session ID is %.8X / Session Attributes are %.8X", | ||
3158 | + (unsigned) sid, (unsigned) sattrs); | ||
3159 | + | ||
3160 | + if (inetd_flag && !(sattrs & sessionIsRoot)) | ||
3161 | + debug("Running in inetd mode in a non-root session... " | ||
3162 | + "assuming inetd created the session for us."); | ||
3163 | + else { | ||
3164 | + debug("Creating new security session..."); | ||
3165 | + err = SessionCreate(0, sessionHasTTY | sessionIsRemote); | ||
3166 | + if (err) | ||
3167 | + error("SessionCreate() failed with error %.8X", | ||
3168 | + (unsigned) err); | ||
3169 | + | ||
3170 | + err = SessionGetInfo(callerSecuritySession, &sid, | ||
3171 | + &sattrs); | ||
3172 | + if (err) | ||
3173 | + error("SessionGetInfo() failed with error %.8X", | ||
3174 | + (unsigned) err); | ||
3175 | + else | ||
3176 | + debug("New Session ID is %.8X / Session Attributes are %.8X", | ||
3177 | + (unsigned) sid, (unsigned) sattrs); | ||
3178 | + } | ||
3179 | + } | ||
3180 | +#endif | ||
3181 | + | ||
3182 | /* | ||
3183 | * We don't want to listen forever unless the other side | ||
3184 | * successfully authenticates itself. So we set up an alarm which is | ||
3185 | @@ -2288,6 +2349,48 @@ do_ssh2_kex(void) | ||
3186 | myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal( | ||
3187 | list_hostkey_types()); | ||
3188 | |||
3189 | +#ifdef GSSAPI | ||
3190 | + { | ||
3191 | + char *orig; | ||
3192 | + char *gss = NULL; | ||
3193 | + char *newstr = NULL; | ||
3194 | + orig = myproposal[PROPOSAL_KEX_ALGS]; | ||
3195 | + | ||
3196 | + /* | ||
3197 | + * If we don't have a host key, then there's no point advertising | ||
3198 | + * the other key exchange algorithms | ||
3199 | + */ | ||
3200 | + | ||
3201 | + if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0) | ||
3202 | + orig = NULL; | ||
3203 | + | ||
3204 | + if (options.gss_keyex) | ||
3205 | + gss = ssh_gssapi_server_mechanisms(); | ||
3206 | + else | ||
3207 | + gss = NULL; | ||
3208 | + | ||
3209 | + if (gss && orig) | ||
3210 | + xasprintf(&newstr, "%s,%s", gss, orig); | ||
3211 | + else if (gss) | ||
3212 | + newstr = gss; | ||
3213 | + else if (orig) | ||
3214 | + newstr = orig; | ||
3215 | + | ||
3216 | + /* | ||
3217 | + * If we've got GSSAPI mechanisms, then we've got the 'null' host | ||
3218 | + * key alg, but we can't tell people about it unless its the only | ||
3219 | + * host key algorithm we support | ||
3220 | + */ | ||
3221 | + if (gss && (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS])) == 0) | ||
3222 | + myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = "null"; | ||
3223 | + | ||
3224 | + if (newstr) | ||
3225 | + myproposal[PROPOSAL_KEX_ALGS] = newstr; | ||
3226 | + else | ||
3227 | + fatal("No supported key exchange algorithms"); | ||
3228 | + } | ||
3229 | +#endif | ||
3230 | + | ||
3231 | /* start key exchange */ | ||
3232 | if ((r = kex_setup(active_state, myproposal)) != 0) | ||
3233 | fatal("kex_setup: %s", ssh_err(r)); | ||
3234 | @@ -2305,6 +2408,13 @@ do_ssh2_kex(void) | ||
3235 | # endif | ||
3236 | #endif | ||
3237 | kex->kex[KEX_C25519_SHA256] = kexc25519_server; | ||
3238 | +#ifdef GSSAPI | ||
3239 | + if (options.gss_keyex) { | ||
3240 | + kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server; | ||
3241 | + kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server; | ||
3242 | + kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server; | ||
3243 | + } | ||
3244 | +#endif | ||
3245 | kex->server = 1; | ||
3246 | kex->client_version_string=client_version_string; | ||
3247 | kex->server_version_string=server_version_string; | ||
3248 | diff --git a/sshd_config b/sshd_config | ||
3249 | index 19b7c91a1..2c48105f8 100644 | ||
3250 | --- a/sshd_config | ||
3251 | +++ b/sshd_config | ||
3252 | @@ -69,6 +69,8 @@ AuthorizedKeysFile .ssh/authorized_keys | ||
3253 | # GSSAPI options | ||
3254 | #GSSAPIAuthentication no | ||
3255 | #GSSAPICleanupCredentials yes | ||
3256 | +#GSSAPIStrictAcceptorCheck yes | ||
3257 | +#GSSAPIKeyExchange no | ||
3258 | |||
3259 | # Set this to 'yes' to enable PAM authentication, account processing, | ||
3260 | # and session processing. If this is enabled, PAM authentication will | ||
3261 | diff --git a/sshd_config.5 b/sshd_config.5 | ||
3262 | index e1b54ba20..a0ac717c7 100644 | ||
3263 | --- a/sshd_config.5 | ||
3264 | +++ b/sshd_config.5 | ||
3265 | @@ -637,6 +637,11 @@ The default is | ||
3266 | Specifies whether user authentication based on GSSAPI is allowed. | ||
3267 | The default is | ||
3268 | .Cm no . | ||
3269 | +.It Cm GSSAPIKeyExchange | ||
3270 | +Specifies whether key exchange based on GSSAPI is allowed. GSSAPI key exchange | ||
3271 | +doesn't rely on ssh keys to verify host identity. | ||
3272 | +The default is | ||
3273 | +.Cm no . | ||
3274 | .It Cm GSSAPICleanupCredentials | ||
3275 | Specifies whether to automatically destroy the user's credentials cache | ||
3276 | on logout. | ||
3277 | @@ -656,6 +661,11 @@ machine's default store. | ||
3278 | This facility is provided to assist with operation on multi homed machines. | ||
3279 | The default is | ||
3280 | .Cm yes . | ||
3281 | +.It Cm GSSAPIStoreCredentialsOnRekey | ||
3282 | +Controls whether the user's GSSAPI credentials should be updated following a | ||
3283 | +successful connection rekeying. This option can be used to accepted renewed | ||
3284 | +or updated credentials from a compatible client. The default is | ||
3285 | +.Cm no . | ||
3286 | .It Cm HostbasedAcceptedKeyTypes | ||
3287 | Specifies the key types that will be accepted for hostbased authentication | ||
3288 | as a list of comma-separated patterns. | ||
3289 | diff --git a/sshkey.c b/sshkey.c | ||
3290 | index 72c08c7e0..91e99a262 100644 | ||
3291 | --- a/sshkey.c | ||
3292 | +++ b/sshkey.c | ||
3293 | @@ -140,6 +140,7 @@ static const struct keytype keytypes[] = { | ||
3294 | # endif /* OPENSSL_HAS_NISTP521 */ | ||
3295 | # endif /* OPENSSL_HAS_ECC */ | ||
3296 | #endif /* WITH_OPENSSL */ | ||
3297 | + { "null", "null", NULL, KEY_NULL, 0, 0, 0 }, | ||
3298 | { NULL, NULL, NULL, -1, -1, 0, 0 } | ||
3299 | }; | ||
3300 | |||
3301 | @@ -228,7 +229,7 @@ sshkey_alg_list(int certs_only, int plain_only, int include_sigonly, char sep) | ||
3302 | const struct keytype *kt; | ||
3303 | |||
3304 | for (kt = keytypes; kt->type != -1; kt++) { | ||
3305 | - if (kt->name == NULL) | ||
3306 | + if (kt->name == NULL || kt->type == KEY_NULL) | ||
3307 | continue; | ||
3308 | if (!include_sigonly && kt->sigonly) | ||
3309 | continue; | ||
3310 | diff --git a/sshkey.h b/sshkey.h | ||
3311 | index 9060b2ecb..0cbdcfd74 100644 | ||
3312 | --- a/sshkey.h | ||
3313 | +++ b/sshkey.h | ||
3314 | @@ -63,6 +63,7 @@ enum sshkey_types { | ||
3315 | KEY_ED25519_CERT, | ||
3316 | KEY_XMSS, | ||
3317 | KEY_XMSS_CERT, | ||
3318 | + KEY_NULL, | ||
3319 | KEY_UNSPEC | ||
3320 | }; | ||
3321 | |||