protocols

package
v0.2.0-dev.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.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

Index

Constants

View Source
const (
	// MaskedSecret is what the API shows instead of a stored secret, and what the client sends back to
	// say "keep the stored value".
	MaskedSecret = "••••"
	// GenerateSecret, like the empty string, asks for a freshly generated secret.
	GenerateSecret = "$generate"
)

Secret handling is done by the framework, not by plugins: a schema property marked "x-secret": true is stored vault-encrypted outside settings_json and masked in the API.

Variables

This section is empty.

Functions

func AllowedForApps

func AllowedForApps(p Protocol, apps ...plugin.ClientID) bool

AllowedForApps reports whether a user with the given enabled apps gets the protocol: one of the enabled apps must appear in the protocol's Clients().

func ChangedPointers

func ChangedPointers(a, b json.RawMessage, ptrs []string) []string

ChangedPointers lists the given pointers whose value differs between two documents.

func FlaggedPointers

func FlaggedPointers(schema []byte, flag string) ([]string, error)

FlaggedPointers returns the JSON pointers of schema properties carrying the boolean flag (e.g. "x-secret", "x-critical"), sorted. Only "properties" of nested objects are walked.

func HasCapability

func HasCapability(caps []string, name, value string) bool

HasCapability reports whether the client announced value for name. Comma-separated values in the header (for example awg=2.0,3.1) are treated as a set; blanks around names and values do not matter ("awg=2.0, 3.1").

func IPv6Unsupported added in v0.1.66

func IPv6Unsupported(spec plugin.InboundSpec) string

IPv6Unsupported says why a server has no IPv6 twin, "" when it has: a CDN host or a certificate for the node's IPv4 address cannot be used when people connect directly to the node's IPv6 address.

func IsExperimental added in v0.1.69

func IsExperimental(p Protocol) bool

IsExperimental reports whether p is marked as experimental.

func IsHostname added in v0.1.69

func IsHostname(host string) bool

IsHostname reports whether host is a DNS host name made of letters, digits, hyphens and dots: not an IP address, no port, no brackets, no empty or over-long label. (A name that needs a dot, as a TLS name does, is the caller's check.)

func IsPerDevice

func IsPerDevice(p Protocol) bool

IsPerDevice reports whether p issues per-device, per-profile credentials.

func MaskSecrets

func MaskSecrets(merged json.RawMessage, secretPtrs []string) (json.RawMessage, error)

MaskSecrets replaces every secret of a merged document by MaskedSecret (for the API).

func MergeSecrets

func MergeSecrets(public json.RawMessage, secrets map[string]string) (json.RawMessage, error)

MergeSecrets puts stored secrets back into the public document.

func NormalizePin

func NormalizePin(s string) (string, bool)

NormalizePin returns the SHA-256 certificate pin a node reported in the form that may be put into a subscription: exactly 64 lowercase hex digits (colons, as in openssl output, are tolerated on the way in). Anything else is not a pin. A node is trusted to serve its own traffic, not to write into the subscription of every user of the inbound, so this is checked where the pin is stored and again where it is rendered.

func ResolveInput

func ResolveInput(input, base, fresh json.RawMessage, secretPtrs []string) (json.RawMessage, error)

ResolveInput turns the settings document sent by a client into the merged settings to validate and store. base is what the client's document is laid over: the stored merged settings on update, or the plugin defaults on create (keys the client omits keep the base value, including generated secrets). Secret fields: MaskedSecret keeps base's value, "" or GenerateSecret takes a fresh value from fresh (a newly generated DefaultSettings document).

func ServerCDN added in v0.1.66

func ServerCDN(spec plugin.InboundSpec) bool

ServerCDN says the client reaches this server through a CDN host, not the node's address.

func SplitSecrets

func SplitSecrets(merged json.RawMessage, secretPtrs []string) (json.RawMessage, map[string]string, error)

SplitSecrets removes the secret values from merged settings. It returns the public document (safe for settings_json) and the removed values by pointer; only string secrets that are present are returned.

Types

type Check

type Check struct {
	ID    string
	Scope CheckScope
	Run   func(ctx context.Context, in CheckInput) []Finding
}

Check is one doctor rule. The runner calls Run for every node that has an inbound of this protocol (Scope node) or once (Scope fleet).

type CheckInput

type CheckInput struct {
	Node     NodeView
	Inbounds []InboundView
	Now      time.Time
	// Observations is filled by the health module: last apply results, latest metrics, synthetic check
	// results. Kept a map so the first version does not freeze its shape.
	Observations map[string]json.RawMessage
}

type CheckScope

type CheckScope int
const (
	ScopeNode CheckScope = iota + 1
	ScopeFleet
)

type ClientReq

type ClientReq struct {
	Client plugin.ClientID
	App    string // display name: "AmneziaVPN"
	Min    string // tag or version: "5.0.1.5"
}

ClientReq is the minimum version of one client app for a profile's settings.

func MinClientsOf

func MinClientsOf(p Protocol, settings json.RawMessage) []ClientReq

MinClientsOf returns the client requirements of p for the given settings, nil when it has none.

type ClientRequirements

type ClientRequirements interface {
	MinClients(settings json.RawMessage) []ClientReq
}

ClientRequirements is an optional interface: the minimum client versions for THIS profile's settings (shown next to every config: an old AmneziaVPN silently drops keys it does not know).

type Experimental added in v0.1.69

type Experimental interface{ Experimental() bool }

Experimental is an optional interface. A plugin answering true is new and not proven in the field: the protocol list marks it (ProtocolInfo.experimental). hysteria2, vless and awg do not implement it.

type FieldError

type FieldError struct {
	Pointer string // "/obfs/password"
	Code    string
	Message string
}

type Finding

type Finding struct {
	Severity int // 1 info, 2 warning, 3 error
	Code     string
	Params   map[string]string
	FixID    string // "" = no one-click fix
}

type InboundInit

type InboundInit struct {
	State  []byte          // secret (AWG: the server private key); encrypted by the framework
	Public json.RawMessage // not secret (AWG: {"public_key": ...})
}

type InboundInitInput

type InboundInitInput struct {
	InboundID string
	Profile   ProfileView
	Node      NodeView
}

type InboundInitializer

type InboundInitializer interface {
	InitInbound(in InboundInitInput) (InboundInit, error)
}

InboundInitializer is an optional interface: a plugin that needs per-inbound key material implements it. The framework calls InitInbound once when an inbound is created, stores State vault-encrypted (AAD = the inbound id) and Public in clear, and hands both back through InboundInput and RenderInput.

type InboundInput

type InboundInput struct {
	Profile               ProfileView
	Node                  NodeView
	PortOverride          uint16 // 0 = none
	TLSServerNameOverride string
	SpecVersion           uint64
	Enabled               bool
	// InboundID and PluginState/PluginPublic carry what InitInbound made for this inbound (AWG: the server
	// key pair). PluginState is already decrypted; empty for a protocol without InboundInitializer.
	InboundID    string
	PluginState  []byte
	PluginPublic json.RawMessage
}

type InboundView

type InboundView struct {
	ID             string
	Node           NodeView
	Port           uint16
	HopFrom, HopTo uint16
	TCPOnly        bool   // relay twin: the forward carries TCP only, even if the direct inbound also serves HTTP/3
	TLSServerName  string // effective SNI
	TLSMode        plugin.TLSMode
	CertPinSHA256  string // reported by the node after apply; empty until then
}

InboundView is the effective facts about one deployed inbound needed to write a client config.

type IssueInput

type IssueInput struct {
	UserID, DeviceID string
	// L3 protocols (PerDevice): the profile the credential belongs to, its merged settings and the peer index
	// the IPAM handed out (address = subnet base + PeerIndex). Zero for hysteria2.
	ProfileID string
	Settings  json.RawMessage
	PeerIndex int
}

type Issued

type Issued struct {
	Secret   string          // client-side secret (hy2 auth token); never sent to a node
	NodeData json.RawMessage // verifier for UserCred.Data (hy2: {"auth_sha256":"<hex>"})
}

type NeedsDomainError

type NeedsDomainError struct {
	Address string
	Reality bool
	MTProto bool
}

NeedsDomainError: the certificate is Let's Encrypt, which is issued for a DNS name only, and the inbound has none: the node address is an IP and no SNI is set (neither on the inbound nor in the profile). Reality: the certificate is the one of the node's own site behind a REALITY profile (VLESS), whose other choice is another site as the target; the UI words that refusal apart (reality_needs_domain).

MTProto: the Fake TLS name of the profile is the node's own name and the node has only an IP address; the profile's other choice is the name of another site (mtproto_needs_domain).

func (*NeedsDomainError) Error

func (e *NeedsDomainError) Error() string

type NodeView

type NodeView struct {
	ID, Name, Address, CountryCode string
}

type NormalizeInput

type NormalizeInput struct {
	Input  json.RawMessage // the document the client sent
	Old    json.RawMessage // the stored merged settings of the profile; nil when the profile is being created
	Merged json.RawMessage // Input laid over Old (over the defaults on create), secrets resolved, not yet validated
	Save   bool            // the result will be stored; false for a live preview of a form
}

NormalizeInput is what a SettingsNormalizer sees: the client's document, what it was laid over and the result.

type PerDevice

type PerDevice interface{ PerDevice() bool }

PerDevice is an optional interface. A plugin answering true issues its credential on demand, bound to ONE profile (several live credentials per device, one per profile), so the generic "every device gets one" pass skips it. hysteria2 does not implement it.

type PortInHopError

type PortInHopError struct{ From, To int }

PortInHopError: the port override lies inside the profile's own port-hopping range.

func (*PortInHopError) Error

func (*PortInHopError) Error() string

type ProfileView

type ProfileView struct {
	ID       string
	Version  uint32
	Settings json.RawMessage
}

type Protocol

type Protocol interface {
	ID() string
	DisplayName() string

	// SettingsSchema is the JSON Schema the admin UI renders the profile form from (vocabulary: see
	// proto/admin profile.proto).
	SettingsSchema() []byte
	// DefaultSettings returns settings for a new profile with secrets already generated.
	DefaultSettings() (json.RawMessage, error)
	// Validate returns per-field errors (JSON pointers); nil = valid. Must be pure and fast: the UI calls
	// it on every edit through PreviewProfile.
	Validate(settings json.RawMessage) []FieldError
	// Summary is the mono parameter line on the profile card: "UDP 443 · Salamander · Let's Encrypt".
	Summary(settings json.RawMessage) string

	// BuildInbound translates profile settings + node + overrides into the node-side spec (ports, TLS
	// mode, egress are lifted out of the settings into first-class fields; the rest goes to Settings).
	BuildInbound(in InboundInput) (plugin.InboundSpec, error)

	// IssueCredential creates the credential of one device: Secret is what the client presents (stored
	// encrypted, shown in subscriptions), NodeData is the verifier shipped to nodes.
	IssueCredential(in IssueInput) (Issued, error)

	// Clients lists the client apps that can consume this protocol. A user gets the protocol when one of
	// their enabled apps appears here.
	Clients() []plugin.ClientSupport
	// Render returns this protocol's piece of a subscription in the requested format, or false if the
	// format/client cannot carry the protocol (Happ cannot carry AWG and vice versa).
	Render(in RenderInput) (plugin.Fragment, bool)

	// Doctor returns the protocol-specific checks for the fleet doctor.
	Doctor() []Check
}

Protocol is the panel half of a protocol plugin. Settings are always the MERGED JSON (secrets in place); the framework masks/splits secrets using the schema's "x-secret" markers.

type Registry

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

Registry holds the protocol plugins of this panel, by plugin id. It is built once at startup and never changes afterwards, so it needs no lock.

func NewRegistry

func NewRegistry(ps ...Protocol) (*Registry, error)

NewRegistry registers the given protocols. A duplicate or empty id is a programming error.

func (*Registry) Get

func (r *Registry) Get(id string) (Protocol, bool)

Get returns the protocol with the given plugin id.

func (*Registry) List

func (r *Registry) List() []Protocol

List returns all protocols ordered by id.

type RenderInput

type RenderInput struct {
	Format       plugin.ClientFormat
	Capabilities []string        // name=value entries from X-Mistgate-Caps; used by FormatMistgate only
	Settings     json.RawMessage // merged, secrets in place
	Inbound      InboundView
	UserID       string
	UserName     string
	DeviceID     string
	Secret       string // decrypted credential secret
	MaskSecrets  bool   // profile preview: render secrets as "••••"
	// NoIPv6Egress: the client gets no IPv6 out of the exit node, so no format of an AmneziaWG server carries an IPv6 address of the tunnel (AllowedIPs keep ::/0).
	// The other formats ignore it; false (the zero value) changes nothing.
	NoIPv6Egress bool

	// L3 protocols (awg). For FormatMihomo, Fragment.Data is ONE proxy as an element of a YAML list built
	// from yaml.v3 nodes (never string templates: node and user names are hostile input); the assembler
	// adds groups, dns and rules.
	Label         string          // device label, for the config's comment / file name
	DisplayName   string          // server name as the subscription shows it (the assembler's remarks())
	Peer          json.RawMessage // decrypted credential secret of the device ({"priv","psk"} for awg)
	InboundPublic json.RawMessage // InboundInit.Public of this inbound
	DNS           []string        // at most 2 plain IPv4 servers (the pair an AWG client carries)
	NodeAddr      string          // host clients connect to (Inbound.Node.Address)
}

type ServerNameError

type ServerNameError struct {
	Name       string
	DomainOnly bool
}

ServerNameError: the server name set for the inbound is not usable: an IP where Let's Encrypt needs a domain (DomainOnly), or neither a host name nor an IP.

func (*ServerNameError) Error

func (e *ServerNameError) Error() string

type SettingsNormalizer

type SettingsNormalizer interface {
	NormalizeSettings(in NormalizeInput) (json.RawMessage, error)
}

SettingsNormalizer is an optional interface: it fixes merged settings before they are validated and stored. AWG uses it so that a schema default never becomes a live config: a profile made without an obfuscation block gets a generated one. It must return Merged itself, byte for byte, when it has nothing to change (the caller compares the bytes to see whether anything changed).

Directories

Path Synopsis
awg
Package awg is the panel half of the AmneziaWG protocol plugin: the settings schema, a validator stricter than both implementations, the obfuscation generator with its mimicry presets, the translation of a profile into a node-side inbound, the per-device X25519 credentials and the three client formats (.conf, vpn://, Mihomo proxy).
Package awg is the panel half of the AmneziaWG protocol plugin: the settings schema, a validator stricter than both implementations, the obfuscation generator with its mimicry presets, the translation of a profile into a node-side inbound, the per-device X25519 credentials and the three client formats (.conf, vpn://, Mihomo proxy).
mimicry
Package mimicry builds and checks the I1..I5 "custom protocol signature" packets of AmneziaWG 2.0/3.x.
Package mimicry builds and checks the I1..I5 "custom protocol signature" packets of AmneziaWG 2.0/3.x.
vpnkey
Package vpnkey encodes and decodes the vpn:// connection key of AmneziaVPN.
Package vpnkey encodes and decodes the vpn:// connection key of AmneziaVPN.
Package builtin builds the registry of the protocol plugins shipped with the panel.
Package builtin builds the registry of the protocol plugins shipped with the panel.
Package hysteria2 is the panel half of the Hysteria2 protocol plugin: the settings schema, validation, translation of a profile into a node-side inbound spec, credential issuing and the hysteria2:// URI.
Package hysteria2 is the panel half of the Hysteria2 protocol plugin: the settings schema, validation, translation of a profile into a node-side inbound spec, credential issuing and the hysteria2:// URI.
Package jsoncheck lets the tests ask the real cores whether a client config they render is valid: Xray in process (xray-core's own config builder) and sing-box through its binary.
Package jsoncheck lets the tests ask the real cores whether a client config they render is valid: Xray in process (xray-core's own config builder) and sing-box through its binary.
Package mtproto is the panel half of the Telegram MTProto proxy plugin: the profile schema, validation, node-side inbound construction, credential issuing and the tg://proxy link.
Package mtproto is the panel half of the Telegram MTProto proxy plugin: the profile schema, validation, node-side inbound construction, credential issuing and the tg://proxy link.
Package trusttunnel is the panel half of the TrustTunnel protocol plugin.
Package trusttunnel is the panel half of the TrustTunnel protocol plugin.
Package vless is the panel half of the VLESS protocol plugin.
Package vless is the panel half of the VLESS protocol plugin.

Jump to

Keyboard shortcuts

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