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