/* * Checks whether the specified key is revoked, returning 0 if not, * SSH_ERR_KEY_REVOKED if it is or another error code if something * unexpected happened. * This will check both the key and, if it is a certificate, its CA key too. * "revoked_keys_file" may be a KRL or a one-per-line list of public keys. */ int sshkey_check_revoked(struct sshkey *key, const char *revoked_keys_file) { int r; #ifdef WITH_OPENSSL r = ssh_krl_file_contains_key(revoked_keys_file, key); /* If this was not a KRL to begin with then continue below */ if (r != SSH_ERR_KRL_BAD_MAGIC) return r; #endif /* * If the file is not a KRL or we can't handle KRLs then attempt to * parse the file as a flat list of keys. */ switch ((r = sshkey_in_file(key, revoked_keys_file, 0, 1))) { case 0: /* Key found => revoked */ return SSH_ERR_KEY_REVOKED; case SSH_ERR_KEY_NOT_FOUND: /* Key not found => not revoked */ return 0; default: /* Some other error occurred */ return r; } }
/* Authenticate a certificate key against TrustedUserCAKeys */ static int user_cert_trusted_ca(struct passwd *pw, Key *key) { char *ca_fp, *principals_file = NULL; const char *reason; int ret = 0, found_principal = 0, use_authorized_principals; if (!key_is_cert(key) || options.trusted_user_ca_keys == NULL) return 0; if ((ca_fp = sshkey_fingerprint(key->cert->signature_key, options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL) return 0; if (sshkey_in_file(key->cert->signature_key, options.trusted_user_ca_keys, 1, 0) != 0) { debug2("%s: CA %s %s is not listed in %s", __func__, key_type(key->cert->signature_key), ca_fp, options.trusted_user_ca_keys); goto out; } /* * If AuthorizedPrincipals is in use, then compare the certificate * principals against the names in that file rather than matching * against the username. */ if ((principals_file = authorized_principals_file(pw)) != NULL) { if (match_principals_file(principals_file, pw, key->cert)) found_principal = 1; } /* Try querying command if specified */ if (!found_principal && match_principals_command(pw, key->cert)) found_principal = 1; /* If principals file or command is specified, then require a match */ use_authorized_principals = principals_file != NULL || options.authorized_principals_command != NULL; if (!found_principal && use_authorized_principals) { reason = "Certificate does not contain an authorized principal"; fail_reason: error("%s", reason); auth_debug_add("%s", reason); goto out; } if (key_cert_check_authority(key, 0, 1, use_authorized_principals ? NULL : pw->pw_name, &reason) != 0) goto fail_reason; if (auth_cert_options(key, pw) != 0) goto out; verbose("Accepted certificate ID \"%s\" signed by %s CA %s via %s", key->cert->key_id, key_type(key->cert->signature_key), ca_fp, options.trusted_user_ca_keys); ret = 1; out: free(principals_file); free(ca_fp); return ret; }