ext.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef EXT_H
  7. #define EXT_H
  8. #include <openssl/x509v3.h>
  9. #include "key.h"
  10. /* Extension types supported */
  11. enum ext_type_e {
  12. EXT_TYPE_NVCOUNTER,
  13. EXT_TYPE_PKEY,
  14. EXT_TYPE_HASH
  15. };
  16. /* NV-Counter types */
  17. enum nvctr_type_e {
  18. NVCTR_TYPE_TFW,
  19. NVCTR_TYPE_NTFW,
  20. NVCTR_TYPE_CCAFW
  21. };
  22. /*
  23. * This structure contains the relevant information to create the extensions
  24. * to be included in the certificates. This extensions will be used to
  25. * establish the chain of trust.
  26. */
  27. typedef struct ext_s {
  28. const char *oid; /* OID of the extension */
  29. const char *sn; /* Short name */
  30. const char *ln; /* Long description */
  31. const char *opt; /* Command line option to specify data */
  32. const char *help_msg; /* Help message */
  33. const char *arg; /* Argument passed from command line */
  34. int asn1_type; /* OpenSSL ASN1 type of the extension data.
  35. * Supported types are:
  36. * - V_ASN1_INTEGER
  37. * - V_ASN1_OCTET_STRING
  38. */
  39. int type; /* See ext_type_e */
  40. /* Extension attributes (depends on extension type) */
  41. union {
  42. int nvctr_type; /* See nvctr_type_e */
  43. int key; /* Index into array of registered public keys */
  44. } attr;
  45. int alias; /* In case OpenSSL provides an standard
  46. * extension of the same type, add the new
  47. * extension as an alias of this one
  48. */
  49. X509V3_EXT_METHOD method; /* This field may be used to define a custom
  50. * function to print the contents of the
  51. * extension */
  52. int optional; /* This field may be used optionally to exclude an image */
  53. } ext_t;
  54. enum {
  55. EXT_NON_CRIT = 0,
  56. EXT_CRIT = !EXT_NON_CRIT,
  57. };
  58. /* Exported API */
  59. int ext_init(void);
  60. ext_t *ext_get_by_opt(const char *opt);
  61. X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md,
  62. unsigned char *buf, size_t len);
  63. X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value);
  64. X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k);
  65. void ext_cleanup(void);
  66. /* Macro to register the extensions used in the CoT */
  67. #define REGISTER_EXTENSIONS(_ext) \
  68. ext_t *def_extensions = &_ext[0]; \
  69. const unsigned int num_def_extensions = sizeof(_ext)/sizeof(_ext[0])
  70. /* Macro to register the platform defined extensions used in the CoT */
  71. #define PLAT_REGISTER_EXTENSIONS(_pdef_ext) \
  72. ext_t *pdef_extensions = &_pdef_ext[0]; \
  73. const unsigned int num_pdef_extensions = sizeof(_pdef_ext)/sizeof(_pdef_ext[0])
  74. /* Exported variables */
  75. extern ext_t *def_extensions;
  76. extern const unsigned int num_def_extensions;
  77. extern ext_t *pdef_extensions;
  78. extern const unsigned int num_pdef_extensions;
  79. extern ext_t *extensions;
  80. extern unsigned int num_extensions;
  81. #endif /* EXT_H */