blob: 1d55486fd25f8ae6f953f9291a3276a9d207a57c [file] [log] [blame]
Juan Castillo11abdcd2014-10-21 11:30:42 +01001/*
laurenw-arm9b4f9d52023-05-02 14:28:38 -05002 * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
Juan Castillo11abdcd2014-10-21 11:30:42 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo11abdcd2014-10-21 11:30:42 +01005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef EXT_H
8#define EXT_H
Juan Castillo11abdcd2014-10-21 11:30:42 +01009
10#include <openssl/x509v3.h>
Isla Mitchell99305012017-07-11 14:54:08 +010011#include "key.h"
Juan Castillo11abdcd2014-10-21 11:30:42 +010012
Juan Castilloe6d30e92015-06-12 11:27:59 +010013/* Extension types supported */
Juan Castillo43529982016-01-22 11:05:24 +000014enum ext_type_e {
Juan Castilloe6d30e92015-06-12 11:27:59 +010015 EXT_TYPE_NVCOUNTER,
16 EXT_TYPE_PKEY,
17 EXT_TYPE_HASH
18};
19
Juan Castillo43529982016-01-22 11:05:24 +000020/* NV-Counter types */
21enum nvctr_type_e {
22 NVCTR_TYPE_TFW,
laurenw-arm9b4f9d52023-05-02 14:28:38 -050023 NVCTR_TYPE_NTFW,
24 NVCTR_TYPE_CCAFW
Juan Castillo43529982016-01-22 11:05:24 +000025};
26
Juan Castillo11abdcd2014-10-21 11:30:42 +010027/*
28 * This structure contains the relevant information to create the extensions
29 * to be included in the certificates. This extensions will be used to
30 * establish the chain of trust.
31 */
32typedef struct ext_s {
33 const char *oid; /* OID of the extension */
34 const char *sn; /* Short name */
35 const char *ln; /* Long description */
Juan Castillo43529982016-01-22 11:05:24 +000036 const char *opt; /* Command line option to specify data */
Juan Castillo212f7382015-12-15 16:37:57 +000037 const char *help_msg; /* Help message */
Juan Castillo43529982016-01-22 11:05:24 +000038 const char *arg; /* Argument passed from command line */
Juan Castilloe6d30e92015-06-12 11:27:59 +010039 int asn1_type; /* OpenSSL ASN1 type of the extension data.
Juan Castillo11abdcd2014-10-21 11:30:42 +010040 * Supported types are:
41 * - V_ASN1_INTEGER
42 * - V_ASN1_OCTET_STRING
43 */
Juan Castillo43529982016-01-22 11:05:24 +000044 int type; /* See ext_type_e */
45
46 /* Extension attributes (depends on extension type) */
Juan Castilloe6d30e92015-06-12 11:27:59 +010047 union {
Juan Castillo43529982016-01-22 11:05:24 +000048 int nvctr_type; /* See nvctr_type_e */
49 int key; /* Index into array of registered public keys */
50 } attr;
Juan Castilloe6d30e92015-06-12 11:27:59 +010051
Juan Castillo11abdcd2014-10-21 11:30:42 +010052 int alias; /* In case OpenSSL provides an standard
53 * extension of the same type, add the new
54 * extension as an alias of this one
55 */
56
57 X509V3_EXT_METHOD method; /* This field may be used to define a custom
58 * function to print the contents of the
59 * extension */
Yatharth Kochar5752b592015-08-21 15:30:55 +010060
61 int optional; /* This field may be used optionally to exclude an image */
Juan Castillo11abdcd2014-10-21 11:30:42 +010062} ext_t;
63
64enum {
65 EXT_NON_CRIT = 0,
66 EXT_CRIT = !EXT_NON_CRIT,
67};
68
Juan Castilloe6d30e92015-06-12 11:27:59 +010069/* Exported API */
Juan Castillo1218dd52015-07-03 16:23:16 +010070int ext_init(void);
71ext_t *ext_get_by_opt(const char *opt);
Juan Castilloac402932015-03-05 14:30:00 +000072X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md,
73 unsigned char *buf, size_t len);
Juan Castillo11abdcd2014-10-21 11:30:42 +010074X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value);
75X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k);
Juan Pablo Conde3539c742022-10-25 19:41:02 -040076void ext_cleanup(void);
Juan Castillo11abdcd2014-10-21 11:30:42 +010077
Juan Castilloe6d30e92015-06-12 11:27:59 +010078/* Macro to register the extensions used in the CoT */
79#define REGISTER_EXTENSIONS(_ext) \
Pankaj Guptadd906e62020-12-09 14:02:38 +053080 ext_t *def_extensions = &_ext[0]; \
81 const unsigned int num_def_extensions = sizeof(_ext)/sizeof(_ext[0])
82
83/* Macro to register the platform defined extensions used in the CoT */
84#define PLAT_REGISTER_EXTENSIONS(_pdef_ext) \
85 ext_t *pdef_extensions = &_pdef_ext[0]; \
86 const unsigned int num_pdef_extensions = sizeof(_pdef_ext)/sizeof(_pdef_ext[0])
Juan Castilloe6d30e92015-06-12 11:27:59 +010087
88/* Exported variables */
Pankaj Guptadd906e62020-12-09 14:02:38 +053089extern ext_t *def_extensions;
90extern const unsigned int num_def_extensions;
91extern ext_t *pdef_extensions;
92extern const unsigned int num_pdef_extensions;
Juan Castilloe6d30e92015-06-12 11:27:59 +010093
Pankaj Guptadd906e62020-12-09 14:02:38 +053094extern ext_t *extensions;
95extern unsigned int num_extensions;
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000096#endif /* EXT_H */