Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tpm2_getekcertificate: add support to high range NV indexes #3440

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix impl to prioritize low range certificate
Signed-off-by: loic.sikidi <[email protected]>
loicsikidi committed Dec 12, 2024

Verified

This commit was signed with the committer’s verified signature.
smira Andrey Smirnov
commit 57263cfb5901e5325ade551b7086e4ab9d10e5c5
8 changes: 8 additions & 0 deletions test/integration/tests/getekcertificate.sh
Original file line number Diff line number Diff line change
@@ -172,4 +172,12 @@ diff nv_ecc_ek_cert.der ecc_ek_cert.der

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

## Make sure that if there are several certificates of the same type, then the one belonging to low range has priority
openssl x509 -in ecc_ek_cert.bin -out ecc_low_range_ek_cert.der -outform DER
define_ek_cert_nv_index ecc_low_range_ek_cert.der $ECC_EK_CERT_NV_INDEX

tpm2 getekcertificate -o nv_ecc_ek_cert.der

diff nv_ecc_ek_cert.der ecc_low_range_ek_cert.der

exit 0
7 changes: 5 additions & 2 deletions tools/tpm2_getekcertificate.c
Original file line number Diff line number Diff line change
@@ -665,6 +665,9 @@ tool_rc get_tpm_properties(ESYS_CONTEXT *ectx) {
goto get_tpm_properties_out;
}

ctx.rsa_ek_cert_nv_location = 0xffffffff;
ctx.ecc_ek_cert_nv_location = 0xffffffff;

UINT32 i;
for (i = 0; i < capability_data->data.handles.count; i++) {
TPMI_RH_NV_INDEX index = capability_data->data.handles.handle[i];
@@ -673,12 +676,12 @@ tool_rc get_tpm_properties(ESYS_CONTEXT *ectx) {
continue;
}

if (m->key_type == KTYPE_RSA) {
if (m->key_type == KTYPE_RSA && index < ctx.rsa_ek_cert_nv_location) {
LOG_INFO("Found pre-provisioned RSA EK certificate at %u [type=%s]", index, m->name);
ctx.is_rsa_ek_cert_nv_location_defined = true;
ctx.rsa_ek_cert_nv_location = m->index;
}
if (m->key_type == KTYPE_ECC) {
if (m->key_type == KTYPE_ECC && index < ctx.ecc_ek_cert_nv_location) {
LOG_INFO("Found pre-provisioned ECC EK certificate at %u [type=%s]", index, m->name);
ctx.is_ecc_ek_cert_nv_location_defined = true;
ctx.ecc_ek_cert_nv_location = m->index;