home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / drafts / draft_ietf_q_t / draft-ietf-secsh-transport-01.txt < prev    next >
Text File  |  1997-07-31  |  54KB  |  1,298 lines

  1.  
  2. Network Working Group                           Tatu Ylonen <ylo@ssh.fi>
  3. INTERNET-DRAFT                               SSH Communications Security
  4. draft-ietf-secsh-transport-01.txt                          July 30, 1997
  5. Expires in six months
  6.  
  7.  
  8.                       SSH Transport Layer Protocol
  9.  
  10. Status of This memo
  11.  
  12. This document is an Internet-Draft. Internet-Drafts are working
  13. documents of the Internet Engineering Task Force (IETF), its areas,
  14. and its working groups. Note that other groups may also distribute
  15. working documents as Internet-Drafts.
  16.  
  17. Internet-Drafts are draft documents valid for a maximum of six
  18. months and may be updated, replaced, or obsoleted by other documents
  19. at any time. It is inappropriate to use Internet-Drafts as reference
  20. material or to cite them other than as ``work in progress.''
  21.  
  22. To learn the current status of any Internet-Draft, please check
  23. the ``1id-abstracts.txt'' listing contained in the Internet-Drafts
  24. Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe),
  25. munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast),
  26. or ftp.isi.edu (US West Coast).
  27.  
  28. Abstract
  29.  
  30. This document describes the SSH transport layer protocol.  The protocol
  31. can be used as a basis for a number of secure network services.  It pro-
  32. vides strong encryption, server authentication, and integrity protec-
  33. tion.
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. Tatu Ylonen <ylo@ssh.fi>                                        [page 1]
  60.  
  61. INTERNET-DRAFT                                             July 30, 1997
  62.  
  63. Table of Contents
  64.  
  65. 1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . . . .  2
  66. 2.  Data Type Representations Used in the Protocol  . . . . . . . . .  3
  67.   2.1.  byte  . . . . . . . . . . . . . . . . . . . . . . . . . . . .  3
  68.   2.2.  boolean   . . . . . . . . . . . . . . . . . . . . . . . . . .  3
  69.   2.3.  uint32  . . . . . . . . . . . . . . . . . . . . . . . . . . .  3
  70.   2.4.  string  . . . . . . . . . . . . . . . . . . . . . . . . . . .  3
  71.   2.5.  mpint   . . . . . . . . . . . . . . . . . . . . . . . . . . .  3
  72. 3.  Algorithm Naming  . . . . . . . . . . . . . . . . . . . . . . . .  4
  73. 4.  Connection Setup  . . . . . . . . . . . . . . . . . . . . . . . .  4
  74.   4.1.  Use over TCP/IP   . . . . . . . . . . . . . . . . . . . . . .  4
  75.   4.2.  Protocol Version Exchange   . . . . . . . . . . . . . . . . .  4
  76.   4.3.  Compatibility with Old SSH Versions   . . . . . . . . . . . .  5
  77.     4.3.1.  Old Client, New Server  . . . . . . . . . . . . . . . . .  5
  78.     4.3.2.  New Client, Old Server  . . . . . . . . . . . . . . . . .  5
  79. 5.  Binary Packet Protocol  . . . . . . . . . . . . . . . . . . . . .  5
  80.   5.1.  Maximum Packet Length   . . . . . . . . . . . . . . . . . . .  6
  81.   5.2.  Compression   . . . . . . . . . . . . . . . . . . . . . . . .  6
  82.   5.3.  Encryption  . . . . . . . . . . . . . . . . . . . . . . . . .  7
  83.   5.4.  Data Integrity  . . . . . . . . . . . . . . . . . . . . . . .  8
  84. 6.  Key Exchange  . . . . . . . . . . . . . . . . . . . . . . . . . .  9
  85.   6.1.  Algorithm Negotiation   . . . . . . . . . . . . . . . . . . .  9
  86.   6.2.  Diffie-Hellman Key Exchange   . . . . . . . . . . . . . . . . 12
  87.   6.3.  Double-Encrypting Key Exchange  . . . . . . . . . . . . . . . 14
  88.     6.3.1.  Server Sends Host Key   . . . . . . . . . . . . . . . . . 14
  89.     6.3.2.  Deriving Exchange Hash and Session Identifier   . . . . . 15
  90.     6.3.3.  Client Sends Double-Encrypted Session Key   . . . . . . . 15
  91.     6.3.4.  Deriving Encryption and Integrity Keys  . . . . . . . . . 16
  92.   6.4.  Taking Keys into Use  . . . . . . . . . . . . . . . . . . . . 16
  93. 7.  Key Re-Exchange   . . . . . . . . . . . . . . . . . . . . . . . . 17
  94.   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
  95. 9.  Additional Messages   . . . . . . . . . . . . . . . . . . . . . . 18
  96.   9.1.  Disconnection Message   . . . . . . . . . . . . . . . . . . . 18
  97.   9.2.  Ignored Data Message  . . . . . . . . . . . . . . . . . . . . 19
  98.   9.3.  Debug Message   . . . . . . . . . . . . . . . . . . . . . . . 19
  99.   9.4.  Reserved Messages   . . . . . . . . . . . . . . . . . . . . . 19
  100. 10.  Summary of Message Numbers   . . . . . . . . . . . . . . . . . . 20
  101. 11.  Public Keys and Public Key Infrastructure  . . . . . . . . . . . 20
  102.   11.1.  x509   . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
  103.   11.2.  spki   . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
  104.   11.3.  ssh-rsa-pkcs1  . . . . . . . . . . . . . . . . . . . . . . . 21
  105. 12.  Security Considerations  . . . . . . . . . . . . . . . . . . . . 22
  106. 13.  Address of Author  . . . . . . . . . . . . . . . . . . . . . . . 22
  107.  
  108.  
  109.  
  110. 1.  Introduction
  111.  
  112. The SSH protocol is a secure transport layer protocol.  It provides
  113. strong encryption, cryptographic host autentication, and integrity
  114. protection.
  115.  
  116.  
  117.  
  118. Tatu Ylonen <ylo@ssh.fi>                                        [page 2]
  119.  
  120. INTERNET-DRAFT                                             July 30, 1997
  121.  
  122. Authentication in this protocol level is host-based; this protocol does
  123. not perform user authentication.  It is expected that a higher level
  124. protocol will be defined on top of this protocol that will perform user
  125. authentication for those services that need it.
  126.  
  127. The protocol has been designed to be simple, flexible, allow parameter
  128. negotiation, and minimize the number of round-trips.  Key exchange
  129. method, public key algorithm, symmetric encryption algorithm, message
  130. authentication algorithm, and hash algorithm are all negotiated.  It is
  131. expected that in most environments, only 1.5 round-trips will be needed
  132. for full key exchange, server authentication, service request, and
  133. acceptance notification of service request.  The worst case is 2.5
  134. round-trips.
  135.  
  136. 2.  Data Type Representations Used in the Protocol
  137.  
  138. 2.1.  byte
  139.  
  140. A byte represents an arbitrary 8-bit value.  Fixed length data is
  141. sometimes represented as an array of bytes, written byte[n], where n is
  142. the number of bytes in the array.
  143.  
  144. 2.2.  boolean
  145.  
  146. A boolean value is represented as a single byte.  The value 0 represents
  147. false, and the value 1 represents true.  All non-zero values are
  148. interpreted as true, but applications should not store values other than
  149. 0 and 1.
  150.  
  151. 2.3.  uint32
  152.  
  153. A 32-bit unsigned integer, represented as four bytes, MSB first.
  154.  
  155. 2.4.  string
  156.  
  157. A string here means an arbitrary length binary string.  Strings are
  158. allowed to contain arbitrary binary data, including null characters and
  159. 8-bit characters.
  160.  
  161. A string is represented as a uint32 containing its length, followed by
  162. zero or more characters that are the value of the string.  No
  163. terminating null character is normally included in the string.
  164.  
  165. 2.5.  mpint
  166.  
  167. Multiple precision integers are represented by the mpint type.
  168.  
  169.   uint32         number of bits
  170.   byte[n]        value, MSB first, n = floor((bits + 7) / 8)
  171.  
  172. The number of bits is exact (e.g., value 5 has 3 bits).  Any unused bits
  173. are in the first value byte (MSB) and must be zero.  The value zero has
  174. zero bits and zero data bytes.  (The exact format is important if as the
  175.  
  176.  
  177. Tatu Ylonen <ylo@ssh.fi>                                        [page 3]
  178.  
  179. INTERNET-DRAFT                                             July 30, 1997
  180.  
  181. data may sometimes be signed.)
  182.  
  183. 3.  Algorithm Naming
  184.  
  185. This protocol refers to particular hash, encryption, integrity,
  186. compression, and key exchange algorithms in various places.  There are
  187. some standard algorithms that all implementations are required to
  188. support.  There are also algorithms that are defined in the protocol
  189. specification but are optional.  Furthermore, it is expected that some
  190. organizations will want to use their own algorithms whenever possible.
  191. This leads to the problem of how algorithm identifiers are allocated.
  192.  
  193. In this protocols, all algorithm identifiers are represented as strings.
  194. Names are case-sensitive.  Algorithm lists are comma-separated lists of
  195. these identifiers, without spaces.  There are two formats for algorithm
  196. identifiers:
  197. o  Algorithms defined in the base protocol are simple strings, such as
  198.    "3des-cbc", "sha-1", "hmac-sha", or "zip" (the quotes are not part of
  199.    the name).  Defined algorithms may be mandatory or optional.  All
  200.    interoperable implementations should implement mandatory algorithms
  201.    and offer them as a possibility in key exchanges.  Optional
  202.    algorithms are not crucial for interoperability, but may provide
  203.    better performance or other advantages.  It is up to an
  204.    implementation to decide which of these are supported and which are
  205.    offered in key exchanges by default.
  206.  
  207. o  Anyone can define additional algorithms by using names in the format
  208.    name@domainname, e.g. "ourcipher-cbc@ssh.fi".  The format of the part
  209.    preceding the at sign is not specified; it may contain any non-
  210.    control characters except at signs and commas.  The part following
  211.    the at sign should be a valid internet domain name for the
  212.    organization defining the name.  It is up to the each organization
  213.    how they manage its locally defined names.
  214.  
  215. 4.  Connection Setup
  216.  
  217. SSH works over any 8-bit clean, binary-transparent transport.  The
  218. client initiates the connection, and sets up the binary-transparent
  219. transport.
  220.  
  221. 4.1.  Use over TCP/IP
  222.  
  223. When used over TCP/IP, the server normally listens for connections on
  224. port 22.  This port number has been registered with the IANA (Internet
  225. Assigned Numbers Authority), and has been officially assigned for SSH.
  226.  
  227. 4.2.  Protocol Version Exchange
  228.  
  229. When the connection has been established, both sides send an
  230. identification string of the form "SSH-protoversion-softwareversion
  231. comments", followed by carriage return and newline (ascii 13 and 10,
  232. respectively).  No null character is sent.  The maximum length of the
  233. string is 255 characters, including the cr and newline.  The protocol
  234.  
  235.  
  236. Tatu Ylonen <ylo@ssh.fi>                                        [page 4]
  237.  
  238. INTERNET-DRAFT                                             July 30, 1997
  239.  
  240. version described in this document is 2.0.  Version strings should only
  241. contain printable characters, not including space or '-'.  The string is
  242. used in debugging outputs to ease debugging; the protocol version is
  243. also used to trigger compatible extensions.  It is recommended that the
  244. strings be as descriptive as possible.  The comment string could include
  245. information such as the platform type which might be useful in solving
  246. user problems.
  247.  
  248. Key exchange will begin immediately after sending this identifier
  249. (normally without waiting for the identifier from the other side -- see
  250. the next section for compatibility issues).  All packets following the
  251. identification string will use the binary packet protocol, to be
  252. described below.
  253.  
  254. 4.3.  Compatibility with Old SSH Versions
  255.  
  256. During a transition period, it is important to be able to work
  257. compatibly with installed SSH clients and servers using an older version
  258. of the protocol.  Information in this section is only relevant for
  259. implementations supporting compatibility with old versions.
  260.  
  261. 4.3.1.  Old Client, New Server
  262.  
  263. Server implementations should support a configurable "compatibility"
  264. flag that enables compatibility with old versions.  When this flag is
  265. on, the server will not send any further data after its initialization
  266. string until it has received an identification string from the client.
  267. The server can then determine whether the client is using an old
  268. protocol, and can revert to the old protocol if desired.
  269.  
  270. When compatibility with old clients is not needed, the server should
  271. send its initial key exchange data immediately after the identification
  272. string.  This saves a round-trip.
  273.  
  274. 4.3.2.  New Client, Old Server
  275.  
  276. Since the new client will immediately send additional data after its
  277. identification string (before receiving server's identification), the
  278. old protocol has already been corrupted when the client learns that the
  279. server is old.  When this happens, the client should close the
  280. connection to the server, and reconnect using the old protocol this
  281. time.
  282.  
  283. 5.  Binary Packet Protocol
  284.  
  285. Each packet consists of the following fields:
  286.  
  287.     Length
  288.       The length of the packet (bytes).  This represents the number of
  289.       bytes that follow this value, not including the optional MAC.  The
  290.       length is represented as a uint32.
  291.  
  292.     Padding length
  293.  
  294.  
  295. Tatu Ylonen <ylo@ssh.fi>                                        [page 5]
  296.  
  297. INTERNET-DRAFT                                             July 30, 1997
  298.  
  299.       Length of padding (bytes).  This field is represented as a byte.
  300.  
  301.     Payload
  302.       The useful contents of the packet.  This field is optionally
  303.       compressed.
  304.  
  305.     Padding
  306.       Arbitrary-length padding, such that the total length of
  307.       length+paddinglength+payload+padding is a multiple of the cipher
  308.       block size or 8, whichever is larger.  It is recommended that at
  309.       least four bytes of random padding be always used.  The maximum
  310.       amount of padding is 255 bytes.
  311.  
  312.     MAC
  313.       Message authentication code.  This field is optional, and its
  314.       length depends on the algorithm in use.
  315.  
  316. Note that length of the concatenation of packet length, padding length,
  317. payload, and padding must be a multiple of the cipher block size or 8,
  318. whichever is larger.  This constraint is enforced even when using stream
  319. ciphers.  Note that the packet length field is also encrypted, and
  320. processing it requires special care when sending/receiving packets.  In
  321. particular, one has to be extra careful when computing the amount of
  322. padding, as changing the amount of padding can also change the size of
  323. the length fields.  The minimum size of a packet is 8 (or cipher block
  324. size, whichever is larger) characters (plus MAC); implementations should
  325. decrypt the length after receiving the first 8 (or cipher block size,
  326. whichever is larger) bytes of a packet.
  327.  
  328. When the protocol starts, no encryption is in effect, no compression is
  329. used, and no MAC is in use.  During key exchange, an encryption method,
  330. compression method, and a MAC method are selected.  Any further messages
  331. will use the negotiated algorithms.
  332.  
  333. 5.1.  Maximum Packet Length
  334.  
  335. All implementations are required to be able to process packets with
  336. uncompressed payload length of at least 32768 bytes with total packet
  337. size up to 35000 bytes (including length, padding length, payload,
  338. padding, and MAC).  The motivation for this limit is to keep the
  339. protocol easy to implement on 16-bit machines.  Implementations are,
  340. however, encouraged to support longer packets, as they might be needed
  341. e.g. if an implementation wants to send a very large number of
  342. certificates.
  343.  
  344. 5.2.  Compression
  345.  
  346. If compression has been negotiated, the payload field (and only it) will
  347. be compressed using the negotiated algorithm.  The length field will
  348. contain the compressed length (i.e., that transmitted on the wire).
  349.  
  350. Compressed packets must not exceed the total packet size limit; the
  351. compression algorithm must guarantee that it does not expand the packet
  352.  
  353.  
  354. Tatu Ylonen <ylo@ssh.fi>                                        [page 6]
  355.  
  356. INTERNET-DRAFT                                             July 30, 1997
  357.  
  358. too much.  The uncompressed payload size must not exceed the maximum
  359. payload size (the compressed payload, however, may be bigger than the
  360. maximum payload size, as long as the packet size limit is not exceeded).
  361.  
  362. The following compression methods are currently defined:
  363.  
  364.           none     mandatory       no compression
  365.           zlib     optional        GNU ZLIB compression at level 6
  366.  
  367. The "zlib" compression is described in RFC1950.
  368.  
  369. The compression context is initialized after key exchange, and is passed
  370. from one packet to the next with only a partial flush being performed at
  371. the end of each packet.  A partial flush means that all data will be
  372. output, but the next packet will continue using compression tables from
  373. the end of the previous packet.
  374.  
  375. Compression is independent in each direction, and the different
  376. compression methods may be used for each direction.
  377.  
  378. 5.3.  Encryption
  379.  
  380. An encryption algorithm and a key will be negotiated during the key
  381. exchange.  When encryption is in effect, the length, padding length,
  382. payload and padding fields of each packet will be encrypted with the
  383. given algorithm.
  384.  
  385. The encrypted data in all packets sent in one direction will be
  386. considered a single data stream.  For example, initialization vectors
  387. will be passed from the end of one packet to the beginning of the next
  388. packet.
  389.  
  390. The ciphers in each direction will run independently of each other.
  391. They will typically use a different key, and different ciphers can be
  392. used in each direction.
  393.  
  394. The following ciphers are currently defined:
  395.  
  396. none             optional          no encryption
  397. 3des-cbc         mandatory         three-key 3DES in CBC mode
  398. idea-cbc         optional          IDEA in CBC mode
  399. arcfour          optional          ARCFOUR stream cipher
  400. blowfish-cbc     optional          Blowfish in CBC mode
  401.  
  402. The 3des-cbc encryption is three-key triple-DES (encrypt-decrypt-
  403. encrypt), where the first 8 bytes of the key are used for the first
  404. encryption, the next 8 bytes for the decryption, and the following 8
  405. bytes for the final encryption.  This requires 24 bytes of key data (of
  406. which the parity bits are not actually used).  To implement CBC mode,
  407. there is only one initialization vector.
  408.  
  409. For ciphers with variable-length keys, 128 bit keys are used.
  410.  
  411.  
  412.  
  413. Tatu Ylonen <ylo@ssh.fi>                                        [page 7]
  414.  
  415. INTERNET-DRAFT                                             July 30, 1997
  416.  
  417. The ARCFOUR cipher is compatible with the RC4 cipher; RC4 is a trademark
  418. of RSA Data Security, Inc.
  419.  
  420. Descriptions of all of these ciphers can be found e.g. from Bruce
  421. Schneier: Applied Cryptography, 2nd ed., John Wiley and Sons, 1996.
  422.  
  423. 5.4.  Data Integrity
  424.  
  425. Data integrity is protected by including with each packet a message
  426. authentication code (MAC) that is computed from a shared secret, packet
  427. sequence number, and the contents of the packet.
  428.  
  429. The message authentication algorithm and key are negotiated during key
  430. exchange.  Initially, no MAC will be in effect, and its length will be
  431. zero.  After key exchange, the selected MAC will be computed before
  432. encryption from the concatenation of packet data (lengths, payload, and
  433. padding) and a packet sequence number (stored as a 32-bit integer, MSB
  434. first).  The integrity key is also used in the computation of the MAC,
  435. but the way it is used depends on the MAC algorithm in use.  Note that
  436. the MAC algorithm may be different for each direction.
  437.  
  438. The packet sequence number is only used for integrity checking.  It is
  439. never explicitly transmitted, but it is included in MAC computation to
  440. ensure that no packets are lost or received out of sequence.  The
  441. sequence number of the first packet sent is zero; from there on the
  442. sequence number is incremented by one for every packet sent (separately
  443. for each direction).  The packet number is 32 bits and wraps around if
  444. 32 bits is not enough for representing it.  The sequence number is
  445. incremented also for packets that are not encrypted or MACed, and is not
  446. reset even if keys are renegotiated later.
  447.  
  448. The check bytes resulting from the MAC algorithm are transmitted without
  449. encryption as the last part of the packet.  The number of check bytes
  450. depends on the algorithm chosen.
  451.  
  452. The following MAC algorithms are currently defined:
  453.  
  454.           none        optional         no MAC
  455.           hmac-md5    optional         HMAC-MD5 (length = 16)
  456.           hmac-sha    optional         HMAC-SHA (length = 20)
  457.           md5-8       optional         first 8 bytes MD5 key+data+key
  458.           sha-8       optional         first 8 bytes SHA-1 key+data+key
  459.           sha         mandatory        SHA of key+data+key (20 bytes)
  460.  
  461. The HMAC methods are described in RFC 2104.
  462.  
  463. The "md5-8" method returns the first 8 bytes of MD5 of the concatenation
  464. of the key, authenticated data, and the key again.  The "sha-8" method
  465. is the same but using the SHA hash.
  466.  
  467. Even though only the "sha" method is mandatory, it is recommended that
  468. implementations support and prefer the other methods.  (This method
  469. exists only as a fallback should unexpected patent problems surface.)
  470.  
  471.  
  472. Tatu Ylonen <ylo@ssh.fi>                                        [page 8]
  473.  
  474. INTERNET-DRAFT                                             July 30, 1997
  475.  
  476. 6.  Key Exchange
  477.  
  478. Key exchange begins by each side sending lists of supported algorithms.
  479. Each side has a preferred algorithm, and it is assumed that most
  480. implementations at any given time will use the same preferred algorithm.
  481. Each side will make the guess that the other side is using the same
  482. algorithm, and may send an initial key exchange packet according to the
  483. algorithm if appropriate for the preferred method.  If the guess is
  484. wrong, they'll ignore the guessed packet, select a common algorithm, and
  485. send the initial key exchange packet again, this time for the same
  486. algorithm.
  487.  
  488. Currently, the following key exchange methods have been defined:
  489.  
  490.           double-encrypting-sha        mandatory
  491.  
  492. The implementation of these methods is described later in this section.
  493.  
  494. One should note that server authentication in the double-encrypting key
  495. exchange is implicit, and the client doesn't really know the identity of
  496. the server until it receives a message from the server using the correct
  497. MAC and encryption.  This means that an attacker could fool the client
  498. into using no encryption (if the client is willing to accept no
  499. encryption), and the client might in some cases send sensitive data,
  500. such as a password, before it notices that the server isn't responding
  501. properly.  For this reason, it is recommended that clients should not
  502. accept "none" encryption unless explicitly requested by the user.
  503. Alternatively, they should wait for the server's response to the service
  504. request before sending anything else.
  505.  
  506. 6.1.  Algorithm Negotiation
  507.  
  508. Each side sends the following packet (this is the part that goes inside
  509. the payload):
  510.  
  511.             byte      SSH_MSG_KEXINIT
  512.             byte[16]  cookie (random bytes)
  513.             string    kex_algorithms
  514.             string    server_host_key_algorithms
  515.             string    encryption_algorithms_client_to_server
  516.             string    encryption_algorithms_server_to_client
  517.             string    mac_algorithms_client_to_server
  518.             string    mac_algorithms_server_to_client
  519.             string    compression_algorithms_client_to_server
  520.             string    compression_algorithms_server_to_client
  521.             string    hash_algorithms
  522.             boolean   first_kex_packet_follows
  523.             byte[4]   0 (reserved for future extension)
  524.  
  525. Each of the algorithms strings are comma-separated lists of algorithm
  526. names.  Each supported (allowed) algorithm should be listed, in order of
  527. preference.  The preferred (guessed) algorithm should be listed first.
  528. Each string must contain at least one algorithm name.  The value "none"
  529.  
  530.  
  531. Tatu Ylonen <ylo@ssh.fi>                                        [page 9]
  532.  
  533. INTERNET-DRAFT                                             July 30, 1997
  534.  
  535. is not automatically allowed; if a party permits connections with "none"
  536. as one of the algorithms, it should list that as an algorithm.
  537.  
  538.     cookie
  539.       The cookies are random values generated by each side.  Their
  540.       purpose is to make it impossible for either side to fully
  541.       determine the keys (which might open possibilities for passing
  542.       certain signatures/authentications to third parties).
  543.  
  544.     kex_algorithms
  545.       Key exchange algorithms were defined above.  The first algorithm
  546.       is the preferred (and guessed) algorithm.  If both sides make the
  547.       same guess, that algorithm is used.  Otherwise, the following
  548.       algorithm is used to choose a key exchange method: iterate over
  549.       client's kex algorithms, one at a time.  Choose the first
  550.       algorithm that satisfies the following conditions: 1) the server
  551.       also supports the algorithm 2) if the algorithm requires an
  552.       encryption-capable host key, there is an encryption-capable
  553.       algorithm on the server's  server_host_key_algorithms  that is
  554.       also supported by the client 3) if the algorithm requires a
  555.       signature-capable host key, there is a signature-capable algorithm
  556.       on the server's  server_host_key_algorithms  that is also
  557.       supported by the client.  If no algorithm satisfying all these
  558.       conditions can be found, connection fails.
  559.  
  560.       The kex algorithm names were listed above.
  561.  
  562.     server_host_key_algorithms
  563.       Lists the algorithms supported for the server host key.  The
  564.       server lists the algorithms for which it has host keys; the client
  565.       lists the algorithms that it is willing to accept.  (There can be
  566.       multiple host keys for a host, possibly with different
  567.       algorithms.)
  568.  
  569.       Some host keys may not support both signatures and encryption
  570.       (this can be determined from the algorithm), and thus not all host
  571.       keys are valid for all key exchange methods.
  572.  
  573.       Algorithm selection depends on whether the chosen kex algorithm
  574.       requires a signature- or encryption capable host key.  The first
  575.       algorithm on the client's list that satisfies the requirements and
  576.       is also supported by the server is chosen.
  577.  
  578.       Section ``Public Key Formats'' lists the available algorithm
  579.       names.
  580.  
  581.     encryption_algorithms
  582.       Lists the acceptable symmetric encryption algorithms in order of
  583.       preference.  The chosen encryption algorithm will be the first
  584.       algorithm on the client's list that is also on the server's list.
  585.       If there is no such algorithm, connection fails.
  586.  
  587.       Note that "none" must be explicitly listed if it is to be
  588.  
  589.  
  590. Tatu Ylonen <ylo@ssh.fi>                                       [page 10]
  591.  
  592. INTERNET-DRAFT                                             July 30, 1997
  593.  
  594.       acceptable.  The defined algorithm names are listed in Section
  595.       ``Encryption''.
  596.  
  597.       The algorithm to use is negotiated separately for each direction,
  598.       and different algorithms may be chosen.
  599.  
  600.     mac_algorithms
  601.       Lists the acceptable MAC algorithms in order of preference.  The
  602.       chosen MAC algorithm will be the first algorithm on the client's
  603.       list that is also on the server's list.  If there is no such
  604.       algorithm, connection fails.
  605.  
  606.       Note that "none" must be explicitly listed if it is to be
  607.       acceptable.  The MAC algorithm names are listed in Section ``Data
  608.       Integrity''.
  609.  
  610.       The algorithm to use is negotiated separately for each direction,
  611.       and different algorithms may be chosen.
  612.  
  613.     compression_algorithms
  614.       Lists the acceptable compression algorithms in order of
  615.       preference.  The chosen compression algorithm will be the first
  616.       algorithm on the client's list that is also on the server's list.
  617.       If there is no such algorithm, connection fails.
  618.  
  619.       Note that "none" must be explicitly listed if it is to be
  620.       acceptable.  The compression algorithm names are listed in Section
  621.       ``Compression''.
  622.  
  623.       The algorithm to use is negotiated separately for each direction,
  624.       and different algorithms may be chosen.
  625.  
  626.     hash_algorithms
  627.       Lists the acceptable hash algorithms in order of preference.  The
  628.       chosen hash algorithm will be the first algorithm on the client's
  629.       list that is also on the server's list.  If there is no such
  630.       algorithm, connection fails.
  631.  
  632.       Implementations should only permit algorithms that they consider
  633.       to be fairly secure, as the hash function will be used e.g. for
  634.       deriving various keys from the shared secret.  All hash algorithms
  635.       must produce at least 16 bytes of output.
  636.  
  637.       Currently, the following hash functions are defined.
  638.  
  639.              md5          optional      MD5 algorithm (16 byte output)
  640.              sha          mandatory     SHA-1 algorithm (20 byte output)
  641.  
  642.     first_kex_packet_follows
  643.       Each side makes a guess of the negotiated key exchange method.
  644.       This is based on the assumption that at any particular time there
  645.       will be a single key exchange method and algorithm combination
  646.       that dominates the installed base.  Making a guess about the
  647.  
  648.  
  649. Tatu Ylonen <ylo@ssh.fi>                                       [page 11]
  650.  
  651. INTERNET-DRAFT                                             July 30, 1997
  652.  
  653.       algorithm will save a round-trip in the typical case, and will
  654.       incur little extra cost in the other cases.
  655.  
  656.       Each side will determine if they are supposed to send an initial
  657.       packet in their guessed key exchange method.  If they are, they
  658.       will set this field to true and follow this packet by the first
  659.       key exchange packet.
  660.  
  661.       The guessed method is the one listed first on the kex_algorithms,
  662.       server_host_key_algorithms, and hash_algorithms lists.  If the
  663.       negotiated values for any of these algorithms differs from the
  664.       first value on either side, the guess is taken to be wrong, and
  665.       the packet sent based on the guess is ignored.  Whether the
  666.       packets based on the guess are actually wrong is not a factor in
  667.       this decision (the information may not be available to make this
  668.       decision).
  669.  
  670.       After receiving the SSH_MSG_KEXINIT packet from the other side,
  671.       each party will know whether their guess was right.  If the guess
  672.       was wrong, and this field is true, the next packet will be
  673.       silently ignored, and each side will then act as determined by the
  674.       negotiated key exchange method.  If the guess was right, key
  675.       exchange will immediately continue.
  676.  
  677. 6.2.  Diffie-Hellman Key Exchange
  678.  
  679. The Diffie-Hellman key exchange is based on performing a diffie-hellman
  680. exchange followed by the server sending a hash of the exchange to the
  681. client.  It works as follows (A is client, B is server; p is a prime, g
  682. is a generator for the prime, and q is the order of the generator; K_B
  683. is B's public host key; I_A is A's KEXINIT message and I_B B's KEXINIT
  684. message which have been exchanged before this part begins):
  685.  
  686. 1. A generates a random number a (0 < a < q) and computes e = g^a mod p.
  687.    A sends "e" to B.
  688.  
  689. 2. B generates a random number b (0 < b < q) and computes f = g^b mod p.
  690.    B receives "e".  It K = e^b mod p, H = hash(I_A || I_B || K_B || K),
  691.    and computes signature s with its private host key on H.  B sends
  692.    "K_B || f || s" to A.
  693.  
  694. 3. A verifies that K_B really is the host key for B (e.g. using
  695.    certificates or a local database).  A is also allowed to accept the
  696.    key without verification; however, doing so will render the protocol
  697.    insecure against active attacks (but may be desirable for practical
  698.    reasons in the short term in many environments).  A then computes K =
  699.    f^a mod p, H = hash(I_A || I_B || K_B || K), and verifies the
  700.    signature s on H.
  701.  
  702. This is implemented with the following messages.  The hash algorithm is
  703. fixed to be SHA-1.  The public key algorithm for signing is negotiated
  704. with the KEXINIT messages.
  705.  
  706.  
  707.  
  708. Tatu Ylonen <ylo@ssh.fi>                                       [page 12]
  709.  
  710. INTERNET-DRAFT                                             July 30, 1997
  711.  
  712. First, the client sends:
  713.  
  714.             byte      SSH_MSG_KEXDH_INIT
  715.             mpint     e
  716.  
  717. The server responds with:
  718.  
  719.             byte      SSH_MSG_KEXDH_REPLY
  720.             string    server public host key and certificates (K_B)
  721.             mpint     f
  722.             string    signature
  723.  
  724. The hash H is computed as the SHA-1 hash of the concatenation of the
  725. following (in this order):
  726. o  the length of the payload of the client's SSH_MSG_KEXINIT message as
  727.    4 bytes, MSB first,
  728.  
  729. o  the payload of the client's SSH_MSG_KEXINIT message,
  730.  
  731. o  the length of the payload of the server's SSH_MSG_KEXINIT message as
  732.    4 bytes, MSB first,
  733.  
  734. o  the payload of the server's SSH_MSG_KEXINIT message,
  735.  
  736. o  K_B, represented as a string.
  737.  
  738. o  K, represented as an mpint.
  739.  
  740. This value is called the exchange hash, and it is used to authenticate
  741. the key exchange.
  742.  
  743. The values of p and g are fixed.  The following values are used: XXX To
  744. be defined!  (Take the 1024 bit field based on decimals of PI from one
  745. of the other existing drafts.)
  746.  
  747. Encryption keys are computed as HASH of a known value and $K$ as
  748. follows:
  749.  
  750. o  Initial IV client to server: HASH(K || "A" || K) ("A" means the
  751.    single character A).
  752.  
  753. o  Initial IV server to client: HASH(K || "B" || K)
  754.  
  755. o  Encryption key client to server: HASH(K || "C" || K)
  756.  
  757. o  Encryption key server to client: HASH(K || "D" || K)
  758.  
  759. o  Integrity key client to server: HASH(K || "E" || K)
  760.  
  761. o  Integrity key server to client: HASH(K || "F" || K)
  762.  
  763. Key data is taken from the beginning of the hash output.  128 bits (16
  764. bytes) will be used for algorithms with variable-length keys.  For other
  765.  
  766.  
  767. Tatu Ylonen <ylo@ssh.fi>                                       [page 13]
  768.  
  769. INTERNET-DRAFT                                             July 30, 1997
  770.  
  771. algorithms, as many bytes as are needed are taken from the beginning of
  772. the hash value.  If a longer key is needed for some algorithm than is
  773. the output of the hash, the key is extended by computing HASH of the
  774. concatenation of K and the entire key so far, and appending the
  775. resulting bytes (as many as HASH outputs) to the key.  This process is
  776. repeated until enough key material is available; the key is taken from
  777. the beginning of this value.  In other words,
  778.  
  779.   K1 = HASH(K || X || K)   (X is e.g. "A")
  780.   K2 = HASH(K || K1)
  781.   K3 = HASH(K || K1 || K2)
  782.   ...
  783.   key = K1 || K2 || K3 || ...
  784.  
  785. 6.3.  Double-Encrypting Key Exchange
  786.  
  787. The double-encrypting key exchange requires that the server host key
  788. supports encryption.  The idea is that the server sends its public host
  789. key and a periodically changing key (called the server key).  The client
  790. then verifies that it is the correct key for the server, generates a
  791. session key, encrypts the session key using both a time-variant server
  792. key and the server host key, and sends the encrypted session key to the
  793. server.
  794.  
  795. The server key and host keys must both support encryption, and their
  796. sizes must be such that the server key can encrypt at least 48 bytes,
  797. and the server host key can encrypt the result of the first encryption.
  798. Note that padding is normally added at each encryption, depending on the
  799. public key method, so the actual size difference of the keys is bigger.
  800. Both keys must use the same public key algorithm.
  801.  
  802. 6.3.1.  Server Sends Host Key
  803.  
  804. First, the server sends its public host and server keys in the following
  805. packet:
  806.  
  807.             byte      SSH_MSG_KEXDE_HOSTKEY
  808.             string    public host key
  809.             string    public server key
  810.  
  811. The host key and server key are stored in binary representation as
  812. described in Section ``Public Key Formats''.  Both keys are of the type
  813. negotiated for the server host key.
  814.  
  815. After receiving the public keys, the client validates that the host key
  816. really belongs to the intended server.  How this verification happens is
  817. not specified in this protocol.  Currently it may be checked against a
  818. database of known name-key mappings; in future it will be validated
  819. using an Internet public key infrastructure.  The key may contain
  820. certificates to facilitate this.
  821.  
  822. If the client is not willing to trust the server host key, it should
  823. send an SSH_MSG_DISCONNECT packet and close the connection.
  824.  
  825.  
  826. Tatu Ylonen <ylo@ssh.fi>                                       [page 14]
  827.  
  828. INTERNET-DRAFT                                             July 30, 1997
  829.  
  830. The client then generates a 256 bit random session key (shared secret).
  831.  
  832. 6.3.2.  Deriving Exchange Hash and Session Identifier
  833.  
  834. To authenticate that no-one has been manipulating the key exchange with
  835. the server, the client computes an SHA-1 hash of the concatenation of
  836. the following (in this order):
  837.  
  838. 1. the length of the payload of the client's SSH_MSG_KEXINIT message as
  839.    4 bytes, MSB first,
  840.  
  841. 2. the payload of the client's SSH_MSG_KEXINIT message,
  842.  
  843. 3. the length of the payload of the server's SSH_MSG_KEXINIT message as
  844.    4 bytes, MSB first,
  845.  
  846. 4. the payload of the server's SSH_MSG_KEXINIT message,
  847.  
  848. 5. the length of the payload of the server's SSH_MSG_KEXDE_HOSTKEY
  849.    message as 4 bytes, MSB first,
  850.  
  851. 6. the payload of the server's SSH_MSG_KEXDE_HOSTKEY message, and
  852.  
  853. 7. the 32 bytes of the session key.
  854.  
  855.    This value is called the exchange hash, and it is used to
  856.    authenticate the key exchange.
  857.  
  858. Note that the use of SHA-1 was hard-coded here.  This is used to
  859. authenticate the key exchange, and using HASH here would lead to all
  860. sorts of potential problems in verifying the security of the protocol.
  861. Using a fixed hash short-circuits verification to the properties of
  862. SHA-1.  Should the need ever arise, the only way to switch to another
  863. algorithm here is to define a new key exchange algorithm (which, in
  864. fact, is not very difficult).
  865.  
  866. The exchange hash from the first key exchange in a connection is called
  867. the session identifier.  It is used in host authentication and other
  868. authentication methods as data that is signed to prove possession of a
  869. private key.
  870.  
  871. Once computed, the session identifier is not changed or recomputed even
  872. if keys are later re-exchanged.  The exchange hash, on the other hand,
  873. is computed separately for each key exchange.
  874.  
  875. 6.3.3.  Client Sends Double-Encrypted Session Key
  876.  
  877. The client forms a message to send to the server by concatenating the
  878. following (in this order): six zero bytes (reserved for future
  879. extension), first 10 bytes of the exchange hash, and the 32 bytes of the
  880. shared secret.  This results in a total of 48 bytes of data to be passed
  881. to the server.  Note that the negotiated algorithms are not explicitly
  882. passed, as the algorithms given in Section ``Algorithm Negotiation''
  883.  
  884.  
  885. Tatu Ylonen <ylo@ssh.fi>                                       [page 15]
  886.  
  887. INTERNET-DRAFT                                             July 30, 1997
  888.  
  889. fully determine the algorithms.
  890.  
  891. The resulting data is encrypted first with the time-variant server key,
  892. and the result then with the server host key.  The resulting double-
  893. encrypted value is then sent to the server.  Note that public-key
  894. encryption probably involves padding, depending on the algorithm.
  895.  
  896.             byte      SSH_MSG_KEXDE_SESSIONKEY
  897.             string    double-encrypted session key
  898.  
  899. Upon receiving this message, the server uses its private host and server
  900. keys to decrypt the session key.  It computes a corresponding SHA hash,
  901. and compares the hash values.  If the hash does not match, the server
  902. disconnects with the appropriate message.  If the hash matches, the
  903. server responds with an SSH_MSG_NEWKEYS message and takes the keys into
  904. use.
  905.  
  906. 6.3.4.  Deriving Encryption and Integrity Keys
  907.  
  908. As a result of the key exchange, the parties have a 256-bit shared
  909. secret.  Various keys are computed from this secret and the exchange
  910. hash.  The session identifier is used to make it impossible for either
  911. party to alone determine the keys.
  912.  
  913. Each key is computed as HASH of the concatenation of the session
  914. identifier and 16 bytes of secret data.  The secret data is different
  915. for each key, and is taken from the 32-byte shared secret as follows:
  916.  
  917. o  Initial IV client to server: bytes 0-15
  918.  
  919. o  Initial IV server to client: bytes 1-16
  920.  
  921. o  Encryption key client to server: bytes 5-20
  922.  
  923. o  Encryption key server to client: bytes 8-23
  924.  
  925. o  Integrity key client to server: bytes 13-28
  926.  
  927. o  Integrity key server to client: bytes 16-31
  928.  
  929. Key data is taken from the beginning of the hash output.  128 bits (16
  930. bytes) will be used for algorithms with variable-length keys.  For other
  931. algorithms, as many bytes as needed are taken from the beginning of the
  932. hash value.  If a longer key is needed for some algorithm than is the
  933. output of the hash, the key is extended by computing HASH of the entire
  934. key so far, and appending the resulting bytes (as many as HASH outputs)
  935. to the key.  This process is repeated until enough key material is
  936. available; the key is taken from the beginning of this value.  (Note
  937. that extending the key does not increase its strength or entropy;
  938. however, 128 bits already provides enough entropy.)
  939.  
  940. 6.4.  Taking Keys into Use
  941.  
  942.  
  943.  
  944. Tatu Ylonen <ylo@ssh.fi>                                       [page 16]
  945.  
  946. INTERNET-DRAFT                                             July 30, 1997
  947.  
  948. Key exchange ends by each side sending an SSH_MSG_NEWKEYS message.  This
  949. message is sent with the old keys and algorithms.  All messages sent
  950. after this message use the new keys and algorithms.
  951. When this message is received, the new keys and algorithms are taken
  952. into use for receiving.
  953.  
  954. This message is the only valid message after key exchange, in addition
  955. to SSH_MSG_DISCONNECT and SSH_MSG_IGNORE messages.  The purpose of this
  956. message is to ensure that a party is able to respond with a disconnect
  957. message that the other party can understand if something goes wrong with
  958. the key exchange.
  959.  
  960.             byte      SSH_MSG_NEWKEYS
  961.  
  962. 7.  Key Re-Exchange
  963.  
  964. Either side may request re-exchange of keys at any time after the
  965. service request has been accepted (and outside other key exchanges).
  966. The re-exchange is not visible to the service.
  967.  
  968. Key re-exchange is started by sending a SSH_MSG_KEXINIT packet
  969. (described in Section ``Algorithm Negotiation'').  When this message is
  970. received, a party must respond with its own SSH_MSG_KEXINIT message.
  971. Either party may initiate the re-exchange, but roles are not changed
  972. (i.e., the server remains the server, and the client remains the
  973. client).
  974.  
  975. Key re-exchange is performed under whatever encryption was in effect
  976. when the exchange was started.  Encryption, compression, and MAC methods
  977. are changed when SSH_MSG_NEWKEYS is sent after the key exchange (as in
  978. the initial key exchange).  Re-exchange is processed identically to the
  979. initial key exchange.  It is permissible to change any or all of the
  980. algorithms during the re-exchange.  Host keys can also change.  All keys
  981. and initialization vectors are recomputed after the exchange.
  982. Compression and encryption contexts are reset.  The packet sequence
  983. number is not reset.  The session identifier is not changed.
  984.  
  985. It is recommended that keys be changed after each gigabyte of
  986. transmitted data or after each hour of connection time, whichever comes
  987. sooner.
  988.  
  989. It is also possible to use the key re-exchange mechanism to switch to
  990. faster algorithms after authentication, or to avoid double processing
  991. for pre-encrypted or pre-authenticated data.  However, since the re-
  992. exchange is a public key operation, it requires a fair amount of
  993. processing power and should not be performed too often.
  994.  
  995. More application data may be sent after the SSH_MSG_NEWKEYS packet has
  996. been sent.
  997.  
  998.  
  999. After the various authentications, the client requests a service.  The
  1000. service is identified by a name.  Service names can contain any non-
  1001.  
  1002.  
  1003. Tatu Ylonen <ylo@ssh.fi>                                       [page 17]
  1004.  
  1005. INTERNET-DRAFT                                             July 30, 1997
  1006.  
  1007. control characters.  The name must not be longer than 64 characters.
  1008. Service names are case-sensitive.
  1009.  
  1010.             byte      SSH_MSG_SERVICE_REQUEST
  1011.             string    service name
  1012.  
  1013. Most server implementations will have a table of services that are
  1014. supported, specifying what to do for each service.
  1015.  
  1016. If the server rejects the service request, it should send a
  1017. SSH_MSG_DISCONNECT message.
  1018.  
  1019. When the service starts, it will have access to the session identifier
  1020. generated during key exchange.
  1021.  
  1022. If the server supports the service (and permits the client to use it),
  1023. it responds with
  1024.  
  1025.             byte      SSH_MSG_SERVICE_ACCEPT
  1026.  
  1027. The client is permitted to send further packets without waiting for the
  1028. this message; those packets will go to the selected service if the
  1029. server accepts the service request.  Message numbers used by services
  1030. should be in the area reserved for services (see Section ``Summary of
  1031. Message Numbers'').  The transport level will continue to process its
  1032. own messages.
  1033.  
  1034. The service name is not considered confidential information.  An active
  1035. network-level attacker may discover the service name by a man-in-the-
  1036. middle attack.  Successful reception of the service accept message will
  1037. confirm to the client that the server successfully received the session
  1038. key and that the key exchange was not tampered with.
  1039.  
  1040. If the negotiated cipher is "none", the client must wait until the
  1041. service accept message has been successfully received before sending any
  1042. more data.  Otherwise, an attacker could learn this data by modifying
  1043. negotiation parameters in such a way that the "none" cipher gets
  1044. selected.
  1045.  
  1046. 9.  Additional Messages
  1047.  
  1048. Either party may send any of the following messages at any time.
  1049.  
  1050. 9.1.  Disconnection Message
  1051.  
  1052.             byte      SSH_MSG_DISCONNECT
  1053.             uint32    reason code
  1054.             string    description
  1055.  
  1056. This message causes immediate termination of the connection.  The
  1057. description field gives the reason for disconnecting in human-readable
  1058. form in English.  The error code gives the reason in a machine-readable
  1059. format (suitable for localization), and can have the following values:
  1060.  
  1061.  
  1062. Tatu Ylonen <ylo@ssh.fi>                                       [page 18]
  1063.  
  1064. INTERNET-DRAFT                                             July 30, 1997
  1065.  
  1066.           #define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT      1
  1067.           #define SSH_DISCONNECT_PROTOCOL_ERROR                   2
  1068.           #define SSH_DISCONNECT_KEY_EXCHANGE_FAILED              3
  1069.           #define SSH_DISCONNECT_HOST_AUTHENTICATION_FAILED       4
  1070.           #define SSH_DISCONNECT_MAC_ERROR                        5
  1071.           #define SSH_DISCONNECT_COMPRESSION_ERROR                6
  1072.           #define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE            7
  1073.           #define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED   8
  1074.           #define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE          9
  1075.           #define SSH_DISCONNECT_CONNECTION_LOST                 10
  1076.           #define SSH_DISCONNECT_BY_APPLICATION                  11
  1077.  
  1078. 9.2.  Ignored Data Message
  1079.  
  1080.             byte      SSH_MSG_IGNORE
  1081.             string    data
  1082.  
  1083. All implementations must understand (and ignore) this message at any
  1084. time (after receiving the protocol version).  No implementation is
  1085. required to ever send them.
  1086.  
  1087. 9.3.  Debug Message
  1088.  
  1089.             byte      SSH_MSG_DEBUG
  1090.             uint32    type
  1091.             string    message
  1092.  
  1093. All implementations must understand this message, but they are allowed
  1094. to ignore it.  This message is used to pass information to the other
  1095. side which may help debugging problems.  The type may have any of the
  1096. following values:
  1097.  
  1098.     0 SSH_DEBUG_DEBUG
  1099.       The message contains information that may be useful for debugging
  1100.       problems; however, it should not normally be shown to the user.
  1101.       It is recommended that the data be available to the user for
  1102.       debugging purposes if explicitly requested.
  1103.  
  1104.     1 SSH_DEBUG_DISPLAY
  1105.       The message contains information that should preferably be shown
  1106.       to the user regardless of whether debugging information has been
  1107.       requested.
  1108.  
  1109. The message need not contain a newline.  It is, however, allowed to
  1110. consist of multiple lines separated by newlines.
  1111.  
  1112. 9.4.  Reserved Messages
  1113.  
  1114. An implementation must respond to all unrecognized messages with an
  1115. SSH_MSG_UNIMPLEMENTED message in the order in which they were received.
  1116. Later protocol versions may define other meanings for these message
  1117. types.
  1118.  
  1119.  
  1120.  
  1121. Tatu Ylonen <ylo@ssh.fi>                                       [page 19]
  1122.  
  1123. INTERNET-DRAFT                                             July 30, 1997
  1124.  
  1125.             byte      SSH_MSG_UNIMPLEMENTED
  1126.             uint32    packet sequence number of rejected message
  1127.  
  1128. 10.  Summary of Message Numbers
  1129.  
  1130. The following message numbers have been defined in this protocol.
  1131.  
  1132. #define SSH_MSG_DISCONNECT             1
  1133. #define SSH_MSG_IGNORE                 2
  1134. #define SSH_MSG_UNIMPLEMENTED          3
  1135. #define SSH_MSG_DEBUG                  4
  1136. #define SSH_MSG_KEXINIT               10
  1137. #define SSH_MSG_NEWKEYS               11
  1138. #define SSH_MSG_SERVICE_REQUEST       12
  1139. #define SSH_MSG_SERVICE_ACCEPT        13
  1140.  
  1141. /* Numbers 15-19 for kex packets.
  1142.    Different kex methods may reuse message numbers in
  1143.    this range. */
  1144. #define SSH_MSG_KEXDE_HOSTKEY         15
  1145. #define SSH_MSG_KEXDE_SESSIONKEY      16
  1146.  
  1147. /* Numbers 20- are reserved for service types.
  1148.    Different service types may reuse the same messages.
  1149.    Messages for stream-based services.  Other service types
  1150.    may be defined in other documents. */
  1151. #define SSH_MSG_STREAM_DATA           20
  1152. #define SSH_MSG_STREAM_EOF            21
  1153. #define SSH_MSG_STREAM_CLOSE          22
  1154.  
  1155. 11.  Public Keys and Public Key Infrastructure
  1156.  
  1157. This protocol has been designed to be able to operate with almost any
  1158. public key format, encoding, and algorithm.
  1159.  
  1160. There are several aspects that define a public key type:
  1161.  
  1162. o  Key format: how is the key encoded and how are certificates
  1163.    represented.  The key blobs in this protocol may (but are not
  1164.    required to) contain certificates in addition to keys.
  1165.  
  1166. o  Signature and/or encryption algorithms.  Some algorithms may not
  1167.    support both encryption and decryption.  Key usage may also be
  1168.    restricted by policy statements in e.g. certificates.
  1169.  
  1170. o  Encoding of signatures and encrypted data.  This includes but is not
  1171.    limited to padding, byte order, and data formats.
  1172.  
  1173. The following public key formats are currently defined:
  1174.  
  1175.           x509                    X.509 certificate
  1176.           spki                    IETF SPKI certificate
  1177.           ssh-rsa-pkcs1           RSA key with PKCS-1 encodings
  1178.  
  1179.  
  1180. Tatu Ylonen <ylo@ssh.fi>                                       [page 20]
  1181.  
  1182. INTERNET-DRAFT                                             July 30, 1997
  1183.  
  1184. Note that the key type is negotiated at the beginning of the key
  1185. exchange, and is not included in the key blob itself.
  1186.  
  1187. 11.1.  x509
  1188.  
  1189. X.509 is the most widely used certificate format at the time of this
  1190. writing.  However, X.509 has many serious problems, both on a conceptual
  1191. and implementation level.  X.509v3 has addressed many of these problems,
  1192. and may be more usable than previous versions.
  1193.  
  1194. The key blob for an "x509" key blob is a X.509 (v3) certificate (or
  1195. certificates) in ASN.1 (DER) format.
  1196.  
  1197. 11.2.  spki
  1198.  
  1199. SPKI (Simple Public Key Infrastructure) is based on the philosophy that
  1200. most applications actually require authorization, not identification.
  1201. SPKI also addresses naming and policy issues in an explicit and useful
  1202. way.
  1203.  
  1204. The key blob for an "spki" key blob contains a SPKI key and certificate
  1205. objects concatenated together.
  1206.  
  1207. 11.3.  ssh-rsa-pkcs1
  1208.  
  1209. This key type defines an RSA public key, with (mostly) PKCS compatible
  1210. signature and encryption formats.  It supports both signatures and
  1211. encryption.
  1212.  
  1213. Public keys of this type are represented as follows:
  1214.  
  1215.             uint32        number of bits in the modulus
  1216.             uint32        number bits in the public exponent
  1217.             bytes[n]      exponent, MSB first, n = floor((bits+7)/8)
  1218.             uint32        number of bits in the modulus
  1219.             bytes[n]      modulus, MSB first, n = floor((bits+7)/8)
  1220.  
  1221. It is permissible that there be other data (e.g., certificates)
  1222. following this; however, such data is not yet defined.
  1223.  
  1224. Note that private key formats are not defined here, and are
  1225. implementation-specific.
  1226.  
  1227. An encrypted message is formed as follows (this follows PKCS-1 padding
  1228. rules).
  1229. o  The data to be encrypted is padded into a long integer of the same
  1230.    number of bits as the modulus as follows:
  1231.  
  1232.               MSB             .  .  .                LSB
  1233.  
  1234.                0   2   RND(n bytes)   0   encrypted_data
  1235.  
  1236. The RND bytes represent non-zero random bytes.
  1237.  
  1238.  
  1239. Tatu Ylonen <ylo@ssh.fi>                                       [page 21]
  1240.  
  1241. INTERNET-DRAFT                                             July 30, 1997
  1242.  
  1243. o  To encrypt, this integer is raised to the public exponent, modulo the
  1244.    modulus.
  1245.  
  1246. o  The result is converted to a byte string of floor((bits+7)/8) bytes
  1247.    (where bits is the number of bits in the modulus), MSB first.  This
  1248.    byte string (without any length or terminating characters) is the
  1249.    result of the encryption.
  1250.  
  1251. A signature is formed as follows.
  1252.  
  1253. o  The data to be signed (typically a message digest, but not required
  1254.    to be such) is padded into a long integer of the same number of bits
  1255.    as the modulus as follows:
  1256.  
  1257.               MSB             .  .  .             LSB
  1258.  
  1259.                0   1   FF (n bytes)   0   signed_data
  1260.  
  1261. o  To sign, this integer is raised to the private exponent, modulo the
  1262.    modulus.
  1263.  
  1264. o  The result is converted to a byte string of floor((bits+7)/8) bytes
  1265.    (where bits is the number of bits in the modulus), MSB first.  This
  1266.    byte string (without any length or terminating characters) is the
  1267.    signature.  Applications may add other data outside this value.
  1268.  
  1269. 12.  Security Considerations
  1270.  
  1271. This protocol is responsible for providing a secure encrypted channel
  1272. over an unsecure network.  It performs server host authentication, key
  1273. exchange, encryption, and integrity protection.  It also derives a
  1274. unique session id that may be by higher-level protocols.
  1275.  
  1276. It is expected that this protocol will sometimes be used without always
  1277. insisting on reliable association between the server host key and the
  1278. server host name.  Such use is inherently insecure, but may be necessary
  1279. in non-security critical environments, and still provides protection
  1280. against passive attacks.  However, protocols running on top of this
  1281. protocol should keep this possibility in mind.
  1282.  
  1283. 13.  Address of Author
  1284.  
  1285.               Tatu Ylonen
  1286.               SSH Communications Security Ltd.
  1287.               Tekniikantie 12
  1288.               FIN-02150 ESPOO
  1289.               Finland
  1290.  
  1291.               E-mail: ylo@ssh.fi
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297. Tatu Ylonen <ylo@ssh.fi>                                       [page 22]
  1298.