From 8ee4de1707f657551d3995fc1579682badadf85f Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Sat, 13 Jan 2024 23:08:37 +0000 Subject: [PATCH 1/5] use user credentials for proxy-authentication --- pyVoIP/SIP/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyVoIP/SIP/client.py b/pyVoIP/SIP/client.py index 7d17aed..b8cdd7d 100644 --- a/pyVoIP/SIP/client.py +++ b/pyVoIP/SIP/client.py @@ -417,6 +417,8 @@ def gen_digest( user = request.headers["From"]["user"] credentials = self.credentials_manager.get(server, realm, user) username = credentials["username"] + if request.authentication["header"].lower() == "proxy-authenticate": + username = credentials["user"] password = credentials["password"] nonce = request.authentication["nonce"] method = request.headers["CSeq"]["method"] From a172f7a6a65400a171681b707f78a7b232323365 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Tue, 16 Jan 2024 17:51:31 +0000 Subject: [PATCH 2/5] 407 --- pyVoIP/SIP/client.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pyVoIP/SIP/client.py b/pyVoIP/SIP/client.py index b8cdd7d..e94f26d 100644 --- a/pyVoIP/SIP/client.py +++ b/pyVoIP/SIP/client.py @@ -1191,7 +1191,9 @@ def bye(self, request: SIPMessage) -> None: ), ) response = SIPMessage(conn.recv(8192)) - if response.status == SIPStatus(401): + if response.status == SIPStatus(401) or response.status == SIPStatus( + 407 + ): # Requires password auth = self.gen_authorization(response) message = message.replace( @@ -1237,7 +1239,9 @@ def __deregister(self) -> bool: first_response = response conn.close() # Regardless of the response, the dialog is over - if response.status == SIPStatus(401): + if response.status == SIPStatus(401) or response.status == SIPStatus( + 407 + ): # Unauthorized, likely due to being password protected. password_request = self.gen_register(response, deregister=True) conn = self.send(password_request) @@ -1265,7 +1269,9 @@ def __deregister(self) -> bool: elif response.status == SIPStatus.OK: return True - elif response.status == SIPStatus(401): + elif response.status == SIPStatus(401) or response.statis == SIPStatus( + 407 + ): # At this point, it's reasonable to assume that # this is caused by invalid credentials. debug("=" * 50) @@ -1338,7 +1344,9 @@ def __register(self) -> bool: first_response = response conn.close() # Regardless of the response, the dialog is over - if response.status == SIPStatus(401): + if response.status == SIPStatus(401) or response.status == SIPStatus( + 407 + ): # Unauthorized, likely due to being password protected. password_request = self.gen_register(response) conn = self.send(password_request) @@ -1364,7 +1372,9 @@ def __register(self) -> bool: elif response.status == SIPStatus.OK: return True - elif response.status == SIPStatus(401): + elif response.status == SIPStatus(401) or response.status == SIPStatus( + 407 + ): # At this point, it's reasonable to assume that # this is caused by invalid credentials. debug("=" * 50) From 08df5d7a2c3c462efc0df96d7e992abf6280ad4c Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Thu, 18 Jan 2024 06:34:38 +0100 Subject: [PATCH 3/5] Remove obsolete lines --- pyVoIP/SIP/client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyVoIP/SIP/client.py b/pyVoIP/SIP/client.py index 21aab57..4c4d8d0 100644 --- a/pyVoIP/SIP/client.py +++ b/pyVoIP/SIP/client.py @@ -417,8 +417,6 @@ def gen_digest( user = request.headers["From"]["user"] credentials = self.credentials_manager.get(server, realm, user) username = credentials["username"] - if request.authentication["header"].lower() == "proxy-authenticate": - username = credentials["user"] password = credentials["password"] nonce = request.authentication["nonce"] method = request.headers["CSeq"]["method"] From 60cf67f92d96bf47709af989451d4ebed111c11b Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Fri, 19 Jan 2024 05:32:12 +0000 Subject: [PATCH 4/5] typo --- pyVoIP/SIP/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyVoIP/SIP/client.py b/pyVoIP/SIP/client.py index 07052c5..e7ebf60 100644 --- a/pyVoIP/SIP/client.py +++ b/pyVoIP/SIP/client.py @@ -1299,7 +1299,7 @@ def __deregister(self) -> bool: elif response.status == SIPStatus.OK: return True - elif response.status == SIPStatus(401) or response.statis == SIPStatus( + elif response.status == SIPStatus(401) or response.status == SIPStatus( 407 ): # At this point, it's reasonable to assume that From a8febf49e714ac29d1cbdca5a3cc5f77a6ef37df Mon Sep 17 00:00:00 2001 From: TJ Porter Date: Wed, 14 Feb 2024 09:37:43 -0600 Subject: [PATCH 5/5] Fixed SIPStatus to be ResponseCode Removed previous elifs catching a 407 response. --- pyVoIP/SIP/client.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/pyVoIP/SIP/client.py b/pyVoIP/SIP/client.py index 1d92f90..0490ae8 100644 --- a/pyVoIP/SIP/client.py +++ b/pyVoIP/SIP/client.py @@ -1237,7 +1237,7 @@ def bye(self, request: SIPMessage) -> None: ), ) response = SIPMessage.from_bytes(conn.recv(8192)) - if response.status == SIPStatus(401) or response.status == SIPStatus( + if response.status == ResponseCode(401) or response.status == ResponseCode( 407 ): # Requires password @@ -1285,7 +1285,7 @@ def __deregister(self) -> bool: first_response = response conn.close() # Regardless of the response, the dialog is over - if response.status == SIPStatus(401) or response.status == SIPStatus( + if response.status == ResponseCode(401) or response.status == ResponseCode( 407 ): # Unauthorized, likely due to being password protected. @@ -1301,11 +1301,6 @@ def __deregister(self) -> bool: # with new urn:uuid or reply with expire 0 self._handle_bad_request() - elif response.status == ResponseCode(407): - # Proxy Authentication Required - # TODO: implement - debug("Proxy auth required") - elif response.status == ResponseCode(500): # We raise so the calling function can sleep and try again raise RetryRequiredError( @@ -1315,7 +1310,7 @@ def __deregister(self) -> bool: elif response.status == ResponseCode.OK: return True - elif response.status == SIPStatus(401) or response.status == SIPStatus( + elif response.status == ResponseCode(401) or response.status == ResponseCode( 407 ): # At this point, it's reasonable to assume that @@ -1390,7 +1385,7 @@ def __register(self) -> bool: first_response = response conn.close() # Regardless of the response, the dialog is over - if response.status == SIPStatus(401) or response.status == SIPStatus( + if response.status == ResponseCode(401) or response.status == ResponseCode( 407 ): # Unauthorized, likely due to being password protected. @@ -1406,11 +1401,6 @@ def __register(self) -> bool: # with new urn:uuid or reply with expire 0 self._handle_bad_request() - elif response.status == ResponseCode(407): - # Proxy Authentication Required - # TODO: implement - debug("Proxy auth required") - elif response.status == ResponseCode(500): # We raise so the calling function can sleep and try again raise RetryRequiredError("Received a 500 error when registering.") @@ -1418,7 +1408,7 @@ def __register(self) -> bool: elif response.status == ResponseCode.OK: return True - elif response.status == SIPStatus(401) or response.status == SIPStatus( + elif response.status == ResponseCode(401) or response.status == ResponseCode( 407 ): # At this point, it's reasonable to assume that