File: fapi-nv-write-read.sh

package info (click to toggle)
tpm2-tools 5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,988 kB
  • sloc: ansic: 45,737; sh: 14,915; xml: 8,342; makefile: 610; python: 51
file content (201 lines) | stat: -rw-r--r-- 4,748 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

set -e
source helpers.sh

start_up

CRYPTO_PROFILE="RSA"
setup_fapi $CRYPTO_PROFILE

function cleanup {
    tss2 delete --path=/
    shut_down
}

trap cleanup EXIT

PW=abc
NV_PATH=/nv/Owner/myNVwrite
DATA_WRITE_FILE=$TEMP_DIR/nv_write_data.file
DATA_READ_FILE=$TEMP_DIR/nv_read_data.file
EMPTY_FILE=$TEMP_DIR/empty.file
BIG_FILE=$TEMP_DIR/big_file.file
LOG_FILE=$TEMP_DIR/log.file
touch $LOG_FILE

tss2 provision

echo 1234567890123456789 > $DATA_WRITE_FILE

tss2 createnv --path=$NV_PATH --type="noDa" --size=20 --authValue=""

tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE

echo "tss2 nvwrite with EMPTY_FILE" # Expected to succeed
tss2 nvwrite --nvPath=$NV_PATH --data=$EMPTY_FILE

echo "tss2 nvwrite with BIG_FILE" # Expected to fail
expect <<EOF
spawn sh -c "tss2 nvwrite --nvPath=$NV_PATH --data=$BIG_FILE 2> $LOG_FILE"
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    set file [open $LOG_FILE r]
    set log [read \$file]
    close $file
    send_user "[lindex \$log]\n"
    exit 1
}
EOF

if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  echo "Error: AddressSanitizer triggered."
  cat $LOG_FILE
  exit 1
fi

tss2 nvread --nvPath=$NV_PATH --data=$DATA_READ_FILE --force

if [ `cat $DATA_READ_FILE` !=  `cat $DATA_WRITE_FILE` ]; then
  echo "Test without password: Strings are not equal"
  exit 99
fi

tss2 delete --path=$NV_PATH

tss2 createnv --path=$NV_PATH --type="noDa" --size=20 --authValue=$PW

expect <<EOF
# Check if system asks for auth value and provide it
spawn tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE
expect {
    "Authorize object: " {
    } eof {
        send_user "The system has not asked for password\n"
        exit 1
    }
    }
    send "$PW\r"
    set ret [wait]
    if {[lindex \$ret 2] || [lindex \$ret 3]} {
        send_user "Passing password has failed\n"
        exit 1
    }
EOF

expect <<EOF
# Try with missing nvPath
spawn tss2 nvread --data=$DATA_READ_FILE --force
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    Command has not failed as expected\n"
    exit 1
}
EOF

expect <<EOF
# Try with missing data
spawn tss2 nvread --nvPath=$NV_PATH  --force
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    Command has not failed as expected\n"
    exit 1
}
EOF

expect <<EOF
# Try with multiple stdout (1)
spawn tss2 nvread --nvPath=$NV_PATH --data=- --logData=- --force
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    Command has not failed as expected\n"
    exit 1
}
EOF

expect <<EOF
# Try with multiple stdout (1)
spawn tss2 nvread --nvPath $NV_PATH --data - --logData - --force
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    Command has not failed as expected\n"
    exit 1
}
EOF

expect <<EOF
# Try with missing nvPath
spawn tss2 nvwrite --data=$DATA_WRITE_FILE
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    Command has not failed as expected\n"
    exit 1
}
EOF

expect <<EOF
# Try with missing data
spawn tss2 nvwrite --nvPath=$NV_PATH
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    Command has not failed as expected\n"
    exit 1
}
EOF

tss2 delete --path=$NV_PATH

NODA="noDa"
expect <<EOF
# Try interactive prompt
spawn tss2 createnv --path=$NV_PATH --type=$NODA --size=20
expect "Authorize object Password: "
send "$PW\r"
expect "Authorize object Retype password: "
send "$PW\r"
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
    send_user "Using interactive prompt with password has failed\n"
    exit 1
}
EOF

# Try with missing type
tss2 delete --path=$NV_PATH
tss2 createnv --path=$NV_PATH --size=20 --authValue=$PW

# Try with size-0 supported types
tss2 delete --path=$NV_PATH
tss2 createnv --path=$NV_PATH --type="bitfield" --size=0 --authValue=$PW
tss2 delete --path=$NV_PATH
tss2 createnv --path=$NV_PATH --type="pcr" --size=0 --authValue=$PW
tss2 delete --path=$NV_PATH
tss2 createnv --path=$NV_PATH --type="counter" --size=0 --authValue=$PW
tss2 delete --path=$NV_PATH
tss2 createnv --path=$NV_PATH --type="bitfield" --authValue=$PW
tss2 delete --path=$NV_PATH
tss2 createnv --path=$NV_PATH --type="pcr" --authValue=$PW
tss2 delete --path=$NV_PATH
tss2 createnv --path=$NV_PATH --type="counter" --authValue=$PW
tss2 delete --path=$NV_PATH

expect <<EOF
# Try with missing size and no type
spawn tss2 createnv --path=$NV_PATH --authValue=$PW
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    Command has not failed as expected\n"
    exit 1
}
EOF

expect <<EOF
# Try with size=0 and no type
spawn tss2 createnv --path=$NV_PATH --size=0 --authValue=$PW
set ret [wait]
if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
    Command has not failed as expected\n"
    exit 1
}
EOF

exit 0