Commit graph

1351 commits

Author SHA1 Message Date
Larry Hayes
455d1fed06 ssl client certs fix crash
I run a web socket server that requires clients to present a certificate.

context_ssl_ = libwebsocket_create_context(wssPort_, wssIpAddr_.c_str(), protocols_ssl,

                           libwebsocket_internal_extensions,

                           cert_path.c_str(), key_path.c_str(), -1, -1,

		LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT);

I am getting a crash in the OpenSSL_verify_callback().

The SSL_get_ex_data() call is returning NULL

I could not find a call to SSL_set_ex_data() for server mode operation.

Has anyone seen this crash in the newer versions?

Signed-off-by: Larry Hayes <larry.hayes@prodeasystems.com>
2013-01-15 01:03:58 +08:00
Andy Green
24b588b6d9 absorb README.rst into main README and code
Some of the advice in README.rst became deprecated with recent patches,
the (good) advice about http connection close is better demonstrated
in the code and API docs, and the remainder can go in the main README,
which will have to be refactored itself at some point.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-13 09:53:18 +08:00
Andy Green
c0d6b63c83 expose compiletime constants to setting from configure
This patch allows control of the main compiletime constants in libwebsockets
from the configure commandline.

README is updated with documentation on what's available, how to set them
and the defaults.

The constants are logged with "info" severity (not visible by default) at
context create time.

The zlib constant previously exposed like this is moved to private-libwebsockets.h
so it can be printed along with the rest.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-12 23:42:17 +08:00
Andy Green
d678ea3cd2 renable deflate frame buffer expansion fixing DoS
This reverts the removal of the deflate_frame code that was crashing after porting
David Galeano's code: he pointed out there's a typo in the merged version causing
the crash which is fixed here.

However the fixed code has a problem, there's no limit (other than int size) to the
amount of memory it will try to malloc, which can allow a DoS of the server by the
client sending malicious compression states that inflate to a large amount.  I have
added checking for OOM already that will avert the segfault that would otherwise follow
but the server will be unusuable if malicious connections were made repeatedly each
forcing it to allocate large buffers and cause small allocations on other connections
to fail.

The patch changes the code to use realloc(), and introduces a configurable limit
on the amount of memory one connection may need for zlib before the server hangs
up the connection.  It defaults to 64KBytes but can be set from ./configure as
described now in the README.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-12 23:36:27 +08:00
Andy Green
3c82019d52 fix config enable name for getifaddrs
copy-paste...

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-12 23:31:39 +08:00
David
c4ef7b1609 introduce getifaddrs for toolchains without it
David found that uclibc did not provide this slightly esoteric api
and provided one from BSD that can be built by the library internally.

AG: Made contingent on configure option --enable-builtin-getifaddrs

Signed-off-by: David <cymerio@gmail.com>
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-12 20:39:47 +08:00
Andy Green
41c5803d0f audit and make all malloc check for OOM
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-12 13:21:08 +08:00
Andy Green
8a26509800 logging add timestamp
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-12 09:31:11 +08:00
Andy Green
de8f27a80b logging extend level set api to allow setting emission function
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-12 09:17:42 +08:00
Andy Green
7e9b427afc update README with info on new logging scheme
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-10 23:34:33 +08:00
Andy Green
46ef0cf3c5 allow enabling debug contexts from test apps
Adds a -d switch to everything so you can set the log level bitfeld.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-10 23:34:33 +08:00
Andy Green
43db045ff8 introduce logging api and convert all library output to use it
- multiple debug context calls lwsl_ err, warn, debug, parser, ext, client

 - api added to set which contexts output to stderr using a bitfield log_level

 - --disable-debug on configure removes all code that is not err or warn severity

 - err and warn contexts always output to stderr unless disabled by log_level

 - err and warn enabled by default in log_level

Signed-off-by: Andy Green <andy@warmcat.com>
2013-01-10 22:16:37 +08:00
Aaron Zinman
4550f1d7b5 compile in xcode, privatize debug macro 2013-01-10 22:14:52 +08:00
Andy Green
6cd1ea9b00 update soname and configure to v1.0
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-10 12:45:54 +08:00
Andy Green
a63c24b35a correct autotools warning
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-10 12:45:54 +08:00
Andy Green
988bd987af zlib code add OOM checks remove buffer expansion on rx path
Here testing with the test serer and chrome 25, the buffer expansion
code on Rx was triggered by a valid no data output condition and looped
until it exhausted all memory.

This patch adds OOM check to all malloc()s and removes the buffer expansion
code on the rx path... leaving the code on tx path for now.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-10 12:45:54 +08:00
David Galeano
ed3c840ed6 Avoid leaking a socket when SSL_accept fails. 2013-01-10 12:45:54 +08:00
David Galeano
7c8d98924b Print error string on accept failure. 2013-01-10 12:45:54 +08:00
David Galeano
6b66791b46 Increased MAX_BROADCAST_PAYLOAD to match MAX_USER_RX_BUFFER. 2013-01-10 12:45:54 +08:00
David Galeano
229b7115bf Added README file with some useful tips for using the library. 2013-01-10 12:45:54 +08:00
David Galeano
96aa7e6a99 Added support for continuation frames on the server. 2013-01-10 12:45:54 +08:00
David Galeano
651544312c Close connection if LWS_CALLBACK_HTTP returns non-zero. 2013-01-10 12:45:54 +08:00
David Galeano
7ffbe1bfca Fixed to keep reading data until the SSL internal buffer is empty.
Before this fix only 2048 bytes were read,
the rest were buffered inside SSL until another message arrived!!!
2013-01-10 12:45:54 +08:00
David Galeano
4fbc40c07d Added no-cache headers to client handshake:
http://www.ietf.org/mail-archive/web/hybi/current/msg09841.html
2013-01-10 12:45:54 +08:00
David Galeano
ed3bc90174 Separate compression levels for server and client,
increased the later one to zlib default (6).
2013-01-10 12:45:54 +08:00
David Galeano
1ed189e421 More correct handling of inflate result. 2013-01-10 12:45:54 +08:00
David Galeano
e0d0fd72b3 Fixed crash when HTTP requests method is not GET. 2013-01-10 12:45:54 +08:00
David Galeano
cc148e4029 Check if macro SSL_OP_NO_COMPRESSION is defined before trying to use it. 2013-01-10 12:45:53 +08:00
David Galeano
1aad881819 Using size_t instead of int for deflate-frame offsets and length. 2013-01-10 12:45:53 +08:00
David Galeano
f177f2a15e Added private macro CIPHERS_LIST_STRING to define ciphers list string. 2013-01-10 12:45:53 +08:00
David Galeano
77a677c2bd When choosing a cipher, use the server's preferences. 2013-01-10 12:45:53 +08:00
David Galeano
584b316700 Pass URI length to LWS_CALLBACK_HTTP. 2013-01-10 12:45:53 +08:00
David Galeano
c72f6f9fa0 Disable compression for SSL socket,
it is a waste of CPU when using compression extensions.
2013-01-10 12:45:53 +08:00
David Galeano
9b3d4b2152 Using "SSL_CTX_use_certificate_chain_file" instead of "SSL_CTX_use_certificate_file"
to support server certificates signed by intermediaries.
2013-01-10 12:45:53 +08:00
David Galeano
0d586c4930 Better definition of "debug" macro for Win32 builds. 2013-01-10 10:08:50 +08:00
David Galeano
7dd9bc57a5 Use __inline for Win32 builds. 2013-01-10 10:07:16 +08:00
David Galeano
a1b39732d7 Avoid checking choked pipe if no extension has more data to write. 2013-01-10 10:06:38 +08:00
David Galeano
960da6eeb0 zlib update 1.2.7
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-10 10:03:42 +08:00
David Galeano
369730921e Set listen backlog to SOMAXCONN. 2013-01-10 09:58:24 +08:00
David Galeano
b88e096e19 Fixed operator precedence bug. 2013-01-10 09:54:10 +08:00
David Galeano
01d0256b42 Avoid deflate of small packets. 2013-01-10 09:51:15 +08:00
David Galeano
2605ffe277 Support compressed packets bigger than MAX_USER_RX_BUFFER.
(AG adapted style and removed logging stuff)
2013-01-10 09:41:06 +08:00
David Galeano
4c38f14527 Allow extensions when no protocol was specified. 2013-01-09 19:49:50 +08:00
David Galeano
85a092135e Added extension "deflate-frame".
Using by default instead of "deflate-stream".
2013-01-09 18:21:33 +08:00
David Galeano
e2cf992571 Added support for extensions that only manipulate application data. 2013-01-09 18:17:42 +08:00
David Galeano
d58c6ab78d Fixed deflate-stream extension.
When the output buffer was exhausted the input buffer was discarded
without checking if zlib had actually consumed all the input,
now we copy the remaining input data for the next call.
2013-01-09 18:17:42 +08:00
David Galeano
c9f1ff843f Added private macro AWAITING_TIMEOUT instead of harcoded value 5. 2013-01-09 18:17:42 +08:00
David Galeano
dae2dcb09e Fixed spacing. 2013-01-09 18:17:42 +08:00
David Galeano
2f82be89d5 Added context creation parameter for CA certificates file. 2013-01-09 16:25:54 +08:00
David Galeano
36750b84fd Return NULL if the handshake failed to complete,
libwebsocket_service_fd closes and frees the websocket in that case.
2013-01-09 16:17:04 +08:00