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 ¶
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 ¶
Forward validates and routes an opaque OSCORE request. The Proxy-Uri must contain only its authority, as produced by Context.ProtectRequest.
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.
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.