Python ssl.wrap_socket阻塞

时间:2016-07-03 23:21:24

标签: python python-2.7 ssl networking pyopenssl

我正在尝试在Python 2.7.10中实现SSL连接,但是当我在accept()之后调用wrap_socket()时,它似乎是阻塞的。我不明白为什么,看看它没有谈到的文件。

设置类是:

类SSLSocketSettings:

def __init__(self, sslVersion = None, ciphers = None, certFile = None
    , privateKey = None, serverSide = False):

    self._sslVersion = sslVersion
    self._ciphers = ciphers
    self._certFile = None
    self._privateKey = None
    self._serverSide = serverSide

接受是:

def Accept(self, timeout):
    if self._rawSocketHandle == None: return None

    readFDS = [ self._rawSocketHandle ]
    read, _, _ = select.select(readFDS, [], [], timeout)

    if  self._rawSocketHandle in read:
        try:
            newHandle, _ = self._rawSocketHandle.accept()

            newSettings = self._settings
            newSettings._serverSide = True

            newSocket = SSLSocket(self._socketType, newSettings, newHandle) 
            return newSocket

        except socket.error:
            return None

SSLSocket的构造函数是:

def __init__(self, socketType, settings, socketHandle = None):
    self._rawSocketHandle = socketHandle

    self._settings = settings

    if self._rawSocketHandle == None:
        try:
            self._rawSocketHandle = socket.socket(socketType
                , socket.SOCK_STREAM)
        except OSError:
            raise SystemError("Failed to create return socket")     

    sslObject = ssl.wrap_socket(self._rawSocketHandle
        , settings._privateKey, settings._certFile
        , self._settings._serverSide, do_handshake_on_connect = True)

任何建议都会被感激地接受。

我的代码基于The Python manual for SSL

0 个答案:

没有答案