blob: d432e639caf2250c6c7bf8bef1cb9cae7134ffcd [file] [log] [blame]
Juan Castillo11abdcd2014-10-21 11:30:42 +01001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo11abdcd2014-10-21 11:30:42 +01005 */
6
7#ifndef EXT_H_
8#define EXT_H_
9
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,
23 NVCTR_TYPE_NTFW
24};
25
Juan Castillo11abdcd2014-10-21 11:30:42 +010026/*
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 */
31typedef struct ext_s {
32 const char *oid; /* OID of the extension */
33 const char *sn; /* Short name */
34 const char *ln; /* Long description */
Juan Castillo43529982016-01-22 11:05:24 +000035 const char *opt; /* Command line option to specify data */
Juan Castillo212f7382015-12-15 16:37:57 +000036 const char *help_msg; /* Help message */
Juan Castillo43529982016-01-22 11:05:24 +000037 const char *arg; /* Argument passed from command line */
Juan Castilloe6d30e92015-06-12 11:27:59 +010038 int asn1_type; /* OpenSSL ASN1 type of the extension data.
Juan Castillo11abdcd2014-10-21 11:30:42 +010039 * Supported types are:
40 * - V_ASN1_INTEGER
41 * - V_ASN1_OCTET_STRING
42 */
Juan Castillo43529982016-01-22 11:05:24 +000043 int type; /* See ext_type_e */
44
45 /* Extension attributes (depends on extension type) */
Juan Castilloe6d30e92015-06-12 11:27:59 +010046 union {
Juan Castillo43529982016-01-22 11:05:24 +000047 int nvctr_type; /* See nvctr_type_e */
48 int key; /* Index into array of registered public keys */
49 } attr;
Juan Castilloe6d30e92015-06-12 11:27:59 +010050
Juan Castillo11abdcd2014-10-21 11:30:42 +010051 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 Kochar5752b592015-08-21 15:30:55 +010059
60 int optional; /* This field may be used optionally to exclude an image */
Juan Castillo11abdcd2014-10-21 11:30:42 +010061} ext_t;
62
63enum {
64 EXT_NON_CRIT = 0,
65 EXT_CRIT = !EXT_NON_CRIT,
66};
67
Juan Castilloe6d30e92015-06-12 11:27:59 +010068/* Exported API */
Juan Castillo1218dd52015-07-03 16:23:16 +010069int ext_init(void);
70ext_t *ext_get_by_opt(const char *opt);
Juan Castilloac402932015-03-05 14:30:00 +000071X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md,
72 unsigned char *buf, size_t len);
Juan Castillo11abdcd2014-10-21 11:30:42 +010073X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value);
74X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k);
75
Juan Castilloe6d30e92015-06-12 11:27:59 +010076/* Macro to register the extensions used in the CoT */
77#define REGISTER_EXTENSIONS(_ext) \
78 ext_t *extensions = &_ext[0]; \
Sandrine Bailleuxdf8de2d2016-01-04 15:49:23 +000079 const unsigned int num_extensions = sizeof(_ext)/sizeof(_ext[0])
Juan Castilloe6d30e92015-06-12 11:27:59 +010080
81/* Exported variables */
82extern ext_t *extensions;
83extern const unsigned int num_extensions;
84
Juan Castillo11abdcd2014-10-21 11:30:42 +010085#endif /* EXT_H_ */