本文整理汇总了Python中M2Crypto.SSL属性的典型用法代码示例。如果您正苦于以下问题:Python M2Crypto.SSL属性的具体用法?Python M2Crypto.SSL怎么用?Python M2Crypto.SSL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类M2Crypto
的用法示例。
在下文中一共展示了M2Crypto.SSL属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __recv_msg_compat
# 需要导入模块: import M2Crypto [as 别名]
# 或者: from M2Crypto import SSL [as 别名]
def __recv_msg_compat(sock,size,timeout): # compatibility implementation for non-MSG_WAITALL / M2Crypto
msglen=0
msglist=[]
# Receive chunks of max. 60kb size:
# (rather arbitrary limit, but it avoids memory/buffer problems on certain OSes -- VAX/VMS, Windows)
while msglen<size:
chunk=sock.recv(min(60000,size-msglen))
if not chunk:
if hasattr(sock,'pending'):
# m2crypto ssl socket - they have problems with a defaulttimeout
if socket.getdefaulttimeout() != None:
raise ConnectionClosedError("m2crypto SSL can't be used when socket.setdefaulttimeout() has been set")
err = ConnectionClosedError('connection lost')
err.partialMsg=''.join(msglist) # store the message that was received until now
raise err
msglist.append(chunk)
msglen+=len(chunk)
return ''.join(msglist)
# Send a message over a socket. Raises ConnectionClosedError if the msg
# couldn't be sent (the connection has probably been lost then).
# We need this because 'send' isn't guaranteed to send all desired
# bytes in one call, for instance, when network load is high.
示例2: __init__
# 需要导入模块: import M2Crypto [as 别名]
# 或者: from M2Crypto import SSL [as 别名]
def __init__(self):
PYROAdapter.__init__(self)
try:
from M2Crypto import SSL
except ImportError:
raise ProtocolError('SSL not available')
self.ctx = SSL.Context('sslv23')
if Pyro.config.PYROSSL_KEY:
keyfile = os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_KEY)
else:
keyfile = None
self.ctx.load_cert(os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_CERT),
keyfile)
self.ctx.load_client_ca(os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_CA_CERT))
self.ctx.load_verify_info(os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_CA_CERT))
self.ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert,10)
self.ctx.set_allow_unknown_ca(1)
Log.msg('PYROSSLAdapter','SSL Context initialized')
示例3: getIPAddress
# 需要导入模块: import M2Crypto [as 别名]
# 或者: from M2Crypto import SSL [as 别名]
def getIPAddress(host=None):
try:
return socket.gethostbyname(host or getHostname())
except socket.error:
return None
#------ Socket helper functions for sending and receiving data correctly.
# process optional timeout on socket.
# notice the check for M2Crypto SSL sockets: if there's data pending,
# a select on them will fail. So we avoid calling select in that case.
示例4: __call__
# 需要导入模块: import M2Crypto [as 别名]
# 或者: from M2Crypto import SSL [as 别名]
def __call__(self,name,iglobals={},ilocals={},fromlist=None, *rest, **krest):
if os.name=="java":
# workaround for odd Jython bug, iglobals and ilocals may not exist in this scope...(?!)
iglobals=vars().get("iglobals",{})
ilocals=vars().get("ilocals",{})
# save the import details:
self.name=name # note: this must be a str object
self.fromlist=fromlist
return self.orig_import(name,iglobals,ilocals,fromlist, *rest, **krest)
#
# The SSL adapter that handles SSL connections instead of regular sockets.
#
示例5: bindToURI
# 需要导入模块: import M2Crypto [as 别名]
# 或者: from M2Crypto import SSL [as 别名]
def bindToURI(self,URI):
if URI.protocol not in ('PYROSSL','PYROLOCSSL'):
Log.error('PYROSSLAdapter','incompatible protocol in URI:',URI.protocol)
raise ProtocolError('incompatible protocol in URI')
try:
self.lock.acquire() # only 1 thread at a time can bind the URI
try:
self.URI=URI
sock = SSL.Connection(self.ctx,socket.socket(socket.AF_INET, socket.SOCK_STREAM))
if not Pyro.config.PYROSSL_POSTCONNCHECK:
sock.postConnectionCheck=None
sock.connect((URI.address, URI.port))
conn=TCPConnection(sock, sock.getpeername())
# receive the authentication challenge string, and use that to build the actual identification string.
authChallenge=self.recvAuthChallenge(conn)
# reply with our ident token, generated from the ident passphrase and the challenge
msg = self._sendConnect(sock,self.newConnValidator.createAuthToken(self.ident, authChallenge, conn.addr, self.URI, None) )
if msg==self.acceptMSG:
self.conn=conn
self.conn.connected=1
Log.msg('PYROSSLAdapter','connected to',str(URI))
if URI.protocol=='PYROLOCSSL':
self.resolvePYROLOC_URI("PYROSSL") # updates self.URI
elif msg[:len(self.denyMSG)]==self.denyMSG:
try:
raise ConnectionDeniedError(Pyro.constants.deniedReasons[int(msg[-1])])
except (KeyError,ValueError):
raise ConnectionDeniedError('invalid response')
except socket.error:
Log.msg('PYROSSLAdapter','connection failed to URI',str(URI))
raise ProtocolError('connection failed')
finally:
self.lock.release()
示例6: _handleRequest_Threaded
# 需要导入模块: import M2Crypto [as 别名]
# 或者: from M2Crypto import SSL [as 别名]
def _handleRequest_Threaded(self,timeout,others,callback):
# self.connections is used to keep track of connection Threads
socklist = [self.sock]+others
ins,outs,exs = safe_select(socklist,[],[],timeout)
if self.sock in ins:
# it was the server socket, new incoming connection
if self._ssl_server:
try:
csock, addr = self.sock.accept()
#if not Pyro.config.PYROSSL_POSTCONNCHECK:
# csock.postConnectionCheck=None
except SSL.SSLError,error:
Log.warn('TCPServer','SSL error: '+str(error))
return
else:
csock, addr = self.sock.accept()
conn=TCPConnection(csock,addr)
thread=Thread(target=self.connectionHandler, args=(conn,))
thread.setDaemon(1) # thread must exit at program termination.
thread.localStorage=LocalStorage()
self.connections.append(thread)
thread.start()
elif callback:
# the 'others' must have fired...
callback(ins)
示例7: _handleRequest_NoThreads
# 需要导入模块: import M2Crypto [as 别名]
# 或者: from M2Crypto import SSL [as 别名]
def _handleRequest_NoThreads(self,timeout,others,callback):
# self.connections is used to keep track of TCPConnections
socklist = self.connections+[self.sock]+others
ins,outs,exs = safe_select(socklist,[],[],timeout)
if self.sock in ins:
# it was the server socket, new incoming connection
ins.remove(self.sock)
if self._ssl_server:
try:
csock, addr = self.sock.accept()
#if not Pyro.config.PYROSSL_POSTCONNCHECK:
# csock.postConnectionCheck=None
except SSL.SSLError,error:
Log.warn('TCPServer','SSL error: '+str(error))
return
else:
csock, addr = self.sock.accept()
conn=TCPConnection(csock,addr)
if self.getAdapter().handleConnection(conn, self):
Log.msg('TCPServer','new connection ',conn, ' #conns=',len(self.connections))
self.connections.append(conn)
else:
# connection denied, log entry has already been written by newConnValidator
self.removeConnection(conn)
for c in ins[0:]:
if isinstance(c,TCPConnection):
ins.remove(c)
try:
self.handleInvocation(c)
if not c.connected:
self.removeConnection(c)
except ConnectionClosedError:
# client went away.
self.removeConnection(c)
except:
self.handleError(c)
if ins and callback:
# the 'others' must have fired...
callback(ins)
# def handleInvocation(self, conn): .... abstract method (implemented in subclass)