Documentation
¶
Overview ¶
Package sources provides adapters for reading credentials from various formats.
Index ¶
- Variables
- func IsAuthError(err error) bool
- func IsFormatError(err error) bool
- func IsNotFound(err error) bool
- func IsPartialRead(err error) bool
- func RegisterDefault(s Source)
- type BitwardenCard
- type BitwardenExport
- type BitwardenField
- type BitwardenFolder
- type BitwardenIdentity
- type BitwardenItem
- type BitwardenLogin
- type BitwardenNote
- type BitwardenSource
- func (s *BitwardenSource) Close() error
- func (s *BitwardenSource) Description() string
- func (s *BitwardenSource) Detect(path string) (int, error)
- func (s *BitwardenSource) Name() string
- func (s *BitwardenSource) Open(path string, opts OpenOptions) error
- func (s *BitwardenSource) Read() ([]model.Credential, error)
- func (s *BitwardenSource) SupportedExtensions() []string
- type BitwardenURI
- type ChromeSource
- func (s *ChromeSource) Close() error
- func (s *ChromeSource) Description() string
- func (s *ChromeSource) Detect(path string) (int, error)
- func (s *ChromeSource) Name() string
- func (s *ChromeSource) Open(path string, opts OpenOptions) error
- func (s *ChromeSource) Read() ([]model.Credential, error)
- func (s *ChromeSource) SupportedExtensions() []string
- type ErrAuthenticationFailed
- type ErrFileNotFound
- type ErrInvalidFormat
- type ErrPartialRead
- type ErrPermissionDenied
- type ErrSourceNotFound
- type ErrUnsupportedFeature
- type FirefoxSource
- func (s *FirefoxSource) Close() error
- func (s *FirefoxSource) Description() string
- func (s *FirefoxSource) Detect(path string) (int, error)
- func (s *FirefoxSource) Name() string
- func (s *FirefoxSource) Open(path string, opts OpenOptions) error
- func (s *FirefoxSource) Read() ([]model.Credential, error)
- func (s *FirefoxSource) SupportedExtensions() []string
- type KeePassSource
- func (s *KeePassSource) Close() error
- func (s *KeePassSource) Description() string
- func (s *KeePassSource) Detect(path string) (int, error)
- func (s *KeePassSource) Name() string
- func (s *KeePassSource) Open(path string, opts OpenOptions) error
- func (s *KeePassSource) Read() ([]model.Credential, error)
- func (s *KeePassSource) SupportedExtensions() []string
- type OpenOptions
- type PasswordPromptFunc
- type Registry
- func (r *Registry) Count() int
- func (r *Registry) DetectSource(path string) (Source, error)
- func (r *Registry) DetectSourceWithThreshold(path string, minConfidence int) (Source, error)
- func (r *Registry) Get(name string) (Source, bool)
- func (r *Registry) List() []Source
- func (r *Registry) Names() []string
- func (r *Registry) Register(s Source)
- func (r *Registry) Unregister(name string)
- type SSHSource
- func (s *SSHSource) Close() error
- func (s *SSHSource) Description() string
- func (s *SSHSource) Detect(path string) (int, error)
- func (s *SSHSource) Name() string
- func (s *SSHSource) Open(path string, opts OpenOptions) error
- func (s *SSHSource) Read() ([]model.Credential, error)
- func (s *SSHSource) SupportedExtensions() []string
- type Source
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotOpen is returned when Read is called before Open. ErrNotOpen = errors.New("source not open") // ErrAlreadyOpen is returned when Open is called on an already-open source. ErrAlreadyOpen = errors.New("source already open") // ErrClosed is returned when operations are attempted on a closed source. ErrClosed = errors.New("source is closed") )
Common errors that can be returned by source adapters.
Functions ¶
func IsAuthError ¶
IsAuthError returns true if the error is an authentication error.
func IsFormatError ¶
IsFormatError returns true if the error is a format error.
func IsNotFound ¶
IsNotFound returns true if the error is a not found error.
func IsPartialRead ¶
IsPartialRead returns true if the error is a partial read error.
func RegisterDefault ¶
func RegisterDefault(s Source)
RegisterDefault registers a source with the default registry.
Types ¶
type BitwardenCard ¶
type BitwardenCard struct {
CardholderName string `json:"cardholderName"`
Brand string `json:"brand"`
Number string `json:"number"`
ExpMonth string `json:"expMonth"`
ExpYear string `json:"expYear"`
Code string `json:"code"`
}
BitwardenCard represents credit card data in a Bitwarden item.
type BitwardenExport ¶
type BitwardenExport struct {
Encrypted bool `json:"encrypted"`
Folders []BitwardenFolder `json:"folders"`
Items []BitwardenItem `json:"items"`
}
BitwardenExport represents the top-level Bitwarden JSON export structure.
type BitwardenField ¶
type BitwardenField struct {
Name string `json:"name"`
Value string `json:"value"`
Type int `json:"type"` // 0=text, 1=hidden, 2=boolean, 3=linked
}
BitwardenField represents a custom field in a Bitwarden item.
type BitwardenFolder ¶
BitwardenFolder represents a folder in the Bitwarden export.
type BitwardenIdentity ¶
type BitwardenIdentity struct {
Title string `json:"title"`
FirstName string `json:"firstName"`
MiddleName string `json:"middleName"`
LastName string `json:"lastName"`
Address1 string `json:"address1"`
Address2 string `json:"address2"`
Address3 string `json:"address3"`
City string `json:"city"`
State string `json:"state"`
PostalCode string `json:"postalCode"`
Country string `json:"country"`
Company string `json:"company"`
Email string `json:"email"`
Phone string `json:"phone"`
SSN string `json:"ssn"`
Username string `json:"username"`
PassportNumber string `json:"passportNumber"`
LicenseNumber string `json:"licenseNumber"`
}
BitwardenIdentity represents identity data in a Bitwarden item.
type BitwardenItem ¶
type BitwardenItem struct {
ID string `json:"id"`
OrganizationID string `json:"organizationId"`
FolderID string `json:"folderId"`
Type int `json:"type"`
Name string `json:"name"`
Notes string `json:"notes"`
Favorite bool `json:"favorite"`
Login *BitwardenLogin `json:"login,omitempty"`
SecureNote *BitwardenNote `json:"secureNote,omitempty"`
Card *BitwardenCard `json:"card,omitempty"`
Identity *BitwardenIdentity `json:"identity,omitempty"`
CollectionIDs []string `json:"collectionIds"`
CreationDate string `json:"creationDate"`
RevisionDate string `json:"revisionDate"`
Reprompt int `json:"reprompt"`
Fields []BitwardenField `json:"fields,omitempty"`
}
BitwardenItem represents a single item in the Bitwarden export.
type BitwardenLogin ¶
type BitwardenLogin struct {
URIs []BitwardenURI `json:"uris"`
Username string `json:"username"`
Password string `json:"password"`
TOTP string `json:"totp"`
}
BitwardenLogin represents login data in a Bitwarden item.
type BitwardenNote ¶
type BitwardenNote struct {
Type int `json:"type"`
}
BitwardenNote represents secure note data in a Bitwarden item.
type BitwardenSource ¶
type BitwardenSource struct {
// contains filtered or unexported fields
}
BitwardenSource implements the Source interface for Bitwarden JSON exports.
func NewBitwardenSource ¶
func NewBitwardenSource() *BitwardenSource
NewBitwardenSource creates a new Bitwarden JSON source adapter.
func (*BitwardenSource) Description ¶
func (s *BitwardenSource) Description() string
Description returns a human-readable description.
func (*BitwardenSource) Detect ¶
func (s *BitwardenSource) Detect(path string) (int, error)
Detect checks if the given path is a Bitwarden JSON export.
func (*BitwardenSource) Name ¶
func (s *BitwardenSource) Name() string
Name returns the unique identifier for this source.
func (*BitwardenSource) Open ¶
func (s *BitwardenSource) Open(path string, opts OpenOptions) error
Open initializes the source with the given file path.
func (*BitwardenSource) Read ¶
func (s *BitwardenSource) Read() ([]model.Credential, error)
Read parses the Bitwarden JSON and returns credentials.
func (*BitwardenSource) SupportedExtensions ¶
func (s *BitwardenSource) SupportedExtensions() []string
SupportedExtensions returns file extensions this source handles.
type BitwardenURI ¶
BitwardenURI represents a URI entry in a Bitwarden login.
type ChromeSource ¶
type ChromeSource struct {
// contains filtered or unexported fields
}
ChromeSource implements the Source interface for Chrome CSV exports.
func NewChromeSource ¶
func NewChromeSource() *ChromeSource
NewChromeSource creates a new Chrome CSV source adapter.
func (*ChromeSource) Description ¶
func (s *ChromeSource) Description() string
Description returns a human-readable description.
func (*ChromeSource) Detect ¶
func (s *ChromeSource) Detect(path string) (int, error)
Detect checks if the given path is a Chrome CSV export.
func (*ChromeSource) Name ¶
func (s *ChromeSource) Name() string
Name returns the unique identifier for this source.
func (*ChromeSource) Open ¶
func (s *ChromeSource) Open(path string, opts OpenOptions) error
Open initializes the source with the given file path.
func (*ChromeSource) Read ¶
func (s *ChromeSource) Read() ([]model.Credential, error)
Read parses the Chrome CSV and returns credentials.
func (*ChromeSource) SupportedExtensions ¶
func (s *ChromeSource) SupportedExtensions() []string
SupportedExtensions returns file extensions this source handles.
type ErrAuthenticationFailed ¶
type ErrAuthenticationFailed struct {
Source string // Source adapter name
Path string // File path
Reason string // Why authentication failed
Err error // Underlying error, if any
}
ErrAuthenticationFailed indicates that authentication failed (wrong password, key, etc.).
func (*ErrAuthenticationFailed) Error ¶
func (e *ErrAuthenticationFailed) Error() string
func (*ErrAuthenticationFailed) Unwrap ¶
func (e *ErrAuthenticationFailed) Unwrap() error
type ErrFileNotFound ¶
type ErrFileNotFound struct {
Path string
}
ErrFileNotFound indicates the specified file does not exist.
func (*ErrFileNotFound) Error ¶
func (e *ErrFileNotFound) Error() string
type ErrInvalidFormat ¶
type ErrInvalidFormat struct {
Source string // Source adapter name
Path string // File path
Details string // What was wrong
Err error // Underlying error, if any
}
ErrInvalidFormat indicates that the source file has an invalid or corrupted format.
func (*ErrInvalidFormat) Error ¶
func (e *ErrInvalidFormat) Error() string
func (*ErrInvalidFormat) Unwrap ¶
func (e *ErrInvalidFormat) Unwrap() error
type ErrPartialRead ¶
type ErrPartialRead struct {
Source string // Source adapter name
TotalItems int // Total items attempted
ReadItems int // Items successfully read
Failures []string // Descriptions of failures
Errs []error // Individual errors
}
ErrPartialRead indicates that some credentials couldn't be read. The source will still return the credentials that were successfully read.
func (*ErrPartialRead) AddFailure ¶
func (e *ErrPartialRead) AddFailure(description string, err error)
AddFailure adds a failure to the partial read error.
func (*ErrPartialRead) Error ¶
func (e *ErrPartialRead) Error() string
func (*ErrPartialRead) HasFailures ¶
func (e *ErrPartialRead) HasFailures() bool
HasFailures returns true if there are any failures recorded.
type ErrPermissionDenied ¶
type ErrPermissionDenied struct {
Path string
Op string // Operation that failed (read, open, etc.)
Err error // Underlying error
}
ErrPermissionDenied indicates a file access permission issue.
func (*ErrPermissionDenied) Error ¶
func (e *ErrPermissionDenied) Error() string
func (*ErrPermissionDenied) Unwrap ¶
func (e *ErrPermissionDenied) Unwrap() error
type ErrSourceNotFound ¶
ErrSourceNotFound indicates that no source adapter could handle the given path.
func (*ErrSourceNotFound) Error ¶
func (e *ErrSourceNotFound) Error() string
type ErrUnsupportedFeature ¶
ErrUnsupportedFeature indicates a feature is not supported by the source.
func (*ErrUnsupportedFeature) Error ¶
func (e *ErrUnsupportedFeature) Error() string
type FirefoxSource ¶
type FirefoxSource struct {
// contains filtered or unexported fields
}
FirefoxSource implements the Source interface for Firefox CSV exports.
func NewFirefoxSource ¶
func NewFirefoxSource() *FirefoxSource
NewFirefoxSource creates a new Firefox CSV source adapter.
func (*FirefoxSource) Description ¶
func (s *FirefoxSource) Description() string
Description returns a human-readable description.
func (*FirefoxSource) Detect ¶
func (s *FirefoxSource) Detect(path string) (int, error)
Detect checks if the given path is a Firefox CSV export.
func (*FirefoxSource) Name ¶
func (s *FirefoxSource) Name() string
Name returns the unique identifier for this source.
func (*FirefoxSource) Open ¶
func (s *FirefoxSource) Open(path string, opts OpenOptions) error
Open initializes the source with the given file path.
func (*FirefoxSource) Read ¶
func (s *FirefoxSource) Read() ([]model.Credential, error)
Read parses the Firefox CSV and returns credentials.
func (*FirefoxSource) SupportedExtensions ¶
func (s *FirefoxSource) SupportedExtensions() []string
SupportedExtensions returns file extensions this source handles.
type KeePassSource ¶
type KeePassSource struct {
// contains filtered or unexported fields
}
KeePassSource implements the Source interface for KeePass .kdbx files.
Security Note: This implementation uses gokeepasslib which relies on Go's standard library encoding/xml for XML parsing. Go's XML parser is safe from XML External Entity (XXE) attacks by design - it does not resolve external entities or support DTD processing. See: https://github.com/golang/go/issues/14107
func NewKeePassSource ¶
func NewKeePassSource() *KeePassSource
NewKeePassSource creates a new KeePass source adapter.
func (*KeePassSource) Close ¶
func (s *KeePassSource) Close() error
Close releases resources and locks protected entries.
func (*KeePassSource) Description ¶
func (s *KeePassSource) Description() string
Description returns a human-readable description.
func (*KeePassSource) Detect ¶
func (s *KeePassSource) Detect(path string) (int, error)
Detect checks if the given path is a KeePass database.
func (*KeePassSource) Name ¶
func (s *KeePassSource) Name() string
Name returns the unique identifier for this source.
func (*KeePassSource) Open ¶
func (s *KeePassSource) Open(path string, opts OpenOptions) error
Open initializes the source with the given file path and options.
func (*KeePassSource) Read ¶
func (s *KeePassSource) Read() ([]model.Credential, error)
Read extracts all entries from the KeePass database.
func (*KeePassSource) SupportedExtensions ¶
func (s *KeePassSource) SupportedExtensions() []string
SupportedExtensions returns file extensions this source handles.
type OpenOptions ¶
type OpenOptions struct {
// Password for encrypted sources (KeePass, encrypted exports).
Password string
// KeyFilePath for sources that support key files (KeePass).
KeyFilePath string
// Interactive indicates whether the source may prompt for missing credentials.
// If true, PasswordFunc will be called when a password is needed.
Interactive bool
// PasswordFunc is a callback for interactive password entry.
// It receives a prompt string and should return the password or an error.
// Only used when Interactive is true.
PasswordFunc func(prompt string) (string, error)
// Recursive indicates whether to search directories recursively.
// Only applicable to directory-based sources like SSH.
Recursive bool
// IncludeHidden indicates whether to include hidden files.
// Only applicable to file-discovery sources.
IncludeHidden bool
}
OpenOptions provides configuration for opening a source.
type PasswordPromptFunc ¶
PasswordPromptFunc is the signature for interactive password callbacks.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages available source adapters. It provides lookup by name and auto-detection by file extension or content.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns the default global registry with all built-in sources. This function is safe for concurrent use.
func (*Registry) DetectSource ¶
DetectSource attempts to auto-detect the appropriate source for a path. It first tries extension matching, then content detection. Returns the best matching source or ErrSourceNotFound if no match.
func (*Registry) DetectSourceWithThreshold ¶
DetectSourceWithThreshold is like DetectSource but requires a minimum confidence.
func (*Registry) Get ¶
Get retrieves a source adapter by name. Returns the source and true if found, or nil and false if not found.
func (*Registry) Register ¶
Register adds a source adapter to the registry. If a source with the same name already exists, it will be replaced.
func (*Registry) Unregister ¶
Unregister removes a source adapter from the registry.
type SSHSource ¶
type SSHSource struct {
// contains filtered or unexported fields
}
SSHSource implements the Source interface for a single SSH private key file.
func (*SSHSource) Description ¶
Description returns a human-readable description.
func (*SSHSource) Detect ¶
Detect checks if the given path is a valid SSH private key file. Returns confidence 0-100 based on whether it looks like an SSH private key.
func (*SSHSource) Open ¶
func (s *SSHSource) Open(path string, opts OpenOptions) error
Open initializes the source with the given file path.
func (*SSHSource) Read ¶
func (s *SSHSource) Read() ([]model.Credential, error)
Read parses the SSH private key file.
func (*SSHSource) SupportedExtensions ¶
SupportedExtensions returns common SSH private key file extensions.
type Source ¶
type Source interface {
// Name returns the unique identifier for this source (e.g., "keepass", "chrome").
Name() string
// Description returns a human-readable description of the source.
Description() string
// SupportedExtensions returns file extensions this source handles (e.g., [".kdbx"]).
// Return empty slice for directory-based sources.
SupportedExtensions() []string
// Detect checks if the given path is valid for this source.
// Returns a confidence score from 0-100 (100 = definitely this format).
// A score of 0 means this source cannot handle the path.
Detect(path string) (confidence int, err error)
// Open initializes the source with the given path and options.
// This may prompt for credentials if Interactive is true and credentials are needed.
Open(path string, opts OpenOptions) error
// Read returns all credentials from the source.
// May be called multiple times; should return the same results.
// Returns ErrPartialRead if some credentials couldn't be read.
Read() ([]model.Credential, error)
// Close releases any resources held by the source.
// Should clear sensitive data from memory where possible.
Close() error
}
Source defines the interface for credential source adapters. Each adapter reads credentials from a specific format (KeePass, Chrome CSV, etc.) and converts them to the internal model representation.