blob: 6acd3cf13a18c70f9a4b8d8bdaf5128dfff6ace4 [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
David Howellsb56e5a12013-08-30 16:07:30 +010013#ifdef CONFIG_SYSTEM_TRUSTED_KEYRING
14
David Howellsa511e1a2016-04-06 16:14:26 +010015extern int restrict_link_by_builtin_trusted(struct key *keyring,
16 const struct key_type *type,
Mat Martineauaaf66c82016-08-30 11:33:13 -070017 const union key_payload *payload,
18 struct key *restriction_key);
Nayna Jain6cbdfb32021-04-09 10:35:07 -040019extern __init int load_module_cert(struct key *keyring);
David Howellsb56e5a12013-08-30 16:07:30 +010020
Mimi Zohar3be4bea2013-08-20 14:36:27 -040021#else
David Howellsa511e1a2016-04-06 16:14:26 +010022#define restrict_link_by_builtin_trusted restrict_link_reject
Nayna Jain6cbdfb32021-04-09 10:35:07 -040023
24static inline __init int load_module_cert(struct key *keyring)
25{
26 return 0;
27}
28
David Howellsb56e5a12013-08-30 16:07:30 +010029#endif
30
David Howellsd3bfe842016-04-06 16:14:27 +010031#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
32extern int restrict_link_by_builtin_and_secondary_trusted(
33 struct key *keyring,
34 const struct key_type *type,
Mat Martineauaaf66c82016-08-30 11:33:13 -070035 const union key_payload *payload,
36 struct key *restriction_key);
David Howellsd3bfe842016-04-06 16:14:27 +010037#else
38#define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
39#endif
40
Eric Snowberg56c58122021-01-22 13:10:51 -050041extern struct pkcs7_message *pkcs7;
David Howells734114f2017-04-03 16:07:24 +010042#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
43extern int mark_hash_blacklisted(const char *hash);
44extern int is_hash_blacklisted(const u8 *hash, size_t hash_len,
45 const char *type);
Nayna Jain2434f7d2019-10-30 23:31:31 -040046extern int is_binary_blacklisted(const u8 *hash, size_t hash_len);
David Howells734114f2017-04-03 16:07:24 +010047#else
48static inline int is_hash_blacklisted(const u8 *hash, size_t hash_len,
49 const char *type)
50{
51 return 0;
52}
Nayna Jain2434f7d2019-10-30 23:31:31 -040053
54static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len)
55{
56 return 0;
57}
David Howells734114f2017-04-03 16:07:24 +010058#endif
59
Eric Snowberg56c58122021-01-22 13:10:51 -050060#ifdef CONFIG_SYSTEM_REVOCATION_LIST
61extern int add_key_to_revocation_list(const char *data, size_t size);
62extern int is_key_on_revocation_list(struct pkcs7_message *pkcs7);
63#else
64static inline int add_key_to_revocation_list(const char *data, size_t size)
65{
66 return 0;
67}
68static inline int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
69{
70 return -ENOKEY;
71}
72#endif
73
David Howells56104cf2016-04-07 09:45:23 +010074#ifdef CONFIG_IMA_BLACKLIST_KEYRING
Petko Manolov41c89b62015-12-02 17:47:55 +020075extern struct key *ima_blacklist_keyring;
76
Petko Manolov41c89b62015-12-02 17:47:55 +020077static inline struct key *get_ima_blacklist_keyring(void)
78{
79 return ima_blacklist_keyring;
80}
81#else
Petko Manolov41c89b62015-12-02 17:47:55 +020082static inline struct key *get_ima_blacklist_keyring(void)
83{
84 return NULL;
85}
David Howells56104cf2016-04-07 09:45:23 +010086#endif /* CONFIG_IMA_BLACKLIST_KEYRING */
Petko Manolov41c89b62015-12-02 17:47:55 +020087
Kairui Song219a3e82019-01-21 17:59:28 +080088#if defined(CONFIG_INTEGRITY_PLATFORM_KEYRING) && \
89 defined(CONFIG_SYSTEM_TRUSTED_KEYRING)
90extern void __init set_platform_trusted_keys(struct key *keyring);
91#else
92static inline void set_platform_trusted_keys(struct key *keyring)
93{
94}
95#endif
Petko Manolov41c89b62015-12-02 17:47:55 +020096
David Howellsb56e5a12013-08-30 16:07:30 +010097#endif /* _KEYS_SYSTEM_KEYRING_H */