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_requester_lib.h"
9 :
10 : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
11 :
12 : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
13 : static uint8_t temp_buf[LIBSPDM_RECEIVER_BUFFER_SIZE];
14 : static uint8_t temp_buff[LIBSPDM_MAX_SPDM_MSG_SIZE];
15 :
16 18 : libspdm_return_t libspdm_requester_encap_request_test_send_message(void *spdm_context,
17 : size_t request_size,
18 : const void *request,
19 : uint64_t timeout)
20 : {
21 : libspdm_test_context_t *spdm_test_context;
22 :
23 18 : spdm_test_context = libspdm_get_test_context();
24 : static uint8_t sub_index = 0;
25 : spdm_deliver_encapsulated_response_request_t *spdm_deliver_encapsulated_response_request;
26 : uint8_t send_temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
27 : size_t decode_message_size;
28 : spdm_error_response_t *spdm_response;
29 : libspdm_return_t status;
30 : uint32_t *message_session_id;
31 : bool is_message_app_message;
32 : uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
33 :
34 18 : memcpy(message_buffer, request, request_size);
35 :
36 18 : switch (spdm_test_context->case_id)
37 : {
38 1 : case 0x1:
39 1 : return LIBSPDM_STATUS_SEND_FAIL;
40 2 : case 0x2:
41 2 : return LIBSPDM_STATUS_SUCCESS;
42 0 : case 0x3:
43 0 : return LIBSPDM_STATUS_SUCCESS;
44 1 : case 0x4:
45 1 : return LIBSPDM_STATUS_SUCCESS;
46 2 : case 0x5:
47 2 : return LIBSPDM_STATUS_SUCCESS;
48 0 : case 0x6:
49 0 : return LIBSPDM_STATUS_SUCCESS;
50 2 : case 0x7:
51 2 : return LIBSPDM_STATUS_SUCCESS;
52 2 : case 0x8:
53 2 : return LIBSPDM_STATUS_SUCCESS;
54 2 : case 0x9:
55 2 : return LIBSPDM_STATUS_SUCCESS;
56 2 : case 0xA:
57 : {
58 2 : if (sub_index == 0) {
59 1 : sub_index++;
60 1 : } else if (sub_index == 1) {
61 1 : sub_index = 0;
62 1 : message_session_id = NULL;
63 1 : is_message_app_message = false;
64 1 : spdm_deliver_encapsulated_response_request = (void*) send_temp_buf;
65 1 : decode_message_size = sizeof(spdm_deliver_encapsulated_response_request_t) +
66 : sizeof(spdm_error_response_t);
67 1 : status = libspdm_transport_test_decode_message(spdm_context, &message_session_id,
68 : &is_message_app_message, true,
69 : request_size, message_buffer,
70 : &decode_message_size,
71 : (void **)&spdm_deliver_encapsulated_response_request);
72 1 : if (LIBSPDM_STATUS_IS_ERROR(status)) {
73 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "transport_decode_message - %xu\n",
74 : status));
75 : }
76 1 : spdm_response = (void*) (spdm_deliver_encapsulated_response_request + 1);
77 1 : if (spdm_response->header.request_response_code != SPDM_ERROR) {
78 0 : return LIBSPDM_STATUS_SEND_FAIL;
79 : }
80 1 : if (spdm_response->header.param1 != SPDM_ERROR_CODE_UNEXPECTED_REQUEST) { /* Here check ErrorCode should be UnexpectedRequestd */
81 0 : return LIBSPDM_STATUS_SEND_FAIL;
82 : }
83 1 : if (spdm_response->header.param2 != 0) {
84 0 : return LIBSPDM_STATUS_SEND_FAIL;
85 : }
86 : }
87 2 : return LIBSPDM_STATUS_SUCCESS;
88 : }
89 1 : case 0xb:
90 1 : return LIBSPDM_STATUS_SUCCESS;
91 1 : case 0xc:
92 1 : return LIBSPDM_STATUS_SUCCESS;
93 2 : case 0xD:
94 2 : return LIBSPDM_STATUS_SUCCESS;
95 0 : default:
96 0 : return LIBSPDM_STATUS_SEND_FAIL;
97 : }
98 : }
99 :
100 17 : libspdm_return_t libspdm_requester_encap_request_test_receive_message(
101 : void *spdm_context, size_t *response_size,
102 : void **response, uint64_t timeout)
103 : {
104 :
105 : libspdm_test_context_t *spdm_test_context;
106 : spdm_encapsulated_request_response_t *libspdm_encapsulated_request_response;
107 : uint8_t *digest;
108 : size_t temp_buf_size;
109 : uint8_t *temp_buf_ptr;
110 :
111 17 : spdm_test_context = libspdm_get_test_context();
112 : static uint8_t sub_index = 0;
113 17 : switch (spdm_test_context->case_id)
114 : {
115 0 : case 0x1:
116 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
117 :
118 2 : case 0x2:
119 : {
120 : spdm_digest_response_t *spdm_response;
121 :
122 : ((libspdm_context_t *)spdm_context)
123 2 : ->connection_info.algorithm.base_hash_algo =
124 : m_libspdm_use_hash_algo;
125 2 : if (sub_index == 0) {
126 1 : temp_buf_size = sizeof(spdm_digest_response_t) +
127 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo) +
128 : sizeof(spdm_encapsulated_request_response_t);
129 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
130 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
131 1 : libspdm_encapsulated_request_response = (void*) temp_buf_ptr;
132 1 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
133 1 : libspdm_encapsulated_request_response->header.request_response_code =
134 : SPDM_ENCAPSULATED_REQUEST;
135 1 : libspdm_encapsulated_request_response->header.param1 = 0;
136 1 : libspdm_encapsulated_request_response->header.param2 = 0;
137 :
138 1 : spdm_response = (void *)(temp_buf_ptr
139 : + sizeof(spdm_encapsulated_request_response_t));
140 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
141 1 : spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
142 1 : spdm_response->header.param1 = 0;
143 1 : spdm_response->header.param2 = 0;
144 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
145 : sizeof(m_libspdm_local_certificate_chain),
146 : (uint8_t)(0xFF));
147 :
148 1 : digest = (void *)(spdm_response + 1);
149 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
150 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
151 1 : spdm_response->header.param2 |= (0x01 << 0);
152 1 : sub_index++;
153 1 : } else if (sub_index == 1) {
154 : /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
155 : spdm_message_header_t *spdm_encapsulated_response_ack_response;
156 1 : temp_buf_size = sizeof(spdm_message_header_t);
157 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
158 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
159 1 : spdm_encapsulated_response_ack_response = (void*) temp_buf_ptr;
160 1 : spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
161 1 : spdm_encapsulated_response_ack_response->request_response_code =
162 : SPDM_ENCAPSULATED_RESPONSE_ACK;
163 1 : spdm_encapsulated_response_ack_response->param1 = 0;
164 1 : spdm_encapsulated_response_ack_response->param2 =
165 : SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
166 1 : sub_index = 0;
167 : } else {
168 0 : temp_buf_size = 0;
169 0 : temp_buf_ptr = NULL;
170 : }
171 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
172 : temp_buf_size, temp_buf_ptr,
173 : response_size, response);
174 : }
175 2 : return LIBSPDM_STATUS_SUCCESS;
176 0 : case 0x3:
177 : {
178 : spdm_digest_response_t *spdm_response;
179 :
180 : ((libspdm_context_t *)spdm_context)
181 0 : ->connection_info.algorithm.base_hash_algo =
182 : m_libspdm_use_hash_algo;
183 0 : if (sub_index == 0) {
184 0 : temp_buf_size = sizeof(spdm_digest_response_t) +
185 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo) +
186 : sizeof(spdm_encapsulated_request_response_t);
187 0 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
188 0 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
189 0 : libspdm_encapsulated_request_response = (void *) temp_buf_ptr;
190 0 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
191 0 : libspdm_encapsulated_request_response->header.request_response_code =
192 : SPDM_ENCAPSULATED_REQUEST;
193 0 : libspdm_encapsulated_request_response->header.param1 = 0;
194 0 : libspdm_encapsulated_request_response->header.param2 = 0;
195 :
196 0 : spdm_response =
197 : (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
198 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
199 0 : spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
200 0 : spdm_response->header.param1 = 0;
201 0 : spdm_response->header.param2 = 0;
202 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
203 : sizeof(m_libspdm_local_certificate_chain),
204 : (uint8_t)(0xFF));
205 :
206 0 : digest = (void *)(spdm_response + 1);
207 0 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
208 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
209 0 : spdm_response->header.param2 |= (0x01 << 0);
210 0 : sub_index++;
211 0 : } else if (sub_index == 1) {
212 : /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
213 : spdm_encapsulated_response_ack_response_t *spdm_encapsulated_response_ack_response;
214 0 : temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
215 0 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
216 0 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
217 0 : spdm_encapsulated_response_ack_response = (void *) temp_buf_ptr;
218 0 : spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
219 0 : spdm_encapsulated_response_ack_response->header.request_response_code =
220 : SPDM_ENCAPSULATED_RESPONSE_ACK;
221 0 : spdm_encapsulated_response_ack_response->header.param1 = 0;
222 0 : spdm_encapsulated_response_ack_response->header.param2 =
223 : SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
224 0 : sub_index = 0;
225 : } else {
226 0 : temp_buf_size = 0;
227 0 : temp_buf_ptr = NULL;
228 : }
229 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
230 : temp_buf_size, temp_buf_ptr,
231 : response_size, response);
232 : }
233 0 : return LIBSPDM_STATUS_SUCCESS;
234 1 : case 0x4:
235 : {
236 : spdm_digest_response_t *spdm_response;
237 :
238 : ((libspdm_context_t *)spdm_context)
239 1 : ->connection_info.algorithm.base_hash_algo =
240 : m_libspdm_use_hash_algo;
241 1 : temp_buf_size = sizeof(spdm_encapsulated_request_response_t);
242 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
243 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
244 1 : spdm_response = (void *) temp_buf_ptr;
245 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
246 1 : spdm_response->header.request_response_code = SPDM_ENCAPSULATED_REQUEST;
247 1 : spdm_response->header.param1 = 0;
248 1 : spdm_response->header.param2 = 0;
249 :
250 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
251 : temp_buf_size, temp_buf_ptr,
252 : response_size, response);
253 : }
254 1 : return LIBSPDM_STATUS_SUCCESS;
255 2 : case 0x5:
256 : {
257 : spdm_digest_response_t *spdm_response;
258 :
259 : ((libspdm_context_t *)spdm_context)
260 2 : ->connection_info.algorithm.base_hash_algo =
261 : m_libspdm_use_hash_algo;
262 2 : if (sub_index == 0) {
263 1 : temp_buf_size = sizeof(spdm_digest_response_t) +
264 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo) +
265 : sizeof(spdm_encapsulated_request_response_t);
266 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
267 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
268 1 : libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
269 1 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
270 1 : libspdm_encapsulated_request_response->header.request_response_code =
271 : SPDM_ENCAPSULATED_REQUEST;
272 1 : libspdm_encapsulated_request_response->header.param1 = 0;
273 1 : libspdm_encapsulated_request_response->header.param2 = 0;
274 :
275 1 : spdm_response =
276 : (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
277 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
278 1 : spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
279 1 : spdm_response->header.param1 = 0;
280 1 : spdm_response->header.param2 = 0;
281 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
282 : sizeof(m_libspdm_local_certificate_chain),
283 : (uint8_t)(0xFF));
284 :
285 1 : digest = (void *)(spdm_response + 1);
286 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
287 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
288 1 : spdm_response->header.param2 |= (0x01 << 0);
289 :
290 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
291 : temp_buf_size, temp_buf_ptr,
292 : response_size, response);
293 1 : sub_index++;
294 1 : } else if (sub_index == 1) {
295 : size_t temp_buff_size;
296 : uint8_t *temp_buff_ptr;
297 :
298 1 : temp_buff_size = sizeof(spdm_message_header_t);
299 1 : libspdm_zero_mem(temp_buff, LIBSPDM_MAX_SPDM_MSG_SIZE);
300 1 : temp_buff_ptr = temp_buff + sizeof(libspdm_test_message_header_t);
301 :
302 1 : sub_index = 0;
303 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
304 : temp_buff_size, temp_buff_ptr,
305 : response_size, response);
306 : }
307 : }
308 2 : return LIBSPDM_STATUS_SUCCESS;
309 0 : case 0x6:
310 : {
311 : spdm_digest_response_t *spdm_response;
312 :
313 : ((libspdm_context_t *)spdm_context)
314 0 : ->connection_info.algorithm.base_hash_algo =
315 : m_libspdm_use_hash_algo;
316 0 : if (sub_index == 0) {
317 0 : temp_buf_size =
318 : sizeof(spdm_digest_response_t) +
319 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo) +
320 : sizeof(spdm_encapsulated_request_response_t);
321 0 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
322 0 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
323 :
324 0 : libspdm_encapsulated_request_response = (void*) temp_buf_ptr;
325 0 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
326 0 : libspdm_encapsulated_request_response->header.request_response_code =
327 : SPDM_ENCAPSULATED_REQUEST;
328 0 : libspdm_encapsulated_request_response->header.param1 = 0;
329 0 : libspdm_encapsulated_request_response->header.param2 = 0;
330 :
331 0 : spdm_response =
332 : (void*) (temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
333 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
334 0 : spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
335 0 : spdm_response->header.param1 = 0;
336 0 : spdm_response->header.param2 = 0;
337 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
338 : sizeof(m_libspdm_local_certificate_chain),
339 : (uint8_t) (0xFF));
340 :
341 0 : digest = (void*) (spdm_response + 1);
342 0 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
343 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
344 0 : spdm_response->header.param2 |= (0x01 << 0);
345 0 : sub_index++;
346 0 : } else if (sub_index == 1) {
347 : spdm_encapsulated_response_ack_response_t* spdm_encapsulated_response_ack_response;
348 0 : temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
349 0 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
350 0 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
351 0 : spdm_encapsulated_response_ack_response = (void*) temp_buf_ptr;
352 0 : spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
353 0 : spdm_encapsulated_response_ack_response->header.request_response_code =
354 : SPDM_ENCAPSULATED_RESPONSE_ACK;
355 0 : spdm_encapsulated_response_ack_response->header.param1 = 0;
356 0 : spdm_encapsulated_response_ack_response->header.param2 = 0;
357 0 : sub_index = 0;
358 : } else {
359 0 : temp_buf_size = 0;
360 0 : temp_buf_ptr = NULL;
361 : }
362 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
363 : temp_buf_size, temp_buf_ptr,
364 : response_size, response);
365 : }
366 0 : return LIBSPDM_STATUS_SUCCESS;
367 2 : case 0x7:
368 : {
369 : spdm_digest_response_t *spdm_response;
370 :
371 : ((libspdm_context_t *)spdm_context)
372 2 : ->connection_info.algorithm.base_hash_algo =
373 : m_libspdm_use_hash_algo;
374 2 : if (sub_index == 0) {
375 1 : temp_buf_size = sizeof(spdm_digest_response_t) +
376 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo) +
377 : sizeof(spdm_encapsulated_request_response_t);
378 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
379 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
380 1 : libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
381 1 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
382 1 : libspdm_encapsulated_request_response->header.request_response_code =
383 : SPDM_ENCAPSULATED_REQUEST;
384 1 : libspdm_encapsulated_request_response->header.param1 = 0;
385 1 : libspdm_encapsulated_request_response->header.param2 = 0;
386 :
387 1 : spdm_response =
388 : (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
389 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
390 1 : spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
391 1 : spdm_response->header.param1 = 0;
392 1 : spdm_response->header.param2 = 0;
393 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
394 : sizeof(m_libspdm_local_certificate_chain),
395 : (uint8_t)(0xFF));
396 :
397 1 : digest = (void *)(spdm_response + 1);
398 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
399 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
400 1 : spdm_response->header.param2 |= (0x01 << 0);
401 1 : sub_index++;
402 1 : } else if (sub_index == 1) {
403 : spdm_encapsulated_response_ack_response_t *spdm_encapsulated_response_ack_response;
404 1 : temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
405 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
406 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
407 1 : spdm_encapsulated_response_ack_response = (void *) temp_buf_ptr;
408 1 : spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
409 1 : spdm_encapsulated_response_ack_response->header.request_response_code =
410 : SPDM_ENCAPSULATED_RESPONSE_ACK;
411 1 : spdm_encapsulated_response_ack_response->header.param1 = 0;
412 1 : spdm_encapsulated_response_ack_response->header.param2 =
413 : SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_REQ_SLOT_NUMBER;
414 1 : sub_index = 0;
415 : } else {
416 0 : temp_buf_size = 0;
417 0 : temp_buf_ptr = NULL;
418 : }
419 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
420 : temp_buf_size, temp_buf_ptr,
421 : response_size, response);
422 : }
423 2 : return LIBSPDM_STATUS_SUCCESS;
424 2 : case 0x8:
425 : {
426 : spdm_get_certificate_request_t *spdm_response;
427 :
428 : ((libspdm_context_t *)spdm_context)
429 2 : ->connection_info.algorithm.base_hash_algo =
430 : m_libspdm_use_hash_algo;
431 2 : if (sub_index == 0) {
432 1 : temp_buf_size = sizeof(spdm_get_certificate_request_t) +
433 : sizeof(spdm_encapsulated_request_response_t);
434 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
435 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
436 1 : libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
437 1 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
438 1 : libspdm_encapsulated_request_response->header.request_response_code =
439 : SPDM_ENCAPSULATED_REQUEST;
440 1 : libspdm_encapsulated_request_response->header.param1 = 0;
441 1 : libspdm_encapsulated_request_response->header.param2 = 0;
442 :
443 1 : spdm_response =
444 : (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
445 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
446 1 : spdm_response->header.request_response_code = SPDM_GET_CERTIFICATE;
447 1 : spdm_response->header.param1 = 0;
448 1 : spdm_response->header.param2 = 0;
449 1 : spdm_response->offset = 0;
450 1 : spdm_response->length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
451 1 : sub_index++;
452 1 : } else if (sub_index == 1) {
453 : /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
454 : spdm_message_header_t *spdm_encapsulated_response_ack_response;
455 1 : temp_buf_size = sizeof(spdm_message_header_t);
456 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
457 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
458 1 : spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
459 1 : spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
460 1 : spdm_encapsulated_response_ack_response->request_response_code =
461 : SPDM_ENCAPSULATED_RESPONSE_ACK;
462 1 : spdm_encapsulated_response_ack_response->param1 = 0;
463 1 : spdm_encapsulated_response_ack_response->param2 =
464 : SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
465 1 : sub_index = 0;
466 : } else {
467 0 : temp_buf_size = 0;
468 0 : temp_buf_ptr = NULL;
469 : }
470 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
471 : temp_buf_size, temp_buf_ptr,
472 : response_size, response);
473 : }
474 2 : return LIBSPDM_STATUS_SUCCESS;
475 :
476 2 : case 0x9:
477 : {
478 : spdm_key_update_request_t *spdm_response;
479 :
480 : ((libspdm_context_t *)spdm_context)
481 2 : ->connection_info.algorithm.base_hash_algo =
482 : m_libspdm_use_hash_algo;
483 2 : if (sub_index == 0) {
484 1 : temp_buf_size = sizeof(spdm_key_update_request_t) +
485 : sizeof(spdm_encapsulated_request_response_t);
486 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
487 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
488 1 : libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
489 1 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
490 1 : libspdm_encapsulated_request_response->header.request_response_code =
491 : SPDM_ENCAPSULATED_REQUEST;
492 1 : libspdm_encapsulated_request_response->header.param1 = 0;
493 1 : libspdm_encapsulated_request_response->header.param2 = 0;
494 :
495 1 : spdm_response =
496 : (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
497 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
498 1 : spdm_response->header.request_response_code = SPDM_KEY_UPDATE;
499 1 : spdm_response->header.param1 = SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
500 1 : spdm_response->header.param2 = 0x3;
501 :
502 1 : sub_index++;
503 1 : } else if (sub_index == 1) {
504 : /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
505 : spdm_message_header_t *spdm_encapsulated_response_ack_response;
506 1 : temp_buf_size = sizeof(spdm_message_header_t);
507 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
508 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
509 1 : spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
510 1 : spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
511 1 : spdm_encapsulated_response_ack_response->request_response_code =
512 : SPDM_ENCAPSULATED_RESPONSE_ACK;
513 1 : spdm_encapsulated_response_ack_response->param1 = 0;
514 1 : spdm_encapsulated_response_ack_response->param2 =
515 : SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
516 1 : sub_index = 0;
517 : } else {
518 0 : temp_buf_size = 0;
519 0 : temp_buf_ptr = NULL;
520 : }
521 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
522 : temp_buf_size, temp_buf_ptr,
523 : response_size, response);
524 : }
525 2 : return LIBSPDM_STATUS_SUCCESS;
526 :
527 2 : case 0xA:
528 : {
529 : spdm_get_encapsulated_request_request_t *spdm_response;
530 :
531 2 : if (sub_index == 0) {
532 1 : temp_buf_size = sizeof(spdm_encapsulated_request_response_t) +
533 : sizeof(spdm_get_encapsulated_request_request_t);
534 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
535 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
536 :
537 : /* The following is ENCAPSULATED_REQUEST response message */
538 1 : libspdm_encapsulated_request_response = (void *) temp_buf_ptr;
539 1 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
540 1 : libspdm_encapsulated_request_response->header.request_response_code =
541 : SPDM_ENCAPSULATED_REQUEST;
542 1 : libspdm_encapsulated_request_response->header.param1 = 0;
543 1 : libspdm_encapsulated_request_response->header.param2 = 0;
544 :
545 : /* The following is EncapsulatedRequest Field of the above ENCAPSULATED_REQUEST response message*/
546 1 : spdm_response =
547 : (void *)(temp_buf_ptr + sizeof(spdm_get_encapsulated_request_request_t));
548 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
549 1 : spdm_response->header.request_response_code = SPDM_GET_ENCAPSULATED_REQUEST; /* Here invalid: GET_ENCAPSULATED_REQUEST is encapsulated */
550 1 : spdm_response->header.param1 = 0;
551 1 : spdm_response->header.param2 = 0;
552 :
553 1 : sub_index++;
554 1 : } else if (sub_index == 1) {
555 : spdm_message_header_t *spdm_encapsulated_response_ack_response;
556 1 : temp_buf_size = sizeof(spdm_message_header_t);
557 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
558 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
559 1 : spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
560 1 : spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
561 1 : spdm_encapsulated_response_ack_response->request_response_code =
562 : SPDM_ENCAPSULATED_RESPONSE_ACK;
563 1 : spdm_encapsulated_response_ack_response->param1 = 0;
564 1 : spdm_encapsulated_response_ack_response->param2 =
565 : SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
566 1 : sub_index = 0;
567 : } else {
568 0 : temp_buf_size = 0;
569 0 : temp_buf_ptr = NULL;
570 : }
571 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
572 : temp_buf_size, temp_buf_ptr,
573 : response_size, response);
574 : }
575 2 : return LIBSPDM_STATUS_SUCCESS;
576 :
577 1 : case 0xB:
578 : {
579 : spdm_error_response_t *spdm_response;
580 :
581 1 : temp_buf_size = sizeof(spdm_error_response_t);
582 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
583 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
584 1 : spdm_response = (void *) temp_buf_ptr;
585 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
586 1 : spdm_response->header.request_response_code = SPDM_ERROR;
587 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
588 1 : spdm_response->header.param2 = 0;
589 :
590 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
591 : temp_buf_size, temp_buf_ptr,
592 : response_size, response);
593 : }
594 1 : return LIBSPDM_STATUS_SUCCESS;
595 :
596 1 : case 0xC:
597 : {
598 : spdm_error_response_t *spdm_response;
599 :
600 1 : temp_buf_size = sizeof(spdm_error_response_t);
601 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
602 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
603 1 : spdm_response = (void *) temp_buf_ptr;
604 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
605 1 : spdm_response->header.request_response_code = SPDM_ERROR;
606 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_NO_PENDING_REQUESTS;
607 1 : spdm_response->header.param2 = 0;
608 :
609 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
610 : temp_buf_size, temp_buf_ptr,
611 : response_size, response);
612 : }
613 1 : return LIBSPDM_STATUS_SUCCESS;
614 :
615 2 : case 0xD:
616 : {
617 : spdm_get_endpoint_info_request_t *spdm_response;
618 : uint8_t *spdm_nonce;
619 :
620 : ((libspdm_context_t *)spdm_context)
621 2 : ->connection_info.algorithm.base_hash_algo =
622 : m_libspdm_use_hash_algo;
623 2 : if (sub_index == 0) {
624 1 : temp_buf_size = sizeof(spdm_encapsulated_request_response_t) +
625 : sizeof(spdm_get_endpoint_info_request_t) + SPDM_NONCE_SIZE;
626 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
627 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
628 1 : libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
629 1 : libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
630 1 : libspdm_encapsulated_request_response->header.request_response_code =
631 : SPDM_ENCAPSULATED_REQUEST;
632 1 : libspdm_encapsulated_request_response->header.param1 = 0;
633 1 : libspdm_encapsulated_request_response->header.param2 = 0;
634 :
635 1 : spdm_response =
636 : (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
637 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
638 1 : spdm_response->header.request_response_code = SPDM_GET_ENDPOINT_INFO;
639 1 : spdm_response->header.param1 =
640 : SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER;
641 1 : spdm_response->header.param2 = 0; /* slot_id */
642 1 : spdm_response->request_attributes =
643 : SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED;
644 1 : libspdm_write_uint24(spdm_response->reserved, 0);
645 1 : spdm_nonce = (uint8_t *)(spdm_response + 1);
646 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, spdm_nonce);
647 :
648 1 : sub_index++;
649 1 : } else if (sub_index == 1) {
650 : spdm_encapsulated_response_ack_response_t *spdm_encapsulated_response_ack_response;
651 1 : temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
652 1 : libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
653 1 : temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
654 1 : spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
655 1 : spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
656 1 : spdm_encapsulated_response_ack_response->header.request_response_code =
657 : SPDM_ENCAPSULATED_RESPONSE_ACK;
658 1 : spdm_encapsulated_response_ack_response->header.param1 = 0;
659 1 : spdm_encapsulated_response_ack_response->header.param2 =
660 : SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
661 1 : spdm_encapsulated_response_ack_response->ack_request_id = 0;
662 1 : libspdm_write_uint24(spdm_encapsulated_response_ack_response->reserved, 0);
663 :
664 1 : sub_index = 0;
665 : } else {
666 0 : temp_buf_size = 0;
667 0 : temp_buf_ptr = NULL;
668 : }
669 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
670 : temp_buf_size, temp_buf_ptr,
671 : response_size, response);
672 : }
673 2 : return LIBSPDM_STATUS_SUCCESS;
674 0 : default:
675 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
676 : }
677 : }
678 :
679 : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
680 1 : void libspdm_test_requester_encap_request_case1(void **State)
681 : {
682 : libspdm_return_t status;
683 : libspdm_test_context_t *spdm_test_context;
684 : libspdm_context_t *spdm_context;
685 : void *data;
686 : size_t data_size;
687 : void *hash;
688 : size_t hash_size;
689 :
690 1 : spdm_test_context = *State;
691 1 : spdm_context = spdm_test_context->spdm_context;
692 1 : spdm_test_context->case_id = 0x1;
693 :
694 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
695 : SPDM_VERSION_NUMBER_SHIFT_BIT;
696 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
697 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
698 1 : spdm_context->connection_info.capability.flags |=
699 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
700 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
701 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
702 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
703 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
704 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
705 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
706 :
707 1 : spdm_context->connection_info.capability.flags |=
708 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
709 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
710 : m_libspdm_use_asym_algo, &data,
711 : &data_size,
712 : &hash, &hash_size);
713 1 : libspdm_reset_message_a(spdm_context);
714 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
715 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
716 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
717 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
718 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
719 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
720 : data_size;
721 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
722 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
723 : data, data_size);
724 : #endif
725 :
726 1 : libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
727 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
728 1 : assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
729 1 : free(data);
730 1 : }
731 :
732 1 : void libspdm_test_requester_encap_request_case2(void **State)
733 : {
734 : libspdm_return_t status;
735 : libspdm_test_context_t *spdm_test_context;
736 : libspdm_context_t *spdm_context;
737 : void *data;
738 : size_t data_size;
739 : void *hash;
740 : size_t hash_size;
741 :
742 1 : spdm_test_context = *State;
743 1 : spdm_context = spdm_test_context->spdm_context;
744 1 : spdm_test_context->case_id = 0x2;
745 :
746 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
747 : SPDM_VERSION_NUMBER_SHIFT_BIT;
748 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
749 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
750 1 : spdm_context->connection_info.capability.flags |=
751 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
752 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
753 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
754 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
755 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
756 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
757 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
758 1 : spdm_context->connection_info.capability.flags |=
759 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
760 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
761 : m_libspdm_use_asym_algo, &data,
762 : &data_size,
763 : &hash, &hash_size);
764 1 : libspdm_reset_message_a(spdm_context);
765 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
766 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
767 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
768 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
769 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
770 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
771 : data_size;
772 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
773 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
774 : data, data_size);
775 : #endif
776 :
777 1 : libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
778 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
779 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
780 1 : free(data);
781 1 : }
782 :
783 0 : void libspdm_test_requester_encap_request_case3(void **State)
784 : {
785 0 : }
786 :
787 1 : void libspdm_test_requester_encap_request_case4(void **State)
788 : {
789 : libspdm_return_t status;
790 : libspdm_test_context_t *spdm_test_context;
791 : libspdm_context_t *spdm_context;
792 : void *data;
793 : size_t data_size;
794 : void *hash;
795 : size_t hash_size;
796 :
797 1 : spdm_test_context = *State;
798 1 : spdm_context = spdm_test_context->spdm_context;
799 1 : spdm_test_context->case_id = 0x4;
800 :
801 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
802 : SPDM_VERSION_NUMBER_SHIFT_BIT;
803 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
804 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
805 1 : spdm_context->connection_info.capability.flags |=
806 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
807 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
808 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
809 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
810 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
811 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
812 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
813 1 : spdm_context->connection_info.capability.flags |=
814 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
815 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
816 : m_libspdm_use_asym_algo, &data,
817 : &data_size,
818 : &hash, &hash_size);
819 1 : libspdm_reset_message_a(spdm_context);
820 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
821 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
822 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
823 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
824 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
825 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
826 : data_size;
827 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
828 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
829 : data, data_size);
830 : #endif
831 :
832 1 : libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
833 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
834 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
835 1 : free(data);
836 1 : }
837 :
838 1 : void libspdm_test_requester_encap_request_case5(void **State)
839 : {
840 : libspdm_return_t status;
841 : libspdm_test_context_t *spdm_test_context;
842 : libspdm_context_t *spdm_context;
843 : void *data;
844 : size_t data_size;
845 : void *hash;
846 : size_t hash_size;
847 :
848 1 : spdm_test_context = *State;
849 1 : spdm_context = spdm_test_context->spdm_context;
850 1 : spdm_test_context->case_id = 0x5;
851 :
852 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
853 : SPDM_VERSION_NUMBER_SHIFT_BIT;
854 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
855 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
856 1 : spdm_context->connection_info.capability.flags |=
857 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
858 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
859 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
860 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
861 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
862 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
863 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
864 1 : spdm_context->connection_info.capability.flags |=
865 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
866 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
867 : m_libspdm_use_asym_algo, &data,
868 : &data_size,
869 : &hash, &hash_size);
870 1 : libspdm_reset_message_a(spdm_context);
871 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
872 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
873 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
874 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
875 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
876 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
877 : data_size;
878 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
879 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
880 : data, data_size);
881 : #endif
882 :
883 1 : libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
884 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
885 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
886 1 : free(data);
887 1 : }
888 :
889 0 : void libspdm_test_requester_encap_request_case6(void **State)
890 : {
891 0 : }
892 :
893 1 : void libspdm_test_requester_encap_request_case7(void **State)
894 : {
895 : libspdm_return_t status;
896 : libspdm_test_context_t *spdm_test_context;
897 : libspdm_context_t *spdm_context;
898 : void *data;
899 : size_t data_size;
900 : void *hash;
901 : size_t hash_size;
902 :
903 1 : spdm_test_context = *State;
904 1 : spdm_context = spdm_test_context->spdm_context;
905 1 : spdm_test_context->case_id = 0x7;
906 :
907 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
908 : SPDM_VERSION_NUMBER_SHIFT_BIT;
909 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
910 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
911 1 : spdm_context->connection_info.capability.flags |=
912 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
913 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
914 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
915 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
916 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
917 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
918 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
919 1 : spdm_context->connection_info.capability.flags |=
920 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
921 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
922 : m_libspdm_use_asym_algo, &data,
923 : &data_size,
924 : &hash, &hash_size);
925 1 : libspdm_reset_message_a(spdm_context);
926 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
927 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
928 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
929 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
930 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
931 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
932 : data_size;
933 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
934 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
935 : data, data_size);
936 : #endif
937 :
938 1 : libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
939 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
940 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
941 1 : free(data);
942 1 : }
943 :
944 1 : void libspdm_test_requester_encap_request_case8(void **State)
945 : {
946 : libspdm_return_t status;
947 : libspdm_test_context_t *spdm_test_context;
948 : libspdm_context_t *spdm_context;
949 : void *data;
950 : size_t data_size;
951 : void *hash;
952 : size_t hash_size;
953 :
954 1 : spdm_test_context = *State;
955 1 : spdm_context = spdm_test_context->spdm_context;
956 1 : spdm_test_context->case_id = 0x8;
957 :
958 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
959 : SPDM_VERSION_NUMBER_SHIFT_BIT;
960 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
961 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
962 1 : spdm_context->connection_info.capability.flags |=
963 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
964 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
965 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
966 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
967 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
968 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
969 1 : spdm_context->local_context.capability.flags |=
970 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
971 1 : spdm_context->connection_info.capability.flags |=
972 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
973 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
974 : m_libspdm_use_asym_algo, &data,
975 : &data_size,
976 : &hash, &hash_size);
977 1 : spdm_context->local_context.local_cert_chain_provision[0] = data;
978 1 : spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
979 :
980 1 : libspdm_reset_message_a(spdm_context);
981 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
982 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
983 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
984 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
985 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
986 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
987 : data_size;
988 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
989 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
990 : data, data_size);
991 : #endif
992 :
993 1 : libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_certificate);
994 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
995 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
996 1 : free(data);
997 1 : }
998 : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP) */
999 :
1000 1 : void libspdm_test_requester_encap_request_case9(void **State)
1001 : {
1002 : libspdm_return_t status;
1003 : libspdm_test_context_t *spdm_test_context;
1004 : libspdm_context_t *spdm_context;
1005 : void *data;
1006 : size_t data_size;
1007 : void *hash;
1008 : size_t hash_size;
1009 :
1010 1 : spdm_test_context = *State;
1011 1 : spdm_context = spdm_test_context->spdm_context;
1012 1 : spdm_test_context->case_id = 0x9;
1013 :
1014 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1015 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1016 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1017 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
1018 1 : spdm_context->connection_info.capability.flags |=
1019 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
1020 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
1021 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
1022 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
1023 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
1024 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
1025 1 : spdm_context->connection_info.capability.flags |=
1026 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
1027 1 : spdm_context->local_context.capability.flags |=
1028 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
1029 1 : spdm_context->connection_info.capability.flags |=
1030 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
1031 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1032 : m_libspdm_use_asym_algo, &data,
1033 : &data_size,
1034 : &hash, &hash_size);
1035 1 : spdm_context->local_context.local_cert_chain_provision[0] = data;
1036 1 : spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
1037 :
1038 1 : libspdm_reset_message_a(spdm_context);
1039 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1040 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1041 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
1042 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
1043 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1044 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
1045 : data_size;
1046 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
1047 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
1048 : data, data_size);
1049 : #endif
1050 :
1051 1 : libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_key_update);
1052 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
1053 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1054 1 : free(data);
1055 1 : }
1056 :
1057 : /**
1058 : * Test 10: GET_ENCAPSULATED_REQUEST request message is encapsulated in ENCAPSULATED_REQUEST response message.
1059 : * Expected Behavior: the Requester should respond with ErrorCode=UnexpectedRequest.
1060 : **/
1061 1 : void libspdm_test_requester_encap_request_case10(void **State)
1062 : {
1063 : libspdm_return_t status;
1064 : libspdm_test_context_t *spdm_test_context;
1065 : libspdm_context_t *spdm_context;
1066 :
1067 1 : spdm_test_context = *State;
1068 1 : spdm_context = spdm_test_context->spdm_context;
1069 1 : spdm_test_context->case_id = 0xA;
1070 :
1071 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1072 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1073 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1074 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
1075 1 : spdm_context->connection_info.capability.flags |=
1076 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
1077 :
1078 1 : libspdm_register_get_encap_response_func(spdm_context, NULL);
1079 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
1080 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1081 1 : }
1082 :
1083 : /**
1084 : * Test 11: In a non-mutual-authentication context, Requester sends GET_ENCAPSULATED_REQUEST and
1085 : * Responder replies with UnexpectedRequest.
1086 : * Expected Behavior: return LIBSPDM_STATUS_SUCCESS as Responder did not have a pending request for
1087 : * the Requester.
1088 : **/
1089 1 : void libspdm_test_requester_encap_request_case11(void **State)
1090 : {
1091 : libspdm_return_t status;
1092 : libspdm_test_context_t *spdm_test_context;
1093 : libspdm_context_t *spdm_context;
1094 :
1095 1 : spdm_test_context = *State;
1096 1 : spdm_context = spdm_test_context->spdm_context;
1097 1 : spdm_test_context->case_id = 0xB;
1098 :
1099 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1100 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1101 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1102 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
1103 1 : spdm_context->connection_info.capability.flags |=
1104 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
1105 :
1106 1 : libspdm_register_get_encap_response_func(spdm_context, NULL);
1107 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
1108 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1109 1 : }
1110 :
1111 : /**
1112 : * Test 12: In a non-mutual-authentication context, Requester sends GET_ENCAPSULATED_REQUEST and
1113 : * Responder replies with NoPendingRequests.
1114 : * Expected Behavior: return LIBSPDM_STATUS_SUCCESS as Responder did not have a pending request for
1115 : * the Requester.
1116 : **/
1117 1 : void libspdm_test_requester_encap_request_case12(void **State)
1118 : {
1119 : libspdm_return_t status;
1120 : libspdm_test_context_t *spdm_test_context;
1121 : libspdm_context_t *spdm_context;
1122 :
1123 1 : spdm_test_context = *State;
1124 1 : spdm_context = spdm_test_context->spdm_context;
1125 1 : spdm_test_context->case_id = 0xC;
1126 :
1127 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1128 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1129 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1130 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
1131 1 : spdm_context->connection_info.capability.flags |=
1132 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
1133 :
1134 1 : libspdm_register_get_encap_response_func(spdm_context, NULL);
1135 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
1136 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1137 1 : }
1138 :
1139 : #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
1140 1 : void libspdm_test_requester_encap_request_case13(void **State)
1141 : {
1142 : libspdm_return_t status;
1143 : libspdm_test_context_t *spdm_test_context;
1144 : libspdm_context_t *spdm_context;
1145 : void *data;
1146 : size_t data_size;
1147 : void *hash;
1148 : size_t hash_size;
1149 :
1150 1 : spdm_test_context = *State;
1151 1 : spdm_context = spdm_test_context->spdm_context;
1152 1 : spdm_test_context->case_id = 0xD;
1153 :
1154 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1155 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1156 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1157 1 : spdm_context->connection_info.capability.flags = 0;
1158 1 : spdm_context->local_context.capability.flags = 0;
1159 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
1160 1 : spdm_context->connection_info.capability.flags |=
1161 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
1162 1 : spdm_context->local_context.capability.flags |=
1163 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG;
1164 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
1165 : m_libspdm_use_req_asym_algo, &data,
1166 : &data_size,
1167 : &hash, &hash_size);
1168 1 : spdm_context->local_context.local_cert_chain_provision[0] = data;
1169 1 : spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
1170 :
1171 1 : libspdm_reset_message_a(spdm_context);
1172 1 : libspdm_reset_message_encap_e(spdm_context, NULL);
1173 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1174 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1175 1 : spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
1176 :
1177 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1178 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
1179 : data_size;
1180 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
1181 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
1182 : data, data_size);
1183 : #endif
1184 :
1185 1 : libspdm_register_get_encap_response_func(spdm_context,
1186 : libspdm_get_encap_response_endpoint_info);
1187 1 : status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
1188 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1189 1 : free(data);
1190 1 : }
1191 : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
1192 :
1193 1 : int libspdm_requester_encap_request_test_main(void)
1194 : {
1195 1 : const struct CMUnitTest spdm_requester_encap_request_tests[] = {
1196 : /* SendRequest failed*/
1197 : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
1198 : cmocka_unit_test(libspdm_test_requester_encap_request_case1),
1199 : /* Success Case ,func :libspdm_get_encap_response_digest*/
1200 : cmocka_unit_test(libspdm_test_requester_encap_request_case2),
1201 : /* Error response:Receive message only SPDM ENCAPSULATED_REQUEST response*/
1202 : cmocka_unit_test(libspdm_test_requester_encap_request_case4),
1203 : /* Error response: spdm_encapsulated_response_ack_response == NULL*/
1204 : cmocka_unit_test(libspdm_test_requester_encap_request_case5),
1205 : /* response: param2 == SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_REQ_SLOT_NUMBER*/
1206 : cmocka_unit_test(libspdm_test_requester_encap_request_case7),
1207 : /*Success Case ,func :libspdm_get_encap_response_certificate */
1208 : cmocka_unit_test(libspdm_test_requester_encap_request_case8),
1209 : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
1210 :
1211 : /*Success Case ,func :libspdm_get_encap_response_key_update */
1212 : cmocka_unit_test(libspdm_test_requester_encap_request_case9),
1213 : /*Error response: GET_ENCAPSULATED_REQUEST message is encapsulated */
1214 : cmocka_unit_test(libspdm_test_requester_encap_request_case10),
1215 : cmocka_unit_test(libspdm_test_requester_encap_request_case11),
1216 : cmocka_unit_test(libspdm_test_requester_encap_request_case12),
1217 : #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
1218 : /*Success Case ,func :libspdm_get_encap_response_endpoint_info */
1219 : cmocka_unit_test(libspdm_test_requester_encap_request_case13),
1220 : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
1221 : };
1222 :
1223 1 : libspdm_test_context_t test_context = {
1224 : LIBSPDM_TEST_CONTEXT_VERSION,
1225 : true,
1226 : libspdm_requester_encap_request_test_send_message,
1227 : libspdm_requester_encap_request_test_receive_message,
1228 : };
1229 :
1230 1 : libspdm_setup_test_context(&test_context);
1231 :
1232 1 : return cmocka_run_group_tests(spdm_requester_encap_request_tests,
1233 : libspdm_unit_test_group_setup,
1234 : libspdm_unit_test_group_teardown);
1235 : }
1236 :
1237 : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
|