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