system_keyring.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* System keyring containing trusted public keys.
  3. *
  4. * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells ([email protected])
  6. */
  7. #ifndef _KEYS_SYSTEM_KEYRING_H
  8. #define _KEYS_SYSTEM_KEYRING_H
  9. #include <linux/key.h>
  10. enum blacklist_hash_type {
  11. /* TBSCertificate hash */
  12. BLACKLIST_HASH_X509_TBS = 1,
  13. /* Raw data hash */
  14. BLACKLIST_HASH_BINARY = 2,
  15. };
  16. #ifdef CONFIG_SYSTEM_TRUSTED_KEYRING
  17. extern int restrict_link_by_builtin_trusted(struct key *keyring,
  18. const struct key_type *type,
  19. const union key_payload *payload,
  20. struct key *restriction_key);
  21. extern __init int load_module_cert(struct key *keyring);
  22. #else
  23. #define restrict_link_by_builtin_trusted restrict_link_reject
  24. static inline __init int load_module_cert(struct key *keyring)
  25. {
  26. return 0;
  27. }
  28. #endif
  29. #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
  30. extern int restrict_link_by_builtin_and_secondary_trusted(
  31. struct key *keyring,
  32. const struct key_type *type,
  33. const union key_payload *payload,
  34. struct key *restriction_key);
  35. #else
  36. #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
  37. #endif
  38. #ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
  39. extern int restrict_link_by_builtin_secondary_and_machine(
  40. struct key *dest_keyring,
  41. const struct key_type *type,
  42. const union key_payload *payload,
  43. struct key *restrict_key);
  44. extern void __init set_machine_trusted_keys(struct key *keyring);
  45. #else
  46. #define restrict_link_by_builtin_secondary_and_machine restrict_link_by_builtin_trusted
  47. static inline void __init set_machine_trusted_keys(struct key *keyring)
  48. {
  49. }
  50. #endif
  51. extern struct pkcs7_message *pkcs7;
  52. #ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
  53. extern int mark_hash_blacklisted(const u8 *hash, size_t hash_len,
  54. enum blacklist_hash_type hash_type);
  55. extern int is_hash_blacklisted(const u8 *hash, size_t hash_len,
  56. enum blacklist_hash_type hash_type);
  57. extern int is_binary_blacklisted(const u8 *hash, size_t hash_len);
  58. #else
  59. static inline int is_hash_blacklisted(const u8 *hash, size_t hash_len,
  60. enum blacklist_hash_type hash_type)
  61. {
  62. return 0;
  63. }
  64. static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len)
  65. {
  66. return 0;
  67. }
  68. #endif
  69. #ifdef CONFIG_SYSTEM_REVOCATION_LIST
  70. extern int add_key_to_revocation_list(const char *data, size_t size);
  71. extern int is_key_on_revocation_list(struct pkcs7_message *pkcs7);
  72. #else
  73. static inline int add_key_to_revocation_list(const char *data, size_t size)
  74. {
  75. return 0;
  76. }
  77. static inline int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
  78. {
  79. return -ENOKEY;
  80. }
  81. #endif
  82. #ifdef CONFIG_IMA_BLACKLIST_KEYRING
  83. extern struct key *ima_blacklist_keyring;
  84. static inline struct key *get_ima_blacklist_keyring(void)
  85. {
  86. return ima_blacklist_keyring;
  87. }
  88. #else
  89. static inline struct key *get_ima_blacklist_keyring(void)
  90. {
  91. return NULL;
  92. }
  93. #endif /* CONFIG_IMA_BLACKLIST_KEYRING */
  94. #if defined(CONFIG_INTEGRITY_PLATFORM_KEYRING) && \
  95. defined(CONFIG_SYSTEM_TRUSTED_KEYRING)
  96. extern void __init set_platform_trusted_keys(struct key *keyring);
  97. #else
  98. static inline void set_platform_trusted_keys(struct key *keyring)
  99. {
  100. }
  101. #endif
  102. #endif /* _KEYS_SYSTEM_KEYRING_H */