Commit graph

53 commits

Author SHA1 Message Date
Ashod Nakashian
71e1e54eb5 wsd: hostname is needed for SSL SNI
Since the hostname argument is passed
to both the base class of SslStreamSocket
and SSL_set_tlsext_host_name, and since
the base class's getter, also called
hostname(), is hidden by the argument,
we cannot move it.

An empty hostname can result in 403 Forbidden
from the server due to missing Server Name
Indication (SNI).

Change-Id: I27990f64f17ec3c81a4dd543a078807629cd0c20
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-27 22:32:38 +02:00
Ashod Nakashian
f74192d9ac wsd: always include the BIO errors in SSL logs
And improved socket logging in general while
making them more consistent.

Change-Id: I1ed7f2561476ca5370af91079d5d616804396f8e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-21 08:57:41 +00:00
Ashod Nakashian
1bb21868b2 wsd: reduce polling when blocked on ssl handshake
While SSL is handshaking, there can be no general
application data communication. During that early
stage of connecting we have data to send (the
request, headers, etc.) and so we poll on POLLOUT.
Naturally, we also always want to poll on POLLIN,
because we can never know when there is data to
read (especially true for web-sockets).

The problem is when SSL will not send data just
yet because it is handshaking. It is typically
waiting for handshake negotiation data to read,
so when we POLLOUT, poll immediately returns, but
writing (via SSL_write) fails with WANTS_READ
error. This goes on in a busy-loop until the
negotiation data is available for read and the
handshake is completed. Very inefficient.

The solution is to poll on whatever SSL needs
during the handshake, exclusively. Once the
handshake is complete, we poll on whatever we
need. However, SSL can renegotiate at any time,
so we also merge with what it needs.

In addition, we avoid the unnecessary read when
poll doesn't give us POLLIN in revents, since the
read will more likely than not fail (except in
the rare case when data becomes available in the
interim). Notice that SSL_read will return
SSL_WANTS_READ when there is no data, which
is misleading (since SSL isn't in need of data to
read at all, nor are we, for that matter).
Best not to do noisy reads unnecessarily.

These changes are disabled by default and can
be enabled via the experimental_features option.

Change-Id: I6a7ed7d871ed257b30062cc720a8b8c7acbab3b7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-17 18:46:46 -04:00
Ashod Nakashian
b53d353779 wsd: reduce debug and generally redundant logs
In 'debug' log-level we expect a detailed, but
still readable output. Having one area with
disproportionately large number of logs reduces
the overall utility of the log output.

This patch reduces a number of redundant log
entries, including errors that are already
logged. It also reduces the level of some
others from 'information' to 'debug' and
from 'debug' to 'trace'.

The goal is to make 'debug' level as useful as
possible to read the progress and be able to
understand what was going on, such that one is
able to decide which area to dig deeper into.
Then, trace level could be used to get more
insight into that area, if necessary. For
example, when investigating a test failure,
one first enables 'debug' logs and reads through.
Once a section between two debug entries is
identified as being of interest, enabling 'trace'
level logs becomes more productive as it's
now possible to easily reach the first DBG
entry and read through until the second one.

It's unfortunate that we don't have per-area
control for enabling/disabling logs, so it
is common to see more and more 'debug' log
entries added all around, making logs
less and less readable.

It is also a limitation of the levels we have
that we really only have 3 usable levels:
one, two, many. That is, 'information' for
the most important events, 'debug' for
technical details needed to investigate issues,
and 'trace' for everything else. ('warning'
and 'error' aren't really 'levels'; they have
semantics that makes them special-cases.)
So we have to avoid degrading one into the
other, or have differences without distinction.

If any of these entries are needed to be
displayed more frequently, changing them
back to 'debug' or even 'information' should
be done. Though for me they seem special
cases that don't benefit most log readings.

Change-Id: Id2c6a9dc027483b81a066b0b4b50a298c5eff449
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-02-24 07:38:13 -05:00
Szymon Kłos
e457aa8b4e Don't try to set empty hostname for SNI
to reduce logging warnings

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I9e1dcb16489f4cec692028b86d377ae776ac44e4
2021-09-15 09:34:56 +02:00
Szymon Kłos
541f6a76d3 ssl: setup hostname for SNI
For some servers we receive failure with HTTP 403 Forbidden in WOPI::CheckFileInfo

"Reason: The client software did not provide a hostname using Server
Name Indication (SNI), which is required to access this server"

fixes #2771 : https://github.com/CollaboraOnline/online/issues/2771

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I761b179580481f8882a4526c1d8be4f1c14ad929
2021-07-22 12:40:05 +02:00
Ashod Nakashian
4c87cc36ff wsd: Close socket hard when necessary
Also clear its input buffer explicitly.

Change-Id: I8badbb96d98eaf10433a65fcfd13b0d6d5893594
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>

Ignore input in a somewhat gentler way.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I758302dc3bb1aa87f9fbfa726f73f4b9339e08c2
2021-07-19 17:31:55 +01:00
Ashod Nakashian
f63d077916 wsd: ssl certificate verification requirements
Change-Id: I72ffa586310296f1986276c3007672c41146c92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
f702c4efab wsd: support certificate verification
Change-Id: I912595f104e24dc66da9cf06bc211cb0c50c9ff0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Dennis Francis
7e9b038ded net: show call-site file/line for assertCorrect...
...Thread.

Conflicts:
	net/Socket.hpp
	net/SslSocket.hpp

Signed-off-by: Dennis Francis <dennis.francis@collabora.com>
Change-Id: I92b8f4b52e7bd60b69305c1916eed8a14a4c1560
2021-07-02 16:48:46 +05:30
Ashod Nakashian
5a310a2232 wsd: separate client SSL context from the server
Change-Id: I4d86f733a16e6c76340b18ff836831ebe6acfd4d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-23 23:39:34 -04:00
Andras Timar
086b4f4fc0 Extend debug only if OpenSSL version > 1.1.0
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I6ba025786cd92388da1e16ddc0bb8c9a5ad56b21
2021-06-04 14:58:36 +01:00
Michael Meeks
b4f3adb8cd Extend debug.
Change-Id: I57bf42a0241d773041f792a2489011f90677254e
2021-06-04 14:58:36 +01:00
Ashod Nakashian
21e99cf128 wsd: better errno handling in sockets
Change-Id: Id3a7744802cbf693a92e39ef4d99433951dfa923
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-01 21:50:18 -05:00
Ashod Nakashian
01138d7ae0 wsd: save errno before invoking any other functions
Most C and Posix API clobber errno. By failing to save
it immediately after invoking an API we risk simply
reporting the result of an arbitrary subsequent API call.

This adds LOG_SYS_ERRNO to take errno explicitly.
This is necessary because sometimes logging is not done
immediately after calling the function for which we
want to report errno. Similarly, log macros that log
errno need to save errno before calling any functions.
This is necessary as the argements might contain calls
that clobber errno.

This also converts some LOG_SYS entries to LOG_ERR
because there can be no relevant errno in that context
(f.e. in a catch clause).

A couple of LOG_ macros have been folded into others,
reducing redundancy.

Finally, both of these log macros append errno to the
log message, so there is little point in ending the
messages with a period.

Change-Id: Iecc656f67115fec78b65cad4e7c17a17623ecf43
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-12-29 11:40:17 +00:00
Ashod Nakashian
04379f45ab wsd: ssl: simplify SSL poll events
This merges OpenSSL's poll events with ours.
Effectively, we now do a single poll when
there are reads and writes to be done,
regardless of the reason (i.e. SSL-specific
or application-specific).

Simpler code, and more efficient performance
by sharing code with http and reducing the
number of poll syscalls.

Change-Id: Ib329c7e76fccfdadc4a0783c1ad79c3eedcdd8f3
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-12-10 14:43:38 -05:00
Michael Meeks
1cd41fd4e6 Simulate EAGAIN in debug mode, every seventh operation.
Hopefully reasonably simple; we perturb the count in the poll to
avoid starving a seventh socket in a poll.

Change-Id: I1a39cc36b9599ffe82186b896c6fd91d792c4127
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2020-12-10 11:53:02 +00:00
Andras Timar
0002fdfd6c fix license headers
Change-Id: I8623770b32d278a45357dc7f757fabfadd2b4af7
2020-10-01 11:56:43 +02:00
Gabriel Masei
6b486f229a wsd: admin: move kit memory reporting from kit to admin module
Sometimes kit process goes into a heavy processing state (or even hangs)
and is not able to report its memory usage. Thus we can't implement cleanup
of problematic kit processes based on memory information reported by kit.
By moving memory reporting to admin module we avoid this problem.

Change-Id: Icf274e3a3a97b33623a93f9d2dc1e640ad9b7d99
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92752
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2020-04-25 09:11:35 +02:00
Tor Lillqvist
e835bbf413 YAGNI: Bin bool parameter that is passed as true at the one single call site
Change-Id: I13b0ff612f8ca0970b3ab7fac3e92761c3c332d4
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92509
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-04-19 22:05:29 +02:00
Tor Lillqvist
4eb598711c Use #pragma once
LibreOffice core uses that, too, and we support an even more
restricted set of compilers.

Change-Id: I0d0e2c8608e323eb5ef0f35ee8c46d02ab49a745
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92467
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-04-18 15:00:18 +02:00
Michael Meeks
28a9c4dc05 Poll - cleanup method naming, and fix merge issues.
This mends several problems from commit
5710c86323.

Change-Id: I1b29f29ca81679608a2692488fa1ef22b2e62dfd
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92032
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2020-04-10 13:58:00 +02:00
Michael Meeks
5710c86323 Poll - switch to ppoll for closer to microsecond accuracy.
Change-Id: Ib8a2bb6f60302df8631edadbbb8db626894c457c
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92000
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2020-04-10 10:06:23 +02:00
Michael Meeks
e924625cc1 re-factor: Socket / WebSocketHandler.
Essentially we want to be able to separate low-level socket code
for eg. TCP vs. UDS, from Protocol handling: eg. WebSocketHandler
and client sessions themselves which handle and send messages
which now implement the simple MessageHandlerInterface.

Some helpful renaming too:

s/SocketHandlerInterface/ProtocolHandlerInterface/

Change-Id: I58092b5e0b5792fda47498fb2c875851eada461d
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90138
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2020-03-11 16:48:03 +01:00
Michael Meeks
1ff820de95 tdf#129306 SslSocket: handle EAGAIN properly.
Change-Id: I9fb3323b8d071fdc50399a67eb6b0aaeed9342b0
2019-12-10 11:45:13 +00:00
Miklos Vajna
5167cf9f58 StreamSocket: make members private
Only a single member needed a setter, otherwise getters were enough.
2018-10-26 09:07:30 +02:00
Michael Meeks
5a94614217 Enable SSL in outbound, client websockets ...
Switch SSL context creation to be generic rather than pure server.

Change-Id: I1b750b4ddc8c607381f5541a4f4412fa16e457d4
2018-05-18 15:16:39 +02:00
Michael Meeks
9e7dff79f3 re-factor socket factories to take a client parameter.
Change-Id: I0be98eb583b4f8081dd8ad23e688e93c55220367
2018-05-18 15:16:39 +02:00
Ashod Nakashian
11cdfb7688 wsd: avoid misleading socket error logs
Change-Id: Ie70d8eb1ecc0442643f4b2a4757b95688b4cf1f7
Reviewed-on: https://gerrit.libreoffice.org/48284
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2018-01-22 10:14:17 +01:00
Ashod Nakashian
2ad3cd4de1 wsd: don't call virtuals in dtors
Change-Id: I2490e2f63dc20cf6b3fa0be45341b041e3ccb1bf
Reviewed-on: https://gerrit.libreoffice.org/36321
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-10 06:06:27 +02:00
Jan Holesovsky
cb2b788cc7 assert(isCorrectThread()) -> assertCorrectThread().
assert()'s are no-op in the release builds, but we still want to see threading
problems in the log at least.

Change-Id: Idb02bb018e8f2d628a57ab570249613ad00bcff2
2017-04-05 14:49:30 +02:00
Michael Meeks
913c469aa8 Cleanup whitespace, return is not a function. 2017-03-30 17:34:52 +01:00
Ashod Nakashian
3895897213 wsd: improved socket logging
Change-Id: Ib4751a5a73b7ec0c7ca319f552d5e0aaff06ffea
Reviewed-on: https://gerrit.libreoffice.org/35707
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-26 05:07:37 +00:00
Ashod Nakashian
e9675ed6e1 wsd: close socket when WS close handshake is complete
We shouldn't send any more data after the client
shuts down, or after we initiate shutdown.

Change-Id: Ibf0cf61dcabe9d02ddcb7eb40b2df23712c5a136
2017-03-20 00:41:53 -04:00
Michael Meeks
9381d4134f Unify and simplify timeout and poll events setup.
Both happen at the same time, and need support from the
SocketHandlerInterface.

Rename hasQueuedWrites to getPollEvents and merge updateTimeout.
2017-03-17 22:00:28 +00:00
Ashod Nakashian
aa19964b03 wsd: SSL logging improvement
Change-Id: I99d08a764fd43ab0c7eb50a1f017202e6bbc3477
2017-03-15 00:04:55 -04:00
Ashod Nakashian
45e1c7763c wsd: Socket stores SocketHandler shared_ptr
Change-Id: I5b460069eb4d91cee2d58833791f961fd6f42b39
2017-03-15 00:04:55 -04:00
Ashod Nakashian
6f11918661 wsd: more informative SSL error logging
Change-Id: I32baadf995f6fc4c9b112d1a62fee2d618fc9e95
Reviewed-on: https://gerrit.libreoffice.org/35116
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:10:03 +00:00
Miklos Vajna
2f07eb9a7d Fix remaining -Werror,-Winconsistent-missing-override warnings
The last ones introduced by the non-blocking merge.

Change-Id: I0b9264428669cdd2b8f6eac911c336c6b0e8de99
2017-03-10 11:11:58 +01:00
Ashod Nakashian
2d621f1a47 nb: logging
Change-Id: Ic3b724d5869f75234af2238b96a90c4745155b86
2017-03-10 10:47:44 +01:00
Jan Holesovsky
b895393cea nb: Perform the socket shutdown asynchronously after the data is served.
Change-Id: I642e26abf4ef9c8d2be1be428b5786692dfea2c7
2017-03-10 10:47:44 +01:00
Ashod Nakashian
b8af470918 nb: serve files synchronously
As there isn't support (yet) to send files
asynchronously, when the socket native buffer
is small, asynchronous writes naturally return
EWOULDBLOCK. As a temp solution, we send files
synchronously, so there is no need to poll.

This should be replaced witha file-server
polling/serving thread that is dedicated to
sending files only (which closes the connection
when done).

Change-Id: I062fea44bfe54ab8d147b745da97bd499bf00657
2017-03-10 10:47:44 +01:00
Michael Meeks
37de43bb58 Tie sockets to threads, and assert that we're being used in the right one.
This shows up some problems around cleaning up prisoners etc. that will
need fixing subsequently.
2017-03-10 10:47:43 +01:00
Michael Meeks
0eaef6c896 config.h - get includes right: must always be the first include. 2017-03-10 10:47:43 +01:00
Ashod Nakashian
d68377748d nb: ReadOrWrite -> Neither
SSL only requests what to poll for next.
So it's more accurate to rename ReadOrWrite
to Neither, since in that case SSL really
isn't blocked on either read or write.

Change-Id: I62dd4f94730d51666a7661b10a9d582d69fbf45e
2017-03-10 10:47:42 +01:00
Ashod Nakashian
9c0d8cc5b2 nb: log more socket activity
Change-Id: Ibcdf5abc3054691c93382c00bb8a9ecc4b882652
2017-03-10 10:47:42 +01:00
Ashod Nakashian
df45db9da2 nb: shutdown socket after file-serving
Change-Id: Ibe0b33f371d46e62637f570265fcdf9c8bf60b2d
2017-03-10 10:47:41 +01:00
Ashod Nakashian
7fdb7a1861 nb: StreamSocket takes ownership of SocketHandler instance
Change-Id: Ica99dc8afbcca71c8d79eecb276ba19f6f01fa57
2017-03-10 10:47:39 +01:00
Jan Holesovsky
a2d457d778 nb: Abstract WebSocketHandler.
We don't need a special "WebSocket" class, as websocket itself is just an
upgrade of an existing socket / connection, and trying to come up with a
concept where a Socket class magically upgrades to a WebSocket class would be
messy.

So let's have just a WebSocketHandler, that communicates over a StreamSocket
or SslStreamSocket, and be done with that :-)

Change-Id: I449e4d662fbe2c5b1789e308053e4a71376fe481
2017-03-10 10:47:39 +01:00
Jan Holesovsky
18876119ad nb: SimpleResponseClient is a client, not a socket I guess.
Introduce the appropriate interface instead of the template, so that we can
de-couple the ResponseClient from the Socket itself.

Change-Id: I21892bbce5d83a18ca580a25cfc2efbb05b08705
2017-03-10 10:47:39 +01:00