📄 rfc.nroff
字号:
example, the value 0x00012345 would have 17 bits). The value zero haszero bits. It is permissible that the number of bits be larger than thereal number of bits.The number of bits is followed by (bits + 7) / 8 bytes of binary data,msb first, giving the value of the integer..RT.ti 0TCP/IP Port Number and Other OptionsThe server listens for connections on TCP/IP port 22.The client may connect the server from any port. However, if theclient wishes to use any form of .rhosts or /etc/hosts.equivauthentication, it must connect from a privileged port (less than1024).For the IP Type of Service field [RFC0791], it is recommended thatinteractive sessions (those having a user terminal or forwarding X11connections) use the IPTOS_LOWDELAY, and non-interactive connectionsuse IPTOS_THROUGHPUT.It is recommended that keepalives are used, because otherwise programson the server may never notice if the other end of the connection isrebooted..ti 0Protocol Version IdentificationAfter the socket is opened, the server sends an identification string,which is of the form"SSH-<protocolmajor>.<protocolminor>-<version>\\n", where<protocolmajor> and <protocolminor> are integers and specify theprotocol version number (not software distribution version).<version> is server side software version string (max 40 characters);it is not interpreted by the remote side but may be useful fordebugging.The client parses the server's string, and sends a correspondingstring with its own information in response. If the server has lowerversion number, and the client contains special code to emulate it,the client responds with the lower number; otherwise it responds withits own number. The server then compares the version number theclient sent with its own, and determines whether they can worktogether. The server either disconnects, or sends the first packetusing the binary packet protocol and both sides start workingaccording to the lower of the protocol versions.By convention, changes which keep the protocol compatible withprevious versions keep the same major protocol version; changes thatare not compatible increment the major version (which will hopefullynever happen). The version described in this document is 1.3.The client will .ti 0Key Exchange and Server Host AuthenticationThe first message sent by the server using the packet protocol isSSH_SMSG_PUBLIC_KEY. It declares the server's host key, server publickey, supported ciphers, supported authentication methods, and flagsfor protocol extensions. It also contains a 64-bit random number(cookie) that must be returned in the client's reply (to make IPspoofing more difficult). No encryption is used for this message.Both sides compute a session id as follows. The modulus of the serverkey is interpreted as a byte string (without explicit length field,with minimum length able to hold the whole value), most significantbyte first. This string is concatenated with the server host keyinterpreted the same way. Additionally, the cookie is concatenatedwith this. Both sides compute MD5 of the resulting string. Theresulting 16 bytes (128 bits) are stored by both parties and arecalled the session id.The client responds with a SSH_CMSG_SESSION_KEY message, whichcontains the selected cipher type, a copy of the 64-bit cookie sent bythe server, client's protocol flags, and a session key encryptedwith both the server's host key and server key. No encryption is usedfor this message.The session key is 32 8-bit bytes (a total of 256 random bitsgenerated by the client). The client first xors the 16 bytes of thesession id with the first 16 bytes of the session key. The resultingstring is then encrypted using the smaller key (one with smallermodulus), and the result is then encrypted using the other key. Thenumber of bits in the public modulus of the two keys must differ by atleast 128 bits.At each encryption step, a multiple-precision integer is constructedfrom the data to be encrypted as follows (the integer is hereinterpreted as a sequence of bytes, msb first; the number of bytes isthe number of bytes needed to represent the modulus).The most significant byte (which is only partial as the value must beless than the public modulus, which is never a power of two) is zero.The next byte contains the value 2 (which stands for public-keyencrypted data in the PKCS standard [PKCS#1]). Then, there arenon-zero random bytes to fill any unused space, a zero byte, and thedata to be encrypted in the least significant bytes, the last byte ofthe data in the least significant byte.This algorithm is used twice. First, it is used to encrypt the 32random bytes generated by the client to be used as the session key(xored by the session id). This value is converted to an integer asdescribed above, and encrypted with RSA using the key with the smallermodulus. The resulting integer is converted to a byte stream, msbfirst. This byte stream is padded and encrypted identically using thekey with the larger modulus.After the client has sent the session key, it starts to use theselected algorithm and key for decrypting any received packets, andfor encrypting any sent packets. Separate ciphers are used fordifferent directions (that is, both directions have separateinitialization vectors or other state for the ciphers).When the server has received the session key message, and has turnedon encryption, it sends a SSH_SMSG_SUCCESS message to the client.The recommended size of the host key is 1024 bits, and 768 bits forthe server key. The minimum size is 512 bits for the smaller key..ti 0Declaring the User NameThe client then sends a SSH_CMSG_USER message to the server. Thismessage specifies the user name to log in as.The server validates that such a user exists, checks whetherauthentication is needed, and responds with either SSH_SMSG_SUCCESS orSSH_SMSG_FAILURE. SSH_SMSG_SUCCESS indicates that no authenticationis needed for this user (no password), and authentication phase hasnow been completed. SSH_SMSG_FAILURE indicates that authentication isneeded (or the user does not exist).If the user does not exist, it is recommended that this returnsfailure, but the server keeps reading messages from the client, andresponds to any messages (except SSH_MSG_DISCONNECT, SSH_MSG_IGNORE,and SSH_MSG_DEBUG) with SSH_SMSG_FAILURE. This way the client cannotbe certain whether the user exists..ti 0Authentication PhaseProvided the server didn't immediately accept the login, anauthentication exchange begins. The client sends messages to theserver requesting different types of authentication in arbitrary order asmany times as desired (however, the server may close the connectionafter a timeout). The server always responds with SSH_SMSG_SUCCESS ifit has accepted the authentication, and with SSH_SMSG_FAILURE if it hasdenied authentication with the requested method or it does notrecognize the message. Some authentication methods cause an exchangeof further messages before the final result is sent. Theauthentication phase ends when the server responds with success.The recommended value for the authentication timeout (timeout beforedisconnecting if no successful authentication has been made) is 5minutes.The following authentication methods are currently supported:.TScenter;l r l.SSH_AUTH_RHOSTS 1 .rhosts or /etc/hosts.equivSSH_AUTH_RSA 2 pure RSA authenticationSSH_AUTH_PASSWORD 3 password authenticationSSH_AUTH_RHOSTS_RSA 4 .rhosts with RSA host authentication.TE.IP SSH_AUTH_RHOSTSThis is the authentication method used by rlogin and rsh [RFC1282].The client sends SSH_CMSG_AUTH_RHOSTS with the client-side user nameas an argument.The server checks whether to permit authentication. On UNIX systems,this is usually done by checking /etc/hosts.equiv, and .rhosts in theuser's home directory. The connection must come from a privilegedport.It is recommended that the server checks that there are no IP options(such as source routing) specified for the socket before acceptingthis type of authentication. The client host name should bereverse-mapped and then forward mapped to ensure that it has theproper IP-address.This authentication method trusts the remote host (root on the remotehost can pretend to be any other user on that host), the nameservices, and partially the network: anyone who can see packets comingout from the server machine can do IP-spoofing and pretend to be anymachine; however, the protocol prevents blind IP-spoofing (which usedto be possible with rlogin).Many sites probably want to disable this authentication method becauseof the fundamental insecurity of conventional .rhosts or/etc/hosts.equiv authentication when faced with spoofing. It isrecommended that this method not be supported by the server bydefault..IP SSH_AUTH_RHOSTS_RSAIn addition to conventional .rhosts and hosts.equiv authentication,this method additionally requires that the client host beauthenticated using RSA.The client sends SSH_CMSG_AUTH_RHOSTS_RSA specifying the client-sideuser name, and the public host key of the client host.The server first checks if normal .rhosts or /etc/hosts.equivauthentication would be accepted, and if not, responds withSSH_SMSG_FAILURE. Otherwise, it checks whether it knows the host keyfor the client machine (using the same name for the host that was usedfor checking the .rhosts and /etc/hosts.equiv files). If it does notknow the RSA key for the client, access is denied and SSH_SMSG_FAILUREis sent.If the server knows the host key of the client machine, it verifiesthat the given host key matches that known for the client. If not,access is denied and SSH_SMSG_FAILURE is sent.The server then sends a SSH_SMSG_AUTH_RSA_CHALLENGE message containingan encrypted challenge for the client. The challenge is 32 8-bitrandom bytes (256 bits). When encrypted, the highest (partial) byteis left as zero, the next byte contains the value 2, the following arenon-zero random bytes, followed by a zero byte, and the challenge putin the remaining bytes. This is then encrypted using RSA with theclient host's public key. (The padding and encryption algorithm isthe same as that used for the session key.)The client decrypts the challenge using its private host key,concatenates this with the session id, and computes an MD5 checksumof the resulting 48 bytes. The MD5 output is returned as 16 bytes ina SSH_CMSG_AUTH_RSA_RESPONSE message. (MD5 is used to deter chosenplaintext attacks against RSA; the session id binds it to a specificsession).The server verifies that the MD5 of the decrypted challenge returned bythe client matches that of the original value, and sends SSH_SMSG_SUCCESS ifso. Otherwise it sends SSH_SMSG_FAILURE and refuses theauthentication attempt.This authentication method trusts the client side machine in that rooton that machine can pretend to be any user on that machine.Additionally, it trusts the client host key. The name and/or IPaddress of the client host is only used to select the public host key.The same host name is used when scanning .rhosts or /etc/hosts.equivand when selecting the host key. It would in principle be possible toeliminate the host name entirely and substitute it directly by thehost key. IP and/or DNS [RFC1034] spoofing can only be usedto pretend to be a host for which the attacker has the private hostkey..IP SSH_AUTH_RSAThe idea behind RSA authentication is that the server recognizes thepublic key offered by the client, generates a random challenge, andencrypts the challenge with the public key. The client must thenprove that it has the corresponding private key by decrypting thechallenge.The client sends SSH_CMSG_AUTH_RSA with public key modulus (n) as anargument.The server may respond immediately with SSH_SMSG_FAILURE if it doesnot permit authentication with this key. Otherwise it generates achallenge, encrypts it using the user's public key (stored on theserver and identified using the modulus), and sendsSSH_SMSG_AUTH_RSA_CHALLENGE with the challenge (mp-int) as anargument.The challenge is 32 8-bit random bytes (256 bits). When encrypted,the highest (partial) byte is left as zero, the next byte contains thevalue 2, the following are non-zero random bytes, followed by a zerobyte, and the challenge put in the remaining bytes. This is thenencrypted with the public key. (The padding and encryption algorithmis the same as that used for the session key.)The client decrypts the challenge using its private key, concatenatesit with the session id, and computes an MD5 checksum of the resulting48 bytes. The MD5 output is returned as 16 bytes in aSSH_CMSG_AUTH_RSA_RESPONSE message. (Note that the MD5 is necessaryto avoid chosen plaintext attacks against RSA; the session id binds itto a specific session.)The server verifies that the MD5 of the decrypted challenge returnedby the client matches that of the original value, and sendsSSH_SMSG_SUCCESS if so. Otherwise it sends SSH_SMSG_FAILURE andrefuses the authentication attempt.This authentication method does not trust the remote host, thenetwork, name services, or anything else. Authentication is basedsolely on the possession of the private identification keys. Anyonein possession of the private keys can log in, but nobody else.The server may have additional requirements for a successfulauthentiation. For example, to limit damage due to a compromised RSAkey, a server might restrict access to a limited set of hosts..IP SSH_AUTH_PASSWORDThe client sends a SSH_CMSG_AUTH_PASSWORD message with the plain textpassword. (Note that even though the password is plain text insidethe message, it is normally encrypted by the packet mechanism.)The server verifies the password, and sends SSH_SMSG_SUCCESS ifauthentication was accepted and SSH_SMSG_FAILURE otherwise.Note that the password is read from the user by the client; the usernever interacts with a login program.This authentication method does not trust the remote host, thenetwork, name services or anything else. Authentication is basedsolely on the possession of the password. Anyone in possession of thepassword can log in, but nobody else..RT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -