Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
import logging
sasl.log.setLevel(logging.CRITICAL)
self.zs = init('test', 'memory:', create=self._create)
def _client(self, user, pwd):
return sasl.SimpleAuth(
sasl.DigestMD5Password,
{},
lambda: user,
lambda: pwd,
lambda: authenticator().service_type(),
lambda: authenticator().host()
)
def _client(self, user, pwd):
return sasl.SimpleAuth(
sasl.DigestMD5Password,
{},
lambda: user,
lambda: pwd,
lambda: authenticator().service_type(),
lambda: authenticator().host()
)
def _login(self, user, pwd, mech=None):
client = self._client(user, pwd)
mech = mech or sasl.DigestMD5
return self._negotiate(mech(authenticator()), mech(client))
def sasl_factory():
saslc = sasl.Client()
saslc.setAttr("host", str(conf.host))
saslc.setAttr("service", str(conf.kerberos_principal))
if conf.mechanism == 'PLAIN':
saslc.setAttr("username", str(conf.username))
saslc.setAttr("password", str(conf.password)) # Defaults to 'hue' for a non-empty string unless using LDAP
else:
saslc.setAttr("maxbufsize", SASL_MAX_BUFFER.get())
saslc.init()
return saslc
transport = TSaslClientTransport(sasl_factory, conf.mechanism, mode)
def sasl_factory():
sasl_client = sasl.Client()
sasl_client.setAttr('host', host)
sasl_client.setAttr('service', kerberos_service_name)
if auth_mechanism.upper() in ['PLAIN', 'LDAP']:
sasl_client.setAttr('username', user)
sasl_client.setAttr('password', password)
sasl_client.init()
return sasl_client
except ImportError:
def _authenticate_with_sasl(self, host, timeout):
saslc = sasl.Client()
saslc.setAttr('host', str(host))
saslc.setAttr('service', str(self.sasl_server_principal))
saslc.init()
ret, chosen_mech, initial_response = saslc.start('GSSAPI')
if not ret:
raise SaslException(saslc.getError())
response = initial_response
xid = 0
while True:
xid += 1
request = SASL(response)
def sasl_factory():
sasl_client = sasl.Client()
sasl_client.setAttr("host", host)
if use_ldap:
sasl_client.setAttr("username", ldap_user)
sasl_client.setAttr("password", ldap_password)
else:
sasl_client.setAttr("service", kerberos_service_name)
sasl_client.init()
return sasl_client
def connect(self):
# use service name component from principal
service = re.split('[\/@]', str(self.hdfs_namenode_principal))[0]
negotiate = RpcSaslProto()
negotiate.state = 1
self._send_sasl_message(negotiate)
self.sasl = sasl.Client()
self.sasl.setAttr("service", service)
self.sasl.setAttr("host", self._trans.host)
self.sasl.init()
# do while true
while True:
res = self._recv_sasl_message()
# TODO: check mechanisms
if res.state == 1:
mechs = []
for auth in res.auths:
mechs.append(auth.mechanism)
log.debug("Available mechs: %s" % (",".join(mechs)))
s_mechs = str(",".join(mechs))
ret, chosen_mech, initial_response = self.sasl.start(s_mechs)
def sasl_factory():
sasl_client = sasl.Client()
sasl_client.setAttr('host', host)
if sasl_auth == 'GSSAPI':
sasl_client.setAttr('service', kerberos_service_name)
elif sasl_auth == 'PLAIN':
sasl_client.setAttr('username', username)
sasl_client.setAttr('password', password)
else:
raise AssertionError
sasl_client.init()
return sasl_client