Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 1 | /* |
| 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 Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 34 | #include "key.h" |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 35 | #include <openssl/x509v3.h> |
| 36 | |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 37 | /* Extension types supported */ |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 38 | enum ext_type_e { |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 39 | EXT_TYPE_NVCOUNTER, |
| 40 | EXT_TYPE_PKEY, |
| 41 | EXT_TYPE_HASH |
| 42 | }; |
| 43 | |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 44 | /* NV-Counter types */ |
| 45 | enum nvctr_type_e { |
| 46 | NVCTR_TYPE_TFW, |
| 47 | NVCTR_TYPE_NTFW |
| 48 | }; |
| 49 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 50 | /* |
| 51 | * This structure contains the relevant information to create the extensions |
| 52 | * to be included in the certificates. This extensions will be used to |
| 53 | * establish the chain of trust. |
| 54 | */ |
| 55 | typedef struct ext_s { |
| 56 | const char *oid; /* OID of the extension */ |
| 57 | const char *sn; /* Short name */ |
| 58 | const char *ln; /* Long description */ |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 59 | const char *opt; /* Command line option to specify data */ |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 60 | const char *help_msg; /* Help message */ |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 61 | const char *arg; /* Argument passed from command line */ |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 62 | int asn1_type; /* OpenSSL ASN1 type of the extension data. |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 63 | * Supported types are: |
| 64 | * - V_ASN1_INTEGER |
| 65 | * - V_ASN1_OCTET_STRING |
| 66 | */ |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 67 | int type; /* See ext_type_e */ |
| 68 | |
| 69 | /* Extension attributes (depends on extension type) */ |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 70 | union { |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 71 | int nvctr_type; /* See nvctr_type_e */ |
| 72 | int key; /* Index into array of registered public keys */ |
| 73 | } attr; |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 74 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 75 | int alias; /* In case OpenSSL provides an standard |
| 76 | * extension of the same type, add the new |
| 77 | * extension as an alias of this one |
| 78 | */ |
| 79 | |
| 80 | X509V3_EXT_METHOD method; /* This field may be used to define a custom |
| 81 | * function to print the contents of the |
| 82 | * extension */ |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 83 | |
| 84 | int optional; /* This field may be used optionally to exclude an image */ |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 85 | } ext_t; |
| 86 | |
| 87 | enum { |
| 88 | EXT_NON_CRIT = 0, |
| 89 | EXT_CRIT = !EXT_NON_CRIT, |
| 90 | }; |
| 91 | |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 92 | /* Exported API */ |
Juan Castillo | 1218dd5 | 2015-07-03 16:23:16 +0100 | [diff] [blame] | 93 | int ext_init(void); |
| 94 | ext_t *ext_get_by_opt(const char *opt); |
Juan Castillo | ac40293 | 2015-03-05 14:30:00 +0000 | [diff] [blame] | 95 | X509_EXTENSION *ext_new_hash(int nid, int crit, const EVP_MD *md, |
| 96 | unsigned char *buf, size_t len); |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 97 | X509_EXTENSION *ext_new_nvcounter(int nid, int crit, int value); |
| 98 | X509_EXTENSION *ext_new_key(int nid, int crit, EVP_PKEY *k); |
| 99 | |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 100 | /* Macro to register the extensions used in the CoT */ |
| 101 | #define REGISTER_EXTENSIONS(_ext) \ |
| 102 | ext_t *extensions = &_ext[0]; \ |
Sandrine Bailleux | df8de2d | 2016-01-04 15:49:23 +0000 | [diff] [blame] | 103 | const unsigned int num_extensions = sizeof(_ext)/sizeof(_ext[0]) |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 104 | |
| 105 | /* Exported variables */ |
| 106 | extern ext_t *extensions; |
| 107 | extern const unsigned int num_extensions; |
| 108 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 109 | #endif /* EXT_H_ */ |