Documentation
¶
Overview ¶
Package crypto provides AES-GCM-256 encryption primitives and master-key helpers for Relay's stored-secret subsystem, plus the claim set inference tokens carry (token_claims.go; the token format itself is auth/token). All functions are pure; the package has no state.
Index ¶
Constants ¶
const TokenIssuer = "relay"
TokenIssuer is the only `iss` a relay-minted token carries.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
Decrypt decrypts ciphertext (with GCM auth tag) using masterKey and nonce. Returns an error if the tag is invalid or inputs are malformed; never panics.
func Encrypt ¶
Encrypt encrypts plaintext with AES-GCM-256 using masterKey. masterKey must be exactly 32 bytes. A fresh 12-byte nonce is read from crypto/rand on each call. Returns ciphertext (with GCM auth tag appended by gcm.Seal) and nonce separately; callers store them in distinct DB columns.
func GenerateMasterKey ¶
GenerateMasterKey generates 32 random bytes and returns them as a base64.StdEncoding string suitable for use as RELAY_MASTER_KEY.
func ParseMasterKey ¶
ParseMasterKey base64-decodes (StdEncoding) raw and validates the result is exactly 32 bytes. Returns the raw key bytes or a structured error.
Types ¶
type TokenClaims ¶ added in v0.10.0
type TokenClaims struct {
Iss string `json:"iss"`
Sub string `json:"sub"` // "user:<id>"
Prj string `json:"prj"` // project id
Grp []string `json:"grp,omitempty"`
Ver int `json:"ver"` // the user's token version at mint time
Jti string `json:"jti"`
Iat int64 `json:"iat"`
Exp int64 `json:"exp"`
}
TokenClaims is the inference token's payload. Every field is required except Grp, which is empty for a user in no groups.
func (TokenClaims) UserID ¶ added in v0.10.0
func (c TokenClaims) UserID() string
UserID returns the user id the "user:<id>" subject names, or "" when the subject is malformed or names another principal kind.