~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to providers/plainbox-provider-tpm2/bin/test_tpm2_hmac.sh

  • Committer: Sylvain Pineau
  • Author(s): Sylvain Pineau
  • Date: 2016-05-09 22:02:27 UTC
  • mfrom: (4323.2.1 launchpad/tpm2-provider)
  • Revision ID: sylvain_pineau-20160509220227-wt2e8boo9ktitvzl
"automatic merge of lp:~sylvain-pineau/checkbox/tpm2-provider/ by tarmac [r=sylvain-pineau][bug=][author=sylvain-pineau]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
new_path=`pwd`
 
3
PATH="$PATH":"$new_path"
 
4
 
 
5
alg_primary_obj=0x000B
 
6
alg_primary_key=0x0001
 
7
alg_create_obj=0x000B
 
8
alg_create_key=0x0008
 
9
halg=0x000B
 
10
 
 
11
handle_hmac_key=0x81010013
 
12
 
 
13
file_primary_key_ctx=context.p_"$alg_primary_obj"_"$alg_primary_key"
 
14
file_hmac_key_pub=opu_"$alg_create_obj"_"$alg_create_key"
 
15
file_hmac_key_priv=opr_"$alg_create_obj"_"$alg_create_key"
 
16
file_hmac_key_name=name.load_"$alg_primary_obj"_"$alg_primary_key"-"$alg_create_obj"_"$alg_create_key"
 
17
file_hmac_key_ctx=ctx_load_out_"$alg_primary_obj"_"$alg_primary_key"-"$alg_create_obj"_"$alg_create_key"
 
18
file_hmac_output=hmac_"$file_hmac_key_ctx"
 
19
 
 
20
file_input_data=secret.data
 
21
 
 
22
fail()
 
23
{
 
24
            echo "$1 test fail, please check the environment or parameters!"
 
25
        exit 1
 
26
}
 
27
Pass()
 
28
{
 
29
            echo ""$1" pass" >>test_getpubak_pass.log
 
30
}
 
31
 
 
32
rm $file_primary_key_ctx $file_hmac_key_pub $file_hmac_key_priv $file_hmac_key_name $file_hmac_key_ctx  $file_hmac_output  -rf
 
33
 
 
34
if [ ! -e "$file_input_data" ]   
 
35
  then    
 
36
echo "12345678" > $file_input_data
 
37
fi 
 
38
 
 
39
tpm2_takeownership -c
 
40
 
 
41
tpm2_createprimary -A e -g $alg_primary_obj -G $alg_primary_key -C $file_primary_key_ctx
 
42
if [ $? != 0 ];then
 
43
         fail createprimary 
 
44
fi
 
45
tpm2_create -g $alg_create_obj -G $alg_create_key -o $file_hmac_key_pub -O $file_hmac_key_priv  -c $file_primary_key_ctx
 
46
if [ $? != 0 ];then
 
47
        fail create 
 
48
fi
 
49
 
 
50
tpm2_load -c $file_primary_key_ctx  -u $file_hmac_key_pub  -r $file_hmac_key_priv -n $file_hmac_key_name -C $file_hmac_key_ctx
 
51
if [ $? != 0 ];then
 
52
        fail load   
 
53
fi
 
54
 
 
55
tpm2_hmac  -c $file_hmac_key_ctx  -g $halg -I $file_input_data -o $file_hmac_output 
 
56
if [ $? != 0 ];then
 
57
        fail hmac 
 
58
fi
 
59
 
 
60
####handle test
 
61
rm -f $file_hmac_output  
 
62
tpm2_evictcontrol -A o -c $file_hmac_key_ctx -S $handle_hmac_key |tee evict.log
 
63
c1="$?"
 
64
grep "persistentHanlde: "$handle_hmac_key"" evict.log
 
65
c2="$?"
 
66
 
 
67
if [ $c1 != 0 ] || [ $c2 != 0  ];then
 
68
     fail evict
 
69
fi
 
70
 
 
71
tpm2_hmac  -k $handle_hmac_key  -g $halg -I $file_input_data -o $file_hmac_output 
 
72
if [ $? != 0 ];then
 
73
        fail hmac 
 
74
fi