PROTOCOL 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. This documents OpenSSH's deviations and extensions to the published SSH
  2. protocol.
  3. Note that OpenSSH's sftp and sftp-server implement revision 3 of the SSH
  4. filexfer protocol described in:
  5. https://www.openssh.com/txt/draft-ietf-secsh-filexfer-02.txt
  6. Newer versions of the draft will not be supported, though some features
  7. are individually implemented as extensions described below.
  8. The protocol used by OpenSSH's ssh-agent is described in the file
  9. PROTOCOL.agent
  10. 1. Transport protocol changes
  11. 1.1. transport: Protocol 2 MAC algorithm "umac-64@openssh.com"
  12. This is a new transport-layer MAC method using the UMAC algorithm
  13. (rfc4418). This method is identical to the "umac-64" method documented
  14. in:
  15. https://www.openssh.com/txt/draft-miller-secsh-umac-01.txt
  16. 1.2. transport: Protocol 2 compression algorithm "zlib@openssh.com"
  17. This transport-layer compression method uses the zlib compression
  18. algorithm (identical to the "zlib" method in rfc4253), but delays the
  19. start of compression until after authentication has completed. This
  20. avoids exposing compression code to attacks from unauthenticated users.
  21. The method is documented in:
  22. https://www.openssh.com/txt/draft-miller-secsh-compression-delayed-00.txt
  23. 1.3. transport: New public key algorithms "ssh-rsa-cert-v01@openssh.com",
  24. "ssh-dsa-cert-v01@openssh.com",
  25. "ecdsa-sha2-nistp256-cert-v01@openssh.com",
  26. "ecdsa-sha2-nistp384-cert-v01@openssh.com" and
  27. "ecdsa-sha2-nistp521-cert-v01@openssh.com"
  28. OpenSSH introduces new public key algorithms to support certificate
  29. authentication for users and host keys. These methods are documented
  30. in the file PROTOCOL.certkeys
  31. 1.4. transport: Elliptic Curve cryptography
  32. OpenSSH supports ECC key exchange and public key authentication as
  33. specified in RFC5656. Only the ecdsa-sha2-nistp256, ecdsa-sha2-nistp384
  34. and ecdsa-sha2-nistp521 curves over GF(p) are supported. Elliptic
  35. curve points encoded using point compression are NOT accepted or
  36. generated.
  37. 1.5 transport: Protocol 2 Encrypt-then-MAC MAC algorithms
  38. OpenSSH supports MAC algorithms, whose names contain "-etm", that
  39. perform the calculations in a different order to that defined in RFC
  40. 4253. These variants use the so-called "encrypt then MAC" ordering,
  41. calculating the MAC over the packet ciphertext rather than the
  42. plaintext. This ordering closes a security flaw in the SSH transport
  43. protocol, where decryption of unauthenticated ciphertext provided a
  44. "decryption oracle" that could, in conjunction with cipher flaws, reveal
  45. session plaintext.
  46. Specifically, the "-etm" MAC algorithms modify the transport protocol
  47. to calculate the MAC over the packet ciphertext and to send the packet
  48. length unencrypted. This is necessary for the transport to obtain the
  49. length of the packet and location of the MAC tag so that it may be
  50. verified without decrypting unauthenticated data.
  51. As such, the MAC covers:
  52. mac = MAC(key, sequence_number || packet_length || encrypted_packet)
  53. where "packet_length" is encoded as a uint32 and "encrypted_packet"
  54. contains:
  55. byte padding_length
  56. byte[n1] payload; n1 = packet_length - padding_length - 1
  57. byte[n2] random padding; n2 = padding_length
  58. 1.6 transport: AES-GCM
  59. OpenSSH supports the AES-GCM algorithm as specified in RFC 5647.
  60. Because of problems with the specification of the key exchange
  61. the behaviour of OpenSSH differs from the RFC as follows:
  62. AES-GCM is only negotiated as the cipher algorithms
  63. "aes128-gcm@openssh.com" or "aes256-gcm@openssh.com" and never as
  64. an MAC algorithm. Additionally, if AES-GCM is selected as the cipher
  65. the exchanged MAC algorithms are ignored and there doesn't have to be
  66. a matching MAC.
  67. 1.7 transport: chacha20-poly1305@openssh.com authenticated encryption
  68. OpenSSH supports authenticated encryption using ChaCha20 and Poly1305
  69. as described in PROTOCOL.chacha20poly1305.
  70. 1.8 transport: curve25519-sha256@libssh.org key exchange algorithm
  71. OpenSSH supports the use of ECDH in Curve25519 for key exchange as
  72. described at:
  73. http://git.libssh.org/users/aris/libssh.git/plain/doc/curve25519-sha256@libssh.org.txt?h=curve25519
  74. 2. Connection protocol changes
  75. 2.1. connection: Channel write close extension "eow@openssh.com"
  76. The SSH connection protocol (rfc4254) provides the SSH_MSG_CHANNEL_EOF
  77. message to allow an endpoint to signal its peer that it will send no
  78. more data over a channel. Unfortunately, there is no symmetric way for
  79. an endpoint to request that its peer should cease sending data to it
  80. while still keeping the channel open for the endpoint to send data to
  81. the peer.
  82. This is desirable, since it saves the transmission of data that would
  83. otherwise need to be discarded and it allows an endpoint to signal local
  84. processes of the condition, e.g. by closing the corresponding file
  85. descriptor.
  86. OpenSSH implements a channel extension message to perform this
  87. signalling: "eow@openssh.com" (End Of Write). This message is sent by
  88. an endpoint when the local output of a session channel is closed or
  89. experiences a write error. The message is formatted as follows:
  90. byte SSH_MSG_CHANNEL_REQUEST
  91. uint32 recipient channel
  92. string "eow@openssh.com"
  93. boolean FALSE
  94. On receiving this message, the peer SHOULD cease sending data of
  95. the channel and MAY signal the process from which the channel data
  96. originates (e.g. by closing its read file descriptor).
  97. As with the symmetric SSH_MSG_CHANNEL_EOF message, the channel does
  98. remain open after a "eow@openssh.com" has been sent and more data may
  99. still be sent in the other direction. This message does not consume
  100. window space and may be sent even if no window space is available.
  101. NB. due to certain broken SSH implementations aborting upon receipt
  102. of this message (in contravention of RFC4254 section 5.4), this
  103. message is only sent to OpenSSH peers (identified by banner).
  104. Other SSH implementations may be listed to receive this message
  105. upon request.
  106. 2.2. connection: disallow additional sessions extension
  107. "no-more-sessions@openssh.com"
  108. Most SSH connections will only ever request a single session, but a
  109. attacker may abuse a running ssh client to surreptitiously open
  110. additional sessions under their control. OpenSSH provides a global
  111. request "no-more-sessions@openssh.com" to mitigate this attack.
  112. When an OpenSSH client expects that it will never open another session
  113. (i.e. it has been started with connection multiplexing disabled), it
  114. will send the following global request:
  115. byte SSH_MSG_GLOBAL_REQUEST
  116. string "no-more-sessions@openssh.com"
  117. char want-reply
  118. On receipt of such a message, an OpenSSH server will refuse to open
  119. future channels of type "session" and instead immediately abort the
  120. connection.
  121. Note that this is not a general defence against compromised clients
  122. (that is impossible), but it thwarts a simple attack.
  123. NB. due to certain broken SSH implementations aborting upon receipt
  124. of this message, the no-more-sessions request is only sent to OpenSSH
  125. servers (identified by banner). Other SSH implementations may be
  126. listed to receive this message upon request.
  127. 2.3. connection: Tunnel forward extension "tun@openssh.com"
  128. OpenSSH supports layer 2 and layer 3 tunnelling via the "tun@openssh.com"
  129. channel type. This channel type supports forwarding of network packets
  130. with datagram boundaries intact between endpoints equipped with
  131. interfaces like the BSD tun(4) device. Tunnel forwarding channels are
  132. requested by the client with the following packet:
  133. byte SSH_MSG_CHANNEL_OPEN
  134. string "tun@openssh.com"
  135. uint32 sender channel
  136. uint32 initial window size
  137. uint32 maximum packet size
  138. uint32 tunnel mode
  139. uint32 remote unit number
  140. The "tunnel mode" parameter specifies whether the tunnel should forward
  141. layer 2 frames or layer 3 packets. It may take one of the following values:
  142. SSH_TUNMODE_POINTOPOINT 1 /* layer 3 packets */
  143. SSH_TUNMODE_ETHERNET 2 /* layer 2 frames */
  144. The "tunnel unit number" specifies the remote interface number, or may
  145. be 0x7fffffff to allow the server to automatically choose an interface. A
  146. server that is not willing to open a client-specified unit should refuse
  147. the request with a SSH_MSG_CHANNEL_OPEN_FAILURE error. On successful
  148. open, the server should reply with SSH_MSG_CHANNEL_OPEN_SUCCESS.
  149. Once established the client and server may exchange packet or frames
  150. over the tunnel channel by encapsulating them in SSH protocol strings
  151. and sending them as channel data. This ensures that packet boundaries
  152. are kept intact. Specifically, packets are transmitted using normal
  153. SSH_MSG_CHANNEL_DATA packets:
  154. byte SSH_MSG_CHANNEL_DATA
  155. uint32 recipient channel
  156. string data
  157. The contents of the "data" field for layer 3 packets is:
  158. uint32 packet length
  159. uint32 address family
  160. byte[packet length - 4] packet data
  161. The "address family" field identifies the type of packet in the message.
  162. It may be one of:
  163. SSH_TUN_AF_INET 2 /* IPv4 */
  164. SSH_TUN_AF_INET6 24 /* IPv6 */
  165. The "packet data" field consists of the IPv4/IPv6 datagram itself
  166. without any link layer header.
  167. The contents of the "data" field for layer 2 packets is:
  168. uint32 packet length
  169. byte[packet length] frame
  170. The "frame" field contains an IEEE 802.3 Ethernet frame, including
  171. header.
  172. 2.4. connection: Unix domain socket forwarding
  173. OpenSSH supports local and remote Unix domain socket forwarding
  174. using the "streamlocal" extension. Forwarding is initiated as per
  175. TCP sockets but with a single path instead of a host and port.
  176. Similar to direct-tcpip, direct-streamlocal is sent by the client
  177. to request that the server make a connection to a Unix domain socket.
  178. byte SSH_MSG_CHANNEL_OPEN
  179. string "direct-streamlocal@openssh.com"
  180. uint32 sender channel
  181. uint32 initial window size
  182. uint32 maximum packet size
  183. string socket path
  184. string reserved
  185. uint32 reserved
  186. Similar to forwarded-tcpip, forwarded-streamlocal is sent by the
  187. server when the client has previously send the server a streamlocal-forward
  188. GLOBAL_REQUEST.
  189. byte SSH_MSG_CHANNEL_OPEN
  190. string "forwarded-streamlocal@openssh.com"
  191. uint32 sender channel
  192. uint32 initial window size
  193. uint32 maximum packet size
  194. string socket path
  195. string reserved for future use
  196. The reserved field is not currently defined and is ignored on the
  197. remote end. It is intended to be used in the future to pass
  198. information about the socket file, such as ownership and mode.
  199. The client currently sends the empty string for this field.
  200. Similar to tcpip-forward, streamlocal-forward is sent by the client
  201. to request remote forwarding of a Unix domain socket.
  202. byte SSH2_MSG_GLOBAL_REQUEST
  203. string "streamlocal-forward@openssh.com"
  204. boolean TRUE
  205. string socket path
  206. Similar to cancel-tcpip-forward, cancel-streamlocal-forward is sent
  207. by the client cancel the forwarding of a Unix domain socket.
  208. byte SSH2_MSG_GLOBAL_REQUEST
  209. string "cancel-streamlocal-forward@openssh.com"
  210. boolean FALSE
  211. string socket path
  212. 2.5. connection: hostkey update and rotation "hostkeys-00@openssh.com"
  213. and "hostkeys-prove-00@openssh.com"
  214. OpenSSH supports a protocol extension allowing a server to inform
  215. a client of all its protocol v.2 host keys after user-authentication
  216. has completed.
  217. byte SSH_MSG_GLOBAL_REQUEST
  218. string "hostkeys-00@openssh.com"
  219. char 0 /* want-reply */
  220. string[] hostkeys
  221. Upon receiving this message, a client should check which of the
  222. supplied host keys are present in known_hosts.
  223. Note that the server may send key types that the client does not
  224. support. The client should disregard such keys if they are received.
  225. If the client identifies any keys that are not present for the host,
  226. it should send a "hostkeys-prove@openssh.com" message to request the
  227. server prove ownership of the private half of the key.
  228. byte SSH_MSG_GLOBAL_REQUEST
  229. string "hostkeys-prove-00@openssh.com"
  230. char 1 /* want-reply */
  231. string[] hostkeys
  232. When a server receives this message, it should generate a signature
  233. using each requested key over the following:
  234. string "hostkeys-prove-00@openssh.com"
  235. string session identifier
  236. string hostkey
  237. These signatures should be included in the reply, in the order matching
  238. the hostkeys in the request:
  239. byte SSH_MSG_REQUEST_SUCCESS
  240. string[] signatures
  241. When the client receives this reply (and not a failure), it should
  242. validate the signatures and may update its known_hosts file, adding keys
  243. that it has not seen before and deleting keys for the server host that
  244. are no longer offered.
  245. These extensions let a client learn key types that it had not previously
  246. encountered, thereby allowing it to potentially upgrade from weaker
  247. key algorithms to better ones. It also supports graceful key rotation:
  248. a server may offer multiple keys of the same type for a period (to
  249. give clients an opportunity to learn them using this extension) before
  250. removing the deprecated key from those offered.
  251. 2.6. connection: SIGINFO support for "signal" channel request
  252. The SSH channels protocol (RFC4254 section 6.9) supports sending a
  253. signal to a session attached to a channel. OpenSSH supports one
  254. extension signal "INFO@openssh.com" that allows sending SIGINFO on
  255. BSD-derived systems.
  256. 3. SFTP protocol changes
  257. 3.1. sftp: Reversal of arguments to SSH_FXP_SYMLINK
  258. When OpenSSH's sftp-server was implemented, the order of the arguments
  259. to the SSH_FXP_SYMLINK method was inadvertently reversed. Unfortunately,
  260. the reversal was not noticed until the server was widely deployed. Since
  261. fixing this to follow the specification would cause incompatibility, the
  262. current order was retained. For correct operation, clients should send
  263. SSH_FXP_SYMLINK as follows:
  264. uint32 id
  265. string targetpath
  266. string linkpath
  267. 3.2. sftp: Server extension announcement in SSH_FXP_VERSION
  268. OpenSSH's sftp-server lists the extensions it supports using the
  269. standard extension announcement mechanism in the SSH_FXP_VERSION server
  270. hello packet:
  271. uint32 3 /* protocol version */
  272. string ext1-name
  273. string ext1-version
  274. string ext2-name
  275. string ext2-version
  276. ...
  277. string extN-name
  278. string extN-version
  279. Each extension reports its integer version number as an ASCII encoded
  280. string, e.g. "1". The version will be incremented if the extension is
  281. ever changed in an incompatible way. The server MAY advertise the same
  282. extension with multiple versions (though this is unlikely). Clients MUST
  283. check the version number before attempting to use the extension.
  284. 3.3. sftp: Extension request "posix-rename@openssh.com"
  285. This operation provides a rename operation with POSIX semantics, which
  286. are different to those provided by the standard SSH_FXP_RENAME in
  287. draft-ietf-secsh-filexfer-02.txt. This request is implemented as a
  288. SSH_FXP_EXTENDED request with the following format:
  289. uint32 id
  290. string "posix-rename@openssh.com"
  291. string oldpath
  292. string newpath
  293. On receiving this request the server will perform the POSIX operation
  294. rename(oldpath, newpath) and will respond with a SSH_FXP_STATUS message.
  295. This extension is advertised in the SSH_FXP_VERSION hello with version
  296. "1".
  297. 3.4. sftp: Extension requests "statvfs@openssh.com" and
  298. "fstatvfs@openssh.com"
  299. These requests correspond to the statvfs and fstatvfs POSIX system
  300. interfaces. The "statvfs@openssh.com" request operates on an explicit
  301. pathname, and is formatted as follows:
  302. uint32 id
  303. string "statvfs@openssh.com"
  304. string path
  305. The "fstatvfs@openssh.com" operates on an open file handle:
  306. uint32 id
  307. string "fstatvfs@openssh.com"
  308. string handle
  309. These requests return a SSH_FXP_STATUS reply on failure. On success they
  310. return the following SSH_FXP_EXTENDED_REPLY reply:
  311. uint32 id
  312. uint64 f_bsize /* file system block size */
  313. uint64 f_frsize /* fundamental fs block size */
  314. uint64 f_blocks /* number of blocks (unit f_frsize) */
  315. uint64 f_bfree /* free blocks in file system */
  316. uint64 f_bavail /* free blocks for non-root */
  317. uint64 f_files /* total file inodes */
  318. uint64 f_ffree /* free file inodes */
  319. uint64 f_favail /* free file inodes for to non-root */
  320. uint64 f_fsid /* file system id */
  321. uint64 f_flag /* bit mask of f_flag values */
  322. uint64 f_namemax /* maximum filename length */
  323. The values of the f_flag bitmask are as follows:
  324. #define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */
  325. #define SSH_FXE_STATVFS_ST_NOSUID 0x2 /* no setuid */
  326. Both the "statvfs@openssh.com" and "fstatvfs@openssh.com" extensions are
  327. advertised in the SSH_FXP_VERSION hello with version "2".
  328. 3.5. sftp: Extension request "hardlink@openssh.com"
  329. This request is for creating a hard link to a regular file. This
  330. request is implemented as a SSH_FXP_EXTENDED request with the
  331. following format:
  332. uint32 id
  333. string "hardlink@openssh.com"
  334. string oldpath
  335. string newpath
  336. On receiving this request the server will perform the operation
  337. link(oldpath, newpath) and will respond with a SSH_FXP_STATUS message.
  338. This extension is advertised in the SSH_FXP_VERSION hello with version
  339. "1".
  340. 3.6. sftp: Extension request "fsync@openssh.com"
  341. This request asks the server to call fsync(2) on an open file handle.
  342. uint32 id
  343. string "fsync@openssh.com"
  344. string handle
  345. One receiving this request, a server will call fsync(handle_fd) and will
  346. respond with a SSH_FXP_STATUS message.
  347. This extension is advertised in the SSH_FXP_VERSION hello with version
  348. "1".
  349. 3.7. sftp: Extension request "lsetstat@openssh.com"
  350. This request is like the "setstat" command, but sets file attributes on
  351. symlinks. It is implemented as a SSH_FXP_EXTENDED request with the
  352. following format:
  353. uint32 id
  354. string "lsetstat@openssh.com"
  355. string path
  356. ATTRS attrs
  357. See the "setstat" command for more details.
  358. This extension is advertised in the SSH_FXP_VERSION hello with version
  359. "1".
  360. 3.8. sftp: Extension request "limits@openssh.com"
  361. This request is used to determine various limits the server might impose.
  362. Clients should not attempt to exceed these limits as the server might sever
  363. the connection immediately.
  364. uint32 id
  365. string "limits@openssh.com"
  366. The server will respond with a SSH_FXP_EXTENDED_REPLY reply:
  367. uint32 id
  368. uint64 max-packet-length
  369. uint64 max-read-length
  370. uint64 max-write-length
  371. uint64 max-open-handles
  372. The 'max-packet-length' applies to the total number of bytes in a
  373. single SFTP packet. Servers SHOULD set this at least to 34000.
  374. The 'max-read-length' is the largest length in a SSH_FXP_READ packet.
  375. Even if the client requests a larger size, servers will usually respond
  376. with a shorter SSH_FXP_DATA packet. Servers SHOULD set this at least to
  377. 32768.
  378. The 'max-write-length' is the largest length in a SSH_FXP_WRITE packet
  379. the server will accept. Servers SHOULD set this at least to 32768.
  380. The 'max-open-handles' is the maximum number of active handles that the
  381. server allows (e.g. handles created by SSH_FXP_OPEN and SSH_FXP_OPENDIR
  382. packets). Servers MAY count internal file handles against this limit
  383. (e.g. system logging or stdout/stderr), so clients SHOULD NOT expect to
  384. open this many handles in practice.
  385. If the server doesn't enforce a specific limit, then the field may be
  386. set to 0. This implies the server relies on the OS to enforce limits
  387. (e.g. available memory or file handles), and such limits might be
  388. dynamic. The client SHOULD take care to not try to exceed reasonable
  389. limits.
  390. This extension is advertised in the SSH_FXP_VERSION hello with version
  391. "1".
  392. 4. Miscellaneous changes
  393. 4.1 Public key format
  394. OpenSSH public keys, as generated by ssh-keygen(1) and appearing in
  395. authorized_keys files, are formatted as a single line of text consisting
  396. of the public key algorithm name followed by a base64-encoded key blob.
  397. The public key blob (before base64 encoding) is the same format used for
  398. the encoding of public keys sent on the wire: as described in RFC4253
  399. section 6.6 for RSA and DSA keys, RFC5656 section 3.1 for ECDSA keys
  400. and the "New public key formats" section of PROTOCOL.certkeys for the
  401. OpenSSH certificate formats.
  402. 4.2 Private key format
  403. OpenSSH private keys, as generated by ssh-keygen(1) use the format
  404. described in PROTOCOL.key by default. As a legacy option, PEM format
  405. (RFC7468) private keys are also supported for RSA, DSA and ECDSA keys
  406. and were the default format before OpenSSH 7.8.
  407. 4.3 KRL format
  408. OpenSSH supports a compact format for Key Revocation Lists (KRLs). This
  409. format is described in the PROTOCOL.krl file.
  410. 4.4 Connection multiplexing
  411. OpenSSH's connection multiplexing uses messages as described in
  412. PROTOCOL.mux over a Unix domain socket for communications between a
  413. master instance and later clients.
  414. $OpenBSD: PROTOCOL,v 1.38 2020/07/05 23:59:45 djm Exp $