@@ -18,6 +18,8 @@ static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE];
18
18
19
19
static bool m_get_cert ;
20
20
21
+ static uint8_t m_cert_model ;
22
+
21
23
/* Loading the target expiration certificate chain and saving root certificate hash
22
24
* "rsa3072_Expiration/bundle_responder.certchain.der"*/
23
25
bool libspdm_libspdm_read_responder_public_certificate_chain_expiration (
@@ -175,6 +177,7 @@ libspdm_return_t libspdm_requester_get_certificate_test_send_message(
175
177
case 0x1C :
176
178
return LIBSPDM_STATUS_SUCCESS ;
177
179
case 0x1D :
180
+ case 0x1E :
178
181
return LIBSPDM_STATUS_SUCCESS ;
179
182
default :
180
183
return LIBSPDM_STATUS_SEND_FAIL ;
@@ -2156,6 +2159,71 @@ libspdm_return_t libspdm_requester_get_certificate_test_receive_message(
2156
2159
spdm_response , response_size ,
2157
2160
response );
2158
2161
2162
+ calling_index ++ ;
2163
+ if (calling_index == count ) {
2164
+ calling_index = 0 ;
2165
+ free (m_libspdm_local_certificate_chain );
2166
+ m_libspdm_local_certificate_chain = NULL ;
2167
+ m_libspdm_local_certificate_chain_size = 0 ;
2168
+ }
2169
+ }
2170
+ return LIBSPDM_STATUS_SUCCESS ;
2171
+ case 0x1E : {
2172
+ spdm_certificate_response_t * spdm_response ;
2173
+ size_t spdm_response_size ;
2174
+ size_t transport_header_size ;
2175
+ uint16_t portion_length ;
2176
+ uint16_t remainder_length ;
2177
+ size_t count ;
2178
+ static size_t calling_index = 0 ;
2179
+
2180
+ if (m_libspdm_local_certificate_chain == NULL ) {
2181
+ libspdm_read_responder_public_certificate_chain (
2182
+ m_libspdm_use_hash_algo , m_libspdm_use_asym_algo ,
2183
+ & m_libspdm_local_certificate_chain ,
2184
+ & m_libspdm_local_certificate_chain_size , NULL , NULL );
2185
+ }
2186
+ if (m_libspdm_local_certificate_chain == NULL ) {
2187
+ return LIBSPDM_STATUS_RECEIVE_FAIL ;
2188
+ }
2189
+ count = (m_libspdm_local_certificate_chain_size +
2190
+ LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN - 1 ) /
2191
+ LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN ;
2192
+ if (calling_index != count - 1 ) {
2193
+ portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN ;
2194
+ remainder_length =
2195
+ (uint16_t )(m_libspdm_local_certificate_chain_size -
2196
+ LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN *
2197
+ (calling_index + 1 ));
2198
+ } else {
2199
+ portion_length = (uint16_t )(
2200
+ m_libspdm_local_certificate_chain_size -
2201
+ LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * (count - 1 ));
2202
+ remainder_length = 0 ;
2203
+ }
2204
+
2205
+ spdm_response_size =
2206
+ sizeof (spdm_certificate_response_t ) + portion_length ;
2207
+ transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE ;
2208
+ spdm_response = (void * )((uint8_t * )* response + transport_header_size );
2209
+
2210
+ spdm_response -> header .spdm_version = SPDM_MESSAGE_VERSION_13 ;
2211
+ spdm_response -> header .request_response_code = SPDM_CERTIFICATE ;
2212
+ spdm_response -> header .param1 = 0 ;
2213
+ spdm_response -> header .param2 = m_cert_model ;
2214
+ spdm_response -> portion_length = portion_length ;
2215
+ spdm_response -> remainder_length = remainder_length ;
2216
+ libspdm_copy_mem (spdm_response + 1 ,
2217
+ (size_t )(* response ) + * response_size - (size_t )(spdm_response + 1 ),
2218
+ (uint8_t * )m_libspdm_local_certificate_chain +
2219
+ LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index ,
2220
+ portion_length );
2221
+
2222
+ libspdm_transport_test_encode_message (spdm_context , NULL , false,
2223
+ false, spdm_response_size ,
2224
+ spdm_response , response_size ,
2225
+ response );
2226
+
2159
2227
calling_index ++ ;
2160
2228
if (calling_index == count ) {
2161
2229
calling_index = 0 ;
@@ -4076,6 +4144,140 @@ void libspdm_test_requester_get_certificate_case29(void **state)
4076
4144
free (data );
4077
4145
}
4078
4146
4147
+ /**
4148
+ * Test 30: check request attributes and response attributes ,
4149
+ * Set CertModel to determine whether it meets expectations
4150
+ * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS
4151
+ **/
4152
+ void libspdm_test_requester_get_certificate_case30 (void * * state )
4153
+ {
4154
+ libspdm_return_t status ;
4155
+ libspdm_test_context_t * spdm_test_context ;
4156
+ libspdm_context_t * spdm_context ;
4157
+ size_t cert_chain_size ;
4158
+ uint8_t cert_chain [LIBSPDM_MAX_CERT_CHAIN_SIZE ];
4159
+ void * data ;
4160
+ size_t data_size ;
4161
+ void * hash ;
4162
+ size_t hash_size ;
4163
+ const uint8_t * root_cert ;
4164
+ size_t root_cert_size ;
4165
+ libspdm_data_parameter_t parameter ;
4166
+
4167
+ #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4168
+ #else
4169
+ uint8_t set_data_buffer_hash [LIBSPDM_MAX_HASH_SIZE ];
4170
+ uint32_t set_data_buffer_hash_size ;
4171
+ #endif
4172
+
4173
+ spdm_test_context = * state ;
4174
+ spdm_context = spdm_test_context -> spdm_context ;
4175
+ spdm_test_context -> case_id = 0x1E ;
4176
+ spdm_context -> retry_times = 1 ;
4177
+ spdm_context -> connection_info .version = SPDM_MESSAGE_VERSION_13 <<
4178
+ SPDM_VERSION_NUMBER_SHIFT_BIT ;
4179
+ spdm_context -> connection_info .connection_state =
4180
+ LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS ;
4181
+ spdm_context -> connection_info .capability .flags = 0 ;
4182
+ spdm_context -> connection_info .capability .flags |=
4183
+ SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP ;
4184
+ spdm_context -> local_context .is_requester = true;
4185
+ libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo ,
4186
+ m_libspdm_use_asym_algo , & data ,
4187
+ & data_size , & hash , & hash_size );
4188
+ libspdm_x509_get_cert_from_cert_chain ((uint8_t * )data + sizeof (spdm_cert_chain_t ) + hash_size ,
4189
+ data_size - sizeof (spdm_cert_chain_t ) - hash_size , 0 ,
4190
+ & root_cert , & root_cert_size );
4191
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "root cert data :\n" ));
4192
+ libspdm_dump_hex (
4193
+ root_cert ,
4194
+ root_cert_size );
4195
+ spdm_context -> local_context .peer_root_cert_provision_size [0 ] =
4196
+ root_cert_size ;
4197
+ spdm_context -> local_context .peer_root_cert_provision [0 ] = root_cert ;
4198
+ libspdm_reset_message_b (spdm_context );
4199
+ spdm_context -> connection_info .algorithm .base_hash_algo =
4200
+ m_libspdm_use_hash_algo ;
4201
+ spdm_context -> connection_info .algorithm .base_asym_algo =
4202
+ m_libspdm_use_asym_algo ;
4203
+ spdm_context -> connection_info .algorithm .req_base_asym_alg =
4204
+ m_libspdm_use_req_asym_algo ;
4205
+
4206
+ libspdm_zero_mem (& parameter , sizeof (parameter ));
4207
+ parameter .location = LIBSPDM_DATA_LOCATION_CONNECTION ;
4208
+ parameter .additional_data [0 ] = 0 ;
4209
+ libspdm_set_data (spdm_context , LIBSPDM_DATA_PEER_USED_CERT_CHAIN_BUFFER , & parameter ,
4210
+ data , data_size );
4211
+
4212
+ #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4213
+ spdm_context -> transcript .message_m .buffer_size =
4214
+ spdm_context -> transcript .message_m .max_buffer_size ;
4215
+ #else
4216
+ set_data_buffer_hash_size =
4217
+ spdm_context -> connection_info .peer_used_cert_chain [0 ].buffer_hash_size ;
4218
+ libspdm_copy_mem (set_data_buffer_hash , set_data_buffer_hash_size ,
4219
+ spdm_context -> connection_info .peer_used_cert_chain [0 ].buffer_hash ,
4220
+ set_data_buffer_hash_size );
4221
+ #endif
4222
+
4223
+ /* Sub Case 1: CertModel Value of 1 , DeviceCert model*/
4224
+ spdm_context -> connection_info .multi_key_conn_rsp = true;
4225
+ spdm_context -> connection_info .peer_cert_info [0 ] = 0 ;
4226
+ m_cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT ;
4227
+ libspdm_reset_message_b (spdm_context );
4228
+
4229
+ cert_chain_size = sizeof (cert_chain );
4230
+ libspdm_zero_mem (cert_chain , sizeof (cert_chain ));
4231
+ status = libspdm_get_certificate (spdm_context , NULL , 0 , & cert_chain_size ,
4232
+ cert_chain );
4233
+ assert_int_equal (status , LIBSPDM_STATUS_SUCCESS );
4234
+ assert_int_equal (spdm_context -> connection_info .peer_cert_info [0 ], m_cert_model );
4235
+
4236
+ /* Sub Case 2: CertModel Value of 2 , AliasCert model*/
4237
+ spdm_context -> connection_info .multi_key_conn_rsp = true;
4238
+ spdm_context -> connection_info .peer_cert_info [0 ] = 0 ;
4239
+ m_cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT ;
4240
+ libspdm_reset_message_b (spdm_context );
4241
+
4242
+ cert_chain_size = sizeof (cert_chain );
4243
+ libspdm_zero_mem (cert_chain , sizeof (cert_chain ));
4244
+ status = libspdm_get_certificate (spdm_context , NULL , 0 , & cert_chain_size ,
4245
+ cert_chain );
4246
+ assert_int_equal (status , LIBSPDM_STATUS_SUCCESS );
4247
+ assert_int_equal (spdm_context -> connection_info .peer_cert_info [0 ], m_cert_model );
4248
+ libspdm_reset_message_b (spdm_context );
4249
+
4250
+ /* Sub Case 3: CertModel Value of 3 , GenericCert model*/
4251
+ spdm_context -> connection_info .multi_key_conn_rsp = true;
4252
+ spdm_context -> connection_info .peer_cert_info [0 ] = 0 ;
4253
+ m_cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT ;
4254
+ libspdm_reset_message_b (spdm_context );
4255
+
4256
+ cert_chain_size = sizeof (cert_chain );
4257
+ libspdm_zero_mem (cert_chain , sizeof (cert_chain ));
4258
+ status = libspdm_get_certificate (spdm_context , NULL , 0 , & cert_chain_size ,
4259
+ cert_chain );
4260
+ assert_int_equal (status , LIBSPDM_STATUS_SUCCESS );
4261
+ assert_int_equal (spdm_context -> connection_info .peer_cert_info [0 ], m_cert_model );
4262
+
4263
+ /* Sub Case 4: CertModel Value of 0 */
4264
+ /* Value of 0 indicates either that the certificate slot does not contain any certificates or that the corresponding
4265
+ * MULTI_KEY_CONN_REQ or MULTI_KEY_CONN_RSP is false. */
4266
+ spdm_context -> connection_info .multi_key_conn_rsp = true;
4267
+ spdm_context -> connection_info .peer_cert_info [0 ] = 0 ;
4268
+ m_cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE ;
4269
+ libspdm_reset_message_b (spdm_context );
4270
+
4271
+ cert_chain_size = sizeof (cert_chain );
4272
+ libspdm_zero_mem (cert_chain , sizeof (cert_chain ));
4273
+ status = libspdm_get_certificate (spdm_context , NULL , 0 , & cert_chain_size ,
4274
+ cert_chain );
4275
+ assert_int_equal (status , LIBSPDM_STATUS_SUCCESS );
4276
+ assert_int_equal (spdm_context -> connection_info .peer_cert_info [0 ], m_cert_model );
4277
+
4278
+ free (data );
4279
+ }
4280
+
4079
4281
libspdm_test_context_t m_libspdm_requester_get_certificate_test_context = {
4080
4282
LIBSPDM_TEST_CONTEXT_VERSION ,
4081
4283
true,
@@ -4147,6 +4349,8 @@ int libspdm_requester_get_certificate_test_main(void)
4147
4349
cmocka_unit_test (libspdm_test_requester_get_certificate_case28 ),
4148
4350
/*Fail response: get the partial alias_cert model cert_chain*/
4149
4351
cmocka_unit_test (libspdm_test_requester_get_certificate_case29 ),
4352
+ /* check request attributes and response attributes*/
4353
+ cmocka_unit_test (libspdm_test_requester_get_certificate_case30 ),
4150
4354
};
4151
4355
4152
4356
libspdm_setup_test_context (& m_libspdm_requester_get_certificate_test_context );
0 commit comments