本文整理汇总了Python中twisted.internet.interfaces.ISSLTransport方法的典型用法代码示例。如果您正苦于以下问题:Python interfaces.ISSLTransport方法的具体用法?Python interfaces.ISSLTransport怎么用?Python interfaces.ISSLTransport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.interfaces
的用法示例。
在下文中一共展示了interfaces.ISSLTransport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: isSecure
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def isSecure(self):
"""
Return L{True} if this request is using a secure transport.
Normally this method returns L{True} if this request's L{HTTPChannel}
instance is using a transport that implements
L{interfaces.ISSLTransport}.
This will also return L{True} if L{Request.setHost} has been called
with C{ssl=True}.
@returns: L{True} if this request is secure
@rtype: C{bool}
"""
if self._forceSSL:
return True
channel = getattr(self, 'channel', None)
if channel is None:
return False
return channel.isSecure()
示例2: __cbLoginCaps
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def __cbLoginCaps(self, capabilities, username, password):
# If the server advertises STARTTLS, we might want to try to switch to TLS
tryTLS = 'STARTTLS' in capabilities
# If our transport supports switching to TLS, we might want to try to switch to TLS.
tlsableTransport = interfaces.ITLSTransport(self.transport, None) is not None
# If our transport is not already using TLS, we might want to try to switch to TLS.
nontlsTransport = interfaces.ISSLTransport(self.transport, None) is None
if not self.startedTLS and tryTLS and tlsableTransport and nontlsTransport:
d = self.startTLS()
d.addCallbacks(
self.__cbLoginTLS,
self.__ebLoginTLS,
callbackArgs=(username, password),
)
return d
else:
if nontlsTransport:
log.msg("Server has no TLS support. logging in over cleartext!")
args = b' '.join((_quote(username), _quote(password)))
return self.sendCommand(Command(b'LOGIN', args))
示例3: test_requireTLSAndHELOFallbackSucceedsIfOverTLS
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def test_requireTLSAndHELOFallbackSucceedsIfOverTLS(self):
"""
If TLS is provided at the transport level, we can honour the HELO
fallback if we're set to require TLS.
"""
transport = StringTransport()
directlyProvides(transport, interfaces.ISSLTransport)
self.clientProtocol.requireAuthentication = False
self.clientProtocol.requireTransportSecurity = True
self.clientProtocol.heloFallback = True
self.clientProtocol.makeConnection(transport)
self.clientProtocol.dataReceived(b"220 localhost\r\n")
transport.clear()
self.clientProtocol.dataReceived(b"500 not an esmtp server\r\n")
self.assertEqual(b"HELO testuser\r\n", transport.value())
示例4: bufferReceived
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def bufferReceived(self, buf):
if isinstance(buf, TLSNegotiation):
assert self.tls is not None # By the time you're receiving a
# negotiation, you have to have called
# startTLS already.
if self.tls.sent:
self.tls.pretendToVerify(buf, self)
self.tls = None # We're done with the handshake if we've gotten
# this far... although maybe it failed...?
# TLS started! Unbuffer...
b, self.tlsbuf = self.tlsbuf, None
self.writeSequence(b)
directlyProvides(self, interfaces.ISSLTransport)
else:
# We haven't sent our own TLS negotiation: time to do that!
self.tls.readyToSend = True
else:
self.protocol.dataReceived(buf)
示例5: testSSLTransportConsideredSecure
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def testSSLTransportConsideredSecure(self):
"""
If a server doesn't offer APOP but the transport is secured using
SSL or TLS, a plaintext login should be allowed, not rejected with
an InsecureAuthenticationDisallowed exception.
"""
p, t = setUp(greet=False)
directlyProvides(t, interfaces.ISSLTransport)
p.dataReceived(b"+OK Howdy\r\n")
d = p.login(b"username", b"password")
self.assertEqual(t.value(), b"USER username\r\n")
t.clear()
p.dataReceived(b"+OK\r\n")
self.assertEqual(t.value(), b"PASS password\r\n")
p.dataReceived(b"+OK\r\n")
return d
示例6: createTransport
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def createTransport(self, skt, peer, data, protocol):
"""
Create a TCP transport, from a socket object passed by the parent.
"""
self._connectionCount += 1
transport = Server(skt, protocol, peer, JustEnoughLikeAPort,
self._connectionCount, reactor)
if data == 'SSL':
if self.usingSocketFile:
# Mark the transport as "secure", enough for getHostInfo() to
# think so
transport.getPeerCertificate = lambda _: None
directlyProvides(transport, ISSLTransport)
else:
transport.startTLS(self.contextFactory)
transport.startReading()
return transport
示例7: isSecure
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def isSecure(self):
"""
Return True if this request is using a secure transport.
Normally this method returns True if this request's HTTPChannel
instance is using a transport that implements ISSLTransport.
This will also return True if setHost() has been called
with ssl=True.
@returns: True if this request is secure
@rtype: C{bool}
"""
if self._forceSSL:
return True
transport = getattr(getattr(self, 'channel', None), 'transport', None)
if interfaces.ISSLTransport(transport, None) is not None:
return True
return False
示例8: _login
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def _login(self, caps, username, password):
if self.serverChallenge is not None:
return self._apop(username, password, self.serverChallenge)
tryTLS = 'STLS' in caps
#If our transport supports switching to TLS, we might want to try to switch to TLS.
tlsableTransport = interfaces.ITLSTransport(self.transport, None) is not None
# If our transport is not already using TLS, we might want to try to switch to TLS.
nontlsTransport = interfaces.ISSLTransport(self.transport, None) is None
if not self.startedTLS and tryTLS and tlsableTransport and nontlsTransport:
d = self.startTLS()
d.addCallback(self._loginTLS, username, password)
return d
elif self.startedTLS or not nontlsTransport or self.allowInsecureLogin:
return self._plaintext(username, password)
else:
return defer.fail(InsecureAuthenticationDisallowed())
示例9: testSSLTransportConsideredSecure
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def testSSLTransportConsideredSecure(self):
"""
If a server doesn't offer APOP but the transport is secured using
SSL or TLS, a plaintext login should be allowed, not rejected with
an InsecureAuthenticationDisallowed exception.
"""
p, t = setUp(greet=False)
directlyProvides(t, interfaces.ISSLTransport)
p.dataReceived("+OK Howdy\r\n")
d = p.login("username", "password")
self.assertEquals(t.value(), "USER username\r\n")
t.clear()
p.dataReceived("+OK\r\n")
self.assertEquals(t.value(), "PASS password\r\n")
p.dataReceived("+OK\r\n")
return d
示例10: bufferReceived
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def bufferReceived(self, buf):
if isinstance(buf, TLSNegotiation):
assert self.tls is not None # By the time you're receiving a
# negotiation, you have to have called
# startTLS already.
if self.tls.sent:
self.tls.pretendToVerify(buf, self)
self.tls = None # we're done with the handshake if we've gotten
# this far... although maybe it failed...?
# TLS started! Unbuffer...
b, self.tlsbuf = self.tlsbuf, None
self.writeSequence(b)
directlyProvides(self, interfaces.ISSLTransport)
else:
# We haven't sent our own TLS negotiation: time to do that!
self.tls.readyToSend = True
else:
self.protocol.dataReceived(buf)
示例11: _login
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def _login(self, caps, username, password):
if self.serverChallenge is not None:
return self._apop(username, password, self.serverChallenge)
tryTLS = 'STLS' in caps
#If our transport supports switching to TLS, we might want to try to switch to TLS.
tlsableTransport = interfaces.ITLSTransport(self.transport, None) is not None
# If our transport is not already using TLS, we might want to try to switch to TLS.
nontlsTransport = interfaces.ISSLTransport(self.transport, None) is None
if not self.startedTLS and tryTLS and tlsableTransport and nontlsTransport:
d = self.startTLS()
d.addCallback(self._loginTLS, username, password)
return d
elif self.startedTLS or self.allowInsecureLogin:
return self._plaintext(username, password)
else:
return defer.fail(InsecureAuthenticationDisallowed())
示例12: __cbLoginCaps
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def __cbLoginCaps(self, capabilities, username, password):
# If the server advertises STARTTLS, we might want to try to switch to TLS
tryTLS = 'STARTTLS' in capabilities
# If our transport supports switching to TLS, we might want to try to switch to TLS.
tlsableTransport = interfaces.ITLSTransport(self.transport, None) is not None
# If our transport is not already using TLS, we might want to try to switch to TLS.
nontlsTransport = interfaces.ISSLTransport(self.transport, None) is None
if not self.startedTLS and tryTLS and tlsableTransport and nontlsTransport:
d = self.startTLS()
d.addCallbacks(
self.__cbLoginTLS,
self.__ebLoginTLS,
callbackArgs=(username, password),
)
return d
else:
if nontlsTransport:
log.msg("Server has no TLS support. logging in over cleartext!")
args = ' '.join((_quote(username), _quote(password)))
return self.sendCommand(Command('LOGIN', args))
示例13: capabilities
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def capabilities(self):
cap = {'AUTH': self.challengers.keys()}
if self.ctx and self.canStartTLS:
t = self.transport
ti = interfaces.ISSLTransport
if not self.startedTLS and ti(t, None) is None:
cap['LOGINDISABLED'] = None
cap['STARTTLS'] = None
cap['NAMESPACE'] = None
cap['IDLE'] = None
# patched ############
cap['LITERAL+'] = None
######################
return cap
示例14: capabilities
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def capabilities(self):
cap = {b'AUTH': list(self.challengers.keys())}
if self.ctx and self.canStartTLS:
if not self.startedTLS and interfaces.ISSLTransport(self.transport, None) is None:
cap[b'LOGINDISABLED'] = None
cap[b'STARTTLS'] = None
cap[b'NAMESPACE'] = None
cap[b'IDLE'] = None
return cap
示例15: _requireTransportSecurityOverSSLTest
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import ISSLTransport [as 别名]
def _requireTransportSecurityOverSSLTest(self, capabilities):
"""
Verify that when L{smtp.ESMTPClient} connects to a server over a
transport providing L{ISSLTransport}, C{requireTransportSecurity} is
C{True}, and it is presented with the given capabilities, it will try
to send its mail and not first attempt to negotiate TLS using the
I{STARTTLS} protocol action.
@param capabilities: Bytes to include in the test server's capability
response. These must be formatted exactly as required by the
protocol, including a line which ends the capability response.
@type param: L{bytes}
@raise: C{self.failureException} if the behavior of
C{self.clientProtocol} is not as described.
"""
transport = StringTransport()
directlyProvides(transport, interfaces.ISSLTransport)
self.clientProtocol.makeConnection(transport)
# Get the handshake out of the way
self.clientProtocol.dataReceived(self.SERVER_GREETING)
transport.clear()
# Tell the client about the server's capabilities
self.clientProtocol.dataReceived(self.EHLO_RESPONSE + capabilities)
# The client should now try to send a message - without first trying to
# negotiate TLS, since the transport is already secure.
self.assertEqual(
b"MAIL FROM:<test@example.org>\r\n",
transport.value())