Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2024-2026 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include "spdm_unit_test.h"
8 : #include "internal/libspdm_requester_lib.h"
9 : #include "internal/libspdm_secured_message_lib.h"
10 :
11 : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
12 :
13 : uint8_t m_response_total_key_pairs;
14 : uint8_t m_response_key_pair_id;
15 : uint16_t m_response_capabilities;
16 : uint16_t m_response_key_usage_capabilities;
17 : uint16_t m_response_current_key_usage;
18 : uint32_t m_response_asym_algo_capabilities;
19 : uint32_t m_response_current_asym_algo;
20 : uint8_t m_response_assoc_cert_slot_mask;
21 :
22 18 : static libspdm_return_t send_message(
23 : void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
24 : {
25 : libspdm_test_context_t *spdm_test_context;
26 :
27 18 : spdm_test_context = libspdm_get_test_context();
28 18 : switch (spdm_test_context->case_id) {
29 18 : case 0x1:
30 : case 0x2:
31 : case 0x3:
32 : case 0x4:
33 18 : return LIBSPDM_STATUS_SUCCESS;
34 0 : default:
35 0 : return LIBSPDM_STATUS_SEND_FAIL;
36 : }
37 : }
38 :
39 18 : static libspdm_return_t receive_message(
40 : void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
41 : {
42 : libspdm_test_context_t *spdm_test_context;
43 :
44 18 : spdm_test_context = libspdm_get_test_context();
45 18 : switch (spdm_test_context->case_id) {
46 1 : case 0x1: {
47 : spdm_key_pair_info_response_t *spdm_response;
48 : size_t spdm_response_size;
49 : size_t transport_header_size;
50 :
51 : uint8_t total_key_pairs;
52 : uint8_t key_pair_id;
53 : uint16_t public_key_info_len;
54 : uint16_t capabilities;
55 : uint16_t key_usage_capabilities;
56 : uint16_t current_key_usage;
57 : uint32_t asym_algo_capabilities;
58 : uint32_t current_asym_algo;
59 : uint8_t assoc_cert_slot_mask;
60 :
61 1 : uint8_t public_key_info_rsa2048[] = {0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
62 : 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00};
63 :
64 1 : key_pair_id = 1;
65 1 : total_key_pairs = 1;
66 1 : public_key_info_len = (uint16_t)sizeof(public_key_info_rsa2048);
67 :
68 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
69 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
70 1 : spdm_response_size = sizeof(spdm_key_pair_info_response_t) + public_key_info_len;
71 :
72 1 : capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
73 1 : key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
74 1 : current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
75 1 : asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
76 1 : current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
77 :
78 : /*association with slot 1*/
79 1 : assoc_cert_slot_mask = 0x02;
80 :
81 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
82 1 : spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
83 1 : spdm_response->header.param1 = 0;
84 1 : spdm_response->header.param2 = 0;
85 1 : spdm_response->total_key_pairs = total_key_pairs;
86 1 : spdm_response->key_pair_id = key_pair_id;
87 1 : spdm_response->capabilities = capabilities;
88 1 : spdm_response->key_usage_capabilities = key_usage_capabilities;
89 1 : spdm_response->current_key_usage = current_key_usage;
90 1 : spdm_response->asym_algo_capabilities = asym_algo_capabilities;
91 1 : spdm_response->current_asym_algo = current_asym_algo;
92 1 : spdm_response->public_key_info_len = public_key_info_len;
93 1 : spdm_response->assoc_cert_slot_mask = assoc_cert_slot_mask;
94 :
95 1 : libspdm_copy_mem((void*)(spdm_response + 1), public_key_info_len,
96 : public_key_info_rsa2048, public_key_info_len);
97 :
98 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
99 : false, spdm_response_size,
100 : spdm_response, response_size,
101 : response);
102 : }
103 1 : return LIBSPDM_STATUS_SUCCESS;
104 :
105 15 : case 0x2: {
106 : spdm_key_pair_info_response_t *spdm_response;
107 : size_t spdm_response_size;
108 : size_t transport_header_size;
109 :
110 : uint16_t public_key_info_len;
111 15 : uint8_t public_key_info_rsa2048[] = {0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
112 : 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00};
113 :
114 15 : public_key_info_len = (uint16_t)sizeof(public_key_info_rsa2048);
115 :
116 15 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
117 15 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
118 15 : spdm_response_size = sizeof(spdm_key_pair_info_response_t) + public_key_info_len;
119 :
120 15 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
121 15 : spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
122 15 : spdm_response->header.param1 = 0;
123 15 : spdm_response->header.param2 = 0;
124 15 : spdm_response->total_key_pairs = m_response_total_key_pairs;
125 15 : spdm_response->key_pair_id = m_response_key_pair_id;
126 15 : spdm_response->capabilities = m_response_capabilities;
127 15 : spdm_response->key_usage_capabilities = m_response_key_usage_capabilities;
128 15 : spdm_response->current_key_usage = m_response_current_key_usage;
129 15 : spdm_response->asym_algo_capabilities = m_response_asym_algo_capabilities;
130 15 : spdm_response->current_asym_algo = m_response_current_asym_algo;
131 15 : spdm_response->public_key_info_len = public_key_info_len;
132 15 : spdm_response->assoc_cert_slot_mask = m_response_assoc_cert_slot_mask;
133 :
134 :
135 15 : libspdm_copy_mem((void*)(spdm_response + 1), public_key_info_len,
136 : public_key_info_rsa2048, public_key_info_len);
137 15 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
138 : false, spdm_response_size,
139 : spdm_response, response_size,
140 : response);
141 : }
142 15 : return LIBSPDM_STATUS_SUCCESS;
143 :
144 1 : case 0x3: {
145 : spdm_key_pair_info_response_t *spdm_response;
146 : size_t spdm_response_size;
147 : size_t transport_header_size;
148 :
149 : uint8_t total_key_pairs;
150 : uint8_t key_pair_id;
151 : uint16_t public_key_info_len;
152 : uint16_t capabilities;
153 : uint16_t key_usage_capabilities;
154 : uint16_t current_key_usage;
155 : uint32_t asym_algo_capabilities;
156 : uint32_t current_asym_algo;
157 : uint8_t assoc_cert_slot_mask;
158 : uint8_t *ptr;
159 :
160 1 : uint8_t public_key_info_rsa2048[] = {0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
161 : 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00};
162 :
163 1 : key_pair_id = 1;
164 1 : total_key_pairs = 1;
165 1 : public_key_info_len = (uint16_t)sizeof(public_key_info_rsa2048);
166 :
167 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
168 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
169 1 : spdm_response_size = sizeof(spdm_key_pair_info_response_t) + public_key_info_len +
170 1 : sizeof(uint8_t) + 5 + sizeof(uint8_t) + 4;
171 :
172 1 : capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
173 1 : key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
174 1 : current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
175 1 : asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
176 1 : current_asym_algo = 0;
177 :
178 : /* association with slot 1 */
179 1 : assoc_cert_slot_mask = 0x02;
180 :
181 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_14;
182 1 : spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
183 1 : spdm_response->header.param1 = 0;
184 1 : spdm_response->header.param2 = 0;
185 1 : spdm_response->total_key_pairs = total_key_pairs;
186 1 : spdm_response->key_pair_id = key_pair_id;
187 1 : spdm_response->capabilities = capabilities;
188 1 : spdm_response->key_usage_capabilities = key_usage_capabilities;
189 1 : spdm_response->current_key_usage = current_key_usage;
190 1 : spdm_response->asym_algo_capabilities = asym_algo_capabilities;
191 1 : spdm_response->current_asym_algo = current_asym_algo;
192 1 : spdm_response->public_key_info_len = public_key_info_len;
193 1 : spdm_response->assoc_cert_slot_mask = assoc_cert_slot_mask;
194 :
195 1 : libspdm_copy_mem((void*)(spdm_response + 1), public_key_info_len,
196 : public_key_info_rsa2048, public_key_info_len);
197 :
198 1 : ptr = (uint8_t *)(spdm_response + 1) + public_key_info_len;
199 1 : *ptr = 5;
200 1 : ptr += sizeof(uint8_t);
201 :
202 : /* First 4 bytes carry ML_DSA_44 capability, 5th byte is non-zero to expose cursor bugs. */
203 1 : ptr[0] = 0x01;
204 1 : ptr[1] = 0x00;
205 1 : ptr[2] = 0x00;
206 1 : ptr[3] = 0x00;
207 1 : ptr[4] = 0x04;
208 1 : ptr += 5;
209 :
210 1 : *ptr = 4;
211 1 : ptr += sizeof(uint8_t);
212 :
213 1 : ptr[0] = 0x01;
214 1 : ptr[1] = 0x00;
215 1 : ptr[2] = 0x00;
216 1 : ptr[3] = 0x00;
217 :
218 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
219 : false, spdm_response_size,
220 : spdm_response, response_size,
221 : response);
222 : }
223 1 : return LIBSPDM_STATUS_SUCCESS;
224 :
225 1 : case 0x4: {
226 : spdm_key_pair_info_response_t *spdm_response;
227 : size_t spdm_response_size;
228 : size_t transport_header_size;
229 :
230 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
231 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
232 :
233 : /* Truncated response carrying only the SPDM header. total_key_pairs and
234 : * key_pair_id are absent. */
235 1 : spdm_response_size = sizeof(spdm_message_header_t);
236 :
237 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
238 1 : spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
239 1 : spdm_response->header.param1 = 0;
240 1 : spdm_response->header.param2 = 0;
241 :
242 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
243 : false, spdm_response_size,
244 : spdm_response, response_size,
245 : response);
246 : }
247 1 : return LIBSPDM_STATUS_SUCCESS;
248 :
249 0 : default:
250 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
251 : }
252 : }
253 :
254 : /**
255 : * Test 1: Successful response to get key pair info
256 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code
257 : **/
258 1 : static void req_get_key_pair_info_case1(void **state)
259 : {
260 : libspdm_return_t status;
261 : libspdm_test_context_t *spdm_test_context;
262 : libspdm_context_t *spdm_context;
263 :
264 : uint8_t key_pair_id;
265 : uint8_t associated_slot_id;
266 : uint8_t total_key_pairs;
267 : uint16_t capabilities;
268 : uint16_t key_usage_capabilities;
269 : uint16_t current_key_usage;
270 : uint32_t asym_algo_capabilities;
271 : uint32_t current_asym_algo;
272 : uint32_t pqc_asym_algo_capabilities;
273 : uint32_t current_pqc_asym_algo;
274 : uint16_t public_key_info_len;
275 : uint8_t assoc_cert_slot_mask;
276 : uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
277 :
278 1 : key_pair_id = 1;
279 1 : associated_slot_id = 1;
280 1 : spdm_test_context = *state;
281 1 : spdm_context = spdm_test_context->spdm_context;
282 1 : spdm_test_context->case_id = 0x1;
283 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
284 : SPDM_VERSION_NUMBER_SHIFT_BIT;
285 :
286 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
287 1 : spdm_context->connection_info.capability.flags |=
288 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP |
289 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
290 :
291 1 : spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
292 1 : public_key_info_len = SPDM_MAX_PUBLIC_KEY_INFO_LEN;
293 :
294 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
295 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
296 : &asym_algo_capabilities, ¤t_asym_algo,
297 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
298 : &assoc_cert_slot_mask, &public_key_info_len,
299 : public_key_info);
300 :
301 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
302 1 : assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
303 1 : assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
304 1 : assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
305 1 : assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
306 1 : assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
307 1 : }
308 :
309 : /**
310 : * Test 2: The collection of multiple sub-cases for invalid combination.
311 : * Expected Behavior: get a LIBSPDM_STATUS_INVALID_MSG_FIELD return code
312 : **/
313 1 : void req_get_key_pair_info_case2(void **state)
314 : {
315 : libspdm_return_t status;
316 : libspdm_test_context_t *spdm_test_context;
317 : libspdm_context_t *spdm_context;
318 :
319 : uint8_t key_pair_id;
320 : uint8_t associated_slot_id;
321 : uint8_t total_key_pairs;
322 : uint16_t capabilities;
323 : uint16_t key_usage_capabilities;
324 : uint16_t current_key_usage;
325 : uint32_t asym_algo_capabilities;
326 : uint32_t current_asym_algo;
327 : uint32_t pqc_asym_algo_capabilities;
328 : uint32_t current_pqc_asym_algo;
329 : uint16_t public_key_info_len;
330 : uint8_t assoc_cert_slot_mask;
331 : uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
332 :
333 1 : spdm_test_context = *state;
334 1 : spdm_context = spdm_test_context->spdm_context;
335 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
336 : SPDM_VERSION_NUMBER_SHIFT_BIT;
337 :
338 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
339 1 : spdm_context->connection_info.capability.flags |=
340 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
341 :
342 1 : spdm_test_context->case_id = 0x2;
343 1 : public_key_info_len = SPDM_MAX_PUBLIC_KEY_INFO_LEN;
344 :
345 : /* Sub Case 1: key_pair_id > total_key_pairs*/
346 1 : key_pair_id = 2;
347 1 : associated_slot_id = 1;
348 1 : spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
349 :
350 1 : m_response_total_key_pairs = 1;
351 1 : m_response_key_pair_id = 2;
352 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
353 1 : m_response_key_usage_capabilities =SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
354 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
355 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
356 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
357 : /* association with slot 1*/
358 1 : m_response_assoc_cert_slot_mask = 0x2;
359 :
360 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
361 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
362 : &asym_algo_capabilities, ¤t_asym_algo,
363 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
364 : &assoc_cert_slot_mask, &public_key_info_len,
365 : public_key_info);
366 :
367 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
368 :
369 : /* Sub Case 2: responder and requester, the KeyPairID are not consistent.*/
370 1 : key_pair_id = 0xA0;
371 1 : associated_slot_id = 1;
372 1 : spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
373 :
374 1 : m_response_total_key_pairs = 1;
375 1 : m_response_key_pair_id = 1;
376 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
377 1 : m_response_key_usage_capabilities =SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
378 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
379 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
380 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
381 : /* association with slot 1*/
382 1 : m_response_assoc_cert_slot_mask = 0x2;
383 :
384 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
385 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
386 : &asym_algo_capabilities, ¤t_asym_algo,
387 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
388 : &assoc_cert_slot_mask, &public_key_info_len,
389 : public_key_info);
390 :
391 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
392 :
393 : /* Sub Case 3: not set capabilities.*/
394 1 : key_pair_id = 1;
395 1 : associated_slot_id = 1;
396 1 : spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
397 :
398 1 : m_response_total_key_pairs = 1;
399 1 : m_response_key_pair_id = 1;
400 1 : m_response_capabilities = 0;
401 1 : m_response_key_usage_capabilities =SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
402 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
403 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
404 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
405 : /* association with slot 1*/
406 1 : m_response_assoc_cert_slot_mask = 0x2;
407 :
408 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
409 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
410 : &asym_algo_capabilities, ¤t_asym_algo,
411 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
412 : &assoc_cert_slot_mask, &public_key_info_len,
413 : public_key_info);
414 :
415 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
416 1 : assert_int_equal(capabilities, 0);
417 1 : assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
418 1 : assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
419 1 : assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
420 1 : assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
421 :
422 : /* Sub Case 4: This bit shall not be set if CertAssocCap is not set.
423 : * Set the ShareableCap bit and not set the CertAssocCap bit.*/
424 1 : key_pair_id = 1;
425 1 : associated_slot_id = 1;
426 1 : spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
427 :
428 1 : m_response_total_key_pairs = 1;
429 1 : m_response_key_pair_id = 1;
430 :
431 1 : m_response_capabilities = 0;
432 1 : m_response_capabilities |= SPDM_KEY_PAIR_CAP_SHAREABLE_CAP;
433 1 : m_response_capabilities &= ~SPDM_KEY_PAIR_CAP_CERT_ASSOC_CAP;
434 :
435 1 : m_response_key_usage_capabilities =SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
436 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
437 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
438 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
439 : /* association with slot 1*/
440 1 : m_response_assoc_cert_slot_mask = 0x2;
441 :
442 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
443 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
444 : &asym_algo_capabilities, ¤t_asym_algo,
445 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
446 : &assoc_cert_slot_mask, &public_key_info_len,
447 : public_key_info);
448 :
449 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
450 :
451 : /* Sub Case 5: KeyUsageCapabilities at least one bit shall be set, not set KeyUsageCapabilities.*/
452 1 : m_response_total_key_pairs = 1;
453 1 : m_response_key_pair_id = 1;
454 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
455 1 : m_response_key_usage_capabilities =0;
456 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
457 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
458 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
459 : /* association with slot 1*/
460 1 : m_response_assoc_cert_slot_mask = 0x2;
461 :
462 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
463 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
464 : &asym_algo_capabilities, ¤t_asym_algo,
465 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
466 : &assoc_cert_slot_mask, &public_key_info_len,
467 : public_key_info);
468 :
469 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
470 :
471 : /* Sub Case 6: KeyUsageCapabilities Set multiple bits.*/
472 1 : m_response_total_key_pairs = 1;
473 1 : m_response_key_pair_id = 1;
474 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
475 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
476 : SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
477 : SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
478 : SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE |
479 : SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE |
480 : SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
481 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
482 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
483 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
484 : /* association with slot 1*/
485 1 : m_response_assoc_cert_slot_mask = 0x2;
486 :
487 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
488 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
489 : &asym_algo_capabilities, ¤t_asym_algo,
490 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
491 : &assoc_cert_slot_mask, &public_key_info_len,
492 : public_key_info);
493 :
494 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
495 1 : assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
496 1 : assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK);
497 1 : assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
498 1 : assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
499 1 : assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
500 :
501 : /* Sub Case 7: not set CurrentKeyUsage*/
502 1 : m_response_total_key_pairs = 1;
503 1 : m_response_key_pair_id = 1;
504 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
505 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
506 1 : m_response_current_key_usage = 0;
507 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
508 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
509 : /* association with slot 1*/
510 1 : m_response_assoc_cert_slot_mask = 0x2;
511 :
512 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
513 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
514 : &asym_algo_capabilities, ¤t_asym_algo,
515 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
516 : &assoc_cert_slot_mask, &public_key_info_len,
517 : public_key_info);
518 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
519 1 : assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
520 1 : assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
521 1 : assert_int_equal(current_key_usage, 0);
522 1 : assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
523 1 : assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
524 :
525 : /* Sub Case 8: CurrentKeyUsage Set multiple bits.*/
526 1 : m_response_total_key_pairs = 1;
527 1 : m_response_key_pair_id = 1;
528 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
529 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
530 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
531 : SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
532 : SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
533 : SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE |
534 : SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE |
535 : SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
536 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
537 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
538 : /* association with slot 1*/
539 1 : m_response_assoc_cert_slot_mask = 0x2;
540 :
541 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
542 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
543 : &asym_algo_capabilities, ¤t_asym_algo,
544 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
545 : &assoc_cert_slot_mask, &public_key_info_len,
546 : public_key_info);
547 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
548 :
549 : /* Sub Case 9: CurrentKeyUsage and KeyUsageCapabilities, Set multiple bits.*/
550 1 : m_response_total_key_pairs = 1;
551 1 : m_response_key_pair_id = 1;
552 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
553 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
554 : SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
555 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
556 : SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
557 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
558 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
559 : /* association with slot 1*/
560 1 : m_response_assoc_cert_slot_mask = 0x2;
561 :
562 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
563 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
564 : &asym_algo_capabilities, ¤t_asym_algo,
565 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
566 : &assoc_cert_slot_mask, &public_key_info_len,
567 : public_key_info);
568 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
569 1 : assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
570 1 : assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
571 : SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE);
572 1 : assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
573 : SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE);
574 1 : assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
575 1 : assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
576 :
577 : /* Sub Case 10: CurrentKeyUsage and KeyUsageCapabilities are not consistent.*/
578 1 : m_response_total_key_pairs = 1;
579 1 : m_response_key_pair_id = 1;
580 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
581 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
582 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
583 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
584 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
585 : /* association with slot 1*/
586 1 : m_response_assoc_cert_slot_mask = 0x2;
587 :
588 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
589 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
590 : &asym_algo_capabilities, ¤t_asym_algo,
591 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
592 : &assoc_cert_slot_mask, &public_key_info_len,
593 : public_key_info);
594 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
595 :
596 : /* Sub Case 11: AsymAlgoCapabilities, at least one bit shall be set.not set AsymAlgoCapabilities*/
597 1 : m_response_total_key_pairs = 1;
598 1 : m_response_key_pair_id = 1;
599 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
600 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
601 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
602 1 : m_response_asym_algo_capabilities = 0;
603 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
604 : /* association with slot 1*/
605 1 : m_response_assoc_cert_slot_mask = 0x2;
606 :
607 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
608 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
609 : &asym_algo_capabilities, ¤t_asym_algo,
610 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
611 : &assoc_cert_slot_mask, &public_key_info_len,
612 : public_key_info);
613 :
614 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
615 :
616 : /* Sub Case 12: AsymAlgoCapabilities Set multiple bits.*/
617 1 : m_response_total_key_pairs = 1;
618 1 : m_response_key_pair_id = 1;
619 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
620 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
621 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
622 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 |
623 : SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448;
624 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
625 : /* association with slot 1*/
626 1 : m_response_assoc_cert_slot_mask = 0x2;
627 :
628 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
629 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
630 : &asym_algo_capabilities, ¤t_asym_algo,
631 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
632 : &assoc_cert_slot_mask, &public_key_info_len,
633 : public_key_info);
634 :
635 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
636 1 : assert_int_equal(capabilities, SPDM_KEY_PAIR_CAP_GEN_KEY_CAP);
637 1 : assert_int_equal(key_usage_capabilities, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
638 1 : assert_int_equal(current_key_usage, SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE);
639 1 : assert_int_equal(asym_algo_capabilities, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 |
640 : SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448);
641 1 : assert_int_equal(current_asym_algo, SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048);
642 :
643 : /* Sub Case 13: CurrentAsymAlgo Set bits more than one bit.*/
644 1 : m_response_total_key_pairs = 1;
645 1 : m_response_key_pair_id = 1;
646 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
647 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
648 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
649 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
650 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 |
651 : SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072;
652 : /* association with slot 1*/
653 1 : m_response_assoc_cert_slot_mask = 0x2;
654 :
655 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
656 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
657 : &asym_algo_capabilities, ¤t_asym_algo,
658 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
659 : &assoc_cert_slot_mask, &public_key_info_len,
660 : public_key_info);
661 :
662 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
663 :
664 : /* Sub Case 14: AsymAlgoCapabilities and AsymAlgoCapabilities are not consistent.*/
665 1 : m_response_total_key_pairs = 1;
666 1 : m_response_key_pair_id = 1;
667 1 : m_response_capabilities = SPDM_KEY_PAIR_CAP_GEN_KEY_CAP;
668 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
669 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
670 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072;
671 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
672 : /* association with slot 1*/
673 1 : m_response_assoc_cert_slot_mask = 0x2;
674 :
675 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
676 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
677 : &asym_algo_capabilities, ¤t_asym_algo,
678 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
679 : &assoc_cert_slot_mask, &public_key_info_len,
680 : public_key_info);
681 :
682 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
683 :
684 : /* Sub Case 15: AssocCertSlotMask set more than one bit, but ShareableCap is not set.*/
685 1 : m_response_total_key_pairs = 1;
686 1 : m_response_key_pair_id = 1;
687 1 : m_response_capabilities = 0;
688 1 : m_response_key_usage_capabilities = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
689 1 : m_response_current_key_usage = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
690 1 : m_response_asym_algo_capabilities = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
691 1 : m_response_current_asym_algo = SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048;
692 : /* association with slot 1*/
693 1 : m_response_assoc_cert_slot_mask = 0xFF;
694 :
695 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
696 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
697 : &asym_algo_capabilities, ¤t_asym_algo,
698 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
699 : &assoc_cert_slot_mask, &public_key_info_len,
700 : public_key_info);
701 :
702 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
703 1 : }
704 :
705 : /**
706 : * Test 3: SPDM 1.4 KEY_PAIR_INFO parser must advance using raw PQC lengths.
707 : * Expected Behavior: get a LIBSPDM_STATUS_SUCCESS return code
708 : **/
709 1 : static void req_get_key_pair_info_case3(void **state)
710 : {
711 : libspdm_return_t status;
712 : libspdm_test_context_t *spdm_test_context;
713 : libspdm_context_t *spdm_context;
714 :
715 : uint8_t key_pair_id;
716 : uint8_t associated_slot_id;
717 : uint8_t total_key_pairs;
718 : uint16_t capabilities;
719 : uint16_t key_usage_capabilities;
720 : uint16_t current_key_usage;
721 : uint32_t asym_algo_capabilities;
722 : uint32_t current_asym_algo;
723 : uint32_t pqc_asym_algo_capabilities;
724 : uint32_t current_pqc_asym_algo;
725 : uint16_t public_key_info_len;
726 : uint8_t assoc_cert_slot_mask;
727 : uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
728 :
729 1 : key_pair_id = 1;
730 1 : associated_slot_id = 1;
731 1 : spdm_test_context = *state;
732 1 : spdm_context = spdm_test_context->spdm_context;
733 1 : spdm_test_context->case_id = 0x3;
734 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_14 <<
735 : SPDM_VERSION_NUMBER_SHIFT_BIT;
736 :
737 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
738 1 : spdm_context->connection_info.capability.flags |=
739 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP |
740 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
741 :
742 1 : spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
743 1 : public_key_info_len = SPDM_MAX_PUBLIC_KEY_INFO_LEN;
744 :
745 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
746 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
747 : &asym_algo_capabilities, ¤t_asym_algo,
748 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
749 : &assoc_cert_slot_mask, &public_key_info_len,
750 : public_key_info);
751 :
752 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
753 1 : assert_int_equal(pqc_asym_algo_capabilities, SPDM_KEY_PAIR_PQC_ASYM_ALGO_CAP_ML_DSA_44);
754 1 : assert_int_equal(current_pqc_asym_algo, SPDM_KEY_PAIR_PQC_ASYM_ALGO_CAP_ML_DSA_44);
755 1 : }
756 :
757 : /**
758 : * Test 4: Response truncated to the SPDM header, so total_key_pairs and key_pair_id
759 : * are not present.
760 : * Expected Behavior: rejected with LIBSPDM_STATUS_INVALID_MSG_SIZE, without reading
761 : * the absent fields.
762 : **/
763 1 : static void req_get_key_pair_info_case4(void **state)
764 : {
765 : libspdm_return_t status;
766 : libspdm_test_context_t *spdm_test_context;
767 : libspdm_context_t *spdm_context;
768 :
769 : uint8_t key_pair_id;
770 : uint8_t associated_slot_id;
771 : uint8_t total_key_pairs;
772 : uint16_t capabilities;
773 : uint16_t key_usage_capabilities;
774 : uint16_t current_key_usage;
775 : uint32_t asym_algo_capabilities;
776 : uint32_t current_asym_algo;
777 : uint32_t pqc_asym_algo_capabilities;
778 : uint32_t current_pqc_asym_algo;
779 : uint16_t public_key_info_len;
780 : uint8_t assoc_cert_slot_mask;
781 : uint8_t public_key_info[SPDM_MAX_PUBLIC_KEY_INFO_LEN];
782 :
783 1 : key_pair_id = 1;
784 1 : associated_slot_id = 1;
785 1 : spdm_test_context = *state;
786 1 : spdm_context = spdm_test_context->spdm_context;
787 1 : spdm_test_context->case_id = 0x4;
788 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
789 : SPDM_VERSION_NUMBER_SHIFT_BIT;
790 :
791 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
792 1 : spdm_context->connection_info.capability.flags |=
793 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP |
794 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP;
795 :
796 1 : spdm_context->connection_info.peer_key_pair_id[associated_slot_id] = key_pair_id;
797 1 : public_key_info_len = SPDM_MAX_PUBLIC_KEY_INFO_LEN;
798 :
799 1 : status = libspdm_get_key_pair_info(spdm_context, NULL, key_pair_id, &total_key_pairs,
800 : &capabilities, &key_usage_capabilities, ¤t_key_usage,
801 : &asym_algo_capabilities, ¤t_asym_algo,
802 : &pqc_asym_algo_capabilities, ¤t_pqc_asym_algo,
803 : &assoc_cert_slot_mask, &public_key_info_len,
804 : public_key_info);
805 :
806 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
807 1 : }
808 :
809 1 : int libspdm_req_get_key_pair_info_test(void)
810 : {
811 1 : const struct CMUnitTest test_cases[] = {
812 : /* Successful response to get key pair info, key_pair_id is 1*/
813 : cmocka_unit_test(req_get_key_pair_info_case1),
814 : /* The collection of multiple sub-cases for invalid combination.*/
815 : cmocka_unit_test(req_get_key_pair_info_case2),
816 : /* SPDM 1.4 oversized PQC length uses raw_len for cursor advancement */
817 : cmocka_unit_test(req_get_key_pair_info_case3),
818 : /* Header-only response is rejected before reading the body fields */
819 : cmocka_unit_test(req_get_key_pair_info_case4),
820 : };
821 :
822 1 : libspdm_test_context_t test_context = {
823 : LIBSPDM_TEST_CONTEXT_VERSION,
824 : true,
825 : send_message,
826 : receive_message,
827 : };
828 :
829 1 : libspdm_setup_test_context(&test_context);
830 :
831 1 : return cmocka_run_group_tests(test_cases,
832 : libspdm_unit_test_group_setup,
833 : libspdm_unit_test_group_teardown);
834 : }
835 :
836 : #endif /*LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
|