Documentation
¶
Overview ¶
Package fde provides a uniform Device interface for Full-Disk Encryption block devices, abstracting over LUKS, APFS FileVault 2, BitLocker, and plaintext (CLEAR) backends.
The LUKS and APFS backends expose a Device whose ReadAt and WriteAt methods transparently decrypt and encrypt I/O using their respective volume keys. The BitLocker backend reads only: its WriteAt returns bitlocker.ErrReadOnly. 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
- BitLocker (Windows 7+, To Go), read-only, via github.com/go-fde/bitlocker
- 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 ¶
- Variables
- 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 OpenBitLocker(path string, passphrase []byte) (Device, error)
- func OpenBitLockerFrom(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 ¶
var ErrCreateBitLocker = errors.New("fde: BitLocker volumes cannot be created, the backend is read-only")
ErrCreateBitLocker is returned by Create and CreateFrom for BITLOCKER: the backend reads volumes Windows made and does not write new ones.
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). BitLocker offsets are those of the decrypted volume, which has the size of the 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 OpenBitLocker ¶
OpenBitLocker opens the BitLocker volume at path read-only, unlocking it with passphrase: a password, a recovery password ("123456-…"), the contents of a .BEK startup key file, or nil for a clear-key volume.
func OpenBitLockerFrom ¶
OpenBitLockerFrom opens a BitLocker volume on top of rw. BitLocker maps the whole device, so rw must tell its size: a Size() int64 method (as Device and most virtual disks have) or a Stat() like *os.File. 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.
type Type ¶
type Type int
Type identifies the FDE backend used by Create and CreateFrom.
const ( // LUKS selects the LUKS 1/2 backend. LUKS Type = iota // APFS selects the APFS FileVault 2 backend. APFS // CLEAR selects the plaintext passthrough backend (no encryption). CLEAR // Auto causes Open and OpenFrom to detect the format automatically. Auto // BITLOCKER selects the BitLocker backend (read-only). It comes after // Auto so that the values of the earlier constants do not change. BITLOCKER )
