blob: 91e080efb918905d71132d2c986ef2b700639466 [file] [log] [blame]
Thomas Gleixnerb4d0d232019-05-20 19:08:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
David Howellsb56e5a12013-08-30 16:07:30 +01002/* 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 Howellsb56e5a12013-08-30 16:07:30 +01006 */
7
8#ifndef _KEYS_SYSTEM_KEYRING_H
9#define _KEYS_SYSTEM_KEYRING_H
10
David Howellsa511e1a2016-04-06 16:14:26 +010011#include <linux/key.h>
12
Mickaël Salaün141e5232021-07-12 19:03:12 +020013enum blacklist_hash_type {
14 /* TBSCertificate hash */
15 BLACKLIST_HASH_X509_TBS = 1,
16 /* Raw data hash */
17 BLACKLIST_HASH_BINARY = 2,
18};
19
David Howellsb56e5a12013-08-30 16:07:30 +010020#ifdef CONFIG_SYSTEM_TRUSTED_KEYRING
21
David Howellsa511e1a2016-04-06 16:14:26 +010022extern int restrict_link_by_builtin_trusted(struct key *keyring,
23 const struct key_type *type,
Mat Martineauaaf66c82016-08-30 11:33:13 -070024 const union key_payload *payload,
25 struct key *restriction_key);
Nayna Jain6cbdfb32021-04-09 10:35:07 -040026extern __init int load_module_cert(struct key *keyring);
David Howellsb56e5a12013-08-30 16:07:30 +010027
Mimi Zohar3be4bea2013-08-20 14:36:27 -040028#else
David Howellsa511e1a2016-04-06 16:14:26 +010029#define restrict_link_by_builtin_trusted restrict_link_reject
Nayna Jain6cbdfb32021-04-09 10:35:07 -040030
31static inline __init int load_module_cert(struct key *keyring)
32{
33 return 0;
34}
35
David Howellsb56e5a12013-08-30 16:07:30 +010036#endif
37
David Howellsd3bfe842016-04-06 16:14:27 +010038#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
39extern int restrict_link_by_builtin_and_secondary_trusted(
40 struct key *keyring,
41 const struct key_type *type,
Mat Martineauaaf66c82016-08-30 11:33:13 -070042 const union key_payload *payload,
43 struct key *restriction_key);
David Howellsd3bfe842016-04-06 16:14:27 +010044#else
45#define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
46#endif
47
Eric Snowberg56edb6c2022-01-25 21:58:30 -050048#ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
Eric Snowberg087aa4e2022-01-25 21:58:31 -050049extern 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 Snowberg56edb6c2022-01-25 21:58:30 -050054extern void __init set_machine_trusted_keys(struct key *keyring);
55#else
Eric Snowberg087aa4e2022-01-25 21:58:31 -050056#define restrict_link_by_builtin_secondary_and_machine restrict_link_by_builtin_trusted
Eric Snowberg56edb6c2022-01-25 21:58:30 -050057static inline void __init set_machine_trusted_keys(struct key *keyring)
58{
59}
60#endif
61
Eric Snowberg56c58122021-01-22 13:10:51 -050062extern struct pkcs7_message *pkcs7;
David Howells734114f2017-04-03 16:07:24 +010063#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
Mickaël Salaün141e5232021-07-12 19:03:12 +020064extern int mark_hash_blacklisted(const u8 *hash, size_t hash_len,
65 enum blacklist_hash_type hash_type);
David Howells734114f2017-04-03 16:07:24 +010066extern int is_hash_blacklisted(const u8 *hash, size_t hash_len,
Mickaël Salaün141e5232021-07-12 19:03:12 +020067 enum blacklist_hash_type hash_type);
Nayna Jain2434f7d2019-10-30 23:31:31 -040068extern int is_binary_blacklisted(const u8 *hash, size_t hash_len);
David Howells734114f2017-04-03 16:07:24 +010069#else
70static inline int is_hash_blacklisted(const u8 *hash, size_t hash_len,
Mickaël Salaün141e5232021-07-12 19:03:12 +020071 enum blacklist_hash_type hash_type)
David Howells734114f2017-04-03 16:07:24 +010072{
73 return 0;
74}
Nayna Jain2434f7d2019-10-30 23:31:31 -040075
76static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len)
77{
78 return 0;
79}
David Howells734114f2017-04-03 16:07:24 +010080#endif
81
Eric Snowberg56c58122021-01-22 13:10:51 -050082#ifdef CONFIG_SYSTEM_REVOCATION_LIST
83extern int add_key_to_revocation_list(const char *data, size_t size);
84extern int is_key_on_revocation_list(struct pkcs7_message *pkcs7);
85#else
86static inline int add_key_to_revocation_list(const char *data, size_t size)
87{
88 return 0;
89}
90static inline int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
91{
92 return -ENOKEY;
93}
94#endif
95
David Howells56104cf2016-04-07 09:45:23 +010096#ifdef CONFIG_IMA_BLACKLIST_KEYRING
Petko Manolov41c89b62015-12-02 17:47:55 +020097extern struct key *ima_blacklist_keyring;
98
Petko Manolov41c89b62015-12-02 17:47:55 +020099static inline struct key *get_ima_blacklist_keyring(void)
100{
101 return ima_blacklist_keyring;
102}
103#else
Petko Manolov41c89b62015-12-02 17:47:55 +0200104static inline struct key *get_ima_blacklist_keyring(void)
105{
106 return NULL;
107}
David Howells56104cf2016-04-07 09:45:23 +0100108#endif /* CONFIG_IMA_BLACKLIST_KEYRING */
Petko Manolov41c89b62015-12-02 17:47:55 +0200109
Kairui Song219a3e82019-01-21 17:59:28 +0800110#if defined(CONFIG_INTEGRITY_PLATFORM_KEYRING) && \
111 defined(CONFIG_SYSTEM_TRUSTED_KEYRING)
112extern void __init set_platform_trusted_keys(struct key *keyring);
113#else
114static inline void set_platform_trusted_keys(struct key *keyring)
115{
116}
117#endif
Petko Manolov41c89b62015-12-02 17:47:55 +0200118
David Howellsb56e5a12013-08-30 16:07:30 +0100119#endif /* _KEYS_SYSTEM_KEYRING_H */