blob: fbd971bdd59eb18aa2d3585f014b034e93e63300 [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 Forissiere4129292022-11-08 10:45:23 +010017 "FAILED" {
18 info "!!! Error\n"
Sumit Garg45cf44c2021-12-24 17:02:25 +053019 exit 1
20 }
21 timeout {
22 info "!!! Timeout\n"
23 exit 1
24 }
25 "# "
26 }
27}
Jerome Forissiere4129292022-11-08 10:45:23 +010028proc run_cmd arg {
29 send -- [append arg " || fail\r"]
30}
Sumit Garg45cf44c2021-12-24 17:02:25 +053031info "Running: keyctl tests...\n"
Jerome Forissiere4129292022-11-08 10:45:23 +010032expect "# "
33send -- "function fail { echo FAILED ; }\r"
34expect "# "
35run_cmd "keyctl add trusted kmk \"new 32\" @u"
Sumit Garg45cf44c2021-12-24 17:02:25 +053036check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010037run_cmd "keyctl add encrypted evm \"new trusted:kmk 32\" @u"
Sumit Garg45cf44c2021-12-24 17:02:25 +053038check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010039run_cmd "keyctl pipe $tk_id > kmk.blob"
Sumit Garg45cf44c2021-12-24 17:02:25 +053040check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010041run_cmd "keyctl pipe $ek_id > evm.blob"
Sumit Garg45cf44c2021-12-24 17:02:25 +053042check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010043run_cmd "keyctl revoke $ek_id"
Sumit Garg45cf44c2021-12-24 17:02:25 +053044check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010045run_cmd "keyctl revoke $tk_id"
Sumit Garg45cf44c2021-12-24 17:02:25 +053046check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010047run_cmd "keyctl add trusted kmk \"load `cat kmk.blob`\" @u"
Sumit Garg45cf44c2021-12-24 17:02:25 +053048check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010049run_cmd "keyctl add encrypted evm \"load `cat evm.blob`\" @u"
Sumit Garg45cf44c2021-12-24 17:02:25 +053050check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010051run_cmd "keyctl pipe $tk_id > kmk.blob2"
Sumit Garg45cf44c2021-12-24 17:02:25 +053052check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010053run_cmd "keyctl pipe $ek_id > evm.blob2"
Sumit Garg45cf44c2021-12-24 17:02:25 +053054check_keyctl_result ek_id
Jerome Forissiere4129292022-11-08 10:45:23 +010055run_cmd "diff kmk.blob kmk.blob2"
Sumit Garg45cf44c2021-12-24 17:02:25 +053056check_keyctl_result tk_id
Jerome Forissiere4129292022-11-08 10:45:23 +010057run_cmd "diff evm.blob evm.blob2"
Sumit Garg45cf44c2021-12-24 17:02:25 +053058check_keyctl_result ek_id
59info "Status: keyctl tests successful\n"