blob: 798bd1be2eaf021df8c9ed02101ef401c43cc4c6 [file] [log] [blame]
Juan Castillo11abdcd2014-10-21 11:30:42 +01001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef EXT_H_
32#define EXT_H_
33
Juan Castilloe6d30e92015-06-12 11:27:59 +010034#include "key.h"
Juan Castillo11abdcd2014-10-21 11:30:42 +010035#include <openssl/x509v3.h>
36
Juan Castilloe6d30e92015-06-12 11:27:59 +010037/* Extension types supported */
38enum {
39 EXT_TYPE_NVCOUNTER,
40 EXT_TYPE_PKEY,
41 EXT_TYPE_HASH
42};
43
Juan Castillo11abdcd2014-10-21 11:30:42 +010044/*
45 * This structure contains the relevant information to create the extensions
46 * to be included in the certificates. This extensions will be used to
47 * establish the chain of trust.
48 */
49typedef struct ext_s {
50 const char *oid; /* OID of the extension */
51 const char *sn; /* Short name */
52 const char *ln; /* Long description */
Juan Castilloe6d30e92015-06-12 11:27:59 +010053 int asn1_type; /* OpenSSL ASN1 type of the extension data.
Juan Castillo11abdcd2014-10-21 11:30:42 +010054 * Supported types are:
55 * - V_ASN1_INTEGER
56 * - V_ASN1_OCTET_STRING
57 */
Juan Castilloe6d30e92015-06-12 11:27:59 +010058 int type;
Juan Castillo1218dd52015-07-03 16:23:16 +010059 const char *opt; /* Command line option to specify data */
Juan Castilloe6d30e92015-06-12 11:27:59 +010060 /* Extension data (depends on extension type) */
61 union {
62 const char *fn; /* File with extension data */
63 int nvcounter; /* Non volatile counter */
64 int key; /* Public key */
65 } data;
66
Juan Castillo11abdcd2014-10-21 11:30:42 +010067 int alias; /* In case OpenSSL provides an standard
68 * extension of the same type, add the new
69 * extension as an alias of this one
70 */
71
72 X509V3_EXT_METHOD method; /* This field may be used to define a custom
73 * function to print the contents of the
74 * extension */
Yatharth Kochar5752b592015-08-21 15:30:55 +010075
76 int optional; /* This field may be used optionally to exclude an image */
Juan Castillo11abdcd2014-10-21 11:30:42 +010077} ext_t;
78
79enum {
80 EXT_NON_CRIT = 0,
81 EXT_CRIT = !EXT_NON_CRIT,
82};
83
Juan Castilloe6d30e92015-06-12 11:27:59 +010084/* Exported API */
Juan Castillo1218dd52015-07-03 16:23:16 +010085int ext_init(void);
86ext_t *ext_get_by_opt(const char *opt);
Juan Castilloac402932015-03-05 14:30:00 +000087X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md,
88 unsigned char *buf, size_t len);
Juan Castillo11abdcd2014-10-21 11:30:42 +010089X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value);
90X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k);
91
Juan Castilloe6d30e92015-06-12 11:27:59 +010092/* Macro to register the extensions used in the CoT */
93#define REGISTER_EXTENSIONS(_ext) \
94 ext_t *extensions = &_ext[0]; \
Sandrine Bailleuxdf8de2d2016-01-04 15:49:23 +000095 const unsigned int num_extensions = sizeof(_ext)/sizeof(_ext[0])
Juan Castilloe6d30e92015-06-12 11:27:59 +010096
97/* Exported variables */
98extern ext_t *extensions;
99extern const unsigned int num_extensions;
100
Juan Castillo11abdcd2014-10-21 11:30:42 +0100101#endif /* EXT_H_ */