#!/bin/sh
#
# Licensed Materials - Property of IBM
# Open Platform Trust Services - An open source TCG PTS
# (C) Copyright International Business Machines Corp. 2007
#
#
# e.g.
# ./getiml.sh x60 tpm12
#

if [ $# -lt 1 ]; then
    echo "USAGE: $0 dirname option"
    echo " option: tpm11 tpm12 "
    exit
fi

mkdir -p $1

if [ -f /usr/bin/tpm_quote ]; then
    UUID=00000000000000000000000000000078
    NONCE=83c5cacb20a590e5b48980598cc69f18068495de
    case "$2" in
	tpm11)
          echo "get QuoteInfo (TPM v1.1)"
          tpm_quote -u $UUID -p 0 -p 2 -p 4 -p 5 -p 8 -p 10  -n $NONCE > $1/quote.properties
        ;;
	tpm12)
          echo "get QuoteInfo (TPM v1.2)"
          tpm_quote -u $UUID -p 0 -p 2 -p 4 -p 5 -p 8 -p 10 -p 17  -n $NONCE > $1/quote.properties
	;;
	*)
	;;
    esac
fi

if [ -f /usr/sbin/tpm_version ]; then
  /usr/sbin/tpm_version > $1/tpm_version
fi

if [ ! -d /sys/kernel/security/tpm0 ]; then
    mount -t securityfs none /sys/kernel/security/ 
fi

if [ -d /sys/kernel/security/tpm0 ]; then
    echo "get BIOS IML"
    cat /sys/kernel/security/tpm0/ascii_bios_measurements > $1/ascii_bios_measurements
    cat /sys/kernel/security/tpm0/binary_bios_measurements > $1/binary_bios_measurements
    cat /sys/class/misc/tpm0/device/pcrs > $1/pcrs
fi

if [ -d /sys/kernel/security/ima ]; then
    echo "get IMA IML"
    cat /sys/kernel/security/ima/ascii_runtime_measurements > $1/ascii_runtime_measurements
    cat /sys/kernel/security/ima/binary_runtime_measurements > $1/binary_runtime_measurements
fi

echo "get BIOS info"
dmidecode > $1/dmidecode

#echo "create $1.tgz"
#tar cvfz $1.tgz ./$1/*

sync
echo "dir $1"
ls -l $1

echo "done"

# EOF
