mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-08-07 05:57:20 +00:00
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>
This commit is contained in:
parent
fd90a9d084
commit
9a07eb6582
@ -156,15 +156,37 @@ static ssize_t stream_read_cb(RedStream *s, void *buf, size_t size)
|
||||
return socket_read(s->socket, buf, size);
|
||||
}
|
||||
|
||||
static ssize_t stream_ssl_error(RedStream *s, int return_code)
|
||||
{
|
||||
SPICE_GNUC_UNUSED int ssl_error;
|
||||
|
||||
ssl_error = SSL_get_error(s->priv->ssl, return_code);
|
||||
|
||||
// OpenSSL can to return SSL_ERROR_WANT_READ if we attempt to read
|
||||
// data and the socket did not receive all SSL packet.
|
||||
// Under Windows errno is not set so potentially caller can detect
|
||||
// the wrong error so we need to set errno.
|
||||
#ifdef _WIN32
|
||||
if (ssl_error == SSL_ERROR_WANT_READ || ssl_error == SSL_ERROR_WANT_WRITE) {
|
||||
errno = EAGAIN;
|
||||
} else {
|
||||
errno = EPIPE;
|
||||
}
|
||||
#endif
|
||||
|
||||
// red_peer_receive is expected to receive -1 on errors while
|
||||
// OpenSSL documentation just state a <0 value
|
||||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t stream_ssl_write_cb(RedStream *s, const void *buf, size_t size)
|
||||
{
|
||||
int return_code;
|
||||
SPICE_GNUC_UNUSED int ssl_error;
|
||||
|
||||
return_code = SSL_write(s->priv->ssl, buf, size);
|
||||
|
||||
if (return_code < 0) {
|
||||
ssl_error = SSL_get_error(s->priv->ssl, return_code);
|
||||
return stream_ssl_error(s, return_code);
|
||||
}
|
||||
|
||||
return return_code;
|
||||
@ -173,12 +195,11 @@ static ssize_t stream_ssl_write_cb(RedStream *s, const void *buf, size_t size)
|
||||
static ssize_t stream_ssl_read_cb(RedStream *s, void *buf, size_t size)
|
||||
{
|
||||
int return_code;
|
||||
SPICE_GNUC_UNUSED int ssl_error;
|
||||
|
||||
return_code = SSL_read(s->priv->ssl, buf, size);
|
||||
|
||||
if (return_code < 0) {
|
||||
ssl_error = SSL_get_error(s->priv->ssl, return_code);
|
||||
return stream_ssl_error(s, return_code);
|
||||
}
|
||||
|
||||
return return_code;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user