Commit e30cc46b authored by Antoine Millet's avatar Antoine Millet
Browse files

Fixed exception when the ssl handshake fail on a new client connection.

parent 9c0445bc
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import ssl
import time
import socket
import select
import logging
from sjrpc.core import RpcConnection, ConnectionManager

class SimpleRpcServer(ConnectionManager):
@@ -47,7 +48,9 @@ class SimpleRpcServer(ConnectionManager):
        if fd == self._listening_sock.fileno():
            # Event concerns the listening socket:
            if event & select.EPOLLIN:
                sock, address = self._accept_connection()
                accepted = self._accept_connection()
                if accepted is not None:
                    sock, address = accepted
                    sock.setblocking(False)
                    connection = RpcConnection(sock, self, 
                                               handler=self._default_handler)
@@ -95,9 +98,13 @@ class SimpleSslRpcServer(SimpleRpcServer):

    def _accept_connection(self):
        sock, address = self._listening_sock.accept()
        sslsock = ssl.wrap_socket(sock, server_side=True, keyfile=self._keyfile,
        try:
            sslsock = ssl.wrap_socket(sock, server_side=True,
                                      keyfile=self._keyfile,
                                      certfile=self._certfile,
                                      ssl_version=ssl.PROTOCOL_TLSv1,
                                      do_handshake_on_connect=True)

        except ssl.SSLError as err:
            logging.error('Error when accepting ssl connection: %s' % err)
        else:
            return sslsock, address