Documentation
¶
Index ¶
- Variables
- func CreateFS(base any, aeadType *AeadType, log2n int, password, masterkey []byte, ...) ([]byte, error)
- func Passwd(base any, oldpass, newpass, masterkey []byte) ([]byte, error)
- func ReadPassword(fd int) []byte
- func ValidBase(base any) bool
- type AeadType
- type Conf
- type EncryptedFile
- func (e *EncryptedFile) Close() error
- func (e *EncryptedFile) Flush() (int, error)
- func (e *EncryptedFile) Read(buf []byte) (int, error)
- func (e *EncryptedFile) ReadAt(buf []byte, at int64) (int, error)
- func (e *EncryptedFile) ReadDir(n int) ([]fs.DirEntry, error)
- func (e *EncryptedFile) Seek(o int64, w int) (int64, error)
- func (e *EncryptedFile) Stat() (fs.FileInfo, error)
- func (e *EncryptedFile) Truncate(n int64) error
- func (e *EncryptedFile) Write(buf []byte) (int, error)
- func (e *EncryptedFile) WriteAt(buf []byte, at int64) (int, error)
- type FS
- func (f *FS) Chmod(name string, mode fs.FileMode) error
- func (f *FS) Close() error
- func (f *FS) Create(name string) (fs.File, error)
- func (f *FS) EncryptName(name string) (string, error)
- func (f *FS) Mkdir(name string, perm fs.FileMode) error
- func (f *FS) MkdirAll(name string, perm fs.FileMode) error
- func (f *FS) Open(name string) (fs.File, error)
- func (f *FS) OpenFile(name string, flag int, perm fs.FileMode) (fs.File, error)
- func (f *FS) ReadDir(name string) ([]fs.DirEntry, error)
- func (f *FS) Remove(name string) error
- func (f *FS) Rename(oldname, newname string) error
- func (f *FS) Stat(name string) (fs.FileInfo, error)
- func (f *FS) Truncate(name string, size int64) error
- type HkdfInfo
- type Purpose
- type ScryptObject
Constants ¶
This section is empty.
Variables ¶
var ( AeadTypeGcm = &AeadType{"AES-GCM-256", HkdfInfoGcmContent, sizeIvAesGcm, sizeKeyAesGcm} AeadTypeSiv = &AeadType{"AES-SIV-512", HkdfInfoSivContent, sizeIvAesSiv, sizeKeyAesSiv} AeadTypeXChaCha20Poly1305 = &AeadType{"XChaCha20-Poly1305", HkdfInfoXChaChaPoly1305Content, sizeIvXChaCha20_Poly1305, sizeKeyXChaChaPoly1305Content} )
Functions ¶
func CreateFS ¶ added in v0.2.0
func CreateFS(base any, aeadType *AeadType, log2n int, password, masterkey []byte, reverse bool) ([]byte, error)
log2n parameter should be >= 10 for security; 16 is recommended; gocryptfs max is 28.
"masterkey" can be nil, or an AeadTypeGcm key (32 bytes).
Returns the master key, print it to user once and wipe it.
func Passwd ¶ added in v0.2.0
Change password and/or masterkey of a gocryptfs.
"masterkey" can be nil, or an AeadTypeGcm key (32 bytes).
Be cautious supplying "masterkey", as changing master key doesn't require "oldpass", and a bad master key risks breaking a fs irreversibly.
Automatically identifies reverse mode fs.
Returns the master key, print it to user once and wipe it.
func ReadPassword ¶
Types ¶
type Conf ¶ added in v0.2.0
type Conf struct {
ScryptObject ScryptObject // not embedded for json.Unmarshal
FeatureFlags []string
Creator string
EncryptedKey string
Version int
}
Same structure as gocryptfs.conf
func (*Conf) GetAeadBackend ¶ added in v0.2.0
Get AEAD backend from feature flags in conf.
func (*Conf) SetKey ¶ added in v0.2.0
Sets master key as EncryptedKey encrypted with password.
If masterkey is nil, a random one is used. If not, it should be size of AeadTypeGcm key (32 bytes).
Returns the plain master key on success. Wipe it after printing it to user once.
type EncryptedFile ¶ added in v0.2.0
type EncryptedFile struct {
// contains filtered or unexported fields
}
A virtual file, for reading underlying cleartext content.
Implements fs.File, io.ReaderAt, io.Seeker, io.Writer, io.WriterAt, and ReadDir, Truncate functions.
func (*EncryptedFile) Close ¶ added in v0.2.0
func (e *EncryptedFile) Close() error
Write modified block to disk (if any), close the underlying file.
func (*EncryptedFile) Flush ¶ added in v0.2.0
func (e *EncryptedFile) Flush() (int, error)
Write current block encrypted to disk (if modified).
func (*EncryptedFile) Read ¶ added in v0.2.0
func (e *EncryptedFile) Read(buf []byte) (int, error)
Read the underlying plaintext data.
For concurrency, use [encryptedFile.ReadAt] with bufsize and seek boundry 4096.
func (*EncryptedFile) ReadAt ¶ added in v0.2.0
func (e *EncryptedFile) ReadAt(buf []byte, at int64) (int, error)
Concurrency safe. Useful for zip, 9p, and more packages.
func (*EncryptedFile) ReadDir ¶ added in v0.2.0
func (e *EncryptedFile) ReadDir(n int) ([]fs.DirEntry, error)
Similar to [(*os.File).ReadDir], useful for [http.FS] etc.
func (*EncryptedFile) Seek ¶ added in v0.2.0
func (e *EncryptedFile) Seek(o int64, w int) (int64, error)
func (*EncryptedFile) Truncate ¶ added in v0.2.0
func (e *EncryptedFile) Truncate(n int64) error
n < size: Preserves part of the last chunk.
n > size: Extends zero bytes to n.
func (*EncryptedFile) Write ¶ added in v0.2.0
func (e *EncryptedFile) Write(buf []byte) (int, error)
Read and Write should only be used synchronously.
For concurrency, use [ReadAt] and [WriteAt].
func (*EncryptedFile) WriteAt ¶ added in v0.2.0
func (e *EncryptedFile) WriteAt(buf []byte, at int64) (int, error)
Identical to Seek, Write, then Flush, guarded by a mutex.
Dev note: unlike [ReadAt], keeping a local block buffer is still unsafe for [WriteAt], as writes to the same block have race condition.
type FS ¶
type FS struct {
// Wrapper for underlying FS.
FS duckfs.FS
// contains filtered or unexported fields
}
Implements fs.FS, fs.ReadDirFS and fs.StatFS.
Plus io.Closer for wiping master key in memory.
func NewFS ¶
New FS. May return ErrBadPassword or other errors.
Optionally pass masterkey, in this case password is ignored. After that, wipe masterkey manually.
func (*FS) EncryptName ¶ added in v0.2.0
Plain filename to encrypted filename.
Make sure to path.Clean the input.
func (*FS) Mkdir ¶ added in v0.2.0
Create a directory, and generate a diriv under it.
Use perm 0o755 if unsure.
func (*FS) MkdirAll ¶ added in v0.2.0
Create directories if they are not yet created.
Use perm 0o755 if unsure.
func (*FS) OpenFile ¶ added in v0.2.0
Similar to os.OpenFile or os.Root.OpenFile. (But not identical!)
Files opened implements io.Writer, io.WriterAt, and other writing functions, if "base" FS implements duckfs.OpenFile or duckfs.OpenFileFS.
In most cases, you want to use FS.Open or FS.Create instead.
Use perm 0o644 if unsure.
func (*FS) Remove ¶ added in v0.2.0
Remove a file or empty directory.
From an outer perspective, an "empty" directory contains exactly one file: gocryptfs.diriv, this function removes it in such case, to remove this directory.
type HkdfInfo ¶ added in v0.2.0
type HkdfInfo string
const ( HkdfInfoEmeNames HkdfInfo = "EME filename encryption" HkdfInfoGcmContent HkdfInfo = "AES-GCM file content encryption" HkdfInfoSivContent HkdfInfo = "AES-SIV file content encryption" HkdfInfoXChaChaPoly1305Content HkdfInfo = "XChaCha20-Poly1305 file content encryption" )
Info strings for hkdf.Key.
ref: gocryptfs/internal/cryptocore/hkdf.go