2019-05-20 19:08:01 +02:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2013-08-30 16:07:30 +01:00
/* System keyring containing trusted public keys.
*
* Copyright ( C ) 2013 Red Hat , Inc . All Rights Reserved .
* Written by David Howells ( dhowells @ redhat . com )
*/
# ifndef _KEYS_SYSTEM_KEYRING_H
# define _KEYS_SYSTEM_KEYRING_H
KEYS: Move the point of trust determination to __key_link()
Move the point at which a key is determined to be trustworthy to
__key_link() so that we use the contents of the keyring being linked in to
to determine whether the key being linked in is trusted or not.
What is 'trusted' then becomes a matter of what's in the keyring.
Currently, the test is done when the key is parsed, but given that at that
point we can only sensibly refer to the contents of the system trusted
keyring, we can only use that as the basis for working out the
trustworthiness of a new key.
With this change, a trusted keyring is a set of keys that once the
trusted-only flag is set cannot be added to except by verification through
one of the contained keys.
Further, adding a key into a trusted keyring, whilst it might grant
trustworthiness in the context of that keyring, does not automatically
grant trustworthiness in the context of a second keyring to which it could
be secondarily linked.
To accomplish this, the authentication data associated with the key source
must now be retained. For an X.509 cert, this means the contents of the
AuthorityKeyIdentifier and the signature data.
If system keyrings are disabled then restrict_link_by_builtin_trusted()
resolves to restrict_link_reject(). The integrity digital signature code
still works correctly with this as it was previously using
KEY_FLAG_TRUSTED_ONLY, which doesn't permit anything to be added if there
is no system keyring against which trust can be determined.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-04-06 16:14:26 +01:00
# include <linux/key.h>
2021-07-12 19:03:12 +02:00
enum blacklist_hash_type {
/* TBSCertificate hash */
BLACKLIST_HASH_X509_TBS = 1 ,
/* Raw data hash */
BLACKLIST_HASH_BINARY = 2 ,
} ;
2013-08-30 16:07:30 +01:00
# ifdef CONFIG_SYSTEM_TRUSTED_KEYRING
KEYS: Move the point of trust determination to __key_link()
Move the point at which a key is determined to be trustworthy to
__key_link() so that we use the contents of the keyring being linked in to
to determine whether the key being linked in is trusted or not.
What is 'trusted' then becomes a matter of what's in the keyring.
Currently, the test is done when the key is parsed, but given that at that
point we can only sensibly refer to the contents of the system trusted
keyring, we can only use that as the basis for working out the
trustworthiness of a new key.
With this change, a trusted keyring is a set of keys that once the
trusted-only flag is set cannot be added to except by verification through
one of the contained keys.
Further, adding a key into a trusted keyring, whilst it might grant
trustworthiness in the context of that keyring, does not automatically
grant trustworthiness in the context of a second keyring to which it could
be secondarily linked.
To accomplish this, the authentication data associated with the key source
must now be retained. For an X.509 cert, this means the contents of the
AuthorityKeyIdentifier and the signature data.
If system keyrings are disabled then restrict_link_by_builtin_trusted()
resolves to restrict_link_reject(). The integrity digital signature code
still works correctly with this as it was previously using
KEY_FLAG_TRUSTED_ONLY, which doesn't permit anything to be added if there
is no system keyring against which trust can be determined.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-04-06 16:14:26 +01:00
extern int restrict_link_by_builtin_trusted ( struct key * keyring ,
const struct key_type * type ,
2016-08-30 11:33:13 -07:00
const union key_payload * payload ,
struct key * restriction_key ) ;
2023-05-22 19:09:42 -04:00
int restrict_link_by_digsig_builtin ( struct key * dest_keyring ,
const struct key_type * type ,
const union key_payload * payload ,
struct key * restriction_key ) ;
2021-04-09 10:35:07 -04:00
extern __init int load_module_cert ( struct key * keyring ) ;
2013-08-30 16:07:30 +01:00
2013-08-20 14:36:27 -04:00
# else
KEYS: Move the point of trust determination to __key_link()
Move the point at which a key is determined to be trustworthy to
__key_link() so that we use the contents of the keyring being linked in to
to determine whether the key being linked in is trusted or not.
What is 'trusted' then becomes a matter of what's in the keyring.
Currently, the test is done when the key is parsed, but given that at that
point we can only sensibly refer to the contents of the system trusted
keyring, we can only use that as the basis for working out the
trustworthiness of a new key.
With this change, a trusted keyring is a set of keys that once the
trusted-only flag is set cannot be added to except by verification through
one of the contained keys.
Further, adding a key into a trusted keyring, whilst it might grant
trustworthiness in the context of that keyring, does not automatically
grant trustworthiness in the context of a second keyring to which it could
be secondarily linked.
To accomplish this, the authentication data associated with the key source
must now be retained. For an X.509 cert, this means the contents of the
AuthorityKeyIdentifier and the signature data.
If system keyrings are disabled then restrict_link_by_builtin_trusted()
resolves to restrict_link_reject(). The integrity digital signature code
still works correctly with this as it was previously using
KEY_FLAG_TRUSTED_ONLY, which doesn't permit anything to be added if there
is no system keyring against which trust can be determined.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-04-06 16:14:26 +01:00
# define restrict_link_by_builtin_trusted restrict_link_reject
2023-05-22 19:09:42 -04:00
# define restrict_link_by_digsig_builtin restrict_link_reject
2021-04-09 10:35:07 -04:00
static inline __init int load_module_cert ( struct key * keyring )
{
return 0 ;
}
2013-08-30 16:07:30 +01:00
# endif
2016-04-06 16:14:27 +01:00
# ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
extern int restrict_link_by_builtin_and_secondary_trusted (
struct key * keyring ,
const struct key_type * type ,
2016-08-30 11:33:13 -07:00
const union key_payload * payload ,
struct key * restriction_key ) ;
2023-05-22 19:09:42 -04:00
int restrict_link_by_digsig_builtin_and_secondary ( struct key * keyring ,
const struct key_type * type ,
const union key_payload * payload ,
struct key * restriction_key ) ;
2023-08-15 07:27:22 -04:00
void __init add_to_secondary_keyring ( const char * source , const void * data , size_t len ) ;
2016-04-06 16:14:27 +01:00
# else
# define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
2023-05-22 19:09:42 -04:00
# define restrict_link_by_digsig_builtin_and_secondary restrict_link_by_digsig_builtin
2023-08-15 07:27:22 -04:00
static inline void __init add_to_secondary_keyring ( const char * source , const void * data , size_t len )
{
}
2016-04-06 16:14:27 +01:00
# endif
2022-01-25 21:58:30 -05:00
# ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
2022-01-25 21:58:31 -05:00
extern int restrict_link_by_builtin_secondary_and_machine (
struct key * dest_keyring ,
const struct key_type * type ,
const union key_payload * payload ,
struct key * restrict_key ) ;
2022-01-25 21:58:30 -05:00
extern void __init set_machine_trusted_keys ( struct key * keyring ) ;
# else
2022-01-25 21:58:31 -05:00
# define restrict_link_by_builtin_secondary_and_machine restrict_link_by_builtin_trusted
2022-01-25 21:58:30 -05:00
static inline void __init set_machine_trusted_keys ( struct key * keyring )
{
}
# endif
2021-01-22 13:10:51 -05:00
extern struct pkcs7_message * pkcs7 ;
2017-04-03 16:07:24 +01:00
# ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
2021-07-12 19:03:12 +02:00
extern int mark_hash_blacklisted ( const u8 * hash , size_t hash_len ,
enum blacklist_hash_type hash_type ) ;
2017-04-03 16:07:24 +01:00
extern int is_hash_blacklisted ( const u8 * hash , size_t hash_len ,
2021-07-12 19:03:12 +02:00
enum blacklist_hash_type hash_type ) ;
2019-10-30 23:31:31 -04:00
extern int is_binary_blacklisted ( const u8 * hash , size_t hash_len ) ;
2017-04-03 16:07:24 +01:00
# else
static inline int is_hash_blacklisted ( const u8 * hash , size_t hash_len ,
2021-07-12 19:03:12 +02:00
enum blacklist_hash_type hash_type )
2017-04-03 16:07:24 +01:00
{
return 0 ;
}
2019-10-30 23:31:31 -04:00
static inline int is_binary_blacklisted ( const u8 * hash , size_t hash_len )
{
return 0 ;
}
2017-04-03 16:07:24 +01:00
# endif
2021-01-22 13:10:51 -05:00
# ifdef CONFIG_SYSTEM_REVOCATION_LIST
extern int add_key_to_revocation_list ( const char * data , size_t size ) ;
extern int is_key_on_revocation_list ( struct pkcs7_message * pkcs7 ) ;
# else
static inline int add_key_to_revocation_list ( const char * data , size_t size )
{
return 0 ;
}
static inline int is_key_on_revocation_list ( struct pkcs7_message * pkcs7 )
{
return - ENOKEY ;
}
# endif
2016-04-07 09:45:23 +01:00
# ifdef CONFIG_IMA_BLACKLIST_KEYRING
2015-12-02 17:47:55 +02:00
extern struct key * ima_blacklist_keyring ;
static inline struct key * get_ima_blacklist_keyring ( void )
{
return ima_blacklist_keyring ;
}
# else
static inline struct key * get_ima_blacklist_keyring ( void )
{
return NULL ;
}
2016-04-07 09:45:23 +01:00
# endif /* CONFIG_IMA_BLACKLIST_KEYRING */
2015-12-02 17:47:55 +02:00
2019-01-21 17:59:28 +08:00
# if defined(CONFIG_INTEGRITY_PLATFORM_KEYRING) && \
defined ( CONFIG_SYSTEM_TRUSTED_KEYRING )
extern void __init set_platform_trusted_keys ( struct key * keyring ) ;
# else
static inline void set_platform_trusted_keys ( struct key * keyring )
{
}
# endif
2015-12-02 17:47:55 +02:00
2013-08-30 16:07:30 +01:00
# endif /* _KEYS_SYSTEM_KEYRING_H */