Example #1
0
/*
 * 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;
	}
}
Example #2
0
/* Returns 1 if key is revoked by revoked_keys_file, 0 otherwise */
int
auth_key_is_revoked(Key *key)
{
	char *key_fp;

	if (options.revoked_keys_file == NULL)
		return 0;
	switch (ssh_krl_file_contains_key(options.revoked_keys_file, key)) {
	case 0:
		return 0;	/* Not revoked */
	case -2:
		break;		/* Not a KRL */
	default:
		goto revoked;
	}
	debug3("%s: treating %s as a key list", __func__,
	    options.revoked_keys_file);
	switch (key_in_file(key, options.revoked_keys_file, 0)) {
	case 0:
		/* key not revoked */
		return 0;
	case -1:
		/* Error opening revoked_keys_file: refuse all keys */
		error("Revoked keys file is unreadable: refusing public key "
		    "authentication");
		return 1;
	case 1:
 revoked:
		/* Key revoked */
		key_fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
		error("WARNING: authentication attempt with a revoked "
		    "%s key %s ", key_type(key), key_fp);
		xfree(key_fp);
		return 1;
	}
	fatal("key_in_file returned junk");
}