keychain

package
v1.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package keychain provides cross-platform secure storage for secrets. - macOS: System Keychain stores DEK (Data Encryption Key), data encrypted with AES-256-GCM - Linux: File-based DEK storage with AES-256-GCM encryption - Windows: DPAPI + Registry storage

Index

Constants

View Source
const (
	// Service is the unified keychain service name for all secrets.
	Service = "dws-cli"

	// AccountToken is the account key for storing auth token data.
	AccountToken = "auth-token"
)

Variables

This section is empty.

Functions

func CleanupLegacyBackup

func CleanupLegacyBackup(configDir string) error

CleanupLegacyBackup removes the backup file created during migration. Call this after confirming the new keychain storage works correctly.

func Exists

func Exists(service, account string) bool

Exists checks if an entry exists in the keychain.

func Get

func Get(service, account string) (string, error)

Get retrieves a value from the keychain. Returns empty string and nil error if the entry does not exist.

func HasLegacyData

func HasLegacyData(configDir string) bool

HasLegacyData checks if legacy .data file exists.

func Remove

func Remove(service, account string) error

Remove deletes an entry from the keychain. Returns nil if the entry does not exist.

func Set

func Set(service, account, data string) error

Set stores a value in the keychain, overwriting any existing entry.

func StorageDir

func StorageDir(service string) string

StorageDir returns the storage directory for a given service name. Follows XDG Base Directory Specification: ~/.local/share/<service>

Types

type KeychainAccess

type KeychainAccess interface {
	Get(service, account string) (string, error)
	Set(service, account, value string) error
	Remove(service, account string) error
}

KeychainAccess abstracts keychain Get/Set/Remove for dependency injection.

type MigrationResult

type MigrationResult struct {
	Migrated    bool   // true if migration was performed
	FromPath    string // source file path
	BackupPath  string // backup file path (if migrated)
	Error       error  // error if migration failed
	NeedRelogin bool   // true if user needs to re-login
}

MigrationResult contains the result of a migration attempt.

func MigrateFromLegacy

func MigrateFromLegacy(configDir string) *MigrationResult

MigrateFromLegacy attempts to migrate from the legacy MAC-based encryption to the new keychain-based storage. It: 1. Checks if legacy .data file exists 2. Tries to decrypt with MAC address 3. Re-encrypts and stores in keychain 4. Backs up the old file

If the keychain already has data, migration is skipped. If the legacy file doesn't exist, migration is skipped. If decryption fails (wrong MAC/corrupted), returns NeedRelogin=true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL