Skip to content

Commit 57263cf

Browse files
committed
fix impl to prioritize low range certificate
Signed-off-by: loic.sikidi <loic.sikidi@gmail.com>
1 parent aa19e64 commit 57263cf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

test/integration/tests/getekcertificate.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,12 @@ diff nv_ecc_ek_cert.der ecc_ek_cert.der
172172

173173
rm nv_rsa_ek_cert.der rsa_ek_cert.der nv_ecc_ek_cert.der ecc_ek_cert.der priv_key.pem -f
174174

175+
## Make sure that if there are several certificates of the same type, then the one belonging to low range has priority
176+
openssl x509 -in ecc_ek_cert.bin -out ecc_low_range_ek_cert.der -outform DER
177+
define_ek_cert_nv_index ecc_low_range_ek_cert.der $ECC_EK_CERT_NV_INDEX
178+
179+
tpm2 getekcertificate -o nv_ecc_ek_cert.der
180+
181+
diff nv_ecc_ek_cert.der ecc_low_range_ek_cert.der
182+
175183
exit 0

tools/tpm2_getekcertificate.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ tool_rc get_tpm_properties(ESYS_CONTEXT *ectx) {
665665
goto get_tpm_properties_out;
666666
}
667667

668+
ctx.rsa_ek_cert_nv_location = 0xffffffff;
669+
ctx.ecc_ek_cert_nv_location = 0xffffffff;
670+
668671
UINT32 i;
669672
for (i = 0; i < capability_data->data.handles.count; i++) {
670673
TPMI_RH_NV_INDEX index = capability_data->data.handles.handle[i];
@@ -673,12 +676,12 @@ tool_rc get_tpm_properties(ESYS_CONTEXT *ectx) {
673676
continue;
674677
}
675678

676-
if (m->key_type == KTYPE_RSA) {
679+
if (m->key_type == KTYPE_RSA && index < ctx.rsa_ek_cert_nv_location) {
677680
LOG_INFO("Found pre-provisioned RSA EK certificate at %u [type=%s]", index, m->name);
678681
ctx.is_rsa_ek_cert_nv_location_defined = true;
679682
ctx.rsa_ek_cert_nv_location = m->index;
680683
}
681-
if (m->key_type == KTYPE_ECC) {
684+
if (m->key_type == KTYPE_ECC && index < ctx.ecc_ek_cert_nv_location) {
682685
LOG_INFO("Found pre-provisioned ECC EK certificate at %u [type=%s]", index, m->name);
683686
ctx.is_ecc_ek_cert_nv_location_defined = true;
684687
ctx.ecc_ek_cert_nv_location = m->index;

0 commit comments

Comments
 (0)