Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2025 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include "spdm_unit_test.h"
8 : #include "internal/libspdm_responder_lib.h"
9 :
10 : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
11 :
12 : #define CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE (64)
13 :
14 : typedef struct {
15 : spdm_message_header_t header;
16 : /* param1 == RSVD
17 : * param2 == RSVD*/
18 : uint16_t standard_id;
19 : uint8_t len;
20 : /*uint8_t vendor_id[len];*/
21 : uint16_t payload_length;
22 : /* uint8_t vendor_defined_payload[payload_length];*/
23 : } my_spdm_vendor_defined_request_msg_t;
24 :
25 1 : libspdm_return_t my_test_get_vendor_id_func(
26 : void *spdm_context,
27 : const uint32_t *session_id,
28 : uint16_t *resp_standard_id,
29 : uint8_t *resp_vendor_id_len,
30 : void *resp_vendor_id)
31 : {
32 1 : *resp_standard_id = 6;
33 1 : *resp_vendor_id_len = 2;
34 1 : ((uint8_t*)resp_vendor_id)[0] = 0xAA;
35 1 : ((uint8_t*)resp_vendor_id)[1] = 0xAA;
36 :
37 1 : return LIBSPDM_STATUS_SUCCESS;
38 : }
39 :
40 1 : libspdm_return_t my_test_get_response_func(
41 : void *spdm_context, const uint32_t *session_id, bool is_app_message,
42 : size_t request_size, const void *request, size_t *response_size,
43 : void *response)
44 : {
45 : /* response message size is greater than the sending transmit buffer size of responder */
46 1 : *response_size = CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE + 1;
47 1 : return LIBSPDM_STATUS_SUCCESS;
48 : }
49 :
50 1 : libspdm_return_t my_test_get_response_func2(
51 : void *spdm_context,
52 : const uint32_t *session_id,
53 : uint16_t req_standard_id,
54 : uint8_t req_vendor_id_len,
55 : const void *req_vendor_id,
56 : uint32_t req_size,
57 : const void *req_data,
58 : uint32_t *resp_size,
59 : void *resp_data)
60 : {
61 : /* response message size is greater than the sending transmit buffer size of responder */
62 1 : *resp_size = CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE + 1;
63 1 : return LIBSPDM_STATUS_SUCCESS;
64 : }
65 :
66 : /**
67 : * Test 1: Test Responder Receive Send flow triggers chunk get mode
68 : * if response buffer is larger than requester data_transfer_size.
69 : **/
70 1 : void libspdm_test_responder_receive_send_rsp_case1(void** state)
71 : {
72 : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
73 : /* This test case is partially copied from test_requester_get_measurement_case4 */
74 : libspdm_return_t status;
75 : libspdm_test_context_t* spdm_test_context;
76 : libspdm_context_t* spdm_context;
77 : size_t response_size;
78 : uint8_t* response;
79 : spdm_error_response_t* spdm_response;
80 : spdm_get_measurements_request_t spdm_request;
81 : void* message;
82 : size_t message_size;
83 : void* data;
84 : size_t data_size;
85 : void* hash;
86 : size_t hash_size;
87 : uint32_t transport_header_size;
88 : uint8_t chunk_handle;
89 :
90 1 : spdm_test_context = *state;
91 1 : spdm_context = spdm_test_context->spdm_context;
92 1 : spdm_test_context->case_id = 1;
93 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
94 : SPDM_VERSION_NUMBER_SHIFT_BIT;
95 :
96 1 : spdm_context->connection_info.connection_state =
97 : LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
98 :
99 1 : spdm_context->local_context.capability.flags |=
100 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
101 : | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
102 1 : spdm_context->connection_info.capability.flags |=
103 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
104 :
105 1 : libspdm_read_responder_public_certificate_chain(
106 : m_libspdm_use_hash_algo,
107 : m_libspdm_use_asym_algo, &data,
108 : &data_size,
109 : &hash, &hash_size);
110 :
111 1 : spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
112 1 : spdm_context->local_context.local_cert_chain_provision[0] = data;
113 :
114 1 : libspdm_reset_message_m(spdm_context, NULL);
115 :
116 1 : spdm_context->connection_info.algorithm.measurement_spec =
117 : m_libspdm_use_measurement_spec;
118 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
119 : m_libspdm_use_measurement_hash_algo;
120 1 : spdm_context->connection_info.algorithm.base_hash_algo =
121 : m_libspdm_use_hash_algo;
122 1 : spdm_context->connection_info.algorithm.base_asym_algo =
123 : m_libspdm_use_asym_algo;
124 :
125 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
126 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
127 : libspdm_copy_mem(
128 : spdm_context->connection_info.peer_used_cert_chain[0].buffer,
129 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
130 : data, data_size);
131 : #else
132 1 : libspdm_hash_all(
133 : spdm_context->connection_info.algorithm.base_hash_algo,
134 : data, data_size,
135 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
136 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
137 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
138 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
139 : spdm_context->connection_info.algorithm.base_hash_algo,
140 : spdm_context->connection_info.algorithm.base_asym_algo,
141 : data, data_size,
142 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
143 : #endif
144 :
145 1 : spdm_context->connection_info.capability.data_transfer_size =
146 : CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
147 :
148 1 : spdm_context->connection_info.capability.max_spdm_msg_size =
149 : LIBSPDM_MAX_SPDM_MSG_SIZE;
150 :
151 1 : libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
152 1 : spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
153 1 : spdm_request.header.request_response_code = SPDM_GET_MEASUREMENTS;
154 1 : spdm_request.header.param1 =
155 : SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
156 1 : spdm_request.header.param2 =
157 : SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS;
158 1 : spdm_request.slot_id_param = 0;
159 :
160 1 : libspdm_copy_mem(spdm_context->last_spdm_request,
161 1 : libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
162 : &spdm_request, sizeof(spdm_request));
163 1 : spdm_context->last_spdm_request_size = sizeof(spdm_request);
164 :
165 1 : assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
166 1 : libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
167 1 : response = message;
168 1 : response_size = message_size;
169 1 : libspdm_zero_mem(response, response_size);
170 :
171 1 : status = libspdm_build_response(spdm_context, NULL, false,
172 : &response_size, (void**)&response);
173 :
174 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
175 1 : transport_header_size = spdm_context->local_context.capability.transport_header_size;
176 :
177 : /* Verify responder returned error large response with chunk_handle == 1
178 : * and responder is in chunking mode (get.chunk_in_use). */
179 1 : spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
180 1 : assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
181 1 : assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
182 1 : assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
183 1 : assert_int_equal(spdm_response->header.param2, 0);
184 :
185 1 : chunk_handle = *(uint8_t*)(spdm_response + 1);
186 1 : assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
187 1 : assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
188 1 : libspdm_release_sender_buffer(spdm_context);
189 :
190 1 : free(data);
191 1 : libspdm_reset_message_m(spdm_context, NULL);
192 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
193 : #else
194 1 : libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo,
195 : spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
196 : #endif
197 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
198 1 : }
199 :
200 : /**
201 : * Test 2: Test Responder Receive Send flow triggers chunk get mode
202 : * if response message size is larger than responder sending transmit buffer size.
203 : **/
204 1 : void libspdm_test_responder_receive_send_rsp_case2(void** state)
205 : {
206 : libspdm_return_t status;
207 : libspdm_test_context_t* spdm_test_context;
208 : libspdm_context_t* spdm_context;
209 : size_t response_size;
210 : uint8_t* response;
211 : spdm_error_response_t* spdm_response;
212 : my_spdm_vendor_defined_request_msg_t spdm_request;
213 : void* message;
214 : size_t message_size;
215 : uint32_t transport_header_size;
216 : uint8_t chunk_handle;
217 :
218 1 : spdm_test_context = *state;
219 1 : spdm_context = spdm_test_context->spdm_context;
220 1 : spdm_test_context->case_id = 2;
221 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
222 : SPDM_VERSION_NUMBER_SHIFT_BIT;
223 :
224 1 : spdm_context->connection_info.connection_state =
225 : LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
226 :
227 1 : spdm_context->local_context.capability.flags |=
228 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
229 : | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
230 1 : spdm_context->connection_info.capability.flags |=
231 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
232 :
233 : /* The local Responder transmit buffer size for sending a single and complete SPDM message */
234 1 : spdm_context->local_context.capability.sender_data_transfer_size =
235 : CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
236 : /* The peer Requester buffer size for receiving a single and complete SPDM message */
237 1 : spdm_context->connection_info.capability.data_transfer_size =
238 : LIBSPDM_DATA_TRANSFER_SIZE;
239 :
240 1 : spdm_context->connection_info.capability.max_spdm_msg_size =
241 : LIBSPDM_MAX_SPDM_MSG_SIZE;
242 :
243 1 : libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
244 1 : spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
245 1 : spdm_request.header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
246 :
247 1 : libspdm_copy_mem(spdm_context->last_spdm_request,
248 1 : libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
249 : &spdm_request, sizeof(spdm_request));
250 1 : spdm_context->last_spdm_request_size = sizeof(spdm_request);
251 :
252 1 : assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
253 1 : libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
254 :
255 1 : response = message;
256 1 : response_size = message_size;
257 1 : libspdm_zero_mem(response, response_size);
258 :
259 : /* Make response message size greater than the sending transmit buffer size of responder */
260 1 : spdm_context->get_response_func = (void *)my_test_get_response_func;
261 :
262 1 : status = libspdm_build_response(spdm_context, NULL, false,
263 : &response_size, (void**)&response);
264 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
265 1 : transport_header_size = spdm_context->local_context.capability.transport_header_size;
266 :
267 : /* Verify responder returned error large response with chunk_handle == 1
268 : * and responder is in chunking mode (get.chunk_in_use). */
269 1 : spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
270 1 : assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
271 1 : assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
272 1 : assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
273 1 : assert_int_equal(spdm_response->header.param2, 0);
274 :
275 1 : chunk_handle = *(uint8_t*)(spdm_response + 1);
276 1 : assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
277 1 : assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
278 1 : libspdm_release_sender_buffer(spdm_context);
279 1 : }
280 :
281 :
282 : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
283 : /**
284 : * Test 3: Test Responder Receive Send flow triggers chunk get mode
285 : * if response message size is larger than responder sending transmit buffer size.
286 : **/
287 1 : void libspdm_test_responder_receive_send_rsp_case3(void** state)
288 : {
289 : libspdm_return_t status;
290 : libspdm_test_context_t* spdm_test_context;
291 : libspdm_context_t* spdm_context;
292 : size_t response_size;
293 : uint8_t* response;
294 : spdm_error_response_t* spdm_response;
295 : my_spdm_vendor_defined_request_msg_t spdm_request;
296 : void* message;
297 : size_t message_size;
298 : uint32_t transport_header_size;
299 : uint8_t chunk_handle;
300 :
301 1 : spdm_test_context = *state;
302 1 : spdm_context = spdm_test_context->spdm_context;
303 1 : spdm_test_context->case_id = 2;
304 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
305 : SPDM_VERSION_NUMBER_SHIFT_BIT;
306 :
307 1 : spdm_context->connection_info.connection_state =
308 : LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
309 :
310 1 : spdm_context->local_context.capability.flags |=
311 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
312 : | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
313 1 : spdm_context->connection_info.capability.flags |=
314 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
315 :
316 : /* The local Responder transmit buffer size for sending a single and complete SPDM message */
317 1 : spdm_context->local_context.capability.sender_data_transfer_size =
318 : CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
319 : /* The peer Requester buffer size for receiving a single and complete SPDM message */
320 1 : spdm_context->connection_info.capability.data_transfer_size =
321 : LIBSPDM_DATA_TRANSFER_SIZE;
322 :
323 1 : spdm_context->connection_info.capability.max_spdm_msg_size =
324 : LIBSPDM_MAX_SPDM_MSG_SIZE;
325 :
326 1 : libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
327 1 : spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
328 1 : spdm_request.header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
329 :
330 1 : libspdm_copy_mem(spdm_context->last_spdm_request,
331 1 : libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
332 : &spdm_request, sizeof(spdm_request));
333 1 : spdm_context->last_spdm_request_size = sizeof(spdm_request);
334 :
335 1 : assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
336 1 : libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
337 :
338 1 : response = message;
339 1 : response_size = message_size;
340 1 : libspdm_zero_mem(response, response_size);
341 :
342 : /* Make response message size greater than the sending transmit buffer size of responder */
343 1 : libspdm_register_vendor_get_id_callback_func(spdm_context, my_test_get_vendor_id_func);
344 1 : libspdm_register_vendor_callback_func(spdm_context, my_test_get_response_func2);
345 :
346 1 : status = libspdm_build_response(spdm_context, NULL, false,
347 : &response_size, (void**)&response);
348 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
349 1 : transport_header_size = spdm_context->local_context.capability.transport_header_size;
350 :
351 : /* Verify responder returned error large response with chunk_handle == 1
352 : * and responder is in chunking mode (get.chunk_in_use). */
353 1 : spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
354 1 : assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
355 1 : assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
356 1 : assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
357 1 : assert_int_equal(spdm_response->header.param2, 0);
358 :
359 1 : chunk_handle = *(uint8_t*)(spdm_response + 1);
360 1 : assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
361 1 : assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
362 1 : libspdm_release_sender_buffer(spdm_context);
363 1 : }
364 : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
365 :
366 : /**
367 : * Test 4: Test Responder Receive Send flow triggers chunk get mode
368 : * if response buffer is larger than requester max_spdm_msg_size.
369 : * expect: SPDM_ERROR_CODE_RESPONSE_TOO_LARGE
370 : **/
371 1 : void libspdm_test_responder_receive_send_rsp_case4(void** state)
372 : {
373 : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
374 : /* This test case is partially copied from test_requester_get_measurement_case4 */
375 : libspdm_return_t status;
376 : libspdm_test_context_t* spdm_test_context;
377 : libspdm_context_t* spdm_context;
378 : size_t response_size;
379 : uint8_t* response;
380 : spdm_error_response_t* spdm_response;
381 : spdm_get_measurements_request_t spdm_request;
382 : void* message;
383 : size_t message_size;
384 : void* data;
385 : size_t data_size;
386 : void* hash;
387 : size_t hash_size;
388 : uint32_t transport_header_size;
389 :
390 1 : spdm_test_context = *state;
391 1 : spdm_context = spdm_test_context->spdm_context;
392 1 : spdm_test_context->case_id = 3;
393 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
394 : SPDM_VERSION_NUMBER_SHIFT_BIT;
395 :
396 1 : spdm_context->connection_info.connection_state =
397 : LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
398 :
399 1 : spdm_context->local_context.capability.flags |=
400 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
401 : | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
402 1 : spdm_context->connection_info.capability.flags |=
403 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
404 :
405 1 : libspdm_read_responder_public_certificate_chain(
406 : m_libspdm_use_hash_algo,
407 : m_libspdm_use_asym_algo, &data,
408 : &data_size,
409 : &hash, &hash_size);
410 :
411 1 : spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
412 1 : spdm_context->local_context.local_cert_chain_provision[0] = data;
413 :
414 1 : libspdm_reset_message_m(spdm_context, NULL);
415 :
416 1 : spdm_context->connection_info.algorithm.measurement_spec =
417 : m_libspdm_use_measurement_spec;
418 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
419 : m_libspdm_use_measurement_hash_algo;
420 1 : spdm_context->connection_info.algorithm.base_hash_algo =
421 : m_libspdm_use_hash_algo;
422 1 : spdm_context->connection_info.algorithm.base_asym_algo =
423 : m_libspdm_use_asym_algo;
424 :
425 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
426 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
427 : libspdm_copy_mem(
428 : spdm_context->connection_info.peer_used_cert_chain[0].buffer,
429 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
430 : data, data_size);
431 : #else
432 1 : libspdm_hash_all(
433 : spdm_context->connection_info.algorithm.base_hash_algo,
434 : data, data_size,
435 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
436 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
437 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
438 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
439 : spdm_context->connection_info.algorithm.base_hash_algo,
440 : spdm_context->connection_info.algorithm.base_asym_algo,
441 : data, data_size,
442 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
443 : #endif
444 :
445 1 : spdm_context->connection_info.capability.data_transfer_size =
446 : CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
447 :
448 : /*set requester small max_spdm_msg_size*/
449 1 : spdm_context->connection_info.capability.max_spdm_msg_size = 100;
450 :
451 1 : libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
452 1 : spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
453 1 : spdm_request.header.request_response_code = SPDM_GET_MEASUREMENTS;
454 1 : spdm_request.header.param1 =
455 : SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
456 1 : spdm_request.header.param2 =
457 : SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS;
458 1 : spdm_request.slot_id_param = 0;
459 :
460 1 : libspdm_copy_mem(spdm_context->last_spdm_request,
461 1 : libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
462 : &spdm_request, sizeof(spdm_request));
463 1 : spdm_context->last_spdm_request_size = sizeof(spdm_request);
464 :
465 1 : assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
466 1 : libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
467 1 : response = message;
468 1 : response_size = message_size;
469 1 : libspdm_zero_mem(response, response_size);
470 :
471 1 : status = libspdm_build_response(spdm_context, NULL, false,
472 : &response_size, (void**)&response);
473 :
474 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
475 1 : transport_header_size = spdm_context->local_context.capability.transport_header_size;
476 :
477 : /* Verify responder returned SPDM_ERROR_CODE_RESPONSE_TOO_LARGE response with chunk_handle == 0
478 : * and responder is not in chunking mode (get.chunk_in_use). */
479 1 : spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
480 1 : assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
481 1 : assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
482 :
483 1 : assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_RESPONSE_TOO_LARGE);
484 1 : assert_int_equal(spdm_response->header.param2, 0);
485 1 : assert_int_equal(0, spdm_context->chunk_context.get.chunk_handle);
486 1 : assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
487 1 : libspdm_release_sender_buffer(spdm_context);
488 :
489 1 : free(data);
490 1 : libspdm_reset_message_m(spdm_context, NULL);
491 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
492 : #else
493 1 : libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo,
494 : spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
495 : #endif
496 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
497 1 : }
498 :
499 1 : int libspdm_responder_receive_send_test_main(void)
500 : {
501 1 : const struct CMUnitTest spdm_responder_receive_send_tests[] = {
502 : /* response message size is larger than requester data_transfer_size */
503 : cmocka_unit_test(libspdm_test_responder_receive_send_rsp_case1),
504 : /* response message size is larger than responder sending transmit buffer size */
505 : cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case2,
506 : libspdm_unit_test_group_setup),
507 : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
508 : /* response message size is larger than responder sending transmit buffer size
509 : * using the new Vendor Defined Message API */
510 : cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case3,
511 : libspdm_unit_test_group_setup),
512 : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
513 : /* response message size is larger than requester max_spdm_msg_size */
514 : cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case4,
515 : libspdm_unit_test_group_setup),
516 : };
517 :
518 1 : libspdm_test_context_t test_context = {
519 : LIBSPDM_TEST_CONTEXT_VERSION,
520 : false,
521 : };
522 :
523 1 : libspdm_setup_test_context(&test_context);
524 :
525 1 : return cmocka_run_group_tests(spdm_responder_receive_send_tests,
526 : libspdm_unit_test_group_setup,
527 : libspdm_unit_test_group_teardown);
528 : }
529 :
530 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
|