deviceauth

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package deviceauth authenticates the optional device transport envelope. A shared transport key does not attest a physical device or an official app.

Index

Constants

View Source
const (
	MaxAge     = 5 * time.Minute
	FutureSkew = 30 * time.Second
)

Variables

View Source
var ErrInvalidEnvelope = errors.New("invalid device envelope")

Functions

func Decrypt

func Decrypt(cipherText string, keyStr string, ivStr string) (string, error)

Decrypt 传入 []byte 类型的加密数据,返回解密后的 []byte 明文数据

func Encrypt

func Encrypt(plainText []byte, keyStr string) (string, string, error)

Encrypt 传入 []byte,返回 []byte 类型的加密数据

func Sign

func Sign(secret, method, path, scope, data, timestamp string) string

Sign binds the ciphertext to its HTTP operation and envelope location. scope is one of "query", "body", or "response".

Types

type Envelope

type Envelope struct {
	Data string `json:"data"`
	Time string `json:"time"`
	Sign string `json:"sign"`
}

func (Envelope) Consume

func (e Envelope) Consume(ctx context.Context, store ReplayStore, secret string) error

Consume reserves the nonce across all server instances. Redis errors fail closed; the TTL spans the entire acceptance window including clock skew.

func (Envelope) Open

func (e Envelope) Open(secret, method, path, scope string, now time.Time) (string, error)

type ReplayStore

type ReplayStore interface {
	SetNX(context.Context, string, interface{}, time.Duration) *redis.BoolCmd
}

Jump to

Keyboard shortcuts

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