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