system_keyring.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 (dhowells@redhat.com)
  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. int restrict_link_by_digsig_builtin(struct key *dest_keyring,
  22. const struct key_type *type,
  23. const union key_payload *payload,
  24. struct key *restriction_key);
  25. extern __init int load_module_cert(struct key *keyring);
  26. #else
  27. #define restrict_link_by_builtin_trusted restrict_link_reject
  28. #define restrict_link_by_digsig_builtin restrict_link_reject
  29. static inline __init int load_module_cert(struct key *keyring)
  30. {
  31. return 0;
  32. }
  33. #endif
  34. #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
  35. extern int restrict_link_by_builtin_and_secondary_trusted(
  36. struct key *keyring,
  37. const struct key_type *type,
  38. const union key_payload *payload,
  39. struct key *restriction_key);
  40. int restrict_link_by_digsig_builtin_and_secondary(struct key *keyring,
  41. const struct key_type *type,
  42. const union key_payload *payload,
  43. struct key *restriction_key);
  44. void __init add_to_secondary_keyring(const char *source, const void *data, size_t len);
  45. #else
  46. #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
  47. #define restrict_link_by_digsig_builtin_and_secondary restrict_link_by_digsig_builtin
  48. static inline void __init add_to_secondary_keyring(const char *source, const void *data, size_t len)
  49. {
  50. }
  51. #endif
  52. #ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
  53. extern int restrict_link_by_builtin_secondary_and_machine(
  54. struct key *dest_keyring,
  55. const struct key_type *type,
  56. const union key_payload *payload,
  57. struct key *restrict_key);
  58. extern void __init set_machine_trusted_keys(struct key *keyring);
  59. #else
  60. #define restrict_link_by_builtin_secondary_and_machine restrict_link_by_builtin_trusted
  61. static inline void __init set_machine_trusted_keys(struct key *keyring)
  62. {
  63. }
  64. #endif
  65. #ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
  66. extern int mark_hash_blacklisted(const u8 *hash, size_t hash_len,
  67. enum blacklist_hash_type hash_type);
  68. extern int is_hash_blacklisted(const u8 *hash, size_t hash_len,
  69. enum blacklist_hash_type hash_type);
  70. extern int is_binary_blacklisted(const u8 *hash, size_t hash_len);
  71. #else
  72. static inline int is_hash_blacklisted(const u8 *hash, size_t hash_len,
  73. enum blacklist_hash_type hash_type)
  74. {
  75. return 0;
  76. }
  77. static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len)
  78. {
  79. return 0;
  80. }
  81. #endif
  82. struct pkcs7_message;
  83. #ifdef CONFIG_SYSTEM_REVOCATION_LIST
  84. extern int add_key_to_revocation_list(const char *data, size_t size);
  85. extern int is_key_on_revocation_list(struct pkcs7_message *pkcs7);
  86. #else
  87. static inline int add_key_to_revocation_list(const char *data, size_t size)
  88. {
  89. return 0;
  90. }
  91. static inline int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
  92. {
  93. return -ENOKEY;
  94. }
  95. #endif
  96. #ifdef CONFIG_IMA_BLACKLIST_KEYRING
  97. extern struct key *ima_blacklist_keyring;
  98. static inline struct key *get_ima_blacklist_keyring(void)
  99. {
  100. return ima_blacklist_keyring;
  101. }
  102. #else
  103. static inline struct key *get_ima_blacklist_keyring(void)
  104. {
  105. return NULL;
  106. }
  107. #endif /* CONFIG_IMA_BLACKLIST_KEYRING */
  108. #if defined(CONFIG_INTEGRITY_PLATFORM_KEYRING) && \
  109. defined(CONFIG_SYSTEM_TRUSTED_KEYRING)
  110. extern void __init set_platform_trusted_keys(struct key *keyring);
  111. #else
  112. static inline void set_platform_trusted_keys(struct key *keyring)
  113. {
  114. }
  115. #endif
  116. #endif /* _KEYS_SYSTEM_KEYRING_H */