Eyepea / aiosip

SIP support for AsyncIO (DEPRECATED)
Apache License 2.0
82 stars 40 forks source link

SIP Digest authentication failed when the qop directive present in the challenge #129

Open Jane-Fan opened 5 years ago

Jane-Fan commented 5 years ago

The sip registration fails sometime via aiosip.auth.py.

The aiosip/auth.py computes the response correctly when the qop directive value is not specified. It should also include the scenario that the qop directive value is present. The response is calculated differently based on qop directive value.

For example, if the qop directive value is not present, response=MD5(HA1:nonce:HA2) If the qop is "auth" or "auth-int", response=MD5(HA1:nonce:nonceCount:cnonce:qop:HA2) Please refer the link [details](https://en.wikipedia.org/wiki/Digest_access_authentication.

@classmethod def from_authenticate_header(cls, authenticate, method, uri, username, password): if authenticate.startswith('Digest'): params = { 'username': username, 'uri': uri }

         params.update(cls.__parse_digest(authenticate))
         auth = cls(mode='Digest', **params)
         ha1 = md5digest(username, auth['realm'], password)
         ha2 = md5digest(method, uri)
         try:
             qop = auth['qop']
         except KeyError:
             auth['response'] = md5digest(ha1, auth['nonce'], ha2)
         else:
             auth['nc'] = '00000001'
             auth['cnonce'] = '0a4f113b'
             auth['response'] = md5digest(
                 ha1, auth['nonce'], auth['nc'], auth['cnonce'], qop, ha2
             )
     else:
         raise ValueError('Authentication method not supported')
     return auth
ovv commented 5 years ago

I believe your are looking for #125

It isn't yet on master since I haven't had time to get back into aiosip much. Please let me know if #125 work as expected for you

Jane-Fan commented 5 years ago

Thanks, the #125 works for me.