authtoken

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenPrefix = "stk"
)

Variables

This section is empty.

Functions

func Parse

func Parse(raw string) (tokenID string, secret string, err error)

func SaveVault

func SaveVault(v *Vault) error

func VaultPath

func VaultPath() (string, error)

func Verify

func Verify(raw string, rec StoredToken) (string, bool)

Types

type CreateOptions

type CreateOptions struct {
	DevicePepper []byte
	BindToDevice bool
	ExpiresAt    *time.Time
	MaxUses      int
	SyncEnabled  bool
}

type ExecPayload

type ExecPayload struct {
	HostID              int    `json:"host_id"`
	DisplayLabel        string `json:"display_label"`
	Hostname            string `json:"hostname"`
	Username            string `json:"username"`
	Port                int    `json:"port"`
	KeyType             string `json:"key_type"`
	Secret              string `json:"secret"`
	HostKeyPolicy       string `json:"host_key_policy"`
	KeepAliveSeconds    int    `json:"keepalive_seconds"`
	Term                string `json:"term"`
	PasswordBackendUnix string `json:"password_backend_unix"`
}

type HostGrant

type HostGrant struct {
	HostID       int
	DisplayLabel string
}

type ResolveResult

type ResolveResult struct {
	TokenIndex int
	TokenID    string
	HostID     int
	HostLabel  string

	DBUnlockSecret string
	LegacyPayload  *ExecPayload
}

type StoredToken

type StoredToken struct {
	TokenID string `json:"token_id"`
	Name    string `json:"name"`

	Salt string `json:"salt,omitempty"`
	Hash string `json:"hash,omitempty"`

	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
	UseCount   int        `json:"use_count"`

	RevokedAt *time.Time `json:"revoked_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`

	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	MaxUses   int        `json:"max_uses,omitempty"`

	SyncEnabled bool `json:"sync_enabled,omitempty"`

	UnlockSalt  string `json:"unlock_salt,omitempty"`
	UnlockData  string `json:"unlock_data,omitempty"`
	UnlockBound bool   `json:"unlock_bound,omitempty"`

	Hosts []StoredTokenHost `json:"hosts"`
}

func CreateToken

func CreateToken(name string, grants []HostGrant, dbUnlockSecret string, opts CreateOptions) (string, StoredToken, error)

func (StoredToken) IsLegacyPayload

func (t StoredToken) IsLegacyPayload() bool

func (StoredToken) IsUsable

func (t StoredToken) IsUsable() bool

type StoredTokenHost

type StoredTokenHost struct {
	HostID       int    `json:"host_id"`
	DisplayLabel string `json:"display_label"`

	// Legacy v1 fields retained for backward compatibility.
	PayloadSalt string `json:"payload_salt,omitempty"`
	Payload     string `json:"payload,omitempty"`
}

type SyncTokenDef

type SyncTokenDef struct {
	TokenID string `json:"token_id"`
	Name    string `json:"name"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	RevokedAt *time.Time `json:"revoked_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	MaxUses   int        `json:"max_uses,omitempty"`

	SyncEnabled bool            `json:"sync_enabled,omitempty"`
	Hosts       []SyncTokenHost `json:"hosts"`
}

type SyncTokenHost

type SyncTokenHost struct {
	HostID       int    `json:"host_id"`
	DisplayLabel string `json:"display_label"`
}

type TokenSummary

type TokenSummary struct {
	TokenID    string
	Name       string
	HostCount  int
	CreatedAt  time.Time
	UpdatedAt  time.Time
	LastUsedAt *time.Time
	UseCount   int
	RevokedAt  *time.Time
	DeletedAt  *time.Time
	ExpiresAt  *time.Time
	MaxUses    int

	SyncEnabled bool
	Usable      bool
	Legacy      bool
}

type Vault

type Vault struct {
	Version int           `json:"version"`
	Tokens  []StoredToken `json:"tokens"`
}

func LoadVault

func LoadVault() (*Vault, error)

func (*Vault) ActivateToken

func (v *Vault) ActivateToken(tokenID string, dbUnlockSecret string, devicePepper []byte) (string, error)

func (*Vault) AddToken

func (v *Vault) AddToken(rawToken string, rec StoredToken) error

func (*Vault) DeleteRevokedToken

func (v *Vault) DeleteRevokedToken(tokenID string) (bool, error)

func (*Vault) ExportSyncDefinitions

func (v *Vault) ExportSyncDefinitions() []SyncTokenDef

func (*Vault) ListSummaries

func (v *Vault) ListSummaries() []TokenSummary

func (*Vault) MarkUsed

func (v *Vault) MarkUsed(tokenIndex int)

func (*Vault) MergeSyncDefinitions

func (v *Vault) MergeSyncDefinitions(defs []SyncTokenDef) bool

func (*Vault) Resolve

func (v *Vault) Resolve(rawToken string, targetLabel string, devicePepper []byte) (ResolveResult, error)

func (*Vault) RevokeToken

func (v *Vault) RevokeToken(tokenID string) bool

func (*Vault) SyncHostLabels

func (v *Vault) SyncHostLabels(labels map[int]string) bool

Jump to

Keyboard shortcuts

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