Skip to content

Commit

Permalink
python: Send non-zero flag for a SSL socket
Browse files Browse the repository at this point in the history
Python std library SSLSocket.send does not allow non-zero value for the optional flag.

pyOpenSSL was recently switched for the Python standard library ssl module
commit 68543dd (python: Replace pyOpenSSL with ssl).
Python SSLsocket.send() does not allow non-zero optional flag and it will explicitly
raise an exception for that. pyOpenSSL did not nothing with this flag but kept
it to be compatible with socket API.
https://github.com/pyca/pyopenssl/blob/main/src/OpenSSL/SSL.py#L1844

In addition, expect for ImportError is not necessary anymore as ssl is part of
the Python standard library. This type of exception should not happen.

Signed-off-by: Miro Tomaska <mtomaska@redhat.com>
Reported-at: https://bugzilla.redhat.com/2115035
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
mtomaska authored and ovsrobot committed Aug 8, 2022
1 parent 434025a commit f09a559
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
5 changes: 1 addition & 4 deletions python/ovs/poller.py
Expand Up @@ -17,6 +17,7 @@

import select
import socket
import ssl
import sys

import ovs.timeval
Expand All @@ -25,10 +26,6 @@
if sys.platform == "win32":
import ovs.winutils as winutils

try:
import ssl
except ImportError:
ssl = None

try:
from eventlet import patcher as eventlet_patcher
Expand Down
7 changes: 6 additions & 1 deletion python/ovs/socket_util.py
Expand Up @@ -17,6 +17,7 @@
import os.path
import random
import socket
import ssl
import sys

import ovs.fatal_signal
Expand Down Expand Up @@ -178,7 +179,11 @@ def check_connection_completion(sock):
if revents & ovs.poller.POLLERR or revents & ovs.poller.POLLHUP:
try:
# The following should raise an exception.
sock.send("\0".encode(), socket.MSG_DONTWAIT)
if isinstance(sock, ssl.SSLSocket):
# a SSL wrapped socket does not allow non-zero optional flag
sock.send("\0".encode())
else:
sock.send("\0".encode(), socket.MSG_DONTWAIT)

# (Here's where we end up if it didn't.)
# XXX rate-limit
Expand Down
9 changes: 2 additions & 7 deletions python/ovs/stream.py
Expand Up @@ -15,16 +15,13 @@
import errno
import os
import socket
import ssl
import sys

import ovs.poller
import ovs.socket_util
import ovs.vlog

try:
import ssl
except ImportError:
ssl = None

if sys.platform == 'win32':
import ovs.winutils as winutils
Expand Down Expand Up @@ -860,6 +857,4 @@ def close(self):
return super(SSLStream, self).close()


if ssl:
# Register SSL only if the OpenSSL module is available
Stream.register_method("ssl", SSLStream)
Stream.register_method("ssl", SSLStream)

0 comments on commit f09a559

Please sign in to comment.