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 | |
Mickaël Salaün | 141e523 | 2021-07-12 19:03:12 +0200 | [diff] [blame] | 13 | enum blacklist_hash_type { |
| 14 | /* TBSCertificate hash */ |
| 15 | BLACKLIST_HASH_X509_TBS = 1, |
| 16 | /* Raw data hash */ |
| 17 | BLACKLIST_HASH_BINARY = 2, |
| 18 | }; |
| 19 | |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 20 | #ifdef CONFIG_SYSTEM_TRUSTED_KEYRING |
| 21 | |
David Howells | a511e1a | 2016-04-06 16:14:26 +0100 | [diff] [blame] | 22 | extern int restrict_link_by_builtin_trusted(struct key *keyring, |
| 23 | const struct key_type *type, |
Mat Martineau | aaf66c8 | 2016-08-30 11:33:13 -0700 | [diff] [blame] | 24 | const union key_payload *payload, |
| 25 | struct key *restriction_key); |
Nayna Jain | 6cbdfb3 | 2021-04-09 10:35:07 -0400 | [diff] [blame] | 26 | extern __init int load_module_cert(struct key *keyring); |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 27 | |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 28 | #else |
David Howells | a511e1a | 2016-04-06 16:14:26 +0100 | [diff] [blame] | 29 | #define restrict_link_by_builtin_trusted restrict_link_reject |
Nayna Jain | 6cbdfb3 | 2021-04-09 10:35:07 -0400 | [diff] [blame] | 30 | |
| 31 | static inline __init int load_module_cert(struct key *keyring) |
| 32 | { |
| 33 | return 0; |
| 34 | } |
| 35 | |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 36 | #endif |
| 37 | |
David Howells | d3bfe84 | 2016-04-06 16:14:27 +0100 | [diff] [blame] | 38 | #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING |
| 39 | extern int restrict_link_by_builtin_and_secondary_trusted( |
| 40 | struct key *keyring, |
| 41 | const struct key_type *type, |
Mat Martineau | aaf66c8 | 2016-08-30 11:33:13 -0700 | [diff] [blame] | 42 | const union key_payload *payload, |
| 43 | struct key *restriction_key); |
David Howells | d3bfe84 | 2016-04-06 16:14:27 +0100 | [diff] [blame] | 44 | #else |
| 45 | #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted |
| 46 | #endif |
| 47 | |
Eric Snowberg | 56edb6c | 2022-01-25 21:58:30 -0500 | [diff] [blame] | 48 | #ifdef CONFIG_INTEGRITY_MACHINE_KEYRING |
Eric Snowberg | 087aa4e | 2022-01-25 21:58:31 -0500 | [diff] [blame] | 49 | extern int restrict_link_by_builtin_secondary_and_machine( |
| 50 | struct key *dest_keyring, |
| 51 | const struct key_type *type, |
| 52 | const union key_payload *payload, |
| 53 | struct key *restrict_key); |
Eric Snowberg | 56edb6c | 2022-01-25 21:58:30 -0500 | [diff] [blame] | 54 | extern void __init set_machine_trusted_keys(struct key *keyring); |
| 55 | #else |
Eric Snowberg | 087aa4e | 2022-01-25 21:58:31 -0500 | [diff] [blame] | 56 | #define restrict_link_by_builtin_secondary_and_machine restrict_link_by_builtin_trusted |
Eric Snowberg | 56edb6c | 2022-01-25 21:58:30 -0500 | [diff] [blame] | 57 | static inline void __init set_machine_trusted_keys(struct key *keyring) |
| 58 | { |
| 59 | } |
| 60 | #endif |
| 61 | |
Eric Snowberg | 56c5812 | 2021-01-22 13:10:51 -0500 | [diff] [blame] | 62 | extern struct pkcs7_message *pkcs7; |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 63 | #ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING |
Mickaël Salaün | 141e523 | 2021-07-12 19:03:12 +0200 | [diff] [blame] | 64 | extern int mark_hash_blacklisted(const u8 *hash, size_t hash_len, |
| 65 | enum blacklist_hash_type hash_type); |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 66 | extern int is_hash_blacklisted(const u8 *hash, size_t hash_len, |
Mickaël Salaün | 141e523 | 2021-07-12 19:03:12 +0200 | [diff] [blame] | 67 | enum blacklist_hash_type hash_type); |
Nayna Jain | 2434f7d | 2019-10-30 23:31:31 -0400 | [diff] [blame] | 68 | extern int is_binary_blacklisted(const u8 *hash, size_t hash_len); |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 69 | #else |
| 70 | static inline int is_hash_blacklisted(const u8 *hash, size_t hash_len, |
Mickaël Salaün | 141e523 | 2021-07-12 19:03:12 +0200 | [diff] [blame] | 71 | enum blacklist_hash_type hash_type) |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 72 | { |
| 73 | return 0; |
| 74 | } |
Nayna Jain | 2434f7d | 2019-10-30 23:31:31 -0400 | [diff] [blame] | 75 | |
| 76 | static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len) |
| 77 | { |
| 78 | return 0; |
| 79 | } |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 80 | #endif |
| 81 | |
Eric Snowberg | 56c5812 | 2021-01-22 13:10:51 -0500 | [diff] [blame] | 82 | #ifdef CONFIG_SYSTEM_REVOCATION_LIST |
| 83 | extern int add_key_to_revocation_list(const char *data, size_t size); |
| 84 | extern int is_key_on_revocation_list(struct pkcs7_message *pkcs7); |
| 85 | #else |
| 86 | static inline int add_key_to_revocation_list(const char *data, size_t size) |
| 87 | { |
| 88 | return 0; |
| 89 | } |
| 90 | static inline int is_key_on_revocation_list(struct pkcs7_message *pkcs7) |
| 91 | { |
| 92 | return -ENOKEY; |
| 93 | } |
| 94 | #endif |
| 95 | |
David Howells | 56104cf | 2016-04-07 09:45:23 +0100 | [diff] [blame] | 96 | #ifdef CONFIG_IMA_BLACKLIST_KEYRING |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 97 | extern struct key *ima_blacklist_keyring; |
| 98 | |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 99 | static inline struct key *get_ima_blacklist_keyring(void) |
| 100 | { |
| 101 | return ima_blacklist_keyring; |
| 102 | } |
| 103 | #else |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 104 | static inline struct key *get_ima_blacklist_keyring(void) |
| 105 | { |
| 106 | return NULL; |
| 107 | } |
David Howells | 56104cf | 2016-04-07 09:45:23 +0100 | [diff] [blame] | 108 | #endif /* CONFIG_IMA_BLACKLIST_KEYRING */ |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 109 | |
Kairui Song | 219a3e8 | 2019-01-21 17:59:28 +0800 | [diff] [blame] | 110 | #if defined(CONFIG_INTEGRITY_PLATFORM_KEYRING) && \ |
| 111 | defined(CONFIG_SYSTEM_TRUSTED_KEYRING) |
| 112 | extern void __init set_platform_trusted_keys(struct key *keyring); |
| 113 | #else |
| 114 | static inline void set_platform_trusted_keys(struct key *keyring) |
| 115 | { |
| 116 | } |
| 117 | #endif |
Petko Manolov | 41c89b6 | 2015-12-02 17:47:55 +0200 | [diff] [blame] | 118 | |
David Howells | b56e5a1 | 2013-08-30 16:07:30 +0100 | [diff] [blame] | 119 | #endif /* _KEYS_SYSTEM_KEYRING_H */ |