3 # Utility Script to create a primary key
5 # It takes three arguments, a STORAGE HANDLE, the RH_OWNER Password and the KEY PASSWORD
11 echo "tpm2_startup --clear -T device --verbose"
12 tpm2_startup --clear -T device --verbose
13 if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
14 error=$(echo "TPM Startup failed"); flag="0";
15 echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
16 echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml;
21 #Check if Primary Key already exists
22 echo "tpm2_readpublic -H ${SRKHANDLE} --opu out_primary_public -T device --verbose"
23 tpm2_readpublic -H ${SRKHANDLE} --opu out_primary_public -T device -V
25 if [ $? -ne 0 ]; then echo; echo -e "${YELLOW} Primary Key does not exist, creating...";
27 echo "tpm2_createprimary -P ${O_PASSWORD} -K ${KEY_PASSWORD} -H o -g 0x000B
28 -G 0x0001 -T device -V -C PrimaryKeyBlob"
30 tpm2_createprimary -P ${O_PASSWORD} -K ${KEY_PASSWORD} -H o -g 0x000B \
31 -G 0x0001 -T device -V -C PrimaryKeyBlob
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;
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}"
47 tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S ${SRKHANDLE} \
48 -T device -V -P ${O_PASSWORD}
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;