1e1051a39Sopenharmony_ciRecord Layer Design 2e1051a39Sopenharmony_ci=================== 3e1051a39Sopenharmony_ci 4e1051a39Sopenharmony_ciThis file provides some guidance on the thinking behind the design of the 5e1051a39Sopenharmony_cirecord layer code to aid future maintenance. 6e1051a39Sopenharmony_ci 7e1051a39Sopenharmony_ciThe record layer is divided into a number of components. At the time of writing 8e1051a39Sopenharmony_cithere are four: SSL3_RECORD, SSL3_BUFFER, DLTS1_BITMAP and RECORD_LAYER. Each 9e1051a39Sopenharmony_ciof these components is defined by: 10e1051a39Sopenharmony_ci1) A struct definition of the same name as the component 11e1051a39Sopenharmony_ci2) A set of source files that define the functions for that component 12e1051a39Sopenharmony_ci3) A set of accessor macros 13e1051a39Sopenharmony_ci 14e1051a39Sopenharmony_ciAll struct definitions are in record.h. The functions and macros are either 15e1051a39Sopenharmony_cidefined in record.h or record_local.h dependent on whether they are intended to 16e1051a39Sopenharmony_cibe private to the record layer, or whether they form part of the API to the rest 17e1051a39Sopenharmony_ciof libssl. 18e1051a39Sopenharmony_ci 19e1051a39Sopenharmony_ciThe source files map to components as follows: 20e1051a39Sopenharmony_ci 21e1051a39Sopenharmony_ci dtls1_bitmap.c -> DTLS1_BITMAP component 22e1051a39Sopenharmony_ci ssl3_buffer.c -> SSL3_BUFFER component 23e1051a39Sopenharmony_ci ssl3_record.c -> SSL3_RECORD component 24e1051a39Sopenharmony_ci rec_layer_s3.c, rec_layer_d1.c -> RECORD_LAYER component 25e1051a39Sopenharmony_ci 26e1051a39Sopenharmony_ciThe RECORD_LAYER component is a facade pattern, i.e. it provides a simplified 27e1051a39Sopenharmony_ciinterface to the record layer for the rest of libssl. The other 3 components are 28e1051a39Sopenharmony_cientirely private to the record layer and therefore should never be accessed 29e1051a39Sopenharmony_cidirectly by libssl. 30e1051a39Sopenharmony_ci 31e1051a39Sopenharmony_ciAny component can directly access its own members - they are private to that 32e1051a39Sopenharmony_cicomponent, e.g. ssl3_buffer.c can access members of the SSL3_BUFFER struct 33e1051a39Sopenharmony_ciwithout using a macro. No component can directly access the members of another 34e1051a39Sopenharmony_cicomponent, e.g. ssl3_buffer cannot reach inside the RECORD_LAYER component to 35e1051a39Sopenharmony_cidirectly access its members. Instead components use accessor macros, so if code 36e1051a39Sopenharmony_ciin ssl3_buffer.c wants to access the members of the RECORD_LAYER it uses the 37e1051a39Sopenharmony_ciRECORD_LAYER_* macros. 38e1051a39Sopenharmony_ci 39e1051a39Sopenharmony_ciConceptually it looks like this: 40e1051a39Sopenharmony_ci 41e1051a39Sopenharmony_ci libssl 42e1051a39Sopenharmony_ci | 43e1051a39Sopenharmony_ci -------------------------|-----record.h------------------------------------ 44e1051a39Sopenharmony_ci | 45e1051a39Sopenharmony_ci _______V______________ 46e1051a39Sopenharmony_ci | | 47e1051a39Sopenharmony_ci | RECORD_LAYER | 48e1051a39Sopenharmony_ci | | 49e1051a39Sopenharmony_ci | rec_layer_s3.c | 50e1051a39Sopenharmony_ci | ^ | 51e1051a39Sopenharmony_ci | _________|__________ | 52e1051a39Sopenharmony_ci || || 53e1051a39Sopenharmony_ci || DTLS1_RECORD_LAYER || 54e1051a39Sopenharmony_ci || || 55e1051a39Sopenharmony_ci || rec_layer_d1.c || 56e1051a39Sopenharmony_ci ||____________________|| 57e1051a39Sopenharmony_ci |______________________| 58e1051a39Sopenharmony_ci record_local.h ^ ^ ^ 59e1051a39Sopenharmony_ci _________________| | |_________________ 60e1051a39Sopenharmony_ci | | | 61e1051a39Sopenharmony_ci _____V_________ ______V________ _______V________ 62e1051a39Sopenharmony_ci | | | | | | 63e1051a39Sopenharmony_ci | SSL3_BUFFER | | SSL3_RECORD | | DTLS1_BITMAP | 64e1051a39Sopenharmony_ci | |--->| | | | 65e1051a39Sopenharmony_ci | ssl3_buffer.c | | ssl3_record.c | | dtls1_bitmap.c | 66e1051a39Sopenharmony_ci |_______________| |_______________| |________________| 67e1051a39Sopenharmony_ci 68e1051a39Sopenharmony_ciThe two RECORD_LAYER source files build on each other, i.e. 69e1051a39Sopenharmony_cithe main one is rec_layer_s3.c which provides the core SSL/TLS layer. The second 70e1051a39Sopenharmony_cione is rec_layer_d1.c which builds off of the SSL/TLS code to provide DTLS 71e1051a39Sopenharmony_cispecific capabilities. It uses some DTLS specific RECORD_LAYER component members 72e1051a39Sopenharmony_ciwhich should only be accessed from rec_layer_d1.c. These are held in the 73e1051a39Sopenharmony_ciDTLS1_RECORD_LAYER struct. 74