Skip to content

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

@Jane-Fan

Description

@Jane-Fan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions