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 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 123 | [NON_TRUSTED_FW_CONTENT_CERT_PK_EXT] = { |
| 124 | .oid = NON_TRUSTED_FW_CONTENT_CERT_PK_OID, |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 125 | .sn = "NonTrustedFirmwareContentCertPK", |
| 126 | .ln = "Non-Trusted Firmware content certificate public key", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 127 | .asn1_type = V_ASN1_OCTET_STRING, |
| 128 | .type = EXT_TYPE_PKEY, |
Juan Castillo | 4352998 | 2016-01-22 11:05:24 +0000 | [diff] [blame] | 129 | .attr.key = NON_TRUSTED_FW_CONTENT_CERT_KEY |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 130 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 131 | [NON_TRUSTED_WORLD_BOOTLOADER_HASH_EXT] = { |
| 132 | .oid = NON_TRUSTED_WORLD_BOOTLOADER_HASH_OID, |
| 133 | .opt = "nt-fw", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 134 | .help_msg = "Non-Trusted World Bootloader image file", |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 135 | .sn = "NonTrustedWorldBootloaderHash", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 136 | .ln = "Non-Trusted World hash (SHA256)", |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 137 | .asn1_type = V_ASN1_OCTET_STRING, |
| 138 | .type = EXT_TYPE_HASH |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 139 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 140 | [SCP_FWU_CFG_HASH_EXT] = { |
| 141 | .oid = SCP_FWU_CFG_HASH_OID, |
| 142 | .opt = "scp-fwu-cfg", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 143 | .help_msg = "SCP Firmware Update Config image file", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 144 | .sn = "SCPFWUpdateConfig", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 145 | .ln = "SCP Firmware Update Config hash (SHA256)", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 146 | .asn1_type = V_ASN1_OCTET_STRING, |
| 147 | .type = EXT_TYPE_HASH, |
| 148 | .optional = 1 |
| 149 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 150 | [AP_FWU_CFG_HASH_EXT] = { |
| 151 | .oid = AP_FWU_CFG_HASH_OID, |
| 152 | .opt = "ap-fwu-cfg", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 153 | .help_msg = "AP Firmware Update Config image file", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 154 | .sn = "APFWUpdateConfig", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 155 | .ln = "AP Firmware Update Config hash (SHA256)", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 156 | .asn1_type = V_ASN1_OCTET_STRING, |
| 157 | .type = EXT_TYPE_HASH, |
| 158 | .optional = 1 |
| 159 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 160 | [FWU_HASH_EXT] = { |
| 161 | .oid = FWU_HASH_OID, |
| 162 | .opt = "fwu", |
Juan Castillo | 212f738 | 2015-12-15 16:37:57 +0000 | [diff] [blame] | 163 | .help_msg = "Firmware Updater image file", |
Yatharth Kochar | 5752b59 | 2015-08-21 15:30:55 +0100 | [diff] [blame] | 164 | .sn = "FWUpdaterHash", |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 165 | .ln = "Firmware Updater 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 |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 169 | } |
Juan Castillo | 11abdcd | 2014-10-21 11:30:42 +0100 | [diff] [blame] | 170 | }; |
Juan Castillo | e6d30e9 | 2015-06-12 11:27:59 +0100 | [diff] [blame] | 171 | |
| 172 | REGISTER_EXTENSIONS(tbb_ext); |