Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 1 | /* |
Masahiro Yamada | a27c166 | 2017-05-22 12:11:24 +0900 | [diff] [blame] | 2 | * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <string.h> |
| 9 | #include <openssl/err.h> |
| 10 | #include <openssl/x509v3.h> |
Masahiro Yamada | a27c166 | 2017-05-22 12:11:24 +0900 | [diff] [blame] | 11 | |
| 12 | #if USE_TBBR_DEFS |
| 13 | #include <tbbr_oid.h> |
| 14 | #else |
| 15 | #include <platform_oid.h> |
| 16 | #endif |
| 17 | |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 18 | #include "ext.h" |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 19 | #include "tbbr/tbb_ext.h" |
| 20 | #include "tbbr/tbb_key.h" |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 21 | |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 22 | /* TODO: get these values from the command line */ |
| 23 | #define TRUSTED_WORLD_NVCTR_VALUE 0 |
| 24 | #define NORMAL_WORLD_NVCTR_VALUE 0 |
| 25 | |
| 26 | static ext_t tbb_ext[] = { |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 27 | [TRUSTED_FW_NVCOUNTER_EXT] = { |
| 28 | .oid = TRUSTED_FW_NVCOUNTER_OID, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 29 | .opt = "tfw-nvctr", |
| 30 | .help_msg = "Trusted Firmware Non-Volatile counter value", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 31 | .sn = "TrustedWorldNVCounter", |
| 32 | .ln = "Trusted World Non-Volatile counter", |
| 33 | .asn1_type = V_ASN1_INTEGER, |
| 34 | .type = EXT_TYPE_NVCOUNTER, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 35 | .attr.nvctr_type = NVCTR_TYPE_TFW |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 36 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 37 | [NON_TRUSTED_FW_NVCOUNTER_EXT] = { |
| 38 | .oid = NON_TRUSTED_FW_NVCOUNTER_OID, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 39 | .opt = "ntfw-nvctr", |
| 40 | .help_msg = "Non-Trusted Firmware Non-Volatile counter value", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 41 | .sn = "NormalWorldNVCounter", |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 42 | .ln = "Non-Trusted Firmware Non-Volatile counter", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 43 | .asn1_type = V_ASN1_INTEGER, |
| 44 | .type = EXT_TYPE_NVCOUNTER, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 45 | .attr.nvctr_type = NVCTR_TYPE_NTFW |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 46 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 47 | [TRUSTED_BOOT_FW_HASH_EXT] = { |
| 48 | .oid = TRUSTED_BOOT_FW_HASH_OID, |
| 49 | .opt = "tb-fw", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 50 | .help_msg = "Trusted Boot Firmware image file", |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 51 | .sn = "TrustedBootFirmwareHash", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 52 | .ln = "Trusted Boot Firmware hash (SHA256)", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 53 | .asn1_type = V_ASN1_OCTET_STRING, |
| 54 | .type = EXT_TYPE_HASH |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 55 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 56 | [TRUSTED_WORLD_PK_EXT] = { |
| 57 | .oid = TRUSTED_WORLD_PK_OID, |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 58 | .sn = "TrustedWorldPublicKey", |
| 59 | .ln = "Trusted World Public Key", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 60 | .asn1_type = V_ASN1_OCTET_STRING, |
| 61 | .type = EXT_TYPE_PKEY, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 62 | .attr.key = TRUSTED_WORLD_KEY |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 63 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 64 | [NON_TRUSTED_WORLD_PK_EXT] = { |
| 65 | .oid = NON_TRUSTED_WORLD_PK_OID, |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 66 | .sn = "NonTrustedWorldPublicKey", |
| 67 | .ln = "Non-Trusted World Public Key", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 68 | .asn1_type = V_ASN1_OCTET_STRING, |
| 69 | .type = EXT_TYPE_PKEY, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 70 | .attr.key = NON_TRUSTED_WORLD_KEY |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 71 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 72 | [SCP_FW_CONTENT_CERT_PK_EXT] = { |
| 73 | .oid = SCP_FW_CONTENT_CERT_PK_OID, |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 74 | .sn = "SCPFirmwareContentCertPK", |
| 75 | .ln = "SCP Firmware content certificate public key", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 76 | .asn1_type = V_ASN1_OCTET_STRING, |
| 77 | .type = EXT_TYPE_PKEY, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 78 | .attr.key = SCP_FW_CONTENT_CERT_KEY |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 79 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 80 | [SCP_FW_HASH_EXT] = { |
| 81 | .oid = SCP_FW_HASH_OID, |
| 82 | .opt = "scp-fw", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 83 | .help_msg = "SCP Firmware image file", |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 84 | .sn = "SCPFirmwareHash", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 85 | .ln = "SCP Firmware hash (SHA256)", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 86 | .asn1_type = V_ASN1_OCTET_STRING, |
| 87 | .type = EXT_TYPE_HASH |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 88 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 89 | [SOC_FW_CONTENT_CERT_PK_EXT] = { |
| 90 | .oid = SOC_FW_CONTENT_CERT_PK_OID, |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 91 | .sn = "SoCFirmwareContentCertPK", |
| 92 | .ln = "SoC Firmware content certificate public key", |
| 93 | .asn1_type = V_ASN1_OCTET_STRING, |
| 94 | .type = EXT_TYPE_PKEY, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 95 | .attr.key = SOC_FW_CONTENT_CERT_KEY |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 96 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 97 | [SOC_AP_FW_HASH_EXT] = { |
| 98 | .oid = SOC_AP_FW_HASH_OID, |
| 99 | .opt = "soc-fw", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 100 | .help_msg = "SoC AP Firmware image file", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 101 | .sn = "SoCAPFirmwareHash", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 102 | .ln = "SoC AP Firmware hash (SHA256)", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 103 | .asn1_type = V_ASN1_OCTET_STRING, |
| 104 | .type = EXT_TYPE_HASH |
| 105 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 106 | [TRUSTED_OS_FW_CONTENT_CERT_PK_EXT] = { |
| 107 | .oid = TRUSTED_OS_FW_CONTENT_CERT_PK_OID, |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 108 | .sn = "TrustedOSFirmwareContentCertPK", |
| 109 | .ln = "Trusted OS Firmware content certificate public key", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 110 | .asn1_type = V_ASN1_OCTET_STRING, |
| 111 | .type = EXT_TYPE_PKEY, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 112 | .attr.key = TRUSTED_OS_FW_CONTENT_CERT_KEY |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 113 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 114 | [TRUSTED_OS_FW_HASH_EXT] = { |
| 115 | .oid = TRUSTED_OS_FW_HASH_OID, |
| 116 | .opt = "tos-fw", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 117 | .help_msg = "Trusted OS image file", |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 118 | .sn = "TrustedOSHash", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 119 | .ln = "Trusted OS hash (SHA256)", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 120 | .asn1_type = V_ASN1_OCTET_STRING, |
| 121 | .type = EXT_TYPE_HASH |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 122 | }, |
Summer Qin | 8072678 | 2017-04-20 16:28:39 +0100 | [diff] [blame] | 123 | [TRUSTED_OS_FW_EXTRA1_HASH_EXT] = { |
| 124 | .oid = TRUSTED_OS_FW_EXTRA1_HASH_OID, |
| 125 | .opt = "tos-fw-extra1", |
| 126 | .help_msg = "Trusted OS Extra1 image file", |
| 127 | .sn = "TrustedOSExtra1Hash", |
| 128 | .ln = "Trusted OS Extra1 hash (SHA256)", |
| 129 | .asn1_type = V_ASN1_OCTET_STRING, |
| 130 | .type = EXT_TYPE_HASH, |
| 131 | .optional = 1 |
| 132 | }, |
| 133 | [TRUSTED_OS_FW_EXTRA2_HASH_EXT] = { |
| 134 | .oid = TRUSTED_OS_FW_EXTRA2_HASH_OID, |
| 135 | .opt = "tos-fw-extra2", |
| 136 | .help_msg = "Trusted OS Extra2 image file", |
| 137 | .sn = "TrustedOSExtra2Hash", |
| 138 | .ln = "Trusted OS Extra2 hash (SHA256)", |
| 139 | .asn1_type = V_ASN1_OCTET_STRING, |
| 140 | .type = EXT_TYPE_HASH, |
| 141 | .optional = 1 |
| 142 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 143 | [NON_TRUSTED_FW_CONTENT_CERT_PK_EXT] = { |
| 144 | .oid = NON_TRUSTED_FW_CONTENT_CERT_PK_OID, |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 145 | .sn = "NonTrustedFirmwareContentCertPK", |
| 146 | .ln = "Non-Trusted Firmware content certificate public key", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 147 | .asn1_type = V_ASN1_OCTET_STRING, |
| 148 | .type = EXT_TYPE_PKEY, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 149 | .attr.key = NON_TRUSTED_FW_CONTENT_CERT_KEY |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 150 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 151 | [NON_TRUSTED_WORLD_BOOTLOADER_HASH_EXT] = { |
| 152 | .oid = NON_TRUSTED_WORLD_BOOTLOADER_HASH_OID, |
| 153 | .opt = "nt-fw", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 154 | .help_msg = "Non-Trusted World Bootloader image file", |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 155 | .sn = "NonTrustedWorldBootloaderHash", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 156 | .ln = "Non-Trusted World hash (SHA256)", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 157 | .asn1_type = V_ASN1_OCTET_STRING, |
| 158 | .type = EXT_TYPE_HASH |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 159 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 160 | [SCP_FWU_CFG_HASH_EXT] = { |
| 161 | .oid = SCP_FWU_CFG_HASH_OID, |
| 162 | .opt = "scp-fwu-cfg", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 163 | .help_msg = "SCP Firmware Update Config image file", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 164 | .sn = "SCPFWUpdateConfig", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 165 | .ln = "SCP Firmware Update Config hash (SHA256)", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 166 | .asn1_type = V_ASN1_OCTET_STRING, |
| 167 | .type = EXT_TYPE_HASH, |
| 168 | .optional = 1 |
| 169 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 170 | [AP_FWU_CFG_HASH_EXT] = { |
| 171 | .oid = AP_FWU_CFG_HASH_OID, |
| 172 | .opt = "ap-fwu-cfg", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 173 | .help_msg = "AP Firmware Update Config image file", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 174 | .sn = "APFWUpdateConfig", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 175 | .ln = "AP Firmware Update Config hash (SHA256)", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 176 | .asn1_type = V_ASN1_OCTET_STRING, |
| 177 | .type = EXT_TYPE_HASH, |
| 178 | .optional = 1 |
| 179 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 180 | [FWU_HASH_EXT] = { |
| 181 | .oid = FWU_HASH_OID, |
| 182 | .opt = "fwu", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 183 | .help_msg = "Firmware Updater image file", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 184 | .sn = "FWUpdaterHash", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 185 | .ln = "Firmware Updater hash (SHA256)", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 186 | .asn1_type = V_ASN1_OCTET_STRING, |
| 187 | .type = EXT_TYPE_HASH, |
| 188 | .optional = 1 |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 189 | } |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 190 | }; |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 191 | |
| 192 | REGISTER_EXTENSIONS(tbb_ext); |