Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy-authentication for development #213

Merged
merged 9 commits into from
Feb 14, 2024
30 changes: 15 additions & 15 deletions pyVoIP/SIP/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,9 @@ def bye(self, request: SIPMessage) -> None:
),
)
response = SIPMessage.from_bytes(conn.recv(8192))
if response.status == ResponseCode(401):
if response.status == ResponseCode(401) or response.status == ResponseCode(
407
):
# Requires password
auth = self.gen_authorization(response)
message = message.replace(
Expand Down Expand Up @@ -1283,7 +1285,9 @@ def __deregister(self) -> bool:
first_response = response
conn.close() # Regardless of the response, the dialog is over

if response.status == ResponseCode(401):
if response.status == ResponseCode(401) or response.status == ResponseCode(
407
):
# Unauthorized, likely due to being password protected.
password_request = self.gen_register(response, deregister=True)
conn = self.send(password_request)
Expand All @@ -1297,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(
Expand All @@ -1311,7 +1310,9 @@ def __deregister(self) -> bool:
elif response.status == ResponseCode.OK:
return True

elif response.status == ResponseCode(401):
elif response.status == ResponseCode(401) or response.status == ResponseCode(
407
):
# At this point, it's reasonable to assume that
# this is caused by invalid credentials.
debug("=" * 50)
Expand Down Expand Up @@ -1384,7 +1385,9 @@ def __register(self) -> bool:
first_response = response
conn.close() # Regardless of the response, the dialog is over

if response.status == ResponseCode(401):
if response.status == ResponseCode(401) or response.status == ResponseCode(
407
):
# Unauthorized, likely due to being password protected.
password_request = self.gen_register(response)
conn = self.send(password_request)
Expand All @@ -1398,19 +1401,16 @@ 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.")

elif response.status == ResponseCode.OK:
return True

elif response.status == ResponseCode(401):
elif response.status == ResponseCode(401) or response.status == ResponseCode(
407
):
# At this point, it's reasonable to assume that
# this is caused by invalid credentials.
debug("=" * 50)
Expand Down
Loading