Documentation
¶
Overview ¶
Package gokeepasslib is a library written in go which provides functionality to decrypt and parse keepass 2 files (kdbx)
Index ¶
- Constants
- Variables
- func LockProtectedEntries(p ProtectedStreamManager, es []Entry)
- func LockProtectedEntry(p ProtectedStreamManager, e *Entry)
- func LockProtectedGroup(p ProtectedStreamManager, g *Group)
- func LockProtectedGroups(p ProtectedStreamManager, gs []Group)
- func ParseKeyFile(location string) ([]byte, error)
- func UnlockProtectedEntries(p ProtectedStreamManager, e []Entry)
- func UnlockProtectedEntry(p ProtectedStreamManager, e *Entry)
- func UnlockProtectedGroup(p ProtectedStreamManager, g *Group)
- func UnlockProtectedGroups(p ProtectedStreamManager, gs []Group)
- type AutoTypeAssociation
- type AutoTypeData
- type Binaries
- type Binary
- type BinaryReference
- type DBContent
- type DBCredentials
- type Database
- type Decoder
- type DeletedObjectData
- type Encoder
- type Entry
- type FileHeaders
- type FileSignature
- type Group
- type History
- type InsecureStreamManager
- type MemProtection
- type MetaData
- type ProtectedStreamManager
- type RootData
- type SalsaManager
- type TimeData
- type UUID
- type V
- type ValueData
Constants ¶
const ( NoStreamID uint32 = 0 ARC4StreamID = 1 SalsaStreamID = 2 )
Constant enumerator for the inner random stream ID
const ( NoCompressionFlag uint32 = 0 GzipCompressionFlag = 1 )
Constants enumerator for compression flags
Variables ¶
var AESCipherID = []byte{0x31, 0xC1, 0xF2, 0xE6, 0xBF, 0x71, 0x43, 0x50, 0xBE, 0x58, 0x05, 0x21, 0x6A, 0xFC, 0x5A, 0xFF}
var BaseSignature = [...]byte{0x03, 0xd9, 0xa2, 0x9a}
BaseSignature is the valid base signature for kdbx files
var DefaultSig = FileSignature{BaseSignature, VersionSignature, FileVersion}
A full valid default signature struct for new databases
var ErrInvalidUUIDLength = errors.New("gokeepasslib: length of decoded UUID was not 16")
var ErrUnsupportedStreamType = errors.New("Type of stream manager unsupported")
ErrUnsupportedStreamType is retured if no streamManager can be created due to an unsupported InnerRandomStreamID value
var FileVersion = [...]byte{0x01, 0x00, 0x03, 0x00}
FileVersion is the most recent valid file version signature for kdbx files
var VersionSignature = [...]byte{0x67, 0xfb, 0x4b, 0xb5}
VersionSignature is the valid version signature for kdbx files
Functions ¶
func LockProtectedEntries ¶
func LockProtectedEntries(p ProtectedStreamManager, es []Entry)
func LockProtectedEntry ¶
func LockProtectedEntry(p ProtectedStreamManager, e *Entry)
func LockProtectedGroup ¶
func LockProtectedGroup(p ProtectedStreamManager, g *Group)
func LockProtectedGroups ¶
func LockProtectedGroups(p ProtectedStreamManager, gs []Group)
func ParseKeyFile ¶
ParseKeyFile returns the hashed key from a key file at the path specified by location, parsing xml if needed
func UnlockProtectedEntries ¶
func UnlockProtectedEntries(p ProtectedStreamManager, e []Entry)
func UnlockProtectedEntry ¶
func UnlockProtectedEntry(p ProtectedStreamManager, e *Entry)
func UnlockProtectedGroup ¶
func UnlockProtectedGroup(p ProtectedStreamManager, g *Group)
func UnlockProtectedGroups ¶
func UnlockProtectedGroups(p ProtectedStreamManager, gs []Group)
Types ¶
type AutoTypeAssociation ¶
type AutoTypeData ¶
type AutoTypeData struct { Enabled boolWrapper `xml:"Enabled"` DataTransferObfuscation int64 `xml:"DataTransferObfuscation"` Association AutoTypeAssociation `xml:"Association"` }
type Binaries ¶
type Binaries []Binary
Binaries Stores a slice of binaries in the metadata header of a database
type Binary ¶
type Binary struct { Content []byte `xml:",innerxml"` ID int `xml:"ID,attr"` Compressed boolWrapper `xml:"Compressed,attr"` }
Binary stores a binary found in the metadata header of a database
func (Binary) CreateReference ¶
func (b Binary) CreateReference(f string) BinaryReference
CreateReference creates a reference with the same id as b with filename f
func (Binary) GetContent ¶
GetContent returns a string which is the plaintext content of a binary
func (*Binary) SetContent ¶
SetContent encodes and (if Compressed=true) compresses c and sets b's content
type BinaryReference ¶
type BinaryReference struct { Name string `xml:"Key"` Value struct { ID int `xml:"Ref,attr"` } `xml:"Value"` }
BinaryReference stores a reference to a binary which appears in the xml of an entry
func NewBinaryReference ¶
func NewBinaryReference(name string, id int) BinaryReference
NewbinaryReference creates a new BinaryReference with the given name and id
func (*BinaryReference) Find ¶
func (br *BinaryReference) Find(bs Binaries) *Binary
Find returns a reference to a binary in the slice of binaries bs with the same id as br, or nil if none is found
func (BinaryReference) String ¶
func (br BinaryReference) String() string
type DBContent ¶
type DBContent struct { XMLName xml.Name `xml:"KeePassFile"` Meta *MetaData `xml:"Meta"` Root *RootData `xml:"Root"` }
DBContent is a container for all elements of a keepass database
func NewDBContent ¶
func NewDBContent() *DBContent
NewDBContent creates a new DB content with some good defaults
type DBCredentials ¶
type DBCredentials struct { Passphrase []byte //Passphrase if using one, stored in sha256 hash Key []byte //Contents of the keyfile if using one, stored in sha256 hash Windows []byte //Whatever is returned from windows user account auth, stored in sha256 hash }
DBCredentials holds the key used to lock and unlock the database
func NewKeyCredentials ¶
func NewKeyCredentials(location string) (*DBCredentials, error)
NewKeyCredentials builds new DBCredentials from a key file at the path specified by location
func NewPasswordCredentials ¶
func NewPasswordCredentials(password string) *DBCredentials
NewPasswordCredentials builds a new DBCredentials from a Password string
func (*DBCredentials) String ¶
func (c *DBCredentials) String() string
type Database ¶
type Database struct { Signature *FileSignature Headers *FileHeaders Credentials *DBCredentials Content *DBContent }
Database stores all contents nessesary for a keepass database file
func NewDatabase ¶
func NewDatabase() *Database
NewDatabase creates a new database with some sensable default settings. To create a database with no settigns per-set, use gokeepasslib.Database{}
func (*Database) LockProtectedEntries ¶
LockProtectedEntries goes through the entire database and decrypts any Values in entries with protected=true set. Warning: Do not call this if entries are already locked Warning: Encoding a database calls LockProtectedEntries automatically
func (*Database) StreamManager ¶
func (db *Database) StreamManager() ProtectedStreamManager
StreamManager returns a ProtectedStreamManager bassed on the db headers, or nil if the type is unsupported Can be used to lock only certain entries instead of calling
func (*Database) UnlockProtectedEntries ¶
UnlockProtectedEntries goes through the entire database and encrypts any Values in entries with protected=true set. This should be called after decoding if you want to view plaintext password in an entry Warning: If you call this when entry values are already unlocked, it will cause them to be unreadable
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder stores a reader which is expected to be in kdbx format
func NewDecoder ¶
type DeletedObjectData ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is used to automaticaly encrypt and write a database to a file, network, etc
func NewEncoder ¶
NewEncoder creates a new encoder with writer w, identical to gokeepasslib.Encoder{w}
type Entry ¶
type Entry struct { UUID UUID `xml:"UUID"` IconID int64 `xml:"IconID"` ForegroundColor string `xml:"ForegroundColor"` BackgroundColor string `xml:"BackgroundColor"` OverrideURL string `xml:"OverrideURL"` Tags string `xml:"Tags"` Times TimeData `xml:"Times"` Values []ValueData `xml:"String,omitempty"` AutoType AutoTypeData `xml:"AutoType"` Histories []History `xml:"History"` Password []byte `xml:"-"` Binaries []BinaryReference `xml:"Binary,omitempty"` }
Entry is the structure which holds information about a parsed entry in a keepass database
func (*Entry) Get ¶
Get returns the value in e corresponding with key k, or an empty string otherwise
func (*Entry) GetContent ¶
GetContent returns the content of the value belonging to the given key in string form
func (*Entry) GetIndex ¶
GetIndex returns the index of the Value belonging to the given key, or -1 if none is found
func (*Entry) GetPassword ¶
GetPassword returns the password of an entry
func (*Entry) GetPasswordIndex ¶
GetPasswordIndex returns the index in the values slice belonging to the password
type FileHeaders ¶
type FileHeaders struct { Comment []byte // FieldID: 1 CipherID []byte // FieldID: 2 CompressionFlags uint32 // FieldID: 3 MasterSeed []byte // FieldID: 4 TransformSeed []byte // FieldID: 5 TransformRounds uint64 // FieldID: 6 EncryptionIV []byte // FieldID: 7 ProtectedStreamKey []byte // FieldID: 8 StreamStartBytes []byte // FieldID: 9 InnerRandomStreamID uint32 // FieldID: 10 }
FileHeaders holds the header information of the Keepass File.
func NewFileHeaders ¶
func NewFileHeaders() *FileHeaders
NewFileHeaders creates a new FileHeaders with good defaults
func ReadHeaders ¶
func ReadHeaders(r io.Reader) (*FileHeaders, error)
ReadHeaders reads the headers from an io.Reader and creates a structure containing the parsed header information
func (FileHeaders) String ¶
func (h FileHeaders) String() string
func (*FileHeaders) WriteHeaders ¶
func (h *FileHeaders) WriteHeaders(w io.Writer) error
WriteHeaders takes the contents of the corresponding FileHeaders struct and writes them to the given io.Writer
type FileSignature ¶
FileSignature holds the Keepass File Signature. The first 4 Bytes are the Base Signature, followed by 4 Bytes for the Version of the Format which is followed by 4 Bytes for the File Version
func ReadSignature ¶
func ReadSignature(r io.Reader) (*FileSignature, error)
func (FileSignature) String ¶
func (s FileSignature) String() string
func (*FileSignature) WriteSignature ¶
func (s *FileSignature) WriteSignature(w io.Writer) error
type Group ¶
type Group struct { UUID UUID `xml:"UUID"` Name string `xml:"Name"` Notes string `xml:"Notes"` IconID int64 `xml:"IconID"` Times TimeData `xml:"Times"` IsExpanded boolWrapper `xml:"IsExpanded"` DefaultAutoTypeSequence string `xml:"DefaultAutoTypeSequence"` EnableAutoType string `xml:"EnableAutoType"` EnableSearching string `xml:"EnableSearching"` LastTopVisibleEntry string `xml:"LastTopVisibleEntry"` Groups []Group `xml:"Group,omitempty"` Entries []Entry `xml:"Entry,omitempty"` }
Group is a structure to store entries in their named groups for organization
type History ¶
type History struct {
Entries []Entry `xml:"Entry"`
}
History stores information about changes made to an entry, in the form of a list of previous versions of that entry
type InsecureStreamManager ¶
type InsecureStreamManager struct{}
InsecureStreamManager is a stream manger which does not encrypt, just stores the plaintext payload
func (InsecureStreamManager) Pack ¶
func (i InsecureStreamManager) Pack(payload []byte) string
Pack returns the string belonging to the given byte slice payload without any packaging to be done
func (InsecureStreamManager) Unpack ¶
func (i InsecureStreamManager) Unpack(payload string) []byte
Unpack returns the given string as a byte slice without any other action being taken
type MemProtection ¶
type MemProtection struct { ProtectTitle boolWrapper `xml:"ProtectTitle"` ProtectUserName boolWrapper `xml:"ProtectUserName"` ProtectPassword boolWrapper `xml:"ProtectPassword"` ProtectURL boolWrapper `xml:"ProtectURL"` ProtectNotes boolWrapper `xml:"ProtectNotes"` }
MemProtection is a structure containing settings for MemoryProtection
type MetaData ¶
type MetaData struct { Generator string `xml:"Generator"` HeaderHash string `xml:"HeaderHash"` DatabaseName string `xml:"DatabaseName"` DatabaseNameChanged *time.Time `xml:"DatabaseNameChanged"` DatabaseDescription string `xml:"DatabaseDescription"` DatabaseDescriptionChanged *time.Time `xml:"DatabaseDescriptionChanged"` DefaultUserName string `xml:"DefaultUserName"` DefaultUserNameChanged *time.Time `xml:"DefaultUserNameChanged"` MaintenanceHistoryDays string `xml:"MaintenanceHistoryDays"` Color string `xml:"Color"` MasterKeyChanged *time.Time `xml:"MasterKeyChanged"` MasterKeyChangeRec int64 `xml:"MasterKeyChangeRec"` MasterKeyChangeForce int64 `xml:"MasterKeyChangeForce"` MemoryProtection MemProtection `xml:"MemoryProtection"` RecycleBinEnabled boolWrapper `xml:"RecycleBinEnabled"` RecycleBinUUID UUID `xml:"RecycleBinUUID"` RecycleBinChanged *time.Time `xml:"RecycleBinChanged"` EntryTemplatesGroup string `xml:"EntryTemplatesGroup"` EntryTemplatesGroupChanged *time.Time `xml:"EntryTemplatesGroupChanged"` HistoryMaxItems int64 `xml:"HistoryMaxItems"` HistoryMaxSize int64 `xml:"HistoryMaxSize"` LastSelectedGroup string `xml:"LastSelectedGroup"` LastTopVisibleGroup string `xml:"LastTopVisibleGroup"` Binaries Binaries `xml:"Binaries>Binary"` CustomData string `xml:"CustomData"` }
MetaData is the structure for the metadata headers at the top of kdbx files, it contains things like the name of the database
func NewMetaData ¶
func NewMetaData() *MetaData
NewMetaData creates a MetaData struct with some defaults set
type ProtectedStreamManager ¶
ProtectedStreamManager is an interface for the different types of StreamManagers which might be used for protecting certain values
type RootData ¶
type RootData struct { Groups []Group `xml:"Group"` DeletedObjects []DeletedObjectData `xml:"DeletedObjects>DeletedObject"` }
RootData stores the actual content of a database (all enteries sorted into groups and the recycle bin)
func NewRootData ¶
func NewRootData() *RootData
NewRootData returns a RootData struct with good defaults
type SalsaManager ¶
type SalsaManager struct {
// contains filtered or unexported fields
}
SalsaManager is a structure holding the salsa key to lock and unlock protected entries.
func NewSalsaManager ¶
func NewSalsaManager(key [32]byte) SalsaManager
NewSalsaManager returns an instance of SalsaManager
func (SalsaManager) Pack ¶
func (m SalsaManager) Pack(payload []byte) string
Pack locks a given payload using the golang.org/x/crypto/salsa20 implementation
func (SalsaManager) Unpack ¶
func (m SalsaManager) Unpack(payload string) []byte
Unpack unlocks a given payload using the golang.org/x/crypto/salsa20 implementation
type TimeData ¶
type TimeData struct { CreationTime *time.Time `xml:"CreationTime"` LastModificationTime *time.Time `xml:"LastModificationTime"` LastAccessTime *time.Time `xml:"LastAccessTime"` ExpiryTime *time.Time `xml:"ExpiryTime"` Expires boolWrapper `xml:"Expires"` UsageCount int64 `xml:"UsageCount"` LocationChanged *time.Time `xml:"LocationChanged"` }
TimeData contains all metadata related to times for groups and entries e.g. the last modification time or the creation time
func NewTimeData ¶
func NewTimeData() TimeData
NewTimeData returns a TimeData struct with good defaults (no expire time, all times set to now)
type UUID ¶
type UUID [16]byte
UUID stores a universal identifier for each group+entry