tdp

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package tdp implements the Teleport desktop protocol (TDP) encoder/decoder. See https://github.com/gravitational/teleport/blob/master/rfd/0037-desktop-access-protocol.md

Index

Constants

View Source
const (
	TypeClientScreenSpec              = MessageType(1)
	TypePNGFrame                      = MessageType(2)
	TypeMouseMove                     = MessageType(3)
	TypeMouseButton                   = MessageType(4)
	TypeKeyboardButton                = MessageType(5)
	TypeClipboardData                 = MessageType(6)
	TypeClientUsername                = MessageType(7)
	TypeMouseWheel                    = MessageType(8)
	TypeError                         = MessageType(9)
	TypeMFA                           = MessageType(10)
	TypeSharedDirectoryAnnounce       = MessageType(11)
	TypeSharedDirectoryAcknowledge    = MessageType(12)
	TypeSharedDirectoryInfoRequest    = MessageType(13)
	TypeSharedDirectoryInfoResponse   = MessageType(14)
	TypeSharedDirectoryCreateRequest  = MessageType(15)
	TypeSharedDirectoryCreateResponse = MessageType(16)
	TypeSharedDirectoryDeleteRequest  = MessageType(17)
	TypeSharedDirectoryDeleteResponse = MessageType(18)
	TypeSharedDirectoryReadRequest    = MessageType(19)
	TypeSharedDirectoryReadResponse   = MessageType(20)
	TypeSharedDirectoryWriteRequest   = MessageType(21)
	TypeSharedDirectoryWriteResponse  = MessageType(22)
	TypeSharedDirectoryMoveRequest    = MessageType(23)
	TypeSharedDirectoryMoveResponse   = MessageType(24)
	TypeSharedDirectoryListRequest    = MessageType(25)
	TypeSharedDirectoryListResponse   = MessageType(26)
	TypePNG2Frame                     = MessageType(27)
	TypeNotification                  = MessageType(28)
	TypeRDPFastPathPDU                = MessageType(29)
	TypeRDPResponsePDU                = MessageType(30)
	TypeRDPConnectionInitialized      = MessageType(31)
	TypeSyncKeys                      = MessageType(32)
)

For descriptions of each message type see: https://github.com/gravitational/teleport/blob/master/rfd/0037-desktop-access-protocol.md#message-types

View Source
const (
	LeftMouseButton   = MouseButtonType(0)
	MiddleMouseButton = MouseButtonType(1)
	RightMouseButton  = MouseButtonType(2)
)
View Source
const (
	ButtonNotPressed = ButtonState(0)
	ButtonPressed    = ButtonState(1)
)
View Source
const (
	VerticalWheelAxis   = MouseWheelAxis(0)
	HorizontalWheelAxis = MouseWheelAxis(1)
)
View Source
const (
	ErrCodeNil           uint32 = 0
	ErrCodeFailed        uint32 = 1
	ErrCodeDoesNotExist  uint32 = 2
	ErrCodeAlreadyExists uint32 = 3
)

These correspond to TdpErrCode enum in the rust RDP client.

Variables

This section is empty.

Functions

func IsFatalErr

func IsFatalErr(err error) bool

IsFatalErr returns the inverse of IsNonFatalErr (except for if err == nil, for which both functions return false)

func IsNonFatalErr

func IsNonFatalErr(err error) bool

IsNonFatalErr returns whether or not an error arising from the tdp package should be interpreted as fatal or non-fatal for an ongoing TDP connection.

func PNGEncoder

func PNGEncoder() *png.Encoder

PNGEncoder returns the encoder used for PNG Frames. It is not safe for concurrent use.

Types

type ButtonState

type ButtonState byte

ButtonState is the press state of a keyboard or mouse button.

type ClientScreenSpec

type ClientScreenSpec struct {
	Width  uint32
	Height uint32
}

ClientScreenSpec is the client screen specification. | message type (1) | width uint32 | height uint32 |

func (ClientScreenSpec) Encode

func (s ClientScreenSpec) Encode() ([]byte, error)

type ClientUsername

type ClientUsername struct {
	Username string
}

ClientUsername is the client username. | message type (7) | username_length uint32 | username []byte |

func (ClientUsername) Encode

func (r ClientUsername) Encode() ([]byte, error)

type ClipboardData

type ClipboardData []byte

ClipboardData represents shared clipboard data. | message type (6) | length uint32 | data []byte |

func (ClipboardData) Encode

func (c ClipboardData) Encode() ([]byte, error)

type Conn

type Conn struct {

	// OnSend is an optional callback that is invoked when a TDP message
	// is sent on the wire. It is passed both the raw bytes and the encoded
	// message.
	OnSend func(m Message, b []byte)

	// OnRecv is an optional callback that is invoked when a TDP message
	// is received on the wire.
	OnRecv func(m Message)
	// contains filtered or unexported fields
}

Conn is a desktop protocol connection. It converts between a stream of bytes (io.ReadWriter) and a stream of Teleport Desktop Protocol (TDP) messages.

func NewConn

func NewConn(rwc io.ReadWriteCloser) *Conn

NewConn creates a new Conn on top of a ReadWriter, for example a TCP connection. If the provided ReadWriter also implements srv.TrackingConn, then its LocalAddr() and RemoteAddr() will apply to this Conn.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection if the underlying reader can be closed.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

LocalAddr returns local address

func (*Conn) ReadClientScreenSpec

func (c *Conn) ReadClientScreenSpec() (*ClientScreenSpec, error)

ReadClientScreenSpec reads the next message from the connection, expecting it to be a ClientScreenSpec. If it is not, an error is returned.

func (*Conn) ReadMessage

func (c *Conn) ReadMessage() (Message, error)

ReadMessage reads the next incoming message from the connection.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns remote address

func (*Conn) SendNotification

func (c *Conn) SendNotification(message string, severity Severity) error

SendNotification is a convenience function for sending a Notification message.

func (*Conn) WriteMessage

func (c *Conn) WriteMessage(m Message) error

WriteMessage sends a message to the connection.

type ConnectionInitialized

type ConnectionInitialized struct {
	IOChannelID   uint16
	UserChannelID uint16
	ScreenWidth   uint16
	ScreenHeight  uint16
}

ConnectionInitialized is sent to the browser when an RDP session is fully initialized. It contains data that the browser needs in order to correctly handle the session.

See "3. Channel Connection" at https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/023f1e69-cfe8-4ee6-9ee0-7e759fb4e4ee

| message type (31) | io_channel_id uint16 | user_channel_id uint16 |

func (ConnectionInitialized) Encode

func (c ConnectionInitialized) Encode() ([]byte, error)

type Error

type Error struct {
	Message string
}

Error is used to send a fatal error message to the browser. In Teleport 12 and up, Error is deprecated and Notification should be preferred. | message type (9) | message_length uint32 | message []byte |

func (Error) Encode

func (m Error) Encode() ([]byte, error)

type FileSystemObject

type FileSystemObject struct {
	LastModified uint64
	Size         uint64
	FileType     uint32
	IsEmpty      uint8
	Path         string
}

FileSystemObject represents a file or directory. | last_modified uint64 | size uint64 | file_type uint32 | is_empty bool | path_length uint32 | path byte[] |

func (FileSystemObject) Encode

func (f FileSystemObject) Encode() ([]byte, error)

type KeyboardButton

type KeyboardButton struct {
	KeyCode uint32
	State   ButtonState
}

KeyboardButton is the keyboard button press message. | message type (5) | key_code uint32 | state byte |

func (KeyboardButton) Encode

func (k KeyboardButton) Encode() ([]byte, error)

type MFA

type MFA struct {
	// Type should be defaults.WebsocketWebauthnChallenge
	Type byte
	// MFAAuthenticateChallenge is the challenge we send to the client.
	// Used for messages from Teleport to the user's browser.
	*client.MFAAuthenticateChallenge
	// MFAAuthenticateResponse is the response to the MFA challenge,
	// sent from the browser to Teleport.
	*authproto.MFAAuthenticateResponse
}

MFA represents a MFA challenge or response. | message type (10) | mfa_type byte | length uint32 | JSON []byte |

func DecodeMFA

func DecodeMFA(in byteReader) (*MFA, error)

func DecodeMFAChallenge

func DecodeMFAChallenge(in byteReader) (*MFA, error)

DecodeMFAChallenge is a helper function used in test purpose to decode MFA challenge payload because in real flow this logic is invoked by a fronted client.

func (MFA) Encode

func (m MFA) Encode() ([]byte, error)

type Message

type Message interface {
	Encode() ([]byte, error)
}

Message is a Go representation of a desktop protocol message.

func Decode

func Decode(buf []byte) (Message, error)

Decode decodes the wire representation of a message.

type MessageType

type MessageType byte

MessageType identifies the type of the message.

type MouseButton

type MouseButton struct {
	Button MouseButtonType
	State  ButtonState
}

MouseButton is the mouse button press message. | message type (4) | button byte | state byte |

func (MouseButton) Encode

func (m MouseButton) Encode() ([]byte, error)

type MouseButtonType

type MouseButtonType byte

MouseButtonType identifies a specific button on the mouse.

type MouseMove

type MouseMove struct {
	X, Y uint32
}

MouseMove is the mouse movement message. | message type (3) | x uint32 | y uint32 |

func (MouseMove) Encode

func (m MouseMove) Encode() ([]byte, error)

type MouseWheel

type MouseWheel struct {
	Axis  MouseWheelAxis
	Delta int16
}

MouseWheel is the mouse wheel scroll message. | message type (8) | axis byte | delta int16 |

func (MouseWheel) Encode

func (w MouseWheel) Encode() ([]byte, error)

type MouseWheelAxis

type MouseWheelAxis byte

MouseWheelAxis identifies a scroll axis on the mouse wheel.

type Notification

type Notification struct {
	Message  string
	Severity Severity
}

Notification is an informational message sent from Teleport to the Web UI. It can be used for fatal errors or non-fatal warnings. | message type (28) | message_length uint32 | message []byte | severity byte |

func (Notification) Encode

func (m Notification) Encode() ([]byte, error)

type PNG2Frame

type PNG2Frame []byte

PNG2Frame is a newer version of PNGFrame that includes the length of the PNG data. It's represented as a fully encoded byte slice to optimize for speed and simplicity of encoding/decoding. | message type (27) | png_length uint32 | left uint32 | top uint32 | right uint32 | bottom uint32 | data []byte |

func (PNG2Frame) Bottom

func (f PNG2Frame) Bottom() uint32

func (PNG2Frame) Data

func (f PNG2Frame) Data() []byte

func (PNG2Frame) Encode

func (f PNG2Frame) Encode() ([]byte, error)

func (PNG2Frame) Left

func (f PNG2Frame) Left() uint32

func (PNG2Frame) Right

func (f PNG2Frame) Right() uint32

func (PNG2Frame) Top

func (f PNG2Frame) Top() uint32

type PNGFrame

type PNGFrame struct {
	Img image.Image
	// contains filtered or unexported fields
}

PNGFrame is the PNG frame message | message type (2) | left uint32 | top uint32 | right uint32 | bottom uint32 | data []byte |

func (PNGFrame) Encode

func (f PNGFrame) Encode() ([]byte, error)

type RDPFastPathPDU

type RDPFastPathPDU []byte

RDPFastPathPDU is an RDP Fast-Path PDU message. It carries a raw RDP Server Fast-Path Update PDU (https://tinyurl.com/3t2t6er8) which is used to transport image data to the frontend.

| message type (29) | data_length uint32 | data []byte |

Whenever you see this type itself, you can assume that it's just the | data []byte | part of the message. Calling Encode() on this type will return the full encoded message, including the | message type (29) | data_length uint32 | parts.

func (RDPFastPathPDU) Encode

func (f RDPFastPathPDU) Encode() ([]byte, error)

type RDPResponsePDU

type RDPResponsePDU []byte

RDPResponsePDU is an RDP Response PDU message. It carries a raw encoded RDP response PDU created by the ironrdp client on the frontend and sends it directly to the RDP server.

| message type (30) | data_length uint32 | data []byte |

Whenever you see this type itself, you can assume that it's just the | data []byte | section of the message. Calling Encode() on this type will return the full encoded message, including the | message type (30) | data_length uint32 | parts.

func (RDPResponsePDU) Encode

func (r RDPResponsePDU) Encode() ([]byte, error)

type Severity

type Severity byte
const (
	SeverityInfo    Severity = 0
	SeverityWarning Severity = 1
	SeverityError   Severity = 2
)

type SharedDirectoryAcknowledge

type SharedDirectoryAcknowledge struct {
	ErrCode     uint32
	DirectoryID uint32
}

SharedDirectoryAcknowledge acknowledges a SharedDirectoryAnnounce was received. | message type (12) | err_code uint32 | directory_id uint32 |

func (SharedDirectoryAcknowledge) Encode

func (s SharedDirectoryAcknowledge) Encode() ([]byte, error)

type SharedDirectoryAnnounce

type SharedDirectoryAnnounce struct {
	DirectoryID uint32
	Name        string
}

SharedDirectoryAnnounce announces a new directory to be shared. | message type (11) | directory_id uint32 | name_length uint32 | name []byte |

func (SharedDirectoryAnnounce) Encode

func (s SharedDirectoryAnnounce) Encode() ([]byte, error)

type SharedDirectoryCreateRequest

type SharedDirectoryCreateRequest struct {
	CompletionID uint32
	DirectoryID  uint32
	FileType     uint32
	Path         string
}

SharedDirectoryCreateRequest is sent by the TDP server to the client to request the creation of a new file or directory. | message type (15) | completion_id uint32 | directory_id uint32 | file_type uint32 | path_length uint32 | path []byte |

func (SharedDirectoryCreateRequest) Encode

func (s SharedDirectoryCreateRequest) Encode() ([]byte, error)

type SharedDirectoryCreateResponse

type SharedDirectoryCreateResponse struct {
	CompletionID uint32
	ErrCode      uint32
	Fso          FileSystemObject
}

SharedDirectoryCreateResponseis sent by the TDP client to the server with information from an executed SharedDirectoryCreateRequest. | message type (16) | completion_id uint32 | err_code uint32 | file_system_object fso |

func (SharedDirectoryCreateResponse) Encode

func (s SharedDirectoryCreateResponse) Encode() ([]byte, error)

type SharedDirectoryDeleteRequest

type SharedDirectoryDeleteRequest struct {
	CompletionID uint32
	DirectoryID  uint32
	Path         string
}

SharedDirectoryDeleteRequest is sent by the TDP server to the client to request the deletion of a file or directory. | message type (17) | completion_id uint32 | directory_id uint32 | path_length uint32 | path []byte |

func (SharedDirectoryDeleteRequest) Encode

func (s SharedDirectoryDeleteRequest) Encode() ([]byte, error)

type SharedDirectoryDeleteResponse

type SharedDirectoryDeleteResponse struct {
	CompletionID uint32
	ErrCode      uint32
}

SharedDirectoryDeleteResponse is sent by the TDP client to the server with information from an executed SharedDirectoryDeleteRequest. | message type (18) | completion_id uint32 | err_code uint32 |

func (SharedDirectoryDeleteResponse) Encode

func (s SharedDirectoryDeleteResponse) Encode() ([]byte, error)

type SharedDirectoryInfoRequest

type SharedDirectoryInfoRequest struct {
	CompletionID uint32
	DirectoryID  uint32
	Path         string
}

SharedDirectoryInfoRequest requests information about a file or directory. | message type (13) | completion_id uint32 | directory_id uint32 | path_length uint32 | path []byte |

func (SharedDirectoryInfoRequest) Encode

func (s SharedDirectoryInfoRequest) Encode() ([]byte, error)

type SharedDirectoryInfoResponse

type SharedDirectoryInfoResponse struct {
	CompletionID uint32
	ErrCode      uint32
	Fso          FileSystemObject
}

SharedDirectoryInfoResponse returns information about a file or directory. | message type (14) | completion_id uint32 | err_code uint32 | file_system_object fso |

func (SharedDirectoryInfoResponse) Encode

func (s SharedDirectoryInfoResponse) Encode() ([]byte, error)

type SharedDirectoryListRequest

type SharedDirectoryListRequest struct {
	CompletionID uint32
	DirectoryID  uint32
	Path         string
}

SharedDirectoryListRequest is sent by the TDP server to the client to request a directory listing. | message type (25) | completion_id uint32 | directory_id uint32 | path_length uint32 | path []byte |

func (SharedDirectoryListRequest) Encode

func (s SharedDirectoryListRequest) Encode() ([]byte, error)

type SharedDirectoryListResponse

type SharedDirectoryListResponse struct {
	CompletionID uint32
	ErrCode      uint32
	FsoList      []FileSystemObject
}

SharedDirectoryListResponse is sent by the TDP client to the server with the information from an executed SharedDirectoryListRequest. | message type (26) | completion_id uint32 | err_code uint32 | fso_list_length uint32 | fso_list fso[] |

func (SharedDirectoryListResponse) Encode

func (s SharedDirectoryListResponse) Encode() ([]byte, error)

type SharedDirectoryMoveRequest

type SharedDirectoryMoveRequest struct {
	CompletionID uint32
	DirectoryID  uint32
	OriginalPath string
	NewPath      string
}

SharedDirectoryMoveRequest is sent from the TDP server to the client to request a file at original_path be moved to new_path. | message type (23) | completion_id uint32 | directory_id uint32 | original_path_length uint32 | original_path []byte | new_path_length uint32 | new_path []byte |

func (SharedDirectoryMoveRequest) Encode

func (s SharedDirectoryMoveRequest) Encode() ([]byte, error)

type SharedDirectoryMoveResponse

type SharedDirectoryMoveResponse struct {
	CompletionID uint32
	ErrCode      uint32
}

SharedDirectoryMoveResponse is sent from the TDP client to the server to acknowledge a SharedDirectoryMoveRequest was executed. | message type (24) | completion_id uint32 | err_code uint32 |

func (SharedDirectoryMoveResponse) Encode

func (s SharedDirectoryMoveResponse) Encode() ([]byte, error)

type SharedDirectoryReadRequest

type SharedDirectoryReadRequest struct {
	CompletionID uint32
	DirectoryID  uint32
	Path         string
	Offset       uint64
	Length       uint32
}

SharedDirectoryReadRequest is a message sent by the TDP server to the client to request bytes to be read from the file at the path and starting at byte offset. | message type (19) | completion_id uint32 | directory_id uint32 | path_length uint32 | path []byte | offset uint64 | length uint32 |

func (SharedDirectoryReadRequest) Encode

func (s SharedDirectoryReadRequest) Encode() ([]byte, error)

type SharedDirectoryReadResponse

type SharedDirectoryReadResponse struct {
	CompletionID   uint32
	ErrCode        uint32
	ReadDataLength uint32
	ReadData       []byte
}

SharedDirectoryReadResponse is a message sent by the TDP client to the server in response to the SharedDirectoryReadRequest. | message type (20) | completion_id uint32 | err_code uint32 | read_data_length uint32 | read_data []byte |

func (SharedDirectoryReadResponse) Encode

func (s SharedDirectoryReadResponse) Encode() ([]byte, error)

type SharedDirectoryWriteRequest

type SharedDirectoryWriteRequest struct {
	CompletionID    uint32
	DirectoryID     uint32
	Offset          uint64
	Path            string
	WriteDataLength uint32
	WriteData       []byte
}

SharedDirectoryWriteRequest is a message sent by the TDP server to the client to request bytes to be written the file at the path and starting at byte offset. | message type (21) | completion_id uint32 | directory_id uint32 | path_length uint32 | path []byte | offset uint64 | write_data_length uint32 | write_data []byte |

func (SharedDirectoryWriteRequest) Encode

func (s SharedDirectoryWriteRequest) Encode() ([]byte, error)

type SharedDirectoryWriteResponse

type SharedDirectoryWriteResponse struct {
	CompletionID uint32
	ErrCode      uint32
	BytesWritten uint32
}

SharedDirectoryWriteResponse is a message sent by the TDP client to the server in response to the SharedDirectoryWriteRequest. | message type (22) | completion_id uint32 | err_code uint32 | bytes_written uint32 |

func (SharedDirectoryWriteResponse) Encode

func (s SharedDirectoryWriteResponse) Encode() ([]byte, error)

type SyncKeys

type SyncKeys struct {
	ScrollLockState ButtonState
	NumLockState    ButtonState
	CapsLockState   ButtonState
	KanaLockState   ButtonState
}

| message type (32) | scroll_lock_state byte | num_lock_state byte | caps_lock_state byte | kana_lock_state byte |

func (SyncKeys) Encode

func (k SyncKeys) Encode() ([]byte, error)

Jump to

Keyboard shortcuts

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