secure

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 14 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 secure holds the node's small cryptographic helpers: random tokens, token hashing, constant-time comparison, AES-256-GCM encryption of stored credentials and HMAC signing.

Index

Constants

This section is empty.

Variables

View Source
var ErrWeakPassword = errors.New("weak password")

ErrWeakPassword explains why a password is refused.

Functions

func CheckPassword

func CheckPassword(hash, pw string) bool

CheckPassword verifies pw against a hash produced by HashPassword.

func DummyPasswordCheck

func DummyPasswordCheck(pw string)

DummyPasswordCheck spends the same time as a real check, so login does not reveal whether an account exists.

func Equal

func Equal(a, b string) bool

Equal compares two strings in constant time.

func HashPassword

func HashPassword(pw string) (string, error)

HashPassword returns a PHC-formatted argon2id hash.

func HashToken

func HashToken(token string) string

HashToken is the SHA-256 hex of a high-entropy token (sufficient for random secrets; passwords use argon2id, see password.go).

func PasswordProblem

func PasswordProblem(pw string) string

PasswordProblem returns "" when pw is acceptable, else a human reason.

func RandomString

func RandomString(n int) string

RandomString returns n random bytes encoded as unpadded base64url.

func Token

func Token(prefix string) string

Token returns prefix + 32 random bytes (256 bits) in base64url.

func WebhookSignature

func WebhookSignature(secret, timestamp string, body []byte) string

WebhookSignature computes the OBX webhook signature header value: v1=hex(HMAC-SHA256(secret, "<ts>.<raw body>")), keyed with the secret's UTF-8 bytes including the whsec_ prefix.

Types

type Keys

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

Keys derives purpose-specific keys from the node secret.

func NewKeys

func NewKeys(secret []byte) *Keys

NewKeys wraps the node secret (OBX_SECRET_KEY, at least 32 bytes).

func (*Keys) Decrypt

func (k *Keys) Decrypt(s string) ([]byte, error)

Decrypt opens a value produced by Encrypt.

func (*Keys) Encrypt

func (k *Keys) Encrypt(plaintext []byte) (string, error)

Encrypt seals plaintext with AES-256-GCM; the result is base64url text.

func (*Keys) Sign

func (k *Keys) Sign(purpose, msg string) string

Sign returns the lowercase hex HMAC-SHA256 of msg under the key for purpose.

func (*Keys) Verify

func (k *Keys) Verify(purpose, msg, sig string) bool

Verify checks a signature produced by Sign in constant time.

Jump to

Keyboard shortcuts

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