我正在尝试在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)
任何建议都会被感激地接受。