xref: /freebsd/crypto/openssh/OVERVIEW (revision 19261079b74319502c6ffa1249920079f0f69a72)
1ae1f160dSDag-Erling Smørgrav[Note: This file has not been updated for OpenSSH versions after
2ae1f160dSDag-Erling SmørgravOpenSSH-1.2 and should be considered OBSOLETE.  It has been left in
3ae1f160dSDag-Erling Smørgravthe distribution because some of its information may still be useful
4ae1f160dSDag-Erling Smørgravto developers.]
5ae1f160dSDag-Erling Smørgrav
6511b41d2SMark MurrayThis document is intended for those who wish to read the ssh source
7511b41d2SMark Murraycode.  This tries to give an overview of the structure of the code.
8511b41d2SMark Murray
9511b41d2SMark MurrayCopyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>
10511b41d2SMark MurrayUpdated 17 Nov 1995.
11511b41d2SMark MurrayUpdated 19 Oct 1999 for OpenSSH-1.2
12ae1f160dSDag-Erling SmørgravUpdated 20 May 2001 note obsolete for > OpenSSH-1.2
13511b41d2SMark Murray
14511b41d2SMark MurrayThe software consists of ssh (client), sshd (server), scp, sdist, and
15511b41d2SMark Murraythe auxiliary programs ssh-keygen, ssh-agent, ssh-add, and
16511b41d2SMark Murraymake-ssh-known-hosts.  The main program for each of these is in a .c
17511b41d2SMark Murrayfile with the same name.
18511b41d2SMark Murray
19511b41d2SMark MurrayThere are some subsystems/abstractions that are used by a number of
20511b41d2SMark Murraythese programs.
21511b41d2SMark Murray
22511b41d2SMark Murray  Buffer manipulation routines
23511b41d2SMark Murray
24511b41d2SMark Murray    - These provide an arbitrary size buffer, where data can be appended.
25511b41d2SMark Murray      Data can be consumed from either end.  The code is used heavily
26190cef3dSDag-Erling Smørgrav      throughout ssh.  The buffer manipulation functions are in
27190cef3dSDag-Erling Smørgrav      sshbuf*.c (header sshbuf.h).
28511b41d2SMark Murray
29511b41d2SMark Murray  Compression Library
30511b41d2SMark Murray
31511b41d2SMark Murray    - Ssh uses the GNU GZIP compression library (ZLIB).
32511b41d2SMark Murray
33511b41d2SMark Murray  Encryption/Decryption
34511b41d2SMark Murray
35511b41d2SMark Murray    - Ssh contains several encryption algorithms.  These are all
36511b41d2SMark Murray      accessed through the cipher.h interface.  The interface code is
37*19261079SEd Maste      in cipher.c, and the implementations are either in libc or
38*19261079SEd Maste      LibreSSL.
39511b41d2SMark Murray
40511b41d2SMark Murray  Multiple Precision Integer Library
41511b41d2SMark Murray
42*19261079SEd Maste    - Uses the LibreSSL BIGNUM sublibrary.
43511b41d2SMark Murray
44511b41d2SMark Murray  Random Numbers
45511b41d2SMark Murray
46511b41d2SMark Murray    - Uses arc4random() and such.
47511b41d2SMark Murray
48511b41d2SMark Murray  RSA key generation, encryption, decryption
49511b41d2SMark Murray
50511b41d2SMark Murray    - Ssh uses the RSA routines in libssl.
51511b41d2SMark Murray
52511b41d2SMark Murray  RSA key files
53511b41d2SMark Murray
54511b41d2SMark Murray    - RSA keys are stored in files with a special format.  The code to
55511b41d2SMark Murray      read/write these files is in authfile.c.  The files are normally
56511b41d2SMark Murray      encrypted with a passphrase.  The functions to read passphrases
57511b41d2SMark Murray      are in readpass.c (the same code is used to read passwords).
58511b41d2SMark Murray
59511b41d2SMark Murray  Binary packet protocol
60511b41d2SMark Murray
61511b41d2SMark Murray    - The ssh binary packet protocol is implemented in packet.c.  The
62511b41d2SMark Murray      code in packet.c does not concern itself with packet types or their
63511b41d2SMark Murray      execution; it contains code to build packets, to receive them and
64511b41d2SMark Murray      extract data from them, and the code to compress and/or encrypt
65190cef3dSDag-Erling Smørgrav      packets.
66511b41d2SMark Murray
67511b41d2SMark Murray    - The code in packet.c calls the buffer manipulation routines
68eccfee6eSDag-Erling Smørgrav      (buffer.c, bufaux.c), compression routines (zlib), and the
69eccfee6eSDag-Erling Smørgrav      encryption routines.
70511b41d2SMark Murray
71511b41d2SMark Murray  X11, TCP/IP, and Agent forwarding
72511b41d2SMark Murray
73511b41d2SMark Murray    - Code for various types of channel forwarding is in channels.c.
74511b41d2SMark Murray      The file defines a generic framework for arbitrary communication
75511b41d2SMark Murray      channels inside the secure channel, and uses this framework to
76511b41d2SMark Murray      implement X11 forwarding, TCP/IP forwarding, and authentication
77511b41d2SMark Murray      agent forwarding.
78511b41d2SMark Murray      The new, Protocol 1.5, channel close implementation is in nchan.c
79511b41d2SMark Murray
80511b41d2SMark Murray  Authentication agent
81511b41d2SMark Murray
82511b41d2SMark Murray    - Code to communicate with the authentication agent is in authfd.c.
83511b41d2SMark Murray
84511b41d2SMark Murray  Authentication methods
85511b41d2SMark Murray
86511b41d2SMark Murray    - Code for various authentication methods resides in auth-*.c
87511b41d2SMark Murray      (auth-passwd.c, auth-rh-rsa.c, auth-rhosts.c, auth-rsa.c).  This
88511b41d2SMark Murray      code is linked into the server.  The routines also manipulate
89511b41d2SMark Murray      known hosts files using code in hostfile.c.  Code in canohost.c
90511b41d2SMark Murray      is used to retrieve the canonical host name of the remote host.
91511b41d2SMark Murray      Code in match.c is used to match host names.
92511b41d2SMark Murray
93511b41d2SMark Murray    - In the client end, authentication code is in sshconnect.c.  It
94511b41d2SMark Murray      reads Passwords/passphrases using code in readpass.c.  It reads
95511b41d2SMark Murray      RSA key files with authfile.c.  It communicates the
96511b41d2SMark Murray      authentication agent using authfd.c.
97511b41d2SMark Murray
98511b41d2SMark Murray  The ssh client
99511b41d2SMark Murray
100511b41d2SMark Murray    - The client main program is in ssh.c.  It first parses arguments
101511b41d2SMark Murray      and reads configuration (readconf.c), then calls ssh_connect (in
102511b41d2SMark Murray      sshconnect.c) to open a connection to the server (possibly via a
103511b41d2SMark Murray      proxy), and performs authentication (ssh_login in sshconnect.c).
104511b41d2SMark Murray      It then makes any pty, forwarding, etc. requests.  It may call
105511b41d2SMark Murray      code in ttymodes.c to encode current tty modes.  Finally it
106511b41d2SMark Murray      calls client_loop in clientloop.c.  This does the real work for
107511b41d2SMark Murray      the session.
108511b41d2SMark Murray
109511b41d2SMark Murray  Pseudo-tty manipulation and tty modes
110511b41d2SMark Murray
111511b41d2SMark Murray    - Code to allocate and use a pseudo tty is in pty.c.  Code to
112511b41d2SMark Murray      encode and set terminal modes is in ttymodes.c.
113511b41d2SMark Murray
114511b41d2SMark Murray  Logging in (updating utmp, lastlog, etc.)
115511b41d2SMark Murray
116511b41d2SMark Murray    - The code to do things that are done when a user logs in are in
117511b41d2SMark Murray      login.c.  This includes things such as updating the utmp, wtmp,
118511b41d2SMark Murray      and lastlog files.  Some of the code is in sshd.c.
119511b41d2SMark Murray
120511b41d2SMark Murray  Writing to the system log and terminal
121511b41d2SMark Murray
122511b41d2SMark Murray    - The programs use the functions fatal(), log(), debug(), error()
123511b41d2SMark Murray      in many places to write messages to system log or user's
124511b41d2SMark Murray      terminal.  The implementation that logs to system log is in
125511b41d2SMark Murray      log-server.c; it is used in the server program.  The other
126511b41d2SMark Murray      programs use an implementation that sends output to stderr; it
127511b41d2SMark Murray      is in log-client.c.  The definitions are in ssh.h.
128511b41d2SMark Murray
129511b41d2SMark Murray  The sshd server (daemon)
130511b41d2SMark Murray
131511b41d2SMark Murray    - The sshd daemon starts by processing arguments and reading the
132511b41d2SMark Murray      configuration file (servconf.c).  It then reads the host key,
133511b41d2SMark Murray      starts listening for connections, and generates the server key.
134511b41d2SMark Murray      The server key will be regenerated every hour by an alarm.
135511b41d2SMark Murray
136511b41d2SMark Murray    - When the server receives a connection, it forks, disables the
137511b41d2SMark Murray      regeneration alarm, and starts communicating with the client.
138511b41d2SMark Murray      They first perform identification string exchange, then
139511b41d2SMark Murray      negotiate encryption, then perform authentication, preparatory
140511b41d2SMark Murray      operations, and finally the server enters the normal session
141511b41d2SMark Murray      mode by calling server_loop in serverloop.c.  This does the real
142511b41d2SMark Murray      work, calling functions in other modules.
143511b41d2SMark Murray
144511b41d2SMark Murray    - The code for the server is in sshd.c.  It contains a lot of
145511b41d2SMark Murray      stuff, including:
146511b41d2SMark Murray	- server main program
147511b41d2SMark Murray	- waiting for connections
148511b41d2SMark Murray	- processing new connection
149511b41d2SMark Murray	- authentication
150511b41d2SMark Murray	- preparatory operations
151511b41d2SMark Murray	- building up the execution environment for the user program
152511b41d2SMark Murray	- starting the user program.
153511b41d2SMark Murray
154511b41d2SMark Murray  Auxiliary files
155511b41d2SMark Murray
156511b41d2SMark Murray    - There are several other files in the distribution that contain
157511b41d2SMark Murray      various auxiliary routines:
158511b41d2SMark Murray	ssh.h	     the main header file for ssh (various definitions)
159511b41d2SMark Murray	uidswap.c    uid-swapping
160511b41d2SMark Murray	xmalloc.c    "safe" malloc routines
161761efaa7SDag-Erling Smørgrav
162*19261079SEd Maste$OpenBSD: OVERVIEW,v 1.15 2018/10/23 05:56:35 djm Exp $
163