@@ -23,6 +23,7 @@ import (
2323 "github.com/microsoft/azure-linux-image-tools/toolkit/tools/internal/safemount"
2424 "github.com/microsoft/azure-linux-image-tools/toolkit/tools/internal/shell"
2525 "github.com/microsoft/azure-linux-image-tools/toolkit/tools/internal/sliceutils"
26+ "github.com/microsoft/azure-linux-image-tools/toolkit/tools/internal/verityutils"
2627 "github.com/sirupsen/logrus"
2728 "go.opentelemetry.io/otel"
2829 "go.opentelemetry.io/otel/attribute"
@@ -620,7 +621,7 @@ func findIdentifiedPartition(partitions []diskutils.PartitionInfo, ref imagecust
620621 return partition , nil
621622}
622623
623- func customizeVerityImageHelper (ctx context.Context , buildDir string , rc * ResolvedConfig ,
624+ func customizeVerityImage (ctx context.Context , buildDir string , rc * ResolvedConfig ,
624625 buildImageFile string , partIdToPartUuid map [string ]string , shrinkHashPartition bool ,
625626 baseImageVerity []verityDeviceMetadata , readonlyPartUuids []string ,
626627 partitionsLayout []fstabEntryPartNum ,
@@ -670,7 +671,7 @@ func customizeVerityImageHelper(ctx context.Context, buildDir string, rc *Resolv
670671
671672 // Format hash partition.
672673 rootHash , err := verityFormat (loopback .DevicePath (), dataPartition .Path , hashPartition .Path ,
673- shrinkHashPartition , sectorSize , metadata .name )
674+ shrinkHashPartition , sectorSize , metadata .name , metadata . formatSettings )
674675 if err != nil {
675676 return nil , err
676677 }
@@ -696,8 +697,14 @@ func customizeVerityImageHelper(ctx context.Context, buildDir string, rc *Resolv
696697 }
697698
698699 // Format hash partition.
700+ formatSettings := verityFormatSettings {
701+ hashAlgorithm : imagecustomizerapi .DefaultVerityHashAlgorithm ,
702+ dataBlockSizeBytes : imagecustomizerapi .DefaultVerityDataBlockSize ,
703+ hashBlockSizeBytes : imagecustomizerapi .DefaultVerityHashBlockSize ,
704+ }
705+
699706 rootHash , err := verityFormat (loopback .DevicePath (), dataPartition .Path , hashPartition .Path ,
700- shrinkHashPartition , sectorSize , verityConfig .Name )
707+ shrinkHashPartition , sectorSize , verityConfig .Name , formatSettings )
701708 if err != nil {
702709 return nil , err
703710 }
@@ -711,6 +718,7 @@ func customizeVerityImageHelper(ctx context.Context, buildDir string, rc *Resolv
711718 hashDeviceMountIdType : verityConfig .HashDeviceMountIdType ,
712719 corruptionOption : verityConfig .CorruptionOption ,
713720 hashSignaturePath : verityConfig .HashSignaturePath ,
721+ formatSettings : formatSettings ,
714722 }
715723 verityMetadata = append (verityMetadata , metadata )
716724 verityUpdated = true
@@ -752,10 +760,17 @@ func customizeVerityImageHelper(ctx context.Context, buildDir string, rc *Resolv
752760}
753761
754762func verityFormat (diskDevicePath string , dataPartitionPath string , hashPartitionPath string , shrinkHashPartition bool ,
755- sectorSize uint64 , name string ,
763+ sectorSize uint64 , name string , formatSettings verityFormatSettings ,
756764) (string , error ) {
757765 // Write hash partition.
758- verityOutput , _ , err := shell .NewExecBuilder ("veritysetup" , "format" , dataPartitionPath , hashPartitionPath ).
766+ formatArgs := []string {
767+ "format" , dataPartitionPath , hashPartitionPath ,
768+ "--hash" , formatSettings .hashAlgorithm ,
769+ "--data-block-size" , fmt .Sprintf ("%d" , formatSettings .dataBlockSizeBytes ),
770+ "--hash-block-size" , fmt .Sprintf ("%d" , formatSettings .hashBlockSizeBytes ),
771+ }
772+
773+ verityOutput , _ , err := shell .NewExecBuilder ("veritysetup" , formatArgs ... ).
759774 LogLevel (logrus .DebugLevel , logrus .DebugLevel ).
760775 ErrorStderrLines (1 ).
761776 ExecuteCaptureOutput ()
@@ -781,10 +796,10 @@ func verityFormat(diskDevicePath string, dataPartitionPath string, hashPartition
781796 return "" , fmt .Errorf ("%w (device='%s'):\n %w" , ErrUpdateDisk , diskDevicePath , err )
782797 }
783798
784- // Calculate the size of the hash partition from it's superblock.
799+ // Calculate the size of the hash partition from its superblock.
785800 // In newer `veritysetup` versions, `veritysetup format` returns the size in its output. But that feature
786801 // is too new for now.
787- hashPartitionSizeInBytes , err := calculateHashFileSizeInBytes (hashPartitionPath )
802+ hashPartitionSizeInBytes , err := verityutils . CalculateHashFileSizeInBytes (hashPartitionPath )
788803 if err != nil {
789804 return "" , fmt .Errorf ("%w (partition='%s'):\n %w" , ErrCalculateHashSize , hashPartitionPath , err )
790805 }
@@ -859,3 +874,11 @@ func updateKernelArgsForVerity(buildDir string, diskPartitions []diskutils.Parti
859874
860875 return nil
861876}
877+
878+ func getVerityNames (verity []verityDeviceMetadata ) []string {
879+ verityNames := make ([]string , len (verity ))
880+ for i , v := range verity {
881+ verityNames [i ] = v .name
882+ }
883+ return verityNames
884+ }
0 commit comments