^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* System keyring containing trusted public keys.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef _KEYS_SYSTEM_KEYRING_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define _KEYS_SYSTEM_KEYRING_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/key.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #ifdef CONFIG_SYSTEM_TRUSTED_KEYRING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) extern int restrict_link_by_builtin_trusted(struct key *keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct key *restriction_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define restrict_link_by_builtin_trusted restrict_link_reject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) extern int restrict_link_by_builtin_and_secondary_trusted(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct key *keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct key *restriction_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) extern struct pkcs7_message *pkcs7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) extern int mark_hash_blacklisted(const char *hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) extern int is_hash_blacklisted(const u8 *hash, size_t hash_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) const char *type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) extern int is_binary_blacklisted(const u8 *hash, size_t hash_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static inline int is_hash_blacklisted(const u8 *hash, size_t hash_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) const char *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #ifdef CONFIG_SYSTEM_REVOCATION_LIST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) extern int add_key_to_revocation_list(const char *data, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) extern int is_key_on_revocation_list(struct pkcs7_message *pkcs7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static inline int add_key_to_revocation_list(const char *data, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static inline int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #ifdef CONFIG_IMA_BLACKLIST_KEYRING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) extern struct key *ima_blacklist_keyring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static inline struct key *get_ima_blacklist_keyring(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return ima_blacklist_keyring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static inline struct key *get_ima_blacklist_keyring(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #endif /* CONFIG_IMA_BLACKLIST_KEYRING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #if defined(CONFIG_INTEGRITY_PLATFORM_KEYRING) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) defined(CONFIG_SYSTEM_TRUSTED_KEYRING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) extern void __init set_platform_trusted_keys(struct key *keyring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static inline void set_platform_trusted_keys(struct key *keyring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #endif /* _KEYS_SYSTEM_KEYRING_H */