aboutsummaryrefslogtreecommitdiffstats
path: root/bin/abrmdcontainer/initialize_tpm.sh
blob: f9d0b68fbc2c22210a344a869bbac9dddfbc59c4 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh

# Location of Shared volume and Node's name
# These variables have to be made available to this script

echo "Shared Volume location is $ABRMD_DATA"
echo "Node name is $TPM_NODE_NAME"

# 1. Create the directory with the host's name to store the output of Init tool
# This is demarcate the generated files which are specific to this host's TPM
mkdir -p ${ABRMD_DATA}/host_${TPM_NODE_NAME}
WORKDIR=${ABRMD_DATA}/host_${TPM_NODE_NAME}
cd ${WORKDIR}
# /abrmd/cred will contain srk_handle and tpm owner hierarchy password
# provided by the admin of the TPM node
SRKHANDLE="$(cat /abrmd/cred/srk_handle | base64 -d)"

# 2. Create initial Flag values which are reset upon failure
error="NULL"
flag="1"

# 3. TPM Startup
echo "tpm2_startup --clear -T device --verbose"
tpm2_startup --clear -T device -V
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 ""

# 4. Read public portion of TPM primary key with stored handle
#    It is expected that the Admin would have created this already
#    using the create_primary.sh script
rm -f out_parent_public
echo "tpm2_readpublic -H ${SRKHANDLE} --opu out_parent_public -T device -V"
tpm2_readpublic -H ${SRKHANDLE} --opu out_parent_public -T device -V
if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
error=$(echo" Error:Reading Public part of 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 ""

# 5. Update the tpm_status.yaml to report the status of this Script
echo "flag:${flag}" >> ${WORKDIR}/tpm_status.yaml
echo "error:${error}" >> ${WORKDIR}/tpm_status.yaml