aboutsummaryrefslogtreecommitdiffstats
path: root/bin/abrmdcontainer/create_primary.sh
diff options
context:
space:
mode:
authorGirish Havaldar <hg0071052@techmahindra.com>2018-09-05 03:33:36 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-05 03:33:36 +0000
commitde6937a3e7939dbbdf4c303a513c8a03b14fc4c0 (patch)
tree67c3b47e88397a01c617c2b7172c41191f7e82a5 /bin/abrmdcontainer/create_primary.sh
parenta5c07a62289e05e3fc7ee0d3baa702c8c3299356 (diff)
parent72d45a672a5ea45439f9d4f630063e70872ed8cb (diff)
Merge "Modify initialization to remove ownership step"
Diffstat (limited to 'bin/abrmdcontainer/create_primary.sh')
-rwxr-xr-xbin/abrmdcontainer/create_primary.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/abrmdcontainer/create_primary.sh b/bin/abrmdcontainer/create_primary.sh
new file mode 100755
index 0000000..3d4f0f9
--- /dev/null
+++ b/bin/abrmdcontainer/create_primary.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# Utility Script to create a primary key
+# Uses TCTI as device
+# It takes three arguments, a STORAGE HANDLE, the RH_OWNER Password and the KEY PASSWORD
+SRKHANDLE=$1
+O_PASSWORD=$2
+KEY_PASSWORD=$3
+
+# TPM Startup
+echo "tpm2_startup --clear -T device --verbose"
+tpm2_startup --clear -T device --verbose
+if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
+error=$(echo "TPM Startup failed"); flag="0";
+echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
+echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml;
+exit 1;
+fi
+echo ""
+
+#Check if Primary Key already exists
+echo "tpm2_readpublic -H ${SRKHANDLE} --opu out_primary_public -T device --verbose"
+tpm2_readpublic -H ${SRKHANDLE} --opu out_primary_public -T device -V
+
+if [ $? -ne 0 ]; then echo; echo -e "${YELLOW} Primary Key does not exist, creating...";
+ rm -f PrimaryKeyBlob
+ echo "tpm2_createprimary -P ${O_PASSWORD} -K ${KEY_PASSWORD} -A o -g 0x000B
+ -G 0x0001 -T device -V -C PrimaryKeyBlob"
+
+ tpm2_createprimary -P ${O_PASSWORD} -K ${KEY_PASSWORD} -A o -g 0x000B \
+ -G 0x0001 -T device -V -C PrimaryKeyBlob
+
+ if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
+ error=$(echo "Error: TPM create Primary key failed");
+ echo "$error"; flag="0";
+ echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
+ echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml;
+ exit 1;
+ fi
+ echo ""
+
+
+ #Store Primary Key in TPMs NV RAM
+ echo "tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S ${SRKHANDLE}
+ -T device -V -P ${O_PASSWORD}"
+
+ tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S ${SRKHANDLE} \
+ -T device -V -P ${O_PASSWORD}
+
+ if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
+ error=$(echo "Error: Inserting Primary Key failed");
+ echo "$error"; flag="0";
+ echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
+ echo "errror:${error}" >> ${WORKDIR}/tpm_status.yaml;
+ rm -f PrimaryKeyBlob
+ exit 1;
+ fi
+ echo ""
+ rm -f PrimaryKeyBlob
+fi
+
+#END \ No newline at end of file