2
0

statem.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /*****************************************************************************
  10. * *
  11. * These enums should be considered PRIVATE to the state machine. No *
  12. * non-state machine code should need to use these *
  13. * *
  14. *****************************************************************************/
  15. /*
  16. * Valid return codes used for functions performing work prior to or after
  17. * sending or receiving a message
  18. */
  19. typedef enum {
  20. /* Something went wrong */
  21. WORK_ERROR,
  22. /* We're done working and there shouldn't be anything else to do after */
  23. WORK_FINISHED_STOP,
  24. /* We're done working move onto the next thing */
  25. WORK_FINISHED_CONTINUE,
  26. /* We're working on phase A */
  27. WORK_MORE_A,
  28. /* We're working on phase B */
  29. WORK_MORE_B,
  30. /* We're working on phase C */
  31. WORK_MORE_C
  32. } WORK_STATE;
  33. /* Write transition return codes */
  34. typedef enum {
  35. /* Something went wrong */
  36. WRITE_TRAN_ERROR,
  37. /* A transition was successfully completed and we should continue */
  38. WRITE_TRAN_CONTINUE,
  39. /* There is no more write work to be done */
  40. WRITE_TRAN_FINISHED
  41. } WRITE_TRAN;
  42. /* Message flow states */
  43. typedef enum {
  44. /* No handshake in progress */
  45. MSG_FLOW_UNINITED,
  46. /* A permanent error with this connection */
  47. MSG_FLOW_ERROR,
  48. /* We are reading messages */
  49. MSG_FLOW_READING,
  50. /* We are writing messages */
  51. MSG_FLOW_WRITING,
  52. /* Handshake has finished */
  53. MSG_FLOW_FINISHED
  54. } MSG_FLOW_STATE;
  55. /* Read states */
  56. typedef enum {
  57. READ_STATE_HEADER,
  58. READ_STATE_BODY,
  59. READ_STATE_POST_PROCESS
  60. } READ_STATE;
  61. /* Write states */
  62. typedef enum {
  63. WRITE_STATE_TRANSITION,
  64. WRITE_STATE_PRE_WORK,
  65. WRITE_STATE_SEND,
  66. WRITE_STATE_POST_WORK
  67. } WRITE_STATE;
  68. /*****************************************************************************
  69. * *
  70. * This structure should be considered "opaque" to anything outside of the *
  71. * state machine. No non-state machine code should be accessing the members *
  72. * of this structure. *
  73. * *
  74. *****************************************************************************/
  75. struct ossl_statem_st {
  76. MSG_FLOW_STATE state;
  77. WRITE_STATE write_state;
  78. WORK_STATE write_state_work;
  79. READ_STATE read_state;
  80. WORK_STATE read_state_work;
  81. OSSL_HANDSHAKE_STATE hand_state;
  82. /* The handshake state requested by an API call (e.g. HelloRequest) */
  83. OSSL_HANDSHAKE_STATE request_state;
  84. int in_init;
  85. int read_state_first_init;
  86. /* true when we are actually in SSL_accept() or SSL_connect() */
  87. int in_handshake;
  88. /*
  89. * True when are processing a "real" handshake that needs cleaning up (not
  90. * just a HelloRequest or similar).
  91. */
  92. int cleanuphand;
  93. /* Should we skip the CertificateVerify message? */
  94. unsigned int no_cert_verify;
  95. int use_timer;
  96. int invalid_enc_write_ctx;
  97. };
  98. typedef struct ossl_statem_st OSSL_STATEM;
  99. /*****************************************************************************
  100. * *
  101. * The following macros/functions represent the libssl internal API to the *
  102. * state machine. Any libssl code may call these functions/macros *
  103. * *
  104. *****************************************************************************/
  105. __owur int ossl_statem_accept(SSL *s);
  106. __owur int ossl_statem_connect(SSL *s);
  107. void ossl_statem_clear(SSL *s);
  108. void ossl_statem_set_renegotiate(SSL *s);
  109. void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,
  110. int line);
  111. # define SSL_AD_NO_ALERT -1
  112. # ifndef OPENSSL_NO_ERR
  113. # define SSLfatal(s, al, f, r) ossl_statem_fatal((s), (al), (f), (r), \
  114. OPENSSL_FILE, OPENSSL_LINE)
  115. # else
  116. # define SSLfatal(s, al, f, r) ossl_statem_fatal((s), (al), (f), (r), NULL, 0)
  117. # endif
  118. int ossl_statem_in_error(const SSL *s);
  119. void ossl_statem_set_in_init(SSL *s, int init);
  120. int ossl_statem_get_in_handshake(SSL *s);
  121. void ossl_statem_set_in_handshake(SSL *s, int inhand);
  122. __owur int ossl_statem_skip_early_data(SSL *s);
  123. void ossl_statem_check_finish_init(SSL *s, int send);
  124. void ossl_statem_set_hello_verify_done(SSL *s);
  125. __owur int ossl_statem_app_data_allowed(SSL *s);
  126. __owur int ossl_statem_export_allowed(SSL *s);
  127. __owur int ossl_statem_export_early_allowed(SSL *s);
  128. /* Flush the write BIO */
  129. int statem_flush(SSL *s);