2022-10-03 09:03:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2023-04-19 12:44:33 +00:00
|
|
|
"github.com/kairos-io/kcrypt/pkg/lib"
|
2022-10-03 09:03:48 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2022-11-15 13:09:56 +00:00
|
|
|
var Version = "v0.0.0-dev"
|
|
|
|
|
2022-10-03 09:03:48 +00:00
|
|
|
func main() {
|
|
|
|
app := &cli.App{
|
2022-11-15 13:09:56 +00:00
|
|
|
Name: "kairos-kcrypt",
|
|
|
|
Version: Version,
|
2022-10-05 21:09:04 +00:00
|
|
|
Author: "Ettore Di Giacinto",
|
2022-11-15 13:09:56 +00:00
|
|
|
Usage: "kairos escrow key agent component",
|
2022-10-03 09:03:48 +00:00
|
|
|
Description: ``,
|
2022-10-05 21:09:04 +00:00
|
|
|
UsageText: ``,
|
|
|
|
Copyright: "Ettore Di Giacinto",
|
2022-10-03 09:03:48 +00:00
|
|
|
Commands: []cli.Command{
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "encrypt",
|
|
|
|
Description: "Encrypts a partition",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
if c.NArg() != 1 {
|
|
|
|
return fmt.Errorf("requires 1 arg, the partition label")
|
|
|
|
}
|
2023-11-30 09:24:55 +00:00
|
|
|
out, err := lib.Luksify(c.Args().First())
|
2022-11-10 14:20:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(out)
|
|
|
|
return nil
|
2022-10-03 09:03:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
Name: "unlock-all",
|
|
|
|
UsageText: "unlock-all",
|
|
|
|
Usage: "Try to unlock all LUKS partitions",
|
|
|
|
Description: `
|
|
|
|
Typically run during initrd to unlock all the LUKS partitions found
|
|
|
|
`,
|
|
|
|
ArgsUsage: "kcrypt unlock-all",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
|
|
|
|
&cli.StringFlag{},
|
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
2023-04-19 12:44:33 +00:00
|
|
|
return lib.UnlockAll()
|
2022-10-03 09:03:48 +00:00
|
|
|
},
|
|
|
|
},
|
2023-11-30 09:24:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
Name: "extract-initrd",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
if c.NArg() != 2 {
|
|
|
|
return fmt.Errorf("requires 3 args. initrd,, dst")
|
|
|
|
}
|
|
|
|
return lib.ExtractInitrd(c.Args()[0], c.Args()[1])
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "inject-initrd",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
if c.NArg() != 3 {
|
|
|
|
return fmt.Errorf("requires 3 args. initrd, srcfile, dst")
|
|
|
|
}
|
|
|
|
return lib.InjectInitrd(c.Args()[0], c.Args()[1], c.Args()[2])
|
|
|
|
},
|
|
|
|
},
|
2022-10-03 09:03:48 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|