Merge "tpm tools for the below functionalities"
[aaf/sshsm.git] / tpm-util / initandverify / Sign_Verify_test.sh
1 #!/bin/sh
2
3 echo "hello world.." > hello_tpm.txt
4
5 # Load the Child context in TPM
6 rm -f ChildKeyName ContextChild
7 tpm2_load -H 0x81000011 -u outPub -r outPriv -n ChildKeyName -C ContextChild
8
9 echo "tpm2_hash -H o -g 0x00B -I hello_tpm.txt -o hello_tpm_hash.bin -t outTicket"
10 rm -f hello_tpm_hash.bin outTicket
11 tpm2_hash -H o -g 0x00B -I hello_tpm.txt -o hello_tpm_hash.bin -t outTicket
12 echo ""
13
14 echo "tpm2_sign -c ContextChild -g 0x000B -m hello_tpm.txt -s hello_tpm.sig"
15 rm -f hello_tpm.sig
16 tpm2_sign -c ContextChild -g 0x000B -m hello_tpm.txt -s hello_tpm.sig
17 echo ""
18
19 echo "tpm2_verifysignature -c ContextChild -g 0x000b -m hello_tpm.txt -s hello_tpm.sig -t tk.sig"
20 rm -f tk.sig
21 tpm2_verifysignature -c ContextChild -g 0x000b -m hello_tpm.txt -s hello_tpm.sig -t tk.sig
22 echo ""
23
24 echo "Extracting signature from TPM format"
25 echo "dd if=hello_tpm.sig of=hello_tpm.sig.raw bs=1 skip=6 count=256"
26 rm -f hello_tpm.sig.raw
27 dd if=hello_tpm.sig of=hello_tpm.sig.raw bs=1 skip=6 count=256
28 echo ""
29
30 echo "openssl dgst -verify public.pem -keyform pem -sha256 -signature hello_tpm.sig.raw hello_tpm.txt"
31 openssl dgst -verify public.pem -keyform pem -sha256 -signature hello_tpm.sig.raw hello_tpm.txt
32 echo ""
33
34 rm -f hello_tpm_hash.bin outTicket tk.sig
35