Home | History | Annotate | Line # | Download | only in dist
      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.8  christos       in cipher.c, and the implementations are either in libc or
     38  1.8  christos       LibreSSL.
     39  1.1  christos 
     40  1.1  christos   Multiple Precision Integer Library
     41  1.1  christos 
     42  1.8  christos     - Uses the LibreSSL BIGNUM sublibrary.
     43  1.1  christos 
     44  1.1  christos   Random Numbers
     45  1.1  christos 
     46  1.1  christos     - Uses arc4random() and such.
     47  1.1  christos 
     48  1.1  christos   RSA key generation, encryption, decryption
     49  1.1  christos 
     50  1.1  christos     - Ssh uses the RSA routines in libssl.
     51  1.1  christos 
     52  1.1  christos   RSA key files
     53  1.1  christos 
     54  1.1  christos     - RSA keys are stored in files with a special format.  The code to
     55  1.1  christos       read/write these files is in authfile.c.  The files are normally
     56  1.1  christos       encrypted with a passphrase.  The functions to read passphrases
     57  1.1  christos       are in readpass.c (the same code is used to read passwords).
     58  1.1  christos 
     59  1.1  christos   Binary packet protocol
     60  1.1  christos 
     61  1.1  christos     - The ssh binary packet protocol is implemented in packet.c.  The
     62  1.1  christos       code in packet.c does not concern itself with packet types or their
     63  1.1  christos       execution; it contains code to build packets, to receive them and
     64  1.1  christos       extract data from them, and the code to compress and/or encrypt
     65  1.7  christos       packets.
     66  1.1  christos 
     67  1.1  christos     - The code in packet.c calls the buffer manipulation routines
     68  1.5  christos       (buffer.c, bufaux.c), compression routines (zlib), and the
     69  1.5  christos       encryption routines.
     70  1.1  christos 
     71  1.1  christos   X11, TCP/IP, and Agent forwarding
     72  1.1  christos 
     73  1.1  christos     - Code for various types of channel forwarding is in channels.c.
     74  1.1  christos       The file defines a generic framework for arbitrary communication
     75  1.1  christos       channels inside the secure channel, and uses this framework to
     76  1.1  christos       implement X11 forwarding, TCP/IP forwarding, and authentication
     77  1.1  christos       agent forwarding.
     78  1.1  christos       The new, Protocol 1.5, channel close implementation is in nchan.c
     79  1.1  christos 
     80  1.1  christos   Authentication agent
     81  1.1  christos 
     82  1.1  christos     - Code to communicate with the authentication agent is in authfd.c.
     83  1.1  christos 
     84  1.1  christos   Authentication methods
     85  1.1  christos 
     86  1.1  christos     - Code for various authentication methods resides in auth-*.c
     87  1.1  christos       (auth-passwd.c, auth-rh-rsa.c, auth-rhosts.c, auth-rsa.c).  This
     88  1.1  christos       code is linked into the server.  The routines also manipulate
     89  1.1  christos       known hosts files using code in hostfile.c.  Code in canohost.c
     90  1.1  christos       is used to retrieve the canonical host name of the remote host.
     91  1.1  christos       Code in match.c is used to match host names.
     92  1.1  christos 
     93  1.1  christos     - In the client end, authentication code is in sshconnect.c.  It
     94  1.1  christos       reads Passwords/passphrases using code in readpass.c.  It reads
     95  1.1  christos       RSA key files with authfile.c.  It communicates the
     96  1.1  christos       authentication agent using authfd.c.
     97  1.1  christos 
     98  1.1  christos   The ssh client
     99  1.1  christos 
    100  1.1  christos     - The client main program is in ssh.c.  It first parses arguments
    101  1.1  christos       and reads configuration (readconf.c), then calls ssh_connect (in
    102  1.1  christos       sshconnect.c) to open a connection to the server (possibly via a
    103  1.1  christos       proxy), and performs authentication (ssh_login in sshconnect.c).
    104  1.1  christos       It then makes any pty, forwarding, etc. requests.  It may call
    105  1.1  christos       code in ttymodes.c to encode current tty modes.  Finally it
    106  1.1  christos       calls client_loop in clientloop.c.  This does the real work for
    107  1.1  christos       the session.
    108  1.1  christos 
    109  1.1  christos   Pseudo-tty manipulation and tty modes
    110  1.1  christos 
    111  1.1  christos     - Code to allocate and use a pseudo tty is in pty.c.  Code to
    112  1.1  christos       encode and set terminal modes is in ttymodes.c.
    113  1.1  christos 
    114  1.1  christos   Logging in (updating utmp, lastlog, etc.)
    115  1.1  christos 
    116  1.1  christos     - The code to do things that are done when a user logs in are in
    117  1.1  christos       login.c.  This includes things such as updating the utmp, wtmp,
    118  1.1  christos       and lastlog files.  Some of the code is in sshd.c.
    119  1.1  christos 
    120  1.1  christos   Writing to the system log and terminal
    121  1.1  christos 
    122  1.1  christos     - The programs use the functions fatal(), log(), debug(), error()
    123  1.1  christos       in many places to write messages to system log or user's
    124  1.1  christos       terminal.  The implementation that logs to system log is in
    125  1.1  christos       log-server.c; it is used in the server program.  The other
    126  1.1  christos       programs use an implementation that sends output to stderr; it
    127  1.1  christos       is in log-client.c.  The definitions are in ssh.h.
    128  1.1  christos 
    129  1.1  christos   The sshd server (daemon)
    130  1.1  christos 
    131  1.1  christos     - The sshd daemon starts by processing arguments and reading the
    132  1.1  christos       configuration file (servconf.c).  It then reads the host key,
    133  1.1  christos       starts listening for connections, and generates the server key.
    134  1.1  christos       The server key will be regenerated every hour by an alarm.
    135  1.1  christos 
    136  1.1  christos     - When the server receives a connection, it forks, disables the
    137  1.1  christos       regeneration alarm, and starts communicating with the client.
    138  1.1  christos       They first perform identification string exchange, then
    139  1.1  christos       negotiate encryption, then perform authentication, preparatory
    140  1.1  christos       operations, and finally the server enters the normal session
    141  1.1  christos       mode by calling server_loop in serverloop.c.  This does the real
    142  1.1  christos       work, calling functions in other modules.
    143  1.1  christos 
    144  1.1  christos     - The code for the server is in sshd.c.  It contains a lot of
    145  1.1  christos       stuff, including:
    146  1.1  christos 	- server main program
    147  1.1  christos 	- waiting for connections
    148  1.1  christos 	- processing new connection
    149  1.1  christos 	- authentication
    150  1.1  christos 	- preparatory operations
    151  1.1  christos 	- building up the execution environment for the user program
    152  1.1  christos 	- starting the user program.
    153  1.1  christos 
    154  1.1  christos   Auxiliary files
    155  1.1  christos 
    156  1.1  christos     - There are several other files in the distribution that contain
    157  1.1  christos       various auxiliary routines:
    158  1.1  christos 	ssh.h	     the main header file for ssh (various definitions)
    159  1.1  christos 	uidswap.c    uid-swapping
    160  1.1  christos 	xmalloc.c    "safe" malloc routines
    161  1.1  christos 
    162  1.8  christos $OpenBSD: OVERVIEW,v 1.15 2018/10/23 05:56:35 djm Exp $
    163  1.2  christos $NetBSD: OVERVIEW,v 1.8 2019/04/20 17:16:40 christos Exp $
    164