auth-options.c revision 1.9 1 1.7 christos /* $NetBSD: auth-options.c,v 1.9 2015/04/03 23:58:19 christos Exp $ */
2 1.9 christos /* $OpenBSD: auth-options.c,v 1.65 2015/01/14 10:30:34 markus Exp $ */
3 1.1 christos /*
4 1.1 christos * Author: Tatu Ylonen <ylo (at) cs.hut.fi>
5 1.1 christos * Copyright (c) 1995 Tatu Ylonen <ylo (at) cs.hut.fi>, Espoo, Finland
6 1.1 christos * All rights reserved
7 1.1 christos * As far as I am concerned, the code I have written for this software
8 1.1 christos * can be used freely for any purpose. Any derived versions of this
9 1.1 christos * software must be clearly marked as such, and if the derived work is
10 1.1 christos * incompatible with the protocol description in the RFC file, it must be
11 1.1 christos * called by a name other than "ssh" or "Secure Shell".
12 1.1 christos */
13 1.1 christos
14 1.2 christos #include "includes.h"
15 1.7 christos __RCSID("$NetBSD: auth-options.c,v 1.9 2015/04/03 23:58:19 christos Exp $");
16 1.1 christos #include <sys/types.h>
17 1.1 christos #include <sys/queue.h>
18 1.1 christos
19 1.1 christos #include <netdb.h>
20 1.1 christos #include <pwd.h>
21 1.1 christos #include <string.h>
22 1.1 christos #include <stdio.h>
23 1.1 christos #include <stdarg.h>
24 1.2 christos #include <time.h>
25 1.1 christos
26 1.9 christos #include "key.h" /* XXX for typedef */
27 1.9 christos #include "buffer.h" /* XXX for typedef */
28 1.1 christos #include "xmalloc.h"
29 1.1 christos #include "match.h"
30 1.9 christos #include "ssherr.h"
31 1.1 christos #include "log.h"
32 1.1 christos #include "canohost.h"
33 1.9 christos #include "sshbuf.h"
34 1.8 christos #include "misc.h"
35 1.1 christos #include "channels.h"
36 1.1 christos #include "servconf.h"
37 1.9 christos #include "sshkey.h"
38 1.3 adam #include "auth-options.h"
39 1.1 christos #include "hostfile.h"
40 1.1 christos #include "auth.h"
41 1.1 christos
42 1.1 christos /* Flags set authorized_keys flags */
43 1.1 christos int no_port_forwarding_flag = 0;
44 1.1 christos int no_agent_forwarding_flag = 0;
45 1.1 christos int no_x11_forwarding_flag = 0;
46 1.1 christos int no_pty_flag = 0;
47 1.1 christos int no_user_rc = 0;
48 1.3 adam int key_is_cert_authority = 0;
49 1.1 christos
50 1.1 christos /* "command=" option. */
51 1.1 christos char *forced_command = NULL;
52 1.1 christos
53 1.1 christos /* "environment=" options. */
54 1.1 christos struct envstring *custom_environment = NULL;
55 1.1 christos
56 1.1 christos /* "tunnel=" option. */
57 1.1 christos int forced_tun_device = -1;
58 1.1 christos
59 1.3 adam /* "principals=" option. */
60 1.3 adam char *authorized_principals = NULL;
61 1.3 adam
62 1.1 christos extern ServerOptions options;
63 1.1 christos
64 1.1 christos void
65 1.1 christos auth_clear_options(void)
66 1.1 christos {
67 1.1 christos no_agent_forwarding_flag = 0;
68 1.1 christos no_port_forwarding_flag = 0;
69 1.1 christos no_pty_flag = 0;
70 1.1 christos no_x11_forwarding_flag = 0;
71 1.1 christos no_user_rc = 0;
72 1.3 adam key_is_cert_authority = 0;
73 1.1 christos while (custom_environment) {
74 1.1 christos struct envstring *ce = custom_environment;
75 1.1 christos custom_environment = ce->next;
76 1.7 christos free(ce->s);
77 1.7 christos free(ce);
78 1.1 christos }
79 1.1 christos if (forced_command) {
80 1.7 christos free(forced_command);
81 1.1 christos forced_command = NULL;
82 1.1 christos }
83 1.3 adam if (authorized_principals) {
84 1.7 christos free(authorized_principals);
85 1.3 adam authorized_principals = NULL;
86 1.3 adam }
87 1.1 christos forced_tun_device = -1;
88 1.1 christos channel_clear_permitted_opens();
89 1.1 christos }
90 1.1 christos
91 1.1 christos /*
92 1.1 christos * return 1 if access is granted, 0 if not.
93 1.1 christos * side effect: sets key option flags
94 1.1 christos */
95 1.1 christos int
96 1.4 christos auth_parse_options(struct passwd *pw, const char *opts, const char *file,
97 1.4 christos u_long linenum)
98 1.1 christos {
99 1.1 christos const char *cp;
100 1.1 christos int i;
101 1.1 christos
102 1.1 christos /* reset options */
103 1.1 christos auth_clear_options();
104 1.1 christos
105 1.1 christos if (!opts)
106 1.1 christos return 1;
107 1.1 christos
108 1.1 christos while (*opts && *opts != ' ' && *opts != '\t') {
109 1.3 adam cp = "cert-authority";
110 1.3 adam if (strncasecmp(opts, cp, strlen(cp)) == 0) {
111 1.3 adam key_is_cert_authority = 1;
112 1.3 adam opts += strlen(cp);
113 1.3 adam goto next_option;
114 1.3 adam }
115 1.1 christos cp = "no-port-forwarding";
116 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
117 1.1 christos auth_debug_add("Port forwarding disabled.");
118 1.1 christos no_port_forwarding_flag = 1;
119 1.1 christos opts += strlen(cp);
120 1.1 christos goto next_option;
121 1.1 christos }
122 1.1 christos cp = "no-agent-forwarding";
123 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
124 1.1 christos auth_debug_add("Agent forwarding disabled.");
125 1.1 christos no_agent_forwarding_flag = 1;
126 1.1 christos opts += strlen(cp);
127 1.1 christos goto next_option;
128 1.1 christos }
129 1.1 christos cp = "no-X11-forwarding";
130 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
131 1.1 christos auth_debug_add("X11 forwarding disabled.");
132 1.1 christos no_x11_forwarding_flag = 1;
133 1.1 christos opts += strlen(cp);
134 1.1 christos goto next_option;
135 1.1 christos }
136 1.1 christos cp = "no-pty";
137 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
138 1.1 christos auth_debug_add("Pty allocation disabled.");
139 1.1 christos no_pty_flag = 1;
140 1.1 christos opts += strlen(cp);
141 1.1 christos goto next_option;
142 1.1 christos }
143 1.1 christos cp = "no-user-rc";
144 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
145 1.1 christos auth_debug_add("User rc file execution disabled.");
146 1.1 christos no_user_rc = 1;
147 1.1 christos opts += strlen(cp);
148 1.1 christos goto next_option;
149 1.1 christos }
150 1.1 christos cp = "command=\"";
151 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
152 1.1 christos opts += strlen(cp);
153 1.3 adam if (forced_command != NULL)
154 1.7 christos free(forced_command);
155 1.1 christos forced_command = xmalloc(strlen(opts) + 1);
156 1.1 christos i = 0;
157 1.1 christos while (*opts) {
158 1.1 christos if (*opts == '"')
159 1.1 christos break;
160 1.1 christos if (*opts == '\\' && opts[1] == '"') {
161 1.1 christos opts += 2;
162 1.1 christos forced_command[i++] = '"';
163 1.1 christos continue;
164 1.1 christos }
165 1.1 christos forced_command[i++] = *opts++;
166 1.1 christos }
167 1.1 christos if (!*opts) {
168 1.1 christos debug("%.100s, line %lu: missing end quote",
169 1.1 christos file, linenum);
170 1.1 christos auth_debug_add("%.100s, line %lu: missing end quote",
171 1.1 christos file, linenum);
172 1.7 christos free(forced_command);
173 1.1 christos forced_command = NULL;
174 1.1 christos goto bad_option;
175 1.1 christos }
176 1.1 christos forced_command[i] = '\0';
177 1.4 christos auth_debug_add("Forced command.");
178 1.1 christos opts++;
179 1.1 christos goto next_option;
180 1.1 christos }
181 1.3 adam cp = "principals=\"";
182 1.3 adam if (strncasecmp(opts, cp, strlen(cp)) == 0) {
183 1.3 adam opts += strlen(cp);
184 1.3 adam if (authorized_principals != NULL)
185 1.7 christos free(authorized_principals);
186 1.3 adam authorized_principals = xmalloc(strlen(opts) + 1);
187 1.3 adam i = 0;
188 1.3 adam while (*opts) {
189 1.3 adam if (*opts == '"')
190 1.3 adam break;
191 1.3 adam if (*opts == '\\' && opts[1] == '"') {
192 1.3 adam opts += 2;
193 1.3 adam authorized_principals[i++] = '"';
194 1.3 adam continue;
195 1.3 adam }
196 1.3 adam authorized_principals[i++] = *opts++;
197 1.3 adam }
198 1.3 adam if (!*opts) {
199 1.3 adam debug("%.100s, line %lu: missing end quote",
200 1.3 adam file, linenum);
201 1.3 adam auth_debug_add("%.100s, line %lu: missing end quote",
202 1.3 adam file, linenum);
203 1.7 christos free(authorized_principals);
204 1.3 adam authorized_principals = NULL;
205 1.3 adam goto bad_option;
206 1.3 adam }
207 1.3 adam authorized_principals[i] = '\0';
208 1.3 adam auth_debug_add("principals: %.900s",
209 1.3 adam authorized_principals);
210 1.3 adam opts++;
211 1.3 adam goto next_option;
212 1.3 adam }
213 1.1 christos cp = "environment=\"";
214 1.1 christos if (options.permit_user_env &&
215 1.1 christos strncasecmp(opts, cp, strlen(cp)) == 0) {
216 1.1 christos char *s;
217 1.1 christos struct envstring *new_envstring;
218 1.1 christos
219 1.1 christos opts += strlen(cp);
220 1.1 christos s = xmalloc(strlen(opts) + 1);
221 1.1 christos i = 0;
222 1.1 christos while (*opts) {
223 1.1 christos if (*opts == '"')
224 1.1 christos break;
225 1.1 christos if (*opts == '\\' && opts[1] == '"') {
226 1.1 christos opts += 2;
227 1.1 christos s[i++] = '"';
228 1.1 christos continue;
229 1.1 christos }
230 1.1 christos s[i++] = *opts++;
231 1.1 christos }
232 1.1 christos if (!*opts) {
233 1.1 christos debug("%.100s, line %lu: missing end quote",
234 1.1 christos file, linenum);
235 1.1 christos auth_debug_add("%.100s, line %lu: missing end quote",
236 1.1 christos file, linenum);
237 1.7 christos free(s);
238 1.1 christos goto bad_option;
239 1.1 christos }
240 1.1 christos s[i] = '\0';
241 1.1 christos auth_debug_add("Adding to environment: %.900s", s);
242 1.1 christos debug("Adding to environment: %.900s", s);
243 1.1 christos opts++;
244 1.7 christos new_envstring = xcalloc(1, sizeof(struct envstring));
245 1.1 christos new_envstring->s = s;
246 1.1 christos new_envstring->next = custom_environment;
247 1.1 christos custom_environment = new_envstring;
248 1.1 christos goto next_option;
249 1.1 christos }
250 1.1 christos cp = "from=\"";
251 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
252 1.1 christos const char *remote_ip = get_remote_ipaddr();
253 1.1 christos const char *remote_host = get_canonical_hostname(
254 1.1 christos options.use_dns);
255 1.1 christos char *patterns = xmalloc(strlen(opts) + 1);
256 1.1 christos
257 1.1 christos opts += strlen(cp);
258 1.1 christos i = 0;
259 1.1 christos while (*opts) {
260 1.1 christos if (*opts == '"')
261 1.1 christos break;
262 1.1 christos if (*opts == '\\' && opts[1] == '"') {
263 1.1 christos opts += 2;
264 1.1 christos patterns[i++] = '"';
265 1.1 christos continue;
266 1.1 christos }
267 1.1 christos patterns[i++] = *opts++;
268 1.1 christos }
269 1.1 christos if (!*opts) {
270 1.1 christos debug("%.100s, line %lu: missing end quote",
271 1.1 christos file, linenum);
272 1.1 christos auth_debug_add("%.100s, line %lu: missing end quote",
273 1.1 christos file, linenum);
274 1.7 christos free(patterns);
275 1.1 christos goto bad_option;
276 1.1 christos }
277 1.1 christos patterns[i] = '\0';
278 1.1 christos opts++;
279 1.1 christos switch (match_host_and_ip(remote_host, remote_ip,
280 1.1 christos patterns)) {
281 1.1 christos case 1:
282 1.7 christos free(patterns);
283 1.1 christos /* Host name matches. */
284 1.1 christos goto next_option;
285 1.1 christos case -1:
286 1.1 christos debug("%.100s, line %lu: invalid criteria",
287 1.1 christos file, linenum);
288 1.1 christos auth_debug_add("%.100s, line %lu: "
289 1.1 christos "invalid criteria", file, linenum);
290 1.1 christos /* FALLTHROUGH */
291 1.1 christos case 0:
292 1.7 christos free(patterns);
293 1.1 christos logit("Authentication tried for %.100s with "
294 1.1 christos "correct key but not from a permitted "
295 1.1 christos "host (host=%.200s, ip=%.200s).",
296 1.1 christos pw->pw_name, remote_host, remote_ip);
297 1.1 christos auth_debug_add("Your host '%.200s' is not "
298 1.1 christos "permitted to use this key for login.",
299 1.1 christos remote_host);
300 1.1 christos break;
301 1.1 christos }
302 1.1 christos /* deny access */
303 1.1 christos return 0;
304 1.1 christos }
305 1.1 christos cp = "permitopen=\"";
306 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
307 1.1 christos char *host, *p;
308 1.1 christos int port;
309 1.1 christos char *patterns = xmalloc(strlen(opts) + 1);
310 1.1 christos
311 1.1 christos opts += strlen(cp);
312 1.1 christos i = 0;
313 1.1 christos while (*opts) {
314 1.1 christos if (*opts == '"')
315 1.1 christos break;
316 1.1 christos if (*opts == '\\' && opts[1] == '"') {
317 1.1 christos opts += 2;
318 1.1 christos patterns[i++] = '"';
319 1.1 christos continue;
320 1.1 christos }
321 1.1 christos patterns[i++] = *opts++;
322 1.1 christos }
323 1.1 christos if (!*opts) {
324 1.1 christos debug("%.100s, line %lu: missing end quote",
325 1.1 christos file, linenum);
326 1.1 christos auth_debug_add("%.100s, line %lu: missing "
327 1.1 christos "end quote", file, linenum);
328 1.7 christos free(patterns);
329 1.1 christos goto bad_option;
330 1.1 christos }
331 1.1 christos patterns[i] = '\0';
332 1.1 christos opts++;
333 1.1 christos p = patterns;
334 1.8 christos /* XXX - add streamlocal support */
335 1.1 christos host = hpdelim(&p);
336 1.1 christos if (host == NULL || strlen(host) >= NI_MAXHOST) {
337 1.1 christos debug("%.100s, line %lu: Bad permitopen "
338 1.1 christos "specification <%.100s>", file, linenum,
339 1.1 christos patterns);
340 1.1 christos auth_debug_add("%.100s, line %lu: "
341 1.1 christos "Bad permitopen specification", file,
342 1.1 christos linenum);
343 1.7 christos free(patterns);
344 1.1 christos goto bad_option;
345 1.1 christos }
346 1.1 christos host = cleanhostname(host);
347 1.5 christos if (p == NULL || (port = permitopen_port(p)) < 0) {
348 1.1 christos debug("%.100s, line %lu: Bad permitopen port "
349 1.1 christos "<%.100s>", file, linenum, p ? p : "");
350 1.1 christos auth_debug_add("%.100s, line %lu: "
351 1.1 christos "Bad permitopen port", file, linenum);
352 1.7 christos free(patterns);
353 1.1 christos goto bad_option;
354 1.1 christos }
355 1.6 christos if ((options.allow_tcp_forwarding & FORWARD_LOCAL) != 0)
356 1.1 christos channel_add_permitted_opens(host, port);
357 1.7 christos free(patterns);
358 1.1 christos goto next_option;
359 1.1 christos }
360 1.1 christos cp = "tunnel=\"";
361 1.1 christos if (strncasecmp(opts, cp, strlen(cp)) == 0) {
362 1.1 christos char *tun = NULL;
363 1.1 christos opts += strlen(cp);
364 1.1 christos tun = xmalloc(strlen(opts) + 1);
365 1.1 christos i = 0;
366 1.1 christos while (*opts) {
367 1.1 christos if (*opts == '"')
368 1.1 christos break;
369 1.1 christos tun[i++] = *opts++;
370 1.1 christos }
371 1.1 christos if (!*opts) {
372 1.1 christos debug("%.100s, line %lu: missing end quote",
373 1.1 christos file, linenum);
374 1.1 christos auth_debug_add("%.100s, line %lu: missing end quote",
375 1.1 christos file, linenum);
376 1.7 christos free(tun);
377 1.1 christos forced_tun_device = -1;
378 1.1 christos goto bad_option;
379 1.1 christos }
380 1.1 christos tun[i] = '\0';
381 1.1 christos forced_tun_device = a2tun(tun, NULL);
382 1.7 christos free(tun);
383 1.1 christos if (forced_tun_device == SSH_TUNID_ERR) {
384 1.1 christos debug("%.100s, line %lu: invalid tun device",
385 1.1 christos file, linenum);
386 1.1 christos auth_debug_add("%.100s, line %lu: invalid tun device",
387 1.1 christos file, linenum);
388 1.1 christos forced_tun_device = -1;
389 1.1 christos goto bad_option;
390 1.1 christos }
391 1.1 christos auth_debug_add("Forced tun device: %d", forced_tun_device);
392 1.1 christos opts++;
393 1.1 christos goto next_option;
394 1.1 christos }
395 1.1 christos next_option:
396 1.1 christos /*
397 1.1 christos * Skip the comma, and move to the next option
398 1.1 christos * (or break out if there are no more).
399 1.1 christos */
400 1.1 christos if (!*opts)
401 1.1 christos fatal("Bugs in auth-options.c option processing.");
402 1.1 christos if (*opts == ' ' || *opts == '\t')
403 1.1 christos break; /* End of options. */
404 1.1 christos if (*opts != ',')
405 1.1 christos goto bad_option;
406 1.1 christos opts++;
407 1.1 christos /* Process the next option. */
408 1.1 christos }
409 1.1 christos
410 1.1 christos /* grant access */
411 1.1 christos return 1;
412 1.1 christos
413 1.1 christos bad_option:
414 1.1 christos logit("Bad options in %.100s file, line %lu: %.50s",
415 1.1 christos file, linenum, opts);
416 1.1 christos auth_debug_add("Bad options in %.100s file, line %lu: %.50s",
417 1.1 christos file, linenum, opts);
418 1.1 christos
419 1.3 adam /* deny access */
420 1.3 adam return 0;
421 1.3 adam }
422 1.3 adam
423 1.3 adam #define OPTIONS_CRITICAL 1
424 1.3 adam #define OPTIONS_EXTENSIONS 2
425 1.3 adam static int
426 1.9 christos parse_option_list(struct sshbuf *oblob, struct passwd *pw,
427 1.3 adam u_int which, int crit,
428 1.3 adam int *cert_no_port_forwarding_flag,
429 1.3 adam int *cert_no_agent_forwarding_flag,
430 1.3 adam int *cert_no_x11_forwarding_flag,
431 1.3 adam int *cert_no_pty_flag,
432 1.3 adam int *cert_no_user_rc,
433 1.3 adam char **cert_forced_command,
434 1.3 adam int *cert_source_address_done)
435 1.3 adam {
436 1.3 adam char *command, *allowed;
437 1.3 adam const char *remote_ip;
438 1.7 christos char *name = NULL;
439 1.9 christos struct sshbuf *c = NULL, *data = NULL;
440 1.9 christos int r, ret = -1, result, found;
441 1.9 christos
442 1.9 christos if ((c = sshbuf_fromb(oblob)) == NULL) {
443 1.9 christos error("%s: sshbuf_fromb failed", __func__);
444 1.9 christos goto out;
445 1.9 christos }
446 1.9 christos
447 1.9 christos while (sshbuf_len(c) > 0) {
448 1.9 christos sshbuf_free(data);
449 1.9 christos data = NULL;
450 1.9 christos if ((r = sshbuf_get_cstring(c, &name, NULL)) != 0 ||
451 1.9 christos (r = sshbuf_froms(c, &data)) != 0) {
452 1.9 christos error("Unable to parse certificate options: %s",
453 1.9 christos ssh_err(r));
454 1.3 adam goto out;
455 1.3 adam }
456 1.9 christos debug3("found certificate option \"%.100s\" len %zu",
457 1.9 christos name, sshbuf_len(data));
458 1.3 adam found = 0;
459 1.3 adam if ((which & OPTIONS_EXTENSIONS) != 0) {
460 1.3 adam if (strcmp(name, "permit-X11-forwarding") == 0) {
461 1.3 adam *cert_no_x11_forwarding_flag = 0;
462 1.3 adam found = 1;
463 1.3 adam } else if (strcmp(name,
464 1.3 adam "permit-agent-forwarding") == 0) {
465 1.3 adam *cert_no_agent_forwarding_flag = 0;
466 1.3 adam found = 1;
467 1.3 adam } else if (strcmp(name,
468 1.3 adam "permit-port-forwarding") == 0) {
469 1.3 adam *cert_no_port_forwarding_flag = 0;
470 1.3 adam found = 1;
471 1.3 adam } else if (strcmp(name, "permit-pty") == 0) {
472 1.3 adam *cert_no_pty_flag = 0;
473 1.3 adam found = 1;
474 1.3 adam } else if (strcmp(name, "permit-user-rc") == 0) {
475 1.3 adam *cert_no_user_rc = 0;
476 1.3 adam found = 1;
477 1.3 adam }
478 1.3 adam }
479 1.3 adam if (!found && (which & OPTIONS_CRITICAL) != 0) {
480 1.3 adam if (strcmp(name, "force-command") == 0) {
481 1.9 christos if ((r = sshbuf_get_cstring(data, &command,
482 1.9 christos NULL)) != 0) {
483 1.9 christos error("Unable to parse \"%s\" "
484 1.9 christos "section: %s", name, ssh_err(r));
485 1.3 adam goto out;
486 1.3 adam }
487 1.3 adam if (*cert_forced_command != NULL) {
488 1.3 adam error("Certificate has multiple "
489 1.3 adam "force-command options");
490 1.7 christos free(command);
491 1.3 adam goto out;
492 1.3 adam }
493 1.3 adam *cert_forced_command = command;
494 1.3 adam found = 1;
495 1.3 adam }
496 1.3 adam if (strcmp(name, "source-address") == 0) {
497 1.9 christos if ((r = sshbuf_get_cstring(data, &allowed,
498 1.9 christos NULL)) != 0) {
499 1.9 christos error("Unable to parse \"%s\" "
500 1.9 christos "section: %s", name, ssh_err(r));
501 1.3 adam goto out;
502 1.3 adam }
503 1.3 adam if ((*cert_source_address_done)++) {
504 1.3 adam error("Certificate has multiple "
505 1.3 adam "source-address options");
506 1.7 christos free(allowed);
507 1.3 adam goto out;
508 1.3 adam }
509 1.3 adam remote_ip = get_remote_ipaddr();
510 1.8 christos result = addr_match_cidr_list(remote_ip,
511 1.8 christos allowed);
512 1.8 christos free(allowed);
513 1.8 christos switch (result) {
514 1.3 adam case 1:
515 1.3 adam /* accepted */
516 1.3 adam break;
517 1.3 adam case 0:
518 1.3 adam /* no match */
519 1.3 adam logit("Authentication tried for %.100s "
520 1.3 adam "with valid certificate but not "
521 1.3 adam "from a permitted host "
522 1.3 adam "(ip=%.200s).", pw->pw_name,
523 1.3 adam remote_ip);
524 1.3 adam auth_debug_add("Your address '%.200s' "
525 1.3 adam "is not permitted to use this "
526 1.3 adam "certificate for login.",
527 1.3 adam remote_ip);
528 1.3 adam goto out;
529 1.3 adam case -1:
530 1.8 christos default:
531 1.3 adam error("Certificate source-address "
532 1.3 adam "contents invalid");
533 1.3 adam goto out;
534 1.3 adam }
535 1.3 adam found = 1;
536 1.3 adam }
537 1.3 adam }
538 1.3 adam
539 1.3 adam if (!found) {
540 1.3 adam if (crit) {
541 1.3 adam error("Certificate critical option \"%s\" "
542 1.3 adam "is not supported", name);
543 1.3 adam goto out;
544 1.3 adam } else {
545 1.3 adam logit("Certificate extension \"%s\" "
546 1.3 adam "is not supported", name);
547 1.3 adam }
548 1.9 christos } else if (sshbuf_len(data) != 0) {
549 1.3 adam error("Certificate option \"%s\" corrupt "
550 1.3 adam "(extra data)", name);
551 1.3 adam goto out;
552 1.3 adam }
553 1.7 christos free(name);
554 1.7 christos name = NULL;
555 1.3 adam }
556 1.3 adam /* successfully parsed all options */
557 1.3 adam ret = 0;
558 1.3 adam
559 1.3 adam out:
560 1.3 adam if (ret != 0 &&
561 1.3 adam cert_forced_command != NULL &&
562 1.3 adam *cert_forced_command != NULL) {
563 1.7 christos free(*cert_forced_command);
564 1.3 adam *cert_forced_command = NULL;
565 1.3 adam }
566 1.3 adam if (name != NULL)
567 1.7 christos free(name);
568 1.9 christos sshbuf_free(data);
569 1.9 christos sshbuf_free(c);
570 1.3 adam return ret;
571 1.3 adam }
572 1.3 adam
573 1.3 adam /*
574 1.3 adam * Set options from critical certificate options. These supersede user key
575 1.3 adam * options so this must be called after auth_parse_options().
576 1.3 adam */
577 1.3 adam int
578 1.9 christos auth_cert_options(struct sshkey *k, struct passwd *pw)
579 1.3 adam {
580 1.3 adam int cert_no_port_forwarding_flag = 1;
581 1.3 adam int cert_no_agent_forwarding_flag = 1;
582 1.3 adam int cert_no_x11_forwarding_flag = 1;
583 1.3 adam int cert_no_pty_flag = 1;
584 1.3 adam int cert_no_user_rc = 1;
585 1.3 adam char *cert_forced_command = NULL;
586 1.3 adam int cert_source_address_done = 0;
587 1.3 adam
588 1.9 christos if (sshkey_cert_is_legacy(k)) {
589 1.3 adam /* All options are in the one field for v00 certs */
590 1.9 christos if (parse_option_list(k->cert->critical, pw,
591 1.3 adam OPTIONS_CRITICAL|OPTIONS_EXTENSIONS, 1,
592 1.3 adam &cert_no_port_forwarding_flag,
593 1.3 adam &cert_no_agent_forwarding_flag,
594 1.3 adam &cert_no_x11_forwarding_flag,
595 1.3 adam &cert_no_pty_flag,
596 1.3 adam &cert_no_user_rc,
597 1.3 adam &cert_forced_command,
598 1.3 adam &cert_source_address_done) == -1)
599 1.3 adam return -1;
600 1.3 adam } else {
601 1.3 adam /* Separate options and extensions for v01 certs */
602 1.9 christos if (parse_option_list(k->cert->critical, pw,
603 1.3 adam OPTIONS_CRITICAL, 1, NULL, NULL, NULL, NULL, NULL,
604 1.3 adam &cert_forced_command,
605 1.3 adam &cert_source_address_done) == -1)
606 1.3 adam return -1;
607 1.9 christos if (parse_option_list(k->cert->extensions, pw,
608 1.3 adam OPTIONS_EXTENSIONS, 1,
609 1.3 adam &cert_no_port_forwarding_flag,
610 1.3 adam &cert_no_agent_forwarding_flag,
611 1.3 adam &cert_no_x11_forwarding_flag,
612 1.3 adam &cert_no_pty_flag,
613 1.3 adam &cert_no_user_rc,
614 1.3 adam NULL, NULL) == -1)
615 1.3 adam return -1;
616 1.3 adam }
617 1.1 christos
618 1.3 adam no_port_forwarding_flag |= cert_no_port_forwarding_flag;
619 1.3 adam no_agent_forwarding_flag |= cert_no_agent_forwarding_flag;
620 1.3 adam no_x11_forwarding_flag |= cert_no_x11_forwarding_flag;
621 1.3 adam no_pty_flag |= cert_no_pty_flag;
622 1.3 adam no_user_rc |= cert_no_user_rc;
623 1.3 adam /* CA-specified forced command supersedes key option */
624 1.3 adam if (cert_forced_command != NULL) {
625 1.3 adam if (forced_command != NULL)
626 1.7 christos free(forced_command);
627 1.3 adam forced_command = cert_forced_command;
628 1.3 adam }
629 1.1 christos return 0;
630 1.1 christos }
631 1.3 adam
632