use realm from first challenge response

This commit is contained in:
Dimitur Kirov 2006-04-08 15:58:50 +00:00
parent 6556d01cbe
commit 2fa30b7e1e
1 changed files with 21 additions and 14 deletions

View File

@ -30,7 +30,7 @@ class SASL(PlugIn):
self.username=username self.username=username
self.password=password self.password=password
self.on_sasl = on_sasl self.on_sasl = on_sasl
self.realm = None
def plugin(self,owner): def plugin(self,owner):
if not self._owner.Dispatcher.Stream._document_attrs.has_key('version'): if not self._owner.Dispatcher.Stream._document_attrs.has_key('version'):
self.startsasl='not-supported' self.startsasl='not-supported'
@ -121,25 +121,32 @@ class SASL(PlugIn):
for pair in data.split(','): for pair in data.split(','):
key, value = pair.split('=', 1) key, value = pair.split('=', 1)
if value[:1] == '"' and value[-1:] == '"': if value[:1] == '"' and value[-1:] == '"':
value=value[1:-1] value = value[1:-1]
chal[key]=value chal[key] = value
if not self.realm and chal.has_key('realm'):
self.realm = chal['realm']
if chal.has_key('qop') and chal['qop']=='auth': if chal.has_key('qop') and chal['qop']=='auth':
resp={} resp={}
resp['username']=self.username resp['username'] = self.username
resp['realm']=self._owner.Server if self.realm:
resp['realm'] = self.realm
else:
resp['realm'] = self._owner.Server
resp['nonce']=chal['nonce'] resp['nonce']=chal['nonce']
cnonce='' cnonce=''
for i in range(7): for i in range(7):
cnonce+=hex(int(random.random()*65536*4096))[2:] cnonce += hex(int(random.random() * 65536 * 4096))[2:]
resp['cnonce']=cnonce resp['cnonce'] = cnonce
resp['nc']=('00000001') resp['nc'] = ('00000001')
resp['qop']='auth' resp['qop'] = 'auth'
resp['digest-uri']='xmpp/'+self._owner.Server resp['digest-uri'] = 'xmpp/'+self._owner.Server
A1=C([H(C([resp['username'], resp['realm'], self.password])), resp['nonce'], resp['cnonce']]) A1=C([H(C([resp['username'], resp['realm'], self.password])),
resp['nonce'], resp['cnonce']])
A2=C(['AUTHENTICATE',resp['digest-uri']]) A2=C(['AUTHENTICATE',resp['digest-uri']])
response= HH(C([HH(A1),resp['nonce'],resp['nc'],resp['cnonce'],resp['qop'],HH(A2)])) response= HH(C([HH(A1), resp['nonce'], resp['nc'], resp['cnonce'],
resp['response']=response resp['qop'], HH(A2)]))
resp['charset']='utf-8' resp['response'] = response
resp['charset'] = 'utf-8'
sasl_data='' sasl_data=''
for key in ['charset', 'username', 'realm', 'nonce', 'nc', 'cnonce', 'digest-uri', 'response', 'qop']: for key in ['charset', 'username', 'realm', 'nonce', 'nc', 'cnonce', 'digest-uri', 'response', 'qop']:
if key in ['nc','qop','response','charset']: if key in ['nc','qop','response','charset']: