Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2025 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include "spdm_unit_test.h"
8 : #include "internal/libspdm_requester_lib.h"
9 : #include "internal/libspdm_responder_lib.h"
10 :
11 : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
12 :
13 : #define LIBSPDM_BIN_STR_2_LABEL "rsp hs data"
14 : #define LIBSPDM_BIN_STR_7_LABEL "finished"
15 :
16 : static size_t m_libspdm_local_buffer_size;
17 : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
18 : static uint8_t m_libspdm_zero_filled_buffer[LIBSPDM_MAX_HASH_SIZE];
19 :
20 : static libspdm_th_managed_buffer_t th_curr;
21 :
22 44 : size_t libspdm_test_get_psk_exchange_request_size(const void *spdm_context,
23 : const void *buffer,
24 : size_t buffer_size)
25 : {
26 : const spdm_psk_exchange_request_t *spdm_request;
27 : size_t message_size;
28 :
29 44 : spdm_request = buffer;
30 44 : message_size = sizeof(spdm_message_header_t);
31 44 : if (buffer_size < message_size) {
32 0 : return buffer_size;
33 : }
34 :
35 44 : if (spdm_request->header.request_response_code != SPDM_PSK_EXCHANGE) {
36 1 : return buffer_size;
37 : }
38 :
39 43 : message_size = sizeof(spdm_psk_exchange_request_t);
40 43 : if (buffer_size < message_size) {
41 0 : return buffer_size;
42 : }
43 :
44 43 : message_size += spdm_request->psk_hint_length +
45 43 : spdm_request->context_length +
46 43 : spdm_request->opaque_length;
47 43 : if (buffer_size < message_size) {
48 0 : return buffer_size;
49 : }
50 :
51 : /* Good message, return actual size*/
52 43 : return message_size;
53 : }
54 :
55 46 : static libspdm_return_t send_message(
56 : void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
57 : {
58 : libspdm_test_context_t *spdm_test_context;
59 : size_t header_size;
60 : size_t message_size;
61 :
62 46 : spdm_test_context = libspdm_get_test_context();
63 46 : header_size = sizeof(libspdm_test_message_header_t);
64 46 : switch (spdm_test_context->case_id) {
65 1 : case 0x1:
66 1 : return LIBSPDM_STATUS_SEND_FAIL;
67 1 : case 0x2:
68 1 : m_libspdm_local_buffer_size = 0;
69 1 : message_size = libspdm_test_get_psk_exchange_request_size(
70 : spdm_context, (const uint8_t *)request + header_size,
71 : request_size - header_size);
72 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
73 : (const uint8_t *)request + header_size, message_size);
74 1 : m_libspdm_local_buffer_size += message_size;
75 1 : return LIBSPDM_STATUS_SUCCESS;
76 0 : case 0x3:
77 0 : m_libspdm_local_buffer_size = 0;
78 0 : message_size = libspdm_test_get_psk_exchange_request_size(
79 : spdm_context, (const uint8_t *)request + header_size,
80 : request_size - header_size);
81 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
82 : (const uint8_t *)request + header_size, message_size);
83 0 : m_libspdm_local_buffer_size += message_size;
84 0 : return LIBSPDM_STATUS_SUCCESS;
85 1 : case 0x4:
86 1 : m_libspdm_local_buffer_size = 0;
87 1 : message_size = libspdm_test_get_psk_exchange_request_size(
88 : spdm_context, (const uint8_t *)request + header_size,
89 : request_size - header_size);
90 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
91 : (const uint8_t *)request + header_size, message_size);
92 1 : m_libspdm_local_buffer_size += message_size;
93 1 : return LIBSPDM_STATUS_SUCCESS;
94 1 : case 0x5:
95 1 : m_libspdm_local_buffer_size = 0;
96 1 : message_size = libspdm_test_get_psk_exchange_request_size(
97 : spdm_context, (const uint8_t *)request + header_size,
98 : request_size - header_size);
99 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
100 : (const uint8_t *)request + header_size, message_size);
101 1 : m_libspdm_local_buffer_size += message_size;
102 1 : return LIBSPDM_STATUS_SUCCESS;
103 2 : case 0x6:
104 2 : m_libspdm_local_buffer_size = 0;
105 2 : message_size = libspdm_test_get_psk_exchange_request_size(
106 : spdm_context, (const uint8_t *)request + header_size,
107 : request_size - header_size);
108 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
109 : (const uint8_t *)request + header_size, message_size);
110 2 : m_libspdm_local_buffer_size += message_size;
111 2 : return LIBSPDM_STATUS_SUCCESS;
112 1 : case 0x7:
113 1 : m_libspdm_local_buffer_size = 0;
114 1 : message_size = libspdm_test_get_psk_exchange_request_size(
115 : spdm_context, (const uint8_t *)request + header_size,
116 : request_size - header_size);
117 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
118 : (const uint8_t *)request + header_size, message_size);
119 1 : m_libspdm_local_buffer_size += message_size;
120 1 : return LIBSPDM_STATUS_SUCCESS;
121 2 : case 0x8:
122 2 : m_libspdm_local_buffer_size = 0;
123 2 : message_size = libspdm_test_get_psk_exchange_request_size(
124 : spdm_context, (const uint8_t *)request + header_size,
125 : request_size - header_size);
126 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
127 : (const uint8_t *)request + header_size, message_size);
128 2 : m_libspdm_local_buffer_size += message_size;
129 2 : return LIBSPDM_STATUS_SUCCESS;
130 2 : case 0x9: {
131 : static size_t sub_index = 0;
132 2 : if (sub_index == 0) {
133 1 : m_libspdm_local_buffer_size = 0;
134 1 : message_size = libspdm_test_get_psk_exchange_request_size(
135 : spdm_context, (const uint8_t *)request + header_size,
136 : request_size - header_size);
137 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
138 : (const uint8_t *)request + header_size, message_size);
139 1 : m_libspdm_local_buffer_size += message_size;
140 1 : sub_index++;
141 : }
142 : }
143 2 : return LIBSPDM_STATUS_SUCCESS;
144 18 : case 0xA:
145 18 : m_libspdm_local_buffer_size = 0;
146 18 : message_size = libspdm_test_get_psk_exchange_request_size(
147 : spdm_context, (const uint8_t *)request + header_size,
148 : request_size - header_size);
149 18 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
150 : (const uint8_t *)request + header_size, message_size);
151 18 : m_libspdm_local_buffer_size += message_size;
152 18 : return LIBSPDM_STATUS_SUCCESS;
153 1 : case 0xB:
154 1 : m_libspdm_local_buffer_size = 0;
155 1 : message_size = libspdm_test_get_psk_exchange_request_size(
156 : spdm_context, (const uint8_t *)request + header_size,
157 : request_size - header_size);
158 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
159 : (const uint8_t *)request + header_size, message_size);
160 1 : m_libspdm_local_buffer_size += message_size;
161 1 : return LIBSPDM_STATUS_SUCCESS;
162 1 : case 0xC:
163 1 : m_libspdm_local_buffer_size = 0;
164 1 : message_size = libspdm_test_get_psk_exchange_request_size(
165 : spdm_context, (const uint8_t *)request + header_size, request_size - header_size);
166 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
167 : (const uint8_t *)request + header_size, message_size);
168 1 : m_libspdm_local_buffer_size += message_size;
169 1 : return LIBSPDM_STATUS_SUCCESS;
170 1 : case 0xD:
171 1 : m_libspdm_local_buffer_size = 0;
172 1 : message_size = libspdm_test_get_psk_exchange_request_size(
173 : spdm_context, (const uint8_t *)request + header_size,
174 : request_size - header_size);
175 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
176 : (const uint8_t *)request + header_size, message_size);
177 1 : m_libspdm_local_buffer_size += message_size;
178 1 : return LIBSPDM_STATUS_SUCCESS;
179 1 : case 0xE:
180 1 : m_libspdm_local_buffer_size = 0;
181 1 : message_size = libspdm_test_get_psk_exchange_request_size(
182 : spdm_context, (const uint8_t *)request + header_size,
183 : request_size - header_size);
184 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
185 : (const uint8_t *)request + header_size, message_size);
186 1 : m_libspdm_local_buffer_size += message_size;
187 1 : return LIBSPDM_STATUS_SUCCESS;
188 1 : case 0xF:
189 1 : m_libspdm_local_buffer_size = 0;
190 1 : message_size = libspdm_test_get_psk_exchange_request_size(
191 : spdm_context, (const uint8_t *)request + header_size,
192 : request_size - header_size);
193 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
194 : (const uint8_t *)request + header_size, message_size);
195 1 : m_libspdm_local_buffer_size += message_size;
196 1 : return LIBSPDM_STATUS_SUCCESS;
197 1 : case 0x10:
198 1 : m_libspdm_local_buffer_size = 0;
199 1 : message_size = libspdm_test_get_psk_exchange_request_size(
200 : spdm_context, (const uint8_t *)request + header_size,
201 : request_size - header_size);
202 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
203 : (const uint8_t *)request + header_size, message_size);
204 1 : m_libspdm_local_buffer_size += message_size;
205 1 : return LIBSPDM_STATUS_SUCCESS;
206 1 : case 0x11:
207 1 : m_libspdm_local_buffer_size = 0;
208 1 : message_size = libspdm_test_get_psk_exchange_request_size(
209 : spdm_context, (const uint8_t *)request + header_size,
210 : request_size - header_size);
211 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
212 : (const uint8_t *)request + header_size, message_size);
213 1 : m_libspdm_local_buffer_size += message_size;
214 1 : return LIBSPDM_STATUS_SUCCESS;
215 1 : case 0x12:
216 1 : m_libspdm_local_buffer_size = 0;
217 1 : message_size = libspdm_test_get_psk_exchange_request_size(
218 : spdm_context, (const uint8_t *)request + header_size,
219 : request_size - header_size);
220 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
221 : (const uint8_t *)request + header_size, message_size);
222 1 : m_libspdm_local_buffer_size += message_size;
223 1 : return LIBSPDM_STATUS_SUCCESS;
224 1 : case 0x13:
225 1 : m_libspdm_local_buffer_size = 0;
226 1 : message_size = libspdm_test_get_psk_exchange_request_size(
227 : spdm_context, (const uint8_t *)request + header_size,
228 : request_size - header_size);
229 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
230 : (const uint8_t *)request + header_size, message_size);
231 1 : m_libspdm_local_buffer_size += message_size;
232 1 : return LIBSPDM_STATUS_SUCCESS;
233 1 : case 0x14:
234 1 : m_libspdm_local_buffer_size = 0;
235 1 : message_size = libspdm_test_get_psk_exchange_request_size(
236 : spdm_context, (const uint8_t *)request + header_size,
237 : request_size - header_size);
238 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
239 : (const uint8_t *)request + header_size, message_size);
240 1 : m_libspdm_local_buffer_size += message_size;
241 1 : return LIBSPDM_STATUS_SUCCESS;
242 1 : case 0x15:
243 1 : m_libspdm_local_buffer_size = 0;
244 1 : message_size = libspdm_test_get_psk_exchange_request_size(
245 : spdm_context, (const uint8_t *)request + header_size,
246 : request_size - header_size);
247 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
248 : (const uint8_t *)request + header_size, message_size);
249 1 : m_libspdm_local_buffer_size += message_size;
250 1 : return LIBSPDM_STATUS_SUCCESS;
251 1 : case 0x16:
252 1 : m_libspdm_local_buffer_size = 0;
253 1 : message_size = libspdm_test_get_psk_exchange_request_size(
254 : spdm_context, (const uint8_t *)request + header_size,
255 : request_size - header_size);
256 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
257 : (const uint8_t *)request + header_size, message_size);
258 1 : m_libspdm_local_buffer_size += message_size;
259 1 : return LIBSPDM_STATUS_SUCCESS;
260 1 : case 0x17:
261 1 : m_libspdm_local_buffer_size = 0;
262 1 : message_size = libspdm_test_get_psk_exchange_request_size(
263 : spdm_context, (const uint8_t *)request + header_size,
264 : request_size - header_size);
265 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
266 : (const uint8_t *)request + header_size, message_size);
267 1 : m_libspdm_local_buffer_size += message_size;
268 1 : return LIBSPDM_STATUS_SUCCESS;
269 1 : case 0x18:
270 1 : m_libspdm_local_buffer_size = 0;
271 1 : message_size = libspdm_test_get_psk_exchange_request_size(
272 : spdm_context, (const uint8_t *)request + header_size,
273 : request_size - header_size);
274 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
275 : (const uint8_t *)request + header_size, message_size);
276 1 : m_libspdm_local_buffer_size += message_size;
277 1 : return LIBSPDM_STATUS_SUCCESS;
278 1 : case 0x19:
279 1 : m_libspdm_local_buffer_size = 0;
280 1 : message_size = libspdm_test_get_psk_exchange_request_size(
281 : spdm_context, (const uint8_t *)request + header_size,
282 : request_size - header_size);
283 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
284 : (const uint8_t *)request + header_size, message_size);
285 1 : m_libspdm_local_buffer_size += message_size;
286 1 : return LIBSPDM_STATUS_SUCCESS;
287 1 : case 0x1A:
288 1 : m_libspdm_local_buffer_size = 0;
289 1 : message_size = libspdm_test_get_psk_exchange_request_size(
290 : spdm_context, (const uint8_t *)request + header_size,
291 : request_size - header_size);
292 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
293 : (const uint8_t *)request + header_size, message_size);
294 1 : m_libspdm_local_buffer_size += message_size;
295 1 : return LIBSPDM_STATUS_SUCCESS;
296 1 : case 0x1B:
297 1 : m_libspdm_local_buffer_size = 0;
298 1 : message_size = libspdm_test_get_psk_exchange_request_size(
299 : spdm_context, (const uint8_t *)request + header_size,
300 : request_size - header_size);
301 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
302 : (const uint8_t *)request + header_size, message_size);
303 1 : m_libspdm_local_buffer_size += message_size;
304 1 : return LIBSPDM_STATUS_SUCCESS;
305 0 : default:
306 0 : return LIBSPDM_STATUS_SEND_FAIL;
307 : }
308 : }
309 :
310 45 : static libspdm_return_t receive_message(
311 : void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
312 : {
313 : libspdm_test_context_t *spdm_test_context;
314 :
315 45 : spdm_test_context = libspdm_get_test_context();
316 45 : switch (spdm_test_context->case_id) {
317 0 : case 0x1:
318 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
319 :
320 1 : case 0x2: {
321 : spdm_psk_exchange_response_t *spdm_response;
322 : uint32_t hash_size;
323 : uint32_t hmac_size;
324 : uint8_t *ptr;
325 : size_t opaque_psk_exchange_rsp_size;
326 : void *data;
327 : size_t data_size;
328 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
329 : uint8_t *cert_buffer;
330 : size_t cert_buffer_size;
331 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
332 : uint8_t bin_str2[128];
333 : size_t bin_str2_size;
334 : uint8_t bin_str7[128];
335 : size_t bin_str7_size;
336 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
337 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
338 : size_t spdm_response_size;
339 : size_t transport_header_size;
340 :
341 :
342 : ((libspdm_context_t *)spdm_context)
343 1 : ->connection_info.algorithm.base_asym_algo =
344 : m_libspdm_use_asym_algo;
345 : ((libspdm_context_t *)spdm_context)
346 1 : ->connection_info.algorithm.base_hash_algo =
347 : m_libspdm_use_hash_algo;
348 : ((libspdm_context_t *)spdm_context)
349 1 : ->connection_info.algorithm.dhe_named_group =
350 : m_libspdm_use_dhe_algo;
351 : ((libspdm_context_t *)spdm_context)
352 1 : ->connection_info.algorithm.measurement_hash_algo =
353 : m_libspdm_use_measurement_hash_algo;
354 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
355 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
356 1 : opaque_psk_exchange_rsp_size =
357 1 : libspdm_get_opaque_data_version_selection_data_size(
358 : spdm_context);
359 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
360 : LIBSPDM_PSK_CONTEXT_LENGTH +
361 1 : opaque_psk_exchange_rsp_size + hmac_size;
362 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
363 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
364 :
365 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
366 1 : spdm_response->header.request_response_code =
367 : SPDM_PSK_EXCHANGE_RSP;
368 1 : spdm_response->header.param1 = 0;
369 1 : spdm_response->header.param2 = 0;
370 1 : spdm_response->rsp_session_id =
371 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
372 1 : spdm_response->reserved = 0;
373 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
374 1 : spdm_response->opaque_length =
375 1 : (uint16_t)opaque_psk_exchange_rsp_size;
376 1 : ptr = (void *)(spdm_response + 1);
377 : /* libspdm_zero_mem (ptr, hash_size);
378 : * ptr += hash_size;*/
379 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
380 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
381 1 : libspdm_build_opaque_data_version_selection_data(
382 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
383 : &opaque_psk_exchange_rsp_size, ptr);
384 1 : ptr += opaque_psk_exchange_rsp_size;
385 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
386 : sizeof(m_libspdm_local_buffer)
387 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
388 : m_libspdm_local_buffer),
389 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
390 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
391 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
392 : m_libspdm_local_buffer_size));
393 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
394 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
395 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
396 : m_libspdm_use_asym_algo, &data,
397 : &data_size, NULL, NULL);
398 1 : cert_buffer =
399 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
400 1 : cert_buffer_size =
401 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
402 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
403 : cert_buffer_hash);
404 : /* transcript.message_a size is 0*/
405 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
406 : m_libspdm_local_buffer_size);
407 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
408 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
409 1 : free(data);
410 1 : bin_str2_size = sizeof(bin_str2);
411 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
412 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
413 1 : hash_data, (uint16_t)hash_size, hash_size,
414 : bin_str2, &bin_str2_size);
415 1 : libspdm_psk_handshake_secret_hkdf_expand(
416 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
417 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
418 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
419 : bin_str2_size,
420 : response_handshake_secret, hash_size);
421 1 : bin_str7_size = sizeof(bin_str7);
422 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
423 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
424 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
425 : &bin_str7_size);
426 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
427 : hash_size, bin_str7, bin_str7_size,
428 : response_finished_key, hash_size);
429 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
430 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
431 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
432 : response_finished_key, hash_size, ptr);
433 1 : ptr += hmac_size;
434 :
435 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
436 : false, spdm_response_size,
437 : spdm_response, response_size,
438 : response);
439 : }
440 1 : return LIBSPDM_STATUS_SUCCESS;
441 :
442 0 : case 0x3: {
443 : spdm_psk_exchange_response_t *spdm_response;
444 : uint32_t hash_size;
445 : uint32_t hmac_size;
446 : uint8_t *ptr;
447 : size_t opaque_psk_exchange_rsp_size;
448 : void *data;
449 : size_t data_size;
450 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
451 : uint8_t *cert_buffer;
452 : size_t cert_buffer_size;
453 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
454 : uint8_t bin_str2[128];
455 : size_t bin_str2_size;
456 : uint8_t bin_str7[128];
457 : size_t bin_str7_size;
458 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
459 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
460 : size_t spdm_response_size;
461 : size_t transport_header_size;
462 :
463 : ((libspdm_context_t *)spdm_context)
464 0 : ->connection_info.algorithm.base_asym_algo =
465 : m_libspdm_use_asym_algo;
466 : ((libspdm_context_t *)spdm_context)
467 0 : ->connection_info.algorithm.base_hash_algo =
468 : m_libspdm_use_hash_algo;
469 : ((libspdm_context_t *)spdm_context)
470 0 : ->connection_info.algorithm.dhe_named_group =
471 : m_libspdm_use_dhe_algo;
472 : ((libspdm_context_t *)spdm_context)
473 0 : ->connection_info.algorithm.measurement_hash_algo =
474 : m_libspdm_use_measurement_hash_algo;
475 0 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
476 0 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
477 0 : opaque_psk_exchange_rsp_size =
478 0 : libspdm_get_opaque_data_version_selection_data_size(
479 : spdm_context);
480 0 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
481 : LIBSPDM_PSK_CONTEXT_LENGTH +
482 0 : opaque_psk_exchange_rsp_size + hmac_size;
483 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
484 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
485 :
486 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
487 0 : spdm_response->header.request_response_code =
488 : SPDM_PSK_EXCHANGE_RSP;
489 0 : spdm_response->header.param1 = 0;
490 0 : spdm_response->header.param2 = 0;
491 0 : spdm_response->rsp_session_id =
492 0 : libspdm_allocate_rsp_session_id(spdm_context, true);
493 0 : spdm_response->reserved = 0;
494 0 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
495 0 : spdm_response->opaque_length =
496 0 : (uint16_t)opaque_psk_exchange_rsp_size;
497 0 : ptr = (void *)(spdm_response + 1);
498 : /* libspdm_zero_mem (ptr, hash_size);
499 : * ptr += hash_size;*/
500 0 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
501 0 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
502 0 : libspdm_build_opaque_data_version_selection_data(
503 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
504 : &opaque_psk_exchange_rsp_size, ptr);
505 0 : ptr += opaque_psk_exchange_rsp_size;
506 0 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
507 : sizeof(m_libspdm_local_buffer)
508 0 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
509 : m_libspdm_local_buffer),
510 0 : spdm_response, (size_t)ptr - (size_t)spdm_response);
511 0 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
512 0 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
513 : m_libspdm_local_buffer_size));
514 0 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
515 0 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
516 0 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
517 : m_libspdm_use_asym_algo, &data,
518 : &data_size, NULL, NULL);
519 0 : cert_buffer =
520 0 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
521 0 : cert_buffer_size =
522 0 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
523 0 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
524 : cert_buffer_hash);
525 : /* transcript.message_a size is 0*/
526 0 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
527 : m_libspdm_local_buffer_size);
528 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
529 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
530 0 : free(data);
531 0 : bin_str2_size = sizeof(bin_str2);
532 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
533 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
534 0 : hash_data, (uint16_t)hash_size, hash_size,
535 : bin_str2, &bin_str2_size);
536 0 : libspdm_psk_handshake_secret_hkdf_expand(
537 0 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
538 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
539 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
540 : bin_str2_size,
541 : response_handshake_secret, hash_size);
542 0 : bin_str7_size = sizeof(bin_str7);
543 0 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
544 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
545 0 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
546 : &bin_str7_size);
547 0 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
548 : hash_size, bin_str7, bin_str7_size,
549 : response_finished_key, hash_size);
550 0 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
551 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
552 0 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
553 : response_finished_key, hash_size, ptr);
554 0 : ptr += hmac_size;
555 :
556 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
557 : false, spdm_response_size,
558 : spdm_response, response_size,
559 : response);
560 : }
561 0 : return LIBSPDM_STATUS_SUCCESS;
562 :
563 1 : case 0x4: {
564 : spdm_error_response_t *spdm_response;
565 : size_t spdm_response_size;
566 : size_t transport_header_size;
567 :
568 1 : spdm_response_size = sizeof(spdm_error_response_t);
569 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
570 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
571 :
572 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
573 1 : spdm_response->header.request_response_code = SPDM_ERROR;
574 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
575 1 : spdm_response->header.param2 = 0;
576 :
577 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
578 : false, spdm_response_size,
579 : spdm_response,
580 : response_size, response);
581 : }
582 1 : return LIBSPDM_STATUS_SUCCESS;
583 :
584 1 : case 0x5: {
585 : spdm_error_response_t *spdm_response;
586 : size_t spdm_response_size;
587 : size_t transport_header_size;
588 :
589 1 : spdm_response_size = sizeof(spdm_error_response_t);
590 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
591 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
592 :
593 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
594 1 : spdm_response->header.request_response_code = SPDM_ERROR;
595 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
596 1 : spdm_response->header.param2 = 0;
597 :
598 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
599 : false, spdm_response_size,
600 : spdm_response,
601 : response_size, response);
602 : }
603 1 : return LIBSPDM_STATUS_SUCCESS;
604 :
605 2 : case 0x6: {
606 : static size_t sub_index1 = 0;
607 2 : if (sub_index1 == 0) {
608 : spdm_error_response_t *spdm_response;
609 : size_t spdm_response_size;
610 : size_t transport_header_size;
611 :
612 1 : spdm_response_size = sizeof(spdm_error_response_t);
613 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
614 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
615 :
616 1 : spdm_response->header.spdm_version =
617 : SPDM_MESSAGE_VERSION_11;
618 1 : spdm_response->header.request_response_code = SPDM_ERROR;
619 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
620 1 : spdm_response->header.param2 = 0;
621 :
622 1 : libspdm_transport_test_encode_message(
623 : spdm_context, NULL, false, false,
624 : spdm_response_size, spdm_response,
625 : response_size, response);
626 1 : sub_index1++;
627 1 : } else if (sub_index1 == 1) {
628 : spdm_psk_exchange_response_t *spdm_response;
629 : uint32_t hash_size;
630 : uint32_t hmac_size;
631 : uint8_t *ptr;
632 : size_t opaque_psk_exchange_rsp_size;
633 : void *data;
634 : size_t data_size;
635 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
636 : uint8_t *cert_buffer;
637 : size_t cert_buffer_size;
638 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
639 : uint8_t bin_str2[128];
640 : size_t bin_str2_size;
641 : uint8_t bin_str7[128];
642 : size_t bin_str7_size;
643 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
644 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
645 : size_t spdm_response_size;
646 : size_t transport_header_size;
647 :
648 : ((libspdm_context_t *)spdm_context)
649 1 : ->connection_info.algorithm.base_asym_algo =
650 : m_libspdm_use_asym_algo;
651 : ((libspdm_context_t *)spdm_context)
652 1 : ->connection_info.algorithm.base_hash_algo =
653 : m_libspdm_use_hash_algo;
654 : ((libspdm_context_t *)spdm_context)
655 1 : ->connection_info.algorithm.dhe_named_group =
656 : m_libspdm_use_dhe_algo;
657 : ((libspdm_context_t *)spdm_context)
658 : ->connection_info.algorithm
659 1 : .measurement_hash_algo =
660 : m_libspdm_use_measurement_hash_algo;
661 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
662 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
663 1 : opaque_psk_exchange_rsp_size =
664 1 : libspdm_get_opaque_data_version_selection_data_size(
665 : spdm_context);
666 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
667 : 0 + LIBSPDM_PSK_CONTEXT_LENGTH +
668 1 : opaque_psk_exchange_rsp_size +
669 : hmac_size;
670 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
671 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
672 :
673 1 : spdm_response->header.spdm_version =
674 : SPDM_MESSAGE_VERSION_11;
675 1 : spdm_response->header.request_response_code =
676 : SPDM_PSK_EXCHANGE_RSP;
677 1 : spdm_response->header.param1 = 0;
678 1 : spdm_response->header.param2 = 0;
679 1 : spdm_response->rsp_session_id =
680 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
681 1 : spdm_response->reserved = 0;
682 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
683 1 : spdm_response->opaque_length =
684 1 : (uint16_t)opaque_psk_exchange_rsp_size;
685 1 : ptr = (void *)(spdm_response + 1);
686 : /* libspdm_zero_mem (ptr, hash_size);
687 : * ptr += hash_size;*/
688 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
689 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
690 1 : libspdm_build_opaque_data_version_selection_data(
691 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
692 : &opaque_psk_exchange_rsp_size, ptr);
693 1 : ptr += opaque_psk_exchange_rsp_size;
694 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
695 : sizeof(m_libspdm_local_buffer)
696 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
697 : m_libspdm_local_buffer),
698 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
699 1 : m_libspdm_local_buffer_size +=
700 1 : ((size_t)ptr - (size_t)spdm_response);
701 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
702 : m_libspdm_local_buffer_size));
703 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
704 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
705 1 : libspdm_read_responder_public_certificate_chain(
706 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
707 : &data_size, NULL, NULL);
708 1 : cert_buffer = (uint8_t *)data +
709 1 : sizeof(spdm_cert_chain_t) + hash_size;
710 1 : cert_buffer_size =
711 1 : data_size -
712 : (sizeof(spdm_cert_chain_t) + hash_size);
713 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
714 : cert_buffer_size, cert_buffer_hash);
715 : /* transcript.message_a size is 0*/
716 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
717 : m_libspdm_local_buffer_size);
718 2 : libspdm_hash_all(m_libspdm_use_hash_algo,
719 1 : libspdm_get_managed_buffer(&th_curr),
720 : libspdm_get_managed_buffer_size(&th_curr),
721 : hash_data);
722 1 : free(data);
723 1 : bin_str2_size = sizeof(bin_str2);
724 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
725 : LIBSPDM_BIN_STR_2_LABEL,
726 : sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1, hash_data,
727 1 : (uint16_t)hash_size, hash_size, bin_str2,
728 : &bin_str2_size);
729 1 : libspdm_psk_handshake_secret_hkdf_expand(
730 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
731 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
732 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
733 : bin_str2_size, response_handshake_secret,
734 : hash_size);
735 1 : bin_str7_size = sizeof(bin_str7);
736 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
737 : LIBSPDM_BIN_STR_7_LABEL,
738 : sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1, NULL,
739 1 : (uint16_t)hash_size, hash_size, bin_str7,
740 : &bin_str7_size);
741 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo,
742 : response_handshake_secret, hash_size,
743 : bin_str7, bin_str7_size,
744 : response_finished_key, hash_size);
745 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
746 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
747 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
748 : response_finished_key, hash_size, ptr);
749 1 : ptr += hmac_size;
750 :
751 1 : libspdm_transport_test_encode_message(
752 : spdm_context, NULL, false, false, spdm_response_size,
753 : spdm_response, response_size, response);
754 : }
755 : }
756 2 : return LIBSPDM_STATUS_SUCCESS;
757 :
758 1 : case 0x7: {
759 : spdm_error_response_t *spdm_response;
760 : size_t spdm_response_size;
761 : size_t transport_header_size;
762 :
763 1 : spdm_response_size = sizeof(spdm_error_response_t);
764 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
765 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
766 :
767 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
768 1 : spdm_response->header.request_response_code = SPDM_ERROR;
769 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
770 1 : spdm_response->header.param2 = 0;
771 :
772 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
773 : false, spdm_response_size,
774 : spdm_response,
775 : response_size, response);
776 : }
777 1 : return LIBSPDM_STATUS_SUCCESS;
778 :
779 2 : case 0x8: {
780 : spdm_error_response_data_response_not_ready_t *spdm_response;
781 : size_t spdm_response_size;
782 : size_t transport_header_size;
783 :
784 2 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
785 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
786 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
787 :
788 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
789 2 : spdm_response->header.request_response_code = SPDM_ERROR;
790 2 : spdm_response->header.param1 =
791 : SPDM_ERROR_CODE_RESPONSE_NOT_READY;
792 2 : spdm_response->header.param2 = 0;
793 2 : spdm_response->extend_error_data.rd_exponent = 1;
794 2 : spdm_response->extend_error_data.rd_tm = 2;
795 2 : spdm_response->extend_error_data.request_code =
796 : SPDM_PSK_EXCHANGE;
797 2 : spdm_response->extend_error_data.token = 0;
798 :
799 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
800 : false, spdm_response_size,
801 : spdm_response,
802 : response_size, response);
803 : }
804 2 : return LIBSPDM_STATUS_SUCCESS;
805 :
806 2 : case 0x9: {
807 : static size_t sub_index2 = 0;
808 2 : if (sub_index2 == 0) {
809 : spdm_error_response_data_response_not_ready_t
810 : *spdm_response;
811 : size_t spdm_response_size;
812 : size_t transport_header_size;
813 :
814 1 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
815 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
816 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
817 :
818 1 : spdm_response->header.spdm_version =
819 : SPDM_MESSAGE_VERSION_11;
820 1 : spdm_response->header.request_response_code = SPDM_ERROR;
821 1 : spdm_response->header.param1 =
822 : SPDM_ERROR_CODE_RESPONSE_NOT_READY;
823 1 : spdm_response->header.param2 = 0;
824 1 : spdm_response->extend_error_data.rd_exponent = 1;
825 1 : spdm_response->extend_error_data.rd_tm = 2;
826 1 : spdm_response->extend_error_data.request_code =
827 : SPDM_PSK_EXCHANGE;
828 1 : spdm_response->extend_error_data.token = 1;
829 :
830 1 : libspdm_transport_test_encode_message(
831 : spdm_context, NULL, false, false,
832 : spdm_response_size, spdm_response,
833 : response_size, response);
834 1 : sub_index2++;
835 1 : } else if (sub_index2 == 1) {
836 : spdm_psk_exchange_response_t *spdm_response;
837 : uint32_t hash_size;
838 : uint32_t hmac_size;
839 : uint8_t *ptr;
840 : size_t opaque_psk_exchange_rsp_size;
841 : void *data;
842 : size_t data_size;
843 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
844 : uint8_t *cert_buffer;
845 : size_t cert_buffer_size;
846 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
847 : uint8_t bin_str2[128];
848 : size_t bin_str2_size;
849 : uint8_t bin_str7[128];
850 : size_t bin_str7_size;
851 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
852 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
853 : size_t spdm_response_size;
854 : size_t transport_header_size;
855 :
856 : ((libspdm_context_t *)spdm_context)
857 1 : ->connection_info.algorithm.base_asym_algo =
858 : m_libspdm_use_asym_algo;
859 : ((libspdm_context_t *)spdm_context)
860 1 : ->connection_info.algorithm.base_hash_algo =
861 : m_libspdm_use_hash_algo;
862 : ((libspdm_context_t *)spdm_context)
863 1 : ->connection_info.algorithm.dhe_named_group =
864 : m_libspdm_use_dhe_algo;
865 : ((libspdm_context_t *)spdm_context)
866 : ->connection_info.algorithm
867 1 : .measurement_hash_algo =
868 : m_libspdm_use_measurement_hash_algo;
869 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
870 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
871 1 : opaque_psk_exchange_rsp_size =
872 1 : libspdm_get_opaque_data_version_selection_data_size(
873 : spdm_context);
874 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
875 : 0 + LIBSPDM_PSK_CONTEXT_LENGTH +
876 1 : opaque_psk_exchange_rsp_size +
877 : hmac_size;
878 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
879 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
880 :
881 1 : spdm_response->header.spdm_version =
882 : SPDM_MESSAGE_VERSION_11;
883 1 : spdm_response->header.request_response_code =
884 : SPDM_PSK_EXCHANGE_RSP;
885 1 : spdm_response->header.param1 = 0;
886 1 : spdm_response->header.param2 = 0;
887 1 : spdm_response->rsp_session_id =
888 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
889 1 : spdm_response->reserved = 0;
890 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
891 1 : spdm_response->opaque_length =
892 1 : (uint16_t)opaque_psk_exchange_rsp_size;
893 1 : ptr = (void *)(spdm_response + 1);
894 : /* libspdm_zero_mem (ptr, hash_size);
895 : * ptr += hash_size;*/
896 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
897 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
898 1 : libspdm_build_opaque_data_version_selection_data(
899 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
900 : &opaque_psk_exchange_rsp_size, ptr);
901 1 : ptr += opaque_psk_exchange_rsp_size;
902 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
903 : sizeof(m_libspdm_local_buffer)
904 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
905 : m_libspdm_local_buffer),
906 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
907 1 : m_libspdm_local_buffer_size +=
908 1 : ((size_t)ptr - (size_t)spdm_response);
909 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
910 : m_libspdm_local_buffer_size));
911 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
912 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
913 1 : libspdm_read_responder_public_certificate_chain(
914 : m_libspdm_use_hash_algo, m_libspdm_use_asym_algo, &data,
915 : &data_size, NULL, NULL);
916 1 : cert_buffer = (uint8_t *)data +
917 1 : sizeof(spdm_cert_chain_t) + hash_size;
918 1 : cert_buffer_size =
919 1 : data_size -
920 : (sizeof(spdm_cert_chain_t) + hash_size);
921 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer,
922 : cert_buffer_size, cert_buffer_hash);
923 : /* transcript.message_a size is 0*/
924 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
925 : m_libspdm_local_buffer_size);
926 2 : libspdm_hash_all(m_libspdm_use_hash_algo,
927 1 : libspdm_get_managed_buffer(&th_curr),
928 : libspdm_get_managed_buffer_size(&th_curr),
929 : hash_data);
930 1 : free(data);
931 1 : bin_str2_size = sizeof(bin_str2);
932 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
933 : LIBSPDM_BIN_STR_2_LABEL,
934 : sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1, hash_data,
935 1 : (uint16_t)hash_size, hash_size, bin_str2,
936 : &bin_str2_size);
937 1 : libspdm_psk_handshake_secret_hkdf_expand(
938 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
939 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
940 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
941 : bin_str2_size, response_handshake_secret,
942 : hash_size);
943 1 : bin_str7_size = sizeof(bin_str7);
944 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
945 : LIBSPDM_BIN_STR_7_LABEL,
946 : sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1, NULL,
947 1 : (uint16_t)hash_size, hash_size, bin_str7,
948 : &bin_str7_size);
949 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo,
950 : response_handshake_secret, hash_size,
951 : bin_str7, bin_str7_size,
952 : response_finished_key, hash_size);
953 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
954 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
955 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
956 : response_finished_key, hash_size, ptr);
957 1 : ptr += hmac_size;
958 :
959 1 : libspdm_transport_test_encode_message(
960 : spdm_context, NULL, false, false, spdm_response_size,
961 : spdm_response, response_size, response);
962 : }
963 : }
964 2 : return LIBSPDM_STATUS_SUCCESS;
965 :
966 18 : case 0xA:
967 : {
968 : static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
969 :
970 : spdm_error_response_t *spdm_response;
971 : size_t spdm_response_size;
972 : size_t transport_header_size;
973 :
974 18 : spdm_response_size = sizeof(spdm_error_response_t);
975 18 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
976 18 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
977 :
978 18 : if(error_code <= 0xff) {
979 18 : libspdm_zero_mem (spdm_response, spdm_response_size);
980 18 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
981 18 : spdm_response->header.request_response_code = SPDM_ERROR;
982 18 : spdm_response->header.param1 = (uint8_t) error_code;
983 18 : spdm_response->header.param2 = 0;
984 :
985 18 : libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
986 : spdm_response_size, spdm_response,
987 : response_size, response);
988 : }
989 :
990 18 : error_code++;
991 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
992 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
993 : }
994 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
995 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
996 : }
997 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
998 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
999 : }
1000 : }
1001 18 : return LIBSPDM_STATUS_SUCCESS;
1002 :
1003 1 : case 0xB: {
1004 : spdm_psk_exchange_response_t *spdm_response;
1005 : uint32_t hash_size;
1006 : uint32_t hmac_size;
1007 : uint8_t *ptr;
1008 : size_t opaque_psk_exchange_rsp_size;
1009 : void *data;
1010 : size_t data_size;
1011 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1012 : uint8_t *cert_buffer;
1013 : size_t cert_buffer_size;
1014 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1015 : uint8_t bin_str2[128];
1016 : size_t bin_str2_size;
1017 : uint8_t bin_str7[128];
1018 : size_t bin_str7_size;
1019 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1020 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1021 : size_t spdm_response_size;
1022 : size_t transport_header_size;
1023 :
1024 : ((libspdm_context_t *)spdm_context)
1025 1 : ->connection_info.algorithm.base_asym_algo =
1026 : m_libspdm_use_asym_algo;
1027 : ((libspdm_context_t *)spdm_context)
1028 1 : ->connection_info.algorithm.base_hash_algo =
1029 : m_libspdm_use_hash_algo;
1030 : ((libspdm_context_t *)spdm_context)
1031 1 : ->connection_info.algorithm.dhe_named_group =
1032 : m_libspdm_use_dhe_algo;
1033 : ((libspdm_context_t *)spdm_context)
1034 1 : ->connection_info.algorithm.measurement_hash_algo =
1035 : m_libspdm_use_measurement_hash_algo;
1036 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1037 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1038 1 : opaque_psk_exchange_rsp_size =
1039 1 : libspdm_get_opaque_data_version_selection_data_size(
1040 : spdm_context);
1041 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
1042 : LIBSPDM_PSK_CONTEXT_LENGTH +
1043 1 : opaque_psk_exchange_rsp_size + hmac_size;
1044 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1045 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1046 :
1047 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1048 1 : spdm_response->header.request_response_code =
1049 : SPDM_PSK_EXCHANGE_RSP;
1050 1 : spdm_response->header.param1 = 0;
1051 1 : spdm_response->header.param2 = 0;
1052 1 : spdm_response->rsp_session_id =
1053 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
1054 1 : spdm_response->reserved = 0;
1055 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
1056 1 : spdm_response->opaque_length =
1057 1 : (uint16_t)opaque_psk_exchange_rsp_size;
1058 1 : ptr = (void *)(spdm_response + 1);
1059 : /* libspdm_zero_mem (ptr, hash_size);
1060 : * ptr += hash_size;*/
1061 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
1062 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
1063 1 : libspdm_build_opaque_data_version_selection_data(
1064 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1065 : &opaque_psk_exchange_rsp_size, ptr);
1066 1 : ptr += opaque_psk_exchange_rsp_size;
1067 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1068 : sizeof(m_libspdm_local_buffer)
1069 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1070 : m_libspdm_local_buffer),
1071 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1072 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1073 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1074 : m_libspdm_local_buffer_size));
1075 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1076 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1077 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1078 : m_libspdm_use_asym_algo, &data,
1079 : &data_size, NULL, NULL);
1080 1 : cert_buffer =
1081 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
1082 1 : cert_buffer_size =
1083 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
1084 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1085 : cert_buffer_hash);
1086 : /* transcript.message_a size is 0*/
1087 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1088 : m_libspdm_local_buffer_size);
1089 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1090 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1091 1 : free(data);
1092 1 : bin_str2_size = sizeof(bin_str2);
1093 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1094 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
1095 1 : hash_data, (uint16_t)hash_size, hash_size,
1096 : bin_str2, &bin_str2_size);
1097 1 : libspdm_psk_handshake_secret_hkdf_expand(
1098 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1099 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
1100 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
1101 : bin_str2_size,
1102 : response_handshake_secret, hash_size);
1103 1 : bin_str7_size = sizeof(bin_str7);
1104 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1105 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
1106 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1107 : &bin_str7_size);
1108 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1109 : hash_size, bin_str7, bin_str7_size,
1110 : response_finished_key, hash_size);
1111 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1112 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1113 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1114 : response_finished_key, hash_size, ptr);
1115 1 : ptr += hmac_size;
1116 :
1117 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1118 : false, spdm_response_size,
1119 : spdm_response, response_size,
1120 : response);
1121 : }
1122 1 : return LIBSPDM_STATUS_SUCCESS;
1123 :
1124 1 : case 0xC: {
1125 : spdm_psk_exchange_response_t *spdm_response;
1126 : uint32_t hash_size;
1127 : uint32_t hmac_size;
1128 : uint8_t *ptr;
1129 : size_t opaque_psk_exchange_rsp_size;
1130 : void *data;
1131 : size_t data_size;
1132 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1133 : uint8_t *cert_buffer;
1134 : size_t cert_buffer_size;
1135 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1136 : uint8_t bin_str2[128];
1137 : size_t bin_str2_size;
1138 : uint8_t bin_str7[128];
1139 : size_t bin_str7_size;
1140 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1141 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1142 : size_t spdm_response_size;
1143 : size_t transport_header_size;
1144 :
1145 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_asym_algo =
1146 : m_libspdm_use_asym_algo;
1147 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.base_hash_algo =
1148 : m_libspdm_use_hash_algo;
1149 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.dhe_named_group =
1150 : m_libspdm_use_dhe_algo;
1151 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
1152 : m_libspdm_use_measurement_hash_algo;
1153 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1154 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1155 1 : opaque_psk_exchange_rsp_size =
1156 1 : libspdm_get_opaque_data_version_selection_data_size(spdm_context);
1157 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
1158 : LIBSPDM_PSK_CONTEXT_LENGTH +
1159 1 : opaque_psk_exchange_rsp_size + hmac_size;
1160 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1161 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1162 :
1163 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1164 1 : spdm_response->header.request_response_code = SPDM_PSK_EXCHANGE_RSP;
1165 1 : spdm_response->header.param1 = 0;
1166 1 : spdm_response->header.param2 = 0;
1167 1 : spdm_response->rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, true);
1168 1 : spdm_response->reserved = 0;
1169 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
1170 1 : spdm_response->opaque_length = (uint16_t)opaque_psk_exchange_rsp_size;
1171 1 : ptr = (void *)(spdm_response + 1);
1172 : /* libspdm_zero_mem (ptr, hash_size);
1173 : * ptr += hash_size;*/
1174 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
1175 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
1176 1 : libspdm_build_opaque_data_version_selection_data(
1177 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1178 : &opaque_psk_exchange_rsp_size, ptr);
1179 1 : ptr += opaque_psk_exchange_rsp_size;
1180 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1181 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
1182 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1183 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1184 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
1185 : m_libspdm_local_buffer_size));
1186 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1187 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1188 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1189 : m_libspdm_use_asym_algo, &data,
1190 : &data_size, NULL, NULL);
1191 1 : cert_buffer = (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
1192 1 : cert_buffer_size = data_size - (sizeof(spdm_cert_chain_t) + hash_size);
1193 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1194 : cert_buffer_hash);
1195 : /* transcript.message_a size is 0*/
1196 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1197 : m_libspdm_local_buffer_size);
1198 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1199 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1200 1 : free(data);
1201 1 : bin_str2_size = sizeof(bin_str2);
1202 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1203 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1204 1 : hash_data, (uint16_t)hash_size, hash_size,
1205 : bin_str2, &bin_str2_size);
1206 1 : libspdm_psk_handshake_secret_hkdf_expand(
1207 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1208 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
1209 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2, bin_str2_size,
1210 : response_handshake_secret, hash_size);
1211 1 : bin_str7_size = sizeof(bin_str7);
1212 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1213 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1214 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7, &bin_str7_size);
1215 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1216 : hash_size, bin_str7, bin_str7_size,
1217 : response_finished_key, hash_size);
1218 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1219 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1220 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1221 : response_finished_key, hash_size, ptr);
1222 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1223 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
1224 : ptr, hmac_size);
1225 1 : m_libspdm_local_buffer_size += hmac_size;
1226 1 : ptr += hmac_size;
1227 :
1228 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1229 : false, spdm_response_size,
1230 : spdm_response, response_size,
1231 : response);
1232 : }
1233 1 : return LIBSPDM_STATUS_SUCCESS;
1234 1 : case 0xD: {
1235 : spdm_psk_exchange_response_t *spdm_response;
1236 : uint32_t hash_size;
1237 : uint32_t hmac_size;
1238 : uint8_t *ptr;
1239 : size_t opaque_psk_exchange_rsp_size;
1240 : void *data;
1241 : size_t data_size;
1242 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1243 : uint8_t *cert_buffer;
1244 : size_t cert_buffer_size;
1245 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1246 : uint8_t bin_str2[128];
1247 : size_t bin_str2_size;
1248 : uint8_t bin_str7[128];
1249 : size_t bin_str7_size;
1250 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1251 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1252 : size_t spdm_response_size;
1253 : size_t transport_header_size;
1254 :
1255 :
1256 : ((libspdm_context_t *)spdm_context)
1257 1 : ->connection_info.algorithm.base_asym_algo =
1258 : m_libspdm_use_asym_algo;
1259 : ((libspdm_context_t *)spdm_context)
1260 1 : ->connection_info.algorithm.base_hash_algo =
1261 : m_libspdm_use_hash_algo;
1262 : ((libspdm_context_t *)spdm_context)
1263 1 : ->connection_info.algorithm.dhe_named_group =
1264 : m_libspdm_use_dhe_algo;
1265 : ((libspdm_context_t *)spdm_context)
1266 1 : ->connection_info.algorithm.measurement_hash_algo =
1267 : m_libspdm_use_measurement_hash_algo;
1268 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1269 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1270 1 : opaque_psk_exchange_rsp_size =
1271 1 : libspdm_get_opaque_data_version_selection_data_size(
1272 : spdm_context);
1273 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
1274 : LIBSPDM_PSK_CONTEXT_LENGTH +
1275 1 : opaque_psk_exchange_rsp_size + hmac_size;
1276 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1277 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1278 :
1279 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
1280 1 : spdm_response->header.request_response_code =
1281 : SPDM_PSK_EXCHANGE_RSP;
1282 1 : spdm_response->header.param1 = 0;
1283 1 : spdm_response->header.param2 = 0;
1284 1 : spdm_response->rsp_session_id =
1285 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
1286 1 : spdm_response->reserved = 0;
1287 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
1288 1 : spdm_response->opaque_length =
1289 1 : (uint16_t)opaque_psk_exchange_rsp_size;
1290 1 : ptr = (void *)(spdm_response + 1);
1291 : /* libspdm_zero_mem (ptr, hash_size);
1292 : * ptr += hash_size;*/
1293 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
1294 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
1295 1 : libspdm_build_opaque_data_version_selection_data(
1296 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1297 : &opaque_psk_exchange_rsp_size, ptr);
1298 1 : ptr += opaque_psk_exchange_rsp_size;
1299 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1300 : sizeof(m_libspdm_local_buffer)
1301 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1302 : m_libspdm_local_buffer),
1303 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1304 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1305 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1306 : m_libspdm_local_buffer_size));
1307 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1308 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1309 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1310 : m_libspdm_use_asym_algo, &data,
1311 : &data_size, NULL, NULL);
1312 1 : cert_buffer =
1313 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
1314 1 : cert_buffer_size =
1315 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
1316 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1317 : cert_buffer_hash);
1318 : /* transcript.message_a size is 0*/
1319 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1320 : m_libspdm_local_buffer_size);
1321 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1322 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1323 1 : free(data);
1324 1 : bin_str2_size = sizeof(bin_str2);
1325 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1326 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
1327 1 : hash_data, (uint16_t)hash_size, hash_size,
1328 : bin_str2, &bin_str2_size);
1329 1 : libspdm_psk_handshake_secret_hkdf_expand(
1330 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1331 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
1332 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
1333 : bin_str2_size,
1334 : response_handshake_secret, hash_size);
1335 1 : bin_str7_size = sizeof(bin_str7);
1336 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1337 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
1338 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1339 : &bin_str7_size);
1340 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1341 : hash_size, bin_str7, bin_str7_size,
1342 : response_finished_key, hash_size);
1343 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1344 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1345 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1346 : response_finished_key, hash_size, ptr);
1347 1 : ptr += hmac_size;
1348 :
1349 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1350 : false, spdm_response_size,
1351 : spdm_response, response_size,
1352 : response);
1353 : }
1354 1 : return LIBSPDM_STATUS_SUCCESS;
1355 1 : case 0xE: {
1356 : spdm_psk_exchange_response_t *spdm_response;
1357 : uint32_t hash_size;
1358 : uint32_t hmac_size;
1359 : uint32_t measurement_hash_size;
1360 : uint8_t *ptr;
1361 : size_t opaque_psk_exchange_rsp_size;
1362 : void *data;
1363 : size_t data_size;
1364 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1365 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1366 : uint8_t *cert_buffer;
1367 : size_t cert_buffer_size;
1368 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1369 : uint8_t bin_str2[128];
1370 : size_t bin_str2_size;
1371 : uint8_t bin_str7[128];
1372 : size_t bin_str7_size;
1373 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1374 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1375 : size_t spdm_response_size;
1376 : size_t transport_header_size;
1377 :
1378 :
1379 : ((libspdm_context_t *)spdm_context)
1380 1 : ->connection_info.algorithm.base_asym_algo =
1381 : m_libspdm_use_asym_algo;
1382 : ((libspdm_context_t *)spdm_context)
1383 1 : ->connection_info.algorithm.base_hash_algo =
1384 : m_libspdm_use_hash_algo;
1385 : ((libspdm_context_t *)spdm_context)
1386 1 : ->connection_info.algorithm.dhe_named_group =
1387 : m_libspdm_use_dhe_algo;
1388 : ((libspdm_context_t *)spdm_context)
1389 1 : ->connection_info.algorithm.measurement_hash_algo =
1390 : m_libspdm_use_measurement_hash_algo;
1391 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1392 1 : measurement_hash_size = libspdm_get_hash_size(
1393 : m_libspdm_use_hash_algo);
1394 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1395 1 : opaque_psk_exchange_rsp_size =
1396 1 : libspdm_get_opaque_data_version_selection_data_size(
1397 : spdm_context);
1398 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
1399 1 : measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
1400 1 : opaque_psk_exchange_rsp_size + hmac_size;
1401 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1402 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1403 :
1404 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1405 :
1406 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1407 1 : spdm_response->header.request_response_code =
1408 : SPDM_PSK_EXCHANGE_RSP;
1409 1 : spdm_response->header.param1 = 0;
1410 1 : spdm_response->header.param2 = 0;
1411 1 : spdm_response->rsp_session_id =
1412 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
1413 1 : spdm_response->reserved = 0;
1414 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
1415 1 : spdm_response->opaque_length =
1416 1 : (uint16_t)opaque_psk_exchange_rsp_size;
1417 1 : ptr = (void *)(spdm_response + 1);
1418 : /*Mock measurement hash as TCB*/
1419 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
1420 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
1421 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1422 : measurement_hash_data, measurement_hash_size);
1423 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1424 1 : ptr += measurement_hash_size;
1425 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
1426 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
1427 1 : libspdm_build_opaque_data_version_selection_data(
1428 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1429 : &opaque_psk_exchange_rsp_size, ptr);
1430 1 : ptr += opaque_psk_exchange_rsp_size;
1431 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1432 : sizeof(m_libspdm_local_buffer)
1433 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1434 : m_libspdm_local_buffer),
1435 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1436 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1437 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1438 : m_libspdm_local_buffer_size));
1439 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1440 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1441 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1442 : m_libspdm_use_asym_algo, &data,
1443 : &data_size, NULL, NULL);
1444 1 : cert_buffer =
1445 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
1446 1 : cert_buffer_size =
1447 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
1448 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1449 : cert_buffer_hash);
1450 : /* transcript.message_a size is 0*/
1451 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1452 : m_libspdm_local_buffer_size);
1453 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1454 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1455 1 : free(data);
1456 1 : bin_str2_size = sizeof(bin_str2);
1457 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1458 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1459 1 : hash_data, (uint16_t)hash_size, hash_size,
1460 : bin_str2, &bin_str2_size);
1461 1 : libspdm_psk_handshake_secret_hkdf_expand(
1462 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1463 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
1464 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
1465 : bin_str2_size,
1466 : response_handshake_secret, hash_size);
1467 1 : bin_str7_size = sizeof(bin_str7);
1468 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1469 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1470 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1471 : &bin_str7_size);
1472 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1473 : hash_size, bin_str7, bin_str7_size,
1474 : response_finished_key, hash_size);
1475 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1476 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1477 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1478 : response_finished_key, hash_size, ptr);
1479 1 : ptr += hmac_size;
1480 :
1481 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1482 : false, spdm_response_size,
1483 : spdm_response, response_size,
1484 : response);
1485 : }
1486 1 : return LIBSPDM_STATUS_SUCCESS;
1487 :
1488 1 : case 0xF: {
1489 : spdm_psk_exchange_response_t *spdm_response;
1490 : uint32_t hash_size;
1491 : uint32_t hmac_size;
1492 : uint32_t measurement_hash_size;
1493 : uint8_t *ptr;
1494 : size_t opaque_psk_exchange_rsp_size;
1495 : void *data;
1496 : size_t data_size;
1497 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1498 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1499 : uint8_t *cert_buffer;
1500 : size_t cert_buffer_size;
1501 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1502 : uint8_t bin_str2[128];
1503 : size_t bin_str2_size;
1504 : uint8_t bin_str7[128];
1505 : size_t bin_str7_size;
1506 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1507 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1508 : size_t spdm_response_size;
1509 : size_t transport_header_size;
1510 :
1511 :
1512 : ((libspdm_context_t *)spdm_context)
1513 1 : ->connection_info.algorithm.base_asym_algo =
1514 : m_libspdm_use_asym_algo;
1515 : ((libspdm_context_t *)spdm_context)
1516 1 : ->connection_info.algorithm.base_hash_algo =
1517 : m_libspdm_use_hash_algo;
1518 : ((libspdm_context_t *)spdm_context)
1519 1 : ->connection_info.algorithm.dhe_named_group =
1520 : m_libspdm_use_dhe_algo;
1521 : ((libspdm_context_t *)spdm_context)
1522 1 : ->connection_info.algorithm.measurement_hash_algo =
1523 : m_libspdm_use_measurement_hash_algo;
1524 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1525 1 : measurement_hash_size = libspdm_get_hash_size(
1526 : m_libspdm_use_hash_algo);
1527 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1528 1 : opaque_psk_exchange_rsp_size =
1529 1 : libspdm_get_opaque_data_version_selection_data_size(
1530 : spdm_context);
1531 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
1532 1 : measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
1533 1 : opaque_psk_exchange_rsp_size + hmac_size;
1534 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1535 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1536 :
1537 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1538 :
1539 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1540 1 : spdm_response->header.request_response_code =
1541 : SPDM_PSK_EXCHANGE_RSP;
1542 1 : spdm_response->header.param1 = 0;
1543 1 : spdm_response->header.param2 = 0;
1544 1 : spdm_response->rsp_session_id =
1545 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
1546 1 : spdm_response->reserved = 0;
1547 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
1548 1 : spdm_response->opaque_length =
1549 1 : (uint16_t)opaque_psk_exchange_rsp_size;
1550 1 : ptr = (void *)(spdm_response + 1);
1551 : /*Mock measurement hash as 0x00 array*/
1552 1 : libspdm_zero_mem(measurement_hash_data, measurement_hash_size);
1553 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1554 : measurement_hash_data, measurement_hash_size);
1555 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1556 1 : ptr += measurement_hash_size;
1557 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
1558 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
1559 1 : libspdm_build_opaque_data_version_selection_data(
1560 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1561 : &opaque_psk_exchange_rsp_size, ptr);
1562 1 : ptr += opaque_psk_exchange_rsp_size;
1563 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1564 : sizeof(m_libspdm_local_buffer)
1565 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1566 : m_libspdm_local_buffer),
1567 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1568 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1569 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1570 : m_libspdm_local_buffer_size));
1571 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1572 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1573 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1574 : m_libspdm_use_asym_algo, &data,
1575 : &data_size, NULL, NULL);
1576 1 : cert_buffer =
1577 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
1578 1 : cert_buffer_size =
1579 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
1580 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1581 : cert_buffer_hash);
1582 : /* transcript.message_a size is 0*/
1583 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1584 : m_libspdm_local_buffer_size);
1585 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1586 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1587 1 : free(data);
1588 1 : bin_str2_size = sizeof(bin_str2);
1589 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1590 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1591 1 : hash_data, (uint16_t)hash_size, hash_size,
1592 : bin_str2, &bin_str2_size);
1593 1 : libspdm_psk_handshake_secret_hkdf_expand(
1594 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1595 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
1596 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
1597 : bin_str2_size,
1598 : response_handshake_secret, hash_size);
1599 1 : bin_str7_size = sizeof(bin_str7);
1600 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1601 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1602 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1603 : &bin_str7_size);
1604 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1605 : hash_size, bin_str7, bin_str7_size,
1606 : response_finished_key, hash_size);
1607 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1608 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1609 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1610 : response_finished_key, hash_size, ptr);
1611 1 : ptr += hmac_size;
1612 :
1613 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1614 : false, spdm_response_size,
1615 : spdm_response, response_size,
1616 : response);
1617 : }
1618 1 : return LIBSPDM_STATUS_SUCCESS;
1619 :
1620 1 : case 0x10: {
1621 : spdm_psk_exchange_response_t *spdm_response;
1622 : uint32_t hash_size;
1623 : uint32_t hmac_size;
1624 : uint32_t measurement_hash_size;
1625 : uint8_t *ptr;
1626 : size_t opaque_psk_exchange_rsp_size;
1627 : void *data;
1628 : size_t data_size;
1629 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
1630 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1631 : uint8_t *cert_buffer;
1632 : size_t cert_buffer_size;
1633 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1634 : uint8_t bin_str2[128];
1635 : size_t bin_str2_size;
1636 : uint8_t bin_str7[128];
1637 : size_t bin_str7_size;
1638 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1639 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1640 : size_t spdm_response_size;
1641 : size_t transport_header_size;
1642 :
1643 :
1644 : ((libspdm_context_t *)spdm_context)
1645 1 : ->connection_info.algorithm.base_asym_algo =
1646 : m_libspdm_use_asym_algo;
1647 : ((libspdm_context_t *)spdm_context)
1648 1 : ->connection_info.algorithm.base_hash_algo =
1649 : m_libspdm_use_hash_algo;
1650 : ((libspdm_context_t *)spdm_context)
1651 1 : ->connection_info.algorithm.dhe_named_group =
1652 : m_libspdm_use_dhe_algo;
1653 : ((libspdm_context_t *)spdm_context)
1654 1 : ->connection_info.algorithm.measurement_hash_algo =
1655 : m_libspdm_use_measurement_hash_algo;
1656 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1657 1 : measurement_hash_size = libspdm_get_hash_size(
1658 : m_libspdm_use_hash_algo);
1659 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1660 1 : opaque_psk_exchange_rsp_size =
1661 1 : libspdm_get_opaque_data_version_selection_data_size(
1662 : spdm_context);
1663 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
1664 1 : measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
1665 1 : opaque_psk_exchange_rsp_size + hmac_size;
1666 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1667 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1668 :
1669 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1670 :
1671 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1672 1 : spdm_response->header.request_response_code =
1673 : SPDM_PSK_EXCHANGE_RSP;
1674 1 : spdm_response->header.param1 = 0;
1675 1 : spdm_response->header.param2 = 0;
1676 1 : spdm_response->rsp_session_id =
1677 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
1678 1 : spdm_response->reserved = 0;
1679 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
1680 1 : spdm_response->opaque_length =
1681 1 : (uint16_t)opaque_psk_exchange_rsp_size;
1682 1 : ptr = (void *)(spdm_response + 1);
1683 : /*Mock measurement hash*/
1684 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
1685 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
1686 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
1687 : measurement_hash_data, measurement_hash_size);
1688 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
1689 1 : ptr += measurement_hash_size;
1690 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
1691 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
1692 1 : libspdm_build_opaque_data_version_selection_data(
1693 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1694 : &opaque_psk_exchange_rsp_size, ptr);
1695 1 : ptr += opaque_psk_exchange_rsp_size;
1696 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1697 : sizeof(m_libspdm_local_buffer)
1698 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1699 : m_libspdm_local_buffer),
1700 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1701 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1702 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1703 : m_libspdm_local_buffer_size));
1704 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1705 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1706 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1707 : m_libspdm_use_asym_algo, &data,
1708 : &data_size, NULL, NULL);
1709 1 : cert_buffer =
1710 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
1711 1 : cert_buffer_size =
1712 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
1713 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1714 : cert_buffer_hash);
1715 : /* transcript.message_a size is 0*/
1716 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1717 : m_libspdm_local_buffer_size);
1718 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1719 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1720 1 : free(data);
1721 1 : bin_str2_size = sizeof(bin_str2);
1722 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1723 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1724 1 : hash_data, (uint16_t)hash_size, hash_size,
1725 : bin_str2, &bin_str2_size);
1726 1 : libspdm_psk_handshake_secret_hkdf_expand(
1727 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1728 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
1729 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
1730 : bin_str2_size,
1731 : response_handshake_secret, hash_size);
1732 1 : bin_str7_size = sizeof(bin_str7);
1733 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1734 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1735 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1736 : &bin_str7_size);
1737 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1738 : hash_size, bin_str7, bin_str7_size,
1739 : response_finished_key, hash_size);
1740 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1741 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1742 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1743 : response_finished_key, hash_size, ptr);
1744 1 : ptr += hmac_size;
1745 :
1746 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1747 : false, spdm_response_size,
1748 : spdm_response, response_size,
1749 : response);
1750 : }
1751 1 : return LIBSPDM_STATUS_SUCCESS;
1752 :
1753 1 : case 0x11: {
1754 : spdm_psk_exchange_response_t *spdm_response;
1755 : uint32_t hash_size;
1756 : uint32_t hmac_size;
1757 : uint8_t *ptr;
1758 : size_t opaque_psk_exchange_rsp_size;
1759 : void *data;
1760 : size_t data_size;
1761 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1762 : uint8_t *cert_buffer;
1763 : size_t cert_buffer_size;
1764 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1765 : uint8_t bin_str2[128];
1766 : size_t bin_str2_size;
1767 : uint8_t bin_str7[128];
1768 : size_t bin_str7_size;
1769 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1770 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1771 : size_t spdm_response_size;
1772 : size_t transport_header_size;
1773 :
1774 :
1775 : ((libspdm_context_t *)spdm_context)
1776 1 : ->connection_info.algorithm.base_asym_algo =
1777 : m_libspdm_use_asym_algo;
1778 : ((libspdm_context_t *)spdm_context)
1779 1 : ->connection_info.algorithm.base_hash_algo =
1780 : m_libspdm_use_hash_algo;
1781 : ((libspdm_context_t *)spdm_context)
1782 1 : ->connection_info.algorithm.dhe_named_group =
1783 : m_libspdm_use_dhe_algo;
1784 : ((libspdm_context_t *)spdm_context)
1785 1 : ->connection_info.algorithm.measurement_hash_algo =
1786 : m_libspdm_use_measurement_hash_algo;
1787 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1788 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1789 1 : opaque_psk_exchange_rsp_size =
1790 1 : libspdm_get_opaque_data_version_selection_data_size(
1791 : spdm_context);
1792 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
1793 : LIBSPDM_PSK_CONTEXT_LENGTH +
1794 1 : opaque_psk_exchange_rsp_size + hmac_size;
1795 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1796 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1797 :
1798 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1799 :
1800 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1801 1 : spdm_response->header.request_response_code =
1802 : SPDM_PSK_EXCHANGE_RSP;
1803 1 : spdm_response->header.param1 = 0;
1804 1 : spdm_response->header.param2 = 0;
1805 1 : spdm_response->rsp_session_id =
1806 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
1807 1 : spdm_response->reserved = 0;
1808 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
1809 1 : spdm_response->opaque_length =
1810 1 : (uint16_t)opaque_psk_exchange_rsp_size;
1811 1 : ptr = (void *)(spdm_response + 1);
1812 : /* libspdm_zero_mem (ptr, hash_size);
1813 : * ptr += hash_size;*/
1814 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
1815 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
1816 1 : libspdm_build_opaque_data_version_selection_data(
1817 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1818 : &opaque_psk_exchange_rsp_size, ptr);
1819 1 : ptr += opaque_psk_exchange_rsp_size;
1820 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1821 : sizeof(m_libspdm_local_buffer)
1822 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1823 : m_libspdm_local_buffer),
1824 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1825 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1826 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1827 : m_libspdm_local_buffer_size));
1828 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1829 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1830 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1831 : m_libspdm_use_asym_algo, &data,
1832 : &data_size, NULL, NULL);
1833 1 : cert_buffer =
1834 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
1835 1 : cert_buffer_size =
1836 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
1837 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1838 : cert_buffer_hash);
1839 : /* transcript.message_a size is 0*/
1840 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1841 : m_libspdm_local_buffer_size);
1842 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1843 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1844 1 : free(data);
1845 1 : bin_str2_size = sizeof(bin_str2);
1846 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1847 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1848 1 : hash_data, (uint16_t)hash_size, hash_size,
1849 : bin_str2, &bin_str2_size);
1850 1 : libspdm_psk_handshake_secret_hkdf_expand(
1851 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1852 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
1853 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
1854 : bin_str2_size,
1855 : response_handshake_secret, hash_size);
1856 1 : bin_str7_size = sizeof(bin_str7);
1857 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1858 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1859 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1860 : &bin_str7_size);
1861 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1862 : hash_size, bin_str7, bin_str7_size,
1863 : response_finished_key, hash_size);
1864 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1865 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1866 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1867 : response_finished_key, hash_size, ptr);
1868 1 : ptr += hmac_size;
1869 :
1870 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1871 : false, spdm_response_size,
1872 : spdm_response, response_size,
1873 : response);
1874 : }
1875 1 : return LIBSPDM_STATUS_SUCCESS;
1876 :
1877 1 : case 0x12: {
1878 : spdm_psk_exchange_response_t *spdm_response;
1879 : uint32_t hash_size;
1880 : uint32_t hmac_size;
1881 : uint8_t *ptr;
1882 : size_t opaque_psk_exchange_rsp_size;
1883 : void *data;
1884 : size_t data_size;
1885 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1886 : uint8_t *cert_buffer;
1887 : size_t cert_buffer_size;
1888 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
1889 : uint8_t bin_str2[128];
1890 : size_t bin_str2_size;
1891 : uint8_t bin_str7[128];
1892 : size_t bin_str7_size;
1893 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
1894 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
1895 : size_t spdm_response_size;
1896 : size_t transport_header_size;
1897 :
1898 :
1899 : ((libspdm_context_t *)spdm_context)
1900 1 : ->connection_info.algorithm.base_asym_algo =
1901 : m_libspdm_use_asym_algo;
1902 : ((libspdm_context_t *)spdm_context)
1903 1 : ->connection_info.algorithm.base_hash_algo =
1904 : m_libspdm_use_hash_algo;
1905 : ((libspdm_context_t *)spdm_context)
1906 1 : ->connection_info.algorithm.dhe_named_group =
1907 : m_libspdm_use_dhe_algo;
1908 : ((libspdm_context_t *)spdm_context)
1909 1 : ->connection_info.algorithm.measurement_hash_algo =
1910 : m_libspdm_use_measurement_hash_algo;
1911 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1912 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
1913 1 : opaque_psk_exchange_rsp_size =
1914 1 : libspdm_get_opaque_data_version_selection_data_size(
1915 : spdm_context);
1916 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
1917 : LIBSPDM_PSK_CONTEXT_LENGTH +
1918 1 : opaque_psk_exchange_rsp_size + hmac_size;
1919 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1920 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1921 :
1922 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
1923 :
1924 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1925 1 : spdm_response->header.request_response_code =
1926 : SPDM_PSK_EXCHANGE_RSP;
1927 1 : spdm_response->header.param1 = 0;
1928 1 : spdm_response->header.param2 = 0;
1929 1 : spdm_response->rsp_session_id =
1930 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
1931 1 : spdm_response->reserved = 0;
1932 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
1933 1 : spdm_response->opaque_length =
1934 1 : (uint16_t)opaque_psk_exchange_rsp_size;
1935 1 : ptr = (void *)(spdm_response + 1);
1936 : /* libspdm_zero_mem (ptr, hash_size);
1937 : * ptr += hash_size;*/
1938 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
1939 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
1940 1 : libspdm_build_opaque_data_version_selection_data(
1941 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
1942 : &opaque_psk_exchange_rsp_size, ptr);
1943 1 : ptr += opaque_psk_exchange_rsp_size;
1944 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1945 : sizeof(m_libspdm_local_buffer)
1946 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1947 : m_libspdm_local_buffer),
1948 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1949 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1950 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1951 : m_libspdm_local_buffer_size));
1952 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1953 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
1954 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
1955 : m_libspdm_use_asym_algo, &data,
1956 : &data_size, NULL, NULL);
1957 1 : cert_buffer =
1958 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
1959 1 : cert_buffer_size =
1960 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
1961 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
1962 : cert_buffer_hash);
1963 : /* transcript.message_a size is 0*/
1964 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
1965 : m_libspdm_local_buffer_size);
1966 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1967 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1968 1 : free(data);
1969 1 : bin_str2_size = sizeof(bin_str2);
1970 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1971 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
1972 1 : hash_data, (uint16_t)hash_size, hash_size,
1973 : bin_str2, &bin_str2_size);
1974 1 : libspdm_psk_handshake_secret_hkdf_expand(
1975 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1976 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
1977 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
1978 : bin_str2_size,
1979 : response_handshake_secret, hash_size);
1980 1 : bin_str7_size = sizeof(bin_str7);
1981 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
1982 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
1983 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
1984 : &bin_str7_size);
1985 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
1986 : hash_size, bin_str7, bin_str7_size,
1987 : response_finished_key, hash_size);
1988 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
1989 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
1990 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
1991 : response_finished_key, hash_size, ptr);
1992 1 : ptr += hmac_size;
1993 :
1994 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1995 : false, spdm_response_size,
1996 : spdm_response, response_size,
1997 : response);
1998 : }
1999 1 : return LIBSPDM_STATUS_SUCCESS;
2000 :
2001 1 : case 0x13: {
2002 : spdm_psk_exchange_response_t *spdm_response;
2003 : uint32_t hash_size;
2004 : uint32_t hmac_size;
2005 : uint32_t measurement_hash_size;
2006 : uint8_t *ptr;
2007 : size_t opaque_psk_exchange_rsp_size;
2008 : void *data;
2009 : size_t data_size;
2010 : uint8_t measurement_hash_data[LIBSPDM_MAX_HASH_SIZE];
2011 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2012 : uint8_t *cert_buffer;
2013 : size_t cert_buffer_size;
2014 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2015 : uint8_t bin_str2[128];
2016 : size_t bin_str2_size;
2017 : uint8_t bin_str7[128];
2018 : size_t bin_str7_size;
2019 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2020 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2021 : size_t spdm_response_size;
2022 : size_t transport_header_size;
2023 :
2024 :
2025 : ((libspdm_context_t *)spdm_context)
2026 1 : ->connection_info.algorithm.base_asym_algo =
2027 : m_libspdm_use_asym_algo;
2028 : ((libspdm_context_t *)spdm_context)
2029 1 : ->connection_info.algorithm.base_hash_algo =
2030 : m_libspdm_use_hash_algo;
2031 : ((libspdm_context_t *)spdm_context)
2032 1 : ->connection_info.algorithm.dhe_named_group =
2033 : m_libspdm_use_dhe_algo;
2034 : ((libspdm_context_t *)spdm_context)
2035 1 : ->connection_info.algorithm.measurement_hash_algo =
2036 : m_libspdm_use_measurement_hash_algo;
2037 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2038 1 : measurement_hash_size = libspdm_get_hash_size(
2039 : m_libspdm_use_hash_algo);
2040 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2041 1 : opaque_psk_exchange_rsp_size =
2042 1 : libspdm_get_opaque_data_version_selection_data_size(
2043 : spdm_context);
2044 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) +
2045 1 : measurement_hash_size + LIBSPDM_PSK_CONTEXT_LENGTH +
2046 1 : opaque_psk_exchange_rsp_size + hmac_size;
2047 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2048 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2049 :
2050 1 : libspdm_zero_mem(spdm_response,spdm_response_size);
2051 :
2052 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2053 1 : spdm_response->header.request_response_code =
2054 : SPDM_PSK_EXCHANGE_RSP;
2055 1 : spdm_response->header.param1 = 0;
2056 1 : spdm_response->header.param2 = 0;
2057 1 : spdm_response->rsp_session_id =
2058 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
2059 1 : spdm_response->reserved = 0;
2060 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
2061 1 : spdm_response->opaque_length =
2062 1 : (uint16_t)opaque_psk_exchange_rsp_size;
2063 1 : ptr = (void *)(spdm_response + 1);
2064 : /*Mock measurement hash as TCB*/
2065 1 : libspdm_copy_mem(measurement_hash_data, sizeof(measurement_hash_data),
2066 : m_libspdm_use_tcb_hash_value, measurement_hash_size);
2067 1 : libspdm_copy_mem(ptr, spdm_response_size - (ptr - (uint8_t *)spdm_response),
2068 : measurement_hash_data, measurement_hash_size);
2069 : /*libspdm_zero_mem (ptr, measurement_hash_size);*/
2070 1 : ptr += measurement_hash_size;
2071 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
2072 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
2073 1 : libspdm_build_opaque_data_version_selection_data(
2074 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2075 : &opaque_psk_exchange_rsp_size, ptr);
2076 1 : ptr += opaque_psk_exchange_rsp_size;
2077 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2078 : sizeof(m_libspdm_local_buffer)
2079 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2080 : m_libspdm_local_buffer),
2081 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2082 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2083 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2084 : m_libspdm_local_buffer_size));
2085 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2086 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2087 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2088 : m_libspdm_use_asym_algo, &data,
2089 : &data_size, NULL, NULL);
2090 1 : cert_buffer =
2091 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
2092 1 : cert_buffer_size =
2093 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
2094 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2095 : cert_buffer_hash);
2096 : /* transcript.message_a size is 0*/
2097 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2098 : m_libspdm_local_buffer_size);
2099 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2100 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2101 1 : free(data);
2102 1 : bin_str2_size = sizeof(bin_str2);
2103 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2104 : SPDM_BIN_STR_2_LABEL, sizeof(SPDM_BIN_STR_2_LABEL) - 1,
2105 1 : hash_data, (uint16_t)hash_size, hash_size,
2106 : bin_str2, &bin_str2_size);
2107 1 : libspdm_psk_handshake_secret_hkdf_expand(
2108 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2109 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
2110 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
2111 : bin_str2_size,
2112 : response_handshake_secret, hash_size);
2113 1 : bin_str7_size = sizeof(bin_str7);
2114 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2115 : SPDM_BIN_STR_7_LABEL, sizeof(SPDM_BIN_STR_7_LABEL) - 1,
2116 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2117 : &bin_str7_size);
2118 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2119 : hash_size, bin_str7, bin_str7_size,
2120 : response_finished_key, hash_size);
2121 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2122 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2123 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2124 : response_finished_key, hash_size, ptr);
2125 1 : ptr += hmac_size;
2126 :
2127 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2128 : false, spdm_response_size,
2129 : spdm_response, response_size,
2130 : response);
2131 : }
2132 1 : return LIBSPDM_STATUS_SUCCESS;
2133 :
2134 1 : case 0x14: {
2135 : spdm_psk_exchange_response_t *spdm_response;
2136 : uint32_t hash_size;
2137 : uint32_t hmac_size;
2138 : uint8_t *ptr;
2139 : size_t opaque_psk_exchange_rsp_size;
2140 : void *data;
2141 : size_t data_size;
2142 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2143 : uint8_t *cert_buffer;
2144 : size_t cert_buffer_size;
2145 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2146 : uint8_t bin_str2[128];
2147 : size_t bin_str2_size;
2148 : uint8_t bin_str7[128];
2149 : size_t bin_str7_size;
2150 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2151 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2152 : size_t spdm_response_size;
2153 : size_t transport_header_size;
2154 :
2155 :
2156 : ((libspdm_context_t *)spdm_context)
2157 1 : ->connection_info.algorithm.base_asym_algo =
2158 : m_libspdm_use_asym_algo;
2159 : ((libspdm_context_t *)spdm_context)
2160 1 : ->connection_info.algorithm.base_hash_algo =
2161 : m_libspdm_use_hash_algo;
2162 : ((libspdm_context_t *)spdm_context)
2163 1 : ->connection_info.algorithm.dhe_named_group =
2164 : m_libspdm_use_dhe_algo;
2165 : ((libspdm_context_t *)spdm_context)
2166 1 : ->connection_info.algorithm.measurement_hash_algo =
2167 : m_libspdm_use_measurement_hash_algo;
2168 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2169 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2170 1 : opaque_psk_exchange_rsp_size =
2171 1 : libspdm_get_opaque_data_version_selection_data_size(
2172 : spdm_context);
2173 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
2174 : LIBSPDM_PSK_CONTEXT_LENGTH +
2175 1 : opaque_psk_exchange_rsp_size + hmac_size;
2176 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2177 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2178 :
2179 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2180 1 : spdm_response->header.request_response_code =
2181 : SPDM_PSK_EXCHANGE_RSP;
2182 1 : spdm_response->header.param1 = 5;
2183 1 : spdm_response->header.param2 = 0;
2184 1 : spdm_response->rsp_session_id =
2185 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
2186 1 : spdm_response->reserved = 0;
2187 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
2188 1 : spdm_response->opaque_length =
2189 1 : (uint16_t)opaque_psk_exchange_rsp_size;
2190 1 : ptr = (void *)(spdm_response + 1);
2191 : /* libspdm_zero_mem (ptr, hash_size);
2192 : * ptr += hash_size;*/
2193 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
2194 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
2195 1 : libspdm_build_opaque_data_version_selection_data(
2196 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2197 : &opaque_psk_exchange_rsp_size, ptr);
2198 1 : ptr += opaque_psk_exchange_rsp_size;
2199 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2200 : sizeof(m_libspdm_local_buffer)
2201 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2202 : m_libspdm_local_buffer),
2203 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2204 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2205 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2206 : m_libspdm_local_buffer_size));
2207 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2208 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2209 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2210 : m_libspdm_use_asym_algo, &data,
2211 : &data_size, NULL, NULL);
2212 1 : cert_buffer =
2213 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
2214 1 : cert_buffer_size =
2215 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
2216 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2217 : cert_buffer_hash);
2218 : /* transcript.message_a size is 0*/
2219 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2220 : m_libspdm_local_buffer_size);
2221 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2222 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2223 1 : free(data);
2224 1 : bin_str2_size = sizeof(bin_str2);
2225 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2226 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
2227 1 : hash_data, (uint16_t)hash_size, hash_size,
2228 : bin_str2, &bin_str2_size);
2229 1 : libspdm_psk_handshake_secret_hkdf_expand(
2230 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2231 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
2232 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
2233 : bin_str2_size,
2234 : response_handshake_secret, hash_size);
2235 1 : bin_str7_size = sizeof(bin_str7);
2236 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2237 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
2238 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2239 : &bin_str7_size);
2240 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2241 : hash_size, bin_str7, bin_str7_size,
2242 : response_finished_key, hash_size);
2243 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2244 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2245 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2246 : response_finished_key, hash_size, ptr);
2247 1 : ptr += hmac_size;
2248 :
2249 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2250 : false, spdm_response_size,
2251 : spdm_response, response_size,
2252 : response);
2253 : }
2254 1 : return LIBSPDM_STATUS_SUCCESS;
2255 :
2256 1 : case 0x15: {
2257 : spdm_psk_exchange_response_t *spdm_response;
2258 : uint32_t hash_size;
2259 : uint32_t hmac_size;
2260 : uint8_t *ptr;
2261 : size_t opaque_psk_exchange_rsp_size;
2262 : void *data;
2263 : size_t data_size;
2264 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2265 : uint8_t *cert_buffer;
2266 : size_t cert_buffer_size;
2267 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2268 : uint8_t bin_str2[128];
2269 : size_t bin_str2_size;
2270 : uint8_t bin_str7[128];
2271 : size_t bin_str7_size;
2272 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2273 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2274 : size_t spdm_response_size;
2275 : size_t transport_header_size;
2276 :
2277 :
2278 : ((libspdm_context_t *)spdm_context)
2279 1 : ->connection_info.algorithm.base_asym_algo =
2280 : m_libspdm_use_asym_algo;
2281 : ((libspdm_context_t *)spdm_context)
2282 1 : ->connection_info.algorithm.base_hash_algo =
2283 : m_libspdm_use_hash_algo;
2284 : ((libspdm_context_t *)spdm_context)
2285 1 : ->connection_info.algorithm.dhe_named_group =
2286 : m_libspdm_use_dhe_algo;
2287 : ((libspdm_context_t *)spdm_context)
2288 1 : ->connection_info.algorithm.measurement_hash_algo =
2289 : m_libspdm_use_measurement_hash_algo;
2290 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2291 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2292 1 : opaque_psk_exchange_rsp_size =
2293 1 : libspdm_get_opaque_data_version_selection_data_size(
2294 : spdm_context);
2295 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
2296 : LIBSPDM_PSK_CONTEXT_LENGTH +
2297 1 : opaque_psk_exchange_rsp_size + hmac_size;
2298 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2299 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2300 :
2301 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2302 1 : spdm_response->header.request_response_code =
2303 : SPDM_PSK_EXCHANGE_RSP;
2304 1 : spdm_response->header.param1 = 5;
2305 1 : spdm_response->header.param2 = 0;
2306 1 : spdm_response->rsp_session_id =
2307 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
2308 1 : spdm_response->reserved = 0;
2309 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
2310 1 : spdm_response->opaque_length =
2311 1 : (uint16_t)opaque_psk_exchange_rsp_size;
2312 1 : ptr = (void *)(spdm_response + 1);
2313 : /* libspdm_zero_mem (ptr, hash_size);
2314 : * ptr += hash_size;*/
2315 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
2316 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
2317 1 : libspdm_build_opaque_data_version_selection_data(
2318 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2319 : &opaque_psk_exchange_rsp_size, ptr);
2320 1 : ptr += opaque_psk_exchange_rsp_size;
2321 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2322 : sizeof(m_libspdm_local_buffer)
2323 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2324 : m_libspdm_local_buffer),
2325 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2326 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2327 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2328 : m_libspdm_local_buffer_size));
2329 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2330 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2331 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2332 : m_libspdm_use_asym_algo, &data,
2333 : &data_size, NULL, NULL);
2334 1 : cert_buffer =
2335 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
2336 1 : cert_buffer_size =
2337 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
2338 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2339 : cert_buffer_hash);
2340 : /* transcript.message_a size is 0*/
2341 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2342 : m_libspdm_local_buffer_size);
2343 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2344 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2345 1 : free(data);
2346 1 : bin_str2_size = sizeof(bin_str2);
2347 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2348 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
2349 1 : hash_data, (uint16_t)hash_size, hash_size,
2350 : bin_str2, &bin_str2_size);
2351 1 : libspdm_psk_handshake_secret_hkdf_expand(
2352 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2353 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
2354 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
2355 : bin_str2_size,
2356 : response_handshake_secret, hash_size);
2357 1 : bin_str7_size = sizeof(bin_str7);
2358 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2359 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
2360 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2361 : &bin_str7_size);
2362 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2363 : hash_size, bin_str7, bin_str7_size,
2364 : response_finished_key, hash_size);
2365 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2366 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2367 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2368 : response_finished_key, hash_size, ptr);
2369 1 : ptr += hmac_size;
2370 :
2371 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2372 : false, spdm_response_size,
2373 : spdm_response, response_size,
2374 : response);
2375 : }
2376 1 : return LIBSPDM_STATUS_SUCCESS;
2377 :
2378 1 : case 0x16: {
2379 : spdm_psk_exchange_response_t *spdm_response;
2380 : uint32_t hash_size;
2381 : uint32_t hmac_size;
2382 : uint8_t *ptr;
2383 : size_t opaque_psk_exchange_rsp_size;
2384 : void *data;
2385 : size_t data_size;
2386 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2387 : uint8_t *cert_buffer;
2388 : size_t cert_buffer_size;
2389 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2390 : uint8_t bin_str2[128];
2391 : size_t bin_str2_size;
2392 : uint8_t bin_str7[128];
2393 : size_t bin_str7_size;
2394 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2395 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2396 : size_t spdm_response_size;
2397 : size_t transport_header_size;
2398 :
2399 :
2400 : ((libspdm_context_t *)spdm_context)
2401 1 : ->connection_info.algorithm.base_asym_algo =
2402 : m_libspdm_use_asym_algo;
2403 : ((libspdm_context_t *)spdm_context)
2404 1 : ->connection_info.algorithm.base_hash_algo =
2405 : m_libspdm_use_hash_algo;
2406 : ((libspdm_context_t *)spdm_context)
2407 1 : ->connection_info.algorithm.dhe_named_group =
2408 : m_libspdm_use_dhe_algo;
2409 : ((libspdm_context_t *)spdm_context)
2410 1 : ->connection_info.algorithm.measurement_hash_algo =
2411 : m_libspdm_use_measurement_hash_algo;
2412 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2413 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2414 1 : opaque_psk_exchange_rsp_size =
2415 1 : libspdm_get_opaque_data_version_selection_data_size(
2416 : spdm_context);
2417 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
2418 : LIBSPDM_PSK_CONTEXT_LENGTH +
2419 1 : opaque_psk_exchange_rsp_size + hmac_size;
2420 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2421 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2422 :
2423 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2424 1 : spdm_response->header.request_response_code =
2425 : SPDM_PSK_EXCHANGE_RSP;
2426 1 : spdm_response->header.param1 = 0;
2427 1 : spdm_response->header.param2 = 0;
2428 1 : spdm_response->rsp_session_id =
2429 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
2430 1 : spdm_response->reserved = 0;
2431 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
2432 1 : spdm_response->opaque_length =
2433 1 : (uint16_t)opaque_psk_exchange_rsp_size;
2434 1 : ptr = (void *)(spdm_response + 1);
2435 : /* libspdm_zero_mem (ptr, hash_size);
2436 : * ptr += hash_size;*/
2437 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
2438 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
2439 1 : libspdm_build_opaque_data_version_selection_data(
2440 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2441 : &opaque_psk_exchange_rsp_size, ptr);
2442 1 : ptr += opaque_psk_exchange_rsp_size;
2443 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2444 : sizeof(m_libspdm_local_buffer)
2445 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2446 : m_libspdm_local_buffer),
2447 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2448 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2449 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2450 : m_libspdm_local_buffer_size));
2451 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2452 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2453 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2454 : m_libspdm_use_asym_algo, &data,
2455 : &data_size, NULL, NULL);
2456 1 : cert_buffer =
2457 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
2458 1 : cert_buffer_size =
2459 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
2460 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2461 : cert_buffer_hash);
2462 : /* transcript.message_a size is 0*/
2463 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2464 : m_libspdm_local_buffer_size);
2465 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2466 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2467 1 : free(data);
2468 1 : bin_str2_size = sizeof(bin_str2);
2469 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2470 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
2471 1 : hash_data, (uint16_t)hash_size, hash_size,
2472 : bin_str2, &bin_str2_size);
2473 1 : libspdm_psk_handshake_secret_hkdf_expand(
2474 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2475 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
2476 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
2477 : bin_str2_size,
2478 : response_handshake_secret, hash_size);
2479 1 : bin_str7_size = sizeof(bin_str7);
2480 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2481 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
2482 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2483 : &bin_str7_size);
2484 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2485 : hash_size, bin_str7, bin_str7_size,
2486 : response_finished_key, hash_size);
2487 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2488 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2489 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2490 : response_finished_key, hash_size, ptr);
2491 1 : ptr += hmac_size;
2492 :
2493 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2494 : false, spdm_response_size,
2495 : spdm_response, response_size,
2496 : response);
2497 : }
2498 1 : return LIBSPDM_STATUS_SUCCESS;
2499 :
2500 1 : case 0x17: {
2501 : spdm_psk_exchange_response_t *spdm_response;
2502 : uint32_t hash_size;
2503 : uint32_t hmac_size;
2504 : uint8_t *ptr;
2505 : size_t opaque_psk_exchange_rsp_size;
2506 : void *data;
2507 : size_t data_size;
2508 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2509 : uint8_t *cert_buffer;
2510 : size_t cert_buffer_size;
2511 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2512 : uint8_t bin_str2[128];
2513 : size_t bin_str2_size;
2514 : uint8_t bin_str7[128];
2515 : size_t bin_str7_size;
2516 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2517 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2518 : size_t spdm_response_size;
2519 : size_t transport_header_size;
2520 :
2521 :
2522 : ((libspdm_context_t *)spdm_context)
2523 1 : ->connection_info.algorithm.base_asym_algo =
2524 : m_libspdm_use_asym_algo;
2525 : ((libspdm_context_t *)spdm_context)
2526 1 : ->connection_info.algorithm.base_hash_algo =
2527 : m_libspdm_use_hash_algo;
2528 : ((libspdm_context_t *)spdm_context)
2529 1 : ->connection_info.algorithm.dhe_named_group =
2530 : m_libspdm_use_dhe_algo;
2531 : ((libspdm_context_t *)spdm_context)
2532 1 : ->connection_info.algorithm.measurement_hash_algo =
2533 : m_libspdm_use_measurement_hash_algo;
2534 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2535 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2536 1 : opaque_psk_exchange_rsp_size =
2537 1 : libspdm_get_opaque_data_version_selection_data_size(
2538 : spdm_context);
2539 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
2540 : LIBSPDM_PSK_CONTEXT_LENGTH +
2541 1 : opaque_psk_exchange_rsp_size + hmac_size;
2542 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2543 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2544 :
2545 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2546 1 : spdm_response->header.request_response_code =
2547 : SPDM_PSK_EXCHANGE_RSP;
2548 1 : spdm_response->header.param1 = 0;
2549 1 : spdm_response->header.param2 = 0;
2550 1 : spdm_response->rsp_session_id =
2551 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
2552 1 : spdm_response->reserved = 0;
2553 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
2554 1 : spdm_response->opaque_length =
2555 1 : (uint16_t)opaque_psk_exchange_rsp_size;
2556 1 : ptr = (void *)(spdm_response + 1);
2557 : /* libspdm_zero_mem (ptr, hash_size);
2558 : * ptr += hash_size;*/
2559 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
2560 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
2561 1 : libspdm_build_opaque_data_version_selection_data(
2562 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2563 : &opaque_psk_exchange_rsp_size, ptr);
2564 1 : ptr += opaque_psk_exchange_rsp_size;
2565 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2566 : sizeof(m_libspdm_local_buffer)
2567 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2568 : m_libspdm_local_buffer),
2569 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2570 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2571 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2572 : m_libspdm_local_buffer_size));
2573 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2574 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2575 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2576 : m_libspdm_use_asym_algo, &data,
2577 : &data_size, NULL, NULL);
2578 1 : cert_buffer =
2579 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
2580 1 : cert_buffer_size =
2581 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
2582 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2583 : cert_buffer_hash);
2584 : /* transcript.message_a size is 0*/
2585 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2586 : m_libspdm_local_buffer_size);
2587 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2588 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2589 1 : free(data);
2590 1 : bin_str2_size = sizeof(bin_str2);
2591 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2592 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
2593 1 : hash_data, (uint16_t)hash_size, hash_size,
2594 : bin_str2, &bin_str2_size);
2595 1 : libspdm_psk_handshake_secret_hkdf_expand(
2596 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2597 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
2598 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
2599 : bin_str2_size,
2600 : response_handshake_secret, hash_size);
2601 1 : bin_str7_size = sizeof(bin_str7);
2602 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2603 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
2604 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2605 : &bin_str7_size);
2606 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2607 : hash_size, bin_str7, bin_str7_size,
2608 : response_finished_key, hash_size);
2609 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2610 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2611 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2612 : response_finished_key, hash_size, ptr);
2613 : /* Flip last byte of ResponderVerifyData*/
2614 1 : ptr += hmac_size-1;
2615 1 : *ptr ^= 0xFF;
2616 1 : ptr++;
2617 :
2618 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2619 : false, spdm_response_size,
2620 : spdm_response, response_size,
2621 : response);
2622 : }
2623 1 : return LIBSPDM_STATUS_SUCCESS;
2624 :
2625 1 : case 0x18: {
2626 : spdm_psk_exchange_response_t *spdm_response;
2627 : uint32_t hash_size;
2628 : uint32_t hmac_size;
2629 : uint8_t *ptr;
2630 : size_t opaque_psk_exchange_rsp_size;
2631 : void *data;
2632 : size_t data_size;
2633 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2634 : uint8_t *cert_buffer;
2635 : size_t cert_buffer_size;
2636 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2637 : uint8_t bin_str2[128];
2638 : size_t bin_str2_size;
2639 : uint8_t bin_str7[128];
2640 : size_t bin_str7_size;
2641 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2642 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2643 : size_t spdm_response_size;
2644 : size_t transport_header_size;
2645 :
2646 :
2647 : ((libspdm_context_t *)spdm_context)
2648 1 : ->connection_info.algorithm.base_asym_algo =
2649 : m_libspdm_use_asym_algo;
2650 : ((libspdm_context_t *)spdm_context)
2651 1 : ->connection_info.algorithm.base_hash_algo =
2652 : m_libspdm_use_hash_algo;
2653 : ((libspdm_context_t *)spdm_context)
2654 1 : ->connection_info.algorithm.dhe_named_group =
2655 : m_libspdm_use_dhe_algo;
2656 : ((libspdm_context_t *)spdm_context)
2657 1 : ->connection_info.algorithm.measurement_hash_algo =
2658 : m_libspdm_use_measurement_hash_algo;
2659 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2660 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2661 1 : opaque_psk_exchange_rsp_size =
2662 1 : libspdm_get_opaque_data_version_selection_data_size(
2663 : spdm_context);
2664 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
2665 : 0 +
2666 1 : opaque_psk_exchange_rsp_size + hmac_size;
2667 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2668 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2669 :
2670 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2671 1 : spdm_response->header.request_response_code =
2672 : SPDM_PSK_EXCHANGE_RSP;
2673 1 : spdm_response->header.param1 = 0;
2674 1 : spdm_response->header.param2 = 0;
2675 1 : spdm_response->rsp_session_id =
2676 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
2677 1 : spdm_response->reserved = 0;
2678 1 : spdm_response->context_length = 0;
2679 1 : spdm_response->opaque_length =
2680 1 : (uint16_t)opaque_psk_exchange_rsp_size;
2681 1 : ptr = (void *)(spdm_response + 1);
2682 : /* libspdm_zero_mem (ptr, hash_size);
2683 : * ptr += hash_size;*/
2684 : /* libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
2685 : * ptr += LIBSPDM_PSK_CONTEXT_LENGTH;*/
2686 1 : libspdm_build_opaque_data_version_selection_data(
2687 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
2688 : &opaque_psk_exchange_rsp_size, ptr);
2689 1 : ptr += opaque_psk_exchange_rsp_size;
2690 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2691 : sizeof(m_libspdm_local_buffer)
2692 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2693 : m_libspdm_local_buffer),
2694 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2695 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2696 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2697 : m_libspdm_local_buffer_size));
2698 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2699 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2700 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2701 : m_libspdm_use_asym_algo, &data,
2702 : &data_size, NULL, NULL);
2703 1 : cert_buffer =
2704 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
2705 1 : cert_buffer_size =
2706 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
2707 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2708 : cert_buffer_hash);
2709 : /* transcript.message_a size is 0*/
2710 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2711 : m_libspdm_local_buffer_size);
2712 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2713 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2714 1 : free(data);
2715 1 : bin_str2_size = sizeof(bin_str2);
2716 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2717 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
2718 1 : hash_data, (uint16_t)hash_size, hash_size,
2719 : bin_str2, &bin_str2_size);
2720 1 : libspdm_psk_handshake_secret_hkdf_expand(
2721 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2722 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
2723 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
2724 : bin_str2_size,
2725 : response_handshake_secret, hash_size);
2726 1 : bin_str7_size = sizeof(bin_str7);
2727 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2728 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
2729 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2730 : &bin_str7_size);
2731 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2732 : hash_size, bin_str7, bin_str7_size,
2733 : response_finished_key, hash_size);
2734 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2735 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2736 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2737 : response_finished_key, hash_size, ptr);
2738 1 : ptr += hmac_size;
2739 :
2740 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2741 : false, spdm_response_size,
2742 : spdm_response, response_size,
2743 : response);
2744 : }
2745 1 : return LIBSPDM_STATUS_SUCCESS;
2746 :
2747 1 : case 0x19: {
2748 : spdm_psk_exchange_response_t *spdm_response;
2749 : uint32_t hash_size;
2750 : uint32_t hmac_size;
2751 : uint8_t *ptr;
2752 : size_t opaque_psk_exchange_rsp_size;
2753 : void *data;
2754 : size_t data_size;
2755 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2756 : uint8_t *cert_buffer;
2757 : size_t cert_buffer_size;
2758 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2759 : uint8_t bin_str2[128];
2760 : size_t bin_str2_size;
2761 : uint8_t bin_str7[128];
2762 : size_t bin_str7_size;
2763 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2764 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2765 : size_t spdm_response_size;
2766 : size_t transport_header_size;
2767 :
2768 :
2769 : ((libspdm_context_t *)spdm_context)
2770 1 : ->connection_info.algorithm.base_asym_algo =
2771 : m_libspdm_use_asym_algo;
2772 : ((libspdm_context_t *)spdm_context)
2773 1 : ->connection_info.algorithm.base_hash_algo =
2774 : m_libspdm_use_hash_algo;
2775 : ((libspdm_context_t *)spdm_context)
2776 1 : ->connection_info.algorithm.dhe_named_group =
2777 : m_libspdm_use_dhe_algo;
2778 : ((libspdm_context_t *)spdm_context)
2779 1 : ->connection_info.algorithm.measurement_hash_algo =
2780 : m_libspdm_use_measurement_hash_algo;
2781 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2782 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2783 1 : opaque_psk_exchange_rsp_size = 0;
2784 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
2785 : LIBSPDM_PSK_CONTEXT_LENGTH +
2786 1 : opaque_psk_exchange_rsp_size + hmac_size;
2787 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2788 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2789 :
2790 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2791 1 : spdm_response->header.request_response_code =
2792 : SPDM_PSK_EXCHANGE_RSP;
2793 1 : spdm_response->header.param1 = 0;
2794 1 : spdm_response->header.param2 = 0;
2795 1 : spdm_response->rsp_session_id =
2796 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
2797 1 : spdm_response->reserved = 0;
2798 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
2799 1 : spdm_response->opaque_length =
2800 1 : (uint16_t)opaque_psk_exchange_rsp_size;
2801 1 : ptr = (void *)(spdm_response + 1);
2802 : /* libspdm_zero_mem (ptr, hash_size);
2803 : * ptr += hash_size;*/
2804 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
2805 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
2806 : /* libspdm_build_opaque_data_version_selection_data(
2807 : * spdm_context, &opaque_psk_exchange_rsp_size, ptr);
2808 : * ptr += opaque_psk_exchange_rsp_size;*/
2809 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2810 : sizeof(m_libspdm_local_buffer)
2811 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2812 : m_libspdm_local_buffer),
2813 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2814 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2815 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2816 : m_libspdm_local_buffer_size));
2817 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2818 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2819 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2820 : m_libspdm_use_asym_algo, &data,
2821 : &data_size, NULL, NULL);
2822 1 : cert_buffer =
2823 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
2824 1 : cert_buffer_size =
2825 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
2826 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2827 : cert_buffer_hash);
2828 : /* transcript.message_a size is 0*/
2829 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2830 : m_libspdm_local_buffer_size);
2831 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2832 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2833 1 : free(data);
2834 1 : bin_str2_size = sizeof(bin_str2);
2835 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2836 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
2837 1 : hash_data, (uint16_t)hash_size, hash_size,
2838 : bin_str2, &bin_str2_size);
2839 1 : libspdm_psk_handshake_secret_hkdf_expand(
2840 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2841 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
2842 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
2843 : bin_str2_size,
2844 : response_handshake_secret, hash_size);
2845 1 : bin_str7_size = sizeof(bin_str7);
2846 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2847 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
2848 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2849 : &bin_str7_size);
2850 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2851 : hash_size, bin_str7, bin_str7_size,
2852 : response_finished_key, hash_size);
2853 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2854 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2855 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2856 : response_finished_key, hash_size, ptr);
2857 1 : ptr += hmac_size;
2858 :
2859 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2860 : false, spdm_response_size,
2861 : spdm_response, response_size,
2862 : response);
2863 : }
2864 1 : return LIBSPDM_STATUS_SUCCESS;
2865 :
2866 1 : case 0x1A: {
2867 : spdm_psk_exchange_response_t *spdm_response;
2868 : uint32_t hash_size;
2869 : uint32_t hmac_size;
2870 : uint8_t *ptr;
2871 : size_t opaque_psk_exchange_rsp_size;
2872 : void *data;
2873 : size_t data_size;
2874 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2875 : uint8_t *cert_buffer;
2876 : size_t cert_buffer_size;
2877 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2878 : uint8_t bin_str2[128];
2879 : size_t bin_str2_size;
2880 : uint8_t bin_str7[128];
2881 : size_t bin_str7_size;
2882 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
2883 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
2884 : size_t spdm_response_size;
2885 : size_t transport_header_size;
2886 :
2887 :
2888 : ((libspdm_context_t *)spdm_context)
2889 1 : ->connection_info.algorithm.base_asym_algo =
2890 : m_libspdm_use_asym_algo;
2891 : ((libspdm_context_t *)spdm_context)
2892 1 : ->connection_info.algorithm.base_hash_algo =
2893 : m_libspdm_use_hash_algo;
2894 : ((libspdm_context_t *)spdm_context)
2895 1 : ->connection_info.algorithm.dhe_named_group =
2896 : m_libspdm_use_dhe_algo;
2897 : ((libspdm_context_t *)spdm_context)
2898 1 : ->connection_info.algorithm.measurement_hash_algo =
2899 : m_libspdm_use_measurement_hash_algo;
2900 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2901 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
2902 1 : opaque_psk_exchange_rsp_size = 0;
2903 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
2904 : 0 +
2905 1 : opaque_psk_exchange_rsp_size + hmac_size;
2906 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2907 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2908 :
2909 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2910 1 : spdm_response->header.request_response_code =
2911 : SPDM_PSK_EXCHANGE_RSP;
2912 1 : spdm_response->header.param1 = 0;
2913 1 : spdm_response->header.param2 = 0;
2914 1 : spdm_response->rsp_session_id =
2915 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
2916 1 : spdm_response->reserved = 0;
2917 1 : spdm_response->context_length = 0;
2918 1 : spdm_response->opaque_length =
2919 1 : (uint16_t)opaque_psk_exchange_rsp_size;
2920 1 : ptr = (void *)(spdm_response + 1);
2921 : /* libspdm_zero_mem (ptr, hash_size);
2922 : * ptr += hash_size;*/
2923 : /*libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
2924 : * ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
2925 : * libspdm_build_opaque_data_version_selection_data(
2926 : * spdm_context, &opaque_psk_exchange_rsp_size, ptr);
2927 : * ptr += opaque_psk_exchange_rsp_size;*/
2928 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2929 : sizeof(m_libspdm_local_buffer)
2930 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2931 : m_libspdm_local_buffer),
2932 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2933 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2934 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2935 : m_libspdm_local_buffer_size));
2936 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2937 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
2938 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
2939 : m_libspdm_use_asym_algo, &data,
2940 : &data_size, NULL, NULL);
2941 1 : cert_buffer =
2942 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
2943 1 : cert_buffer_size =
2944 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
2945 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
2946 : cert_buffer_hash);
2947 : /* transcript.message_a size is 0*/
2948 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
2949 : m_libspdm_local_buffer_size);
2950 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2951 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2952 1 : free(data);
2953 1 : bin_str2_size = sizeof(bin_str2);
2954 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2955 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
2956 1 : hash_data, (uint16_t)hash_size, hash_size,
2957 : bin_str2, &bin_str2_size);
2958 1 : libspdm_psk_handshake_secret_hkdf_expand(
2959 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2960 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
2961 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
2962 : bin_str2_size,
2963 : response_handshake_secret, hash_size);
2964 1 : bin_str7_size = sizeof(bin_str7);
2965 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
2966 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
2967 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
2968 : &bin_str7_size);
2969 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
2970 : hash_size, bin_str7, bin_str7_size,
2971 : response_finished_key, hash_size);
2972 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
2973 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
2974 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
2975 : response_finished_key, hash_size, ptr);
2976 1 : ptr += hmac_size;
2977 :
2978 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2979 : false, spdm_response_size,
2980 : spdm_response, response_size,
2981 : response);
2982 : }
2983 1 : return LIBSPDM_STATUS_SUCCESS;
2984 1 : case 0x1B: {
2985 : spdm_psk_exchange_response_t *spdm_response;
2986 : uint32_t hash_size;
2987 : uint32_t hmac_size;
2988 : uint8_t *ptr;
2989 : size_t opaque_psk_exchange_rsp_size;
2990 : void *data;
2991 : size_t data_size;
2992 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2993 : uint8_t *cert_buffer;
2994 : size_t cert_buffer_size;
2995 : uint8_t cert_buffer_hash[LIBSPDM_MAX_HASH_SIZE];
2996 : uint8_t bin_str2[128];
2997 : size_t bin_str2_size;
2998 : uint8_t bin_str7[128];
2999 : size_t bin_str7_size;
3000 : uint8_t response_handshake_secret[LIBSPDM_MAX_HASH_SIZE];
3001 : uint8_t response_finished_key[LIBSPDM_MAX_HASH_SIZE];
3002 : size_t spdm_response_size;
3003 : size_t transport_header_size;
3004 :
3005 :
3006 : ((libspdm_context_t *)spdm_context)
3007 1 : ->connection_info.algorithm.base_asym_algo =
3008 : m_libspdm_use_asym_algo;
3009 : ((libspdm_context_t *)spdm_context)
3010 1 : ->connection_info.algorithm.base_hash_algo =
3011 : m_libspdm_use_hash_algo;
3012 : ((libspdm_context_t *)spdm_context)
3013 1 : ->connection_info.algorithm.dhe_named_group =
3014 : m_libspdm_use_dhe_algo;
3015 : ((libspdm_context_t *)spdm_context)
3016 1 : ->connection_info.algorithm.measurement_hash_algo =
3017 : m_libspdm_use_measurement_hash_algo;
3018 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3019 1 : hmac_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
3020 1 : opaque_psk_exchange_rsp_size =
3021 1 : libspdm_get_opaque_data_version_selection_data_size(
3022 : spdm_context);
3023 1 : spdm_response_size = sizeof(spdm_psk_exchange_response_t) + 0 +
3024 : LIBSPDM_PSK_CONTEXT_LENGTH +
3025 1 : opaque_psk_exchange_rsp_size + hmac_size;
3026 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
3027 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
3028 :
3029 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
3030 1 : spdm_response->header.request_response_code =
3031 : SPDM_PSK_EXCHANGE_RSP;
3032 1 : spdm_response->header.param1 = 0;
3033 1 : spdm_response->header.param2 = 0;
3034 1 : spdm_response->rsp_session_id =
3035 1 : libspdm_allocate_rsp_session_id(spdm_context, true);
3036 1 : spdm_response->reserved = 0;
3037 1 : spdm_response->context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
3038 1 : spdm_response->opaque_length =
3039 1 : (uint16_t)opaque_psk_exchange_rsp_size;
3040 1 : ptr = (void *)(spdm_response + 1);
3041 : /* libspdm_zero_mem (ptr, hash_size);
3042 : * ptr += hash_size;*/
3043 1 : libspdm_get_random_number(LIBSPDM_PSK_CONTEXT_LENGTH, ptr);
3044 1 : ptr += LIBSPDM_PSK_CONTEXT_LENGTH;
3045 1 : libspdm_build_opaque_data_version_selection_data(
3046 : spdm_context, SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT,
3047 : &opaque_psk_exchange_rsp_size, ptr);
3048 1 : ptr += opaque_psk_exchange_rsp_size;
3049 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
3050 : sizeof(m_libspdm_local_buffer)
3051 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
3052 : m_libspdm_local_buffer),
3053 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
3054 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
3055 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
3056 : m_libspdm_local_buffer_size));
3057 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3058 1 : libspdm_init_managed_buffer(&th_curr, sizeof(th_curr.buffer));
3059 1 : libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3060 : m_libspdm_use_asym_algo, &data,
3061 : &data_size, NULL, NULL);
3062 1 : cert_buffer =
3063 1 : (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size;
3064 1 : cert_buffer_size =
3065 1 : data_size - (sizeof(spdm_cert_chain_t) + hash_size);
3066 1 : libspdm_hash_all(m_libspdm_use_hash_algo, cert_buffer, cert_buffer_size,
3067 : cert_buffer_hash);
3068 : /* transcript.message_a size is 0*/
3069 1 : libspdm_append_managed_buffer(&th_curr, m_libspdm_local_buffer,
3070 : m_libspdm_local_buffer_size);
3071 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3072 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3073 1 : free(data);
3074 1 : bin_str2_size = sizeof(bin_str2);
3075 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3076 : LIBSPDM_BIN_STR_2_LABEL, sizeof(LIBSPDM_BIN_STR_2_LABEL) - 1,
3077 1 : hash_data, (uint16_t)hash_size, hash_size,
3078 : bin_str2, &bin_str2_size);
3079 1 : libspdm_psk_handshake_secret_hkdf_expand(
3080 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
3081 : m_libspdm_use_hash_algo, (const uint8_t *)LIBSPDM_TEST_PSK_HINT_STRING,
3082 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING), bin_str2,
3083 : bin_str2_size,
3084 : response_handshake_secret, hash_size);
3085 1 : bin_str7_size = sizeof(bin_str7);
3086 1 : libspdm_bin_concat(((libspdm_context_t *)spdm_context)->connection_info.version,
3087 : LIBSPDM_BIN_STR_7_LABEL, sizeof(LIBSPDM_BIN_STR_7_LABEL) - 1,
3088 1 : NULL, (uint16_t)hash_size, hash_size, bin_str7,
3089 : &bin_str7_size);
3090 1 : libspdm_hkdf_expand(m_libspdm_use_hash_algo, response_handshake_secret,
3091 : hash_size, bin_str7, bin_str7_size,
3092 : response_finished_key, hash_size);
3093 1 : libspdm_hash_all(m_libspdm_use_hash_algo, libspdm_get_managed_buffer(&th_curr),
3094 : libspdm_get_managed_buffer_size(&th_curr), hash_data);
3095 1 : libspdm_hmac_all(m_libspdm_use_hash_algo, hash_data, hash_size,
3096 : response_finished_key, hash_size, ptr);
3097 1 : ptr += hmac_size;
3098 :
3099 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3100 : false, spdm_response_size,
3101 : spdm_response, response_size,
3102 : response);
3103 : }
3104 1 : return LIBSPDM_STATUS_SUCCESS;
3105 :
3106 0 : default:
3107 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
3108 : }
3109 : }
3110 :
3111 1 : static void req_psk_exchange_case1(void **state)
3112 : {
3113 : libspdm_return_t status;
3114 : libspdm_test_context_t *spdm_test_context;
3115 : libspdm_context_t *spdm_context;
3116 : uint32_t session_id;
3117 : uint8_t heartbeat_period;
3118 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3119 : void *data;
3120 : size_t data_size;
3121 : void *hash;
3122 : size_t hash_size;
3123 :
3124 1 : spdm_test_context = *state;
3125 1 : spdm_context = spdm_test_context->spdm_context;
3126 1 : spdm_test_context->case_id = 0x1;
3127 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3128 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3129 1 : spdm_context->connection_info.connection_state =
3130 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3131 1 : spdm_context->connection_info.capability.flags &=
3132 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3133 1 : spdm_context->connection_info.capability.flags |=
3134 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT |
3135 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
3136 1 : spdm_context->local_context.capability.flags |=
3137 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER |
3138 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
3139 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3140 : m_libspdm_use_asym_algo, &data,
3141 : &data_size, &hash, &hash_size)) {
3142 0 : assert(false);
3143 : }
3144 1 : libspdm_reset_message_a(spdm_context);
3145 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3146 : m_libspdm_use_hash_algo;
3147 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3148 : m_libspdm_use_dhe_algo;
3149 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3150 : m_libspdm_use_aead_algo;
3151 1 : spdm_context->connection_info.algorithm.key_schedule =
3152 : m_libspdm_use_key_schedule_algo;
3153 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3154 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3155 : data_size;
3156 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3157 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3158 : data, data_size);
3159 : #endif
3160 :
3161 1 : heartbeat_period = 0;
3162 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3163 1 : status = libspdm_send_receive_psk_exchange(
3164 : spdm_context, NULL, 0,
3165 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3166 : &heartbeat_period, measurement_hash);
3167 1 : assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
3168 1 : free(data);
3169 1 : }
3170 :
3171 1 : static void req_psk_exchange_case2(void **state)
3172 : {
3173 : libspdm_return_t status;
3174 : libspdm_test_context_t *spdm_test_context;
3175 : libspdm_context_t *spdm_context;
3176 : uint32_t session_id;
3177 : uint8_t heartbeat_period;
3178 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3179 : void *data;
3180 : size_t data_size;
3181 : void *hash;
3182 : size_t hash_size;
3183 :
3184 1 : spdm_test_context = *state;
3185 1 : spdm_context = spdm_test_context->spdm_context;
3186 1 : spdm_test_context->case_id = 0x2;
3187 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3188 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3189 1 : spdm_context->connection_info.connection_state =
3190 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3191 1 : spdm_context->connection_info.capability.flags &=
3192 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3193 1 : spdm_context->connection_info.capability.flags |=
3194 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3195 1 : spdm_context->local_context.capability.flags |=
3196 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3197 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
3198 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
3199 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
3200 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3201 : m_libspdm_use_asym_algo, &data,
3202 : &data_size, &hash, &hash_size)) {
3203 0 : assert(false);
3204 : }
3205 1 : libspdm_reset_message_a(spdm_context);
3206 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3207 : m_libspdm_use_hash_algo;
3208 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3209 : m_libspdm_use_dhe_algo;
3210 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3211 : m_libspdm_use_aead_algo;
3212 1 : spdm_context->connection_info.algorithm.key_schedule =
3213 : m_libspdm_use_key_schedule_algo;
3214 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3215 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3216 : data_size;
3217 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3218 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3219 : data, data_size);
3220 : #endif
3221 :
3222 1 : heartbeat_period = 0;
3223 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3224 1 : status = libspdm_send_receive_psk_exchange(
3225 : spdm_context,
3226 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3227 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3228 : &heartbeat_period, measurement_hash);
3229 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3230 1 : assert_int_equal(session_id, 0xFFFFFFFF);
3231 1 : assert_int_equal(
3232 : libspdm_secured_message_get_session_state(
3233 : spdm_context->session_info[0].secured_message_context),
3234 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3235 1 : free(data);
3236 1 : }
3237 :
3238 1 : static void req_psk_exchange_case3(void **state)
3239 : {
3240 : libspdm_return_t status;
3241 : libspdm_test_context_t *spdm_test_context;
3242 : libspdm_context_t *spdm_context;
3243 : uint32_t session_id;
3244 : uint8_t heartbeat_period;
3245 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3246 : void *data;
3247 : size_t data_size;
3248 : void *hash;
3249 : size_t hash_size;
3250 :
3251 1 : spdm_test_context = *state;
3252 1 : spdm_context = spdm_test_context->spdm_context;
3253 1 : spdm_test_context->case_id = 0x3;
3254 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3255 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3256 1 : spdm_context->connection_info.connection_state =
3257 : LIBSPDM_CONNECTION_STATE_NOT_STARTED;
3258 1 : spdm_context->connection_info.capability.flags &=
3259 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3260 1 : spdm_context->connection_info.capability.flags |=
3261 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3262 1 : spdm_context->local_context.capability.flags |=
3263 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3264 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3265 : m_libspdm_use_asym_algo, &data,
3266 : &data_size, &hash, &hash_size)) {
3267 0 : assert(false);
3268 : }
3269 1 : libspdm_reset_message_a(spdm_context);
3270 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3271 : m_libspdm_use_hash_algo;
3272 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3273 : m_libspdm_use_dhe_algo;
3274 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3275 : m_libspdm_use_aead_algo;
3276 1 : spdm_context->connection_info.algorithm.key_schedule =
3277 : m_libspdm_use_key_schedule_algo;
3278 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3279 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3280 : data_size;
3281 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3282 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3283 : data, data_size);
3284 : #endif
3285 :
3286 1 : heartbeat_period = 0;
3287 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3288 1 : status = libspdm_send_receive_psk_exchange(
3289 : spdm_context,
3290 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3291 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3292 : &heartbeat_period, measurement_hash);
3293 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
3294 1 : free(data);
3295 1 : }
3296 :
3297 1 : static void req_psk_exchange_case4(void **state)
3298 : {
3299 : libspdm_return_t status;
3300 : libspdm_test_context_t *spdm_test_context;
3301 : libspdm_context_t *spdm_context;
3302 : uint32_t session_id;
3303 : uint8_t heartbeat_period;
3304 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3305 : void *data;
3306 : size_t data_size;
3307 : void *hash;
3308 : size_t hash_size;
3309 :
3310 1 : spdm_test_context = *state;
3311 1 : spdm_context = spdm_test_context->spdm_context;
3312 1 : spdm_test_context->case_id = 0x4;
3313 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3314 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3315 1 : spdm_context->connection_info.connection_state =
3316 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3317 1 : spdm_context->connection_info.capability.flags &=
3318 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3319 1 : spdm_context->connection_info.capability.flags |=
3320 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3321 1 : spdm_context->local_context.capability.flags |=
3322 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3323 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3324 : m_libspdm_use_asym_algo, &data,
3325 : &data_size, &hash, &hash_size)) {
3326 0 : assert(false);
3327 : }
3328 1 : libspdm_reset_message_a(spdm_context);
3329 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3330 : m_libspdm_use_hash_algo;
3331 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3332 : m_libspdm_use_dhe_algo;
3333 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3334 : m_libspdm_use_aead_algo;
3335 1 : spdm_context->connection_info.algorithm.key_schedule =
3336 : m_libspdm_use_key_schedule_algo;
3337 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3338 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3339 : data_size;
3340 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3341 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3342 : data, data_size);
3343 : #endif
3344 :
3345 1 : heartbeat_period = 0;
3346 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3347 1 : status = libspdm_send_receive_psk_exchange(
3348 : spdm_context,
3349 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3350 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3351 : &heartbeat_period, measurement_hash);
3352 1 : assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
3353 1 : free(data);
3354 1 : }
3355 :
3356 1 : static void req_psk_exchange_case5(void **state)
3357 : {
3358 : libspdm_return_t status;
3359 : libspdm_test_context_t *spdm_test_context;
3360 : libspdm_context_t *spdm_context;
3361 : uint32_t session_id;
3362 : uint8_t heartbeat_period;
3363 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3364 : void *data;
3365 : size_t data_size;
3366 : void *hash;
3367 : size_t hash_size;
3368 :
3369 1 : spdm_test_context = *state;
3370 1 : spdm_context = spdm_test_context->spdm_context;
3371 1 : spdm_test_context->case_id = 0x5;
3372 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3373 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3374 1 : spdm_context->connection_info.connection_state =
3375 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3376 1 : spdm_context->connection_info.capability.flags &=
3377 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3378 1 : spdm_context->connection_info.capability.flags |=
3379 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3380 1 : spdm_context->local_context.capability.flags |=
3381 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3382 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3383 : m_libspdm_use_asym_algo, &data,
3384 : &data_size, &hash, &hash_size)) {
3385 0 : assert(false);
3386 : }
3387 1 : libspdm_reset_message_a(spdm_context);
3388 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3389 : m_libspdm_use_hash_algo;
3390 1 : spdm_context->connection_info.algorithm.base_asym_algo =
3391 : m_libspdm_use_asym_algo;
3392 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3393 : m_libspdm_use_dhe_algo;
3394 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3395 : m_libspdm_use_aead_algo;
3396 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3397 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3398 : data_size;
3399 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3400 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3401 : data, data_size);
3402 : #endif
3403 :
3404 1 : heartbeat_period = 0;
3405 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3406 1 : status = libspdm_send_receive_psk_exchange(
3407 : spdm_context,
3408 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3409 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3410 : &heartbeat_period, measurement_hash);
3411 1 : assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
3412 1 : free(data);
3413 1 : }
3414 :
3415 1 : static void req_psk_exchange_case6(void **state)
3416 : {
3417 : libspdm_return_t status;
3418 : libspdm_test_context_t *spdm_test_context;
3419 : libspdm_context_t *spdm_context;
3420 : uint32_t session_id;
3421 : uint8_t heartbeat_period;
3422 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3423 : void *data;
3424 : size_t data_size;
3425 : void *hash;
3426 : size_t hash_size;
3427 :
3428 1 : spdm_test_context = *state;
3429 1 : spdm_context = spdm_test_context->spdm_context;
3430 1 : spdm_test_context->case_id = 0x6;
3431 1 : spdm_context->retry_times = 3;
3432 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3433 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3434 1 : spdm_context->connection_info.connection_state =
3435 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3436 1 : spdm_context->connection_info.capability.flags &=
3437 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3438 1 : spdm_context->connection_info.capability.flags |=
3439 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3440 1 : spdm_context->local_context.capability.flags |=
3441 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3442 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3443 : m_libspdm_use_asym_algo, &data,
3444 : &data_size, &hash, &hash_size)) {
3445 0 : assert(false);
3446 : }
3447 1 : libspdm_reset_message_a(spdm_context);
3448 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3449 : m_libspdm_use_hash_algo;
3450 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3451 : m_libspdm_use_dhe_algo;
3452 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3453 : m_libspdm_use_aead_algo;
3454 1 : spdm_context->connection_info.algorithm.key_schedule =
3455 : m_libspdm_use_key_schedule_algo;
3456 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3457 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3458 : data_size;
3459 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3460 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3461 : data, data_size);
3462 : #endif
3463 :
3464 1 : heartbeat_period = 0;
3465 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3466 1 : status = libspdm_send_receive_psk_exchange(
3467 : spdm_context,
3468 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3469 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3470 : &heartbeat_period, measurement_hash);
3471 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3472 1 : assert_int_equal(session_id, 0xFFFEFFFE);
3473 1 : assert_int_equal(
3474 : libspdm_secured_message_get_session_state(
3475 : spdm_context->session_info[0].secured_message_context),
3476 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3477 1 : free(data);
3478 1 : }
3479 :
3480 1 : static void req_psk_exchange_case7(void **state)
3481 : {
3482 : libspdm_return_t status;
3483 : libspdm_test_context_t *spdm_test_context;
3484 : libspdm_context_t *spdm_context;
3485 : uint32_t session_id;
3486 : uint8_t heartbeat_period;
3487 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3488 : void *data;
3489 : size_t data_size;
3490 : void *hash;
3491 : size_t hash_size;
3492 :
3493 1 : spdm_test_context = *state;
3494 1 : spdm_context = spdm_test_context->spdm_context;
3495 1 : spdm_test_context->case_id = 0x7;
3496 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3497 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3498 1 : spdm_context->connection_info.connection_state =
3499 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3500 1 : spdm_context->connection_info.capability.flags &=
3501 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3502 1 : spdm_context->connection_info.capability.flags |=
3503 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3504 1 : spdm_context->local_context.capability.flags |=
3505 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3506 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3507 : m_libspdm_use_asym_algo, &data,
3508 : &data_size, &hash, &hash_size)) {
3509 0 : assert(false);
3510 : }
3511 1 : libspdm_reset_message_a(spdm_context);
3512 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3513 : m_libspdm_use_hash_algo;
3514 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3515 : m_libspdm_use_dhe_algo;
3516 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3517 : m_libspdm_use_aead_algo;
3518 1 : spdm_context->connection_info.algorithm.key_schedule =
3519 : m_libspdm_use_key_schedule_algo;
3520 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3521 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3522 : data_size;
3523 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3524 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3525 : data, data_size);
3526 : #endif
3527 :
3528 1 : heartbeat_period = 0;
3529 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3530 1 : status = libspdm_send_receive_psk_exchange(
3531 : spdm_context,
3532 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3533 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3534 : &heartbeat_period, measurement_hash);
3535 1 : assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
3536 1 : assert_int_equal(spdm_context->connection_info.connection_state,
3537 : LIBSPDM_CONNECTION_STATE_NOT_STARTED);
3538 1 : free(data);
3539 1 : }
3540 :
3541 1 : static void req_psk_exchange_case8(void **state)
3542 : {
3543 : libspdm_return_t status;
3544 : libspdm_test_context_t *spdm_test_context;
3545 : libspdm_context_t *spdm_context;
3546 : uint32_t session_id;
3547 : uint8_t heartbeat_period;
3548 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3549 : void *data;
3550 : size_t data_size;
3551 : void *hash;
3552 : size_t hash_size;
3553 :
3554 1 : spdm_test_context = *state;
3555 1 : spdm_context = spdm_test_context->spdm_context;
3556 1 : spdm_test_context->case_id = 0x8;
3557 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3558 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3559 1 : spdm_context->connection_info.connection_state =
3560 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3561 1 : spdm_context->connection_info.capability.flags &=
3562 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3563 1 : spdm_context->connection_info.capability.flags |=
3564 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3565 1 : spdm_context->local_context.capability.flags |=
3566 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3567 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3568 : m_libspdm_use_asym_algo, &data,
3569 : &data_size, &hash, &hash_size)) {
3570 0 : assert(false);
3571 : }
3572 1 : libspdm_reset_message_a(spdm_context);
3573 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3574 : m_libspdm_use_hash_algo;
3575 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3576 : m_libspdm_use_dhe_algo;
3577 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3578 : m_libspdm_use_aead_algo;
3579 1 : spdm_context->connection_info.algorithm.key_schedule =
3580 : m_libspdm_use_key_schedule_algo;
3581 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3582 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3583 : data_size;
3584 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3585 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3586 : data, data_size);
3587 : #endif
3588 :
3589 1 : heartbeat_period = 0;
3590 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3591 1 : status = libspdm_send_receive_psk_exchange(
3592 : spdm_context,
3593 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3594 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3595 : &heartbeat_period, measurement_hash);
3596 1 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
3597 1 : free(data);
3598 1 : }
3599 :
3600 1 : static void req_psk_exchange_case9(void **state)
3601 : {
3602 : libspdm_return_t status;
3603 : libspdm_test_context_t *spdm_test_context;
3604 : libspdm_context_t *spdm_context;
3605 : uint32_t session_id;
3606 : uint8_t heartbeat_period;
3607 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3608 : void *data;
3609 : size_t data_size;
3610 : void *hash;
3611 : size_t hash_size;
3612 :
3613 1 : spdm_test_context = *state;
3614 1 : spdm_context = spdm_test_context->spdm_context;
3615 1 : spdm_test_context->case_id = 0x9;
3616 1 : spdm_context->retry_times = 3;
3617 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3618 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3619 1 : spdm_context->connection_info.connection_state =
3620 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3621 1 : spdm_context->connection_info.capability.flags &=
3622 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3623 1 : spdm_context->connection_info.capability.flags |=
3624 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3625 1 : spdm_context->local_context.capability.flags |=
3626 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3627 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3628 : m_libspdm_use_asym_algo, &data,
3629 : &data_size, &hash, &hash_size)) {
3630 0 : assert(false);
3631 : }
3632 1 : libspdm_reset_message_a(spdm_context);
3633 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3634 : m_libspdm_use_hash_algo;
3635 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3636 : m_libspdm_use_dhe_algo;
3637 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3638 : m_libspdm_use_aead_algo;
3639 1 : spdm_context->connection_info.algorithm.key_schedule =
3640 : m_libspdm_use_key_schedule_algo;
3641 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3642 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3643 : data_size;
3644 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3645 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3646 : data, data_size);
3647 : #endif
3648 :
3649 1 : heartbeat_period = 0;
3650 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3651 1 : status = libspdm_send_receive_psk_exchange(
3652 : spdm_context,
3653 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3654 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3655 : &heartbeat_period, measurement_hash);
3656 : if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
3657 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3658 1 : assert_int_equal(session_id, 0xFFFDFFFD);
3659 1 : assert_int_equal(
3660 : libspdm_secured_message_get_session_state(
3661 : spdm_context->session_info[0].secured_message_context),
3662 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3663 : } else {
3664 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
3665 : }
3666 :
3667 1 : free(data);
3668 1 : }
3669 :
3670 1 : static void req_psk_exchange_case10(void **state) {
3671 : libspdm_return_t status;
3672 : libspdm_test_context_t *spdm_test_context;
3673 : libspdm_context_t *spdm_context;
3674 : uint32_t session_id;
3675 : uint8_t heartbeat_period;
3676 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3677 : void *data;
3678 : size_t data_size;
3679 : void *hash;
3680 : size_t hash_size;
3681 : uint16_t error_code;
3682 :
3683 1 : spdm_test_context = *state;
3684 1 : spdm_context = spdm_test_context->spdm_context;
3685 1 : spdm_test_context->case_id = 0xA;
3686 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3687 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3688 1 : spdm_context->connection_info.capability.flags |=
3689 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3690 1 : spdm_context->local_context.capability.flags |=
3691 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3692 1 : libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
3693 : m_libspdm_use_asym_algo,
3694 : &data, &data_size,
3695 : &hash, &hash_size);
3696 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3697 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3698 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
3699 1 : spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
3700 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3701 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3702 : data_size;
3703 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3704 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3705 : data, data_size);
3706 : #endif
3707 :
3708 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
3709 19 : while(error_code <= 0xff) {
3710 18 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3711 18 : libspdm_reset_message_a(spdm_context);
3712 :
3713 18 : heartbeat_period = 0;
3714 18 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3715 18 : status = libspdm_send_receive_psk_exchange (spdm_context,
3716 : LIBSPDM_TEST_PSK_HINT_STRING,
3717 : sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3718 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
3719 : 0,
3720 : &session_id, &heartbeat_period,
3721 : measurement_hash);
3722 18 : LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
3723 :
3724 18 : error_code++;
3725 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
3726 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
3727 : }
3728 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
3729 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
3730 : }
3731 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
3732 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
3733 : }
3734 : }
3735 :
3736 1 : free(data);
3737 1 : }
3738 :
3739 1 : static void req_psk_exchange_case11(void **state)
3740 : {
3741 : libspdm_return_t status;
3742 : libspdm_test_context_t *spdm_test_context;
3743 : libspdm_context_t *spdm_context;
3744 : uint32_t session_id;
3745 : uint8_t heartbeat_period;
3746 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3747 : void *data;
3748 : size_t data_size;
3749 : void *hash;
3750 : size_t hash_size;
3751 :
3752 1 : spdm_test_context = *state;
3753 1 : spdm_context = spdm_test_context->spdm_context;
3754 1 : spdm_test_context->case_id = 0xB;
3755 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3756 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3757 1 : spdm_context->connection_info.connection_state =
3758 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3759 1 : spdm_context->connection_info.capability.flags &=
3760 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3761 1 : spdm_context->connection_info.capability.flags |=
3762 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3763 1 : spdm_context->local_context.capability.flags |=
3764 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3765 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3766 : m_libspdm_use_asym_algo, &data,
3767 : &data_size, &hash, &hash_size)) {
3768 0 : assert(false);
3769 : }
3770 1 : libspdm_reset_message_a(spdm_context);
3771 1 : spdm_context->connection_info.algorithm.base_hash_algo =
3772 : m_libspdm_use_hash_algo;
3773 1 : spdm_context->connection_info.algorithm.dhe_named_group =
3774 : m_libspdm_use_dhe_algo;
3775 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
3776 : m_libspdm_use_aead_algo;
3777 1 : spdm_context->connection_info.algorithm.key_schedule =
3778 : m_libspdm_use_key_schedule_algo;
3779 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3780 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3781 : data_size;
3782 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3783 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3784 : data, data_size);
3785 : #endif
3786 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3787 : spdm_context->transcript.message_m.buffer_size =
3788 : spdm_context->transcript.message_m.max_buffer_size;
3789 : spdm_context->transcript.message_b.buffer_size =
3790 : spdm_context->transcript.message_b.max_buffer_size;
3791 : spdm_context->transcript.message_c.buffer_size =
3792 : spdm_context->transcript.message_c.max_buffer_size;
3793 : spdm_context->transcript.message_mut_b.buffer_size =
3794 : spdm_context->transcript.message_mut_b.max_buffer_size;
3795 : spdm_context->transcript.message_mut_c.buffer_size =
3796 : spdm_context->transcript.message_mut_c.max_buffer_size;
3797 : #endif
3798 :
3799 1 : heartbeat_period = 0;
3800 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3801 1 : status = libspdm_send_receive_psk_exchange(
3802 : spdm_context,
3803 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3804 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3805 : &heartbeat_period, measurement_hash);
3806 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3807 1 : assert_int_equal(session_id, 0xfffcfffc);
3808 1 : assert_int_equal(
3809 : libspdm_secured_message_get_session_state(
3810 : spdm_context->session_info[0].secured_message_context),
3811 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3812 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3813 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3814 : assert_int_equal(spdm_context->transcript.message_b.buffer_size, 0);
3815 : assert_int_equal(spdm_context->transcript.message_c.buffer_size, 0);
3816 : assert_int_equal(spdm_context->transcript.message_mut_b.buffer_size, 0);
3817 : assert_int_equal(spdm_context->transcript.message_mut_c.buffer_size, 0);
3818 : #endif
3819 :
3820 1 : free(data);
3821 1 : }
3822 :
3823 1 : static void req_psk_exchange_case12(void **state)
3824 : {
3825 : libspdm_return_t status;
3826 : libspdm_test_context_t *spdm_test_context;
3827 : libspdm_context_t *spdm_context;
3828 : uint32_t session_id;
3829 : uint8_t heartbeat_period;
3830 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3831 : void *data;
3832 : size_t data_size;
3833 : void *hash;
3834 : size_t hash_size;
3835 :
3836 1 : spdm_test_context = *state;
3837 1 : spdm_context = spdm_test_context->spdm_context;
3838 :
3839 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
3840 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
3841 : }
3842 :
3843 1 : spdm_test_context->case_id = 0xC;
3844 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3845 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3846 1 : spdm_context->connection_info.connection_state =
3847 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3848 1 : spdm_context->connection_info.capability.flags &=
3849 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3850 1 : spdm_context->connection_info.capability.flags |=
3851 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3852 1 : spdm_context->local_context.capability.flags |=
3853 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3854 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3855 : m_libspdm_use_asym_algo, &data,
3856 : &data_size, &hash, &hash_size)) {
3857 0 : assert(false);
3858 : }
3859 1 : libspdm_reset_message_a(spdm_context);
3860 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3861 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3862 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
3863 1 : spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
3864 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3865 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3866 : data_size;
3867 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3868 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3869 : data, data_size);
3870 : #endif
3871 :
3872 1 : heartbeat_period = 0;
3873 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3874 1 : status = libspdm_send_receive_psk_exchange(
3875 : spdm_context,
3876 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3877 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
3878 : &heartbeat_period, measurement_hash);
3879 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3880 1 : assert_int_equal(session_id, 0xFFFFFFFF);
3881 1 : assert_int_equal(
3882 : libspdm_secured_message_get_session_state(
3883 : spdm_context->session_info[0].secured_message_context),
3884 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3885 :
3886 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3887 : assert_int_equal(spdm_context->session_info[0].session_transcript.message_k.buffer_size,
3888 : m_libspdm_local_buffer_size);
3889 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
3890 : m_libspdm_local_buffer_size));
3891 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3892 : assert_memory_equal(spdm_context->session_info[0].session_transcript.message_k.buffer,
3893 : m_libspdm_local_buffer, m_libspdm_local_buffer_size);
3894 : #endif
3895 1 : free(data);
3896 1 : }
3897 :
3898 1 : static void req_psk_exchange_case13(void **state)
3899 : {
3900 : libspdm_return_t status;
3901 : libspdm_test_context_t *spdm_test_context;
3902 : libspdm_context_t *spdm_context;
3903 : uint32_t session_id;
3904 : uint8_t heartbeat_period;
3905 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3906 : void *data;
3907 : size_t data_size;
3908 : void *hash;
3909 : size_t hash_size;
3910 :
3911 1 : spdm_test_context = *state;
3912 1 : spdm_context = spdm_test_context->spdm_context;
3913 1 : spdm_test_context->case_id = 0xD;
3914 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
3915 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3916 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3917 1 : spdm_context->connection_info.capability.flags &=
3918 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3919 1 : spdm_context->connection_info.capability.flags |=
3920 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3921 1 : spdm_context->local_context.capability.flags |=
3922 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
3923 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
3924 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
3925 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
3926 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3927 : m_libspdm_use_asym_algo, &data,
3928 : &data_size, &hash, &hash_size)) {
3929 0 : assert(false);
3930 : }
3931 1 : libspdm_reset_message_a(spdm_context);
3932 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3933 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
3934 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
3935 1 : spdm_context->connection_info.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
3936 1 : spdm_context->connection_info.algorithm.other_params_support =
3937 : SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
3938 1 : libspdm_session_info_init(spdm_context,
3939 1 : spdm_context->session_info,
3940 : 0,
3941 : INVALID_SESSION_ID, false);
3942 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3943 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
3944 : data_size;
3945 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3946 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3947 : data, data_size);
3948 : #endif
3949 :
3950 1 : heartbeat_period = 0;
3951 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
3952 1 : status = libspdm_send_receive_psk_exchange(
3953 : spdm_context,
3954 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
3955 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
3956 : SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, &session_id,
3957 : &heartbeat_period, measurement_hash);
3958 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3959 1 : assert_int_equal(session_id, 0xFFFFFFFF);
3960 1 : assert_int_equal(
3961 : libspdm_secured_message_get_session_state(
3962 : spdm_context->session_info[0].secured_message_context),
3963 : LIBSPDM_SESSION_STATE_HANDSHAKING);
3964 1 : assert_int_equal(
3965 : spdm_context->session_info[0].session_policy,
3966 : SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH);
3967 1 : free(data);
3968 1 : }
3969 :
3970 1 : static void req_psk_exchange_case14(void **state)
3971 : {
3972 : libspdm_return_t status;
3973 : libspdm_test_context_t *spdm_test_context;
3974 : libspdm_context_t *spdm_context;
3975 : uint32_t session_id;
3976 : uint8_t heartbeat_period;
3977 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
3978 : void *data;
3979 : size_t data_size;
3980 : void *hash;
3981 : size_t hash_size;
3982 :
3983 1 : spdm_test_context = *state;
3984 1 : spdm_context = spdm_test_context->spdm_context;
3985 :
3986 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
3987 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
3988 : }
3989 :
3990 1 : spdm_test_context->case_id = 0xE;
3991 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3992 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3993 1 : spdm_context->connection_info.connection_state =
3994 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
3995 1 : spdm_context->connection_info.capability.flags &=
3996 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
3997 1 : spdm_context->connection_info.capability.flags |=
3998 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
3999 1 : spdm_context->local_context.capability.flags |=
4000 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4001 1 : spdm_context->connection_info.capability.flags |=
4002 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4003 1 : spdm_context->connection_info.algorithm.measurement_spec =
4004 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4005 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4006 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4007 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4008 :
4009 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4010 : m_libspdm_use_asym_algo, &data,
4011 : &data_size, &hash, &hash_size)) {
4012 0 : assert(false);
4013 : }
4014 1 : libspdm_reset_message_a(spdm_context);
4015 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4016 : m_libspdm_use_hash_algo;
4017 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4018 : m_libspdm_use_dhe_algo;
4019 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4020 : m_libspdm_use_aead_algo;
4021 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4022 : m_libspdm_use_measurement_hash_algo;
4023 1 : spdm_context->connection_info.algorithm.key_schedule =
4024 : m_libspdm_use_key_schedule_algo;
4025 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4026 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4027 : data_size;
4028 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4029 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4030 : data, data_size);
4031 :
4032 : #endif
4033 :
4034 1 : heartbeat_period = 0;
4035 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4036 1 : status = libspdm_send_receive_psk_exchange(
4037 : spdm_context,
4038 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4039 : SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
4040 : &heartbeat_period, measurement_hash);
4041 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4042 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4043 1 : assert_memory_equal(
4044 : measurement_hash,
4045 : m_libspdm_use_tcb_hash_value,
4046 : libspdm_get_hash_size(m_libspdm_use_hash_algo));
4047 1 : assert_int_equal(
4048 : libspdm_secured_message_get_session_state(
4049 : spdm_context->session_info[0].secured_message_context),
4050 : LIBSPDM_SESSION_STATE_HANDSHAKING);
4051 1 : free(data);
4052 1 : }
4053 :
4054 1 : static void req_psk_exchange_case15(void **state)
4055 : {
4056 : libspdm_return_t status;
4057 : libspdm_test_context_t *spdm_test_context;
4058 : libspdm_context_t *spdm_context;
4059 : uint32_t session_id;
4060 : uint8_t heartbeat_period;
4061 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4062 : void *data;
4063 : size_t data_size;
4064 : void *hash;
4065 : size_t hash_size;
4066 :
4067 1 : spdm_test_context = *state;
4068 1 : spdm_context = spdm_test_context->spdm_context;
4069 :
4070 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4071 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4072 : }
4073 :
4074 1 : spdm_test_context->case_id = 0xF;
4075 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4076 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4077 1 : spdm_context->connection_info.connection_state =
4078 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4079 1 : spdm_context->connection_info.capability.flags &=
4080 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4081 1 : spdm_context->connection_info.capability.flags |=
4082 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4083 1 : spdm_context->connection_info.capability.flags |=
4084 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4085 1 : spdm_context->local_context.capability.flags |=
4086 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4087 1 : spdm_context->connection_info.algorithm.measurement_spec =
4088 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4089 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4090 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4091 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4092 :
4093 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4094 : m_libspdm_use_asym_algo, &data,
4095 : &data_size, &hash, &hash_size)) {
4096 0 : assert(false);
4097 : }
4098 1 : libspdm_reset_message_a(spdm_context);
4099 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4100 : m_libspdm_use_hash_algo;
4101 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4102 : m_libspdm_use_dhe_algo;
4103 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4104 : m_libspdm_use_aead_algo;
4105 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4106 : m_libspdm_use_measurement_hash_algo;
4107 1 : spdm_context->connection_info.algorithm.key_schedule =
4108 : m_libspdm_use_key_schedule_algo;
4109 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4110 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4111 : data_size;
4112 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4113 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4114 : data, data_size);
4115 :
4116 : #endif
4117 :
4118 1 : heartbeat_period = 0;
4119 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4120 1 : status = libspdm_send_receive_psk_exchange(
4121 : spdm_context,
4122 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4123 : SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
4124 : &heartbeat_period, measurement_hash);
4125 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4126 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4127 1 : assert_memory_equal(
4128 : measurement_hash,
4129 : m_libspdm_zero_filled_buffer,
4130 : libspdm_get_hash_size(m_libspdm_use_hash_algo));
4131 1 : assert_int_equal(
4132 : libspdm_secured_message_get_session_state(
4133 : spdm_context->session_info[0].secured_message_context),
4134 : LIBSPDM_SESSION_STATE_HANDSHAKING);
4135 1 : free(data);
4136 1 : }
4137 :
4138 1 : static void req_psk_exchange_case16(void **state)
4139 : {
4140 : libspdm_return_t status;
4141 : libspdm_test_context_t *spdm_test_context;
4142 : libspdm_context_t *spdm_context;
4143 : uint32_t session_id;
4144 : uint8_t heartbeat_period;
4145 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4146 : void *data;
4147 : size_t data_size;
4148 : void *hash;
4149 : size_t hash_size;
4150 :
4151 1 : spdm_test_context = *state;
4152 1 : spdm_context = spdm_test_context->spdm_context;
4153 :
4154 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4155 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4156 : }
4157 :
4158 1 : spdm_test_context->case_id = 0x10;
4159 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4160 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4161 1 : spdm_context->connection_info.connection_state =
4162 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4163 1 : spdm_context->connection_info.capability.flags &=
4164 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4165 1 : spdm_context->connection_info.capability.flags |=
4166 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4167 1 : spdm_context->connection_info.capability.flags |=
4168 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4169 1 : spdm_context->local_context.capability.flags |=
4170 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4171 1 : spdm_context->connection_info.algorithm.measurement_spec =
4172 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4173 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4174 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4175 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4176 :
4177 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4178 : m_libspdm_use_asym_algo, &data,
4179 : &data_size, &hash, &hash_size)) {
4180 0 : assert(false);
4181 : }
4182 1 : libspdm_reset_message_a(spdm_context);
4183 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4184 : m_libspdm_use_hash_algo;
4185 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4186 : m_libspdm_use_dhe_algo;
4187 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4188 : m_libspdm_use_aead_algo;
4189 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4190 : m_libspdm_use_measurement_hash_algo;
4191 1 : spdm_context->connection_info.algorithm.key_schedule =
4192 : m_libspdm_use_key_schedule_algo;
4193 :
4194 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4195 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4196 : data_size;
4197 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4198 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4199 : data, data_size);
4200 :
4201 : #endif
4202 :
4203 1 : heartbeat_period = 0;
4204 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4205 1 : status = libspdm_send_receive_psk_exchange(
4206 : spdm_context,
4207 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4208 : SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, &session_id,
4209 : &heartbeat_period, measurement_hash);
4210 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4211 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4212 1 : assert_memory_equal(
4213 : measurement_hash,
4214 : m_libspdm_use_tcb_hash_value,
4215 : libspdm_get_hash_size(m_libspdm_use_hash_algo));
4216 1 : assert_int_equal(
4217 : libspdm_secured_message_get_session_state(
4218 : spdm_context->session_info[0].secured_message_context),
4219 : LIBSPDM_SESSION_STATE_HANDSHAKING);
4220 1 : free(data);
4221 1 : }
4222 :
4223 1 : static void req_psk_exchange_case17(void **state)
4224 : {
4225 : libspdm_return_t status;
4226 : libspdm_test_context_t *spdm_test_context;
4227 : libspdm_context_t *spdm_context;
4228 : uint32_t session_id;
4229 : uint8_t heartbeat_period;
4230 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4231 : void *data;
4232 : size_t data_size;
4233 : void *hash;
4234 : size_t hash_size;
4235 :
4236 1 : spdm_test_context = *state;
4237 1 : spdm_context = spdm_test_context->spdm_context;
4238 :
4239 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4240 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4241 : }
4242 :
4243 1 : spdm_test_context->case_id = 0x11;
4244 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4245 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4246 1 : spdm_context->connection_info.connection_state =
4247 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4248 1 : spdm_context->connection_info.capability.flags &=
4249 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4250 1 : spdm_context->connection_info.capability.flags |=
4251 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4252 1 : spdm_context->connection_info.capability.flags |=
4253 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4254 1 : spdm_context->local_context.capability.flags |=
4255 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4256 1 : spdm_context->connection_info.algorithm.measurement_spec =
4257 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4258 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4259 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4260 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4261 :
4262 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4263 : m_libspdm_use_asym_algo, &data,
4264 : &data_size, &hash, &hash_size)) {
4265 0 : assert(false);
4266 : }
4267 1 : libspdm_reset_message_a(spdm_context);
4268 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4269 : m_libspdm_use_hash_algo;
4270 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4271 : m_libspdm_use_dhe_algo;
4272 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4273 : m_libspdm_use_aead_algo;
4274 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4275 : m_libspdm_use_measurement_hash_algo;
4276 1 : spdm_context->connection_info.algorithm.key_schedule =
4277 : m_libspdm_use_key_schedule_algo;
4278 :
4279 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4280 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4281 : data_size;
4282 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4283 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4284 : data, data_size);
4285 :
4286 : #endif
4287 :
4288 1 : heartbeat_period = 0;
4289 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4290 1 : status = libspdm_send_receive_psk_exchange(
4291 : spdm_context,
4292 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4293 : SPDM_PSK_EXCHANGE_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH, 0, &session_id,
4294 : &heartbeat_period, measurement_hash);
4295 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
4296 1 : free(data);
4297 1 : }
4298 :
4299 1 : static void req_psk_exchange_case18(void **state)
4300 : {
4301 : libspdm_return_t status;
4302 : libspdm_test_context_t *spdm_test_context;
4303 : libspdm_context_t *spdm_context;
4304 : uint32_t session_id;
4305 : uint8_t heartbeat_period;
4306 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4307 : void *data;
4308 : size_t data_size;
4309 : void *hash;
4310 : size_t hash_size;
4311 :
4312 1 : spdm_test_context = *state;
4313 1 : spdm_context = spdm_test_context->spdm_context;
4314 :
4315 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4316 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4317 : }
4318 :
4319 1 : spdm_test_context->case_id = 0x12;
4320 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4321 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4322 1 : spdm_context->connection_info.connection_state =
4323 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4324 1 : spdm_context->connection_info.capability.flags &=
4325 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4326 1 : spdm_context->connection_info.capability.flags |=
4327 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4328 1 : spdm_context->connection_info.capability.flags |=
4329 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4330 1 : spdm_context->local_context.capability.flags |=
4331 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4332 1 : spdm_context->connection_info.algorithm.measurement_spec =
4333 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4334 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4335 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4336 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4337 :
4338 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4339 : m_libspdm_use_asym_algo, &data,
4340 : &data_size, &hash, &hash_size)) {
4341 0 : assert(false);
4342 : }
4343 1 : libspdm_reset_message_a(spdm_context);
4344 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4345 : m_libspdm_use_hash_algo;
4346 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4347 : m_libspdm_use_dhe_algo;
4348 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4349 : m_libspdm_use_aead_algo;
4350 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4351 : m_libspdm_use_measurement_hash_algo;
4352 1 : spdm_context->connection_info.algorithm.key_schedule =
4353 : m_libspdm_use_key_schedule_algo;
4354 :
4355 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4356 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4357 : data_size;
4358 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4359 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4360 : data, data_size);
4361 :
4362 : #endif
4363 :
4364 1 : heartbeat_period = 0;
4365 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4366 1 : status = libspdm_send_receive_psk_exchange(
4367 : spdm_context,
4368 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4369 : SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, 0, &session_id,
4370 : &heartbeat_period, measurement_hash);
4371 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
4372 1 : free(data);
4373 1 : }
4374 :
4375 1 : static void req_psk_exchange_case19(void **state)
4376 : {
4377 : libspdm_return_t status;
4378 : libspdm_test_context_t *spdm_test_context;
4379 : libspdm_context_t *spdm_context;
4380 : uint32_t session_id;
4381 : uint8_t heartbeat_period;
4382 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4383 : void *data;
4384 : size_t data_size;
4385 : void *hash;
4386 : size_t hash_size;
4387 :
4388 1 : spdm_test_context = *state;
4389 1 : spdm_context = spdm_test_context->spdm_context;
4390 :
4391 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4392 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4393 : }
4394 :
4395 1 : spdm_test_context->case_id = 0x13;
4396 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4397 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4398 1 : spdm_context->connection_info.connection_state =
4399 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4400 1 : spdm_context->connection_info.capability.flags &=
4401 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4402 1 : spdm_context->connection_info.capability.flags |=
4403 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4404 1 : spdm_context->connection_info.capability.flags |=
4405 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4406 1 : spdm_context->local_context.capability.flags |=
4407 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4408 1 : spdm_context->connection_info.algorithm.measurement_spec =
4409 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4410 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4411 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4412 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4413 :
4414 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4415 : m_libspdm_use_asym_algo, &data,
4416 : &data_size, &hash, &hash_size)) {
4417 0 : assert(false);
4418 : }
4419 1 : libspdm_reset_message_a(spdm_context);
4420 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4421 : m_libspdm_use_hash_algo;
4422 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4423 : m_libspdm_use_dhe_algo;
4424 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4425 : m_libspdm_use_aead_algo;
4426 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4427 : m_libspdm_use_measurement_hash_algo;
4428 1 : spdm_context->connection_info.algorithm.key_schedule =
4429 : m_libspdm_use_key_schedule_algo;
4430 :
4431 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4432 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4433 : data_size;
4434 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4435 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4436 : data, data_size);
4437 :
4438 : #endif
4439 :
4440 1 : heartbeat_period = 0;
4441 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4442 1 : status = libspdm_send_receive_psk_exchange(
4443 : spdm_context,
4444 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4445 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
4446 : &heartbeat_period, measurement_hash);
4447 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4448 1 : free(data);
4449 1 : }
4450 :
4451 1 : static void req_psk_exchange_case20(void **state)
4452 : {
4453 : libspdm_return_t status;
4454 : libspdm_test_context_t *spdm_test_context;
4455 : libspdm_context_t *spdm_context;
4456 : uint32_t session_id;
4457 : uint8_t heartbeat_period;
4458 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4459 : void *data;
4460 : size_t data_size;
4461 : void *hash;
4462 : size_t hash_size;
4463 :
4464 1 : spdm_test_context = *state;
4465 1 : spdm_context = spdm_test_context->spdm_context;
4466 :
4467 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4468 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4469 : }
4470 :
4471 1 : spdm_test_context->case_id = 0x14;
4472 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4473 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4474 1 : spdm_context->connection_info.connection_state =
4475 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4476 1 : spdm_context->connection_info.capability.flags &=
4477 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4478 1 : spdm_context->connection_info.capability.flags |=
4479 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4480 1 : spdm_context->connection_info.capability.flags |=
4481 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4482 1 : spdm_context->local_context.capability.flags |=
4483 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4484 1 : spdm_context->connection_info.algorithm.measurement_spec =
4485 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4486 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4487 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4488 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4489 :
4490 :
4491 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4492 : m_libspdm_use_asym_algo, &data,
4493 : &data_size, &hash, &hash_size)) {
4494 0 : assert(false);
4495 : }
4496 1 : libspdm_reset_message_a(spdm_context);
4497 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4498 : m_libspdm_use_hash_algo;
4499 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4500 : m_libspdm_use_dhe_algo;
4501 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4502 : m_libspdm_use_aead_algo;
4503 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4504 : m_libspdm_use_measurement_hash_algo;
4505 1 : spdm_context->connection_info.algorithm.key_schedule =
4506 : m_libspdm_use_key_schedule_algo;
4507 :
4508 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4509 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4510 : data_size;
4511 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4512 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4513 : data, data_size);
4514 :
4515 : #endif
4516 :
4517 1 : heartbeat_period = 0;
4518 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4519 1 : status = libspdm_send_receive_psk_exchange(
4520 : spdm_context,
4521 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4522 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
4523 : &heartbeat_period, measurement_hash);
4524 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4525 1 : free(data);
4526 1 : }
4527 :
4528 1 : static void req_psk_exchange_case21(void **state)
4529 : {
4530 : libspdm_return_t status;
4531 : libspdm_test_context_t *spdm_test_context;
4532 : libspdm_context_t *spdm_context;
4533 : uint32_t session_id;
4534 : uint8_t heartbeat_period;
4535 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4536 : void *data;
4537 : size_t data_size;
4538 : void *hash;
4539 : size_t hash_size;
4540 :
4541 1 : spdm_test_context = *state;
4542 1 : spdm_context = spdm_test_context->spdm_context;
4543 :
4544 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4545 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4546 : }
4547 :
4548 1 : spdm_test_context->case_id = 0x15;
4549 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4550 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4551 1 : spdm_context->connection_info.connection_state =
4552 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4553 1 : spdm_context->connection_info.capability.flags &=
4554 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4555 1 : spdm_context->connection_info.capability.flags |=
4556 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4557 1 : spdm_context->connection_info.capability.flags |=
4558 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4559 1 : spdm_context->local_context.capability.flags |=
4560 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4561 :
4562 1 : spdm_context->connection_info.capability.flags |=
4563 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
4564 1 : spdm_context->local_context.capability.flags |=
4565 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
4566 :
4567 1 : spdm_context->connection_info.algorithm.measurement_spec =
4568 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4569 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4570 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4571 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4572 :
4573 :
4574 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4575 : m_libspdm_use_asym_algo, &data,
4576 : &data_size, &hash, &hash_size)) {
4577 0 : assert(false);
4578 : }
4579 1 : libspdm_reset_message_a(spdm_context);
4580 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4581 : m_libspdm_use_hash_algo;
4582 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4583 : m_libspdm_use_dhe_algo;
4584 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4585 : m_libspdm_use_aead_algo;
4586 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4587 : m_libspdm_use_measurement_hash_algo;
4588 1 : spdm_context->connection_info.algorithm.key_schedule =
4589 : m_libspdm_use_key_schedule_algo;
4590 :
4591 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4592 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4593 : data_size;
4594 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4595 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4596 : data, data_size);
4597 :
4598 : #endif
4599 :
4600 1 : heartbeat_period = 0;
4601 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4602 1 : status = libspdm_send_receive_psk_exchange(
4603 : spdm_context,
4604 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4605 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
4606 : &heartbeat_period, measurement_hash);
4607 : /* clear Heartbeat flags */
4608 1 : spdm_context->connection_info.capability.flags &=
4609 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
4610 1 : spdm_context->local_context.capability.flags &=
4611 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
4612 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4613 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4614 1 : assert_int_equal(
4615 : libspdm_secured_message_get_session_state(
4616 : spdm_context->session_info[0].secured_message_context),
4617 : LIBSPDM_SESSION_STATE_HANDSHAKING);
4618 1 : assert_int_equal(heartbeat_period,5);
4619 1 : free(data);
4620 1 : }
4621 :
4622 1 : static void req_psk_exchange_case22(void **state)
4623 : {
4624 : libspdm_return_t status;
4625 : libspdm_test_context_t *spdm_test_context;
4626 : libspdm_context_t *spdm_context;
4627 : uint32_t session_id;
4628 : uint8_t heartbeat_period;
4629 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4630 : void *data;
4631 : size_t data_size;
4632 : void *hash;
4633 : size_t hash_size;
4634 :
4635 1 : spdm_test_context = *state;
4636 1 : spdm_context = spdm_test_context->spdm_context;
4637 :
4638 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4639 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4640 : }
4641 :
4642 1 : spdm_test_context->case_id = 0x16;
4643 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4644 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4645 1 : spdm_context->connection_info.connection_state =
4646 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4647 1 : spdm_context->connection_info.capability.flags &=
4648 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4649 1 : spdm_context->connection_info.capability.flags |=
4650 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4651 1 : spdm_context->connection_info.capability.flags |=
4652 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
4653 1 : spdm_context->local_context.capability.flags |=
4654 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4655 :
4656 1 : spdm_context->connection_info.capability.flags |=
4657 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
4658 1 : spdm_context->local_context.capability.flags |=
4659 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
4660 :
4661 1 : spdm_context->connection_info.algorithm.measurement_spec =
4662 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4663 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4664 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4665 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4666 :
4667 :
4668 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4669 : m_libspdm_use_asym_algo, &data,
4670 : &data_size, &hash, &hash_size)) {
4671 0 : assert(false);
4672 : }
4673 1 : libspdm_reset_message_a(spdm_context);
4674 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4675 : m_libspdm_use_hash_algo;
4676 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4677 : m_libspdm_use_dhe_algo;
4678 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4679 : m_libspdm_use_aead_algo;
4680 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4681 : m_libspdm_use_measurement_hash_algo;
4682 1 : spdm_context->connection_info.algorithm.key_schedule =
4683 : m_libspdm_use_key_schedule_algo;
4684 :
4685 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4686 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4687 : data_size;
4688 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4689 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4690 : data, data_size);
4691 :
4692 : #endif
4693 :
4694 1 : heartbeat_period = 0;
4695 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4696 1 : status = libspdm_send_receive_psk_exchange(
4697 : spdm_context,
4698 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4699 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
4700 : &heartbeat_period, measurement_hash);
4701 :
4702 : /*clear Heartbeat flags*/
4703 1 : spdm_context->connection_info.capability.flags &=
4704 : ~SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP;
4705 1 : spdm_context->local_context.capability.flags &=
4706 : ~SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP;
4707 :
4708 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4709 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4710 1 : assert_int_equal(
4711 : libspdm_secured_message_get_session_state(
4712 : spdm_context->session_info[0].secured_message_context),
4713 : LIBSPDM_SESSION_STATE_HANDSHAKING);
4714 1 : assert_int_equal(heartbeat_period,0);
4715 1 : free(data);
4716 1 : }
4717 :
4718 1 : static void req_psk_exchange_case23(void **state)
4719 : {
4720 : libspdm_return_t status;
4721 : libspdm_test_context_t *spdm_test_context;
4722 : libspdm_context_t *spdm_context;
4723 : uint32_t session_id;
4724 : uint8_t heartbeat_period;
4725 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4726 : void *data;
4727 : size_t data_size;
4728 : void *hash;
4729 : size_t hash_size;
4730 :
4731 1 : spdm_test_context = *state;
4732 1 : spdm_context = spdm_test_context->spdm_context;
4733 :
4734 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4735 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4736 : }
4737 :
4738 1 : spdm_test_context->case_id = 0x17;
4739 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4740 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4741 1 : spdm_context->connection_info.connection_state =
4742 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4743 1 : spdm_context->connection_info.capability.flags &=
4744 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4745 1 : spdm_context->connection_info.capability.flags |=
4746 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4747 1 : spdm_context->local_context.capability.flags |=
4748 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4749 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4750 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4751 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4752 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4753 : m_libspdm_use_asym_algo, &data,
4754 : &data_size, &hash, &hash_size)) {
4755 0 : assert(false);
4756 : }
4757 1 : libspdm_reset_message_a(spdm_context);
4758 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4759 : m_libspdm_use_hash_algo;
4760 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4761 : m_libspdm_use_dhe_algo;
4762 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4763 : m_libspdm_use_aead_algo;
4764 1 : spdm_context->connection_info.algorithm.key_schedule =
4765 : m_libspdm_use_key_schedule_algo;
4766 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4767 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4768 : data_size;
4769 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4770 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4771 : data, data_size);
4772 : #endif
4773 :
4774 1 : heartbeat_period = 0;
4775 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4776 1 : status = libspdm_send_receive_psk_exchange(
4777 : spdm_context,
4778 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4779 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
4780 : &heartbeat_period, measurement_hash);
4781 1 : assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
4782 1 : free(data);
4783 1 : }
4784 :
4785 1 : static void req_psk_exchange_case24(void **state)
4786 : {
4787 : libspdm_return_t status;
4788 : libspdm_test_context_t *spdm_test_context;
4789 : libspdm_context_t *spdm_context;
4790 : uint32_t session_id;
4791 : uint8_t heartbeat_period;
4792 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4793 : void *data;
4794 : size_t data_size;
4795 : void *hash;
4796 : size_t hash_size;
4797 :
4798 1 : spdm_test_context = *state;
4799 1 : spdm_context = spdm_test_context->spdm_context;
4800 :
4801 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4802 0 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4803 : }
4804 :
4805 1 : spdm_test_context->case_id = 0x18;
4806 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4807 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4808 1 : spdm_context->connection_info.connection_state =
4809 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4810 1 : spdm_context->connection_info.capability.flags &=
4811 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4812 1 : spdm_context->connection_info.capability.flags |=
4813 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER;
4814 1 : spdm_context->local_context.capability.flags |=
4815 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4816 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4817 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4818 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4819 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4820 : m_libspdm_use_asym_algo, &data,
4821 : &data_size, &hash, &hash_size)) {
4822 0 : assert(false);
4823 : }
4824 1 : libspdm_reset_message_a(spdm_context);
4825 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4826 : m_libspdm_use_hash_algo;
4827 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4828 : m_libspdm_use_dhe_algo;
4829 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4830 : m_libspdm_use_aead_algo;
4831 1 : spdm_context->connection_info.algorithm.key_schedule =
4832 : m_libspdm_use_key_schedule_algo;
4833 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4834 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4835 : data_size;
4836 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4837 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4838 : data, data_size);
4839 : #endif
4840 :
4841 1 : heartbeat_period = 0;
4842 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4843 1 : status = libspdm_send_receive_psk_exchange(
4844 : spdm_context,
4845 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4846 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
4847 : &heartbeat_period, measurement_hash);
4848 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4849 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4850 1 : assert_int_equal(
4851 : libspdm_secured_message_get_session_state(
4852 : spdm_context->session_info[0].secured_message_context),
4853 : LIBSPDM_SESSION_STATE_ESTABLISHED);
4854 1 : free(data);
4855 1 : }
4856 :
4857 1 : static void req_psk_exchange_case25(void **state)
4858 : {
4859 : libspdm_return_t status;
4860 : libspdm_test_context_t *spdm_test_context;
4861 : libspdm_context_t *spdm_context;
4862 : uint32_t session_id;
4863 : uint8_t heartbeat_period;
4864 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4865 : void *data;
4866 : size_t data_size;
4867 : void *hash;
4868 : size_t hash_size;
4869 :
4870 1 : spdm_test_context = *state;
4871 1 : spdm_context = spdm_test_context->spdm_context;
4872 :
4873 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4874 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4875 : }
4876 :
4877 1 : spdm_test_context->case_id = 0x19;
4878 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4879 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4880 1 : spdm_context->connection_info.connection_state =
4881 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4882 1 : spdm_context->connection_info.capability.flags &=
4883 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4884 1 : spdm_context->connection_info.capability.flags |=
4885 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
4886 1 : spdm_context->local_context.capability.flags |=
4887 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4888 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4889 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4890 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4891 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4892 : m_libspdm_use_asym_algo, &data,
4893 : &data_size, &hash, &hash_size)) {
4894 0 : assert(false);
4895 : }
4896 1 : libspdm_reset_message_a(spdm_context);
4897 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4898 : m_libspdm_use_hash_algo;
4899 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4900 : m_libspdm_use_dhe_algo;
4901 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4902 : m_libspdm_use_aead_algo;
4903 1 : spdm_context->connection_info.algorithm.key_schedule =
4904 : m_libspdm_use_key_schedule_algo;
4905 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4906 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4907 : data_size;
4908 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4909 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4910 : data, data_size);
4911 : #endif
4912 :
4913 1 : heartbeat_period = 0;
4914 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4915 1 : status = libspdm_send_receive_psk_exchange(
4916 : spdm_context,
4917 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4918 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
4919 : &heartbeat_period, measurement_hash);
4920 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4921 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4922 1 : assert_int_equal(
4923 : libspdm_secured_message_get_session_state(
4924 : spdm_context->session_info[0].secured_message_context),
4925 : LIBSPDM_SESSION_STATE_HANDSHAKING);
4926 1 : free(data);
4927 1 : }
4928 :
4929 1 : static void req_psk_exchange_case26(void **state)
4930 : {
4931 : libspdm_return_t status;
4932 : libspdm_test_context_t *spdm_test_context;
4933 : libspdm_context_t *spdm_context;
4934 : uint32_t session_id;
4935 : uint8_t heartbeat_period;
4936 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
4937 : void *data;
4938 : size_t data_size;
4939 : void *hash;
4940 : size_t hash_size;
4941 :
4942 1 : spdm_test_context = *state;
4943 1 : spdm_context = spdm_test_context->spdm_context;
4944 :
4945 1 : if(spdm_context->session_info[0].session_id != INVALID_SESSION_ID) {
4946 1 : libspdm_free_session_id(spdm_context,0xFFFFFFFF);
4947 : }
4948 :
4949 1 : spdm_test_context->case_id = 0x1A;
4950 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4951 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4952 1 : spdm_context->connection_info.connection_state =
4953 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
4954 1 : spdm_context->connection_info.capability.flags &=
4955 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
4956 1 : spdm_context->connection_info.capability.flags |=
4957 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER;
4958 1 : spdm_context->local_context.capability.flags |=
4959 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
4960 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
4961 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
4962 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
4963 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4964 : m_libspdm_use_asym_algo, &data,
4965 : &data_size, &hash, &hash_size)) {
4966 0 : assert(false);
4967 : }
4968 1 : libspdm_reset_message_a(spdm_context);
4969 1 : spdm_context->connection_info.algorithm.base_hash_algo =
4970 : m_libspdm_use_hash_algo;
4971 1 : spdm_context->connection_info.algorithm.dhe_named_group =
4972 : m_libspdm_use_dhe_algo;
4973 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
4974 : m_libspdm_use_aead_algo;
4975 1 : spdm_context->connection_info.algorithm.key_schedule =
4976 : m_libspdm_use_key_schedule_algo;
4977 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4978 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
4979 : data_size;
4980 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4981 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4982 : data, data_size);
4983 : #endif
4984 :
4985 1 : heartbeat_period = 0;
4986 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
4987 1 : status = libspdm_send_receive_psk_exchange(
4988 : spdm_context,
4989 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
4990 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH, 0, &session_id,
4991 : &heartbeat_period, measurement_hash);
4992 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4993 1 : assert_int_equal(session_id, 0xFFFFFFFF);
4994 1 : assert_int_equal(
4995 : libspdm_secured_message_get_session_state(
4996 : spdm_context->session_info[0].secured_message_context),
4997 : LIBSPDM_SESSION_STATE_ESTABLISHED);
4998 1 : free(data);
4999 1 : }
5000 :
5001 1 : static void req_psk_exchange_case27(void **state)
5002 : {
5003 : libspdm_return_t status;
5004 : libspdm_test_context_t *spdm_test_context;
5005 : libspdm_context_t *spdm_context;
5006 : uint32_t session_id;
5007 : uint8_t heartbeat_period;
5008 : uint8_t measurement_hash[LIBSPDM_MAX_HASH_SIZE];
5009 : void *data;
5010 : size_t data_size;
5011 : void *hash;
5012 : size_t hash_size;
5013 :
5014 1 : spdm_test_context = *state;
5015 1 : spdm_context = spdm_test_context->spdm_context;
5016 1 : spdm_test_context->case_id = 0x1B;
5017 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
5018 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5019 1 : spdm_context->connection_info.connection_state =
5020 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
5021 1 : spdm_context->connection_info.capability.flags &=
5022 : ~(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP);
5023 1 : spdm_context->connection_info.capability.flags |=
5024 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT;
5025 1 : spdm_context->local_context.capability.flags |=
5026 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER;
5027 1 : spdm_context->local_context.secured_message_version.spdm_version_count = 1;
5028 1 : spdm_context->local_context.secured_message_version.spdm_version[0] =
5029 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
5030 1 : spdm_context->connection_info.algorithm.other_params_support =
5031 : SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
5032 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5033 : m_libspdm_use_asym_algo, &data,
5034 : &data_size, &hash, &hash_size)) {
5035 0 : assert(false);
5036 : }
5037 1 : libspdm_reset_message_a(spdm_context);
5038 1 : spdm_context->connection_info.algorithm.base_hash_algo =
5039 : m_libspdm_use_hash_algo;
5040 1 : spdm_context->connection_info.algorithm.dhe_named_group =
5041 : m_libspdm_use_dhe_algo;
5042 1 : spdm_context->connection_info.algorithm.aead_cipher_suite =
5043 : m_libspdm_use_aead_algo;
5044 1 : spdm_context->connection_info.algorithm.key_schedule =
5045 : m_libspdm_use_key_schedule_algo;
5046 1 : libspdm_session_info_init(spdm_context,
5047 1 : spdm_context->session_info,
5048 : 0,
5049 : INVALID_SESSION_ID, false);
5050 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5051 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
5052 : data_size;
5053 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5054 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5055 : data, data_size);
5056 : #endif
5057 :
5058 1 : heartbeat_period = 0;
5059 1 : libspdm_zero_mem(measurement_hash, sizeof(measurement_hash));
5060 1 : status = libspdm_send_receive_psk_exchange(
5061 : spdm_context,
5062 : LIBSPDM_TEST_PSK_HINT_STRING, sizeof(LIBSPDM_TEST_PSK_HINT_STRING),
5063 : SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH,
5064 : SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH, &session_id,
5065 : &heartbeat_period, measurement_hash);
5066 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5067 1 : assert_int_equal(session_id, 0xFFFFFFFF);
5068 1 : assert_int_equal(
5069 : libspdm_secured_message_get_session_state(
5070 : spdm_context->session_info[0].secured_message_context),
5071 : LIBSPDM_SESSION_STATE_HANDSHAKING);
5072 1 : assert_int_equal(
5073 : spdm_context->session_info[0].session_policy,
5074 : SPDM_PSK_EXCHANGE_REQUEST_ALL_MEASUREMENTS_HASH);
5075 1 : free(data);
5076 1 : }
5077 :
5078 1 : int libspdm_req_psk_exchange_test(void)
5079 : {
5080 1 : const struct CMUnitTest test_cases[] = {
5081 : /* SendRequest failed*/
5082 : cmocka_unit_test(req_psk_exchange_case1),
5083 : /* Successful response*/
5084 : cmocka_unit_test(req_psk_exchange_case2),
5085 : /* connection_state check failed*/
5086 : cmocka_unit_test(req_psk_exchange_case3),
5087 : /* Error response: SPDM_ERROR_CODE_INVALID_REQUEST*/
5088 : cmocka_unit_test(req_psk_exchange_case4),
5089 : /* Always SPDM_ERROR_CODE_BUSY*/
5090 : cmocka_unit_test(req_psk_exchange_case5),
5091 : /* SPDM_ERROR_CODE_BUSY + Successful response*/
5092 : cmocka_unit_test(req_psk_exchange_case6),
5093 : /* Error response: SPDM_ERROR_CODE_REQUEST_RESYNCH*/
5094 : cmocka_unit_test(req_psk_exchange_case7),
5095 : /* Always SPDM_ERROR_CODE_RESPONSE_NOT_READY*/
5096 : cmocka_unit_test(req_psk_exchange_case8),
5097 : /* SPDM_ERROR_CODE_RESPONSE_NOT_READY + Successful response*/
5098 : cmocka_unit_test(req_psk_exchange_case9),
5099 : /* Unexpected errors*/
5100 : cmocka_unit_test(req_psk_exchange_case10),
5101 : cmocka_unit_test(req_psk_exchange_case11),
5102 : /* Buffer verification*/
5103 : cmocka_unit_test(req_psk_exchange_case12),
5104 : /* Successful response V1.2*/
5105 : cmocka_unit_test(req_psk_exchange_case13),
5106 : /* Measurement hash 1, returns a measurement hash*/
5107 : cmocka_unit_test(req_psk_exchange_case14),
5108 : /* Measurement hash 1, returns a 0x00 array (no TCB components)*/
5109 : cmocka_unit_test(req_psk_exchange_case15),
5110 : /* Measurement hash FF, returns a measurement_hash*/
5111 : cmocka_unit_test(req_psk_exchange_case16),
5112 : /* Measurement hash 1, returns no measurement_hash*/
5113 : cmocka_unit_test(req_psk_exchange_case17),
5114 : /* Measurement hash FF, returns no measurement_hash*/
5115 : cmocka_unit_test(req_psk_exchange_case18),
5116 : /* Measurement hash not requested, returns a measurement_hash*/
5117 : cmocka_unit_test(req_psk_exchange_case19),
5118 : /* Heartbeat not supported, heartbeat period different from 0 sent*/
5119 : cmocka_unit_test(req_psk_exchange_case20),
5120 : /* Heartbeat supported, heartbeat period different from 0 sent*/
5121 : cmocka_unit_test(req_psk_exchange_case21),
5122 : /* Heartbeat supported, heartbeat period 0 sent NOTE: This should disable heartbeat*/
5123 : cmocka_unit_test(req_psk_exchange_case22),
5124 : /* Wrong ResponderVerifyData*/
5125 : cmocka_unit_test(req_psk_exchange_case23),
5126 : /* No ResponderContext*/
5127 : cmocka_unit_test(req_psk_exchange_case24),
5128 : /* No OpaqueData*/
5129 : cmocka_unit_test(req_psk_exchange_case25),
5130 : /* No ResponderContext and OpaqueData*/
5131 : cmocka_unit_test(req_psk_exchange_case26),
5132 : /* OpaqueData only supports OpaqueDataFmt1, Success Case */
5133 : cmocka_unit_test(req_psk_exchange_case27),
5134 : };
5135 :
5136 1 : libspdm_test_context_t test_context = {
5137 : LIBSPDM_TEST_CONTEXT_VERSION,
5138 : true,
5139 : send_message,
5140 : receive_message,
5141 : };
5142 :
5143 1 : libspdm_setup_test_context(&test_context);
5144 :
5145 1 : return cmocka_run_group_tests(test_cases,
5146 : libspdm_unit_test_group_setup,
5147 : libspdm_unit_test_group_teardown);
5148 : }
5149 :
5150 : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
|