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 : #include "internal/libspdm_secured_message_lib.h"
10 :
11 : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
12 :
13 : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
14 :
15 : static void *m_libspdm_local_certificate_chain_test_cert;
16 : static size_t m_libspdm_local_certificate_chain_size;
17 :
18 : static size_t m_libspdm_local_buffer_size;
19 : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE];
20 :
21 : static bool m_get_digest;
22 :
23 : static spdm_key_usage_bit_mask_t m_local_key_usage_bit_mask[SPDM_MAX_SLOT_COUNT];
24 : static spdm_certificate_info_t m_local_cert_info[SPDM_MAX_SLOT_COUNT];
25 : static spdm_key_pair_id_t m_local_key_pair_id[SPDM_MAX_SLOT_COUNT];
26 :
27 13 : static libspdm_return_t send_message(
28 : void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
29 : {
30 : libspdm_test_context_t *spdm_test_context;
31 :
32 13 : spdm_test_context = libspdm_get_test_context();
33 13 : switch (spdm_test_context->case_id) {
34 0 : case 0x1:
35 0 : return LIBSPDM_STATUS_SEND_FAIL;
36 1 : case 0x2:
37 1 : return LIBSPDM_STATUS_SUCCESS;
38 0 : case 0x3:
39 0 : return LIBSPDM_STATUS_SUCCESS;
40 0 : case 0x4:
41 0 : return LIBSPDM_STATUS_SUCCESS;
42 0 : case 0x5:
43 0 : return LIBSPDM_STATUS_SUCCESS;
44 0 : case 0x6:
45 0 : return LIBSPDM_STATUS_SUCCESS;
46 0 : case 0x7:
47 0 : return LIBSPDM_STATUS_SUCCESS;
48 0 : case 0x8:
49 0 : return LIBSPDM_STATUS_SUCCESS;
50 0 : case 0x9:
51 0 : return LIBSPDM_STATUS_SUCCESS;
52 0 : case 0xA:
53 0 : return LIBSPDM_STATUS_SUCCESS;
54 0 : case 0xB:
55 0 : return LIBSPDM_STATUS_SUCCESS;
56 0 : case 0xC:
57 0 : return LIBSPDM_STATUS_SUCCESS;
58 0 : case 0xD:
59 0 : return LIBSPDM_STATUS_SUCCESS;
60 0 : case 0xE:
61 0 : return LIBSPDM_STATUS_SUCCESS;
62 0 : case 0xF:
63 0 : return LIBSPDM_STATUS_SUCCESS;
64 0 : case 0x10:
65 0 : return LIBSPDM_STATUS_SUCCESS;
66 0 : case 0x11:
67 0 : return LIBSPDM_STATUS_SUCCESS;
68 0 : case 0x12:
69 0 : return LIBSPDM_STATUS_SUCCESS;
70 0 : case 0x13:
71 0 : return LIBSPDM_STATUS_SUCCESS;
72 0 : case 0x14:
73 0 : return LIBSPDM_STATUS_SUCCESS;
74 0 : case 0x15:
75 0 : return LIBSPDM_STATUS_SUCCESS;
76 0 : case 0x16:
77 0 : return LIBSPDM_STATUS_SUCCESS;
78 1 : case 0x17: {
79 1 : const uint8_t *ptr = (const uint8_t *)request;
80 :
81 1 : m_libspdm_local_buffer_size = 0;
82 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
83 1 : &ptr[1], request_size - 1);
84 1 : m_libspdm_local_buffer_size += (request_size - 1);
85 : }
86 1 : return LIBSPDM_STATUS_SUCCESS;
87 4 : case 0x18:
88 4 : return LIBSPDM_STATUS_SUCCESS;
89 7 : case 0x19:
90 : case 0x1A:
91 : case 0x1B:
92 : case 0x1C:
93 : case 0x1D:
94 7 : return LIBSPDM_STATUS_SUCCESS;
95 0 : default:
96 0 : return LIBSPDM_STATUS_SEND_FAIL;
97 : }
98 : }
99 :
100 13 : static libspdm_return_t receive_message(
101 : void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
102 : {
103 : libspdm_test_context_t *spdm_test_context;
104 :
105 13 : spdm_test_context = libspdm_get_test_context();
106 13 : switch (spdm_test_context->case_id) {
107 0 : case 0x1:
108 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
109 :
110 1 : case 0x2: {
111 : spdm_digest_response_t *spdm_response;
112 : uint8_t *digest;
113 : size_t spdm_response_size;
114 : size_t transport_header_size;
115 :
116 : ((libspdm_context_t *)spdm_context)
117 1 : ->connection_info.algorithm.base_hash_algo =
118 : m_libspdm_use_hash_algo;
119 1 : spdm_response_size = sizeof(spdm_digest_response_t) +
120 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT;
121 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
122 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
123 :
124 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
125 1 : spdm_response->header.param1 = 0;
126 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
127 1 : spdm_response->header.param2 = 0;
128 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
129 : sizeof(m_libspdm_local_certificate_chain),
130 : (uint8_t)(0xFF));
131 :
132 1 : digest = (void *)(spdm_response + 1);
133 1 : libspdm_zero_mem (digest,
134 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
135 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
136 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
137 1 : spdm_response->header.param2 |= (0x01 << 0);
138 :
139 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
140 : false, spdm_response_size,
141 : spdm_response, response_size,
142 : response);
143 : }
144 1 : return LIBSPDM_STATUS_SUCCESS;
145 :
146 0 : case 0x3: {
147 : spdm_digest_response_t *spdm_response;
148 : uint8_t *digest;
149 : size_t spdm_response_size;
150 : size_t transport_header_size;
151 :
152 : ((libspdm_context_t *)spdm_context)
153 0 : ->connection_info.algorithm.base_hash_algo =
154 : m_libspdm_use_hash_algo;
155 0 : spdm_response_size = sizeof(spdm_digest_response_t) +
156 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
157 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
158 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
159 :
160 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
161 0 : spdm_response->header.param1 = 0;
162 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
163 0 : spdm_response->header.param2 = 0;
164 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
165 : sizeof(m_libspdm_local_certificate_chain),
166 : (uint8_t)(0xFF));
167 :
168 0 : digest = (void *)(spdm_response + 1);
169 0 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
170 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
171 0 : spdm_response->header.param2 |= (1 << 0);
172 :
173 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
174 : false, spdm_response_size,
175 : spdm_response, response_size,
176 : response);
177 : }
178 0 : return LIBSPDM_STATUS_SUCCESS;
179 :
180 0 : case 0x4: {
181 : spdm_error_response_t *spdm_response;
182 : size_t spdm_response_size;
183 : size_t transport_header_size;
184 :
185 0 : spdm_response_size = sizeof(spdm_error_response_t);
186 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
187 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
188 :
189 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
190 0 : spdm_response->header.request_response_code = SPDM_ERROR;
191 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
192 0 : spdm_response->header.param2 = 0;
193 :
194 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
195 : false, spdm_response_size,
196 : spdm_response,
197 : response_size, response);
198 : }
199 0 : return LIBSPDM_STATUS_SUCCESS;
200 :
201 0 : case 0x5: {
202 : spdm_error_response_t *spdm_response;
203 : size_t spdm_response_size;
204 : size_t transport_header_size;
205 :
206 0 : spdm_response_size = sizeof(spdm_error_response_t);
207 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
208 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
209 :
210 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
211 0 : spdm_response->header.request_response_code = SPDM_ERROR;
212 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
213 0 : spdm_response->header.param2 = 0;
214 :
215 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
216 : false, spdm_response_size,
217 : spdm_response,
218 : response_size, response);
219 : }
220 0 : return LIBSPDM_STATUS_SUCCESS;
221 :
222 0 : case 0x6: {
223 : static size_t sub_index1 = 0;
224 0 : if (sub_index1 == 0) {
225 : spdm_error_response_t *spdm_response;
226 : size_t spdm_response_size;
227 : size_t transport_header_size;
228 :
229 0 : spdm_response_size = sizeof(spdm_error_response_t);
230 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
231 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
232 :
233 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
234 0 : spdm_response->header.request_response_code = SPDM_ERROR;
235 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
236 0 : spdm_response->header.param2 = 0;
237 :
238 0 : libspdm_transport_test_encode_message(
239 : spdm_context, NULL, false, false,
240 : spdm_response_size, spdm_response,
241 : response_size, response);
242 0 : } else if (sub_index1 == 1) {
243 : spdm_digest_response_t *spdm_response;
244 : uint8_t *digest;
245 : size_t spdm_response_size;
246 : size_t transport_header_size;
247 :
248 : ((libspdm_context_t *)spdm_context)
249 0 : ->connection_info.algorithm.base_hash_algo =
250 : m_libspdm_use_hash_algo;
251 0 : spdm_response_size = sizeof(spdm_digest_response_t) +
252 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
253 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
254 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
255 :
256 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
257 0 : spdm_response->header.param1 = 0;
258 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
259 0 : spdm_response->header.param2 = 0;
260 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
261 : sizeof(m_libspdm_local_certificate_chain), (uint8_t)(0xFF));
262 :
263 0 : digest = (void *)(spdm_response + 1);
264 0 : libspdm_hash_all(m_libspdm_use_hash_algo,
265 : m_libspdm_local_certificate_chain,
266 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
267 0 : spdm_response->header.param2 |= (1 << 0);
268 :
269 0 : libspdm_transport_test_encode_message(
270 : spdm_context, NULL, false, false, spdm_response_size,
271 : spdm_response, response_size, response);
272 : }
273 0 : sub_index1++;
274 : }
275 0 : return LIBSPDM_STATUS_SUCCESS;
276 :
277 0 : case 0x7: {
278 : spdm_error_response_t *spdm_response;
279 : size_t spdm_response_size;
280 : size_t transport_header_size;
281 :
282 0 : spdm_response_size = sizeof(spdm_error_response_t);
283 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
284 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
285 :
286 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
287 0 : spdm_response->header.request_response_code = SPDM_ERROR;
288 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
289 0 : spdm_response->header.param2 = 0;
290 :
291 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
292 : false, spdm_response_size,
293 : spdm_response,
294 : response_size, response);
295 : }
296 0 : return LIBSPDM_STATUS_SUCCESS;
297 :
298 0 : case 0x8: {
299 : spdm_error_response_data_response_not_ready_t *spdm_response;
300 : size_t spdm_response_size;
301 : size_t transport_header_size;
302 :
303 0 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
304 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
305 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
306 :
307 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
308 0 : spdm_response->header.request_response_code = SPDM_ERROR;
309 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
310 0 : spdm_response->header.param2 = 0;
311 0 : spdm_response->extend_error_data.rd_exponent = 1;
312 0 : spdm_response->extend_error_data.rd_tm = 2;
313 0 : spdm_response->extend_error_data.request_code = SPDM_GET_DIGESTS;
314 0 : spdm_response->extend_error_data.token = 0;
315 :
316 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
317 : false, spdm_response_size,
318 : spdm_response,
319 : response_size, response);
320 : }
321 0 : return LIBSPDM_STATUS_SUCCESS;
322 :
323 0 : case 0x9: {
324 : static size_t sub_index2 = 0;
325 0 : if (sub_index2 == 0) {
326 : spdm_error_response_data_response_not_ready_t
327 : *spdm_response;
328 : size_t spdm_response_size;
329 : size_t transport_header_size;
330 :
331 0 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
332 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
333 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
334 :
335 0 : spdm_response->header.spdm_version =
336 : SPDM_MESSAGE_VERSION_10;
337 0 : spdm_response->header.request_response_code = SPDM_ERROR;
338 0 : spdm_response->header.param1 =
339 : SPDM_ERROR_CODE_RESPONSE_NOT_READY;
340 0 : spdm_response->header.param2 = 0;
341 0 : spdm_response->extend_error_data.rd_exponent = 1;
342 0 : spdm_response->extend_error_data.rd_tm = 2;
343 0 : spdm_response->extend_error_data.request_code =
344 : SPDM_GET_DIGESTS;
345 0 : spdm_response->extend_error_data.token = 1;
346 :
347 0 : libspdm_transport_test_encode_message(
348 : spdm_context, NULL, false, false,
349 : spdm_response_size, spdm_response,
350 : response_size, response);
351 0 : } else if (sub_index2 == 1) {
352 : spdm_digest_response_t *spdm_response;
353 : uint8_t *digest;
354 : size_t spdm_response_size;
355 : size_t transport_header_size;
356 :
357 : ((libspdm_context_t *)spdm_context)
358 0 : ->connection_info.algorithm.base_hash_algo =
359 : m_libspdm_use_hash_algo;
360 0 : spdm_response_size = sizeof(spdm_digest_response_t) +
361 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
362 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
363 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
364 :
365 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
366 0 : spdm_response->header.param1 = 0;
367 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
368 0 : spdm_response->header.param2 = 0;
369 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
370 : sizeof(m_libspdm_local_certificate_chain), (uint8_t)(0xFF));
371 :
372 0 : digest = (void *)(spdm_response + 1);
373 0 : libspdm_hash_all(m_libspdm_use_hash_algo,
374 : m_libspdm_local_certificate_chain,
375 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
376 0 : spdm_response->header.param2 |= (1 << 0);
377 :
378 0 : libspdm_transport_test_encode_message(
379 : spdm_context, NULL, false, false, spdm_response_size,
380 : spdm_response, response_size, response);
381 : }
382 0 : sub_index2++;
383 : }
384 0 : return LIBSPDM_STATUS_SUCCESS;
385 :
386 0 : case 0xA:
387 0 : return LIBSPDM_STATUS_SUCCESS;
388 :
389 0 : case 0xB:
390 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
391 :
392 0 : case 0xC: {
393 : spdm_digest_response_t *spdm_response;
394 : size_t spdm_response_size;
395 : size_t transport_header_size;
396 :
397 : ((libspdm_context_t *)spdm_context)
398 0 : ->connection_info.algorithm.base_hash_algo =
399 : m_libspdm_use_hash_algo;
400 0 : spdm_response_size = 2;
401 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
402 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
403 :
404 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
405 0 : spdm_response->header.param1 = 0;
406 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
407 0 : spdm_response->header.param2 = 0;
408 :
409 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
410 : false, spdm_response_size,
411 : spdm_response, response_size,
412 : response);
413 : }
414 0 : return LIBSPDM_STATUS_SUCCESS;
415 :
416 0 : case 0xD: {
417 : spdm_digest_response_t *spdm_response;
418 : uint8_t *digest;
419 : size_t spdm_response_size;
420 : size_t transport_header_size;
421 :
422 : ((libspdm_context_t *)spdm_context)
423 0 : ->connection_info.algorithm.base_hash_algo =
424 : m_libspdm_use_hash_algo;
425 0 : spdm_response_size = sizeof(spdm_digest_response_t) +
426 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
427 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
428 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
429 :
430 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
431 0 : spdm_response->header.param1 = 0;
432 0 : spdm_response->header.request_response_code = SPDM_CERTIFICATE;
433 0 : spdm_response->header.param2 = 0;
434 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
435 : sizeof(m_libspdm_local_certificate_chain),
436 : (uint8_t)(0xFF));
437 :
438 0 : digest = (void *)(spdm_response + 1);
439 0 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
440 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
441 0 : spdm_response->header.param2 |= (1 << 0);
442 :
443 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
444 : false, spdm_response_size,
445 : spdm_response, response_size,
446 : response);
447 : }
448 0 : return LIBSPDM_STATUS_SUCCESS;
449 :
450 0 : case 0xE: {
451 : spdm_digest_response_t *spdm_response;
452 : size_t spdm_response_size;
453 : size_t transport_header_size;
454 :
455 0 : spdm_response_size = sizeof(spdm_digest_response_t);
456 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
457 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
458 :
459 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
460 0 : spdm_response->header.param1 = 0;
461 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
462 0 : spdm_response->header.param2 = 0;
463 :
464 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
465 : false, spdm_response_size,
466 : spdm_response,
467 : response_size, response);
468 : }
469 0 : return LIBSPDM_STATUS_SUCCESS;
470 :
471 0 : case 0xF:
472 0 : return LIBSPDM_STATUS_SUCCESS;
473 :
474 0 : case 0x10: {
475 : spdm_digest_response_t *spdm_response;
476 : uint8_t *digest;
477 : size_t spdm_response_size;
478 : size_t transport_header_size;
479 :
480 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
481 : ((libspdm_context_t *)spdm_context)->transcript.message_b.buffer_size =
482 : ((libspdm_context_t *)spdm_context)->transcript.message_b.max_buffer_size -
483 : (sizeof(spdm_digest_response_t));
484 : #endif
485 :
486 : ((libspdm_context_t *)spdm_context)
487 0 : ->connection_info.algorithm.base_hash_algo =
488 : m_libspdm_use_hash_algo;
489 0 : spdm_response_size = sizeof(spdm_digest_response_t) +
490 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
491 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
492 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
493 :
494 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
495 0 : spdm_response->header.param1 = 0;
496 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
497 0 : spdm_response->header.param2 = 0;
498 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
499 : sizeof(m_libspdm_local_certificate_chain),
500 : (uint8_t)(0xFF));
501 :
502 0 : digest = (void *)(spdm_response + 1);
503 0 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
504 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
505 0 : spdm_response->header.param2 |= (1 << 0);
506 :
507 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
508 : false, spdm_response_size,
509 : spdm_response, response_size,
510 : response);
511 : }
512 0 : return LIBSPDM_STATUS_SUCCESS;
513 :
514 0 : case 0x11: {
515 : spdm_digest_response_t *spdm_response;
516 : uint8_t *digest;
517 : size_t spdm_response_size;
518 : size_t transport_header_size;
519 :
520 : ((libspdm_context_t *)spdm_context)
521 0 : ->connection_info.algorithm.base_hash_algo =
522 : m_libspdm_use_hash_algo;
523 0 : spdm_response_size = sizeof(spdm_digest_response_t) +
524 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
525 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
526 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
527 :
528 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
529 0 : spdm_response->header.param1 = 0;
530 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
531 0 : spdm_response->header.param2 = 0;
532 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
533 : sizeof(m_libspdm_local_certificate_chain),
534 : (uint8_t)(0xFF));
535 :
536 0 : digest = (void *)(spdm_response + 1);
537 0 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
538 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
539 0 : digest[libspdm_get_hash_size(m_libspdm_use_hash_algo) - 1] = 0;
540 0 : spdm_response->header.param2 |= (1 << 0);
541 :
542 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
543 : false, spdm_response_size,
544 : spdm_response, response_size,
545 : response);
546 : }
547 0 : return LIBSPDM_STATUS_SUCCESS;
548 :
549 0 : case 0x12: {
550 : spdm_digest_response_t *spdm_response;
551 : uint8_t *digest;
552 : size_t digest_count;
553 : size_t spdm_response_size;
554 : size_t transport_header_size;
555 : size_t index;
556 :
557 : ((libspdm_context_t *)spdm_context)
558 0 : ->connection_info.algorithm.base_hash_algo =
559 : m_libspdm_use_hash_algo;
560 0 : digest_count = 4;
561 0 : spdm_response_size = sizeof(spdm_digest_response_t) +
562 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
563 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
564 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
565 :
566 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
567 0 : spdm_response->header.param1 = 0;
568 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
569 0 : spdm_response->header.param2 = 0;
570 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
571 : sizeof(m_libspdm_local_certificate_chain),
572 : (uint8_t)(0xFF));
573 :
574 0 : digest = (void *)(spdm_response + 1);
575 :
576 0 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
577 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
578 0 : for (index = 0; index < digest_count; index++) {
579 0 : spdm_response->header.param2 |= (1 << index);
580 : }
581 :
582 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
583 : false, spdm_response_size,
584 : spdm_response, response_size,
585 : response);
586 : }
587 0 : return LIBSPDM_STATUS_SUCCESS;
588 :
589 0 : case 0x13: {
590 : spdm_digest_response_t *spdm_response;
591 : uint8_t *digest;
592 : size_t digest_count;
593 : size_t spdm_response_size;
594 : size_t transport_header_size;
595 : size_t index;
596 :
597 : ((libspdm_context_t *)spdm_context)
598 0 : ->connection_info.algorithm.base_hash_algo =
599 : m_libspdm_use_hash_algo;
600 0 : digest_count = 4;
601 0 : spdm_response_size =
602 : sizeof(spdm_digest_response_t) +
603 0 : digest_count * libspdm_get_hash_size(m_libspdm_use_hash_algo);
604 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
605 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
606 :
607 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
608 0 : spdm_response->header.param1 = 0;
609 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
610 0 : spdm_response->header.param2 = 0;
611 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
612 : sizeof(m_libspdm_local_certificate_chain),
613 : (uint8_t)(0xFF));
614 :
615 0 : digest = (void *)(spdm_response + 1);
616 :
617 0 : for (index = 0; index < digest_count; index++) {
618 0 : libspdm_hash_all(
619 : m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
620 : sizeof(m_libspdm_local_certificate_chain),
621 0 : &digest[index *
622 0 : libspdm_get_hash_size(m_libspdm_use_hash_algo)]);
623 0 : spdm_response->header.param2 |= (1 << index);
624 0 : if (index == 0) {
625 0 : continue;
626 : }
627 0 : digest[(index + 1) * libspdm_get_hash_size(m_libspdm_use_hash_algo) -
628 0 : 1] = 0;
629 : }
630 :
631 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
632 : false, spdm_response_size,
633 : spdm_response, response_size,
634 : response);
635 : }
636 0 : return LIBSPDM_STATUS_SUCCESS;
637 :
638 0 : case 0x14: {
639 : spdm_digest_response_t *spdm_response;
640 : size_t spdm_response_size;
641 : size_t transport_header_size;
642 :
643 : ((libspdm_context_t *)spdm_context)
644 0 : ->connection_info.algorithm.base_hash_algo =
645 : m_libspdm_use_hash_algo;
646 0 : spdm_response_size = 5;
647 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
648 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
649 :
650 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
651 0 : spdm_response->header.param1 = 0;
652 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
653 0 : spdm_response->header.param2 = 0;
654 :
655 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
656 : false, spdm_response_size,
657 : spdm_response, response_size,
658 : response);
659 : }
660 0 : return LIBSPDM_STATUS_SUCCESS;
661 :
662 0 : case 0x15: {
663 : spdm_digest_response_t *spdm_response;
664 : uint8_t *digest;
665 : size_t spdm_response_size;
666 : size_t transport_header_size;
667 :
668 : ((libspdm_context_t *)spdm_context)
669 0 : ->connection_info.algorithm.base_hash_algo =
670 : m_libspdm_use_hash_algo;
671 0 : spdm_response_size = sizeof(spdm_message_header_t) +
672 : LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT + 1;
673 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
674 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
675 :
676 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
677 0 : spdm_response->header.param1 = 0;
678 0 : spdm_response->header.request_response_code = SPDM_DIGESTS;
679 0 : spdm_response->header.param2 = 0;
680 0 : libspdm_set_mem(m_libspdm_local_certificate_chain,
681 : sizeof(m_libspdm_local_certificate_chain),
682 : (uint8_t)(0xFF));
683 :
684 0 : digest = (void *)(spdm_response + 1);
685 0 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
686 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
687 0 : spdm_response->header.param2 |= (1 << 0);
688 :
689 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
690 : false, spdm_response_size,
691 : spdm_response, response_size,
692 : response);
693 : }
694 0 : return LIBSPDM_STATUS_SUCCESS;
695 :
696 0 : case 0x16:
697 : {
698 : static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
699 :
700 : spdm_error_response_t *spdm_response;
701 : size_t spdm_response_size;
702 : size_t transport_header_size;
703 :
704 0 : spdm_response_size = sizeof(spdm_error_response_t);
705 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
706 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
707 :
708 0 : if(error_code <= 0xff) {
709 0 : libspdm_zero_mem (spdm_response, spdm_response_size);
710 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
711 0 : spdm_response->header.request_response_code = SPDM_ERROR;
712 0 : spdm_response->header.param1 = (uint8_t) error_code;
713 0 : spdm_response->header.param2 = 0;
714 :
715 0 : libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
716 : spdm_response_size, spdm_response,
717 : response_size, response);
718 : }
719 :
720 0 : error_code++;
721 0 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
722 0 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
723 : }
724 0 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
725 0 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
726 : }
727 0 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
728 0 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
729 : }
730 : }
731 0 : return LIBSPDM_STATUS_SUCCESS;
732 :
733 1 : case 0x17: {
734 : spdm_digest_response_t *spdm_response;
735 : uint8_t *digest;
736 : size_t spdm_response_size;
737 : size_t transport_header_size;
738 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
739 : size_t arbitrary_size;
740 : #endif
741 :
742 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
743 : /*filling B with arbitrary data*/
744 : arbitrary_size = 8;
745 : libspdm_set_mem(((libspdm_context_t *)spdm_context)->transcript.message_b.buffer,
746 : arbitrary_size, (uint8_t) 0xEE);
747 : ((libspdm_context_t *)spdm_context)->transcript.message_b.buffer_size =
748 : arbitrary_size;
749 : #endif
750 :
751 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
752 : m_libspdm_use_hash_algo;
753 1 : spdm_response_size = sizeof(spdm_digest_response_t) +
754 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
755 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
756 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
757 :
758 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
759 1 : spdm_response->header.param1 = 0;
760 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
761 1 : spdm_response->header.param2 = 0;
762 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
763 : sizeof(m_libspdm_local_certificate_chain),
764 : (uint8_t)(0xFF));
765 :
766 1 : digest = (void *)(spdm_response + 1);
767 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
768 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
769 1 : spdm_response->header.param2 |= (0x01 << 0);
770 :
771 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
772 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
773 : spdm_response, spdm_response_size);
774 1 : m_libspdm_local_buffer_size += spdm_response_size;
775 :
776 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
777 : false, spdm_response_size,
778 : spdm_response, response_size,
779 : response);
780 : }
781 1 : return LIBSPDM_STATUS_SUCCESS;
782 :
783 4 : case 0x18: {
784 4 : if (m_get_digest) {
785 : spdm_digest_response_t *spdm_response;
786 : uint8_t *digest;
787 : size_t spdm_response_size;
788 : size_t transport_header_size;
789 :
790 : ((libspdm_context_t *)spdm_context)
791 2 : ->connection_info.algorithm.base_hash_algo =
792 : m_libspdm_use_hash_algo;
793 2 : spdm_response_size = sizeof(spdm_digest_response_t) +
794 2 : libspdm_get_hash_size(m_libspdm_use_hash_algo) *
795 : SPDM_MAX_SLOT_COUNT;
796 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
797 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
798 :
799 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
800 2 : spdm_response->header.param1 = 0;
801 2 : spdm_response->header.request_response_code = SPDM_DIGESTS;
802 2 : spdm_response->header.param2 = 0;
803 :
804 2 : if (m_libspdm_local_certificate_chain_test_cert == NULL) {
805 2 : libspdm_read_responder_public_certificate_chain(
806 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
807 : &m_libspdm_local_certificate_chain_test_cert,
808 : &m_libspdm_local_certificate_chain_size, NULL, NULL);
809 : }
810 2 : if (m_libspdm_local_certificate_chain_test_cert == NULL) {
811 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
812 : }
813 2 : digest = (void *)(spdm_response + 1);
814 2 : libspdm_zero_mem(digest,
815 2 : libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
816 2 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain_test_cert,
817 : m_libspdm_local_certificate_chain_size, &digest[0]);
818 2 : spdm_response->header.param2 |= (0x01 << 0);
819 :
820 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
821 : false, spdm_response_size,
822 : spdm_response, response_size,
823 : response);
824 : } else {
825 : spdm_certificate_response_t *spdm_response;
826 : size_t spdm_response_size;
827 : size_t transport_header_size;
828 : uint16_t portion_length;
829 : uint16_t remainder_length;
830 : size_t count;
831 : static size_t calling_index = 0;
832 :
833 2 : if (m_libspdm_local_certificate_chain_test_cert == NULL) {
834 0 : libspdm_read_responder_public_certificate_chain(
835 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
836 : &m_libspdm_local_certificate_chain_test_cert,
837 : &m_libspdm_local_certificate_chain_size, NULL, NULL);
838 : }
839 2 : if (m_libspdm_local_certificate_chain_test_cert == NULL) {
840 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
841 : }
842 2 : count = (m_libspdm_local_certificate_chain_size +
843 2 : LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN - 1) /
844 : LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
845 2 : if (calling_index != count - 1) {
846 1 : portion_length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
847 1 : remainder_length =
848 1 : (uint16_t)(m_libspdm_local_certificate_chain_size -
849 : LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN *
850 1 : (calling_index + 1));
851 : } else {
852 1 : portion_length = (uint16_t)(
853 : m_libspdm_local_certificate_chain_size -
854 1 : LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * (count - 1));
855 1 : remainder_length = 0;
856 : }
857 :
858 2 : spdm_response_size =
859 2 : sizeof(spdm_certificate_response_t) + portion_length;
860 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
861 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
862 :
863 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
864 2 : spdm_response->header.request_response_code = SPDM_CERTIFICATE;
865 2 : spdm_response->header.param1 = 0;
866 2 : spdm_response->header.param2 = 0;
867 2 : spdm_response->portion_length = portion_length;
868 2 : spdm_response->remainder_length = remainder_length;
869 2 : libspdm_copy_mem(spdm_response + 1,
870 2 : (size_t)(*response) + *response_size - (size_t)(spdm_response + 1),
871 2 : (uint8_t *)m_libspdm_local_certificate_chain_test_cert +
872 2 : LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN * calling_index,
873 : portion_length);
874 :
875 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
876 : false, spdm_response_size,
877 : spdm_response, response_size,
878 : response);
879 :
880 2 : calling_index++;
881 2 : if (calling_index == count) {
882 1 : calling_index = 0;
883 1 : free(m_libspdm_local_certificate_chain_test_cert);
884 1 : m_libspdm_local_certificate_chain_test_cert = NULL;
885 1 : m_libspdm_local_certificate_chain_size = 0;
886 : }
887 : }
888 : }
889 4 : return LIBSPDM_STATUS_SUCCESS;
890 :
891 1 : case 0x19: {
892 : spdm_digest_response_t *spdm_response;
893 : uint8_t *digest;
894 : size_t spdm_response_size;
895 : size_t transport_header_size;
896 : uint32_t session_id;
897 : libspdm_session_info_t *session_info;
898 : uint8_t *scratch_buffer;
899 : size_t scratch_buffer_size;
900 :
901 1 : session_id = 0xFFFFFFFF;
902 :
903 : ((libspdm_context_t *)spdm_context)
904 1 : ->connection_info.algorithm.base_hash_algo =
905 : m_libspdm_use_hash_algo;
906 1 : spdm_response_size = sizeof(spdm_digest_response_t) +
907 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
908 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
909 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
910 :
911 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
912 1 : spdm_response->header.param1 = 0;
913 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
914 1 : spdm_response->header.param2 = 0;
915 :
916 : /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
917 : * transport_message is always in sender buffer. */
918 1 : libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
919 :
920 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
921 : sizeof(m_libspdm_local_certificate_chain),
922 : (uint8_t)(0xFF));
923 :
924 1 : digest = (void *)(spdm_response + 1);
925 : /* send certchain digest of slot 7 */
926 1 : libspdm_zero_mem (digest,
927 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo) * SPDM_MAX_SLOT_COUNT);
928 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
929 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
930 1 : spdm_response->header.param2 |= (0x80 << 0);
931 :
932 1 : libspdm_copy_mem (scratch_buffer + transport_header_size,
933 : scratch_buffer_size - transport_header_size,
934 : spdm_response, spdm_response_size);
935 1 : spdm_response = (void *)(scratch_buffer + transport_header_size);
936 1 : libspdm_transport_test_encode_message(spdm_context, &session_id, false,
937 : false, spdm_response_size,
938 : spdm_response, response_size,
939 : response);
940 :
941 1 : session_info = libspdm_get_session_info_via_session_id(
942 : spdm_context, session_id);
943 1 : if (session_info == NULL) {
944 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
945 : }
946 : /* WALKAROUND: If just use single context to encode message and then decode message */
947 : ((libspdm_secured_message_context_t
948 1 : *)(session_info->secured_message_context))
949 1 : ->application_secret.response_data_sequence_number--;
950 :
951 : }
952 1 : return LIBSPDM_STATUS_SUCCESS;
953 :
954 2 : case 0x1A: {
955 : spdm_digest_response_t *spdm_response;
956 : uint8_t *digest;
957 : size_t hash_size;
958 : size_t spdm_response_size;
959 : size_t transport_header_size;
960 : spdm_key_pair_id_t *key_pair_id;
961 : spdm_certificate_info_t *cert_info;
962 : spdm_key_usage_bit_mask_t *key_usage_bit_mask;
963 :
964 : ((libspdm_context_t *)spdm_context)
965 2 : ->connection_info.algorithm.base_hash_algo =
966 : m_libspdm_use_hash_algo;
967 2 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
968 2 : spdm_response_size = sizeof(spdm_digest_response_t) +
969 : hash_size + sizeof(spdm_key_pair_id_t) +
970 : sizeof(spdm_certificate_info_t) + sizeof(spdm_key_usage_bit_mask_t);
971 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
972 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
973 :
974 2 : spdm_response->header.request_response_code = SPDM_DIGESTS;
975 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
976 2 : spdm_response->header.param1 = (0x01 << 0);
977 2 : spdm_response->header.param2 = 0;
978 2 : spdm_response->header.param2 |= (0x01 << 0);
979 :
980 2 : libspdm_set_mem(m_libspdm_local_certificate_chain,
981 : sizeof(m_libspdm_local_certificate_chain),
982 : (uint8_t)(0xFF));
983 :
984 2 : digest = (void *)(spdm_response + 1);
985 2 : libspdm_zero_mem (digest, hash_size);
986 2 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
987 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
988 2 : key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + hash_size);
989 2 : cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
990 : sizeof(spdm_key_pair_id_t));
991 2 : key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
992 : sizeof(spdm_certificate_info_t));
993 2 : *key_pair_id = 0;
994 2 : *cert_info = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
995 2 : *key_usage_bit_mask = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
996 : SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
997 : SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
998 : SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
999 :
1000 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1001 : false, spdm_response_size,
1002 : spdm_response, response_size,
1003 : response);
1004 : }
1005 2 : return LIBSPDM_STATUS_SUCCESS;
1006 1 : case 0x1B: {
1007 : spdm_digest_response_t *spdm_response;
1008 : uint8_t *digest;
1009 : size_t spdm_response_size;
1010 : size_t transport_header_size;
1011 : spdm_key_pair_id_t *key_pair_id;
1012 : spdm_certificate_info_t *cert_info;
1013 : spdm_key_usage_bit_mask_t *key_usage_bit_mask;
1014 : uint32_t hash_size;
1015 : uint8_t slot_count;
1016 : size_t additional_size;
1017 :
1018 1 : slot_count = SPDM_MAX_SLOT_COUNT;
1019 1 : additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
1020 : sizeof(spdm_key_usage_bit_mask_t);
1021 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1022 :
1023 1 : spdm_response_size = sizeof(spdm_digest_response_t) +
1024 1 : (hash_size + additional_size) * slot_count;
1025 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1026 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1027 :
1028 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
1029 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
1030 1 : spdm_response->header.param1 = 0;
1031 1 : spdm_response->header.param2 = 0;
1032 :
1033 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1034 : sizeof(m_libspdm_local_certificate_chain),
1035 : (uint8_t)(0xFF));
1036 :
1037 1 : digest = (void *)(spdm_response + 1);
1038 1 : libspdm_zero_mem (digest, hash_size * slot_count);
1039 1 : key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
1040 1 : cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
1041 1 : sizeof(spdm_key_pair_id_t) * slot_count);
1042 1 : key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
1043 1 : sizeof(spdm_certificate_info_t) *
1044 : slot_count);
1045 :
1046 9 : for (uint8_t index = 0; index < slot_count; index++)
1047 : {
1048 8 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
1049 8 : sizeof(m_libspdm_local_certificate_chain), &digest[hash_size * index]);
1050 :
1051 8 : key_pair_id[index] = m_local_key_pair_id[index];
1052 8 : cert_info[index] = m_local_cert_info[index];
1053 8 : key_usage_bit_mask[index] = m_local_key_usage_bit_mask[index];
1054 :
1055 8 : spdm_response->header.param1 |= (1 << index);
1056 8 : spdm_response->header.param2 |= (1 << index);
1057 : }
1058 :
1059 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1060 : false, spdm_response_size,
1061 : spdm_response, response_size,
1062 : response);
1063 : }
1064 1 : return LIBSPDM_STATUS_SUCCESS;
1065 2 : case 0x1C: {
1066 : spdm_digest_response_t *spdm_response;
1067 : uint8_t *digest;
1068 : size_t spdm_response_size;
1069 : size_t transport_header_size;
1070 : spdm_key_pair_id_t *key_pair_id;
1071 : spdm_certificate_info_t *cert_info;
1072 : spdm_key_usage_bit_mask_t *key_usage_bit_mask;
1073 : uint32_t hash_size;
1074 : uint8_t slot_count;
1075 : size_t additional_size;
1076 :
1077 2 : slot_count = 1;
1078 2 : additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
1079 : sizeof(spdm_key_usage_bit_mask_t);
1080 2 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1081 :
1082 2 : spdm_response_size = sizeof(spdm_digest_response_t) +
1083 2 : (hash_size + additional_size) * slot_count;
1084 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1085 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1086 :
1087 2 : spdm_response->header.request_response_code = SPDM_DIGESTS;
1088 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
1089 2 : spdm_response->header.param1 = 0;
1090 2 : spdm_response->header.param2 = 0;
1091 :
1092 2 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1093 : sizeof(m_libspdm_local_certificate_chain),
1094 : (uint8_t)(0xFF));
1095 :
1096 2 : digest = (void *)(spdm_response + 1);
1097 2 : key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
1098 2 : cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
1099 2 : sizeof(spdm_key_pair_id_t) * slot_count);
1100 2 : key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
1101 2 : sizeof(spdm_certificate_info_t) *
1102 : slot_count);
1103 :
1104 : /* Set Digest KeyUsageMask and CertificateInfo to 0*/
1105 2 : libspdm_zero_mem (digest, hash_size * slot_count);
1106 2 : key_pair_id[0] = m_local_key_pair_id[0];
1107 2 : cert_info[0] = m_local_cert_info[0];
1108 2 : key_usage_bit_mask[0] = m_local_key_usage_bit_mask[0];
1109 :
1110 2 : spdm_response->header.param1 |= (1 << 0);
1111 2 : spdm_response->header.param2 |= (1 << 0);
1112 :
1113 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1114 : false, spdm_response_size,
1115 : spdm_response, response_size,
1116 : response);
1117 : }
1118 2 : return LIBSPDM_STATUS_SUCCESS;
1119 1 : case 0x1D: {
1120 : spdm_digest_response_t *spdm_response;
1121 : uint8_t *digest;
1122 : size_t spdm_response_size;
1123 : size_t transport_header_size;
1124 : spdm_key_pair_id_t *key_pair_id;
1125 : spdm_certificate_info_t *cert_info;
1126 : spdm_key_usage_bit_mask_t *key_usage_bit_mask;
1127 : uint32_t hash_size;
1128 : uint8_t slot_count;
1129 : size_t additional_size;
1130 :
1131 1 : slot_count = 2;
1132 1 : additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
1133 : sizeof(spdm_key_usage_bit_mask_t);
1134 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1135 :
1136 1 : spdm_response_size = sizeof(spdm_digest_response_t) +
1137 1 : (hash_size + additional_size) * slot_count;
1138 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1139 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1140 :
1141 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
1142 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
1143 1 : spdm_response->header.param1 = 0;
1144 1 : spdm_response->header.param2 = 0;
1145 :
1146 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1147 : sizeof(m_libspdm_local_certificate_chain),
1148 : (uint8_t)(0xFF));
1149 :
1150 1 : digest = (void *)(spdm_response + 1);
1151 1 : key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
1152 1 : cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
1153 1 : sizeof(spdm_key_pair_id_t) * slot_count);
1154 1 : key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
1155 1 : sizeof(spdm_certificate_info_t) *
1156 : slot_count);
1157 :
1158 1 : libspdm_zero_mem (digest, hash_size * slot_count);
1159 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
1160 : sizeof(m_libspdm_local_certificate_chain), &digest[hash_size * 0]);
1161 1 : key_pair_id[0] = m_local_key_pair_id[0];
1162 1 : cert_info[0] = m_local_cert_info[0];
1163 1 : key_usage_bit_mask[0] = m_local_key_usage_bit_mask[0];
1164 :
1165 1 : spdm_response->header.param1 |= (1 << 0);
1166 1 : spdm_response->header.param2 |= (1 << 0);
1167 :
1168 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
1169 1 : sizeof(m_libspdm_local_certificate_chain), &digest[hash_size * 1]);
1170 1 : key_pair_id[1] = m_local_key_pair_id[1];
1171 1 : cert_info[1] = m_local_cert_info[1];
1172 1 : key_usage_bit_mask[1] = m_local_key_usage_bit_mask[1];
1173 :
1174 1 : spdm_response->header.param1 |= (1 << 1);
1175 1 : spdm_response->header.param2 |= (1 << 1);
1176 :
1177 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1178 : false, spdm_response_size,
1179 : spdm_response, response_size,
1180 : response);
1181 : }
1182 1 : return LIBSPDM_STATUS_SUCCESS;
1183 0 : default:
1184 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
1185 : }
1186 : }
1187 :
1188 : /**
1189 : * Test 1:
1190 : * Expected Behavior:
1191 : **/
1192 1 : static void req_get_digests_case1(void **state)
1193 : {
1194 1 : }
1195 :
1196 : /**
1197 : * Test 2: a request message is successfully sent and a response message is successfully received
1198 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a DIGESTS message is received
1199 : **/
1200 1 : static void req_get_digests_case2(void **state)
1201 : {
1202 : libspdm_return_t status;
1203 : libspdm_test_context_t *spdm_test_context;
1204 : libspdm_context_t *spdm_context;
1205 : libspdm_data_parameter_t parameter;
1206 : uint8_t slot_mask;
1207 : uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1208 : uint8_t my_total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1209 : uint8_t *digest;
1210 : size_t data_return_size;
1211 :
1212 1 : spdm_test_context = *state;
1213 1 : spdm_context = spdm_test_context->spdm_context;
1214 1 : spdm_test_context->case_id = 0x2;
1215 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1216 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1217 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1218 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
1219 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1220 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1221 : sizeof(m_libspdm_local_certificate_chain),
1222 : (uint8_t)(0xFF));
1223 1 : libspdm_reset_message_b(spdm_context);
1224 :
1225 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1226 : spdm_context->transcript.message_m.buffer_size =
1227 : spdm_context->transcript.message_m.max_buffer_size;
1228 : #endif
1229 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1230 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1231 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1232 :
1233 1 : assert_int_equal(slot_mask, 0x01);
1234 1 : libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
1235 1 : digest = my_total_digest_buffer;
1236 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
1237 : sizeof(m_libspdm_local_certificate_chain), digest);
1238 1 : assert_memory_equal (total_digest_buffer, my_total_digest_buffer,
1239 : sizeof(my_total_digest_buffer));
1240 :
1241 1 : parameter.location = LIBSPDM_DATA_LOCATION_CONNECTION;
1242 1 : data_return_size = sizeof(uint8_t);
1243 1 : status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
1244 : ¶meter, &slot_mask, &data_return_size);
1245 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1246 1 : assert_int_equal(data_return_size, sizeof(uint8_t));
1247 1 : assert_int_equal(slot_mask, 0x01);
1248 :
1249 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1250 : assert_int_equal(
1251 : spdm_context->transcript.message_b.buffer_size,
1252 : sizeof(spdm_get_digest_request_t) +
1253 : sizeof(spdm_digest_response_t) +
1254 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
1255 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
1256 : #endif
1257 1 : }
1258 :
1259 : /**
1260 : * Test 3:
1261 : * Expected Behavior:
1262 : **/
1263 1 : static void req_get_digests_case3(void **state)
1264 : {
1265 1 : }
1266 :
1267 : /**
1268 : * Test 4:
1269 : * Expected Behavior:
1270 : **/
1271 1 : static void req_get_digests_case4(void **state)
1272 : {
1273 1 : }
1274 :
1275 : /**
1276 : * Test 5:
1277 : * Expected Behavior:
1278 : **/
1279 1 : static void req_get_digests_case5(void **state)
1280 : {
1281 1 : }
1282 :
1283 : /**
1284 : * Test 6:
1285 : * Expected Behavior:
1286 : **/
1287 1 : static void req_get_digests_case6(void **state)
1288 : {
1289 1 : }
1290 :
1291 : /**
1292 : * Test 7:
1293 : * Expected Behavior:
1294 : **/
1295 1 : static void req_get_digests_case7(void **state)
1296 : {
1297 1 : }
1298 :
1299 : /**
1300 : * Test 8:
1301 : * Expected Behavior:
1302 : **/
1303 1 : static void req_get_digests_case8(void **state)
1304 : {
1305 1 : }
1306 :
1307 : /**
1308 : * Test 9:
1309 : * Expected Behavior:
1310 : **/
1311 1 : static void req_get_digests_case9(void **state)
1312 : {
1313 1 : }
1314 :
1315 : /**
1316 : * Test 10:
1317 : * Expected Behavior:
1318 : **/
1319 1 : static void req_get_digests_case10(void **state)
1320 : {
1321 1 : }
1322 :
1323 : /**
1324 : * Test 11:
1325 : * Expected Behavior:
1326 : **/
1327 1 : static void req_get_digests_case11(void **state)
1328 : {
1329 1 : }
1330 :
1331 : /**
1332 : * Test 12:
1333 : * Expected Behavior:
1334 : **/
1335 1 : static void req_get_digests_case12(void **state)
1336 : {
1337 1 : }
1338 :
1339 : /**
1340 : * Test 13:
1341 : * Expected Behavior:
1342 : **/
1343 1 : static void req_get_digests_case13(void **state)
1344 : {
1345 1 : }
1346 :
1347 : /**
1348 : * Test 14:
1349 : * Expected Behavior:
1350 : **/
1351 1 : static void req_get_digests_case14(void **state)
1352 : {
1353 1 : }
1354 :
1355 : /**
1356 : * Test 15:
1357 : * Expected Behavior:
1358 : **/
1359 1 : static void req_get_digests_case15(void **state)
1360 : {
1361 1 : }
1362 :
1363 : /**
1364 : * Test 16:
1365 : * Expected Behavior:
1366 : **/
1367 1 : static void req_get_digests_case16(void **state)
1368 : {
1369 1 : }
1370 :
1371 : /**
1372 : * Test 17:
1373 : * Expected Behavior:
1374 : **/
1375 1 : static void req_get_digests_case17(void **state)
1376 : {
1377 1 : }
1378 :
1379 : /**
1380 : * Test 18:
1381 : * Expected Behavior:
1382 : **/
1383 1 : static void req_get_digests_case18(void **state)
1384 : {
1385 1 : }
1386 :
1387 : /**
1388 : * Test 19:
1389 : * Expected Behavior:
1390 : **/
1391 1 : static void req_get_digests_case19(void **state)
1392 : {
1393 1 : }
1394 :
1395 : /**
1396 : * Test 20:
1397 : * Expected Behavior:
1398 : **/
1399 1 : static void req_get_digests_case20(void **state)
1400 : {
1401 1 : }
1402 :
1403 : /**
1404 : * Test 21:
1405 : * Expected Behavior:
1406 : **/
1407 1 : static void req_get_digests_case21(void **state)
1408 : {
1409 1 : }
1410 :
1411 : /**
1412 : * Test 22:
1413 : * Expected behavior:.
1414 : **/
1415 1 : static void req_get_digests_case22(void **state)
1416 : {
1417 1 : }
1418 :
1419 : /**
1420 : * Test 23: a request message is successfully sent and a response message is successfully received.
1421 : * Buffer B already has arbitrary data.
1422 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a DIGESTS message is
1423 : * received, buffer B appends the exchanged GET_DIGESTS and DIGESTS messages.
1424 : **/
1425 1 : static void req_get_digests_case23(void **state)
1426 : {
1427 : libspdm_return_t status;
1428 : libspdm_test_context_t *spdm_test_context;
1429 : libspdm_context_t *spdm_context;
1430 : uint8_t slot_mask;
1431 : uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1432 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1433 : size_t arbitrary_size;
1434 : #endif
1435 :
1436 1 : spdm_test_context = *state;
1437 1 : spdm_context = spdm_test_context->spdm_context;
1438 1 : spdm_test_context->case_id = 0x17;
1439 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1440 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1441 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1442 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
1443 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1444 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1445 : sizeof(m_libspdm_local_certificate_chain),
1446 : (uint8_t)(0xFF));
1447 1 : libspdm_reset_message_b(spdm_context);
1448 :
1449 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1450 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1451 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1452 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1453 : arbitrary_size = 8;
1454 : assert_int_equal(spdm_context->transcript.message_b.buffer_size,
1455 : arbitrary_size + m_libspdm_local_buffer_size);
1456 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
1457 : m_libspdm_local_buffer_size));
1458 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1459 : assert_memory_equal(spdm_context->transcript.message_b.buffer + arbitrary_size,
1460 : m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1461 : #endif
1462 1 : }
1463 :
1464 : /**
1465 : * Test 24: Test case for GetDigest, GetCert and GetDigest
1466 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a second GetDigest can be sent.
1467 : **/
1468 1 : static void req_get_digests_case24(void **state)
1469 : {
1470 : libspdm_return_t status;
1471 : libspdm_test_context_t *spdm_test_context;
1472 : libspdm_context_t *spdm_context;
1473 : libspdm_data_parameter_t parameter;
1474 : uint8_t slot_mask;
1475 : uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1476 : uint8_t my_total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1477 : uint8_t *digest;
1478 : size_t data_return_size;
1479 : void *data;
1480 : size_t data_size;
1481 : void *hash;
1482 : size_t hash_size;
1483 : const uint8_t *root_cert;
1484 : size_t root_cert_size;
1485 : size_t cert_chain_size;
1486 : uint8_t cert_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
1487 :
1488 1 : spdm_test_context = *state;
1489 1 : spdm_context = spdm_test_context->spdm_context;
1490 1 : spdm_test_context->case_id = 0x18;
1491 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1492 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1493 1 : spdm_context->connection_info.capability.flags |=
1494 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
1495 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1496 1 : spdm_context->connection_info.algorithm.base_hash_algo =
1497 : m_libspdm_use_hash_algo;
1498 1 : spdm_context->connection_info.algorithm.base_asym_algo =
1499 : m_libspdm_use_asym_algo;
1500 1 : spdm_context->connection_info.algorithm.req_base_asym_alg =
1501 : m_libspdm_use_req_asym_algo;
1502 1 : spdm_context->local_context.is_requester = true;
1503 :
1504 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1505 : m_libspdm_use_asym_algo, &data,
1506 : &data_size, &hash, &hash_size)) {
1507 0 : assert(false);
1508 : }
1509 1 : libspdm_x509_get_cert_from_cert_chain(
1510 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
1511 1 : data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
1512 : &root_cert, &root_cert_size);
1513 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "root cert data :\n"));
1514 1 : libspdm_dump_hex(root_cert, root_cert_size);
1515 1 : spdm_context->local_context.peer_root_cert_provision_size[0] =
1516 : root_cert_size;
1517 1 : spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
1518 :
1519 1 : m_get_digest = true;
1520 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1521 : spdm_context->transcript.message_m.buffer_size =
1522 : spdm_context->transcript.message_m.max_buffer_size;
1523 : #endif
1524 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1525 : /* first GetDigest */
1526 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1527 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1528 1 : assert_int_equal(slot_mask, 0x01);
1529 1 : libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
1530 1 : digest = my_total_digest_buffer;
1531 1 : if (m_libspdm_local_certificate_chain_test_cert == NULL) {
1532 0 : libspdm_read_responder_public_certificate_chain(
1533 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo,
1534 : &m_libspdm_local_certificate_chain_test_cert,
1535 : &m_libspdm_local_certificate_chain_size, NULL, NULL);
1536 : }
1537 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain_test_cert,
1538 : m_libspdm_local_certificate_chain_size, digest);
1539 1 : assert_memory_equal(total_digest_buffer, my_total_digest_buffer,
1540 : sizeof(my_total_digest_buffer));
1541 :
1542 1 : parameter.location = LIBSPDM_DATA_LOCATION_CONNECTION;
1543 1 : data_return_size = sizeof(uint8_t);
1544 1 : status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
1545 : ¶meter, &slot_mask, &data_return_size);
1546 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1547 1 : assert_int_equal(data_return_size, sizeof(uint8_t));
1548 1 : assert_int_equal(slot_mask, 0x01);
1549 :
1550 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1551 : assert_int_equal(
1552 : spdm_context->transcript.message_b.buffer_size,
1553 : sizeof(spdm_get_digest_request_t) +
1554 : sizeof(spdm_digest_response_t) +
1555 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
1556 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
1557 : #endif
1558 :
1559 1 : m_get_digest = false;
1560 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1561 : spdm_context->transcript.message_m.buffer_size =
1562 : spdm_context->transcript.message_m.max_buffer_size;
1563 : #endif
1564 1 : cert_chain_size = sizeof(cert_chain);
1565 1 : libspdm_zero_mem(cert_chain, sizeof(cert_chain));
1566 1 : status = libspdm_get_certificate(spdm_context, NULL, 0, &cert_chain_size,
1567 : cert_chain);
1568 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1569 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1570 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
1571 : #endif
1572 1 : free(data);
1573 :
1574 1 : m_get_digest = true;
1575 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1576 : spdm_context->transcript.message_m.buffer_size =
1577 : spdm_context->transcript.message_m.max_buffer_size;
1578 : #endif
1579 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1580 : /* second GetDigest */
1581 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1582 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1583 1 : assert_int_equal(slot_mask, 0x01);
1584 1 : libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
1585 1 : digest = my_total_digest_buffer;
1586 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain_test_cert,
1587 : m_libspdm_local_certificate_chain_size, digest);
1588 1 : assert_memory_equal (total_digest_buffer, my_total_digest_buffer,
1589 : sizeof(my_total_digest_buffer));
1590 1 : data_return_size = sizeof(uint8_t);
1591 1 : status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
1592 : ¶meter, &slot_mask, &data_return_size);
1593 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1594 1 : assert_int_equal(data_return_size, sizeof(uint8_t));
1595 1 : assert_int_equal(slot_mask, 0x01);
1596 :
1597 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1598 : assert_int_equal(
1599 : spdm_context->transcript.message_b.buffer_size,
1600 : sizeof(spdm_get_digest_request_t) +
1601 : sizeof(spdm_digest_response_t) +
1602 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo));
1603 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
1604 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = 0;
1605 : #else
1606 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size = 0;
1607 : #endif
1608 1 : }
1609 :
1610 : /**
1611 : * Test 25: a request message is successfully sent and a response message is successfully received
1612 : * in a session.
1613 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a DIGESTS message is received
1614 : **/
1615 1 : static void req_get_digests_case25(void **state)
1616 : {
1617 : libspdm_return_t status;
1618 : libspdm_test_context_t *spdm_test_context;
1619 : libspdm_context_t *spdm_context;
1620 : libspdm_data_parameter_t parameter;
1621 : uint8_t slot_mask;
1622 : uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1623 : uint8_t my_total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1624 : uint8_t *digest;
1625 : size_t data_return_size;
1626 : uint32_t session_id;
1627 : libspdm_session_info_t *session_info;
1628 :
1629 1 : spdm_test_context = *state;
1630 1 : spdm_context = spdm_test_context->spdm_context;
1631 1 : spdm_test_context->case_id = 0x19;
1632 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1633 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1634 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1635 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
1636 1 : spdm_context->connection_info.capability.flags |=
1637 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
1638 1 : spdm_context->connection_info.capability.flags |=
1639 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
1640 1 : spdm_context->connection_info.capability.flags |=
1641 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
1642 1 : spdm_context->local_context.capability.flags |=
1643 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
1644 1 : spdm_context->local_context.capability.flags |=
1645 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
1646 1 : spdm_context->local_context.capability.flags |=
1647 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
1648 1 : spdm_context->connection_info.algorithm.dhe_named_group =
1649 : m_libspdm_use_dhe_algo;
1650 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
1651 : m_libspdm_use_aead_algo;
1652 :
1653 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1654 :
1655 1 : session_id = 0xFFFFFFFF;
1656 1 : session_info = &spdm_context->session_info[0];
1657 1 : libspdm_session_info_init(spdm_context, session_info, session_id,
1658 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT, true);
1659 1 : libspdm_secured_message_set_session_state(session_info->secured_message_context,
1660 : LIBSPDM_SESSION_STATE_ESTABLISHED);
1661 :
1662 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1663 : sizeof(m_libspdm_local_certificate_chain),
1664 : (uint8_t)(0xFF));
1665 1 : libspdm_reset_message_b(spdm_context);
1666 :
1667 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1668 : session_info->session_transcript.message_m.buffer_size =
1669 : session_info->session_transcript.message_m.max_buffer_size;
1670 : #endif
1671 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1672 1 : status = libspdm_get_digest(spdm_context, &session_id, &slot_mask, &total_digest_buffer);
1673 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1674 :
1675 1 : assert_int_equal(slot_mask, 0x80);
1676 1 : libspdm_zero_mem(my_total_digest_buffer, sizeof(my_total_digest_buffer));
1677 1 : digest = my_total_digest_buffer;
1678 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
1679 : sizeof(m_libspdm_local_certificate_chain), digest);
1680 1 : assert_memory_equal (total_digest_buffer, my_total_digest_buffer,
1681 : sizeof(my_total_digest_buffer));
1682 :
1683 1 : parameter.location = LIBSPDM_DATA_LOCATION_CONNECTION;
1684 1 : data_return_size = sizeof(uint8_t);
1685 1 : status = libspdm_get_data(spdm_context, LIBSPDM_DATA_PEER_SLOT_MASK,
1686 : ¶meter, &slot_mask, &data_return_size);
1687 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1688 1 : assert_int_equal(data_return_size, sizeof(uint8_t));
1689 1 : assert_int_equal(slot_mask, 0x80);
1690 :
1691 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1692 : assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
1693 : #endif
1694 1 : }
1695 :
1696 :
1697 : /**
1698 : * Test 26: a response message is successfully sent ,
1699 : * Set multi_key_conn_rsp to check if it responds correctly
1700 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS
1701 : **/
1702 1 : static void req_get_digests_case26(void **state)
1703 : {
1704 : libspdm_return_t status;
1705 : libspdm_test_context_t *spdm_test_context;
1706 : libspdm_context_t *spdm_context;
1707 : uint8_t slot_mask;
1708 : uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1709 :
1710 1 : spdm_test_context = *state;
1711 1 : spdm_context = spdm_test_context->spdm_context;
1712 1 : spdm_test_context->case_id = 0x1A;
1713 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1714 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1715 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1716 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
1717 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1718 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1719 : sizeof(m_libspdm_local_certificate_chain),
1720 : (uint8_t)(0xFF));
1721 1 : libspdm_reset_message_b(spdm_context);
1722 :
1723 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1724 : spdm_context->transcript.message_m.buffer_size =
1725 : spdm_context->transcript.message_m.max_buffer_size;
1726 : #endif
1727 : /* Sub Case 1: Set multi_key_conn_rsp to true*/
1728 1 : spdm_context->connection_info.multi_key_conn_rsp = true;
1729 1 : libspdm_reset_message_d(spdm_context);
1730 :
1731 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1732 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1733 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1734 1 : assert_int_equal(
1735 : spdm_context->transcript.message_d.buffer_size,
1736 : sizeof(spdm_digest_response_t) + sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
1737 : sizeof(spdm_key_usage_bit_mask_t) +
1738 : libspdm_get_hash_size(
1739 : spdm_context->connection_info.algorithm.base_hash_algo));
1740 :
1741 : /* Sub Case 2: Set multi_key_conn_rsp to false*/
1742 1 : spdm_context->connection_info.multi_key_conn_rsp = false;
1743 1 : libspdm_reset_message_d(spdm_context);
1744 :
1745 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1746 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1747 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1748 1 : assert_int_equal(spdm_context->transcript.message_d.buffer_size,0);
1749 1 : }
1750 :
1751 : /**
1752 : * Test 27: a response message is successfully sent ,
1753 : * Set multi_key_conn_rsp to check if it responds correctly
1754 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS
1755 : **/
1756 1 : static void req_get_digests_case27(void **state)
1757 : {
1758 : libspdm_return_t status;
1759 : libspdm_test_context_t *spdm_test_context;
1760 : libspdm_context_t *spdm_context;
1761 : uint8_t slot_mask;
1762 : uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1763 : uint32_t hash_size;
1764 : uint8_t slot_count;
1765 : size_t additional_size;
1766 :
1767 1 : spdm_test_context = *state;
1768 1 : spdm_context = spdm_test_context->spdm_context;
1769 1 : spdm_test_context->case_id = 0x1B;
1770 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1771 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1772 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1773 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
1774 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1775 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1776 : sizeof(m_libspdm_local_certificate_chain),
1777 : (uint8_t)(0xFF));
1778 1 : libspdm_reset_message_b(spdm_context);
1779 :
1780 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1781 : spdm_context->transcript.message_m.buffer_size =
1782 : spdm_context->transcript.message_m.max_buffer_size;
1783 : #endif
1784 1 : spdm_context->connection_info.multi_key_conn_rsp = true;
1785 1 : libspdm_reset_message_d(spdm_context);
1786 :
1787 1 : m_local_key_pair_id[0] = 0x00;
1788 1 : m_local_cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
1789 1 : m_local_key_usage_bit_mask[0] = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
1790 :
1791 1 : m_local_key_pair_id[1] = 0x01;
1792 1 : m_local_cert_info[1] = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT;
1793 1 : m_local_key_usage_bit_mask[1] = SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
1794 :
1795 1 : m_local_key_pair_id[2] = 0x02;
1796 1 : m_local_cert_info[2] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
1797 1 : m_local_key_usage_bit_mask[2] = SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
1798 :
1799 1 : m_local_key_pair_id[3] = 0x03;
1800 1 : m_local_cert_info[3] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
1801 1 : m_local_key_usage_bit_mask[3] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
1802 :
1803 1 : m_local_key_pair_id[4] = 0x04;
1804 1 : m_local_cert_info[4] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
1805 1 : m_local_key_usage_bit_mask[4] = SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE;
1806 :
1807 1 : m_local_key_pair_id[5] = 0x05;
1808 1 : m_local_cert_info[5] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
1809 1 : m_local_key_usage_bit_mask[5] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
1810 :
1811 1 : m_local_key_pair_id[6] = 0x06;
1812 1 : m_local_cert_info[6] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
1813 1 : m_local_key_usage_bit_mask[6] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
1814 :
1815 1 : m_local_key_pair_id[7] = 0x07;
1816 1 : m_local_cert_info[7] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
1817 1 : m_local_key_usage_bit_mask[7] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
1818 :
1819 1 : slot_count = SPDM_MAX_SLOT_COUNT;
1820 1 : additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
1821 : sizeof(spdm_key_usage_bit_mask_t);
1822 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1823 :
1824 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1825 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1826 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1827 1 : assert_int_equal(
1828 : spdm_context->transcript.message_d.buffer_size,
1829 : sizeof(spdm_digest_response_t) + (additional_size + hash_size) * slot_count);
1830 :
1831 9 : for (uint8_t index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
1832 8 : assert_memory_equal((void *)&m_local_key_pair_id[index],
1833 : (void *)&spdm_context->connection_info.peer_key_pair_id[index],
1834 : sizeof(spdm_key_pair_id_t));
1835 8 : assert_memory_equal((void *)&m_local_cert_info[index],
1836 : (void *)&spdm_context->connection_info.peer_cert_info[index],
1837 : sizeof(spdm_key_pair_id_t));
1838 8 : assert_memory_equal((void *)&m_local_key_usage_bit_mask[index],
1839 : (void *)&spdm_context->connection_info.peer_key_usage_bit_mask[index],
1840 : sizeof(spdm_key_pair_id_t));
1841 : }
1842 1 : }
1843 :
1844 : /**
1845 : * Test 28:
1846 : * 1.For slot 0, at least one of KeyExUse , ChallengeUse , MeasurementUse , and EndpointInfoUse shall be set. The
1847 : * corresponding capability bits shall be set appropriately
1848 : * 2.In all cases, the certificate model for slot 0 shall be either the device certificate model or the alias certificate model.
1849 : * Set KeyUsageMask to 0 and Set CertificateInfo to SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT(GenericCert model)
1850 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_INVALID_MSG_FIELD
1851 : **/
1852 1 : static void req_get_digests_case28(void **state)
1853 : {
1854 : libspdm_return_t status;
1855 : libspdm_test_context_t *spdm_test_context;
1856 : libspdm_context_t *spdm_context;
1857 : uint8_t slot_mask;
1858 : uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1859 :
1860 1 : spdm_test_context = *state;
1861 1 : spdm_context = spdm_test_context->spdm_context;
1862 1 : spdm_test_context->case_id = 0x1C;
1863 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1864 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1865 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1866 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
1867 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1868 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
1869 : sizeof(m_libspdm_local_certificate_chain),
1870 : (uint8_t)(0xFF));
1871 1 : libspdm_reset_message_b(spdm_context);
1872 :
1873 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1874 : spdm_context->transcript.message_m.buffer_size =
1875 : spdm_context->transcript.message_m.max_buffer_size;
1876 : #endif
1877 :
1878 1 : spdm_context->connection_info.multi_key_conn_rsp = true;
1879 1 : libspdm_reset_message_d(spdm_context);
1880 :
1881 : /* Sub Case 1: Set KeyUsageMask to 0*/
1882 1 : m_local_key_pair_id[0] = 0x00;
1883 1 : m_local_cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
1884 1 : m_local_key_usage_bit_mask[0] = 0;
1885 :
1886 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1887 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1888 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1889 :
1890 : /* Sub Case 2: Set CertificateInfo to SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT*/
1891 1 : m_local_key_pair_id[0] = 0x00;
1892 1 : m_local_cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
1893 1 : m_local_key_usage_bit_mask[0] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
1894 :
1895 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1896 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1897 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1898 1 : }
1899 :
1900 : /**
1901 : * Test 29:
1902 : * Digest: If a certificate chain is not present in this slot, the value of this field shall be all zeros.
1903 : * CertModel: Value of 0 indicates either that the certificate slot does not contain any certificates or that the corresponding
1904 : * MULTI_KEY_CONN_REQ or MULTI_KEY_CONN_RSP is false.
1905 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_INVALID_MSG_FIELD
1906 : **/
1907 1 : static void req_get_digests_case29(void **state)
1908 : {
1909 : libspdm_return_t status;
1910 : libspdm_test_context_t *spdm_test_context;
1911 : libspdm_context_t *spdm_context;
1912 : uint8_t slot_mask;
1913 : uint8_t total_digest_buffer[LIBSPDM_MAX_HASH_SIZE * SPDM_MAX_SLOT_COUNT];
1914 :
1915 1 : spdm_test_context = *state;
1916 1 : spdm_context = spdm_test_context->spdm_context;
1917 1 : spdm_test_context->case_id = 0x1D;
1918 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1919 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1920 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1921 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
1922 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1923 1 : libspdm_zero_mem(m_libspdm_local_certificate_chain, sizeof(m_libspdm_local_certificate_chain));
1924 1 : libspdm_reset_message_b(spdm_context);
1925 :
1926 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1927 : spdm_context->transcript.message_m.buffer_size =
1928 : spdm_context->transcript.message_m.max_buffer_size;
1929 : #endif
1930 :
1931 1 : spdm_context->connection_info.multi_key_conn_rsp = true;
1932 1 : libspdm_reset_message_d(spdm_context);
1933 :
1934 1 : m_local_key_pair_id[0] = 0x00;
1935 1 : m_local_cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
1936 1 : m_local_key_usage_bit_mask[0] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
1937 :
1938 : /* CertModel:Value of 0 indicates either that the certificate slot does not contain any certificates or that the corresponding
1939 : * MULTI_KEY_CONN_REQ or MULTI_KEY_CONN_RSP is false. */
1940 1 : m_local_key_pair_id[1] = 0x01;
1941 1 : m_local_cert_info[1] = SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE;
1942 1 : m_local_key_usage_bit_mask[1] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
1943 :
1944 1 : libspdm_zero_mem(total_digest_buffer, sizeof(total_digest_buffer));
1945 1 : status = libspdm_get_digest(spdm_context, NULL, &slot_mask, &total_digest_buffer);
1946 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1947 1 : }
1948 :
1949 1 : int libspdm_req_get_digests_test(void)
1950 : {
1951 1 : const struct CMUnitTest test_cases[] = {
1952 : cmocka_unit_test(req_get_digests_case1),
1953 : cmocka_unit_test(req_get_digests_case2),
1954 : cmocka_unit_test(req_get_digests_case3),
1955 : cmocka_unit_test(req_get_digests_case4),
1956 : cmocka_unit_test(req_get_digests_case5),
1957 : cmocka_unit_test(req_get_digests_case6),
1958 : cmocka_unit_test(req_get_digests_case7),
1959 : cmocka_unit_test(req_get_digests_case8),
1960 : cmocka_unit_test(req_get_digests_case9),
1961 : cmocka_unit_test(req_get_digests_case10),
1962 : cmocka_unit_test(req_get_digests_case11),
1963 : cmocka_unit_test(req_get_digests_case12),
1964 : cmocka_unit_test(req_get_digests_case13),
1965 : cmocka_unit_test(req_get_digests_case14),
1966 : cmocka_unit_test(req_get_digests_case15),
1967 : cmocka_unit_test(req_get_digests_case16),
1968 : cmocka_unit_test(req_get_digests_case17),
1969 : cmocka_unit_test(req_get_digests_case18),
1970 : cmocka_unit_test(req_get_digests_case19),
1971 : cmocka_unit_test(req_get_digests_case20),
1972 : cmocka_unit_test(req_get_digests_case21),
1973 : cmocka_unit_test(req_get_digests_case22),
1974 : cmocka_unit_test(req_get_digests_case23),
1975 : cmocka_unit_test(req_get_digests_case24),
1976 : cmocka_unit_test(req_get_digests_case25),
1977 : cmocka_unit_test(req_get_digests_case26),
1978 : cmocka_unit_test(req_get_digests_case27),
1979 : cmocka_unit_test(req_get_digests_case28),
1980 : cmocka_unit_test(req_get_digests_case29),
1981 : };
1982 :
1983 1 : libspdm_test_context_t test_context = {
1984 : LIBSPDM_TEST_CONTEXT_VERSION,
1985 : true,
1986 : send_message,
1987 : receive_message,
1988 : };
1989 :
1990 1 : libspdm_setup_test_context(&test_context);
1991 :
1992 1 : return cmocka_run_group_tests(test_cases,
1993 : libspdm_unit_test_group_setup,
1994 : libspdm_unit_test_group_teardown);
1995 : }
1996 :
1997 : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
|