1180750SdesThis documents OpenSSH's deviations and extensions to the published SSH
2180750Sdesprotocol.
3180750Sdes
4180750SdesNote that OpenSSH's sftp and sftp-server implement revision 3 of the SSH
5180750Sdesfilexfer protocol described in:
6180750Sdes
7180750Sdeshttp://www.openssh.com/txt/draft-ietf-secsh-filexfer-02.txt
8180750Sdes
9204917SdesNewer versions of the draft will not be supported, though some features
10204917Sdesare individually implemented as extensions described below.
11180750Sdes
12180750SdesThe protocol used by OpenSSH's ssh-agent is described in the file
13180750SdesPROTOCOL.agent
14180750Sdes
15221420Sdes1. Transport protocol changes
16180750Sdes
17221420Sdes1.1. transport: Protocol 2 MAC algorithm "umac-64@openssh.com"
18221420Sdes
19180750SdesThis is a new transport-layer MAC method using the UMAC algorithm
20180750Sdes(rfc4418). This method is identical to the "umac-64" method documented
21180750Sdesin:
22180750Sdes
23180750Sdeshttp://www.openssh.com/txt/draft-miller-secsh-umac-01.txt
24180750Sdes
25221420Sdes1.2. transport: Protocol 2 compression algorithm "zlib@openssh.com"
26180750Sdes
27180750SdesThis transport-layer compression method uses the zlib compression
28180750Sdesalgorithm (identical to the "zlib" method in rfc4253), but delays the
29180750Sdesstart of compression until after authentication has completed. This
30180750Sdesavoids exposing compression code to attacks from unauthenticated users.
31180750Sdes
32180750SdesThe method is documented in:
33180750Sdes
34180750Sdeshttp://www.openssh.com/txt/draft-miller-secsh-compression-delayed-00.txt
35180750Sdes
36221420Sdes1.3. transport: New public key algorithms "ssh-rsa-cert-v00@openssh.com",
37221420Sdes     "ssh-dsa-cert-v00@openssh.com",
38221420Sdes     "ecdsa-sha2-nistp256-cert-v01@openssh.com",
39221420Sdes     "ecdsa-sha2-nistp384-cert-v01@openssh.com" and
40221420Sdes     "ecdsa-sha2-nistp521-cert-v01@openssh.com"
41180750Sdes
42221420SdesOpenSSH introduces new public key algorithms to support certificate
43204917Sdesauthentication for users and hostkeys. These methods are documented in
44204917Sdesthe file PROTOCOL.certkeys
45204917Sdes
46221420Sdes1.4. transport: Elliptic Curve cryptography
47204917Sdes
48221420SdesOpenSSH supports ECC key exchange and public key authentication as
49221420Sdesspecified in RFC5656. Only the ecdsa-sha2-nistp256, ecdsa-sha2-nistp384
50221420Sdesand ecdsa-sha2-nistp521 curves over GF(p) are supported. Elliptic
51221420Sdescurve points encoded using point compression are NOT accepted or
52221420Sdesgenerated.
53221420Sdes
54248619Sdes1.5 transport: Protocol 2 Encrypt-then-MAC MAC algorithms
55248619Sdes
56248619SdesOpenSSH supports MAC algorithms, whose names contain "-etm", that
57248619Sdesperform the calculations in a different order to that defined in RFC
58248619Sdes4253. These variants use the so-called "encrypt then MAC" ordering,
59248619Sdescalculating the MAC over the packet ciphertext rather than the
60248619Sdesplaintext. This ordering closes a security flaw in the SSH transport
61248619Sdesprotocol, where decryption of unauthenticated ciphertext provided a
62248619Sdes"decryption oracle" that could, in conjunction with cipher flaws, reveal
63248619Sdessession plaintext.
64248619Sdes
65248619SdesSpecifically, the "-etm" MAC algorithms modify the transport protocol
66248619Sdesto calculate the MAC over the packet ciphertext and to send the packet
67248619Sdeslength unencrypted. This is necessary for the transport to obtain the
68248619Sdeslength of the packet and location of the MAC tag so that it may be
69248619Sdesverified without decrypting unauthenticated data.
70248619Sdes
71248619SdesAs such, the MAC covers:
72248619Sdes
73248619Sdes      mac = MAC(key, sequence_number || packet_length || encrypted_packet)
74248619Sdes
75248619Sdeswhere "packet_length" is encoded as a uint32 and "encrypted_packet"
76248619Sdescontains:
77248619Sdes
78248619Sdes      byte      padding_length
79248619Sdes      byte[n1]  payload; n1 = packet_length - padding_length - 1
80248619Sdes      byte[n2]  random padding; n2 = padding_length
81248619Sdes
82248619Sdes1.6 transport: AES-GCM
83248619Sdes
84248619SdesOpenSSH supports the AES-GCM algorithm as specified in RFC 5647.
85248619SdesBecause of problems with the specification of the key exchange
86248619Sdesthe behaviour of OpenSSH differs from the RFC as follows:
87248619Sdes
88248619SdesAES-GCM is only negotiated as the cipher algorithms
89248619Sdes"aes128-gcm@openssh.com" or "aes256-gcm@openssh.com" and never as
90248619Sdesan MAC algorithm. Additionally, if AES-GCM is selected as the cipher
91248619Sdesthe exchanged MAC algorithms are ignored and there doesn't have to be
92248619Sdesa matching MAC.
93248619Sdes
94221420Sdes2. Connection protocol changes
95221420Sdes
96221420Sdes2.1. connection: Channel write close extension "eow@openssh.com"
97221420Sdes
98180750SdesThe SSH connection protocol (rfc4254) provides the SSH_MSG_CHANNEL_EOF
99180750Sdesmessage to allow an endpoint to signal its peer that it will send no
100180750Sdesmore data over a channel. Unfortunately, there is no symmetric way for
101180750Sdesan endpoint to request that its peer should cease sending data to it
102180750Sdeswhile still keeping the channel open for the endpoint to send data to
103180750Sdesthe peer.
104180750Sdes
105180750SdesThis is desirable, since it saves the transmission of data that would
106180750Sdesotherwise need to be discarded and it allows an endpoint to signal local
107180750Sdesprocesses of the condition, e.g. by closing the corresponding file
108180750Sdesdescriptor.
109180750Sdes
110180750SdesOpenSSH implements a channel extension message to perform this
111180750Sdessignalling: "eow@openssh.com" (End Of Write). This message is sent by
112180750Sdesan endpoint when the local output of a session channel is closed or
113180750Sdesexperiences a write error. The message is formatted as follows:
114180750Sdes
115180750Sdes	byte		SSH_MSG_CHANNEL_REQUEST
116180750Sdes	uint32		recipient channel
117180750Sdes	string		"eow@openssh.com"
118180750Sdes	boolean		FALSE
119180750Sdes
120180750SdesOn receiving this message, the peer SHOULD cease sending data of
121180750Sdesthe channel and MAY signal the process from which the channel data
122180750Sdesoriginates (e.g. by closing its read file descriptor).
123180750Sdes
124180750SdesAs with the symmetric SSH_MSG_CHANNEL_EOF message, the channel does
125180750Sdesremain open after a "eow@openssh.com" has been sent and more data may
126180750Sdesstill be sent in the other direction. This message does not consume
127180750Sdeswindow space and may be sent even if no window space is available.
128180750Sdes
129192595SdesNB. due to certain broken SSH implementations aborting upon receipt
130192595Sdesof this message (in contravention of RFC4254 section 5.4), this
131192595Sdesmessage is only sent to OpenSSH peers (identified by banner).
132192595SdesOther SSH implementations may be whitelisted to receive this message
133192595Sdesupon request.
134192595Sdes
135221420Sdes2.2. connection: disallow additional sessions extension
136221420Sdes     "no-more-sessions@openssh.com"
137180750Sdes
138180750SdesMost SSH connections will only ever request a single session, but a
139180750Sdesattacker may abuse a running ssh client to surreptitiously open
140180750Sdesadditional sessions under their control. OpenSSH provides a global
141180750Sdesrequest "no-more-sessions@openssh.com" to mitigate this attack.
142180750Sdes
143180750SdesWhen an OpenSSH client expects that it will never open another session
144180750Sdes(i.e. it has been started with connection multiplexing disabled), it
145180750Sdeswill send the following global request:
146180750Sdes
147180750Sdes	byte		SSH_MSG_GLOBAL_REQUEST
148180750Sdes	string		"no-more-sessions@openssh.com"
149180750Sdes	char		want-reply
150180750Sdes
151180750SdesOn receipt of such a message, an OpenSSH server will refuse to open
152180750Sdesfuture channels of type "session" and instead immediately abort the
153180750Sdesconnection.
154180750Sdes
155180750SdesNote that this is not a general defence against compromised clients
156180750Sdes(that is impossible), but it thwarts a simple attack.
157180750Sdes
158192595SdesNB. due to certain broken SSH implementations aborting upon receipt
159192595Sdesof this message, the no-more-sessions request is only sent to OpenSSH
160192595Sdesservers (identified by banner). Other SSH implementations may be
161192595Sdeswhitelisted to receive this message upon request.
162192595Sdes
163221420Sdes2.3. connection: Tunnel forward extension "tun@openssh.com"
164180750Sdes
165180750SdesOpenSSH supports layer 2 and layer 3 tunnelling via the "tun@openssh.com"
166180750Sdeschannel type. This channel type supports forwarding of network packets
167180750Sdeswith datagram boundaries intact between endpoints equipped with 
168180750Sdesinterfaces like the BSD tun(4) device. Tunnel forwarding channels are
169180750Sdesrequested by the client with the following packet:
170180750Sdes
171180750Sdes	byte		SSH_MSG_CHANNEL_OPEN
172180750Sdes	string		"tun@openssh.com"
173180750Sdes	uint32		sender channel
174180750Sdes	uint32		initial window size
175180750Sdes	uint32		maximum packet size
176180750Sdes	uint32		tunnel mode
177180750Sdes	uint32		remote unit number
178180750Sdes
179180750SdesThe "tunnel mode" parameter specifies whether the tunnel should forward
180180750Sdeslayer 2 frames or layer 3 packets. It may take one of the following values:
181180750Sdes
182180750Sdes	SSH_TUNMODE_POINTOPOINT  1		/* layer 3 packets */
183180750Sdes	SSH_TUNMODE_ETHERNET     2		/* layer 2 frames */
184180750Sdes
185180750SdesThe "tunnel unit number" specifies the remote interface number, or may
186204917Sdesbe 0x7fffffff to allow the server to automatically chose an interface. A
187204917Sdesserver that is not willing to open a client-specified unit should refuse
188204917Sdesthe request with a SSH_MSG_CHANNEL_OPEN_FAILURE error. On successful
189204917Sdesopen, the server should reply with SSH_MSG_CHANNEL_OPEN_SUCCESS.
190180750Sdes
191180750SdesOnce established the client and server may exchange packet or frames
192180750Sdesover the tunnel channel by encapsulating them in SSH protocol strings
193180750Sdesand sending them as channel data. This ensures that packet boundaries
194180750Sdesare kept intact. Specifically, packets are transmitted using normal
195180750SdesSSH_MSG_CHANNEL_DATA packets:
196180750Sdes
197180750Sdes	byte		SSH_MSG_CHANNEL_DATA
198180750Sdes	uint32		recipient channel
199180750Sdes	string		data
200180750Sdes
201180750SdesThe contents of the "data" field for layer 3 packets is:
202180750Sdes
203180750Sdes	uint32			packet length
204180750Sdes	uint32			address family
205180750Sdes	byte[packet length - 4]	packet data
206180750Sdes
207180750SdesThe "address family" field identifies the type of packet in the message.
208180750SdesIt may be one of:
209180750Sdes
210180750Sdes	SSH_TUN_AF_INET		2		/* IPv4 */
211180750Sdes	SSH_TUN_AF_INET6	24		/* IPv6 */
212180750Sdes
213180750SdesThe "packet data" field consists of the IPv4/IPv6 datagram itself
214180750Sdeswithout any link layer header.
215180750Sdes
216204917SdesThe contents of the "data" field for layer 2 packets is:
217180750Sdes
218180750Sdes	uint32			packet length
219180750Sdes	byte[packet length]	frame
220180750Sdes
221180750SdesThe "frame" field contains an IEEE 802.3 Ethernet frame, including
222180750Sdesheader.
223180750Sdes
224221420Sdes3. SFTP protocol changes
225180750Sdes
226221420Sdes3.1. sftp: Reversal of arguments to SSH_FXP_SYMLINK
227221420Sdes
228180750SdesWhen OpenSSH's sftp-server was implemented, the order of the arguments
229180750Sdesto the SSH_FXP_SYMLINK method was inadvertently reversed. Unfortunately,
230180750Sdesthe reversal was not noticed until the server was widely deployed. Since
231180750Sdesfixing this to follow the specification would cause incompatibility, the
232180750Sdescurrent order was retained. For correct operation, clients should send
233180750SdesSSH_FXP_SYMLINK as follows:
234180750Sdes
235180750Sdes	uint32		id
236180750Sdes	string		targetpath
237180750Sdes	string		linkpath
238180750Sdes
239221420Sdes3.2. sftp: Server extension announcement in SSH_FXP_VERSION
240180750Sdes
241180750SdesOpenSSH's sftp-server lists the extensions it supports using the
242180750Sdesstandard extension announcement mechanism in the SSH_FXP_VERSION server
243180750Sdeshello packet:
244180750Sdes
245180750Sdes	uint32		3		/* protocol version */
246180750Sdes	string		ext1-name
247180750Sdes	string		ext1-version
248180750Sdes	string		ext2-name
249180750Sdes	string		ext2-version
250180750Sdes	...
251180750Sdes	string		extN-name
252180750Sdes	string		extN-version
253180750Sdes
254180750SdesEach extension reports its integer version number as an ASCII encoded
255180750Sdesstring, e.g. "1". The version will be incremented if the extension is
256180750Sdesever changed in an incompatible way. The server MAY advertise the same
257180750Sdesextension with multiple versions (though this is unlikely). Clients MUST
258180750Sdescheck the version number before attempting to use the extension.
259180750Sdes
260221420Sdes3.3. sftp: Extension request "posix-rename@openssh.com"
261180750Sdes
262180750SdesThis operation provides a rename operation with POSIX semantics, which
263180750Sdesare different to those provided by the standard SSH_FXP_RENAME in
264180750Sdesdraft-ietf-secsh-filexfer-02.txt. This request is implemented as a
265180750SdesSSH_FXP_EXTENDED request with the following format:
266180750Sdes
267180750Sdes	uint32		id
268180750Sdes	string		"posix-rename@openssh.com"
269180750Sdes	string		oldpath
270180750Sdes	string		newpath
271180750Sdes
272180750SdesOn receiving this request the server will perform the POSIX operation
273180750Sdesrename(oldpath, newpath) and will respond with a SSH_FXP_STATUS message.
274180750SdesThis extension is advertised in the SSH_FXP_VERSION hello with version
275180750Sdes"1".
276180750Sdes
277221420Sdes3.4. sftp: Extension requests "statvfs@openssh.com" and
278180750Sdes         "fstatvfs@openssh.com"
279180750Sdes
280180750SdesThese requests correspond to the statvfs and fstatvfs POSIX system
281180750Sdesinterfaces. The "statvfs@openssh.com" request operates on an explicit
282180750Sdespathname, and is formatted as follows:
283180750Sdes
284180750Sdes	uint32		id
285180750Sdes	string		"statvfs@openssh.com"
286180750Sdes	string		path
287180750Sdes
288180750SdesThe "fstatvfs@openssh.com" operates on an open file handle:
289180750Sdes
290180750Sdes	uint32		id
291180750Sdes	string		"fstatvfs@openssh.com"
292180750Sdes	string		handle
293180750Sdes
294180750SdesThese requests return a SSH_FXP_STATUS reply on failure. On success they
295180750Sdesreturn the following SSH_FXP_EXTENDED_REPLY reply:
296180750Sdes
297180750Sdes	uint32		id
298180750Sdes	uint64		f_bsize		/* file system block size */
299180750Sdes	uint64		f_frsize	/* fundamental fs block size */
300180750Sdes	uint64		f_blocks	/* number of blocks (unit f_frsize) */
301180750Sdes	uint64		f_bfree		/* free blocks in file system */
302180750Sdes	uint64		f_bavail	/* free blocks for non-root */
303180750Sdes	uint64		f_files		/* total file inodes */
304180750Sdes	uint64		f_ffree		/* free file inodes */
305180750Sdes	uint64		f_favail	/* free file inodes for to non-root */
306180750Sdes	uint64		f_fsid		/* file system id */
307180750Sdes	uint64		f_flag		/* bit mask of f_flag values */
308180750Sdes	uint64		f_namemax	/* maximum filename length */
309180750Sdes
310180750SdesThe values of the f_flag bitmask are as follows:
311180750Sdes
312180750Sdes	#define SSH_FXE_STATVFS_ST_RDONLY	0x1	/* read-only */
313180750Sdes	#define SSH_FXE_STATVFS_ST_NOSUID	0x2	/* no setuid */
314180750Sdes
315180750SdesBoth the "statvfs@openssh.com" and "fstatvfs@openssh.com" extensions are
316180750Sdesadvertised in the SSH_FXP_VERSION hello with version "2".
317180750Sdes
318221420Sdes10. sftp: Extension request "hardlink@openssh.com"
319221420Sdes
320221420SdesThis request is for creating a hard link to a regular file. This
321221420Sdesrequest is implemented as a SSH_FXP_EXTENDED request with the
322221420Sdesfollowing format:
323221420Sdes
324221420Sdes	uint32		id
325221420Sdes	string		"hardlink@openssh.com"
326221420Sdes	string		oldpath
327221420Sdes	string		newpath
328221420Sdes
329221420SdesOn receiving this request the server will perform the operation
330221420Sdeslink(oldpath, newpath) and will respond with a SSH_FXP_STATUS message.
331221420SdesThis extension is advertised in the SSH_FXP_VERSION hello with version
332221420Sdes"1".
333221420Sdes
334248619Sdes$OpenBSD: PROTOCOL,v 1.20 2013/01/08 18:49:04 markus Exp $
335