@@ -611,16 +611,9 @@ tpm2_unseal() {
611611 fi
612612
613613 # tpm2 unseal will write the unsealed data to stdout and any errors to
614- # stderr. We capture the unsealed data to $file, but still log the errors for quiet mode.
615- # In case of unseal error, caller will also report on TOTP not being able to be unsealed.
616- TMP_ERR_FILE=$( mktemp)
614+ # stderr; capture stderr to log.
617615 if ! tpm2 unseal -Q -c " $handle " -p " session:$POLICY_SESSION$UNSEAL_PASS_SUFFIX " \
618- -S " $ENC_SESSION_FILE " > " $file " 2> " $TMP_ERR_FILE " ; then
619- # Log the contents of the temporary error file
620- while IFS= read -r line; do
621- LOG " tpm2 stderr: $line "
622- done < " $TMP_ERR_FILE "
623- rm -f " $TMP_ERR_FILE "
616+ -S " $ENC_SESSION_FILE " > " $file " 2> >( SINK_LOG " tpm2 stderr" ) ; then
624617 LOG " Unable to unseal secret from TPM NVRAM"
625618
626619 # should succeed, exit if it doesn't
@@ -672,15 +665,15 @@ tpm2_reset() {
672665 # output TPM Owner Password to a file to be reused in this boot session until recovery shell/reboot
673666 DEBUG " Caching TPM Owner Password to $SECRET_DIR /tpm_owner_password"
674667 echo -n " $tpm_owner_password " > " $SECRET_DIR /tpm_owner_password"
675- tpm2 clear -c platform > /dev/null 2>&1 || LOG " Unable to clear TPM on platform hierarchy "
676- tpm2 changeauth -c owner " $( tpm2_password_hex " $tpm_owner_password " ) " > /dev/null 2>&1 || LOG " Unable to change owner password "
677- tpm2 changeauth -c endorsement " $( tpm2_password_hex " $tpm_owner_password " ) " > /dev/null 2>&1 || LOG " Unable to change endorsement password "
678- tpm2 createprimary -C owner -g sha256 -G " ${CONFIG_PRIMARY_KEY_TYPE:- rsa} " \
679- -c " $SECRET_DIR /primary.ctx" -P " $( tpm2_password_hex " $tpm_owner_password " ) " > /dev/null 2>&1 || LOG " Unable to create primary key "
680- tpm2 evictcontrol -C owner -c " $SECRET_DIR /primary.ctx" " $PRIMARY_HANDLE " \
681- -P " $( tpm2_password_hex " $tpm_owner_password " ) " > /dev/null 2>&1 || LOG " Unable to evict primary key "
682- shred -u " $SECRET_DIR /primary.ctx" > /dev/null 2>&1
683- tpm2_startsession > /dev/null 2>&1 || LOG " Unable to start session "
668+ DO_WITH_DEBUG tpm2 clear -c platform & > /dev/null
669+ DO_WITH_DEBUG tpm2 changeauth -c owner " $( tpm2_password_hex " $tpm_owner_password " ) " & > /dev/null
670+ DO_WITH_DEBUG tpm2 changeauth -c endorsement " $( tpm2_password_hex " $tpm_owner_password " ) " & > /dev/null
671+ DO_WITH_DEBUG tpm2 createprimary -C owner -g sha256 -G " ${CONFIG_PRIMARY_KEY_TYPE:- rsa} " \
672+ -c " $SECRET_DIR /primary.ctx" -P " $( tpm2_password_hex " $tpm_owner_password " ) " & > /dev/null
673+ DO_WITH_DEBUG tpm2 evictcontrol -C owner -c " $SECRET_DIR /primary.ctx" " $PRIMARY_HANDLE " \
674+ -P " $( tpm2_password_hex " $tpm_owner_password " ) " & > /dev/null
675+ shred -u " $SECRET_DIR /primary.ctx" & > /dev/null
676+ DO_WITH_DEBUG tpm2_startsession & > /dev/null
684677
685678 # Set the dictionary attack parameters. TPM2 defaults vary widely, we
686679 # want consistent behavior on any TPM.
@@ -722,17 +715,17 @@ tpm1_reset() {
722715 DEBUG " Caching TPM Owner Password to $SECRET_DIR /tpm_owner_password"
723716 echo -n " $tpm_owner_password " > " $SECRET_DIR /tpm_owner_password"
724717 # Make sure the TPM is ready to be reset
725- tpm physicalpresence -s > /dev/null 2>&1 || LOG " Unable to assert physical presence "
726- tpm physicalenable > /dev/null 2>&1 || LOG " Unable to enable TPM "
727- tpm physicalsetdeactivated -c > /dev/null 2>&1 || LOG " Unable to deactivate TPM "
728- tpm forceclear > /dev/null 2>&1 || LOG " Unable to clear TPM "
729- tpm physicalenable > /dev/null 2>&1 || LOG " Unable to enable TPM "
730- tpm takeown -pwdo " $tpm_owner_password " > /dev/null 2>&1 || LOG " Unable to take ownership of TPM "
718+ DO_WITH_DEBUG tpm physicalpresence -s & > /dev/null
719+ DO_WITH_DEBUG tpm physicalenable & > /dev/null
720+ DO_WITH_DEBUG tpm physicalsetdeactivated -c & > /dev/null
721+ DO_WITH_DEBUG tpm forceclear & > /dev/null
722+ DO_WITH_DEBUG tpm physicalenable & > /dev/null
723+ DO_WITH_DEBUG tpm takeown -pwdo " $tpm_owner_password " & > /dev/null
731724
732725 # And now turn it all back on
733- tpm physicalpresence -s > /dev/null 2>&1 || LOG " Unable to assert physical presence "
734- tpm physicalenable > /dev/null 2>&1 || LOG " Unable to enable TPM "
735- tpm physicalsetdeactivated -c > /dev/null 2>&1 || LOG " Unable to deactivate TPM physical presence requirement "
726+ DO_WITH_DEBUG tpm physicalpresence -s & > /dev/null
727+ DO_WITH_DEBUG tpm physicalenable & > /dev/null
728+ DO_WITH_DEBUG tpm physicalsetdeactivated -c & > /dev/null
736729}
737730
738731# Perform final cleanup before boot and lock the platform heirarchy.
@@ -810,13 +803,9 @@ if [ "$CONFIG_TPM2_TOOLS" != "y" ]; then
810803 TRACE_FUNC
811804 LOG " TPM: Extending PCR[$3 ] with hash $hash "
812805
813- # Redirect the output of DO_WITH_DEBUG to a temporary file so we can LOG it in quiet mode
814- TMP_DEBUG_FILE=$( mktemp)
815- DO_WITH_DEBUG exec tpm " $@ " > " $TMP_DEBUG_FILE " 2>&1
816- while IFS= read -r line; do
817- LOG " $line "
818- done < " $TMP_DEBUG_FILE "
819- rm -f " $TMP_DEBUG_FILE "
806+ # Silence stdout/stderr, they're only useful for debugging
807+ # and DO_WITH_DEBUG captures them
808+ DO_WITH_DEBUG exec tpm " $@ " & > /dev/null
820809 ;;
821810 seal)
822811 shift
0 commit comments