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
22 changes: 17 additions & 5 deletions pyVoIP/SIP/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
key2peace marked this conversation as resolved.
Show resolved Hide resolved
password = credentials["password"]
nonce = request.authentication["nonce"]
method = request.headers["CSeq"]["method"]
Expand Down Expand Up @@ -1189,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(
Expand Down Expand Up @@ -1235,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)
Expand Down Expand Up @@ -1263,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)
Expand Down Expand Up @@ -1336,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)
Expand All @@ -1362,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)
Expand Down