tayler6000 / pyVoIP

Pure python VoIP/SIP/RTP library. Currently supports PCMA, PCMU, and telephone-event
https://pypi.org/project/pyVoIP/
GNU General Public License v3.0
229 stars 105 forks source link

Tag in Request Line of ACK #101

Open jrozhon opened 1 year ago

jrozhon commented 1 year ago

Hi,

first, let me thank you for your work. I am on the development branch and found out that ACK requests are formatted improperly having ";tag=xxxx" in request line. Example:

ACK sip:402@x.x.x.x>;tag=z9hG4bK4e07408562bedb8b60ce05c1d SIP/2.0
Via: SIP/2.0/UDP x.x.x.x:5070;branch=z9hG4bK4e07408562bedb8b60ce05c1d;rport=5070;received=xxx
Max-Forwards: 70
To: "" <sip:402@x.x.x.x>;tag=251d4995
From: "" <sip:iptel401@x.x.x.x>;tag=4cb0f475
Call-ID: 4b227777d4dd1fc61c6f884f48641d02@x.x.x.x:5070
CSeq: 1 ACK
User-Agent: pyVoIP 2.0.0
Content-Length: 0

This comes from the fact that the request line is populated by the contents of request.headers["To"]["raw"].

I fixed it by:


--- pyVoIP_orig/pyVoIP/SIP.py   2023-01-23 17:14:24.520953996 +0100
+++ pyVoIP/pyVoIP/SIP.py        2023-01-23 17:40:44.314523342 +0100
@@ -1400,7 +1400,7 @@

     def gen_ack(self, request: SIPMessage) -> str:
         tag = self.tagLibrary[request.headers["Call-ID"]]
-        t = request.headers["To"]["raw"].strip("<").strip(">")
+        t = request.headers["To"]["uri"].strip("<").strip(">")
         ackMessage = f"ACK {t} SIP/2.0\r\n"
         ackMessage += self._gen_response_via_header(request)
         ackMessage += "Max-Forwards: 70\r\n"

Now, ACK seems to be properly formatted.

ACK sip:402@x.x.x.x SIP/2.0
Via: SIP/2.0/UDP x.x.x.x:5070;branch=z9hG4bK4e07408562bedb8b60ce05c1d;rport=5070;received=x.x.x.x
Max-Forwards: 70
To: "" <sip:402@x.x.x.x>;tag=5dc7fdbc
From: "" <sip:iptel401@x.x.x.x>;tag=9b47e14d
Call-ID: 4b227777d4dd1fc61c6f884f48641d02@x.x.x.x:5070
CSeq: 1 ACK
User-Agent: pyVoIP 2.0.0
Content-Length: 0

Please, let me know if I can help you fix this issue.

tayler6000 commented 1 year ago

This issue was resolved in the development branch in commit c3acacc. This is still an issue in pyVoIP v1.6.4 however. @jrozhon do you remember if this caused a PBX, UAS, Proxy, or similar to not accept the ACK? If so, this would be a broken feature and I would consider patching it and releasing v1.6.5.

Moving to the Todo - Patching status for now.

tayler6000 commented 1 year ago

Upon further checking, this is actually not an issue in master.

jrozhon commented 1 year ago

Hi, in my case, it caused Asterisk to ignore the ACK, but I think this would be a general issue