auth

package
v0.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: GPL-3.0 Imports: 12 Imported by: 0 modules, 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 auth 实现桥接协议的认证原语:双向 HMAC 挑战应答握手(会话/配对两种模式)、 配对码派生(HKDF)与长期密钥下发(AES-256-GCM)。长期密钥的落盘存储见 internal/daemon/store。全部常量取自内嵌 protocol.json(见 internal/pkg/protocol), 不在此硬编码。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPairingCode

func FormatPairingCode(canonical string) string

FormatPairingCode 把规范配对码格式化为 XXXX-XXXX 展示形。

func NewLongTermKey

func NewLongTermKey() ([]byte, error)

NewLongTermKey 生成 256-bit 长期共享密钥 K。

func NewPairingCode

func NewPairingCode() (canonical, display string, err error)

NewPairingCode 生成一次性配对码,返回规范形(8 字符)与展示形(XXXX-XXXX)。

func NormalizePairingCode

func NormalizePairingCode(s string) string

NormalizePairingCode 归一化用户输入:去连字符/空格、大写,并按 Crockford 规则消歧混淆字符。

func RandomNonceHex

func RandomNonceHex(n int) (string, error)

RandomNonceHex 生成 n 字节随机数并返回小写 hex 表示。

Types

type Crypto

type Crypto struct {
	// contains filtered or unexported fields
}

Crypto 承载从 protocol.json 读出的上下文字符串,提供握手与配对的密码学操作。

func NewCrypto

func NewCrypto(p *protocol.Protocol) *Crypto

NewCrypto 用协议常量构造密码学助手。

func (*Crypto) BrowserDaemonHMAC added in v0.2.0

func (c *Crypto) BrowserDaemonHMAC(mode Mode, instanceID string, key []byte, nonceD, nonceE string) string

BrowserDaemonHMAC 计算 daemon 对浏览器实例的 $session.authenticated HMAC: context=browser*Daemon || instanceID || nonceE || nonceD。

func (*Crypto) BrowserExtHMAC added in v0.2.0

func (c *Crypto) BrowserExtHMAC(mode Mode, instanceID string, key []byte, nonceD, nonceE string) string

BrowserExtHMAC 计算浏览器实例对 $session.authenticate 的应答 HMAC: context=browser*Ext(区分对端类型)|| instanceID || nonceD || nonceE。instanceID 与 nonce 都是定长 小写 hex(由 bridge 在边界校验),拼接无歧义;绑定实例 ID 使截获的 MAC 无法冒充另一实例重放。

func (*Crypto) DaemonHMAC

func (c *Crypto) DaemonHMAC(mode Mode, key []byte, nonceD, nonceE string) string

DaemonHMAC 计算 daemon $session.authenticated 通知应携带的 HMAC:context=ctx.*Daemon,顺序 nonceE||nonceD。

func (*Crypto) DerivePairingKeys

func (c *Crypto) DerivePairingKeys(code string) (kpMac, kpEnc []byte, err error)

DerivePairingKeys 从配对码派生 (Kp_mac, Kp_enc),各 32 字节。

func (*Crypto) ExtHMAC

func (c *Crypto) ExtHMAC(mode Mode, key []byte, nonceD, nonceE string) string

ExtHMAC 计算扩展对 $session.authenticate 的响应应携带的 HMAC:context=ctx.*Ext,顺序 nonceD||nonceE。

func (*Crypto) OpenKey

func (c *Crypto) OpenKey(kpEnc []byte, ctB64, ivB64 string) ([]byte, error)

OpenKey 用 Kp_enc 解出下发的长期密钥 K(扩展侧逻辑,供测试对拍)。

func (*Crypto) SealKey

func (c *Crypto) SealKey(kpEnc, k []byte) (ctB64, ivB64 string, err error)

SealKey 用 Kp_enc 以 AES-256-GCM 加密长期密钥 K,返回 base64(密文+tag) 与 base64(iv)。

func (*Crypto) VerifyBrowserDaemonHMAC added in v0.2.0

func (c *Crypto) VerifyBrowserDaemonHMAC(mode Mode, instanceID string, key []byte, nonceD, nonceE, got string) bool

VerifyBrowserDaemonHMAC 恒定时间校验 daemon 对浏览器实例的 HMAC(供扩展/测试使用)。

func (*Crypto) VerifyBrowserExtHMAC added in v0.2.0

func (c *Crypto) VerifyBrowserExtHMAC(mode Mode, instanceID string, key []byte, nonceD, nonceE, got string) bool

VerifyBrowserExtHMAC 恒定时间校验浏览器实例应答的 HMAC。

func (*Crypto) VerifyDaemonHMAC

func (c *Crypto) VerifyDaemonHMAC(mode Mode, key []byte, nonceD, nonceE, got string) bool

VerifyDaemonHMAC 恒定时间校验 daemon $session.authenticated 的 HMAC(供扩展/测试使用)。

func (*Crypto) VerifyExtHMAC

func (c *Crypto) VerifyExtHMAC(mode Mode, key []byte, nonceD, nonceE, got string) bool

VerifyExtHMAC 恒定时间校验扩展应答的 HMAC。

type Mode

type Mode int

Mode 区分握手所用的上下文与密钥来源。

const (
	// ModeSession 使用长期共享密钥 K 的会话握手。
	ModeSession Mode = iota
	// ModePairing 使用配对码派生密钥 Kp_mac 的首次配对握手。
	ModePairing
)

Jump to

Keyboard shortcuts

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