Merge "tpm tools for the below functionalities"
[aaf/sshsm.git] / tpm-util / initandverify / Init_and_create_tpm_primary.sh
1 #!/bin/sh
2
3 case "$1" in
4
5 --out-public)
6     out_primary_public=$2
7     ;;
8
9 --help)
10     echo "$0 [--out-public primaty_public_bin_file (optional)]"
11     exit 0
12     ;;
13
14 *)
15     out_primary_public="out_parent_public"
16     ;;
17
18 esac
19
20 #echo "out-public file: $out_primary_public"
21
22 # TPM initialize
23 echo "tpm2_startup -clear -T tabrmd -V"
24 tpm2_startup -clear -T tabrmd -V
25 if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit."; exit 1; fi
26 echo ""
27
28 # Take ownership
29 echo "tpm2_takeownership -o new -e new -l new -T tabrmd -V"
30 tpm2_takeownership -o new -e new -l new -T tabrmd -V
31 if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit."; exit 1; fi
32 echo ""
33
34 # Create Primary Key in RH_OWNER hierarchy
35 rm -f PrimaryKeyBlob
36 echo "tpm2_createprimary -P new -A o -g 0x000B -G 0x0001 -T tabrmd -V -C PrimaryKeyBlob"
37 tpm2_createprimary -P new -A o -g 0x000B -G 0x0001 -T tabrmd -V -C PrimaryKeyBlob
38 if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit."; exit 1; fi
39 echo ""
40
41 # Store Primary Key in TPMs NV RAM
42 echo "tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S 0x81000011 -T tabrmd -V -P new"
43 tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S 0x81000011 -T tabrmd -V -P new
44 if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit."; exit 1; fi
45 echo ""
46 rm -f PrimaryKeyBlob
47
48 # To test, Read public portion of TPM primary key with stored handle
49 rm -f $out_primary_public
50 echo "tpm2_readpublic -H 0x81000011 --opu $out_primary_public -T tabrmd -V"
51 tpm2_readpublic -H 0x81000011 --opu $out_primary_public -T tabrmd -V
52 if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit."; exit 1; fi
53 echo ""
54
55
56 # Some TPM commands to test
57 #tpm2_load -c PrimaryKeyBlob -u outPub -r outPriv -n ChildKeyName -C ContextChild
58