mirror of
https://github.com/kairos-io/kcrypt.git
synced 2025-08-11 18:22:11 +00:00
Minor fixups to the encryption process
This commit is contained in:
parent
d977bdf888
commit
5fbdc4d614
21
main.go
21
main.go
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -47,19 +46,11 @@ func luksUnlock(device, mapper, password string) error {
|
|||||||
}
|
}
|
||||||
defer dev.Close()
|
defer dev.Close()
|
||||||
|
|
||||||
// set LUKS flags before unlocking the volume
|
err = dev.Unlock(0, []byte(password), mapper)
|
||||||
if err := dev.FlagsAdd(luks.FlagAllowDiscards); err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnsealVolume+SetupMapper is equivalent of `cryptsetup open /dev/sda1 volumename`
|
|
||||||
volume, err := dev.UnsealVolume(0, []byte(password))
|
|
||||||
if err == luks.ErrPassphraseDoesNotMatch {
|
|
||||||
return fmt.Errorf("incorrect password")
|
|
||||||
} else if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return volume.SetupMapper(mapper)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func unlockDisk(b *block.Partition) error {
|
func unlockDisk(b *block.Partition) error {
|
||||||
@ -68,7 +59,7 @@ func unlockDisk(b *block.Partition) error {
|
|||||||
return fmt.Errorf("error retreiving password remotely: %w", err)
|
return fmt.Errorf("error retreiving password remotely: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return luksUnlock(fmt.Sprintf("/dev/%s", b.Name), b.UUID, pass)
|
return luksUnlock(fmt.Sprintf("/dev/%s", b.Name), b.Name, pass)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createLuks(dev, password, version string, cryptsetupArgs ...string) error {
|
func createLuks(dev, password, version string, cryptsetupArgs ...string) error {
|
||||||
@ -124,11 +115,11 @@ func luksify(label string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := luksUnlock(persistent, b.UUID, pass); err != nil {
|
if err := luksUnlock(persistent, b.Name, pass); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := sh(fmt.Sprintf("mkfs.ext4 %s -n %s", b.UUID, label))
|
out, err := sh(fmt.Sprintf("mkfs.ext4 %s -L %s", fmt.Sprintf("/dev/mapper/%s", b.Name), label))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("err: %w, out: %s", err, out)
|
return fmt.Errorf("err: %w, out: %s", err, out)
|
||||||
|
Loading…
Reference in New Issue
Block a user