blob: 025e8aea76ca33ac91815a7cd31d546808229657 [file] [log] [blame]
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -06001*** Settings ***
2Documentation Test certificate in OpenBMC.
3
4Resource ../../lib/resource.robot
5Resource ../../lib/bmc_redfish_resource.robot
6Resource ../../lib/openbmc_ffdc.robot
7Resource ../../lib/certificate_utils.robot
George Keishingbf17fab2019-06-13 09:22:22 -05008Library String
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -06009
Matt Fischer6fb70d92023-10-24 19:06:33 -060010Test Tags Certificate
Rahul Maheshwarie48fd3e2019-07-22 02:28:58 -050011
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060012Suite Setup Suite Setup Execution
Anusha Dathatri109c2ce2020-06-03 22:19:05 -050013Suite Teardown Suite Teardown
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060014Test Teardown Test Teardown Execution
15
16
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -050017*** Variables ***
18
19${invalid_value} abc
Zbigniew Kurzynski84ae0d32019-10-11 15:51:59 +020020${ROOT_CA_FILE_PATH} /etc/ssl/certs/authority/*
Rahul Maheshwarib0d8da42023-08-25 06:55:59 -050021${keybit_length} ${2048}
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -050022
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060023** Test Cases **
24
25Verify Server Certificate Replace
26 [Documentation] Verify server certificate replace.
27 [Tags] Verify_Server_Certificate_Replace
28 [Template] Replace Certificate Via Redfish
29
rramyasr-ind19c1b12025-11-13 01:10:34 -060030 # cert_type cert_format expected_status.
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050031 Server Valid Certificate Valid Privatekey ok
32 Server Empty Certificate Valid Privatekey error
33 Server Valid Certificate Empty Privatekey error
34 Server Empty Certificate Empty Privatekey error
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060035
36
37Verify Client Certificate Replace
38 [Documentation] Verify client certificate replace.
39 [Tags] Verify_Client_Certificate_Replace
40 [Template] Replace Certificate Via Redfish
41
rramyasr-ind19c1b12025-11-13 01:10:34 -060042 # cert_type cert_format expected_status.
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050043 Client Valid Certificate Valid Privatekey ok
44 Client Empty Certificate Valid Privatekey error
45 Client Valid Certificate Empty Privatekey error
46 Client Empty Certificate Empty Privatekey error
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060047
48
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -050049Verify CA Certificate Replace
50 [Documentation] Verify CA certificate replace.
51 [Tags] Verify_CA_Certificate_Replace
52 [Template] Replace Certificate Via Redfish
53
rramyasr-ind19c1b12025-11-13 01:10:34 -060054 # cert_type cert_format expected_status.
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -050055 CA Valid Certificate ok
56 CA Empty Certificate error
57
58
Rahul Maheshwari037a3432019-05-23 00:55:40 -050059Verify Client Certificate Install
60 [Documentation] Verify client certificate install.
61 [Tags] Verify_Client_Certificate_Install
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050062 [Template] Install And Verify Certificate Via Redfish
Rahul Maheshwari037a3432019-05-23 00:55:40 -050063
rramyasr-ind19c1b12025-11-13 01:10:34 -060064 # cert_type cert_format expected_status.
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050065 Client Valid Certificate Valid Privatekey ok
66 Client Empty Certificate Valid Privatekey error
67 Client Valid Certificate Empty Privatekey error
68 Client Empty Certificate Empty Privatekey error
Rahul Maheshwari037a3432019-05-23 00:55:40 -050069
70
Rahul Maheshwari479c9c52019-06-03 01:23:12 -050071Verify CA Certificate Install
72 [Documentation] Verify CA certificate install.
73 [Tags] Verify_CA_Certificate_Install
74 [Template] Install And Verify Certificate Via Redfish
75
rramyasr-ind19c1b12025-11-13 01:10:34 -060076 # cert_type cert_format expected_status.
Rahul Maheshwari479c9c52019-06-03 01:23:12 -050077 CA Valid Certificate ok
78 CA Empty Certificate error
79
80
Rahul Maheshwarid35e6872020-02-11 03:16:46 -060081Verify Maximum CA Certificate Install
82 [Documentation] Verify maximum CA certificate install.
83 [Tags] Verify_Maximum_CA_Certificate_Install
84 [Teardown] Run Keywords FFDC On Test Case Fail AND Delete All CA Certificate Via Redfish
85
86 # Get CA certificate count from BMC.
ganesanb4d430282023-04-27 14:33:23 +000087 ${cert_list}= Redfish_Utils.Get Member List /redfish/v1/Managers/${MANAGER_ID}/Truststore/Certificates
Rahul Maheshwarid35e6872020-02-11 03:16:46 -060088 ${cert_count}= Get Length ${cert_list}
89
90 # Install CA certificate to reach maximum count of 10.
91 FOR ${INDEX} IN RANGE ${cert_count} 10
92 Install And Verify Certificate Via Redfish CA Valid Certificate ok ${FALSE}
93 ${cert_count}= Evaluate ${cert_count} + 1
94 END
95
96 # Verify error while installing 11th CA certificate.
97 Install And Verify Certificate Via Redfish CA Valid Certificate error ${FALSE}
98
99
George Keishing16b3c7b2021-01-28 09:23:37 -0600100Verify Error While Uploading Same CA Certificate
Rahul Maheshwari8ba1ebd2020-02-12 03:40:03 -0600101 [Documentation] Verify error while uploading same CA certificate two times.
George Keishing16b3c7b2021-01-28 09:23:37 -0600102 [Tags] Verify_Error_While_Uploading_Same_CA_Certificate
Rahul Maheshwari8ba1ebd2020-02-12 03:40:03 -0600103
104 # Create certificate file for uploading.
105 ${cert_file_path}= Generate Certificate File Via Openssl Valid Certificate 365
106 ${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
107 ${file_data}= Decode Bytes To String ${bytes} UTF-8
108
109 # Install CA certificate.
110 Install Certificate File On BMC ${REDFISH_CA_CERTIFICATE_URI} ok data=${file_data}
111
112 # Adding delay after certificate installation.
113 Sleep 30s
114
115 # Check error while uploading same certificate.
116 Install Certificate File On BMC ${REDFISH_CA_CERTIFICATE_URI} error data=${file_data}
117
118
Rahul Maheshwarifa95b092019-05-22 05:10:59 -0500119Verify Server Certificate View Via Openssl
120 [Documentation] Verify server certificate via openssl command.
121 [Tags] Verify_Server_Certificate_View_Via_Openssl
122
Rahul Maheshwarifa95b092019-05-22 05:10:59 -0500123 ${cert_file_path}= Generate Certificate File Via Openssl Valid Certificate Valid Privatekey
George Keishingbf17fab2019-06-13 09:22:22 -0500124 ${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
125 ${file_data}= Decode Bytes To String ${bytes} UTF-8
Rahul Maheshwarifa95b092019-05-22 05:10:59 -0500126
127 ${certificate_dict}= Create Dictionary
ganesanb4d430282023-04-27 14:33:23 +0000128 ... @odata.id=/redfish/v1/Managers/${MANAGER_ID}/NetworkProtocol/HTTPS/Certificates/1
Rahul Maheshwarifa95b092019-05-22 05:10:59 -0500129 ${payload}= Create Dictionary CertificateString=${file_data}
130 ... CertificateType=PEM CertificateUri=${certificate_dict}
131
132 ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate
ganesanb85c22652023-04-22 16:08:30 +0000133 ... body=${payload} valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Rahul Maheshwarifa95b092019-05-22 05:10:59 -0500134
135 Wait Until Keyword Succeeds 2 mins 15 secs Verify Certificate Visible Via OpenSSL ${cert_file_path}
136
137
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500138Verify CSR Generation For Server Certificate
139 [Documentation] Verify CSR generation for server certificate.
140 [Tags] Verify_CSR_Generation_For_Server_Certificate
141 [Template] Generate CSR Via Redfish
142
rramyasr-ind19c1b12025-11-13 01:10:34 -0600143 # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status.
144 Server RSA ${keybit_length} ${EMPTY} ok
145 Server EC ${EMPTY} prime256v1 ok
146 Server EC ${EMPTY} secp521r1 ok
147 Server EC ${EMPTY} secp384r1 ok
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500148
149
150Verify CSR Generation For Client Certificate
151 [Documentation] Verify CSR generation for client certificate.
152 [Tags] Verify_CSR_Generation_For_Client_Certificate
153 [Template] Generate CSR Via Redfish
154
rramyasr-ind19c1b12025-11-13 01:10:34 -0600155 # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status.
156 Client RSA ${keybit_length} ${EMPTY} ok
157 Client EC ${EMPTY} prime256v1 ok
158 Client EC ${EMPTY} secp521r1 ok
159 Client EC ${EMPTY} secp384r1 ok
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500160
161
162Verify CSR Generation For Server Certificate With Invalid Value
163 [Documentation] Verify error while generating CSR for server certificate with invalid value.
164 [Tags] Verify_CSR_Generation_For_Server_Certificate_With_Invalid_Value
165 [Template] Generate CSR Via Redfish
166
rramyasr-ind19c1b12025-11-13 01:10:34 -0600167 # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status.
168 Server ${invalid_value} ${keybit_length} prime256v1 error
169 Server RAS ${invalid_value} ${EMPTY} error
170 Server EC ${EMPTY} ${invalid_value} error
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500171
172
173Verify CSR Generation For Client Certificate With Invalid Value
174 [Documentation] Verify error while generating CSR for client certificate with invalid value.
175 [Tags] Verify_CSR_Generation_For_Client_Certificate_With_Invalid_Value
176 [Template] Generate CSR Via Redfish
177
rramyasr-ind19c1b12025-11-13 01:10:34 -0600178 # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status.
179 Client ${invalid_value} ${keybit_length} prime256v1 error
180 Client RSA ${invalid_value} ${EMPTY} error
181 Client EC ${EMPTY} ${invalid_value} error
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500182
183
Anusha Dathatribc855642020-06-17 05:21:14 -0500184Verify Expired Certificate Install
185 [Documentation] Verify installation of expired certificate.
186 [Tags] Verify_Expired_Certificate_Install
187 [Setup] Run Keywords Get Current BMC Date AND Modify BMC Date
188 [Template] Install And Verify Certificate Via Redfish
189 [Teardown] Run Keywords FFDC On Test Case Fail AND Restore BMC Date
Anusha Dathatrie20d18d2020-05-07 04:02:30 -0500190
rramyasr-ind19c1b12025-11-13 01:10:34 -0600191 # cert_type cert_format expected_status.
192 Client Expired Certificate ok
193 CA Expired Certificate ok
Anusha Dathatrie20d18d2020-05-07 04:02:30 -0500194
195
Anusha Dathatribc855642020-06-17 05:21:14 -0500196Verify Expired Certificate Replace
197 [Documentation] Verify replacing the certificate with an expired one.
198 [Tags] Verify_Expired_Certificate_Replace
199 [Setup] Run Keywords Get Current BMC Date AND Modify BMC Date
200 [Template] Replace Certificate Via Redfish
rramyasr-ind19c1b12025-11-13 01:10:34 -0600201 #[Teardown] Run Keywords FFDC On Test Case Fail AND Restore BMC Date
Anusha Dathatrie20d18d2020-05-07 04:02:30 -0500202
rramyasr-ind19c1b12025-11-13 01:10:34 -0600203 # cert_type cert_format expected_status.
204 Server Expired Certificate ok
Anusha Dathatrie20d18d2020-05-07 04:02:30 -0500205
206
Anusha Dathatribc855642020-06-17 05:21:14 -0500207Verify Not Yet Valid Certificate Install
208 [Documentation] Verify installation of not yet valid certificates.
209 [Tags] Verify_Not_Yet_Valid_Certificate_Install
210 [Setup] Run Keywords Get Current BMC Date AND Modify BMC Date
211 [Template] Install And Verify Certificate Via Redfish
212 [Teardown] Run Keywords FFDC On Test Case Fail AND Restore BMC Date
Anusha Dathatri1a7a6b52020-06-10 04:57:37 -0500213
rramyasr-ind19c1b12025-11-13 01:10:34 -0600214 # cert_type cert_format expected_status.
215 Client Not Yet Valid Certificate ok
216 CA Not Yet Valid Certificate ok
Anusha Dathatribc855642020-06-17 05:21:14 -0500217
218
219Verify Not Yet Valid Certificate Replace
220 [Documentation] Verify replacing certificate with a not yet valid one.
221 [Tags] Verify_Not_Yet_Valid_Certificate_Replace
222 [Setup] Run Keywords Get Current BMC Date AND Modify BMC Date
223 [Template] Replace Certificate Via Redfish
224 [Teardown] Run Keywords FFDC On Test Case Fail AND Restore BMC Date
225
rramyasr-ind19c1b12025-11-13 01:10:34 -0600226 # cert_type cert_format expected_status.
227 Server Not Yet Valid Certificate ok
228 Client Not Yet Valid Certificate ok
229 CA Not Yet Valid Certificate ok
Anusha Dathatribc855642020-06-17 05:21:14 -0500230
Anusha Dathatri1a7a6b52020-06-10 04:57:37 -0500231
Tony Lee027f6072021-02-09 17:41:41 +0800232Verify Certificates Location Via Redfish
233 [Documentation] Verify the location of certificates via Redfish.
234 [Tags] Verify_Certificates_Location_Via_Redfish
235
236 ${cert_id}= Install And Verify Certificate Via Redfish
237 ... CA Valid Certificate ok
238
239 ${resp}= Redfish.Get /redfish/v1/CertificateService/CertificateLocations
240 ${Links}= Get From Dictionary ${resp.dict} Links
241
242 ${match_cert}= Catenate
ganesanb4d430282023-04-27 14:33:23 +0000243 ... /redfish/v1/Managers/${MANAGER_ID}/Truststore/Certificates/${cert_id}
Tony Lee027f6072021-02-09 17:41:41 +0800244 ${match}= Set Variable ${False}
245
246 FOR ${Certificates_dict} IN @{Links['Certificates']}
Sridevi Rameshac155722025-05-02 05:09:40 -0500247 IF "${Certificates_dict['@odata.id']}}" != "${match_cert}}" CONTINUE
Tony Lee027f6072021-02-09 17:41:41 +0800248 ${match}= Set Variable ${True}
249 END
250
251 Should Be Equal ${match} ${True}
252 ... msg=Verify the location of certificates via Redfish fail.
253
254
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600255*** Keywords ***
256
Anusha Dathatri109c2ce2020-06-03 22:19:05 -0500257Get Current BMC Date
258 [Documentation] Get current BMC date.
259
260 ${cli_date_time}= CLI Get BMC DateTime
261 Set Test Variable ${cli_date_time}
262
rramyasr-ind19c1b12025-11-13 01:10:34 -0600263
Anusha Dathatri109c2ce2020-06-03 22:19:05 -0500264Restore BMC Date
265 [Documentation] Restore BMC date to its prior value.
266
ganesanb4d430282023-04-27 14:33:23 +0000267 Redfish.Patch ${REDFISH_BASE_URI}Managers/${MANAGER_ID} body={'DateTime': '${cli_date_time}'}
rramyasr-ined0c14a2025-03-03 03:35:04 -0600268 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500269
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600270
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500271Generate CSR Via Redfish
272 [Documentation] Generate CSR using Redfish.
273 [Arguments] ${cert_type} ${key_pair_algorithm} ${key_bit_length} ${key_curv_id} ${expected_status}
274
275 # Description of argument(s):
276 # cert_type Certificate type ("Server" or "Client").
277 # key_pair_algorithm CSR key pair algorithm ("EC" or "RSA")
278 # key_bit_length CSR key bit length ("2048").
279 # key_curv_id CSR key curv id ("prime256v1" or "secp521r1" or "secp384r1").
280 # expected_status Expected status of certificate replace Redfish
281 # request ("ok" or "error").
rramyasr-ind19c1b12025-11-13 01:10:34 -0600282 IF '${cert_type}' == 'Server'
283 ${certificate_uri}= Set Variable ${REDFISH_HTTPS_CERTIFICATE_URI}/
284 ELSE IF '${cert_type}' == 'Client'
285 ${certificate_uri}= Set Variable ${REDFISH_LDAP_CERTIFICATE_URI}/
286 ELSE
287 ${certificate_uri}= Set Variable None
288 END
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500289
290 ${certificate_dict}= Create Dictionary @odata.id=${certificate_uri}
291 ${payload}= Create Dictionary City=Austin CertificateCollection=${certificate_dict}
rramyasr-in8e6ebd22023-02-20 09:44:23 -0600292 ... CommonName=${OPENBMC_HOST} Country=US Organization=xyz
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500293 ... OrganizationalUnit=ISL State=AU KeyBitLength=${key_bit_length}
294 ... KeyPairAlgorithm=${key_pair_algorithm} KeyCurveId=${key_curv_id}
295
296 # Remove not applicable field for CSR generation.
George Keishinge6e161e2025-05-08 10:18:30 +0530297 IF '${key_pair_algorithm}' == 'EC'
298 Remove From Dictionary ${payload} KeyBitLength
299 ELSE IF '${key_pair_algorithm}' == 'RSA'
300 Remove From Dictionary ${payload} KeyCurveId
301 END
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500302
rramyasr-ind19c1b12025-11-13 01:10:34 -0600303 IF '${expected_status}' == 'ok'
304 ${expected_resp}= Evaluate [${HTTP_OK}]
305 ELSE IF '${expected_status}' == 'error'
306 ${expected_resp}= Evaluate [${HTTP_INTERNAL_SERVER_ERROR}, ${HTTP_BAD_REQUEST}]
307 ELSE
308 ${expected_resp}= Evaluate [] # empty or default list if needed
309 END
310
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500311 ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR
rramyasr-ind19c1b12025-11-13 01:10:34 -0600312 ... body=${payload} valid_status_codes=${expected_resp}
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500313
314 # Delay added between two CSR generation request.
315 Sleep 5s
316
317
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600318Suite Setup Execution
319 [Documentation] Do suite setup tasks.
320
321 # Create certificate sub-directory in current working directory.
322 Create Directory certificate_dir
Anusha Dathatri109c2ce2020-06-03 22:19:05 -0500323 Redfish.Login
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600324
325
326Test Teardown Execution
327 [Documentation] Do the post test teardown.
328
329 FFDC On Test Case Fail
Anusha Dathatri109c2ce2020-06-03 22:19:05 -0500330
rramyasr-ind19c1b12025-11-13 01:10:34 -0600331
Anusha Dathatri109c2ce2020-06-03 22:19:05 -0500332Suite Teardown
333 [Documentation] Do suite teardown tasks.
334
rramyasr-ind19c1b12025-11-13 01:10:34 -0600335 Redfish.Logout