2
0

README 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. State Machine Design
  2. ====================
  3. This file provides some guidance on the thinking behind the design of the
  4. state machine code to aid future maintenance.
  5. The state machine code replaces an older state machine present in OpenSSL
  6. versions 1.0.2 and below. The new state machine has the following objectives:
  7. - Remove duplication of state code between client and server
  8. - Remove duplication of state code between TLS and DTLS
  9. - Simplify transitions and bring the logic together in a single location
  10. so that it is easier to validate
  11. - Remove duplication of code between each of the message handling functions
  12. - Receive a message first and then work out whether that is a valid
  13. transition - not the other way around (the other way causes lots of issues
  14. where we are expecting one type of message next but actually get something
  15. else)
  16. - Separate message flow state from handshake state (in order to better
  17. understand each)
  18. - message flow state = when to flush buffers; handling restarts in the
  19. event of NBIO events; handling the common flow of steps for reading a
  20. message and the common flow of steps for writing a message etc
  21. - handshake state = what handshake message are we working on now
  22. - Control complexity: only the state machine can change state: keep all
  23. the state changes local to the state machine component
  24. The message flow state machine is divided into a reading sub-state machine and a
  25. writing sub-state machine. See the source comments in statem.c for a more
  26. detailed description of the various states and transitions possible.
  27. Conceptually the state machine component is designed as follows:
  28. libssl
  29. |
  30. ---------------------------|-----statem.h--------------------------------------
  31. |
  32. _______V____________________
  33. | |
  34. | statem.c |
  35. | |
  36. | Core state machine code |
  37. |____________________________|
  38. statem_locl.h ^ ^
  39. _________| |_______
  40. | |
  41. _____________|____________ _____________|____________
  42. | | | |
  43. | statem_clnt.c | | statem_srvr.c |
  44. | | | |
  45. | TLS/DTLS client specific | | TLS/DTLS server specific |
  46. | state machine code | | state machine code |
  47. |__________________________| |__________________________|
  48. | |_______________|__ |
  49. | ________________| | |
  50. | | | |
  51. ____________V_______V________ ________V______V_______________
  52. | | | |
  53. | statem_both.c | | statem_dtls.c |
  54. | | | |
  55. | Non core functions common | | Non core functions common to |
  56. | to both servers and clients | | both DTLS servers and clients |
  57. |_____________________________| |_______________________________|