httpsign

package
v0.0.0-...-ff4cbb2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 18 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 httpsign 实现 RFC 9421 的有界 HMAC-SHA256 请求签名配置,包含正文摘要与防重放。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sign

func Sign(r *http.Request, key Key, options ...SignOptions) error

Sign 签署方法、完整目标、类型与正文摘要,选项只能传零或一个。 客户端仅需 ID 和 Secret;Principal 只用于服务端可信密钥到身份的映射。

Types

type Config

type Config struct {
	Realm                string
	Keys                 []Key
	KeyStore             Keys
	Replays              dpop.Store
	MaxAge, Leeway       time.Duration
	MaxBodyBytes         int64
	MaxKeys, MaxRequests int
	AllowHTTP            bool
}

Config 限定可信密钥、重放存储、时间窗口与正文预算。

type Key

type Key struct {
	ID        string
	Secret    []byte
	Principal security.Principal
}

Key 保存调用方签名密钥及最小权限主体,密钥至少 32 字节。

func (Key) GoString

func (Key) GoString() string

GoString 隐藏 Go 格式化输出中的签名密钥。

func (Key) String

func (Key) String() string

String 隐藏签名密钥。

type Keys

type Keys interface {
	Get(context.Context, string) (Key, error)
}

Keys 提供登记密钥,调用方可实现外部密钥仓库。

type MemoryKeys

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

MemoryKeys 保存有界的独立密钥副本,支持原子轮换。

func NewMemoryKeys

func NewMemoryKeys(max int) (*MemoryKeys, error)

NewMemoryKeys 创建默认容量为 256 的内存密钥仓库。

func (*MemoryKeys) Close

func (m *MemoryKeys) Close()

Close 清除自有密钥内容并停止后续操作。

func (*MemoryKeys) Delete

func (m *MemoryKeys) Delete(ctx context.Context, id string) error

Delete 撤销可信调用方密钥。

func (*MemoryKeys) Get

func (m *MemoryKeys) Get(ctx context.Context, id string) (Key, error)

Get 返回独立密钥副本,缺失密钥不能回退为匿名认证。

func (*MemoryKeys) Put

func (m *MemoryKeys) Put(ctx context.Context, k Key) error

Put 新增或原子轮换可信密钥,复制密钥避免调用方修改。

type Service

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

Service 通过既有安全 Filter 验证签名与重放,外部存储由调用方拥有。

func New

func New(c Config) (*Service, error)

New 创建默认一分钟窗口、一 MiB 正文预算的签名验证器。

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, c security.Credential) (security.Principal, error)

Authenticate 校验签名、目标、时间及 nonce,成功后才原子登记重放状态。

func (*Service) Close

func (s *Service) Close() error

Close 仅释放自有密钥与重放仓库。

func (*Service) Credentials

func (s *Service) Credentials(r *http.Request) (security.Credential, error)

Credentials 验证完整正文摘要并恢复请求体,不读取转发目标或信任客户端身份头。

type SignOptions

type SignOptions struct {
	Lifetime     time.Duration
	MaxBodyBytes int64
	AllowHTTP    bool
}

SignOptions 可覆盖一分钟期限和一 MiB 正文预算。

Jump to

Keyboard shortcuts

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