blob: d0038a2bd857146f7c254bf8b6ed0b0bf577107e [file] [log] [blame]
Juan Castillo11abdcd2014-10-21 11:30:42 +01001/*
Soby Mathew2ffb4732017-11-07 16:50:31 +00002 * Copyright (c) 2015-2018, 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
7#include <stdio.h>
8#include <string.h>
9#include <openssl/err.h>
10#include <openssl/x509v3.h>
Masahiro Yamadaa27c1662017-05-22 12:11:24 +090011
12#if USE_TBBR_DEFS
13#include <tbbr_oid.h>
14#else
15#include <platform_oid.h>
16#endif
17
Juan Castillo11abdcd2014-10-21 11:30:42 +010018#include "ext.h"
Juan Castilloe6d30e92015-06-12 11:27:59 +010019#include "tbbr/tbb_ext.h"
20#include "tbbr/tbb_key.h"
Juan Castillo11abdcd2014-10-21 11:30:42 +010021
Juan Castilloe6d30e92015-06-12 11:27:59 +010022/* TODO: get these values from the command line */
23#define TRUSTED_WORLD_NVCTR_VALUE 0
24#define NORMAL_WORLD_NVCTR_VALUE 0
25
26static ext_t tbb_ext[] = {
Juan Castillobe801202015-12-03 10:19:21 +000027 [TRUSTED_FW_NVCOUNTER_EXT] = {
28 .oid = TRUSTED_FW_NVCOUNTER_OID,
Juan Castillo43529982016-01-22 11:05:24 +000029 .opt = "tfw-nvctr",
30 .help_msg = "Trusted Firmware Non-Volatile counter value",
Juan Castilloe6d30e92015-06-12 11:27:59 +010031 .sn = "TrustedWorldNVCounter",
32 .ln = "Trusted World Non-Volatile counter",
33 .asn1_type = V_ASN1_INTEGER,
34 .type = EXT_TYPE_NVCOUNTER,
Juan Castillo43529982016-01-22 11:05:24 +000035 .attr.nvctr_type = NVCTR_TYPE_TFW
Juan Castillo11abdcd2014-10-21 11:30:42 +010036 },
Juan Castillobe801202015-12-03 10:19:21 +000037 [NON_TRUSTED_FW_NVCOUNTER_EXT] = {
38 .oid = NON_TRUSTED_FW_NVCOUNTER_OID,
Juan Castillo43529982016-01-22 11:05:24 +000039 .opt = "ntfw-nvctr",
40 .help_msg = "Non-Trusted Firmware Non-Volatile counter value",
Juan Castilloe6d30e92015-06-12 11:27:59 +010041 .sn = "NormalWorldNVCounter",
Juan Castillo43529982016-01-22 11:05:24 +000042 .ln = "Non-Trusted Firmware Non-Volatile counter",
Juan Castilloe6d30e92015-06-12 11:27:59 +010043 .asn1_type = V_ASN1_INTEGER,
44 .type = EXT_TYPE_NVCOUNTER,
Juan Castillo43529982016-01-22 11:05:24 +000045 .attr.nvctr_type = NVCTR_TYPE_NTFW
Juan Castillo11abdcd2014-10-21 11:30:42 +010046 },
Juan Castillobe801202015-12-03 10:19:21 +000047 [TRUSTED_BOOT_FW_HASH_EXT] = {
48 .oid = TRUSTED_BOOT_FW_HASH_OID,
49 .opt = "tb-fw",
Juan Castillo212f7382015-12-15 16:37:57 +000050 .help_msg = "Trusted Boot Firmware image file",
Juan Castillo11abdcd2014-10-21 11:30:42 +010051 .sn = "TrustedBootFirmwareHash",
Juan Castillobe801202015-12-03 10:19:21 +000052 .ln = "Trusted Boot Firmware hash (SHA256)",
Juan Castilloe6d30e92015-06-12 11:27:59 +010053 .asn1_type = V_ASN1_OCTET_STRING,
54 .type = EXT_TYPE_HASH
Juan Castillo11abdcd2014-10-21 11:30:42 +010055 },
Soby Mathew2ffb4732017-11-07 16:50:31 +000056 [TRUSTED_BOOT_FW_CONFIG_HASH_EXT] = {
57 .oid = TRUSTED_BOOT_FW_CONFIG_HASH_OID,
58 .opt = "tb-fw-config",
59 .help_msg = "Trusted Boot Firmware Config file",
60 .sn = "TrustedBootFirmwareConfigHash",
61 .ln = "Trusted Boot Firmware Config hash",
62 .asn1_type = V_ASN1_OCTET_STRING,
63 .type = EXT_TYPE_HASH,
64 .optional = 1
65 },
66 [HW_CONFIG_HASH_EXT] = {
67 .oid = HW_CONFIG_HASH_OID,
68 .opt = "hw-config",
69 .help_msg = "HW Config file",
70 .sn = "HWConfigHash",
71 .ln = "HW Config hash",
72 .asn1_type = V_ASN1_OCTET_STRING,
73 .type = EXT_TYPE_HASH,
74 .optional = 1
75 },
Juan Castillobe801202015-12-03 10:19:21 +000076 [TRUSTED_WORLD_PK_EXT] = {
77 .oid = TRUSTED_WORLD_PK_OID,
Juan Castillo11abdcd2014-10-21 11:30:42 +010078 .sn = "TrustedWorldPublicKey",
79 .ln = "Trusted World Public Key",
Juan Castilloe6d30e92015-06-12 11:27:59 +010080 .asn1_type = V_ASN1_OCTET_STRING,
81 .type = EXT_TYPE_PKEY,
Juan Castillo43529982016-01-22 11:05:24 +000082 .attr.key = TRUSTED_WORLD_KEY
Juan Castillo11abdcd2014-10-21 11:30:42 +010083 },
Juan Castillobe801202015-12-03 10:19:21 +000084 [NON_TRUSTED_WORLD_PK_EXT] = {
85 .oid = NON_TRUSTED_WORLD_PK_OID,
Juan Castillo11abdcd2014-10-21 11:30:42 +010086 .sn = "NonTrustedWorldPublicKey",
87 .ln = "Non-Trusted World Public Key",
Juan Castilloe6d30e92015-06-12 11:27:59 +010088 .asn1_type = V_ASN1_OCTET_STRING,
89 .type = EXT_TYPE_PKEY,
Juan Castillo43529982016-01-22 11:05:24 +000090 .attr.key = NON_TRUSTED_WORLD_KEY
Juan Castillo11abdcd2014-10-21 11:30:42 +010091 },
Juan Castillobe801202015-12-03 10:19:21 +000092 [SCP_FW_CONTENT_CERT_PK_EXT] = {
93 .oid = SCP_FW_CONTENT_CERT_PK_OID,
Juan Castillo11abdcd2014-10-21 11:30:42 +010094 .sn = "SCPFirmwareContentCertPK",
95 .ln = "SCP Firmware content certificate public key",
Juan Castilloe6d30e92015-06-12 11:27:59 +010096 .asn1_type = V_ASN1_OCTET_STRING,
97 .type = EXT_TYPE_PKEY,
Juan Castillo43529982016-01-22 11:05:24 +000098 .attr.key = SCP_FW_CONTENT_CERT_KEY
Juan Castillo11abdcd2014-10-21 11:30:42 +010099 },
Juan Castillobe801202015-12-03 10:19:21 +0000100 [SCP_FW_HASH_EXT] = {
101 .oid = SCP_FW_HASH_OID,
102 .opt = "scp-fw",
Juan Castillo212f7382015-12-15 16:37:57 +0000103 .help_msg = "SCP Firmware image file",
Juan Castillo11abdcd2014-10-21 11:30:42 +0100104 .sn = "SCPFirmwareHash",
Juan Castillobe801202015-12-03 10:19:21 +0000105 .ln = "SCP Firmware hash (SHA256)",
Juan Castilloe6d30e92015-06-12 11:27:59 +0100106 .asn1_type = V_ASN1_OCTET_STRING,
107 .type = EXT_TYPE_HASH
Juan Castillo11abdcd2014-10-21 11:30:42 +0100108 },
Juan Castillobe801202015-12-03 10:19:21 +0000109 [SOC_FW_CONTENT_CERT_PK_EXT] = {
110 .oid = SOC_FW_CONTENT_CERT_PK_OID,
Juan Castilloe6d30e92015-06-12 11:27:59 +0100111 .sn = "SoCFirmwareContentCertPK",
112 .ln = "SoC Firmware content certificate public key",
113 .asn1_type = V_ASN1_OCTET_STRING,
114 .type = EXT_TYPE_PKEY,
Juan Castillo43529982016-01-22 11:05:24 +0000115 .attr.key = SOC_FW_CONTENT_CERT_KEY
Juan Castilloe6d30e92015-06-12 11:27:59 +0100116 },
Juan Castillobe801202015-12-03 10:19:21 +0000117 [SOC_AP_FW_HASH_EXT] = {
118 .oid = SOC_AP_FW_HASH_OID,
119 .opt = "soc-fw",
Juan Castillo212f7382015-12-15 16:37:57 +0000120 .help_msg = "SoC AP Firmware image file",
Juan Castilloe6d30e92015-06-12 11:27:59 +0100121 .sn = "SoCAPFirmwareHash",
Juan Castillobe801202015-12-03 10:19:21 +0000122 .ln = "SoC AP Firmware hash (SHA256)",
Juan Castilloe6d30e92015-06-12 11:27:59 +0100123 .asn1_type = V_ASN1_OCTET_STRING,
124 .type = EXT_TYPE_HASH
125 },
Soby Mathew2bb78d32018-03-29 14:29:55 +0100126 [SOC_FW_CONFIG_HASH_EXT] = {
127 .oid = SOC_FW_CONFIG_HASH_OID,
128 .opt = "soc-fw-config",
129 .help_msg = "SoC Firmware Config file",
130 .sn = "SocFirmwareConfigHash",
131 .ln = "SoC Firmware Config hash",
132 .asn1_type = V_ASN1_OCTET_STRING,
133 .type = EXT_TYPE_HASH,
134 .optional = 1
135 },
Juan Castillobe801202015-12-03 10:19:21 +0000136 [TRUSTED_OS_FW_CONTENT_CERT_PK_EXT] = {
137 .oid = TRUSTED_OS_FW_CONTENT_CERT_PK_OID,
Juan Castillo11abdcd2014-10-21 11:30:42 +0100138 .sn = "TrustedOSFirmwareContentCertPK",
139 .ln = "Trusted OS Firmware content certificate public key",
Juan Castilloe6d30e92015-06-12 11:27:59 +0100140 .asn1_type = V_ASN1_OCTET_STRING,
141 .type = EXT_TYPE_PKEY,
Juan Castillo43529982016-01-22 11:05:24 +0000142 .attr.key = TRUSTED_OS_FW_CONTENT_CERT_KEY
Juan Castillo11abdcd2014-10-21 11:30:42 +0100143 },
Juan Castillobe801202015-12-03 10:19:21 +0000144 [TRUSTED_OS_FW_HASH_EXT] = {
145 .oid = TRUSTED_OS_FW_HASH_OID,
146 .opt = "tos-fw",
Juan Castillo212f7382015-12-15 16:37:57 +0000147 .help_msg = "Trusted OS image file",
Juan Castillo11abdcd2014-10-21 11:30:42 +0100148 .sn = "TrustedOSHash",
Juan Castillobe801202015-12-03 10:19:21 +0000149 .ln = "Trusted OS hash (SHA256)",
Juan Castilloe6d30e92015-06-12 11:27:59 +0100150 .asn1_type = V_ASN1_OCTET_STRING,
151 .type = EXT_TYPE_HASH
Juan Castillo11abdcd2014-10-21 11:30:42 +0100152 },
Summer Qin80726782017-04-20 16:28:39 +0100153 [TRUSTED_OS_FW_EXTRA1_HASH_EXT] = {
154 .oid = TRUSTED_OS_FW_EXTRA1_HASH_OID,
155 .opt = "tos-fw-extra1",
156 .help_msg = "Trusted OS Extra1 image file",
157 .sn = "TrustedOSExtra1Hash",
158 .ln = "Trusted OS Extra1 hash (SHA256)",
159 .asn1_type = V_ASN1_OCTET_STRING,
160 .type = EXT_TYPE_HASH,
161 .optional = 1
162 },
163 [TRUSTED_OS_FW_EXTRA2_HASH_EXT] = {
164 .oid = TRUSTED_OS_FW_EXTRA2_HASH_OID,
165 .opt = "tos-fw-extra2",
166 .help_msg = "Trusted OS Extra2 image file",
167 .sn = "TrustedOSExtra2Hash",
168 .ln = "Trusted OS Extra2 hash (SHA256)",
169 .asn1_type = V_ASN1_OCTET_STRING,
170 .type = EXT_TYPE_HASH,
171 .optional = 1
172 },
Soby Mathew2bb78d32018-03-29 14:29:55 +0100173 [TRUSTED_OS_FW_CONFIG_HASH_EXT] = {
174 .oid = TRUSTED_OS_FW_CONFIG_HASH_OID,
175 .opt = "tos-fw-config",
176 .help_msg = "Trusted OS Firmware Config file",
177 .sn = "TrustedOSFirmwareConfigHash",
178 .ln = "Trusted OS Firmware Config hash",
179 .asn1_type = V_ASN1_OCTET_STRING,
180 .type = EXT_TYPE_HASH,
181 .optional = 1
182 },
Juan Castillobe801202015-12-03 10:19:21 +0000183 [NON_TRUSTED_FW_CONTENT_CERT_PK_EXT] = {
184 .oid = NON_TRUSTED_FW_CONTENT_CERT_PK_OID,
Juan Castillo11abdcd2014-10-21 11:30:42 +0100185 .sn = "NonTrustedFirmwareContentCertPK",
186 .ln = "Non-Trusted Firmware content certificate public key",
Juan Castilloe6d30e92015-06-12 11:27:59 +0100187 .asn1_type = V_ASN1_OCTET_STRING,
188 .type = EXT_TYPE_PKEY,
Juan Castillo43529982016-01-22 11:05:24 +0000189 .attr.key = NON_TRUSTED_FW_CONTENT_CERT_KEY
Juan Castillo11abdcd2014-10-21 11:30:42 +0100190 },
Juan Castillobe801202015-12-03 10:19:21 +0000191 [NON_TRUSTED_WORLD_BOOTLOADER_HASH_EXT] = {
192 .oid = NON_TRUSTED_WORLD_BOOTLOADER_HASH_OID,
193 .opt = "nt-fw",
Juan Castillo212f7382015-12-15 16:37:57 +0000194 .help_msg = "Non-Trusted World Bootloader image file",
Juan Castillo11abdcd2014-10-21 11:30:42 +0100195 .sn = "NonTrustedWorldBootloaderHash",
Juan Castillobe801202015-12-03 10:19:21 +0000196 .ln = "Non-Trusted World hash (SHA256)",
Juan Castilloe6d30e92015-06-12 11:27:59 +0100197 .asn1_type = V_ASN1_OCTET_STRING,
198 .type = EXT_TYPE_HASH
Yatharth Kochar5752b592015-08-21 15:30:55 +0100199 },
Soby Mathew2bb78d32018-03-29 14:29:55 +0100200 [NON_TRUSTED_FW_CONFIG_HASH_EXT] = {
201 .oid = NON_TRUSTED_FW_CONFIG_HASH_OID,
202 .opt = "nt-fw-config",
203 .help_msg = "Non Trusted OS Firmware Config file",
204 .sn = "NonTrustedOSFirmwareConfigHash",
205 .ln = "Non-Trusted OS Firmware Config hash",
206 .asn1_type = V_ASN1_OCTET_STRING,
207 .type = EXT_TYPE_HASH,
208 .optional = 1
209 },
Juan Castillobe801202015-12-03 10:19:21 +0000210 [SCP_FWU_CFG_HASH_EXT] = {
211 .oid = SCP_FWU_CFG_HASH_OID,
212 .opt = "scp-fwu-cfg",
Juan Castillo212f7382015-12-15 16:37:57 +0000213 .help_msg = "SCP Firmware Update Config image file",
Yatharth Kochar5752b592015-08-21 15:30:55 +0100214 .sn = "SCPFWUpdateConfig",
Juan Castillobe801202015-12-03 10:19:21 +0000215 .ln = "SCP Firmware Update Config hash (SHA256)",
Yatharth Kochar5752b592015-08-21 15:30:55 +0100216 .asn1_type = V_ASN1_OCTET_STRING,
217 .type = EXT_TYPE_HASH,
218 .optional = 1
219 },
Juan Castillobe801202015-12-03 10:19:21 +0000220 [AP_FWU_CFG_HASH_EXT] = {
221 .oid = AP_FWU_CFG_HASH_OID,
222 .opt = "ap-fwu-cfg",
Juan Castillo212f7382015-12-15 16:37:57 +0000223 .help_msg = "AP Firmware Update Config image file",
Yatharth Kochar5752b592015-08-21 15:30:55 +0100224 .sn = "APFWUpdateConfig",
Juan Castillobe801202015-12-03 10:19:21 +0000225 .ln = "AP Firmware Update Config hash (SHA256)",
Yatharth Kochar5752b592015-08-21 15:30:55 +0100226 .asn1_type = V_ASN1_OCTET_STRING,
227 .type = EXT_TYPE_HASH,
228 .optional = 1
229 },
Juan Castillobe801202015-12-03 10:19:21 +0000230 [FWU_HASH_EXT] = {
231 .oid = FWU_HASH_OID,
232 .opt = "fwu",
Juan Castillo212f7382015-12-15 16:37:57 +0000233 .help_msg = "Firmware Updater image file",
Yatharth Kochar5752b592015-08-21 15:30:55 +0100234 .sn = "FWUpdaterHash",
Juan Castillobe801202015-12-03 10:19:21 +0000235 .ln = "Firmware Updater hash (SHA256)",
Yatharth Kochar5752b592015-08-21 15:30:55 +0100236 .asn1_type = V_ASN1_OCTET_STRING,
237 .type = EXT_TYPE_HASH,
238 .optional = 1
Juan Castilloe6d30e92015-06-12 11:27:59 +0100239 }
Juan Castillo11abdcd2014-10-21 11:30:42 +0100240};
Juan Castilloe6d30e92015-06-12 11:27:59 +0100241
242REGISTER_EXTENSIONS(tbb_ext);