Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Test certificate in OpenBMC. |
| 3 | |
| 4 | Resource ../../lib/resource.robot |
| 5 | Resource ../../lib/bmc_redfish_resource.robot |
| 6 | Resource ../../lib/openbmc_ffdc.robot |
| 7 | Resource ../../lib/certificate_utils.robot |
George Keishing | bf17fab | 2019-06-13 09:22:22 -0500 | [diff] [blame] | 8 | Library String |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 9 | |
Rahul Maheshwari | e48fd3e | 2019-07-22 02:28:58 -0500 | [diff] [blame] | 10 | Force Tags Certificate_Test |
| 11 | |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 12 | Suite Setup Suite Setup Execution |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 13 | Suite Teardown Suite Teardown |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 14 | Test Teardown Test Teardown Execution |
| 15 | |
| 16 | |
Rahul Maheshwari | 1e0f6a8 | 2019-08-29 01:33:23 -0500 | [diff] [blame] | 17 | *** Variables *** |
| 18 | |
| 19 | ${invalid_value} abc |
Zbigniew Kurzynski | 84ae0d3 | 2019-10-11 15:51:59 +0200 | [diff] [blame] | 20 | ${ROOT_CA_FILE_PATH} /etc/ssl/certs/authority/* |
Rahul Maheshwari | 1e0f6a8 | 2019-08-29 01:33:23 -0500 | [diff] [blame] | 21 | |
| 22 | |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 23 | ** Test Cases ** |
| 24 | |
| 25 | Verify Server Certificate Replace |
| 26 | [Documentation] Verify server certificate replace. |
| 27 | [Tags] Verify_Server_Certificate_Replace |
| 28 | [Template] Replace Certificate Via Redfish |
| 29 | |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 30 | # cert_type cert_format expected_status |
| 31 | 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 Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 35 | |
| 36 | |
| 37 | Verify Client Certificate Replace |
| 38 | [Documentation] Verify client certificate replace. |
| 39 | [Tags] Verify_Client_Certificate_Replace |
| 40 | [Template] Replace Certificate Via Redfish |
| 41 | |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 42 | # cert_type cert_format expected_status |
| 43 | 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 Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 47 | |
| 48 | |
Rahul Maheshwari | c1f43ed | 2019-06-03 01:00:16 -0500 | [diff] [blame] | 49 | Verify CA Certificate Replace |
| 50 | [Documentation] Verify CA certificate replace. |
| 51 | [Tags] Verify_CA_Certificate_Replace |
| 52 | [Template] Replace Certificate Via Redfish |
| 53 | |
| 54 | # cert_type cert_format expected_status |
| 55 | CA Valid Certificate ok |
| 56 | CA Empty Certificate error |
| 57 | |
| 58 | |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 59 | Verify Client Certificate Install |
| 60 | [Documentation] Verify client certificate install. |
| 61 | [Tags] Verify_Client_Certificate_Install |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 62 | [Template] Install And Verify Certificate Via Redfish |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 63 | |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 64 | # cert_type cert_format expected_status |
| 65 | 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 Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 69 | |
| 70 | |
Rahul Maheshwari | 479c9c5 | 2019-06-03 01:23:12 -0500 | [diff] [blame] | 71 | Verify CA Certificate Install |
| 72 | [Documentation] Verify CA certificate install. |
| 73 | [Tags] Verify_CA_Certificate_Install |
| 74 | [Template] Install And Verify Certificate Via Redfish |
| 75 | |
| 76 | # cert_type cert_format expected_status |
| 77 | CA Valid Certificate ok |
| 78 | CA Empty Certificate error |
| 79 | |
| 80 | |
Rahul Maheshwari | d35e687 | 2020-02-11 03:16:46 -0600 | [diff] [blame] | 81 | Verify 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. |
Rahul Maheshwari | d35e687 | 2020-02-11 03:16:46 -0600 | [diff] [blame] | 87 | ${cert_list}= Redfish_Utils.Get Member List /redfish/v1/Managers/bmc/Truststore/Certificates |
| 88 | ${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 | |
Rahul Maheshwari | 8ba1ebd | 2020-02-12 03:40:03 -0600 | [diff] [blame] | 100 | Verify Error While Uploding Same CA Certificate |
| 101 | [Documentation] Verify error while uploading same CA certificate two times. |
| 102 | [Tags] Verify_Error_While_Uploding_Same_CA_Certificate |
| 103 | |
| 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 Maheshwari | fa95b09 | 2019-05-22 05:10:59 -0500 | [diff] [blame] | 119 | Verify Server Certificate View Via Openssl |
| 120 | [Documentation] Verify server certificate via openssl command. |
| 121 | [Tags] Verify_Server_Certificate_View_Via_Openssl |
| 122 | |
Rahul Maheshwari | fa95b09 | 2019-05-22 05:10:59 -0500 | [diff] [blame] | 123 | ${cert_file_path}= Generate Certificate File Via Openssl Valid Certificate Valid Privatekey |
George Keishing | bf17fab | 2019-06-13 09:22:22 -0500 | [diff] [blame] | 124 | ${bytes}= OperatingSystem.Get Binary File ${cert_file_path} |
| 125 | ${file_data}= Decode Bytes To String ${bytes} UTF-8 |
Rahul Maheshwari | fa95b09 | 2019-05-22 05:10:59 -0500 | [diff] [blame] | 126 | |
| 127 | ${certificate_dict}= Create Dictionary |
| 128 | ... @odata.id=/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/1 |
| 129 | ${payload}= Create Dictionary CertificateString=${file_data} |
| 130 | ... CertificateType=PEM CertificateUri=${certificate_dict} |
| 131 | |
| 132 | ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate |
| 133 | ... body=${payload} |
| 134 | |
| 135 | Wait Until Keyword Succeeds 2 mins 15 secs Verify Certificate Visible Via OpenSSL ${cert_file_path} |
| 136 | |
| 137 | |
Rahul Maheshwari | 1e0f6a8 | 2019-08-29 01:33:23 -0500 | [diff] [blame] | 138 | Verify 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 | |
| 143 | # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status |
| 144 | Server RSA ${2048} ${EMPTY} ok |
| 145 | Server EC ${EMPTY} prime256v1 ok |
| 146 | Server EC ${EMPTY} secp521r1 ok |
| 147 | Server EC ${EMPTY} secp384r1 ok |
| 148 | |
| 149 | |
| 150 | Verify 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 | |
| 155 | # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status |
| 156 | Client RSA ${2048} ${EMPTY} ok |
| 157 | Client EC ${EMPTY} prime256v1 ok |
| 158 | Client EC ${EMPTY} secp521r1 ok |
| 159 | Client EC ${EMPTY} secp384r1 ok |
| 160 | |
| 161 | |
| 162 | Verify 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 | |
| 167 | # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status |
| 168 | Server ${invalid_value} ${2048} prime256v1 error |
| 169 | Server RAS ${invalid_value} ${EMPTY} error |
| 170 | Server EC ${EMPTY} ${invalid_value} error |
| 171 | |
| 172 | |
| 173 | Verify 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 | |
| 178 | Client ${invalid_value} ${2048} prime256v1 error |
| 179 | Client RSA ${invalid_value} ${EMPTY} error |
| 180 | Client EC ${EMPTY} ${invalid_value} error |
| 181 | |
| 182 | |
Anusha Dathatri | e20d18d | 2020-05-07 04:02:30 -0500 | [diff] [blame] | 183 | Verify Expired Client Certificate Install |
| 184 | [Documentation] Verify installation of expired CA certificate. |
| 185 | [Tags] Verify_Expired_Client_Certificate_Install |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 186 | [Setup] Get Current BMC Date |
| 187 | [Teardown] Run Keywords FFDC On Test Case Fail AND |
| 188 | ... Restore BMC Date |
Anusha Dathatri | e20d18d | 2020-05-07 04:02:30 -0500 | [diff] [blame] | 189 | |
Anusha Dathatri | 5b7dc6f | 2020-06-12 05:16:58 -0500 | [diff] [blame] | 190 | Modify BMC Date |
Anusha Dathatri | e20d18d | 2020-05-07 04:02:30 -0500 | [diff] [blame] | 191 | Install And Verify Certificate Via Redfish Client Expired Certificate error |
| 192 | |
| 193 | |
| 194 | Verify Expired CA Certificate Install |
| 195 | [Documentation] Verify installation of expired CA certificate. |
| 196 | [Tags] Verify_Expired_CA_Certificate_Install |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 197 | [Setup] Get Current BMC Date |
| 198 | [Teardown] Run Keywords FFDC On Test Case Fail AND |
| 199 | ... Restore BMC Date |
Anusha Dathatri | e20d18d | 2020-05-07 04:02:30 -0500 | [diff] [blame] | 200 | |
Anusha Dathatri | 5b7dc6f | 2020-06-12 05:16:58 -0500 | [diff] [blame] | 201 | Modify BMC Date |
Anusha Dathatri | e20d18d | 2020-05-07 04:02:30 -0500 | [diff] [blame] | 202 | Install And Verify Certificate Via Redfish CA Expired Certificate error |
| 203 | |
| 204 | |
Anusha Dathatri | 1a7a6b5 | 2020-06-10 04:57:37 -0500 | [diff] [blame] | 205 | Verify Expired Server Certificate Replace |
| 206 | [Documentation] Verify replacing the server certificate with an expired one. |
| 207 | [Tags] Verify_Expired_Server_Certificate_Replace |
| 208 | [Setup] Get Current BMC Date |
| 209 | [Teardown] Run Keywords FFDC On Test Case Fail AND |
| 210 | ... Restore BMC Date |
| 211 | |
| 212 | Modify BMC Date |
| 213 | Replace Certificate Via Redfish Server Expired Certificate error |
| 214 | |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 215 | *** Keywords *** |
| 216 | |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 217 | Install And Verify Certificate Via Redfish |
| 218 | [Documentation] Install and verify certificate using Redfish. |
Rahul Maheshwari | d35e687 | 2020-02-11 03:16:46 -0600 | [diff] [blame] | 219 | [Arguments] ${cert_type} ${cert_format} ${expected_status} ${delete_cert}=${True} |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 220 | |
| 221 | # Description of argument(s): |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 222 | # cert_type Certificate type (e.g. "Client" or "CA"). |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 223 | # cert_format Certificate file format |
| 224 | # (e.g. "Valid_Certificate_Valid_Privatekey"). |
| 225 | # expected_status Expected status of certificate replace Redfish |
| 226 | # request (i.e. "ok" or "error"). |
Rahul Maheshwari | d35e687 | 2020-02-11 03:16:46 -0600 | [diff] [blame] | 227 | # delete_cert Certificate will be deleted before installing if this True. |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 228 | |
Rahul Maheshwari | d35e687 | 2020-02-11 03:16:46 -0600 | [diff] [blame] | 229 | Run Keyword If '${cert_type}' == 'CA' and '${delete_cert}' == '${True}' |
| 230 | ... Delete All CA Certificate Via Redfish |
| 231 | ... ELSE IF '${cert_type}' == 'Client' and '${delete_cert}' == '${True}' |
| 232 | ... Delete Certificate Via BMC CLI ${cert_type} |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 233 | |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 234 | ${cert_file_path}= Generate Certificate File Via Openssl ${cert_format} |
George Keishing | bf17fab | 2019-06-13 09:22:22 -0500 | [diff] [blame] | 235 | ${bytes}= OperatingSystem.Get Binary File ${cert_file_path} |
| 236 | ${file_data}= Decode Bytes To String ${bytes} UTF-8 |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 237 | |
Rahul Maheshwari | 479c9c5 | 2019-06-03 01:23:12 -0500 | [diff] [blame] | 238 | ${certificate_uri}= Set Variable If |
| 239 | ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI} |
| 240 | ... '${cert_type}' == 'CA' ${REDFISH_CA_CERTIFICATE_URI} |
| 241 | |
Anusha Dathatri | 5b7dc6f | 2020-06-12 05:16:58 -0500 | [diff] [blame] | 242 | Run Keyword If '${cert_format}' == 'Expired Certificate' Modify BMC Date future |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 243 | |
Zbigniew Kurzynski | 84ae0d3 | 2019-10-11 15:51:59 +0200 | [diff] [blame] | 244 | ${cert_id}= Install Certificate File On BMC ${certificate_uri} ${expected_status} data=${file_data} |
| 245 | Logging Installed certificate id: ${cert_id} |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 246 | |
| 247 | # Adding delay after certificate installation. |
Rahul Maheshwari | c1f43ed | 2019-06-03 01:00:16 -0500 | [diff] [blame] | 248 | Sleep 30s |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 249 | |
| 250 | ${cert_file_content}= OperatingSystem.Get File ${cert_file_path} |
| 251 | ${bmc_cert_content}= Run Keyword If '${expected_status}' == 'ok' redfish_utils.Get Attribute |
Zbigniew Kurzynski | 84ae0d3 | 2019-10-11 15:51:59 +0200 | [diff] [blame] | 252 | ... ${certificate_uri}/${cert_id} CertificateString |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 253 | |
| 254 | Run Keyword If '${expected_status}' == 'ok' Should Contain ${cert_file_content} ${bmc_cert_content} |
Rahul Maheshwari | ce6e1a5 | 2020-02-11 04:09:19 -0600 | [diff] [blame] | 255 | [Return] ${cert_id} |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 256 | |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 257 | Modify BMC Date |
| 258 | [Documentation] Modify date in BMC. |
Anusha Dathatri | 5b7dc6f | 2020-06-12 05:16:58 -0500 | [diff] [blame] | 259 | [Arguments] ${date_set_type}=current |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 260 | |
| 261 | # Description of argument(s): |
Anusha Dathatri | 5b7dc6f | 2020-06-12 05:16:58 -0500 | [diff] [blame] | 262 | # date_set_type Set BMC date to a current, future, old date by 375 days. |
| 263 | # current - Sets date to local system date. |
| 264 | # future - Sets to a future date from current date. |
| 265 | # old - Sets to a old date from current date. |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 266 | |
| 267 | Redfish Power Off stack_mode=skip |
Anusha Dathatri | 5b7dc6f | 2020-06-12 05:16:58 -0500 | [diff] [blame] | 268 | ${current_date_time}= Get Current Date |
| 269 | ${new_time}= Run Keyword If '${date_set_type}' == 'current' Set Variable ${current_date_time} |
| 270 | ... ELSE IF '${date_set_type}' == 'future' |
| 271 | ... Add Time To Date ${current_date_time} 375 days |
| 272 | ... ELSE IF '${date_set_type}' == 'old' |
| 273 | ... Subtract Time From Date ${current_date_time} 375 days |
| 274 | |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 275 | # Enable manaual mode. |
| 276 | Redfish.Patch ${REDFISH_NW_PROTOCOL_URI} |
| 277 | ... body={'NTP':{'ProtocolEnabled': ${False}}} |
| 278 | ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] |
| 279 | Redfish.Patch ${REDFISH_BASE_URI}Managers/bmc body={'DateTime': '${new_time}'} |
| 280 | ... valid_status_codes=[${HTTP_OK}] |
| 281 | |
| 282 | Get Current BMC Date |
| 283 | [Documentation] Get current BMC date. |
| 284 | |
| 285 | ${cli_date_time}= CLI Get BMC DateTime |
| 286 | Set Test Variable ${cli_date_time} |
| 287 | |
| 288 | Restore BMC Date |
| 289 | [Documentation] Restore BMC date to its prior value. |
| 290 | |
| 291 | Redfish.Patch ${REDFISH_BASE_URI}Managers/bmc body={'DateTime': '${cli_date_time}'} |
| 292 | ... valid_status_codes=[${HTTP_OK}] |
Rahul Maheshwari | 037a343 | 2019-05-23 00:55:40 -0500 | [diff] [blame] | 293 | |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 294 | Replace Certificate Via Redfish |
| 295 | [Documentation] Test 'replace certificate' operation in the BMC via Redfish. |
| 296 | [Arguments] ${cert_type} ${cert_format} ${expected_status} |
| 297 | |
| 298 | # Description of argument(s): |
| 299 | # cert_type Certificate type (e.g. "Server" or "Client"). |
| 300 | # cert_format Certificate file format |
| 301 | # (e.g. Valid_Certificate_Valid_Privatekey). |
| 302 | # expected_status Expected status of certificate replace Redfish |
| 303 | # request (i.e. "ok" or "error"). |
| 304 | |
Rahul Maheshwari | c1f43ed | 2019-06-03 01:00:16 -0500 | [diff] [blame] | 305 | # Install certificate before replacing client or CA certificate. |
Rahul Maheshwari | ce6e1a5 | 2020-02-11 04:09:19 -0600 | [diff] [blame] | 306 | ${cert_id}= Run Keyword If '${cert_type}' == 'Client' |
Rahul Maheshwari | c1f43ed | 2019-06-03 01:00:16 -0500 | [diff] [blame] | 307 | ... Install And Verify Certificate Via Redfish ${cert_type} Valid Certificate Valid Privatekey ok |
| 308 | ... ELSE IF '${cert_type}' == 'CA' |
| 309 | ... Install And Verify Certificate Via Redfish ${cert_type} Valid Certificate ok |
Rahul Maheshwari | 9862eb5 | 2019-05-31 04:04:42 -0500 | [diff] [blame] | 310 | |
Anusha Dathatri | 1a7a6b5 | 2020-06-10 04:57:37 -0500 | [diff] [blame] | 311 | ${cert_file_path}= Generate Certificate File Via Openssl ${cert_format} |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 312 | |
George Keishing | bf17fab | 2019-06-13 09:22:22 -0500 | [diff] [blame] | 313 | ${bytes}= OperatingSystem.Get Binary File ${cert_file_path} |
| 314 | ${file_data}= Decode Bytes To String ${bytes} UTF-8 |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 315 | |
Anusha Dathatri | 1a7a6b5 | 2020-06-10 04:57:37 -0500 | [diff] [blame] | 316 | Run Keyword If '${cert_format}' == 'Expired Certificate' Modify BMC Date future |
| 317 | |
Rahul Maheshwari | c1f43ed | 2019-06-03 01:00:16 -0500 | [diff] [blame] | 318 | ${certificate_uri}= Set Variable If |
Rahul Maheshwari | c142c09 | 2019-06-13 00:42:35 -0500 | [diff] [blame] | 319 | ... '${cert_type}' == 'Server' ${REDFISH_HTTPS_CERTIFICATE_URI}/1 |
Rahul Maheshwari | c1f43ed | 2019-06-03 01:00:16 -0500 | [diff] [blame] | 320 | ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI}/1 |
Rahul Maheshwari | ce6e1a5 | 2020-02-11 04:09:19 -0600 | [diff] [blame] | 321 | ... '${cert_type}' == 'CA' ${REDFISH_CA_CERTIFICATE_URI}/${cert_id} |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 322 | |
| 323 | ${certificate_dict}= Create Dictionary @odata.id=${certificate_uri} |
| 324 | ${payload}= Create Dictionary CertificateString=${file_data} |
| 325 | ... CertificateType=PEM CertificateUri=${certificate_dict} |
Rahul Maheshwari | 19e6e44 | 2019-06-03 00:22:45 -0500 | [diff] [blame] | 326 | |
| 327 | ${expected_resp}= Set Variable If '${expected_status}' == 'ok' ${HTTP_OK} |
George Keishing | d225180 | 2020-01-24 00:23:12 -0600 | [diff] [blame] | 328 | ... '${expected_status}' == 'error' ${HTTP_NOT_FOUND}, ${HTTP_INTERNAL_SERVER_ERROR} |
Rahul Maheshwari | 9862eb5 | 2019-05-31 04:04:42 -0500 | [diff] [blame] | 329 | ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate |
Rahul Maheshwari | 19e6e44 | 2019-06-03 00:22:45 -0500 | [diff] [blame] | 330 | ... body=${payload} valid_status_codes=[${expected_resp}] |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 331 | |
| 332 | ${cert_file_content}= OperatingSystem.Get File ${cert_file_path} |
| 333 | ${bmc_cert_content}= redfish_utils.Get Attribute ${certificate_uri} CertificateString |
| 334 | |
| 335 | Run Keyword If '${expected_status}' == 'ok' |
| 336 | ... Should Contain ${cert_file_content} ${bmc_cert_content} |
| 337 | ... ELSE |
| 338 | ... Should Not Contain ${cert_file_content} ${bmc_cert_content} |
| 339 | |
| 340 | |
Rahul Maheshwari | 1e0f6a8 | 2019-08-29 01:33:23 -0500 | [diff] [blame] | 341 | Generate CSR Via Redfish |
| 342 | [Documentation] Generate CSR using Redfish. |
| 343 | [Arguments] ${cert_type} ${key_pair_algorithm} ${key_bit_length} ${key_curv_id} ${expected_status} |
| 344 | |
| 345 | # Description of argument(s): |
| 346 | # cert_type Certificate type ("Server" or "Client"). |
| 347 | # key_pair_algorithm CSR key pair algorithm ("EC" or "RSA") |
| 348 | # key_bit_length CSR key bit length ("2048"). |
| 349 | # key_curv_id CSR key curv id ("prime256v1" or "secp521r1" or "secp384r1"). |
| 350 | # expected_status Expected status of certificate replace Redfish |
| 351 | # request ("ok" or "error"). |
| 352 | |
Rahul Maheshwari | 1e0f6a8 | 2019-08-29 01:33:23 -0500 | [diff] [blame] | 353 | ${certificate_uri}= Set Variable If |
| 354 | ... '${cert_type}' == 'Server' ${REDFISH_HTTPS_CERTIFICATE_URI}/ |
| 355 | ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI}/ |
| 356 | |
| 357 | ${certificate_dict}= Create Dictionary @odata.id=${certificate_uri} |
| 358 | ${payload}= Create Dictionary City=Austin CertificateCollection=${certificate_dict} |
| 359 | ... CommonName=${OPENBMC_HOST} Country=US Organization=IBM |
| 360 | ... OrganizationalUnit=ISL State=AU KeyBitLength=${key_bit_length} |
| 361 | ... KeyPairAlgorithm=${key_pair_algorithm} KeyCurveId=${key_curv_id} |
| 362 | |
| 363 | # Remove not applicable field for CSR generation. |
| 364 | Run Keyword If '${key_pair_algorithm}' == 'EC' Remove From Dictionary ${payload} KeyBitLength |
| 365 | ... ELSE IF '${key_pair_algorithm}' == 'RSA' Remove From Dictionary ${payload} KeyCurveId |
| 366 | |
| 367 | ${expected_resp}= Set Variable If '${expected_status}' == 'ok' ${HTTP_OK} |
| 368 | ... '${expected_status}' == 'error' ${HTTP_INTERNAL_SERVER_ERROR}, ${HTTP_BAD_REQUEST} |
| 369 | ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR |
| 370 | ... body=${payload} valid_status_codes=[${expected_resp}] |
| 371 | |
| 372 | # Delay added between two CSR generation request. |
| 373 | Sleep 5s |
| 374 | |
| 375 | |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 376 | Delete Certificate Via BMC CLI |
| 377 | [Documentation] Delete certificate via BMC CLI. |
| 378 | [Arguments] ${cert_type} |
| 379 | |
| 380 | # Description of argument(s): |
| 381 | # cert_type Certificate type (e.g. "Client" or "CA"). |
| 382 | |
| 383 | ${certificate_file_path} ${certificate_service} ${certificate_uri}= |
| 384 | ... Run Keyword If '${cert_type}' == 'Client' |
| 385 | ... Set Variable /etc/nslcd/certs/cert.pem phosphor-certificate-manager@nslcd.service |
| 386 | ... ${REDFISH_LDAP_CERTIFICATE_URI} |
| 387 | ... ELSE IF '${cert_type}' == 'CA' |
Zbigniew Kurzynski | 84ae0d3 | 2019-10-11 15:51:59 +0200 | [diff] [blame] | 388 | ... Set Variable ${ROOT_CA_FILE_PATH} phosphor-certificate-manager@authority.service |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 389 | ... ${REDFISH_CA_CERTIFICATE_URI} |
Rahul Maheshwari | a5b1767 | 2019-05-30 11:08:30 -0500 | [diff] [blame] | 390 | |
| 391 | ${file_status} ${stderr} ${rc}= BMC Execute Command |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 392 | ... [ -f ${certificate_file_path} ] && echo "Found" || echo "Not Found" |
Rahul Maheshwari | a5b1767 | 2019-05-30 11:08:30 -0500 | [diff] [blame] | 393 | |
Rahul Maheshwari | 3ecd1a6 | 2019-06-03 01:44:34 -0500 | [diff] [blame] | 394 | Return From Keyword If "${file_status}" != "Found" |
| 395 | BMC Execute Command rm ${certificate_file_path} |
| 396 | BMC Execute Command systemctl restart ${certificate_service} |
Zbigniew Kurzynski | 84ae0d3 | 2019-10-11 15:51:59 +0200 | [diff] [blame] | 397 | BMC Execute Command systemctl daemon-reload |
George Keishing | 2d0804e | 2019-12-12 22:27:05 -0600 | [diff] [blame] | 398 | Wait Until Keyword Succeeds 1 min 10 sec Redfish.Get ${certificate_uri}/1 |
| 399 | ... valid_status_codes=[${HTTP_NOT_FOUND}, ${HTTP_INTERNAL_SERVER_ERROR}] |
Rahul Maheshwari | a5b1767 | 2019-05-30 11:08:30 -0500 | [diff] [blame] | 400 | |
| 401 | |
Rahul Maheshwari | 382c4dc | 2020-02-09 23:50:54 -0600 | [diff] [blame] | 402 | Delete All CA Certificate Via Redfish |
| 403 | [Documentation] Delete all CA certificate via Redfish. |
| 404 | |
| 405 | ${cert_list}= Redfish_Utils.Get Member List /redfish/v1/Managers/bmc/Truststore/Certificates |
| 406 | FOR ${cert} IN @{cert_list} |
| 407 | Redfish.Delete ${cert} valid_status_codes=[${HTTP_NO_CONTENT}] |
| 408 | END |
| 409 | |
| 410 | |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 411 | Suite Setup Execution |
| 412 | [Documentation] Do suite setup tasks. |
| 413 | |
| 414 | # Create certificate sub-directory in current working directory. |
| 415 | Create Directory certificate_dir |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 416 | Redfish.Login |
Rahul Maheshwari | b4b8bb6 | 2019-03-04 23:56:10 -0600 | [diff] [blame] | 417 | |
| 418 | |
| 419 | Test Teardown Execution |
| 420 | [Documentation] Do the post test teardown. |
| 421 | |
| 422 | FFDC On Test Case Fail |
Anusha Dathatri | 109c2ce | 2020-06-03 22:19:05 -0500 | [diff] [blame] | 423 | |
| 424 | Suite Teardown |
| 425 | [Documentation] Do suite teardown tasks. |
| 426 | |
| 427 | Redfish.Logout |