mirror of
https://github.com/bolkedebruin/rdpgw.git
synced 2025-08-17 14:03:50 +02:00
Add test cases and start client
This commit is contained in:
parent
dadaeb611b
commit
5618294f10
4 changed files with 162 additions and 12 deletions
|
@ -3,6 +3,8 @@ package protocol
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -43,4 +45,72 @@ func (c *ClientConfig) handshakeRequest() []byte {
|
|||
return createPacket(PKT_TYPE_HANDSHAKE_REQUEST, buf.Bytes())
|
||||
}
|
||||
|
||||
func (c *ClientConfig) readServerHandshakeResponse(data []byte) ()
|
||||
func (c *ClientConfig) handshakeResponse(data []byte) (caps uint16, err error) {
|
||||
var errorCode int32
|
||||
var major byte
|
||||
var minor byte
|
||||
var version uint16
|
||||
|
||||
r := bytes.NewReader(data)
|
||||
binary.Read(r, binary.LittleEndian, &errorCode)
|
||||
binary.Read(r, binary.LittleEndian, &major)
|
||||
binary.Read(r, binary.LittleEndian, &minor)
|
||||
binary.Read(r, binary.LittleEndian, &version)
|
||||
binary.Read(r, binary.LittleEndian, &caps)
|
||||
|
||||
if errorCode > 0 {
|
||||
return 0, fmt.Errorf("error code: %d", errorCode)
|
||||
}
|
||||
|
||||
return caps, nil
|
||||
}
|
||||
|
||||
func (c *ClientConfig) tunnelRequest() []byte {
|
||||
buf := new(bytes.Buffer)
|
||||
var caps uint32
|
||||
var size uint16
|
||||
var fields uint16
|
||||
|
||||
if len(c.PAAToken) > 0 {
|
||||
fields = fields | HTTP_TUNNEL_PACKET_FIELD_PAA_COOKIE
|
||||
}
|
||||
|
||||
caps = caps | HTTP_CAPABILITY_IDLE_TIMEOUT
|
||||
|
||||
binary.Write(buf, binary.LittleEndian, caps)
|
||||
binary.Write(buf, binary.LittleEndian, fields)
|
||||
binary.Write(buf, binary.LittleEndian, uint16(0)) // reserved
|
||||
|
||||
if len(c.PAAToken) > 0 {
|
||||
utf16Token := EncodeUTF16(c.PAAToken)
|
||||
size = uint16(len(utf16Token))
|
||||
binary.Write(buf, binary.LittleEndian, size)
|
||||
buf.Write(utf16Token)
|
||||
}
|
||||
|
||||
return createPacket(PKT_TYPE_TUNNEL_CREATE, buf.Bytes())
|
||||
}
|
||||
|
||||
func (c *ClientConfig) tunnelResponse(data []byte) (tunnelId uint32, caps uint32, err error) {
|
||||
var version uint16
|
||||
var errorCode uint32
|
||||
var fields uint16
|
||||
|
||||
r := bytes.NewReader(data)
|
||||
binary.Read(r, binary.LittleEndian, &version)
|
||||
binary.Read(r, binary.LittleEndian, &errorCode)
|
||||
binary.Read(r, binary.LittleEndian, &fields)
|
||||
r.Seek(2, io.SeekCurrent)
|
||||
if (fields & HTTP_TUNNEL_RESPONSE_FIELD_TUNNEL_ID) == HTTP_TUNNEL_RESPONSE_FIELD_TUNNEL_ID {
|
||||
binary.Read(r, binary.LittleEndian, &tunnelId)
|
||||
}
|
||||
if (fields & HTTP_TUNNEL_RESPONSE_FIELD_CAPS) == HTTP_TUNNEL_RESPONSE_FIELD_CAPS {
|
||||
binary.Read(r, binary.LittleEndian, &caps)
|
||||
}
|
||||
|
||||
if errorCode != 0 {
|
||||
err = fmt.Errorf("tunnel error %d", errorCode)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue