I need to specify some terminal modes, specifically the TTY_OP_ISPEED/TTY_OP_OSPEED
in our SSH
client. However for the life of me I can't figure out the correct format.
Reading http://www.ietf.org/proceedings/56/I-D/draft-ietf-secsh-connect-16.txt tells me that they are encoded into a byte stream, but there is absolutely no indication of HOW.
I'm guessing I need to format my string similar to:
byte[] terminalModes = "TTY_OP_ISPEED=36000;TTY_OP_OSPEED=36000;".getBytes();
or:
byte[] terminalModes = "128 36000 129 36000".getBytes();
Our program is using a ssh client implemented de.mud.jta.plugin/ch.ethz.ssh2 however I don't think this matters as I can see they are simply using the byte[] as is. (I'm using the http://www.ganymed.ethz.ch/ssh2/javadoc/ch/ethz/ssh2/Session.html#requestPTY(java.lang.String, int, int, int, int, byte[]) method to pass in the termnial modes)
Any examples of valid pty-req strings would be appreciated.
Thanks in advance!
The format is specified at the beginning of section 8 of RFC 4254, which is the finalized version of the draft you were reading:
All 'encoded terminal modes' (as passed in a pty request) are encoded
into a byte stream. It is intended that the coding be portable
across different environments. The stream consists of opcode-
argument pairs wherein the opcode is a byte value. Opcodes 1 to 159
have a single uint32 argument. Opcodes 160 to 255 are not yet
defined, and cause parsing to stop (they should only be used after
any other data). The stream is terminated by opcode TTY_OP_END
(0x00).
So, if you wanted to specify input and output speeds of 36000, you'd encode that as:
byte[] terminalModes = {
128, // TTY_OP_ISPEED
0, 0, 0x8c, 0xa0, // 36000 = 00008ca0
129, // TTY_OP_OSPEED
0, 0, 0x8c, 0xa0, // 36000 again
0, // TTY_OP_END
};
(There's probably a more fluent way of doing this in Java, but I don't know it offhand.)
Note that not all servers will actually support this. Most UNIX-based OSes only support standard baud rates for PTYs (e.g, 14400, 28800, 38400, 57600, 115200), and most of them don't even use that for anything.