Extension TLS - jedimatt42/tipi GitHub Wiki

TLS Extension

Represent TLS socket access from Raw extensions. This is registered as 0x24 in RawExtensions.py

Usage

Client Socket Commands

command Message format Errors
open 0x24 + handle-byte + 0x01 + "hostname:port" 0 : failed to connect
close 0x24 + handle-byte + 0x02 n/a
write 0x24 + handle-byte + 0x03 + [ data array ] 0 : failed to write
read 0x24 + handle-byte + 0x04 + size-msb + size-lsb n/a

Send a message starting with 0x24 as the first byte. The second byte should be socket handle number to use. The third byte is the command to process, followed by command specific arguments.

Client Sockets

Socket handle numbers are a single byte 0-255, assigned arbitrarily by the TI code when it passes the value in the open command.

For command 0x01 open / follow with string in the form of "hostname:port". Tipi will return a message of 255 if connected or 0 if failed to connect. The string will be assumed to be the message length - 1. To connect as handle 0x00 to www.google.com port 80 the message bytes could be:

0x24 0x00 0x01 'w' 'w' 'w' '.' 'g' 'o' 'o' 'g' 'l' 'e' '.' 'c' 'o' 'm' ':' '4' '4' '3'

For command 0x02 close / no parameters. Tipi will return 255. To close socket with handle 0x00:

0x24 0x00 0x02

For command 0x03 write / follow with bytes to write to socket. Tipi will return after bytes are written with 255 or 0 if failed to write. To write "HELLO" to socket with handle 0x00:

0x24 0x00 0x03 'H' 'E' 'L' 'L' 'O'

For 0x04 read / follow with max size to read as int (two bytes, [msb,lsb]). Tipi will return message of read socket data no greater than max size. It may read from 0 to max size. This depends on the available bytes in the socket buffer on the Raspberry PI's TCP stack. Reading 0 bytes does not indicate that the there is no more data, just that it hasn't been buffered yet. Use higher-level protocols to determine completeness. TIPI returns a 0 length array if the socket is not open. To request reading upto 2k from the socket with handle 0x00:

0x24 0x00 0x04 0x02 0x00

Note on read - if the remote system disconnects, it will not be detected by reading alone. However, attempts to write will eventually fail in the case of a remote initiated disconnect.