blob: 3d4f0f93f723daccae8168aa8075cca1d46da5e6 [file] [log] [blame]
Kiran Kamineni72d45a62018-08-28 16:24:42 -07001#!/bin/sh
2
3# Utility Script to create a primary key
4# Uses TCTI as device
5# It takes three arguments, a STORAGE HANDLE, the RH_OWNER Password and the KEY PASSWORD
6SRKHANDLE=$1
7O_PASSWORD=$2
8KEY_PASSWORD=$3
9
10# TPM Startup
11echo "tpm2_startup --clear -T device --verbose"
12tpm2_startup --clear -T device --verbose
13if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
14error=$(echo "TPM Startup failed"); flag="0";
15echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
16echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml;
17exit 1;
18fi
19echo ""
20
21#Check if Primary Key already exists
22echo "tpm2_readpublic -H ${SRKHANDLE} --opu out_primary_public -T device --verbose"
23tpm2_readpublic -H ${SRKHANDLE} --opu out_primary_public -T device -V
24
25if [ $? -ne 0 ]; then echo; echo -e "${YELLOW} Primary Key does not exist, creating...";
26 rm -f PrimaryKeyBlob
27 echo "tpm2_createprimary -P ${O_PASSWORD} -K ${KEY_PASSWORD} -A o -g 0x000B
28 -G 0x0001 -T device -V -C PrimaryKeyBlob"
29
30 tpm2_createprimary -P ${O_PASSWORD} -K ${KEY_PASSWORD} -A o -g 0x000B \
31 -G 0x0001 -T device -V -C PrimaryKeyBlob
32
33 if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
34 error=$(echo "Error: TPM create Primary key failed");
35 echo "$error"; flag="0";
36 echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
37 echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml;
38 exit 1;
39 fi
40 echo ""
41
42
43 #Store Primary Key in TPMs NV RAM
44 echo "tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S ${SRKHANDLE}
45 -T device -V -P ${O_PASSWORD}"
46
47 tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S ${SRKHANDLE} \
48 -T device -V -P ${O_PASSWORD}
49
50 if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
51 error=$(echo "Error: Inserting Primary Key failed");
52 echo "$error"; flag="0";
53 echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
54 echo "errror:${error}" >> ${WORKDIR}/tpm_status.yaml;
55 rm -f PrimaryKeyBlob
56 exit 1;
57 fi
58 echo ""
59 rm -f PrimaryKeyBlob
60fi
61
62#END