15 Commits

Author SHA1 Message Date
Azat Khuzhin
5412b2c30d bufferevent_ssl: fix freeing ctx in case of error in bufferevent_ssl_new_impl 2024-02-18 19:51:21 +01:00
Azat Khuzhin
c9793baa87 bufferevent_ssl: proper NULL checks 2024-02-18 19:49:44 +01:00
Azat Khuzhin
2f27523e44 bufferevent_ssl: do not return NULL from upcast
/src/le/libevent/bufferevent_ssl.c:863: error: Null Dereference
      pointer `bev_ssl` last assigned on line 855 could be null and is dereferenced at line 863, column 6.
      861.          r2 = start_writing(bev_ssl);
      862.
      863.  if (bev_ssl->underlying) {
                ^
      864.          if (events & EV_READ)
      865.                  BEV_RESET_GENERIC_READ_TIMEOUT(bev);
2024-02-18 19:49:44 +01:00
Azat Khuzhin
49a7ae4c56 ssl: add some comments for lack of notify_close 2023-05-16 21:20:35 +02:00
Thuan Tran
ef51444f43 More SSL_read() to fill big buffer
Once SSL_read() only get max 16K bytes (one TLS record).
In case of big buffer, should more SSL_read() to fill the buffer.

Using sample https-client to measure max income MBit/s via nload tool.
Note: set bufferevent_set_max_single_read() by 32K and add the chunk
callback to read out each piece of data.

The client sample do https request a data 900KB (the server don't use
Transfer-Encoding: chunked)
- With origin/master: max income is 2.26 MBit/s
  The chunk callback never get a piece of data > 16K.
- With this PR: max income is 2.44 MBit/s
  The chunk callback can get some piece of data 32K or more.
2023-05-16 21:11:54 +02:00
Thuan Tran
4ab3242da1 Make bufferevent_set_max_single_read() effect 2023-05-16 21:11:54 +02:00
Azat Khuzhin
7652cf4068 ssl: do not triger EOF if some data had been successfully read
Previously in case when evbuffer_reserve_space() returns > 1, but
it was able to read only 1 IO vector, it will try to read the next one,
got 0 (EOF for mbedTLS or SSL_ERROR_ZERO_RETURN for OpenSSL) and will
trigger EOF, while instead, it should trigger EV_READ w/o EOF and only
after EOF.
2023-05-14 16:53:13 +02:00
Azat Khuzhin
6375dcb46d ssl: rename err_is_ok to handshake_is_ok (internal API) 2023-05-14 16:49:18 +02:00
zhenhaonong
fc568ff045 Deal with partial writes on SSL write
SSL write may do partial writes in some cases. For example, document
of mbedtls_ssl_write says:
  If the return value is non-negative but less than length, the function
  must be called again with updated arguments: buf + ret, len - ret
  (if ret is the return value) until it returns a value equal to the
  last 'len' argument.

In case of partial writes, we should continue writing the same chain of
buffer, not the next chain.
2023-03-29 06:19:10 +02:00
Azat Khuzhin
41b5ab0f49 bufferevent_ssl: check return value of the evbuffer_drain()
Refs: #1163
2021-09-19 00:39:54 +03:00
Azat Khuzhin
59e31c9667 Do not try to do SSL handshake if the connect() fails
This will avoid this icky error:

    $ https-client -4 -url https://127.1
    some request failed - no idea which one though!
    error:00000005:lib(0):func(0):DH lib

And instead will report only:

    $ https-client -4 -url https://127.1
    some request failed - no idea which one though!
    socket error = Connection refused (111)

Refs: #1115
2020-11-05 00:57:39 +03:00
Azat Khuzhin
a490172d69 Introduce new BUFFEREVENT_SSL_BATCH_WRITE flag to avoid Nagle effect in SSL 2020-10-31 23:04:46 +03:00
Azat Khuzhin
7e0fc878c5 Introduce new API for flags of the SSL bufferevent
Introduce more generic API (like for evbuffer):
- bufferevent_ssl_set_flags()
- bufferevent_ssl_clear_flags()
- bufferevent_ssl_get_flags()

And deprecate existing:
- bufferevent_openssl_get_allow_dirty_shutdown()
- bufferevent_openssl_set_allow_dirty_shutdown()
- bufferevent_mbedtls_get_allow_dirty_shutdown()
- bufferevent_mbedtls_set_allow_dirty_shutdown()
2020-10-31 22:51:40 +03:00
Azat Khuzhin
5671575a1c Join le_ssl_ops.post_init with le_ssl_ops.init 2020-07-22 23:08:50 +03:00
okhowang(王沛文)
d095b834a9 Merge ssl implementations (openssl and mbedtls)
This patch splits common part out to avoid copy-paste from the
- bufferevent_openssl.c
- bufferevent_mbedtls.c

It uses VFS/bufferevent-like approach, i.e. structure of callbacks.
2020-07-22 23:03:17 +03:00