credentials

package
v0.23.5 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package credentials shares remote-service credentials between family apps (spec §8): one login-Keychain item per vendor account (service "ActNow", account "vendor.<id>", written with /usr/bin/security), and credentials.json for what is not secret (a hint, a fingerprint, which apps use it). An app reads a shared secret only after the user agreed in that app ("Use this key"), which adds it to the vendor's users.

Index

Constants

View Source
const (
	EnvNoKeychain   = "ACTNOW_NO_KEYCHAIN"
	EnvKeychainFile = "ACTNOW_KEYCHAIN_FILE"
)

EnvNoKeychain set to "1" keeps every Keychain of the process away from the macOS Keychain (scripted checks, CI): the items go to a stand-in file (EnvKeychainFile, else $HOME/.actnow-keychain-standin.json).

View Source
const (
	AuthAPIKey           = "apiKey"
	AuthAppIDAccessToken = "appId+accessToken" // Doubao speech: the App ID is not secret
	AuthToken            = "token"             // Hugging Face access token
)

Auth kinds of a vendor's credential.

View Source
const Kind = "credentials"

Kind is the schema kind of credentials.json.

View Source
const Service = "ActNow"

Service is the Keychain service of the family's shared secrets.

Variables

View Source
var (
	ErrNotFound   = errors.New("no such Keychain item")
	ErrNoKeychain = errors.New("no Keychain on this system")
)

Errors of the Keychain.

View Source
var (
	ErrUnknownVendor = errors.New("unknown vendor")
	// ErrNotConsented: this app is not among the vendor's users; ask the
	// user first (TextUseKeyFrom) and call Use.
	ErrNotConsented = errors.New("the user has not agreed to use this shared key in this app")
	// ErrMissing: the metadata names a key whose Keychain item is gone
	// (deleted in Keychain Access): ask for the key again.
	ErrMissing = errors.New("the shared key is no longer in the Keychain")
)

Errors of the Store.

View Source
var (
	TextShareCheckbox = family.Text{EN: "Let other ActNow apps on this Mac use this key", ZH: "允许这台 Mac 上的其他 ActNow app 使用此密钥"}
	TextUseKeyFrom    = family.Text{EN: "Use the {vendor} key from {app} ({hint})", ZH: "使用 {app} 中的 {vendor} 密钥({hint})"}
	TextUseThisKey    = family.Text{EN: "Use this key", ZH: "使用此密钥"}
	TextEnterAnother  = family.Text{EN: "Enter another key", ZH: "输入其他密钥"}
	TextFoundKeys     = family.Text{
		EN: "Found API keys in other ActNow apps: {vendors}. Use them in {app}?",
		ZH: "在其他 ActNow app 中找到 API 密钥:{vendors}。要在 {app} 中使用吗?",
	}
	TextUseThem = family.Text{EN: "Use them", ZH: "使用"}
	TextNotNow  = family.Text{EN: "Not now", ZH: "暂不"}
	// Deprecated: use TextAlsoUpdatesShared (v0.22.1), which names no apps.
	TextAlsoUpdates = family.Text{EN: "Also updates it in {apps}.", ZH: "{apps} 中也会一并更新。"}
	// TextAlsoUpdatesShared: under a shared key, without the apps' names.
	TextAlsoUpdatesShared = family.Text{EN: "Shared across ActNow: the other apps get the new key too.", ZH: "ActNow 共用:其他 App 也会一并更新。"}
	TextAlsoUsesKey       = family.Text{EN: "{apps} also uses this key.", ZH: "{apps} 也在使用此密钥。"}
	TextStopHere          = family.Text{EN: "Stop using it here", ZH: "仅在此处停用"}
	TextDeleteAll         = family.Text{EN: "Delete for all apps", ZH: "为所有 app 删除"}
	TextDifferentKey      = family.Text{EN: "{app} has a different {vendor} key.", ZH: "{app} 中的 {vendor} 密钥与此不同。"}
	TextSecurityHelp      = family.Text{
		EN: "Shared keys are stored in your login keychain. Like each app's own keys, other programs you run can read them with the security tool.",
		ZH: "共享密钥保存在登录钥匙串中。与各 app 自己保存的密钥一样,你运行的其他程序可以通过 security 工具读取它们。",
	}
)

Reference texts (spec §8.3).

View Source
var OnSecurity func(args ...string)

OnSecurity, when set, is called before every run of /usr/bin/security (with its arguments): tests and scripted checks prove a guarded process never runs it.

View Source
var Vendors = []Vendor{
	{ID: "openai", Name: "OpenAI", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.openai"), llm("auralink", "llm.openai"), llm("auralink", "asr.openai")},
		Note: "Auralink's OpenAI-compatible ASR with a custom endpoint is not this vendor."},
	{ID: "anthropic", Name: "Anthropic", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.anthropic"), llm("auralink", "llm.anthropic")}},
	{ID: "deepseek", Name: "DeepSeek", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.deepseek"), llm("auralink", "llm.deepseek")}},
	{ID: "dashscope", Name: "Alibaba Cloud Model Studio (China)", NameZH: "阿里云百炼(中国站)", Auth: AuthAPIKey,
		Legacy: []Legacy{llm("audiosmith", "llm.dashscope"), llm("auralink", "llm.dashscope"), llm("auralink", "asr.aliyun")},
		Note:   "One DashScope key serves both ASR and LLM."},
	{ID: "dashscope-intl", Name: "Alibaba Cloud Model Studio (International)", NameZH: "阿里云百炼(国际站)", Auth: AuthAPIKey,
		Legacy: []Legacy{llm("audiosmith", "llm.dashscope-intl"), llm("auralink", "llm.dashscope-intl")}},
	{ID: "stepfun", Name: "StepFun", NameZH: "阶跃星辰", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "llm.stepfun"), llm("auralink", "asr.stepfun")}},
	{ID: "volcengine-ark", Name: "Volcano Engine Ark", NameZH: "火山方舟", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "llm.volcengine")},
		Note: "Not the same credential as Doubao speech."},
	{ID: "volcengine-speech", Name: "Doubao Speech", NameZH: "豆包语音", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "asr.doubao")},
		Note: "Either an API key, or an App ID (not secret, kept in credentials.json) and an access token."},
	{ID: "moonshot", Name: "Kimi (moonshot.cn)", NameZH: "Kimi(中国站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.moonshot"), llm("auralink", "llm.moonshot")},
		Note: "AudioSmith's llm.moonshot served both sites: its base URL decides (VendorForLegacy)."},
	{ID: "moonshot-intl", Name: "Kimi (moonshot.ai)", NameZH: "Kimi(国际站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "llm.moonshot-intl")}},
	{ID: "siliconflow", Name: "SiliconFlow (siliconflow.cn)", NameZH: "硅基流动(中国站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.siliconflow"), llm("auralink", "llm.siliconflow")},
		Note: "AudioSmith's llm.siliconflow served both sites: its base URL decides (VendorForLegacy)."},
	{ID: "siliconflow-intl", Name: "SiliconFlow (siliconflow.com)", NameZH: "硅基流动(国际站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "llm.siliconflow-intl")}},
	{ID: "zhipu", Name: "Zhipu AI", NameZH: "智谱 AI", Auth: AuthAPIKey, Legacy: both("llm.zhipu")},
	{ID: "minimax", Name: "MiniMax", Auth: AuthAPIKey, Legacy: both("llm.minimax")},
	{ID: "mimo", Name: "Xiaomi MiMo", NameZH: "小米 MiMo", Auth: AuthAPIKey, Legacy: both("llm.mimo")},
	{ID: "gemini", Name: "Google Gemini", Auth: AuthAPIKey, Legacy: both("llm.gemini")},
	{ID: "xai", Name: "xAI", Auth: AuthAPIKey, Legacy: both("llm.xai")},
	{ID: "groq", Name: "Groq", Auth: AuthAPIKey, Legacy: both("llm.groq")},
	{ID: "mistral", Name: "Mistral AI", Auth: AuthAPIKey, Legacy: both("llm.mistral")},
	{ID: "together", Name: "Together AI", Auth: AuthAPIKey, Legacy: both("llm.together")},
	{ID: "fireworks", Name: "Fireworks AI", Auth: AuthAPIKey, Legacy: both("llm.fireworks")},
	{ID: "cerebras", Name: "Cerebras", Auth: AuthAPIKey, Legacy: both("llm.cerebras")},
	{ID: "nvidia", Name: "NVIDIA NIM", Auth: AuthAPIKey, Legacy: both("llm.nvidia")},
	{ID: "openrouter", Name: "OpenRouter", Auth: AuthAPIKey, Legacy: both("llm.openrouter")},
	{ID: "deepl", Name: "DeepL", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "mt.deepl")}},
	{ID: "google-translate", Name: "Google Cloud Translation", NameZH: "Google 翻译", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "mt.google")},
		Note: "mt.google-v3 is an OAuth token and is not shared."},
	{ID: "microsoft-translator", Name: "Microsoft Translator", NameZH: "微软翻译", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "mt.microsoft")}},
	{ID: "huggingface", Name: "Hugging Face", Auth: AuthToken, Legacy: []Legacy{llm("audiosmith", "huggingface-token"), llm("dicta", "huggingface-token")}},
}

Vendors is the vendor table. New vendors only add rows.

Functions

func Account

func Account(vendor string) string

Account is a vendor's account name: "vendor.deepseek".

func Fingerprint

func Fingerprint(secret string) string

Fingerprint is "sha256:" and the first 12 hex digits of the secret's SHA-256: enough to tell whether two apps hold the same key, nothing more (spec §8.2).

func Hint

func Hint(secret string) string

Hint shows a secret as the UI may: its prefix ("sk-", "hf_") and last 4 characters, "sk-…a1b2"; short secrets show nothing.

func KeychainGuarded added in v0.22.0

func KeychainGuarded() (bool, string)

KeychainGuarded reports whether this process keeps away from the macOS Keychain (and why): its Keychains then use a stand-in file.

func ParseRef

func ParseRef(ref string) (vendor string, ok bool)

ParseRef returns the vendor of a credentialRef; ok false when it is not a shared one.

func Ref

func Ref(vendor string) string

Ref is the credentialRef an app keeps in its provider settings for a shared credential: "actnow:vendor.deepseek".

func RunSecurity

func RunSecurity(stdin string, args ...string) ([]byte, []byte, error)

RunSecurity runs /usr/bin/security (the default Keychain.Run).

Types

type Entry

type Entry struct {
	Account     string       `json:"account"` // "vendor.deepseek"
	Auth        string       `json:"auth"`
	AppID       string       `json:"appId,omitempty"` // Doubao speech's App ID
	Hint        string       `json:"hint"`
	Fingerprint string       `json:"fingerprint"`
	AddedBy     string       `json:"addedBy"` // bundle id
	Updated     time.Time    `json:"updated"`
	Users       []string     `json:"users"` // bundle ids that agreed to use it
	Extra       family.Extra `json:"-"`
}

Entry is a shared vendor credential's metadata in credentials.json. Never a secret: hint and fingerprint only.

func (Entry) MarshalJSON

func (e Entry) MarshalJSON() ([]byte, error)

func (*Entry) UnmarshalJSON

func (e *Entry) UnmarshalJSON(b []byte) error

type File

type File struct {
	Schema  string           `json:"schema"`
	Rev     int              `json:"rev"`
	Vendors map[string]Entry `json:"vendors"`
	Extra   family.Extra     `json:"-"`
}

File is credentials.json (multi-writer, locks/credentials.lock).

func Read

func Read(d family.Dir) (f File, readOnly bool, err error)

Read reads credentials.json; readOnly when a newer major wrote it.

func (File) MarshalJSON

func (f File) MarshalJSON() ([]byte, error)

func (*File) UnmarshalJSON

func (f *File) UnmarshalJSON(b []byte) error

type Keychain

type Keychain struct {
	// Service is the items' service; "" = Service ("ActNow"). Apps also
	// use a Keychain with their own service to read legacy items.
	Service string
	// File is a keychain file to use instead of the login keychain
	// (tests: the login keychain is locked in SSH sessions).
	File string
	// Run runs security with args and stdin and returns its standard
	// output and error; nil = /usr/bin/security (tests replace it), or,
	// when the process must keep away from the Keychain (KeychainGuarded:
	// a HOME that is not the user's, ACTNOW_NO_KEYCHAIN=1), a stand-in
	// file. A missing item is ErrNotFound.
	Run func(stdin string, args ...string) (stdout, stderr []byte, err error)
}

Keychain is generic-password items of the login keychain, read and written by /usr/bin/security as the apps already do (spec §8.2): no -T, so any process of the user running security can read them — the same protection the apps' own items have today. Every method may block: call them off the main thread.

func (Keychain) Delete

func (k Keychain) Delete(account string) error

Delete removes an item; none is not an error.

func (Keychain) Get

func (k Keychain) Get(account string) (string, error)

Get reads a secret; ErrNotFound when there is no item. It uses -g rather than -w: -w prints secrets with non-printable characters (and quotes, backslashes, non-ASCII) as bare hex, which cannot be told apart from a secret made of hex digits; -g marks hex with "0x".

func (Keychain) Set

func (k Keychain) Set(account, label, secret string) error

Set saves a secret, replacing an item with the same service and account. The secret goes to security's standard input (interactive mode), hex-encoded (-X), never on a command line other processes can list, and needs no escaping.

type Legacy

type Legacy struct {
	App     string // app id
	Service string // Keychain service: the app's name
	Account string
}

Legacy is a secret an app kept under its own service before the spec ("AudioSmith" / "llm.deepseek"). Migration copies it to the shared item once the user agrees.

type SaveOptions

type SaveOptions struct {
	// AppID is Doubao speech's App ID (Auth AuthAppIDAccessToken).
	AppID string
	// Auth overrides the vendor's default auth kind.
	Auth string
}

SaveOptions are extra fields of Save.

type Store

type Store struct {
	Family   family.Dir
	BundleID string
	Keychain Keychain // Service "" = "ActNow"
}

Store is one app's access to the shared credentials.

func (*Store) Compare

func (s *Store) Compare(vendor, secret string) (shared, same bool)

Compare tells whether an app's own key for a vendor is the shared one (spec §15.2 step 6: different keys are never merged; the consumer shows TextDifferentKey and lets the user choose). shared is false when the vendor has no shared key.

func (*Store) DeleteForAll

func (s *Store) DeleteForAll(ctx context.Context, vendor string) error

DeleteForAll removes the Keychain item and its metadata.

func (*Store) Forget

func (s *Store) Forget(ctx context.Context, vendor string) error

Forget drops a vendor's metadata (its item is gone).

func (*Store) MigrateLegacy

func (s *Store) MigrateLegacy(ctx context.Context, vendor string, old Legacy, opts SaveOptions) error

MigrateLegacy copies an app's old item (e.g. "AudioSmith"/"llm.deepseek") to the shared item after the user agreed to share it, reads it back to check, and joins the users. The old item is kept until the app's next major version (spec §15.2 step 6).

func (*Store) Offer

func (s *Store) Offer(vendor string) (Entry, bool)

Offer returns the shared credential of a vendor, if any, for the consumer's prompt "Use the DeepSeek key from Auralink (sk-…a1b2)". It never reads the secret.

func (*Store) OtherUsers

func (s *Store) OtherUsers(vendor string) []string

OtherUsers are the vendor's users besides this app, for "Auralink also uses this key" before deleting.

func (*Store) Save

func (s *Store) Save(ctx context.Context, vendor, secret string, opts SaveOptions) error

Save stores a key the user entered in this app with "Let other ActNow apps on this Mac use this key" checked (spec §8.3): the Keychain item "ActNow"/"vendor.<id>" is written (replacing another app's key for the same vendor: TextAlsoUpdates) and this app joins its users.

func (*Store) Secret

func (s *Store) Secret(ctx context.Context, vendor string) (string, error)

Secret reads the vendor's shared key for an app that agreed to use it (ErrNotConsented otherwise: never read it before the user agreed, not even for a connection test). A missing item drops the metadata and returns ErrMissing.

func (*Store) StopUsing

func (s *Store) StopUsing(ctx context.Context, vendor string) error

StopUsing is "Stop using it here": this app leaves the users; the key stays for the others.

func (*Store) Use

func (s *Store) Use(ctx context.Context, vendor string) (string, error)

Use is the user clicking "Use this key": this app joins the vendor's users, then reads the secret. ErrMissing when the item is gone (the metadata is then dropped).

func (*Store) Using

func (s *Store) Using(vendor string) bool

Using reports whether this app agreed to use the vendor's shared key.

type Vendor

type Vendor struct {
	ID     string
	Name   string // English display name
	NameZH string // Chinese display name ("" = Name)
	Auth   string
	Legacy []Legacy
	Note   string
}

Vendor is a row of the vendor table (spec §8.1): one account on one platform, whatever an app uses it for (ASR, LLM).

func VendorByID

func VendorByID(id string) (Vendor, bool)

VendorByID finds a vendor.

func VendorForLegacy

func VendorForLegacy(appID, account, baseURL string) (Vendor, bool)

VendorForLegacy finds the vendor of an app's old Keychain account ("audiosmith", "llm.deepseek"). baseURL is the provider's endpoint, which decides the site for accounts that served two (AudioSmith's llm.moonshot, llm.siliconflow); "" picks the Chinese site. An OpenAI account with a custom (non-api.openai.com) endpoint is not shared.

func (Vendor) Label

func (v Vendor) Label() string

Label is the Keychain item's label: "ActNow DeepSeek".

Jump to

Keyboard shortcuts

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