uplink

package
v0.0.0-...-9f27993 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: GPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package uplink implements the server side of the ipxbox uplink protocol. This is largely the same IPX-in-UDP protocol used by DOSbox, but there is a challenge-response authentication system to provide a bit more security since uplinked packets can be any MAC address.

Index

Constants

View Source
const (
	// MessageTypeGetChallengeRequest is the uplink message type initially
	// sent from client to server, requesting a challenge nonce. No other
	// field is set.
	// {"message-type": "get-challenge-request"}
	MessageTypeGetChallengeRequest = "get-challenge-request"

	// MessageTypeGetChallengeResponse is the uplink message type returned
	// by the server in response to MessageTypeGetChallengeRequest.
	// {"message-type": "get-challenge-response",
	//  "challenge": "[base64 challenge bytes]"}
	MessageTypeGetChallengeResponse = "get-challenge-response"

	// MessageTypeSubmitSolution is the uplink message type sent from the
	// client to server submitting its solution to the challenge from the
	// server. It also contains its own reverse-challenge to the server.
	// {"message-type": "submit-solution",
	//  "solution": "[base64 solution to server challenge]",
	//  "challenge": "[base64 challenge bytes]"}
	MessageTypeSubmitSolution = "submit-solution"

	// MessageTypeSubmitSolutionAccepted is the uplink message type sent
	// from the server to client confirming it accepts the client's
	// solution to the challenge. It also contains its own solution to the
	// client's challenge. At this point the server has confirmed
	// authentication of the client and will begin allowing traffic.
	// {"message-type": "submit-solution-accepted",
	//  "solution": "[base64 solution to client challenge]"}
	MessageTypeSubmitSolutionAccepted = "submit-solution-accepted"

	// MessageTypeSubmitSolutionRejected is the uplink message type sent
	// from the server to the client when the client's solution is not
	// accepted. Essentially this is wrong password, authentication
	// rejected.
	// {"message-type": "submit-solution-rejected"}
	MessageTypeSubmitSolutionRejected = "submit-solution-rejected"

	// MessageTypeKeepalive is the uplink message type sent by the server
	// when no traffic has been detected recently. It prevents any NAT
	// gateway in the middle from timing out the connection.
	MessageTypeKeepalive = "keepalive"

	// MessageTypeClose is the uplink message type from the client to
	// the server to close the connection and disconnect.
	// {"message-type": "close-connection"}
	MessageTypeClose = "close-connection"
)
View Source
const (
	MinChallengeLength = 64
)

Variables

View Source
var (

	// Address is a special IPX address used to identify control packets;
	// control packets have this destination address.
	Address = ipx.Addr{'U', 'p', 'L', 'i', 'N', 'K'}
)

Functions

func SolveChallenge

func SolveChallenge(side, password string, challenge []byte) []byte

Types

type Message

type Message struct {
	Type      string `json:"message-type"`
	Challenge []byte `json:"challenge",omitempty`
	Solution  []byte `json:"solution",omitempty`
}

func (*Message) Marshal

func (m *Message) Marshal() ([]byte, error)

func (*Message) Unmarshal

func (m *Message) Unmarshal(data []byte) error

type Protocol

type Protocol struct {
	// A new Node is created in this network each time a client connects.
	// This should not be an Addressable network since for uplink we want
	// to allow traffic to and from any arbitrary address.
	Network network.Network

	// If not nil, log entries are written as clients connect and
	// disconnect.
	Logger *log.Logger

	// Clients *must* supply a password. Uplink is always authenticated.
	Password string

	// If non-zero, always send at least one packet every few seconds to
	// keep the UDP connection open. Some NAT networks and firewalls can be
	// very aggressive about closing off the ability for clients to receive
	// packets on particular ports if nothing is received for a while.
	// This controls the time for keepalives.
	KeepaliveTime time.Duration
}

Protocol is an implementation of server.Protocol that provides uplink capability.

func (*Protocol) IsRegistrationPacket

func (p *Protocol) IsRegistrationPacket(packet *ipx.Packet) bool

IsRegistrationPacket returns true if this is an uplink packet of type MessageTypeGetChallengeRequest, which is the opening packet of a connection handshake.

func (*Protocol) StartClient

func (p *Protocol) StartClient(ctx context.Context, inner ipx.ReadWriteCloser, remoteAddr net.Addr) error

StartClient is invoked as a new goroutine when a new client connects.

Jump to

Keyboard shortcuts

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