aboutsummaryrefslogtreecommitdiffstats
path: root/tpm-tools/initandverify/Sign_Verify_test.sh
blob: 660dff9badc200e3e1974699827ddb622a2eb861 (plain)
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
#!/bin/sh

echo "hello world.." > hello_tpm.txt

# Load the Child context in TPM
rm -f ChildKeyName ContextChild
tpm2_load -H 0x81000011 -u outPub -r outPriv -n ChildKeyName -C ContextChild

echo "tpm2_hash -H o -g 0x00B -I hello_tpm.txt -o hello_tpm_hash.bin -t outTicket"
rm -f hello_tpm_hash.bin outTicket
tpm2_hash -H o -g 0x00B -I hello_tpm.txt -o hello_tpm_hash.bin -t outTicket
echo ""

echo "tpm2_sign -c ContextChild -g 0x000B -m hello_tpm.txt -s hello_tpm.sig"
rm -f hello_tpm.sig
tpm2_sign -c ContextChild -g 0x000B -m hello_tpm.txt -s hello_tpm.sig
echo ""

echo "tpm2_verifysignature -c ContextChild -g 0x000b -m hello_tpm.txt -s hello_tpm.sig -t tk.sig"
rm -f tk.sig
tpm2_verifysignature -c ContextChild -g 0x000b -m hello_tpm.txt -s hello_tpm.sig -t tk.sig
echo ""

echo "Extracting signature from TPM format"
echo "dd if=hello_tpm.sig of=hello_tpm.sig.raw bs=1 skip=6 count=256"
rm -f hello_tpm.sig.raw
dd if=hello_tpm.sig of=hello_tpm.sig.raw bs=1 skip=6 count=256
echo ""

echo "openssl dgst -verify public.pem -keyform pem -sha256 -signature hello_tpm.sig.raw hello_tpm.txt"
openssl dgst -verify public.pem -keyform pem -sha256 -signature hello_tpm.sig.raw hello_tpm.txt
echo ""

rm -f hello_tpm_hash.bin outTicket tk.sig