Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ssl_buffer.c 9.1 KiB

Factor out the buffering and low-level record code. This begins decoupling the transport from the SSL state machine. The buffering logic is hidden behind an opaque API. Fields like ssl->packet and ssl->packet_length are gone. ssl3_get_record and dtls1_get_record now call low-level tls_open_record and dtls_open_record functions that unpack a single record independent of who owns the buffer. Both may be called in-place. This removes ssl->rstate which was redundant with the buffer length. Future work will push the buffer up the stack until it is above the handshake. Then we can expose SSL_open and SSL_seal APIs which act like *_open_record but return a slightly larger enum due to other events being possible. Likewise the handshake state machine will be detached from its buffer. The existing SSL_read, SSL_write, etc., APIs will be implemented on top of SSL_open, etc., combined with ssl_read_buffer_* and ssl_write_buffer_*. (Which is why ssl_read_buffer_extend still tries to abstract between TLS's and DTLS's fairly different needs.) The new buffering logic does not support read-ahead (removed previously) since it lacks a memmove on ssl_read_buffer_discard for TLS, but this could be added if desired. The old buffering logic wasn't quite right anyway; it tried to avoid the memmove in some cases and could get stuck too far into the buffer and not accept records. (The only time the memmove is optional is in DTLS or if enough of the record header is available to know that the entire next record would fit in the buffer.) The new logic also now actually decrypts the ciphertext in-place again, rather than almost in-place when there's an explicit nonce/IV. (That accidentally switched in https://boringssl-review.googlesource.com/#/c/4792/; see 3d59e04bce96474099ba76786a2337e99ae14505.) BUG=468889 Change-Id: I403c1626253c46897f47c7ae93aeab1064b767b2 Reviewed-on: https://boringssl-review.googlesource.com/5715 Reviewed-by: Adam Langley <agl@google.com>
pirms 9 gadiem
Factor out the buffering and low-level record code. This begins decoupling the transport from the SSL state machine. The buffering logic is hidden behind an opaque API. Fields like ssl->packet and ssl->packet_length are gone. ssl3_get_record and dtls1_get_record now call low-level tls_open_record and dtls_open_record functions that unpack a single record independent of who owns the buffer. Both may be called in-place. This removes ssl->rstate which was redundant with the buffer length. Future work will push the buffer up the stack until it is above the handshake. Then we can expose SSL_open and SSL_seal APIs which act like *_open_record but return a slightly larger enum due to other events being possible. Likewise the handshake state machine will be detached from its buffer. The existing SSL_read, SSL_write, etc., APIs will be implemented on top of SSL_open, etc., combined with ssl_read_buffer_* and ssl_write_buffer_*. (Which is why ssl_read_buffer_extend still tries to abstract between TLS's and DTLS's fairly different needs.) The new buffering logic does not support read-ahead (removed previously) since it lacks a memmove on ssl_read_buffer_discard for TLS, but this could be added if desired. The old buffering logic wasn't quite right anyway; it tried to avoid the memmove in some cases and could get stuck too far into the buffer and not accept records. (The only time the memmove is optional is in DTLS or if enough of the record header is available to know that the entire next record would fit in the buffer.) The new logic also now actually decrypts the ciphertext in-place again, rather than almost in-place when there's an explicit nonce/IV. (That accidentally switched in https://boringssl-review.googlesource.com/#/c/4792/; see 3d59e04bce96474099ba76786a2337e99ae14505.) BUG=468889 Change-Id: I403c1626253c46897f47c7ae93aeab1064b767b2 Reviewed-on: https://boringssl-review.googlesource.com/5715 Reviewed-by: Adam Langley <agl@google.com>
pirms 9 gadiem
Factor out the buffering and low-level record code. This begins decoupling the transport from the SSL state machine. The buffering logic is hidden behind an opaque API. Fields like ssl->packet and ssl->packet_length are gone. ssl3_get_record and dtls1_get_record now call low-level tls_open_record and dtls_open_record functions that unpack a single record independent of who owns the buffer. Both may be called in-place. This removes ssl->rstate which was redundant with the buffer length. Future work will push the buffer up the stack until it is above the handshake. Then we can expose SSL_open and SSL_seal APIs which act like *_open_record but return a slightly larger enum due to other events being possible. Likewise the handshake state machine will be detached from its buffer. The existing SSL_read, SSL_write, etc., APIs will be implemented on top of SSL_open, etc., combined with ssl_read_buffer_* and ssl_write_buffer_*. (Which is why ssl_read_buffer_extend still tries to abstract between TLS's and DTLS's fairly different needs.) The new buffering logic does not support read-ahead (removed previously) since it lacks a memmove on ssl_read_buffer_discard for TLS, but this could be added if desired. The old buffering logic wasn't quite right anyway; it tried to avoid the memmove in some cases and could get stuck too far into the buffer and not accept records. (The only time the memmove is optional is in DTLS or if enough of the record header is available to know that the entire next record would fit in the buffer.) The new logic also now actually decrypts the ciphertext in-place again, rather than almost in-place when there's an explicit nonce/IV. (That accidentally switched in https://boringssl-review.googlesource.com/#/c/4792/; see 3d59e04bce96474099ba76786a2337e99ae14505.) BUG=468889 Change-Id: I403c1626253c46897f47c7ae93aeab1064b767b2 Reviewed-on: https://boringssl-review.googlesource.com/5715 Reviewed-by: Adam Langley <agl@google.com>
pirms 9 gadiem
Factor out the buffering and low-level record code. This begins decoupling the transport from the SSL state machine. The buffering logic is hidden behind an opaque API. Fields like ssl->packet and ssl->packet_length are gone. ssl3_get_record and dtls1_get_record now call low-level tls_open_record and dtls_open_record functions that unpack a single record independent of who owns the buffer. Both may be called in-place. This removes ssl->rstate which was redundant with the buffer length. Future work will push the buffer up the stack until it is above the handshake. Then we can expose SSL_open and SSL_seal APIs which act like *_open_record but return a slightly larger enum due to other events being possible. Likewise the handshake state machine will be detached from its buffer. The existing SSL_read, SSL_write, etc., APIs will be implemented on top of SSL_open, etc., combined with ssl_read_buffer_* and ssl_write_buffer_*. (Which is why ssl_read_buffer_extend still tries to abstract between TLS's and DTLS's fairly different needs.) The new buffering logic does not support read-ahead (removed previously) since it lacks a memmove on ssl_read_buffer_discard for TLS, but this could be added if desired. The old buffering logic wasn't quite right anyway; it tried to avoid the memmove in some cases and could get stuck too far into the buffer and not accept records. (The only time the memmove is optional is in DTLS or if enough of the record header is available to know that the entire next record would fit in the buffer.) The new logic also now actually decrypts the ciphertext in-place again, rather than almost in-place when there's an explicit nonce/IV. (That accidentally switched in https://boringssl-review.googlesource.com/#/c/4792/; see 3d59e04bce96474099ba76786a2337e99ae14505.) BUG=468889 Change-Id: I403c1626253c46897f47c7ae93aeab1064b767b2 Reviewed-on: https://boringssl-review.googlesource.com/5715 Reviewed-by: Adam Langley <agl@google.com>
pirms 9 gadiem
Factor out the buffering and low-level record code. This begins decoupling the transport from the SSL state machine. The buffering logic is hidden behind an opaque API. Fields like ssl->packet and ssl->packet_length are gone. ssl3_get_record and dtls1_get_record now call low-level tls_open_record and dtls_open_record functions that unpack a single record independent of who owns the buffer. Both may be called in-place. This removes ssl->rstate which was redundant with the buffer length. Future work will push the buffer up the stack until it is above the handshake. Then we can expose SSL_open and SSL_seal APIs which act like *_open_record but return a slightly larger enum due to other events being possible. Likewise the handshake state machine will be detached from its buffer. The existing SSL_read, SSL_write, etc., APIs will be implemented on top of SSL_open, etc., combined with ssl_read_buffer_* and ssl_write_buffer_*. (Which is why ssl_read_buffer_extend still tries to abstract between TLS's and DTLS's fairly different needs.) The new buffering logic does not support read-ahead (removed previously) since it lacks a memmove on ssl_read_buffer_discard for TLS, but this could be added if desired. The old buffering logic wasn't quite right anyway; it tried to avoid the memmove in some cases and could get stuck too far into the buffer and not accept records. (The only time the memmove is optional is in DTLS or if enough of the record header is available to know that the entire next record would fit in the buffer.) The new logic also now actually decrypts the ciphertext in-place again, rather than almost in-place when there's an explicit nonce/IV. (That accidentally switched in https://boringssl-review.googlesource.com/#/c/4792/; see 3d59e04bce96474099ba76786a2337e99ae14505.) BUG=468889 Change-Id: I403c1626253c46897f47c7ae93aeab1064b767b2 Reviewed-on: https://boringssl-review.googlesource.com/5715 Reviewed-by: Adam Langley <agl@google.com>
pirms 9 gadiem
Factor out the buffering and low-level record code. This begins decoupling the transport from the SSL state machine. The buffering logic is hidden behind an opaque API. Fields like ssl->packet and ssl->packet_length are gone. ssl3_get_record and dtls1_get_record now call low-level tls_open_record and dtls_open_record functions that unpack a single record independent of who owns the buffer. Both may be called in-place. This removes ssl->rstate which was redundant with the buffer length. Future work will push the buffer up the stack until it is above the handshake. Then we can expose SSL_open and SSL_seal APIs which act like *_open_record but return a slightly larger enum due to other events being possible. Likewise the handshake state machine will be detached from its buffer. The existing SSL_read, SSL_write, etc., APIs will be implemented on top of SSL_open, etc., combined with ssl_read_buffer_* and ssl_write_buffer_*. (Which is why ssl_read_buffer_extend still tries to abstract between TLS's and DTLS's fairly different needs.) The new buffering logic does not support read-ahead (removed previously) since it lacks a memmove on ssl_read_buffer_discard for TLS, but this could be added if desired. The old buffering logic wasn't quite right anyway; it tried to avoid the memmove in some cases and could get stuck too far into the buffer and not accept records. (The only time the memmove is optional is in DTLS or if enough of the record header is available to know that the entire next record would fit in the buffer.) The new logic also now actually decrypts the ciphertext in-place again, rather than almost in-place when there's an explicit nonce/IV. (That accidentally switched in https://boringssl-review.googlesource.com/#/c/4792/; see 3d59e04bce96474099ba76786a2337e99ae14505.) BUG=468889 Change-Id: I403c1626253c46897f47c7ae93aeab1064b767b2 Reviewed-on: https://boringssl-review.googlesource.com/5715 Reviewed-by: Adam Langley <agl@google.com>
pirms 9 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /* Copyright (c) 2015, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #include <openssl/ssl.h>
  15. #include <assert.h>
  16. #include <limits.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <openssl/bio.h>
  20. #include <openssl/err.h>
  21. #include <openssl/mem.h>
  22. #include <openssl/type_check.h>
  23. #include "internal.h"
  24. OPENSSL_COMPILE_ASSERT(0xffff <= INT_MAX, uint16_fits_in_int);
  25. OPENSSL_COMPILE_ASSERT((SSL3_ALIGN_PAYLOAD & (SSL3_ALIGN_PAYLOAD - 1)) == 0,
  26. align_to_a_power_of_two);
  27. /* setup_buffer initializes |buf| with capacity |cap|, aligned such that data
  28. * written after |header_len| is aligned to a |SSL3_ALIGN_PAYLOAD|-byte
  29. * boundary. It returns one on success and zero on error. */
  30. static int setup_buffer(SSL3_BUFFER *buf, size_t header_len, size_t cap) {
  31. if (buf->buf != NULL || cap > 0xffff) {
  32. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  33. return 0;
  34. }
  35. /* Add up to |SSL3_ALIGN_PAYLOAD| - 1 bytes of slack for alignment. */
  36. buf->buf = OPENSSL_malloc(cap + SSL3_ALIGN_PAYLOAD - 1);
  37. if (buf->buf == NULL) {
  38. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  39. return 0;
  40. }
  41. /* Arrange the buffer such that the record body is aligned. */
  42. buf->offset = (0 - header_len - (uintptr_t)buf->buf) &
  43. (SSL3_ALIGN_PAYLOAD - 1);
  44. buf->len = 0;
  45. buf->cap = cap;
  46. return 1;
  47. }
  48. static void consume_buffer(SSL3_BUFFER *buf, size_t len) {
  49. if (len > buf->len) {
  50. abort();
  51. }
  52. buf->offset += (uint16_t)len;
  53. buf->len -= (uint16_t)len;
  54. buf->cap -= (uint16_t)len;
  55. }
  56. static void clear_buffer(SSL3_BUFFER *buf) {
  57. OPENSSL_free(buf->buf);
  58. memset(buf, 0, sizeof(SSL3_BUFFER));
  59. }
  60. OPENSSL_COMPILE_ASSERT(DTLS1_RT_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH +
  61. SSL3_RT_MAX_EXTRA <= 0xffff,
  62. maximum_read_buffer_too_large);
  63. /* setup_read_buffer initializes the read buffer if not already initialized. It
  64. * returns one on success and zero on failure. */
  65. static int setup_read_buffer(SSL *ssl) {
  66. SSL3_BUFFER *buf = &ssl->s3->read_buffer;
  67. if (buf->buf != NULL) {
  68. return 1;
  69. }
  70. size_t header_len = ssl_record_prefix_len(ssl);
  71. size_t cap = SSL3_RT_MAX_ENCRYPTED_LENGTH;
  72. if (SSL_IS_DTLS(ssl)) {
  73. cap += DTLS1_RT_HEADER_LENGTH;
  74. } else {
  75. cap += SSL3_RT_HEADER_LENGTH;
  76. }
  77. if (ssl->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) {
  78. cap += SSL3_RT_MAX_EXTRA;
  79. }
  80. return setup_buffer(buf, header_len, cap);
  81. }
  82. uint8_t *ssl_read_buffer(SSL *ssl) {
  83. return ssl->s3->read_buffer.buf + ssl->s3->read_buffer.offset;
  84. }
  85. size_t ssl_read_buffer_len(const SSL *ssl) {
  86. return ssl->s3->read_buffer.len;
  87. }
  88. static int dtls_read_buffer_next_packet(SSL *ssl) {
  89. SSL3_BUFFER *buf = &ssl->s3->read_buffer;
  90. if (buf->len > 0) {
  91. /* It is an error to call |dtls_read_buffer_extend| when the read buffer is
  92. * not empty. */
  93. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  94. return -1;
  95. }
  96. /* Read a single packet from |ssl->rbio|. |buf->cap| must fit in an int. */
  97. ssl->rwstate = SSL_READING;
  98. int ret = BIO_read(ssl->rbio, buf->buf + buf->offset, (int)buf->cap);
  99. if (ret <= 0) {
  100. return ret;
  101. }
  102. ssl->rwstate = SSL_NOTHING;
  103. /* |BIO_read| was bound by |buf->cap|, so this cannot overflow. */
  104. buf->len = (uint16_t)ret;
  105. return 1;
  106. }
  107. static int tls_read_buffer_extend_to(SSL *ssl, size_t len) {
  108. SSL3_BUFFER *buf = &ssl->s3->read_buffer;
  109. if (len > buf->cap) {
  110. /* This may occur if |SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER| was toggled after
  111. * |setup_read_buffer| was called. Stay within bounds, but do not attempt to
  112. * recover. */
  113. OPENSSL_PUT_ERROR(SSL, SSL_R_BUFFER_TOO_SMALL);
  114. return -1;
  115. }
  116. /* Read until the target length is reached. */
  117. while (buf->len < len) {
  118. /* The amount of data to read is bounded by |buf->cap|, which must fit in an
  119. * int. */
  120. ssl->rwstate = SSL_READING;
  121. int ret = BIO_read(ssl->rbio, buf->buf + buf->offset + buf->len,
  122. (int)(len - buf->len));
  123. if (ret <= 0) {
  124. return ret;
  125. }
  126. ssl->rwstate = SSL_NOTHING;
  127. /* |BIO_read| was bound by |buf->cap - buf->len|, so this cannot
  128. * overflow. */
  129. buf->len += (uint16_t)ret;
  130. }
  131. return 1;
  132. }
  133. int ssl_read_buffer_extend_to(SSL *ssl, size_t len) {
  134. /* |ssl_read_buffer_extend_to| implicitly discards any consumed data. */
  135. ssl_read_buffer_discard(ssl);
  136. if (!setup_read_buffer(ssl)) {
  137. return -1;
  138. }
  139. if (ssl->rbio == NULL) {
  140. OPENSSL_PUT_ERROR(SSL, SSL_R_BIO_NOT_SET);
  141. return -1;
  142. }
  143. ERR_clear_system_error();
  144. int ret;
  145. if (SSL_IS_DTLS(ssl)) {
  146. /* |len| is ignored for a datagram transport. */
  147. ret = dtls_read_buffer_next_packet(ssl);
  148. } else {
  149. ret = tls_read_buffer_extend_to(ssl, len);
  150. }
  151. if (ret <= 0) {
  152. /* If the buffer was empty originally and remained empty after attempting to
  153. * extend it, release the buffer until the next attempt. */
  154. ssl_read_buffer_discard(ssl);
  155. }
  156. return ret;
  157. }
  158. void ssl_read_buffer_consume(SSL *ssl, size_t len) {
  159. SSL3_BUFFER *buf = &ssl->s3->read_buffer;
  160. consume_buffer(buf, len);
  161. if (!SSL_IS_DTLS(ssl)) {
  162. /* The TLS stack never reads beyond the current record, so there will never
  163. * be unconsumed data. If read-ahead is ever reimplemented,
  164. * |ssl_read_buffer_discard| will require a |memcpy| to shift the excess
  165. * back to the front of the buffer, to ensure there is enough space for the
  166. * next record. */
  167. assert(buf->len == 0);
  168. }
  169. }
  170. void ssl_read_buffer_discard(SSL *ssl) {
  171. if (ssl->s3->read_buffer.len == 0) {
  172. ssl_read_buffer_clear(ssl);
  173. }
  174. }
  175. void ssl_read_buffer_clear(SSL *ssl) {
  176. clear_buffer(&ssl->s3->read_buffer);
  177. }
  178. int ssl_write_buffer_is_pending(const SSL *ssl) {
  179. return ssl->s3->write_buffer.len > 0;
  180. }
  181. OPENSSL_COMPILE_ASSERT(SSL3_RT_HEADER_LENGTH * 2 +
  182. SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD * 2 +
  183. SSL3_RT_MAX_PLAIN_LENGTH <= 0xffff,
  184. maximum_tls_write_buffer_too_large);
  185. OPENSSL_COMPILE_ASSERT(DTLS1_RT_HEADER_LENGTH +
  186. SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD +
  187. SSL3_RT_MAX_PLAIN_LENGTH <= 0xffff,
  188. maximum_dtls_write_buffer_too_large);
  189. int ssl_write_buffer_init(SSL *ssl, uint8_t **out_ptr, size_t max_len) {
  190. SSL3_BUFFER *buf = &ssl->s3->write_buffer;
  191. if (buf->buf != NULL) {
  192. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  193. return 0;
  194. }
  195. size_t header_len = ssl_seal_prefix_len(ssl);
  196. /* TODO(davidben): This matches the original behavior in keeping the malloc
  197. * size consistent. Does this matter? |cap| could just be |max_len|. */
  198. size_t cap = SSL3_RT_MAX_PLAIN_LENGTH + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
  199. if (SSL_IS_DTLS(ssl)) {
  200. cap += DTLS1_RT_HEADER_LENGTH;
  201. } else {
  202. cap += SSL3_RT_HEADER_LENGTH;
  203. if (ssl->mode & SSL_MODE_CBC_RECORD_SPLITTING) {
  204. cap += SSL3_RT_HEADER_LENGTH + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
  205. }
  206. }
  207. if (max_len > cap) {
  208. OPENSSL_PUT_ERROR(SSL, SSL_R_BUFFER_TOO_SMALL);
  209. return 0;
  210. }
  211. if (!setup_buffer(buf, header_len, cap)) {
  212. return 0;
  213. }
  214. *out_ptr = buf->buf + buf->offset;
  215. return 1;
  216. }
  217. void ssl_write_buffer_set_len(SSL *ssl, size_t len) {
  218. SSL3_BUFFER *buf = &ssl->s3->write_buffer;
  219. if (len > buf->cap) {
  220. abort();
  221. }
  222. buf->len = len;
  223. }
  224. static int tls_write_buffer_flush(SSL *ssl) {
  225. SSL3_BUFFER *buf = &ssl->s3->write_buffer;
  226. while (buf->len > 0) {
  227. ssl->rwstate = SSL_WRITING;
  228. int ret = BIO_write(ssl->wbio, buf->buf + buf->offset, buf->len);
  229. if (ret <= 0) {
  230. return ret;
  231. }
  232. ssl->rwstate = SSL_NOTHING;
  233. consume_buffer(buf, (size_t)ret);
  234. }
  235. ssl_write_buffer_clear(ssl);
  236. return 1;
  237. }
  238. static int dtls_write_buffer_flush(SSL *ssl) {
  239. SSL3_BUFFER *buf = &ssl->s3->write_buffer;
  240. if (buf->len == 0) {
  241. return 1;
  242. }
  243. ssl->rwstate = SSL_WRITING;
  244. int ret = BIO_write(ssl->wbio, buf->buf + buf->offset, buf->len);
  245. if (ret <= 0) {
  246. /* If the write failed, drop the write buffer anyway. Datagram transports
  247. * can't write half a packet, so the caller is expected to retry from the
  248. * top. */
  249. ssl_write_buffer_clear(ssl);
  250. return ret;
  251. }
  252. ssl->rwstate = SSL_NOTHING;
  253. ssl_write_buffer_clear(ssl);
  254. return 1;
  255. }
  256. int ssl_write_buffer_flush(SSL *ssl) {
  257. if (ssl->wbio == NULL) {
  258. OPENSSL_PUT_ERROR(SSL, SSL_R_BIO_NOT_SET);
  259. return -1;
  260. }
  261. ERR_clear_system_error();
  262. if (SSL_IS_DTLS(ssl)) {
  263. return dtls_write_buffer_flush(ssl);
  264. } else {
  265. return tls_write_buffer_flush(ssl);
  266. }
  267. }
  268. void ssl_write_buffer_clear(SSL *ssl) {
  269. clear_buffer(&ssl->s3->write_buffer);
  270. }