Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2022 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link:
5 : * https://github.com/DMTF/libspdm/blob/main/LICENSE.md
6 : **/
7 : #include "spdm_unit_test.h"
8 : #include "internal/libspdm_responder_lib.h"
9 :
10 : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && \
11 : (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
12 :
13 : uint8_t m_local_digests_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
14 : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
15 :
16 : /**
17 : * Test 1: Response message received successfully
18 : * Expected Behavior: requester returns the status RETURN_SUCCESS and a DIGESTS message is received
19 : **/
20 1 : void test_spdm_responder_encap_get_digests_case1(void **state)
21 : {
22 : libspdm_return_t status;
23 : libspdm_test_context_t *spdm_test_context;
24 : libspdm_context_t *spdm_context;
25 : spdm_digest_response_t *spdm_response;
26 : uint8_t *digest;
27 : uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
28 : size_t spdm_response_size;
29 : bool need_continue;
30 :
31 1 : spdm_test_context = *state;
32 1 : spdm_context = spdm_test_context->spdm_context;
33 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
34 : SPDM_VERSION_NUMBER_SHIFT_BIT;
35 1 : spdm_context->connection_info.connection_state =
36 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
37 1 : spdm_context->connection_info.capability.flags |=
38 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
39 1 : spdm_context->connection_info.algorithm.base_hash_algo =
40 : m_libspdm_use_hash_algo;
41 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
42 : sizeof(m_libspdm_local_certificate_chain),
43 : (uint8_t)(0xFF));
44 1 : libspdm_reset_message_b(spdm_context);
45 :
46 : ((libspdm_context_t *)spdm_context)
47 1 : ->connection_info.algorithm.base_hash_algo =
48 : m_libspdm_use_hash_algo;
49 1 : spdm_response_size = sizeof(spdm_digest_response_t) +
50 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
51 1 : spdm_response = (void *)temp_buf;
52 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
53 1 : spdm_response->header.param1 = 0;
54 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
55 1 : spdm_response->header.param2 = 0;
56 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
57 : sizeof(m_libspdm_local_certificate_chain),
58 : (uint8_t)(0xFF));
59 :
60 1 : digest = (void *)(spdm_response + 1);
61 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
62 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
63 1 : spdm_response->header.param2 |= (0x01 << 0);
64 :
65 1 : status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
66 : spdm_response, &need_continue);
67 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
68 1 : }
69 :
70 : /**
71 : * Test 2: Error response message with error code busy
72 : * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
73 : **/
74 1 : void test_spdm_responder_encap_get_digests_case2(void **state)
75 : {
76 : libspdm_return_t status;
77 : libspdm_test_context_t *spdm_test_context;
78 : libspdm_context_t *spdm_context;
79 : spdm_error_response_t spdm_response;
80 : size_t spdm_response_size;
81 : bool need_continue;
82 :
83 1 : spdm_test_context = *state;
84 1 : spdm_context = spdm_test_context->spdm_context;
85 1 : spdm_test_context->case_id = 0x2;
86 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
87 : SPDM_VERSION_NUMBER_SHIFT_BIT;
88 1 : spdm_context->connection_info.connection_state =
89 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
90 1 : spdm_context->connection_info.capability.flags |=
91 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
92 1 : spdm_context->connection_info.algorithm.base_hash_algo =
93 : m_libspdm_use_hash_algo;
94 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
95 : sizeof(m_libspdm_local_certificate_chain),
96 : (uint8_t)(0xFF));
97 1 : libspdm_reset_message_b(spdm_context);
98 :
99 1 : spdm_response_size = sizeof(spdm_error_response_t);
100 1 : spdm_response.header.spdm_version = SPDM_MESSAGE_VERSION_10;
101 1 : spdm_response.header.request_response_code = SPDM_ERROR;
102 1 : spdm_response.header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
103 1 : spdm_response.header.param2 = 0;
104 :
105 1 : status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
106 : &spdm_response, &need_continue);
107 :
108 1 : assert_int_equal(status, LIBSPDM_STATUS_UNSUPPORTED_CAP);
109 1 : }
110 :
111 : /**
112 : * Test 3: Error response message with error code busy response seize incorrect
113 : * Expected Behavior: Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
114 : **/
115 1 : void test_spdm_responder_encap_get_digests_case3(void **state)
116 : {
117 : libspdm_return_t status;
118 : libspdm_test_context_t *spdm_test_context;
119 : libspdm_context_t *spdm_context;
120 : bool need_continue;
121 :
122 1 : spdm_test_context = *state;
123 1 : spdm_context = spdm_test_context->spdm_context;
124 1 : spdm_test_context->case_id = 0x3;
125 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
126 : SPDM_VERSION_NUMBER_SHIFT_BIT;
127 1 : spdm_context->connection_info.connection_state =
128 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
129 1 : spdm_context->connection_info.capability.flags |=
130 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
131 1 : spdm_context->connection_info.algorithm.base_hash_algo =
132 : m_libspdm_use_hash_algo;
133 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
134 : sizeof(m_libspdm_local_certificate_chain),
135 : (uint8_t)(0xFF));
136 1 : libspdm_reset_message_b(spdm_context);
137 :
138 : spdm_digest_response_t *spdm_response;
139 1 : uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE] = {0};
140 : size_t spdm_response_size;
141 :
142 1 : spdm_response_size = 0;
143 1 : spdm_response = (void *)temp_buf;
144 :
145 1 : status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
146 : spdm_response, &need_continue);
147 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
148 1 : }
149 :
150 : /**
151 : * Test 4: The code of the request_response_code summary in the response message is different
152 : * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
153 : **/
154 1 : void test_spdm_responder_encap_get_digests_case4(void **state)
155 : {
156 : libspdm_return_t status;
157 : libspdm_test_context_t *spdm_test_context;
158 : libspdm_context_t *spdm_context;
159 : bool need_continue;
160 :
161 1 : spdm_test_context = *state;
162 1 : spdm_context = spdm_test_context->spdm_context;
163 1 : spdm_test_context->case_id = 0x4;
164 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
165 : SPDM_VERSION_NUMBER_SHIFT_BIT;
166 1 : spdm_context->connection_info.connection_state =
167 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
168 1 : spdm_context->connection_info.capability.flags |=
169 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
170 1 : spdm_context->connection_info.algorithm.base_hash_algo =
171 : m_libspdm_use_hash_algo;
172 :
173 : spdm_digest_response_t *spdm_response;
174 : uint8_t *digest;
175 : uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
176 : size_t spdm_response_size;
177 :
178 1 : spdm_response_size = sizeof(spdm_digest_response_t) +
179 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
180 1 : spdm_response = (void *)temp_buf;
181 :
182 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
183 1 : spdm_response->header.request_response_code = SPDM_CERTIFICATE;
184 1 : spdm_response->header.param1 = 0;
185 1 : spdm_response->header.param2 = 0;
186 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
187 : sizeof(m_libspdm_local_certificate_chain),
188 : (uint8_t)(0xFF));
189 :
190 1 : digest = (void *)(spdm_response + 1);
191 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
192 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
193 1 : spdm_response->header.param2 |= (1 << 0);
194 :
195 1 : status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
196 : spdm_response, &need_continue);
197 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
198 1 : }
199 :
200 : /**
201 : * Test 5: flag cert_cap from CAPABILITIES is not set meaning the Requester does not support DIGESTS and
202 : * CERTIFICATE response messages
203 : * Expected Behavior: requester returns the status RETURN_DEVICE_ERROR, with no DIGESTS message received
204 : **/
205 1 : void test_spdm_responder_encap_get_digests_case5(void **state)
206 : {
207 : libspdm_return_t status;
208 : libspdm_test_context_t *spdm_test_context;
209 : libspdm_context_t *spdm_context;
210 : spdm_digest_response_t *spdm_response;
211 1 : uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE] = {0};
212 : size_t spdm_response_size;
213 : bool need_continue;
214 :
215 1 : spdm_test_context = *state;
216 1 : spdm_context = spdm_test_context->spdm_context;
217 1 : spdm_test_context->case_id = 0x5;
218 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
219 : SPDM_VERSION_NUMBER_SHIFT_BIT;
220 1 : spdm_context->connection_info.capability.flags |=
221 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
222 1 : spdm_context->connection_info.algorithm.base_hash_algo =
223 : m_libspdm_use_hash_algo;
224 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
225 : sizeof(m_libspdm_local_certificate_chain),
226 : (uint8_t)(0xFF));
227 1 : libspdm_reset_message_b(spdm_context);
228 :
229 1 : spdm_response_size = sizeof(spdm_digest_response_t);
230 1 : spdm_response = (void *)temp_buf;
231 :
232 1 : status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
233 : spdm_response, &need_continue);
234 :
235 1 : assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
236 1 : }
237 :
238 : /**
239 : * Test 6: a response message is successfully sent , Set multi_key_conn_req to check if it responds correctly
240 : * Expected Behavior: requester returns the status RETURN_SUCCESS
241 : **/
242 1 : void test_spdm_responder_encap_get_digests_case6(void **state)
243 : {
244 : libspdm_return_t status;
245 : libspdm_test_context_t *spdm_test_context;
246 : libspdm_context_t *spdm_context;
247 : spdm_digest_response_t *spdm_response;
248 : uint8_t *digest;
249 : size_t hash_size;
250 : uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
251 : size_t spdm_response_size;
252 : bool need_continue;
253 : uint32_t session_id;
254 : libspdm_session_info_t *session_info;
255 : spdm_key_pair_id_t *key_pair_id;
256 : spdm_certificate_info_t *cert_info;
257 : spdm_key_usage_bit_mask_t *key_usage_bit_mask;
258 :
259 1 : spdm_test_context = *state;
260 1 : spdm_context = spdm_test_context->spdm_context;
261 1 : spdm_test_context->case_id = 0x6;
262 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
263 : SPDM_VERSION_NUMBER_SHIFT_BIT;
264 1 : spdm_context->connection_info.connection_state =
265 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
266 1 : spdm_context->connection_info.capability.flags |=
267 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
268 1 : spdm_context->connection_info.algorithm.base_hash_algo =
269 : m_libspdm_use_hash_algo;
270 :
271 1 : libspdm_reset_message_b(spdm_context);
272 :
273 1 : spdm_response = (void *)temp_buf;
274 1 : libspdm_zero_mem(temp_buf, sizeof(temp_buf));
275 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
276 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
277 1 : spdm_response->header.param1 = (0x01 << 0);
278 1 : spdm_response->header.param2 = 0;
279 1 : spdm_response->header.param2 |= (0x01 << 0);
280 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
281 : sizeof(m_libspdm_local_certificate_chain),
282 : (uint8_t)(0xFF));
283 :
284 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
285 1 : digest = (void *)(spdm_response + 1);
286 1 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
287 : sizeof(m_libspdm_local_certificate_chain), &digest[0]);
288 1 : key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + hash_size);
289 1 : cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
290 : sizeof(spdm_key_pair_id_t));
291 1 : key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
292 : sizeof(spdm_certificate_info_t));
293 1 : *key_pair_id = 0;
294 1 : *cert_info = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
295 1 : *key_usage_bit_mask = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
296 : SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
297 : SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
298 : SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
299 :
300 1 : session_id = 0xFFFFFFFF;
301 1 : spdm_context->latest_session_id = session_id;
302 1 : spdm_context->last_spdm_request_session_id_valid = true;
303 1 : spdm_context->last_spdm_request_session_id = session_id;
304 1 : session_info = &spdm_context->session_info[0];
305 1 : libspdm_session_info_init(spdm_context, session_info, session_id, true);
306 1 : libspdm_secured_message_set_session_state(
307 : session_info->secured_message_context,
308 : LIBSPDM_SESSION_STATE_ESTABLISHED);
309 :
310 : /* Sub Case 1: Set multi_key_conn_req to true*/
311 1 : spdm_context->connection_info.multi_key_conn_req = true;
312 1 : libspdm_reset_message_encap_d(spdm_context, session_info);
313 :
314 1 : spdm_response_size = sizeof(spdm_digest_response_t) + sizeof(spdm_key_pair_id_t) +
315 : sizeof(spdm_certificate_info_t) +
316 : sizeof(spdm_key_usage_bit_mask_t) +
317 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
318 :
319 1 : status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
320 : spdm_response, &need_continue);
321 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
322 1 : assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size,
323 : spdm_response_size);
324 :
325 : /* Sub Case 2: Set multi_key_conn_req to false*/
326 1 : spdm_context->connection_info.multi_key_conn_req = false;
327 1 : libspdm_reset_message_encap_d(spdm_context, session_info);
328 :
329 1 : spdm_response_size = sizeof(spdm_digest_response_t) + sizeof(spdm_key_pair_id_t) +
330 : sizeof(spdm_certificate_info_t) +
331 : sizeof(spdm_key_usage_bit_mask_t) +
332 1 : libspdm_get_hash_size(m_libspdm_use_hash_algo);
333 1 : status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
334 : spdm_response, &need_continue);
335 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
336 1 : assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size, 0);
337 1 : }
338 :
339 : /**
340 : * Test 7: a response message is successfully sent ,
341 : * Check KeyPairID CertificateInfo and KeyUsageMask
342 : * Expected Behavior: requester returns the status RETURN_SUCCESS
343 : **/
344 1 : void test_spdm_responder_encap_get_digests_case7(void **state)
345 : {
346 : libspdm_return_t status;
347 : libspdm_test_context_t *spdm_test_context;
348 : libspdm_context_t *spdm_context;
349 : spdm_digest_response_t *spdm_response;
350 : uint8_t *digest;
351 : uint8_t temp_buf[LIBSPDM_MAX_SPDM_MSG_SIZE];
352 : size_t spdm_response_size;
353 : bool need_continue;
354 : uint32_t session_id;
355 : libspdm_session_info_t *session_info;
356 : spdm_key_pair_id_t *key_pair_id;
357 : spdm_certificate_info_t *cert_info;
358 : spdm_key_usage_bit_mask_t *key_usage_bit_mask;
359 : uint32_t hash_size;
360 : uint8_t slot_count;
361 : size_t additional_size;
362 :
363 1 : spdm_test_context = *state;
364 1 : spdm_context = spdm_test_context->spdm_context;
365 1 : spdm_test_context->case_id = 0x7;
366 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
367 : SPDM_VERSION_NUMBER_SHIFT_BIT;
368 1 : spdm_context->connection_info.connection_state =
369 : LIBSPDM_CONNECTION_STATE_NEGOTIATED;
370 1 : spdm_context->connection_info.capability.flags |=
371 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
372 1 : spdm_context->connection_info.algorithm.base_hash_algo =
373 : m_libspdm_use_hash_algo;
374 :
375 1 : libspdm_reset_message_b(spdm_context);
376 :
377 1 : spdm_response = (void *)temp_buf;
378 1 : libspdm_zero_mem(temp_buf, sizeof(temp_buf));
379 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
380 1 : spdm_response->header.request_response_code = SPDM_DIGESTS;
381 1 : spdm_response->header.param1 = 0;
382 1 : spdm_response->header.param2 = 0;
383 1 : libspdm_set_mem(m_libspdm_local_certificate_chain,
384 : sizeof(m_libspdm_local_certificate_chain),
385 : (uint8_t)(0xFF));
386 :
387 1 : slot_count = SPDM_MAX_SLOT_COUNT;
388 1 : additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
389 : sizeof(spdm_key_usage_bit_mask_t);
390 1 : hash_size = libspdm_get_hash_size(m_libspdm_use_hash_algo);
391 :
392 1 : digest = (void *)(spdm_response + 1);
393 1 : libspdm_zero_mem (digest, hash_size * slot_count);
394 1 : key_pair_id = (spdm_key_pair_id_t *)((uint8_t *)digest + (hash_size * slot_count));
395 1 : cert_info = (spdm_certificate_info_t *)((uint8_t *)key_pair_id +
396 1 : sizeof(spdm_key_pair_id_t) * slot_count);
397 1 : key_usage_bit_mask = (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info +
398 1 : sizeof(spdm_certificate_info_t) *
399 : slot_count);
400 :
401 9 : for (uint8_t index = 0; index < slot_count; index++)
402 : {
403 8 : libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
404 8 : sizeof(m_libspdm_local_certificate_chain), &digest[hash_size * index]);
405 :
406 8 : spdm_response->header.param1 |= (1 << index);
407 8 : spdm_response->header.param2 |= (1 << index);
408 : }
409 1 : key_pair_id[0] = 0x00;
410 1 : cert_info[0] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
411 1 : key_usage_bit_mask[0] = SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE;
412 :
413 1 : key_pair_id[1] = 0x01;
414 1 : cert_info[1] = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT;
415 1 : key_usage_bit_mask[1] = SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE;
416 :
417 1 : key_pair_id[2] = 0x02;
418 1 : cert_info[2] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
419 1 : key_usage_bit_mask[2] = SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
420 :
421 1 : key_pair_id[3] = 0x03;
422 1 : cert_info[3] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
423 1 : key_usage_bit_mask[3] = SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE;
424 :
425 1 : key_pair_id[4] = 0x04;
426 1 : cert_info[4] = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
427 1 : key_usage_bit_mask[4] = SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE;
428 :
429 1 : key_pair_id[5] = 0x05;
430 1 : cert_info[5] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
431 1 : key_usage_bit_mask[5] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
432 :
433 1 : key_pair_id[6] = 0x06;
434 1 : cert_info[6] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
435 1 : key_usage_bit_mask[6] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
436 :
437 1 : key_pair_id[7] = 0x07;
438 1 : cert_info[7] = SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT;
439 1 : key_usage_bit_mask[7] = SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE;
440 :
441 1 : session_id = 0xFFFFFFFF;
442 1 : spdm_context->latest_session_id = session_id;
443 1 : spdm_context->last_spdm_request_session_id_valid = true;
444 1 : spdm_context->last_spdm_request_session_id = session_id;
445 1 : session_info = &spdm_context->session_info[0];
446 1 : libspdm_session_info_init(spdm_context, session_info, session_id, true);
447 1 : libspdm_secured_message_set_session_state(
448 : session_info->secured_message_context,
449 : LIBSPDM_SESSION_STATE_ESTABLISHED);
450 :
451 1 : spdm_context->connection_info.multi_key_conn_req = true;
452 1 : libspdm_reset_message_encap_d(spdm_context, session_info);
453 :
454 1 : spdm_response_size = sizeof(spdm_digest_response_t) +
455 1 : (hash_size + additional_size) * slot_count;
456 :
457 1 : status = libspdm_process_encap_response_digest(spdm_context, spdm_response_size,
458 : spdm_response, &need_continue);
459 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
460 1 : assert_int_equal(session_info->session_transcript.message_encap_d.buffer_size,
461 : spdm_response_size);
462 :
463 9 : for (uint8_t index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
464 8 : assert_memory_equal((void *)&key_pair_id[index],
465 : (void *)&spdm_context->connection_info.peer_key_pair_id[index],
466 : sizeof(spdm_key_pair_id_t));
467 8 : assert_memory_equal((void *)&cert_info[index],
468 : (void *)&spdm_context->connection_info.peer_cert_info[index],
469 : sizeof(spdm_certificate_info_t));
470 8 : assert_memory_equal((void *)&key_usage_bit_mask[index],
471 : (void *)&spdm_context->connection_info.peer_key_usage_bit_mask[index],
472 : sizeof(spdm_key_usage_bit_mask_t));
473 : }
474 1 : }
475 :
476 1 : int spdm_responder_encap_get_digests_test_main(void)
477 : {
478 1 : const struct CMUnitTest spdm_responder_digests_tests[] = {
479 : /* Success Case*/
480 : cmocka_unit_test(test_spdm_responder_encap_get_digests_case1),
481 : /* Error response: SPDM_ERROR*/
482 : cmocka_unit_test(test_spdm_responder_encap_get_digests_case2),
483 : /* Error response: RETURN_DEVICE_ERROR*/
484 : cmocka_unit_test(test_spdm_responder_encap_get_digests_case3),
485 : /* request_response_code wrong in response*/
486 : cmocka_unit_test(test_spdm_responder_encap_get_digests_case4),
487 : /* capability flags check failed*/
488 : cmocka_unit_test(test_spdm_responder_encap_get_digests_case5),
489 : /* Set multi_key_conn_req to check if it responds correctly */
490 : cmocka_unit_test(test_spdm_responder_encap_get_digests_case6),
491 : /* Check KeyPairID CertificateInfo and KeyUsageMask*/
492 : cmocka_unit_test(test_spdm_responder_encap_get_digests_case7),
493 : };
494 :
495 1 : libspdm_test_context_t test_context = {
496 : LIBSPDM_TEST_CONTEXT_VERSION,
497 : false,
498 : };
499 :
500 1 : libspdm_setup_test_context(&test_context);
501 :
502 1 : return cmocka_run_group_tests(spdm_responder_digests_tests,
503 : libspdm_unit_test_group_setup,
504 : libspdm_unit_test_group_teardown);
505 : }
506 :
507 : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (...) */
|