blob: 6bd2c32d33fea8a1edd3d7f7a25cd08a0883832a [file] [log] [blame]
Pramod Raghavendra Jayathirth51449da2018-08-02 10:41:31 -07001#!/bin/sh
2
3# 1.Environmental variables
4
5# 1.a Location of Shared volume and Node's name
6# These varaibles has to be made avaialble to this script
7
8echo "Shared Volume location is $ABRMD_DATA"
9echo "Node name is $TPM_NODE_NAME"
10
11# 2. Create the directory with the host's name to store the output of Init tool
12# This is demarcate the generated files which are specific to this host's TPM
13srkhandle="$(cat ${ABRMD_DATA}/host_${TPM_NODE_NAME}/srkhandle)"
14passphrase="$(cat ${ABRMD_DATA}/host_${TPM_NODE_NAME}/password-passphrase)"
15echo "${passphrase}" | gpg --batch --yes --passphrase-fd 0 password.txt.gpg
16password="$(cat ${ABRMD_DATA}/host_${TPM_NODE_NAME}/password.txt)"
17
18# 3. Create initial Flag values which are reset upon failure
19error="NULL"
20flag="1"
21
22# 4. TPM initialize
23echo "tpm2_startup -clear -T tabrmd -V"
24tpm2_startup -clear -T tabrmd -V
25if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
26error=$(echo "TPM Startup failed"); flag="0";
27echo "flag:${flag}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
28echo "error:${error}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
29exit 1;
30fi
31echo ""
32
33# 5. Take ownership
34echo "tpm2_takeownership -o new -e new -l new -T tabrmd -V"
35tpm2_takeownership -o new -e new -l new -T tabrmd -V
36if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
37error=$(echo "Error:TPM ownership acquire failed");flag="0";
38echo "flag:${flag}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
39echo "error:${error}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
40echo "$error"; exit 1;
41fi
42echo ""
43
44# 6. Create Primary Key in RH_OWNER hierarchy
45rm -f PrimaryKeyBlob
46echo "tpm2_createprimary -P $password -A o -g 0x000B -G 0x0001 -T tabrmd -V -C PrimaryKeyBlob"
47tpm2_createprimary -P $password -A o -g 0x000B -G 0x0001 -T tabrmd -V -C PrimaryKeyBlob
48if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
49error=$(echo "Error: TPM create Primary key failed");
50echo "$error"; flag="0";
51echo "flag:${flag}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
52echo "error:${error}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
53exit 1;
54fi
55echo ""
56
57# 7. Store Primary Key in TPMs NV RAM
58echo "tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S ${srkhandle} -T tabrmd -V -P $password"
59tpm2_evictcontrol -A o -c ./PrimaryKeyBlob -S ${srkhandle} -T tabrmd -V -P $password
60if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
61error=$(echo "Error: Inserting Primary Key failed");
62echo "$error"; flag="0";
63echo "flag:${flag}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
64echo "errror:${error}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
65exit 1;
66fi
67echo ""
68rm -f PrimaryKeyBlob
69
70# 8. To test, Read public portion of TPM primary key with stored handle
71rm -f $out_primary_public
72echo "tpm2_readpublic -H ${srkhandle} --opu out_primary_public -T tabrmd -V"
73tpm2_readpublic -H ${srkhandle} --opu out_primary_public -T tabrmd -V
74if [ $? -ne 0 ]; then echo; echo -e "${RED}Error, Exit.";
75error=$(echo" Error:Reading Public part of Primary Key failed");
76echo "$error"; flag="0";
77echo "flag:${flag}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
78echo "error:${error}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml;
79exit 1;
80fi
81echo ""
82
83# 9. Update the tpm_status.yaml to report the status of this Script
84echo "flag:${flag}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml
85echo "error:${error}" >> ${ABRMD_DATA}/host_${TPM_NODE_NAME}/tpm_status.yaml
86
87# 10. Copy the public portion of the Primary key to the Shared volume
88# Use environment variable TPM_NODE_NAME
89cp out_parent_public ${ABRMD_DATA}/host_${TPM_NODE_NAME}