diff options
Diffstat (limited to 'auth2-pubkey.c')
-rw-r--r-- | auth2-pubkey.c | 72 |
1 files changed, 24 insertions, 48 deletions
diff --git a/auth2-pubkey.c b/auth2-pubkey.c index 0b3975a74..df12c2c60 100644 --- a/auth2-pubkey.c +++ b/auth2-pubkey.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: auth2-pubkey.c,v 1.87 2019/01/22 11:26:16 djm Exp $ */ | 1 | /* $OpenBSD: auth2-pubkey.c,v 1.94 2019/09/06 04:53:27 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -28,6 +28,7 @@ | |||
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | 30 | ||
31 | #include <stdlib.h> | ||
31 | #include <errno.h> | 32 | #include <errno.h> |
32 | #include <fcntl.h> | 33 | #include <fcntl.h> |
33 | #ifdef HAVE_PATHS_H | 34 | #ifdef HAVE_PATHS_H |
@@ -109,7 +110,7 @@ userauth_pubkey(struct ssh *ssh) | |||
109 | 110 | ||
110 | if ((pkbuf = sshbuf_from(pkblob, blen)) == NULL) | 111 | if ((pkbuf = sshbuf_from(pkblob, blen)) == NULL) |
111 | fatal("%s: sshbuf_from failed", __func__); | 112 | fatal("%s: sshbuf_from failed", __func__); |
112 | if ((keystring = sshbuf_dtob64(pkbuf)) == NULL) | 113 | if ((keystring = sshbuf_dtob64_string(pkbuf, 0)) == NULL) |
113 | fatal("%s: sshbuf_dtob64 failed", __func__); | 114 | fatal("%s: sshbuf_dtob64 failed", __func__); |
114 | debug2("%s: %s user %s %s public key %s %s", __func__, | 115 | debug2("%s: %s user %s %s public key %s %s", __func__, |
115 | authctxt->valid ? "valid" : "invalid", authctxt->user, | 116 | authctxt->valid ? "valid" : "invalid", authctxt->user, |
@@ -418,7 +419,7 @@ match_principals_command(struct ssh *ssh, struct passwd *user_pw, | |||
418 | pid_t pid; | 419 | pid_t pid; |
419 | char *tmp, *username = NULL, *command = NULL, **av = NULL; | 420 | char *tmp, *username = NULL, *command = NULL, **av = NULL; |
420 | char *ca_fp = NULL, *key_fp = NULL, *catext = NULL, *keytext = NULL; | 421 | char *ca_fp = NULL, *key_fp = NULL, *catext = NULL, *keytext = NULL; |
421 | char serial_s[16], uidstr[32]; | 422 | char serial_s[32], uidstr[32]; |
422 | void (*osigchld)(int); | 423 | void (*osigchld)(int); |
423 | 424 | ||
424 | if (authoptsp != NULL) | 425 | if (authoptsp != NULL) |
@@ -450,12 +451,12 @@ match_principals_command(struct ssh *ssh, struct passwd *user_pw, | |||
450 | /* Turn the command into an argument vector */ | 451 | /* Turn the command into an argument vector */ |
451 | if (argv_split(options.authorized_principals_command, &ac, &av) != 0) { | 452 | if (argv_split(options.authorized_principals_command, &ac, &av) != 0) { |
452 | error("AuthorizedPrincipalsCommand \"%s\" contains " | 453 | error("AuthorizedPrincipalsCommand \"%s\" contains " |
453 | "invalid quotes", command); | 454 | "invalid quotes", options.authorized_principals_command); |
454 | goto out; | 455 | goto out; |
455 | } | 456 | } |
456 | if (ac == 0) { | 457 | if (ac == 0) { |
457 | error("AuthorizedPrincipalsCommand \"%s\" yielded no arguments", | 458 | error("AuthorizedPrincipalsCommand \"%s\" yielded no arguments", |
458 | command); | 459 | options.authorized_principals_command); |
459 | goto out; | 460 | goto out; |
460 | } | 461 | } |
461 | if ((ca_fp = sshkey_fingerprint(cert->signature_key, | 462 | if ((ca_fp = sshkey_fingerprint(cert->signature_key, |
@@ -538,38 +539,6 @@ match_principals_command(struct ssh *ssh, struct passwd *user_pw, | |||
538 | return found_principal; | 539 | return found_principal; |
539 | } | 540 | } |
540 | 541 | ||
541 | static void | ||
542 | skip_space(char **cpp) | ||
543 | { | ||
544 | char *cp; | ||
545 | |||
546 | for (cp = *cpp; *cp == ' ' || *cp == '\t'; cp++) | ||
547 | ; | ||
548 | *cpp = cp; | ||
549 | } | ||
550 | |||
551 | /* | ||
552 | * Advanced *cpp past the end of key options, defined as the first unquoted | ||
553 | * whitespace character. Returns 0 on success or -1 on failure (e.g. | ||
554 | * unterminated quotes). | ||
555 | */ | ||
556 | static int | ||
557 | advance_past_options(char **cpp) | ||
558 | { | ||
559 | char *cp = *cpp; | ||
560 | int quoted = 0; | ||
561 | |||
562 | for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) { | ||
563 | if (*cp == '\\' && cp[1] == '"') | ||
564 | cp++; /* Skip both */ | ||
565 | else if (*cp == '"') | ||
566 | quoted = !quoted; | ||
567 | } | ||
568 | *cpp = cp; | ||
569 | /* return failure for unterminated quotes */ | ||
570 | return (*cp == '\0' && quoted) ? -1 : 0; | ||
571 | } | ||
572 | |||
573 | /* | 542 | /* |
574 | * Check a single line of an authorized_keys-format file. Returns 0 if key | 543 | * Check a single line of an authorized_keys-format file. Returns 0 if key |
575 | * matches, -1 otherwise. Will return key/cert options via *authoptsp | 544 | * matches, -1 otherwise. Will return key/cert options via *authoptsp |
@@ -600,7 +569,7 @@ check_authkey_line(struct ssh *ssh, struct passwd *pw, struct sshkey *key, | |||
600 | /* no key? check for options */ | 569 | /* no key? check for options */ |
601 | debug2("%s: check options: '%s'", loc, cp); | 570 | debug2("%s: check options: '%s'", loc, cp); |
602 | key_options = cp; | 571 | key_options = cp; |
603 | if (advance_past_options(&cp) != 0) { | 572 | if (sshkey_advance_past_options(&cp) != 0) { |
604 | reason = "invalid key option string"; | 573 | reason = "invalid key option string"; |
605 | goto fail_reason; | 574 | goto fail_reason; |
606 | } | 575 | } |
@@ -1014,9 +983,10 @@ int | |||
1014 | user_key_allowed(struct ssh *ssh, struct passwd *pw, struct sshkey *key, | 983 | user_key_allowed(struct ssh *ssh, struct passwd *pw, struct sshkey *key, |
1015 | int auth_attempt, struct sshauthopt **authoptsp) | 984 | int auth_attempt, struct sshauthopt **authoptsp) |
1016 | { | 985 | { |
1017 | u_int success, i; | 986 | u_int success = 0, i; |
1018 | char *file; | 987 | char *file; |
1019 | struct sshauthopt *opts = NULL; | 988 | struct sshauthopt *opts = NULL; |
989 | |||
1020 | if (authoptsp != NULL) | 990 | if (authoptsp != NULL) |
1021 | *authoptsp = NULL; | 991 | *authoptsp = NULL; |
1022 | 992 | ||
@@ -1026,6 +996,21 @@ user_key_allowed(struct ssh *ssh, struct passwd *pw, struct sshkey *key, | |||
1026 | auth_key_is_revoked(key->cert->signature_key)) | 996 | auth_key_is_revoked(key->cert->signature_key)) |
1027 | return 0; | 997 | return 0; |
1028 | 998 | ||
999 | for (i = 0; !success && i < options.num_authkeys_files; i++) { | ||
1000 | if (strcasecmp(options.authorized_keys_files[i], "none") == 0) | ||
1001 | continue; | ||
1002 | file = expand_authorized_keys( | ||
1003 | options.authorized_keys_files[i], pw); | ||
1004 | success = user_key_allowed2(ssh, pw, key, file, &opts); | ||
1005 | free(file); | ||
1006 | if (!success) { | ||
1007 | sshauthopt_free(opts); | ||
1008 | opts = NULL; | ||
1009 | } | ||
1010 | } | ||
1011 | if (success) | ||
1012 | goto out; | ||
1013 | |||
1029 | if ((success = user_cert_trusted_ca(ssh, pw, key, &opts)) != 0) | 1014 | if ((success = user_cert_trusted_ca(ssh, pw, key, &opts)) != 0) |
1030 | goto out; | 1015 | goto out; |
1031 | sshauthopt_free(opts); | 1016 | sshauthopt_free(opts); |
@@ -1036,15 +1021,6 @@ user_key_allowed(struct ssh *ssh, struct passwd *pw, struct sshkey *key, | |||
1036 | sshauthopt_free(opts); | 1021 | sshauthopt_free(opts); |
1037 | opts = NULL; | 1022 | opts = NULL; |
1038 | 1023 | ||
1039 | for (i = 0; !success && i < options.num_authkeys_files; i++) { | ||
1040 | if (strcasecmp(options.authorized_keys_files[i], "none") == 0) | ||
1041 | continue; | ||
1042 | file = expand_authorized_keys( | ||
1043 | options.authorized_keys_files[i], pw); | ||
1044 | success = user_key_allowed2(ssh, pw, key, file, &opts); | ||
1045 | free(file); | ||
1046 | } | ||
1047 | |||
1048 | out: | 1024 | out: |
1049 | if (success && authoptsp != NULL) { | 1025 | if (success && authoptsp != NULL) { |
1050 | *authoptsp = opts; | 1026 | *authoptsp = opts; |