blob: 6074b62309e1233d0e7ac0ce57ce4f951e2ce74a [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
16** Test Cases **
17
18Verify Server Certificate Replace
19 [Documentation] Verify server certificate replace.
20 [Tags] Verify_Server_Certificate_Replace
21 [Template] Replace Certificate Via Redfish
22
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050023 # cert_type cert_format expected_status
24 Server Valid Certificate Valid Privatekey ok
25 Server Empty Certificate Valid Privatekey error
26 Server Valid Certificate Empty Privatekey error
27 Server Empty Certificate Empty Privatekey error
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060028
29
30Verify Client Certificate Replace
31 [Documentation] Verify client certificate replace.
32 [Tags] Verify_Client_Certificate_Replace
33 [Template] Replace Certificate Via Redfish
34
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050035 # cert_type cert_format expected_status
36 Client Valid Certificate Valid Privatekey ok
37 Client Empty Certificate Valid Privatekey error
38 Client Valid Certificate Empty Privatekey error
39 Client Empty Certificate Empty Privatekey error
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060040
41
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -050042Verify CA Certificate Replace
43 [Documentation] Verify CA certificate replace.
44 [Tags] Verify_CA_Certificate_Replace
45 [Template] Replace Certificate Via Redfish
46
47 # cert_type cert_format expected_status
48 CA Valid Certificate ok
49 CA Empty Certificate error
50
51
Rahul Maheshwari037a3432019-05-23 00:55:40 -050052Verify Client Certificate Install
53 [Documentation] Verify client certificate install.
54 [Tags] Verify_Client_Certificate_Install
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050055 [Template] Install And Verify Certificate Via Redfish
Rahul Maheshwari037a3432019-05-23 00:55:40 -050056
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050057 # cert_type cert_format expected_status
58 Client Valid Certificate Valid Privatekey ok
59 Client Empty Certificate Valid Privatekey error
60 Client Valid Certificate Empty Privatekey error
61 Client Empty Certificate Empty Privatekey error
Rahul Maheshwari037a3432019-05-23 00:55:40 -050062
63
Rahul Maheshwari479c9c52019-06-03 01:23:12 -050064Verify CA Certificate Install
65 [Documentation] Verify CA certificate install.
66 [Tags] Verify_CA_Certificate_Install
67 [Template] Install And Verify Certificate Via Redfish
68
69 # cert_type cert_format expected_status
70 CA Valid Certificate ok
71 CA Empty Certificate error
72
73
Rahul Maheshwarifa95b092019-05-22 05:10:59 -050074Verify Server Certificate View Via Openssl
75 [Documentation] Verify server certificate via openssl command.
76 [Tags] Verify_Server_Certificate_View_Via_Openssl
77
78 redfish.Login
79
80 ${cert_file_path}= Generate Certificate File Via Openssl Valid Certificate Valid Privatekey
George Keishingbf17fab2019-06-13 09:22:22 -050081 ${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
82 ${file_data}= Decode Bytes To String ${bytes} UTF-8
Rahul Maheshwarifa95b092019-05-22 05:10:59 -050083
84 ${certificate_dict}= Create Dictionary
85 ... @odata.id=/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/1
86 ${payload}= Create Dictionary CertificateString=${file_data}
87 ... CertificateType=PEM CertificateUri=${certificate_dict}
88
89 ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate
90 ... body=${payload}
91
92 Wait Until Keyword Succeeds 2 mins 15 secs Verify Certificate Visible Via OpenSSL ${cert_file_path}
93
94
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -060095*** Keywords ***
96
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -050097Install And Verify Certificate Via Redfish
98 [Documentation] Install and verify certificate using Redfish.
99 [Arguments] ${cert_type} ${cert_format} ${expected_status}
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500100
101 # Description of argument(s):
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500102 # cert_type Certificate type (e.g. "Client" or "CA").
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500103 # cert_format Certificate file format
104 # (e.g. "Valid_Certificate_Valid_Privatekey").
105 # expected_status Expected status of certificate replace Redfish
106 # request (i.e. "ok" or "error").
107
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500108 redfish.Login
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500109 Delete Certificate Via BMC CLI ${cert_type}
110
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500111 ${time}= Set Variable If '${cert_format}' == 'Expired Certificate' -10 365
112 ${cert_file_path}= Generate Certificate File Via Openssl ${cert_format} ${time}
George Keishingbf17fab2019-06-13 09:22:22 -0500113 ${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
114 ${file_data}= Decode Bytes To String ${bytes} UTF-8
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500115
Rahul Maheshwari479c9c52019-06-03 01:23:12 -0500116 ${certificate_uri}= Set Variable If
117 ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI}
118 ... '${cert_type}' == 'CA' ${REDFISH_CA_CERTIFICATE_URI}
119
120 Install Certificate File On BMC ${certificate_uri} ${expected_status} data=${file_data}
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500121
122 # Adding delay after certificate installation.
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -0500123 Sleep 30s
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500124
125 ${cert_file_content}= OperatingSystem.Get File ${cert_file_path}
126 ${bmc_cert_content}= Run Keyword If '${expected_status}' == 'ok' redfish_utils.Get Attribute
Rahul Maheshwari479c9c52019-06-03 01:23:12 -0500127 ... ${certificate_uri}/1 CertificateString
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500128
129 Run Keyword If '${expected_status}' == 'ok' Should Contain ${cert_file_content} ${bmc_cert_content}
130
131
Rahul Maheshwari479c9c52019-06-03 01:23:12 -0500132Install Certificate File On BMC
Rahul Maheshwari037a3432019-05-23 00:55:40 -0500133 [Documentation] Install certificate file in BMC using POST operation.
134 [Arguments] ${uri} ${status}=ok &{kwargs}
135
136 # Description of argument(s):
137 # uri URI for installing certificate file via REST
138 # e.g. "/xyz/openbmc_project/certs/server/https".
139 # status Expected status of certificate installation via REST
140 # e.g. error, ok.
141 # kwargs A dictionary of keys/values to be passed directly to
142 # POST Request.
143
144 Initialize OpenBMC quiet=${quiet}
145
146 ${headers}= Create Dictionary Content-Type=application/octet-stream
147 ... X-Auth-Token=${XAUTH_TOKEN}
148 Set To Dictionary ${kwargs} headers ${headers}
149
150 ${ret}= Post Request openbmc ${uri} &{kwargs}
151
152 Run Keyword If '${status}' == 'ok'
153 ... Should Be Equal As Strings ${ret.status_code} ${HTTP_OK}
154 ... ELSE IF '${status}' == 'error'
155 ... Should Be Equal As Strings ${ret.status_code} ${HTTP_INTERNAL_SERVER_ERROR}
156
157 Delete All Sessions
158
159
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600160Replace Certificate Via Redfish
161 [Documentation] Test 'replace certificate' operation in the BMC via Redfish.
162 [Arguments] ${cert_type} ${cert_format} ${expected_status}
163
164 # Description of argument(s):
165 # cert_type Certificate type (e.g. "Server" or "Client").
166 # cert_format Certificate file format
167 # (e.g. Valid_Certificate_Valid_Privatekey).
168 # expected_status Expected status of certificate replace Redfish
169 # request (i.e. "ok" or "error").
170
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -0500171 # Install certificate before replacing client or CA certificate.
172 Run Keyword If '${cert_type}' == 'Client'
173 ... Install And Verify Certificate Via Redfish ${cert_type} Valid Certificate Valid Privatekey ok
174 ... ELSE IF '${cert_type}' == 'CA'
175 ... Install And Verify Certificate Via Redfish ${cert_type} Valid Certificate ok
Rahul Maheshwari9862eb52019-05-31 04:04:42 -0500176
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600177 redfish.Login
178
179 ${time}= Set Variable If '${cert_format}' == 'Expired Certificate' -10 365
180 ${cert_file_path}= Generate Certificate File Via Openssl ${cert_format} ${time}
181
George Keishingbf17fab2019-06-13 09:22:22 -0500182 ${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
183 ${file_data}= Decode Bytes To String ${bytes} UTF-8
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600184
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -0500185 ${certificate_uri}= Set Variable If
Rahul Maheshwaric142c092019-06-13 00:42:35 -0500186 ... '${cert_type}' == 'Server' ${REDFISH_HTTPS_CERTIFICATE_URI}/1
Rahul Maheshwaric1f43ed2019-06-03 01:00:16 -0500187 ... '${cert_type}' == 'Client' ${REDFISH_LDAP_CERTIFICATE_URI}/1
188 ... '${cert_type}' == 'CA' ${REDFISH_CA_CERTIFICATE_URI}/1
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600189
190 ${certificate_dict}= Create Dictionary @odata.id=${certificate_uri}
191 ${payload}= Create Dictionary CertificateString=${file_data}
192 ... CertificateType=PEM CertificateUri=${certificate_dict}
Rahul Maheshwari19e6e442019-06-03 00:22:45 -0500193
194 ${expected_resp}= Set Variable If '${expected_status}' == 'ok' ${HTTP_OK}
195 ... '${expected_status}' == 'error' ${HTTP_INTERNAL_SERVER_ERROR}
Rahul Maheshwari9862eb52019-05-31 04:04:42 -0500196 ${resp}= redfish.Post /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate
Rahul Maheshwari19e6e442019-06-03 00:22:45 -0500197 ... body=${payload} valid_status_codes=[${expected_resp}]
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600198
199 ${cert_file_content}= OperatingSystem.Get File ${cert_file_path}
200 ${bmc_cert_content}= redfish_utils.Get Attribute ${certificate_uri} CertificateString
201
202 Run Keyword If '${expected_status}' == 'ok'
203 ... Should Contain ${cert_file_content} ${bmc_cert_content}
204 ... ELSE
205 ... Should Not Contain ${cert_file_content} ${bmc_cert_content}
206
207
Rahul Maheshwarifa95b092019-05-22 05:10:59 -0500208Verify Certificate Visible Via OpenSSL
209 [Documentation] Checks if given certificate is visible via openssl's showcert command.
210 [Arguments] ${cert_file_path}
211
212 # Description of argument(s):
213 # cert_file_path Certificate file path.
214
215 ${cert_file_content}= OperatingSystem.Get File ${cert_file_path}
216 ${openssl_cert_content}= Get Certificate Content From BMC Via Openssl
217 Should Contain ${cert_file_content} ${openssl_cert_content}
218
219
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500220Delete Certificate Via BMC CLI
221 [Documentation] Delete certificate via BMC CLI.
222 [Arguments] ${cert_type}
223
224 # Description of argument(s):
225 # cert_type Certificate type (e.g. "Client" or "CA").
226
227 ${certificate_file_path} ${certificate_service} ${certificate_uri}=
228 ... Run Keyword If '${cert_type}' == 'Client'
229 ... Set Variable /etc/nslcd/certs/cert.pem phosphor-certificate-manager@nslcd.service
230 ... ${REDFISH_LDAP_CERTIFICATE_URI}
231 ... ELSE IF '${cert_type}' == 'CA'
232 ... Set Variable /etc/ssl/certs/Root-CA.pem phosphor-certificate-manager@authority.service
233 ... ${REDFISH_CA_CERTIFICATE_URI}
Rahul Maheshwaria5b17672019-05-30 11:08:30 -0500234
235 ${file_status} ${stderr} ${rc}= BMC Execute Command
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500236 ... [ -f ${certificate_file_path} ] && echo "Found" || echo "Not Found"
Rahul Maheshwaria5b17672019-05-30 11:08:30 -0500237
Rahul Maheshwari3ecd1a62019-06-03 01:44:34 -0500238 Return From Keyword If "${file_status}" != "Found"
239 BMC Execute Command rm ${certificate_file_path}
240 BMC Execute Command systemctl restart ${certificate_service}
241 Wait Until Keyword Succeeds 1 min 10 sec
242 ... Redfish.Get ${certificate_uri}/1 valid_status_codes=[${HTTP_INTERNAL_SERVER_ERROR}]
Rahul Maheshwaria5b17672019-05-30 11:08:30 -0500243
244
Rahul Maheshwarib4b8bb62019-03-04 23:56:10 -0600245Suite Setup Execution
246 [Documentation] Do suite setup tasks.
247
248 # Create certificate sub-directory in current working directory.
249 Create Directory certificate_dir
250
251
252Test Teardown Execution
253 [Documentation] Do the post test teardown.
254
255 FFDC On Test Case Fail
256 redfish.Logout