Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 1 | /* |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 2 | * Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved. |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef EXT_H |
| 8 | #define EXT_H |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 9 | |
| 10 | #include <openssl/x509v3.h> |
Isla Mitchell | 9930501 | 2017-07-11 14:54:08 +0100 | [diff] [blame] | 11 | #include "key.h" |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 12 | |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 13 | /* Extension types supported */ |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 14 | enum ext_type_e { |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 15 | EXT_TYPE_NVCOUNTER, |
| 16 | EXT_TYPE_PKEY, |
| 17 | EXT_TYPE_HASH |
| 18 | }; |
| 19 | |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 20 | /* NV-Counter types */ |
| 21 | enum nvctr_type_e { |
| 22 | NVCTR_TYPE_TFW, |
| 23 | NVCTR_TYPE_NTFW |
| 24 | }; |
| 25 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 26 | /* |
| 27 | * This structure contains the relevant information to create the extensions |
| 28 | * to be included in the certificates. This extensions will be used to |
| 29 | * establish the chain of trust. |
| 30 | */ |
| 31 | typedef struct ext_s { |
| 32 | const char *oid; /* OID of the extension */ |
| 33 | const char *sn; /* Short name */ |
| 34 | const char *ln; /* Long description */ |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 35 | const char *opt; /* Command line option to specify data */ |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 36 | const char *help_msg; /* Help message */ |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 37 | const char *arg; /* Argument passed from command line */ |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 38 | int asn1_type; /* OpenSSL ASN1 type of the extension data. |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 39 | * Supported types are: |
| 40 | * - V_ASN1_INTEGER |
| 41 | * - V_ASN1_OCTET_STRING |
| 42 | */ |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 43 | int type; /* See ext_type_e */ |
| 44 | |
| 45 | /* Extension attributes (depends on extension type) */ |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 46 | union { |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 47 | int nvctr_type; /* See nvctr_type_e */ |
| 48 | int key; /* Index into array of registered public keys */ |
| 49 | } attr; |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 50 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 51 | int alias; /* In case OpenSSL provides an standard |
| 52 | * extension of the same type, add the new |
| 53 | * extension as an alias of this one |
| 54 | */ |
| 55 | |
| 56 | X509V3_EXT_METHOD method; /* This field may be used to define a custom |
| 57 | * function to print the contents of the |
| 58 | * extension */ |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 59 | |
| 60 | int optional; /* This field may be used optionally to exclude an image */ |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 61 | } ext_t; |
| 62 | |
| 63 | enum { |
| 64 | EXT_NON_CRIT = 0, |
| 65 | EXT_CRIT = !EXT_NON_CRIT, |
| 66 | }; |
| 67 | |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 68 | /* Exported API */ |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 69 | int ext_init(void); |
| 70 | ext_t *ext_get_by_opt(const char *opt); |
Juan Castillo | ac40293 | 2015-03-05 14:30:00 +0000 | [diff] [blame] | 71 | X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md, |
| 72 | unsigned char *buf, size_t len); |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 73 | X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value); |
| 74 | X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k); |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 75 | void ext_cleanup(void); |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 76 | |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 77 | /* Macro to register the extensions used in the CoT */ |
| 78 | #define REGISTER_EXTENSIONS(_ext) \ |
Pankaj Gupta | dd906e6 | 2020-12-09 14:02:38 +0530 | [diff] [blame] | 79 | ext_t *def_extensions = &_ext[0]; \ |
| 80 | const unsigned int num_def_extensions = sizeof(_ext)/sizeof(_ext[0]) |
| 81 | |
| 82 | /* Macro to register the platform defined extensions used in the CoT */ |
| 83 | #define PLAT_REGISTER_EXTENSIONS(_pdef_ext) \ |
| 84 | ext_t *pdef_extensions = &_pdef_ext[0]; \ |
| 85 | const unsigned int num_pdef_extensions = sizeof(_pdef_ext)/sizeof(_pdef_ext[0]) |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 86 | |
| 87 | /* Exported variables */ |
Pankaj Gupta | dd906e6 | 2020-12-09 14:02:38 +0530 | [diff] [blame] | 88 | extern ext_t *def_extensions; |
| 89 | extern const unsigned int num_def_extensions; |
| 90 | extern ext_t *pdef_extensions; |
| 91 | extern const unsigned int num_pdef_extensions; |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 92 | |
Pankaj Gupta | dd906e6 | 2020-12-09 14:02:38 +0530 | [diff] [blame] | 93 | extern ext_t *extensions; |
| 94 | extern unsigned int num_extensions; |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 95 | #endif /* EXT_H */ |