Sumit Garg | 45cf44c | 2021-12-24 17:02:25 +0530 | [diff] [blame] | 1 | #!/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 | |
| 7 | set timeout 60 |
| 8 | set tk_id 0 |
| 9 | set ek_id 0 |
| 10 | proc check_keyctl_result arg { |
| 11 | expect { |
Jerome Forissier | f263e91 | 2022-01-05 09:02:08 +0100 | [diff] [blame] | 12 | -re "(\n)(\\d+)\r" { |
Sumit Garg | 45cf44c | 2021-12-24 17:02:25 +0530 | [diff] [blame] | 13 | set ::$arg $expect_out(2,string) |
| 14 | exp_continue |
| 15 | } |
| 16 | -re "Operation not permitted" { |
| 17 | info "keyctl failed: Operation not permitted\n" |
| 18 | exit 1 |
| 19 | } |
| 20 | -re "No such device" { |
| 21 | info "keyctl failed: Trusted Keys support missing\n" |
| 22 | exit 1 |
| 23 | } |
| 24 | -re "\n---" { |
| 25 | info "keyctl failed: mismatch\n" |
| 26 | exit 1 |
| 27 | } |
| 28 | timeout { |
| 29 | info "!!! Timeout\n" |
| 30 | exit 1 |
| 31 | } |
| 32 | "# " |
| 33 | } |
| 34 | } |
| 35 | info "Running: keyctl tests...\n" |
| 36 | send -- "keyctl add trusted kmk \"new 32\" @u\r" |
| 37 | check_keyctl_result tk_id |
| 38 | send -- "keyctl add encrypted evm \"new trusted:kmk 32\" @u\r" |
| 39 | check_keyctl_result ek_id |
| 40 | send -- "keyctl pipe $tk_id > kmk.blob\r" |
| 41 | check_keyctl_result tk_id |
| 42 | send -- "keyctl pipe $ek_id > evm.blob\r" |
| 43 | check_keyctl_result ek_id |
| 44 | send -- "keyctl revoke $ek_id\r" |
| 45 | check_keyctl_result ek_id |
| 46 | send -- "keyctl revoke $tk_id\r" |
| 47 | check_keyctl_result tk_id |
| 48 | send -- "keyctl add trusted kmk \"load `cat kmk.blob`\" @u\r" |
| 49 | check_keyctl_result tk_id |
| 50 | send -- "keyctl add encrypted evm \"load `cat evm.blob`\" @u\r" |
| 51 | check_keyctl_result ek_id |
| 52 | send -- "keyctl pipe $tk_id > kmk.blob2\r" |
| 53 | check_keyctl_result tk_id |
| 54 | send -- "keyctl pipe $ek_id > evm.blob2\r" |
| 55 | check_keyctl_result ek_id |
| 56 | send -- "diff kmk.blob kmk.blob2\r" |
| 57 | check_keyctl_result tk_id |
| 58 | send -- "diff evm.blob evm.blob2\r" |
| 59 | check_keyctl_result ek_id |
| 60 | info "Status: keyctl tests successful\n" |