mirror of
https://github.com/kairos-io/kcrypt.git
synced 2025-08-07 18:43:31 +00:00
Also unlock with TPM
so we can use the same functions everywhere just with a flag Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
parent
e73e33b26d
commit
94af8c8dd3
10
main.go
10
main.go
@ -55,9 +55,15 @@ func main() {
|
|||||||
UsageText: "unlock-all",
|
UsageText: "unlock-all",
|
||||||
Usage: "Try to unlock all LUKS partitions",
|
Usage: "Try to unlock all LUKS partitions",
|
||||||
Description: "Typically run during initrd to unlock all the LUKS partitions found",
|
Description: "Typically run during initrd to unlock all the LUKS partitions found",
|
||||||
ArgsUsage: "kcrypt unlock-all",
|
ArgsUsage: "kcrypt [--tpm] unlock-all",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "tpm",
|
||||||
|
Usage: "Use TPM to unlock the partition",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
return lib.UnlockAll()
|
return lib.UnlockAll(c.Bool("tpm"))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// UnlockAll Unlocks all encrypted devices found in the system
|
// UnlockAll Unlocks all encrypted devices found in the system
|
||||||
func UnlockAll() error {
|
func UnlockAll(tpm bool) error {
|
||||||
bus.Manager.Initialize()
|
bus.Manager.Initialize()
|
||||||
|
|
||||||
config, err := configpkg.GetConfiguration(configpkg.ConfigScanDirs)
|
config, err := configpkg.GetConfiguration(configpkg.ConfigScanDirs)
|
||||||
@ -52,10 +52,18 @@ func UnlockAll() error {
|
|||||||
// We mount it under /dev/mapper/DEVICE, so It's pretty easy to check
|
// We mount it under /dev/mapper/DEVICE, so It's pretty easy to check
|
||||||
if !utils.Exists(filepath.Join("/dev", "mapper", p.Name)) {
|
if !utils.Exists(filepath.Join("/dev", "mapper", p.Name)) {
|
||||||
fmt.Printf("Unmounted Luks found at '%s' LABEL '%s' \n", filepath.Join("/dev", p.Name), p.FilesystemLabel)
|
fmt.Printf("Unmounted Luks found at '%s' LABEL '%s' \n", filepath.Join("/dev", p.Name), p.FilesystemLabel)
|
||||||
|
if tpm {
|
||||||
|
out, err := utils.SH(fmt.Sprintf("/usr/lib/systemd/systemd-cryptsetup attach %s %s - tpm2-device=auto", p.Name, filepath.Join("/dev", p.Name)))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Unlocking failed: '%s'\n", err.Error())
|
||||||
|
fmt.Printf("Unlocking failed, command output: '%s'\n", out)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
err = UnlockDisk(p)
|
err = UnlockDisk(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Unlocking failed: '%s'\n", err.Error())
|
fmt.Printf("Unlocking failed: '%s'\n", err.Error())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Device %s seems to be mounted at %s, skipping\n", filepath.Join("/dev", p.Name), filepath.Join("/dev", "mapper", p.Name))
|
fmt.Printf("Device %s seems to be mounted at %s, skipping\n", filepath.Join("/dev", p.Name), filepath.Join("/dev", "mapper", p.Name))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user