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

Master-Secret calculation inconsistent with SPDM specification #987

Closed
annarossa opened this issue Jun 30, 2022 · 10 comments · Fixed by #988
Closed

Master-Secret calculation inconsistent with SPDM specification #987

annarossa opened this issue Jun 30, 2022 · 10 comments · Fixed by #988
Assignees
Labels
bug Something isn't working

Comments

@annarossa
Copy link

In master_secret calculation salt and IKM seem to have swapped places.
In DSP0274_1.2.0 (paragraph 738 & 742) for Master-Secret salt is Salt_1 and IKM is 0_filled, and in the code it is otherwise.
master_secret calculation:

status = libspdm_hmac_all(
secured_message_context->base_hash_algo,
m_zero_filled_buffer, hash_size, salt1, hash_size,
secured_message_context->master_secret.master_secret);

bool libspdm_hmac_all(uint32_t base_hash_algo, const void *data,
size_t data_size, const uint8_t *key,
size_t key_size, uint8_t *hmac_value);

@jyao1
Copy link
Member

jyao1 commented Jun 30, 2022

@annarossa , good catch!

@jyao1 jyao1 added the bug Something isn't working label Jun 30, 2022
@jyao1 jyao1 self-assigned this Jun 30, 2022
@steven-bellock
Copy link
Contributor

@jyao1 In the specification HMAC-Hash is ill-defined, but assuming that HMAC-Hash is defined as HMAC-Hash(key, data) libspdm is correct no?

@jyao1
Copy link
Member

jyao1 commented Jun 30, 2022

Checking

status = libspdm_hmac_all(
secured_message_context->base_hash_algo,
m_zero_filled_buffer, hash_size,
secured_message_context->master_secret.dhe_secret,
secured_message_context->dhe_key_size,
secured_message_context->master_secret.handshake_secret);

They must be consistent.

@jyao1
Copy link
Member

jyao1 commented Jun 30, 2022

Since they are not consistent, one of them is wrong.

@steven-bellock
Copy link
Contributor

Sure we can make libspdm consistent, but we don't know if it's consistent with the specification, because the specification doesn't define which parameter in HMAC-Hash is the key and which is the data.

@annarossa
Copy link
Author

I think the answer is here: https://datatracker.ietf.org/doc/html/rfc5869

2.1 Notation

HMAC always has two arguments: the first is a key
and the second an input (or message). (Note that in the extract
step, 'IKM' is used as the HMAC input, not as the HMAC key.)

HMAC-Hash(salt, IKM)

@jyao1
Copy link
Member

jyao1 commented Jun 30, 2022

Ok, then Master-Secret is correct, it is Handshake-Secret that is wrong.

@steven-bellock
Copy link
Contributor

steven-bellock commented Jun 30, 2022

The SPDM specification says

A key schedule describes how the various keys such as encryption keys used by a session are derived, and when each key is used. The default SPDM key schedule makes heavy use of HMAC, which RFC2104 defines, and HKDF-Expand, which RFC5869 describes.

So 5869 is only used for HKDF-Expand. 2104 doesn't define HMAC or HMAC-Hash but it does define hmac_md5(text, text_len, key, key_len, digest) in which case the text / data is the first parameter and the key is the second parameter.

@jyao1
Copy link
Member

jyao1 commented Jun 30, 2022

I am filing SPDM spec issue to get it clarified - https://github.com/DMTF/Security-TF/issues/2076

Assuming HMAC-Hash(salt, IKM) == HMAC(key, input data), we need fix handshake secret calculation, right?

@steven-bellock
Copy link
Contributor

Assuming HMAC-Hash(salt, IKM) == HMAC(key, input data), we need fix handshake secret calculation, right?

Correct, though we should delay the Q2 checkpoint until the specification is resolved and this issue needs to be broadcast widely since it effects interoperability and (possibly) security. It seems like folks that are implementing non-libspdm endpoints haven't made it to session establishment, and that's why we haven't run into this issue sooner.

@jyao1 jyao1 closed this as completed in #988 Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants