Files
lmvpn_client/internal/keychain/keychain_other.go
T
kevin 027d837cb2 fix: 修复 Windows 端密码无法持久化的问题
Windows 端使用内存版 MemStore(keychain_other.go, 构建标签 !darwin),
进程退出后密码丢失,导致每次启动都需重新输入密码才能连接。

新增 keychain_windows.go,基于 Windows 凭据管理器(Credential Manager)
实现 Store 接口,密码经 Windows 登录凭据加密并持久化,跨重启保留。
keychain_other.go 构建标签收窄为 !darwin && !windows,作为 Linux 回退。

macOS 版本不受影响(仍由 keychain_darwin.go 独占编译)。
2026-07-07 17:47:41 +08:00

53 lines
1.4 KiB
Go

//go:build !darwin && !windows
package keychain
// MemStore is an in-memory fallback used on non-darwin, non-windows
// platforms (currently Linux). Passwords do not persist across
// restarts; a platform-appropriate backend (e.g. Secret Service)
// should be added for production use.
type MemStore struct {
data map[string]string
}
// New returns an in-memory Store (non-darwin fallback).
func New() Store {
return &MemStore{data: make(map[string]string)}
}
func (m *MemStore) SetPassword(profileName, password string) error {
m.data["password:"+profileName] = password
return nil
}
func (m *MemStore) GetPassword(profileName string) (string, error) {
v, ok := m.data["password:"+profileName]
if !ok {
return "", ErrNotFound
}
return v, nil
}
func (m *MemStore) DeletePassword(profileName string) error {
delete(m.data, "password:"+profileName)
return nil
}
func (m *MemStore) SetToken(profileName, token string) error {
m.data["token:"+profileName] = token
return nil
}
func (m *MemStore) GetToken(profileName string) (string, error) {
v, ok := m.data["token:"+profileName]
if !ok {
return "", ErrNotFound
}
return v, nil
}
func (m *MemStore) DeleteToken(profileName string) error {
delete(m.data, "token:"+profileName)
return nil
}
func (m *MemStore) DeleteAll(profileName string) error {
m.DeletePassword(profileName)
m.DeleteToken(profileName)
return nil
}