mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-26 00:35:19 -04:00
add cryptsetup wrapper to core
Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
parent
bb56b46e21
commit
1b6ecf27ee
13 changed files with 215 additions and 18 deletions
57
coordinator/core/diskencryption.go
Normal file
57
coordinator/core/diskencryption.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// GetDiskUUID gets the disk's UUID.
|
||||
func (c *Core) GetDiskUUID() (string, error) {
|
||||
if err := c.encryptedDisk.Open(); err != nil {
|
||||
return "", fmt.Errorf("retrieving uuid of encrypted disk failed: cannot open disk: %w", err)
|
||||
}
|
||||
defer c.encryptedDisk.Close()
|
||||
uuid, err := c.encryptedDisk.UUID()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot retrieve uuid of disk: %w", err)
|
||||
}
|
||||
return uuid, nil
|
||||
}
|
||||
|
||||
// UpdateDiskPassphrase switches the initial random passphrase of the encrypted disk to a permanent passphrase.
|
||||
func (c *Core) UpdateDiskPassphrase(passphrase string) error {
|
||||
if err := c.encryptedDisk.Open(); err != nil {
|
||||
return fmt.Errorf("updating passphrase of encrypted disk failed: cannot open disk: %w", err)
|
||||
}
|
||||
defer c.encryptedDisk.Close()
|
||||
return c.encryptedDisk.UpdatePassphrase(passphrase)
|
||||
}
|
||||
|
||||
// EncryptedDisk manages the encrypted state disk.
|
||||
type EncryptedDisk interface {
|
||||
// Open prepares the underlying device for disk operations.
|
||||
Open() error
|
||||
// Close closes the underlying device.
|
||||
Close() error
|
||||
// UUID gets the device's UUID.
|
||||
UUID() (string, error)
|
||||
// UpdatePassphrase switches the initial random passphrase of the encrypted disk to a permanent passphrase.
|
||||
UpdatePassphrase(passphrase string) error
|
||||
}
|
||||
|
||||
type EncryptedDiskFake struct{}
|
||||
|
||||
func (f *EncryptedDiskFake) UUID() (string, error) {
|
||||
return "fake-disk-uuid", nil
|
||||
}
|
||||
|
||||
func (f *EncryptedDiskFake) UpdatePassphrase(passphrase string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *EncryptedDiskFake) Open() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *EncryptedDiskFake) Close() error {
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue