proxy

package
v3.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 11 Imported by: ? 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 proxy provides a minimal opaque forwarder for OSCORE-protected CoAP requests. It routes on the outer Proxy-Uri authority and does not inspect or modify the encrypted request payload or OSCORE option.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRequest         = errors.New("invalid OSCORE proxy request")
	ErrBadGateway             = errors.New("invalid OSCORE proxy origin response")
	ErrTargetNotAllowed       = errors.New("OSCORE proxy target is not allowed")
	ErrRateLimited            = errors.New("OSCORE proxy request rate limited")
	ErrUnsupportedOperation   = errors.New("unsupported OSCORE proxy operation")
	ErrInvalidForwarderConfig = errors.New("invalid OSCORE proxy forwarder configuration")
)

Functions

func AllowPublicIPLiteralTarget

func AllowPublicIPLiteralTarget(ctx context.Context, target oscore.ProxyTarget) bool

AllowPublicIPLiteralTarget accepts only literal public IP destinations. It rejects hostnames as well as loopback, private, link-local, multicast, and unspecified addresses. Only ports 5683 and 5684 are permitted. Applications with DNS targets should instead resolve and pin addresses in their policy and RoundTripper.

func AllowPublicIPLiteralTargetWithPorts

func AllowPublicIPLiteralTargetWithPorts(
	_ context.Context, target oscore.ProxyTarget, allowedPorts ...uint16,
) bool

AllowPublicIPLiteralTargetWithPorts is AllowPublicIPLiteralTarget with an application-configured allowlist of destination ports.

Types

type Forwarder

type Forwarder struct {
	RoundTripper RoundTripper
	AllowTarget  TargetPolicy
	// RateLimit rejects a request when it returns false. It is optional; when
	// configured, it runs after target authorization and before forwarding.
	// The peer is nil for direct Forward calls that do not provide transport
	// metadata.
	RateLimit func(context.Context, net.Addr, oscore.ProxyTarget) bool
	OnError   func(error)
}

Forwarder implements a one-request/one-response OSCORE forwarding path. The surrounding CoAP transport handles Outer Blockwise when enabled. RoundTripper implementations should use Blockwise for large envelopes. The forwarder does not provide caching, Observe, or proxy session management. OnError is called for forwarding errors. When it is nil, errors are not logged by the package.

func (*Forwarder) Forward

func (f *Forwarder) Forward(ctx context.Context, request message.Message) (message.Message, error)

Forward validates and routes an opaque OSCORE request. The Proxy-Uri must contain only its authority, as produced by Context.ProtectRequest.

func (*Forwarder) ForwardFrom

func (f *Forwarder) ForwardFrom(ctx context.Context, peer net.Addr, request message.Message) (message.Message, error)

ForwardFrom validates and routes an opaque OSCORE request while exposing the transport peer to the optional rate limiter.

func (*Forwarder) ServeCOAP

func (f *Forwarder) ServeCOAP(w mux.ResponseWriter, r *mux.Message)

ServeCOAP adapts the forwarder to a mux.Handler.

type RoundTripper

type RoundTripper interface {
	RoundTrip(context.Context, oscore.ProxyTarget, message.Message) (message.Message, error)
}

RoundTripper sends a CoAP request to the selected target and returns its response. Implementations should use a fresh transport connection per request unless they provide collision-safe token rewriting.

type RoundTripperFunc

type RoundTripperFunc func(context.Context, oscore.ProxyTarget, message.Message) (message.Message, error)

RoundTripperFunc adapts a function to the RoundTripper interface.

func (RoundTripperFunc) RoundTrip

func (f RoundTripperFunc) RoundTrip(ctx context.Context, target oscore.ProxyTarget, request message.Message) (message.Message, error)

RoundTrip sends the request using the function.

type TargetPolicy

type TargetPolicy func(context.Context, oscore.ProxyTarget) bool

TargetPolicy authorizes a destination before the forwarder contacts it. Applications should implement an allowlist; a nil policy is not permitted. A policy that permits hostnames must ensure they are resolved and the resulting IP is pinned by the RoundTripper. Resolving a hostname once for policy evaluation but again during dialing permits DNS rebinding and SSRF.

Jump to

Keyboard shortcuts

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