Thomas Gleixner | b4d0d23 | 2019-05-20 19:08:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 2 | /* System keyring containing trusted public keys. |
| 3 | * |
| 4 | * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _KEYS_SYSTEM_KEYRING_H |
| 9 | #define _KEYS_SYSTEM_KEYRING_H |
| 10 | |
David Howells | a511e1a | 2016-04-06 16:14:26 +0100 | [diff] [blame] | 11 | #include <linux/key.h> |
| 12 | |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 13 | #ifdef CONFIG_SYSTEM_TRUSTED_KEYRING |
| 14 | |
David Howells | a511e1a | 2016-04-06 16:14:26 +0100 | [diff] [blame] | 15 | extern int restrict_link_by_builtin_trusted(struct key *keyring, |
| 16 | const struct key_type *type, |
Mat Martineau | aaf66c8 | 2016-08-30 11:33:13 -0700 | [diff] [blame] | 17 | const union key_payload *payload, |
| 18 | struct key *restriction_key); |
Nayna Jain | 6cbdfb3 | 2021-04-09 10:35:07 -0400 | [diff] [blame] | 19 | extern __init int load_module_cert(struct key *keyring); |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 20 | |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 21 | #else |
David Howells | a511e1a | 2016-04-06 16:14:26 +0100 | [diff] [blame] | 22 | #define restrict_link_by_builtin_trusted restrict_link_reject |
Nayna Jain | 6cbdfb3 | 2021-04-09 10:35:07 -0400 | [diff] [blame] | 23 | |
| 24 | static inline __init int load_module_cert(struct key *keyring) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 29 | #endif |
| 30 | |
David Howells | d3bfe84 | 2016-04-06 16:14:27 +0100 | [diff] [blame] | 31 | #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING |
| 32 | extern int restrict_link_by_builtin_and_secondary_trusted( |
| 33 | struct key *keyring, |
| 34 | const struct key_type *type, |
Mat Martineau | aaf66c8 | 2016-08-30 11:33:13 -0700 | [diff] [blame] | 35 | const union key_payload *payload, |
| 36 | struct key *restriction_key); |
David Howells | d3bfe84 | 2016-04-06 16:14:27 +0100 | [diff] [blame] | 37 | #else |
| 38 | #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted |
| 39 | #endif |
| 40 | |
Eric Snowberg | 56c5812 | 2021-01-22 13:10:51 -0500 | [diff] [blame] | 41 | extern struct pkcs7_message *pkcs7; |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 42 | #ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING |
| 43 | extern int mark_hash_blacklisted(const char *hash); |
| 44 | extern int is_hash_blacklisted(const u8 *hash, size_t hash_len, |
| 45 | const char *type); |
Nayna Jain | 2434f7d | 2019-10-30 23:31:31 -0400 | [diff] [blame] | 46 | extern int is_binary_blacklisted(const u8 *hash, size_t hash_len); |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 47 | #else |
| 48 | static inline int is_hash_blacklisted(const u8 *hash, size_t hash_len, |
| 49 | const char *type) |
| 50 | { |
| 51 | return 0; |
| 52 | } |
Nayna Jain | 2434f7d | 2019-10-30 23:31:31 -0400 | [diff] [blame] | 53 | |
| 54 | static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len) |
| 55 | { |
| 56 | return 0; |
| 57 | } |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 58 | #endif |
| 59 | |
Eric Snowberg | 56c5812 | 2021-01-22 13:10:51 -0500 | [diff] [blame] | 60 | #ifdef CONFIG_SYSTEM_REVOCATION_LIST |
| 61 | extern int add_key_to_revocation_list(const char *data, size_t size); |
| 62 | extern int is_key_on_revocation_list(struct pkcs7_message *pkcs7); |
| 63 | #else |
| 64 | static inline int add_key_to_revocation_list(const char *data, size_t size) |
| 65 | { |
| 66 | return 0; |
| 67 | } |
| 68 | static inline int is_key_on_revocation_list(struct pkcs7_message *pkcs7) |
| 69 | { |
| 70 | return -ENOKEY; |
| 71 | } |
| 72 | #endif |
| 73 | |
David Howells | 56104cf | 2016-04-07 09:45:23 +0100 | [diff] [blame] | 74 | #ifdef CONFIG_IMA_BLACKLIST_KEYRING |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 75 | extern struct key *ima_blacklist_keyring; |
| 76 | |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 77 | static inline struct key *get_ima_blacklist_keyring(void) |
| 78 | { |
| 79 | return ima_blacklist_keyring; |
| 80 | } |
| 81 | #else |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 82 | static inline struct key *get_ima_blacklist_keyring(void) |
| 83 | { |
| 84 | return NULL; |
| 85 | } |
David Howells | 56104cf | 2016-04-07 09:45:23 +0100 | [diff] [blame] | 86 | #endif /* CONFIG_IMA_BLACKLIST_KEYRING */ |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 87 | |
Kairui Song | 219a3e8 | 2019-01-21 17:59:28 +0800 | [diff] [blame] | 88 | #if defined(CONFIG_INTEGRITY_PLATFORM_KEYRING) && \ |
| 89 | defined(CONFIG_SYSTEM_TRUSTED_KEYRING) |
| 90 | extern void __init set_platform_trusted_keys(struct key *keyring); |
| 91 | #else |
| 92 | static inline void set_platform_trusted_keys(struct key *keyring) |
| 93 | { |
| 94 | } |
| 95 | #endif |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 96 | |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 97 | #endif /* _KEYS_SYSTEM_KEYRING_H */ |