Commit Graph

24 Commits

Author SHA1 Message Date
Frediano Ziglio
9a07eb6582 red-stream: Fix SSL connection for Windows
Set correctly errno to make callers handle correctly encrypted
traffic.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:31 +01:00
Frediano Ziglio
524acca643 windows: Disable code not working on Windows
- global signals;
- CLOEXEC flag;
- mmap and statistics;
- IPTOS_LOWDELAY flag;
- Unix sockets;
- sharing file descriptors through Unix sockets;
- TCP_CORK flag.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:22 +01:00
Frediano Ziglio
5c65107663 red-stream: Use socket compatibility layer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:14 +01:00
Frediano Ziglio
ed68d491fd Do not check for HAVE_CONFIG_H
This should always be defined and including config.h is a requirement.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-04-30 09:26:55 +01:00
Christophe Fergeau
474158dfef ssl: Dump OpenSSL error stack on errors
Bugs such as https://bugzilla.redhat.com/show_bug.cgi?id=1651882 can be
quite tricky to figure out without the detailed OpenSSL error. This
commit adds a detailed dump of the OpenSSL error stack when an OpenSSL
failure happens.

In the bug above, this would have displayed:
(process:13154): Spice-WARNING **: 05:43:10.139: reds.c:2816:reds_init_ssl: Could not load certificates from /etc/pki/libvirt-spice/server-cert.pem

(process:13154): Spice-WARNING **: 05:43:10.140: error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-02-07 09:55:11 +00:00
Frediano Ziglio
f8e8ac4910 windows: Do not include headers not available on Windows
This is a preparatory patch for next portability patches

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-01-31 10:48:34 +00:00
Christophe Fergeau
9b04c9961e sasl: Simplify red_stream_write_u32_le call with '0' serveroutlen
Instead of
if (serveroutlen) {
...
} else {
    red_stream_write_u32_le(stream, serveroutlen);
}

use 'red_stream_write_u32_le(stream, 0);' in the else block as it's
slightly more obvious.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-01-15 17:07:44 +01:00
Frediano Ziglio
9a0d8b2db8 red-stream: Propagate RedStreamSslStatus type
Do not convert RedStreamSslStatus enumeration type back to int.
This allows compilers to perform some more type safe checks.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-10-09 12:52:48 +01:00
Frediano Ziglio
4b1d33d384 red-stream: Implements flush using TCP_CORK
Cork is a system interface implemented by Linux and some *BSD systems to
tell the system that other data are expected to be written to a socket.
This allows the system to reduce network fragmentation waiting for network
packets to be complete.

Using some replay capture and some instrumentation resulted in a
bandwith reduction of 11% and a packet reduction of 56%.

The tests was done using replay utility so results could be a bit different
from real cases as:
- replay goes as fast as it can, for instance packets could
  be merged by the kernel decreasing packet numbers and a bit
  byte spent (this actually make the following improves worse);
- there are fewer channels (no much cursor, sound, etc).
The following tests shows count packet and total bytes from server to
client using a real network. I used a direct cable connection using 1gb
connection and 2 laptops.

cork: 537 1582240
cork: 681 1823754
cork: 524 1583287
cork: 538 1582350
no cork: 1329 1834630
no cork: 1290 1829094
no cork: 1289 1830164
no cork: 1317 1833589
no cork: 1320 1835705

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-04-17 15:45:35 +01:00
Frediano Ziglio
63d02ab10e red-stream: Define interface for manual flush
The writing to network was always immediate.
Every write in the stream causes a write to the OS.
This can have some penalty if you don't write large data as network
packets can be more fragmented or you encrypt data in smaller chunks
(when data are encrypted some padding is added then data is split in
multiple of encryption block which is usually the size of encryption
key and this is done for every write).
Define an interface to allow higher levels code to tell low level when
data should be sent to remote or when can wait more data.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-04-17 15:45:28 +01:00
Frediano Ziglio
72d095ac8c red-stream: Handle reading of 0 bytes in red_stream_async_read
Currently red_stream_async_read cannot handle read of 0 bytes.
This would cause a wrong assert in async_read_handler.
Fixing the assert would just make the code wrongly detect a
disconnection (usually a return of 0 from read is handled that
way but happens also if you try to read 0 bytes).
Current callers of these function does not pass 0 as size however
handling data protocols having data_length+data this can happen
and is handled manually in red_sasl_handle_auth_steplen.
Avoid needing manually to check for this condition.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe de Dinechin <dinechin@redhat.com>
2018-01-30 15:06:03 +00:00
Frediano Ziglio
5998e34ffb red-stream: Remove AsyncRead::stream
AsyncRead is always included in RedStream and there are only
a possible operation pending on a RedStream.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-16 14:11:16 +00:00
Frediano Ziglio
233f710ba9 red-stream: Reuse red_stream_disable_writev function
The same function is used to reset writev field in SASL code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-16 12:41:13 +00:00
Frediano Ziglio
6c416f5098 red-stream: Encapsulate all authentication state in RedSASLAuth
Instead of having half state in RedSASL and half in RedSASLAuth
move everything in RedSASLAuth. This also reduces memory usage
when we are using SASL but we finish the authentication step.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-09 17:06:11 +00:00
Frediano Ziglio
cb70583e5c red-stream: Unify start and step passes
Most of these function are identical.
Only difference were basically debugging message but now
with a proper tests are less important.
The mechname field is used to differentiate between first step and
following ones.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-09 17:06:08 +00:00
Frediano Ziglio
5c516a6e42 red-stream: Handle properly endianness in SASL code
All SPICE protocol is little endian, there's no agreement on other
endian and currently we support only little endian so make sure
this will work even possibly running on a big endian machine.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-09 17:06:06 +00:00
Frediano Ziglio
5c438510cd Handle SASL initialisation mainly in red-stream.c
Asynchronous code jumping from a file to another is tedious to read
also having code handling the same stuff in two files does not look
a good design.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-09 17:06:04 +00:00
Frediano Ziglio
7362882993 red-stream: Avoid infinite loop on sasl_encode/decode failure
These functions do not set errno so it is possible that errno has a
stale value which happens to be EAGAIN.
This would cause an infinite loop in functions like red_stream_write_all
(or potentially using the event loop).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-04 20:08:17 +00:00
Frediano Ziglio
cb099522bf red-stream: Avoid to specify 2 mech names during SASL
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2018-01-02 11:39:36 +00:00
Frediano Ziglio
f3be28fb5e red-stream: Simplify mechname matching
Avoid over complicated matching using quoting and a simple strstr
operation.
The mech names are separated and quoted with the same chararacter (',')
making possible to search for ",MECHNAME," instead of manually check for
prefix and suffix after the search for "MECHNAME".

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2018-01-02 11:39:15 +00:00
Frediano Ziglio
f7ca5d4a15 red-stream: Use mechname for mechname
There's no reason to copy mechname into mechlist to use mechlist
instead of mechname.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-12-19 16:55:13 +00:00
Frediano Ziglio
a7b8ea4b7a red-stream: Remove SASL "data" field leak
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-12-19 16:55:11 +00:00
Uri Lublin
49234be2dd red-stream: fix build without SASL
put red_stream_disable_writev in an #ifdef HAVE_SASL block.
red_stream_disable_writev is only called from functions
that are already in an #ifdef HAVE_SASL block.

Currently when building with SASL disabled, I get:
  CC       red-stream.lo
red-stream.c:441:13: error: 'red_stream_disable_writev'
           defined but not used [-Werror=unused-function]

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-11-27 10:13:11 +00:00
Jonathon Jongsma
a5aa2a2261 Use standard "Red" namespace
The objects RedsStream and RedsSASL are currently using the namespace
"Reds" rather than the standard "Red" namespace used throughout the rest
of the project. Change these to be consistent. This also means changing
method names and some related enumeration types.

The files were also renamed to reflect the change:
  reds-stream.[ch] -> red-stream.[ch]

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-10-21 08:47:02 +01:00