本文整理汇总了Python中puresasl.client.SASLClient.choose_mechanism方法的典型用法代码示例。如果您正苦于以下问题:Python SASLClient.choose_mechanism方法的具体用法?Python SASLClient.choose_mechanism怎么用?Python SASLClient.choose_mechanism使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类puresasl.client.SASLClient
的用法示例。
在下文中一共展示了SASLClient.choose_mechanism方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate_xmpp
# 需要导入模块: from puresasl.client import SASLClient [as 别名]
# 或者: from puresasl.client.SASLClient import choose_mechanism [as 别名]
def authenticate_xmpp(self):
"""Authenticate the user to the XMPP server via the BOSH connection."""
self.request_sid()
self.log.debug('Prepare the XMPP authentication')
# Instantiate a sasl object
sasl = SASLClient(host=self.to,
service='xmpp',
username=self.jid,
password=self.password)
# Choose an auth mechanism
sasl.choose_mechanism(self.server_auth, allow_anonymous=False)
# Request challenge
challenge = self.get_challenge(sasl.mechanism)
# Process challenge and generate response
response = sasl.process(base64.b64decode(challenge))
# Send response
success = self.send_challenge_response(response)
if not success:
return False
self.request_restart()
self.bind_resource()
return True
示例2: authenticate_xmpp
# 需要导入模块: from puresasl.client import SASLClient [as 别名]
# 或者: from puresasl.client.SASLClient import choose_mechanism [as 别名]
def authenticate_xmpp(self):
"""Authenticate the user to the XMPP server via the BOSH connection."""
self.request_sid()
self.log.debug('Prepare the XMPP authentication')
# Instantiate a sasl object
sasl = SASLClient(
host=self.to,
service='xmpp',
username=self.jid,
password=self.password
)
# Choose an auth mechanism
sasl.choose_mechanism(self.server_auth, allow_anonymous=False)
# Request challenge
challenge = self.get_challenge(sasl.mechanism)
# Process challenge and generate response
response = sasl.process(base64.b64decode(challenge))
# Send response
resp_root = self.send_challenge_response(response)
success = self.check_authenticate_success(resp_root)
if success is None and\
resp_root.find('{{{0}}}challenge'.format(XMPP_SASL_NS)) is not None:
resp_root = self.send_challenge_response('')
return self.check_authenticate_success(resp_root)
return success
示例3: LDAPSocket
# 需要导入模块: from puresasl.client import SASLClient [as 别名]
# 或者: from puresasl.client.SASLClient import choose_mechanism [as 别名]
#.........这里部分代码省略.........
logger.debug('Installed TLS layer on #{0}'.format(self.ID))
def check_hostname(self, cert_cn, cert):
"""SSL check_hostname according to RFC 4513 sec 3.1.3. Compares supplied values against ``self.host`` to
determine the validity of the cert.
:param str cert_cn: The common name of the cert
:param dict cert: A dictionary representing the rest of the cert. Checks key subjectAltNames for a list of
(type, value) tuples, where type is 'DNS' or 'IP'. DNS supports leading wildcard.
:rtype: None
:raises LDAPConnectionError: if no supplied values match ``self.host``
"""
if self.host == cert_cn:
logger.debug('Matched server identity to cert commonName')
else:
valid = False
tried = [cert_cn]
for type, value in cert.get('subjectAltName', []):
if type == 'DNS' and value.startswith('*.'):
valid = self.host.endswith(value[1:])
else:
valid = (self.host == value)
tried.append(value)
if valid:
logger.debug('Matched server identity to cert {0} subjectAltName'.format(type))
break
if not valid:
raise LDAPConnectionError('Server identity "{0}" does not match any cert names: {1}'.format(
self.host, ', '.join(tried)))
def sasl_init(self, mechs, **props):
"""Initialize a :class:`.puresasl.client.SASLClient`"""
self._sasl_client = SASLClient(self.host, 'ldap', **props)
self._sasl_client.choose_mechanism(mechs)
def _has_sasl_client(self):
return self._sasl_client is not None
def _require_sasl_client(self):
if not self._has_sasl_client():
raise LDAPSASLError('SASL init not complete')
@property
def sasl_qop(self):
"""Obtain the chosen quality of protection"""
self._require_sasl_client()
return self._sasl_client.qop
@property
def sasl_mech(self):
"""Obtain the chosen mechanism"""
self._require_sasl_client()
mech = self._sasl_client.mechanism
if mech is None:
raise LDAPSASLError('SASL init not complete - no mech chosen')
else:
return mech
def sasl_process_auth_challenge(self, challenge):
"""Process an auth challenge and return the correct response"""
self._require_sasl_client()
return self._sasl_client.process(challenge)
def _prep_message(self, op, obj, controls=None):
"""Prepare a message for transmission"""
mid = self._next_message_id