Blame ssl/record/README

Packit c4476c
Record Layer Design
Packit c4476c
===================
Packit c4476c
Packit c4476c
This file provides some guidance on the thinking behind the design of the
Packit c4476c
record layer code to aid future maintenance.
Packit c4476c
Packit c4476c
The record layer is divided into a number of components. At the time of writing
Packit c4476c
there are four: SSL3_RECORD, SSL3_BUFFER, DLTS1_BITMAP and RECORD_LAYER. Each
Packit c4476c
of these components is defined by:
Packit c4476c
1) A struct definition of the same name as the component
Packit c4476c
2) A set of source files that define the functions for that component
Packit c4476c
3) A set of accessor macros
Packit c4476c
Packit c4476c
All struct definitions are in record.h. The functions and macros are either
Packit c4476c
defined in record.h or record_local.h dependent on whether they are intended to
Packit c4476c
be private to the record layer, or whether they form part of the API to the rest
Packit c4476c
of libssl.
Packit c4476c
Packit c4476c
The source files map to components as follows:
Packit c4476c
Packit c4476c
dtls1_bitmap.c                                   -> DTLS1_BITMAP component
Packit c4476c
ssl3_buffer.c                                    -> SSL3_BUFFER component
Packit c4476c
ssl3_record.c                                    -> SSL3_RECORD component
Packit c4476c
rec_layer_s3.c, rec_layer_d1.c                   -> RECORD_LAYER component
Packit c4476c
Packit c4476c
The RECORD_LAYER component is a facade pattern, i.e. it provides a simplified
Packit c4476c
interface to the record layer for the rest of libssl. The other 3 components are
Packit c4476c
entirely private to the record layer and therefore should never be accessed
Packit c4476c
directly by libssl.
Packit c4476c
Packit c4476c
Any component can directly access its own members - they are private to that
Packit c4476c
component, e.g. ssl3_buffer.c can access members of the SSL3_BUFFER struct
Packit c4476c
without using a macro. No component can directly access the members of another
Packit c4476c
component, e.g. ssl3_buffer cannot reach inside the RECORD_LAYER component to
Packit c4476c
directly access its members. Instead components use accessor macros, so if code
Packit c4476c
in ssl3_buffer.c wants to access the members of the RECORD_LAYER it uses the
Packit c4476c
RECORD_LAYER_* macros.
Packit c4476c
Packit c4476c
Conceptually it looks like this:
Packit c4476c
Packit c4476c
                        libssl
Packit c4476c
                           |
Packit c4476c
---------------------------|-----record.h--------------------------------------
Packit c4476c
                           |
Packit c4476c
                    _______V______________
Packit c4476c
                   |                      |
Packit c4476c
                   |    RECORD_LAYER      |
Packit c4476c
                   |                      |
Packit c4476c
                   |    rec_layer_s3.c    |
Packit c4476c
                   |          ^           |
Packit c4476c
                   | _________|__________ |
Packit c4476c
                   ||                    ||
Packit c4476c
                   || DTLS1_RECORD_LAYER ||
Packit c4476c
                   ||                    ||
Packit c4476c
                   || rec_layer_d1.c     ||
Packit c4476c
                   ||____________________||
Packit c4476c
                   |______________________|
Packit c4476c
        record_local.h     ^   ^   ^
Packit c4476c
         _________________|   |   |_________________
Packit c4476c
        |                     |                     |
Packit c4476c
   _____V_________      ______V________      _______V________
Packit c4476c
  |               |    |               |    |                |
Packit c4476c
  | SSL3_BUFFER   |    | SSL3_RECORD   |    | DTLS1_BITMAP   |
Packit c4476c
  |               |--->|               |    |                |
Packit c4476c
  | ssl3_buffer.c |    | ssl3_record.c |    | dtls1_bitmap.c |
Packit c4476c
  |_______________|    |_______________|    |________________|
Packit c4476c
Packit c4476c
Packit c4476c
The two RECORD_LAYER source files build on each other, i.e.
Packit c4476c
the main one is rec_layer_s3.c which provides the core SSL/TLS layer. The second
Packit c4476c
one is rec_layer_d1.c which builds off of the SSL/TLS code to provide DTLS
Packit c4476c
specific capabilities. It uses some DTLS specific RECORD_LAYER component members
Packit c4476c
which should only be accessed from rec_layer_d1.c. These are held in the
Packit c4476c
DTLS1_RECORD_LAYER struct.