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_responder_lib.h"
9 :
10 : int libspdm_rsp_version_test(void);
11 : int libspdm_rsp_capabilities_test(void);
12 : int libspdm_rsp_algorithms_test(void);
13 :
14 : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
15 : int libspdm_rsp_digests_test(void);
16 : int libspdm_rsp_certificate_test(void);
17 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
18 :
19 : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
20 : int libspdm_rsp_challenge_auth_test(void);
21 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
22 :
23 : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
24 : int libspdm_rsp_measurements_test(void);
25 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
26 :
27 : #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
28 : int libspdm_rsp_endpoint_info_test(void);
29 : int libspdm_rsp_endpoint_info_error_test(void);
30 : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP*/
31 :
32 : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
33 : int libspdm_rsp_measurement_extension_log_test(void);
34 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP*/
35 :
36 : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
37 : int libspdm_rsp_key_pair_info_test(void);
38 : #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
39 :
40 : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
41 : int libspdm_rsp_set_key_pair_info_ack_test(void);
42 : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
43 :
44 : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
45 : #if (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP || LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP || \
46 : LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP || LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP || \
47 : LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
48 : int libspdm_rsp_respond_if_ready_test (void);
49 : #endif /* LIBSPDM_ENABLE_CAPABILITY_*_CAP */
50 : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
51 :
52 : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
53 : int libspdm_rsp_key_exchange_rsp_test(void);
54 : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
55 :
56 : int libspdm_rsp_finish_test(void);
57 :
58 : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
59 : int libspdm_rsp_psk_exchange_rsp_test(void);
60 : int libspdm_rsp_psk_finish_rsp_test(void);
61 : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
62 :
63 : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
64 : int libspdm_rsp_heartbeat_ack_test(void);
65 : int libspdm_rsp_key_update_ack_test(void);
66 : int libspdm_rsp_end_session_ack_test(void);
67 : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
68 :
69 : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
70 : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
71 : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
72 : int spdm_rsp_encap_get_digests_test(void);
73 : int spdm_rsp_encap_get_certificate_test(void);
74 : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
75 : #if LIBSPDM_SEND_CHALLENGE_SUPPORT
76 : int libspdm_rsp_encap_challenge_test(void);
77 : #endif /* LIBSPDM_SEND_CHALLENGE_SUPPORT */
78 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
79 : int libspdm_rsp_encapsulated_response_test(void);
80 : int libspdm_rsp_encap_key_update_test(void);
81 : #if LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT
82 : int libspdm_rsp_encap_get_endpoint_info_test(void);
83 : int libspdm_rsp_encap_get_endpoint_info_error_test(void);
84 : #endif /* LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT */
85 : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
86 : int libspdm_rsp_encap_send_event_test(void);
87 : int libspdm_rsp_encap_send_event_error_test(void);
88 : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
89 : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP*/
90 :
91 : int libspdm_rsp_set_certificate_rsp_test(void);
92 : int libspdm_rsp_csr_test(void);
93 :
94 : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
95 : int libspdm_rsp_chunk_response_test(void);
96 : int libspdm_rsp_receive_send_test(void);
97 : int libspdm_rsp_chunk_send_ack_test(void);
98 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
99 :
100 : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
101 : int libspdm_rsp_supported_event_types_test(void);
102 : int libspdm_rsp_supported_event_types_error_test(void);
103 : int libspdm_rsp_subscribe_event_types_ack_test(void);
104 : int libspdm_rsp_subscribe_event_types_ack_error_test(void);
105 : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
106 :
107 : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
108 : int libspdm_rsp_event_ack_test(void);
109 : int libspdm_rsp_event_ack_error_test(void);
110 : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
111 :
112 : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
113 : int libspdm_rsp_vendor_defined_response_test(void);
114 : int libspdm_rsp_vendor_defined_response_error_test(void);
115 : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
116 :
117 1 : int main(void)
118 : {
119 1 : int return_value = 0;
120 :
121 1 : if (libspdm_rsp_version_test() != 0) {
122 0 : return_value = 1;
123 : }
124 :
125 1 : if (libspdm_rsp_capabilities_test() != 0) {
126 0 : return_value = 1;
127 : }
128 :
129 1 : if (libspdm_rsp_algorithms_test() != 0) {
130 0 : return_value = 1;
131 : }
132 :
133 : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
134 1 : if (libspdm_rsp_digests_test() != 0) {
135 0 : return_value = 1;
136 : }
137 1 : if (libspdm_rsp_certificate_test() != 0) {
138 0 : return_value = 1;
139 : }
140 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP*/
141 :
142 : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
143 1 : if (libspdm_rsp_challenge_auth_test() != 0) {
144 0 : return_value = 1;
145 : }
146 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
147 :
148 : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
149 1 : if (libspdm_rsp_measurements_test() != 0) {
150 0 : return_value = 1;
151 : }
152 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
153 :
154 : #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
155 1 : if (libspdm_rsp_endpoint_info_test() != 0) {
156 0 : return_value = 1;
157 : }
158 1 : if (libspdm_rsp_endpoint_info_error_test() != 0) {
159 0 : return_value = 1;
160 : }
161 : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP*/
162 :
163 : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
164 1 : if (libspdm_rsp_measurement_extension_log_test() != 0) {
165 0 : return_value = 1;
166 : }
167 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP*/
168 :
169 : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
170 1 : if (libspdm_rsp_key_pair_info_test() != 0) {
171 0 : return_value = 1;
172 : }
173 : #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP*/
174 :
175 : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
176 1 : if (libspdm_rsp_set_key_pair_info_ack_test() != 0) {
177 0 : return_value = 1;
178 : }
179 : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP*/
180 :
181 : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
182 : #if (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP || LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP || \
183 : LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP || LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP || \
184 : LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
185 1 : if (libspdm_rsp_respond_if_ready_test() != 0) {
186 0 : return_value = 1;
187 : }
188 : #endif /* LIBSPDM_ENABLE_CAPABILITY_*_CAP */
189 : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
190 :
191 : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
192 1 : if (libspdm_rsp_key_exchange_rsp_test() != 0) {
193 0 : return_value = 1;
194 : }
195 : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
196 :
197 : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
198 1 : if (libspdm_rsp_finish_test() != 0) {
199 0 : return_value = 1;
200 : }
201 : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
202 :
203 : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
204 1 : if (libspdm_rsp_psk_exchange_rsp_test() != 0) {
205 0 : return_value = 1;
206 : }
207 : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
208 :
209 : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
210 1 : if (libspdm_rsp_psk_finish_rsp_test() != 0) {
211 0 : return_value = 1;
212 : }
213 : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
214 :
215 : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
216 1 : if (libspdm_rsp_heartbeat_ack_test() != 0) {
217 0 : return_value = 1;
218 : }
219 1 : if (libspdm_rsp_key_update_ack_test() != 0) {
220 0 : return_value = 1;
221 : }
222 1 : if (libspdm_rsp_end_session_ack_test() != 0) {
223 0 : return_value = 1;
224 : }
225 : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
226 :
227 : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
228 : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
229 : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
230 1 : if (spdm_rsp_encap_get_digests_test() != 0) {
231 0 : return_value = 1;
232 : }
233 1 : if (spdm_rsp_encap_get_certificate_test() != 0) {
234 0 : return_value = 1;
235 : }
236 : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
237 : #if LIBSPDM_SEND_CHALLENGE_SUPPORT
238 1 : if (libspdm_rsp_encap_challenge_test() != 0) {
239 0 : return_value = 1;
240 : }
241 : #endif /* LIBSPDM_SEND_CHALLENGE_SUPPORT */
242 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
243 1 : if (libspdm_rsp_encapsulated_response_test() != 0) {
244 0 : return_value = 1;
245 : }
246 1 : if (libspdm_rsp_encap_key_update_test() != 0) {
247 0 : return_value = 1;
248 : }
249 : #if (LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT) && (LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP)
250 1 : if (libspdm_rsp_encap_get_endpoint_info_test() != 0) {
251 0 : return_value = 1;
252 : }
253 1 : if (libspdm_rsp_encap_get_endpoint_info_error_test() != 0) {
254 0 : return_value = 1;
255 : }
256 : #endif /* LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT */
257 : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
258 1 : if (libspdm_rsp_encap_send_event_test() != 0) {
259 0 : return_value = 1;
260 : }
261 1 : if (libspdm_rsp_encap_send_event_error_test() != 0) {
262 0 : return_value = 1;
263 : }
264 : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
265 : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP*/
266 :
267 : #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
268 1 : if (libspdm_rsp_set_certificate_rsp_test() != 0) {
269 0 : return_value = 1;
270 : }
271 : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP */
272 :
273 : #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
274 1 : if (libspdm_rsp_csr_test() != 0) {
275 0 : return_value = 1;
276 : }
277 : #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
278 :
279 : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
280 1 : if (libspdm_rsp_chunk_response_test() != 0) {
281 0 : return_value = 1;
282 : }
283 :
284 1 : if (libspdm_rsp_receive_send_test() != 0) {
285 0 : return_value = 1;
286 : }
287 :
288 1 : if (libspdm_rsp_chunk_send_ack_test() != 0) {
289 0 : return_value = 1;
290 : }
291 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
292 :
293 : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
294 1 : if (libspdm_rsp_supported_event_types_test() != 0) {
295 0 : return_value = 1;
296 : }
297 1 : if (libspdm_rsp_supported_event_types_error_test() != 0) {
298 0 : return_value = 1;
299 : }
300 1 : if (libspdm_rsp_subscribe_event_types_ack_test() != 0) {
301 0 : return_value = 1;
302 : }
303 1 : if (libspdm_rsp_subscribe_event_types_ack_error_test() != 0) {
304 0 : return_value = 1;
305 : }
306 : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
307 :
308 : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
309 1 : if (libspdm_rsp_event_ack_test() != 0) {
310 0 : return_value = 1;
311 : }
312 1 : if (libspdm_rsp_event_ack_error_test() != 0) {
313 0 : return_value = 1;
314 : }
315 : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
316 :
317 : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
318 1 : if (libspdm_rsp_vendor_defined_response_test() != 0) {
319 0 : return_value = 1;
320 : }
321 1 : if (libspdm_rsp_vendor_defined_response_error_test() != 0) {
322 0 : return_value = 1;
323 : }
324 : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
325 :
326 1 : return return_value;
327 : }
|