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