Documentation
¶
Overview ¶
Package lease verifies a KeyGrant lease offline: a compact JWS, EdDSA over Ed25519, against the build's key set (the reference's shared crypto.ts verifyLease), and reads its claims as the reference reads them.
Index ¶
- Constants
- func Grants(ent Entitlements, code string) bool
- func IsID(s string) bool
- func KeyID(jwk any) (string, error)
- func NamedKeyID(header, start string) string
- func PublicKeyBytes(jwk any) ([]byte, error)
- type Claims
- type Entitlement
- type EntitlementKind
- type Entitlements
- type Key
- type Meter
- type Meters
- type Result
Constants ¶
const ( Malformed = "malformed" UnknownKey = "unknown-key" BadSignature = "bad-signature" BadClaims = "bad-claims" Expired = "expired" )
Why a lease did not verify.
const Issuer = "keygrant"
Issuer is the `iss` every lease carries.
const OpenMajor = 1_000_000
OpenMajor is the `major` claim of a key with no upper bound.
Variables ¶
This section is empty.
Functions ¶
func Grants ¶
func Grants(ent Entitlements, code string) bool
Grants is whether ent grants code (grants): a flag that is true, a number that is not 0 (a negative counts), a text that is not empty. The code is matched exactly, case included.
func IsID ¶
IsID is whether s takes the form of a key id: 1 to 64 characters of the base64url alphabet.
func KeyID ¶
KeyID is a public key's id (keyId): the base64url, no padding, of the SHA-256 of {"crv":"Ed25519","kty":"OKP","x":"<x>"} with x written canonically. A kid member the JWK carries is not read.
func NamedKeyID ¶
NamedKeyID is the key id a header names when it is, byte for byte, canonical base64url of <start><kid>"}, kid 1 to 64 characters of the base64url alphabet; "" for any other header. Matched as bytes, never parsed.
func PublicKeyBytes ¶
PublicKeyBytes is a public JWK's raw key, checked as every SDK checks one (publicKeyBytes): an object whose kty is "OKP" and crv "Ed25519"; no private d; use, when given, "sig"; key_ops, when given, a list naming "verify"; alg, when given, "EdDSA" or "Ed25519"; and an x that, its trailing "=" dropped, is canonical base64url of 32 bytes. No other member is read.
Types ¶
type Claims ¶
type Claims struct {
Sub, Product, Aid string
Fp *string // the device's fingerprint claim, 1 to 128 UTF-16 units
Fpk *string // "machine" or "hostname"
Model string // "perpetual", "subscription" or "trial"
Lim float64 // a positive whole number
Major float64 // a non-negative whole number, 0 when absent
MinMajor *float64
UpgradeUntil *float64 // seconds
Ent Entitlements
Met Meters // nil when the lease has no `met`
Iat, Exp float64 // seconds
Grace *bool
Test *bool
}
Claims are a lease's claims as a verifier reads them (LeaseClaims). Numbers are doubles, as the reference reads JSON; an optional claim the lease does not carry is nil. Unknown claims are not kept.
func ParseClaims ¶
ParseClaims reads a payload's JSON value as LeaseClaims.parse does, or reports false for one that is not a lease's claims (bad-claims).
type Entitlement ¶
type Entitlement struct {
Kind EntitlementKind
Flag bool
Number float64
Text string
}
Entitlement is one entitlement's value: a flag, a number (a double, as JSON and JavaScript read one) or a text. Only the field its Kind names is set.
type EntitlementKind ¶
type EntitlementKind int
EntitlementKind is what an entitlement's value is.
const ( // Flag is a JSON boolean. Flag EntitlementKind = iota + 1 // Number is a JSON number, read as a double. Number // Text is a JSON string. Text )
type Entitlements ¶
type Entitlements map[string]Entitlement
Entitlements are a lease's `ent`, by name. A Go map has no order; nothing in the SDK reads one, and any listing of them sorts the names.
func EntitlementsOf ¶
func EntitlementsOf(raw any) Entitlements
EntitlementsOf is `ent` as a verifier reads it (entitlementsOf): an object's flag, number and text members, kept as they are; every other member (an object, a list, null) dropped; and none at all from anything but an object. Never a refusal.
type Key ¶
Key is one public key of a key set, with its id (its RFC 7638 thumbprint).
func ImportKeys ¶
ImportKeys is a key set (importVerifyingKeys): each public JWK with its id, in the order given, a key given twice kept once. An empty set, or a JWK that is not an Ed25519 public key, is an error.
type Meter ¶
Meter is one meter as a lease signs it (`met`): what the key had left when it was signed, the uses it holds, the allowance each device may spend with no answer, and whether it comes back each billing period.
type Meters ¶
Meters are a lease's `met`, by code.
func MetersOf ¶
MetersOf is `met` as a verifier reads it (metersOf): each member of an object that is an object whose left, total and offline are figures, resets true only for JSON true; every other member dropped; none at all from anything but an object. Never a refusal, and the server's caps are not enforced.
type Result ¶
type Result struct {
Valid bool
Reason string // "" when valid
Claims *Claims // the claims of a valid or an expired lease, else nil
}
Result is what verifying a lease says: valid with its claims, or why not, with the claims of a lease that merely expired.
func Verify ¶
Verify verifies a lease offline against a key set at now (ms), as verifyLease does: three parts; a canonical signature; the key the header names (only in the exact form the server writes it), or each key in turn when it names none; Ed25519 over header.payload as received; the claims; then expiry, exp * 1000 < now. The algorithm is the verifier's, never the token's.