Skip to content

Instantly share code, notes, and snippets.

@moneeb777

moneeb777/tpm2.sh

Last active May 10, 2018
Embed
What would you like to do?
tpm2-tools setup
#!/bin/bash
set -e # Exit on error
## stable release links
tss="https://github.com/tpm2-software/tpm2-tss/archive/2.0.0_rc0.tar.gz"
abrmd="https://github.com/tpm2-software/tpm2-abrmd/archive/1.3.1.tar.gz"
tools="https://github.com/tpm2-software/tpm2-tools/archive/3.0.4.tar.gz"
sudo apt-get -qq -y install autoconf-archive libcmocka0 libcmocka-dev build-essential git pkg-config gcc g++ m4 libtool automake liburiparser-dev autoconf libgcrypt11-dev #> /dev/null
# install package manager deps for tools
sudo apt-get -qq -y install lcov pandoc autoconf-archive #> /dev/null
# Other deps for tpm2-tools
sudo apt-get -qq -y install libcurl4-openssl-dev python-pip libssl-dev #> /dev/null
pip install pyyaml
# install package manage deps for tss
sudo apt-get -qq -y install liburiparser-dev #> /dev/null
# install package manager deps for abrmd
# Note: the dbus-x11 dependency is for dbus-launch not for abrmd itself.
sudo apt-get -qq -y install libdbus-1-dev libglib2.0-dev dbus-x11 #> /dev/null
# Create systemuser tss for abrmd
if id "tss" >/dev/null 2>&1; then
echo "tss user already exists. Continuing..."
else
sudo useradd --system --user-group tss
fi
# install TSS
FOLDER="tpm2-tss"
if [ ! -d "$FOLDER" ] ; then
# Check for which version to use
if [ "$1" = '--stable' ] ; then
wget "$tss" -O "tss.tar.gz"
mkdir tpm2-tss
tar -xzf tss.tar.gz -C tpm2-tss --strip 1
rm -rf "tss.tar.gz"
else
git clone https://github.com/tpm2-software/tpm2-tss.git
fi
fi
cd tpm2-tss
./bootstrap
./configure --enable-unit
make -j2 check
sudo make -j2 install
cd ../
# Install abrmd
FOLDER="tpm2-abrmd"
if [ ! -d "$FOLDER" ] ; then
# Check for which version to use
if [ "$1" = '--stable' ] ; then
wget "$abrmd" -O "abrmd.tar.gz"
mkdir tpm2-abrmd
tar -xzf abrmd.tar.gz -C tpm2-abrmd --strip 1
rm -rf "abrmd.tar.gz"
else
git clone https://github.com/tpm2-software/tpm2-abrmd.git
fi
fi
cd tpm2-abrmd
./bootstrap
./configure --with-dbuspolicydir=/etc/dbus-1/system.d --with-systemdsystemunitdir=/lib/systemd/system --with-udevrulesdir=/etc/udev/rules.d
dbus-launch make -j2 check
sudo make -j2 install
cd ../
sudo ldconfig
# Install tools
FOLDER="tpm2-tools"
if [ ! -d "$FOLDER" ] ; then
if [ "$1" = '--stable' ] ; then
wget "$tools" -O "tools.tar.gz"
mkdir tpm2-tools
tar -xzf tools.tar.gz -C tpm2-tools --strip 1
rm -rf "tools.tar.gz"
else
git clone https://github.com/tpm2-software/tpm2-tools.git
fi
fi
cd tpm2-tools
./bootstrap
./configure --enable-unit
make -j2 check
sudo make -j2 install
cd ../
# Restart udev, dbus and systemd
sudo udevadm control --reload-rules && sudo udevadm trigger
sudo pkill -HUP dbus-daemon
systemctl daemon-reload
sudo ldconfig
# Install tpm2 simulator
wget https://downloads.sourceforge.net/project/ibmswtpm2/ibmtpm974.tar.gz
mkdir ibmtpm974
cd ibmtpm974
tar -xavf ../ibmtpm974.tar.gz
cd src
make -j2
# Starting simulator
./tpm_server &
# Starting abrmd
sudo -u tss tpm2-abrmd --tcti=libtss2-tcti-mssim.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment