blob: 546b4872c6d7d1f68fd3be21682ee39cc06c4302 [file] [log] [blame]
Sumit Garg45cf44c2021-12-24 17:02:25 +05301#!/usr/bin/expect -f
2#
3# This script test Linux trusted keys support using OP-TEE as a trust
4# source. The return code is 0 for success, >0 for error.
5#
6
Jerome Forissiere4129292022-11-08 10:45:23 +01007set timeout 5
Sumit Garg45cf44c2021-12-24 17:02:25 +05308set tk_id 0
9set ek_id 0
Jerome Forissiere4129292022-11-08 10:45:23 +010010# Wait for next prompt, dealing with key ID, failure message and timeout
Sumit Garg45cf44c2021-12-24 17:02:25 +053011proc check_keyctl_result arg {
12 expect {
Jerome Forissiere4129292022-11-08 10:45:23 +010013 -re {(\d+)\r} {
14 set ::$arg $expect_out(1,string)
Sumit Garg45cf44c2021-12-24 17:02:25 +053015 exp_continue
16 }
Jerome Forissier4d36aea2022-11-08 14:25:46 +010017 "add_key: No such device" {
18 info [join {"Skipping test due to 'No such device':"
19 "trusted keys are not supported"
20 "(missing driver? CFG_CORE_DYN_SHM=n?)\n"}]
21 exit 0
22 }
Jerome Forissiere4129292022-11-08 10:45:23 +010023 "FAILED" {
24 info "!!! Error\n"
Sumit Garg45cf44c2021-12-24 17:02:25 +053025 exit 1
26 }
27 timeout {
28 info "!!! Timeout\n"
29 exit 1
30 }
31 "# "
32 }
33}
Jerome Forissiere4129292022-11-08 10:45:23 +010034proc run_cmd arg {
35 send -- [append arg " || fail\r"]
36}
Sumit Garg45cf44c2021-12-24 17:02:25 +053037info "Running: keyctl tests...\n"
Jerome Forissiere4129292022-11-08 10:45:23 +010038expect "# "
39send -- "function fail { echo FAILED ; }\r"
40expect "# "
41run_cmd "keyctl add trusted kmk \"new 32\" @u"
Sumit Garg45cf44c2021-12-24 17:02:25 +053042check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010043run_cmd "keyctl add encrypted evm \"new trusted:kmk 32\" @u"
Sumit Garg45cf44c2021-12-24 17:02:25 +053044check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010045run_cmd "keyctl pipe $tk_id > kmk.blob"
Sumit Garg45cf44c2021-12-24 17:02:25 +053046check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010047run_cmd "keyctl pipe $ek_id > evm.blob"
Sumit Garg45cf44c2021-12-24 17:02:25 +053048check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010049run_cmd "keyctl revoke $ek_id"
Sumit Garg45cf44c2021-12-24 17:02:25 +053050check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010051run_cmd "keyctl revoke $tk_id"
Sumit Garg45cf44c2021-12-24 17:02:25 +053052check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010053run_cmd "keyctl add trusted kmk \"load `cat kmk.blob`\" @u"
Sumit Garg45cf44c2021-12-24 17:02:25 +053054check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010055run_cmd "keyctl add encrypted evm \"load `cat evm.blob`\" @u"
Sumit Garg45cf44c2021-12-24 17:02:25 +053056check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010057run_cmd "keyctl pipe $tk_id > kmk.blob2"
Sumit Garg45cf44c2021-12-24 17:02:25 +053058check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010059run_cmd "keyctl pipe $ek_id > evm.blob2"
Sumit Garg45cf44c2021-12-24 17:02:25 +053060check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010061run_cmd "diff kmk.blob kmk.blob2"
Sumit Garg45cf44c2021-12-24 17:02:25 +053062check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010063run_cmd "diff evm.blob evm.blob2"
Sumit Garg45cf44c2021-12-24 17:02:25 +053064check_keyctl_result ek_id
65info "Status: keyctl tests successful\n"