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