Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2026 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include "spdm_unit_test.h"
8 : #include "internal/libspdm_requester_lib.h"
9 : #include "internal/libspdm_secured_message_lib.h"
10 :
11 : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
12 :
13 : #define LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID 2
14 : #define LIBSPDM_LARGE_MEASUREMENT_SIZE ((1 << 24) - 1)
15 :
16 : static size_t m_libspdm_local_buffer_size;
17 : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE];
18 : static uint8_t m_libspdm_msg_log_buffer[LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE * 2];
19 :
20 : static size_t m_libspdm_opaque_data_size;
21 : static uint8_t m_libspdm_opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
22 :
23 : static uint8_t m_requester_context[SPDM_REQ_CONTEXT_SIZE];
24 :
25 160 : static size_t libspdm_test_get_measurement_request_size(const void *spdm_context,
26 : const void *buffer,
27 : size_t buffer_size)
28 : {
29 : const spdm_get_measurements_request_t *spdm_request;
30 : size_t message_size;
31 :
32 160 : spdm_request = buffer;
33 160 : message_size = sizeof(spdm_message_header_t);
34 160 : if (buffer_size < message_size) {
35 0 : return buffer_size;
36 : }
37 :
38 160 : if (spdm_request->header.request_response_code != SPDM_GET_MEASUREMENTS) {
39 2 : return buffer_size;
40 : }
41 :
42 158 : if ((spdm_request->header.param1 &
43 : SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE) != 0) {
44 42 : if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_11) {
45 42 : if (buffer_size < sizeof(spdm_get_measurements_request_t)) {
46 0 : return buffer_size;
47 : }
48 42 : message_size = sizeof(spdm_get_measurements_request_t);
49 : } else {
50 0 : if (buffer_size <
51 : sizeof(spdm_get_measurements_request_t) -
52 : sizeof(spdm_request->slot_id_param)) {
53 0 : return buffer_size;
54 : }
55 0 : message_size = sizeof(spdm_get_measurements_request_t) -
56 : sizeof(spdm_request->slot_id_param);
57 : }
58 : } else {
59 : /* already checked before if buffer_size < sizeof(spdm_message_header_t)*/
60 116 : message_size = sizeof(spdm_message_header_t);
61 : }
62 :
63 : /* Good message, return actual size*/
64 158 : return message_size;
65 : }
66 :
67 162 : static libspdm_return_t send_message(
68 : void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
69 : {
70 : libspdm_test_context_t *spdm_test_context;
71 : size_t header_size;
72 : size_t message_size;
73 : uint32_t *session_id;
74 : libspdm_session_info_t *session_info;
75 : bool is_app_message;
76 : uint8_t *app_message;
77 : size_t app_message_size;
78 : uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
79 :
80 162 : memcpy(message_buffer, request, request_size);
81 :
82 162 : spdm_test_context = libspdm_get_test_context();
83 162 : header_size = sizeof(libspdm_test_message_header_t);
84 162 : switch (spdm_test_context->case_id) {
85 1 : case 0x1:
86 1 : return LIBSPDM_STATUS_SEND_FAIL;
87 1 : case 0x2:
88 1 : m_libspdm_local_buffer_size = 0;
89 1 : message_size = libspdm_test_get_measurement_request_size(
90 : spdm_context, (const uint8_t *)request + header_size,
91 : request_size - header_size);
92 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
93 : (const uint8_t *)request + header_size, message_size);
94 1 : m_libspdm_local_buffer_size += message_size;
95 1 : return LIBSPDM_STATUS_SUCCESS;
96 1 : case 0x3:
97 1 : m_libspdm_local_buffer_size = 0;
98 1 : message_size = libspdm_test_get_measurement_request_size(
99 : spdm_context, (const uint8_t *)request + header_size,
100 : request_size - header_size);
101 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
102 : (const uint8_t *)request + header_size, message_size);
103 1 : m_libspdm_local_buffer_size += message_size;
104 1 : return LIBSPDM_STATUS_SUCCESS;
105 1 : case 0x4:
106 1 : m_libspdm_local_buffer_size = 0;
107 1 : message_size = libspdm_test_get_measurement_request_size(
108 : spdm_context, (const uint8_t *)request + header_size,
109 : request_size - header_size);
110 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
111 : (const uint8_t *)request + header_size, message_size);
112 1 : m_libspdm_local_buffer_size += message_size;
113 1 : return LIBSPDM_STATUS_SUCCESS;
114 1 : case 0x5:
115 1 : m_libspdm_local_buffer_size = 0;
116 1 : message_size = libspdm_test_get_measurement_request_size(
117 : spdm_context, (const uint8_t *)request + header_size,
118 : request_size - header_size);
119 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
120 : (const uint8_t *)request + header_size, message_size);
121 1 : m_libspdm_local_buffer_size += message_size;
122 1 : return LIBSPDM_STATUS_SUCCESS;
123 2 : case 0x6:
124 2 : m_libspdm_local_buffer_size = 0;
125 2 : message_size = libspdm_test_get_measurement_request_size(
126 : spdm_context, (const uint8_t *)request + header_size,
127 : request_size - header_size);
128 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
129 : (const uint8_t *)request + header_size, message_size);
130 2 : m_libspdm_local_buffer_size += message_size;
131 2 : return LIBSPDM_STATUS_SUCCESS;
132 1 : case 0x7:
133 1 : m_libspdm_local_buffer_size = 0;
134 1 : message_size = libspdm_test_get_measurement_request_size(
135 : spdm_context, (const uint8_t *)request + header_size,
136 : request_size - header_size);
137 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
138 : (const uint8_t *)request + header_size, message_size);
139 1 : m_libspdm_local_buffer_size += message_size;
140 1 : return LIBSPDM_STATUS_SUCCESS;
141 2 : case 0x8:
142 2 : m_libspdm_local_buffer_size = 0;
143 2 : message_size = libspdm_test_get_measurement_request_size(
144 : spdm_context, (const uint8_t *)request + header_size,
145 : request_size - header_size);
146 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
147 : (const uint8_t *)request + header_size, message_size);
148 2 : m_libspdm_local_buffer_size += message_size;
149 2 : return LIBSPDM_STATUS_SUCCESS;
150 2 : case 0x9: {
151 : static size_t sub_index = 0;
152 2 : if (sub_index == 0) {
153 1 : m_libspdm_local_buffer_size = 0;
154 1 : message_size = libspdm_test_get_measurement_request_size(
155 : spdm_context, (const uint8_t *)request + header_size,
156 : request_size - header_size);
157 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
158 : (const uint8_t *)request + header_size,
159 : message_size);
160 1 : m_libspdm_local_buffer_size += message_size;
161 1 : sub_index++;
162 : }
163 : }
164 2 : return LIBSPDM_STATUS_SUCCESS;
165 1 : case 0xA:
166 1 : m_libspdm_local_buffer_size = 0;
167 1 : message_size = libspdm_test_get_measurement_request_size(
168 : spdm_context, (const uint8_t *)request + header_size,
169 : request_size - header_size);
170 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
171 : (const uint8_t *)request + header_size, message_size);
172 1 : m_libspdm_local_buffer_size += message_size;
173 1 : return LIBSPDM_STATUS_SUCCESS;
174 1 : case 0xB:
175 1 : m_libspdm_local_buffer_size = 0;
176 1 : message_size = libspdm_test_get_measurement_request_size(
177 : spdm_context, (const uint8_t *)request + header_size,
178 : request_size - header_size);
179 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
180 : (const uint8_t *)request + header_size, message_size);
181 1 : m_libspdm_local_buffer_size += message_size;
182 1 : return LIBSPDM_STATUS_SUCCESS;
183 1 : case 0xC:
184 1 : m_libspdm_local_buffer_size = 0;
185 1 : message_size = libspdm_test_get_measurement_request_size(
186 : spdm_context, (const uint8_t *)request + header_size,
187 : request_size - header_size);
188 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
189 : (const uint8_t *)request + header_size, message_size);
190 1 : m_libspdm_local_buffer_size += message_size;
191 1 : return LIBSPDM_STATUS_SUCCESS;
192 1 : case 0xD:
193 1 : m_libspdm_local_buffer_size = 0;
194 1 : message_size = libspdm_test_get_measurement_request_size(
195 : spdm_context, (const uint8_t *)request + header_size,
196 : request_size - header_size);
197 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
198 : (const uint8_t *)request + header_size, message_size);
199 1 : m_libspdm_local_buffer_size += message_size;
200 1 : return LIBSPDM_STATUS_SUCCESS;
201 1 : case 0xE:
202 1 : m_libspdm_local_buffer_size = 0;
203 1 : message_size = libspdm_test_get_measurement_request_size(
204 : spdm_context, (const uint8_t *)request + header_size,
205 : request_size - header_size);
206 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
207 : (const uint8_t *)request + header_size, message_size);
208 1 : m_libspdm_local_buffer_size += message_size;
209 1 : return LIBSPDM_STATUS_SUCCESS;
210 1 : case 0xF:
211 1 : m_libspdm_local_buffer_size = 0;
212 1 : message_size = libspdm_test_get_measurement_request_size(
213 : spdm_context, (const uint8_t *)request + header_size,
214 : request_size - header_size);
215 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
216 : (const uint8_t *)request + header_size, message_size);
217 1 : m_libspdm_local_buffer_size += message_size;
218 1 : return LIBSPDM_STATUS_SUCCESS;
219 4 : case 0x10:
220 4 : m_libspdm_local_buffer_size = 0;
221 4 : message_size = libspdm_test_get_measurement_request_size(
222 : spdm_context, (const uint8_t *)request + header_size,
223 : request_size - header_size);
224 4 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
225 : (const uint8_t *)request + header_size, message_size);
226 4 : m_libspdm_local_buffer_size += message_size;
227 4 : return LIBSPDM_STATUS_SUCCESS;
228 3 : case 0x11:
229 3 : m_libspdm_local_buffer_size = 0;
230 3 : message_size = libspdm_test_get_measurement_request_size(
231 : spdm_context, (const uint8_t *)request + header_size,
232 : request_size - header_size);
233 3 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
234 : (const uint8_t *)request + header_size, message_size);
235 3 : m_libspdm_local_buffer_size += message_size;
236 3 : return LIBSPDM_STATUS_SUCCESS;
237 0 : case 0x12:
238 0 : m_libspdm_local_buffer_size = 0;
239 0 : message_size = libspdm_test_get_measurement_request_size(
240 : spdm_context, (const uint8_t *)request + header_size,
241 : request_size - header_size);
242 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
243 : (const uint8_t *)request + header_size, message_size);
244 0 : m_libspdm_local_buffer_size += message_size;
245 0 : return LIBSPDM_STATUS_SUCCESS;
246 1 : case 0x13:
247 1 : m_libspdm_local_buffer_size = 0;
248 1 : message_size = libspdm_test_get_measurement_request_size(
249 : spdm_context, (const uint8_t *)request + header_size,
250 : request_size - header_size);
251 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
252 : (const uint8_t *)request + header_size, message_size);
253 1 : m_libspdm_local_buffer_size += message_size;
254 1 : return LIBSPDM_STATUS_SUCCESS;
255 1 : case 0x14:
256 1 : m_libspdm_local_buffer_size = 0;
257 1 : message_size = libspdm_test_get_measurement_request_size(
258 : spdm_context, (const uint8_t *)request + header_size,
259 : request_size - header_size);
260 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
261 : (const uint8_t *)request + header_size, message_size);
262 1 : m_libspdm_local_buffer_size += message_size;
263 1 : return LIBSPDM_STATUS_SUCCESS;
264 1 : case 0x15:
265 1 : m_libspdm_local_buffer_size = 0;
266 1 : message_size = libspdm_test_get_measurement_request_size(
267 : spdm_context, (const uint8_t *)request + header_size,
268 : request_size - header_size);
269 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
270 : (const uint8_t *)request + header_size, message_size);
271 1 : m_libspdm_local_buffer_size += message_size;
272 1 : return LIBSPDM_STATUS_SUCCESS;
273 100 : case 0x16:
274 100 : m_libspdm_local_buffer_size = 0;
275 100 : message_size = libspdm_test_get_measurement_request_size(
276 : spdm_context, (const uint8_t *)request + header_size,
277 : request_size - header_size);
278 100 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
279 : (const uint8_t *)request + header_size, message_size);
280 100 : m_libspdm_local_buffer_size += message_size;
281 100 : return LIBSPDM_STATUS_SUCCESS;
282 1 : case 0x17:
283 1 : m_libspdm_local_buffer_size = 0;
284 1 : message_size = libspdm_test_get_measurement_request_size(
285 : spdm_context, (const uint8_t *)request + header_size,
286 : request_size - header_size);
287 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
288 : (const uint8_t *)request + header_size, message_size);
289 1 : m_libspdm_local_buffer_size += message_size;
290 1 : return LIBSPDM_STATUS_SUCCESS;
291 1 : case 0x18:
292 1 : m_libspdm_local_buffer_size = 0;
293 1 : message_size = libspdm_test_get_measurement_request_size(
294 : spdm_context, (const uint8_t *)request + header_size,
295 : request_size - header_size);
296 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
297 : (const uint8_t *)request + header_size, message_size);
298 1 : m_libspdm_local_buffer_size += message_size;
299 1 : return LIBSPDM_STATUS_SUCCESS;
300 1 : case 0x19:
301 1 : m_libspdm_local_buffer_size = 0;
302 1 : message_size = libspdm_test_get_measurement_request_size(
303 : spdm_context, (const uint8_t *)request + header_size,
304 : request_size - header_size);
305 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
306 : (const uint8_t *)request + header_size, message_size);
307 1 : m_libspdm_local_buffer_size += message_size;
308 1 : return LIBSPDM_STATUS_SUCCESS;
309 1 : case 0x1A:
310 1 : m_libspdm_local_buffer_size = 0;
311 1 : message_size = libspdm_test_get_measurement_request_size(
312 : spdm_context, (const uint8_t *)request + header_size,
313 : request_size - header_size);
314 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
315 : (const uint8_t *)request + header_size, message_size);
316 1 : m_libspdm_local_buffer_size += message_size;
317 1 : return LIBSPDM_STATUS_SUCCESS;
318 1 : case 0x1B:
319 1 : m_libspdm_local_buffer_size = 0;
320 1 : message_size = libspdm_test_get_measurement_request_size(
321 : spdm_context, (const uint8_t *)request + header_size,
322 : request_size - header_size);
323 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
324 : (const uint8_t *)request + header_size, message_size);
325 1 : m_libspdm_local_buffer_size += message_size;
326 1 : return LIBSPDM_STATUS_SUCCESS;
327 1 : case 0x1C:
328 1 : m_libspdm_local_buffer_size = 0;
329 1 : message_size = libspdm_test_get_measurement_request_size(
330 : spdm_context, (const uint8_t *)request + header_size,
331 : request_size - header_size);
332 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
333 : (const uint8_t *)request + header_size, message_size);
334 1 : m_libspdm_local_buffer_size += message_size;
335 1 : return LIBSPDM_STATUS_SUCCESS;
336 1 : case 0x1D:
337 1 : m_libspdm_local_buffer_size = 0;
338 1 : message_size = libspdm_test_get_measurement_request_size(
339 : spdm_context, (const uint8_t *)request + header_size,
340 : request_size - header_size);
341 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
342 : (const uint8_t *)request + header_size, message_size);
343 1 : m_libspdm_local_buffer_size += message_size;
344 1 : return LIBSPDM_STATUS_SUCCESS;
345 0 : case 0x1E:
346 0 : m_libspdm_local_buffer_size = 0;
347 0 : message_size = libspdm_test_get_measurement_request_size(
348 : spdm_context, (const uint8_t *)request + header_size,
349 : request_size - header_size);
350 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
351 : (const uint8_t *)request + header_size, message_size);
352 0 : m_libspdm_local_buffer_size += message_size;
353 0 : return LIBSPDM_STATUS_SUCCESS;
354 0 : case 0x1F:
355 0 : m_libspdm_local_buffer_size = 0;
356 0 : message_size = libspdm_test_get_measurement_request_size(
357 : spdm_context, (const uint8_t *)request + header_size,
358 : request_size - header_size);
359 0 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
360 : (const uint8_t *)request + header_size, message_size);
361 0 : m_libspdm_local_buffer_size += message_size;
362 0 : return LIBSPDM_STATUS_SUCCESS;
363 1 : case 0x20:
364 1 : m_libspdm_local_buffer_size = 0;
365 1 : message_size = libspdm_test_get_measurement_request_size(
366 : spdm_context, (const uint8_t *)request + header_size,
367 : request_size - header_size);
368 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
369 : (const uint8_t *)request + header_size, message_size);
370 1 : m_libspdm_local_buffer_size += message_size;
371 1 : return LIBSPDM_STATUS_SUCCESS;
372 18 : case 0x21:
373 18 : m_libspdm_local_buffer_size = 0;
374 18 : message_size = libspdm_test_get_measurement_request_size(
375 : spdm_context, (const uint8_t *)request + header_size,
376 : request_size - header_size);
377 18 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
378 : (const uint8_t *)request + header_size, message_size);
379 18 : m_libspdm_local_buffer_size += message_size;
380 18 : return LIBSPDM_STATUS_SUCCESS;
381 1 : case 0x22:
382 1 : m_libspdm_local_buffer_size = 0;
383 1 : session_id = NULL;
384 1 : session_info = libspdm_get_session_info_via_session_id( spdm_context, 0xFFFFFFFF);
385 1 : message_size = libspdm_test_get_measurement_request_size(
386 : spdm_context, (const uint8_t *)request + header_size,
387 : request_size - header_size);
388 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Request (0x%zx):\n", request_size));
389 1 : libspdm_dump_hex(request, request_size);
390 1 : libspdm_get_scratch_buffer (spdm_context, (void **)&app_message, &app_message_size);
391 1 : libspdm_transport_test_decode_message(
392 : spdm_context, &session_id, &is_app_message,
393 : false, request_size, message_buffer,
394 : &app_message_size, (void **)&app_message);
395 : ((libspdm_secured_message_context_t
396 1 : *)(session_info->secured_message_context))
397 1 : ->application_secret.response_data_sequence_number--;
398 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
399 : app_message, app_message_size);
400 1 : m_libspdm_local_buffer_size += app_message_size;
401 1 : return LIBSPDM_STATUS_SUCCESS;
402 1 : case 0x23:
403 : /* m_libspdm_local_buffer_size is set by case35 and already contains the arbitrary fill
404 : * data. */
405 1 : message_size = libspdm_test_get_measurement_request_size(
406 : spdm_context, (const uint8_t *)request + header_size,
407 : request_size - header_size);
408 1 : libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
409 : sizeof(m_libspdm_local_buffer),
410 : (const uint8_t *)request + header_size, message_size);
411 1 : m_libspdm_local_buffer_size += message_size;
412 1 : return LIBSPDM_STATUS_SUCCESS;
413 1 : case 0x24:
414 1 : m_libspdm_local_buffer_size = 0;
415 1 : message_size = libspdm_test_get_measurement_request_size(
416 : spdm_context, (const uint8_t *)request + header_size,
417 : request_size - header_size);
418 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
419 : (const uint8_t *)request + header_size, message_size);
420 1 : m_libspdm_local_buffer_size += message_size;
421 1 : return LIBSPDM_STATUS_SUCCESS;
422 1 : case 0x25:
423 1 : m_libspdm_local_buffer_size = 0;
424 1 : message_size = libspdm_test_get_measurement_request_size(
425 : spdm_context, (const uint8_t *)request + header_size,
426 : request_size - header_size);
427 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
428 : (const uint8_t *)request + header_size, message_size);
429 1 : m_libspdm_local_buffer_size += message_size;
430 1 : return LIBSPDM_STATUS_SUCCESS;
431 1 : case 0x26:
432 1 : m_libspdm_local_buffer_size = 0;
433 1 : message_size = libspdm_test_get_measurement_request_size(
434 : spdm_context, (const uint8_t *)request + header_size,
435 : request_size - header_size);
436 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
437 : (const uint8_t *)request + header_size, message_size);
438 1 : m_libspdm_local_buffer_size += message_size;
439 1 : return LIBSPDM_STATUS_SUCCESS;
440 1 : case 0x27:
441 1 : m_libspdm_local_buffer_size = 0;
442 1 : message_size = libspdm_test_get_measurement_request_size(
443 : spdm_context, (const uint8_t *)request + header_size,
444 : request_size - header_size);
445 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
446 : (const uint8_t *)request + header_size, message_size);
447 1 : m_libspdm_local_buffer_size += message_size;
448 1 : return LIBSPDM_STATUS_SUCCESS;
449 2 : case 0x28:
450 : case 0x29:
451 2 : m_libspdm_local_buffer_size = 0;
452 2 : message_size = libspdm_test_get_measurement_request_size(
453 : spdm_context, (const uint8_t *)request + header_size,
454 : request_size - header_size);
455 2 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer),
456 : (const uint8_t *)request + header_size, message_size);
457 2 : m_libspdm_local_buffer_size += message_size;
458 2 : return LIBSPDM_STATUS_SUCCESS;
459 0 : default:
460 0 : return LIBSPDM_STATUS_SEND_FAIL;
461 : }
462 : }
463 :
464 161 : static libspdm_return_t receive_message(
465 : void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
466 : {
467 : libspdm_test_context_t *spdm_test_context;
468 : libspdm_return_t status;
469 :
470 161 : spdm_test_context = libspdm_get_test_context();
471 161 : switch (spdm_test_context->case_id) {
472 0 : case 0x1:
473 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
474 :
475 1 : case 0x2: {
476 : spdm_measurements_response_t *spdm_response;
477 : uint8_t *ptr;
478 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
479 : size_t sig_size;
480 : size_t measurment_sig_size;
481 : spdm_measurement_block_dmtf_t *measurment_block;
482 : size_t spdm_response_size;
483 : size_t transport_header_size;
484 :
485 : ((libspdm_context_t *)spdm_context)
486 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
487 : ((libspdm_context_t *)spdm_context)
488 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
489 : ((libspdm_context_t *)spdm_context)
490 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
491 1 : measurment_sig_size =
492 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
493 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
494 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
495 : sizeof(spdm_measurement_block_dmtf_t) +
496 1 : libspdm_get_measurement_hash_size(
497 1 : m_libspdm_use_measurement_hash_algo) +
498 : measurment_sig_size;
499 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
500 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
501 :
502 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
503 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
504 1 : spdm_response->header.param1 = 0;
505 1 : spdm_response->header.param2 = 0;
506 1 : spdm_response->number_of_blocks = 1;
507 1 : libspdm_write_uint24(
508 1 : spdm_response->measurement_record_length,
509 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
510 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
511 1 : measurment_block = (void *)(spdm_response + 1);
512 1 : libspdm_set_mem(measurment_block,
513 : sizeof(spdm_measurement_block_dmtf_t) +
514 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
515 : measurment_block->measurement_block_common_header
516 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
517 : measurment_block->measurement_block_common_header
518 1 : .measurement_size =
519 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
520 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
521 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
522 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
523 1 : ptr += SPDM_NONCE_SIZE;
524 1 : *(uint16_t *)ptr = 0;
525 1 : ptr += sizeof(uint16_t);
526 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
527 : sizeof(m_libspdm_local_buffer)
528 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
529 : m_libspdm_local_buffer),
530 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
531 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
532 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
533 : m_libspdm_local_buffer_size));
534 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
535 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
536 : m_libspdm_local_buffer_size, hash_data);
537 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
538 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
539 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
540 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
541 1 : libspdm_responder_data_sign(
542 : spdm_context,
543 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
544 : 0, SPDM_MEASUREMENTS,
545 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
546 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
547 : ptr, &sig_size);
548 1 : ptr += sig_size;
549 :
550 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
551 : false, spdm_response_size,
552 : spdm_response, response_size,
553 : response);
554 : }
555 1 : return LIBSPDM_STATUS_SUCCESS;
556 :
557 1 : case 0x3: {
558 : spdm_measurements_response_t *spdm_response;
559 : uint8_t *ptr;
560 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
561 : size_t sig_size;
562 : size_t measurment_sig_size;
563 : spdm_measurement_block_dmtf_t *measurment_block;
564 : size_t spdm_response_size;
565 : size_t transport_header_size;
566 :
567 : ((libspdm_context_t *)spdm_context)
568 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
569 : ((libspdm_context_t *)spdm_context)
570 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
571 : ((libspdm_context_t *)spdm_context)
572 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
573 1 : measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) + strlen("libspdm") +
574 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
575 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
576 : sizeof(spdm_measurement_block_dmtf_t) +
577 1 : libspdm_get_measurement_hash_size(
578 1 : m_libspdm_use_measurement_hash_algo) + measurment_sig_size;
579 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
580 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
581 :
582 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
583 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
584 1 : spdm_response->header.param1 = 0;
585 1 : spdm_response->header.param2 = 0;
586 1 : spdm_response->number_of_blocks = 1;
587 1 : libspdm_write_uint24(
588 1 : spdm_response->measurement_record_length,
589 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
590 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
591 1 : measurment_block = (void *)(spdm_response + 1);
592 1 : libspdm_set_mem(measurment_block,
593 : sizeof(spdm_measurement_block_dmtf_t) +
594 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
595 : measurment_block->measurement_block_common_header
596 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
597 1 : measurment_block->measurement_block_common_header.measurement_size =
598 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
599 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
600 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
601 1 : libspdm_set_mem(ptr, SPDM_NONCE_SIZE, 0x12);
602 1 : ptr += SPDM_NONCE_SIZE;
603 :
604 1 : *(uint16_t *)ptr = (uint16_t)strlen("libspdm");
605 1 : ptr += sizeof(uint16_t);
606 1 : libspdm_copy_mem(ptr, strlen("libspdm"), "libspdm", strlen("libspdm"));
607 :
608 1 : ptr += strlen("libspdm");
609 :
610 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
611 : sizeof(m_libspdm_local_buffer)
612 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
613 : m_libspdm_local_buffer),
614 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
615 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
616 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
617 : m_libspdm_local_buffer_size));
618 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
619 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
620 : m_libspdm_local_buffer_size, hash_data);
621 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
622 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
623 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
624 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
625 1 : libspdm_responder_data_sign(
626 : spdm_context,
627 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
628 : 0, SPDM_MEASUREMENTS,
629 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
630 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
631 : ptr, &sig_size);
632 1 : ptr += sig_size;
633 :
634 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
635 : false, spdm_response_size,
636 : spdm_response, response_size,
637 : response);
638 : }
639 1 : return LIBSPDM_STATUS_SUCCESS;
640 :
641 1 : case 0x4: {
642 : spdm_error_response_t *spdm_response;
643 : size_t spdm_response_size;
644 : size_t transport_header_size;
645 :
646 1 : spdm_response_size = sizeof(spdm_error_response_t);
647 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
648 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
649 :
650 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
651 1 : spdm_response->header.request_response_code = SPDM_ERROR;
652 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
653 1 : spdm_response->header.param2 = 0;
654 :
655 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
656 : false, spdm_response_size,
657 : spdm_response,
658 : response_size, response);
659 : }
660 1 : return LIBSPDM_STATUS_SUCCESS;
661 :
662 1 : case 0x5: {
663 : spdm_error_response_t *spdm_response;
664 : size_t spdm_response_size;
665 : size_t transport_header_size;
666 :
667 1 : spdm_response_size = sizeof(spdm_error_response_t);
668 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
669 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
670 :
671 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
672 1 : spdm_response->header.request_response_code = SPDM_ERROR;
673 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
674 1 : spdm_response->header.param2 = 0;
675 :
676 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
677 : false, spdm_response_size,
678 : spdm_response,
679 : response_size, response);
680 : }
681 1 : return LIBSPDM_STATUS_SUCCESS;
682 :
683 2 : case 0x6: {
684 : static size_t sub_index1 = 0;
685 2 : if (sub_index1 == 0) {
686 : spdm_error_response_t *spdm_response;
687 : size_t spdm_response_size;
688 : size_t transport_header_size;
689 :
690 1 : spdm_response_size = sizeof(spdm_error_response_t);
691 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
692 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
693 :
694 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
695 1 : spdm_response->header.request_response_code = SPDM_ERROR;
696 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
697 1 : spdm_response->header.param2 = 0;
698 :
699 1 : libspdm_transport_test_encode_message(
700 : spdm_context, NULL, false, false,
701 : spdm_response_size, spdm_response,
702 : response_size, response);
703 1 : sub_index1++;
704 1 : } else if (sub_index1 == 1) {
705 : spdm_measurements_response_t *spdm_response;
706 : uint8_t *ptr;
707 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
708 : size_t sig_size;
709 : size_t measurment_sig_size;
710 : spdm_measurement_block_dmtf_t *measurment_block;
711 : size_t spdm_response_size;
712 : size_t transport_header_size;
713 :
714 : ((libspdm_context_t *)spdm_context)
715 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
716 : ((libspdm_context_t *)spdm_context)
717 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
718 : ((libspdm_context_t *)spdm_context)
719 : ->connection_info.algorithm
720 1 : .measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
721 1 : measurment_sig_size =
722 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
723 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
724 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
725 : sizeof(spdm_measurement_block_dmtf_t) +
726 1 : libspdm_get_measurement_hash_size(
727 1 : m_libspdm_use_measurement_hash_algo) +
728 : measurment_sig_size;
729 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
730 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
731 :
732 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
733 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
734 1 : spdm_response->header.param1 = 0;
735 1 : spdm_response->header.param2 = 0;
736 1 : spdm_response->number_of_blocks = 1;
737 1 : libspdm_write_uint24(
738 1 : spdm_response->measurement_record_length,
739 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
740 1 : libspdm_get_measurement_hash_size(
741 : m_libspdm_use_measurement_hash_algo)));
742 1 : measurment_block = (void *)(spdm_response + 1);
743 1 : libspdm_set_mem(measurment_block,
744 : sizeof(spdm_measurement_block_dmtf_t) +
745 1 : libspdm_get_measurement_hash_size(
746 : m_libspdm_use_measurement_hash_algo),
747 : 1);
748 : measurment_block->measurement_block_common_header
749 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
750 : measurment_block->measurement_block_common_header
751 1 : .measurement_size = (uint16_t)(
752 : sizeof(spdm_measurement_block_dmtf_header_t) +
753 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
754 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
755 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
756 1 : ptr += SPDM_NONCE_SIZE;
757 1 : *(uint16_t *)ptr = 0;
758 1 : ptr += sizeof(uint16_t);
759 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
760 : sizeof(m_libspdm_local_buffer)
761 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
762 : m_libspdm_local_buffer),
763 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
764 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
765 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
766 : m_libspdm_local_buffer_size));
767 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
768 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
769 : m_libspdm_local_buffer_size, hash_data);
770 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
771 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
772 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
773 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
774 1 : libspdm_responder_data_sign(
775 : spdm_context,
776 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
777 : 0, SPDM_MEASUREMENTS,
778 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo,
779 : m_libspdm_use_hash_algo,
780 : false, m_libspdm_local_buffer,
781 : m_libspdm_local_buffer_size, ptr,
782 : &sig_size);
783 1 : ptr += sig_size;
784 :
785 1 : libspdm_transport_test_encode_message(
786 : spdm_context, NULL, false, false, spdm_response_size,
787 : spdm_response, response_size, response);
788 : }
789 : }
790 2 : return LIBSPDM_STATUS_SUCCESS;
791 :
792 1 : case 0x7: {
793 : spdm_error_response_t *spdm_response;
794 : size_t spdm_response_size;
795 : size_t transport_header_size;
796 :
797 1 : spdm_response_size = sizeof(spdm_error_response_t);
798 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
799 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
800 :
801 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
802 1 : spdm_response->header.request_response_code = SPDM_ERROR;
803 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
804 1 : spdm_response->header.param2 = 0;
805 :
806 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
807 : false, spdm_response_size,
808 : spdm_response,
809 : response_size, response);
810 : }
811 1 : return LIBSPDM_STATUS_SUCCESS;
812 :
813 2 : case 0x8: {
814 : spdm_error_response_data_response_not_ready_t *spdm_response;
815 : size_t spdm_response_size;
816 : size_t transport_header_size;
817 :
818 2 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
819 2 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
820 2 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
821 :
822 2 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
823 2 : spdm_response->header.request_response_code = SPDM_ERROR;
824 2 : spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
825 2 : spdm_response->header.param2 = 0;
826 2 : spdm_response->extend_error_data.rd_exponent = 1;
827 2 : spdm_response->extend_error_data.rd_tm = 2;
828 2 : spdm_response->extend_error_data.request_code = SPDM_GET_MEASUREMENTS;
829 2 : spdm_response->extend_error_data.token = 0;
830 :
831 2 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
832 : false, spdm_response_size,
833 : spdm_response,
834 : response_size, response);
835 : }
836 2 : return LIBSPDM_STATUS_SUCCESS;
837 :
838 2 : case 0x9: {
839 : static size_t sub_index2 = 0;
840 2 : if (sub_index2 == 0) {
841 : spdm_error_response_data_response_not_ready_t
842 : *spdm_response;
843 : size_t spdm_response_size;
844 : size_t transport_header_size;
845 :
846 1 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
847 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
848 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
849 :
850 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
851 1 : spdm_response->header.request_response_code = SPDM_ERROR;
852 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
853 1 : spdm_response->header.param2 = 0;
854 1 : spdm_response->extend_error_data.rd_exponent = 1;
855 1 : spdm_response->extend_error_data.rd_tm = 2;
856 1 : spdm_response->extend_error_data.request_code = SPDM_GET_MEASUREMENTS;
857 1 : spdm_response->extend_error_data.token = 1;
858 :
859 1 : libspdm_transport_test_encode_message(
860 : spdm_context, NULL, false, false,
861 : spdm_response_size, spdm_response,
862 : response_size, response);
863 1 : sub_index2++;
864 1 : } else if (sub_index2 == 1) {
865 : spdm_measurements_response_t *spdm_response;
866 : uint8_t *ptr;
867 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
868 : size_t sig_size;
869 : size_t measurment_sig_size;
870 : spdm_measurement_block_dmtf_t *measurment_block;
871 : size_t spdm_response_size;
872 : size_t transport_header_size;
873 :
874 : ((libspdm_context_t *)spdm_context)
875 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
876 : ((libspdm_context_t *)spdm_context)
877 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
878 : ((libspdm_context_t *)spdm_context)
879 : ->connection_info.algorithm
880 1 : .measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
881 1 : measurment_sig_size =
882 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
883 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
884 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
885 : sizeof(spdm_measurement_block_dmtf_t) +
886 1 : libspdm_get_measurement_hash_size(
887 1 : m_libspdm_use_measurement_hash_algo) +
888 : measurment_sig_size;
889 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
890 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
891 :
892 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
893 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
894 1 : spdm_response->header.param1 = 0;
895 1 : spdm_response->header.param2 = 0;
896 1 : spdm_response->number_of_blocks = 1;
897 1 : libspdm_write_uint24(
898 1 : spdm_response->measurement_record_length,
899 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
900 1 : libspdm_get_measurement_hash_size(
901 : m_libspdm_use_measurement_hash_algo)));
902 1 : measurment_block = (void *)(spdm_response + 1);
903 1 : libspdm_set_mem(measurment_block,
904 : sizeof(spdm_measurement_block_dmtf_t) +
905 1 : libspdm_get_measurement_hash_size(
906 : m_libspdm_use_measurement_hash_algo),
907 : 1);
908 : measurment_block->measurement_block_common_header
909 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
910 : measurment_block->measurement_block_common_header
911 1 : .measurement_size = (uint16_t)(
912 : sizeof(spdm_measurement_block_dmtf_header_t) +
913 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
914 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
915 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
916 1 : ptr += SPDM_NONCE_SIZE;
917 1 : *(uint16_t *)ptr = 0;
918 1 : ptr += sizeof(uint16_t);
919 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
920 : sizeof(m_libspdm_local_buffer)
921 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
922 : m_libspdm_local_buffer),
923 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
924 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
925 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
926 : m_libspdm_local_buffer_size));
927 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
928 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
929 : m_libspdm_local_buffer_size, hash_data);
930 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
931 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
932 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
933 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
934 1 : libspdm_responder_data_sign(
935 : spdm_context,
936 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
937 : 0, SPDM_MEASUREMENTS,
938 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo,
939 : m_libspdm_use_hash_algo,
940 : false, m_libspdm_local_buffer,
941 : m_libspdm_local_buffer_size, ptr,
942 : &sig_size);
943 1 : ptr += sig_size;
944 :
945 1 : libspdm_transport_test_encode_message(
946 : spdm_context, NULL, false, false, spdm_response_size,
947 : spdm_response, response_size, response);
948 : }
949 : }
950 2 : return LIBSPDM_STATUS_SUCCESS;
951 :
952 1 : case 0xA: {
953 : spdm_measurements_response_t *spdm_response;
954 : size_t spdm_response_size;
955 : size_t transport_header_size;
956 : uint8_t *ptr;
957 1 : spdm_response_size =
958 : sizeof(spdm_measurements_response_t)
959 : + SPDM_NONCE_SIZE + sizeof(uint16_t);
960 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
961 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
962 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
963 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
964 1 : spdm_response->header.param1 = 4;
965 1 : spdm_response->header.param2 = 0;
966 1 : spdm_response->number_of_blocks = 0;
967 1 : libspdm_write_uint24(spdm_response->measurement_record_length, 0);
968 :
969 1 : ptr = (uint8_t *)spdm_response +
970 : sizeof(spdm_measurements_response_t);
971 1 : libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
972 1 : ptr += SPDM_NONCE_SIZE;
973 1 : *(uint16_t *)ptr = 0;
974 :
975 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
976 : false, spdm_response_size,
977 : spdm_response, response_size,
978 : response);
979 : }
980 1 : return LIBSPDM_STATUS_SUCCESS;
981 :
982 1 : case 0xB: {
983 : spdm_measurements_response_t *spdm_response;
984 : spdm_measurement_block_dmtf_t *measurment_block;
985 : size_t spdm_response_size;
986 : size_t transport_header_size;
987 : uint8_t *ptr;
988 : ((libspdm_context_t *)spdm_context)
989 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
990 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
991 : sizeof(spdm_measurement_block_dmtf_t) +
992 1 : libspdm_get_measurement_hash_size(
993 : m_libspdm_use_measurement_hash_algo) +
994 : SPDM_NONCE_SIZE + sizeof(uint16_t);
995 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
996 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
997 :
998 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
999 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1000 1 : spdm_response->header.param1 = 0;
1001 1 : spdm_response->header.param2 = 0;
1002 1 : spdm_response->number_of_blocks = 1;
1003 1 : libspdm_write_uint24(
1004 1 : spdm_response->measurement_record_length,
1005 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1006 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1007 1 : measurment_block = (void *)(spdm_response + 1);
1008 1 : libspdm_set_mem(measurment_block,
1009 : sizeof(spdm_measurement_block_dmtf_t) +
1010 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1011 : measurment_block->measurement_block_common_header
1012 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1013 : measurment_block->measurement_block_common_header
1014 1 : .measurement_size =
1015 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1016 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1017 :
1018 1 : ptr = (uint8_t *)spdm_response +
1019 : sizeof(spdm_measurements_response_t) +
1020 1 : sizeof(spdm_measurement_block_dmtf_t) +
1021 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo);
1022 1 : libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
1023 1 : *(uint16_t *)(ptr + SPDM_NONCE_SIZE) = 0;
1024 :
1025 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1026 : false, spdm_response_size,
1027 : spdm_response, response_size,
1028 : response);
1029 : }
1030 1 : return LIBSPDM_STATUS_SUCCESS;
1031 :
1032 1 : case 0xC: {
1033 : spdm_measurements_response_t *spdm_response;
1034 : uint8_t *ptr;
1035 : size_t sig_size;
1036 : size_t measurment_sig_size;
1037 : spdm_measurement_block_dmtf_t *measurment_block;
1038 : size_t spdm_response_size;
1039 : size_t transport_header_size;
1040 :
1041 : ((libspdm_context_t *)spdm_context)
1042 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1043 : ((libspdm_context_t *)spdm_context)
1044 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1045 : ((libspdm_context_t *)spdm_context)
1046 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1047 :
1048 1 : measurment_sig_size =
1049 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
1050 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1051 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1052 : sizeof(spdm_measurement_block_dmtf_t) +
1053 1 : libspdm_get_measurement_hash_size(
1054 1 : m_libspdm_use_measurement_hash_algo) +
1055 : measurment_sig_size;
1056 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1057 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1058 :
1059 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1060 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1061 1 : spdm_response->header.param1 = 0;
1062 1 : spdm_response->header.param2 = 0;
1063 1 : spdm_response->number_of_blocks = 1;
1064 1 : libspdm_write_uint24(
1065 1 : spdm_response->measurement_record_length,
1066 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1067 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1068 1 : measurment_block = (void *)(spdm_response + 1);
1069 1 : libspdm_set_mem(measurment_block,
1070 : sizeof(spdm_measurement_block_dmtf_t) +
1071 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1072 : measurment_block->measurement_block_common_header
1073 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1074 : measurment_block->measurement_block_common_header
1075 1 : .measurement_size =
1076 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1077 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1078 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
1079 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
1080 1 : ptr += SPDM_NONCE_SIZE;
1081 1 : *(uint16_t *)ptr = 0;
1082 1 : ptr += sizeof(uint16_t);
1083 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1084 1 : libspdm_set_mem(ptr, sig_size, 0);
1085 1 : ptr += sig_size;
1086 :
1087 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1088 : false, spdm_response_size,
1089 : spdm_response, response_size,
1090 : response);
1091 : }
1092 1 : return LIBSPDM_STATUS_SUCCESS;
1093 :
1094 1 : case 0xD: {
1095 : spdm_measurements_response_t *spdm_response;
1096 : uint8_t *ptr;
1097 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1098 : size_t sig_size;
1099 : size_t measurment_sig_size;
1100 : spdm_measurement_block_dmtf_t *measurment_block;
1101 : size_t spdm_response_size;
1102 : size_t transport_header_size;
1103 :
1104 : ((libspdm_context_t *)spdm_context)
1105 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1106 : ((libspdm_context_t *)spdm_context)
1107 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1108 : ((libspdm_context_t *)spdm_context)
1109 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1110 1 : measurment_sig_size =
1111 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
1112 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1113 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1114 : sizeof(spdm_measurement_block_dmtf_t) +
1115 1 : libspdm_get_measurement_hash_size(
1116 1 : m_libspdm_use_measurement_hash_algo) +
1117 : measurment_sig_size;
1118 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1119 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1120 :
1121 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1122 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1123 1 : spdm_response->header.param1 = 0;
1124 1 : spdm_response->header.param2 = 0;
1125 1 : spdm_response->number_of_blocks = 1;
1126 1 : libspdm_write_uint24(
1127 1 : spdm_response->measurement_record_length,
1128 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1129 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1130 1 : measurment_block = (void *)(spdm_response + 1);
1131 1 : libspdm_set_mem(measurment_block,
1132 : sizeof(spdm_measurement_block_dmtf_t) +
1133 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1134 : measurment_block->measurement_block_common_header
1135 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1136 : measurment_block->measurement_block_common_header
1137 1 : .measurement_size =
1138 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1139 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1140 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
1141 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
1142 1 : ptr += SPDM_NONCE_SIZE;
1143 1 : *(uint16_t *)ptr = 0;
1144 1 : ptr += sizeof(uint16_t);
1145 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1146 : sizeof(m_libspdm_local_buffer)
1147 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1148 : m_libspdm_local_buffer),
1149 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1150 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1151 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1152 : m_libspdm_local_buffer_size));
1153 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1154 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
1155 : m_libspdm_local_buffer_size, hash_data);
1156 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
1157 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
1158 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1159 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1160 1 : libspdm_get_random_number(sig_size, ptr);
1161 1 : ptr += sig_size;
1162 :
1163 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1164 : false, spdm_response_size,
1165 : spdm_response, response_size,
1166 : response);
1167 : }
1168 1 : return LIBSPDM_STATUS_SUCCESS;
1169 :
1170 1 : case 0xE: {
1171 : spdm_measurements_response_t *spdm_response;
1172 : spdm_measurement_block_dmtf_t *measurment_block;
1173 : size_t spdm_response_size;
1174 : size_t transport_header_size;
1175 :
1176 : ((libspdm_context_t *)spdm_context)
1177 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1178 : ((libspdm_context_t *)spdm_context)
1179 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1180 : ((libspdm_context_t *)spdm_context)
1181 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1182 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1183 : sizeof(spdm_measurement_block_dmtf_t) +
1184 1 : libspdm_get_measurement_hash_size(
1185 : m_libspdm_use_measurement_hash_algo) +
1186 : SPDM_NONCE_SIZE + sizeof(uint16_t);
1187 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1188 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1189 :
1190 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1191 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1192 1 : spdm_response->header.param1 = 0;
1193 1 : spdm_response->header.param2 = 0;
1194 1 : spdm_response->number_of_blocks = 1;
1195 1 : libspdm_write_uint24(
1196 1 : spdm_response->measurement_record_length,
1197 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1198 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1199 1 : measurment_block = (void *)(spdm_response + 1);
1200 1 : libspdm_set_mem(measurment_block,
1201 : sizeof(spdm_measurement_block_dmtf_t) +
1202 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1203 : measurment_block->measurement_block_common_header
1204 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1205 : measurment_block->measurement_block_common_header
1206 1 : .measurement_size =
1207 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1208 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1209 :
1210 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1211 : false, spdm_response_size,
1212 : spdm_response, response_size,
1213 : response);
1214 : }
1215 1 : return LIBSPDM_STATUS_SUCCESS;
1216 :
1217 1 : case 0xF: {
1218 : spdm_measurements_response_t *spdm_response;
1219 : uint8_t *ptr;
1220 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1221 : size_t sig_size;
1222 : size_t measurment_sig_size;
1223 : spdm_measurement_block_dmtf_t *measurment_block;
1224 : size_t spdm_response_size;
1225 : size_t transport_header_size;
1226 :
1227 : ((libspdm_context_t *)spdm_context)
1228 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1229 : ((libspdm_context_t *)spdm_context)
1230 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1231 : ((libspdm_context_t *)spdm_context)
1232 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1233 1 : measurment_sig_size =
1234 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
1235 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1236 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1237 : sizeof(spdm_measurement_block_dmtf_t) +
1238 1 : libspdm_get_measurement_hash_size(
1239 1 : m_libspdm_use_measurement_hash_algo) +
1240 : measurment_sig_size;
1241 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1242 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1243 :
1244 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1245 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS + 1;
1246 1 : spdm_response->header.param1 = 0;
1247 1 : spdm_response->header.param2 = 0;
1248 1 : spdm_response->number_of_blocks = 1;
1249 1 : libspdm_write_uint24(
1250 1 : spdm_response->measurement_record_length,
1251 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1252 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1253 1 : measurment_block = (void *)(spdm_response + 1);
1254 1 : libspdm_set_mem(measurment_block,
1255 : sizeof(spdm_measurement_block_dmtf_t) +
1256 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1257 : measurment_block->measurement_block_common_header
1258 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1259 : measurment_block->measurement_block_common_header
1260 1 : .measurement_size =
1261 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1262 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1263 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
1264 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
1265 1 : ptr += SPDM_NONCE_SIZE;
1266 1 : *(uint16_t *)ptr = 0;
1267 1 : ptr += sizeof(uint16_t);
1268 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1269 : sizeof(m_libspdm_local_buffer)
1270 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1271 : m_libspdm_local_buffer),
1272 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1273 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1274 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1275 : m_libspdm_local_buffer_size));
1276 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1277 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
1278 : m_libspdm_local_buffer_size, hash_data);
1279 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
1280 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
1281 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1282 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1283 1 : libspdm_responder_data_sign(
1284 : spdm_context,
1285 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1286 : 0, SPDM_MEASUREMENTS,
1287 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1288 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
1289 : ptr, &sig_size);
1290 1 : ptr += sig_size;
1291 :
1292 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1293 : false, spdm_response_size,
1294 : spdm_response, response_size,
1295 : response);
1296 : }
1297 1 : return LIBSPDM_STATUS_SUCCESS;
1298 :
1299 4 : case 0x10: {
1300 : spdm_measurements_response_t *spdm_response;
1301 : uint8_t *ptr;
1302 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1303 : size_t sig_size;
1304 : size_t measurment_sig_size;
1305 : spdm_measurement_block_dmtf_t *measurment_block;
1306 : size_t spdm_response_size;
1307 : size_t transport_header_size;
1308 :
1309 : ((libspdm_context_t *)spdm_context)
1310 4 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1311 : ((libspdm_context_t *)spdm_context)
1312 4 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1313 : ((libspdm_context_t *)spdm_context)
1314 4 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1315 4 : measurment_sig_size =
1316 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
1317 4 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1318 4 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1319 : sizeof(spdm_measurement_block_dmtf_t) +
1320 4 : libspdm_get_measurement_hash_size(
1321 4 : m_libspdm_use_measurement_hash_algo) +
1322 : measurment_sig_size;
1323 4 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1324 4 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1325 :
1326 4 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1327 4 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1328 4 : spdm_response->header.param1 = 0;
1329 4 : spdm_response->header.param2 = LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID;
1330 4 : spdm_response->number_of_blocks = 1;
1331 4 : libspdm_write_uint24(
1332 4 : spdm_response->measurement_record_length,
1333 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1334 4 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1335 4 : measurment_block = (void *)(spdm_response + 1);
1336 4 : libspdm_set_mem(measurment_block,
1337 : sizeof(spdm_measurement_block_dmtf_t) +
1338 4 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1339 : measurment_block->measurement_block_common_header
1340 4 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1341 : measurment_block->measurement_block_common_header
1342 4 : .measurement_size =
1343 4 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1344 4 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1345 4 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
1346 4 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
1347 4 : ptr += SPDM_NONCE_SIZE;
1348 4 : *(uint16_t *)ptr = 0;
1349 4 : ptr += sizeof(uint16_t);
1350 4 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1351 : sizeof(m_libspdm_local_buffer)
1352 4 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1353 : m_libspdm_local_buffer),
1354 4 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1355 4 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1356 4 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1357 : m_libspdm_local_buffer_size));
1358 4 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1359 4 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
1360 : m_libspdm_local_buffer_size, hash_data);
1361 4 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
1362 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
1363 4 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1364 4 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1365 4 : libspdm_responder_data_sign(
1366 : spdm_context,
1367 4 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1368 : 0, SPDM_MEASUREMENTS,
1369 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1370 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
1371 : ptr, &sig_size);
1372 4 : ptr += sig_size;
1373 :
1374 4 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1375 : false, spdm_response_size,
1376 : spdm_response, response_size,
1377 : response);
1378 : }
1379 4 : return LIBSPDM_STATUS_SUCCESS;
1380 :
1381 3 : case 0x11: {
1382 : static size_t sub_index0x11 = 0;
1383 :
1384 : spdm_measurements_response_t *spdm_response;
1385 : spdm_measurement_block_dmtf_t *measurment_block;
1386 : size_t spdm_response_size;
1387 : size_t transport_header_size;
1388 3 : spdm_response_size = sizeof(spdm_measurements_response_t);
1389 :
1390 : ((libspdm_context_t *)spdm_context)
1391 3 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1392 3 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1393 3 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1394 :
1395 3 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1396 3 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1397 3 : spdm_response->header.param1 = 1;
1398 3 : spdm_response->header.param2 = 0;
1399 3 : if (sub_index0x11 == 0) {
1400 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1401 : sizeof(spdm_measurement_block_dmtf_t) +
1402 1 : libspdm_get_measurement_hash_size(
1403 : m_libspdm_use_measurement_hash_algo) +
1404 : SPDM_NONCE_SIZE + sizeof(uint16_t);
1405 1 : spdm_response->number_of_blocks = 1;
1406 1 : libspdm_write_uint24(
1407 1 : spdm_response->measurement_record_length,
1408 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1409 1 : libspdm_get_measurement_hash_size(
1410 : m_libspdm_use_measurement_hash_algo)));
1411 1 : measurment_block = (void *)(spdm_response + 1);
1412 1 : libspdm_set_mem(measurment_block,
1413 : sizeof(spdm_measurement_block_dmtf_t) +
1414 1 : libspdm_get_measurement_hash_size(
1415 : m_libspdm_use_measurement_hash_algo),
1416 : 1);
1417 : measurment_block->measurement_block_common_header
1418 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1419 : measurment_block->measurement_block_common_header
1420 1 : .measurement_size = (uint16_t)(
1421 : sizeof(spdm_measurement_block_dmtf_header_t) +
1422 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1423 2 : } else if (sub_index0x11 == 1) {
1424 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1425 : SPDM_NONCE_SIZE + sizeof(uint16_t);
1426 1 : spdm_response->number_of_blocks = 1;
1427 1 : libspdm_write_uint24( spdm_response->measurement_record_length, 0);
1428 1 : } else if (sub_index0x11 == 2) {
1429 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1430 : sizeof(spdm_measurement_block_dmtf_t) +
1431 1 : libspdm_get_measurement_hash_size(
1432 : m_libspdm_use_measurement_hash_algo) +
1433 : SPDM_NONCE_SIZE + sizeof(uint16_t);
1434 1 : spdm_response->number_of_blocks = 0;
1435 1 : libspdm_write_uint24(
1436 1 : spdm_response->measurement_record_length,
1437 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1438 1 : libspdm_get_measurement_hash_size(
1439 : m_libspdm_use_measurement_hash_algo)));
1440 1 : measurment_block = (void *)(spdm_response + 1);
1441 1 : libspdm_set_mem(measurment_block,
1442 : sizeof(spdm_measurement_block_dmtf_t) +
1443 1 : libspdm_get_measurement_hash_size(
1444 : m_libspdm_use_measurement_hash_algo),
1445 : 1);
1446 : measurment_block->measurement_block_common_header
1447 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1448 : measurment_block->measurement_block_common_header
1449 1 : .measurement_size = (uint16_t)(
1450 : sizeof(spdm_measurement_block_dmtf_header_t) +
1451 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1452 : }
1453 3 : sub_index0x11++;
1454 :
1455 3 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1456 : false, spdm_response_size,
1457 : spdm_response, response_size,
1458 : response);
1459 : }
1460 3 : return LIBSPDM_STATUS_SUCCESS;
1461 :
1462 0 : case 0x12: {
1463 : spdm_measurements_response_t *spdm_response;
1464 : spdm_measurement_block_dmtf_t *measurment_block;
1465 : uint8_t *large_spdm_response;
1466 : size_t spdm_response_size;
1467 : size_t transport_header_size;
1468 : size_t count;
1469 :
1470 : large_spdm_response =
1471 0 : (uint8_t *)malloc(sizeof(spdm_measurements_response_t) +
1472 : LIBSPDM_LARGE_MEASUREMENT_SIZE);
1473 :
1474 : ((libspdm_context_t *)spdm_context)
1475 0 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1476 0 : spdm_response_size = sizeof(spdm_measurements_response_t);
1477 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1478 0 : spdm_response = (void *)large_spdm_response;
1479 :
1480 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1481 0 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1482 0 : spdm_response->header.param1 = 0;
1483 0 : spdm_response->header.param2 = 0;
1484 0 : spdm_response->number_of_blocks = 0xFF;
1485 0 : libspdm_write_uint24(spdm_response->measurement_record_length,
1486 : (uint32_t)(LIBSPDM_LARGE_MEASUREMENT_SIZE));
1487 0 : measurment_block = (void *)(spdm_response + 1);
1488 0 : libspdm_set_mem(measurment_block, LIBSPDM_LARGE_MEASUREMENT_SIZE, 1);
1489 0 : for (count = 0; count < spdm_response->number_of_blocks; count++) {
1490 0 : measurment_block->measurement_block_common_header.index = (uint8_t)(count + 1);
1491 : measurment_block->measurement_block_common_header
1492 0 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1493 : measurment_block->measurement_block_common_header
1494 0 : .measurement_size = 0xFFFF;
1495 0 : spdm_response_size += (size_t)(
1496 : sizeof(spdm_measurement_block_common_header_t) +
1497 : 0xFFFF);
1498 : }
1499 :
1500 0 : spdm_response = (void *)((uint8_t *)(*response) + transport_header_size);
1501 0 : if (spdm_response_size > (size_t)(*response) + *response_size - (size_t)spdm_response) {
1502 0 : spdm_response_size = (size_t)(*response) + *response_size - (size_t)spdm_response;
1503 : }
1504 0 : libspdm_copy_mem (spdm_response, spdm_response_size,
1505 : large_spdm_response, spdm_response_size);
1506 :
1507 0 : status = libspdm_transport_test_encode_message(
1508 : spdm_context, NULL, false, false, spdm_response_size,
1509 : spdm_response, response_size, response);
1510 :
1511 0 : free(large_spdm_response);
1512 : }
1513 0 : return status;
1514 :
1515 1 : case 0x13: {
1516 : spdm_measurements_response_t *spdm_response;
1517 : spdm_measurement_block_dmtf_t *measurment_block;
1518 : size_t spdm_response_size;
1519 : size_t transport_header_size;
1520 :
1521 : ((libspdm_context_t *)spdm_context)
1522 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1523 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1524 : sizeof(spdm_measurement_block_dmtf_t) +
1525 1 : libspdm_get_measurement_hash_size(
1526 : m_libspdm_use_measurement_hash_algo) +
1527 : SPDM_NONCE_SIZE + sizeof(uint16_t);
1528 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1529 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1530 :
1531 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1532 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1533 1 : spdm_response->header.param1 = 0;
1534 1 : spdm_response->header.param2 = 0;
1535 1 : spdm_response->number_of_blocks = 1;
1536 1 : libspdm_write_uint24(
1537 1 : spdm_response->measurement_record_length,
1538 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1539 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1540 1 : measurment_block = (void *)(spdm_response + 1);
1541 1 : libspdm_set_mem(measurment_block,
1542 : sizeof(spdm_measurement_block_dmtf_t) +
1543 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1544 1 : measurment_block->measurement_block_common_header.index = 1;
1545 : measurment_block->measurement_block_common_header
1546 1 : .measurement_specification = 0x00000001 | 0x00000002;
1547 : measurment_block->measurement_block_common_header
1548 1 : .measurement_size =
1549 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1550 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1551 :
1552 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1553 : false, spdm_response_size,
1554 : spdm_response, response_size,
1555 : response);
1556 : }
1557 1 : return LIBSPDM_STATUS_SUCCESS;
1558 :
1559 1 : case 0x14: {
1560 : spdm_measurements_response_t *spdm_response;
1561 : spdm_measurement_block_dmtf_t *measurment_block;
1562 : size_t spdm_response_size;
1563 : size_t transport_header_size;
1564 :
1565 : ((libspdm_context_t *)spdm_context)
1566 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1567 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1568 : sizeof(spdm_measurement_block_dmtf_t) +
1569 1 : libspdm_get_measurement_hash_size(
1570 : m_libspdm_use_measurement_hash_algo) +
1571 : SPDM_NONCE_SIZE + sizeof(uint16_t);
1572 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1573 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1574 :
1575 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1576 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1577 1 : spdm_response->header.param1 = 0;
1578 1 : spdm_response->header.param2 = 0;
1579 1 : spdm_response->number_of_blocks = 1;
1580 1 : libspdm_write_uint24(
1581 1 : spdm_response->measurement_record_length,
1582 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1583 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1584 1 : measurment_block = (void *)(spdm_response + 1);
1585 1 : libspdm_set_mem(measurment_block,
1586 : sizeof(spdm_measurement_block_dmtf_t) +
1587 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1588 1 : measurment_block->measurement_block_common_header.index = 1;
1589 : measurment_block->measurement_block_common_header
1590 1 : .measurement_specification = 0x00000004 | 0x00000002;
1591 : measurment_block->measurement_block_common_header
1592 1 : .measurement_size =
1593 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1594 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1595 :
1596 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1597 : false, spdm_response_size,
1598 : spdm_response, response_size,
1599 : response);
1600 : }
1601 1 : return LIBSPDM_STATUS_SUCCESS;
1602 :
1603 1 : case 0x15: {
1604 : spdm_measurements_response_t *spdm_response;
1605 : spdm_measurement_block_dmtf_t *measurment_block;
1606 : size_t spdm_response_size;
1607 : size_t transport_header_size;
1608 :
1609 : ((libspdm_context_t *)spdm_context)
1610 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1611 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1612 : sizeof(spdm_measurement_block_dmtf_t) +
1613 1 : libspdm_get_measurement_hash_size(
1614 : m_libspdm_use_measurement_hash_algo) +
1615 : SPDM_NONCE_SIZE + sizeof(uint16_t);
1616 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1617 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1618 :
1619 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1620 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1621 1 : spdm_response->header.param1 = 0;
1622 1 : spdm_response->header.param2 = 0;
1623 1 : spdm_response->number_of_blocks = 1;
1624 1 : libspdm_write_uint24(
1625 1 : spdm_response->measurement_record_length,
1626 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1627 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1628 1 : measurment_block = (void *)(spdm_response + 1);
1629 1 : libspdm_set_mem(measurment_block,
1630 : sizeof(spdm_measurement_block_dmtf_t) +
1631 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1632 1 : measurment_block->measurement_block_common_header.index = 1;
1633 : measurment_block->measurement_block_common_header
1634 1 : .measurement_specification = (uint8_t)(m_libspdm_use_measurement_spec << 1);
1635 : measurment_block->measurement_block_common_header
1636 1 : .measurement_size =
1637 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1638 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1639 :
1640 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1641 : false, spdm_response_size,
1642 : spdm_response, response_size,
1643 : response);
1644 : }
1645 1 : return LIBSPDM_STATUS_SUCCESS;
1646 :
1647 100 : case 0x16: {
1648 : spdm_measurements_response_t *spdm_response;
1649 : spdm_measurement_block_dmtf_t *measurment_block;
1650 : size_t spdm_response_size;
1651 : size_t transport_header_size;
1652 : uint8_t *ptr;
1653 : ((libspdm_context_t *)spdm_context)
1654 100 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1655 100 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1656 : sizeof(spdm_measurement_block_dmtf_t) +
1657 100 : libspdm_get_measurement_hash_size(
1658 : m_libspdm_use_measurement_hash_algo) +
1659 : SPDM_NONCE_SIZE + sizeof(uint16_t);
1660 100 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1661 100 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1662 :
1663 100 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1664 100 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1665 100 : spdm_response->header.param1 = 0;
1666 100 : spdm_response->header.param2 = 0;
1667 100 : spdm_response->number_of_blocks = 1;
1668 100 : libspdm_write_uint24(
1669 100 : spdm_response->measurement_record_length,
1670 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1671 100 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1672 100 : measurment_block = (void *)(spdm_response + 1);
1673 100 : libspdm_set_mem(measurment_block,
1674 : sizeof(spdm_measurement_block_dmtf_t) +
1675 100 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1676 : measurment_block->measurement_block_common_header
1677 100 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1678 : measurment_block->measurement_block_common_header
1679 100 : .measurement_size =
1680 100 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1681 100 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1682 100 : *(uint16_t *)((uint8_t *)spdm_response +
1683 : sizeof(spdm_measurements_response_t) +
1684 100 : sizeof(spdm_measurement_block_dmtf_t) +
1685 100 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)) = 0;
1686 100 : ptr = (uint8_t *)spdm_response + spdm_response_size - SPDM_NONCE_SIZE - sizeof(uint16_t);
1687 100 : libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
1688 100 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1689 : false, spdm_response_size,
1690 : spdm_response, response_size,
1691 : response);
1692 : }
1693 100 : return LIBSPDM_STATUS_SUCCESS;
1694 :
1695 1 : case 0x17: {
1696 : spdm_measurements_response_t *spdm_response;
1697 : uint8_t *ptr;
1698 : spdm_measurement_block_dmtf_t *measurment_block;
1699 : size_t spdm_response_size;
1700 : size_t transport_header_size;
1701 :
1702 : ((libspdm_context_t *)spdm_context)
1703 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1704 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1705 : sizeof(spdm_measurement_block_dmtf_t) +
1706 1 : libspdm_get_measurement_hash_size(
1707 : m_libspdm_use_measurement_hash_algo) +
1708 : SPDM_NONCE_SIZE +
1709 : sizeof(uint16_t) + SPDM_MAX_OPAQUE_DATA_SIZE;
1710 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1711 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1712 :
1713 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1714 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1715 1 : spdm_response->header.param1 = 0;
1716 1 : spdm_response->header.param2 = 0;
1717 1 : spdm_response->number_of_blocks = 1;
1718 1 : libspdm_write_uint24(
1719 1 : spdm_response->measurement_record_length,
1720 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1721 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1722 1 : measurment_block = (void *)(spdm_response + 1);
1723 1 : libspdm_set_mem(measurment_block,
1724 : sizeof(spdm_measurement_block_dmtf_t) +
1725 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1726 : measurment_block->measurement_block_common_header
1727 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1728 : measurment_block->measurement_block_common_header
1729 1 : .measurement_size =
1730 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1731 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1732 : /* adding extra fields: opaque_length, opaque_data*/
1733 1 : ptr = (void *)((uint8_t *)spdm_response +
1734 : sizeof(spdm_measurements_response_t) +
1735 1 : sizeof(spdm_measurement_block_dmtf_t) +
1736 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1737 1 : libspdm_get_random_number (SPDM_NONCE_SIZE, ptr);
1738 1 : ptr += SPDM_NONCE_SIZE;
1739 1 : *(uint16_t *)ptr = SPDM_MAX_OPAQUE_DATA_SIZE; /* opaque_length*/
1740 1 : ptr += sizeof(uint16_t);
1741 1 : libspdm_set_mem(ptr, SPDM_MAX_OPAQUE_DATA_SIZE, 255);
1742 1 : ptr += SPDM_MAX_OPAQUE_DATA_SIZE;
1743 :
1744 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1745 : false, spdm_response_size,
1746 : spdm_response, response_size,
1747 : response);
1748 : }
1749 1 : return LIBSPDM_STATUS_SUCCESS;
1750 :
1751 1 : case 0x18: {
1752 : spdm_measurements_response_t *spdm_response;
1753 : uint8_t *ptr;
1754 : spdm_measurement_block_dmtf_t *measurment_block;
1755 : size_t spdm_response_size;
1756 : size_t transport_header_size;
1757 :
1758 : ((libspdm_context_t *)spdm_context)
1759 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1760 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1761 : sizeof(spdm_measurement_block_dmtf_t) +
1762 1 : libspdm_get_measurement_hash_size(
1763 : m_libspdm_use_measurement_hash_algo) +
1764 : SPDM_NONCE_SIZE +
1765 : sizeof(uint16_t) +
1766 : (SPDM_MAX_OPAQUE_DATA_SIZE + 1);
1767 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1768 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1769 :
1770 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1771 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1772 1 : spdm_response->header.param1 = 0;
1773 1 : spdm_response->header.param2 = 0;
1774 1 : spdm_response->number_of_blocks = 1;
1775 1 : libspdm_write_uint24(
1776 1 : spdm_response->measurement_record_length,
1777 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1778 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1779 1 : measurment_block = (void *)(spdm_response + 1);
1780 1 : libspdm_set_mem(measurment_block,
1781 : sizeof(spdm_measurement_block_dmtf_t) +
1782 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1783 : measurment_block->measurement_block_common_header
1784 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1785 : measurment_block->measurement_block_common_header
1786 1 : .measurement_size =
1787 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1788 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1789 : /* adding extra fields: opaque_length, opaque_data*/
1790 1 : ptr = (void *)((uint8_t *)spdm_response +
1791 : sizeof(spdm_measurements_response_t) +
1792 1 : sizeof(spdm_measurement_block_dmtf_t) +
1793 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1794 1 : ptr += SPDM_NONCE_SIZE;
1795 1 : *(uint16_t *)ptr =
1796 : (SPDM_MAX_OPAQUE_DATA_SIZE + 1); /* opaque_length*/
1797 1 : ptr += sizeof(uint16_t);
1798 1 : libspdm_set_mem(ptr, (SPDM_MAX_OPAQUE_DATA_SIZE + 1), 255);
1799 1 : ptr += (SPDM_MAX_OPAQUE_DATA_SIZE + 1);
1800 :
1801 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1802 : false, spdm_response_size,
1803 : spdm_response, response_size,
1804 : response);
1805 : }
1806 1 : return LIBSPDM_STATUS_SUCCESS;
1807 :
1808 1 : case 0x19: {
1809 : spdm_measurements_response_t *spdm_response;
1810 : uint8_t *ptr;
1811 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1812 : size_t sig_size;
1813 : size_t measurment_sig_size;
1814 : spdm_measurement_block_dmtf_t *measurment_block;
1815 : size_t spdm_response_size;
1816 : size_t transport_header_size;
1817 1 : uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
1818 :
1819 : ((libspdm_context_t *)spdm_context)
1820 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1821 : ((libspdm_context_t *)spdm_context)
1822 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1823 : ((libspdm_context_t *)spdm_context)
1824 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1825 1 : measurment_sig_size =
1826 2 : SPDM_NONCE_SIZE + sizeof(uint16_t) + opaque_size_test +
1827 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1828 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1829 : sizeof(spdm_measurement_block_dmtf_t) +
1830 1 : libspdm_get_measurement_hash_size(
1831 1 : m_libspdm_use_measurement_hash_algo) +
1832 : measurment_sig_size;
1833 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1834 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1835 :
1836 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1837 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1838 1 : spdm_response->header.param1 = 0;
1839 1 : spdm_response->header.param2 = 0;
1840 1 : spdm_response->number_of_blocks = 1;
1841 1 : libspdm_write_uint24(
1842 1 : spdm_response->measurement_record_length,
1843 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1844 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1845 1 : measurment_block = (void *)(spdm_response + 1);
1846 1 : libspdm_set_mem(measurment_block,
1847 : sizeof(spdm_measurement_block_dmtf_t) +
1848 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1849 : measurment_block->measurement_block_common_header
1850 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1851 : measurment_block->measurement_block_common_header
1852 1 : .measurement_size =
1853 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1854 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1855 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
1856 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
1857 1 : ptr += SPDM_NONCE_SIZE;
1858 :
1859 1 : *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
1860 1 : ptr += sizeof(uint16_t);
1861 1 : libspdm_set_mem(ptr, opaque_size_test, 255);
1862 1 : ptr += opaque_size_test;
1863 :
1864 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1865 : sizeof(m_libspdm_local_buffer)
1866 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1867 : m_libspdm_local_buffer),
1868 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1869 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1870 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1871 : m_libspdm_local_buffer_size));
1872 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1873 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
1874 : m_libspdm_local_buffer_size, hash_data);
1875 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
1876 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
1877 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1878 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1879 1 : libspdm_responder_data_sign(
1880 : spdm_context,
1881 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1882 : 0, SPDM_MEASUREMENTS,
1883 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1884 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
1885 : ptr, &sig_size);
1886 1 : ptr += sig_size;
1887 :
1888 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1889 : false, spdm_response_size,
1890 : spdm_response, response_size,
1891 : response);
1892 : }
1893 1 : return LIBSPDM_STATUS_SUCCESS;
1894 :
1895 1 : case 0x1A: {
1896 : spdm_measurements_response_t *spdm_response;
1897 : uint8_t *ptr;
1898 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1899 : size_t sig_size;
1900 : size_t measurment_sig_size;
1901 : spdm_measurement_block_dmtf_t *measurment_block;
1902 : size_t spdm_response_size;
1903 : size_t transport_header_size;
1904 : size_t MissingBytes;
1905 1 : uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
1906 :
1907 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1908 1 : MissingBytes = sig_size;
1909 :
1910 : ((libspdm_context_t *)spdm_context)
1911 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1912 : ((libspdm_context_t *)spdm_context)
1913 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1914 : ((libspdm_context_t *)spdm_context)
1915 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
1916 1 : measurment_sig_size =
1917 : SPDM_NONCE_SIZE + sizeof(uint16_t) +
1918 2 : (opaque_size_test - MissingBytes) +
1919 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1920 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
1921 : sizeof(spdm_measurement_block_dmtf_t) +
1922 1 : libspdm_get_measurement_hash_size(
1923 1 : m_libspdm_use_measurement_hash_algo) +
1924 : measurment_sig_size;
1925 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1926 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1927 :
1928 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
1929 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
1930 1 : spdm_response->header.param1 = 0;
1931 1 : spdm_response->header.param2 = 0;
1932 1 : spdm_response->number_of_blocks = 1;
1933 1 : libspdm_write_uint24(
1934 1 : spdm_response->measurement_record_length,
1935 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
1936 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
1937 1 : measurment_block = (void *)(spdm_response + 1);
1938 1 : libspdm_set_mem(measurment_block,
1939 : sizeof(spdm_measurement_block_dmtf_t) +
1940 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
1941 : measurment_block->measurement_block_common_header
1942 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1943 : measurment_block->measurement_block_common_header
1944 1 : .measurement_size =
1945 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
1946 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
1947 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
1948 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
1949 1 : ptr += SPDM_NONCE_SIZE;
1950 :
1951 1 : *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
1952 1 : ptr += sizeof(uint16_t);
1953 1 : libspdm_set_mem(ptr, opaque_size_test - MissingBytes, 255);
1954 1 : ptr += (opaque_size_test - MissingBytes);
1955 :
1956 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
1957 : sizeof(m_libspdm_local_buffer)
1958 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
1959 : m_libspdm_local_buffer),
1960 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
1961 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
1962 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
1963 : m_libspdm_local_buffer_size));
1964 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1965 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
1966 : m_libspdm_local_buffer_size, hash_data);
1967 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
1968 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
1969 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1970 1 : libspdm_responder_data_sign(
1971 : spdm_context,
1972 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
1973 : 0, SPDM_MEASUREMENTS,
1974 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
1975 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
1976 : ptr, &sig_size);
1977 1 : ptr += sig_size;
1978 :
1979 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1980 : false, spdm_response_size,
1981 : spdm_response, response_size,
1982 : response);
1983 : }
1984 1 : return LIBSPDM_STATUS_SUCCESS;
1985 :
1986 1 : case 0x1B: {
1987 : spdm_measurements_response_t *spdm_response;
1988 : uint8_t *ptr;
1989 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
1990 : size_t sig_size;
1991 : size_t measurment_sig_size;
1992 : spdm_measurement_block_dmtf_t *measurment_block;
1993 : size_t spdm_response_size;
1994 : size_t transport_header_size;
1995 : size_t MissingBytes;
1996 1 : uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE;
1997 :
1998 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
1999 1 : MissingBytes = sig_size + 1;
2000 :
2001 : ((libspdm_context_t *)spdm_context)
2002 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2003 : ((libspdm_context_t *)spdm_context)
2004 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2005 : ((libspdm_context_t *)spdm_context)
2006 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2007 1 : measurment_sig_size =
2008 : SPDM_NONCE_SIZE + sizeof(uint16_t) +
2009 2 : (opaque_size_test - MissingBytes) +
2010 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2011 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2012 : sizeof(spdm_measurement_block_dmtf_t) +
2013 1 : libspdm_get_measurement_hash_size(
2014 1 : m_libspdm_use_measurement_hash_algo) +
2015 : measurment_sig_size;
2016 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2017 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2018 :
2019 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2020 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2021 1 : spdm_response->header.param1 = 0;
2022 1 : spdm_response->header.param2 = 0;
2023 1 : spdm_response->number_of_blocks = 1;
2024 1 : libspdm_write_uint24(
2025 1 : spdm_response->measurement_record_length,
2026 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2027 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2028 1 : measurment_block = (void *)(spdm_response + 1);
2029 1 : libspdm_set_mem(measurment_block,
2030 : sizeof(spdm_measurement_block_dmtf_t) +
2031 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2032 : measurment_block->measurement_block_common_header
2033 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2034 : measurment_block->measurement_block_common_header
2035 1 : .measurement_size =
2036 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2037 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2038 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
2039 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
2040 1 : ptr += SPDM_NONCE_SIZE;
2041 :
2042 1 : *(uint16_t *)ptr = opaque_size_test; /* opaque_length*/
2043 1 : ptr += sizeof(uint16_t);
2044 1 : libspdm_set_mem(ptr, opaque_size_test - MissingBytes, 255);
2045 1 : ptr += (opaque_size_test - MissingBytes);
2046 :
2047 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2048 : sizeof(m_libspdm_local_buffer)
2049 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2050 : m_libspdm_local_buffer),
2051 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2052 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2053 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2054 : m_libspdm_local_buffer_size));
2055 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2056 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
2057 : m_libspdm_local_buffer_size, hash_data);
2058 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
2059 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
2060 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2061 1 : libspdm_responder_data_sign(
2062 : spdm_context,
2063 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2064 : 0, SPDM_MEASUREMENTS,
2065 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2066 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
2067 : ptr, &sig_size);
2068 1 : ptr += sig_size;
2069 :
2070 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2071 : false, spdm_response_size,
2072 : spdm_response, response_size,
2073 : response);
2074 : }
2075 1 : return LIBSPDM_STATUS_SUCCESS;
2076 :
2077 1 : case 0x1C: {
2078 : spdm_measurements_response_t *spdm_response;
2079 : uint8_t *ptr;
2080 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2081 : size_t sig_size;
2082 : size_t measurment_sig_size;
2083 : spdm_measurement_block_dmtf_t *measurment_block;
2084 : size_t spdm_response_size;
2085 : size_t transport_header_size;
2086 1 : uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
2087 1 : uint16_t opaque_informed_size = opaque_size_test - 1;
2088 :
2089 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2090 :
2091 : ((libspdm_context_t *)spdm_context)
2092 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2093 : ((libspdm_context_t *)spdm_context)
2094 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2095 : ((libspdm_context_t *)spdm_context)
2096 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2097 1 : measurment_sig_size =
2098 2 : SPDM_NONCE_SIZE + sizeof(uint16_t) + opaque_size_test +
2099 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2100 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2101 : sizeof(spdm_measurement_block_dmtf_t) +
2102 1 : libspdm_get_measurement_hash_size(
2103 1 : m_libspdm_use_measurement_hash_algo) +
2104 : measurment_sig_size;
2105 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2106 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2107 :
2108 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2109 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2110 1 : spdm_response->header.param1 = 0;
2111 1 : spdm_response->header.param2 = 0;
2112 1 : spdm_response->number_of_blocks = 1;
2113 1 : libspdm_write_uint24(
2114 1 : spdm_response->measurement_record_length,
2115 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2116 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2117 1 : measurment_block = (void *)(spdm_response + 1);
2118 1 : libspdm_set_mem(measurment_block,
2119 : sizeof(spdm_measurement_block_dmtf_t) +
2120 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2121 : measurment_block->measurement_block_common_header
2122 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2123 : measurment_block->measurement_block_common_header
2124 1 : .measurement_size =
2125 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2126 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2127 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
2128 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
2129 1 : ptr += SPDM_NONCE_SIZE;
2130 :
2131 1 : *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
2132 1 : ptr += sizeof(uint16_t);
2133 1 : libspdm_set_mem(ptr, opaque_size_test, 255);
2134 1 : ptr += (opaque_size_test);
2135 :
2136 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2137 : sizeof(m_libspdm_local_buffer)
2138 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2139 : m_libspdm_local_buffer),
2140 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2141 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2142 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2143 : m_libspdm_local_buffer_size));
2144 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2145 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
2146 : m_libspdm_local_buffer_size, hash_data);
2147 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
2148 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
2149 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2150 1 : libspdm_responder_data_sign(
2151 : spdm_context,
2152 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2153 : 0, SPDM_MEASUREMENTS,
2154 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2155 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
2156 : ptr, &sig_size);
2157 1 : ptr += sig_size;
2158 :
2159 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2160 : false, spdm_response_size,
2161 : spdm_response, response_size,
2162 : response);
2163 : }
2164 1 : return LIBSPDM_STATUS_SUCCESS;
2165 :
2166 1 : case 0x1D: {
2167 : spdm_measurements_response_t *spdm_response;
2168 : uint8_t *ptr;
2169 : spdm_measurement_block_dmtf_t *measurment_block;
2170 : size_t spdm_response_size;
2171 : size_t transport_header_size;
2172 1 : uint16_t opaque_size_test = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
2173 1 : uint16_t opaque_informed_size = opaque_size_test - 1;
2174 :
2175 : ((libspdm_context_t *)spdm_context)
2176 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2177 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2178 : sizeof(spdm_measurement_block_dmtf_t) +
2179 1 : libspdm_get_measurement_hash_size(
2180 : m_libspdm_use_measurement_hash_algo) +
2181 : SPDM_NONCE_SIZE +
2182 1 : sizeof(uint16_t) + opaque_size_test;
2183 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2184 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2185 :
2186 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2187 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2188 1 : spdm_response->header.param1 = 0;
2189 1 : spdm_response->header.param2 = 0;
2190 1 : spdm_response->number_of_blocks = 1;
2191 1 : libspdm_write_uint24(
2192 1 : spdm_response->measurement_record_length,
2193 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2194 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2195 1 : measurment_block = (void *)(spdm_response + 1);
2196 1 : libspdm_set_mem(measurment_block,
2197 : sizeof(spdm_measurement_block_dmtf_t) +
2198 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2199 : measurment_block->measurement_block_common_header
2200 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2201 : measurment_block->measurement_block_common_header
2202 1 : .measurement_size =
2203 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2204 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2205 : /* adding extra fields: opaque_length, opaque_data*/
2206 1 : ptr = (void *)((uint8_t *)spdm_response +
2207 : sizeof(spdm_measurements_response_t) +
2208 1 : sizeof(spdm_measurement_block_dmtf_t) +
2209 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2210 1 : libspdm_get_random_number (SPDM_NONCE_SIZE, ptr);
2211 1 : ptr += SPDM_NONCE_SIZE;
2212 1 : *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
2213 1 : ptr += sizeof(uint16_t);
2214 1 : libspdm_set_mem(ptr, opaque_size_test, 255);
2215 1 : ptr += opaque_size_test;
2216 :
2217 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2218 : false, spdm_response_size,
2219 : spdm_response, response_size,
2220 : response);
2221 : }
2222 1 : return LIBSPDM_STATUS_SUCCESS;
2223 :
2224 0 : case 0x1E: {
2225 : spdm_measurements_response_t *spdm_response;
2226 : uint8_t *ptr;
2227 : spdm_measurement_block_dmtf_t *measurment_block;
2228 : size_t spdm_response_size;
2229 : size_t transport_header_size;
2230 0 : uint16_t opaque_size_test = 0xFFFF;
2231 0 : uint16_t opaque_informed_size = SPDM_MAX_OPAQUE_DATA_SIZE / 2;
2232 :
2233 : ((libspdm_context_t *)spdm_context)
2234 0 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2235 0 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2236 : sizeof(spdm_measurement_block_dmtf_t) +
2237 0 : libspdm_get_measurement_hash_size(
2238 : m_libspdm_use_measurement_hash_algo) +
2239 : SPDM_NONCE_SIZE +
2240 0 : sizeof(uint16_t) + opaque_size_test;
2241 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2242 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2243 :
2244 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2245 0 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2246 0 : spdm_response->header.param1 = 0;
2247 0 : spdm_response->header.param2 = 0;
2248 0 : spdm_response->number_of_blocks = 1;
2249 0 : libspdm_write_uint24(
2250 0 : spdm_response->measurement_record_length,
2251 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2252 0 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2253 0 : measurment_block = (void *)(spdm_response + 1);
2254 0 : libspdm_set_mem(measurment_block,
2255 : sizeof(spdm_measurement_block_dmtf_t) +
2256 0 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2257 : measurment_block->measurement_block_common_header
2258 0 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2259 : measurment_block->measurement_block_common_header
2260 0 : .measurement_size =
2261 0 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2262 0 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2263 : /* adding extra fields: NONCE, opaque_length, opaque_data*/
2264 0 : ptr = (void *)((uint8_t *)spdm_response +
2265 : sizeof(spdm_measurements_response_t) +
2266 0 : sizeof(spdm_measurement_block_dmtf_t) +
2267 0 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2268 0 : ptr += SPDM_NONCE_SIZE;
2269 0 : *(uint16_t *)ptr = opaque_informed_size; /* opaque_length*/
2270 0 : ptr += sizeof(uint16_t);
2271 0 : libspdm_set_mem(ptr, opaque_size_test, 255);
2272 0 : ptr += opaque_size_test;
2273 :
2274 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2275 : false, spdm_response_size,
2276 : spdm_response, response_size,
2277 : response);
2278 : }
2279 0 : return LIBSPDM_STATUS_SUCCESS;
2280 :
2281 0 : case 0x1F: {
2282 : spdm_measurements_response_t *spdm_response;
2283 : uint8_t *ptr;
2284 : spdm_measurement_block_dmtf_t *measurment_block;
2285 : size_t spdm_response_size;
2286 : size_t transport_header_size;
2287 0 : uint16_t opaque_size_test = 0xFFFF;
2288 :
2289 : ((libspdm_context_t *)spdm_context)
2290 0 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2291 0 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2292 : sizeof(spdm_measurement_block_dmtf_t) +
2293 0 : libspdm_get_measurement_hash_size(
2294 : m_libspdm_use_measurement_hash_algo) +
2295 0 : SPDM_NONCE_SIZE + sizeof(uint16_t) +
2296 : opaque_size_test;
2297 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2298 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2299 :
2300 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2301 0 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2302 0 : spdm_response->header.param1 = 0;
2303 0 : spdm_response->header.param2 = 0;
2304 0 : spdm_response->number_of_blocks = 1;
2305 0 : libspdm_write_uint24(
2306 0 : spdm_response->measurement_record_length,
2307 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2308 0 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2309 0 : measurment_block = (void *)(spdm_response + 1);
2310 0 : libspdm_set_mem(measurment_block,
2311 : sizeof(spdm_measurement_block_dmtf_t) +
2312 0 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2313 : measurment_block->measurement_block_common_header
2314 0 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2315 : measurment_block->measurement_block_common_header
2316 0 : .measurement_size =
2317 0 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2318 0 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2319 : /* adding extra fields: NONCE, opaque_length, opaque_data*/
2320 0 : ptr = (void *)((uint8_t *)spdm_response +
2321 : sizeof(spdm_measurements_response_t) +
2322 0 : sizeof(spdm_measurement_block_dmtf_t) +
2323 0 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2324 0 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
2325 0 : ptr += SPDM_NONCE_SIZE;
2326 0 : *(uint16_t *)ptr = (opaque_size_test); /* opaque_length*/
2327 0 : ptr += sizeof(uint16_t);
2328 0 : libspdm_set_mem(ptr, (opaque_size_test), 255);
2329 0 : ptr += (opaque_size_test);
2330 :
2331 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2332 : false, spdm_response_size,
2333 : spdm_response, response_size,
2334 : response);
2335 : }
2336 0 : return LIBSPDM_STATUS_SUCCESS;
2337 :
2338 1 : case 0x20: {
2339 : spdm_measurements_response_t *spdm_response;
2340 : spdm_measurement_block_dmtf_t *measurment_block;
2341 : size_t spdm_response_size;
2342 : size_t transport_header_size;
2343 : uint8_t *ptr;
2344 : ((libspdm_context_t *)spdm_context)
2345 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2346 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2347 : 2 * (sizeof(spdm_measurement_block_dmtf_t) +
2348 1 : libspdm_get_measurement_hash_size(
2349 1 : m_libspdm_use_measurement_hash_algo)) +
2350 : SPDM_NONCE_SIZE;
2351 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2352 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2353 :
2354 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2355 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2356 1 : spdm_response->header.param1 = 0;
2357 1 : spdm_response->header.param2 = 0;
2358 1 : spdm_response->number_of_blocks = 2;
2359 1 : *(uint32_t *)spdm_response->measurement_record_length =
2360 1 : 2 * ((uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2361 1 : libspdm_get_measurement_hash_size(
2362 : m_libspdm_use_measurement_hash_algo)));
2363 1 : measurment_block = (void *)(spdm_response + 1);
2364 1 : libspdm_set_mem(measurment_block,
2365 1 : 2 * (sizeof(spdm_measurement_block_dmtf_t) +
2366 1 : libspdm_get_measurement_hash_size(
2367 : m_libspdm_use_measurement_hash_algo)),
2368 : 1);
2369 1 : measurment_block->measurement_block_common_header.index = 1;
2370 : measurment_block->measurement_block_common_header
2371 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2372 : measurment_block->measurement_block_common_header
2373 1 : .measurement_size =
2374 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2375 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2376 1 : measurment_block =
2377 : (void *)(((uint8_t *)measurment_block) +
2378 1 : (sizeof(spdm_measurement_block_dmtf_t) +
2379 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2380 1 : measurment_block->measurement_block_common_header.index = 2;
2381 : measurment_block->measurement_block_common_header
2382 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2383 : measurment_block->measurement_block_common_header
2384 1 : .measurement_size =
2385 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2386 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2387 1 : ptr = (uint8_t *)spdm_response + spdm_response_size - SPDM_NONCE_SIZE;
2388 1 : libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
2389 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2390 : false, spdm_response_size,
2391 : spdm_response, response_size,
2392 : response);
2393 : }
2394 1 : return LIBSPDM_STATUS_SUCCESS;
2395 :
2396 18 : case 0x21:
2397 : {
2398 : static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
2399 :
2400 : spdm_error_response_t *spdm_response;
2401 : size_t spdm_response_size;
2402 : size_t transport_header_size;
2403 :
2404 18 : spdm_response_size = sizeof(spdm_error_response_t);
2405 18 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2406 18 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2407 :
2408 18 : if(error_code <= 0xff) {
2409 18 : libspdm_zero_mem (spdm_response, spdm_response_size);
2410 18 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2411 18 : spdm_response->header.request_response_code = SPDM_ERROR;
2412 18 : spdm_response->header.param1 = (uint8_t) error_code;
2413 18 : spdm_response->header.param2 = 0;
2414 :
2415 18 : libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
2416 : spdm_response_size, spdm_response,
2417 : response_size, response);
2418 : }
2419 :
2420 18 : error_code++;
2421 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
2422 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
2423 : }
2424 : /* skip some reserved error codes (0d to 3e) */
2425 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
2426 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
2427 : }
2428 : /* skip response not ready, request resync, and some reserved codes (44 to fc) */
2429 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
2430 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
2431 : }
2432 : }
2433 18 : return LIBSPDM_STATUS_SUCCESS;
2434 1 : case 0x22: {
2435 : spdm_measurements_response_t *spdm_response;
2436 : uint8_t *ptr;
2437 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2438 : size_t sig_size;
2439 : size_t measurment_sig_size;
2440 : spdm_measurement_block_dmtf_t *measurment_block;
2441 : size_t spdm_response_size;
2442 : size_t transport_header_size;
2443 : uint32_t session_id;
2444 : libspdm_session_info_t *session_info;
2445 : uint8_t *scratch_buffer;
2446 : size_t scratch_buffer_size;
2447 :
2448 1 : session_id = 0xFFFFFFFF;
2449 : ((libspdm_context_t *)spdm_context)
2450 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2451 : ((libspdm_context_t *)spdm_context)
2452 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2453 : ((libspdm_context_t *)spdm_context)
2454 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2455 1 : measurment_sig_size =
2456 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
2457 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2458 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2459 : sizeof(spdm_measurement_block_dmtf_t) +
2460 1 : libspdm_get_measurement_hash_size(
2461 1 : m_libspdm_use_measurement_hash_algo) +
2462 : measurment_sig_size;
2463 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2464 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2465 :
2466 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2467 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2468 1 : spdm_response->header.param1 = 0;
2469 1 : spdm_response->header.param2 = 0;
2470 1 : spdm_response->number_of_blocks = 1;
2471 1 : libspdm_write_uint24(
2472 1 : spdm_response->measurement_record_length,
2473 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2474 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2475 1 : measurment_block = (void *)(spdm_response + 1);
2476 1 : libspdm_set_mem(measurment_block,
2477 : sizeof(spdm_measurement_block_dmtf_t) +
2478 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2479 : measurment_block->measurement_block_common_header
2480 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2481 : measurment_block->measurement_block_common_header
2482 1 : .measurement_size =
2483 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2484 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2485 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
2486 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
2487 1 : ptr += SPDM_NONCE_SIZE;
2488 1 : *(uint16_t *)ptr = 0;
2489 1 : ptr += sizeof(uint16_t);
2490 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2491 : sizeof(m_libspdm_local_buffer)
2492 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2493 : m_libspdm_local_buffer),
2494 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2495 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2496 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2497 : m_libspdm_local_buffer_size));
2498 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2499 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
2500 : m_libspdm_local_buffer_size, hash_data);
2501 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
2502 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
2503 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2504 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2505 1 : libspdm_responder_data_sign(
2506 : spdm_context,
2507 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2508 : 0, SPDM_MEASUREMENTS,
2509 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2510 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
2511 : ptr, &sig_size);
2512 1 : ptr += sig_size;
2513 :
2514 : /* For secure message, message is in sender buffer, we need copy it to scratch buffer.
2515 : * transport_message is always in sender buffer. */
2516 1 : libspdm_get_scratch_buffer (spdm_context, (void **)&scratch_buffer, &scratch_buffer_size);
2517 1 : libspdm_copy_mem (scratch_buffer + transport_header_size,
2518 : scratch_buffer_size - transport_header_size,
2519 : spdm_response, spdm_response_size);
2520 1 : spdm_response = (void *)(scratch_buffer + transport_header_size);
2521 1 : libspdm_transport_test_encode_message(spdm_context, &session_id, false,
2522 : false, spdm_response_size,
2523 : spdm_response, response_size,
2524 : response);
2525 1 : session_info = libspdm_get_session_info_via_session_id( spdm_context, session_id);
2526 1 : if (session_info == NULL) {
2527 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
2528 : }
2529 : /* WALKAROUND: If just use single context to encode message and then decode message */
2530 1 : ((libspdm_secured_message_context_t *)(session_info->secured_message_context))
2531 1 : ->application_secret.response_data_sequence_number--;
2532 : }
2533 1 : return LIBSPDM_STATUS_SUCCESS;
2534 :
2535 1 : case 0x23: {
2536 : spdm_measurements_response_t *spdm_response;
2537 : spdm_measurement_block_dmtf_t *measurment_block;
2538 : size_t spdm_response_size;
2539 : size_t transport_header_size;
2540 : uint8_t *ptr;
2541 1 : ((libspdm_context_t *)spdm_context)->connection_info.algorithm.measurement_hash_algo =
2542 : m_libspdm_use_measurement_hash_algo;
2543 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2544 : sizeof(spdm_measurement_block_dmtf_t) +
2545 1 : libspdm_get_measurement_hash_size(
2546 : m_libspdm_use_measurement_hash_algo) + SPDM_NONCE_SIZE + sizeof(uint16_t);
2547 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2548 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2549 :
2550 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
2551 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2552 1 : spdm_response->header.param1 = 0;
2553 1 : spdm_response->header.param2 = 0;
2554 1 : spdm_response->number_of_blocks = 1;
2555 1 : libspdm_write_uint24(
2556 1 : spdm_response->measurement_record_length,
2557 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2558 1 : libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)));
2559 1 : measurment_block = (void *)(spdm_response + 1);
2560 1 : libspdm_set_mem(measurment_block,
2561 : sizeof(spdm_measurement_block_dmtf_t) +
2562 1 : libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo), 1);
2563 1 : measurment_block->measurement_block_common_header.measurement_specification =
2564 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2565 1 : measurment_block->measurement_block_common_header.measurement_size =
2566 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2567 1 : libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo));
2568 :
2569 1 : ptr = (uint8_t *)spdm_response +
2570 : sizeof(spdm_measurements_response_t) +
2571 1 : sizeof(spdm_measurement_block_dmtf_t) +
2572 1 : libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo);
2573 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
2574 1 : *(uint16_t *)(ptr + SPDM_NONCE_SIZE) = 0;
2575 :
2576 1 : libspdm_copy_mem (m_libspdm_local_buffer + m_libspdm_local_buffer_size,
2577 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
2578 : spdm_response, spdm_response_size);
2579 1 : m_libspdm_local_buffer_size += spdm_response_size;
2580 :
2581 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2582 : false, spdm_response_size,
2583 : spdm_response, response_size,
2584 : response);
2585 : }
2586 1 : return LIBSPDM_STATUS_SUCCESS;
2587 :
2588 1 : case 0x24: {
2589 : spdm_measurements_response_t *spdm_response;
2590 : uint8_t *ptr;
2591 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2592 : size_t sig_size;
2593 : size_t measurment_sig_size;
2594 : spdm_measurement_block_dmtf_t *measurment_block;
2595 : size_t spdm_response_size;
2596 : size_t transport_header_size;
2597 :
2598 : ((libspdm_context_t *)spdm_context)
2599 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2600 : ((libspdm_context_t *)spdm_context)
2601 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2602 : ((libspdm_context_t *)spdm_context)
2603 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2604 1 : measurment_sig_size =
2605 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
2606 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2607 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2608 : sizeof(spdm_measurement_block_dmtf_t) +
2609 1 : libspdm_get_measurement_hash_size(
2610 1 : m_libspdm_use_measurement_hash_algo) +
2611 : measurment_sig_size;
2612 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2613 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2614 :
2615 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
2616 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2617 1 : spdm_response->header.param1 = 0;
2618 1 : spdm_response->header.param2 = 0;
2619 1 : spdm_response->number_of_blocks = 1;
2620 1 : libspdm_write_uint24(
2621 1 : spdm_response->measurement_record_length,
2622 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2623 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2624 1 : measurment_block = (void *)(spdm_response + 1);
2625 1 : libspdm_set_mem(measurment_block,
2626 : sizeof(spdm_measurement_block_dmtf_t) +
2627 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2628 : measurment_block->measurement_block_common_header
2629 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2630 : measurment_block->measurement_block_common_header
2631 1 : .measurement_size =
2632 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2633 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2634 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
2635 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
2636 1 : ptr += SPDM_NONCE_SIZE;
2637 1 : *(uint16_t *)ptr = 0;
2638 1 : ptr += sizeof(uint16_t);
2639 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2640 : sizeof(m_libspdm_local_buffer)
2641 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2642 : m_libspdm_local_buffer),
2643 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2644 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2645 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2646 : m_libspdm_local_buffer_size));
2647 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2648 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
2649 : m_libspdm_local_buffer_size, hash_data);
2650 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
2651 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
2652 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2653 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2654 1 : libspdm_responder_data_sign(
2655 : spdm_context,
2656 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2657 : 0, SPDM_MEASUREMENTS,
2658 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2659 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
2660 : ptr, &sig_size);
2661 1 : ptr += sig_size;
2662 :
2663 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2664 : false, spdm_response_size,
2665 : spdm_response, response_size,
2666 : response);
2667 : }
2668 1 : return LIBSPDM_STATUS_SUCCESS;
2669 1 : case 0x25: {
2670 : spdm_measurements_response_t *spdm_response;
2671 : size_t spdm_response_size;
2672 : size_t transport_header_size;
2673 : uint8_t *ptr;
2674 1 : spdm_response_size =
2675 : sizeof(spdm_measurements_response_t)
2676 : + SPDM_NONCE_SIZE + sizeof(uint16_t);
2677 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2678 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2679 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
2680 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2681 1 : spdm_response->header.param1 = 4;
2682 1 : spdm_response->header.param2 = 0;
2683 1 : spdm_response->number_of_blocks = 0;
2684 1 : libspdm_write_uint24(spdm_response->measurement_record_length, 0);
2685 :
2686 1 : ptr = (uint8_t *)spdm_response +
2687 : sizeof(spdm_measurements_response_t);
2688 1 : libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
2689 1 : ptr += SPDM_NONCE_SIZE;
2690 1 : *(uint16_t *)ptr = 0;
2691 :
2692 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2693 : false, spdm_response_size,
2694 : spdm_response, response_size,
2695 : response);
2696 : }
2697 1 : return LIBSPDM_STATUS_SUCCESS;
2698 1 : case 0x26: {
2699 : spdm_measurements_response_t *spdm_response;
2700 : uint8_t *ptr;
2701 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2702 : size_t sig_size;
2703 : size_t measurment_sig_size;
2704 : spdm_measurement_block_dmtf_t *measurment_block;
2705 : size_t spdm_response_size;
2706 : size_t transport_header_size;
2707 :
2708 : ((libspdm_context_t *)spdm_context)
2709 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2710 : ((libspdm_context_t *)spdm_context)
2711 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2712 : ((libspdm_context_t *)spdm_context)
2713 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2714 1 : measurment_sig_size =
2715 : SPDM_NONCE_SIZE + sizeof(uint16_t) + 0 +
2716 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2717 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2718 : sizeof(spdm_measurement_block_dmtf_t) +
2719 1 : libspdm_get_measurement_hash_size(
2720 1 : m_libspdm_use_measurement_hash_algo) +
2721 : measurment_sig_size;
2722 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2723 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2724 :
2725 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
2726 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2727 1 : spdm_response->header.param1 = 0;
2728 1 : spdm_response->header.param2 = 0x0F;
2729 1 : spdm_response->number_of_blocks = 1;
2730 1 : libspdm_write_uint24(
2731 1 : spdm_response->measurement_record_length,
2732 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2733 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2734 1 : measurment_block = (void *)(spdm_response + 1);
2735 1 : libspdm_set_mem(measurment_block,
2736 : sizeof(spdm_measurement_block_dmtf_t) +
2737 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2738 : measurment_block->measurement_block_common_header
2739 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2740 : measurment_block->measurement_block_common_header
2741 1 : .measurement_size =
2742 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2743 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2744 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
2745 1 : libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
2746 1 : ptr += SPDM_NONCE_SIZE;
2747 1 : *(uint16_t *)ptr = 0;
2748 1 : ptr += sizeof(uint16_t);
2749 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2750 : sizeof(m_libspdm_local_buffer)
2751 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2752 : m_libspdm_local_buffer),
2753 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2754 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2755 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2756 : m_libspdm_local_buffer_size));
2757 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2758 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
2759 : m_libspdm_local_buffer_size, hash_data);
2760 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
2761 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
2762 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2763 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2764 1 : libspdm_responder_data_sign(
2765 : spdm_context,
2766 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2767 : 0, SPDM_MEASUREMENTS,
2768 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2769 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
2770 : ptr, &sig_size);
2771 1 : ptr += sig_size;
2772 :
2773 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2774 : false, spdm_response_size,
2775 : spdm_response, response_size,
2776 : response);
2777 : }
2778 1 : return LIBSPDM_STATUS_SUCCESS;
2779 1 : case 0x27: {
2780 : spdm_measurements_response_t *spdm_response;
2781 : spdm_general_opaque_data_table_header_t
2782 : *spdm_general_opaque_data_table_header;
2783 : opaque_element_table_header_t
2784 : *opaque_element_table_header;
2785 : uint8_t *ptr;
2786 : uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
2787 : size_t sig_size;
2788 : size_t measurment_sig_size;
2789 : spdm_measurement_block_dmtf_t *measurment_block;
2790 : size_t spdm_response_size;
2791 : size_t transport_header_size;
2792 : uint8_t element_num;
2793 : uint8_t element_index;
2794 : size_t current_element_len;
2795 : uint16_t opaque_element_data_len;
2796 :
2797 : ((libspdm_context_t *)spdm_context)
2798 1 : ->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2799 : ((libspdm_context_t *)spdm_context)
2800 1 : ->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2801 : ((libspdm_context_t *)spdm_context)
2802 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2803 :
2804 1 : spdm_general_opaque_data_table_header = (void *)m_libspdm_opaque_data;
2805 1 : spdm_general_opaque_data_table_header->total_elements = 2;
2806 1 : opaque_element_table_header = (void *)(spdm_general_opaque_data_table_header + 1);
2807 :
2808 1 : element_num = spdm_general_opaque_data_table_header->total_elements;
2809 1 : m_libspdm_opaque_data_size = sizeof(spdm_general_opaque_data_table_header_t);
2810 :
2811 3 : for (element_index = 0; element_index < element_num; element_index++) {
2812 2 : opaque_element_table_header->id = SPDM_REGISTRY_ID_MAX;
2813 2 : opaque_element_table_header->vendor_len = 0;
2814 2 : opaque_element_data_len = (uint16_t)strlen("libspdm");
2815 :
2816 2 : ptr = (void *)(opaque_element_table_header + 1);
2817 2 : ptr += opaque_element_table_header->vendor_len;
2818 :
2819 2 : libspdm_copy_mem((uint16_t *)ptr,
2820 : sizeof(opaque_element_data_len),
2821 : &opaque_element_data_len,
2822 : sizeof(opaque_element_data_len));
2823 :
2824 2 : libspdm_copy_mem(ptr + sizeof(opaque_element_data_len),
2825 : SPDM_MAX_OPAQUE_DATA_SIZE -
2826 : sizeof(opaque_element_table_header_t), "libspdm",
2827 : strlen("libspdm"));
2828 :
2829 2 : current_element_len = sizeof(opaque_element_table_header_t) +
2830 2 : opaque_element_table_header->vendor_len +
2831 2 : sizeof(opaque_element_data_len) +
2832 : opaque_element_data_len;
2833 2 : current_element_len = (current_element_len + 3) & ~3;
2834 :
2835 : /*move to next element*/
2836 2 : opaque_element_table_header =
2837 : (opaque_element_table_header_t *)
2838 : ((uint8_t *)opaque_element_table_header + current_element_len);
2839 :
2840 2 : m_libspdm_opaque_data_size += current_element_len;
2841 : }
2842 :
2843 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2844 :
2845 1 : measurment_sig_size = SPDM_NONCE_SIZE + sizeof(uint16_t) +
2846 1 : m_libspdm_opaque_data_size +
2847 1 : libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2848 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2849 : sizeof(spdm_measurement_block_dmtf_t) +
2850 1 : libspdm_get_measurement_hash_size(
2851 1 : m_libspdm_use_measurement_hash_algo) + measurment_sig_size;
2852 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2853 :
2854 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
2855 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2856 1 : spdm_response->header.param1 = 0;
2857 1 : spdm_response->header.param2 = 0;
2858 1 : spdm_response->number_of_blocks = 1;
2859 1 : libspdm_write_uint24(
2860 1 : spdm_response->measurement_record_length,
2861 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2862 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2863 1 : measurment_block = (void *)(spdm_response + 1);
2864 1 : libspdm_set_mem(measurment_block,
2865 : sizeof(spdm_measurement_block_dmtf_t) +
2866 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2867 : measurment_block->measurement_block_common_header
2868 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2869 1 : measurment_block->measurement_block_common_header.measurement_size =
2870 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2871 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2872 1 : ptr = (void *)((uint8_t *)spdm_response + spdm_response_size - measurment_sig_size);
2873 1 : libspdm_set_mem(ptr, SPDM_NONCE_SIZE, 0x12);
2874 1 : ptr += SPDM_NONCE_SIZE;
2875 :
2876 1 : *(uint16_t *)ptr = (uint16_t)m_libspdm_opaque_data_size;
2877 1 : ptr += sizeof(uint16_t);
2878 1 : libspdm_copy_mem(ptr, (size_t)(*response) + *response_size - (size_t)ptr,
2879 : m_libspdm_opaque_data,
2880 : m_libspdm_opaque_data_size);
2881 1 : ptr += m_libspdm_opaque_data_size;
2882 :
2883 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
2884 : sizeof(m_libspdm_local_buffer)
2885 1 : - (&m_libspdm_local_buffer[m_libspdm_local_buffer_size] -
2886 : m_libspdm_local_buffer),
2887 1 : spdm_response, (size_t)ptr - (size_t)spdm_response);
2888 1 : m_libspdm_local_buffer_size += ((size_t)ptr - (size_t)spdm_response);
2889 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer_size (0x%zx):\n",
2890 : m_libspdm_local_buffer_size));
2891 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2892 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_buffer,
2893 : m_libspdm_local_buffer_size, hash_data);
2894 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "HashDataSize (0x%x):\n",
2895 : libspdm_get_hash_size(m_libspdm_use_hash_algo)));
2896 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
2897 1 : sig_size = libspdm_get_asym_signature_size(m_libspdm_use_asym_algo);
2898 1 : libspdm_responder_data_sign(
2899 : spdm_context,
2900 1 : spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
2901 : 0, SPDM_MEASUREMENTS,
2902 : m_libspdm_use_asym_algo, m_libspdm_use_pqc_asym_algo, m_libspdm_use_hash_algo,
2903 : false, m_libspdm_local_buffer, m_libspdm_local_buffer_size,
2904 : ptr, &sig_size);
2905 1 : ptr += sig_size;
2906 :
2907 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2908 : false, spdm_response_size,
2909 : spdm_response, response_size,
2910 : response);
2911 : }
2912 1 : return LIBSPDM_STATUS_SUCCESS;
2913 1 : case 0x28: {
2914 : spdm_measurements_response_t *spdm_response;
2915 : spdm_measurement_block_dmtf_t *measurment_block;
2916 : size_t spdm_response_size;
2917 : size_t transport_header_size;
2918 : uint8_t *ptr;
2919 : ((libspdm_context_t *)spdm_context)
2920 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2921 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2922 : sizeof(spdm_measurement_block_dmtf_t) +
2923 1 : libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)
2924 : + SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE;
2925 :
2926 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2927 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2928 :
2929 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
2930 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2931 1 : spdm_response->header.param1 = 0;
2932 1 : spdm_response->header.param2 = 0;
2933 1 : spdm_response->number_of_blocks = 1;
2934 1 : libspdm_write_uint24(
2935 1 : spdm_response->measurement_record_length,
2936 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
2937 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
2938 :
2939 1 : measurment_block = (void *)(spdm_response + 1);
2940 1 : libspdm_set_mem(measurment_block,
2941 : sizeof(spdm_measurement_block_dmtf_t) +
2942 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
2943 :
2944 : measurment_block->measurement_block_common_header
2945 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
2946 : measurment_block->measurement_block_common_header
2947 1 : .measurement_size =
2948 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
2949 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
2950 :
2951 1 : ptr = (uint8_t *)spdm_response +
2952 : sizeof(spdm_measurements_response_t) +
2953 1 : sizeof(spdm_measurement_block_dmtf_t) +
2954 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo);
2955 1 : libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
2956 :
2957 1 : ptr += SPDM_NONCE_SIZE;
2958 1 : *(uint16_t *)ptr = 0;
2959 :
2960 1 : ptr += sizeof(uint16_t);
2961 1 : libspdm_copy_mem(ptr, SPDM_REQ_CONTEXT_SIZE, m_requester_context, SPDM_REQ_CONTEXT_SIZE);
2962 :
2963 1 : libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
2964 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
2965 : spdm_response, spdm_response_size);
2966 :
2967 1 : m_libspdm_local_buffer_size += spdm_response_size;
2968 :
2969 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
2970 : false, spdm_response_size,
2971 : spdm_response, response_size,
2972 : response);
2973 : }
2974 1 : return LIBSPDM_STATUS_SUCCESS;
2975 1 : case 0x29: {
2976 : spdm_measurements_response_t *spdm_response;
2977 : spdm_measurement_block_dmtf_t *measurment_block;
2978 : size_t spdm_response_size;
2979 : size_t transport_header_size;
2980 : uint8_t *ptr;
2981 : ((libspdm_context_t *)spdm_context)
2982 1 : ->connection_info.algorithm.measurement_hash_algo = m_libspdm_use_measurement_hash_algo;
2983 1 : spdm_response_size = sizeof(spdm_measurements_response_t) +
2984 : sizeof(spdm_measurement_block_dmtf_t) +
2985 1 : libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo)
2986 : +
2987 : SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE;
2988 :
2989 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
2990 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
2991 :
2992 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
2993 1 : spdm_response->header.request_response_code = SPDM_MEASUREMENTS;
2994 1 : spdm_response->header.param1 = 0;
2995 1 : spdm_response->header.param2 = 0;
2996 1 : spdm_response->number_of_blocks = 1;
2997 1 : libspdm_write_uint24(
2998 1 : spdm_response->measurement_record_length,
2999 : (uint32_t)(sizeof(spdm_measurement_block_dmtf_t) +
3000 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo)));
3001 :
3002 1 : measurment_block = (void *)(spdm_response + 1);
3003 1 : libspdm_set_mem(measurment_block,
3004 : sizeof(spdm_measurement_block_dmtf_t) +
3005 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo), 1);
3006 :
3007 : measurment_block->measurement_block_common_header
3008 1 : .measurement_specification = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3009 : measurment_block->measurement_block_common_header
3010 1 : .measurement_size =
3011 1 : (uint16_t)(sizeof(spdm_measurement_block_dmtf_header_t) +
3012 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo));
3013 :
3014 1 : ptr = (uint8_t *)spdm_response +
3015 : sizeof(spdm_measurements_response_t) +
3016 1 : sizeof(spdm_measurement_block_dmtf_t) +
3017 1 : libspdm_get_measurement_hash_size( m_libspdm_use_measurement_hash_algo);
3018 1 : libspdm_get_random_number(SPDM_NONCE_SIZE,ptr);
3019 :
3020 1 : ptr += SPDM_NONCE_SIZE;
3021 1 : *(uint16_t *)ptr = 0;
3022 :
3023 1 : ptr += sizeof(uint16_t);
3024 1 : libspdm_get_random_number(SPDM_REQ_CONTEXT_SIZE,ptr);
3025 :
3026 1 : libspdm_copy_mem(m_libspdm_local_buffer + m_libspdm_local_buffer_size,
3027 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
3028 : spdm_response, spdm_response_size);
3029 :
3030 1 : m_libspdm_local_buffer_size += spdm_response_size;
3031 :
3032 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
3033 : false, spdm_response_size,
3034 : spdm_response, response_size,
3035 : response);
3036 : }
3037 1 : return LIBSPDM_STATUS_SUCCESS;
3038 0 : default:
3039 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
3040 : }
3041 : }
3042 :
3043 : /**
3044 : * Test 1: message could not be sent
3045 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
3046 : **/
3047 1 : static void req_get_measurements_case1(void **state)
3048 : {
3049 : libspdm_return_t status;
3050 : libspdm_test_context_t *spdm_test_context;
3051 : libspdm_context_t *spdm_context;
3052 : uint8_t number_of_block;
3053 : uint32_t measurement_record_length;
3054 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3055 : uint8_t request_attribute;
3056 : void *data;
3057 : size_t data_size;
3058 : void *hash;
3059 : size_t hash_size;
3060 :
3061 1 : spdm_test_context = *state;
3062 1 : spdm_context = spdm_test_context->spdm_context;
3063 1 : spdm_test_context->case_id = 0x1;
3064 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3065 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3066 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3067 1 : spdm_context->connection_info.capability.flags |=
3068 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3069 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3070 : m_libspdm_use_asym_algo, &data,
3071 : &data_size, &hash, &hash_size)) {
3072 0 : assert(false);
3073 : }
3074 1 : libspdm_reset_message_m(spdm_context, NULL);
3075 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3076 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3077 : m_libspdm_use_measurement_hash_algo;
3078 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3079 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3080 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3081 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3082 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3083 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3084 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3085 : data, data_size);
3086 : #else
3087 1 : libspdm_hash_all(
3088 : spdm_context->connection_info.algorithm.base_hash_algo,
3089 : data, data_size,
3090 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3091 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3092 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3093 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3094 : spdm_context->connection_info.algorithm.base_hash_algo,
3095 : spdm_context->connection_info.algorithm.base_asym_algo,
3096 : data, data_size,
3097 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3098 : #endif
3099 :
3100 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3101 :
3102 1 : measurement_record_length = sizeof(measurement_record);
3103 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3104 : 0, NULL, &number_of_block,
3105 : &measurement_record_length,
3106 : measurement_record);
3107 1 : assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
3108 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3109 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3110 : #endif
3111 1 : free(data);
3112 1 : }
3113 :
3114 : /**
3115 : * Test 2: Successful response to get a measurement with signature
3116 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, with an empty transcript.message_m
3117 : **/
3118 1 : static void req_get_measurements_case2(void **state)
3119 : {
3120 : libspdm_return_t status;
3121 : libspdm_test_context_t *spdm_test_context;
3122 : libspdm_context_t *spdm_context;
3123 : uint8_t number_of_block;
3124 : uint32_t measurement_record_length;
3125 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3126 : uint8_t request_attribute;
3127 : void *data;
3128 : size_t data_size;
3129 : void *hash;
3130 : size_t hash_size;
3131 :
3132 1 : spdm_test_context = *state;
3133 1 : spdm_context = spdm_test_context->spdm_context;
3134 1 : spdm_test_context->case_id = 0x2;
3135 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3136 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3137 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3138 1 : spdm_context->connection_info.capability.flags |=
3139 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3140 1 : if (!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 0 : assert(false);
3144 : }
3145 1 : libspdm_reset_message_m(spdm_context, NULL);
3146 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3147 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3148 : m_libspdm_use_measurement_hash_algo;
3149 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3150 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3151 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3152 :
3153 : #if LIBSPDM_ENABLE_MSG_LOG
3154 1 : libspdm_init_msg_log (spdm_context, m_libspdm_msg_log_buffer, sizeof(m_libspdm_msg_log_buffer));
3155 1 : libspdm_set_msg_log_mode (spdm_context, LIBSPDM_MSG_LOG_MODE_ENABLE);
3156 : #endif /* LIBSPDM_ENABLE_MSG_LOG */
3157 :
3158 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3159 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3160 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3161 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3162 : data, data_size);
3163 : #else
3164 1 : libspdm_hash_all(
3165 : spdm_context->connection_info.algorithm.base_hash_algo,
3166 : data, data_size,
3167 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3168 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3169 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3170 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3171 : spdm_context->connection_info.algorithm.base_hash_algo,
3172 : spdm_context->connection_info.algorithm.base_asym_algo,
3173 : data, data_size,
3174 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3175 : #endif
3176 :
3177 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3178 :
3179 1 : measurement_record_length = sizeof(measurement_record);
3180 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3181 : 0, NULL, &number_of_block,
3182 : &measurement_record_length,
3183 : measurement_record);
3184 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3185 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3186 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3187 : #endif
3188 1 : free(data);
3189 :
3190 : #if LIBSPDM_ENABLE_MSG_LOG
3191 1 : libspdm_reset_msg_log(spdm_context);
3192 : #endif /* LIBSPDM_ENABLE_MSG_LOG */
3193 1 : }
3194 :
3195 : /**
3196 : * Test 3: Exercise the libspdm_get_measurement_ex function.
3197 : * Expected Behavior: Requester uses requester_nonce_in and returns responder_nonce.
3198 : **/
3199 1 : static void req_get_measurements_case3(void **state)
3200 : {
3201 : libspdm_return_t status;
3202 : libspdm_test_context_t *spdm_test_context;
3203 : libspdm_context_t *spdm_context;
3204 : uint8_t number_of_block;
3205 : uint32_t measurement_record_length;
3206 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3207 : uint8_t request_attribute;
3208 : void *data;
3209 : size_t data_size;
3210 : void *hash;
3211 : size_t hash_size;
3212 : uint8_t requester_nonce_in[SPDM_NONCE_SIZE];
3213 : uint8_t requester_nonce[SPDM_NONCE_SIZE];
3214 : uint8_t responder_nonce[SPDM_NONCE_SIZE];
3215 : uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
3216 : size_t opaque_data_size;
3217 :
3218 1 : spdm_test_context = *state;
3219 1 : spdm_context = spdm_test_context->spdm_context;
3220 1 : spdm_test_context->case_id = 0x3;
3221 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3222 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3223 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3224 1 : spdm_context->connection_info.capability.flags |=
3225 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3226 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3227 : m_libspdm_use_asym_algo, &data,
3228 : &data_size, &hash, &hash_size)) {
3229 0 : assert(false);
3230 : }
3231 1 : libspdm_reset_message_m(spdm_context, NULL);
3232 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3233 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3234 : m_libspdm_use_measurement_hash_algo;
3235 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3236 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3237 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3238 :
3239 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3240 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3241 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3242 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3243 : data, data_size);
3244 : #else
3245 1 : libspdm_hash_all(
3246 : spdm_context->connection_info.algorithm.base_hash_algo,
3247 : data, data_size,
3248 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3249 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3250 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3251 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3252 : spdm_context->connection_info.algorithm.base_hash_algo,
3253 : spdm_context->connection_info.algorithm.base_asym_algo,
3254 : data, data_size,
3255 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3256 : #endif
3257 :
3258 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3259 :
3260 1 : measurement_record_length = sizeof(measurement_record);
3261 :
3262 33 : for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
3263 32 : requester_nonce_in[index] = 0x5c;
3264 32 : requester_nonce[index] = 0x00;
3265 32 : responder_nonce[index] = 0x00;
3266 : }
3267 :
3268 1 : opaque_data_size = sizeof(opaque_data);
3269 :
3270 1 : status = libspdm_get_measurement_ex(spdm_context, NULL, request_attribute, 1,
3271 : 0, NULL, &number_of_block,
3272 : &measurement_record_length,
3273 : measurement_record, requester_nonce_in,
3274 : requester_nonce, responder_nonce,
3275 : opaque_data, &opaque_data_size);
3276 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3277 33 : for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
3278 32 : assert_int_equal (requester_nonce_in[index], requester_nonce[index]);
3279 32 : assert_int_equal (responder_nonce[index], 0x12);
3280 : }
3281 1 : assert_int_equal(opaque_data_size, strlen("libspdm"));
3282 1 : assert_memory_equal(opaque_data, "libspdm", strlen("libspdm"));
3283 :
3284 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3285 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3286 : #endif
3287 1 : free(data);
3288 1 : }
3289 :
3290 : /**
3291 : * Test 4: Error case, always get an error response with code SPDM_ERROR_CODE_INVALID_REQUEST
3292 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
3293 : **/
3294 1 : static void req_get_measurements_case4(void **state)
3295 : {
3296 : libspdm_return_t status;
3297 : libspdm_test_context_t *spdm_test_context;
3298 : libspdm_context_t *spdm_context;
3299 : uint8_t number_of_block;
3300 : uint32_t measurement_record_length;
3301 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3302 : uint8_t request_attribute;
3303 : void *data;
3304 : size_t data_size;
3305 : void *hash;
3306 : size_t hash_size;
3307 :
3308 1 : spdm_test_context = *state;
3309 1 : spdm_context = spdm_test_context->spdm_context;
3310 1 : spdm_test_context->case_id = 0x4;
3311 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3312 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3313 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3314 1 : spdm_context->connection_info.capability.flags |=
3315 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3316 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3317 : m_libspdm_use_asym_algo, &data,
3318 : &data_size, &hash, &hash_size)) {
3319 0 : assert(false);
3320 : }
3321 1 : libspdm_reset_message_m(spdm_context, NULL);
3322 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3323 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3324 : m_libspdm_use_measurement_hash_algo;
3325 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3326 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3327 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3328 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3329 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3330 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3331 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3332 : data, data_size);
3333 : #else
3334 1 : libspdm_hash_all(
3335 : spdm_context->connection_info.algorithm.base_hash_algo,
3336 : data, data_size,
3337 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3338 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3339 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3340 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3341 : spdm_context->connection_info.algorithm.base_hash_algo,
3342 : spdm_context->connection_info.algorithm.base_asym_algo,
3343 : data, data_size,
3344 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3345 : #endif
3346 :
3347 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3348 :
3349 1 : measurement_record_length = sizeof(measurement_record);
3350 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3351 : 0, NULL, &number_of_block,
3352 : &measurement_record_length,
3353 : measurement_record);
3354 1 : assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
3355 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3356 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3357 : #endif
3358 1 : free(data);
3359 1 : }
3360 :
3361 : /**
3362 : * Test 5: Error case, always get an error response with code SPDM_ERROR_CODE_BUSY
3363 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
3364 : **/
3365 1 : static void req_get_measurements_case5(void **state)
3366 : {
3367 : libspdm_return_t status;
3368 : libspdm_test_context_t *spdm_test_context;
3369 : libspdm_context_t *spdm_context;
3370 : uint8_t number_of_block;
3371 : uint32_t measurement_record_length;
3372 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3373 : uint8_t request_attribute;
3374 : void *data;
3375 : size_t data_size;
3376 : void *hash;
3377 : size_t hash_size;
3378 :
3379 1 : spdm_test_context = *state;
3380 1 : spdm_context = spdm_test_context->spdm_context;
3381 1 : spdm_test_context->case_id = 0x5;
3382 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3383 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3384 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3385 1 : spdm_context->connection_info.capability.flags |=
3386 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3387 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3388 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3389 : m_libspdm_use_asym_algo, &data,
3390 : &data_size, &hash, &hash_size)) {
3391 0 : assert(false);
3392 : }
3393 1 : libspdm_reset_message_m(spdm_context, NULL);
3394 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3395 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3396 : m_libspdm_use_measurement_hash_algo;
3397 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3398 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3399 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3400 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3401 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3402 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3403 : data, data_size);
3404 : #else
3405 1 : libspdm_hash_all(
3406 : spdm_context->connection_info.algorithm.base_hash_algo,
3407 : data, data_size,
3408 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3409 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3410 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3411 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3412 : spdm_context->connection_info.algorithm.base_hash_algo,
3413 : spdm_context->connection_info.algorithm.base_asym_algo,
3414 : data, data_size,
3415 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3416 : #endif
3417 :
3418 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3419 :
3420 1 : measurement_record_length = sizeof(measurement_record);
3421 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3422 : 0, NULL, &number_of_block,
3423 : &measurement_record_length,
3424 : measurement_record);
3425 1 : assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
3426 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3427 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3428 : #endif
3429 1 : free(data);
3430 1 : }
3431 :
3432 : /**
3433 : * Test 6: Successfully get one measurement block (signed), after getting SPDM_ERROR_CODE_BUSY on first attempt
3434 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, with an empty transcript.message_m
3435 : **/
3436 1 : static void req_get_measurements_case6(void **state)
3437 : {
3438 : libspdm_return_t status;
3439 : libspdm_test_context_t *spdm_test_context;
3440 : libspdm_context_t *spdm_context;
3441 : uint8_t number_of_block;
3442 : uint32_t measurement_record_length;
3443 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3444 : uint8_t request_attribute;
3445 : void *data;
3446 : size_t data_size;
3447 : void *hash;
3448 : size_t hash_size;
3449 :
3450 1 : spdm_test_context = *state;
3451 1 : spdm_context = spdm_test_context->spdm_context;
3452 1 : spdm_test_context->case_id = 0x6;
3453 1 : spdm_context->retry_times = 3;
3454 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3455 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3456 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3457 1 : spdm_context->connection_info.capability.flags |=
3458 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3459 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3460 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3461 : m_libspdm_use_asym_algo, &data,
3462 : &data_size, &hash, &hash_size)) {
3463 0 : assert(false);
3464 : }
3465 1 : libspdm_reset_message_m(spdm_context, NULL);
3466 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3467 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3468 : m_libspdm_use_measurement_hash_algo;
3469 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3470 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3471 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3472 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3473 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3474 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3475 : data, data_size);
3476 : #else
3477 1 : libspdm_hash_all(
3478 : spdm_context->connection_info.algorithm.base_hash_algo,
3479 : data, data_size,
3480 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3481 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3482 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3483 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3484 : spdm_context->connection_info.algorithm.base_hash_algo,
3485 : spdm_context->connection_info.algorithm.base_asym_algo,
3486 : data, data_size,
3487 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3488 : #endif
3489 :
3490 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3491 :
3492 1 : measurement_record_length = sizeof(measurement_record);
3493 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3494 : 0, NULL, &number_of_block,
3495 : &measurement_record_length,
3496 : measurement_record);
3497 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3498 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3499 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3500 : #endif
3501 1 : free(data);
3502 1 : }
3503 :
3504 : /**
3505 : * Test 7: Error case, get an error response with code SPDM_ERROR_CODE_REQUEST_RESYNCH
3506 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
3507 : **/
3508 1 : static void req_get_measurements_case7(void **state)
3509 : {
3510 : libspdm_return_t status;
3511 : libspdm_test_context_t *spdm_test_context;
3512 : libspdm_context_t *spdm_context;
3513 : uint8_t number_of_block;
3514 : uint32_t measurement_record_length;
3515 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3516 : uint8_t request_attribute;
3517 : void *data;
3518 : size_t data_size;
3519 : void *hash;
3520 : size_t hash_size;
3521 :
3522 1 : spdm_test_context = *state;
3523 1 : spdm_context = spdm_test_context->spdm_context;
3524 1 : spdm_test_context->case_id = 0x7;
3525 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3526 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3527 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3528 1 : spdm_context->connection_info.capability.flags |=
3529 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3530 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3531 : m_libspdm_use_asym_algo, &data,
3532 : &data_size, &hash, &hash_size)) {
3533 0 : assert(false);
3534 : }
3535 1 : libspdm_reset_message_m(spdm_context, NULL);
3536 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3537 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3538 : m_libspdm_use_measurement_hash_algo;
3539 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3540 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3541 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3542 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3543 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3544 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3545 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3546 : data, data_size);
3547 : #else
3548 1 : libspdm_hash_all(
3549 : spdm_context->connection_info.algorithm.base_hash_algo,
3550 : data, data_size,
3551 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3552 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3553 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3554 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3555 : spdm_context->connection_info.algorithm.base_hash_algo,
3556 : spdm_context->connection_info.algorithm.base_asym_algo,
3557 : data, data_size,
3558 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3559 : #endif
3560 :
3561 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3562 :
3563 1 : measurement_record_length = sizeof(measurement_record);
3564 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3565 : 0, NULL, &number_of_block,
3566 : &measurement_record_length,
3567 : measurement_record);
3568 1 : assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
3569 1 : assert_int_equal(spdm_context->connection_info.connection_state,
3570 : LIBSPDM_CONNECTION_STATE_NOT_STARTED);
3571 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3572 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3573 : #endif
3574 1 : free(data);
3575 1 : }
3576 :
3577 : /**
3578 : * Test 8: Error case, always get an error response with code SPDM_ERROR_CODE_RESPONSE_NOT_READY
3579 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, with an empty transcript.message_m
3580 : **/
3581 1 : static void req_get_measurements_case8(void **state)
3582 : {
3583 : libspdm_return_t status;
3584 : libspdm_test_context_t *spdm_test_context;
3585 : libspdm_context_t *spdm_context;
3586 : uint8_t number_of_block;
3587 : uint32_t measurement_record_length;
3588 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3589 : uint8_t request_attribute;
3590 : void *data;
3591 : size_t data_size;
3592 : void *hash;
3593 : size_t hash_size;
3594 :
3595 1 : spdm_test_context = *state;
3596 1 : spdm_context = spdm_test_context->spdm_context;
3597 1 : spdm_test_context->case_id = 0x8;
3598 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3599 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3600 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3601 1 : spdm_context->connection_info.capability.flags |=
3602 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3603 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3604 : m_libspdm_use_asym_algo, &data,
3605 : &data_size, &hash, &hash_size)) {
3606 0 : assert(false);
3607 : }
3608 1 : libspdm_reset_message_m(spdm_context, NULL);
3609 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3610 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3611 : m_libspdm_use_measurement_hash_algo;
3612 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3613 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3614 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3615 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3616 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3617 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3618 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3619 : data, data_size);
3620 : #else
3621 1 : libspdm_hash_all(
3622 : spdm_context->connection_info.algorithm.base_hash_algo,
3623 : data, data_size,
3624 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3625 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3626 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3627 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3628 : spdm_context->connection_info.algorithm.base_hash_algo,
3629 : spdm_context->connection_info.algorithm.base_asym_algo,
3630 : data, data_size,
3631 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3632 : #endif
3633 :
3634 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3635 :
3636 1 : measurement_record_length = sizeof(measurement_record);
3637 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3638 : 0, NULL, &number_of_block,
3639 : &measurement_record_length,
3640 : measurement_record);
3641 1 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
3642 1 : free(data);
3643 1 : }
3644 :
3645 : /**
3646 : * Test 9: Successfully get one measurement block (signed), after getting SPDM_ERROR_CODE_RESPONSE_NOT_READY on first attempt
3647 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, with an empty transcript.message_m
3648 : **/
3649 1 : static void req_get_measurements_case9(void **state)
3650 : {
3651 : libspdm_return_t status;
3652 : libspdm_test_context_t *spdm_test_context;
3653 : libspdm_context_t *spdm_context;
3654 : uint8_t number_of_block;
3655 : uint32_t measurement_record_length;
3656 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3657 : uint8_t request_attribute;
3658 : void *data;
3659 : size_t data_size;
3660 : void *hash;
3661 : size_t hash_size;
3662 :
3663 1 : spdm_test_context = *state;
3664 1 : spdm_context = spdm_test_context->spdm_context;
3665 1 : spdm_test_context->case_id = 0x9;
3666 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3667 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3668 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3669 1 : spdm_context->connection_info.capability.flags |=
3670 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3671 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3672 : m_libspdm_use_asym_algo, &data,
3673 : &data_size, &hash, &hash_size)) {
3674 0 : assert(false);
3675 : }
3676 1 : libspdm_reset_message_m(spdm_context, NULL);
3677 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3678 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3679 : m_libspdm_use_measurement_hash_algo;
3680 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3681 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3682 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3683 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3684 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3685 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3686 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3687 : data, data_size);
3688 : #else
3689 1 : libspdm_hash_all(
3690 : spdm_context->connection_info.algorithm.base_hash_algo,
3691 : data, data_size,
3692 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3693 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3694 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3695 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3696 : spdm_context->connection_info.algorithm.base_hash_algo,
3697 : spdm_context->connection_info.algorithm.base_asym_algo,
3698 : data, data_size,
3699 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3700 : #endif
3701 :
3702 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3703 :
3704 1 : measurement_record_length = sizeof(measurement_record);
3705 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3706 : 0, NULL, &number_of_block,
3707 : &measurement_record_length,
3708 : measurement_record);
3709 : if (LIBSPDM_RESPOND_IF_READY_SUPPORT) {
3710 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3711 : } else {
3712 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
3713 : }
3714 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3715 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3716 : #endif
3717 1 : free(data);
3718 1 : }
3719 :
3720 : /**
3721 : * Test 10: Successful response to get total number of measurements, without signature
3722 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, correct number_of_blocks, correct transcript.message_m.buffer_size
3723 : **/
3724 1 : static void req_get_measurements_case10(void **state)
3725 : {
3726 : libspdm_return_t status;
3727 : libspdm_test_context_t *spdm_test_context;
3728 : libspdm_context_t *spdm_context;
3729 : uint8_t number_of_blocks;
3730 : uint8_t request_attribute;
3731 : void *data;
3732 : size_t data_size;
3733 : void *hash;
3734 : size_t hash_size;
3735 :
3736 1 : spdm_test_context = *state;
3737 1 : spdm_context = spdm_test_context->spdm_context;
3738 1 : spdm_test_context->case_id = 0xA;
3739 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3740 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3741 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3742 1 : spdm_context->connection_info.capability.flags |=
3743 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3744 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3745 : m_libspdm_use_asym_algo, &data,
3746 : &data_size, &hash, &hash_size)) {
3747 0 : assert(false);
3748 : }
3749 1 : libspdm_reset_message_m(spdm_context, NULL);
3750 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3751 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3752 : m_libspdm_use_measurement_hash_algo;
3753 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3754 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3755 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3756 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3757 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3758 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3759 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3760 : data, data_size);
3761 : #else
3762 1 : libspdm_hash_all(
3763 : spdm_context->connection_info.algorithm.base_hash_algo,
3764 : data, data_size,
3765 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3766 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3767 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3768 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3769 : spdm_context->connection_info.algorithm.base_hash_algo,
3770 : spdm_context->connection_info.algorithm.base_asym_algo,
3771 : data, data_size,
3772 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3773 : #endif
3774 :
3775 1 : request_attribute = 0;
3776 :
3777 1 : status = libspdm_get_measurement(
3778 : spdm_context, NULL, request_attribute,
3779 : SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
3780 : 0, NULL, &number_of_blocks, NULL, NULL);
3781 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3782 1 : assert_int_equal(number_of_blocks, 4);
3783 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3784 : assert_int_equal(spdm_context->transcript.message_m.buffer_size,
3785 : sizeof(spdm_message_header_t) +
3786 : sizeof(spdm_measurements_response_t) +
3787 : SPDM_NONCE_SIZE + sizeof(uint16_t));
3788 : #endif
3789 1 : free(data);
3790 1 : }
3791 :
3792 : /**
3793 : * Test 11: Successful response to get a measurement block, without signature
3794 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, correct transcript.message_m.buffer_size
3795 : **/
3796 1 : static void req_get_measurements_case11(void **state)
3797 : {
3798 : libspdm_return_t status;
3799 : libspdm_test_context_t *spdm_test_context;
3800 : libspdm_context_t *spdm_context;
3801 : uint8_t number_of_block;
3802 : uint32_t measurement_record_length;
3803 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3804 : uint8_t request_attribute;
3805 : void *data;
3806 : size_t data_size;
3807 : void *hash;
3808 : size_t hash_size;
3809 :
3810 1 : spdm_test_context = *state;
3811 1 : spdm_context = spdm_test_context->spdm_context;
3812 1 : spdm_test_context->case_id = 0xB;
3813 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3814 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3815 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3816 1 : spdm_context->connection_info.capability.flags |=
3817 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3818 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3819 : m_libspdm_use_asym_algo, &data,
3820 : &data_size, &hash, &hash_size)) {
3821 0 : assert(false);
3822 : }
3823 1 : libspdm_reset_message_m(spdm_context, NULL);
3824 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3825 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3826 : m_libspdm_use_measurement_hash_algo;
3827 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3828 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3829 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3830 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3831 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3832 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3833 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3834 : data, data_size);
3835 : #else
3836 1 : libspdm_hash_all(
3837 : spdm_context->connection_info.algorithm.base_hash_algo,
3838 : data, data_size,
3839 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3840 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3841 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3842 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3843 : spdm_context->connection_info.algorithm.base_hash_algo,
3844 : spdm_context->connection_info.algorithm.base_asym_algo,
3845 : data, data_size,
3846 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3847 : #endif
3848 :
3849 1 : request_attribute = 0;
3850 :
3851 1 : measurement_record_length = sizeof(measurement_record);
3852 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3853 : 0, NULL, &number_of_block,
3854 : &measurement_record_length,
3855 : measurement_record);
3856 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
3857 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3858 : assert_int_equal(spdm_context->transcript.message_m.buffer_size,
3859 : sizeof(spdm_message_header_t) +
3860 : sizeof(spdm_measurements_response_t) +
3861 : sizeof(spdm_measurement_block_dmtf_t) +
3862 : libspdm_get_measurement_hash_size(
3863 : m_libspdm_use_measurement_hash_algo) +
3864 : SPDM_NONCE_SIZE + sizeof(uint16_t));
3865 : #endif
3866 1 : free(data);
3867 1 : }
3868 :
3869 : /**
3870 : * Test 12: Error case, signature is invalid (all bytes are 0)
3871 : * Expected Behavior: get a RETURN_SECURITY_VIOLATION return code
3872 : **/
3873 1 : static void req_get_measurements_case12(void **state)
3874 : {
3875 : libspdm_return_t status;
3876 : libspdm_test_context_t *spdm_test_context;
3877 : libspdm_context_t *spdm_context;
3878 : uint8_t number_of_block;
3879 : uint32_t measurement_record_length;
3880 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3881 : uint8_t request_attribute;
3882 : void *data;
3883 : size_t data_size;
3884 : void *hash;
3885 : size_t hash_size;
3886 :
3887 1 : spdm_test_context = *state;
3888 1 : spdm_context = spdm_test_context->spdm_context;
3889 1 : spdm_test_context->case_id = 0xC;
3890 :
3891 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3892 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3893 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3894 1 : spdm_context->connection_info.capability.flags |=
3895 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3896 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3897 : m_libspdm_use_asym_algo, &data,
3898 : &data_size, &hash, &hash_size)) {
3899 0 : assert(false);
3900 : }
3901 1 : libspdm_reset_message_m(spdm_context, NULL);
3902 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3903 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3904 : m_libspdm_use_measurement_hash_algo;
3905 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3906 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3907 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3908 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3909 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3910 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3911 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3912 : data, data_size);
3913 : #else
3914 1 : libspdm_hash_all(
3915 : spdm_context->connection_info.algorithm.base_hash_algo,
3916 : data, data_size,
3917 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3918 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3919 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3920 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3921 : spdm_context->connection_info.algorithm.base_hash_algo,
3922 : spdm_context->connection_info.algorithm.base_asym_algo,
3923 : data, data_size,
3924 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3925 : #endif
3926 :
3927 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
3928 :
3929 1 : measurement_record_length = sizeof(measurement_record);
3930 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
3931 : 0, NULL, &number_of_block,
3932 : &measurement_record_length,
3933 : measurement_record);
3934 1 : assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
3935 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3936 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
3937 : #endif
3938 1 : free(data);
3939 1 : }
3940 :
3941 : /**
3942 : * Test 13: Error case, signature is invalid (random)
3943 : * Expected Behavior: get a RETURN_SECURITY_VIOLATION return code
3944 : **/
3945 1 : static void req_get_measurements_case13(void **state)
3946 : {
3947 : libspdm_return_t status;
3948 : libspdm_test_context_t *spdm_test_context;
3949 : libspdm_context_t *spdm_context;
3950 : uint8_t number_of_block;
3951 : uint32_t measurement_record_length;
3952 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
3953 : uint8_t request_attribute;
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 1 : spdm_test_context->case_id = 0xD;
3962 :
3963 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
3964 : SPDM_VERSION_NUMBER_SHIFT_BIT;
3965 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
3966 1 : spdm_context->connection_info.capability.flags |=
3967 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
3968 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
3969 : m_libspdm_use_asym_algo, &data,
3970 : &data_size, &hash, &hash_size)) {
3971 0 : assert(false);
3972 : }
3973 1 : libspdm_reset_message_m(spdm_context, NULL);
3974 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
3975 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
3976 : m_libspdm_use_measurement_hash_algo;
3977 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
3978 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
3979 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
3980 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
3981 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
3982 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
3983 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
3984 : data, data_size);
3985 : #else
3986 1 : libspdm_hash_all(
3987 : spdm_context->connection_info.algorithm.base_hash_algo,
3988 : data, data_size,
3989 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
3990 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
3991 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
3992 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
3993 : spdm_context->connection_info.algorithm.base_hash_algo,
3994 : spdm_context->connection_info.algorithm.base_asym_algo,
3995 : data, data_size,
3996 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
3997 : #endif
3998 :
3999 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
4000 :
4001 1 : measurement_record_length = sizeof(measurement_record);
4002 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4003 : 0, NULL, &number_of_block,
4004 : &measurement_record_length,
4005 : measurement_record);
4006 1 : assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
4007 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4008 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4009 : #endif
4010 1 : free(data);
4011 1 : }
4012 :
4013 : /**
4014 : * Test 14: Error case, request a signed response, but response is malformed (signature absent)
4015 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code
4016 : **/
4017 1 : static void req_get_measurements_case14(void **state)
4018 : {
4019 : libspdm_return_t status;
4020 : libspdm_test_context_t *spdm_test_context;
4021 : libspdm_context_t *spdm_context;
4022 : uint8_t number_of_block;
4023 : uint32_t measurement_record_length;
4024 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4025 : uint8_t request_attribute;
4026 : void *data;
4027 : size_t data_size;
4028 : void *hash;
4029 : size_t hash_size;
4030 :
4031 1 : spdm_test_context = *state;
4032 1 : spdm_context = spdm_test_context->spdm_context;
4033 1 : spdm_test_context->case_id = 0xE;
4034 :
4035 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4036 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4037 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4038 1 : spdm_context->connection_info.capability.flags |=
4039 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4040 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4041 : m_libspdm_use_asym_algo, &data,
4042 : &data_size, &hash, &hash_size)) {
4043 0 : assert(false);
4044 : }
4045 1 : libspdm_reset_message_m(spdm_context, NULL);
4046 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4047 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4048 : m_libspdm_use_measurement_hash_algo;
4049 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4050 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4051 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4052 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4053 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4054 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4055 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4056 : data, data_size);
4057 : #else
4058 1 : libspdm_hash_all(
4059 : spdm_context->connection_info.algorithm.base_hash_algo,
4060 : data, data_size,
4061 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4062 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4063 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4064 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4065 : spdm_context->connection_info.algorithm.base_hash_algo,
4066 : spdm_context->connection_info.algorithm.base_asym_algo,
4067 : data, data_size,
4068 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4069 : #endif
4070 :
4071 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
4072 :
4073 1 : measurement_record_length = sizeof(measurement_record);
4074 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4075 : 0, NULL, &number_of_block,
4076 : &measurement_record_length,
4077 : measurement_record);
4078 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
4079 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4080 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4081 : #endif
4082 1 : free(data);
4083 1 : }
4084 :
4085 : /**
4086 : * Test 15: Error case, response with wrong response code
4087 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code
4088 : **/
4089 1 : static void req_get_measurements_case15(void **state)
4090 : {
4091 : libspdm_return_t status;
4092 : libspdm_test_context_t *spdm_test_context;
4093 : libspdm_context_t *spdm_context;
4094 : uint8_t number_of_block;
4095 : uint32_t measurement_record_length;
4096 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4097 : uint8_t request_attribute;
4098 : void *data;
4099 : size_t data_size;
4100 : void *hash;
4101 : size_t hash_size;
4102 :
4103 1 : spdm_test_context = *state;
4104 1 : spdm_context = spdm_test_context->spdm_context;
4105 1 : spdm_test_context->case_id = 0xF;
4106 :
4107 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4108 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4109 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4110 1 : spdm_context->connection_info.capability.flags |=
4111 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4112 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4113 : m_libspdm_use_asym_algo, &data,
4114 : &data_size, &hash, &hash_size)) {
4115 0 : assert(false);
4116 : }
4117 1 : libspdm_reset_message_m(spdm_context, NULL);
4118 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4119 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4120 : m_libspdm_use_measurement_hash_algo;
4121 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4122 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4123 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4124 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4125 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4126 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4127 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4128 : data, data_size);
4129 : #else
4130 1 : libspdm_hash_all(
4131 : spdm_context->connection_info.algorithm.base_hash_algo,
4132 : data, data_size,
4133 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4134 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4135 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4136 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4137 : spdm_context->connection_info.algorithm.base_hash_algo,
4138 : spdm_context->connection_info.algorithm.base_asym_algo,
4139 : data, data_size,
4140 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4141 : #endif
4142 :
4143 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
4144 :
4145 1 : measurement_record_length = sizeof(measurement_record);
4146 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4147 : 0, NULL, &number_of_block,
4148 : &measurement_record_length,
4149 : measurement_record);
4150 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4151 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4152 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4153 : #endif
4154 1 : free(data);
4155 1 : }
4156 :
4157 : /**
4158 : * Test 16: SlotID verificaton, the response's SlotID should match the request
4159 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code if the fields match, RETURN_DEVICE_ERROR otherwise. Either way, transcript.message_m should be empty
4160 : **/
4161 1 : static void req_get_measurements_case16(void **state)
4162 : {
4163 : libspdm_return_t status;
4164 : libspdm_test_context_t *spdm_test_context;
4165 : libspdm_context_t *spdm_context;
4166 : uint8_t number_of_block;
4167 : uint32_t measurement_record_length;
4168 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4169 : uint8_t request_attribute;
4170 : void *data;
4171 : size_t data_size;
4172 : void *hash;
4173 : size_t hash_size;
4174 1 : uint8_t SlotIDs[] = { 0, 1, 2, 3 };
4175 :
4176 1 : spdm_test_context = *state;
4177 1 : spdm_context = spdm_test_context->spdm_context;
4178 1 : spdm_test_context->case_id = 0x10;
4179 :
4180 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4181 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4182 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4183 1 : spdm_context->connection_info.capability.flags |=
4184 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4185 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4186 : m_libspdm_use_asym_algo, &data,
4187 : &data_size, &hash, &hash_size)) {
4188 0 : assert(false);
4189 : }
4190 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4191 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4192 : m_libspdm_use_measurement_hash_algo;
4193 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4194 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4195 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4196 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4197 : for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
4198 : spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_size = data_size;
4199 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer,
4200 : sizeof(spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].
4201 : buffer),
4202 : data, data_size);
4203 : }
4204 : #else
4205 5 : for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
4206 4 : libspdm_hash_all(
4207 : spdm_context->connection_info.algorithm.base_hash_algo,
4208 : data, data_size,
4209 4 : spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_hash);
4210 8 : spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].buffer_hash_size =
4211 4 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4212 4 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4213 : spdm_context->connection_info.algorithm.base_hash_algo,
4214 : spdm_context->connection_info.algorithm.base_asym_algo,
4215 : data, data_size,
4216 4 : &spdm_context->connection_info.peer_used_cert_chain[SlotIDs[i]].leaf_cert_public_key);
4217 : }
4218 : #endif
4219 :
4220 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
4221 :
4222 5 : for (int i = 0; i < sizeof(SlotIDs) / sizeof(SlotIDs[0]); i++) {
4223 4 : measurement_record_length = sizeof(measurement_record);
4224 4 : libspdm_reset_message_m(spdm_context, NULL);
4225 4 : status = libspdm_get_measurement(spdm_context, NULL,
4226 4 : request_attribute, 1, SlotIDs[i],
4227 : NULL, &number_of_block,
4228 : &measurement_record_length,
4229 : measurement_record);
4230 4 : if (SlotIDs[i] == LIBSPDM_ALTERNATIVE_DEFAULT_SLOT_ID) {
4231 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4232 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4233 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4234 : #endif
4235 : } else {
4236 3 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4237 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4238 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4239 : #endif
4240 : }
4241 : }
4242 1 : free(data);
4243 1 : }
4244 :
4245 : /**
4246 : * Test 17: Error case, response to get total number of measurements, but response number_of_blocks and/or measurement_record_length are non 0
4247 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code
4248 : **/
4249 1 : static void req_get_measurements_case17(void **state)
4250 : {
4251 : libspdm_return_t status;
4252 : libspdm_test_context_t *spdm_test_context;
4253 : libspdm_context_t *spdm_context;
4254 : uint8_t number_of_blocks;
4255 : uint8_t request_attribute;
4256 : void *data;
4257 : size_t data_size;
4258 : void *hash;
4259 : size_t hash_size;
4260 :
4261 1 : spdm_test_context = *state;
4262 1 : spdm_context = spdm_test_context->spdm_context;
4263 1 : spdm_test_context->case_id = 0x11;
4264 :
4265 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4266 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4267 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4268 1 : spdm_context->connection_info.capability.flags |=
4269 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4270 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4271 : m_libspdm_use_asym_algo, &data,
4272 : &data_size, &hash, &hash_size)) {
4273 0 : assert(false);
4274 : }
4275 1 : libspdm_reset_message_m(spdm_context, NULL);
4276 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4277 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4278 : m_libspdm_use_measurement_hash_algo;
4279 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4280 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4281 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4282 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4283 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4284 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4285 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4286 : data, data_size);
4287 : #else
4288 1 : libspdm_hash_all(
4289 : spdm_context->connection_info.algorithm.base_hash_algo,
4290 : data, data_size,
4291 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4292 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4293 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4294 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4295 : spdm_context->connection_info.algorithm.base_hash_algo,
4296 : spdm_context->connection_info.algorithm.base_asym_algo,
4297 : data, data_size,
4298 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4299 : #endif
4300 :
4301 1 : request_attribute = 0;
4302 :
4303 4 : for (int i = 0; i < 3; i++) {
4304 : /* i=0 => both number_of_blocks and measurement_record_length are non 0
4305 : * i=1 => only number_of_blocks is non 0
4306 : * i=2 => only is measurement_record_length is non 0*/
4307 3 : status = libspdm_get_measurement(
4308 : spdm_context, NULL, request_attribute,
4309 : SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
4310 : 0, NULL, &number_of_blocks, NULL, NULL);
4311 3 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4312 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4313 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4314 : #endif
4315 : }
4316 1 : free(data);
4317 1 : }
4318 :
4319 : /**
4320 : * Test 18:
4321 : * Expected Behavior:
4322 : **/
4323 1 : static void req_get_measurements_case18(void **state)
4324 : {
4325 1 : }
4326 :
4327 : /**
4328 : * Test 19: Error case, measurement_specification field in response has 2 bits set (bit 0 is one of them)
4329 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
4330 : **/
4331 1 : static void req_get_measurements_case19(void **state)
4332 : {
4333 : libspdm_return_t status;
4334 : libspdm_test_context_t *spdm_test_context;
4335 : libspdm_context_t *spdm_context;
4336 : uint8_t number_of_block;
4337 : uint32_t measurement_record_length;
4338 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4339 : uint8_t request_attribute;
4340 : void *data;
4341 : size_t data_size;
4342 : void *hash;
4343 : size_t hash_size;
4344 :
4345 1 : spdm_test_context = *state;
4346 1 : spdm_context = spdm_test_context->spdm_context;
4347 1 : spdm_test_context->case_id = 0x13;
4348 :
4349 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4350 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4351 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4352 1 : spdm_context->connection_info.capability.flags |=
4353 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4354 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4355 : m_libspdm_use_asym_algo, &data,
4356 : &data_size, &hash, &hash_size)) {
4357 0 : assert(false);
4358 : }
4359 1 : libspdm_reset_message_m(spdm_context, NULL);
4360 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4361 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4362 : m_libspdm_use_measurement_hash_algo;
4363 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4364 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4365 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4366 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4367 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4368 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4369 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4370 : data, data_size);
4371 : #else
4372 1 : libspdm_hash_all(
4373 : spdm_context->connection_info.algorithm.base_hash_algo,
4374 : data, data_size,
4375 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4376 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4377 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4378 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4379 : spdm_context->connection_info.algorithm.base_hash_algo,
4380 : spdm_context->connection_info.algorithm.base_asym_algo,
4381 : data, data_size,
4382 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4383 : #endif
4384 :
4385 1 : request_attribute = 0;
4386 :
4387 1 : measurement_record_length = sizeof(measurement_record);
4388 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4389 : 0, NULL, &number_of_block,
4390 : &measurement_record_length,
4391 : measurement_record);
4392 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4393 : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
4394 : /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
4395 : /* #endif*/
4396 1 : free(data);
4397 1 : }
4398 :
4399 : /**
4400 : * Test 20: Error case, measurement_specification field in response has 2 bits set (bit 0 is not one of them)
4401 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
4402 : **/
4403 1 : static void req_get_measurements_case20(void **state)
4404 : {
4405 : libspdm_return_t status;
4406 : libspdm_test_context_t *spdm_test_context;
4407 : libspdm_context_t *spdm_context;
4408 : uint8_t number_of_block;
4409 : uint32_t measurement_record_length;
4410 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4411 : uint8_t request_attribute;
4412 : void *data;
4413 : size_t data_size;
4414 : void *hash;
4415 : size_t hash_size;
4416 :
4417 1 : spdm_test_context = *state;
4418 1 : spdm_context = spdm_test_context->spdm_context;
4419 1 : spdm_test_context->case_id = 0x14;
4420 :
4421 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4422 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4423 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4424 1 : spdm_context->connection_info.capability.flags |=
4425 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4426 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4427 : m_libspdm_use_asym_algo, &data,
4428 : &data_size, &hash, &hash_size)) {
4429 0 : assert(false);
4430 : }
4431 1 : libspdm_reset_message_m(spdm_context, NULL);
4432 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4433 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4434 : m_libspdm_use_measurement_hash_algo;
4435 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4436 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4437 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4438 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4439 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4440 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4441 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4442 : data, data_size);
4443 : #else
4444 1 : libspdm_hash_all(
4445 : spdm_context->connection_info.algorithm.base_hash_algo,
4446 : data, data_size,
4447 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4448 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4449 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4450 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4451 : spdm_context->connection_info.algorithm.base_hash_algo,
4452 : spdm_context->connection_info.algorithm.base_asym_algo,
4453 : data, data_size,
4454 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4455 : #endif
4456 :
4457 1 : request_attribute = 0;
4458 :
4459 1 : measurement_record_length = sizeof(measurement_record);
4460 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4461 : 0, NULL, &number_of_block,
4462 : &measurement_record_length,
4463 : measurement_record);
4464 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4465 : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
4466 : /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
4467 : /* #endif*/
4468 1 : free(data);
4469 1 : }
4470 :
4471 : /**
4472 : * Test 21: Error case, measurement_specification field in response does not "match the selected measurement specification in the ALGORITHMS message"
4473 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code,
4474 : **/
4475 1 : static void req_get_measurements_case21(void **state)
4476 : {
4477 : libspdm_return_t status;
4478 : libspdm_test_context_t *spdm_test_context;
4479 : libspdm_context_t *spdm_context;
4480 : uint8_t number_of_block;
4481 : uint32_t measurement_record_length;
4482 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4483 : uint8_t request_attribute;
4484 : void *data;
4485 : size_t data_size;
4486 : void *hash;
4487 : size_t hash_size;
4488 :
4489 1 : spdm_test_context = *state;
4490 1 : spdm_context = spdm_test_context->spdm_context;
4491 1 : spdm_test_context->case_id = 0x15;
4492 :
4493 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4494 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4495 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4496 1 : spdm_context->connection_info.capability.flags |=
4497 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4498 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4499 : m_libspdm_use_asym_algo, &data,
4500 : &data_size, &hash, &hash_size)) {
4501 0 : assert(false);
4502 : }
4503 1 : libspdm_reset_message_m(spdm_context, NULL);
4504 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4505 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4506 : m_libspdm_use_measurement_hash_algo;
4507 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4508 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4509 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4510 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4511 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4512 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4513 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4514 : data, data_size);
4515 : #else
4516 1 : libspdm_hash_all(
4517 : spdm_context->connection_info.algorithm.base_hash_algo,
4518 : data, data_size,
4519 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4520 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4521 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4522 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4523 : spdm_context->connection_info.algorithm.base_hash_algo,
4524 : spdm_context->connection_info.algorithm.base_asym_algo,
4525 : data, data_size,
4526 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4527 : #endif
4528 :
4529 1 : request_attribute = 0;
4530 :
4531 1 : measurement_record_length = sizeof(measurement_record);
4532 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4533 : 0, NULL, &number_of_block,
4534 : &measurement_record_length,
4535 : measurement_record);
4536 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4537 : /* #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT*/
4538 : /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
4539 : /* #endif*/
4540 1 : free(data);
4541 1 : }
4542 :
4543 : /**
4544 : * Test 22: request a large number of unsigned measurements before requesting a signature
4545 : * Expected Behavior: LIBSPDM_STATUS_SUCCESS return code and correct transcript.message_m.buffer_size while transcript.message_m has room; RETURN_DEVICE_ERROR otherwise
4546 : **/
4547 1 : static void req_get_measurements_case22(void **state)
4548 : {
4549 : libspdm_return_t status;
4550 : libspdm_test_context_t *spdm_test_context;
4551 : libspdm_context_t *spdm_context;
4552 : uint8_t number_of_block;
4553 : uint32_t measurement_record_length;
4554 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4555 : uint8_t request_attribute;
4556 : void *data;
4557 : size_t data_size;
4558 : void *hash;
4559 : size_t hash_size;
4560 : size_t NumberOfMessages;
4561 : #define TOTAL_MESSAGES 100
4562 :
4563 1 : spdm_test_context = *state;
4564 1 : spdm_context = spdm_test_context->spdm_context;
4565 1 : spdm_test_context->case_id = 0x16;
4566 :
4567 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4568 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4569 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4570 1 : spdm_context->connection_info.capability.flags |=
4571 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4572 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4573 : m_libspdm_use_asym_algo, &data,
4574 : &data_size, &hash, &hash_size)) {
4575 0 : assert(false);
4576 : }
4577 1 : libspdm_reset_message_m(spdm_context, NULL);
4578 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4579 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4580 : m_libspdm_use_measurement_hash_algo;
4581 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4582 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4583 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4584 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4585 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4586 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4587 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4588 : data, data_size);
4589 : #else
4590 1 : libspdm_hash_all(
4591 : spdm_context->connection_info.algorithm.base_hash_algo,
4592 : data, data_size,
4593 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4594 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4595 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4596 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4597 : spdm_context->connection_info.algorithm.base_hash_algo,
4598 : spdm_context->connection_info.algorithm.base_asym_algo,
4599 : data, data_size,
4600 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4601 : #endif
4602 :
4603 1 : request_attribute = 0;
4604 :
4605 1 : measurement_record_length = sizeof(measurement_record);
4606 101 : for (NumberOfMessages = 1; NumberOfMessages <= TOTAL_MESSAGES; NumberOfMessages++) {
4607 100 : status = libspdm_get_measurement(spdm_context, NULL,
4608 : request_attribute, 1, 0,
4609 : NULL, &number_of_block,
4610 : &measurement_record_length,
4611 : measurement_record);
4612 : /* It may fail due to transcript.message_m overflow*/
4613 100 : if (status == LIBSPDM_STATUS_SUCCESS) {
4614 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4615 : assert_int_equal(
4616 : spdm_context->transcript.message_m.buffer_size,
4617 : NumberOfMessages *
4618 : (sizeof(spdm_message_header_t) +
4619 : sizeof(spdm_measurements_response_t) +
4620 : sizeof(spdm_measurement_block_dmtf_t) +
4621 : libspdm_get_measurement_hash_size(
4622 : m_libspdm_use_measurement_hash_algo) +
4623 : SPDM_NONCE_SIZE +
4624 : sizeof(uint16_t)));
4625 : #endif
4626 : } else {
4627 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4628 : assert_int_equal( spdm_context->transcript.message_m.buffer_size, 0);
4629 : #endif
4630 0 : break;
4631 : }
4632 : }
4633 1 : free(data);
4634 1 : }
4635 :
4636 : /**
4637 : * Test 23: Successful response to get a measurement block, without signature. response contains opaque data
4638 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, correct transcript.message_m.buffer_size
4639 : **/
4640 1 : static void req_get_measurements_case23(void **state)
4641 : {
4642 : libspdm_return_t status;
4643 : libspdm_test_context_t *spdm_test_context;
4644 : libspdm_context_t *spdm_context;
4645 : uint8_t number_of_block;
4646 : uint32_t measurement_record_length;
4647 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4648 : uint8_t request_attribute;
4649 : void *data;
4650 : size_t data_size;
4651 : void *hash;
4652 : size_t hash_size;
4653 :
4654 1 : spdm_test_context = *state;
4655 1 : spdm_context = spdm_test_context->spdm_context;
4656 1 : spdm_test_context->case_id = 0x17;
4657 :
4658 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4659 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4660 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4661 1 : spdm_context->connection_info.capability.flags |=
4662 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4663 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4664 : m_libspdm_use_asym_algo, &data,
4665 : &data_size, &hash, &hash_size)) {
4666 0 : assert(false);
4667 : }
4668 1 : libspdm_reset_message_m(spdm_context, NULL);
4669 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4670 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4671 : m_libspdm_use_measurement_hash_algo;
4672 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4673 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4674 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4675 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4676 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4677 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4678 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4679 : data, data_size);
4680 : #else
4681 1 : libspdm_hash_all(
4682 : spdm_context->connection_info.algorithm.base_hash_algo,
4683 : data, data_size,
4684 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4685 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4686 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4687 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4688 : spdm_context->connection_info.algorithm.base_hash_algo,
4689 : spdm_context->connection_info.algorithm.base_asym_algo,
4690 : data, data_size,
4691 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4692 : #endif
4693 :
4694 1 : request_attribute = 0;
4695 :
4696 1 : measurement_record_length = sizeof(measurement_record);
4697 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4698 : 0, NULL, &number_of_block,
4699 : &measurement_record_length,
4700 : measurement_record);
4701 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4702 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4703 : assert_int_equal(spdm_context->transcript.message_m.buffer_size,
4704 : sizeof(spdm_message_header_t) +
4705 : sizeof(spdm_measurements_response_t) +
4706 : sizeof(spdm_measurement_block_dmtf_t) +
4707 : libspdm_get_measurement_hash_size(
4708 : m_libspdm_use_measurement_hash_algo) +
4709 : SPDM_NONCE_SIZE +
4710 : sizeof(uint16_t) + SPDM_MAX_OPAQUE_DATA_SIZE);
4711 : #endif
4712 1 : free(data);
4713 1 : }
4714 :
4715 : /**
4716 : * Test 24: Error case, response contains opaque data larger than the maximum allowed
4717 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
4718 : **/
4719 1 : static void req_get_measurements_case24(void **state)
4720 : {
4721 : libspdm_return_t status;
4722 : libspdm_test_context_t *spdm_test_context;
4723 : libspdm_context_t *spdm_context;
4724 : uint8_t number_of_block;
4725 : uint32_t measurement_record_length;
4726 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4727 : uint8_t request_attribute;
4728 : void *data;
4729 : size_t data_size;
4730 : void *hash;
4731 : size_t hash_size;
4732 :
4733 1 : spdm_test_context = *state;
4734 1 : spdm_context = spdm_test_context->spdm_context;
4735 1 : spdm_test_context->case_id = 0x18;
4736 :
4737 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4738 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4739 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4740 1 : spdm_context->connection_info.capability.flags |=
4741 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4742 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4743 : m_libspdm_use_asym_algo, &data,
4744 : &data_size, &hash, &hash_size)) {
4745 0 : assert(false);
4746 : }
4747 1 : libspdm_reset_message_m(spdm_context, NULL);
4748 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4749 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4750 : m_libspdm_use_measurement_hash_algo;
4751 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4752 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4753 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4754 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4755 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4756 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4757 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4758 : data, data_size);
4759 : #else
4760 1 : libspdm_hash_all(
4761 : spdm_context->connection_info.algorithm.base_hash_algo,
4762 : data, data_size,
4763 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4764 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4765 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4766 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4767 : spdm_context->connection_info.algorithm.base_hash_algo,
4768 : spdm_context->connection_info.algorithm.base_asym_algo,
4769 : data, data_size,
4770 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4771 : #endif
4772 :
4773 1 : request_attribute = 0;
4774 :
4775 1 : measurement_record_length = sizeof(measurement_record);
4776 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4777 : 0, NULL, &number_of_block,
4778 : &measurement_record_length,
4779 : measurement_record);
4780 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
4781 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4782 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4783 : #endif
4784 1 : free(data);
4785 1 : }
4786 :
4787 : /**
4788 : * Test 25: Successful response to get a measurement block, with signature. response contains opaque data
4789 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, empty transcript.message_m.buffer_size
4790 : **/
4791 1 : static void req_get_measurements_case25(void **state)
4792 : {
4793 : libspdm_return_t status;
4794 : libspdm_test_context_t *spdm_test_context;
4795 : libspdm_context_t *spdm_context;
4796 : uint8_t number_of_block;
4797 : uint32_t measurement_record_length;
4798 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4799 : uint8_t request_attribute;
4800 : void *data;
4801 : size_t data_size;
4802 : void *hash;
4803 : size_t hash_size;
4804 :
4805 1 : spdm_test_context = *state;
4806 1 : spdm_context = spdm_test_context->spdm_context;
4807 1 : spdm_test_context->case_id = 0x19;
4808 :
4809 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4810 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4811 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4812 1 : spdm_context->connection_info.capability.flags |=
4813 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4814 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4815 : m_libspdm_use_asym_algo, &data,
4816 : &data_size, &hash, &hash_size)) {
4817 0 : assert(false);
4818 : }
4819 1 : libspdm_reset_message_m(spdm_context, NULL);
4820 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4821 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4822 : m_libspdm_use_measurement_hash_algo;
4823 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4824 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4825 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4826 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4827 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4828 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4829 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4830 : data, data_size);
4831 : #else
4832 1 : libspdm_hash_all(
4833 : spdm_context->connection_info.algorithm.base_hash_algo,
4834 : data, data_size,
4835 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4836 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4837 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4838 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4839 : spdm_context->connection_info.algorithm.base_hash_algo,
4840 : spdm_context->connection_info.algorithm.base_asym_algo,
4841 : data, data_size,
4842 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4843 : #endif
4844 :
4845 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
4846 :
4847 1 : measurement_record_length = sizeof(measurement_record);
4848 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4849 : 0, NULL, &number_of_block,
4850 : &measurement_record_length,
4851 : measurement_record);
4852 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
4853 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4854 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4855 : #endif
4856 1 : free(data);
4857 1 : }
4858 :
4859 : /**
4860 : * Test 26: Error case, request with signature, but response opaque data is S bytes shorter than informed
4861 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
4862 : **/
4863 1 : static void req_get_measurements_case26(void **state)
4864 : {
4865 : libspdm_return_t status;
4866 : libspdm_test_context_t *spdm_test_context;
4867 : libspdm_context_t *spdm_context;
4868 : uint8_t number_of_block;
4869 : uint32_t measurement_record_length;
4870 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4871 : uint8_t request_attribute;
4872 : void *data;
4873 : size_t data_size;
4874 : void *hash;
4875 : size_t hash_size;
4876 :
4877 1 : spdm_test_context = *state;
4878 1 : spdm_context = spdm_test_context->spdm_context;
4879 1 : spdm_test_context->case_id = 0x1A;
4880 :
4881 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4882 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4883 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4884 1 : spdm_context->connection_info.capability.flags |=
4885 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4886 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4887 : m_libspdm_use_asym_algo, &data,
4888 : &data_size, &hash, &hash_size)) {
4889 0 : assert(false);
4890 : }
4891 1 : libspdm_reset_message_m(spdm_context, NULL);
4892 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4893 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4894 : m_libspdm_use_measurement_hash_algo;
4895 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4896 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4897 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4898 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4899 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4900 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4901 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4902 : data, data_size);
4903 : #else
4904 1 : libspdm_hash_all(
4905 : spdm_context->connection_info.algorithm.base_hash_algo,
4906 : data, data_size,
4907 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4908 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4909 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4910 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4911 : spdm_context->connection_info.algorithm.base_hash_algo,
4912 : spdm_context->connection_info.algorithm.base_asym_algo,
4913 : data, data_size,
4914 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4915 : #endif
4916 :
4917 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
4918 :
4919 1 : measurement_record_length = sizeof(measurement_record);
4920 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4921 : 0, NULL, &number_of_block,
4922 : &measurement_record_length,
4923 : measurement_record);
4924 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
4925 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4926 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4927 : #endif
4928 1 : free(data);
4929 1 : }
4930 :
4931 : /**
4932 : * Test 27: Error case, request with signature, but response opaque data is (S+1) bytes shorter than informed
4933 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
4934 : **/
4935 1 : static void req_get_measurements_case27(void **state)
4936 : {
4937 : libspdm_return_t status;
4938 : libspdm_test_context_t *spdm_test_context;
4939 : libspdm_context_t *spdm_context;
4940 : uint8_t number_of_block;
4941 : uint32_t measurement_record_length;
4942 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
4943 : uint8_t request_attribute;
4944 : void *data;
4945 : size_t data_size;
4946 : void *hash;
4947 : size_t hash_size;
4948 :
4949 1 : spdm_test_context = *state;
4950 1 : spdm_context = spdm_test_context->spdm_context;
4951 1 : spdm_test_context->case_id = 0x1B;
4952 :
4953 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
4954 : SPDM_VERSION_NUMBER_SHIFT_BIT;
4955 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
4956 1 : spdm_context->connection_info.capability.flags |=
4957 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
4958 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
4959 : m_libspdm_use_asym_algo, &data,
4960 : &data_size, &hash, &hash_size)) {
4961 0 : assert(false);
4962 : }
4963 1 : libspdm_reset_message_m(spdm_context, NULL);
4964 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
4965 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
4966 : m_libspdm_use_measurement_hash_algo;
4967 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
4968 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
4969 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
4970 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4971 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
4972 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
4973 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
4974 : data, data_size);
4975 : #else
4976 1 : libspdm_hash_all(
4977 : spdm_context->connection_info.algorithm.base_hash_algo,
4978 : data, data_size,
4979 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
4980 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
4981 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
4982 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
4983 : spdm_context->connection_info.algorithm.base_hash_algo,
4984 : spdm_context->connection_info.algorithm.base_asym_algo,
4985 : data, data_size,
4986 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
4987 : #endif
4988 :
4989 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
4990 :
4991 1 : measurement_record_length = sizeof(measurement_record);
4992 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
4993 : 0, NULL, &number_of_block,
4994 : &measurement_record_length,
4995 : measurement_record);
4996 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
4997 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
4998 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
4999 : #endif
5000 1 : free(data);
5001 1 : }
5002 :
5003 : /**
5004 : * Test 28: Error case, request with signature, but response opaque data is 1 byte longer than informed
5005 : * Expected Behavior: get a RETURN_DEVICE_ERROR return code, correct transcript.message_m.buffer_size
5006 : **/
5007 1 : static void req_get_measurements_case28(void **state)
5008 : {
5009 : libspdm_return_t status;
5010 : libspdm_test_context_t *spdm_test_context;
5011 : libspdm_context_t *spdm_context;
5012 : uint8_t number_of_block;
5013 : uint32_t measurement_record_length;
5014 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5015 : uint8_t request_attribute;
5016 : void *data;
5017 : size_t data_size;
5018 : void *hash;
5019 : size_t hash_size;
5020 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5021 : size_t ExpectedBufferSize;
5022 : #endif
5023 1 : spdm_test_context = *state;
5024 1 : spdm_context = spdm_test_context->spdm_context;
5025 1 : spdm_test_context->case_id = 0x1C;
5026 :
5027 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5028 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5029 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5030 1 : spdm_context->connection_info.capability.flags |=
5031 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5032 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5033 : m_libspdm_use_asym_algo, &data,
5034 : &data_size, &hash, &hash_size)) {
5035 0 : assert(false);
5036 : }
5037 1 : libspdm_reset_message_m(spdm_context, NULL);
5038 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5039 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5040 : m_libspdm_use_measurement_hash_algo;
5041 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5042 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5043 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5044 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5045 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5046 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5047 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5048 : data, data_size);
5049 : #else
5050 1 : libspdm_hash_all(
5051 : spdm_context->connection_info.algorithm.base_hash_algo,
5052 : data, data_size,
5053 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5054 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5055 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5056 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5057 : spdm_context->connection_info.algorithm.base_hash_algo,
5058 : spdm_context->connection_info.algorithm.base_asym_algo,
5059 : data, data_size,
5060 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5061 : #endif
5062 :
5063 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
5064 :
5065 1 : measurement_record_length = sizeof(measurement_record);
5066 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
5067 : 0, NULL, &number_of_block,
5068 : &measurement_record_length,
5069 : measurement_record);
5070 1 : assert_int_equal(status, LIBSPDM_STATUS_VERIF_FAIL);
5071 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5072 : ExpectedBufferSize = 0;
5073 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, ExpectedBufferSize);
5074 : #endif
5075 1 : free(data);
5076 1 : }
5077 :
5078 : /**
5079 : * Test 29: request measurement without signature, but response opaque data is 1 byte longer than informed
5080 : * Expected Behavior: extra byte should just be ignored. Get a LIBSPDM_STATUS_SUCCESS return code, correct transcript.message_m.buffer_size
5081 : **/
5082 1 : static void req_get_measurements_case29(void **state)
5083 : {
5084 : libspdm_return_t status;
5085 : libspdm_test_context_t *spdm_test_context;
5086 : libspdm_context_t *spdm_context;
5087 : uint8_t number_of_block;
5088 : uint32_t measurement_record_length;
5089 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5090 : uint8_t request_attribute;
5091 : void *data;
5092 : size_t data_size;
5093 : void *hash;
5094 : size_t hash_size;
5095 :
5096 1 : spdm_test_context = *state;
5097 1 : spdm_context = spdm_test_context->spdm_context;
5098 1 : spdm_test_context->case_id = 0x1D;
5099 :
5100 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5101 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5102 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5103 1 : spdm_context->connection_info.capability.flags |=
5104 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5105 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5106 : m_libspdm_use_asym_algo, &data,
5107 : &data_size, &hash, &hash_size)) {
5108 0 : assert(false);
5109 : }
5110 1 : libspdm_reset_message_m(spdm_context, NULL);
5111 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5112 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5113 : m_libspdm_use_measurement_hash_algo;
5114 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5115 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5116 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5117 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5118 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5119 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5120 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5121 : data, data_size);
5122 : #else
5123 1 : libspdm_hash_all(
5124 : spdm_context->connection_info.algorithm.base_hash_algo,
5125 : data, data_size,
5126 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5127 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5128 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5129 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5130 : spdm_context->connection_info.algorithm.base_hash_algo,
5131 : spdm_context->connection_info.algorithm.base_asym_algo,
5132 : data, data_size,
5133 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5134 : #endif
5135 :
5136 1 : request_attribute = 0;
5137 :
5138 1 : measurement_record_length = sizeof(measurement_record);
5139 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
5140 : 0, NULL, &number_of_block,
5141 : &measurement_record_length,
5142 : measurement_record);
5143 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5144 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5145 : assert_int_equal(spdm_context->transcript.message_m.buffer_size,
5146 : sizeof(spdm_message_header_t) +
5147 : sizeof(spdm_measurements_response_t) +
5148 : sizeof(spdm_measurement_block_dmtf_t) +
5149 : libspdm_get_measurement_hash_size(
5150 : m_libspdm_use_measurement_hash_algo) +
5151 : SPDM_NONCE_SIZE +
5152 : sizeof(uint16_t) +
5153 : SPDM_MAX_OPAQUE_DATA_SIZE / 2 - 1);
5154 : #endif
5155 1 : free(data);
5156 1 : }
5157 :
5158 : /**
5159 : * Test 30:
5160 : * Expected Behavior:
5161 : **/
5162 1 : static void req_get_measurements_case30(void **state)
5163 : {
5164 1 : }
5165 :
5166 : /**
5167 : * Test 31:
5168 : * Expected Behavior:
5169 : **/
5170 1 : static void req_get_measurements_case31(void **state)
5171 : {
5172 1 : }
5173 :
5174 : /**
5175 : * Test 32: Successful response to get all measurement blocks, without signature
5176 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, correct transcript.message_m.buffer_size
5177 : **/
5178 1 : static void req_get_measurements_case32(void **state)
5179 : {
5180 : libspdm_return_t status;
5181 : libspdm_test_context_t *spdm_test_context;
5182 : libspdm_context_t *spdm_context;
5183 : uint8_t number_of_block;
5184 : uint32_t measurement_record_length;
5185 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5186 : uint8_t request_attribute;
5187 : void *data;
5188 : size_t data_size;
5189 : void *hash;
5190 : size_t hash_size;
5191 :
5192 1 : spdm_test_context = *state;
5193 1 : spdm_context = spdm_test_context->spdm_context;
5194 1 : spdm_test_context->case_id = 0x20;
5195 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5196 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5197 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5198 1 : spdm_context->connection_info.capability.flags |=
5199 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5200 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5201 : m_libspdm_use_asym_algo, &data,
5202 : &data_size, &hash, &hash_size)) {
5203 0 : assert(false);
5204 : }
5205 1 : libspdm_reset_message_m(spdm_context, NULL);
5206 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5207 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5208 : m_libspdm_use_measurement_hash_algo;
5209 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5210 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5211 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5212 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5213 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5214 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5215 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5216 : data, data_size);
5217 : #else
5218 1 : libspdm_hash_all(
5219 : spdm_context->connection_info.algorithm.base_hash_algo,
5220 : data, data_size,
5221 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5222 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5223 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5224 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5225 : spdm_context->connection_info.algorithm.base_hash_algo,
5226 : spdm_context->connection_info.algorithm.base_asym_algo,
5227 : data, data_size,
5228 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5229 : #endif
5230 :
5231 1 : request_attribute = 0;
5232 :
5233 1 : measurement_record_length = sizeof(measurement_record);
5234 1 : status = libspdm_get_measurement(
5235 : spdm_context, NULL, request_attribute,
5236 : SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS,
5237 : 0, NULL, &number_of_block, &measurement_record_length,
5238 : measurement_record);
5239 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5240 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5241 : assert_int_equal(spdm_context->transcript.message_m.buffer_size,
5242 : sizeof(spdm_message_header_t) +
5243 : sizeof(spdm_measurements_response_t) +
5244 : 2 * (sizeof(spdm_measurement_block_dmtf_t) +
5245 : libspdm_get_measurement_hash_size(
5246 : m_libspdm_use_measurement_hash_algo)) +
5247 : sizeof(uint16_t) + SPDM_NONCE_SIZE);
5248 : #endif
5249 1 : free(data);
5250 1 : }
5251 :
5252 : /**
5253 : * Test 33: receiving an unexpected ERROR message from the responder.
5254 : * There are tests for all named codes, including some reserved ones
5255 : * (namely, 0x00, 0x0b, 0x0c, 0x3f, 0xfd, 0xfe).
5256 : * However, for having specific test cases, it is excluded from this case:
5257 : * Busy (0x03), ResponseNotReady (0x42), and RequestResync (0x43).
5258 : * Expected behavior: client returns a status of RETURN_DEVICE_ERROR.
5259 : **/
5260 1 : static void req_get_measurements_case33(void **state) {
5261 : libspdm_return_t status;
5262 : libspdm_test_context_t *spdm_test_context;
5263 : libspdm_context_t *spdm_context;
5264 : uint8_t number_of_block;
5265 : uint32_t measurement_record_length;
5266 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5267 : uint8_t request_attribute;
5268 : void *data;
5269 : size_t data_size;
5270 : void *hash;
5271 : size_t hash_size;
5272 : uint16_t error_code;
5273 :
5274 1 : spdm_test_context = *state;
5275 1 : spdm_context = spdm_test_context->spdm_context;
5276 1 : spdm_test_context->case_id = 0x21;
5277 1 : spdm_context->connection_info.capability.flags |=
5278 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5279 1 : libspdm_read_responder_public_certificate_chain (m_libspdm_use_hash_algo,
5280 : m_libspdm_use_asym_algo,
5281 : &data, &data_size,
5282 : &hash, &hash_size);
5283 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5284 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5285 : m_libspdm_use_measurement_hash_algo;
5286 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5287 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5288 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5289 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5290 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5291 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5292 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5293 : data, data_size);
5294 : #else
5295 1 : libspdm_hash_all(
5296 : spdm_context->connection_info.algorithm.base_hash_algo,
5297 : data, data_size,
5298 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5299 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5300 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5301 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5302 : spdm_context->connection_info.algorithm.base_hash_algo,
5303 : spdm_context->connection_info.algorithm.base_asym_algo,
5304 : data, data_size,
5305 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5306 : #endif
5307 :
5308 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
5309 :
5310 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
5311 19 : while(error_code <= 0xff) {
5312 18 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5313 18 : libspdm_reset_message_m(spdm_context, NULL);
5314 :
5315 18 : measurement_record_length = sizeof(measurement_record);
5316 18 : status = libspdm_get_measurement (spdm_context, NULL, request_attribute, 1, 0, NULL,
5317 : &number_of_block, &measurement_record_length,
5318 : measurement_record);
5319 18 : LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
5320 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5321 : /* assert_int_equal (spdm_context->transcript.message_m.buffer_size, 0);*/
5322 : LIBSPDM_ASSERT_INT_EQUAL_CASE (spdm_context->transcript.message_m.buffer_size, 0,
5323 : error_code);
5324 : #endif
5325 :
5326 18 : error_code++;
5327 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
5328 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
5329 : }
5330 : /* skip some reserved error codes (0d to 3e) */
5331 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) {
5332 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
5333 : }
5334 : /* skip response not ready, request resync, and some reserved codes (44 to fc) */
5335 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
5336 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
5337 : }
5338 : }
5339 :
5340 1 : free(data);
5341 1 : }
5342 :
5343 : /**
5344 : * Test 34: Successful response to get a session based measurement with signature
5345 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code, with an empty session_transcript.message_m
5346 : **/
5347 1 : static void req_get_measurements_case34(void **state)
5348 : {
5349 : libspdm_return_t status;
5350 : libspdm_test_context_t *spdm_test_context;
5351 : libspdm_context_t *spdm_context;
5352 : uint32_t session_id;
5353 : libspdm_session_info_t *session_info;
5354 : uint8_t number_of_block;
5355 : uint32_t measurement_record_length;
5356 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5357 : uint8_t request_attribute;
5358 : void *data;
5359 : size_t data_size;
5360 : void *hash;
5361 : size_t hash_size;
5362 :
5363 1 : spdm_test_context = *state;
5364 1 : spdm_context = spdm_test_context->spdm_context;
5365 1 : spdm_test_context->case_id = 0x22;
5366 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5367 1 : spdm_context->connection_info.capability.flags |=
5368 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5369 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5370 : m_libspdm_use_asym_algo, &data,
5371 : &data_size, &hash, &hash_size)) {
5372 0 : assert(false);
5373 : }
5374 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
5375 1 : spdm_context->connection_info.capability.flags |=
5376 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
5377 1 : spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
5378 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
5379 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
5380 1 : spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
5381 1 : spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
5382 1 : spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
5383 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5384 1 : session_id = 0xFFFFFFFF;
5385 1 : session_info = &spdm_context->session_info[0];
5386 1 : libspdm_session_info_init(spdm_context, session_info, session_id,
5387 : SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT, true);
5388 1 : libspdm_secured_message_set_session_state(
5389 : session_info->secured_message_context,
5390 : LIBSPDM_SESSION_STATE_ESTABLISHED);
5391 :
5392 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5393 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5394 : m_libspdm_use_measurement_hash_algo;
5395 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5396 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5397 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5398 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5399 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5400 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5401 : data, data_size);
5402 : #else
5403 1 : libspdm_hash_all(
5404 : spdm_context->connection_info.algorithm.base_hash_algo,
5405 : data, data_size,
5406 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5407 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5408 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5409 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5410 : spdm_context->connection_info.algorithm.base_hash_algo,
5411 : spdm_context->connection_info.algorithm.base_asym_algo,
5412 : data, data_size,
5413 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5414 : #endif
5415 :
5416 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
5417 :
5418 1 : measurement_record_length = sizeof(measurement_record);
5419 1 : status = libspdm_get_measurement(spdm_context, &session_id, request_attribute, 1,
5420 : 0, NULL, &number_of_block,
5421 : &measurement_record_length,
5422 : measurement_record);
5423 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5424 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5425 : assert_int_equal(session_info->session_transcript.message_m.buffer_size, 0);
5426 : #endif
5427 1 : free(data);
5428 1 : }
5429 :
5430 : /**
5431 : * Test 35: a request message is successfully sent and a response message is successfully received.
5432 : * Buffer M already has arbitrary data. No signature is requested.
5433 : * Expected Behavior: requester returns the status LIBSPDM_STATUS_SUCCESS and a MEASUREMENTS message
5434 : * is received, buffer M appends the exchanged GET_MEASUREMENTS and MEASUREMENTS messages.
5435 : *
5436 : * Note that this test is only exercised when LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT is enabled.
5437 : **/
5438 1 : static void req_get_measurements_case35(void **state)
5439 : {
5440 : libspdm_return_t status;
5441 : libspdm_test_context_t *spdm_test_context;
5442 : libspdm_context_t *spdm_context;
5443 : uint8_t number_of_block;
5444 : uint32_t measurement_record_length;
5445 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5446 : uint8_t request_attribute;
5447 : void *data;
5448 : size_t data_size;
5449 : void *hash;
5450 : size_t hash_size;
5451 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5452 : const size_t arbitrary_fill_size = 18;
5453 : #endif
5454 :
5455 1 : spdm_test_context = *state;
5456 1 : spdm_context = spdm_test_context->spdm_context;
5457 1 : spdm_test_context->case_id = 0x23;
5458 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
5459 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5460 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5461 1 : spdm_context->connection_info.capability.flags |=
5462 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5463 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5464 : m_libspdm_use_asym_algo, &data,
5465 : &data_size, &hash, &hash_size)) {
5466 0 : assert(false);
5467 : }
5468 1 : libspdm_reset_message_m(spdm_context, NULL);
5469 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5470 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5471 : m_libspdm_use_measurement_hash_algo;
5472 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5473 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5474 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5475 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5476 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5477 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5478 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5479 : data, data_size);
5480 : #else
5481 1 : libspdm_hash_all(
5482 : spdm_context->connection_info.algorithm.base_hash_algo,
5483 : data, data_size,
5484 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5485 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5486 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5487 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5488 : spdm_context->connection_info.algorithm.base_hash_algo,
5489 : spdm_context->connection_info.algorithm.base_asym_algo,
5490 : data, data_size,
5491 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5492 : #endif
5493 :
5494 1 : request_attribute = 0; /* Do not request a signature. */
5495 :
5496 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5497 : /* Fill M buffer and local buffer with arbitrary data. */
5498 : libspdm_set_mem(spdm_context->transcript.message_m.buffer, arbitrary_fill_size, 0xFF);
5499 : libspdm_set_mem(m_libspdm_local_buffer, arbitrary_fill_size, 0xFF);
5500 : spdm_context->transcript.message_m.buffer_size = arbitrary_fill_size;
5501 : m_libspdm_local_buffer_size = arbitrary_fill_size;
5502 : #endif
5503 :
5504 1 : measurement_record_length = sizeof(measurement_record);
5505 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
5506 : 0, NULL, &number_of_block,
5507 : &measurement_record_length,
5508 : measurement_record);
5509 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5510 :
5511 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5512 : /* Check that the size of the two buffers are the same (fill data + request + response) */
5513 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, m_libspdm_local_buffer_size);
5514 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%x):\n",
5515 : m_libspdm_local_buffer_size));
5516 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
5517 : /* Check that the contents of the two buffers are the same (fill data, request, response) */
5518 : assert_memory_equal(spdm_context->transcript.message_m.buffer,
5519 : m_libspdm_local_buffer, m_libspdm_local_buffer_size);
5520 : #endif
5521 1 : free(data);
5522 1 : }
5523 :
5524 1 : static void req_get_measurements_case36(void **state)
5525 : {
5526 : libspdm_return_t status;
5527 : libspdm_test_context_t *spdm_test_context;
5528 : libspdm_context_t *spdm_context;
5529 : uint8_t number_of_block;
5530 : uint32_t measurement_record_length;
5531 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5532 : uint8_t request_attribute;
5533 : void *data;
5534 : size_t data_size;
5535 : void *hash;
5536 : size_t hash_size;
5537 :
5538 1 : spdm_test_context = *state;
5539 1 : spdm_context = spdm_test_context->spdm_context;
5540 1 : spdm_test_context->case_id = 0x24;
5541 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
5542 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5543 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5544 1 : spdm_context->connection_info.capability.flags |=
5545 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5546 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5547 : m_libspdm_use_asym_algo, &data,
5548 : &data_size, &hash, &hash_size)) {
5549 0 : assert(false);
5550 : }
5551 1 : libspdm_reset_message_m(spdm_context, NULL);
5552 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5553 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5554 : m_libspdm_use_measurement_hash_algo;
5555 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5556 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5557 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5558 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5559 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5560 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5561 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5562 : data, data_size);
5563 : #else
5564 1 : libspdm_hash_all(
5565 : spdm_context->connection_info.algorithm.base_hash_algo,
5566 : data, data_size,
5567 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5568 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5569 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5570 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5571 : spdm_context->connection_info.algorithm.base_hash_algo,
5572 : spdm_context->connection_info.algorithm.base_asym_algo,
5573 : data, data_size,
5574 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5575 : #endif
5576 :
5577 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
5578 :
5579 1 : measurement_record_length = sizeof(measurement_record);
5580 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
5581 : 0, NULL, &number_of_block,
5582 : &measurement_record_length,
5583 : measurement_record);
5584 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5585 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5586 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
5587 : #endif
5588 1 : free(data);
5589 1 : }
5590 :
5591 1 : static void req_get_measurements_case37(void **state)
5592 : {
5593 : libspdm_return_t status;
5594 : libspdm_test_context_t *spdm_test_context;
5595 : libspdm_context_t *spdm_context;
5596 : uint8_t number_of_blocks;
5597 : uint8_t request_attribute;
5598 : void *data;
5599 : size_t data_size;
5600 : void *hash;
5601 : size_t hash_size;
5602 :
5603 1 : spdm_test_context = *state;
5604 1 : spdm_context = spdm_test_context->spdm_context;
5605 1 : spdm_test_context->case_id = 0x25;
5606 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
5607 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5608 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5609 1 : spdm_context->connection_info.capability.flags |=
5610 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5611 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5612 : m_libspdm_use_asym_algo, &data,
5613 : &data_size, &hash, &hash_size)) {
5614 0 : assert(false);
5615 : }
5616 1 : libspdm_reset_message_m(spdm_context, NULL);
5617 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5618 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5619 : m_libspdm_use_measurement_hash_algo;
5620 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5621 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5622 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5623 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5624 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5625 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5626 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5627 : data, data_size);
5628 : #else
5629 1 : libspdm_hash_all(
5630 : spdm_context->connection_info.algorithm.base_hash_algo,
5631 : data, data_size,
5632 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5633 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5634 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5635 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5636 : spdm_context->connection_info.algorithm.base_hash_algo,
5637 : spdm_context->connection_info.algorithm.base_asym_algo,
5638 : data, data_size,
5639 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5640 : #endif
5641 :
5642 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_RAW_BIT_STREAM_REQUESTED;
5643 :
5644 1 : status = libspdm_get_measurement(
5645 : spdm_context, NULL, request_attribute,
5646 : SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
5647 : 0, NULL, &number_of_blocks, NULL, NULL);
5648 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5649 1 : assert_int_equal(number_of_blocks, 4);
5650 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5651 : assert_int_equal(spdm_context->transcript.message_m.buffer_size,
5652 : sizeof(spdm_message_header_t) +
5653 : sizeof(spdm_measurements_response_t) +
5654 : SPDM_NONCE_SIZE + sizeof(uint16_t));
5655 : #endif
5656 1 : free(data);
5657 1 : }
5658 :
5659 1 : static void req_get_measurements_case38(void **state)
5660 : {
5661 : libspdm_return_t status;
5662 : libspdm_test_context_t *spdm_test_context;
5663 : libspdm_context_t *spdm_context;
5664 : uint8_t number_of_block;
5665 : uint32_t measurement_record_length;
5666 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5667 : uint8_t request_attribute;
5668 : void *data;
5669 : size_t data_size;
5670 :
5671 1 : spdm_test_context = *state;
5672 1 : spdm_context = spdm_test_context->spdm_context;
5673 1 : spdm_test_context->case_id = 0x26;
5674 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
5675 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5676 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5677 1 : spdm_context->connection_info.capability.flags |=
5678 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5679 1 : spdm_context->connection_info.capability.flags |=
5680 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
5681 1 : libspdm_read_responder_public_key(m_libspdm_use_asym_algo, &data, &data_size);
5682 1 : spdm_context->local_context.peer_public_key_provision = data;
5683 1 : spdm_context->local_context.peer_public_key_provision_size = data_size;
5684 :
5685 1 : libspdm_reset_message_m(spdm_context, NULL);
5686 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5687 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5688 : m_libspdm_use_measurement_hash_algo;
5689 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5690 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5691 :
5692 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
5693 :
5694 1 : measurement_record_length = sizeof(measurement_record);
5695 1 : status = libspdm_get_measurement(spdm_context, NULL, request_attribute, 1,
5696 : 0xF, NULL, &number_of_block,
5697 : &measurement_record_length,
5698 : measurement_record);
5699 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5700 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5701 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
5702 : #endif
5703 1 : free(data);
5704 1 : }
5705 :
5706 : /**
5707 : * Test 39: Exercise the libspdm_get_measurement_ex function.
5708 : * Expected Behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
5709 : **/
5710 1 : static void req_get_measurements_case39(void **state)
5711 : {
5712 : libspdm_return_t status;
5713 : libspdm_test_context_t *spdm_test_context;
5714 : libspdm_context_t *spdm_context;
5715 : uint8_t number_of_block;
5716 : uint32_t measurement_record_length;
5717 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5718 : uint8_t request_attribute;
5719 : void *data;
5720 : size_t data_size;
5721 : void *hash;
5722 : size_t hash_size;
5723 : uint8_t requester_nonce_in[SPDM_NONCE_SIZE];
5724 : uint8_t requester_nonce[SPDM_NONCE_SIZE];
5725 : uint8_t responder_nonce[SPDM_NONCE_SIZE];
5726 : uint8_t opaque_data[SPDM_MAX_OPAQUE_DATA_SIZE];
5727 : size_t opaque_data_size;
5728 :
5729 1 : spdm_test_context = *state;
5730 1 : spdm_context = spdm_test_context->spdm_context;
5731 1 : spdm_test_context->case_id = 0x27;
5732 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
5733 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5734 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5735 1 : spdm_context->connection_info.capability.flags |=
5736 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5737 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5738 : m_libspdm_use_asym_algo, &data,
5739 : &data_size, &hash, &hash_size)) {
5740 0 : assert(false);
5741 : }
5742 1 : libspdm_reset_message_m(spdm_context, NULL);
5743 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5744 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5745 : m_libspdm_use_measurement_hash_algo;
5746 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5747 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5748 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5749 1 : spdm_context->connection_info.algorithm.other_params_support =
5750 : SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
5751 :
5752 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5753 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5754 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5755 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5756 : data, data_size);
5757 : #else
5758 1 : libspdm_hash_all(
5759 : spdm_context->connection_info.algorithm.base_hash_algo,
5760 : data, data_size,
5761 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5762 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5763 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5764 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5765 : spdm_context->connection_info.algorithm.base_hash_algo,
5766 : spdm_context->connection_info.algorithm.base_asym_algo,
5767 : data, data_size,
5768 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5769 : #endif
5770 :
5771 1 : request_attribute = SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
5772 :
5773 1 : measurement_record_length = sizeof(measurement_record);
5774 :
5775 33 : for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
5776 32 : requester_nonce_in[index] = 0x5c;
5777 32 : requester_nonce[index] = 0x00;
5778 32 : responder_nonce[index] = 0x00;
5779 : }
5780 :
5781 1 : opaque_data_size = sizeof(opaque_data);
5782 :
5783 1 : status = libspdm_get_measurement_ex(spdm_context, NULL, request_attribute, 1,
5784 : 0, NULL, &number_of_block,
5785 : &measurement_record_length,
5786 : measurement_record, requester_nonce_in,
5787 : requester_nonce, responder_nonce,
5788 : opaque_data, &opaque_data_size);
5789 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5790 33 : for (int index = 0; index < SPDM_NONCE_SIZE; index++) {
5791 32 : assert_int_equal (requester_nonce_in[index], requester_nonce[index]);
5792 32 : assert_int_equal (responder_nonce[index], 0x12);
5793 : }
5794 :
5795 1 : assert_int_equal(opaque_data_size, m_libspdm_opaque_data_size);
5796 1 : assert_memory_equal(opaque_data, m_libspdm_opaque_data, opaque_data_size);
5797 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5798 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
5799 : #endif
5800 1 : free(data);
5801 1 : }
5802 :
5803 : /**
5804 : * Test 40: Successful case , correct measuerments context field , without signature
5805 : * Expected Behavior: client returns a status of LIBSPDM_STATUS_SUCCESS.
5806 : **/
5807 1 : static void req_get_measurements_case40(void **state)
5808 : {
5809 : libspdm_return_t status;
5810 : libspdm_test_context_t *spdm_test_context;
5811 : libspdm_context_t *spdm_context;
5812 : uint8_t number_of_block;
5813 : uint32_t measurement_record_length;
5814 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5815 : uint8_t request_attribute;
5816 : void *data;
5817 : size_t data_size;
5818 : void *hash;
5819 : size_t hash_size;
5820 :
5821 1 : spdm_test_context = *state;
5822 1 : spdm_context = spdm_test_context->spdm_context;
5823 1 : spdm_test_context->case_id = 0x28;
5824 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
5825 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5826 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5827 1 : spdm_context->connection_info.capability.flags |=
5828 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5829 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5830 : m_libspdm_use_asym_algo, &data,
5831 : &data_size, &hash, &hash_size)) {
5832 0 : assert(false);
5833 : }
5834 1 : libspdm_reset_message_m(spdm_context, NULL);
5835 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5836 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5837 : m_libspdm_use_measurement_hash_algo;
5838 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5839 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5840 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5841 :
5842 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5843 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5844 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5845 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5846 : data, data_size);
5847 : #else
5848 1 : libspdm_hash_all(
5849 : spdm_context->connection_info.algorithm.base_hash_algo,
5850 : data, data_size,
5851 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5852 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5853 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5854 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5855 : spdm_context->connection_info.algorithm.base_hash_algo,
5856 : spdm_context->connection_info.algorithm.base_asym_algo,
5857 : data, data_size,
5858 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5859 : #endif
5860 :
5861 1 : measurement_record_length = sizeof(measurement_record);
5862 :
5863 1 : libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
5864 :
5865 1 : request_attribute = 0; /* Do not request a signature. */
5866 :
5867 1 : status = libspdm_get_measurement_ex2(spdm_context, NULL, request_attribute, 1,
5868 : 0, m_requester_context, NULL, &number_of_block,
5869 : &measurement_record_length,
5870 : measurement_record, NULL, NULL, NULL, NULL, NULL);
5871 :
5872 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
5873 :
5874 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5875 : assert_int_equal(spdm_context->transcript.message_m.buffer_size,
5876 : sizeof(spdm_message_header_t) + SPDM_REQ_CONTEXT_SIZE +
5877 : sizeof(spdm_measurements_response_t) +
5878 : sizeof(spdm_measurement_block_dmtf_t) +
5879 : libspdm_get_measurement_hash_size(m_libspdm_use_measurement_hash_algo) +
5880 : SPDM_NONCE_SIZE + sizeof(uint16_t) + SPDM_REQ_CONTEXT_SIZE);
5881 : #endif
5882 1 : free(data);
5883 1 : }
5884 :
5885 : /**
5886 : * Test 41: Error case , Measurement context fields are inconsistent , without signature
5887 : * Expected Behavior: get a LIBSPDM_STATUS_INVALID_MSG_FIELD return code
5888 : **/
5889 1 : static void req_get_measurements_case41(void **state)
5890 : {
5891 : libspdm_return_t status;
5892 : libspdm_test_context_t *spdm_test_context;
5893 : libspdm_context_t *spdm_context;
5894 : uint8_t number_of_block;
5895 : uint32_t measurement_record_length;
5896 : uint8_t measurement_record[LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE];
5897 : uint8_t request_attribute;
5898 : void *data;
5899 : size_t data_size;
5900 : void *hash;
5901 : size_t hash_size;
5902 :
5903 1 : spdm_test_context = *state;
5904 1 : spdm_context = spdm_test_context->spdm_context;
5905 1 : spdm_test_context->case_id = 0x29;
5906 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
5907 : SPDM_VERSION_NUMBER_SHIFT_BIT;
5908 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
5909 1 : spdm_context->connection_info.capability.flags |=
5910 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
5911 1 : if (!libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
5912 : m_libspdm_use_asym_algo, &data,
5913 : &data_size, &hash, &hash_size)) {
5914 0 : assert(false);
5915 : }
5916 1 : libspdm_reset_message_m(spdm_context, NULL);
5917 1 : spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
5918 1 : spdm_context->connection_info.algorithm.measurement_hash_algo =
5919 : m_libspdm_use_measurement_hash_algo;
5920 1 : spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
5921 1 : spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
5922 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
5923 :
5924 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5925 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
5926 : libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
5927 : sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
5928 : data, data_size);
5929 : #else
5930 1 : libspdm_hash_all(
5931 : spdm_context->connection_info.algorithm.base_hash_algo,
5932 : data, data_size,
5933 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
5934 1 : spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
5935 1 : libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
5936 1 : libspdm_get_leaf_cert_public_key_from_cert_chain(
5937 : spdm_context->connection_info.algorithm.base_hash_algo,
5938 : spdm_context->connection_info.algorithm.base_asym_algo,
5939 : data, data_size,
5940 : &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
5941 : #endif
5942 :
5943 1 : measurement_record_length = sizeof(measurement_record);
5944 :
5945 1 : libspdm_set_mem(m_requester_context, SPDM_REQ_CONTEXT_SIZE, 0xAA);
5946 :
5947 1 : request_attribute = 0; /* Do not request a signature. */
5948 :
5949 1 : status = libspdm_get_measurement_ex2(spdm_context, NULL, request_attribute, 1,
5950 : 0, m_requester_context, NULL, &number_of_block,
5951 : &measurement_record_length,
5952 : measurement_record, NULL, NULL, NULL, NULL, NULL);
5953 :
5954 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
5955 :
5956 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
5957 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
5958 : #endif
5959 1 : free(data);
5960 1 : }
5961 :
5962 1 : int libspdm_req_get_measurements_test(void)
5963 : {
5964 1 : const struct CMUnitTest test_cases[] = {
5965 : cmocka_unit_test(req_get_measurements_case1),
5966 : cmocka_unit_test(req_get_measurements_case2),
5967 : cmocka_unit_test(req_get_measurements_case3),
5968 : cmocka_unit_test(req_get_measurements_case4),
5969 : cmocka_unit_test(req_get_measurements_case5),
5970 : cmocka_unit_test(req_get_measurements_case6),
5971 : cmocka_unit_test(req_get_measurements_case7),
5972 : cmocka_unit_test(req_get_measurements_case8),
5973 : cmocka_unit_test(req_get_measurements_case9),
5974 : cmocka_unit_test(req_get_measurements_case10),
5975 : cmocka_unit_test(req_get_measurements_case11),
5976 : cmocka_unit_test(req_get_measurements_case12),
5977 : cmocka_unit_test(req_get_measurements_case13),
5978 : cmocka_unit_test(req_get_measurements_case14),
5979 : cmocka_unit_test(req_get_measurements_case15),
5980 : cmocka_unit_test(req_get_measurements_case16),
5981 : cmocka_unit_test(req_get_measurements_case17),
5982 : cmocka_unit_test(req_get_measurements_case18),
5983 : cmocka_unit_test(req_get_measurements_case19),
5984 : cmocka_unit_test(req_get_measurements_case20),
5985 : cmocka_unit_test(req_get_measurements_case21),
5986 : cmocka_unit_test(req_get_measurements_case22),
5987 : cmocka_unit_test(req_get_measurements_case23),
5988 : cmocka_unit_test(req_get_measurements_case24),
5989 : cmocka_unit_test(req_get_measurements_case25),
5990 : cmocka_unit_test(req_get_measurements_case26),
5991 : cmocka_unit_test(req_get_measurements_case27),
5992 : cmocka_unit_test(req_get_measurements_case28),
5993 : cmocka_unit_test(req_get_measurements_case29),
5994 : cmocka_unit_test(req_get_measurements_case30),
5995 : cmocka_unit_test(req_get_measurements_case31),
5996 : cmocka_unit_test(req_get_measurements_case32),
5997 : cmocka_unit_test(req_get_measurements_case33),
5998 : cmocka_unit_test(req_get_measurements_case34),
5999 : cmocka_unit_test(req_get_measurements_case35),
6000 : cmocka_unit_test(req_get_measurements_case36),
6001 : cmocka_unit_test(req_get_measurements_case37),
6002 : cmocka_unit_test(req_get_measurements_case38),
6003 : cmocka_unit_test(req_get_measurements_case39),
6004 : cmocka_unit_test(req_get_measurements_case40),
6005 : cmocka_unit_test(req_get_measurements_case41),
6006 : };
6007 :
6008 1 : libspdm_test_context_t test_context = {
6009 : LIBSPDM_TEST_CONTEXT_VERSION,
6010 : true,
6011 : send_message,
6012 : receive_message,
6013 : };
6014 :
6015 1 : libspdm_setup_test_context(&test_context);
6016 :
6017 1 : return cmocka_run_group_tests(test_cases,
6018 : libspdm_unit_test_group_setup,
6019 : libspdm_unit_test_group_teardown);
6020 : }
6021 :
6022 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
|