OVERVIEW 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. [Note: This file has not been updated for OpenSSH versions after
  2. OpenSSH-1.2 and should be considered OBSOLETE. It has been left in
  3. the distribution because some of its information may still be useful
  4. to developers.]
  5. This document is intended for those who wish to read the ssh source
  6. code. This tries to give an overview of the structure of the code.
  7. Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>
  8. Updated 17 Nov 1995.
  9. Updated 19 Oct 1999 for OpenSSH-1.2
  10. Updated 20 May 2001 note obsolete for > OpenSSH-1.2
  11. The software consists of ssh (client), sshd (server), scp, sdist, and
  12. the auxiliary programs ssh-keygen, ssh-agent, ssh-add, and
  13. make-ssh-known-hosts. The main program for each of these is in a .c
  14. file with the same name.
  15. There are some subsystems/abstractions that are used by a number of
  16. these programs.
  17. Buffer manipulation routines
  18. - These provide an arbitrary size buffer, where data can be appended.
  19. Data can be consumed from either end. The code is used heavily
  20. throughout ssh. The buffer manipulation functions are in
  21. sshbuf*.c (header sshbuf.h).
  22. Compression Library
  23. - Ssh uses the GNU GZIP compression library (ZLIB).
  24. Encryption/Decryption
  25. - Ssh contains several encryption algorithms. These are all
  26. accessed through the cipher.h interface. The interface code is
  27. in cipher.c, and the implementations are either in libc or
  28. LibreSSL.
  29. Multiple Precision Integer Library
  30. - Uses the LibreSSL BIGNUM sublibrary.
  31. Random Numbers
  32. - Uses arc4random() and such.
  33. RSA key generation, encryption, decryption
  34. - Ssh uses the RSA routines in libssl.
  35. RSA key files
  36. - RSA keys are stored in files with a special format. The code to
  37. read/write these files is in authfile.c. The files are normally
  38. encrypted with a passphrase. The functions to read passphrases
  39. are in readpass.c (the same code is used to read passwords).
  40. Binary packet protocol
  41. - The ssh binary packet protocol is implemented in packet.c. The
  42. code in packet.c does not concern itself with packet types or their
  43. execution; it contains code to build packets, to receive them and
  44. extract data from them, and the code to compress and/or encrypt
  45. packets.
  46. - The code in packet.c calls the buffer manipulation routines
  47. (buffer.c, bufaux.c), compression routines (zlib), and the
  48. encryption routines.
  49. X11, TCP/IP, and Agent forwarding
  50. - Code for various types of channel forwarding is in channels.c.
  51. The file defines a generic framework for arbitrary communication
  52. channels inside the secure channel, and uses this framework to
  53. implement X11 forwarding, TCP/IP forwarding, and authentication
  54. agent forwarding.
  55. The new, Protocol 1.5, channel close implementation is in nchan.c
  56. Authentication agent
  57. - Code to communicate with the authentication agent is in authfd.c.
  58. Authentication methods
  59. - Code for various authentication methods resides in auth-*.c
  60. (auth-passwd.c, auth-rh-rsa.c, auth-rhosts.c, auth-rsa.c). This
  61. code is linked into the server. The routines also manipulate
  62. known hosts files using code in hostfile.c. Code in canohost.c
  63. is used to retrieve the canonical host name of the remote host.
  64. Code in match.c is used to match host names.
  65. - In the client end, authentication code is in sshconnect.c. It
  66. reads Passwords/passphrases using code in readpass.c. It reads
  67. RSA key files with authfile.c. It communicates the
  68. authentication agent using authfd.c.
  69. The ssh client
  70. - The client main program is in ssh.c. It first parses arguments
  71. and reads configuration (readconf.c), then calls ssh_connect (in
  72. sshconnect.c) to open a connection to the server (possibly via a
  73. proxy), and performs authentication (ssh_login in sshconnect.c).
  74. It then makes any pty, forwarding, etc. requests. It may call
  75. code in ttymodes.c to encode current tty modes. Finally it
  76. calls client_loop in clientloop.c. This does the real work for
  77. the session.
  78. Pseudo-tty manipulation and tty modes
  79. - Code to allocate and use a pseudo tty is in pty.c. Code to
  80. encode and set terminal modes is in ttymodes.c.
  81. Logging in (updating utmp, lastlog, etc.)
  82. - The code to do things that are done when a user logs in are in
  83. login.c. This includes things such as updating the utmp, wtmp,
  84. and lastlog files. Some of the code is in sshd.c.
  85. Writing to the system log and terminal
  86. - The programs use the functions fatal(), log(), debug(), error()
  87. in many places to write messages to system log or user's
  88. terminal. The implementation that logs to system log is in
  89. log-server.c; it is used in the server program. The other
  90. programs use an implementation that sends output to stderr; it
  91. is in log-client.c. The definitions are in ssh.h.
  92. The sshd server (daemon)
  93. - The sshd daemon starts by processing arguments and reading the
  94. configuration file (servconf.c). It then reads the host key,
  95. starts listening for connections, and generates the server key.
  96. The server key will be regenerated every hour by an alarm.
  97. - When the server receives a connection, it forks, disables the
  98. regeneration alarm, and starts communicating with the client.
  99. They first perform identification string exchange, then
  100. negotiate encryption, then perform authentication, preparatory
  101. operations, and finally the server enters the normal session
  102. mode by calling server_loop in serverloop.c. This does the real
  103. work, calling functions in other modules.
  104. - The code for the server is in sshd.c. It contains a lot of
  105. stuff, including:
  106. - server main program
  107. - waiting for connections
  108. - processing new connection
  109. - authentication
  110. - preparatory operations
  111. - building up the execution environment for the user program
  112. - starting the user program.
  113. Auxiliary files
  114. - There are several other files in the distribution that contain
  115. various auxiliary routines:
  116. ssh.h the main header file for ssh (various definitions)
  117. uidswap.c uid-swapping
  118. xmalloc.c "safe" malloc routines
  119. $OpenBSD: OVERVIEW,v 1.15 2018/10/23 05:56:35 djm Exp $