Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 1 | This documents OpenSSH's deviations and extensions to the published SSH |
| 2 | protocol. |
| 3 | |
| 4 | Note that OpenSSH's sftp and sftp-server implement revision 3 of the SSH |
| 5 | filexfer protocol described in: |
| 6 | |
| 7 | http://www.openssh.com/txt/draft-ietf-secsh-filexfer-02.txt |
| 8 | |
Darren Tucker | a2e1048 | 2010-01-09 22:25:14 +1100 | [diff] [blame] | 9 | Newer versions of the draft will not be supported, though some features |
| 10 | are individually implemented as extensions described below. |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 11 | |
Damien Miller | 1e18beb | 2008-06-30 00:07:00 +1000 | [diff] [blame] | 12 | The protocol used by OpenSSH's ssh-agent is described in the file |
| 13 | PROTOCOL.agent |
| 14 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 15 | 1. Transport protocol changes |
| 16 | |
| 17 | 1.1. transport: Protocol 2 MAC algorithm "umac-64@openssh.com" |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 18 | |
| 19 | This is a new transport-layer MAC method using the UMAC algorithm |
| 20 | (rfc4418). This method is identical to the "umac-64" method documented |
| 21 | in: |
| 22 | |
| 23 | http://www.openssh.com/txt/draft-miller-secsh-umac-01.txt |
| 24 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 25 | 1.2. transport: Protocol 2 compression algorithm "zlib@openssh.com" |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 26 | |
| 27 | This transport-layer compression method uses the zlib compression |
| 28 | algorithm (identical to the "zlib" method in rfc4253), but delays the |
| 29 | start of compression until after authentication has completed. This |
| 30 | avoids exposing compression code to attacks from unauthenticated users. |
| 31 | |
| 32 | The method is documented in: |
| 33 | |
| 34 | http://www.openssh.com/txt/draft-miller-secsh-compression-delayed-00.txt |
| 35 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 36 | 1.3. transport: New public key algorithms "ssh-rsa-cert-v00@openssh.com", |
| 37 | "ssh-dsa-cert-v00@openssh.com", |
| 38 | "ecdsa-sha2-nistp256-cert-v01@openssh.com", |
| 39 | "ecdsa-sha2-nistp384-cert-v01@openssh.com" and |
| 40 | "ecdsa-sha2-nistp521-cert-v01@openssh.com" |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 41 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 42 | OpenSSH introduces new public key algorithms to support certificate |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 43 | authentication for users and hostkeys. These methods are documented in |
| 44 | the file PROTOCOL.certkeys |
| 45 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 46 | 1.4. transport: Elliptic Curve cryptography |
| 47 | |
| 48 | OpenSSH supports ECC key exchange and public key authentication as |
| 49 | specified in RFC5656. Only the ecdsa-sha2-nistp256, ecdsa-sha2-nistp384 |
| 50 | and ecdsa-sha2-nistp521 curves over GF(p) are supported. Elliptic |
| 51 | curve points encoded using point compression are NOT accepted or |
| 52 | generated. |
| 53 | |
Damien Miller | af43a7a | 2012-12-12 10:46:31 +1100 | [diff] [blame] | 54 | 1.5 transport: Protocol 2 Encrypt-then-MAC MAC algorithms |
| 55 | |
| 56 | OpenSSH supports MAC algorithms, whose names contain "-etm", that |
| 57 | perform the calculations in a different order to that defined in RFC |
| 58 | 4253. These variants use the so-called "encrypt then MAC" ordering, |
| 59 | calculating the MAC over the packet ciphertext rather than the |
| 60 | plaintext. This ordering closes a security flaw in the SSH transport |
| 61 | protocol, where decryption of unauthenticated ciphertext provided a |
| 62 | "decryption oracle" that could, in conjunction with cipher flaws, reveal |
| 63 | session plaintext. |
| 64 | |
| 65 | Specifically, the "-etm" MAC algorithms modify the transport protocol |
| 66 | to calculate the MAC over the packet ciphertext and to send the packet |
| 67 | length unencrypted. This is necessary for the transport to obtain the |
| 68 | length of the packet and location of the MAC tag so that it may be |
| 69 | verified without decrypting unauthenticated data. |
| 70 | |
| 71 | As such, the MAC covers: |
| 72 | |
Damien Miller | 3739c8f | 2013-01-09 15:57:16 +1100 | [diff] [blame] | 73 | mac = MAC(key, sequence_number || packet_length || encrypted_packet) |
Damien Miller | af43a7a | 2012-12-12 10:46:31 +1100 | [diff] [blame] | 74 | |
Damien Miller | 3739c8f | 2013-01-09 15:57:16 +1100 | [diff] [blame] | 75 | where "packet_length" is encoded as a uint32 and "encrypted_packet" |
| 76 | contains: |
Damien Miller | af43a7a | 2012-12-12 10:46:31 +1100 | [diff] [blame] | 77 | |
| 78 | byte padding_length |
| 79 | byte[n1] payload; n1 = packet_length - padding_length - 1 |
| 80 | byte[n2] random padding; n2 = padding_length |
| 81 | |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 82 | 1.6 transport: AES-GCM |
| 83 | |
| 84 | OpenSSH supports the AES-GCM algorithm as specified in RFC 5647. |
| 85 | Because of problems with the specification of the key exchange |
| 86 | the behaviour of OpenSSH differs from the RFC as follows: |
| 87 | |
| 88 | AES-GCM is only negotiated as the cipher algorithms |
| 89 | "aes128-gcm@openssh.com" or "aes256-gcm@openssh.com" and never as |
| 90 | an MAC algorithm. Additionally, if AES-GCM is selected as the cipher |
| 91 | the exchanged MAC algorithms are ignored and there doesn't have to be |
| 92 | a matching MAC. |
| 93 | |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame^] | 94 | 1.7 transport: chacha20-poly1305@openssh.com authenticated encryption |
| 95 | |
| 96 | OpenSSH supports authenticated encryption using ChaCha20 and Poly1305 |
| 97 | as described in PROTOCOL.chacha20poly1305. |
| 98 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 99 | 2. Connection protocol changes |
| 100 | |
| 101 | 2.1. connection: Channel write close extension "eow@openssh.com" |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 102 | |
| 103 | The SSH connection protocol (rfc4254) provides the SSH_MSG_CHANNEL_EOF |
| 104 | message to allow an endpoint to signal its peer that it will send no |
| 105 | more data over a channel. Unfortunately, there is no symmetric way for |
| 106 | an endpoint to request that its peer should cease sending data to it |
| 107 | while still keeping the channel open for the endpoint to send data to |
| 108 | the peer. |
| 109 | |
| 110 | This is desirable, since it saves the transmission of data that would |
| 111 | otherwise need to be discarded and it allows an endpoint to signal local |
| 112 | processes of the condition, e.g. by closing the corresponding file |
| 113 | descriptor. |
| 114 | |
| 115 | OpenSSH implements a channel extension message to perform this |
Darren Tucker | 1f781b1 | 2008-07-02 22:33:16 +1000 | [diff] [blame] | 116 | signalling: "eow@openssh.com" (End Of Write). This message is sent by |
| 117 | an endpoint when the local output of a session channel is closed or |
| 118 | experiences a write error. The message is formatted as follows: |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 119 | |
| 120 | byte SSH_MSG_CHANNEL_REQUEST |
| 121 | uint32 recipient channel |
| 122 | string "eow@openssh.com" |
| 123 | boolean FALSE |
| 124 | |
| 125 | On receiving this message, the peer SHOULD cease sending data of |
| 126 | the channel and MAY signal the process from which the channel data |
| 127 | originates (e.g. by closing its read file descriptor). |
| 128 | |
| 129 | As with the symmetric SSH_MSG_CHANNEL_EOF message, the channel does |
| 130 | remain open after a "eow@openssh.com" has been sent and more data may |
| 131 | still be sent in the other direction. This message does not consume |
| 132 | window space and may be sent even if no window space is available. |
| 133 | |
Damien Miller | 6385e75 | 2009-02-14 18:00:52 +1100 | [diff] [blame] | 134 | NB. due to certain broken SSH implementations aborting upon receipt |
| 135 | of this message (in contravention of RFC4254 section 5.4), this |
| 136 | message is only sent to OpenSSH peers (identified by banner). |
| 137 | Other SSH implementations may be whitelisted to receive this message |
| 138 | upon request. |
| 139 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 140 | 2.2. connection: disallow additional sessions extension |
| 141 | "no-more-sessions@openssh.com" |
Darren Tucker | 8901fa9 | 2008-06-11 09:34:01 +1000 | [diff] [blame] | 142 | |
| 143 | Most SSH connections will only ever request a single session, but a |
| 144 | attacker may abuse a running ssh client to surreptitiously open |
| 145 | additional sessions under their control. OpenSSH provides a global |
| 146 | request "no-more-sessions@openssh.com" to mitigate this attack. |
| 147 | |
| 148 | When an OpenSSH client expects that it will never open another session |
| 149 | (i.e. it has been started with connection multiplexing disabled), it |
| 150 | will send the following global request: |
| 151 | |
| 152 | byte SSH_MSG_GLOBAL_REQUEST |
| 153 | string "no-more-sessions@openssh.com" |
| 154 | char want-reply |
| 155 | |
| 156 | On receipt of such a message, an OpenSSH server will refuse to open |
| 157 | future channels of type "session" and instead immediately abort the |
| 158 | connection. |
| 159 | |
| 160 | Note that this is not a general defence against compromised clients |
| 161 | (that is impossible), but it thwarts a simple attack. |
| 162 | |
Damien Miller | 6385e75 | 2009-02-14 18:00:52 +1100 | [diff] [blame] | 163 | NB. due to certain broken SSH implementations aborting upon receipt |
| 164 | of this message, the no-more-sessions request is only sent to OpenSSH |
| 165 | servers (identified by banner). Other SSH implementations may be |
| 166 | whitelisted to receive this message upon request. |
| 167 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 168 | 2.3. connection: Tunnel forward extension "tun@openssh.com" |
Darren Tucker | e5d9829 | 2008-06-13 04:53:27 +1000 | [diff] [blame] | 169 | |
Damien Miller | bd45afb | 2008-06-30 00:04:57 +1000 | [diff] [blame] | 170 | OpenSSH supports layer 2 and layer 3 tunnelling via the "tun@openssh.com" |
Darren Tucker | e5d9829 | 2008-06-13 04:53:27 +1000 | [diff] [blame] | 171 | channel type. This channel type supports forwarding of network packets |
Damien Miller | bd45afb | 2008-06-30 00:04:57 +1000 | [diff] [blame] | 172 | with datagram boundaries intact between endpoints equipped with |
Darren Tucker | e5d9829 | 2008-06-13 04:53:27 +1000 | [diff] [blame] | 173 | interfaces like the BSD tun(4) device. Tunnel forwarding channels are |
| 174 | requested by the client with the following packet: |
| 175 | |
| 176 | byte SSH_MSG_CHANNEL_OPEN |
| 177 | string "tun@openssh.com" |
| 178 | uint32 sender channel |
| 179 | uint32 initial window size |
| 180 | uint32 maximum packet size |
| 181 | uint32 tunnel mode |
| 182 | uint32 remote unit number |
| 183 | |
| 184 | The "tunnel mode" parameter specifies whether the tunnel should forward |
| 185 | layer 2 frames or layer 3 packets. It may take one of the following values: |
| 186 | |
| 187 | SSH_TUNMODE_POINTOPOINT 1 /* layer 3 packets */ |
| 188 | SSH_TUNMODE_ETHERNET 2 /* layer 2 frames */ |
| 189 | |
| 190 | The "tunnel unit number" specifies the remote interface number, or may |
Darren Tucker | f2705c8 | 2010-01-08 18:54:17 +1100 | [diff] [blame] | 191 | be 0x7fffffff to allow the server to automatically chose an interface. A |
| 192 | server that is not willing to open a client-specified unit should refuse |
| 193 | the request with a SSH_MSG_CHANNEL_OPEN_FAILURE error. On successful |
| 194 | open, the server should reply with SSH_MSG_CHANNEL_OPEN_SUCCESS. |
Darren Tucker | e5d9829 | 2008-06-13 04:53:27 +1000 | [diff] [blame] | 195 | |
| 196 | Once established the client and server may exchange packet or frames |
| 197 | over the tunnel channel by encapsulating them in SSH protocol strings |
| 198 | and sending them as channel data. This ensures that packet boundaries |
| 199 | are kept intact. Specifically, packets are transmitted using normal |
| 200 | SSH_MSG_CHANNEL_DATA packets: |
| 201 | |
| 202 | byte SSH_MSG_CHANNEL_DATA |
| 203 | uint32 recipient channel |
| 204 | string data |
| 205 | |
| 206 | The contents of the "data" field for layer 3 packets is: |
| 207 | |
| 208 | uint32 packet length |
| 209 | uint32 address family |
| 210 | byte[packet length - 4] packet data |
| 211 | |
| 212 | The "address family" field identifies the type of packet in the message. |
| 213 | It may be one of: |
| 214 | |
| 215 | SSH_TUN_AF_INET 2 /* IPv4 */ |
| 216 | SSH_TUN_AF_INET6 24 /* IPv6 */ |
| 217 | |
| 218 | The "packet data" field consists of the IPv4/IPv6 datagram itself |
| 219 | without any link layer header. |
| 220 | |
Darren Tucker | f2705c8 | 2010-01-08 18:54:17 +1100 | [diff] [blame] | 221 | The contents of the "data" field for layer 2 packets is: |
Darren Tucker | e5d9829 | 2008-06-13 04:53:27 +1000 | [diff] [blame] | 222 | |
| 223 | uint32 packet length |
| 224 | byte[packet length] frame |
| 225 | |
Damien Miller | bd45afb | 2008-06-30 00:04:57 +1000 | [diff] [blame] | 226 | The "frame" field contains an IEEE 802.3 Ethernet frame, including |
Darren Tucker | e5d9829 | 2008-06-13 04:53:27 +1000 | [diff] [blame] | 227 | header. |
| 228 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 229 | 3. SFTP protocol changes |
| 230 | |
| 231 | 3.1. sftp: Reversal of arguments to SSH_FXP_SYMLINK |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 232 | |
| 233 | When OpenSSH's sftp-server was implemented, the order of the arguments |
Damien Miller | bd45afb | 2008-06-30 00:04:57 +1000 | [diff] [blame] | 234 | to the SSH_FXP_SYMLINK method was inadvertently reversed. Unfortunately, |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 235 | the reversal was not noticed until the server was widely deployed. Since |
| 236 | fixing this to follow the specification would cause incompatibility, the |
| 237 | current order was retained. For correct operation, clients should send |
| 238 | SSH_FXP_SYMLINK as follows: |
| 239 | |
| 240 | uint32 id |
| 241 | string targetpath |
| 242 | string linkpath |
| 243 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 244 | 3.2. sftp: Server extension announcement in SSH_FXP_VERSION |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 245 | |
| 246 | OpenSSH's sftp-server lists the extensions it supports using the |
| 247 | standard extension announcement mechanism in the SSH_FXP_VERSION server |
| 248 | hello packet: |
| 249 | |
| 250 | uint32 3 /* protocol version */ |
| 251 | string ext1-name |
| 252 | string ext1-version |
| 253 | string ext2-name |
| 254 | string ext2-version |
| 255 | ... |
| 256 | string extN-name |
| 257 | string extN-version |
| 258 | |
| 259 | Each extension reports its integer version number as an ASCII encoded |
| 260 | string, e.g. "1". The version will be incremented if the extension is |
| 261 | ever changed in an incompatible way. The server MAY advertise the same |
| 262 | extension with multiple versions (though this is unlikely). Clients MUST |
Damien Miller | bd45afb | 2008-06-30 00:04:57 +1000 | [diff] [blame] | 263 | check the version number before attempting to use the extension. |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 264 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 265 | 3.3. sftp: Extension request "posix-rename@openssh.com" |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 266 | |
| 267 | This operation provides a rename operation with POSIX semantics, which |
| 268 | are different to those provided by the standard SSH_FXP_RENAME in |
| 269 | draft-ietf-secsh-filexfer-02.txt. This request is implemented as a |
| 270 | SSH_FXP_EXTENDED request with the following format: |
| 271 | |
| 272 | uint32 id |
| 273 | string "posix-rename@openssh.com" |
| 274 | string oldpath |
| 275 | string newpath |
| 276 | |
| 277 | On receiving this request the server will perform the POSIX operation |
| 278 | rename(oldpath, newpath) and will respond with a SSH_FXP_STATUS message. |
| 279 | This extension is advertised in the SSH_FXP_VERSION hello with version |
| 280 | "1". |
| 281 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 282 | 3.4. sftp: Extension requests "statvfs@openssh.com" and |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 283 | "fstatvfs@openssh.com" |
| 284 | |
| 285 | These requests correspond to the statvfs and fstatvfs POSIX system |
| 286 | interfaces. The "statvfs@openssh.com" request operates on an explicit |
| 287 | pathname, and is formatted as follows: |
| 288 | |
| 289 | uint32 id |
| 290 | string "statvfs@openssh.com" |
| 291 | string path |
| 292 | |
Damien Miller | bd45afb | 2008-06-30 00:04:57 +1000 | [diff] [blame] | 293 | The "fstatvfs@openssh.com" operates on an open file handle: |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 294 | |
| 295 | uint32 id |
| 296 | string "fstatvfs@openssh.com" |
| 297 | string handle |
| 298 | |
| 299 | These requests return a SSH_FXP_STATUS reply on failure. On success they |
| 300 | return the following SSH_FXP_EXTENDED_REPLY reply: |
| 301 | |
| 302 | uint32 id |
Darren Tucker | cd2ada6 | 2008-06-09 23:49:09 +1000 | [diff] [blame] | 303 | uint64 f_bsize /* file system block size */ |
| 304 | uint64 f_frsize /* fundamental fs block size */ |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 305 | uint64 f_blocks /* number of blocks (unit f_frsize) */ |
| 306 | uint64 f_bfree /* free blocks in file system */ |
| 307 | uint64 f_bavail /* free blocks for non-root */ |
| 308 | uint64 f_files /* total file inodes */ |
| 309 | uint64 f_ffree /* free file inodes */ |
| 310 | uint64 f_favail /* free file inodes for to non-root */ |
Darren Tucker | 17ec5d4 | 2008-06-09 23:47:37 +1000 | [diff] [blame] | 311 | uint64 f_fsid /* file system id */ |
Darren Tucker | cd2ada6 | 2008-06-09 23:49:09 +1000 | [diff] [blame] | 312 | uint64 f_flag /* bit mask of f_flag values */ |
| 313 | uint64 f_namemax /* maximum filename length */ |
Damien Miller | 58a8114 | 2008-05-19 16:11:56 +1000 | [diff] [blame] | 314 | |
| 315 | The values of the f_flag bitmask are as follows: |
| 316 | |
| 317 | #define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */ |
| 318 | #define SSH_FXE_STATVFS_ST_NOSUID 0x2 /* no setuid */ |
| 319 | |
Damien Miller | c9c96f2 | 2008-07-05 15:17:48 +1000 | [diff] [blame] | 320 | Both the "statvfs@openssh.com" and "fstatvfs@openssh.com" extensions are |
| 321 | advertised in the SSH_FXP_VERSION hello with version "2". |
Darren Tucker | 17ec5d4 | 2008-06-09 23:47:37 +1000 | [diff] [blame] | 322 | |
Darren Tucker | af1f909 | 2010-12-05 09:02:47 +1100 | [diff] [blame] | 323 | 10. sftp: Extension request "hardlink@openssh.com" |
| 324 | |
| 325 | This request is for creating a hard link to a regular file. This |
| 326 | request is implemented as a SSH_FXP_EXTENDED request with the |
| 327 | following format: |
| 328 | |
| 329 | uint32 id |
| 330 | string "hardlink@openssh.com" |
| 331 | string oldpath |
| 332 | string newpath |
| 333 | |
| 334 | On receiving this request the server will perform the operation |
| 335 | link(oldpath, newpath) and will respond with a SSH_FXP_STATUS message. |
| 336 | This extension is advertised in the SSH_FXP_VERSION hello with version |
| 337 | "1". |
| 338 | |
Damien Miller | f29238e | 2013-10-17 11:48:52 +1100 | [diff] [blame] | 339 | 10. sftp: Extension request "fsync@openssh.com" |
| 340 | |
| 341 | This request asks the server to call fsync(2) on an open file handle. |
| 342 | |
| 343 | uint32 id |
| 344 | string "fsync@openssh.com" |
| 345 | string handle |
| 346 | |
| 347 | One receiving this request, a server will call fsync(handle_fd) and will |
| 348 | respond with a SSH_FXP_STATUS message. |
| 349 | |
| 350 | This extension is advertised in the SSH_FXP_VERSION hello with version |
| 351 | "1". |
| 352 | |
Damien Miller | 0fde8ac | 2013-11-21 14:12:23 +1100 | [diff] [blame^] | 353 | $OpenBSD: PROTOCOL,v 1.22 2013/11/21 00:45:43 djm Exp $ |