Documentation
¶
Overview ¶
Package grdp is a Go implementation of Microsoft's Remote Desktop Protocol: the client half of RDP, the RFB (VNC) client that this fork inherited alongside it, and the codecs, orders and virtual channels they need.
It is meant to be built on rather than used as a program. There is no window anywhere in it, and every drawing path hands out pixels and leaves the painting to the caller, so the same library serves a desktop client, a command line tool and a browser gateway.
Getting started ¶
s := client.NewSetting()
s.Width, s.Height = 1024, 768
s.Protocol = "nla" // "tls" (the default), "nla" or "rdp"
c := client.NewClient("host:3389", "user", "password", client.TC_RDP, s)
defer c.Close()
c.OnFrame(func(dirty []image.Rectangle) { /* encode these regions */ })
c.OnCursor(func(cur *client.Cursor) { /* draw cur.Image at cur.Hotspot */ })
if err := c.Login(); err != nil {
log.Fatal(err)
}
c.MouseMove(400, 300)
c.TypeText("text", 8*time.Millisecond)
[client.Framebuffer] is where the pixels are, whichever way the server chose to draw them, and [client.Client.OnFrame] says which parts of it changed. cmd/rdpcli is a headless client that dumps a PNG, and cmd/rdpws is a gateway that serves one to a browser; both are small enough to read as examples.
How it is put together ¶
The layers are the protocol's, from the socket upwards, and each one is a package that knows only about the layer beneath it:
protocol/tpkt TPKT framing, and the TLS and CredSSP handshake
protocol/x224 the X.224 connection request, where security is chosen
protocol/nla NTLMv2 and CredSSP, used by tpkt
protocol/t125 MCS: channel joins, and the GCC blocks that carry
the client's capabilities and settings
protocol/sec RDP security: encryption, and the licensing exchange
protocol/pdu the PDU layer: capabilities, updates, input, orders
protocol/rfb RFB (VNC), which is a different protocol and shares none
of the above except the socket
[client] sits on top and is the only package most callers need. The packages below it are exported because types from them appear in the API: a pointer update is a [pdu.PointerDataPDU], a security negotiation failure is an [x224.NegotiationFailure]. They are not offered as a stable interface of their own, and they change when the protocol work needs them to.
The three drawing paths ¶
A session uses one path at a time, and the choice is made at connect time by what the client advertises:
- Bitmap updates, the default. Rectangles of RLE or codec data decoded into BGRA. Every server supports this and it is the path that works.
- Drawing orders, with Setting.EnableOrders. The client advertises MEMBLT and the server stops sending bitmap updates entirely, drawing through its bitmap cache instead, which is far smaller on the wire and far more work to render.
- EGFX, with Setting.EnableEGFX. A dynamic virtual channel carries surfaces and codec data, and the client composites. Again the server stops sending bitmap updates.
The last two cannot be mixed with the first in one session, which is why both are off by default: turning one on and meeting a codec that is not implemented gives a blank screen rather than a degraded one.
What it does not do ¶
It does not paint. There is no widget, no window and no pixel format conversion for a display, only the pixels as the protocol delivers them.
It does not implement RemoteFX Progressive, which needs an arithmetic decoder, or H.264, whose framing is implemented but whose decoding is left to a caller through the codec.AVCDecoder interface, because a pure Go decoder is out of scope and cgo would change what this library is.
It does not implement bitmap cache revision 3, and two of the drawing orders have no server here to be checked against. Both are recorded in the README rather than implied by silence.
What has been verified ¶
The connection, TLS, NLA, licensing, bitmap, RemoteFX, NSCodec, ZGFX, orders, EGFX, cursor, input and Display Control paths have all been run against a real Windows 10 host and against xrdp, and the codecs are checked byte for byte against libfreerdp rather than against expectations written by the same person who wrote the decoder. docs/windows-verification.md records what was checked and how, including the traps that have already been paid for once.
"It builds" is not "it works", and this package's own history is the argument: five separate faults were found only by pointing the code at a server that disagreed, after unit tests had passed. When a layout or a value is in question, settle it against FreeRDP's implementation or against a capture rather than against the specification's prose, which has been ambiguous or wrong every time it was asked.
Traps ¶
- Setting.EnableEGFX and Setting.EnableOrders are opt in, change how the server draws, and cannot be mixed with the bitmap path in one session.
- Setting.EnableClipboard and Setting.EnableDisplayControl are opt in because each opens a channel and changes the connect sequence. Without them the clipboard and resize methods return an error rather than doing nothing.
- A refused logon against an NLA server arrives looking like a TLS problem. [client.ErrAuthenticationFailed] is what says otherwise; see the README for the whole set of failure kinds.
- Change a capability and you change what the server sends. Order support and the pointer cache size in particular are contracts: advertise a pointer cache and the server stops resending shapes, so a client with nowhere to put them loses the cursor.
Working on it ¶
go build ./... && go vet ./... && go test ./... go run ./cmd/docaudit ./... // exported identifiers with no doc comment
scripts/dev-rdp.sh manages a local xrdp for integration testing and scripts/vnc-dev.sh fetches TigerVNC without root for the RFB side. The decoders are checked against libfreerdp by scripts/gen-codec-vectors.sh, which is why they can be trusted further than their own tests.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client is the API to use.
|
Package client is the API to use. |
|
cmd
|
|
|
docaudit
command
Command docaudit lists exported identifiers without doc comments.
|
Command docaudit lists exported identifiers without doc comments. |
|
rdpcli
command
Command rdpcli is a small headless RDP client used to verify connectivity against a live server.
|
Command rdpcli is a small headless RDP client used to verify connectivity against a live server. |
|
rdpws
command
Command rdpws is a headless RDP gateway: it holds an RDP session and serves the screen to a browser over a WebSocket, taking the browser's keyboard and mouse back the other way.
|
Command rdpws is a headless RDP gateway: it holds an RDP session and serves the screen to a browser over a WebSocket, taking the browser's keyboard and mouse back the other way. |
|
Package codec implements the bitmap codecs that RDP servers use to encode bitmap update and surface command payloads.
|
Package codec implements the bitmap codecs that RDP servers use to encode bitmap update and surface command payloads. |
|
Package core is the layer everything else is built on: bounded readers and writers over io.Reader and io.Writer, a net.Conn wrapper that can be upgraded to TLS, small string and pixel conversions, and the RLE bitmap decompressor.
|
Package core is the layer everything else is built on: bounded readers and writers over io.Reader and io.Writer, a net.Conn wrapper that can be upgraded to TLS, small string and pixel conversions, and the RLE bitmap decompressor. |
|
Package emission is an event emitter: named events with listener functions, and an optional panic recoverer.
|
Package emission is an event emitter: named events with listener functions, and an optional panic recoverer. |
|
Package glog is the logging shim the protocol layers write through.
|
Package glog is the logging shim the protocol layers write through. |
|
Package orders renders the drawing orders a server sends when the client says it supports them.
|
Package orders renders the drawing orders a server sends when the client says it supports them. |
|
Package plugin is the virtual channel framework.
|
Package plugin is the virtual channel framework. |
|
cliprdr
Package cliprdr implements the clipboard virtual channel: text and files, in both directions.
|
Package cliprdr implements the clipboard virtual channel: text and files, in both directions. |
|
disp
Package disp implements the display control dynamic virtual channel (MS-RDPEDISP), which is how a client asks the server to change the desktop size while a session is running.
|
Package disp implements the display control dynamic virtual channel (MS-RDPEDISP), which is how a client asks the server to change the desktop size while a session is running. |
|
drdynvc
Package drdynvc implements the dynamic virtual channel channel (MS-RDPEDYC).
|
Package drdynvc implements the dynamic virtual channel channel (MS-RDPEDYC). |
|
rdpgfx
Package rdpgfx implements the RDP Graphics Pipeline Extension channel (MS-RDPEGFX), the modern drawing path where a server composites surfaces and sends them as compressed bitmaps.
|
Package rdpgfx implements the RDP Graphics Pipeline Extension channel (MS-RDPEGFX), the modern drawing path where a server composites surfaces and sends them as compressed bitmaps. |
|
protocol
|
|
|
lic
Package lic holds the licensing PDUs, which an RDP client must answer before the session becomes usable.
|
Package lic holds the licensing PDUs, which an RDP client must answer before the session becomes usable. |
|
nla
Package nla implements NTLMv2 and CredSSP, which is how RDP authenticates the account before the session exists.
|
Package nla implements NTLMv2 and CredSSP, which is how RDP authenticates the account before the session exists. |
|
pdu
Package pdu is the RDP PDU layer: capabilities, session updates, input, and the drawing orders that the orders package renders.
|
Package pdu is the RDP PDU layer: capabilities, session updates, input, and the drawing orders that the orders package renders. |
|
rfb
Package rfb is the RFB (VNC) client protocol this fork inherited from upstream.
|
Package rfb is the RFB (VNC) client protocol this fork inherited from upstream. |
|
sec
Package sec is RDP security: the encryption of the session, and the licensing exchange that runs on top of it.
|
Package sec is RDP security: the encryption of the session, and the licensing exchange that runs on top of it. |
|
t125
Package t125 is MCS, the layer that carries RDP's channels over the connection X.224 established.
|
Package t125 is MCS, the layer that carries RDP's channels over the connection X.224 established. |
|
t125/ber
Package ber implements the BER/DER primitives that CredSSP's TSRequest is built from: tags, lengths, integers, octet strings and sequences.
|
Package ber implements the BER/DER primitives that CredSSP's TSRequest is built from: tags, lengths, integers, octet strings and sequences. |
|
t125/gcc
Package gcc holds the GCC user data blocks that travel inside the MCS connect initial: the client's core settings, the set of virtual channels it wants, and its security settings.
|
Package gcc holds the GCC user data blocks that travel inside the MCS connect initial: the client's core settings, the set of virtual channels it wants, and its security settings. |
|
t125/per
Package per implements the subset of PER encoding that MCS and the GCC blocks need: lengths, choices, enumerations, integers and octet streams.
|
Package per implements the subset of PER encoding that MCS and the GCC blocks need: lengths, choices, enumerations, integers and octet streams. |
|
tpkt
Package tpkt is the bottom of the RDP stack: the TPKT framing that every packet sits in, and the TLS and CredSSP handshake that runs before any RDP PDU does.
|
Package tpkt is the bottom of the RDP stack: the TPKT framing that every packet sits in, and the TLS and CredSSP handshake that runs before any RDP PDU does. |
|
x224
Package x224 carries the X.224 connection request and confirm, which is the first thing an RDP client says and the point at which the security protocol is chosen.
|
Package x224 carries the X.224 connection request and confirm, which is the first thing an RDP client says and the point at which the security protocol is chosen. |