xref: /rk3399_ARM-atf/tools/cert_create/include/ext.h (revision 96103d5af671b566cf523b0a5a1bb4fe4ef9bb64)
16f971622SJuan Castillo /*
26f971622SJuan Castillo  * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
36f971622SJuan Castillo  *
46f971622SJuan Castillo  * Redistribution and use in source and binary forms, with or without
56f971622SJuan Castillo  * modification, are permitted provided that the following conditions are met:
66f971622SJuan Castillo  *
76f971622SJuan Castillo  * Redistributions of source code must retain the above copyright notice, this
86f971622SJuan Castillo  * list of conditions and the following disclaimer.
96f971622SJuan Castillo  *
106f971622SJuan Castillo  * Redistributions in binary form must reproduce the above copyright notice,
116f971622SJuan Castillo  * this list of conditions and the following disclaimer in the documentation
126f971622SJuan Castillo  * and/or other materials provided with the distribution.
136f971622SJuan Castillo  *
146f971622SJuan Castillo  * Neither the name of ARM nor the names of its contributors may be used
156f971622SJuan Castillo  * to endorse or promote products derived from this software without specific
166f971622SJuan Castillo  * prior written permission.
176f971622SJuan Castillo  *
186f971622SJuan Castillo  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
196f971622SJuan Castillo  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206f971622SJuan Castillo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
216f971622SJuan Castillo  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
226f971622SJuan Castillo  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
236f971622SJuan Castillo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
246f971622SJuan Castillo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
256f971622SJuan Castillo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
266f971622SJuan Castillo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
276f971622SJuan Castillo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
286f971622SJuan Castillo  * POSSIBILITY OF SUCH DAMAGE.
296f971622SJuan Castillo  */
306f971622SJuan Castillo 
316f971622SJuan Castillo #ifndef EXT_H_
326f971622SJuan Castillo #define EXT_H_
336f971622SJuan Castillo 
3455e291a4SJuan Castillo #include "key.h"
356f971622SJuan Castillo #include <openssl/x509v3.h>
366f971622SJuan Castillo 
3755e291a4SJuan Castillo /* Extension types supported */
38*96103d5aSJuan Castillo enum ext_type_e {
3955e291a4SJuan Castillo 	EXT_TYPE_NVCOUNTER,
4055e291a4SJuan Castillo 	EXT_TYPE_PKEY,
4155e291a4SJuan Castillo 	EXT_TYPE_HASH
4255e291a4SJuan Castillo };
4355e291a4SJuan Castillo 
44*96103d5aSJuan Castillo /* NV-Counter types */
45*96103d5aSJuan Castillo enum nvctr_type_e {
46*96103d5aSJuan Castillo 	NVCTR_TYPE_TFW,
47*96103d5aSJuan Castillo 	NVCTR_TYPE_NTFW
48*96103d5aSJuan Castillo };
49*96103d5aSJuan Castillo 
506f971622SJuan Castillo /*
516f971622SJuan Castillo  * This structure contains the relevant information to create the extensions
526f971622SJuan Castillo  * to be included in the certificates. This extensions will be used to
536f971622SJuan Castillo  * establish the chain of trust.
546f971622SJuan Castillo  */
556f971622SJuan Castillo typedef struct ext_s {
566f971622SJuan Castillo 	const char *oid;	/* OID of the extension */
576f971622SJuan Castillo 	const char *sn;		/* Short name */
586f971622SJuan Castillo 	const char *ln;		/* Long description */
59*96103d5aSJuan Castillo 	const char *opt;	/* Command line option to specify data */
60159807e2SJuan Castillo 	const char *help_msg;	/* Help message */
61*96103d5aSJuan Castillo 	const char *arg;	/* Argument passed from command line */
6255e291a4SJuan Castillo 	int asn1_type;		/* OpenSSL ASN1 type of the extension data.
636f971622SJuan Castillo 				 * Supported types are:
646f971622SJuan Castillo 				 *   - V_ASN1_INTEGER
656f971622SJuan Castillo 				 *   - V_ASN1_OCTET_STRING
666f971622SJuan Castillo 				 */
67*96103d5aSJuan Castillo 	int type;		/* See ext_type_e */
68*96103d5aSJuan Castillo 
69*96103d5aSJuan Castillo 	/* Extension attributes (depends on extension type) */
7055e291a4SJuan Castillo 	union {
71*96103d5aSJuan Castillo 		int nvctr_type;	/* See nvctr_type_e */
72*96103d5aSJuan Castillo 		int key;	/* Index into array of registered public keys */
73*96103d5aSJuan Castillo 	} attr;
7455e291a4SJuan Castillo 
756f971622SJuan Castillo 	int alias;		/* In case OpenSSL provides an standard
766f971622SJuan Castillo 				 * extension of the same type, add the new
776f971622SJuan Castillo 				 * extension as an alias of this one
786f971622SJuan Castillo 				 */
796f971622SJuan Castillo 
806f971622SJuan Castillo 	X509V3_EXT_METHOD method; /* This field may be used to define a custom
816f971622SJuan Castillo 				   * function to print the contents of the
826f971622SJuan Castillo 				   * extension */
83cebe1f23SYatharth Kochar 
84cebe1f23SYatharth Kochar 	int optional;	/* This field may be used optionally to exclude an image */
856f971622SJuan Castillo } ext_t;
866f971622SJuan Castillo 
876f971622SJuan Castillo enum {
886f971622SJuan Castillo 	EXT_NON_CRIT = 0,
896f971622SJuan Castillo 	EXT_CRIT = !EXT_NON_CRIT,
906f971622SJuan Castillo };
916f971622SJuan Castillo 
9255e291a4SJuan Castillo /* Exported API */
93ad2c1a9aSJuan Castillo int ext_init(void);
94ad2c1a9aSJuan Castillo ext_t *ext_get_by_opt(const char *opt);
95c3da66b1SJuan Castillo X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md,
96c3da66b1SJuan Castillo 		unsigned char *buf, size_t len);
976f971622SJuan Castillo X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value);
986f971622SJuan Castillo X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k);
996f971622SJuan Castillo 
10055e291a4SJuan Castillo /* Macro to register the extensions used in the CoT */
10155e291a4SJuan Castillo #define REGISTER_EXTENSIONS(_ext) \
10255e291a4SJuan Castillo 	ext_t *extensions = &_ext[0]; \
103aa856917SSandrine Bailleux 	const unsigned int num_extensions = sizeof(_ext)/sizeof(_ext[0])
10455e291a4SJuan Castillo 
10555e291a4SJuan Castillo /* Exported variables */
10655e291a4SJuan Castillo extern ext_t *extensions;
10755e291a4SJuan Castillo extern const unsigned int num_extensions;
10855e291a4SJuan Castillo 
1096f971622SJuan Castillo #endif /* EXT_H_ */
110