license

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 9 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 license implements offline validation of signed 2papi licenses.

Format (one line): <prefix>:<base64url(payloadJSON)>.<base64url(sig)>

  • prefix is the edition id ("ent" | "cloud");
  • sig = ed25519.Sign(private, []byte(prefix+"."+b64payload)) — the prefix is inside the signature, so swapping editions breaks it;
  • payload is canonical JSON (see License struct).

Public key resolution: env 2PAPI_LICENSE_PUBKEY (hex) overrides the embedded default. No key configured => every license fails with ErrNoKey and the caller degrades to OSS. Validation never touches the network — air-gapped deployments work out of the box.

Spec: plan/build-spine-specs.md (шаг 1 хребта).

Index

Constants

View Source
const (
	// PubKeyEnv overrides the embedded public key (hex-encoded).
	PubKeyEnv = "2PAPI_LICENSE_PUBKEY"

	// DefaultPubKeyHex is replaced at release time with the real
	// production key. Empty means "no licenses trusted yet".
	DefaultPubKeyHex = ""

	// Edition ids allowed as license prefix/payload edition.
	EdEnt   = "ent"
	EdCloud = "cloud"
)

Variables

View Source
var (
	ErrBadFormat       = errors.New("license: bad format")
	ErrBadSig          = errors.New("license: bad signature")
	ErrExpired         = errors.New("license: expired")
	ErrNotYet          = errors.New("license: not valid yet")
	ErrNoKey           = errors.New("license: no trusted public key configured")
	ErrUnknownFeature  = errors.New("license: unknown feature")
	ErrEditionMismatch = errors.New("license: edition mismatch")
)

Functions

This section is empty.

Types

type License

type License struct {
	Edition    string   `json:"ed"`
	CustomerID string   `json:"cid"`
	CapacityM  int64    `json:"cap"`           // годовая ёмкость запросов, млн; 0 = без лимита
	IssuedAt   int64    `json:"iat"`           // unix sec
	ExpiresAt  int64    `json:"exp"`           // unix sec
	Features   []string `json:"f,omitempty"`   // включённые фичи
	NotBefore  int64    `json:"nbf,omitempty"` // unix sec
	Trial      bool     `json:"trial,omitempty"`
}

License is the decoded payload. JSON field order here is also the canonical generation order (lexicographic) for our own keygen.

func LoadFile

func LoadFile(path string, now time.Time) (*License, error)

LoadFile validates the license stored in path (trailing newline ok).

func Validate

func Validate(s string, now time.Time) (*License, error)

Validate parses and verifies s at time now.

Jump to

Keyboard shortcuts

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