Documentation
¶
Index ¶
- Constants
- Variables
- func AutoEncryptedMetadataSize() int
- func CondensedFormat(ns, format string) string
- func MapKeys[T any](m map[string]T) []string
- func ReadTarFile(tarBuf io.Reader) (map[string]*bytes.Buffer, error)
- func RegisterAutoEncryptor(src AutoEncryptor)
- func RegisterFormat(ns string, formats ...*Format)
- type AutoEncryptedFileBlock
- type AutoEncryptedFile_FullFile
- func (f *AutoEncryptedFile_FullFile) Get(name string) (*bytes.Buffer, error)
- func (f *AutoEncryptedFile_FullFile) Sections() (map[string]*bytes.Buffer, error)
- func (f *AutoEncryptedFile_FullFile) Size() int
- func (f *AutoEncryptedFile_FullFile) WriteJsonSection(i any, name string) error
- func (f *AutoEncryptedFile_FullFile) WriteOutput(w io.Writer) error
- func (f *AutoEncryptedFile_FullFile) WriteSection(buf *bytes.Buffer, name string) error
- type AutoEncryptedFile_PerSection
- func (f *AutoEncryptedFile_PerSection) Get(name string, src AutoEncryptor) (*bytes.Buffer, error)
- func (f *AutoEncryptedFile_PerSection) RawSections() (map[string]*AutoEncryptedFileBlock, error)
- func (f *AutoEncryptedFile_PerSection) WriteJsonSection(i any, name string, src AutoEncryptor) error
- func (f *AutoEncryptedFile_PerSection) WriteOutput(w io.Writer) error
- func (f *AutoEncryptedFile_PerSection) WriteSection(buf *bytes.Buffer, name string, src AutoEncryptor) error
- type AutoEncryptor
- type DeducedType
- type DeducedTypeInfo
- type Format
- type Meta
- type RawFile
- type SourceParsed
Constants ¶
const CurrentVersion = 1
const Protocol = "frostpaw-rev7" // The exact protocol version to use
Variables ¶
var ( AutoEncryptedFileMagic = []byte("iblaef") AutoEncryptedFileChecksumSize = 32 // sha256 AutoEncryptedFileIDSize = 16 )
var AutoEncryptorRegistry = make(map[string]AutoEncryptor)
var FormatVersionMap = map[string][]*Format{}
Functions ¶
func AutoEncryptedMetadataSize ¶
func AutoEncryptedMetadataSize() int
func CondensedFormat ¶
func RegisterAutoEncryptor ¶
func RegisterAutoEncryptor(src AutoEncryptor)
func RegisterFormat ¶
Types ¶
type AutoEncryptedFileBlock ¶
type AutoEncryptedFileBlock struct {
// Magic bytes
Magic []byte
// Checksum
Checksum []byte
// Encryptor
Encryptor []byte
// Data
Data []byte
}
Represents an autoencrypted file block
func NewAutoEncryptedFileBlock ¶
func NewAutoEncryptedFileBlock(data []byte, src AutoEncryptor) (*AutoEncryptedFileBlock, error)
func ParseAutoEncryptedFileBlock ¶
func ParseAutoEncryptedFileBlock(block []byte) (*AutoEncryptedFileBlock, error)
func QuickBlockParser ¶
func QuickBlockParser(r io.ReadSeeker) (*AutoEncryptedFileBlock, error)
QuickBlockParser reads the first AutoEncryptedMetadataSize into a buffer and parses it
Note that the block returned by this is *not* valid and is only meant for quick parsing of the encryptor
func (*AutoEncryptedFileBlock) Decrypt ¶
func (b *AutoEncryptedFileBlock) Decrypt(src AutoEncryptor) ([]byte, error)
Decrypts a block into a byte slice
func (*AutoEncryptedFileBlock) Validate ¶
func (b *AutoEncryptedFileBlock) Validate() error
Validates a block to ensure that it is a valid autoencrypted file block
type AutoEncryptedFile_FullFile ¶
type AutoEncryptedFile_FullFile struct {
// contains filtered or unexported fields
}
A full file autoencrypted file. This type stores all data as one single encrypted block rather than per-section blocks
This is the first, and simplest+quickest autoencrypted () file
func NewAutoEncryptedFile_FullFile ¶
func NewAutoEncryptedFile_FullFile(src AutoEncryptor) *AutoEncryptedFile_FullFile
func OpenAutoEncryptedFile_FullFile ¶
func OpenAutoEncryptedFile_FullFile(r io.Reader, src AutoEncryptor) (*AutoEncryptedFile_FullFile, error)
OpenAutoEncryptedFile_FullFile opens a full file as a single autoencrypted block
func (*AutoEncryptedFile_FullFile) Get ¶
func (f *AutoEncryptedFile_FullFile) Get(name string) (*bytes.Buffer, error)
Get a section from the file
func (*AutoEncryptedFile_FullFile) Sections ¶
func (f *AutoEncryptedFile_FullFile) Sections() (map[string]*bytes.Buffer, error)
Returns all sections of the file
func (*AutoEncryptedFile_FullFile) Size ¶
func (f *AutoEncryptedFile_FullFile) Size() int
Returns the size of the file
func (*AutoEncryptedFile_FullFile) WriteJsonSection ¶
func (f *AutoEncryptedFile_FullFile) WriteJsonSection(i any, name string) error
Adds a section to a file with json file format
func (*AutoEncryptedFile_FullFile) WriteOutput ¶
func (f *AutoEncryptedFile_FullFile) WriteOutput(w io.Writer) error
func (*AutoEncryptedFile_FullFile) WriteSection ¶
func (f *AutoEncryptedFile_FullFile) WriteSection(buf *bytes.Buffer, name string) error
Adds a section to a file
type AutoEncryptedFile_PerSection ¶
type AutoEncryptedFile_PerSection struct {
// contains filtered or unexported fields
}
The second type of autoencrypted file
This one encrypts individual sections
func NewAutoEncryptedFile_PerSection ¶
func NewAutoEncryptedFile_PerSection() *AutoEncryptedFile_PerSection
func OpenAutoEncryptedFile_PerSection ¶
func OpenAutoEncryptedFile_PerSection(r io.Reader) (*AutoEncryptedFile_PerSection, error)
OpenAutoEncryptedFile_PerSection opens a per-section autoencrypted file
func (*AutoEncryptedFile_PerSection) Get ¶
func (f *AutoEncryptedFile_PerSection) Get(name string, src AutoEncryptor) (*bytes.Buffer, error)
Gets a section given its name and a src
func (*AutoEncryptedFile_PerSection) RawSections ¶
func (f *AutoEncryptedFile_PerSection) RawSections() (map[string]*AutoEncryptedFileBlock, error)
Returns all sections of the file (raw and encrypted)
func (*AutoEncryptedFile_PerSection) WriteJsonSection ¶
func (f *AutoEncryptedFile_PerSection) WriteJsonSection(i any, name string, src AutoEncryptor) error
Adds a section to a file with json file format
func (*AutoEncryptedFile_PerSection) WriteOutput ¶
func (f *AutoEncryptedFile_PerSection) WriteOutput(w io.Writer) error
func (*AutoEncryptedFile_PerSection) WriteSection ¶
func (f *AutoEncryptedFile_PerSection) WriteSection(buf *bytes.Buffer, name string, src AutoEncryptor) error
Adds a section to a file given a buf, a name and a src
type AutoEncryptor ¶
type AutoEncryptor interface {
// Returns the identifier of the source, must be unique
//
// Max size: 8 ASCII characters (8 bytes)
ID() string
// Encrypts a byte slice
Encrypt([]byte) ([]byte, error)
// Decrypts a byte slice
Decrypt([]byte) ([]byte, error) // Decrypts a byte slice
}
Autoencrypted files can be encypted in many ways
This defines an interface for all of them
type DeducedType ¶
type DeducedType int
DeduceType tries to deduce the ibl file type a io.Reader
const ( DeducedTypeLegacyFileLsw DeducedType = iota // A legacy rev5 or older file DeducedTypeTarWithNoMetadata DeducedType = iota // A file with no metadata DeducedTypeTarWithBadMetadata DeducedType = iota // A file with bad metadata DeducedTypeNormal DeducedType = iota // A normal file of the current protocol version DeducedTypeLegacyFileTar DeducedType = iota // A legacy rev6 file DeducedTypeAutoEncryptedFile_FullFile DeducedType = iota // A full file autoencrypted file DeducedTypeAutoEncryptedFile_PerSection DeducedType = iota // A per-section autoencrypted file )
func (DeducedType) String ¶
func (d DeducedType) String() string
type DeducedTypeInfo ¶
type DeducedTypeInfo struct {
Type DeducedType
Sections map[string]*bytes.Buffer // Not present on autoencrypted_fullfile files
ParseErrors []error
}
Returns info from deducing the type of an ibl file
func DeduceType ¶
func DeduceType(r io.Reader, shortcut bool) (*DeducedTypeInfo, error)
DeduceType tries to deduce the ibl file type a io.Reader
This is useful when you want to open an iblfile but you don't know what type it is
If shortcut is true, certain checks are skipped (e.g. per-section block finding) which may slightly speed up deducing
Note that deducing is a SLOW operation and should be avoided if possible ¶
Example of deducing a file type:
root@Olympia:~/iblfile/testcli# ./testcli deduce /staging/pg/infinity/infinity-2023-10-21@13_00_01.iblcli-backup filename: /staging/pg/infinity/infinity-2023-10-21@13_00_01.iblcli-backup deduced type: LegacyFileLsw deduced sections: [data meta] deduced errors: [] root@Olympia:~/iblfile/testcli#
As seen above, the file above was deduced to be a LegacyFileLsw file (a rev5 or older file which used LSW compression at the time)
Another example: frostpaw@frostpaws-MacBook-Air ~/i/testcli (main)> ./testcli deduce '/Users/frostpaw/Downloads/ antiraid-backup (4).iblfile' filename: /Users/frostpaw/Downloads/antiraid-backup (4).iblfile deduced type: LegacyFileTar deduced sections: [meta sec/sourceType sec/encSections sec/encKeyHashMethod backup_opts dbg/bot dbg/basePerms core/guild] deduced errors: [] frostpaw@frostpaws-MacBook-Air ~/i/testcli (main)>
As seen above, the file above was deduced to be a LegacyFileTar file (a rev6 file)
A rev6 file can be made into a rev7 file by either simply updating meta (if no encryption is used) or (recommended) by using AutoEncrypted file's which support all the functionality of rev6 along with a more stable interface and sha256 checksums
type Format ¶
type Format struct {
Format string
Version string
GetExtended func(section map[string]*bytes.Buffer, meta *Meta) (map[string]any, error)
}
A helper struct to register/store a format
type Meta ¶
type Meta struct {
CreatedAt time.Time `json:"c"`
Protocol string `json:"p"`
// Format version
//
// This can be used to create breaking changes to a file type without changing the entire protocol
FormatVersion string `json:"v,omitempty"`
// Type of the file
Type string `json:"t"`
// Extra metadata attributes
ExtraMetadata map[string]string `json:"m,omitempty"`
}
func LoadMetadata ¶
Load metadata loads the metadata
type RawFile ¶
type RawFile struct {
// contains filtered or unexported fields
}
Note that RawFile's are not meant to be directly used
Using AutoEncryptedFiles is recommended as these also include SHA256 checksums and encryption support