Blame Add-attestation-test-which-ensures-full-attestation-.patch

Javier Martinez Canillas af88e8
From 70733e919aaa72aa03cccf6cd453bbe0da752de1 Mon Sep 17 00:00:00 2001
Javier Martinez Canillas af88e8
From: jetwhiz <Charles.Munson@ll.mit.edu>
Javier Martinez Canillas af88e8
Date: Tue, 9 Apr 2019 17:57:36 -0400
Javier Martinez Canillas af88e8
Subject: [PATCH] Add attestation test, which ensures full attestation
Javier Martinez Canillas af88e8
 process works
Javier Martinez Canillas af88e8
Javier Martinez Canillas af88e8
Signed-off-by: jetwhiz <Charles.Munson@ll.mit.edu>
Javier Martinez Canillas af88e8
---
Javier Martinez Canillas af88e8
 test/system/test_attestation.sh | 125 ++++++++++++++++++++++++++++++++
Javier Martinez Canillas af88e8
 1 file changed, 125 insertions(+)
Javier Martinez Canillas af88e8
 create mode 100755 test/system/test_attestation.sh
Javier Martinez Canillas af88e8
Javier Martinez Canillas af88e8
diff --git a/test/system/test_attestation.sh b/test/system/test_attestation.sh
Javier Martinez Canillas af88e8
new file mode 100755
Javier Martinez Canillas af88e8
index 00000000000..ea9da13a419
Javier Martinez Canillas af88e8
--- /dev/null
Javier Martinez Canillas af88e8
+++ b/test/system/test_attestation.sh
Javier Martinez Canillas af88e8
@@ -0,0 +1,125 @@
Javier Martinez Canillas af88e8
+#!/bin/bash
Javier Martinez Canillas af88e8
+#;**********************************************************************;
Javier Martinez Canillas af88e8
+#
Javier Martinez Canillas af88e8
+# Copyright (c) 2019 Massachusetts Institute of Technology.
Javier Martinez Canillas af88e8
+# All rights reserved.
Javier Martinez Canillas af88e8
+#
Javier Martinez Canillas af88e8
+# Redistribution and use in source and binary forms, with or without
Javier Martinez Canillas af88e8
+# modification, are permitted provided that the following conditions are met:
Javier Martinez Canillas af88e8
+#
Javier Martinez Canillas af88e8
+# 1. Redistributions of source code must retain the above copyright notice,
Javier Martinez Canillas af88e8
+# this list of conditions and the following disclaimer.
Javier Martinez Canillas af88e8
+#
Javier Martinez Canillas af88e8
+# 2. Redistributions in binary form must reproduce the above copyright notice,
Javier Martinez Canillas af88e8
+# this list of conditions and the following disclaimer in the documentation
Javier Martinez Canillas af88e8
+# and/or other materials provided with the distribution.
Javier Martinez Canillas af88e8
+#
Javier Martinez Canillas af88e8
+# 3. Neither the name of Intel Corporation nor the names of its contributors
Javier Martinez Canillas af88e8
+# may be used to endorse or promote products derived from this software without
Javier Martinez Canillas af88e8
+# specific prior written permission.
Javier Martinez Canillas af88e8
+#
Javier Martinez Canillas af88e8
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Javier Martinez Canillas af88e8
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Javier Martinez Canillas af88e8
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Javier Martinez Canillas af88e8
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
Javier Martinez Canillas af88e8
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Javier Martinez Canillas af88e8
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Javier Martinez Canillas af88e8
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Javier Martinez Canillas af88e8
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Javier Martinez Canillas af88e8
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Javier Martinez Canillas af88e8
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
Javier Martinez Canillas af88e8
+# THE POSSIBILITY OF SUCH DAMAGE.
Javier Martinez Canillas af88e8
+#;**********************************************************************;
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+source test_helpers.sh
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+handle_ek=0x81010007
Javier Martinez Canillas af88e8
+handle_ak=0x81010008
Javier Martinez Canillas af88e8
+handle_nv=0x1500018
Javier Martinez Canillas af88e8
+handle_hier=0x40000001
Javier Martinez Canillas af88e8
+ek_alg=rsa
Javier Martinez Canillas af88e8
+ak_alg=rsa
Javier Martinez Canillas af88e8
+digestAlg=sha256
Javier Martinez Canillas af88e8
+signAlg=rsassa
Javier Martinez Canillas af88e8
+ownerpw=ownerpass
Javier Martinez Canillas af88e8
+endorsepw=endorsepass
Javier Martinez Canillas af88e8
+ekpw=ekpass
Javier Martinez Canillas af88e8
+akpw=akpass
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+file_input_data=secret.data
Javier Martinez Canillas af88e8
+file_input_key=nv.data
Javier Martinez Canillas af88e8
+output_ek_pub_pem=ekpub.pem
Javier Martinez Canillas af88e8
+output_ek_pub=ek.pub
Javier Martinez Canillas af88e8
+output_ak_pub_pem=akpub.pem
Javier Martinez Canillas af88e8
+output_ak_pub=ak.pub
Javier Martinez Canillas af88e8
+output_ak_priv=ak.priv
Javier Martinez Canillas af88e8
+output_ak_pub_name=ak.name
Javier Martinez Canillas af88e8
+output_mkcredential=mkcred.out
Javier Martinez Canillas af88e8
+output_actcredential=actcred.out
Javier Martinez Canillas af88e8
+output_quote=quote.out
Javier Martinez Canillas af88e8
+output_quotesig=quotesig.out
Javier Martinez Canillas af88e8
+output_quotepcr=quotepcr.out
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+cleanup() {
Javier Martinez Canillas af88e8
+  rm -f $output_ak_priv \
Javier Martinez Canillas af88e8
+        $file_input_data $file_input_key $output_ek_pub $output_ek_pub_pem $output_ak_pub \
Javier Martinez Canillas af88e8
+        $output_ak_pub_pem $output_ak_pub_name $output_mkcredential \
Javier Martinez Canillas af88e8
+        $output_actcredential $output_quote $output_quotesig $output_quotepcr rand.out 
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+  tpm2_pcrreset 16
Javier Martinez Canillas af88e8
+  tpm2_evictcontrol -Q -Ao -c $handle_ek 2>/dev/null || true
Javier Martinez Canillas af88e8
+  tpm2_evictcontrol -Q -Ao -c $handle_ak 2>/dev/null || true
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+  tpm2_nvrelease -Q -x $handle_nv -a $handle_hier -P "$ownerpw" 2>/dev/null || true
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+  tpm2_takeownership -c 2>/dev/null || true
Javier Martinez Canillas af88e8
+}
Javier Martinez Canillas af88e8
+trap cleanup EXIT
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+cleanup
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+echo "12345678" > $file_input_data
Javier Martinez Canillas af88e8
+echo "1234567890123456789012345678901" > $file_input_key
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+getrandom() {
Javier Martinez Canillas af88e8
+  tpm2_getrandom -Q -o rand.out $1
Javier Martinez Canillas af88e8
+  local file_size=`stat --printf="%s" rand.out`
Javier Martinez Canillas af88e8
+  loaded_randomness=`cat rand.out | xxd -p -c $file_size`
Javier Martinez Canillas af88e8
+}
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+tpm2_takeownership -o "$ownerpw" -e "$endorsepw"
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+# Key generation
Javier Martinez Canillas af88e8
+tpm2_getpubek -Q -H $handle_ek -g $ek_alg -f $output_ek_pub -P "$ekpw" -o "$ownerpw" -e "$endorsepw"
Javier Martinez Canillas af88e8
+tpm2_readpublic -Q -H $handle_ek -o $output_ek_pub_pem -f pem
Javier Martinez Canillas af88e8
+tpm2_getpubak -Q -E $handle_ek -k $handle_ak -g $ak_alg -D $digestAlg -s $signAlg -f $output_ak_pub -n $output_ak_pub_name -e "$endorsepw" -P "$akpw" -o "$ownerpw"
Javier Martinez Canillas af88e8
+tpm2_readpublic -Q -H $handle_ak -o $output_ak_pub_pem -f pem
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+# Validate keys (registrar)
Javier Martinez Canillas af88e8
+file_size=`stat --printf="%s" $output_ak_pub_name`
Javier Martinez Canillas af88e8
+loaded_key_name=`cat $output_ak_pub_name | xxd -p -c $file_size`
Javier Martinez Canillas af88e8
+tpm2_makecredential -Q -T none -e $output_ek_pub  -s $file_input_data -n $loaded_key_name -o $output_mkcredential 
Javier Martinez Canillas af88e8
+tpm2_activatecredential -Q -H $handle_ak -k $handle_ek -f $output_mkcredential -o $output_actcredential -P "$akpw" -e "$endorsepw"
Javier Martinez Canillas af88e8
+diff $file_input_data $output_actcredential
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+# Quoting
Javier Martinez Canillas af88e8
+tpm2_pcrreset -Q 16
Javier Martinez Canillas af88e8
+tpm2_pcrextend -Q 16:sha256=6ea40aa7267bb71251c1de1c3605a3df759b86b22fa9f62aa298d4197cd88a38
Javier Martinez Canillas af88e8
+tpm2_pcrlist -Q
Javier Martinez Canillas af88e8
+getrandom 20
Javier Martinez Canillas af88e8
+tpm2_quote -Q -k $handle_ak -L $digestAlg:15,16,22 -q $loaded_randomness -m $output_quote -s $output_quotesig -p $output_quotepcr -G $digestAlg -P "$akpw"
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+# Verify quote
Javier Martinez Canillas af88e8
+tpm2_checkquote -Q -c $output_ak_pub_pem -m $output_quote -s $output_quotesig -p $output_quotepcr -G $digestAlg -q $loaded_randomness
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+# Save U key from verifier
Javier Martinez Canillas af88e8
+tpm2_nvdefine -Q -x $handle_nv -a $handle_hier -s 32 -t "ownerread|policywrite|ownerwrite" -I "indexpass" -P "$ownerpw"
Javier Martinez Canillas af88e8
+tpm2_nvwrite -Q -x $handle_nv -a $handle_hier -P "$ownerpw" $file_input_key
Javier Martinez Canillas af88e8
+tpm2_nvread -Q -x $handle_nv -a $handle_hier -s 32 -P "$ownerpw"
Javier Martinez Canillas af88e8
+
Javier Martinez Canillas af88e8
+exit 0
Javier Martinez Canillas af88e8
-- 
Javier Martinez Canillas af88e8
2.21.0
Javier Martinez Canillas af88e8