shared

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Rendered for darwin/amd64

Overview

Package shared holds the models, constants, and XPC protocol descriptors used by both the Warden network-extension daemon and the controlling app — mirroring Warden's Shared/ directory (Rule, consts, XPCDaemonProto, XPCUserProto).

Index

Constants

View Source
const (
	RuleDurationAlways  = 101
	RuleDurationOnce    = 102
	RuleDurationProcess = 103
	RuleDurationCustom  = 104
)

Rule durations (how long a rule persists).

View Source
const (
	DaemonProtocolName = "WardenDaemonProtocol"
	UserProtocolName   = "WardenUserProtocol"
)

Protocol names for the runtime-built ObjC protocols used over NSXPCConnection.

View Source
const DaemonMachServiceName = "com.example.warden.daemon"

DaemonMachServiceName is the registered mach service the daemon vends and the app connects to. A real deployment uses a team-prefixed name matching the extension's NEMachServiceName entitlement.

Variables

This section is empty.

Functions

func BytesToNSData added in v0.13.0

func BytesToNSData(b []byte) rt.ID

BytesToNSData builds an NSData that copies b. An empty b yields an empty NSData (+[NSData data]) rather than nil, which XPC reply blocks expect.

func ClassID added in v0.13.0

func ClassID(name string) rt.ID

ClassID returns an ObjC class object as an ID for class-method dispatch (e.g. ClassID("NSData") to send +dataWithBytes:length:). Both the app and the extension marshal NSData over XPC, so these helpers live here rather than being copied into each side.

func DaemonProtocol

func DaemonProtocol() rt.XPCProtocol

DaemonProtocol describes the daemon-side XPC interface (Warden's XPCDaemonProto): the app sends these to the extension's remote-object proxy. Reply-bearing methods carry their result in a reply block; fire-and-forget mutators do not.

func NSDataBytes added in v0.13.0

func NSDataBytes(d rt.ID) []byte

NSDataBytes copies an NSData's bytes into a freshly allocated Go slice, so the result stays valid after the NSData is released. A nil or empty NSData yields nil.

func UserProtocol

func UserProtocol() rt.XPCProtocol

UserProtocol describes the app-side XPC interface (Warden's XPCUserProto): the daemon sends these to the app's exported object — a rules-changed notification and an alert that expects the user's decision in its reply.

Types

type EndpointType

type EndpointType int

EndpointType classifies how a rule's endpoint address is matched.

const (
	EndpointTypeExact EndpointType = 0
	EndpointTypeRegex EndpointType = 1
	EndpointTypeCIDR  EndpointType = 2
)

type Rule

type Rule struct {
	UUID string `json:"uuid"`
	// Key is the process identity the rule is filed under — the signing identifier
	// when code-signed, otherwise the binary path.
	Key string `json:"key"`

	// Process identity.
	Path        string `json:"path"`
	Name        string `json:"name,omitempty"`
	IsGlobal    bool   `json:"isGlobal,omitempty"`
	IsDirectory bool   `json:"isDirectory,omitempty"`

	// Endpoint match. Empty EndpointAddr means "any endpoint".
	EndpointAddr string       `json:"endpointAddr,omitempty"`
	EndpointPort string       `json:"endpointPort,omitempty"`
	EndpointType EndpointType `json:"endpointType,omitempty"`

	// Verdict + lifecycle.
	Action     RuleState  `json:"action"` // RuleStateAllow / RuleStateBlock
	Type       int        `json:"type,omitempty"`
	Protocol   int        `json:"protocol,omitempty"`
	IsDisabled bool       `json:"isDisabled,omitempty"`
	Creation   time.Time  `json:"creation"`
	Expiration *time.Time `json:"expiration,omitempty"`

	// Managed marks rules that originate from the declarative config (provenance,
	// e.g. for display). Reconciliation is authoritative and prunes any rule not
	// in the config regardless of this flag, so it is not a safety gate.
	Managed bool `json:"managed,omitempty"`
}

Rule is a firewall rule, mirroring Warden's Shared/Rule. It is JSON-serializable so the daemon can persist the rule set to disk and ship it to the app over XPC (Warden uses NSData / NSKeyedArchiver; a Go port uses JSON for the same purpose).

func (*Rule) Matches

func (r *Rule) Matches(remoteAddr, remotePort string) bool

Matches reports whether the rule applies to a flow to remoteAddr:remotePort. An empty EndpointAddr matches any endpoint (a process-wide rule). Disabled or expired rules never match.

type RuleState added in v0.13.0

type RuleState int

RuleState is the verdict a rule encodes for a flow. It is a named type rather than a bare int so the zero value (RuleStateBlock) is explicit at every call site and the compiler rejects accidental mixing with unrelated integers.

const (
	RuleStateNotFound RuleState = -1 // no matching rule
	RuleStateBlock    RuleState = 0  // deny the flow
	RuleStateAllow    RuleState = 1  // permit the flow
)

func (RuleState) String added in v0.13.0

func (s RuleState) String() string

String renders a verdict as "allow"/"block" (and "not-found" for the sentinel), so callers can log a rule's action without re-deriving the mapping.

Jump to

Keyboard shortcuts

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