cert.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef CERT_H
  7. #define CERT_H
  8. #include <openssl/ossl_typ.h>
  9. #include <openssl/x509.h>
  10. #include "ext.h"
  11. #include "key.h"
  12. #define CERT_MAX_EXT 9
  13. /*
  14. * This structure contains information related to the generation of the
  15. * certificates. All these fields must be known and specified at build time
  16. * except for the file name, which is picked up from the command line at
  17. * run time.
  18. *
  19. * One instance of this structure must be created for each of the certificates
  20. * present in the chain of trust.
  21. *
  22. * If the issuer points to this same instance, the generated certificate will
  23. * be self-signed.
  24. */
  25. typedef struct cert_s cert_t;
  26. struct cert_s {
  27. int id; /* Unique identifier */
  28. const char *opt; /* Command line option to pass filename */
  29. const char *fn; /* Filename to save the certificate */
  30. const char *cn; /* Subject CN (Company Name) */
  31. const char *help_msg; /* Help message */
  32. /* These fields must be defined statically */
  33. int key; /* Key to be signed */
  34. int issuer; /* Issuer certificate */
  35. int ext[CERT_MAX_EXT]; /* Certificate extensions */
  36. int num_ext; /* Number of extensions in the certificate */
  37. X509 *x; /* X509 certificate container */
  38. };
  39. /* Exported API */
  40. int cert_init(void);
  41. cert_t *cert_get_by_opt(const char *opt);
  42. int cert_add_ext(X509 *issuer, X509 *subject, int nid, char *value);
  43. int cert_new(
  44. int md_alg,
  45. cert_t *cert,
  46. int days,
  47. int ca,
  48. STACK_OF(X509_EXTENSION) * sk);
  49. void cert_cleanup(void);
  50. /* Macro to register the certificates used in the CoT */
  51. #define REGISTER_COT(_certs) \
  52. cert_t *def_certs = &_certs[0]; \
  53. const unsigned int num_def_certs = sizeof(_certs)/sizeof(_certs[0])
  54. /* Macro to register the platform defined certificates used in the CoT */
  55. #define PLAT_REGISTER_COT(_pdef_certs) \
  56. cert_t *pdef_certs = &_pdef_certs[0]; \
  57. const unsigned int num_pdef_certs = sizeof(_pdef_certs)/sizeof(_pdef_certs[0])
  58. /* Exported variables */
  59. extern cert_t *def_certs;
  60. extern const unsigned int num_def_certs;
  61. extern cert_t *pdef_certs;
  62. extern const unsigned int num_pdef_certs;
  63. extern cert_t *certs;
  64. extern unsigned int num_certs;
  65. #endif /* CERT_H */