derptun

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerTokenPrefix       = "dts1_"
	CustomServerTokenPrefix = "dts2_"
	ClientTokenPrefix       = "DT1"
	CustomClientTokenPrefix = "DT2"
	TokenVersion            = 1
	CustomTokenVersion      = 2
	DefaultServerDays       = 180
	DefaultClientDays       = 90
	ProtocolTCP             = "tcp"
	ProtocolUDP             = "udp"
)

Variables

View Source
var (
	ErrExpired      = errors.New("derptun token expired")
	ErrInvalidToken = errors.New("invalid derptun token")
)

Functions

func DeriveClientBearerSecretForClaim added in v0.9.0

func DeriveClientBearerSecretForClaim(secret [32]byte, clientID [16]byte) [32]byte

func EncodeClientCredential added in v0.12.0

func EncodeClientCredential(cred ClientCredential) (string, error)

func GenerateClientToken added in v0.9.0

func GenerateClientToken(opts ClientTokenOptions) (string, error)

func GenerateServerToken added in v0.9.0

func GenerateServerToken(opts ServerTokenOptions) (string, error)

func GenerateServerTokenFromEnvironment added in v0.17.0

func GenerateServerTokenFromEnvironment(opts ServerTokenOptions) (string, error)

func HasClientTokenPrefix added in v0.17.0

func HasClientTokenPrefix(value string) bool

func HasServerTokenPrefix added in v0.17.0

func HasServerTokenPrefix(value string) bool

func VerifyClientCredential added in v0.9.0

func VerifyClientCredential(secret [32]byte, client ClientCredential, now time.Time) error

Types

type ClientCredential added in v0.9.0

type ClientCredential struct {
	Version      int      `json:"version"`
	SessionID    [16]byte `json:"session_id"`
	ClientID     [16]byte `json:"client_id"`
	TokenID      [16]byte `json:"token_id"`
	ClientName   string   `json:"client_name"`
	ExpiresUnix  int64    `json:"expires_unix"`
	DERPPublic   [32]byte `json:"derp_public"`
	QUICPublic   [32]byte `json:"quic_public"`
	BearerSecret [32]byte `json:"bearer_secret"`
	ProofMAC     string   `json:"proof_mac"`
	DERPRoute    *derpbind.Route
}

func DecodeClientToken added in v0.9.0

func DecodeClientToken(encoded string, now time.Time) (ClientCredential, error)

func (ClientCredential) SessionToken added in v0.9.0

func (cred ClientCredential) SessionToken() (sessiontoken.Token, error)

type ClientTokenOptions added in v0.9.0

type ClientTokenOptions struct {
	Now         time.Time
	ServerToken string
	Days        int
	Expires     time.Time
}

type ForwardSpec

type ForwardSpec struct {
	Protocol           string `json:"protocol"`
	ListenAddr         string `json:"listen_addr,omitempty"`
	TargetAddr         string `json:"target_addr,omitempty"`
	IdleTimeoutSeconds int    `json:"idle_timeout_seconds,omitempty"`
}

type Mux

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

func NewMux

func NewMux(cfg MuxConfig) *Mux

func (*Mux) Accept

func (m *Mux) Accept(ctx context.Context) (net.Conn, error)

func (*Mux) ActiveStreamCount added in v0.9.0

func (m *Mux) ActiveStreamCount() int

func (*Mux) Close

func (m *Mux) Close() error

func (*Mux) LastPeerActivity added in v0.9.0

func (m *Mux) LastPeerActivity() time.Time

func (*Mux) OpenStream

func (m *Mux) OpenStream(ctx context.Context) (net.Conn, error)

func (*Mux) Ping added in v0.9.0

func (m *Mux) Ping(ctx context.Context, timeout time.Duration) error

func (*Mux) ReplaceCarrier

func (m *Mux) ReplaceCarrier(carrier io.ReadWriteCloser)

type MuxConfig

type MuxConfig struct {
	Role             MuxRole
	ReconnectTimeout time.Duration
}

type MuxRole

type MuxRole string
const (
	MuxRoleClient MuxRole = "client"
	MuxRoleServer MuxRole = "server"
)

type ServerCredential added in v0.9.0

type ServerCredential struct {
	Version       int             `json:"version"`
	SessionID     [16]byte        `json:"session_id"`
	ExpiresUnix   int64           `json:"expires_unix"`
	DERPPrivate   string          `json:"derp_private"`
	QUICPrivate   []byte          `json:"quic_private"`
	SigningSecret [32]byte        `json:"signing_secret"`
	Forwards      []ForwardSpec   `json:"forwards,omitempty"`
	DERPRoute     *derpbind.Route `json:"derp_route,omitempty"`
}

func DecodeServerToken added in v0.9.0

func DecodeServerToken(encoded string, now time.Time) (ServerCredential, error)

func (ServerCredential) DERPKey added in v0.9.0

func (cred ServerCredential) DERPKey() (key.NodePrivate, error)

func (ServerCredential) QUICPrivateKey added in v0.9.0

func (cred ServerCredential) QUICPrivateKey() (ed25519.PrivateKey, error)

func (ServerCredential) SessionToken added in v0.9.0

func (cred ServerCredential) SessionToken() (sessiontoken.Token, error)

type ServerTokenOptions added in v0.9.0

type ServerTokenOptions struct {
	Now       time.Time
	Days      int
	Expires   time.Time
	DERPRoute derpbind.Route
}

Jump to

Keyboard shortcuts

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