/
test_smoking.sh
executable file
·297 lines (262 loc) · 8.09 KB
/
test_smoking.sh
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#;**********************************************************************;
#
# Copyright (c) 2016, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of Intel Corporation nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#;**********************************************************************;
#!/bin/sh
new_path=`dirname $0`
PATH="$PATH":"$new_path"
ekHandle=0x81010007
akHandle=0x81010008
fail()
{
echo "$1 test fail, please check the environment or parameters!"
exit 1
}
Pass()
{
echo ""$1" pass" >>test_getpubak_pass.log
}
rm *.out
tpm2_takeownership -c
if [ $? != 0 ];then
fail takeownership
fi
test_tpm2_nv.sh
tpm2_getpubek -H $ekHandle -g 0x01 -f ek.pub1.out
if [ $? != 0 ];then
fail getpubek
fi
tpm2_getpubak -E $ekHandle -k $akHandle -f ak.pub1.out -n ak.name_1.out |tee output_ak
if [ $? != 0 ] || [ ! -e ak.name_1.out ];then
fail getpubak
fi
grep -A 3 "Name of loaded key:" output_ak|tr "\n" " " >grep.txt
Loadkeyname=`sed -e 's/ //g' grep.txt | awk -F':' '{print $2}'`
echo 123456 | xxd -r -ps > secret.data
tpm2_makecredential -e ek.pub1.out -s secret.data -n $Loadkeyname -o makecredential.out
if [ $? != 0 ];then
fail makecredential
fi
tpm2_activatecredential -H $akHandle -k $ekHandle -f makecredential.out -o act_credential.out
if [ $? != 0 ];then
fail activatecredential
fi
tpm2_akparse -f ak.pub1.out -k akparse.out
if [ $? != 0 ];then
fail akparse
fi
##### getrandom & hash
tpm2_getrandom -o random.out 20
if [ $? != 0 ];then
fail getrandom
fi
tpm2_hash -H n -g 0x004 -I random.out -o hash.out -t hash_tk.out
if [ $? != 0 ];then
fail hash
fi
############context ##############
###unseal
tpm2_createprimary -A p -g 0x0004 -G 0x001 -C context.p1.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -c context.p1.out -g 0x000B -G 0x0008 -o opu1.out -O opr1.out -I secret.data
if [ $? != 0 ];then
fail create
fi
tpm2_load -c context.p1.out -u opu1.out -r opr1.out -n name.load.1.out -C context_load_out1.out
if [ $? != 0 ];then
fail load
fi
tpm2_unseal -c context_load_out1.out -o usl.data.out
if [ $? != 0 ];then
fail unseal
fi
#####quote
tpm2_createprimary -A p -g 0x000B -G 0x001 -C context.p2.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -c context.p2.out -g 0x000B -G 0x0008 -o opu2.out -O opr2.out
if [ $? != 0 ];then
fail create
fi
tpm2_load -c context.p2.out -u opu2.out -r opr2.out -n name.load_2.out -C context_load_out2.out
if [ $? != 0 ];then
fail load
fi
tpm2_quote -c context_load_out2.out -g 0x4 -l 16,17,18 -o quote_outFile.out
if [ $? != 0 ];then
fail quote
fi
######Hmac
tpm2_createprimary -A e -g 0x000B -G 0x0001 -C context.p3.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -c context.p3.out -g 0x000B -G 0x0008 -o opu3.out -O opr3.out
if [ $? != 0 ];then
fail create
fi
tpm2_load -c context.p3.out -u opu3.out -r opr3.out -n name.load.3.out -C context_load_out3.out
if [ $? != 0 ];then
fail load
fi
tpm2_hmac -c context_load_out3.out -g 0x00B -I secret.data -o hmac.out
if [ $? != 0 ];then
fail hmac
fi
######readpublic
tpm2_createprimary -A e -g 0x000B -G 0x0001 -C context.p4.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -c context.p4.out -g 0x000B -G 0x0008 -o opu4.out -O opr4.out
if [ $? != 0 ];then
fail create
fi
tpm2_load -c context.p4.out -u opu4.out -r opr4.out -n name.load.4.out -C context_load_out4.out
if [ $? != 0 ];then
fail load
fi
tpm2_readpublic -c context_load_out4.out -o rd-opu.out
if [ $? != 0 ];then
fail readpublic
fi
######evictcontrol
tpm2_createprimary -A e -g 0x000B -G 0x0001 -C context.p5.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -g 0x000B -G 0x0008 -o opu5.out -O opr5.out -c context.p5.out
if [ $? != 0 ];then
fail create
fi
tpm2_load -c context.p5.out -u opu5.out -r opr5.out -n name.load5.out -C context_load_out5.out
if [ $? != 0 ];then
fail load
fi
tpm2_evictcontrol -A o -c context_load_out5.out -S 0x81010003
if [ $? != 0 ];then
fail evictontronl
else
tpm2_evictcontrol -A o -H 0x81010003 -S 0x81010003
if [ $? != 0 ];then
fail evictcontrol_release_Handle
fi
fi
#####rsaencrypt & rsadecrypt
tpm2_createprimary -A e -g 0x000B -G 0x0001 -C context.p6.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -g 0x000B -G 0x0001 -o opu6.out -O opr6.out -c context.p6.out
if [ $? != 0 ];then
fail create
fi
tpm2_loadexternal -H n -u opu6.out -C context_loadexternal_out6.out
if [ $? != 0 ];then
fail loadexternal
fi
tpm2_rsaencrypt -c context_loadexternal_out6.out -I secret.data -o rsa_en.out
if [ $? != 0 ];then
fail rsa_encrypt
fi
tpm2_load -c context.p6.out -u opu6.out -r opr6.out -n name.load6.out -C context_load_out6.out
if [ $? != 0 ];then
fail load
fi
tpm2_rsadecrypt -c context_load_out6.out -I rsa_en.out -o rsa_de.out
if [ $? != 0 ];then
fail rsa_decrypt
fi
#####sign
tpm2_createprimary -A e -g 0x000B -G 0x0001 -C context.p7.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -g 0x000B -G 0x0008 -o opu7.out -O opr7.out -c context.p7.out
if [ $? != 0 ];then
fail create
fi
tpm2_load -c context.p7.out -u opu7.out -r opr7.out -n name.load7.out -C context_load_out7.out
if [ $? != 0 ];then
fail load
fi
tpm2_sign -c context_load_out7.out -g 0x00B -m secret.data -s sign.f.out
if [ $? != 0 ];then
fail sign
fi
tpm2_verifysignature -c context_load_out7.out -g 0x000B -m secret.data -s sign.f.out -t tickt_verify_sign.out
if [ $? != 0 ];then
fail verifysignature
fi
######encryptdecrypt
tpm2_createprimary -A e -g 0x000B -G 0x0001 -C context.p8.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -g 0x000B -G 0x0025 -o opu8.out -O opr8.out -c context.p8.out
if [ $? != 0 ];then
fail create
fi
tpm2_load -c context.p8.out -u opu8.out -r opr8.out -n name.load8.out -C context_load_out8.out
if [ $? != 0 ];then
fail load
fi
tpm2_encryptdecrypt -c context_load_out8.out -D NO -I secret.data -o endecrypt.out
if [ $? != 0 ];then
fail encrypt
fi
tpm2_encryptdecrypt -c context_load_out8.out -D YES -I endecrypt.out -o endecrypt_de.out
if [ $? != 0 ];then
fail decrypt
fi
######certify
tpm2_createprimary -A e -g 0x000B -G 0x0001 -C context.p9.out
if [ $? != 0 ];then
fail createprimary
fi
tpm2_create -g 0x000B -G 0x0001 -o opu9.out -O opr9.out -c context.p9.out
if [ $? != 0 ];then
fail create
fi
tpm2_load -c context.p9.out -u opu9.out -r opr9.out -n name.load9.out -C context_load_out9.out -d 3
if [ $? != 0 ];then
fail load
fi
tpm2_certify -C context.p9.out -c context_load_out9.out -g 0x000B -a attest.out -s certify_signature.out
if [ $? != 0 ];then
fail certify
fi
tpm2_listpcrs
if [ $? != 0 ];then
fail listpcrs
fi