Skip to content

Calls terminating because messages apply randomly generated "To" tags #312

Description

@hseidema

Was trying to initiate outbound calls, but found that calls were being terminated after only 6 seconds. Looking through the PCAP logs, I saw that my voip provider was providing a 200 OK (INVITE) response for the call initiation, with from and to tags in the header. pyVoIP responded with an ACK message that provided the correct From tag in the header, but randomly generated a To tag. This caused the ACK to not be accepted by the server side, causing repeated attempts to complete the handshake before the call was terminated.

Was able to resolve the problem by modifying SIP.py at line 1565 by changing

ackMessage += (
    f"To: {request.headers['To']['raw']};tag="
    + f"{self.gen_tag()}\r\n"
)

to

to_header = request.headers['To']['raw']
if 'tag' in request.headers['To']:
    ackMessage += f"To: {to_header};tag={request.headers['To']['tag']}\r\n"
else:
    ackMessage += f"To: {to_header}\r\n"

A similar problem exists in the responses to BYE requests at line 1308 of SIP.py, where the current code copies the From tag from the request and then randomly generates a To tag. The code in question:

okResponse += (
    f"From: {request.headers['From']['raw']};tag="
    + f"{request.headers['From']['tag']}\r\n"
)
okResponse += (
    f"To: {request.headers['To']['raw']};tag="
    + f"{self.gen_tag()}\r\n"
)

Correcting these errors caused the handshakes to complete properly and calls to continue until intentionally terminated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions