Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2025 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include "spdm_unit_test.h"
8 : #include "internal/libspdm_requester_lib.h"
9 :
10 : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG \
11 : (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
12 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP)
13 :
14 : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11 \
15 : (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
16 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP | \
17 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP | \
18 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP | \
19 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP | \
20 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP | \
21 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER | \
22 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP | \
23 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP | \
24 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP | \
25 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
26 :
27 : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_12 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP
28 :
29 : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 \
30 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP | \
31 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP | \
32 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP | \
33 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG | \
34 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP | \
35 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | \
36 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | \
37 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP | \
38 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | \
39 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT | \
40 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP | \
41 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP | \
42 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP | \
43 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
44 :
45 : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12 \
46 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP | \
47 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
48 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP | \
49 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP)
50 :
51 56 : static libspdm_return_t send_message(
52 : void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
53 : {
54 : libspdm_test_context_t *spdm_test_context;
55 :
56 56 : spdm_test_context = libspdm_get_test_context();
57 56 : switch (spdm_test_context->case_id) {
58 1 : case 0x1:
59 1 : return LIBSPDM_STATUS_SEND_FAIL;
60 1 : case 0x2:
61 1 : return LIBSPDM_STATUS_SUCCESS;
62 1 : case 0x3:
63 1 : return LIBSPDM_STATUS_SUCCESS;
64 1 : case 0x4:
65 1 : return LIBSPDM_STATUS_SUCCESS;
66 1 : case 0x5:
67 1 : return LIBSPDM_STATUS_SUCCESS;
68 1 : case 0x6:
69 1 : return LIBSPDM_STATUS_SUCCESS;
70 1 : case 0x7:
71 1 : return LIBSPDM_STATUS_SUCCESS;
72 1 : case 0x8:
73 1 : return LIBSPDM_STATUS_SUCCESS;
74 1 : case 0x9:
75 1 : return LIBSPDM_STATUS_SUCCESS;
76 1 : case 0xa:
77 1 : return LIBSPDM_STATUS_SUCCESS;
78 1 : case 0xb:
79 1 : return LIBSPDM_STATUS_SUCCESS;
80 1 : case 0xc:
81 1 : return LIBSPDM_STATUS_SUCCESS;
82 1 : case 0xd:
83 1 : return LIBSPDM_STATUS_SUCCESS;
84 1 : case 0xe:
85 1 : return LIBSPDM_STATUS_SUCCESS;
86 1 : case 0xf:
87 1 : return LIBSPDM_STATUS_SUCCESS;
88 1 : case 0x10:
89 1 : return LIBSPDM_STATUS_SUCCESS;
90 1 : case 0x11:
91 1 : return LIBSPDM_STATUS_SUCCESS;
92 1 : case 0x12:
93 1 : return LIBSPDM_STATUS_SUCCESS;
94 1 : case 0x13:
95 1 : return LIBSPDM_STATUS_SUCCESS;
96 1 : case 0x14:
97 1 : return LIBSPDM_STATUS_SUCCESS;
98 1 : case 0x15:
99 1 : return LIBSPDM_STATUS_SUCCESS;
100 1 : case 0x16:
101 1 : return LIBSPDM_STATUS_SUCCESS;
102 1 : case 0x17:
103 1 : return LIBSPDM_STATUS_SUCCESS;
104 1 : case 0x18:
105 1 : return LIBSPDM_STATUS_SUCCESS;
106 1 : case 0x19:
107 1 : return LIBSPDM_STATUS_SUCCESS;
108 1 : case 0x1a:
109 1 : return LIBSPDM_STATUS_SUCCESS;
110 1 : case 0x1b:
111 1 : return LIBSPDM_STATUS_SUCCESS;
112 1 : case 0x1c:
113 1 : return LIBSPDM_STATUS_SUCCESS;
114 18 : case 0x1d:
115 18 : return LIBSPDM_STATUS_SUCCESS;
116 1 : case 0x1E:
117 1 : return LIBSPDM_STATUS_SUCCESS;
118 1 : case 0x1F:
119 1 : return LIBSPDM_STATUS_SUCCESS;
120 1 : case 0x20:
121 1 : return LIBSPDM_STATUS_SUCCESS;
122 1 : case 0x21:
123 1 : return LIBSPDM_STATUS_SUCCESS;
124 1 : case 0x22:
125 1 : return LIBSPDM_STATUS_SUCCESS;
126 1 : case 0x23:
127 1 : return LIBSPDM_STATUS_SUCCESS;
128 1 : case 0x24:
129 1 : return LIBSPDM_STATUS_SUCCESS;
130 1 : case 0x25:
131 1 : return LIBSPDM_STATUS_SUCCESS;
132 1 : case 0x26:
133 1 : return LIBSPDM_STATUS_SUCCESS;
134 1 : case 0x27:
135 1 : return LIBSPDM_STATUS_SUCCESS;
136 0 : default:
137 0 : return LIBSPDM_STATUS_SEND_FAIL;
138 : }
139 : }
140 :
141 54 : static libspdm_return_t receive_message(
142 : void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
143 : {
144 : libspdm_test_context_t *spdm_test_context;
145 :
146 54 : spdm_test_context = libspdm_get_test_context();
147 54 : switch (spdm_test_context->case_id) {
148 0 : case 0x1:
149 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
150 :
151 1 : case 0x2: {
152 : spdm_capabilities_response_t *spdm_response;
153 : size_t spdm_response_size;
154 : size_t transport_header_size;
155 :
156 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
157 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
158 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
159 :
160 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
161 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
162 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
163 1 : spdm_response->header.param1 = 0;
164 1 : spdm_response->header.param2 = 0;
165 1 : spdm_response->ct_exponent = 0;
166 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP;
167 :
168 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
169 : false, spdm_response_size,
170 : spdm_response,
171 : response_size, response);
172 : }
173 1 : return LIBSPDM_STATUS_SUCCESS;
174 :
175 0 : case 0x3: {
176 : spdm_capabilities_response_t *spdm_response;
177 : size_t spdm_response_size;
178 : size_t transport_header_size;
179 :
180 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
181 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
182 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
183 :
184 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
185 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
186 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
187 0 : spdm_response->header.param1 = 0;
188 0 : spdm_response->header.param2 = 0;
189 0 : spdm_response->ct_exponent = 0;
190 0 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
191 :
192 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
193 : false, spdm_response_size,
194 : spdm_response,
195 : response_size, response);
196 : }
197 0 : return LIBSPDM_STATUS_SUCCESS;
198 :
199 1 : case 0x4: {
200 : spdm_error_response_t *spdm_response;
201 : size_t spdm_response_size;
202 : size_t transport_header_size;
203 :
204 1 : spdm_response_size = sizeof(spdm_error_response_t);
205 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
206 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
207 :
208 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
209 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
210 1 : spdm_response->header.request_response_code = SPDM_ERROR;
211 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
212 1 : spdm_response->header.param2 = 0;
213 :
214 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
215 : false, spdm_response_size,
216 : spdm_response,
217 : response_size, response);
218 : }
219 1 : return LIBSPDM_STATUS_SUCCESS;
220 :
221 1 : case 0x5: {
222 : spdm_error_response_t *spdm_response;
223 : size_t spdm_response_size;
224 : size_t transport_header_size;
225 :
226 1 : spdm_response_size = sizeof(spdm_error_response_t);
227 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
228 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
229 :
230 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
231 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
232 1 : spdm_response->header.request_response_code = SPDM_ERROR;
233 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
234 1 : spdm_response->header.param2 = 0;
235 :
236 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
237 : false, spdm_response_size,
238 : spdm_response,
239 : response_size, response);
240 : }
241 1 : return LIBSPDM_STATUS_SUCCESS;
242 :
243 1 : case 0x6: {
244 : spdm_capabilities_response_t *spdm_response;
245 : size_t spdm_response_size;
246 : size_t transport_header_size;
247 :
248 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
249 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
250 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
251 :
252 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
253 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
254 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
255 1 : spdm_response->header.param1 = 0;
256 1 : spdm_response->header.param2 = 0;
257 1 : spdm_response->ct_exponent = 0;
258 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG |
259 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
260 :
261 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
262 : false, spdm_response_size,
263 : spdm_response,
264 : response_size, response);
265 : }
266 1 : return LIBSPDM_STATUS_SUCCESS;
267 :
268 1 : case 0x7: {
269 : spdm_error_response_t *spdm_response;
270 : size_t spdm_response_size;
271 : size_t transport_header_size;
272 :
273 1 : spdm_response_size = sizeof(spdm_error_response_t);
274 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
275 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
276 :
277 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
278 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
279 1 : spdm_response->header.request_response_code = SPDM_ERROR;
280 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
281 1 : spdm_response->header.param2 = 0;
282 :
283 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
284 : false, spdm_response_size,
285 : spdm_response,
286 : response_size, response);
287 : }
288 1 : return LIBSPDM_STATUS_SUCCESS;
289 :
290 1 : case 0x8: {
291 : spdm_error_response_data_response_not_ready_t *spdm_response;
292 : size_t spdm_response_size;
293 : size_t transport_header_size;
294 :
295 1 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
296 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
297 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
298 :
299 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
300 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
301 1 : spdm_response->header.request_response_code = SPDM_ERROR;
302 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
303 1 : spdm_response->header.param2 = 0;
304 1 : spdm_response->extend_error_data.rd_exponent = 1;
305 1 : spdm_response->extend_error_data.rd_tm = 2;
306 1 : spdm_response->extend_error_data.request_code = SPDM_GET_CAPABILITIES;
307 1 : spdm_response->extend_error_data.token = 0;
308 :
309 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
310 : false, spdm_response_size,
311 : spdm_response,
312 : response_size, response);
313 : }
314 1 : return LIBSPDM_STATUS_SUCCESS;
315 :
316 1 : case 0x9: {
317 : spdm_capabilities_response_t *spdm_response;
318 : size_t spdm_response_size;
319 : size_t transport_header_size;
320 :
321 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
322 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
323 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
324 :
325 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
326 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
327 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
328 1 : spdm_response->header.param1 = 0;
329 1 : spdm_response->header.param2 = 0;
330 1 : spdm_response->ct_exponent = 0;
331 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
332 :
333 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
334 : false, spdm_response_size,
335 : spdm_response,
336 : response_size, response);
337 : }
338 1 : return LIBSPDM_STATUS_SUCCESS;
339 :
340 1 : case 0xa: {
341 : spdm_capabilities_response_t *spdm_response;
342 : size_t spdm_response_size;
343 : size_t transport_header_size;
344 :
345 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
346 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
347 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
348 :
349 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
350 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
351 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
352 1 : spdm_response->header.param1 = 0;
353 1 : spdm_response->header.param2 = 0;
354 1 : spdm_response->ct_exponent = 0;
355 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
356 :
357 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
358 : false, spdm_response_size,
359 : spdm_response,
360 : response_size, response);
361 : }
362 1 : return LIBSPDM_STATUS_SUCCESS;
363 :
364 1 : case 0xb: {
365 : spdm_capabilities_response_t *spdm_response;
366 : size_t spdm_response_size;
367 : size_t transport_header_size;
368 :
369 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
370 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
371 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
372 :
373 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
374 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
375 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
376 1 : spdm_response->header.param1 = 0;
377 1 : spdm_response->header.param2 = 0;
378 1 : spdm_response->ct_exponent = 0;
379 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
380 :
381 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
382 : false, spdm_response_size,
383 : spdm_response,
384 : response_size, response);
385 : }
386 1 : return LIBSPDM_STATUS_SUCCESS;
387 :
388 1 : case 0xc: {
389 : spdm_capabilities_response_t *spdm_response;
390 : size_t spdm_response_size;
391 : size_t transport_header_size;
392 :
393 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
394 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
395 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
396 :
397 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
398 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
399 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
400 1 : spdm_response->header.param1 = 0;
401 1 : spdm_response->header.param2 = 0;
402 1 : spdm_response->ct_exponent = 0;
403 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
404 :
405 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
406 : false, spdm_response_size,
407 : spdm_response,
408 : response_size, response);
409 : }
410 1 : return LIBSPDM_STATUS_SUCCESS;
411 :
412 1 : case 0xd: {
413 : spdm_capabilities_response_t *spdm_response;
414 : size_t spdm_response_size;
415 : size_t transport_header_size;
416 :
417 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
418 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
419 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
420 :
421 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
422 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
423 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
424 1 : spdm_response->header.param1 = 0;
425 1 : spdm_response->header.param2 = 0;
426 :
427 1 : libspdm_transport_test_encode_message(
428 : spdm_context, NULL, false, false,
429 : sizeof(spdm_message_header_t), spdm_response,
430 : response_size, response);
431 : }
432 1 : return LIBSPDM_STATUS_SUCCESS;
433 :
434 1 : case 0xe: {
435 : spdm_capabilities_response_t *spdm_response;
436 : size_t spdm_response_size;
437 : size_t transport_header_size;
438 :
439 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
440 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
441 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
442 :
443 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
444 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
445 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
446 1 : spdm_response->header.param1 = 0;
447 1 : spdm_response->header.param2 = 0;
448 1 : spdm_response->ct_exponent = 0;
449 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
450 :
451 1 : libspdm_transport_test_encode_message(
452 : spdm_context, NULL, false, false,
453 : sizeof(spdm_capabilities_response_t) + sizeof(uint8_t), spdm_response,
454 : response_size, response);
455 : }
456 1 : return LIBSPDM_STATUS_INVALID_MSG_SIZE;
457 :
458 1 : case 0xf: {
459 : spdm_capabilities_response_t *spdm_response;
460 : size_t spdm_response_size;
461 : size_t transport_header_size;
462 :
463 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
464 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
465 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
466 :
467 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
468 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
469 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
470 1 : spdm_response->header.param1 = 0;
471 1 : spdm_response->header.param2 = 0;
472 1 : spdm_response->ct_exponent = 0;
473 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
474 :
475 1 : libspdm_transport_test_encode_message(
476 : spdm_context, NULL, false, false,
477 : sizeof(spdm_capabilities_response_t) - sizeof(uint8_t), spdm_response,
478 : response_size, response);
479 : }
480 1 : return LIBSPDM_STATUS_INVALID_MSG_SIZE;
481 :
482 1 : case 0x10: {
483 : spdm_capabilities_response_t *spdm_response;
484 : size_t spdm_response_size;
485 : size_t transport_header_size;
486 :
487 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
488 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
489 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
490 :
491 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
492 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
493 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
494 1 : spdm_response->header.param1 = 0;
495 1 : spdm_response->header.param2 = 0;
496 1 : spdm_response->ct_exponent = 0;
497 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
498 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
499 :
500 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
501 : false, spdm_response_size,
502 : spdm_response,
503 : response_size, response);
504 : }
505 1 : return LIBSPDM_STATUS_SUCCESS;
506 :
507 1 : case 0x11: {
508 : spdm_capabilities_response_t *spdm_response;
509 : size_t spdm_response_size;
510 : size_t transport_header_size;
511 :
512 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
513 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
514 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
515 :
516 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
517 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
518 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
519 1 : spdm_response->header.param1 = 0;
520 1 : spdm_response->header.param2 = 0;
521 1 : spdm_response->ct_exponent = 0;
522 1 : spdm_response->flags =
523 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
524 : (0xFFFFFFFF ^
525 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
526 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
527 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
528 :
529 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
530 : false, spdm_response_size,
531 : spdm_response,
532 : response_size, response);
533 : }
534 1 : return LIBSPDM_STATUS_SUCCESS;
535 :
536 1 : case 0x12: {
537 : spdm_capabilities_response_t *spdm_response;
538 : size_t spdm_response_size;
539 : size_t transport_header_size;
540 :
541 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
542 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
543 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
544 :
545 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
546 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
547 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
548 1 : spdm_response->header.param1 = 0;
549 1 : spdm_response->header.param2 = 0;
550 1 : spdm_response->ct_exponent = 0;
551 1 : spdm_response->flags =
552 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
553 : (0xFFFFFFFF ^
554 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
555 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
556 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
557 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
558 :
559 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
560 : false, spdm_response_size,
561 : spdm_response,
562 : response_size, response);
563 : }
564 1 : return LIBSPDM_STATUS_SUCCESS;
565 :
566 1 : case 0x13: {
567 : spdm_capabilities_response_t *spdm_response;
568 : size_t spdm_response_size;
569 : size_t transport_header_size;
570 :
571 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
572 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
573 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
574 :
575 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
576 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
577 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
578 1 : spdm_response->header.param1 = 0;
579 1 : spdm_response->header.param2 = 0;
580 1 : spdm_response->ct_exponent = 0;
581 1 : spdm_response->flags =
582 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
583 : (0xFFFFFFFF ^
584 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
585 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
586 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
587 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
588 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
589 : false, spdm_response_size,
590 : spdm_response,
591 : response_size, response);
592 : }
593 1 : return LIBSPDM_STATUS_SUCCESS;
594 :
595 1 : case 0x14: {
596 : spdm_capabilities_response_t *spdm_response;
597 : size_t spdm_response_size;
598 : size_t transport_header_size;
599 :
600 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
601 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
602 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
603 :
604 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
605 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
606 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
607 1 : spdm_response->header.param1 = 0;
608 1 : spdm_response->header.param2 = 0;
609 1 : spdm_response->ct_exponent = 0;
610 1 : spdm_response->flags =
611 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
612 : (0xFFFFFFFF ^
613 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
614 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
615 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
616 :
617 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
618 : false, spdm_response_size,
619 : spdm_response,
620 : response_size, response);
621 : }
622 1 : return LIBSPDM_STATUS_SUCCESS;
623 :
624 1 : case 0x15: {
625 : spdm_capabilities_response_t *spdm_response;
626 : size_t spdm_response_size;
627 : size_t transport_header_size;
628 :
629 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
630 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
631 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
632 :
633 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
634 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
635 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
636 1 : spdm_response->header.param1 = 0;
637 1 : spdm_response->header.param2 = 0;
638 1 : spdm_response->ct_exponent = 0;
639 1 : spdm_response->flags =
640 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
641 : (0xFFFFFFFF ^
642 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
643 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
644 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
645 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
646 :
647 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
648 : false, spdm_response_size,
649 : spdm_response,
650 : response_size, response);
651 : }
652 1 : return LIBSPDM_STATUS_SUCCESS;
653 :
654 :
655 1 : case 0x16: {
656 : spdm_capabilities_response_t *spdm_response;
657 : size_t spdm_response_size;
658 : size_t transport_header_size;
659 :
660 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
661 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
662 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
663 :
664 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
665 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
666 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
667 1 : spdm_response->header.param1 = 0;
668 1 : spdm_response->header.param2 = 0;
669 1 : spdm_response->ct_exponent = 0;
670 1 : spdm_response->flags =
671 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
672 : (0xFFFFFFFF ^
673 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
674 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
675 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
676 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
677 :
678 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
679 : false, spdm_response_size,
680 : spdm_response,
681 : response_size, response);
682 : }
683 1 : return LIBSPDM_STATUS_SUCCESS;
684 :
685 1 : case 0x17: {
686 : spdm_capabilities_response_t *spdm_response;
687 : size_t spdm_response_size;
688 : size_t transport_header_size;
689 :
690 1 : spdm_response_size = sizeof(spdm_capabilities_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 : libspdm_zero_mem(spdm_response, spdm_response_size);
695 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
696 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
697 1 : spdm_response->header.param1 = 0;
698 1 : spdm_response->header.param2 = 0;
699 1 : spdm_response->ct_exponent = 0;
700 1 : spdm_response->flags =
701 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
702 : (0xFFFFFFFF ^
703 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP));
704 :
705 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
706 : false, spdm_response_size,
707 : spdm_response,
708 : response_size, response);
709 : }
710 1 : return LIBSPDM_STATUS_SUCCESS;
711 :
712 1 : case 0x18: {
713 : spdm_capabilities_response_t *spdm_response;
714 : size_t spdm_response_size;
715 : size_t transport_header_size;
716 :
717 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
718 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
719 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
720 :
721 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
722 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
723 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
724 1 : spdm_response->header.param1 = 0;
725 1 : spdm_response->header.param2 = 0;
726 1 : spdm_response->ct_exponent = 0;
727 1 : spdm_response->flags =
728 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
729 : (0xFFFFFFFF ^
730 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP));
731 :
732 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
733 : false, spdm_response_size,
734 : spdm_response,
735 : response_size, response);
736 : }
737 1 : return LIBSPDM_STATUS_SUCCESS;
738 :
739 1 : case 0x19: {
740 : spdm_capabilities_response_t *spdm_response;
741 : size_t spdm_response_size;
742 : size_t transport_header_size;
743 :
744 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
745 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
746 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
747 :
748 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
749 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
750 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
751 1 : spdm_response->header.param1 = 0;
752 1 : spdm_response->header.param2 = 0;
753 1 : spdm_response->ct_exponent = 0;
754 1 : spdm_response->flags =
755 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
756 : (0xFFFFFFFF ^
757 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
758 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
759 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP));
760 :
761 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
762 : false, spdm_response_size,
763 : spdm_response,
764 : response_size, response);
765 : }
766 1 : return LIBSPDM_STATUS_SUCCESS;
767 :
768 1 : case 0x1a: {
769 : spdm_capabilities_response_t *spdm_response;
770 : size_t spdm_response_size;
771 : size_t transport_header_size;
772 :
773 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
774 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
775 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
776 :
777 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
778 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
779 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
780 1 : spdm_response->header.param1 = 0;
781 1 : spdm_response->header.param2 = 0;
782 1 : spdm_response->ct_exponent = 0;
783 1 : spdm_response->flags =
784 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 |
785 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
786 :
787 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
788 : false, spdm_response_size,
789 : spdm_response,
790 : response_size, response);
791 : }
792 1 : return LIBSPDM_STATUS_SUCCESS;
793 :
794 1 : case 0x1b: {
795 : spdm_capabilities_response_t *spdm_response;
796 : size_t spdm_response_size;
797 : size_t transport_header_size;
798 :
799 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
800 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
801 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
802 :
803 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
804 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
805 1 : spdm_response->header.request_response_code =
806 : SPDM_GET_CAPABILITIES;
807 1 : spdm_response->header.param1 = 0;
808 1 : spdm_response->header.param2 = 0;
809 1 : spdm_response->ct_exponent = 0;
810 1 : spdm_response->flags =
811 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
812 :
813 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
814 : false, spdm_response_size,
815 : spdm_response,
816 : response_size, response);
817 : }
818 1 : return LIBSPDM_STATUS_SUCCESS;
819 :
820 1 : case 0x1c: {
821 : spdm_capabilities_response_t *spdm_response;
822 : size_t spdm_response_size;
823 : size_t transport_header_size;
824 :
825 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
826 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
827 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
828 :
829 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
830 1 : spdm_response->header.spdm_version = 0xFF;
831 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
832 1 : spdm_response->header.param1 = 0;
833 1 : spdm_response->header.param2 = 0;
834 1 : spdm_response->ct_exponent = 0;
835 1 : spdm_response->flags =
836 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
837 :
838 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
839 : false, spdm_response_size,
840 : spdm_response,
841 : response_size, response);
842 : }
843 1 : return LIBSPDM_STATUS_SUCCESS;
844 :
845 18 : case 0x1d: {
846 : static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
847 :
848 : spdm_error_response_t *spdm_response;
849 : size_t spdm_response_size;
850 : size_t transport_header_size;
851 :
852 18 : spdm_response_size = sizeof(spdm_error_response_t);
853 18 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
854 18 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
855 :
856 18 : if(error_code <= 0xff) {
857 18 : libspdm_zero_mem(spdm_response, spdm_response_size);
858 18 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
859 18 : spdm_response->header.request_response_code = SPDM_ERROR;
860 18 : spdm_response->header.param1 = (uint8_t) error_code;
861 18 : spdm_response->header.param2 = 0;
862 :
863 18 : libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
864 : spdm_response_size, spdm_response,
865 : response_size, response);
866 : }
867 :
868 18 : error_code++;
869 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
870 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
871 : }
872 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
873 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
874 : }
875 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
876 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
877 : }
878 : }
879 18 : return LIBSPDM_STATUS_SUCCESS;
880 :
881 1 : case 0x1e: {
882 : spdm_capabilities_response_t *spdm_response;
883 : size_t spdm_response_size;
884 : size_t transport_header_size;
885 :
886 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
887 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
888 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
889 :
890 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
891 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
892 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
893 1 : spdm_response->header.param1 = 0;
894 1 : spdm_response->header.param2 = 0;
895 1 : spdm_response->ct_exponent = 0;
896 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP;
897 :
898 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
899 : false, spdm_response_size,
900 : spdm_response,
901 : response_size, response);
902 : }
903 1 : return LIBSPDM_STATUS_SUCCESS;
904 :
905 1 : case 0x1F:
906 1 : return LIBSPDM_STATUS_RECEIVE_FAIL;
907 :
908 1 : case 0x20: {
909 : spdm_capabilities_response_t *spdm_response;
910 : size_t spdm_response_size;
911 : size_t transport_header_size;
912 :
913 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
914 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
915 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
916 :
917 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
918 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
919 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
920 1 : spdm_response->header.param1 = 0;
921 1 : spdm_response->header.param2 = 0;
922 1 : spdm_response->ct_exponent = 0;
923 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CSR_CAP;
924 :
925 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
926 : false, spdm_response_size,
927 : spdm_response,
928 : response_size, response);
929 : }
930 1 : return LIBSPDM_STATUS_SUCCESS;
931 :
932 1 : case 0x21: {
933 : spdm_capabilities_response_t *spdm_response;
934 : size_t spdm_response_size;
935 : size_t transport_header_size;
936 :
937 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
938 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
939 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
940 :
941 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
942 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
943 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
944 1 : spdm_response->header.param1 = 0;
945 1 : spdm_response->header.param2 = 0;
946 1 : spdm_response->ct_exponent = 0;
947 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_INSTALL_RESET_CAP;
948 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
949 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
950 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
951 : false, spdm_response_size,
952 : spdm_response,
953 : response_size, response);
954 : }
955 1 : return LIBSPDM_STATUS_SUCCESS;
956 1 : case 0x22: {
957 : spdm_capabilities_response_t *spdm_response;
958 : size_t spdm_response_size;
959 : size_t transport_header_size;
960 :
961 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
962 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
963 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
964 :
965 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
966 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
967 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
968 1 : spdm_response->header.param1 = 0;
969 1 : spdm_response->header.param2 = 0;
970 1 : spdm_response->ct_exponent = 0;
971 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
972 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
973 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
974 :
975 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
976 : false, spdm_response_size,
977 : spdm_response,
978 : response_size, response);
979 : }
980 1 : return LIBSPDM_STATUS_SUCCESS;
981 :
982 1 : case 0x23: {
983 : spdm_capabilities_response_t *spdm_response;
984 : size_t spdm_response_size;
985 : size_t transport_header_size;
986 :
987 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
988 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
989 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
990 :
991 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
992 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
993 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
994 1 : spdm_response->header.param1 = 0;
995 1 : spdm_response->header.param2 = 0;
996 1 : spdm_response->ct_exponent = 0;
997 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
998 1 : spdm_response->data_transfer_size = 0;
999 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
1000 :
1001 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1002 : false, spdm_response_size,
1003 : spdm_response,
1004 : response_size, response);
1005 : }
1006 1 : return LIBSPDM_STATUS_SUCCESS;
1007 :
1008 1 : case 0x24: {
1009 : spdm_capabilities_response_t *spdm_response;
1010 : size_t spdm_response_size;
1011 : size_t transport_header_size;
1012 :
1013 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
1014 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1015 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1016 :
1017 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
1018 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
1019 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
1020 1 : spdm_response->header.param1 = 0;
1021 1 : spdm_response->header.param2 = 0;
1022 1 : spdm_response->ct_exponent = 0;
1023 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1024 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE - 1;
1025 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
1026 :
1027 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1028 : false, spdm_response_size,
1029 : spdm_response,
1030 : response_size, response);
1031 : }
1032 1 : return LIBSPDM_STATUS_SUCCESS;
1033 :
1034 1 : case 0x25: {
1035 : spdm_capabilities_response_t *spdm_response;
1036 : size_t spdm_response_size;
1037 : size_t transport_header_size;
1038 :
1039 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
1040 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1041 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1042 :
1043 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
1044 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
1045 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
1046 1 : spdm_response->header.param1 = 0;
1047 1 : spdm_response->header.param2 = 0;
1048 1 : spdm_response->ct_exponent = 0;
1049 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12;
1050 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
1051 1 : spdm_response->max_spdm_msg_size = LIBSPDM_DATA_TRANSFER_SIZE - 1;
1052 :
1053 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1054 : false, spdm_response_size,
1055 : spdm_response,
1056 : response_size, response);
1057 : }
1058 1 : return LIBSPDM_STATUS_SUCCESS;
1059 :
1060 1 : case 0x26: {
1061 : spdm_capabilities_response_t *spdm_response;
1062 : size_t spdm_response_size;
1063 : size_t transport_header_size;
1064 :
1065 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
1066 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1067 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1068 :
1069 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
1070 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
1071 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
1072 1 : spdm_response->header.param1 = 0;
1073 1 : spdm_response->header.param2 = 0;
1074 1 : spdm_response->ct_exponent = LIBSPDM_MAX_CT_EXPONENT + 1;
1075 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12;
1076 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
1077 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
1078 :
1079 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1080 : false, spdm_response_size,
1081 : spdm_response,
1082 : response_size, response);
1083 : }
1084 1 : return LIBSPDM_STATUS_SUCCESS;
1085 :
1086 1 : case 0x27: {
1087 : spdm_capabilities_response_t *spdm_response;
1088 : size_t spdm_response_size;
1089 : size_t transport_header_size;
1090 :
1091 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
1092 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1093 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1094 :
1095 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
1096 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
1097 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
1098 1 : spdm_response->header.param1 = 0;
1099 1 : spdm_response->header.param2 = 0;
1100 1 : spdm_response->ct_exponent = LIBSPDM_MAX_CT_EXPONENT;
1101 : /* CERT_CAP needs to be set if these capabilities are set. */
1102 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG |
1103 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY |
1104 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
1105 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
1106 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
1107 :
1108 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1109 : false, spdm_response_size,
1110 : spdm_response,
1111 : response_size, response);
1112 : }
1113 1 : return LIBSPDM_STATUS_SUCCESS;
1114 :
1115 0 : default:
1116 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
1117 : }
1118 : }
1119 :
1120 1 : static void libspdm_test_requester_get_capabilities_err_case1(void **state)
1121 : {
1122 : libspdm_return_t status;
1123 : libspdm_test_context_t *spdm_test_context;
1124 : libspdm_context_t *spdm_context;
1125 :
1126 1 : spdm_test_context = *state;
1127 1 : spdm_context = spdm_test_context->spdm_context;
1128 1 : spdm_test_context->case_id = 0x1;
1129 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1130 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1131 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1132 :
1133 1 : spdm_context->local_context.capability.ct_exponent = 0;
1134 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1135 1 : status = libspdm_get_capabilities(spdm_context);
1136 1 : assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
1137 1 : }
1138 :
1139 : /**
1140 : * Test 2: Responder sets MEAS_FRESH_CAP but does not set MEAS_CAP.
1141 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1142 : **/
1143 1 : static void libspdm_test_requester_get_capabilities_err_case2(void **state)
1144 : {
1145 : libspdm_return_t status;
1146 : libspdm_test_context_t *spdm_test_context;
1147 : libspdm_context_t *spdm_context;
1148 :
1149 1 : spdm_test_context = *state;
1150 1 : spdm_context = spdm_test_context->spdm_context;
1151 1 : spdm_test_context->case_id = 0x2;
1152 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1153 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1154 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1155 :
1156 1 : spdm_context->local_context.capability.ct_exponent = 0;
1157 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1158 1 : status = libspdm_get_capabilities(spdm_context);
1159 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1160 1 : }
1161 :
1162 1 : static void libspdm_test_requester_get_capabilities_err_case3(void **state)
1163 : {
1164 : libspdm_return_t status;
1165 : libspdm_test_context_t *spdm_test_context;
1166 : libspdm_context_t *spdm_context;
1167 :
1168 1 : spdm_test_context = *state;
1169 1 : spdm_context = spdm_test_context->spdm_context;
1170 1 : spdm_test_context->case_id = 0x3;
1171 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1172 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1173 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
1174 :
1175 1 : spdm_context->local_context.capability.ct_exponent = 0;
1176 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1177 1 : status = libspdm_get_capabilities(spdm_context);
1178 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_STATE_LOCAL);
1179 1 : }
1180 :
1181 1 : static void libspdm_test_requester_get_capabilities_err_case4(void **state)
1182 : {
1183 : libspdm_return_t status;
1184 : libspdm_test_context_t *spdm_test_context;
1185 : libspdm_context_t *spdm_context;
1186 :
1187 1 : spdm_test_context = *state;
1188 1 : spdm_context = spdm_test_context->spdm_context;
1189 1 : spdm_test_context->case_id = 0x4;
1190 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1191 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1192 1 : spdm_context->connection_info.connection_state =
1193 : LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1194 :
1195 1 : spdm_context->local_context.capability.ct_exponent = 0;
1196 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1197 1 : status = libspdm_get_capabilities(spdm_context);
1198 1 : assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
1199 1 : }
1200 :
1201 1 : static void libspdm_test_requester_get_capabilities_err_case5(void **state)
1202 : {
1203 : libspdm_return_t status;
1204 : libspdm_test_context_t *spdm_test_context;
1205 : libspdm_context_t *spdm_context;
1206 :
1207 1 : spdm_test_context = *state;
1208 1 : spdm_context = spdm_test_context->spdm_context;
1209 1 : spdm_test_context->case_id = 0x5;
1210 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1211 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1212 1 : spdm_context->connection_info.connection_state =
1213 : LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1214 :
1215 1 : spdm_context->local_context.capability.ct_exponent = 0;
1216 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1217 1 : status = libspdm_get_capabilities(spdm_context);
1218 1 : assert_int_equal(status, LIBSPDM_STATUS_BUSY_PEER);
1219 1 : }
1220 :
1221 : /**
1222 : * Test 6: Responder sets illegal SPDM 1.0 combination of MEAS_CAP (no signature), CERT_CAP,
1223 : * and CHAL_CAP.
1224 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1225 : **/
1226 1 : static void libspdm_test_requester_get_capabilities_err_case6(void **state)
1227 : {
1228 : libspdm_return_t status;
1229 : libspdm_test_context_t *spdm_test_context;
1230 : libspdm_context_t *spdm_context;
1231 :
1232 1 : spdm_test_context = *state;
1233 1 : spdm_context = spdm_test_context->spdm_context;
1234 1 : spdm_test_context->case_id = 0x6;
1235 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1236 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1237 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1238 :
1239 1 : spdm_context->local_context.capability.ct_exponent = 0;
1240 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1241 1 : status = libspdm_get_capabilities(spdm_context);
1242 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1243 1 : }
1244 :
1245 1 : static void libspdm_test_requester_get_capabilities_err_case7(void **state)
1246 : {
1247 : libspdm_return_t status;
1248 : libspdm_test_context_t *spdm_test_context;
1249 : libspdm_context_t *spdm_context;
1250 :
1251 1 : spdm_test_context = *state;
1252 1 : spdm_context = spdm_test_context->spdm_context;
1253 1 : spdm_test_context->case_id = 0x7;
1254 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1255 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1256 1 : spdm_context->connection_info.connection_state =
1257 : LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1258 :
1259 1 : spdm_context->local_context.capability.ct_exponent = 0;
1260 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1261 1 : status = libspdm_get_capabilities(spdm_context);
1262 1 : assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
1263 1 : assert_int_equal(spdm_context->connection_info.connection_state,
1264 : LIBSPDM_CONNECTION_STATE_NOT_STARTED);
1265 1 : }
1266 :
1267 1 : static void libspdm_test_requester_get_capabilities_err_case8(void **state)
1268 : {
1269 : libspdm_return_t status;
1270 : libspdm_test_context_t *spdm_test_context;
1271 : libspdm_context_t *spdm_context;
1272 :
1273 1 : spdm_test_context = *state;
1274 1 : spdm_context = spdm_test_context->spdm_context;
1275 1 : spdm_test_context->case_id = 0x8;
1276 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1277 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1278 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1279 :
1280 1 : spdm_context->local_context.capability.ct_exponent = 0;
1281 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1282 1 : status = libspdm_get_capabilities(spdm_context);
1283 1 : assert_int_equal(status, LIBSPDM_STATUS_NOT_READY_PEER);
1284 1 : }
1285 :
1286 : /**
1287 : * Test 9: Responder returns a Reserved MEAS_CAP value.
1288 : * Expected behavior: returns a status of LIBSPDM_STATUS_INVALID_MSG_FIELD.
1289 : **/
1290 1 : static void libspdm_test_requester_get_capabilities_err_case9(void **state)
1291 : {
1292 : libspdm_return_t status;
1293 : libspdm_test_context_t *spdm_test_context;
1294 : libspdm_context_t *spdm_context;
1295 :
1296 1 : spdm_test_context = *state;
1297 1 : spdm_context = spdm_test_context->spdm_context;
1298 1 : spdm_test_context->case_id = 0x9;
1299 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1300 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1301 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1302 :
1303 1 : spdm_context->local_context.capability.ct_exponent = 0;
1304 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1305 1 : status = libspdm_get_capabilities(spdm_context);
1306 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1307 1 : }
1308 :
1309 : /**
1310 : * Test 10: Responder sets illegal SPDM 1.0 combination of MEAS_CAP (with signature), CERT_CAP,
1311 : * and CHAL_CAP.
1312 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1313 : **/
1314 1 : static void libspdm_test_requester_get_capabilities_err_case10(void **state)
1315 : {
1316 : libspdm_return_t status;
1317 : libspdm_test_context_t *spdm_test_context;
1318 : libspdm_context_t *spdm_context;
1319 :
1320 1 : spdm_test_context = *state;
1321 1 : spdm_context = spdm_test_context->spdm_context;
1322 1 : spdm_test_context->case_id = 0xa;
1323 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1324 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1325 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1326 :
1327 1 : spdm_context->local_context.capability.ct_exponent = 0;
1328 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1329 1 : status = libspdm_get_capabilities(spdm_context);
1330 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1331 1 : }
1332 :
1333 : /**
1334 : * Test 11: Responder sets illegal 1.1/1.2 PSK_CAP value (3).
1335 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1336 : **/
1337 1 : static void libspdm_test_requester_get_capabilities_err_case11(void **state)
1338 : {
1339 : libspdm_return_t status;
1340 : libspdm_test_context_t *spdm_test_context;
1341 : libspdm_context_t *spdm_context;
1342 :
1343 1 : spdm_test_context = *state;
1344 1 : spdm_context = spdm_test_context->spdm_context;
1345 1 : spdm_test_context->case_id = 0xb;
1346 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1347 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1348 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1349 :
1350 1 : spdm_context->local_context.capability.ct_exponent = 0;
1351 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1352 1 : status = libspdm_get_capabilities(spdm_context);
1353 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1354 1 : }
1355 :
1356 : /**
1357 : * Test 11: Responder sets illegal 1.1/1.2 combination of values.
1358 : * CERT_CAP enabled.
1359 : * CHAL_CAP and KEY_EX_CAP disabled.
1360 : * MEAS_CAP with signature is disabled.
1361 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1362 : **/
1363 1 : static void libspdm_test_requester_get_capabilities_err_case12(void **state)
1364 : {
1365 : libspdm_return_t status;
1366 : libspdm_test_context_t *spdm_test_context;
1367 : libspdm_context_t *spdm_context;
1368 :
1369 1 : spdm_test_context = *state;
1370 1 : spdm_context = spdm_test_context->spdm_context;
1371 1 : spdm_test_context->case_id = 0xc;
1372 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1373 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1374 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1375 :
1376 1 : spdm_context->local_context.capability.ct_exponent = 0;
1377 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1378 1 : status = libspdm_get_capabilities(spdm_context);
1379 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1380 1 : }
1381 :
1382 1 : static void libspdm_test_requester_get_capabilities_err_case13(void **state)
1383 : {
1384 : libspdm_return_t status;
1385 : libspdm_test_context_t *spdm_test_context;
1386 : libspdm_context_t *spdm_context;
1387 :
1388 1 : spdm_test_context = *state;
1389 1 : spdm_context = spdm_test_context->spdm_context;
1390 1 : spdm_test_context->case_id = 0xd;
1391 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1392 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1393 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1394 :
1395 1 : spdm_context->local_context.capability.ct_exponent = 0;
1396 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1397 1 : status = libspdm_get_capabilities(spdm_context);
1398 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
1399 1 : }
1400 :
1401 1 : static void libspdm_test_requester_get_capabilities_err_case14(void **state)
1402 : {
1403 : libspdm_return_t status;
1404 : libspdm_test_context_t *spdm_test_context;
1405 : libspdm_context_t *spdm_context;
1406 :
1407 1 : spdm_test_context = *state;
1408 1 : spdm_context = spdm_test_context->spdm_context;
1409 1 : spdm_test_context->case_id = 0xe;
1410 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1411 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1412 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1413 :
1414 1 : spdm_context->local_context.capability.ct_exponent = 0;
1415 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1416 1 : status = libspdm_get_capabilities(spdm_context);
1417 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
1418 1 : }
1419 :
1420 1 : static void libspdm_test_requester_get_capabilities_err_case15(void **state)
1421 : {
1422 : libspdm_return_t status;
1423 : libspdm_test_context_t *spdm_test_context;
1424 : libspdm_context_t *spdm_context;
1425 :
1426 1 : spdm_test_context = *state;
1427 1 : spdm_context = spdm_test_context->spdm_context;
1428 1 : spdm_test_context->case_id = 0xf;
1429 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1430 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1431 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1432 :
1433 1 : spdm_context->local_context.capability.ct_exponent = 0;
1434 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1435 1 : status = libspdm_get_capabilities(spdm_context);
1436 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
1437 1 : }
1438 :
1439 : /**
1440 : * Test 16: Responder sets illegal 1.1/1.2 combination of values.
1441 : * CERT_CAP and PUB_KEY_ID_CAP disabled.
1442 : * At least one of CHAL_CAP, KEY_EX_CAP, MEAS_CAP (with signature), or MUT_AUTH_CAP
1443 : * is enabled.
1444 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1445 : **/
1446 1 : static void libspdm_test_requester_get_capabilities_err_case16(void **state)
1447 : {
1448 : libspdm_return_t status;
1449 : libspdm_test_context_t *spdm_test_context;
1450 : libspdm_context_t *spdm_context;
1451 :
1452 1 : spdm_test_context = *state;
1453 1 : spdm_context = spdm_test_context->spdm_context;
1454 1 : spdm_test_context->case_id = 0x10;
1455 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1456 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1457 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1458 :
1459 1 : spdm_context->local_context.capability.ct_exponent = 0;
1460 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1461 1 : status = libspdm_get_capabilities(spdm_context);
1462 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1463 1 : }
1464 :
1465 1 : static void libspdm_test_requester_get_capabilities_err_case17(void **state)
1466 : {
1467 : libspdm_return_t status;
1468 : libspdm_test_context_t *spdm_test_context;
1469 : libspdm_context_t *spdm_context;
1470 :
1471 1 : spdm_test_context = *state;
1472 1 : spdm_context = spdm_test_context->spdm_context;
1473 1 : spdm_test_context->case_id = 0x11;
1474 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1475 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1476 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1477 :
1478 1 : spdm_context->local_context.capability.ct_exponent = 0;
1479 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1480 1 : status = libspdm_get_capabilities(spdm_context);
1481 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1482 : /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
1483 : * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
1484 1 : }
1485 :
1486 1 : static void libspdm_test_requester_get_capabilities_err_case18(void **state)
1487 : {
1488 : libspdm_return_t status;
1489 : libspdm_test_context_t *spdm_test_context;
1490 : libspdm_context_t *spdm_context;
1491 :
1492 1 : spdm_test_context = *state;
1493 1 : spdm_context = spdm_test_context->spdm_context;
1494 1 : spdm_test_context->case_id = 0x12;
1495 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1496 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1497 1 : spdm_context->connection_info.connection_state =
1498 : LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1499 :
1500 1 : spdm_context->local_context.capability.ct_exponent = 0;
1501 1 : spdm_context->local_context.capability.flags =
1502 : LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1503 1 : status = libspdm_get_capabilities(spdm_context);
1504 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1505 : /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
1506 : * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
1507 1 : }
1508 :
1509 1 : static void libspdm_test_requester_get_capabilities_err_case19(void **state)
1510 : {
1511 : libspdm_return_t status;
1512 : libspdm_test_context_t *spdm_test_context;
1513 : libspdm_context_t *spdm_context;
1514 :
1515 1 : spdm_test_context = *state;
1516 1 : spdm_context = spdm_test_context->spdm_context;
1517 1 : spdm_test_context->case_id = 0x13;
1518 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1519 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1520 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1521 1 : libspdm_reset_message_a(spdm_context);
1522 :
1523 1 : spdm_context->local_context.capability.ct_exponent = 0;
1524 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1525 1 : status = libspdm_get_capabilities(spdm_context);
1526 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1527 : /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
1528 : * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)));*/
1529 1 : }
1530 :
1531 1 : static void libspdm_test_requester_get_capabilities_err_case20(void **state)
1532 : {
1533 : libspdm_return_t status;
1534 : libspdm_test_context_t *spdm_test_context;
1535 : libspdm_context_t *spdm_context;
1536 :
1537 1 : spdm_test_context = *state;
1538 1 : spdm_context = spdm_test_context->spdm_context;
1539 1 : spdm_test_context->case_id = 0x14;
1540 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1541 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1542 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1543 1 : libspdm_reset_message_a(spdm_context);
1544 :
1545 1 : spdm_context->local_context.capability.ct_exponent = 0;
1546 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1547 1 : status = libspdm_get_capabilities(spdm_context);
1548 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1549 1 : }
1550 :
1551 1 : static void libspdm_test_requester_get_capabilities_err_case21(void **state)
1552 : {
1553 : libspdm_return_t status;
1554 : libspdm_test_context_t *spdm_test_context;
1555 : libspdm_context_t *spdm_context;
1556 :
1557 1 : spdm_test_context = *state;
1558 1 : spdm_context = spdm_test_context->spdm_context;
1559 1 : spdm_test_context->case_id = 0x15;
1560 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1561 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1562 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1563 1 : libspdm_reset_message_a(spdm_context);
1564 :
1565 1 : spdm_context->local_context.capability.ct_exponent = 0;
1566 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1567 1 : status = libspdm_get_capabilities(spdm_context);
1568 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1569 1 : }
1570 :
1571 1 : static void libspdm_test_requester_get_capabilities_err_case22(void **state)
1572 : {
1573 : libspdm_return_t status;
1574 : libspdm_test_context_t *spdm_test_context;
1575 : libspdm_context_t *spdm_context;
1576 :
1577 1 : spdm_test_context = *state;
1578 1 : spdm_context = spdm_test_context->spdm_context;
1579 1 : spdm_test_context->case_id = 0x16;
1580 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1581 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1582 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1583 1 : libspdm_reset_message_a(spdm_context);
1584 :
1585 1 : spdm_context->local_context.capability.ct_exponent = 0;
1586 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1587 1 : status = libspdm_get_capabilities(spdm_context);
1588 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1589 1 : }
1590 :
1591 1 : static void libspdm_test_requester_get_capabilities_err_case23(void **state)
1592 : {
1593 : libspdm_return_t status;
1594 : libspdm_test_context_t *spdm_test_context;
1595 : libspdm_context_t *spdm_context;
1596 :
1597 1 : spdm_test_context = *state;
1598 1 : spdm_context = spdm_test_context->spdm_context;
1599 1 : spdm_test_context->case_id = 0x17;
1600 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1601 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1602 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1603 1 : libspdm_reset_message_a(spdm_context);
1604 :
1605 1 : spdm_context->local_context.capability.ct_exponent = 0;
1606 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1607 1 : status = libspdm_get_capabilities(spdm_context);
1608 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1609 : /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
1610 : * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP)));*/
1611 1 : }
1612 :
1613 1 : static void libspdm_test_requester_get_capabilities_err_case24(void **state)
1614 : {
1615 : libspdm_return_t status;
1616 : libspdm_test_context_t *spdm_test_context;
1617 : libspdm_context_t *spdm_context;
1618 :
1619 1 : spdm_test_context = *state;
1620 1 : spdm_context = spdm_test_context->spdm_context;
1621 1 : spdm_test_context->case_id = 0x18;
1622 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1623 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1624 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1625 1 : libspdm_reset_message_a(spdm_context);
1626 :
1627 1 : spdm_context->local_context.capability.ct_exponent = 0;
1628 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1629 1 : status = libspdm_get_capabilities(spdm_context);
1630 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1631 : /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
1632 : * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 & (0xFFFFFFFF^(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP)));*/
1633 1 : }
1634 :
1635 1 : static void libspdm_test_requester_get_capabilities_err_case25(void **state)
1636 : {
1637 : libspdm_return_t status;
1638 : libspdm_test_context_t *spdm_test_context;
1639 : libspdm_context_t *spdm_context;
1640 :
1641 1 : spdm_test_context = *state;
1642 1 : spdm_context = spdm_test_context->spdm_context;
1643 1 : spdm_test_context->case_id = 0x19;
1644 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1645 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1646 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1647 1 : libspdm_reset_message_a(spdm_context);
1648 :
1649 1 : spdm_context->local_context.capability.ct_exponent = 0;
1650 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1651 1 : status = libspdm_get_capabilities(spdm_context);
1652 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1653 1 : }
1654 :
1655 1 : static void libspdm_test_requester_get_capabilities_err_case26(void **state)
1656 : {
1657 : libspdm_return_t status;
1658 : libspdm_test_context_t *spdm_test_context;
1659 : libspdm_context_t *spdm_context;
1660 :
1661 1 : spdm_test_context = *state;
1662 1 : spdm_context = spdm_test_context->spdm_context;
1663 1 : spdm_test_context->case_id = 0x1a;
1664 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1665 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1666 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1667 1 : libspdm_reset_message_a(spdm_context);
1668 :
1669 1 : spdm_context->local_context.capability.ct_exponent = 0;
1670 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1671 1 : status = libspdm_get_capabilities(spdm_context);
1672 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1673 : /*assert_int_equal (spdm_context->connection_info.capability.ct_exponent, 0);
1674 : * assert_int_equal (spdm_context->connection_info.capability.flags, LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP);*/
1675 1 : }
1676 :
1677 1 : static void libspdm_test_requester_get_capabilities_err_case27(void **state)
1678 : {
1679 : libspdm_return_t status;
1680 : libspdm_test_context_t *spdm_test_context;
1681 : libspdm_context_t *spdm_context;
1682 :
1683 1 : spdm_test_context = *state;
1684 1 : spdm_context = spdm_test_context->spdm_context;
1685 1 : spdm_test_context->case_id = 0x1b;
1686 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1687 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1688 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1689 1 : libspdm_reset_message_a(spdm_context);
1690 :
1691 1 : spdm_context->local_context.capability.ct_exponent = 0;
1692 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1693 1 : status = libspdm_get_capabilities(spdm_context);
1694 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1695 1 : }
1696 :
1697 1 : static void libspdm_test_requester_get_capabilities_err_case28(void **state)
1698 : {
1699 : libspdm_return_t status;
1700 : libspdm_test_context_t *spdm_test_context;
1701 : libspdm_context_t *spdm_context;
1702 :
1703 1 : spdm_test_context = *state;
1704 1 : spdm_context = spdm_test_context->spdm_context;
1705 1 : spdm_test_context->case_id = 0x1c;
1706 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1707 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1708 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1709 1 : libspdm_reset_message_a(spdm_context);
1710 :
1711 1 : spdm_context->local_context.capability.ct_exponent = 0;
1712 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1713 1 : status = libspdm_get_capabilities(spdm_context);
1714 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1715 1 : }
1716 :
1717 1 : static void libspdm_test_requester_get_capabilities_err_case29(void **state) {
1718 : libspdm_return_t status;
1719 : libspdm_test_context_t *spdm_test_context;
1720 : libspdm_context_t *spdm_context;
1721 : uint16_t error_code;
1722 :
1723 1 : spdm_test_context = *state;
1724 1 : spdm_context = spdm_test_context->spdm_context;
1725 1 : spdm_test_context->case_id = 0x1d;
1726 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1727 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1728 1 : spdm_context->local_context.capability.ct_exponent = 0;
1729 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1730 :
1731 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
1732 19 : while(error_code <= 0xff) {
1733 18 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1734 18 : libspdm_reset_message_a(spdm_context);
1735 :
1736 18 : status = libspdm_get_capabilities (spdm_context);
1737 18 : LIBSPDM_ASSERT_INT_EQUAL_CASE (status, LIBSPDM_STATUS_ERROR_PEER, error_code);
1738 :
1739 18 : error_code++;
1740 18 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
1741 1 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
1742 : }
1743 18 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
1744 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
1745 : }
1746 18 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
1747 1 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
1748 : }
1749 : }
1750 1 : }
1751 :
1752 : /**
1753 : * Test 30: Responder sets illegal 1.2 combination of values.
1754 : * CERT_CAP is disabled.
1755 : * ALIAS_CERT_CAP is enabled.
1756 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1757 : **/
1758 1 : static void libspdm_test_requester_get_capabilities_err_case30(void **state)
1759 : {
1760 : libspdm_return_t status;
1761 : libspdm_test_context_t *spdm_test_context;
1762 : libspdm_context_t *spdm_context;
1763 :
1764 1 : spdm_test_context = *state;
1765 1 : spdm_context = spdm_test_context->spdm_context;
1766 1 : spdm_test_context->case_id = 0x1E;
1767 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
1768 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1769 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1770 :
1771 1 : spdm_context->local_context.capability.ct_exponent = 0;
1772 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1773 1 : status = libspdm_get_capabilities(spdm_context);
1774 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1775 1 : }
1776 :
1777 1 : static void libspdm_test_requester_get_capabilities_err_case31(void **state)
1778 : {
1779 : libspdm_return_t status;
1780 : libspdm_test_context_t *spdm_test_context;
1781 : libspdm_context_t *spdm_context;
1782 :
1783 1 : spdm_test_context = *state;
1784 1 : spdm_context = spdm_test_context->spdm_context;
1785 1 : spdm_test_context->case_id = 0x1F;
1786 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1787 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1788 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1789 1 : spdm_context->local_context.capability.ct_exponent = 0;
1790 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1791 1 : status = libspdm_get_capabilities(spdm_context);
1792 1 : assert_int_equal(status, LIBSPDM_STATUS_RECEIVE_FAIL);
1793 1 : }
1794 :
1795 : /**
1796 : * Test 32: Responder sets illegal 1.2 combination of values.
1797 : * CSR_CAP is enabled.
1798 : * SET_CERT_CAP is disabled.
1799 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1800 : **/
1801 1 : static void libspdm_test_requester_get_capabilities_err_case32(void **state)
1802 : {
1803 : libspdm_return_t status;
1804 : libspdm_test_context_t *spdm_test_context;
1805 : libspdm_context_t *spdm_context;
1806 :
1807 1 : spdm_test_context = *state;
1808 1 : spdm_context = spdm_test_context->spdm_context;
1809 1 : spdm_test_context->case_id = 0x20;
1810 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
1811 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1812 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1813 :
1814 1 : spdm_context->local_context.capability.ct_exponent = 0;
1815 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1816 1 : status = libspdm_get_capabilities(spdm_context);
1817 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1818 1 : }
1819 :
1820 : /**
1821 : * Test 33: Responder sets illegal 1.2 combination of values.
1822 : * CERT_INSTALL_RESET_CAP is enabled.
1823 : * CSR_CAP and SET_CERT_CAP are disabled.
1824 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1825 : **/
1826 1 : static void libspdm_test_requester_get_capabilities_err_case33(void **state)
1827 : {
1828 : libspdm_return_t status;
1829 : libspdm_test_context_t *spdm_test_context;
1830 : libspdm_context_t *spdm_context;
1831 :
1832 1 : spdm_test_context = *state;
1833 1 : spdm_context = spdm_test_context->spdm_context;
1834 1 : spdm_test_context->case_id = 0x21;
1835 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
1836 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1837 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1838 :
1839 1 : spdm_context->local_context.capability.ct_exponent = 0;
1840 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1841 1 : status = libspdm_get_capabilities(spdm_context);
1842 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1843 1 : }
1844 :
1845 1 : static void libspdm_test_requester_get_capabilities_err_case34(void **state)
1846 : {
1847 : libspdm_return_t status;
1848 : libspdm_test_context_t *spdm_test_context;
1849 : libspdm_context_t *spdm_context;
1850 :
1851 1 : spdm_test_context = *state;
1852 1 : spdm_context = spdm_test_context->spdm_context;
1853 1 : spdm_test_context->case_id = 0x22;
1854 :
1855 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
1856 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1857 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1858 1 : spdm_context->transcript.message_a.buffer_size =
1859 1 : spdm_context->transcript.message_a.max_buffer_size;
1860 1 : spdm_context->local_context.capability.ct_exponent = 0;
1861 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1862 1 : status = libspdm_get_capabilities(spdm_context);
1863 1 : assert_int_equal(status, LIBSPDM_STATUS_BUFFER_FULL);
1864 :
1865 1 : spdm_context->transcript.message_a.buffer_size = 0;
1866 1 : }
1867 :
1868 : /**
1869 : * Test 35: Unable to acquire sender buffer.
1870 : * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
1871 : **/
1872 1 : static void libspdm_test_requester_get_capabilities_err_case35(void **state)
1873 : {
1874 : libspdm_return_t status;
1875 : libspdm_test_context_t *spdm_test_context;
1876 : libspdm_context_t *spdm_context;
1877 :
1878 1 : spdm_test_context = *state;
1879 1 : spdm_context = spdm_test_context->spdm_context;
1880 1 : spdm_test_context->case_id = 0x3;
1881 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1882 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1883 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1884 :
1885 1 : spdm_context->local_context.capability.ct_exponent = 0;
1886 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1887 :
1888 1 : libspdm_force_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
1889 1 : status = libspdm_get_capabilities(spdm_context);
1890 1 : libspdm_release_error (LIBSPDM_ERR_ACQUIRE_SENDER_BUFFER);
1891 :
1892 1 : assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
1893 1 : }
1894 :
1895 : /**
1896 : * Test 36: Unable to acquire receiver buffer.
1897 : * Expected behavior: returns with status LIBSPDM_STATUS_ACQUIRE_FAIL.
1898 : **/
1899 1 : static void libspdm_test_requester_get_capabilities_err_case36(void **state)
1900 : {
1901 : libspdm_return_t status;
1902 : libspdm_test_context_t *spdm_test_context;
1903 : libspdm_context_t *spdm_context;
1904 :
1905 1 : spdm_test_context = *state;
1906 1 : spdm_context = spdm_test_context->spdm_context;
1907 1 : spdm_test_context->case_id = 0x3;
1908 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1909 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1910 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1911 :
1912 1 : spdm_context->local_context.capability.ct_exponent = 0;
1913 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1914 :
1915 1 : libspdm_force_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
1916 1 : status = libspdm_get_capabilities(spdm_context);
1917 1 : libspdm_release_error (LIBSPDM_ERR_ACQUIRE_RECEIVER_BUFFER);
1918 :
1919 1 : assert_int_equal(status, LIBSPDM_STATUS_ACQUIRE_FAIL);
1920 1 : }
1921 :
1922 : /**
1923 : * Test 37: Responder sets illegal DataTransferSize that is less than MinDataTransferSize.
1924 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1925 : **/
1926 1 : static void libspdm_test_requester_get_capabilities_err_case37(void **state)
1927 : {
1928 : libspdm_return_t status;
1929 : libspdm_test_context_t *spdm_test_context;
1930 : libspdm_context_t *spdm_context;
1931 :
1932 1 : spdm_test_context = *state;
1933 1 : spdm_context = spdm_test_context->spdm_context;
1934 1 : spdm_test_context->case_id = 0x23;
1935 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
1936 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1937 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1938 :
1939 1 : spdm_context->local_context.capability.ct_exponent = 0;
1940 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1941 :
1942 1 : status = libspdm_get_capabilities(spdm_context);
1943 :
1944 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1945 1 : }
1946 :
1947 : /**
1948 : * Test 38: Responder does not support chunking but also does not set DataTransferSize equal
1949 : * to MaxSPDMmsgSize.
1950 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1951 : **/
1952 1 : static void libspdm_test_requester_get_capabilities_err_case38(void **state)
1953 : {
1954 : libspdm_return_t status;
1955 : libspdm_test_context_t *spdm_test_context;
1956 : libspdm_context_t *spdm_context;
1957 :
1958 1 : spdm_test_context = *state;
1959 1 : spdm_context = spdm_test_context->spdm_context;
1960 1 : spdm_test_context->case_id = 0x24;
1961 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
1962 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1963 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1964 :
1965 1 : spdm_context->local_context.capability.ct_exponent = 0;
1966 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1967 :
1968 1 : status = libspdm_get_capabilities(spdm_context);
1969 :
1970 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1971 1 : }
1972 :
1973 : /**
1974 : * Test 39: Responder sets illegal MaxSPDMmsgSize that is less than DataTransferSize.
1975 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
1976 : **/
1977 1 : static void libspdm_test_requester_get_capabilities_err_case39(void **state)
1978 : {
1979 : libspdm_return_t status;
1980 : libspdm_test_context_t *spdm_test_context;
1981 : libspdm_context_t *spdm_context;
1982 :
1983 1 : spdm_test_context = *state;
1984 1 : spdm_context = spdm_test_context->spdm_context;
1985 1 : spdm_test_context->case_id = 0x25;
1986 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
1987 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1988 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1989 :
1990 1 : spdm_context->local_context.capability.ct_exponent = 0;
1991 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1992 :
1993 1 : status = libspdm_get_capabilities(spdm_context);
1994 :
1995 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
1996 1 : }
1997 :
1998 : /**
1999 : * Test 40: Responder returns a CTExponent value that is larger than LIBSPDM_MAX_CT_EXPONENT.
2000 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
2001 : **/
2002 1 : static void libspdm_test_requester_get_capabilities_err_case40(void **state)
2003 : {
2004 : libspdm_return_t status;
2005 : libspdm_test_context_t *spdm_test_context;
2006 : libspdm_context_t *spdm_context;
2007 :
2008 1 : spdm_test_context = *state;
2009 1 : spdm_context = spdm_test_context->spdm_context;
2010 1 : spdm_test_context->case_id = 0x26;
2011 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
2012 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2013 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
2014 :
2015 1 : spdm_context->local_context.capability.ct_exponent = 0;
2016 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
2017 :
2018 1 : status = libspdm_get_capabilities(spdm_context);
2019 :
2020 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
2021 1 : }
2022 :
2023 : /**
2024 : * Test 41: Responder sets MULTI_KEY_CAP but does not set CERT_CAP.
2025 : * Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
2026 : **/
2027 1 : static void libspdm_test_requester_get_capabilities_err_case41(void **state)
2028 : {
2029 : libspdm_return_t status;
2030 : libspdm_test_context_t *spdm_test_context;
2031 : libspdm_context_t *spdm_context;
2032 :
2033 1 : spdm_test_context = *state;
2034 1 : spdm_context = spdm_test_context->spdm_context;
2035 1 : spdm_test_context->case_id = 0x27;
2036 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
2037 : SPDM_VERSION_NUMBER_SHIFT_BIT;
2038 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
2039 :
2040 1 : spdm_context->local_context.capability.ct_exponent = 0;
2041 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
2042 :
2043 1 : status = libspdm_get_capabilities(spdm_context);
2044 :
2045 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
2046 1 : }
2047 :
2048 1 : int libspdm_req_get_capabilities_error_test(void)
2049 : {
2050 1 : const struct CMUnitTest test_cases[] = {
2051 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case1),
2052 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case2),
2053 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case3),
2054 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case4),
2055 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case5),
2056 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case6),
2057 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case7),
2058 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case8),
2059 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case9),
2060 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case10),
2061 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case11),
2062 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case12),
2063 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case13),
2064 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case14),
2065 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case15),
2066 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case16),
2067 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case17),
2068 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case18),
2069 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case19),
2070 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case20),
2071 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case21),
2072 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case22),
2073 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case23),
2074 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case24),
2075 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case25),
2076 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case26),
2077 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case27),
2078 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case28),
2079 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case29),
2080 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case30),
2081 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case31),
2082 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case32),
2083 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case33),
2084 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case34),
2085 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case35),
2086 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case36),
2087 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case37),
2088 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case38),
2089 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case39),
2090 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case40),
2091 : cmocka_unit_test(libspdm_test_requester_get_capabilities_err_case41),
2092 : };
2093 :
2094 1 : libspdm_test_context_t test_context = {
2095 : LIBSPDM_TEST_CONTEXT_VERSION,
2096 : true,
2097 : send_message,
2098 : receive_message,
2099 : };
2100 :
2101 1 : libspdm_setup_test_context(&test_context);
2102 :
2103 1 : return cmocka_run_group_tests(test_cases,
2104 : libspdm_unit_test_group_setup,
2105 : libspdm_unit_test_group_teardown);
2106 : }
|