1212typedef struct {
1313 spdm_message_header_t header ;
1414 uint8_t digest [LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT ];
15+ spdm_key_pair_id_t key_pair_id [SPDM_MAX_SLOT_COUNT ];
16+ spdm_certificate_info_t cert_info [SPDM_MAX_SLOT_COUNT ];
17+ spdm_key_usage_bit_mask_t key_usage_bit_mask [SPDM_MAX_SLOT_COUNT ];
1518} libspdm_digests_response_max_t ;
1619#pragma pack()
1720
@@ -59,6 +62,12 @@ static libspdm_return_t libspdm_try_get_digest(libspdm_context_t *spdm_context,
5962 size_t transport_header_size ;
6063 libspdm_session_info_t * session_info ;
6164 libspdm_session_state_t session_state ;
65+ size_t additional_size ;
66+ spdm_key_pair_id_t * key_pair_id ;
67+ spdm_certificate_info_t * cert_info ;
68+ spdm_key_usage_bit_mask_t * key_usage_bit_mask ;
69+ size_t slot_index ;
70+ uint8_t cert_model ;
6271
6372 /* -=[Verify State Phase]=- */
6473 if (!libspdm_is_capabilities_flag_supported (
@@ -159,6 +168,18 @@ static libspdm_return_t libspdm_try_get_digest(libspdm_context_t *spdm_context,
159168 * slot_mask = spdm_response -> header .param2 ;
160169 }
161170
171+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "provisioned_slot_mask - 0x%02x\n" ,
172+ spdm_response -> header .param2 ));
173+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
174+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "supported_slot_mask - 0x%02x\n" ,
175+ spdm_response -> header .param1 ));
176+ if ((spdm_response -> header .param1 & spdm_response -> header .param2 ) !=
177+ spdm_response -> header .param2 ) {
178+ status = LIBSPDM_STATUS_INVALID_MSG_FIELD ;
179+ goto receive_done ;
180+ }
181+ }
182+
162183 digest_count = 0 ;
163184 for (index = 0 ; index < SPDM_MAX_SLOT_COUNT ; index ++ ) {
164185 if (spdm_response -> header .param2 & (1 << index )) {
@@ -170,11 +191,19 @@ static libspdm_return_t libspdm_try_get_digest(libspdm_context_t *spdm_context,
170191 goto receive_done ;
171192 }
172193
173- if (spdm_response_size < sizeof (spdm_digest_response_t ) + digest_count * digest_size ) {
194+ additional_size = 0 ;
195+ if ((spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) &&
196+ spdm_context -> connection_info .multi_key_conn_rsp ) {
197+ additional_size = sizeof (spdm_key_pair_id_t ) + sizeof (spdm_certificate_info_t ) +
198+ sizeof (spdm_key_usage_bit_mask_t );
199+ }
200+ if (spdm_response_size <
201+ sizeof (spdm_digest_response_t ) + digest_count * (digest_size + additional_size )) {
174202 status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
175203 goto receive_done ;
176204 }
177- spdm_response_size = sizeof (spdm_digest_response_t ) + digest_count * digest_size ;
205+ spdm_response_size =
206+ sizeof (spdm_digest_response_t ) + digest_count * (digest_size + additional_size );
178207
179208 /* -=[Process Response Phase]=- */
180209 if (session_id == NULL ) {
@@ -196,22 +225,74 @@ static libspdm_return_t libspdm_try_get_digest(libspdm_context_t *spdm_context,
196225 }
197226 }
198227
228+ key_pair_id =
229+ (spdm_key_pair_id_t * )((uint8_t * )spdm_response -> digest + digest_size * digest_count );
230+ cert_info =
231+ (spdm_certificate_info_t * )((uint8_t * )key_pair_id + sizeof (spdm_key_pair_id_t ) *
232+ digest_count );
233+ key_usage_bit_mask =
234+ (spdm_key_usage_bit_mask_t * )((uint8_t * )cert_info + sizeof (spdm_certificate_info_t ) *
235+ digest_count );
199236 for (index = 0 ; index < digest_count ; index ++ ) {
200237 LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "digest (0x%x) - " , index ));
201238 LIBSPDM_INTERNAL_DUMP_DATA (& spdm_response -> digest [digest_size * index ], digest_size );
202239 LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "\n" ));
203240 }
241+ if ((spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) &&
242+ spdm_context -> connection_info .multi_key_conn_rsp ) {
243+ for (index = 0 ; index < digest_count ; index ++ ) {
244+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "key_pair_id (0x%x) - 0x%02x\n" , index ,
245+ key_pair_id [index ]));
246+ }
247+ for (index = 0 ; index < digest_count ; index ++ ) {
248+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "cert_info (0x%x) - 0x%02x\n" , index ,
249+ cert_info [index ]));
250+ }
251+ for (index = 0 ; index < digest_count ; index ++ ) {
252+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "key_usage_bit_mask (0x%x) - 0x%04x\n" , index ,
253+ key_usage_bit_mask [index ]));
254+ }
255+ }
204256
205257 if (total_digest_buffer != NULL ) {
206258 libspdm_copy_mem (total_digest_buffer , digest_size * digest_count ,
207259 spdm_response -> digest , digest_size * digest_count );
208260 }
209261
210- spdm_context -> connection_info .peer_digest_slot_mask = spdm_response -> header .param2 ;
262+ spdm_context -> connection_info .peer_provisioned_slot_mask = spdm_response -> header .param2 ;
263+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
264+ spdm_context -> connection_info .peer_supported_slot_mask = spdm_response -> header .param1 ;
265+ } else {
266+ spdm_context -> connection_info .peer_supported_slot_mask = spdm_response -> header .param2 ;
267+ }
211268 libspdm_copy_mem (
212269 spdm_context -> connection_info .peer_total_digest_buffer ,
213270 sizeof (spdm_context -> connection_info .peer_total_digest_buffer ),
214271 spdm_response -> digest , digest_size * digest_count );
272+ libspdm_zero_mem (spdm_context -> connection_info .peer_key_pair_id ,
273+ sizeof (spdm_context -> connection_info .peer_key_pair_id ));
274+ libspdm_zero_mem (spdm_context -> connection_info .peer_cert_info ,
275+ sizeof (spdm_context -> connection_info .peer_cert_info ));
276+ libspdm_zero_mem (spdm_context -> connection_info .peer_key_usage_bit_mask ,
277+ sizeof (spdm_context -> connection_info .peer_key_usage_bit_mask ));
278+ if ((spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) &&
279+ spdm_context -> connection_info .multi_key_conn_rsp ) {
280+ slot_index = 0 ;
281+ for (index = 0 ; index < SPDM_MAX_SLOT_COUNT ; index ++ ) {
282+ if (spdm_response -> header .param2 & (1 << index )) {
283+ spdm_context -> connection_info .peer_key_pair_id [index ] = key_pair_id [slot_index ];
284+ cert_model = cert_info [slot_index ] & SPDM_CERTIFICATE_INFO_CERT_MODEL_MASK ;
285+ if (cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT ) {
286+ status = LIBSPDM_STATUS_INVALID_MSG_FIELD ;
287+ goto receive_done ;
288+ }
289+ spdm_context -> connection_info .peer_cert_info [index ] = cert_model ;
290+ spdm_context -> connection_info .peer_key_usage_bit_mask [index ] =
291+ key_usage_bit_mask [slot_index ];
292+ slot_index ++ ;
293+ }
294+ }
295+ }
215296
216297 /* -=[Update State Phase]=- */
217298 if (spdm_context -> connection_info .connection_state < LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS ) {
0 commit comments