[dwd] better way to encode using base64. Fixes #4568

This commit is contained in:
Yann Leboulanger 2009-01-14 08:51:07 +00:00
parent 5575502c0b
commit 9b2382cd0e
1 changed files with 12 additions and 10 deletions

View File

@ -212,10 +212,12 @@ class SASL(PlugIn):
self.mechanism = 'DIGEST-MD5' self.mechanism = 'DIGEST-MD5'
elif 'PLAIN' in self.mecs: elif 'PLAIN' in self.mecs:
self.mecs.remove('PLAIN') self.mecs.remove('PLAIN')
sasl_data='%s\x00%s\x00%s' % (self.username+'@' + self._owner.Server, sasl_data = u'%s\x00%s\x00%s' % (self.username + '@' + \
self.username, self.password) self._owner.Server, self.username, self.password)
node = Node('auth', attrs={'xmlns':NS_SASL,'mechanism':'PLAIN'}, sasl_data = sasl_data.encode('utf-8').encode('base64').replace(
payload=[base64.encodestring(sasl_data).replace('\n','')]) '\n','')
node = Node('auth', attrs={'xmlns': NS_SASL, 'mechanism': 'PLAIN'},
payload=[sasl_data])
self.mechanism = 'PLAIN' self.mechanism = 'PLAIN'
else: else:
self.startsasl = SASL_FAILURE self.startsasl = SASL_FAILURE
@ -312,16 +314,16 @@ class SASL(PlugIn):
resp['qop'], HH(A2)])) resp['qop'], HH(A2)]))
resp['response'] = response resp['response'] = response
resp['charset'] = 'utf-8' resp['charset'] = 'utf-8'
sasl_data = '' sasl_data = u''
for key in ('charset', 'username', 'realm', 'nonce', 'nc', 'cnonce', for key in ('charset', 'username', 'realm', 'nonce', 'nc', 'cnonce',
'digest-uri', 'response', 'qop'): 'digest-uri', 'response', 'qop'):
if key in ('nc','qop','response','charset'): if key in ('nc','qop','response','charset'):
sasl_data += "%s=%s," % (key, resp[key]) sasl_data += u"%s=%s," % (key, resp[key])
else: else:
sasl_data += '%s="%s",' % (key, resp[key]) sasl_data += u'%s="%s",' % (key, resp[key])
node = Node('response', attrs={'xmlns':NS_SASL}, sasl_data = sasl_data[:-1].encode('utf-8').encode('base64').replace(
payload=[base64.encodestring(sasl_data[:-1]).replace('\r',''). '\r','').replace('\n','')
replace('\n','')]) node = Node('response', attrs={'xmlns':NS_SASL}, payload=[sasl_data])
self._owner.send(str(node)) self._owner.send(str(node))
elif 'rspauth' in chal: elif 'rspauth' in chal:
self._owner.send(str(Node('response', attrs={'xmlns':NS_SASL}))) self._owner.send(str(Node('response', attrs={'xmlns':NS_SASL})))