blob: 889b699e86b8b8e28012e9b50c900012373f7c80 [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
Rahul Maheshwarie48fd3e2019-07-22 02:28:58 -050010Force Tags Certificate_Test
11
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060012Suite Setup Suite Setup Execution
13Test Teardown Test Teardown Execution
14
15
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -050016*** Variables ***
17
18${invalid_value} abc
19
20
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060021** Test Cases **
22
23Verify Server Certificate Replace
24 [Documentation] Verify server certificate replace.
25 [Tags] Verify_Server_Certificate_Replace
26 [Template] Replace Certificate Via Redfish
27
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050028 # cert_type cert_format expected_status
29 Server Valid Certificate Valid Privatekey ok
30 Server Empty Certificate Valid Privatekey error
31 Server Valid Certificate Empty Privatekey error
32 Server Empty Certificate Empty Privatekey error
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060033
34
35Verify Client Certificate Replace
36 [Documentation] Verify client certificate replace.
37 [Tags] Verify_Client_Certificate_Replace
38 [Template] Replace Certificate Via Redfish
39
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050040 # cert_type cert_format expected_status
41 Client Valid Certificate Valid Privatekey ok
42 Client Empty Certificate Valid Privatekey error
43 Client Valid Certificate Empty Privatekey error
44 Client Empty Certificate Empty Privatekey error
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060045
46
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -050047Verify CA Certificate Replace
48 [Documentation] Verify CA certificate replace.
49 [Tags] Verify_CA_Certificate_Replace
50 [Template] Replace Certificate Via Redfish
51
52 # cert_type cert_format expected_status
53 CA Valid Certificate ok
54 CA Empty Certificate error
55
56
Rahul Maheshwari037a3432019-05-23 00:55:40 -050057Verify Client Certificate Install
58 [Documentation] Verify client certificate install.
59 [Tags] Verify_Client_Certificate_Install
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050060 [Template] Install And Verify Certificate Via Redfish
Rahul Maheshwari037a3432019-05-23 00:55:40 -050061
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050062 # cert_type cert_format expected_status
63 Client Valid Certificate Valid Privatekey ok
64 Client Empty Certificate Valid Privatekey error
65 Client Valid Certificate Empty Privatekey error
66 Client Empty Certificate Empty Privatekey error
Rahul Maheshwari037a3432019-05-23 00:55:40 -050067
68
Rahul Maheshwari479c9c52019-06-03 01:23:12 -050069Verify CA Certificate Install
70 [Documentation] Verify CA certificate install.
71 [Tags] Verify_CA_Certificate_Install
72 [Template] Install And Verify Certificate Via Redfish
73
74 # cert_type cert_format expected_status
75 CA Valid Certificate ok
76 CA Empty Certificate error
77
78
Rahul Maheshwarifa95b092019-05-22 05:10:59 -050079Verify Server Certificate View Via Openssl
80 [Documentation] Verify server certificate via openssl command.
81 [Tags] Verify_Server_Certificate_View_Via_Openssl
82
83 redfish.Login
84
85 ${cert_file_path}= Generate Certificate File Via Openssl Valid Certificate Valid Privatekey
George Keishingbf17fab2019-06-13 09:22:22 -050086 ${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
87 ${file_data}= Decode Bytes To String ${bytes} UTF-8
Rahul Maheshwarifa95b092019-05-22 05:10:59 -050088
89 ${certificate_dict}= Create Dictionary
90 ... @odata.id=/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/1
91 ${payload}= Create Dictionary CertificateString=${file_data}
92 ... CertificateType=PEM CertificateUri=${certificate_dict}
93
94 ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate
95 ... body=${payload}
96
97 Wait Until Keyword Succeeds 2 mins 15 secs Verify Certificate Visible Via OpenSSL ${cert_file_path}
98
99
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500100Verify CSR Generation For Server Certificate
101 [Documentation] Verify CSR generation for server certificate.
102 [Tags] Verify_CSR_Generation_For_Server_Certificate
103 [Template] Generate CSR Via Redfish
104
105 # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status
106 Server RSA ${2048} ${EMPTY} ok
107 Server EC ${EMPTY} prime256v1 ok
108 Server EC ${EMPTY} secp521r1 ok
109 Server EC ${EMPTY} secp384r1 ok
110
111
112Verify CSR Generation For Client Certificate
113 [Documentation] Verify CSR generation for client certificate.
114 [Tags] Verify_CSR_Generation_For_Client_Certificate
115 [Template] Generate CSR Via Redfish
116
117 # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status
118 Client RSA ${2048} ${EMPTY} ok
119 Client EC ${EMPTY} prime256v1 ok
120 Client EC ${EMPTY} secp521r1 ok
121 Client EC ${EMPTY} secp384r1 ok
122
123
124Verify CSR Generation For Server Certificate With Invalid Value
125 [Documentation] Verify error while generating CSR for server certificate with invalid value.
126 [Tags] Verify_CSR_Generation_For_Server_Certificate_With_Invalid_Value
127 [Template] Generate CSR Via Redfish
128
129 # csr_type key_pair_algorithm key_bit_length key_curv_id expected_status
130 Server ${invalid_value} ${2048} prime256v1 error
131 Server RAS ${invalid_value} ${EMPTY} error
132 Server EC ${EMPTY} ${invalid_value} error
133
134
135Verify CSR Generation For Client Certificate With Invalid Value
136 [Documentation] Verify error while generating CSR for client certificate with invalid value.
137 [Tags] Verify_CSR_Generation_For_Client_Certificate_With_Invalid_Value
138 [Template] Generate CSR Via Redfish
139
140 Client ${invalid_value} ${2048} prime256v1 error
141 Client RSA ${invalid_value} ${EMPTY} error
142 Client EC ${EMPTY} ${invalid_value} error
143
144
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600145*** Keywords ***
146
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500147Install And Verify Certificate Via Redfish
148 [Documentation] Install and verify certificate using Redfish.
149 [Arguments] ${cert_type} ${cert_format} ${expected_status}
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500150
151 # Description of argument(s):
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500152 # cert_type Certificate type (e.g. "Client" or "CA").
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500153 # cert_format Certificate file format
154 # (e.g. "Valid_Certificate_Valid_Privatekey").
155 # expected_status Expected status of certificate replace Redfish
156 # request (i.e. "ok" or "error").
157
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500158 redfish.Login
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500159 Delete Certificate Via BMC CLI ${cert_type}
160
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500161 ${time}= Set Variable If '${cert_format}' == 'Expired Certificate' -10 365
162 ${cert_file_path}= Generate Certificate File Via Openssl ${cert_format} ${time}
George Keishingbf17fab2019-06-13 09:22:22 -0500163 ${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
164 ${file_data}= Decode Bytes To String ${bytes} UTF-8
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500165
Rahul Maheshwari479c9c52019-06-03 01:23:12 -0500166 ${certificate_uri}= Set Variable If
167 ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI}
168 ... '${cert_type}' == 'CA' ${REDFISH_CA_CERTIFICATE_URI}
169
170 Install Certificate File On BMC ${certificate_uri} ${expected_status} data=${file_data}
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500171
172 # Adding delay after certificate installation.
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -0500173 Sleep 30s
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500174
175 ${cert_file_content}= OperatingSystem.Get File ${cert_file_path}
176 ${bmc_cert_content}= Run Keyword If '${expected_status}' == 'ok' redfish_utils.Get Attribute
Rahul Maheshwari479c9c52019-06-03 01:23:12 -0500177 ... ${certificate_uri}/1 CertificateString
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500178
179 Run Keyword If '${expected_status}' == 'ok' Should Contain ${cert_file_content} ${bmc_cert_content}
180
181
Rahul Maheshwari479c9c52019-06-03 01:23:12 -0500182Install Certificate File On BMC
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500183 [Documentation] Install certificate file in BMC using POST operation.
184 [Arguments] ${uri} ${status}=ok &{kwargs}
185
186 # Description of argument(s):
187 # uri URI for installing certificate file via REST
188 # e.g. "/xyz/openbmc_project/certs/server/https".
189 # status Expected status of certificate installation via REST
190 # e.g. error, ok.
191 # kwargs A dictionary of keys/values to be passed directly to
192 # POST Request.
193
194 Initialize OpenBMC quiet=${quiet}
195
196 ${headers}= Create Dictionary Content-Type=application/octet-stream
197 ... X-Auth-Token=${XAUTH_TOKEN}
198 Set To Dictionary ${kwargs} headers ${headers}
199
200 ${ret}= Post Request openbmc ${uri} &{kwargs}
201
202 Run Keyword If '${status}' == 'ok'
203 ... Should Be Equal As Strings ${ret.status_code} ${HTTP_OK}
204 ... ELSE IF '${status}' == 'error'
205 ... Should Be Equal As Strings ${ret.status_code} ${HTTP_INTERNAL_SERVER_ERROR}
206
207 Delete All Sessions
208
209
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600210Replace Certificate Via Redfish
211 [Documentation] Test 'replace certificate' operation in the BMC via Redfish.
212 [Arguments] ${cert_type} ${cert_format} ${expected_status}
213
214 # Description of argument(s):
215 # cert_type Certificate type (e.g. "Server" or "Client").
216 # cert_format Certificate file format
217 # (e.g. Valid_Certificate_Valid_Privatekey).
218 # expected_status Expected status of certificate replace Redfish
219 # request (i.e. "ok" or "error").
220
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -0500221 # Install certificate before replacing client or CA certificate.
222 Run Keyword If '${cert_type}' == 'Client'
223 ... Install And Verify Certificate Via Redfish ${cert_type} Valid Certificate Valid Privatekey ok
224 ... ELSE IF '${cert_type}' == 'CA'
225 ... Install And Verify Certificate Via Redfish ${cert_type} Valid Certificate ok
Rahul Maheshwari9862eb52019-05-31 04:04:42 -0500226
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600227 redfish.Login
228
229 ${time}= Set Variable If '${cert_format}' == 'Expired Certificate' -10 365
230 ${cert_file_path}= Generate Certificate File Via Openssl ${cert_format} ${time}
231
George Keishingbf17fab2019-06-13 09:22:22 -0500232 ${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
233 ${file_data}= Decode Bytes To String ${bytes} UTF-8
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600234
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -0500235 ${certificate_uri}= Set Variable If
Rahul Maheshwaric142c092019-06-13 00:42:35 -0500236 ... '${cert_type}' == 'Server' ${REDFISH_HTTPS_CERTIFICATE_URI}/1
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -0500237 ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI}/1
238 ... '${cert_type}' == 'CA' ${REDFISH_CA_CERTIFICATE_URI}/1
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600239
240 ${certificate_dict}= Create Dictionary @odata.id=${certificate_uri}
241 ${payload}= Create Dictionary CertificateString=${file_data}
242 ... CertificateType=PEM CertificateUri=${certificate_dict}
Rahul Maheshwari19e6e442019-06-03 00:22:45 -0500243
244 ${expected_resp}= Set Variable If '${expected_status}' == 'ok' ${HTTP_OK}
245 ... '${expected_status}' == 'error' ${HTTP_INTERNAL_SERVER_ERROR}
Rahul Maheshwari9862eb52019-05-31 04:04:42 -0500246 ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate
Rahul Maheshwari19e6e442019-06-03 00:22:45 -0500247 ... body=${payload} valid_status_codes=[${expected_resp}]
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600248
249 ${cert_file_content}= OperatingSystem.Get File ${cert_file_path}
250 ${bmc_cert_content}= redfish_utils.Get Attribute ${certificate_uri} CertificateString
251
252 Run Keyword If '${expected_status}' == 'ok'
253 ... Should Contain ${cert_file_content} ${bmc_cert_content}
254 ... ELSE
255 ... Should Not Contain ${cert_file_content} ${bmc_cert_content}
256
257
Rahul Maheshwari1e0f6a82019-08-29 01:33:23 -0500258Generate CSR Via Redfish
259 [Documentation] Generate CSR using Redfish.
260 [Arguments] ${cert_type} ${key_pair_algorithm} ${key_bit_length} ${key_curv_id} ${expected_status}
261
262 # Description of argument(s):
263 # cert_type Certificate type ("Server" or "Client").
264 # key_pair_algorithm CSR key pair algorithm ("EC" or "RSA")
265 # key_bit_length CSR key bit length ("2048").
266 # key_curv_id CSR key curv id ("prime256v1" or "secp521r1" or "secp384r1").
267 # expected_status Expected status of certificate replace Redfish
268 # request ("ok" or "error").
269
270 redfish.Login
271
272 ${certificate_uri}= Set Variable If
273 ... '${cert_type}' == 'Server' ${REDFISH_HTTPS_CERTIFICATE_URI}/
274 ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI}/
275
276 ${certificate_dict}= Create Dictionary @odata.id=${certificate_uri}
277 ${payload}= Create Dictionary City=Austin CertificateCollection=${certificate_dict}
278 ... CommonName=${OPENBMC_HOST} Country=US Organization=IBM
279 ... OrganizationalUnit=ISL State=AU KeyBitLength=${key_bit_length}
280 ... KeyPairAlgorithm=${key_pair_algorithm} KeyCurveId=${key_curv_id}
281
282 # Remove not applicable field for CSR generation.
283 Run Keyword If '${key_pair_algorithm}' == 'EC' Remove From Dictionary ${payload} KeyBitLength
284 ... ELSE IF '${key_pair_algorithm}' == 'RSA' Remove From Dictionary ${payload} KeyCurveId
285
286 ${expected_resp}= Set Variable If '${expected_status}' == 'ok' ${HTTP_OK}
287 ... '${expected_status}' == 'error' ${HTTP_INTERNAL_SERVER_ERROR}, ${HTTP_BAD_REQUEST}
288 ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR
289 ... body=${payload} valid_status_codes=[${expected_resp}]
290
291 # Delay added between two CSR generation request.
292 Sleep 5s
293
294
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500295Delete Certificate Via BMC CLI
296 [Documentation] Delete certificate via BMC CLI.
297 [Arguments] ${cert_type}
298
299 # Description of argument(s):
300 # cert_type Certificate type (e.g. "Client" or "CA").
301
302 ${certificate_file_path} ${certificate_service} ${certificate_uri}=
303 ... Run Keyword If '${cert_type}' == 'Client'
304 ... Set Variable /etc/nslcd/certs/cert.pem phosphor-certificate-manager@nslcd.service
305 ... ${REDFISH_LDAP_CERTIFICATE_URI}
306 ... ELSE IF '${cert_type}' == 'CA'
307 ... Set Variable /etc/ssl/certs/Root-CA.pem phosphor-certificate-manager@authority.service
308 ... ${REDFISH_CA_CERTIFICATE_URI}
Rahul Maheshwaria5b17672019-05-30 11:08:30 -0500309
310 ${file_status} ${stderr} ${rc}= BMC Execute Command
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500311 ... [ -f ${certificate_file_path} ] && echo "Found" || echo "Not Found"
Rahul Maheshwaria5b17672019-05-30 11:08:30 -0500312
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500313 Return From Keyword If "${file_status}" != "Found"
314 BMC Execute Command rm ${certificate_file_path}
315 BMC Execute Command systemctl restart ${certificate_service}
316 Wait Until Keyword Succeeds 1 min 10 sec
317 ... Redfish.Get ${certificate_uri}/1 valid_status_codes=[${HTTP_INTERNAL_SERVER_ERROR}]
Rahul Maheshwaria5b17672019-05-30 11:08:30 -0500318
319
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600320Suite Setup Execution
321 [Documentation] Do suite setup tasks.
322
323 # Create certificate sub-directory in current working directory.
324 Create Directory certificate_dir
325
326
327Test Teardown Execution
328 [Documentation] Do the post test teardown.
329
330 FFDC On Test Case Fail
331 redfish.Logout