blob: f9d0b68fbc2c22210a344a869bbac9dddfbc59c4 [file] [log] [blame]
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -07001#!/bin/sh
2
Kiran Kamineni72d45a62018-08-28 16:24:42 -07003# Location of Shared volume and Node's name
4# These variables have to be made available to this script
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -07005
6echo "Shared Volume location is $ABRMD_DATA"
7echo "Node name is $TPM_NODE_NAME"
8
Kiran Kamineni72d45a62018-08-28 16:24:42 -07009# 1. Create the directory with the host's name to store the output of Init tool
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -070010# This is demarcate the generated files which are specific to this host's TPM
Kiran Kamineni72d45a62018-08-28 16:24:42 -070011mkdir -p ${ABRMD_DATA}/host_${TPM_NODE_NAME}
12WORKDIR=${ABRMD_DATA}/host_${TPM_NODE_NAME}
13cd ${WORKDIR}
14# /abrmd/cred will contain srk_handle and tpm owner hierarchy password
15# provided by the admin of the TPM node
16SRKHANDLE="$(cat /abrmd/cred/srk_handle | base64 -d)"
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -070017
Kiran Kamineni72d45a62018-08-28 16:24:42 -070018# 2. Create initial Flag values which are reset upon failure
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -070019error="NULL"
20flag="1"
21
Kiran Kamineni72d45a62018-08-28 16:24:42 -070022# 3. TPM Startup
23echo "tpm2_startup --clear -T device --verbose"
24tpm2_startup --clear -T device -V
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -070025if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
26error=$(echo "TPM Startup failed"); flag="0";
Kiran Kamineni72d45a62018-08-28 16:24:42 -070027echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
28echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml;
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -070029exit 1;
30fi
31echo ""
32
Kiran Kamineni72d45a62018-08-28 16:24:42 -070033# 4. Read public portion of TPM primary key with stored handle
34# It is expected that the Admin would have created this already
35# using the create_primary.sh script
36rm -f out_parent_public
37echo "tpm2_readpublic -H ${SRKHANDLE} --opu out_parent_public -T device -V"
38tpm2_readpublic -H ${SRKHANDLE} --opu out_parent_public -T device -V
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -070039if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
40error=$(echo" Error:Reading Public part of Primary Key failed");
41echo "$error"; flag="0";
Kiran Kamineni72d45a62018-08-28 16:24:42 -070042echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml;
43echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml;
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -070044exit 1;
45fi
46echo ""
47
Kiran Kamineni72d45a62018-08-28 16:24:42 -070048# 5. Update the tpm_status.yaml to report the status of this Script
49echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml
50echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml