@@ -75,24 +75,17 @@ const (
75
75
EmptyPassword = ""
76
76
vaultKeyLength = 32 //Bytes
77
77
78
- // TpmSavedDiskSealingPcrs is the file that holds a copy of PCR values
78
+ // savedSealingPcrsFile is the file that holds a copy of PCR values
79
79
// at the time of generating and sealing the disk key into the TPM.
80
- TpmSavedDiskSealingPcrs = types .PersistStatusDir + "/sealingpcrs"
80
+ savedSealingPcrsFile = types .PersistStatusDir + "/sealingpcrs"
81
81
82
- // MeasurementLogSealSuccess is files that holds a copy of event log at the time
82
+ // measurementLogSealSuccess is files that holds a copy of event log at the time
83
83
// of generating/sealing the disk key into the TPM.
84
- MeasurementLogSealSuccess = types .PersistStatusDir + "/tpm_measurement_seal_success"
84
+ measurementLogSealSuccess = types .PersistStatusDir + "/tpm_measurement_seal_success"
85
85
86
- // MeasurementLogUnsealFail is files that holds a copy of event log at the time EVE
86
+ // measurementLogUnsealFail is files that holds a copy of event log at the time EVE
87
87
// fails to unseal the vault key from TPM.
88
- MeasurementLogUnsealFail = types .PersistStatusDir + "/tpm_measurement_unseal_fail"
89
-
90
- // TpmEvtLogSavePattern contains the pattern used to save event log files,
91
- // considering the case when multiple tpm devices are present.
92
- TpmEvtLogSavePattern = "%s-tpm%d"
93
-
94
- // TpmEvtLogCollectPattern contains the pattern used to collect event log files.
95
- TpmEvtLogCollectPattern = "%s-backup"
88
+ measurementLogUnsealFail = types .PersistStatusDir + "/tpm_measurement_unseal_fail"
96
89
97
90
// measurementLogFile is a kernel exposed variable that contains the
98
91
// TPM measurements and events log.
@@ -653,7 +646,7 @@ func SealDiskKey(key []byte, pcrSel tpm2.PCRSelection) error {
653
646
}
654
647
655
648
// save a snapshot of current PCR values
656
- if err := saveDiskKeySealingPCRs (TpmSavedDiskSealingPcrs ); err != nil {
649
+ if err := saveDiskKeySealingPCRs (savedSealingPcrsFile ); err != nil {
657
650
return fmt .Errorf ("saving snapshot of sealing PCRs failed: %w" , err )
658
651
}
659
652
@@ -673,7 +666,7 @@ func SealDiskKey(key []byte, pcrSel tpm2.PCRSelection) error {
673
666
}
674
667
675
668
// save a copy of the current measurement log
676
- if err := copyMeasurementLog (MeasurementLogSealSuccess ); err != nil {
669
+ if err := copyMeasurementLog (measurementLogSealSuccess ); err != nil {
677
670
return fmt .Errorf ("copying current TPM measurement log failed: %w" , err )
678
671
}
679
672
@@ -735,14 +728,14 @@ func UnsealDiskKey(pcrSel tpm2.PCRSelection) ([]byte, error) {
735
728
// We get here mostly because of RCPolicyFail error, so first try to save
736
729
// a copy of TPM measurement log, it comes handy for diagnosing the issue.
737
730
evtLogStat := "copied (failed unseal) TPM measurement log"
738
- if errEvtLog := copyMeasurementLog (MeasurementLogUnsealFail ); errEvtLog != nil {
731
+ if errEvtLog := copyMeasurementLog (measurementLogUnsealFail ); errEvtLog != nil {
739
732
// just report the failure, still give findMismatchingPCRs a chance so
740
733
// we can at least have some partial information about why unseal failed.
741
734
evtLogStat = fmt .Sprintf ("copying (failed unseal) TPM measurement log failed: %v" , errEvtLog )
742
735
}
743
736
744
737
// try to find out the mismatching PCR index
745
- mismatch , errPcrMiss := findMismatchingPCRs (TpmSavedDiskSealingPcrs )
738
+ mismatch , errPcrMiss := findMismatchingPCRs (savedSealingPcrsFile )
746
739
if errPcrMiss != nil {
747
740
return nil , fmt .Errorf ("UnsealWithSession failed: %w, %s, finding mismatching PCR failed: %v" , err , evtLogStat , errPcrMiss )
748
741
}
@@ -857,6 +850,14 @@ func pcrBankSHA256EnabledHelper() bool {
857
850
return err == nil
858
851
}
859
852
853
+ func getLogCopyPath (destination string , tpmIndex int ) string {
854
+ return fmt .Sprintf ("%s-tpm%d" , destination , tpmIndex )
855
+ }
856
+
857
+ func getLogBackupPath (destination string ) string {
858
+ return fmt .Sprintf ("%s-backup" , destination )
859
+ }
860
+
860
861
func getMappedTpmsPath () ([]string , error ) {
861
862
paths , err := filepath .Glob (syfsTpmDir )
862
863
if err != nil {
@@ -902,11 +903,11 @@ func backupCopiedMeasurementLogs() error {
902
903
903
904
leftToBackup := counted
904
905
for i := 0 ; i < counted ; i ++ {
905
- sealSuccessPath := fmt . Sprintf ( TpmEvtLogSavePattern , MeasurementLogSealSuccess , i )
906
- unsealFailPath := fmt . Sprintf ( TpmEvtLogSavePattern , MeasurementLogUnsealFail , i )
906
+ sealSuccessPath := getLogCopyPath ( measurementLogSealSuccess , i )
907
+ unsealFailPath := getLogCopyPath ( measurementLogUnsealFail , i )
907
908
if fileutils .FileExists (nil , sealSuccessPath ) && fileutils .FileExists (nil , unsealFailPath ) {
908
- sealSuccessBackupPath := fmt . Sprintf ( TpmEvtLogCollectPattern , sealSuccessPath )
909
- unsealFailBackupPath := fmt . Sprintf ( TpmEvtLogCollectPattern , unsealFailPath )
909
+ sealSuccessBackupPath := getLogBackupPath ( sealSuccessPath )
910
+ unsealFailBackupPath := getLogBackupPath ( unsealFailPath )
910
911
if err := os .Rename (sealSuccessPath , sealSuccessBackupPath ); err != nil {
911
912
fmt .Fprintf (os .Stderr , "failed to backup tpm%d \" seal success\" previously copied measurement log: %v" , i , err )
912
913
continue
@@ -935,8 +936,8 @@ func removeCopiedMeasurementLogs() error {
935
936
}
936
937
937
938
for i := 0 ; i < counted ; i ++ {
938
- sealSuccessPath := fmt . Sprintf ( TpmEvtLogSavePattern , MeasurementLogSealSuccess , i )
939
- unsealFailPath := fmt . Sprintf ( TpmEvtLogSavePattern , MeasurementLogUnsealFail , i )
939
+ sealSuccessPath := getLogCopyPath ( measurementLogSealSuccess , i )
940
+ unsealFailPath := getLogCopyPath ( measurementLogUnsealFail , i )
940
941
_ = os .Remove (sealSuccessPath )
941
942
_ = os .Remove (unsealFailPath )
942
943
}
@@ -958,7 +959,7 @@ func copyMeasurementLog(dstPath string) error {
958
959
continue
959
960
}
960
961
961
- copyPath := fmt . Sprintf ( TpmEvtLogSavePattern , dstPath , i )
962
+ copyPath := getLogCopyPath ( dstPath , i )
962
963
err = fileutils .WriteRename (copyPath , measurementLogContent )
963
964
if err != nil {
964
965
fmt .Fprintf (os .Stderr , "failed to copy stored measurement log file: %v" , err )
0 commit comments