@@ -235,14 +235,22 @@ tpm2_extend() {
235
235
while true ; do
236
236
case " $1 " in
237
237
-ix)
238
+ # store index and shift so -ic and -if can be processed
238
239
index=" $2 "
239
240
shift 2
240
241
;;
241
242
-ic)
243
+ # this is to extend the PCR with a hash of a multiword string, use array to pass multiple words in $2
244
+ # use array to pass multiple words in $2
245
+ string=$( echo -n " $2 " )
242
246
hash=" $( echo -n " $2 " | sha256sum | cut -d' ' -f1) "
247
+ TRACE_FUNC
248
+ DEBUG " TPM: Will extend PCR[$index ] with hash of string $string "
243
249
shift 2
244
250
;;
245
251
-if)
252
+ TRACE_FUNC
253
+ DEBUG " TPM: Will extend PCR[$index ] with hash of file content $2 "
246
254
hash=" $( sha256sum " $2 " | cut -d' ' -f1) "
247
255
shift 2
248
256
;;
@@ -253,7 +261,9 @@ tpm2_extend() {
253
261
done
254
262
tpm2 pcrextend " $index :sha256=$hash "
255
263
tpm2 pcrread " sha256:$index "
256
- DEBUG " TPM: Extended PCR[$index ] with $hash "
264
+
265
+ TRACE_FUNC
266
+ DEBUG " TPM: Extended PCR[$index ] with hash $hash "
257
267
}
258
268
259
269
tpm2_counter_read () {
@@ -767,7 +777,18 @@ if [ "$CONFIG_TPM2_TOOLS" != "y" ]; then
767
777
tpm1_destroy " $@ "
768
778
;;
769
779
extend)
770
- DEBUG " TPM: Extending PCR[$3 ] with $5 "
780
+ # check if we extend with a hash or a file
781
+ if [ " $4 " = " -if" ]; then
782
+ DEBUG " TPM: Will extend PCR[$3 ] hash content of file $5 "
783
+ hash=" $( sha1sum " $5 " | cut -d' ' -f1) "
784
+ elif [ " $4 " = " -ic" ]; then
785
+ string=$( echo -n " $5 " )
786
+ DEBUG " TPM: Will extend PCR[$3 ] with hash of filename $string "
787
+ hash=" $( echo -n " $5 " | sha1sum | cut -d' ' -f1) "
788
+ fi
789
+
790
+ TRACE_FUNC
791
+ DEBUG " TPM: Extending PCR[$3 ] with hash $hash "
771
792
DO_WITH_DEBUG exec tpm " $@ "
772
793
;;
773
794
seal)
@@ -808,6 +829,7 @@ calcfuturepcr)
808
829
replay_pcr " sha256" " $@ "
809
830
;;
810
831
extend)
832
+ TRACE_FUNC
811
833
DEBUG " TPM: Extending PCR[$2 ] with $4 "
812
834
tpm2_extend " $@ "
813
835
;;
0 commit comments