Documentation
¶
Overview ¶
Package fde provides a uniform Device interface for Full-Disk Encryption block devices, abstracting over LUKS, APFS FileVault 2, and plaintext (CLEAR) backends.
Both encrypted backends expose a Device whose ReadAt and WriteAt methods transparently decrypt and encrypt I/O using their respective volume keys. The CLEAR backend is a passthrough that applies no encryption.
Supported backends ¶
- LUKS 1/2 via github.com/go-fde/luks
- APFS FileVault 2 via github.com/go-fde/apfs
- Plaintext passthrough via github.com/go-fde/clear
Usage ¶
// Open a raw LUKS device:
dev, err := fde.OpenLUKS("/path/to/disk.luks", []byte("passphrase"))
// Stack APFS FDE on top of a QCOW2 virtual disk:
qdev, _ := qcow2.OpenDevice("/path/to/disk.qcow2")
dev, err := fde.OpenAPFSFrom(qdev, []byte("passphrase"))
// Auto-detect format and open:
dev, err := fde.Open(fde.Auto, "/path/to/disk", []byte("passphrase"))
Index ¶
- type Device
- func Create(kind Type, path string, passphrase []byte) (Device, error)
- func CreateFrom(kind Type, rw RW, passphrase []byte) (Device, error)
- func Open(kind Type, path string, passphrase []byte) (Device, error)
- func OpenAPFS(path string, passphrase []byte) (Device, error)
- func OpenAPFSFrom(rw RW, passphrase []byte) (Device, error)
- func OpenClear(path string) (Device, error)
- func OpenClearFrom(rw RW) (Device, error)
- func OpenFrom(kind Type, rw RW, passphrase []byte) (Device, error)
- func OpenLUKS(path string, passphrase []byte) (Device, error)
- func OpenLUKSFrom(rw RW, passphrase []byte) (Device, error)
- type RW
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device interface {
io.ReaderAt
WriteAt(p []byte, off int64) (int, error)
// Size returns the byte length of the plaintext payload.
// Returns 0 when the size is not exposed by the backend (APFS).
Size() int64
// Close releases all resources held by the device.
Close() error
}
Device is the uniform interface exposed by all FDE backends. ReadAt and WriteAt transparently decrypt and encrypt data using the volume key.
LUKS offsets are relative to the start of the plaintext payload. APFS offsets are absolute (relative to the start of the container device).
func Create ¶
Create initialises a new FDE container of the given type at path, encrypting it with passphrase. The file must already exist. Returns an opened Device ready for payload I/O. For CLEAR, no initialisation is performed; the file is opened as a passthrough device.
func CreateFrom ¶
CreateFrom initialises a new FDE container of the given type on rw, encrypting it with passphrase. Returns an opened Device ready for payload I/O. For CLEAR, no initialisation is performed; rw is wrapped as a passthrough device.
func Open ¶
Open opens an FDE device of the given type at path, unlocking it with passphrase. It dispatches based on kind; when kind is Auto the format is detected from the file header. For CLEAR devices passphrase is ignored.
func OpenAPFS ¶
OpenAPFS opens the FileVault 2-encrypted APFS container at path, unlocking it with passphrase. path may be a raw disk image or block device file.
func OpenAPFSFrom ¶
OpenAPFSFrom opens a FileVault 2 APFS container on top of an existing block device rw, unlocking it with passphrase. Close on the returned Device also closes rw.
func OpenClear ¶
OpenClear opens the plaintext block device at path as a passthrough Device. No decryption is applied; I/O is forwarded directly to the file.
func OpenClearFrom ¶
OpenClearFrom wraps rw as a passthrough Device with no encryption.
func OpenFrom ¶
OpenFrom opens an FDE device of the given type on top of rw, unlocking it with passphrase. When kind is Auto the format is detected from rw's header. For CLEAR devices passphrase is ignored.
func OpenLUKS ¶
OpenLUKS opens the LUKS1/LUKS2 encrypted container at path, unlocking it with passphrase. path may be a raw disk image or block device file.
func OpenLUKSFrom ¶
OpenLUKSFrom opens a LUKS container on top of an existing block device rw, unlocking it with passphrase. This allows LUKS to be stacked on a QCOW2 device or any other RW backend. Close on the returned Device also closes rw.
type RW ¶
RW is the minimal read-write-close interface accepted by OpenLUKSFrom and OpenAPFSFrom. It allows FDE to be layered on top of any block device, such as a QCOW2 virtual disk.
