Documentation
¶
Overview ¶
Package security — value resolution.
alaye.Value is the canonical type for lazy-resolving config strings. pkg/security provides Resolver to wire the keeper Store into alaye's resolution system via alaye.SetStoreLookup.
SecureString is kept here as a small wipe-on-use wrapper for any server-side code that wants an explicit zero-on-free primitive.
Index ¶
- Variables
- func NewPPK(path string) error
- type Cipher
- type HOTPGenerator
- func (h *HOTPGenerator) GenerateCode(secret string, counter int64) (string, error)
- func (h *HOTPGenerator) GenerateSecret() (string, error)
- func (h *HOTPGenerator) GetProvisioningURI(secret, username string, counter int64) string
- func (h *HOTPGenerator) NewHOTP(secret string) *gotp.HOTP
- func (h *HOTPGenerator) VerifyCode(secret, code string, counter int64) bool
- type PPK
- type Password
- func (g *Password) Dummy() []byte
- func (g *Password) Generate(length int) (string, error)
- func (g *Password) Hash(password string) (string, error)
- func (g *Password) HashWithCost(password string, cost int) (string, error)
- func (g *Password) JTI() (string, error)
- func (g *Password) Make(length int) (password, hash string, err error)
- func (g *Password) Random(n int) ([]byte, error)
- func (g *Password) Verify(password, hash string) bool
- type SecureString
- type TOTPConfig
- type TOTPGenerator
- func (t *TOTPGenerator) GenerateCode(secret string, timestamp int64) (string, error)
- func (t *TOTPGenerator) GenerateSecret() (string, error)
- func (t *TOTPGenerator) GetProvisioningURI(secret, username string) string
- func (t *TOTPGenerator) NewTOTP(secret string) *gotp.TOTP
- func (t *TOTPGenerator) Now(secret string) (string, error)
- func (t *TOTPGenerator) ValidateSecret(secret string) bool
- func (t *TOTPGenerator) VerifyCode(secret, code string) (ok bool)
- func (t *TOTPGenerator) VerifyCodeAtTime(secret, code string, timestamp int64) bool
- type TokenClaims
- type VerifiedToken
Constants ¶
This section is empty.
Variables ¶
var ErrDecrypt = errors.New("decryption failed")
Functions ¶
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher handles authenticated encryption using XChaCha20-Poly1305.
func NewCipher ¶
NewCipher creates a cipher. It attempts to decode secret as Base64. If decoding fails or length != 32, it hashes the string to generate a 32-byte key.
func NewCipherFromKey ¶ added in v0.1.0
type HOTPGenerator ¶ added in v0.1.0
type HOTPGenerator struct {
// contains filtered or unexported fields
}
HOTP support (counter-based)
func NewHOTPGenerator ¶ added in v0.1.0
func NewHOTPGenerator(config *TOTPConfig) *HOTPGenerator
NewHOTPGenerator creates a new HOTP generator
func (*HOTPGenerator) GenerateCode ¶ added in v0.1.0
func (h *HOTPGenerator) GenerateCode(secret string, counter int64) (string, error)
GenerateCode generates an HOTP code at the given counter
func (*HOTPGenerator) GenerateSecret ¶ added in v0.1.0
func (h *HOTPGenerator) GenerateSecret() (string, error)
GenerateSecret creates a new random HOTP secret
func (*HOTPGenerator) GetProvisioningURI ¶ added in v0.1.0
func (h *HOTPGenerator) GetProvisioningURI(secret, username string, counter int64) string
GetProvisioningURI returns the otpauth:// URI for HOTP
func (*HOTPGenerator) NewHOTP ¶ added in v0.1.0
func (h *HOTPGenerator) NewHOTP(secret string) *gotp.HOTP
NewHOTP creates a gotp.HOTP instance
func (*HOTPGenerator) VerifyCode ¶ added in v0.1.0
func (h *HOTPGenerator) VerifyCode(secret, code string, counter int64) bool
VerifyCode verifies an HOTP code at the given counter
type PPK ¶ added in v0.1.0
type PPK struct {
// contains filtered or unexported fields
}
func GeneratePPK ¶ added in v0.1.0
func LoadPPKFromPEM ¶ added in v0.1.0
type Password ¶ added in v0.1.0
type Password struct{}
Password handles password and hash generation
func NewPassword ¶ added in v0.1.0
func NewPassword() *Password
NewPassword creates a new password generator
func (*Password) Dummy ¶ added in v0.1.0
Dummy returns a dummy bcrypt hash for timing attack resistance
func (*Password) Generate ¶ added in v0.1.0
Generate creates a cryptographically secure random password of the specified length (default 32 if length <= 0)
func (*Password) HashWithCost ¶ added in v0.1.0
HashWithCost generates a bcrypt hash with custom cost
func (*Password) JTI ¶ added in v0.1.0
It returns the JTI string or an error if random generation fails.
type SecureString ¶ added in v0.1.0
type SecureString struct {
// contains filtered or unexported fields
}
SecureString holds a sensitive string and provides an explicit Wipe method that zeros the backing memory. Use it for short-lived copies of secrets that should not linger in heap memory.
func NewSecureString ¶ added in v0.1.0
func NewSecureString(s string) *SecureString
func (*SecureString) String ¶ added in v0.1.0
func (ss *SecureString) String() string
func (*SecureString) Wipe ¶ added in v0.1.0
func (ss *SecureString) Wipe()
type TOTPConfig ¶ added in v0.1.0
type TOTPConfig struct {
Digits int // 6 or 8 digits (default 6)
Period int // Time step in seconds (default 30)
Algorithm string // SHA1, SHA256, SHA512 (default SHA1)
Window int // Verification window size in time steps (default 1)
Issuer string // Issuer name for URI
}
TOTPConfig holds configuration for TOTP generation
func DefaultTOTPConfig ¶ added in v0.1.0
func DefaultTOTPConfig() *TOTPConfig
DefaultTOTPConfig returns sensible defaults
type TOTPGenerator ¶ added in v0.1.0
type TOTPGenerator struct {
// contains filtered or unexported fields
}
TOTPGenerator handles TOTP secret generation and code verification
func NewTOTPGenerator ¶ added in v0.1.0
func NewTOTPGenerator(config *TOTPConfig) *TOTPGenerator
NewTOTPGenerator creates a new TOTP generator with the given config
func (*TOTPGenerator) GenerateCode ¶ added in v0.1.0
func (t *TOTPGenerator) GenerateCode(secret string, timestamp int64) (string, error)
GenerateCode generates a TOTP code for the given secret at the specified time
func (*TOTPGenerator) GenerateSecret ¶ added in v0.1.0
func (t *TOTPGenerator) GenerateSecret() (string, error)
GenerateSecret creates a new random TOTP secret Returns base32-encoded secret (RFC 4648, no padding)
func (*TOTPGenerator) GetProvisioningURI ¶ added in v0.1.0
func (t *TOTPGenerator) GetProvisioningURI(secret, username string) string
GetProvisioningURI returns the otpauth:// URI for QR code generation Format: otpauth://totp/{issuer}:{username}?secret={secret}&issuer={issuer}&digits={digits}&period={period}
func (*TOTPGenerator) NewTOTP ¶ added in v0.1.0
func (t *TOTPGenerator) NewTOTP(secret string) *gotp.TOTP
NewTOTP creates a gotp.TOTP instance with the configured parameters
func (*TOTPGenerator) Now ¶ added in v0.1.0
func (t *TOTPGenerator) Now(secret string) (string, error)
Now generates the current TOTP code
func (*TOTPGenerator) ValidateSecret ¶ added in v0.1.0
func (t *TOTPGenerator) ValidateSecret(secret string) bool
ValidateSecret checks if a secret is valid base32
func (*TOTPGenerator) VerifyCode ¶ added in v0.1.0
func (t *TOTPGenerator) VerifyCode(secret, code string) (ok bool)
VerifyCode verifies a TOTP code against a secret Checks current time and adjacent windows based on config.Window
func (*TOTPGenerator) VerifyCodeAtTime ¶ added in v0.1.0
func (t *TOTPGenerator) VerifyCodeAtTime(secret, code string, timestamp int64) bool
VerifyCodeAtTime verifies a TOTP code at a specific timestamp
type TokenClaims ¶
type TokenClaims struct {
Service string `json:"svc"`
jwt.RegisteredClaims
}