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