|
1 | 1 | *** Settings *** |
2 | 2 | Documentation Test thin-edge.io MQTT client authentication using a Hardware Security Module (HSM). |
3 | 3 | ... |
4 | | -... To do this, we install SoftHSM2 which allows us to create software-backed PKCS#11 (cryptoki) |
5 | | -... cryptographic tokens that will be read by thin-edge. In real production environments a dedicated |
6 | | -... hardware device would be used. |
| 4 | +... This suite focuses on testing selection and connecting to the cloud using different types of private |
| 5 | +... keys stored in PKCS#11 tokens. |
| 6 | +... |
| 7 | +... Uses SoftHSM2 to simulate a hardware security module for testing purposes. In real production |
| 8 | +... environments, a dedicated hardware device would be used. |
7 | 9 |
|
8 | 10 | # it would be good to explain here why we use the tedge-p11-server exclusively and not the module mode |
9 | 11 | Resource pkcs11_common.resource |
@@ -160,188 +162,8 @@ Can pass PIN in the request using device.key_pin |
160 | 162 |
|
161 | 163 | [Teardown] Execute Command tedge config unset device.key_pin |
162 | 164 |
|
163 | | -Can create a private key on the PKCS11 token |
164 | | - Execute Command cmd=softhsm2-util --init-token --free --label create-key-token --pin=123456 --so-pin=123456 |
165 | | - |
166 | | - ${output}= Execute Command |
167 | | - ... cmd=p11tool --login --set-pin=123456 --list-privkeys "pkcs11:token=create-key-token" |
168 | | - ... exp_exit_code=!0 |
169 | | - ... strip=True |
170 | | - ... stdout=False |
171 | | - ... stderr=True |
172 | | - Should Be Equal ${output} No matching objects found |
173 | | - |
174 | | - Set tedge-p11-server Uri value=pkcs11:token=create-key-token |
175 | | - |
176 | | - Create private key label=rsa-2048 type=rsa p11tool_keytype=RSA-2048 |
177 | | - Create private key |
178 | | - ... label=rsa-3072 |
179 | | - ... type=rsa |
180 | | - ... bits=3072 |
181 | | - ... p11tool_keytype=RSA-3072 |
182 | | - Create private key |
183 | | - ... label=rsa-4096 |
184 | | - ... type=rsa |
185 | | - ... bits=4096 |
186 | | - ... p11tool_keytype=RSA-4096 |
187 | | - |
188 | | - Create private key |
189 | | - ... label=ec-256 |
190 | | - ... type=ecdsa |
191 | | - ... curve=p256 |
192 | | - ... p11tool_keytype=EC/ECDSA-SECP256R1 |
193 | | - Create private key |
194 | | - ... label=ec-384 |
195 | | - ... type=ecdsa |
196 | | - ... curve=p384 |
197 | | - ... p11tool_keytype=EC/ECDSA-SECP384R1 |
198 | | - # ECDSA P521 not supported by rcgen |
199 | | - |
200 | | - [Teardown] Set tedge-p11-server Uri value= |
201 | | - |
202 | | -tedge cert create-key-hsm should ask where to create keypair if multiple tokens available |
203 | | - # setup multiple tokens |
204 | | - Execute Command cmd=softhsm2-util --init-token --free --label create-key-token1 --pin=123456 --so-pin=123456 |
205 | | - Execute Command cmd=softhsm2-util --init-token --free --label create-key-token2 --pin=123456 --so-pin=123456 |
206 | | - |
207 | | - # unset key_uri so there there's no hint where to generate the keypair |
208 | | - Execute Command cmd=tedge config unset device.key_uri |
209 | | - ${stderr}= Execute Command |
210 | | - ... cmd=tedge cert create-key-hsm --type ecdsa --label my-key |
211 | | - ... strip=True |
212 | | - ... stdout=False |
213 | | - ... stderr=True |
214 | | - ... exp_exit_code=1 |
215 | | - Should Contain ${stderr} No token URL was provided for this operation; the available tokens are: |
216 | | - Should Contain ${stderr} token=create-key-token1 |
217 | | - Should Contain ${stderr} token=create-key-token2 |
218 | | - |
219 | | -tedge cert create-key-hsm can set chosen id and returns error if object with this id already exists |
220 | | - ${output}= Execute Command |
221 | | - ... cmd=tedge cert create-key-hsm --type ecdsa --label my-key --id 010203 "pkcs11:token=tedge" |
222 | | - ... strip=True |
223 | | - ... stdout=False |
224 | | - ... stderr=True |
225 | | - Should Contain ${output} id=%01%02%03 |
226 | | - |
227 | | - ${output}= Execute Command |
228 | | - ... cmd=tedge cert create-key-hsm --type ecdsa --label my-key --id 010203 "pkcs11:token=tedge" |
229 | | - ... strip=True |
230 | | - ... stdout=False |
231 | | - ... stderr=True |
232 | | - ... exp_exit_code=!0 |
233 | | - Should Contain ${output} Object with this id already exists on the token |
234 | | - |
235 | | -tedge cert create-key-hsm can set pin per request |
236 | | - ${output}= Execute Command |
237 | | - ... cmd=tedge cert create-key-hsm --label my-key --pin 000000 "pkcs11:token=tedge" |
238 | | - ... strip=True |
239 | | - ... stdout=False |
240 | | - ... stderr=True |
241 | | - ... exp_exit_code=!0 |
242 | | - Should Contain ${output} The specified PIN is incorrect |
243 | | - |
244 | | -tedge cert create-key-hsm can save public key to file |
245 | | - ${output}= Execute Command |
246 | | - ... cmd=tedge cert create-key-hsm --label my-key --outfile-pubkey pubkey.pem "pkcs11:token=tedge" |
247 | | - ... strip=True |
248 | | - ... stdout=False |
249 | | - ... stderr=True |
250 | | - ${pubkey}= Execute Command cat pubkey.pem strip=True |
251 | | - Should Contain ${output} ${pubkey} |
252 | | - |
253 | | -Ignore tedge.toml if missing |
254 | | - Execute Command rm -f ./tedge.toml |
255 | | - ${stderr}= Execute Command tedge-p11-server --config-dir . --module-path xx.so exp_exit_code=!0 |
256 | | - # Don't log anything (this is normal behaviour as the user does not have to create a tedge.toml file) |
257 | | - Should Not Contain ${stderr} Failed to read ./tedge.toml: No such file |
258 | | - # And proceed |
259 | | - Should Contain ${stderr} Using cryptoki configuration |
260 | | - # Using default values |
261 | | - Should Contain ${stderr} tedge-p11-server.sock |
262 | | - |
263 | | -Ignore tedge.toml if empty |
264 | | - Execute Command touch ./tedge.toml |
265 | | - ${stderr}= Execute Command tedge-p11-server --config-dir . --module-path xx.so exp_exit_code=!0 |
266 | | - # Don't log anything (this is normal behaviour, where the file is used for tedge and not tedge-p11-server) |
267 | | - Should Not Contain ${stderr} Failed to parse ./tedge.toml: invalid TOML |
268 | | - # And proceed |
269 | | - Should Contain ${stderr} Using cryptoki configuration |
270 | | - # Using default values |
271 | | - Should Contain ${stderr} tedge-p11-server.sock |
272 | | - |
273 | | -Ignore tedge.toml if incomplete |
274 | | - Execute Command echo '[device]' >./tedge.toml |
275 | | - ${stderr}= Execute Command tedge-p11-server --config-dir . --module-path xx.so exp_exit_code=!0 |
276 | | - # Don't log anything (this is normal behaviour, where the file is used for tedge and not tedge-p11-server) |
277 | | - Should Not Contain ${stderr} Failed to parse ./tedge.toml: invalid TOML |
278 | | - Should Not Contain ${stderr} missing field `cryptoki` |
279 | | - # And proceed |
280 | | - Should Contain ${stderr} Using cryptoki configuration |
281 | | - # Using default values |
282 | | - Should Contain ${stderr} tedge-p11-server.sock |
283 | | - |
284 | | -Do not warn the user if tedge.toml is incomplete but not used |
285 | | - Execute Command rm -f ./tedge.toml |
286 | | - ${stderr}= Execute Command |
287 | | - ... tedge-p11-server --config-dir . --module-path xx.so --pin 11.pin --socket-path yy.sock --uri zz.uri |
288 | | - ... exp_exit_code=!0 |
289 | | - # Don't warn as all values are provided on the command line |
290 | | - Should Not Contain ${stderr} Failed to read ./tedge.toml: No such file |
291 | | - # And proceed |
292 | | - Should Contain ${stderr} Using cryptoki configuration |
293 | | - # Using the values provided on the command lin |
294 | | - Should Contain ${stderr} xx.so |
295 | | - Should Contain ${stderr} yy.sock |
296 | | - Should Contain ${stderr} zz.uri |
297 | | - |
298 | | -Warn the user if tedge.toml exists but cannot be read |
299 | | - Execute Command echo '[device.cryptoki]' >./tedge.toml |
300 | | - Execute Command chmod a-rw ./tedge.toml |
301 | | - ${stderr}= Execute Command |
302 | | - ... sudo -u tedge tedge-p11-server --config-dir . --module-path xx.so |
303 | | - ... exp_exit_code=!0 |
304 | | - # Warn the user |
305 | | - Should Contain ${stderr} Failed to read ./tedge.toml: Permission denied |
306 | | - # But proceed |
307 | | - Should Contain ${stderr} Using cryptoki configuration |
308 | | - |
309 | | -Warn the user if tedge.toml cannot be parsed |
310 | | - Execute Command rm -f ./tedge.toml |
311 | | - Execute Command echo '[corrupted toml ...' >./tedge.toml |
312 | | - ${stderr}= Execute Command tedge-p11-server --config-dir . --module-path xx.so exp_exit_code=!0 |
313 | | - # Warn the user |
314 | | - Should Contain ${stderr} Failed to parse ./tedge.toml: invalid TOML |
315 | | - # But proceed |
316 | | - Should Contain ${stderr} Using cryptoki configuration |
317 | | - |
318 | 165 |
|
319 | 166 | *** Keywords *** |
320 | | -Create private key |
321 | | - [Arguments] ${type} ${label} ${bits}=${EMPTY} ${curve}=${EMPTY} ${p11tool_keytype}=${EMPTY} |
322 | | - # create the private key on token and write CSR to device.csr_path |
323 | | - VAR ${command}= tedge cert create-key-hsm --label ${label} --type ${type} "pkcs11:token=create-key-token" |
324 | | - IF $bits |
325 | | - VAR ${command}= ${command} --bits ${bits} |
326 | | - END |
327 | | - IF $curve |
328 | | - VAR ${command}= ${command} --curve ${curve} |
329 | | - END |
330 | | - ${create_key_output}= Execute Command ${command} strip=True stderr=True stdout=False |
331 | | - |
332 | | - # check if key is created |
333 | | - ${output}= Execute Command |
334 | | - ... cmd=p11tool --login --set-pin=123456 --list-privkeys "pkcs11:token=create-key-token" |
335 | | - IF $p11tool_keytype |
336 | | - Should Contain ${output} Type: Private key (${p11tool_keytype}) |
337 | | - ELSE |
338 | | - Should Contain ${output} Type: Private key |
339 | | - END |
340 | | - Should Contain ${output} Label: ${label} |
341 | | - |
342 | | - ${key_uri}= Execute Command tedge config get device.key_uri strip=True |
343 | | - Should Contain ${create_key_output} ${key_uri} |
344 | | - |
345 | 167 | Test tedge cert renew |
346 | 168 | [Arguments] ${type} ${bits}=${EMPTY} ${curve}=${EMPTY} |
347 | 169 |
|
|
0 commit comments