idnits 2.17.1 draft-ietf-secsh-transport-02.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Cannot find the required boilerplate sections (Copyright, IPR, etc.) in this document. Expected boilerplate is as follows today (2024-04-25) according to https://trustee.ietf.org/license-info : IETF Trust Legal Provisions of 28-dec-2009, Section 6.a: This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 2: Copyright (c) 2024 IETF Trust and the persons identified as the document authors. All rights reserved. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 3: This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing expiration date. The document expiration date should appear on the first and last page. ** The document seems to lack a 1id_guidelines paragraph about Internet-Drafts being working documents. ** The document seems to lack a 1id_guidelines paragraph about 6 months document validity -- however, there's a paragraph with a matching beginning. Boilerplate error? ** The document seems to lack a 1id_guidelines paragraph about the list of current Internet-Drafts. ** The document seems to lack a 1id_guidelines paragraph about the list of Shadow Directories. == No 'Intended status' indicated for this document; assuming Proposed Standard Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack an Authors' Addresses Section. ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. ** There is 1 instance of too long lines in the document, the longest one being 3 characters in excess of 72. Miscellaneous warnings: ---------------------------------------------------------------------------- == Line 423 has weird spacing: '... string cert...' == Line 489 has weird spacing: '... string kex...' == Line 490 has weird spacing: '... string ser...' == Line 491 has weird spacing: '... string enc...' == Line 492 has weird spacing: '... string enc...' == (18 more instances...) == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). == Using lowercase 'not' together with uppercase 'MUST', 'SHALL', 'SHOULD', or 'RECOMMENDED' is not an accepted usage according to RFC 2119. Please use uppercase 'NOT' together with RFC 2119 keywords (if that is what you mean). Found 'SHOULD not' in this paragraph: Server implementations MAY support a configurable "compatibility" flag that enables compatibility with old versions. When this flag is on, the server SHOULD not send any further data after its initialization string until it has received an identification string from the client. The server can then determine whether the client is using an old protocol, and can revert to the old protocol if desired. -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (14 October 1997) is 9690 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: 'SPKI' is mentioned on line 459, but not defined -- Looks like a reference, but probably isn't: '16' on line 488 == Unused Reference: 'RFC-1034' is defined on line 959, but no explicit reference was found in the text == Unused Reference: 'RFC-1766' is defined on line 962, but no explicit reference was found in the text == Unused Reference: 'SSH-CONNECT' is defined on line 993, but no explicit reference was found in the text -- Possible downref: Non-RFC (?) normative reference: ref. 'FIPS-186' -- Possible downref: Non-RFC (?) normative reference: ref. 'Orm96' ** Obsolete normative reference: RFC 1766 (Obsoleted by RFC 3066, RFC 3282) ** Downref: Normative reference to an Informational RFC: RFC 1950 ** Downref: Normative reference to an Informational RFC: RFC 1951 ** Obsolete normative reference: RFC 2044 (Obsoleted by RFC 2279) ** Downref: Normative reference to an Informational RFC: RFC 2104 ** Downref: Normative reference to an Informational RFC: RFC 2144 -- Possible downref: Non-RFC (?) normative reference: ref. 'Schneier' == Outdated reference: A later version (-22) exists of draft-ietf-secsh-architecture-00 == Outdated reference: A later version (-25) exists of draft-ietf-secsh-connect-02 -- Possible downref: Non-RFC (?) normative reference: ref. 'PGP' -- Possible downref: Non-RFC (?) normative reference: ref. 'PKIX-Part1' Summary: 16 errors (**), 0 flaws (~~), 15 warnings (==), 9 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 1 Network Working Group T. Ylonen 2 INTERNET-DRAFT T. Kivinen 3 draft-ietf-secsh-transport-02.txt M. Saarinen 4 Expires in six months SSH 5 14 October 1997 7 SSH Transport Layer Protocol 9 Status of This memo 11 This document is an Internet-Draft. Internet-Drafts are working 12 documents of the Internet Engineering Task Force (IETF), its areas, 13 and its working groups. Note that other groups may also distribute 14 working documents as Internet-Drafts. 16 Internet-Drafts are draft documents valid for a maximum of six 17 months and may be updated, replaced, or obsoleted by other documents 18 at any time. It is inappropriate to use Internet-Drafts as reference 19 material or to cite them other than as ``work in progress.'' 21 To learn the current status of any Internet-Draft, please check 22 the ``1id-abstracts.txt'' listing contained in the Internet-Drafts 23 Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe), 24 munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), 25 or ftp.isi.edu (US West Coast). 27 Abstract 29 SSH is a protocol for secure remote login and other secure network ser- 30 vices over an insecure network. 32 This document describes the SSH transport layer protocol which typically 33 runs on top of TCP/IP. The protocol can be used as a basis for a number 34 of secure network services. It provides strong encryption, server 35 authentication, and integrity protection. It may also provide 36 compression. 38 Key exchange method, public key algorithm, symmetric encryption 39 algorithm, message authentication algorithm, and hash algorithm are all 40 negotiated. 42 This document also describes the Diffie-Hellman key exchange method and 43 the minimal set of algorithms that are needed to implement the SSH 44 transport layer protocol. 46 Table of Contents 48 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . 2 49 2. Conventions Used in This Document . . . . . . . . . . . . . . . 3 50 3. Connection Setup . . . . . . . . . . . . . . . . . . . . . . . . 3 51 3.1. Use over TCP/IP . . . . . . . . . . . . . . . . . . . . . . 3 52 3.2. Protocol Version Exchange . . . . . . . . . . . . . . . . . 3 53 3.3. Compatibility with Old SSH Versions . . . . . . . . . . . . 4 54 3.3.1. Old Client, New Server . . . . . . . . . . . . . . . . . 4 55 3.3.2. New Client, Old Server . . . . . . . . . . . . . . . . . 4 56 4. Binary Packet Protocol . . . . . . . . . . . . . . . . . . . . . 4 57 4.1. Maximum Packet Length . . . . . . . . . . . . . . . . . . . 5 58 4.2. Compression . . . . . . . . . . . . . . . . . . . . . . . . 5 59 4.3. Encryption . . . . . . . . . . . . . . . . . . . . . . . . . 6 60 4.4. Data Integrity . . . . . . . . . . . . . . . . . . . . . . . 7 61 4.5. Key Exchange Methods . . . . . . . . . . . . . . . . . . . . 8 62 4.6. Public Key Algorithms . . . . . . . . . . . . . . . . . . . 8 63 5. Key Exchange . . . . . . . . . . . . . . . . . . . . . . . . . . 9 64 5.1. Algorithm Negotiation . . . . . . . . . . . . . . . . . . . 10 65 5.2. Output from Key Exchange . . . . . . . . . . . . . . . . . . 12 66 5.3. Taking Keys into Use . . . . . . . . . . . . . . . . . . . . 13 67 6. Diffie-Hellman Key Exchange . . . . . . . . . . . . . . . . . . 13 68 6.1. diffie-hellman-group1-sha1 . . . . . . . . . . . . . . . . . 15 69 7. Key Re-Exchange . . . . . . . . . . . . . . . . . . . . . . . . 15 70 8. Service Request . . . . . . . . . . . . . . . . . . . . . . . . 16 71 9. Additional Messages . . . . . . . . . . . . . . . . . . . . . . 16 72 9.1. Disconnection Message . . . . . . . . . . . . . . . . . . . 16 73 9.2. Ignored Data Message . . . . . . . . . . . . . . . . . . . . 17 74 9.3. Debug Message . . . . . . . . . . . . . . . . . . . . . . . 17 75 9.4. Reserved Messages . . . . . . . . . . . . . . . . . . . . . 18 76 10. Summary of Message Numbers . . . . . . . . . . . . . . . . . . 18 77 11. Security Considerations . . . . . . . . . . . . . . . . . . . . 18 78 12. References . . . . . . . . . . . . . . . . . . . . . . . . . . 19 79 13. Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . 20 81 1. Introduction 83 The SSH transport layer is a secure low level transport protocol. It 84 provides strong encryption, cryptographic host authentication, and 85 integrity protection. 87 Authentication in this protocol level is host-based; this protocol does 88 not perform user authentication. A higher level protocol for user 89 authentication can be designed on top of this protocol. 91 The protocol has been designed to be simple, flexible, to allow 92 parameter negotiation, and to minimize the number of round-trips. Key 93 exchange method, public key algorithm, symmetric encryption algorithm, 94 message authentication algorithm, and hash algorithm are all negotiated. 95 It is expected that in most environments, only 2 round-trips will be 96 needed for full key exchange, server authentication, service request, 97 and acceptance notification of service request. The worst case is 3 98 round-trips. 100 2. Conventions Used in This Document 102 The keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT", and 103 "MAY" that appear in this document are to be interpreted as described in 104 [RFC-2119]. 106 The used data types and terminology are specified in the architecture 107 document [SSH-ARCH]. 109 The architecture document also discusses the algorithm naming 110 conventions that MUST be used with the SSH protocols. 111 3. Connection Setup 113 SSH works over any 8-bit clean, binary-transparent packet-based 114 transport. The underlying transport SHOULD protect against transmission 115 errors as such errors cause the SSH connection to terminate. 117 The client initiates the connection. 119 3.1. Use over TCP/IP 121 When used over TCP/IP, the server normally listens for connections on 122 port 22. This port number has been registered with the IANA, and has 123 been officially assigned for SSH. 125 3.2. Protocol Version Exchange 127 When the connection has been established, both sides MUST send an 128 identification string of the form "SSH-protoversion-softwareversion 129 comments", followed by carriage return and newline characters (ascii 13 130 and 10, respectively). No null character is sent. The maximum length 131 of the string is 255 characters, including the carriage return and 132 newline. 134 The part of the identification string preceding carriage return and 135 newline is used in the Diffie-Hellman key exchange (Section ``Diffie- 136 Hellman Key Exchange''). 138 The server MAY send other lines of data before sending the version 139 string. Each line SHOULD be terminated by a carriage return and 140 newline. Such lines MUST NOT begin with "SSH-", and SHOULD be encoded 141 in ISO-10646 UTF-8 [RFC-2044] (language is not specified). Clients MUST 142 be able to process such lines; they MAY be silently ignored, or MAY be 143 displayed to the client user; if they are displayed, control character 144 filtering discussed in [SSH-ARCH] SHOULD be used. The primary use of 145 this feature is to allow TCP-wrappers to display an error message before 146 disconnecting. 148 Version strings MUST consist of printable US-ASCII characters, not 149 including whitespaces or a minus sign (-). The version string is 150 primarily used to trigger compatible extensions and to indicate the 151 capabilities of an implementation. The comment string should contain 152 additional information that might be useful in solving user problems. 154 The protocol version described in this document is 2.0. 156 Key exchange will begin immediately after sending this identifier. All 157 packets following the identification string SHALL use the binary packet 158 protocol, to be described below. 160 3.3. Compatibility with Old SSH Versions 162 During a transition period, it is important to be able to work 163 compatibly with installed SSH clients and servers using an older version 164 of the protocol. Information in this section is only relevant for 165 implementations supporting compatibility with SSH versions 1.x. 167 3.3.1. Old Client, New Server 169 Server implementations MAY support a configurable "compatibility" flag 170 that enables compatibility with old versions. When this flag is on, the 171 server SHOULD not send any further data after its initialization string 172 until it has received an identification string from the client. The 173 server can then determine whether the client is using an old protocol, 174 and can revert to the old protocol if desired. 176 When compatibility with old clients is not needed, the server MAY send 177 its initial key exchange data immediately after the identification 178 string. 180 3.3.2. New Client, Old Server 182 Since the new client MAY immediately send additional data after its 183 identification string (before receiving server's identification), the 184 old protocol may already have been corrupted when the client learns that 185 the server is old. When this happens, the client SHOULD close the 186 connection to the server, and reconnect using the old protocol. 188 4. Binary Packet Protocol 190 Each packet is of the following format. 192 uint32 packet_length 193 byte padding_length 194 byte[n1] payload; n1 = packet_length - padding_length - 1 195 byte[n2] random padding; n2 = padding_length 196 byte[m] mac (message authentication code); m = mac_length 198 packet_length 199 The length of the packet (bytes), not including MAC or the 200 packet_length field itself. 202 padding_length 203 Length of padding (bytes). 205 payload 206 The useful contents of the packet. If compression has been 207 negotiated, this field is compressed. Initially, compression MUST 208 be "none". 210 Padding 211 Arbitrary-length padding, such that the total length of 212 (packet_length || padding_length || payload || padding) is a 213 multiple of the cipher block size or 8, whichever is larger. 214 There MUST be at least four bytes of padding. The padding SHOULD 215 consist of random bytes. The maximum amount of padding is 255 216 bytes. 218 MAC 219 Message authentication code. If message authentication has been 220 negotiated, this field contains the MAC bytes. Initially, the MAC 221 algorithm MUST be "none". 223 Note that length of the concatenation of packet length, padding length, 224 payload, and padding MUST be a multiple of the cipher block size or 8, 225 whichever is larger. This constraint MUST be enforced even when using 226 stream ciphers. Note that the packet length field is also encrypted, 227 and processing it requires special care when sending or receiving 228 packets. 230 The minimum size of a packet is 16 (or the cipher block size, whichever 231 is larger) bytes (plus MAC); implementations SHOULD decrypt the length 232 after receiving the first 8 (or cipher block size, whichever is larger) 233 bytes of a packet. 235 4.1. Maximum Packet Length 237 All implementations MUST be able to process packets with uncompressed 238 payload length of 32768 bytes or less and total packet size of 35000 239 bytes or less (including length, padding length, payload, padding, and 240 MAC). Implementations SHOULD support longer packets, where they might 241 be needed e.g. if an implementation wants to send a very large number of 242 certificates. Such packets MAY be sent if the version string indicates 243 that the other party is able to process them. However, implementations 244 SHOULD check that the packet length is reasonable for the implementation 245 to avoid denial-of-service and/or buffer overflow attacks. 247 4.2. Compression 249 If compression has been negotiated, the payload field (and only it) will 250 be compressed using the negotiated algorithm. The length field and MAC 251 will be computed from the compressed payload. 253 Compression MAY be stateful, depending on the method. Compression MUST 254 be independent for each direction, and implementations MUST allow 255 independently choosing the algorithm for each direction. 257 The following compression methods are currently defined: 259 none REQUIRED no compression 260 zlib OPTIONAL GNU ZLIB (LZ77) compression 262 The "zlib" compression is described in [RFC-1950] and in [RFC-1951]. 263 The compression context is initialized after each key exchange, and is 264 passed from one packet to the next with only a partial flush being 265 performed at the end of each packet. A partial flush means that all 266 data will be output, but the next packet will continue using compression 267 tables from the end of the previous packet. 269 Additional methods may be defined as specified in [SSH-ARCH]. 271 4.3. Encryption 273 An encryption algorithm and a key will be negotiated during the key 274 exchange. When encryption is in effect, the packet length, padding 275 length, payload and padding fields of each packet MUST be encrypted with 276 the given algorithm. 278 The encrypted data in all packets sent in one direction SHOULD be 279 considered a single data stream. For example, initialization vectors 280 SHOULD be passed from the end of one packet to the beginning of the next 281 packet. All ciphers SHOULD use keys with an effective key length of 128 282 bits or more. 284 The ciphers in each direction MUST run independently of each other, and 285 implementations MUST allow independently choosing the algorithm for each 286 direction (if multiple algorithms are allowed by local policy). 288 The following ciphers are currently defined: 290 3des-cbc REQUIRED three-key 3DES in CBC mode 291 blowfish-cbc RECOMMENDED Blowfish in CBC mode 292 arcfour OPTIONAL the ARCFOUR stream cipher 293 idea-cbc OPTIONAL IDEA in CBC mode 294 cast128-cbc OPTIONAL CAST-128 in CBC mode 295 none OPTIONAL no encryption; NOT RECOMMENDED 297 The "3des-cbc" cipher is three-key triple-DES (encrypt-decrypt-encrypt), 298 where the first 8 bytes of the key are used for the first encryption, 299 the next 8 bytes for the decryption, and the following 8 bytes for the 300 final encryption. This requires 24 bytes of key data (of which 168 bits 301 are actually used). To implement CBC mode, outer chaining MUST be used 302 (i.e., there is only one initialization vector). This is a block cipher 303 with 8 byte blocks. This algorithm is defined in [Schneier]. 305 The "blowfish-cbc" cipher is Blowfish in CBC mode, with 128 bit keys 306 [Schneier]. This is a block cipher with 8 byte blocks. 308 The "arcfour" is the Arcfour stream cipher with 128 bit keys. The 309 Arcfour cipher is believed to be compatible with the RC4 cipher 310 [Schneier]. RC4 is a registered trademark of RSA Data Security Inc. 312 The "idea-cbc" cipher is the IDEA cipher in CBC mode [Schneier]. IDEA 313 is patented by Ascom AG. 315 The "cast128-cbc" cipher is the CAST-128 cipher in CBC mode [RFC-2144]. 317 The "none" algorithm specifies that no encryption is to be done. Note 318 that this method provides no confidentiality protection, and it is not 319 recommended. Some functionality (e.g. password authentication) may be 320 disabled for security reasons if this cipher is chosen. 322 Additional methods may be defined as specified in [SSH-ARCH]. 324 4.4. Data Integrity 326 Data integrity is protected by including with each packet a message 327 authentication code (MAC) that is computed from a shared secret, packet 328 sequence number, and the contents of the packet. 330 The message authentication algorithm and key are negotiated during key 331 exchange. Initially, no MAC will be in effect, and its length MUST be 332 zero. After key exchange, the selected MAC will be computed before 333 encryption from the concatenation of packet data: 335 mac = MAC(key, sequence_number || unencrypted_packet) 337 where unencrypted_packet is the entire packet without MAC (the length 338 fields, payload and padding), and sequence_number is an implicit packet 339 sequence number represented as uint32. The sequence number is initial- 340 ized to zero for the first packet, and is incremented after every packet 341 (regardless of whether encryption or MAC is in use). It is never reset, 342 even if keys/algorithms are renegotiated later. It wraps around to zero 343 after every 2^32 packets. The packet sequence number itself is not 344 included in the packet sent over the wire. 346 The MAC algorithms for each direction MUST run independently, and 347 implementations MUST allow choosing the algorithm independently for both 348 directions. 350 The MAC bytes resulting from the MAC algorithm MUST be transmitted 351 without encryption as the last part of the packet. The number of MAC 352 bytes depends on the algorithm chosen. 354 The following MAC algorithms are currently defined: 356 hmac-sha1 REQUIRED HMAC-SHA1 (length = 20) 357 hmac-sha-96 RECOMMENDED first 96 bits of HMAC-SHA1 (length = 12) 358 hmac-md5 OPTIONAL HMAC-MD5 (length = 16) 359 hmac-md5-96 OPTIONAL first 96 bits of HMAC-MD5 (length = 12) 360 none OPTIONAL no MAC; NOT RECOMMENDED 362 The "hmac-*" algorithms are described in [RFC-2104]. The "*-n" MACs use 363 only the first n bits of the resulting value. 365 The hash algorithms are described in [Schneier]. 367 The "none" method is NOT RECOMMENDED. An active attacker may be able to 368 modify transmitted data if this is used. 370 Additional methods may be defined as specified in [SSH-ARCH]. 372 4.5. Key Exchange Methods 374 The key exchange method specifies how one-time session keys are 375 generated for encryption and for authentication, and how the server 376 authentication is done. 378 Only one REQUIRED key exchange method has been defined: 380 diffie-hellman-group1-sha1 REQUIRED 382 This method is described later in this document. 384 Additional methods may be defined as specified in [SSH-ARCH]. 386 4.6. Public Key Algorithms 388 This protocol has been designed to be able to operate with almost any 389 public key format, encoding, and algorithm (signature and/or 390 encryption). 392 There are several aspects that define a public key type: 394 o Key format: how is the key encoded and how are certificates 395 represented. The key blobs in this protocol MAY contain certificates 396 in addition to keys. 398 o Signature and/or encryption algorithms. Some key types may not 399 support both signing and encryption. Key usage may also be 400 restricted by policy statements in e.g. certificates. In this case, 401 different key types SHOULD be defined for the different policy 402 alternatives. 404 o Encoding of signatures and/or encrypted data. This includes but is 405 not limited to padding, byte order, and data formats. 407 The following public key and/or certificate formats are currently 408 defined: 410 ssh-dss REQUIRED sign Simple DSS 411 x509v3 RECOMMENDED sign X.509 certificates 412 spki OPTIONAL sign SPKI certificates 413 pgp OPTIONAL sign OpenPGP certificates 415 Additional key types may be defined as specified in [SSH-ARCH]. 417 The key type MUST always be explicitly known (from algorithm negotiation 418 or some other source). It is not normally included in the key blob. 420 Certificates and public keys are encoded as: 422 uint32 the combined length of the format identifier and associated data 423 string certificate or public key format identifier 424 byte[n] key/certificate data 426 The certificate part may have be a zero length string, but a public key 427 is required. This is the public key that will be used for 428 authentication; the certificate sequence contained in the certificate 429 blob can be used to provide authorization. 431 The "ssh-dss" key format has the following specific encoding: 433 uint32 length 434 string "ssh-dss" 435 mpint p 436 mpint q 437 mpint g 438 mpint y 440 Here the "p", "q", "g", and "y" parameters form the signature key blob. 442 Signing and verifying using this key format are done according to the 443 Digital Signature Standard [FIPS-186] using the SHA-1 hash. A 444 description can also be found in [Schneier]. 446 The resulting signature is encoded as: 448 uint32 length 449 string "ssh-dss" 450 mpint r 451 mpint s 453 The "x509v3" method indicates that the certificates, the public key, and 454 the resulting signature are in X.509v3 compatible DER-encoded format. 455 The formats used in X.509v3 is described in [PKIX-Part1]. 457 The "spki" method indicates that the certificate blob contains a 458 sequence of SPKI certificates. The format of SPKI certificates is 459 described in [SPKI]. 461 The "pgp" method indicates the the certificates, the public key, and the 462 signature are in OpenPGP compatible binary format. [PGP] 464 5. Key Exchange 466 Key exchange begins by each side sending lists of supported algorithms. 467 Each side has a preferred algorithm in each category, and it is assumed 468 that most implementations at any given time will use the same preferred 469 algorithm. Each side MAY guess which algorithm the other side is using, 470 and MAY send an initial key exchange packet according to the algorithm 471 if appropriate for the preferred method. If all algorithms were guessed 472 right, the optimistically sent packet MUST be handled as the first key 473 exchange packet. However, if the guess was wrong, and a packet was 474 optimistically sent by one or both parties, such packets MUST be ignored 475 (even if the error in the guess would not affect the contents of the 476 initial packet(s)), and the appropriate side MUST send the correct 477 initial packet. 479 Server authentication in the key exchange MAY be implicit. After a key 480 exchange with implicit server authentication, the client MUST wait for 481 response to its service request message before sending any further data. 483 5.1. Algorithm Negotiation 485 Key exchange begins by each side sending the following packet: 487 byte SSH_MSG_KEXINIT 488 byte[16] cookie (random bytes) 489 string kex_algorithms 490 string server_host_key_algorithms 491 string encryption_algorithms_client_to_server 492 string encryption_algorithms_server_to_client 493 string mac_algorithms_client_to_server 494 string mac_algorithms_server_to_client 495 string compression_algorithms_client_to_server 496 string compression_algorithms_server_to_client 497 boolean first_kex_packet_follows 498 uint32 0 (reserved for future extension) 500 Each of the algorithm strings MUST be a comma-separated list of 501 algorithm names (see ``Algorithm Naming'' in [SSH-ARCH]). Each 502 supported (allowed) algorithm MUST be listed, in order of preference. 504 The first algorithm in each list MUST be the preferred (guessed) 505 algorithm. Each string MUST contain at least one algorithm name. 507 cookie 508 The cookie MUST be a random value generated by the sender. Its 509 purpose is to make it impossible for either side to fully 510 determine the keys and the session identifier. 512 kex_algorithms 513 Key exchange algorithms were defined above. The first algorithm 514 MUST be the preferred (and guessed) algorithm. If both sides make 515 the same guess, that algorithm MUST used. Otherwise, the 516 following algorithm MUST be used to choose a key exchange method: 517 iterate over client's kex algorithms, one at a time. Choose the 518 first algorithm that satisfies the following conditions: 520 o the server also supports the algorithm, 522 o if the algorithm requires an encryption-capable host key, there is 523 an encryption-capable algorithm on the server's 524 server_host_key_algorithms that is also supported by the client, 525 and 527 o if the algorithm requires a signature-capable host key, there is a 528 signature-capable algorithm on the server's 529 server_host_key_algorithms that is also supported by the client. 531 If no algorithm satisfying all these conditions can be found, 532 connection fails, and both sides MUST disconnect. 533 server_host_key_algorithms 534 List of the algorithms supported for the server host key. The 535 server lists the algorithms for which it has host keys; the client 536 lists the algorithms that it is willing to accept. (There MAY be 537 multiple host keys for a host, possibly with different 538 algorithms.) 540 Some host keys may not support both signatures and encryption 541 (this can be determined from the algorithm), and thus not all host 542 keys are valid for all key exchange methods. 544 Algorithm selection depends on whether the chosen key exchange 545 algorithm requires a signature- or encryption capable host key. 546 It MUST be possible to determine this from the public key 547 algorithm name. The first algorithm on the client's list that 548 satisfies the requirements and is also supported by the server 549 MUST be chosen. If there is no such algorithm, both sides MUST 550 disconnect. 552 encryption_algorithms 553 Lists the acceptable symmetric encryption algorithms in order of 554 preference. The chosen encryption algorithm to each direction 555 MUST be the first algorithm on the client's list that is also on 556 the server's list. If there is no such algorithm, both sides MUST 557 disconnect. 559 Note that "none" must be explicitly listed if it is to be 560 acceptable. The defined algorithm names are listed in Section 561 ``Encryption''. 563 mac_algorithms 564 Lists the acceptable MAC algorithms in order of preference. The 565 chosen MAC algorithm MUST be the first algorithm on the client's 566 list that is also on the server's list. If there is no such 567 algorithm, both sides MUST disconnect. 569 Note that "none" must be explicitly listed if it is to be 570 acceptable. The MAC algorithm names are listed in Section ``Data 571 Integrity''. 573 compression_algorithms 574 Lists the acceptable compression algorithms in order of 575 preference. The chosen compression algorithm MUST be the first 576 algorithm on the client's list that is also on the server's list. 577 If there is no such algorithm, both sides MUST disconnect. 579 Note that "none" must be explicitly listed if it is to be 580 acceptable. The compression algorithm names are listed in Section 581 ``Compression''. 583 first_kex_packet_follows 584 Indicates whether a guessed key exchange packet follows. If a 585 guessed packet will be sent, this MUST be true. If no guessed 586 packet will be sent, this MUST be false. 588 After receiving the SSH_MSG_KEXINIT packet from the other side, 589 each party will know whether their guess was right. If the other 590 party's guess was wrong, and this field was true, the next packet 591 MUST be silently ignored, and both sides MUST then act as 592 determined by the negotiated key exchange method. If the guess 593 was right, key exchange MUST continue using the guessed packet. 595 After the KEXINIT packet exchange, the key exchange algorithm is run. 596 It may involve several packet exchanges, as specified by the key 597 exchange method. 599 5.2. Output from Key Exchange 601 The key exchange produces two values: a shared secret K, and an exchange 602 hash H. Encryption and authentication keys are derived from these. The 603 exchange hash H from the first key exchange is additionally used as the 604 session identifier, which is a unique identifier for this connection. 605 It is used by authentication methods as a part of the data that is 606 signed as a proof of possession of a private key. Once computed, the 607 session identifier is not changed, even if keys are later re-exchanged. 609 Each key exchange method specifies a hash function that is used in the 610 key exchange. The same hash algorithm MUST be used in key derivation. 611 Here, we'll call it HASH. 613 Encryption keys MUST be computed as HASH of a known value and K as 614 follows: 616 o Initial IV client to server: HASH(K || "A" || session_id) ("A" means 617 the single character A, ascii 65). 619 o Initial IV server to client: HASH(K || "B" || session_id) 621 o Encryption key client to server: HASH(K || "C" || session_id) 623 o Encryption key server to client: HASH(K || "D" || session_id) 625 o Integrity key client to server: HASH(K || "E" || session_id) 627 o Integrity key server to client: HASH(K || "F" || session_id) 628 Key data MUST be taken from the beginning of the hash output. 128 bits 629 (16 bytes) SHOULD be used for algorithms with variable-length keys. For 630 other algorithms, as many bytes as are needed are taken from the 631 beginning of the hash value. If the key length in longer than the output 632 of the HASH, the key is extended by computing HASH of the concatenation 633 of K and the entire key so far, and appending the resulting bytes (as 634 many as HASH generates) to the key. This process is repeated until 635 enough key material is available; the key is taken from the beginning of 636 this value. In other words, 638 K1 = HASH(K || X || session_id) (X is e.g. "A") 639 K2 = HASH(K || K1) 640 K3 = HASH(K || K1 || K2) 641 ... 642 key = K1 || K2 || K3 || ... 644 5.3. Taking Keys into Use 646 Key exchange ends by each side sending an SSH_MSG_NEWKEYS message. This 647 message is sent with the old keys and algorithms. All messages sent 648 after this message MUST use the new keys and algorithms. 650 When this message is received, the new keys and algorithms MUST be taken 651 into use for receiving. 653 This message is the only valid message after key exchange, in addition 654 to SSH_MSG_DEBUG, SSH_MSG_DISCONNECT and SSH_MSG_IGNORE messages. The 655 purpose of this message is to ensure that a party is able to respond 656 with a disconnect message that the other party can understand if 657 something goes wrong with the key exchange. Implementations MUST NOT 658 accept any other messages after key exchange before receiving 659 SSH_MSG_NEWKEYS. 661 byte SSH_MSG_NEWKEYS 663 6. Diffie-Hellman Key Exchange 665 The Diffie-Hellman key exchange provides a shared secret that can not be 666 determined by either party alone. The key exchange is combined with a 667 signature with the host key to provide host authentication. 669 In the following description (C is the client, S is the server; p is a 670 large safe prime, g is a generator for a subgroup of GF(p), and q is the 671 order of the subgroup; V_S is S's version string; V_C is C's version 672 string; K_S is S's public host key; I_C is C's KEXINIT message and I_S 673 S's KEXINIT message which have been exchanged before this part begins): 675 1. C generates a random number x (1 < x < q) and computes e = g^x mod p. 676 C sends "e" to S. 678 2. S generates a random number y (0 < y < q) and computes f = g^y mod p. 679 S receives "e". It computes K = e^y mod p, H = hash(V_C || V_S || 680 I_C || I_S || K_S || e || f || K), and signature s on H with its 681 private host key. S sends "K_S || f || s" to C. The signing 682 operation may involve a second hashing operation. 684 3. C verifies that K_S really is the host key for S (e.g. using 685 certificates or a local database). C is also allowed to accept the 686 key without verification; however, doing so will render the protocol 687 insecure against active attacks (but may be desirable for practical 688 reasons in the short term in many environments). C then computes K = 689 f^x mod p, H = hash(V_C || V_S || I_C || I_S || K_S || e || f || K), 690 and verifies the signature s on H. 692 Either side MUST NOT send or accept e or f values that are not in the 693 range [1, p-1]. If this condition is violated, the key exchange 694 fails. 696 This is implemented with the following messages. The hash algorithm for 697 computing the exchange hash is defined by the method name, and is called 698 HASH. The public key algorithm for signing is negotiated with the 699 KEXINIT messages. 701 First, the client sends: 703 byte SSH_MSG_KEXDH_INIT 704 mpint e 706 The server responds with: 708 byte SSH_MSG_KEXDH_REPLY 709 string server public host key and certificates (K_S) 710 mpint f 711 string signature of H 713 The hash H is computed as the HASH hash of the concatenation of the 714 following: 716 string V_C, the client's version string (CR and NL excluded) 717 string V_S, the server's version string (CR and NL excluded) 718 string I_C, the payload of the client's SSH_MSG_KEXINIT 719 string I_S, the payload of the server's SSH_MSG_KEXINIT 720 string K_S, the host key 721 mpint e, exchange value sent by the client 722 mpint f, exchange value sent by the server 723 mpint K, the shared secret 725 This value is called the exchange hash, and it is used to authenticate 726 the key exchange. 728 The signature algorithm MUST be applied over H, not the original data. 729 Most signature algorithms include hashing and additional padding. For 730 example, a "ssh-dss" specifies SHA-1 hashing; in that case, the data is 731 first hashed with HASH to compute H, and H is then hashed with SHA-1 as 732 part of the signing operation. 734 6.1. diffie-hellman-group1-sha1 736 The "diffie-hellman-group1-sha1" method specifies Diffie-Hellman key 737 exchange with SHA-1 as HASH, and the following group: 739 The prime p is equal to 2^1024 - 2^960 - 1 + 2^64 * floor( 2^894 Pi + 740 129093 ). Its hexadecimal value is 742 FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 743 29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD 744 EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245 745 E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED 746 EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381 747 FFFFFFFF FFFFFFFF. 749 In decimal, this value is 751 179769313486231590770839156793787453197860296048756011706444 752 423684197180216158519368947833795864925541502180565485980503 753 646440548199239100050792877003355816639229553136239076508735 754 759914822574862575007425302077447712589550957937778424442426 755 617334727629299387668709205606050270810842907692932019128194 756 467627007. 758 The generator used with this prime is g = 2. The group order q is (p - 759 1) / 2. 761 This group was taken from the ISAKMP/Oakley specification, and was 762 originally generated by Richard Schroeppel at the University of Arizona. 763 Properties of this prime are described in [Orm96]. 765 7. Key Re-Exchange 767 Key re-exchange is started by sending a SSH_MSG_KEXINIT packet when not 768 already doing a key exchange (as described in Section ``Algorithm 769 Negotiation''). When this message is received, a party MUST respond 770 with its own SSH_MSG_KEXINIT message except when the received 771 SSH_MSG_KEXINIT already was a reply. Either party MAY initiate the re- 772 exchange, but roles MUST NOT be changed (i.e., the server remains the 773 server, and the client remains the client). 775 Key re-exchange is performed using whatever encryption was in effect 776 when the exchange was started. Encryption, compression, and MAC methods 777 are not changed before a new SSH_MSG_NEWKEYS is sent after the key 778 exchange (as in the initial key exchange). Re-exchange is processed 779 identically to the initial key exchange, except for the session 780 identifier that will remain unchanged. It is permissible to change some 781 or all of the algorithms during the re-exchange. Host keys can also 782 change. All keys and initialization vectors are recomputed after the 783 exchange. Compression and encryption contexts are reset. 785 It is recommended that the keys are changed after each gigabyte of 786 transmitted data or after each hour of connection time, whichever comes 787 sooner. However, since the re-exchange is a public key operation, it 788 requires a fair amount of processing power and should not be performed 789 too often. 791 More application data may be sent after the SSH_MSG_NEWKEYS packet has 792 been sent; key exchange does not affect the protocols that lie above the 793 SSH transport layer. 795 8. Service Request 797 After the key exchange, the client requests a service. The service is 798 identified by a name. The format of names and procedures for defining 799 new names are defined in [SSH-ARCH]. 801 Currently, the following names have been reserved: 803 ssh-userauth 804 ssh-connection 806 Similar local naming policy is applied to the service names that is 807 applied to the algorithm names; a local service should use the 808 servicename@domain syntax. 810 byte SSH_MSG_SERVICE_REQUEST 811 string service name 813 If the server rejects the service request, it SHOULD send an appropriate 814 SSH_MSG_DISCONNECT message and MUST disconnect. 816 When the service starts, it may have access to the session identifier 817 generated during the key exchange. 819 If the server supports the service (and permits the client to use it), 820 it MUST respond with 822 byte SSH_MSG_SERVICE_ACCEPT 823 string service name 825 Message numbers used by services should be in the area reserved for them 826 (see Section ``Summary of Message Numbers''). The transport level will 827 continue to process its own messages. 829 Note that after a key exchange with implicit server authentication, the 830 client MUST wait for response to its service request message before 831 sending any further data. 833 9. Additional Messages 835 Either party may send any of the following messages at any time. 837 9.1. Disconnection Message 839 byte SSH_MSG_DISCONNECT 840 uint32 reason code 841 string description [[RFC-2044]] 842 string language tag [[RFC-1766]] 844 This message causes immediate termination of the connection. All 845 implementations MUST be able to process this message; they SHOULD be 846 able to send this message. 848 The sender MUST NOT send or receive any data after this message, and the 849 recipient MUST NOT accept any data after receiving this message. The 850 description field gives a more specific explanation in a human-readable 851 form. The error code gives the reason in a more machine-readable format 852 (suitable for localization), and can have the following values: 854 #define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1 855 #define SSH_DISCONNECT_PROTOCOL_ERROR 2 856 #define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3 857 #define SSH_DISCONNECT_HOST_AUTHENTICATION_FAILED 4 858 #define SSH_DISCONNECT_MAC_ERROR 5 859 #define SSH_DISCONNECT_COMPRESSION_ERROR 6 860 #define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7 861 #define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8 862 #define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9 863 #define SSH_DISCONNECT_CONNECTION_LOST 10 864 #define SSH_DISCONNECT_BY_APPLICATION 11 866 If the description string is displayed, control character filtering 867 discussed in [SSH-ARCH] should be used to avoid attacks by sending 868 terminal control characters. 870 9.2. Ignored Data Message 872 byte SSH_MSG_IGNORE 873 string data 875 All implementations MUST understand (and ignore) this message at any 876 time (after receiving the protocol version). No implementation is 877 required to send them. This message can be used as an additional 878 protection measure against advanced traffic analysis techniques. 880 9.3. Debug Message 882 byte SSH_MSG_DEBUG 883 boolean always_display 884 string message [[RFC-2044]] 885 string language tag [[RFC-1766]] 887 All implementations MUST understand this message, but they are allowed 888 to ignore it. This message is used to pass information to the other 889 side that may help debugging. If always_display is true, the message 890 SHOULD be displayed. Otherwise, it SHOULD NOT be displayed unless 891 debugging information has been explicitly requested by the user. 893 The message doesn't need to contain a newline. It is, however, allowed 894 to consist of multiple lines separated by newlines. 896 If the message string is displayed, terminal control character filtering 897 discussed in [SSH-ARCH] should be used to avoid attacks by sending 898 terminal control characters. 900 9.4. Reserved Messages 902 An implementation MUST respond to all unrecognized messages with an 903 SSH_MSG_UNIMPLEMENTED message in the order in which they were received. 904 Such messages MUST be otherwise ignored. Later protocol versions may 905 define other meanings for these message types. 907 byte SSH_MSG_UNIMPLEMENTED 908 uint32 packet sequence number of rejected message 910 10. Summary of Message Numbers 912 The following message numbers have been defined in this protocol. 914 #define SSH_MSG_DISCONNECT 1 915 #define SSH_MSG_IGNORE 2 916 #define SSH_MSG_UNIMPLEMENTED 3 917 #define SSH_MSG_DEBUG 4 918 #define SSH_MSG_SERVICE_REQUEST 5 919 #define SSH_MSG_SERVICE_ACCEPT 6 921 #define SSH_MSG_KEXINIT 20 922 #define SSH_MSG_NEWKEYS 21 924 /* Numbers 30-49 used for kex packets. 925 Different kex methods may reuse message numbers in 926 this range. */ 927 #define SSH_MSG_KEXDH_INIT 30 928 #define SSH_MSG_KEXDH_REPLY 31 930 11. Security Considerations 932 This protocol provides a secure encrypted channel over an unsecure 933 network. It performs server host authentication, key exchange, 934 encryption, and integrity protection. It also derives a unique session 935 id that may be by higher-level protocols. 937 It is expected that this protocol will sometimes be used without 938 insisting on reliable association between the server host key and the 939 server host name. Such use is inherently insecure, but may be necessary 940 in non-security critical environments, and still provides protection 941 against passive attacks. However, implementors of protocols running on 942 top of this protocol should keep this possibility in mind. 944 This protocol is designed to be used over an reliable transport. If 945 transmission errors or message manipulation occur, the connection is 946 closed. The connection SHOULD be re-established if this occurs. Denial 947 of service attacks of this type ("wire cutter") are almost impossible to 948 avoid. 950 12. References 952 [FIPS-186] Federal Information Processing Standards Publication (FIPS 953 PUB) 186, Digital Signature Standard, 18 May 1994. 955 [Orm96] Orman, H., "The Oakley Key Determination Protocol", version 1, 956 TR97-92, Department of Computer Science Technical Report, University of 957 Arizona. 959 [RFC-1034] Mockapetris, P., "Domain Names - Concepts and Facilities", 960 November 1987. 962 [RFC-1766] Alvestrand, H., "Tags for the Identification of Languages", 963 March 1995. 965 [RFC-1950] Deutch, P. and Gailly, J-L., "ZLIB Compressed Data Format 966 Specification version 3.3", May 1996. 968 [RFC-1951] Deutch, P., "DEFLATE Compressed Data Format Specification 969 version 1.3", May 1996. 971 [RFC-2044] Yergeau, F., "UTF-8, a Transformation Format of Unicode and 972 ISO 10646", October 1996. 974 [RFC-2104] Krawczyk, H., Bellare, M., and Canetti, R., "HMAC: Keyed- 975 Hashing for Message Authentication", February 1997 977 [RFC-2119] Bradner, S., "Key words for use in RFCs to indicate 978 Requirement Levels", March 1997. 980 [RFC-2144] Adams, C., "The CAST-128 Encryption Algorithm", May 1997. 982 [Schneier] Schneier, B., "Applied Cryptography Second Edition: 983 protocols, algorithms, and source code in C", 2nd edition, John Wiley & 984 Sons, New York, NY, 1996. 986 [SSH-ARCH] Ylonen, T., Kivinen, T, and Saarinen, M., "SSH Protocol 987 Architecture", Internet Draft, draft-ietf-secsh-architecture-00.txt 989 #91;SSH-USERAUTH] Ylonen, T., Kivinen, T, and Saarinen, M., "SSH 990 Authentication Protocol", Internet Draft, draft-ietf-secsh- 991 userauth-02.txt 993 [SSH-CONNECT] Ylonen, T., Kivinen, T, and Saarinen, M., "SSH Connection 994 Protocol", Internet Draft, draft-ietf-secsh-connect-02.txt 996 [PGP] (XXX n.a.) 998 [PKIX-Part1] (XXX n.a.) 999 13. Authors' Addresses 1001 Tatu Ylonen 1002 SSH Communications Security Ltd. 1003 Tekniikantie 12 1004 FIN-02150 ESPOO 1005 Finland 1006 E-mail: ylo@ssh.fi 1008 Tero Kivinen 1009 SSH Communications Security Ltd. 1010 Tekniikantie 12 1011 FIN-02150 ESPOO 1012 Finland 1013 E-mail: kivinen@ssh.fi 1015 Markku-Juhani O. Saarinen 1016 SSH Communications Security Ltd. 1017 Tekniikantie 12 1018 FIN-02150 ESPOO 1019 Finland 1020 E-mail: mjos@ssh.fi