64 Commits

Author SHA1 Message Date
Azat Khuzhin
08981f8d75 Fix compilation without OPENSSL_API_COMPAT
Use the following for openssl 1.1+:
- X509_getm_notBefore over X509_get_notBefore
- X509_getm_notAfter  over X509_get_notAfter
- use OPENSSL_VERSION_NUMBER over SSLeay()
- add missing headers

Refs: openssl/openssl@0b7347effe
2020-01-07 22:15:08 +03:00
Azat Khuzhin
ae9b285d2d
test/ssl/bufferevent_wm: explicitly break the loop once client/server received enough
There can be tricky cases (that can be reproduced by reducing
SO_RCVBUF/SO_SNDBUF to 6144, on linux, and be aware, since linux doubles
this const), when there is still write event pending, although we read
enough.

This should be fixed in a more sophisticated way, but to backport the
patch, let's simply break the loop manually.

The ssl/bufferevent_wm originally failed on solaris.
2019-02-03 18:51:28 +03:00
Azat Khuzhin
b29207dcee
Eliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows)
windows has intptr_t instead of regular int.

Also tt_fd_op() had been introduced, since we cannot use tt_int_op() for
comparing fd, since it is not always int.
2019-01-29 22:03:08 +03:00
Azat Khuzhin
1fc1c7ef1d
regress_ssl: fix ssl/bufferevent_wm_filter for non defered callbacks
Even after referenced patch there is still possible recursive callbacks
from evbuffer_drain(bev_input), i.e.:
  wm_transfer() -> evbuffer_drain() -> wm_transfer()
                   inc(ctx->get)

But if we will increment ctx->get before drain that we will not add more
data to buffer.

Refs: 54c6fe3c ("regress_ssl: make ssl/bufferevent_wm_filter more fault-tolerance")
CI: https://ci.appveyor.com/project/nmathewson/libevent/build/job/f0rv299i71wnuxdq#L2546
2018-11-08 00:46:13 +03:00
Azat Khuzhin
54c6fe3c06
regress_ssl: make ssl/bufferevent_wm_filter more fault-tolerance
Due to inplace callbacks (i.e. no BEV_OPT_DEFER_CALLBACKS) we cannot be
sure that wm_transfer() will not be called recursively and indeed it
still happens sometimes, and the referenced patch increase amount of
this times, especially for linux/poll.

Fixes: 66304a23cf748714159c988e78f35401c5352827 ("Fix
ssl/bufferevent_wm_filter when bev does not reach watermark on break")
2018-11-05 22:25:15 +03:00
Azat Khuzhin
66304a23cf
Fix ssl/bufferevent_wm_filter when bev does not reach watermark on break
For the ssl/bufferevent_wm* we have next configuration:
- payload_len = 1024
- wm_high     = 5120
- limit       = 40960
- to_read     = 512

In this test we expect that with high watermark installed to "wm_high"
we will read "limit" bytes by reading "to_read" at a time, but adding
"payload_len" at a time (this "to_read"/"payload_len" limits is
installed to finally overflow watermark).

Once we read "limit" bytes we break, by disable EV_READ and reset
callbacks. Although this will not work if when we want to break we do
not reach watermark, this is because watermarks installs evbuffer
callback for the input buffer and if the watermark does not reached it
will enable EV_READ while be_openssl_enable() will read from the
underlying buffer (in case the openssl bufferevent created via
bufferevent_openssl_filter_new()) and call callback again (until it will
reach watermark or read al from the underlying buffer -- this is why it
stops in our caes).

And this is exactly what happened in win32, you can see this in the
following logs:

- win32 before:
    OK C:\vagrant\test\regress_ssl.c:829: wm_transfer-client(00DC2750): in: 4608, out: 0, got: 40960
    OK C:\vagrant\test\regress_ssl.c:834: wm_transfer-client(00DC2750): break
    OK C:\vagrant\test\regress_ssl.c:829: wm_transfer-client(00DC2750): in: 4608, out: 0, got: 41472
    OK C:\vagrant\test\regress_ssl.c:834: wm_transfer-client(00DC2750): break
    OK C:\vagrant\test\regress_ssl.c:829: wm_transfer-client(00DC2750): in: 4608, out: 0, got: 41984
    OK C:\vagrant\test\regress_ssl.c:834: wm_transfer-client(00DC2750): break
    OK C:\vagrant\test\regress_ssl.c:829: wm_transfer-client(00DC2750): in: 4608, out: 0, got: 42496
    OK C:\vagrant\test\regress_ssl.c:834: wm_transfer-client(00DC2750): break

- win32 after:
    OK C:\vagrant\test\regress_ssl.c:821: wm_transfer-client(00FC26F0): break
    OK C:\vagrant\test\regress_ssl.c:836: wm_transfer-client(00FC26F0): in: 4800, out: 0, got: 40960

- linux before:
    OK ../test/regress_ssl.c:829: wm_transfer-client(0x55555566f5e0): in: 5120, out: 0, got: 40960
    OK ../test/regress_ssl.c:834: wm_transfer-client(0x55555566f5e0): break

- linux after:
    OK ../test/regress_ssl.c:821: wm_transfer-client(0x55555566f5e0): break
    OK ../test/regress_ssl.c:836: wm_transfer-client(0x55555566f5e0): in: 5120, out: 0, got: 40960

(As you can see in linux case we already reach watermark hence it passed
before).

So fix the issue by breaking before draining.

But during fixing this I was thinking is this right? I.e. reading from
the be_openssl_enable(), maybe we should force deferred callbacks at
least?
2018-11-04 21:41:13 +03:00
Azat Khuzhin
e8c407e7b5
regress_ssl: cover watermarks with deferred callbacks 2018-11-04 21:41:13 +03:00
Azat Khuzhin
fb7f43f064
regress_ssl: improve bufferevent_wm/bufferevent_wm_filter logging
- add bev pointer
- use EV_SIZE_FMT over %zu (win32)
2018-11-04 21:41:13 +03:00
Azat Khuzhin
9fe952a0ae
regress_ssl: reset static variables on test setup/cleanup and eliminate leaks
One tricky bit is reply to the BIO_C_GET_FD command, since otherwise it
will try to close(0) and accepted bev in ssl/bufferevent_connect_sleep
will leak. Other seems more or less trivial.

This was done to make sure that for at least generic cases does not
leak (tricky cases was listed here nmathewson/Libevent#83).

And this will allow run ssl/.. with --no-fork
2018-10-28 01:25:43 +03:00
Azat Khuzhin
a5b2ed56c3
test: cover watermarks (with some corner cases) in ssl bufferevent 2018-10-17 11:23:51 +03:00
Bernard Spil
28b8075400 Fix build with LibreSSL 2.7
LibreSSL 2.7 implements OpenSSL 1.1 API except for BIO_get_init()

See also: https://bugs.freebsd.org/226900
Signed-off-by: Bernard Spil <brnrd@FreeBSD.org>
Closes: #617 (cherry-pick)
2018-04-02 23:13:28 +03:00
Azat Khuzhin
c2c08e0203 Add missing includes into openssl-compat.h
Before it depends from the caller #include appropriate headers (at least
for OPENSSL_VERSION_NUMBER), but let's make it independent.

Fixes: #574
2017-11-22 10:35:01 +03:00
Jan Beich
d057c45e8f Unbreak build with LibreSSL after openssl 1.1 support added
Fixes: 3e9e0a0d46e4 ("Make it build using OpenSSL 1.1.0")
Fixes: #445
2017-01-30 00:25:26 +03:00
Azat Khuzhin
09b6201304 test/ssl: fix bufferevent_getfd() for bufferevent_openssl_filter_new() 2017-01-19 20:53:05 +03:00
Azat Khuzhin
d047c2412e test/ssl: cover case when we writing to be_openssl after connecting
Right now it fails because of regression for filtered openssl
bufferevent, and by it I mean ssl/bufferevent_filter_write_after_connect
test, and by fails - hang.

Regression-for: da52933550fd4736aa1c213b6de497e2ffc31e34 ("be_openssl:
don't call do_write() directly from outbuf_cb")
2017-01-19 20:53:05 +03:00
Azat Khuzhin
532a47ce1e test: fix building under openssl 1.1 (init functions has been deprecated)
Refs: #397
2016-12-07 01:14:16 +03:00
Azat Khuzhin
336f3b11e5 Fix _FILE_OFFSET_BITS redinition (solaris/autotools)
So firstly include our header (config.h) -- <evconfig-private.h>, and
only after it <sys/types.h> since latest has #ifdef guard, while our
config.h is not inteded for this.

And besides all this thing with LARGE_FILE is a abit awkward, since we
don't nefine _LP64/_LP32 anyway, and so we have next error actually (64bit VS
32bit):
==> solaris: In file included from ./util-internal.h:30:0,
==> solaris:                  from test/regress_ssl.c:49:
  ==> solaris: ./evconfig-private.h:29:0: warning: "_FILE_OFFSET_BITS" redefined
  ==> solaris:  #define _FILE_OFFSET_BITS 64
  ==> solaris:  ^
  ==> solaris: In file included from /usr/include/sys/types.h:17:0,
  ==> solaris:                  from test/regress_ssl.c:38:
  ==> solaris: /opt/csw/lib/gcc/i386-pc-solaris2.10/5.2.0/include-fixed/sys/feature_tests.h:196:0: note: this is the location of the previous definition
  ==> solaris:  #define _FILE_OFFSET_BITS 32
  ==> solaris:  ^

For cmake it commented in: 8b228e27f57300be61b57a41a2ec8666b726dc34
("Lot's of cmake updates")
2016-12-06 13:21:28 +03:00
Kurt Roeckx
3e9e0a0d46 Make it build using OpenSSL 1.1.0
Rebased (azat):
- tabs instead of whitespaces
- make openssl-compat.h safe for complex expressions
- do not call sk_SSL_COMP_free() in 1.1 (fixes double free)

TODO:
- clean methods_bufferevent

Closes: #397 (cherry-picked)
2016-10-16 19:05:24 +03:00
Adam Langley
f9803a6943 Switch from a 512 to 2048-bit RSA key.
The 512 bit key is too small to sign larger hashes. This can cause the
regression tests to fail depending on the defaults in libssl.
2016-10-13 16:12:07 -07:00
Azat Khuzhin
a9e8cd6738 test/ssl: use send()/recv()/EVUTIL_ERR_RW_RETRIABLE()/EVUTIL_SOCKET_ERROR() to fix win32
Fixes: https://ci.appveyor.com/project/azat/libevent/build/2.1.5.107/job/k70our1xdp0ym4dm#L1906
Fixes: ssl/bufferevent_connect_sleep
2016-08-09 15:47:58 +03:00
Trond Norbye
73d0360e83 test/regress_ssl: Fix compile problems for win32
Windows doesn't have unistd.h, but have the required
functionality in io.h.

azat: use ev_ssize_t instead of ssize_t
2016-02-15 23:29:10 +03:00
Azat Khuzhin
da0ea7ae77 test/ssl: cover busy-loop (i.e. {read,write}-blocked-on-{write,read} stuff)
This covers SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE error codes from ssl,
under which we must block read/write to avoid busy looping, and hence extra CPU
usage.
This test introduces custom BIO that will count read/write and validates
counters, with patches for be_openssl that drops handling
SSL/SSL_ERROR_WANT_READ there are more then 43K reads, so 100 is pretty ok.
2015-11-18 15:40:47 +03:00
Azat Khuzhin
0c4c387c15 test/ssl: export getkey()/getcert()/get_ssl_ctx()/init_ssl() for https 2015-11-05 11:00:06 +03:00
Thomas Bernard
9f02a44513 make test/regress_ssl.c compile without warnings 2015-10-05 12:37:41 +02:00
Azat Khuzhin
cdafdf017e test/regress_ssl: check events fd/pending after timeout triggered
In this case client can't connect to server, and this bring to the front some
bugs with assigning on already added events (because of ```fd_is_set``` stuff),
for more info see #258, since this is the reproducible for it.
2015-09-02 19:15:27 +03:00
Azat Khuzhin
74845f1198 test/regress_ssl: cover case when server didn't up (failed with timeout) 2015-09-02 19:08:36 +03:00
Azat Khuzhin
df507afafd test/regress_ssl: covert that we can't change fd with underlying 2015-09-02 19:07:08 +03:00
Azat Khuzhin
762edb46a8 test/regress_ssl: cover that events (read/write) at finish not pending 2015-09-02 19:06:45 +03:00
Azat Khuzhin
b78a829752 test/regress_ssl: cover fd manipulations 2015-09-02 19:04:52 +03:00
Azat Khuzhin
46bba73103 test/regress_ssl: convert open_ssl_bufevs() to mask 2015-09-02 19:04:45 +03:00
Azat Khuzhin
34559913c0 test/regress_ssl: convert client/server to mask too 2015-09-02 19:04:39 +03:00
Azat Khuzhin
0430327364 test/regress_ssl: cover "allow_dirty_shutdown" 2015-09-02 19:04:11 +03:00
Azat Khuzhin
342e116ff6 test/regress_ssl: convert regress_bufferevent_openssl() to bitmask 2015-09-02 19:04:11 +03:00
Azat Khuzhin
25e56fdbc1 tests/regress_ssl: drop duplicated assert 2015-09-01 20:40:03 +03:00
Nick Mathewson
89c1a3b7fe Fix several memory leaks in the unit tests.
Also add a comment to buffer.c about why we call
evbuffer_file_segment_free on failure to add the segment.
2014-09-18 12:40:38 -04:00
Joakim Soderberg
e212c5486d Check for OSX when checking for clang. 2014-01-22 13:19:49 +01:00
Joakim Soderberg
0ef1d04e44 Get rid of unknown pragma warnings. 2013-12-17 14:32:07 +01:00
Joakim Söderberg
69c3516be6 Get rid of deprecation warnings for OpenSSL on OSX 10.7+ 2013-12-17 13:28:23 +01:00
Nick Mathewson
5a9a014189 Fix a couple of compile warnings in the unit tests 2012-11-16 16:17:07 -05:00
Nick Mathewson
1f5a48d1d0 Merge remote-tracking branch 'origin/patches-2.0' 2012-11-15 11:45:12 -05:00
Nick Mathewson
ac009f9245 Warn when openssl version in unit test mismatches compiled version. 2012-11-15 11:43:45 -05:00
Nick Mathewson
c2f30863e2 Fix renegotiation test to work around openssl 1.0.1 bug
There's a bug in openssl 1.0.1 where TLS1.1 and TLS1.2 can't
renegotiate with themselves.  When testing renegotiation with OpenSSL
>=1.0.1 and <1.0.1d, disable those protocols.
2012-11-15 11:43:45 -05:00
Nick Mathewson
2e6a985003 Merge remote-tracking branch 'github/20_win64_compilation' into 21_win64_compilation
Conflicts:
	event.c
	http.c
	sample/event-read-fifo.c
	test/regress_bufferevent.c
2012-11-01 18:12:07 -04:00
Nick Mathewson
94866c2763 Compile without warnings on mingw64
This is mostly a matter of catching cases where we were still
assuming that evutil_socket_t could be used as an int.
2012-11-01 17:56:06 -04:00
Nick Mathewson
9852107f37 Merge remote-tracking branch 'origin/patches-2.0'
Conflicts:
	buffer.c
	http.c
2012-07-26 10:43:13 -04:00
Nick Mathewson
a2006c0087 Move assignment outside tt_assert in ssl unit tests. Appeases coverity. 2012-07-26 10:37:47 -04:00
Nick Mathewson
539466e568 Merge remote-tracking branch 'origin/patches-2.0'
Conflicts:
	Makefile.am
	WIN32-Code/event2/event-config.h
	configure.in
2012-02-10 17:33:50 -05:00
Nick Mathewson
e49e289129 Update copyright notices to 2012 2012-02-10 17:29:53 -05:00
Nick Mathewson
0cb70e3333 Merge remote-tracking branch 'origin/patches-2.0' 2011-10-26 10:17:21 -04:00
Nick Mathewson
3c824bd334 Update copyright dates to 2011. 2011-10-24 13:18:09 -04:00