-
Notifications
You must be signed in to change notification settings - Fork 100
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
Enforce mandatory CA in SET_CERTIFICATE #2850
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,10 @@ | |
|
||
#if LIBSPDM_CERT_PARSE_SUPPORT | ||
/*set_cert verify cert_chain*/ | ||
static bool libspdm_set_cert_verify_certchain(const uint8_t *cert_chain, size_t cert_chain_size, | ||
static bool libspdm_set_cert_verify_certchain(uint8_t spdm_version, | ||
const uint8_t *cert_chain, size_t cert_chain_size, | ||
uint32_t base_asym_algo, uint32_t base_hash_algo, | ||
bool is_device_cert_model) | ||
uint8_t cert_model) | ||
{ | ||
const uint8_t *root_cert_buffer; | ||
size_t root_cert_buffer_size; | ||
|
@@ -39,11 +40,22 @@ static bool libspdm_set_cert_verify_certchain(const uint8_t *cert_chain, size_t | |
return false; | ||
} | ||
|
||
/*verify leaf cert*/ | ||
if (!libspdm_x509_set_cert_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size, | ||
base_asym_algo, base_hash_algo, | ||
false, is_device_cert_model)) { | ||
return false; | ||
if (spdm_version == SPDM_MESSAGE_VERSION_12) { | ||
const bool is_device_cert_model = | ||
(cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT); | ||
|
||
/*verify leaf cert*/ | ||
if (!libspdm_x509_set_cert_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size, | ||
base_asym_algo, base_hash_algo, | ||
false, is_device_cert_model)) { | ||
return false; | ||
} | ||
} else { | ||
if (!libspdm_x509_set_cert_certificate_check_ex(leaf_cert_buffer, leaf_cert_buffer_size, | ||
base_asym_algo, base_hash_algo, | ||
false, cert_model)) { | ||
Comment on lines
+48
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks weird to only support 1.3 in ex version and only support 1.2 in non-ex version. But I don't have good idea now. Need to think through. |
||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
|
@@ -58,8 +70,10 @@ libspdm_return_t libspdm_get_response_set_certificate(libspdm_context_t *spdm_co | |
spdm_set_certificate_response_t *spdm_response; | ||
|
||
bool result; | ||
uint8_t spdm_version; | ||
uint8_t slot_id; | ||
bool erase; | ||
uint8_t set_cert_model; | ||
|
||
size_t root_cert_hash_size; | ||
const spdm_cert_chain_t *cert_chain_header; | ||
|
@@ -69,21 +83,21 @@ libspdm_return_t libspdm_get_response_set_certificate(libspdm_context_t *spdm_co | |
libspdm_session_info_t *session_info; | ||
libspdm_session_state_t session_state; | ||
|
||
bool is_device_cert_model; | ||
|
||
spdm_request = request; | ||
|
||
/* -=[Check Parameters Phase]=- */ | ||
LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_SET_CERTIFICATE); | ||
|
||
if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) { | ||
spdm_version = libspdm_get_connection_version(spdm_context); | ||
|
||
if (spdm_version < SPDM_MESSAGE_VERSION_12) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, | ||
SPDM_SET_CERTIFICATE, | ||
response_size, response); | ||
} | ||
|
||
if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) { | ||
if (spdm_request->header.spdm_version != spdm_version) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_VERSION_MISMATCH, 0, | ||
response_size, response); | ||
|
@@ -153,13 +167,13 @@ libspdm_return_t libspdm_get_response_set_certificate(libspdm_context_t *spdm_co | |
root_cert_hash_size = libspdm_get_hash_size( | ||
spdm_context->connection_info.algorithm.base_hash_algo); | ||
|
||
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) { | ||
const uint8_t set_cert_model = | ||
if (spdm_version >= SPDM_MESSAGE_VERSION_13) { | ||
const uint8_t key_pair_id = spdm_request->header.param2; | ||
|
||
set_cert_model = | ||
(spdm_request->header.param1 & | ||
SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_MASK) >> | ||
SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_CERT_MODEL_OFFSET; | ||
const uint8_t key_pair_id = spdm_request->header.param2; | ||
|
||
erase = (spdm_request->header.param1 & SPDM_SET_CERTIFICATE_REQUEST_ATTRIBUTES_ERASE) != 0; | ||
|
||
if (spdm_context->connection_info.multi_key_conn_rsp) { | ||
|
@@ -182,10 +196,23 @@ libspdm_return_t libspdm_get_response_set_certificate(libspdm_context_t *spdm_co | |
SPDM_ERROR_CODE_INVALID_REQUEST, 0, | ||
response_size, response); | ||
} | ||
if ((spdm_context->local_context.capability.flags & | ||
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP) != 0) { | ||
set_cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT; | ||
} else { | ||
set_cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT; | ||
} | ||
} | ||
} else { | ||
if ((spdm_context->local_context.capability.flags & | ||
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP) != 0) { | ||
set_cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT; | ||
} else { | ||
set_cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT; | ||
} | ||
} | ||
|
||
if ((libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) && erase) { | ||
if ((spdm_version >= SPDM_MESSAGE_VERSION_13) && erase) { | ||
/*the CertChain field shall be absent;the value of SetCertModel shall be zero*/ | ||
if ((request_size < sizeof(spdm_set_certificate_request_t)) || | ||
((spdm_request->header.param1 & | ||
|
@@ -237,18 +264,13 @@ libspdm_return_t libspdm_get_response_set_certificate(libspdm_context_t *spdm_co | |
cert_chain = (const void*)((const uint8_t *)cert_chain | ||
+ sizeof(spdm_cert_chain_t) + root_cert_hash_size); | ||
|
||
is_device_cert_model = false; | ||
if((spdm_context->local_context.capability.flags & | ||
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP) == 0) { | ||
is_device_cert_model = true; | ||
} | ||
|
||
#if LIBSPDM_CERT_PARSE_SUPPORT | ||
/*check the cert_chain*/ | ||
result = libspdm_set_cert_verify_certchain(cert_chain, cert_chain_size, | ||
result = libspdm_set_cert_verify_certchain(spdm_version, | ||
cert_chain, cert_chain_size, | ||
spdm_context->connection_info.algorithm.base_asym_algo, | ||
spdm_context->connection_info.algorithm.base_hash_algo, | ||
is_device_cert_model); | ||
set_cert_model); | ||
if (!result) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_UNSPECIFIED, 0, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had better add some reason for the ex/non-ex version difference.
For example, the
basic constrain
is not checked in 1.2, but will be checked in 1.3.