Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2022 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_ENABLE_CAPABILITY_KEY_EX_CAP
12 :
13 : static size_t m_libspdm_local_buffer_size;
14 : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
15 :
16 : static uint8_t m_libspdm_dummy_buffer[LIBSPDM_MAX_HASH_SIZE];
17 : static const uint8_t m_libspdm_zero_buffer[LIBSPDM_MAX_HASH_SIZE] = {0};
18 :
19 : static libspdm_th_managed_buffer_t th_curr;
20 :
21 40 : void libspdm_secured_message_set_response_finished_key(
22 : void *spdm_secured_message_context, const void *key, size_t key_size)
23 : {
24 : libspdm_secured_message_context_t *secured_message_context;
25 :
26 40 : secured_message_context = spdm_secured_message_context;
27 40 : LIBSPDM_ASSERT(key_size == secured_message_context->hash_size);
28 40 : libspdm_copy_mem(secured_message_context->handshake_secret.response_finished_key,
29 : sizeof(secured_message_context->handshake_secret.response_finished_key),
30 : key, secured_message_context->hash_size);
31 40 : }
32 :
33 39 : libspdm_return_t libspdm_requester_finish_test_send_message(void *spdm_context,
34 : size_t request_size,
35 : const void *request,
36 : uint64_t timeout)
37 : {
38 : libspdm_test_context_t *spdm_test_context;
39 : const uint8_t *ptr;
40 :
41 39 : spdm_test_context = libspdm_get_test_context();
42 39 : ptr = (const uint8_t *)request;
43 39 : switch (spdm_test_context->case_id) {
44 1 : case 0x1:
45 1 : return LIBSPDM_STATUS_SEND_FAIL;
46 1 : case 0x2:
47 1 : m_libspdm_local_buffer_size = 0;
48 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
49 : request_size - 1);
50 1 : m_libspdm_local_buffer_size += (request_size - 1);
51 1 : return LIBSPDM_STATUS_SUCCESS;
52 0 : case 0x3:
53 0 : m_libspdm_local_buffer_size = 0;
54 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
55 : request_size - 1);
56 0 : m_libspdm_local_buffer_size += (request_size - 1);
57 0 : return LIBSPDM_STATUS_SUCCESS;
58 1 : case 0x4:
59 1 : m_libspdm_local_buffer_size = 0;
60 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
61 : request_size - 1);
62 1 : m_libspdm_local_buffer_size += (request_size - 1);
63 1 : return LIBSPDM_STATUS_SUCCESS;
64 1 : case 0x5:
65 1 : m_libspdm_local_buffer_size = 0;
66 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
67 : request_size - 1);
68 1 : m_libspdm_local_buffer_size += (request_size - 1);
69 1 : return LIBSPDM_STATUS_SUCCESS;
70 2 : case 0x6:
71 2 : m_libspdm_local_buffer_size = 0;
72 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
73 : request_size - 1);
74 2 : m_libspdm_local_buffer_size += (request_size - 1);
75 2 : return LIBSPDM_STATUS_SUCCESS;
76 1 : case 0x7:
77 1 : m_libspdm_local_buffer_size = 0;
78 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
79 : request_size - 1);
80 1 : m_libspdm_local_buffer_size += (request_size - 1);
81 1 : return LIBSPDM_STATUS_SUCCESS;
82 2 : case 0x8:
83 2 : m_libspdm_local_buffer_size = 0;
84 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
85 : request_size - 1);
86 2 : m_libspdm_local_buffer_size += (request_size - 1);
87 2 : return LIBSPDM_STATUS_SUCCESS;
88 2 : case 0x9: {
89 : static size_t sub_index = 0;
90 2 : if (sub_index == 0) {
91 1 : m_libspdm_local_buffer_size = 0;
92 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
93 : request_size - 1);
94 1 : m_libspdm_local_buffer_size += (request_size - 1);
95 1 : sub_index++;
96 : }
97 : }
98 2 : return LIBSPDM_STATUS_SUCCESS;
99 18 : case 0xA:
100 18 : m_libspdm_local_buffer_size = 0;
101 18 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
102 : request_size - 1);
103 18 : m_libspdm_local_buffer_size += (request_size - 1);
104 18 : return LIBSPDM_STATUS_SUCCESS;
105 1 : case 0xB:
106 1 : m_libspdm_local_buffer_size = 0;
107 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
108 : request_size - 1);
109 1 : m_libspdm_local_buffer_size += (request_size - 1);
110 1 : return LIBSPDM_STATUS_SUCCESS;
111 0 : case 0xC:
112 0 : m_libspdm_local_buffer_size = 0;
113 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
114 : request_size - 1);
115 0 : m_libspdm_local_buffer_size += (request_size - 1);
116 0 : return LIBSPDM_STATUS_SUCCESS;
117 0 : case 0xD:
118 0 : m_libspdm_local_buffer_size = 0;
119 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
120 : request_size - 1);
121 0 : m_libspdm_local_buffer_size += (request_size - 1);
122 0 : return LIBSPDM_STATUS_SUCCESS;
123 1 : case 0xE:
124 1 : m_libspdm_local_buffer_size = 0;
125 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
126 : request_size - 1);
127 1 : m_libspdm_local_buffer_size += (request_size - 1);
128 1 : return LIBSPDM_STATUS_SUCCESS;
129 0 : case 0xF:
130 0 : m_libspdm_local_buffer_size = 0;
131 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
132 : request_size - 1);
133 0 : m_libspdm_local_buffer_size += (request_size - 1);
134 0 : return LIBSPDM_STATUS_SUCCESS;
135 1 : case 0x10:
136 1 : m_libspdm_local_buffer_size = 0;
137 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
138 : request_size - 1);
139 1 : m_libspdm_local_buffer_size += (request_size - 1);
140 1 : return LIBSPDM_STATUS_SUCCESS;
141 1 : case 0x11:
142 1 : m_libspdm_local_buffer_size = 0;
143 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
144 : request_size - 1);
145 1 : m_libspdm_local_buffer_size += (request_size - 1);
146 1 : return LIBSPDM_STATUS_SUCCESS;
147 1 : case 0x12:
148 1 : m_libspdm_local_buffer_size = 0;
149 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
150 : request_size - 1);
151 1 : m_libspdm_local_buffer_size += (request_size - 1);
152 1 : return LIBSPDM_STATUS_SUCCESS;
153 0 : case 0x13:
154 0 : m_libspdm_local_buffer_size = 0;
155 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
156 : request_size - 1);
157 0 : m_libspdm_local_buffer_size += (request_size - 1);
158 0 : return LIBSPDM_STATUS_SUCCESS;
159 1 : case 0x14:
160 1 : m_libspdm_local_buffer_size = 0;
161 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
162 : request_size - 1);
163 1 : m_libspdm_local_buffer_size += (request_size - 1);
164 1 : return LIBSPDM_STATUS_SUCCESS;
165 1 : case 0x15:
166 1 : m_libspdm_local_buffer_size = 0;
167 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
168 : request_size - 1);
169 1 : m_libspdm_local_buffer_size += (request_size - 1);
170 1 : return LIBSPDM_STATUS_SUCCESS;
171 1 : case 0x16:
172 1 : m_libspdm_local_buffer_size = 0;
173 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
174 : request_size - 1);
175 1 : m_libspdm_local_buffer_size += (request_size - 1);
176 1 : return LIBSPDM_STATUS_SUCCESS;
177 2 : case 0x17:
178 : case 0x18:
179 2 : m_libspdm_local_buffer_size = 0;
180 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
181 : request_size - 1);
182 2 : m_libspdm_local_buffer_size += (request_size - 1);
183 2 : return LIBSPDM_STATUS_SUCCESS;
184 0 : default:
185 0 : return LIBSPDM_STATUS_SEND_FAIL;
186 : }
187 : }
188 :
189 38 : libspdm_return_t libspdm_requester_finish_test_receive_message(
190 : void *spdm_context, size_t *response_size,
191 : void **response, uint64_t timeout)
192 : {
193 : libspdm_test_context_t *spdm_test_context;
194 :
195 38 : spdm_test_context = libspdm_get_test_context();
196 38 : switch (spdm_test_context->case_id) {
197 0 : case 0x1:
198 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
199 :
200 1 : case 0x2: {
201 : spdm_finish_response_t *spdm_response;
202 : uint32_t hash_size;
203 : uint32_t hmac_size;
204 : uint8_t *ptr;
205 : void *data;
206 : size_t data_size;
207 : uint8_t *cert_buffer;
208 : size_t cert_buffer_size;
209 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
210 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
211 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
212 : size_t spdm_response_size;
213 : size_t transport_header_size;
214 :
215 : ((libspdm_context_t *)spdm_context)
216 1 : ->connection_info.algorithm.base_asym_algo =
217 : m_libspdm_use_asym_algo;
218 : ((libspdm_context_t *)spdm_context)
219 1 : ->connection_info.algorithm.base_hash_algo =
220 : m_libspdm_use_hash_algo;
221 : ((libspdm_context_t *)spdm_context)
222 1 : ->connection_info.algorithm.dhe_named_group =
223 : m_libspdm_use_dhe_algo;
224 : ((libspdm_context_t *)spdm_context)
225 1 : ->connection_info.algorithm.measurement_hash_algo =
226 : m_libspdm_use_measurement_hash_algo;
227 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
228 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
229 1 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
230 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
231 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
232 :
233 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
234 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
235 1 : spdm_response->header.param1 = 0;
236 1 : spdm_response->header.param2 = 0;
237 1 : ptr = (void *)(spdm_response + 1);
238 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
239 : sizeof(m_libspdm_local_buffer)
240 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
241 : m_libspdm_local_buffer),
242 : spdm_response, sizeof(spdm_finish_response_t));
243 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
244 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
245 : m_libspdm_use_asym_algo, &data,
246 : &data_size, NULL, NULL);
247 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
248 1 : cert_buffer = (uint8_t *)data;
249 1 : cert_buffer_size = data_size;
250 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
251 : cert_buffer_hash);
252 : /* transcript.message_a size is 0*/
253 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
254 : /* session_transcript.message_k is 0*/
255 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
256 : m_libspdm_local_buffer_size);
257 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
258 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
259 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
260 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
261 : response_finished_key, hash_size, ptr);
262 1 : ptr += hmac_size;
263 1 : free(data);
264 :
265 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
266 : false, spdm_response_size,
267 : spdm_response, response_size,
268 : response);
269 : }
270 1 : return LIBSPDM_STATUS_SUCCESS;
271 :
272 0 : case 0x3: {
273 : spdm_finish_response_t *spdm_response;
274 : uint32_t hash_size;
275 : uint32_t hmac_size;
276 : uint8_t *ptr;
277 : void *data;
278 : size_t data_size;
279 : uint8_t *cert_buffer;
280 : size_t cert_buffer_size;
281 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
282 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
283 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
284 : size_t spdm_response_size;
285 : size_t transport_header_size;
286 :
287 : ((libspdm_context_t *)spdm_context)
288 0 : ->connection_info.algorithm.base_asym_algo =
289 : m_libspdm_use_asym_algo;
290 : ((libspdm_context_t *)spdm_context)
291 0 : ->connection_info.algorithm.base_hash_algo =
292 : m_libspdm_use_hash_algo;
293 : ((libspdm_context_t *)spdm_context)
294 0 : ->connection_info.algorithm.dhe_named_group =
295 : m_libspdm_use_dhe_algo;
296 : ((libspdm_context_t *)spdm_context)
297 0 : ->connection_info.algorithm.measurement_hash_algo =
298 : m_libspdm_use_measurement_hash_algo;
299 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
300 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
301 0 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
302 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
303 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
304 :
305 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
306 0 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
307 0 : spdm_response->header.param1 = 0;
308 0 : spdm_response->header.param2 = 0;
309 0 : ptr = (void *)(spdm_response + 1);
310 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
311 : sizeof(m_libspdm_local_buffer)
312 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
313 : m_libspdm_local_buffer),
314 : spdm_response, sizeof(spdm_finish_response_t));
315 0 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
316 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
317 : m_libspdm_use_asym_algo, &data,
318 : &data_size, NULL, NULL);
319 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
320 0 : cert_buffer = (uint8_t *)data;
321 0 : cert_buffer_size = data_size;
322 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
323 : cert_buffer_hash);
324 : /* transcript.message_a size is 0*/
325 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
326 : /* session_transcript.message_k is 0*/
327 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
328 : m_libspdm_local_buffer_size);
329 0 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
330 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
331 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
332 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
333 : response_finished_key, hash_size, ptr);
334 0 : ptr += hmac_size;
335 0 : free(data);
336 :
337 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
338 : false, spdm_response_size,
339 : spdm_response, response_size,
340 : response);
341 : }
342 0 : return LIBSPDM_STATUS_SUCCESS;
343 :
344 1 : case 0x4: {
345 : spdm_error_response_t *spdm_response;
346 : size_t spdm_response_size;
347 : size_t transport_header_size;
348 :
349 1 : spdm_response_size = sizeof(spdm_error_response_t);
350 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
351 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
352 :
353 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
354 1 : spdm_response->header.request_response_code = SPDM_ERROR;
355 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
356 1 : spdm_response->header.param2 = 0;
357 :
358 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
359 : false, spdm_response_size,
360 : spdm_response,
361 : response_size, response);
362 : }
363 1 : return LIBSPDM_STATUS_SUCCESS;
364 :
365 1 : case 0x5: {
366 : spdm_error_response_t *spdm_response;
367 : size_t spdm_response_size;
368 : size_t transport_header_size;
369 :
370 1 : spdm_response_size = sizeof(spdm_error_response_t);
371 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
372 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
373 :
374 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
375 1 : spdm_response->header.request_response_code = SPDM_ERROR;
376 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
377 1 : spdm_response->header.param2 = 0;
378 :
379 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
380 : false, spdm_response_size,
381 : spdm_response,
382 : response_size, response);
383 : }
384 1 : return LIBSPDM_STATUS_SUCCESS;
385 :
386 2 : case 0x6: {
387 : static size_t sub_index1 = 0;
388 2 : if (sub_index1 == 0) {
389 : spdm_error_response_t *spdm_response;
390 : size_t spdm_response_size;
391 : size_t transport_header_size;
392 :
393 1 : spdm_response_size = sizeof(spdm_error_response_t);
394 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
395 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
396 :
397 1 : spdm_response->header.spdm_version =
398 : SPDM_MESSAGE_VERSION_11;
399 1 : spdm_response->header.request_response_code = SPDM_ERROR;
400 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
401 1 : spdm_response->header.param2 = 0;
402 :
403 1 : libspdm_transport_test_encode_message(
404 : spdm_context, NULL, false, false,
405 : spdm_response_size, spdm_response,
406 : response_size, response);
407 1 : sub_index1++;
408 1 : } else if (sub_index1 == 1) {
409 : spdm_finish_response_t *spdm_response;
410 : uint32_t hash_size;
411 : uint32_t hmac_size;
412 : uint8_t *ptr;
413 : void *data;
414 : size_t data_size;
415 : uint8_t *cert_buffer;
416 : size_t cert_buffer_size;
417 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
418 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
419 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
420 : size_t spdm_response_size;
421 : size_t transport_header_size;
422 :
423 : ((libspdm_context_t *)spdm_context)
424 1 : ->connection_info.algorithm.base_asym_algo =
425 : m_libspdm_use_asym_algo;
426 : ((libspdm_context_t *)spdm_context)
427 1 : ->connection_info.algorithm.base_hash_algo =
428 : m_libspdm_use_hash_algo;
429 : ((libspdm_context_t *)spdm_context)
430 1 : ->connection_info.algorithm.dhe_named_group =
431 : m_libspdm_use_dhe_algo;
432 : ((libspdm_context_t *)spdm_context)
433 : ->connection_info.algorithm
434 1 : .measurement_hash_algo =
435 : m_libspdm_use_measurement_hash_algo;
436 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
437 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
438 1 : spdm_response_size =
439 1 : sizeof(spdm_finish_response_t) + hmac_size;
440 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
441 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
442 :
443 1 : spdm_response->header.spdm_version =
444 : SPDM_MESSAGE_VERSION_11;
445 1 : spdm_response->header.request_response_code =
446 : SPDM_FINISH_RSP;
447 1 : spdm_response->header.param1 = 0;
448 1 : spdm_response->header.param2 = 0;
449 1 : ptr = (void *)(spdm_response + 1);
450 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
451 : sizeof(m_libspdm_local_buffer)
452 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
453 : m_libspdm_local_buffer),
454 : spdm_response, sizeof(spdm_finish_response_t));
455 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
456 1 : libspdm_read_responder_public_certificate_chain(
457 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
458 : &data_size, NULL, NULL);
459 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
460 1 : cert_buffer = (uint8_t *)data;
461 1 : cert_buffer_size = data_size;
462 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
463 : cert_buffer_size, cert_buffer_hash);
464 : /* transcript.message_a size is 0*/
465 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
466 : hash_size);
467 : /* session_transcript.message_k is 0*/
468 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
469 : m_libspdm_local_buffer_size);
470 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE,
471 : (uint8_t)(0xFF));
472 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
473 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
474 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
475 : response_finished_key, hash_size, ptr);
476 1 : ptr += hmac_size;
477 1 : free(data);
478 :
479 1 : libspdm_transport_test_encode_message(
480 : spdm_context, NULL, false, false, spdm_response_size,
481 : spdm_response, response_size, response);
482 : }
483 : }
484 2 : return LIBSPDM_STATUS_SUCCESS;
485 :
486 1 : case 0x7: {
487 : spdm_error_response_t *spdm_response;
488 : size_t spdm_response_size;
489 : size_t transport_header_size;
490 :
491 1 : spdm_response_size = sizeof(spdm_error_response_t);
492 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
493 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
494 :
495 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
496 1 : spdm_response->header.request_response_code = SPDM_ERROR;
497 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
498 1 : spdm_response->header.param2 = 0;
499 :
500 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
501 : false, spdm_response_size,
502 : spdm_response,
503 : response_size, response);
504 : }
505 1 : return LIBSPDM_STATUS_SUCCESS;
506 :
507 2 : case 0x8: {
508 : spdm_error_response_data_response_not_ready_t *spdm_response;
509 : size_t spdm_response_size;
510 : size_t transport_header_size;
511 :
512 2 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
513 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
514 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
515 :
516 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
517 2 : spdm_response->header.request_response_code = SPDM_ERROR;
518 2 : spdm_response->header.param1 =
519 : SPDM_ERROR_CODE_RESPONSE_NOT_READY;
520 2 : spdm_response->header.param2 = 0;
521 2 : spdm_response->extend_error_data.rd_exponent = 1;
522 2 : spdm_response->extend_error_data.rd_tm = 2;
523 2 : spdm_response->extend_error_data.request_code = SPDM_FINISH;
524 2 : spdm_response->extend_error_data.token = 0;
525 :
526 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
527 : false, spdm_response_size,
528 : spdm_response,
529 : response_size, response);
530 : }
531 2 : return LIBSPDM_STATUS_SUCCESS;
532 :
533 2 : case 0x9: {
534 : static size_t sub_index2 = 0;
535 2 : if (sub_index2 == 0) {
536 : spdm_error_response_data_response_not_ready_t
537 : *spdm_response;
538 : size_t spdm_response_size;
539 : size_t transport_header_size;
540 :
541 1 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
542 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
543 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
544 :
545 1 : spdm_response->header.spdm_version =
546 : SPDM_MESSAGE_VERSION_11;
547 1 : spdm_response->header.request_response_code = SPDM_ERROR;
548 1 : spdm_response->header.param1 =
549 : SPDM_ERROR_CODE_RESPONSE_NOT_READY;
550 1 : spdm_response->header.param2 = 0;
551 1 : spdm_response->extend_error_data.rd_exponent = 1;
552 1 : spdm_response->extend_error_data.rd_tm = 2;
553 1 : spdm_response->extend_error_data.request_code =
554 : SPDM_FINISH;
555 1 : spdm_response->extend_error_data.token = 1;
556 :
557 1 : libspdm_transport_test_encode_message(
558 : spdm_context, NULL, false, false,
559 : spdm_response_size, spdm_response,
560 : response_size, response);
561 1 : sub_index2++;
562 1 : } else if (sub_index2 == 1) {
563 : spdm_finish_response_t *spdm_response;
564 : uint32_t hash_size;
565 : uint32_t hmac_size;
566 : uint8_t *ptr;
567 : void *data;
568 : size_t data_size;
569 : uint8_t *cert_buffer;
570 : size_t cert_buffer_size;
571 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
572 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
573 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
574 : size_t spdm_response_size;
575 : size_t transport_header_size;
576 :
577 : ((libspdm_context_t *)spdm_context)
578 1 : ->connection_info.algorithm.base_asym_algo =
579 : m_libspdm_use_asym_algo;
580 : ((libspdm_context_t *)spdm_context)
581 1 : ->connection_info.algorithm.base_hash_algo =
582 : m_libspdm_use_hash_algo;
583 : ((libspdm_context_t *)spdm_context)
584 1 : ->connection_info.algorithm.dhe_named_group =
585 : m_libspdm_use_dhe_algo;
586 : ((libspdm_context_t *)spdm_context)
587 : ->connection_info.algorithm
588 1 : .measurement_hash_algo =
589 : m_libspdm_use_measurement_hash_algo;
590 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
591 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
592 1 : spdm_response_size =
593 1 : sizeof(spdm_finish_response_t) + hmac_size;
594 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
595 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
596 :
597 1 : spdm_response->header.spdm_version =
598 : SPDM_MESSAGE_VERSION_11;
599 1 : spdm_response->header.request_response_code =
600 : SPDM_FINISH_RSP;
601 1 : spdm_response->header.param1 = 0;
602 1 : spdm_response->header.param2 = 0;
603 1 : ptr = (void *)(spdm_response + 1);
604 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
605 : sizeof(m_libspdm_local_buffer)
606 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
607 : m_libspdm_local_buffer),
608 : spdm_response, sizeof(spdm_finish_response_t));
609 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
610 1 : libspdm_read_responder_public_certificate_chain(
611 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
612 : &data_size, NULL, NULL);
613 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
614 1 : cert_buffer = (uint8_t *)data;
615 1 : cert_buffer_size = data_size;
616 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
617 : cert_buffer_size, cert_buffer_hash);
618 : /* transcript.message_a size is 0*/
619 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash,
620 : hash_size);
621 : /* session_transcript.message_k is 0*/
622 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
623 : m_libspdm_local_buffer_size);
624 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE,
625 : (uint8_t)(0xFF));
626 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
627 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
628 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
629 : response_finished_key, hash_size, ptr);
630 1 : ptr += hmac_size;
631 1 : free(data);
632 :
633 1 : libspdm_transport_test_encode_message(
634 : spdm_context, NULL, false, false, spdm_response_size,
635 : spdm_response, response_size, response);
636 : }
637 : }
638 2 : return LIBSPDM_STATUS_SUCCESS;
639 :
640 18 : case 0xA:
641 : {
642 : static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
643 :
644 : spdm_error_response_t *spdm_response;
645 : size_t spdm_response_size;
646 : size_t transport_header_size;
647 :
648 18 : spdm_response_size = sizeof(spdm_error_response_t);
649 18 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
650 18 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
651 :
652 18 : if(error_code <= 0xff) {
653 18 : libspdm_zero_mem (spdm_response, spdm_response_size);
654 18 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
655 18 : spdm_response->header.request_response_code = SPDM_ERROR;
656 18 : spdm_response->header.param1 = (uint8_t) error_code;
657 18 : spdm_response->header.param2 = 0;
658 :
659 18 : libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
660 : spdm_response_size, spdm_response,
661 : response_size, response);
662 : }
663 :
664 18 : error_code++;
665 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
666 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
667 : }
668 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
669 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
670 : }
671 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
672 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
673 : }
674 : }
675 18 : return LIBSPDM_STATUS_SUCCESS;
676 1 : case 0xB:
677 : {
678 : spdm_finish_response_t *spdm_response;
679 : uint32_t hash_size;
680 : uint32_t hmac_size;
681 : uint8_t *ptr;
682 : void *data;
683 : size_t data_size;
684 : uint8_t *cert_buffer;
685 : size_t cert_buffer_size;
686 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
687 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
688 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
689 : size_t spdm_response_size;
690 : size_t transport_header_size;
691 :
692 : ((libspdm_context_t *)spdm_context)
693 1 : ->connection_info.algorithm.base_asym_algo =
694 : m_libspdm_use_asym_algo;
695 : ((libspdm_context_t *)spdm_context)
696 1 : ->connection_info.algorithm.base_hash_algo =
697 : m_libspdm_use_hash_algo;
698 : ((libspdm_context_t *)spdm_context)
699 1 : ->connection_info.algorithm.dhe_named_group =
700 : m_libspdm_use_dhe_algo;
701 : ((libspdm_context_t *)spdm_context)
702 1 : ->connection_info.algorithm.measurement_hash_algo =
703 : m_libspdm_use_measurement_hash_algo;
704 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
705 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
706 1 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
707 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
708 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
709 :
710 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
711 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
712 1 : spdm_response->header.param1 = 0;
713 1 : spdm_response->header.param2 = 0;
714 1 : ptr = (void *)(spdm_response + 1);
715 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
716 : sizeof(m_libspdm_local_buffer)
717 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
718 : m_libspdm_local_buffer),
719 : spdm_response, sizeof(spdm_finish_response_t));
720 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
721 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
722 : m_libspdm_use_asym_algo, &data,
723 : &data_size, NULL, NULL);
724 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
725 1 : cert_buffer = (uint8_t *)data;
726 1 : cert_buffer_size = data_size;
727 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
728 : cert_buffer_hash);
729 : /* transcript.message_a size is 0*/
730 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
731 : /* session_transcript.message_k is 0*/
732 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
733 : m_libspdm_local_buffer_size);
734 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
735 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
736 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
737 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
738 : response_finished_key, hash_size, ptr);
739 1 : ptr += hmac_size;
740 1 : free(data);
741 :
742 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
743 : false, spdm_response_size,
744 : spdm_response, response_size,
745 : response);
746 : }
747 1 : return LIBSPDM_STATUS_SUCCESS;
748 :
749 0 : case 0xC: {
750 : spdm_finish_response_t *spdm_response;
751 : uint32_t hash_size;
752 : uint32_t hmac_size;
753 : uint8_t *ptr;
754 : void *data;
755 : size_t data_size;
756 : uint8_t *cert_buffer;
757 : size_t cert_buffer_size;
758 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
759 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
760 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
761 : size_t spdm_response_size;
762 : size_t transport_header_size;
763 :
764 : ((libspdm_context_t *)spdm_context)
765 0 : ->connection_info.algorithm.base_asym_algo =
766 : m_libspdm_use_asym_algo;
767 : ((libspdm_context_t *)spdm_context)
768 0 : ->connection_info.algorithm.base_hash_algo =
769 : m_libspdm_use_hash_algo;
770 : ((libspdm_context_t *)spdm_context)
771 0 : ->connection_info.algorithm.dhe_named_group =
772 : m_libspdm_use_dhe_algo;
773 : ((libspdm_context_t *)spdm_context)
774 0 : ->connection_info.algorithm.measurement_hash_algo =
775 : m_libspdm_use_measurement_hash_algo;
776 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
777 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
778 0 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
779 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
780 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
781 :
782 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
783 0 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
784 0 : spdm_response->header.param1 = 0;
785 0 : spdm_response->header.param2 = 0;
786 0 : ptr = (void *)(spdm_response + 1);
787 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
788 : sizeof(m_libspdm_local_buffer)
789 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
790 : m_libspdm_local_buffer),
791 : spdm_response, sizeof(spdm_finish_response_t));
792 0 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
793 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
794 : m_libspdm_use_asym_algo, &data,
795 : &data_size, NULL, NULL);
796 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
797 0 : cert_buffer = (uint8_t *)data;
798 0 : cert_buffer_size = data_size;
799 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
800 : cert_buffer_hash);
801 : /* transcript.message_a size is 0*/
802 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
803 : /* session_transcript.message_k is 0*/
804 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
805 : m_libspdm_local_buffer_size);
806 0 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
807 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
808 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
809 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
810 : response_finished_key, hash_size, ptr);
811 0 : ptr += hmac_size;
812 0 : free(data);
813 :
814 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
815 : false, spdm_response_size,
816 : spdm_response, response_size,
817 : response);
818 : }
819 0 : return LIBSPDM_STATUS_SUCCESS;
820 :
821 0 : case 0xD: {
822 : spdm_finish_response_t *spdm_response;
823 : uint32_t hash_size;
824 : uint32_t hmac_size;
825 : uint8_t *ptr;
826 : void *data;
827 : size_t data_size;
828 : uint8_t *cert_buffer;
829 : size_t cert_buffer_size;
830 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
831 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
832 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
833 : size_t spdm_response_size;
834 : size_t transport_header_size;
835 :
836 : ((libspdm_context_t *)spdm_context)
837 0 : ->connection_info.algorithm.base_asym_algo =
838 : m_libspdm_use_asym_algo;
839 : ((libspdm_context_t *)spdm_context)
840 0 : ->connection_info.algorithm.base_hash_algo =
841 : m_libspdm_use_hash_algo;
842 : ((libspdm_context_t *)spdm_context)
843 0 : ->connection_info.algorithm.dhe_named_group =
844 : m_libspdm_use_dhe_algo;
845 : ((libspdm_context_t *)spdm_context)
846 0 : ->connection_info.algorithm.measurement_hash_algo =
847 : m_libspdm_use_measurement_hash_algo;
848 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
849 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
850 0 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
851 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
852 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
853 :
854 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
855 0 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
856 0 : spdm_response->header.param1 = 0;
857 0 : spdm_response->header.param2 = 0;
858 0 : ptr = (void *)(spdm_response + 1);
859 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
860 : sizeof(m_libspdm_local_buffer)
861 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
862 : m_libspdm_local_buffer),
863 : spdm_response, sizeof(spdm_finish_response_t));
864 0 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
865 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
866 : m_libspdm_use_asym_algo, &data,
867 : &data_size, NULL, NULL);
868 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
869 0 : cert_buffer = (uint8_t *)data;
870 0 : cert_buffer_size = data_size;
871 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
872 : cert_buffer_hash);
873 : /* transcript.message_a size is 0*/
874 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
875 : /* session_transcript.message_k is 0*/
876 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
877 : m_libspdm_local_buffer_size);
878 0 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
879 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
880 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
881 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
882 : response_finished_key, hash_size, ptr);
883 0 : ptr += hmac_size;
884 0 : free(data);
885 :
886 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
887 : false, spdm_response_size,
888 : spdm_response, response_size,
889 : response);
890 : }
891 0 : return LIBSPDM_STATUS_SUCCESS;
892 :
893 1 : case 0xE: {
894 : spdm_finish_response_t *spdm_response;
895 : uint32_t hash_size;
896 : uint32_t hmac_size;
897 : uint8_t *ptr;
898 : void *data;
899 : size_t data_size;
900 : uint8_t *cert_buffer;
901 : size_t cert_buffer_size;
902 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
903 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
904 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
905 : size_t spdm_response_size;
906 : size_t transport_header_size;
907 :
908 : ((libspdm_context_t *)spdm_context)
909 1 : ->connection_info.algorithm.base_asym_algo =
910 : m_libspdm_use_asym_algo;
911 : ((libspdm_context_t *)spdm_context)
912 1 : ->connection_info.algorithm.base_hash_algo =
913 : m_libspdm_use_hash_algo;
914 : ((libspdm_context_t *)spdm_context)
915 1 : ->connection_info.algorithm.dhe_named_group =
916 : m_libspdm_use_dhe_algo;
917 : ((libspdm_context_t *)spdm_context)
918 1 : ->connection_info.algorithm.measurement_hash_algo =
919 : m_libspdm_use_measurement_hash_algo;
920 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
921 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
922 1 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
923 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
924 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
925 :
926 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
927 : /*wrong response code*/
928 1 : spdm_response->header.request_response_code = SPDM_FINISH;
929 1 : spdm_response->header.param1 = 0;
930 1 : spdm_response->header.param2 = 0;
931 1 : ptr = (void *)(spdm_response + 1);
932 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
933 : sizeof(m_libspdm_local_buffer)
934 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
935 : m_libspdm_local_buffer),
936 : spdm_response, sizeof(spdm_finish_response_t));
937 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
938 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
939 : m_libspdm_use_asym_algo, &data,
940 : &data_size, NULL, NULL);
941 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
942 1 : cert_buffer = (uint8_t *)data;
943 1 : cert_buffer_size = data_size;
944 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
945 : cert_buffer_hash);
946 : /* transcript.message_a size is 0*/
947 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
948 : /* session_transcript.message_k is 0*/
949 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
950 : m_libspdm_local_buffer_size);
951 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
952 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
953 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
954 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
955 : response_finished_key, hash_size, ptr);
956 1 : ptr += hmac_size;
957 1 : free(data);
958 :
959 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
960 : false, spdm_response_size,
961 : spdm_response, response_size,
962 : response);
963 : }
964 1 : return LIBSPDM_STATUS_SUCCESS;
965 :
966 0 : case 0xF: {
967 : spdm_finish_response_t *spdm_response;
968 : uint32_t hash_size;
969 : uint32_t hmac_size;
970 : uint8_t *ptr;
971 : void *data;
972 : size_t data_size;
973 : uint8_t *cert_buffer;
974 : size_t cert_buffer_size;
975 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
976 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
977 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
978 : size_t spdm_response_size;
979 : size_t transport_header_size;
980 :
981 : ((libspdm_context_t *)spdm_context)
982 0 : ->connection_info.algorithm.base_asym_algo =
983 : m_libspdm_use_asym_algo;
984 : ((libspdm_context_t *)spdm_context)
985 0 : ->connection_info.algorithm.base_hash_algo =
986 : m_libspdm_use_hash_algo;
987 : ((libspdm_context_t *)spdm_context)
988 0 : ->connection_info.algorithm.dhe_named_group =
989 : m_libspdm_use_dhe_algo;
990 : ((libspdm_context_t *)spdm_context)
991 0 : ->connection_info.algorithm.measurement_hash_algo =
992 : m_libspdm_use_measurement_hash_algo;
993 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
994 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
995 0 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
996 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
997 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
998 :
999 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1000 0 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
1001 0 : spdm_response->header.param1 = 0;
1002 0 : spdm_response->header.param2 = 0;
1003 0 : ptr = (void *)(spdm_response + 1);
1004 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1005 : sizeof(m_libspdm_local_buffer)
1006 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1007 : m_libspdm_local_buffer),
1008 : spdm_response, sizeof(spdm_finish_response_t));
1009 0 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
1010 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1011 : m_libspdm_use_asym_algo, &data,
1012 : &data_size, NULL, NULL);
1013 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1014 0 : cert_buffer = (uint8_t *)data;
1015 0 : cert_buffer_size = data_size;
1016 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1017 : cert_buffer_hash);
1018 : /* transcript.message_a size is 0*/
1019 0 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1020 : /* session_transcript.message_k is 0*/
1021 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1022 : m_libspdm_local_buffer_size);
1023 0 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
1024 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1025 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1026 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1027 : response_finished_key, hash_size, ptr);
1028 0 : ptr += hmac_size;
1029 0 : free(data);
1030 :
1031 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1032 : false, spdm_response_size,
1033 : spdm_response, response_size,
1034 : response);
1035 : }
1036 0 : return LIBSPDM_STATUS_SUCCESS;
1037 :
1038 1 : case 0x10: {
1039 : spdm_finish_response_t *spdm_response;
1040 : uint32_t hash_size;
1041 : uint32_t hmac_size;
1042 : uint8_t *ptr;
1043 : void *data;
1044 : size_t data_size;
1045 : uint8_t *cert_buffer;
1046 : size_t cert_buffer_size;
1047 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1048 : uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1049 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1050 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1051 : size_t spdm_response_size;
1052 : size_t transport_header_size;
1053 :
1054 : ((libspdm_context_t *)spdm_context)
1055 1 : ->connection_info.algorithm.base_asym_algo =
1056 : m_libspdm_use_asym_algo;
1057 : ((libspdm_context_t *)spdm_context)
1058 1 : ->connection_info.algorithm.req_base_asym_alg =
1059 : m_libspdm_use_req_asym_algo;
1060 : ((libspdm_context_t *)spdm_context)
1061 1 : ->connection_info.algorithm.base_hash_algo =
1062 : m_libspdm_use_hash_algo;
1063 : ((libspdm_context_t *)spdm_context)
1064 1 : ->connection_info.algorithm.dhe_named_group =
1065 : m_libspdm_use_dhe_algo;
1066 : ((libspdm_context_t *)spdm_context)
1067 1 : ->connection_info.algorithm.measurement_hash_algo =
1068 : m_libspdm_use_measurement_hash_algo;
1069 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1070 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1071 1 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
1072 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1073 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1074 :
1075 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1076 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
1077 1 : spdm_response->header.param1 = 0;
1078 1 : spdm_response->header.param2 = 0;
1079 1 : ptr = (void *)(spdm_response + 1);
1080 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1081 : sizeof(m_libspdm_local_buffer)
1082 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1083 : m_libspdm_local_buffer),
1084 : spdm_response, sizeof(spdm_finish_response_t));
1085 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
1086 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1087 : m_libspdm_use_asym_algo, &data,
1088 : &data_size, NULL, NULL);
1089 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1090 1 : cert_buffer = (uint8_t *)data;
1091 1 : cert_buffer_size = data_size;
1092 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1093 : cert_buffer_hash);
1094 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
1095 : m_libspdm_use_req_asym_algo, &data,
1096 : &data_size, NULL, NULL);
1097 1 : cert_buffer = (uint8_t *)data;
1098 1 : cert_buffer_size = data_size;
1099 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1100 : req_cert_buffer_hash);
1101 : /* transcript.message_a size is 0*/
1102 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1103 : /* session_transcript.message_k is 0*/
1104 1 : libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash,
1105 : hash_size);
1106 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1107 : m_libspdm_local_buffer_size);
1108 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
1109 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1110 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1111 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1112 : response_finished_key, hash_size, ptr);
1113 1 : ptr += hmac_size;
1114 1 : free(data);
1115 :
1116 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1117 : false, spdm_response_size,
1118 : spdm_response, response_size,
1119 : response);
1120 : }
1121 1 : return LIBSPDM_STATUS_SUCCESS;
1122 :
1123 1 : case 0x11: {
1124 : spdm_finish_response_t *spdm_response;
1125 : uint32_t hmac_size;
1126 : uint8_t *ptr;
1127 : size_t spdm_response_size;
1128 : size_t transport_header_size;
1129 :
1130 : ((libspdm_context_t *)spdm_context)
1131 1 : ->connection_info.algorithm.base_asym_algo =
1132 : m_libspdm_use_asym_algo;
1133 : ((libspdm_context_t *)spdm_context)
1134 1 : ->connection_info.algorithm.req_base_asym_alg =
1135 : m_libspdm_use_req_asym_algo;
1136 : ((libspdm_context_t *)spdm_context)
1137 1 : ->connection_info.algorithm.base_hash_algo =
1138 : m_libspdm_use_hash_algo;
1139 : ((libspdm_context_t *)spdm_context)
1140 1 : ->connection_info.algorithm.dhe_named_group =
1141 : m_libspdm_use_dhe_algo;
1142 : ((libspdm_context_t *)spdm_context)
1143 1 : ->connection_info.algorithm.measurement_hash_algo =
1144 : m_libspdm_use_measurement_hash_algo;
1145 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1146 1 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
1147 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1148 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1149 :
1150 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1151 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
1152 1 : spdm_response->header.param1 = 0;
1153 1 : spdm_response->header.param2 = 0;
1154 1 : ptr = (void *)(spdm_response + 1);
1155 1 : libspdm_set_mem(ptr, hmac_size, (uint8_t)(0x00)); /*all-zero MAC*/
1156 1 : ptr += hmac_size;
1157 :
1158 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1159 : false, spdm_response_size,
1160 : spdm_response, response_size,
1161 : response);
1162 : }
1163 1 : return LIBSPDM_STATUS_SUCCESS;
1164 :
1165 1 : case 0x12: {
1166 : spdm_finish_response_t *spdm_response;
1167 : uint32_t hash_size;
1168 : uint32_t hmac_size;
1169 : uint8_t *ptr;
1170 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1171 : uint8_t zero_data[LIBSPDM_MAX_HASH_SIZE];
1172 : size_t spdm_response_size;
1173 : size_t transport_header_size;
1174 :
1175 : ((libspdm_context_t *)spdm_context)
1176 1 : ->connection_info.algorithm.base_asym_algo =
1177 : m_libspdm_use_asym_algo;
1178 : ((libspdm_context_t *)spdm_context)
1179 1 : ->connection_info.algorithm.req_base_asym_alg =
1180 : m_libspdm_use_req_asym_algo;
1181 : ((libspdm_context_t *)spdm_context)
1182 1 : ->connection_info.algorithm.base_hash_algo =
1183 : m_libspdm_use_hash_algo;
1184 : ((libspdm_context_t *)spdm_context)
1185 1 : ->connection_info.algorithm.dhe_named_group =
1186 : m_libspdm_use_dhe_algo;
1187 : ((libspdm_context_t *)spdm_context)
1188 1 : ->connection_info.algorithm.measurement_hash_algo =
1189 : m_libspdm_use_measurement_hash_algo;
1190 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1191 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1192 1 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
1193 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1194 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1195 :
1196 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1197 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
1198 1 : spdm_response->header.param1 = 0;
1199 1 : spdm_response->header.param2 = 0;
1200 1 : ptr = (void *)(spdm_response + 1);
1201 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
1202 1 : libspdm_set_mem(zero_data, hash_size, (uint8_t)(0x00));
1203 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, zero_data, hash_size,
1204 : response_finished_key, hash_size, ptr);
1205 1 : ptr += hmac_size;
1206 :
1207 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1208 : false, spdm_response_size,
1209 : spdm_response, response_size,
1210 : response);
1211 : }
1212 1 : return LIBSPDM_STATUS_SUCCESS;
1213 :
1214 0 : case 0x13: {
1215 : }
1216 0 : return LIBSPDM_STATUS_SUCCESS;
1217 :
1218 1 : case 0x14: {
1219 : spdm_finish_response_t *spdm_response;
1220 : uint32_t hash_size;
1221 : uint32_t hmac_size;
1222 : uint8_t *ptr;
1223 : void *data;
1224 : size_t data_size;
1225 : uint8_t *cert_buffer;
1226 : size_t cert_buffer_size;
1227 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1228 : uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1229 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1230 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1231 : size_t spdm_response_size;
1232 : size_t transport_header_size;
1233 :
1234 : ((libspdm_context_t *)spdm_context)
1235 1 : ->connection_info.algorithm.base_asym_algo =
1236 : m_libspdm_use_asym_algo;
1237 : ((libspdm_context_t *)spdm_context)
1238 1 : ->connection_info.algorithm.req_base_asym_alg =
1239 : m_libspdm_use_req_asym_algo;
1240 : ((libspdm_context_t *)spdm_context)
1241 1 : ->connection_info.algorithm.base_hash_algo =
1242 : m_libspdm_use_hash_algo;
1243 : ((libspdm_context_t *)spdm_context)
1244 1 : ->connection_info.algorithm.dhe_named_group =
1245 : m_libspdm_use_dhe_algo;
1246 : ((libspdm_context_t *)spdm_context)
1247 1 : ->connection_info.algorithm.measurement_hash_algo =
1248 : m_libspdm_use_measurement_hash_algo;
1249 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1250 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1251 1 : spdm_response_size = sizeof(spdm_finish_response_t) +
1252 1 : hmac_size/2;/* half HMAC size*/
1253 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1254 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1255 :
1256 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1257 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
1258 1 : spdm_response->header.param1 = 0;
1259 1 : spdm_response->header.param2 = 0;
1260 1 : ptr = (void *)(spdm_response + 1);
1261 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1262 : sizeof(m_libspdm_local_buffer)
1263 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1264 : m_libspdm_local_buffer),
1265 : spdm_response, sizeof(spdm_finish_response_t));
1266 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
1267 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1268 : m_libspdm_use_asym_algo, &data,
1269 : &data_size, NULL, NULL);
1270 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1271 1 : cert_buffer = (uint8_t *)data;
1272 1 : cert_buffer_size = data_size;
1273 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1274 : cert_buffer_hash);
1275 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
1276 : m_libspdm_use_req_asym_algo, &data,
1277 : &data_size, NULL, NULL);
1278 1 : cert_buffer = (uint8_t *)data;
1279 1 : cert_buffer_size = data_size;
1280 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1281 : req_cert_buffer_hash);
1282 : /* transcript.message_a size is 0*/
1283 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1284 : /* session_transcript.message_k is 0*/
1285 1 : libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash,
1286 : hash_size);
1287 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1288 : m_libspdm_local_buffer_size);
1289 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
1290 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1291 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1292 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1293 : response_finished_key, hash_size, ptr);
1294 1 : ptr += hmac_size/2; /* half HMAC size*/
1295 1 : libspdm_set_mem(ptr, hmac_size/2, (uint8_t) 0x00);
1296 1 : free(data);
1297 :
1298 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1299 : false, spdm_response_size,
1300 : spdm_response, response_size,
1301 : response);
1302 : }
1303 1 : return LIBSPDM_STATUS_SUCCESS;
1304 :
1305 1 : case 0x15: {
1306 : spdm_error_response_t *spdm_response;
1307 : size_t spdm_response_size;
1308 : size_t transport_header_size;
1309 :
1310 1 : spdm_response_size = sizeof(spdm_error_response_t);
1311 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1312 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1313 :
1314 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1315 1 : spdm_response->header.request_response_code = SPDM_ERROR;
1316 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_DECRYPT_ERROR;
1317 1 : spdm_response->header.param2 = 0;
1318 :
1319 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1320 : false, spdm_response_size,
1321 : spdm_response,
1322 : response_size, response);
1323 : }
1324 1 : return LIBSPDM_STATUS_SUCCESS;
1325 :
1326 1 : case 0x16: {
1327 : spdm_finish_response_t *spdm_response;
1328 : uint32_t hash_size;
1329 : uint32_t hmac_size;
1330 : uint8_t *ptr;
1331 : void *data;
1332 : size_t data_size;
1333 : uint8_t *cert_buffer;
1334 : size_t cert_buffer_size;
1335 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1336 : uint8_t req_cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1337 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1338 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1339 : size_t spdm_response_size;
1340 : size_t transport_header_size;
1341 :
1342 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
1343 : m_libspdm_use_asym_algo;
1344 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.req_base_asym_alg =
1345 : m_libspdm_use_req_asym_algo;
1346 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
1347 : m_libspdm_use_hash_algo;
1348 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
1349 : m_libspdm_use_dhe_algo;
1350 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
1351 : m_libspdm_use_measurement_hash_algo;
1352 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1353 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1354 1 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
1355 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1356 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1357 :
1358 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1359 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
1360 1 : spdm_response->header.param1 = 0;
1361 1 : spdm_response->header.param2 = 0;
1362 1 : ptr = (void *)(spdm_response + 1);
1363 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1364 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
1365 : spdm_response, sizeof(spdm_finish_response_t));
1366 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
1367 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1368 : m_libspdm_use_asym_algo, &data,
1369 : &data_size, NULL, NULL);
1370 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1371 1 : cert_buffer = (uint8_t *)data;
1372 1 : cert_buffer_size = data_size;
1373 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size, cert_buffer_hash);
1374 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
1375 : m_libspdm_use_req_asym_algo, &data,
1376 : &data_size, NULL, NULL);
1377 1 : cert_buffer = (uint8_t *)data;
1378 1 : cert_buffer_size = data_size;
1379 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1380 : req_cert_buffer_hash);
1381 : /* transcript.message_a size is 0*/
1382 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1383 : /* session_transcript.message_k is 0*/
1384 1 : libspdm_append_managed_buffer(&th_curr, req_cert_buffer_hash, hash_size);
1385 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1386 : m_libspdm_local_buffer_size);
1387 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
1388 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1389 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1390 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1391 : response_finished_key, hash_size, ptr);
1392 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1393 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
1394 : ptr, hmac_size);
1395 1 : m_libspdm_local_buffer_size += hmac_size;
1396 1 : ptr += hmac_size;
1397 1 : free(data);
1398 :
1399 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1400 : false, spdm_response_size,
1401 : spdm_response, response_size,
1402 : response);
1403 : }
1404 1 : return LIBSPDM_STATUS_SUCCESS;
1405 1 : case 0x17: {
1406 : spdm_finish_response_t *spdm_response;
1407 : uint32_t hash_size;
1408 : uint32_t hmac_size;
1409 : uint8_t *ptr;
1410 : void *data;
1411 : size_t data_size;
1412 : uint8_t *cert_buffer;
1413 : size_t cert_buffer_size;
1414 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1415 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1416 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1417 : size_t spdm_response_size;
1418 : size_t transport_header_size;
1419 :
1420 : ((libspdm_context_t *)spdm_context)
1421 1 : ->connection_info.algorithm.base_asym_algo =
1422 : m_libspdm_use_asym_algo;
1423 : ((libspdm_context_t *)spdm_context)
1424 1 : ->connection_info.algorithm.base_hash_algo =
1425 : m_libspdm_use_hash_algo;
1426 : ((libspdm_context_t *)spdm_context)
1427 1 : ->connection_info.algorithm.dhe_named_group =
1428 : m_libspdm_use_dhe_algo;
1429 : ((libspdm_context_t *)spdm_context)
1430 1 : ->connection_info.algorithm.measurement_hash_algo =
1431 : m_libspdm_use_measurement_hash_algo;
1432 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1433 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1434 1 : spdm_response_size = sizeof(spdm_finish_response_t) + hmac_size;
1435 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1436 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1437 :
1438 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1439 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
1440 1 : spdm_response->header.param1 = 0;
1441 1 : spdm_response->header.param2 = 0;
1442 1 : ptr = (void *)(spdm_response + 1);
1443 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1444 : sizeof(m_libspdm_local_buffer)
1445 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1446 : m_libspdm_local_buffer),
1447 : spdm_response, sizeof(spdm_finish_response_t));
1448 1 : m_libspdm_local_buffer_size += sizeof(spdm_finish_response_t);
1449 1 : libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
1450 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1451 1 : cert_buffer = (uint8_t *)data;
1452 1 : cert_buffer_size = data_size;
1453 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1454 : cert_buffer_hash);
1455 : /* transcript.message_a size is 0*/
1456 1 : libspdm_append_managed_buffer(&th_curr, cert_buffer_hash, hash_size);
1457 : /* session_transcript.message_k is 0*/
1458 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1459 : m_libspdm_local_buffer_size);
1460 1 : libspdm_set_mem(response_finished_key, LIBSPDM_MAX_HASH_SIZE, (uint8_t)(0xFF));
1461 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1462 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1463 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1464 : response_finished_key, hash_size, ptr);
1465 1 : ptr += hmac_size;
1466 1 : free(data);
1467 :
1468 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1469 : false, spdm_response_size,
1470 : spdm_response, response_size,
1471 : response);
1472 : }
1473 1 : return LIBSPDM_STATUS_SUCCESS;
1474 1 : case 0x18: {
1475 : spdm_finish_response_t *spdm_response;
1476 : libspdm_session_info_t *session_info;
1477 : size_t spdm_response_size;
1478 : size_t transport_header_size;
1479 : uint32_t session_id;
1480 : uint8_t *scratch_buffer;
1481 : size_t scratch_buffer_size;
1482 :
1483 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1484 :
1485 : /* The ResponderVerifyData field does absent.*/
1486 1 : spdm_response_size = sizeof(spdm_finish_response_t);
1487 :
1488 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1489 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1490 1 : spdm_response->header.request_response_code = SPDM_FINISH_RSP;
1491 1 : spdm_response->header.param1 = 0;
1492 1 : spdm_response->header.param2 = 0;
1493 :
1494 1 : session_id = 0xFFFFFFFF;
1495 : /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
1496 : * transport_message is always in sender buffer. */
1497 1 : libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
1498 1 : libspdm_copy_mem (scratch_buffer + transport_header_size,
1499 : scratch_buffer_size - transport_header_size,
1500 : spdm_response, spdm_response_size);
1501 1 : spdm_response = (void *)(scratch_buffer + transport_header_size);
1502 1 : libspdm_transport_test_encode_message (spdm_context, &session_id, false, false,
1503 : spdm_response_size, spdm_response,
1504 : response_size, response);
1505 :
1506 1 : session_info = libspdm_get_session_info_via_session_id (spdm_context, session_id);
1507 1 : ((libspdm_secured_message_context_t*)(session_info->secured_message_context))->
1508 1 : handshake_secret.response_handshake_sequence_number--;
1509 : }
1510 1 : return LIBSPDM_STATUS_SUCCESS;
1511 :
1512 0 : default:
1513 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
1514 : }
1515 : }
1516 :
1517 : /**
1518 : * Test 1: when no FINISH_RSP message is received, and the client returns a
1519 : * device error.
1520 : * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
1521 : **/
1522 1 : void libspdm_test_requester_finish_case1(void **state)
1523 : {
1524 : libspdm_return_t status;
1525 : libspdm_test_context_t *spdm_test_context;
1526 : libspdm_context_t *spdm_context;
1527 : uint32_t session_id;
1528 : uint8_t req_slot_id_param;
1529 : void *data;
1530 : size_t data_size;
1531 : void *hash;
1532 : size_t hash_size;
1533 : libspdm_session_info_t *session_info;
1534 :
1535 1 : spdm_test_context = *state;
1536 1 : spdm_context = spdm_test_context->spdm_context;
1537 1 : spdm_test_context->case_id = 0x1;
1538 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1539 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1540 1 : spdm_context->connection_info.connection_state =
1541 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1542 1 : spdm_context->connection_info.capability.flags |=
1543 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
1544 1 : spdm_context->connection_info.capability.flags |=
1545 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
1546 1 : spdm_context->connection_info.capability.flags |=
1547 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
1548 1 : spdm_context->local_context.capability.flags |=
1549 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
1550 1 : spdm_context->local_context.capability.flags |=
1551 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
1552 1 : spdm_context->local_context.capability.flags |=
1553 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
1554 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1555 : m_libspdm_use_asym_algo, &data,
1556 : &data_size, &hash, &hash_size);
1557 1 : libspdm_reset_message_a(spdm_context);
1558 1 : spdm_context->connection_info.algorithm.base_hash_algo =
1559 : m_libspdm_use_hash_algo;
1560 1 : spdm_context->connection_info.algorithm.base_asym_algo =
1561 : m_libspdm_use_asym_algo;
1562 1 : spdm_context->connection_info.algorithm.dhe_named_group =
1563 : m_libspdm_use_dhe_algo;
1564 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
1565 : m_libspdm_use_aead_algo;
1566 :
1567 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1568 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
1569 : data_size;
1570 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
1571 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
1572 : data, data_size);
1573 : #else
1574 1 : libspdm_hash_all(
1575 : spdm_context->connection_info.algorithm.base_hash_algo,
1576 : data, data_size,
1577 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
1578 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
1579 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
1580 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
1581 : spdm_context->connection_info.algorithm.base_hash_algo,
1582 : spdm_context->connection_info.algorithm.base_asym_algo,
1583 : data, data_size,
1584 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
1585 : #endif
1586 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
1587 :
1588 1 : session_id = 0xFFFFFFFF;
1589 1 : session_info = &spdm_context->session_info[0];
1590 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
1591 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1592 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
1593 1 : libspdm_secured_message_set_response_finished_key(
1594 : session_info->secured_message_context, m_libspdm_dummy_buffer,
1595 : hash_size);
1596 1 : libspdm_secured_message_set_session_state(
1597 : session_info->secured_message_context,
1598 : LIBSPDM_SESSION_STATE_HANDSHAKING);
1599 :
1600 1 : spdm_context->connection_info.capability.flags |=
1601 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1602 1 : spdm_context->local_context.capability.flags |=
1603 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1604 1 : req_slot_id_param = 0;
1605 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
1606 : req_slot_id_param);
1607 1 : assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
1608 1 : free(data);
1609 1 : }
1610 :
1611 : /**
1612 : * Test 2: receiving a correct FINISH_RSP message with only MAC (no
1613 : * mutual authentication) and 'handshake in the clear'.
1614 : * Expected behavior: client returns a Status of RETURN_SUCCESS and
1615 : * session is established.
1616 : **/
1617 1 : void libspdm_test_requester_finish_case2(void **state)
1618 : {
1619 : libspdm_return_t status;
1620 : libspdm_test_context_t *spdm_test_context;
1621 : libspdm_context_t *spdm_context;
1622 : uint32_t session_id;
1623 : uint8_t req_slot_id_param;
1624 : void *data;
1625 : size_t data_size;
1626 : void *hash;
1627 : size_t hash_size;
1628 : libspdm_session_info_t *session_info;
1629 : libspdm_secured_message_context_t *secured_message_context;
1630 :
1631 1 : spdm_test_context = *state;
1632 1 : spdm_context = spdm_test_context->spdm_context;
1633 1 : spdm_test_context->case_id = 0x2;
1634 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1635 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1636 1 : spdm_context->connection_info.connection_state =
1637 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1638 1 : spdm_context->connection_info.capability.flags |=
1639 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
1640 1 : spdm_context->connection_info.capability.flags |=
1641 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
1642 1 : spdm_context->connection_info.capability.flags |=
1643 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
1644 1 : spdm_context->local_context.capability.flags |=
1645 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
1646 1 : spdm_context->local_context.capability.flags |=
1647 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
1648 1 : spdm_context->local_context.capability.flags |=
1649 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
1650 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1651 : m_libspdm_use_asym_algo, &data,
1652 : &data_size, &hash, &hash_size);
1653 1 : libspdm_reset_message_a(spdm_context);
1654 1 : spdm_context->connection_info.algorithm.base_hash_algo =
1655 : m_libspdm_use_hash_algo;
1656 1 : spdm_context->connection_info.algorithm.base_asym_algo =
1657 : m_libspdm_use_asym_algo;
1658 1 : spdm_context->connection_info.algorithm.dhe_named_group =
1659 : m_libspdm_use_dhe_algo;
1660 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
1661 : m_libspdm_use_aead_algo;
1662 :
1663 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1664 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
1665 : data_size;
1666 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
1667 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
1668 : data, data_size);
1669 : #else
1670 1 : libspdm_hash_all(
1671 : spdm_context->connection_info.algorithm.base_hash_algo,
1672 : data, data_size,
1673 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
1674 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
1675 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
1676 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
1677 : spdm_context->connection_info.algorithm.base_hash_algo,
1678 : spdm_context->connection_info.algorithm.base_asym_algo,
1679 : data, data_size,
1680 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
1681 : #endif
1682 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
1683 :
1684 1 : session_id = 0xFFFFFFFF;
1685 1 : session_info = &spdm_context->session_info[0];
1686 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
1687 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1688 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
1689 1 : libspdm_secured_message_set_response_finished_key(
1690 : session_info->secured_message_context, m_libspdm_dummy_buffer,
1691 : hash_size);
1692 1 : libspdm_secured_message_set_session_state(
1693 : session_info->secured_message_context,
1694 : LIBSPDM_SESSION_STATE_HANDSHAKING);
1695 :
1696 1 : spdm_context->connection_info.capability.flags |=
1697 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1698 1 : spdm_context->local_context.capability.flags |=
1699 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1700 1 : req_slot_id_param = 0;
1701 1 : status = libspdm_send_receive_finish(spdm_context, session_id, req_slot_id_param);
1702 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1703 1 : assert_int_equal(
1704 : libspdm_secured_message_get_session_state(
1705 : spdm_context->session_info[0].secured_message_context),
1706 : LIBSPDM_SESSION_STATE_ESTABLISHED);
1707 :
1708 1 : secured_message_context = session_info->secured_message_context;
1709 :
1710 1 : assert_memory_equal((const void *)secured_message_context->master_secret.master_secret,
1711 : (const void *)m_libspdm_zero_buffer, sizeof(m_libspdm_zero_buffer));
1712 1 : free(data);
1713 1 : }
1714 :
1715 : /**
1716 : * Test 3: requester state has not been negotiated, as if GET_VERSION, GET_CAPABILITIES and
1717 : * NEGOTIATE_ALGORITHMS had not been exchanged.
1718 : * Expected behavior: client returns a Status of RETURN_UNSUPPORTED.
1719 : **/
1720 1 : void libspdm_test_requester_finish_case3(void **state)
1721 : {
1722 : libspdm_return_t status;
1723 : libspdm_test_context_t *spdm_test_context;
1724 : libspdm_context_t *spdm_context;
1725 : uint32_t session_id;
1726 : uint8_t req_slot_id_param;
1727 : void *data;
1728 : size_t data_size;
1729 : void *hash;
1730 : size_t hash_size;
1731 : libspdm_session_info_t *session_info;
1732 :
1733 1 : spdm_test_context = *state;
1734 1 : spdm_context = spdm_test_context->spdm_context;
1735 1 : spdm_test_context->case_id = 0x3;
1736 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1737 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1738 1 : spdm_context->connection_info.connection_state =
1739 : LIBSPDM_CONNECTION_STATE_NOT_STARTED;
1740 1 : spdm_context->connection_info.capability.flags |=
1741 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
1742 1 : spdm_context->connection_info.capability.flags |=
1743 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
1744 1 : spdm_context->connection_info.capability.flags |=
1745 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
1746 1 : spdm_context->local_context.capability.flags |=
1747 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
1748 1 : spdm_context->local_context.capability.flags |=
1749 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
1750 1 : spdm_context->local_context.capability.flags |=
1751 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
1752 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1753 : m_libspdm_use_asym_algo, &data,
1754 : &data_size, &hash, &hash_size);
1755 1 : libspdm_reset_message_a(spdm_context);
1756 1 : spdm_context->connection_info.algorithm.base_hash_algo =
1757 : m_libspdm_use_hash_algo;
1758 1 : spdm_context->connection_info.algorithm.base_asym_algo =
1759 : m_libspdm_use_asym_algo;
1760 1 : spdm_context->connection_info.algorithm.dhe_named_group =
1761 : m_libspdm_use_dhe_algo;
1762 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
1763 : m_libspdm_use_aead_algo;
1764 :
1765 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1766 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
1767 : data_size;
1768 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
1769 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
1770 : data, data_size);
1771 : #else
1772 1 : libspdm_hash_all(
1773 : spdm_context->connection_info.algorithm.base_hash_algo,
1774 : data, data_size,
1775 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
1776 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
1777 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
1778 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
1779 : spdm_context->connection_info.algorithm.base_hash_algo,
1780 : spdm_context->connection_info.algorithm.base_asym_algo,
1781 : data, data_size,
1782 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
1783 : #endif
1784 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
1785 :
1786 1 : session_id = 0xFFFFFFFF;
1787 1 : session_info = &spdm_context->session_info[0];
1788 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
1789 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1790 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
1791 1 : libspdm_secured_message_set_response_finished_key(
1792 : session_info->secured_message_context, m_libspdm_dummy_buffer,
1793 : hash_size);
1794 1 : libspdm_secured_message_set_session_state(
1795 : session_info->secured_message_context,
1796 : LIBSPDM_SESSION_STATE_HANDSHAKING);
1797 :
1798 1 : spdm_context->connection_info.capability.flags |=
1799 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1800 1 : spdm_context->local_context.capability.flags |=
1801 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1802 1 : req_slot_id_param = 0;
1803 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
1804 : req_slot_id_param);
1805 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
1806 1 : free(data);
1807 1 : }
1808 :
1809 : /**
1810 : * Test 4: the requester is setup correctly (see Test 2), but receives an ERROR
1811 : * message indicating InvalidParameters.
1812 : * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
1813 : **/
1814 1 : void libspdm_test_requester_finish_case4(void **state)
1815 : {
1816 : libspdm_return_t status;
1817 : libspdm_test_context_t *spdm_test_context;
1818 : libspdm_context_t *spdm_context;
1819 : uint32_t session_id;
1820 : uint8_t req_slot_id_param;
1821 : void *data;
1822 : size_t data_size;
1823 : void *hash;
1824 : size_t hash_size;
1825 : libspdm_session_info_t *session_info;
1826 :
1827 1 : spdm_test_context = *state;
1828 1 : spdm_context = spdm_test_context->spdm_context;
1829 1 : spdm_test_context->case_id = 0x4;
1830 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1831 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1832 1 : spdm_context->connection_info.connection_state =
1833 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1834 1 : spdm_context->connection_info.capability.flags |=
1835 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
1836 1 : spdm_context->connection_info.capability.flags |=
1837 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
1838 1 : spdm_context->connection_info.capability.flags |=
1839 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
1840 1 : spdm_context->local_context.capability.flags |=
1841 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
1842 1 : spdm_context->local_context.capability.flags |=
1843 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
1844 1 : spdm_context->local_context.capability.flags |=
1845 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
1846 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1847 : m_libspdm_use_asym_algo, &data,
1848 : &data_size, &hash, &hash_size);
1849 1 : libspdm_reset_message_a(spdm_context);
1850 1 : spdm_context->connection_info.algorithm.base_hash_algo =
1851 : m_libspdm_use_hash_algo;
1852 1 : spdm_context->connection_info.algorithm.base_asym_algo =
1853 : m_libspdm_use_asym_algo;
1854 1 : spdm_context->connection_info.algorithm.dhe_named_group =
1855 : m_libspdm_use_dhe_algo;
1856 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
1857 : m_libspdm_use_aead_algo;
1858 :
1859 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1860 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
1861 : data_size;
1862 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
1863 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
1864 : data, data_size);
1865 : #else
1866 1 : libspdm_hash_all(
1867 : spdm_context->connection_info.algorithm.base_hash_algo,
1868 : data, data_size,
1869 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
1870 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
1871 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
1872 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
1873 : spdm_context->connection_info.algorithm.base_hash_algo,
1874 : spdm_context->connection_info.algorithm.base_asym_algo,
1875 : data, data_size,
1876 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
1877 : #endif
1878 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
1879 :
1880 1 : session_id = 0xFFFFFFFF;
1881 1 : session_info = &spdm_context->session_info[0];
1882 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
1883 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1884 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
1885 1 : libspdm_secured_message_set_response_finished_key(
1886 : session_info->secured_message_context, m_libspdm_dummy_buffer,
1887 : hash_size);
1888 1 : libspdm_secured_message_set_session_state(
1889 : session_info->secured_message_context,
1890 : LIBSPDM_SESSION_STATE_HANDSHAKING);
1891 :
1892 1 : spdm_context->connection_info.capability.flags |=
1893 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1894 1 : spdm_context->local_context.capability.flags |=
1895 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1896 1 : req_slot_id_param = 0;
1897 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
1898 : req_slot_id_param);
1899 1 : assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
1900 1 : assert_int_equal(spdm_context->session_info->session_id, INVALID_SESSION_ID);
1901 1 : free(data);
1902 1 : }
1903 :
1904 : /**
1905 : * Test 5: the requester is setup correctly (see Test 2), but receives an ERROR
1906 : * message indicating the Busy status of the responder.
1907 : * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
1908 : **/
1909 1 : void libspdm_test_requester_finish_case5(void **state)
1910 : {
1911 : libspdm_return_t status;
1912 : libspdm_test_context_t *spdm_test_context;
1913 : libspdm_context_t *spdm_context;
1914 : uint32_t session_id;
1915 : uint8_t req_slot_id_param;
1916 : void *data;
1917 : size_t data_size;
1918 : void *hash;
1919 : size_t hash_size;
1920 : libspdm_session_info_t *session_info;
1921 :
1922 1 : spdm_test_context = *state;
1923 1 : spdm_context = spdm_test_context->spdm_context;
1924 1 : spdm_test_context->case_id = 0x5;
1925 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1926 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1927 1 : spdm_context->connection_info.connection_state =
1928 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
1929 1 : spdm_context->connection_info.capability.flags |=
1930 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
1931 1 : spdm_context->connection_info.capability.flags |=
1932 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
1933 1 : spdm_context->connection_info.capability.flags |=
1934 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
1935 1 : spdm_context->local_context.capability.flags |=
1936 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
1937 1 : spdm_context->local_context.capability.flags |=
1938 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
1939 1 : spdm_context->local_context.capability.flags |=
1940 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
1941 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1942 : m_libspdm_use_asym_algo, &data,
1943 : &data_size, &hash, &hash_size);
1944 1 : libspdm_reset_message_a(spdm_context);
1945 1 : spdm_context->connection_info.algorithm.base_hash_algo =
1946 : m_libspdm_use_hash_algo;
1947 1 : spdm_context->connection_info.algorithm.base_asym_algo =
1948 : m_libspdm_use_asym_algo;
1949 1 : spdm_context->connection_info.algorithm.dhe_named_group =
1950 : m_libspdm_use_dhe_algo;
1951 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
1952 : m_libspdm_use_aead_algo;
1953 :
1954 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1955 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
1956 : data_size;
1957 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
1958 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
1959 : data, data_size);
1960 : #else
1961 1 : libspdm_hash_all(
1962 : spdm_context->connection_info.algorithm.base_hash_algo,
1963 : data, data_size,
1964 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
1965 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
1966 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
1967 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
1968 : spdm_context->connection_info.algorithm.base_hash_algo,
1969 : spdm_context->connection_info.algorithm.base_asym_algo,
1970 : data, data_size,
1971 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
1972 : #endif
1973 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
1974 :
1975 1 : session_id = 0xFFFFFFFF;
1976 1 : session_info = &spdm_context->session_info[0];
1977 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
1978 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1979 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
1980 1 : libspdm_secured_message_set_response_finished_key(
1981 : session_info->secured_message_context, m_libspdm_dummy_buffer,
1982 : hash_size);
1983 1 : libspdm_secured_message_set_session_state(
1984 : session_info->secured_message_context,
1985 : LIBSPDM_SESSION_STATE_HANDSHAKING);
1986 :
1987 1 : spdm_context->connection_info.capability.flags |=
1988 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1989 1 : spdm_context->local_context.capability.flags |=
1990 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
1991 1 : req_slot_id_param = 0;
1992 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
1993 : req_slot_id_param);
1994 1 : assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
1995 1 : free(data);
1996 1 : }
1997 :
1998 : /**
1999 : * Test 6: the requester is setup correctly (see Test 2), but, on the first try,
2000 : * receiving a Busy ERROR message, and on retry, receiving a correct FINISH_RSP
2001 : * message with only MAC (no mutual authentication).
2002 : * Expected behavior: client returns a Status of RETURN_SUCCESS.
2003 : **/
2004 1 : void libspdm_test_requester_finish_case6(void **state)
2005 : {
2006 : libspdm_return_t status;
2007 : libspdm_test_context_t *spdm_test_context;
2008 : libspdm_context_t *spdm_context;
2009 : uint32_t session_id;
2010 : uint8_t req_slot_id_param;
2011 : void *data;
2012 : size_t data_size;
2013 : void *hash;
2014 : size_t hash_size;
2015 : libspdm_session_info_t *session_info;
2016 :
2017 1 : spdm_test_context = *state;
2018 1 : spdm_context = spdm_test_context->spdm_context;
2019 1 : spdm_test_context->case_id = 0x6;
2020 1 : spdm_context->retry_times = 3;
2021 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2022 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2023 1 : spdm_context->connection_info.connection_state =
2024 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2025 1 : spdm_context->connection_info.capability.flags |=
2026 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2027 1 : spdm_context->connection_info.capability.flags |=
2028 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2029 1 : spdm_context->connection_info.capability.flags |=
2030 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2031 1 : spdm_context->local_context.capability.flags |=
2032 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2033 1 : spdm_context->local_context.capability.flags |=
2034 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2035 1 : spdm_context->local_context.capability.flags |=
2036 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2037 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2038 : m_libspdm_use_asym_algo, &data,
2039 : &data_size, &hash, &hash_size);
2040 1 : libspdm_reset_message_a(spdm_context);
2041 1 : spdm_context->connection_info.algorithm.base_hash_algo =
2042 : m_libspdm_use_hash_algo;
2043 1 : spdm_context->connection_info.algorithm.base_asym_algo =
2044 : m_libspdm_use_asym_algo;
2045 1 : spdm_context->connection_info.algorithm.dhe_named_group =
2046 : m_libspdm_use_dhe_algo;
2047 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
2048 : m_libspdm_use_aead_algo;
2049 :
2050 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2051 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2052 : data_size;
2053 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2054 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2055 : data, data_size);
2056 : #else
2057 1 : libspdm_hash_all(
2058 : spdm_context->connection_info.algorithm.base_hash_algo,
2059 : data, data_size,
2060 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2061 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2062 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2063 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2064 : spdm_context->connection_info.algorithm.base_hash_algo,
2065 : spdm_context->connection_info.algorithm.base_asym_algo,
2066 : data, data_size,
2067 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2068 : #endif
2069 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2070 :
2071 1 : session_id = 0xFFFFFFFF;
2072 1 : session_info = &spdm_context->session_info[0];
2073 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2074 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2075 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2076 1 : libspdm_secured_message_set_response_finished_key(
2077 : session_info->secured_message_context, m_libspdm_dummy_buffer,
2078 : hash_size);
2079 1 : libspdm_secured_message_set_session_state(
2080 : session_info->secured_message_context,
2081 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2082 :
2083 1 : spdm_context->connection_info.capability.flags |=
2084 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2085 1 : spdm_context->local_context.capability.flags |=
2086 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2087 1 : req_slot_id_param = 0;
2088 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
2089 : req_slot_id_param);
2090 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
2091 1 : assert_int_equal(
2092 : libspdm_secured_message_get_session_state(
2093 : spdm_context->session_info[0].secured_message_context),
2094 : LIBSPDM_SESSION_STATE_ESTABLISHED);
2095 1 : free(data);
2096 1 : }
2097 :
2098 : /**
2099 : * Test 7: the requester is setup correctly (see Test 2), but receives an ERROR
2100 : * message indicating the RequestResynch status of the responder.
2101 : * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR, and the
2102 : * communication is reset to expect a new GET_VERSION message.
2103 : **/
2104 1 : void libspdm_test_requester_finish_case7(void **state)
2105 : {
2106 : libspdm_return_t status;
2107 : libspdm_test_context_t *spdm_test_context;
2108 : libspdm_context_t *spdm_context;
2109 : uint32_t session_id;
2110 : uint8_t req_slot_id_param;
2111 : void *data;
2112 : size_t data_size;
2113 : void *hash;
2114 : size_t hash_size;
2115 : libspdm_session_info_t *session_info;
2116 :
2117 1 : spdm_test_context = *state;
2118 1 : spdm_context = spdm_test_context->spdm_context;
2119 1 : spdm_test_context->case_id = 0x7;
2120 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2121 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2122 1 : spdm_context->connection_info.connection_state =
2123 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2124 1 : spdm_context->connection_info.capability.flags |=
2125 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2126 1 : spdm_context->connection_info.capability.flags |=
2127 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2128 1 : spdm_context->connection_info.capability.flags |=
2129 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2130 1 : spdm_context->local_context.capability.flags |=
2131 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2132 1 : spdm_context->local_context.capability.flags |=
2133 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2134 1 : spdm_context->local_context.capability.flags |=
2135 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2136 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2137 : m_libspdm_use_asym_algo, &data,
2138 : &data_size, &hash, &hash_size);
2139 1 : libspdm_reset_message_a(spdm_context);
2140 1 : spdm_context->connection_info.algorithm.base_hash_algo =
2141 : m_libspdm_use_hash_algo;
2142 1 : spdm_context->connection_info.algorithm.base_asym_algo =
2143 : m_libspdm_use_asym_algo;
2144 1 : spdm_context->connection_info.algorithm.dhe_named_group =
2145 : m_libspdm_use_dhe_algo;
2146 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
2147 : m_libspdm_use_aead_algo;
2148 :
2149 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2150 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2151 : data_size;
2152 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2153 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2154 : data, data_size);
2155 : #else
2156 1 : libspdm_hash_all(
2157 : spdm_context->connection_info.algorithm.base_hash_algo,
2158 : data, data_size,
2159 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2160 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2161 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2162 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2163 : spdm_context->connection_info.algorithm.base_hash_algo,
2164 : spdm_context->connection_info.algorithm.base_asym_algo,
2165 : data, data_size,
2166 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2167 : #endif
2168 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2169 :
2170 1 : session_id = 0xFFFFFFFF;
2171 1 : session_info = &spdm_context->session_info[0];
2172 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2173 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2174 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2175 1 : libspdm_secured_message_set_response_finished_key(
2176 : session_info->secured_message_context, m_libspdm_dummy_buffer,
2177 : hash_size);
2178 1 : libspdm_secured_message_set_session_state(
2179 : session_info->secured_message_context,
2180 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2181 :
2182 1 : spdm_context->connection_info.capability.flags |=
2183 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2184 1 : spdm_context->local_context.capability.flags |=
2185 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2186 1 : req_slot_id_param = 0;
2187 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
2188 : req_slot_id_param);
2189 1 : assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
2190 1 : assert_int_equal(spdm_context->connection_info.connection_state,
2191 : LIBSPDM_CONNECTION_STATE_NOT_STARTED);
2192 1 : free(data);
2193 1 : }
2194 :
2195 : /**
2196 : * Test 8: the requester is setup correctly (see Test 2), but receives an ERROR
2197 : * message indicating the ResponseNotReady status of the responder.
2198 : * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR,.
2199 : **/
2200 1 : void libspdm_test_requester_finish_case8(void **state)
2201 : {
2202 : libspdm_return_t status;
2203 : libspdm_test_context_t *spdm_test_context;
2204 : libspdm_context_t *spdm_context;
2205 : uint32_t session_id;
2206 : uint8_t req_slot_id_param;
2207 : void *data;
2208 : size_t data_size;
2209 : void *hash;
2210 : size_t hash_size;
2211 : libspdm_session_info_t *session_info;
2212 :
2213 1 : spdm_test_context = *state;
2214 1 : spdm_context = spdm_test_context->spdm_context;
2215 1 : spdm_test_context->case_id = 0x8;
2216 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2217 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2218 1 : spdm_context->connection_info.connection_state =
2219 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2220 1 : spdm_context->connection_info.capability.flags |=
2221 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2222 1 : spdm_context->connection_info.capability.flags |=
2223 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2224 1 : spdm_context->connection_info.capability.flags |=
2225 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2226 1 : spdm_context->local_context.capability.flags |=
2227 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2228 1 : spdm_context->local_context.capability.flags |=
2229 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2230 1 : spdm_context->local_context.capability.flags |=
2231 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2232 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2233 : m_libspdm_use_asym_algo, &data,
2234 : &data_size, &hash, &hash_size);
2235 1 : libspdm_reset_message_a(spdm_context);
2236 1 : spdm_context->connection_info.algorithm.base_hash_algo =
2237 : m_libspdm_use_hash_algo;
2238 1 : spdm_context->connection_info.algorithm.base_asym_algo =
2239 : m_libspdm_use_asym_algo;
2240 1 : spdm_context->connection_info.algorithm.dhe_named_group =
2241 : m_libspdm_use_dhe_algo;
2242 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
2243 : m_libspdm_use_aead_algo;
2244 :
2245 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2246 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2247 : data_size;
2248 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2249 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2250 : data, data_size);
2251 : #else
2252 1 : libspdm_hash_all(
2253 : spdm_context->connection_info.algorithm.base_hash_algo,
2254 : data, data_size,
2255 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2256 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2257 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2258 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2259 : spdm_context->connection_info.algorithm.base_hash_algo,
2260 : spdm_context->connection_info.algorithm.base_asym_algo,
2261 : data, data_size,
2262 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2263 : #endif
2264 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2265 :
2266 1 : session_id = 0xFFFFFFFF;
2267 1 : session_info = &spdm_context->session_info[0];
2268 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2269 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2270 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2271 1 : libspdm_secured_message_set_response_finished_key(
2272 : session_info->secured_message_context, m_libspdm_dummy_buffer,
2273 : hash_size);
2274 1 : libspdm_secured_message_set_session_state(
2275 : session_info->secured_message_context,
2276 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2277 :
2278 1 : spdm_context->connection_info.capability.flags |=
2279 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2280 1 : spdm_context->local_context.capability.flags |=
2281 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2282 1 : req_slot_id_param = 0;
2283 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
2284 : req_slot_id_param);
2285 1 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
2286 1 : free(data);
2287 1 : }
2288 :
2289 : /**
2290 : * Test 9: the requester is setup correctly (see Test 2), but, on the first try,
2291 : * receiving a ResponseNotReady ERROR message, and on retry, receiving a correct
2292 : * FINISH_RSP message with only MAC (no mutual authentication).
2293 : * Expected behavior: client returns a Status of RETURN_SUCCESS.
2294 : **/
2295 1 : void libspdm_test_requester_finish_case9(void **state)
2296 : {
2297 : libspdm_return_t status;
2298 : libspdm_test_context_t *spdm_test_context;
2299 : libspdm_context_t *spdm_context;
2300 : uint32_t session_id;
2301 : uint8_t req_slot_id_param;
2302 : void *data;
2303 : size_t data_size;
2304 : void *hash;
2305 : size_t hash_size;
2306 : libspdm_session_info_t *session_info;
2307 :
2308 1 : spdm_test_context = *state;
2309 1 : spdm_context = spdm_test_context->spdm_context;
2310 1 : spdm_test_context->case_id = 0x9;
2311 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2312 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2313 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2314 1 : spdm_context->connection_info.capability.flags |=
2315 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2316 1 : spdm_context->connection_info.capability.flags |=
2317 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2318 1 : spdm_context->connection_info.capability.flags |=
2319 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2320 1 : spdm_context->local_context.capability.flags |=
2321 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2322 1 : spdm_context->local_context.capability.flags |=
2323 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2324 1 : spdm_context->local_context.capability.flags |=
2325 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2326 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2327 : m_libspdm_use_asym_algo, &data,
2328 : &data_size, &hash, &hash_size);
2329 1 : libspdm_reset_message_a(spdm_context);
2330 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2331 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2332 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
2333 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
2334 :
2335 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2336 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
2337 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2338 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2339 : data, data_size);
2340 : #else
2341 1 : libspdm_hash_all(
2342 : spdm_context->connection_info.algorithm.base_hash_algo,
2343 : data, data_size,
2344 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2345 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2346 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2347 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2348 : spdm_context->connection_info.algorithm.base_hash_algo,
2349 : spdm_context->connection_info.algorithm.base_asym_algo,
2350 : data, data_size,
2351 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2352 : #endif
2353 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2354 :
2355 1 : session_id = 0xFFFFFFFF;
2356 1 : session_info = &spdm_context->session_info[0];
2357 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2358 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2359 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2360 1 : libspdm_secured_message_set_response_finished_key(
2361 : session_info->secured_message_context, m_libspdm_dummy_buffer, hash_size);
2362 1 : libspdm_secured_message_set_session_state(
2363 : session_info->secured_message_context,
2364 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2365 :
2366 1 : spdm_context->connection_info.capability.flags |=
2367 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2368 1 : spdm_context->local_context.capability.flags |=
2369 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2370 1 : req_slot_id_param = 0;
2371 1 : status = libspdm_send_receive_finish(spdm_context, session_id, req_slot_id_param);
2372 : if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
2373 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
2374 1 : assert_int_equal(
2375 : libspdm_secured_message_get_session_state(
2376 : spdm_context->session_info[0].secured_message_context),
2377 : LIBSPDM_SESSION_STATE_ESTABLISHED);
2378 : } else {
2379 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
2380 : }
2381 :
2382 1 : free(data);
2383 1 : }
2384 :
2385 : /**
2386 : * Test 10: receiving an unexpected ERROR message from the responder.
2387 : * There are tests for all named codes, including some reserved ones
2388 : * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
2389 : * However, for having specific test cases, it is excluded from this case:
2390 : * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
2391 : * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
2392 : **/
2393 1 : void libspdm_test_requester_finish_case10(void **state) {
2394 : libspdm_return_t status;
2395 : libspdm_test_context_t *spdm_test_context;
2396 : libspdm_context_t *spdm_context;
2397 : uint32_t session_id;
2398 : uint8_t req_slot_id_param;
2399 : void *data;
2400 : size_t data_size;
2401 : void *hash;
2402 : size_t hash_size;
2403 : libspdm_session_info_t *session_info;
2404 : uint16_t error_code;
2405 :
2406 1 : spdm_test_context = *state;
2407 1 : spdm_context = spdm_test_context->spdm_context;
2408 1 : spdm_test_context->case_id = 0xA;
2409 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2410 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2411 1 : spdm_context->connection_info.capability.flags |=
2412 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2413 1 : spdm_context->connection_info.capability.flags |=
2414 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2415 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2416 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2417 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2418 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2419 1 : libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
2420 : m_libspdm_use_asym_algo,
2421 : &data, &data_size,
2422 : &hash, &hash_size);
2423 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2424 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2425 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
2426 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
2427 :
2428 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2429 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2430 : data_size;
2431 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2432 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2433 : data, data_size);
2434 : #else
2435 1 : libspdm_hash_all(
2436 : spdm_context->connection_info.algorithm.base_hash_algo,
2437 : data, data_size,
2438 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2439 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2440 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2441 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2442 : spdm_context->connection_info.algorithm.base_hash_algo,
2443 : spdm_context->connection_info.algorithm.base_asym_algo,
2444 : data, data_size,
2445 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2446 : #endif
2447 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2448 :
2449 1 : session_id = 0xFFFFFFFF;
2450 1 : spdm_context->connection_info.capability.flags |=
2451 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2452 1 : spdm_context->local_context.capability.flags |=
2453 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2454 1 : req_slot_id_param = 0;
2455 :
2456 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
2457 19 : while(error_code <= 0xff) {
2458 18 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2459 18 : libspdm_reset_message_a(spdm_context);
2460 :
2461 18 : session_info = &spdm_context->session_info[0];
2462 18 : libspdm_session_info_init (spdm_context, session_info, session_id, false);
2463 18 : hash_size = libspdm_get_hash_size (m_libspdm_use_hash_algo);
2464 18 : libspdm_set_mem (m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2465 18 : libspdm_secured_message_set_response_finished_key (session_info->secured_message_context,
2466 : m_libspdm_dummy_buffer, hash_size);
2467 18 : libspdm_secured_message_set_session_state (session_info->secured_message_context,
2468 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2469 :
2470 18 : status = libspdm_send_receive_finish (spdm_context, session_id, req_slot_id_param);
2471 18 : if(error_code != SPDM_ERROR_CODE_DECRYPT_ERROR) {
2472 17 : LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
2473 : } else {
2474 1 : LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_SESSION_MSG_ERROR, error_code);
2475 : }
2476 :
2477 18 : error_code++;
2478 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
2479 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
2480 : }
2481 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
2482 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
2483 : }
2484 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
2485 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
2486 : }
2487 : }
2488 :
2489 1 : free(data);
2490 1 : }
2491 :
2492 1 : void libspdm_test_requester_finish_case11(void **state)
2493 : {
2494 : libspdm_return_t status;
2495 : libspdm_test_context_t *spdm_test_context;
2496 : libspdm_context_t *spdm_context;
2497 : uint32_t session_id;
2498 : uint8_t req_slot_id_param;
2499 : void *data;
2500 : size_t data_size;
2501 : void *hash;
2502 : size_t hash_size;
2503 : libspdm_session_info_t *session_info;
2504 :
2505 1 : spdm_test_context = *state;
2506 1 : spdm_context = spdm_test_context->spdm_context;
2507 1 : spdm_test_context->case_id = 0xB;
2508 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2509 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2510 1 : spdm_context->connection_info.connection_state =
2511 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2512 1 : spdm_context->connection_info.capability.flags |=
2513 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2514 1 : spdm_context->connection_info.capability.flags |=
2515 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2516 1 : spdm_context->connection_info.capability.flags |=
2517 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2518 1 : spdm_context->local_context.capability.flags |=
2519 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2520 1 : spdm_context->local_context.capability.flags |=
2521 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2522 1 : spdm_context->local_context.capability.flags |=
2523 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2524 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2525 : m_libspdm_use_asym_algo, &data,
2526 : &data_size, &hash, &hash_size);
2527 1 : libspdm_reset_message_a(spdm_context);
2528 1 : spdm_context->connection_info.algorithm.base_hash_algo =
2529 : m_libspdm_use_hash_algo;
2530 1 : spdm_context->connection_info.algorithm.base_asym_algo =
2531 : m_libspdm_use_asym_algo;
2532 1 : spdm_context->connection_info.algorithm.dhe_named_group =
2533 : m_libspdm_use_dhe_algo;
2534 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
2535 : m_libspdm_use_aead_algo;
2536 :
2537 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2538 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2539 : data_size;
2540 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2541 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2542 : data, data_size);
2543 : #else
2544 1 : libspdm_hash_all(
2545 : spdm_context->connection_info.algorithm.base_hash_algo,
2546 : data, data_size,
2547 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2548 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2549 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2550 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2551 : spdm_context->connection_info.algorithm.base_hash_algo,
2552 : spdm_context->connection_info.algorithm.base_asym_algo,
2553 : data, data_size,
2554 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2555 : #endif
2556 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2557 :
2558 1 : session_id = 0xFFFFFFFF;
2559 1 : session_info = &spdm_context->session_info[0];
2560 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2561 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2562 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2563 1 : libspdm_secured_message_set_response_finished_key(
2564 : session_info->secured_message_context, m_libspdm_dummy_buffer,
2565 : hash_size);
2566 1 : libspdm_secured_message_set_session_state(
2567 : session_info->secured_message_context,
2568 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2569 :
2570 1 : spdm_context->connection_info.capability.flags |=
2571 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2572 1 : spdm_context->local_context.capability.flags |=
2573 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2574 1 : req_slot_id_param = 0;
2575 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2576 : session_info->session_transcript.message_m.buffer_size =
2577 : session_info->session_transcript.message_m.max_buffer_size;
2578 : spdm_context->transcript.message_b.buffer_size =
2579 : spdm_context->transcript.message_b.max_buffer_size;
2580 : spdm_context->transcript.message_c.buffer_size =
2581 : spdm_context->transcript.message_c.max_buffer_size;
2582 : spdm_context->transcript.message_mut_b.buffer_size =
2583 : spdm_context->transcript.message_mut_b.max_buffer_size;
2584 : spdm_context->transcript.message_mut_c.buffer_size =
2585 : spdm_context->transcript.message_mut_c.max_buffer_size;
2586 : #endif
2587 :
2588 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
2589 : req_slot_id_param);
2590 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
2591 1 : assert_int_equal(
2592 : libspdm_secured_message_get_session_state(
2593 : spdm_context->session_info[0].secured_message_context),
2594 : LIBSPDM_SESSION_STATE_ESTABLISHED);
2595 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2596 : assert_int_equal(session_info->session_transcript.message_m.buffer_size,
2597 : 0);
2598 : assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
2599 : assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
2600 : assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
2601 : assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
2602 : #endif
2603 1 : free(data);
2604 1 : }
2605 :
2606 : /**
2607 : * Test 12: requester is not setup correctly to support key exchange
2608 : * (no capabilities). The responder would attempt to return a correct
2609 : * FINISH_RSP message.
2610 : * Expected behavior: client returns a Status of RETURN_UNSUPPORTED.
2611 : **/
2612 1 : void libspdm_test_requester_finish_case12(void **state)
2613 : {
2614 : libspdm_return_t status;
2615 : libspdm_test_context_t *spdm_test_context;
2616 : libspdm_context_t *spdm_context;
2617 : uint32_t session_id;
2618 : uint8_t req_slot_id_param;
2619 : void *data;
2620 : size_t data_size;
2621 : void *hash;
2622 : size_t hash_size;
2623 : libspdm_session_info_t *session_info;
2624 :
2625 1 : spdm_test_context = *state;
2626 1 : spdm_context = spdm_test_context->spdm_context;
2627 1 : spdm_test_context->case_id = 0xC;
2628 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2629 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2630 1 : spdm_context->connection_info.connection_state =
2631 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2632 1 : spdm_context->connection_info.capability.flags = 0;
2633 1 : spdm_context->connection_info.capability.flags |=
2634 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2635 1 : spdm_context->connection_info.capability.flags |=
2636 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2637 1 : spdm_context->connection_info.capability.flags |=
2638 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2639 1 : spdm_context->local_context.capability.flags = 0;
2640 : /* no key exchange capabilities (requester)*/
2641 1 : spdm_context->local_context.capability.flags |=
2642 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2643 1 : spdm_context->local_context.capability.flags |=
2644 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2645 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2646 : m_libspdm_use_asym_algo, &data,
2647 : &data_size, &hash, &hash_size);
2648 1 : libspdm_reset_message_a(spdm_context);
2649 1 : spdm_context->connection_info.algorithm.base_hash_algo =
2650 : m_libspdm_use_hash_algo;
2651 1 : spdm_context->connection_info.algorithm.base_asym_algo =
2652 : m_libspdm_use_asym_algo;
2653 1 : spdm_context->connection_info.algorithm.dhe_named_group =
2654 : m_libspdm_use_dhe_algo;
2655 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
2656 : m_libspdm_use_aead_algo;
2657 :
2658 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2659 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2660 : data_size;
2661 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2662 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2663 : data, data_size);
2664 : #else
2665 1 : libspdm_hash_all(
2666 : spdm_context->connection_info.algorithm.base_hash_algo,
2667 : data, data_size,
2668 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2669 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2670 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2671 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2672 : spdm_context->connection_info.algorithm.base_hash_algo,
2673 : spdm_context->connection_info.algorithm.base_asym_algo,
2674 : data, data_size,
2675 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2676 : #endif
2677 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2678 :
2679 1 : session_id = 0xFFFFFFFF;
2680 1 : session_info = &spdm_context->session_info[0];
2681 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2682 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2683 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2684 1 : libspdm_secured_message_set_response_finished_key(
2685 : session_info->secured_message_context, m_libspdm_dummy_buffer,
2686 : hash_size);
2687 1 : libspdm_secured_message_set_session_state(
2688 : session_info->secured_message_context,
2689 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2690 :
2691 1 : spdm_context->connection_info.capability.flags |=
2692 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2693 1 : spdm_context->local_context.capability.flags |=
2694 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2695 1 : req_slot_id_param = 0;
2696 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
2697 : req_slot_id_param);
2698 1 : assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
2699 1 : free(data);
2700 1 : }
2701 :
2702 : /**
2703 : * Test 13: requester is not setup correctly to accept key exchange and
2704 : * finish at this point (at least NEGOTIATE_ALGORITHMS is required, if
2705 : * the public key was provisioned before the key exchange). The
2706 : * responder would attempt to return a correct FINISH_RSP message.
2707 : * Expected behavior: client returns a Status of RETURN_UNSUPPORTED.
2708 : **/
2709 1 : void libspdm_test_requester_finish_case13(void **state)
2710 : {
2711 : libspdm_return_t status;
2712 : libspdm_test_context_t *spdm_test_context;
2713 : libspdm_context_t *spdm_context;
2714 : uint32_t session_id;
2715 : uint8_t req_slot_id_param;
2716 : void *data;
2717 : size_t data_size;
2718 : void *hash;
2719 : size_t hash_size;
2720 : libspdm_session_info_t *session_info;
2721 :
2722 1 : spdm_test_context = *state;
2723 1 : spdm_context = spdm_test_context->spdm_context;
2724 1 : spdm_test_context->case_id = 0xD;
2725 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2726 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2727 1 : spdm_context->connection_info.connection_state =
2728 : LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
2729 1 : spdm_context->connection_info.capability.flags |=
2730 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2731 1 : spdm_context->connection_info.capability.flags |=
2732 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2733 1 : spdm_context->connection_info.capability.flags |=
2734 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2735 1 : spdm_context->local_context.capability.flags |=
2736 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2737 1 : spdm_context->local_context.capability.flags |=
2738 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2739 1 : spdm_context->local_context.capability.flags |=
2740 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2741 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2742 : m_libspdm_use_asym_algo, &data,
2743 : &data_size, &hash, &hash_size);
2744 1 : libspdm_reset_message_a(spdm_context);
2745 1 : spdm_context->connection_info.algorithm.base_hash_algo =
2746 : m_libspdm_use_hash_algo;
2747 1 : spdm_context->connection_info.algorithm.base_asym_algo =
2748 : m_libspdm_use_asym_algo;
2749 1 : spdm_context->connection_info.algorithm.dhe_named_group =
2750 : m_libspdm_use_dhe_algo;
2751 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
2752 : m_libspdm_use_aead_algo;
2753 :
2754 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2755 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2756 : data_size;
2757 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2758 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2759 : data, data_size);
2760 : #else
2761 1 : libspdm_hash_all(
2762 : spdm_context->connection_info.algorithm.base_hash_algo,
2763 : data, data_size,
2764 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2765 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2766 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2767 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2768 : spdm_context->connection_info.algorithm.base_hash_algo,
2769 : spdm_context->connection_info.algorithm.base_asym_algo,
2770 : data, data_size,
2771 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2772 : #endif
2773 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2774 :
2775 1 : session_id = 0xFFFFFFFF;
2776 1 : session_info = &spdm_context->session_info[0];
2777 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2778 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2779 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2780 1 : libspdm_secured_message_set_response_finished_key(
2781 : session_info->secured_message_context, m_libspdm_dummy_buffer,
2782 : hash_size);
2783 1 : libspdm_secured_message_set_session_state(
2784 : session_info->secured_message_context,
2785 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2786 :
2787 1 : spdm_context->connection_info.capability.flags |=
2788 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2789 1 : spdm_context->local_context.capability.flags |=
2790 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2791 1 : req_slot_id_param = 0;
2792 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
2793 : req_slot_id_param);
2794 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
2795 1 : free(data);
2796 1 : }
2797 :
2798 : /**
2799 : * Test 14: receiving an incorrect FINISH_RSP message, with wrong response
2800 : * code, but all other field correct.
2801 : * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
2802 : **/
2803 1 : void libspdm_test_requester_finish_case14(void **state)
2804 : {
2805 : libspdm_return_t status;
2806 : libspdm_test_context_t *spdm_test_context;
2807 : libspdm_context_t *spdm_context;
2808 : uint32_t session_id;
2809 : uint8_t req_slot_id_param;
2810 : void *data;
2811 : size_t data_size;
2812 : void *hash;
2813 : size_t hash_size;
2814 : libspdm_session_info_t *session_info;
2815 :
2816 1 : spdm_test_context = *state;
2817 1 : spdm_context = spdm_test_context->spdm_context;
2818 1 : spdm_test_context->case_id = 0xE;
2819 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2820 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2821 1 : spdm_context->connection_info.connection_state =
2822 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2823 1 : spdm_context->connection_info.capability.flags |=
2824 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2825 1 : spdm_context->connection_info.capability.flags |=
2826 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2827 1 : spdm_context->connection_info.capability.flags |=
2828 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2829 1 : spdm_context->local_context.capability.flags |=
2830 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2831 1 : spdm_context->local_context.capability.flags |=
2832 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2833 1 : spdm_context->local_context.capability.flags |=
2834 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2835 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2836 : m_libspdm_use_asym_algo, &data,
2837 : &data_size, &hash, &hash_size);
2838 1 : libspdm_reset_message_a(spdm_context);
2839 1 : spdm_context->connection_info.algorithm.base_hash_algo =
2840 : m_libspdm_use_hash_algo;
2841 1 : spdm_context->connection_info.algorithm.base_asym_algo =
2842 : m_libspdm_use_asym_algo;
2843 1 : spdm_context->connection_info.algorithm.dhe_named_group =
2844 : m_libspdm_use_dhe_algo;
2845 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
2846 : m_libspdm_use_aead_algo;
2847 :
2848 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2849 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2850 : data_size;
2851 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2852 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2853 : data, data_size);
2854 : #else
2855 1 : libspdm_hash_all(
2856 : spdm_context->connection_info.algorithm.base_hash_algo,
2857 : data, data_size,
2858 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2859 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2860 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2861 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2862 : spdm_context->connection_info.algorithm.base_hash_algo,
2863 : spdm_context->connection_info.algorithm.base_asym_algo,
2864 : data, data_size,
2865 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2866 : #endif
2867 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2868 :
2869 1 : session_id = 0xFFFFFFFF;
2870 1 : session_info = &spdm_context->session_info[0];
2871 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2872 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2873 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2874 1 : libspdm_secured_message_set_response_finished_key(
2875 : session_info->secured_message_context, m_libspdm_dummy_buffer,
2876 : hash_size);
2877 1 : libspdm_secured_message_set_session_state(
2878 : session_info->secured_message_context,
2879 : LIBSPDM_SESSION_STATE_HANDSHAKING);
2880 :
2881 1 : spdm_context->connection_info.capability.flags |=
2882 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2883 1 : spdm_context->local_context.capability.flags |=
2884 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2885 1 : req_slot_id_param = 0;
2886 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
2887 : req_slot_id_param);
2888 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
2889 1 : free(data);
2890 1 : }
2891 :
2892 : /**
2893 : * Test 15: requester is not setup correctly by not initializing a
2894 : * session during KEY_EXCHANGE. The responder would attempt to
2895 : * return a correct FINISH_RSP message.
2896 : * Expected behavior: client returns a Status of RETURN_UNSUPPORTED.
2897 : **/
2898 1 : void libspdm_test_requester_finish_case15(void **state)
2899 : {
2900 : libspdm_return_t status;
2901 : libspdm_test_context_t *spdm_test_context;
2902 : libspdm_context_t *spdm_context;
2903 : uint32_t session_id;
2904 : uint8_t req_slot_id_param;
2905 : void *data;
2906 : size_t data_size;
2907 : void *hash;
2908 : size_t hash_size;
2909 : libspdm_session_info_t *session_info;
2910 :
2911 1 : spdm_test_context = *state;
2912 1 : spdm_context = spdm_test_context->spdm_context;
2913 1 : spdm_test_context->case_id = 0xF;
2914 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
2915 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2916 1 : spdm_context->connection_info.connection_state =
2917 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
2918 1 : spdm_context->connection_info.capability.flags |=
2919 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
2920 1 : spdm_context->connection_info.capability.flags |=
2921 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
2922 1 : spdm_context->connection_info.capability.flags |=
2923 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
2924 1 : spdm_context->local_context.capability.flags |=
2925 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
2926 1 : spdm_context->local_context.capability.flags |=
2927 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
2928 1 : spdm_context->local_context.capability.flags |=
2929 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
2930 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2931 : m_libspdm_use_asym_algo, &data,
2932 : &data_size, &hash, &hash_size);
2933 1 : libspdm_reset_message_a(spdm_context);
2934 1 : spdm_context->connection_info.algorithm.base_hash_algo =
2935 : m_libspdm_use_hash_algo;
2936 1 : spdm_context->connection_info.algorithm.base_asym_algo =
2937 : m_libspdm_use_asym_algo;
2938 1 : spdm_context->connection_info.algorithm.dhe_named_group =
2939 : m_libspdm_use_dhe_algo;
2940 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
2941 : m_libspdm_use_aead_algo;
2942 :
2943 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
2944 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
2945 : data_size;
2946 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
2947 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
2948 : data, data_size);
2949 : #else
2950 1 : libspdm_hash_all(
2951 : spdm_context->connection_info.algorithm.base_hash_algo,
2952 : data, data_size,
2953 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
2954 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
2955 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
2956 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
2957 : spdm_context->connection_info.algorithm.base_hash_algo,
2958 : spdm_context->connection_info.algorithm.base_asym_algo,
2959 : data, data_size,
2960 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
2961 : #endif
2962 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
2963 :
2964 1 : session_id = 0xFFFFFFFF;
2965 1 : session_info = &spdm_context->session_info[0];
2966 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
2967 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2968 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
2969 1 : libspdm_secured_message_set_response_finished_key(
2970 : session_info->secured_message_context, m_libspdm_dummy_buffer,
2971 : hash_size);
2972 1 : libspdm_secured_message_set_session_state(
2973 : session_info->secured_message_context,
2974 : LIBSPDM_SESSION_STATE_NOT_STARTED);
2975 :
2976 1 : spdm_context->connection_info.capability.flags |=
2977 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2978 1 : spdm_context->local_context.capability.flags |=
2979 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
2980 1 : req_slot_id_param = 0;
2981 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
2982 : req_slot_id_param);
2983 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
2984 1 : free(data);
2985 1 : }
2986 :
2987 : /**
2988 : * Test 16: receiving a correct FINISH_RSP message with a correct MAC,
2989 : * mutual authentication and 'handshake in the clear'.
2990 : * Expected behavior: client returns a Status of RETURN_SUCCESS and
2991 : * session is established.
2992 : **/
2993 1 : void libspdm_test_requester_finish_case16(void **state)
2994 : {
2995 : libspdm_return_t status;
2996 : libspdm_test_context_t *spdm_test_context;
2997 : libspdm_context_t *spdm_context;
2998 : uint32_t session_id;
2999 : uint8_t req_slot_id_param;
3000 : void *data;
3001 : size_t data_size;
3002 : void *hash;
3003 : size_t hash_size;
3004 : libspdm_session_info_t *session_info;
3005 :
3006 1 : spdm_test_context = *state;
3007 1 : spdm_context = spdm_test_context->spdm_context;
3008 1 : spdm_test_context->case_id = 0x10;
3009 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3010 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3011 1 : spdm_context->connection_info.connection_state =
3012 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3013 1 : spdm_context->connection_info.capability.flags |=
3014 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
3015 1 : spdm_context->connection_info.capability.flags |=
3016 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
3017 1 : spdm_context->connection_info.capability.flags |=
3018 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3019 1 : spdm_context->local_context.capability.flags |=
3020 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
3021 1 : spdm_context->local_context.capability.flags |=
3022 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
3023 1 : spdm_context->local_context.capability.flags |=
3024 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3025 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3026 : m_libspdm_use_asym_algo, &data,
3027 : &data_size, &hash, &hash_size);
3028 1 : libspdm_reset_message_a(spdm_context);
3029 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3030 : m_libspdm_use_hash_algo;
3031 1 : spdm_context->connection_info.algorithm.base_asym_algo =
3032 : m_libspdm_use_asym_algo;
3033 1 : spdm_context->connection_info.algorithm.req_base_asym_alg =
3034 : m_libspdm_use_req_asym_algo;
3035 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3036 : m_libspdm_use_dhe_algo;
3037 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3038 : m_libspdm_use_aead_algo;
3039 :
3040 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3041 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3042 : data_size;
3043 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3044 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3045 : data, data_size);
3046 : #else
3047 1 : libspdm_hash_all(
3048 : spdm_context->connection_info.algorithm.base_hash_algo,
3049 : data, data_size,
3050 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3051 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3052 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3053 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3054 : spdm_context->connection_info.algorithm.base_hash_algo,
3055 : spdm_context->connection_info.algorithm.base_asym_algo,
3056 : data, data_size,
3057 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3058 : #endif
3059 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
3060 :
3061 1 : req_slot_id_param = 0;
3062 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
3063 : m_libspdm_use_req_asym_algo, &data,
3064 : &data_size, &hash, &hash_size);
3065 : spdm_context->local_context.
3066 1 : local_cert_chain_provision_size[req_slot_id_param] = data_size;
3067 : spdm_context->local_context.
3068 1 : local_cert_chain_provision[req_slot_id_param] = data;
3069 :
3070 1 : session_id = 0xFFFFFFFF;
3071 1 : session_info = &spdm_context->session_info[0];
3072 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
3073 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3074 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
3075 1 : libspdm_secured_message_set_response_finished_key(
3076 : session_info->secured_message_context, m_libspdm_dummy_buffer,
3077 : hash_size);
3078 1 : libspdm_secured_message_set_session_state(
3079 : session_info->secured_message_context,
3080 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3081 1 : session_info->mut_auth_requested = 1;
3082 :
3083 1 : spdm_context->connection_info.capability.flags |=
3084 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3085 1 : spdm_context->local_context.capability.flags |=
3086 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3087 :
3088 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
3089 : req_slot_id_param);
3090 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3091 1 : assert_int_equal(
3092 : libspdm_secured_message_get_session_state(
3093 : spdm_context->session_info[0].secured_message_context),
3094 : LIBSPDM_SESSION_STATE_ESTABLISHED);
3095 1 : free(data);
3096 1 : }
3097 :
3098 : /**
3099 : * Test 17: receiving a FINISH_RSP message with an incorrect MAC
3100 : * (all-zero), mutual authentication, and 'handshake in the clear'.
3101 : * Expected behavior: client returns a Status of RETURN_SECURITY_VIOLATION.
3102 : **/
3103 1 : void libspdm_test_requester_finish_case17(void **state)
3104 : {
3105 : libspdm_return_t status;
3106 : libspdm_test_context_t *spdm_test_context;
3107 : libspdm_context_t *spdm_context;
3108 : uint32_t session_id;
3109 : uint8_t req_slot_id_param;
3110 : void *data;
3111 : size_t data_size;
3112 : void *hash;
3113 : size_t hash_size;
3114 : libspdm_session_info_t *session_info;
3115 :
3116 1 : spdm_test_context = *state;
3117 1 : spdm_context = spdm_test_context->spdm_context;
3118 1 : spdm_test_context->case_id = 0x11;
3119 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3120 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3121 1 : spdm_context->connection_info.connection_state =
3122 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3123 1 : spdm_context->connection_info.capability.flags |=
3124 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
3125 1 : spdm_context->connection_info.capability.flags |=
3126 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
3127 1 : spdm_context->connection_info.capability.flags |=
3128 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3129 1 : spdm_context->local_context.capability.flags |=
3130 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
3131 1 : spdm_context->local_context.capability.flags |=
3132 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
3133 1 : spdm_context->local_context.capability.flags |=
3134 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3135 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3136 : m_libspdm_use_asym_algo, &data,
3137 : &data_size, &hash, &hash_size);
3138 1 : libspdm_reset_message_a(spdm_context);
3139 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3140 : m_libspdm_use_hash_algo;
3141 1 : spdm_context->connection_info.algorithm.base_asym_algo =
3142 : m_libspdm_use_asym_algo;
3143 1 : spdm_context->connection_info.algorithm.req_base_asym_alg =
3144 : m_libspdm_use_req_asym_algo;
3145 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3146 : m_libspdm_use_dhe_algo;
3147 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3148 : m_libspdm_use_aead_algo;
3149 :
3150 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3151 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3152 : data_size;
3153 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3154 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3155 : data, data_size);
3156 : #else
3157 1 : libspdm_hash_all(
3158 : spdm_context->connection_info.algorithm.base_hash_algo,
3159 : data, data_size,
3160 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3161 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3162 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3163 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3164 : spdm_context->connection_info.algorithm.base_hash_algo,
3165 : spdm_context->connection_info.algorithm.base_asym_algo,
3166 : data, data_size,
3167 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3168 : #endif
3169 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
3170 :
3171 1 : req_slot_id_param = 0;
3172 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
3173 : m_libspdm_use_req_asym_algo, &data,
3174 : &data_size, &hash, &hash_size);
3175 : spdm_context->local_context.
3176 1 : local_cert_chain_provision_size[req_slot_id_param] = data_size;
3177 : spdm_context->local_context.
3178 1 : local_cert_chain_provision[req_slot_id_param] = data;
3179 :
3180 1 : session_id = 0xFFFFFFFF;
3181 1 : session_info = &spdm_context->session_info[0];
3182 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
3183 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3184 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
3185 1 : libspdm_secured_message_set_response_finished_key(
3186 : session_info->secured_message_context, m_libspdm_dummy_buffer,
3187 : hash_size);
3188 1 : libspdm_secured_message_set_session_state(
3189 : session_info->secured_message_context,
3190 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3191 1 : session_info->mut_auth_requested = 1;
3192 :
3193 1 : spdm_context->connection_info.capability.flags |=
3194 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3195 1 : spdm_context->local_context.capability.flags |=
3196 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3197 :
3198 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
3199 : req_slot_id_param);
3200 1 : assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
3201 1 : free(data);
3202 1 : }
3203 :
3204 : /**
3205 : * Test 18: receiving a FINISH_RSP message with an incorrect MAC
3206 : * (arbitrary), mutual authentication, and 'handshake in the clear'.
3207 : * Expected behavior: client returns a Status of RETURN_SECURITY_VIOLATION.
3208 : **/
3209 1 : void libspdm_test_requester_finish_case18(void **state)
3210 : {
3211 : libspdm_return_t status;
3212 : libspdm_test_context_t *spdm_test_context;
3213 : libspdm_context_t *spdm_context;
3214 : uint32_t session_id;
3215 : uint8_t req_slot_id_param;
3216 : void *data;
3217 : size_t data_size;
3218 : void *hash;
3219 : size_t hash_size;
3220 : libspdm_session_info_t *session_info;
3221 :
3222 1 : spdm_test_context = *state;
3223 1 : spdm_context = spdm_test_context->spdm_context;
3224 1 : spdm_test_context->case_id = 0x12;
3225 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3226 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3227 1 : spdm_context->connection_info.connection_state =
3228 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3229 1 : spdm_context->connection_info.capability.flags |=
3230 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
3231 1 : spdm_context->connection_info.capability.flags |=
3232 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
3233 1 : spdm_context->connection_info.capability.flags |=
3234 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3235 1 : spdm_context->local_context.capability.flags |=
3236 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
3237 1 : spdm_context->local_context.capability.flags |=
3238 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
3239 1 : spdm_context->local_context.capability.flags |=
3240 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3241 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3242 : m_libspdm_use_asym_algo, &data,
3243 : &data_size, &hash, &hash_size);
3244 1 : libspdm_reset_message_a(spdm_context);
3245 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3246 : m_libspdm_use_hash_algo;
3247 1 : spdm_context->connection_info.algorithm.base_asym_algo =
3248 : m_libspdm_use_asym_algo;
3249 1 : spdm_context->connection_info.algorithm.req_base_asym_alg =
3250 : m_libspdm_use_req_asym_algo;
3251 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3252 : m_libspdm_use_dhe_algo;
3253 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3254 : m_libspdm_use_aead_algo;
3255 :
3256 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3257 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3258 : data_size;
3259 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3260 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3261 : data, data_size);
3262 : #else
3263 1 : libspdm_hash_all(
3264 : spdm_context->connection_info.algorithm.base_hash_algo,
3265 : data, data_size,
3266 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3267 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3268 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3269 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3270 : spdm_context->connection_info.algorithm.base_hash_algo,
3271 : spdm_context->connection_info.algorithm.base_asym_algo,
3272 : data, data_size,
3273 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3274 : #endif
3275 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
3276 :
3277 1 : req_slot_id_param = 0;
3278 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
3279 : m_libspdm_use_req_asym_algo, &data,
3280 : &data_size, &hash, &hash_size);
3281 : spdm_context->local_context.
3282 1 : local_cert_chain_provision_size[req_slot_id_param] = data_size;
3283 : spdm_context->local_context.
3284 1 : local_cert_chain_provision[req_slot_id_param] = data;
3285 :
3286 1 : session_id = 0xFFFFFFFF;
3287 1 : session_info = &spdm_context->session_info[0];
3288 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
3289 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3290 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
3291 1 : libspdm_secured_message_set_response_finished_key(
3292 : session_info->secured_message_context, m_libspdm_dummy_buffer,
3293 : hash_size);
3294 1 : libspdm_secured_message_set_session_state(
3295 : session_info->secured_message_context,
3296 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3297 1 : session_info->mut_auth_requested = 1;
3298 :
3299 1 : spdm_context->connection_info.capability.flags |=
3300 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3301 1 : spdm_context->local_context.capability.flags |=
3302 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3303 :
3304 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
3305 : req_slot_id_param);
3306 1 : assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
3307 1 : free(data);
3308 1 : }
3309 :
3310 : /**
3311 : * Test 19:
3312 : * Expected behavior:
3313 : **/
3314 1 : void libspdm_test_requester_finish_case19(void **state)
3315 : {
3316 1 : }
3317 :
3318 : /**
3319 : * Test 20: receiving a FINISH_RSP message an incorrect MAC size (only the
3320 : * correct first half of the MAC), mutual authentication, and 'handshake
3321 : * in the clear'.
3322 : * Expected behavior: client returns a Status of RETURN_DEVICE_ERROR.
3323 : **/
3324 1 : void libspdm_test_requester_finish_case20(void **state)
3325 : {
3326 : libspdm_return_t status;
3327 : libspdm_test_context_t *spdm_test_context;
3328 : libspdm_context_t *spdm_context;
3329 : uint32_t session_id;
3330 : uint8_t req_slot_id_param;
3331 : void *data;
3332 : size_t data_size;
3333 : void *hash;
3334 : size_t hash_size;
3335 : libspdm_session_info_t *session_info;
3336 :
3337 1 : spdm_test_context = *state;
3338 1 : spdm_context = spdm_test_context->spdm_context;
3339 1 : spdm_test_context->case_id = 0x14;
3340 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3341 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3342 1 : spdm_context->connection_info.connection_state =
3343 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3344 1 : spdm_context->connection_info.capability.flags |=
3345 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
3346 1 : spdm_context->connection_info.capability.flags |=
3347 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
3348 1 : spdm_context->connection_info.capability.flags |=
3349 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3350 1 : spdm_context->local_context.capability.flags |=
3351 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
3352 1 : spdm_context->local_context.capability.flags |=
3353 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
3354 1 : spdm_context->local_context.capability.flags |=
3355 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3356 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3357 : m_libspdm_use_asym_algo, &data,
3358 : &data_size, &hash, &hash_size);
3359 1 : libspdm_reset_message_a(spdm_context);
3360 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3361 : m_libspdm_use_hash_algo;
3362 1 : spdm_context->connection_info.algorithm.base_asym_algo =
3363 : m_libspdm_use_asym_algo;
3364 1 : spdm_context->connection_info.algorithm.req_base_asym_alg =
3365 : m_libspdm_use_req_asym_algo;
3366 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3367 : m_libspdm_use_dhe_algo;
3368 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3369 : m_libspdm_use_aead_algo;
3370 :
3371 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3372 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3373 : data_size;
3374 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3375 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3376 : data, data_size);
3377 : #else
3378 1 : libspdm_hash_all(
3379 : spdm_context->connection_info.algorithm.base_hash_algo,
3380 : data, data_size,
3381 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3382 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3383 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3384 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3385 : spdm_context->connection_info.algorithm.base_hash_algo,
3386 : spdm_context->connection_info.algorithm.base_asym_algo,
3387 : data, data_size,
3388 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3389 : #endif
3390 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
3391 :
3392 1 : req_slot_id_param = 0;
3393 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
3394 : m_libspdm_use_req_asym_algo, &data,
3395 : &data_size, &hash, &hash_size);
3396 : spdm_context->local_context.
3397 1 : local_cert_chain_provision_size[req_slot_id_param] = data_size;
3398 : spdm_context->local_context.
3399 1 : local_cert_chain_provision[req_slot_id_param] = data;
3400 :
3401 1 : session_id = 0xFFFFFFFF;
3402 1 : session_info = &spdm_context->session_info[0];
3403 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
3404 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3405 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
3406 1 : libspdm_secured_message_set_response_finished_key(
3407 : session_info->secured_message_context, m_libspdm_dummy_buffer,
3408 : hash_size);
3409 1 : libspdm_secured_message_set_session_state(
3410 : session_info->secured_message_context,
3411 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3412 1 : session_info->mut_auth_requested = 1;
3413 :
3414 1 : spdm_context->connection_info.capability.flags |=
3415 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3416 1 : spdm_context->local_context.capability.flags |=
3417 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3418 :
3419 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
3420 : req_slot_id_param);
3421 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
3422 1 : free(data);
3423 1 : }
3424 :
3425 : /**
3426 : * Test 21: the requester is setup correctly, but receives an ERROR with SPDM_ERROR_CODE_DECRYPT_ERROR.
3427 : * Expected behavior: client returns a Status of INVALID_SESSION_ID and free the session ID.
3428 : **/
3429 1 : void libspdm_test_requester_finish_case21(void **state)
3430 : {
3431 : libspdm_return_t status;
3432 : libspdm_test_context_t *spdm_test_context;
3433 : libspdm_context_t *spdm_context;
3434 : uint32_t session_id;
3435 : uint8_t req_slot_id_param;
3436 : void *data;
3437 : size_t data_size;
3438 : void *hash;
3439 : size_t hash_size;
3440 : libspdm_session_info_t *session_info;
3441 :
3442 1 : spdm_test_context = *state;
3443 1 : spdm_context = spdm_test_context->spdm_context;
3444 1 : spdm_test_context->case_id = 0x15;
3445 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3446 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3447 1 : spdm_context->connection_info.connection_state =
3448 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3449 1 : spdm_context->connection_info.capability.flags |=
3450 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
3451 1 : spdm_context->connection_info.capability.flags |=
3452 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
3453 1 : spdm_context->connection_info.capability.flags |=
3454 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3455 1 : spdm_context->local_context.capability.flags |=
3456 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
3457 1 : spdm_context->local_context.capability.flags |=
3458 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
3459 1 : spdm_context->local_context.capability.flags |=
3460 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3461 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3462 : m_libspdm_use_asym_algo, &data,
3463 : &data_size, &hash, &hash_size);
3464 1 : libspdm_reset_message_a(spdm_context);
3465 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3466 : m_libspdm_use_hash_algo;
3467 1 : spdm_context->connection_info.algorithm.base_asym_algo =
3468 : m_libspdm_use_asym_algo;
3469 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3470 : m_libspdm_use_dhe_algo;
3471 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3472 : m_libspdm_use_aead_algo;
3473 :
3474 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3475 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3476 : data_size;
3477 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3478 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3479 : data, data_size);
3480 : #else
3481 1 : libspdm_hash_all(
3482 : spdm_context->connection_info.algorithm.base_hash_algo,
3483 : data, data_size,
3484 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3485 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3486 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3487 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3488 : spdm_context->connection_info.algorithm.base_hash_algo,
3489 : spdm_context->connection_info.algorithm.base_asym_algo,
3490 : data, data_size,
3491 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3492 : #endif
3493 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
3494 :
3495 1 : session_id = 0xFFFFFFFF;
3496 1 : session_info = &spdm_context->session_info[0];
3497 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
3498 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3499 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
3500 1 : libspdm_secured_message_set_response_finished_key(
3501 : session_info->secured_message_context, m_libspdm_dummy_buffer,
3502 : hash_size);
3503 1 : libspdm_secured_message_set_session_state(
3504 : session_info->secured_message_context,
3505 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3506 :
3507 1 : spdm_context->connection_info.capability.flags |=
3508 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3509 1 : spdm_context->local_context.capability.flags |=
3510 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3511 1 : req_slot_id_param = 0;
3512 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
3513 : req_slot_id_param);
3514 1 : assert_int_equal(status, LIBSPDM_STATUS_SESSION_MSG_ERROR);
3515 1 : assert_int_equal(spdm_context->session_info->session_id, INVALID_SESSION_ID);
3516 1 : free(data);
3517 1 : }
3518 :
3519 : /**
3520 : * Test 22: a FINISH request message is successfully sent and a FINISH_RSP response message is
3521 : * successfully received.
3522 : * Expected Behavior: requester returns the status RETURN_SUCCESS and a FINISH_RSP message is
3523 : * received, buffer F appends the exchanged FINISH and FINISH_RSP
3524 : **/
3525 1 : void libspdm_test_requester_finish_case22(void **state)
3526 : {
3527 : libspdm_return_t status;
3528 : libspdm_test_context_t *spdm_test_context;
3529 : libspdm_context_t *spdm_context;
3530 : uint32_t session_id;
3531 : uint8_t req_slot_id_param;
3532 : void *data;
3533 : size_t data_size;
3534 : void *hash;
3535 : size_t hash_size;
3536 : libspdm_session_info_t *session_info;
3537 :
3538 1 : spdm_test_context = *state;
3539 1 : spdm_context = spdm_test_context->spdm_context;
3540 1 : spdm_test_context->case_id = 0x16;
3541 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3542 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3543 1 : spdm_context->connection_info.connection_state =
3544 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3545 1 : spdm_context->connection_info.capability.flags |=
3546 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
3547 1 : spdm_context->connection_info.capability.flags |=
3548 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
3549 1 : spdm_context->connection_info.capability.flags |=
3550 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3551 1 : spdm_context->local_context.capability.flags |=
3552 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
3553 1 : spdm_context->local_context.capability.flags |=
3554 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
3555 1 : spdm_context->local_context.capability.flags |=
3556 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3557 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3558 : m_libspdm_use_asym_algo, &data,
3559 : &data_size, &hash, &hash_size);
3560 1 : libspdm_reset_message_a(spdm_context);
3561 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3562 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3563 1 : spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
3564 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3565 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
3566 :
3567 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3568 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3569 : data_size;
3570 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3571 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3572 : data, data_size);
3573 : #else
3574 1 : libspdm_hash_all(
3575 : spdm_context->connection_info.algorithm.base_hash_algo,
3576 : data, data_size,
3577 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3578 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3579 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3580 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3581 : spdm_context->connection_info.algorithm.base_hash_algo,
3582 : spdm_context->connection_info.algorithm.base_asym_algo,
3583 : data, data_size,
3584 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3585 : #endif
3586 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
3587 :
3588 1 : req_slot_id_param = 0;
3589 1 : libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
3590 : m_libspdm_use_req_asym_algo, &data,
3591 : &data_size, &hash, &hash_size);
3592 : spdm_context->local_context.
3593 1 : local_cert_chain_provision_size[req_slot_id_param] = data_size;
3594 : spdm_context->local_context.
3595 1 : local_cert_chain_provision[req_slot_id_param] = data;
3596 :
3597 1 : session_id = 0xFFFFFFFF;
3598 1 : session_info = &spdm_context->session_info[0];
3599 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
3600 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3601 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
3602 1 : libspdm_secured_message_set_response_finished_key(
3603 : session_info->secured_message_context, m_libspdm_dummy_buffer,
3604 : hash_size);
3605 1 : libspdm_secured_message_set_session_state(
3606 : session_info->secured_message_context,
3607 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3608 1 : session_info->mut_auth_requested = 1;
3609 :
3610 1 : spdm_context->connection_info.capability.flags |=
3611 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3612 1 : spdm_context->local_context.capability.flags |=
3613 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3614 :
3615 1 : status = libspdm_send_receive_finish(spdm_context, session_id,
3616 : req_slot_id_param);
3617 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3618 1 : assert_int_equal(
3619 : libspdm_secured_message_get_session_state(
3620 : spdm_context->session_info[0].secured_message_context),
3621 : LIBSPDM_SESSION_STATE_ESTABLISHED);
3622 :
3623 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3624 : assert_int_equal(spdm_context->session_info[0].session_transcript.message_f.buffer_size,
3625 : m_libspdm_local_buffer_size);
3626 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
3627 : m_libspdm_local_buffer_size));
3628 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3629 : assert_memory_equal(spdm_context->session_info[0].session_transcript.message_f.buffer,
3630 : m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3631 : #endif
3632 1 : free(data);
3633 1 : }
3634 :
3635 : /**
3636 : * Test 23: receiving a correct FINISH_RSP message using slot_id 0xFF
3637 : * Expected behavior: client returns a Status of RETURN_SUCCESS and
3638 : * session is established.
3639 : **/
3640 1 : void libspdm_test_requester_finish_case23(void **state)
3641 : {
3642 : libspdm_return_t status;
3643 : libspdm_test_context_t *spdm_test_context;
3644 : libspdm_context_t *spdm_context;
3645 : uint32_t session_id;
3646 : uint8_t req_slot_id_param;
3647 : void *data;
3648 : size_t data_size;
3649 : size_t hash_size;
3650 : libspdm_session_info_t *session_info;
3651 : libspdm_secured_message_context_t *secured_message_context;
3652 :
3653 1 : spdm_test_context = *state;
3654 1 : spdm_context = spdm_test_context->spdm_context;
3655 1 : spdm_test_context->case_id = 0x17;
3656 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3657 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3658 1 : spdm_context->connection_info.connection_state =
3659 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3660 1 : spdm_context->connection_info.capability.flags |=
3661 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
3662 1 : spdm_context->connection_info.capability.flags |=
3663 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
3664 1 : spdm_context->connection_info.capability.flags |=
3665 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3666 1 : spdm_context->connection_info.capability.flags |=
3667 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
3668 1 : spdm_context->local_context.capability.flags |=
3669 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
3670 1 : spdm_context->local_context.capability.flags |=
3671 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
3672 1 : spdm_context->local_context.capability.flags |=
3673 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3674 1 : spdm_context->local_context.capability.flags |=
3675 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP;
3676 1 : libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
3677 1 : spdm_context->local_context.peer_public_key_provision = data;
3678 1 : spdm_context->local_context.peer_public_key_provision_size = data_size;
3679 :
3680 1 : libspdm_reset_message_a(spdm_context);
3681 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3682 : m_libspdm_use_hash_algo;
3683 1 : spdm_context->connection_info.algorithm.base_asym_algo =
3684 : m_libspdm_use_asym_algo;
3685 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3686 : m_libspdm_use_dhe_algo;
3687 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3688 : m_libspdm_use_aead_algo;
3689 :
3690 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0xFF;
3691 :
3692 1 : session_id = 0xFFFFFFFF;
3693 1 : session_info = &spdm_context->session_info[0];
3694 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
3695 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3696 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
3697 1 : libspdm_secured_message_set_response_finished_key(
3698 : session_info->secured_message_context, m_libspdm_dummy_buffer,
3699 : hash_size);
3700 1 : libspdm_secured_message_set_session_state(
3701 : session_info->secured_message_context,
3702 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3703 :
3704 1 : spdm_context->connection_info.capability.flags |=
3705 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3706 1 : spdm_context->local_context.capability.flags |=
3707 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3708 1 : req_slot_id_param = 0;
3709 1 : status = libspdm_send_receive_finish(spdm_context, session_id, req_slot_id_param);
3710 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3711 1 : assert_int_equal(
3712 : libspdm_secured_message_get_session_state(
3713 : spdm_context->session_info[0].secured_message_context),
3714 : LIBSPDM_SESSION_STATE_ESTABLISHED);
3715 :
3716 1 : secured_message_context = session_info->secured_message_context;
3717 :
3718 1 : assert_memory_equal((const void *)secured_message_context->master_secret.master_secret,
3719 : (const void *)m_libspdm_zero_buffer, sizeof(m_libspdm_zero_buffer));
3720 1 : free(data);
3721 1 : }
3722 :
3723 : /**
3724 : * Test 24: Set HANDSHAKE_IN_THE_CLEAR_CAP to 0 , The ResponderVerifyData field is absent.
3725 : * Expected behavior: client returns a Status of RETURN_SUCCESS and
3726 : * session is established.
3727 : **/
3728 1 : void libspdm_test_requester_finish_case24(void **state)
3729 : {
3730 : libspdm_return_t status;
3731 : libspdm_test_context_t *spdm_test_context;
3732 : libspdm_context_t *spdm_context;
3733 : uint32_t session_id;
3734 : uint8_t req_slot_id_param;
3735 : void *data;
3736 : size_t data_size;
3737 : void *hash;
3738 : size_t hash_size;
3739 : libspdm_session_info_t *session_info;
3740 : libspdm_secured_message_context_t *secured_message_context;
3741 :
3742 1 : spdm_test_context = *state;
3743 1 : spdm_context = spdm_test_context->spdm_context;
3744 1 : spdm_test_context->case_id = 0x18;
3745 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3746 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3747 1 : spdm_context->connection_info.connection_state =
3748 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3749 1 : spdm_context->connection_info.capability.flags |=
3750 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
3751 1 : spdm_context->connection_info.capability.flags |=
3752 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
3753 1 : spdm_context->connection_info.capability.flags |=
3754 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3755 1 : spdm_context->local_context.capability.flags |=
3756 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
3757 1 : spdm_context->local_context.capability.flags |=
3758 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
3759 1 : spdm_context->local_context.capability.flags |=
3760 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3761 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3762 : m_libspdm_use_asym_algo, &data,
3763 : &data_size, &hash, &hash_size);
3764 1 : libspdm_reset_message_a(spdm_context);
3765 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3766 : m_libspdm_use_hash_algo;
3767 1 : spdm_context->connection_info.algorithm.base_asym_algo =
3768 : m_libspdm_use_asym_algo;
3769 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3770 : m_libspdm_use_dhe_algo;
3771 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3772 : m_libspdm_use_aead_algo;
3773 :
3774 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3775 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3776 : data_size;
3777 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3778 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3779 : data, data_size);
3780 : #else
3781 1 : libspdm_hash_all(
3782 : m_libspdm_use_hash_algo,
3783 : data, data_size,
3784 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3785 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3786 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
3787 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3788 : m_libspdm_use_hash_algo,
3789 : spdm_context->connection_info.algorithm.base_asym_algo,
3790 : data, data_size,
3791 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3792 : #endif
3793 1 : spdm_context->connection_info.peer_used_cert_chain_slot_id = 0;
3794 :
3795 : /* Set HANDSHAKE_IN_THE_CLEAR_CAP to 0*/
3796 1 : spdm_context->connection_info.capability.flags &=
3797 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3798 1 : spdm_context->local_context.capability.flags &=
3799 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP;
3800 :
3801 1 : session_id = 0xFFFFFFFF;
3802 1 : session_info = &spdm_context->session_info[0];
3803 1 : spdm_context->last_spdm_request_session_id_valid = true;
3804 1 : spdm_context->last_spdm_request_session_id = session_id;
3805 1 : libspdm_session_info_init(spdm_context, session_info, session_id, false);
3806 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3807 1 : libspdm_set_mem(m_libspdm_dummy_buffer, hash_size, (uint8_t)(0xFF));
3808 1 : libspdm_secured_message_set_response_finished_key(
3809 : session_info->secured_message_context, m_libspdm_dummy_buffer,
3810 : hash_size);
3811 1 : libspdm_secured_message_set_session_state(
3812 : session_info->secured_message_context,
3813 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3814 :
3815 1 : req_slot_id_param = 0;
3816 1 : status = libspdm_send_receive_finish(spdm_context, session_id, req_slot_id_param);
3817 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3818 1 : assert_int_equal(
3819 : libspdm_secured_message_get_session_state(
3820 : spdm_context->session_info[0].secured_message_context),
3821 : LIBSPDM_SESSION_STATE_ESTABLISHED);
3822 :
3823 1 : secured_message_context = session_info->secured_message_context;
3824 :
3825 1 : assert_memory_equal((const void *)secured_message_context->master_secret.master_secret,
3826 : (const void *)m_libspdm_zero_buffer, sizeof(m_libspdm_zero_buffer));
3827 1 : free(data);
3828 1 : }
3829 :
3830 1 : int libspdm_requester_finish_test_main(void)
3831 : {
3832 1 : const struct CMUnitTest spdm_requester_finish_tests[] = {
3833 : /* SendRequest failed*/
3834 : cmocka_unit_test(libspdm_test_requester_finish_case1),
3835 : /* Successful response*/
3836 : cmocka_unit_test(libspdm_test_requester_finish_case2),
3837 : /* connection_state check failed*/
3838 : cmocka_unit_test(libspdm_test_requester_finish_case3),
3839 : /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
3840 : cmocka_unit_test(libspdm_test_requester_finish_case4),
3841 : /* Always SPDM_ERROR_CODE_BUSY*/
3842 : cmocka_unit_test(libspdm_test_requester_finish_case5),
3843 : /* SPDM_ERROR_CODE_BUSY + Successful response*/
3844 : cmocka_unit_test(libspdm_test_requester_finish_case6),
3845 : /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
3846 : cmocka_unit_test(libspdm_test_requester_finish_case7),
3847 : /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
3848 : cmocka_unit_test(libspdm_test_requester_finish_case8),
3849 : /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
3850 : cmocka_unit_test(libspdm_test_requester_finish_case9),
3851 : /* Unexpected errors*/
3852 : cmocka_unit_test(libspdm_test_requester_finish_case10),
3853 : /* Buffer reset*/
3854 : cmocka_unit_test(libspdm_test_requester_finish_case11),
3855 : /* No correct setup*/
3856 : cmocka_unit_test(libspdm_test_requester_finish_case12),
3857 : cmocka_unit_test(libspdm_test_requester_finish_case13),
3858 : cmocka_unit_test(libspdm_test_requester_finish_case14),
3859 : cmocka_unit_test(libspdm_test_requester_finish_case15),
3860 : /* Successful response*/
3861 : cmocka_unit_test(libspdm_test_requester_finish_case16),
3862 : /* Response with invalid MAC*/
3863 : cmocka_unit_test(libspdm_test_requester_finish_case17),
3864 : cmocka_unit_test(libspdm_test_requester_finish_case18),
3865 : /* Can be populated with new test.*/
3866 : cmocka_unit_test(libspdm_test_requester_finish_case19),
3867 : cmocka_unit_test(libspdm_test_requester_finish_case20),
3868 : /* Error response: SPDM_ERROR_CODE_DECRYPT_ERROR*/
3869 : cmocka_unit_test(libspdm_test_requester_finish_case21),
3870 : /* Buffer verification*/
3871 : cmocka_unit_test(libspdm_test_requester_finish_case22),
3872 : /* Successful response using provisioned public key (slot_id 0xFF) */
3873 : cmocka_unit_test(libspdm_test_requester_finish_case23),
3874 : /* Set HANDSHAKE_IN_THE_CLEAR_CAP to 0 , The ResponderVerifyData field is absent.*/
3875 : cmocka_unit_test(libspdm_test_requester_finish_case24),
3876 : };
3877 :
3878 1 : libspdm_test_context_t test_context = {
3879 : LIBSPDM_TEST_CONTEXT_VERSION,
3880 : true,
3881 : libspdm_requester_finish_test_send_message,
3882 : libspdm_requester_finish_test_receive_message,
3883 : };
3884 :
3885 1 : libspdm_setup_test_context(&test_context);
3886 :
3887 1 : return cmocka_run_group_tests(spdm_requester_finish_tests,
3888 : libspdm_unit_test_group_setup,
3889 : libspdm_unit_test_group_teardown);
3890 : }
3891 :
3892 : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
|