[Home]

Summary:ASTERISK-20745: In MESSAGE received over WebSocket, the body last char is cut
Reporter:Iñaki Baz Castillo (ibc)Labels:
Date Opened:2012-11-27 11:24:44.000-0600Date Closed:2012-11-29 10:54:45.000-0600
Priority:MajorRegression?
Status:Closed/CompleteComponents:Channels/chan_sip/WebSocket
Versions:SVN 11.0.1 Frequency of
Occurrence
Constant
Related
Issues:
Environment:Attachments:
Description:When Asterisk receives a SIP MESSAGE over WebSocket it cuts the last char of the body. So if for example the MESSAGE contains "Content-Length: 4" and a body with content "1234" (without quotes), the Asterisk debug console prints the body as "123", and then it forwards the MESSAGE with "123" as body.

This bug seems not to occur when the SIP MESSAGE arrives via SIP over TCP or UDP, so it must be a bug in the SIP WebSocket layer/parser.
Comments:By: Pedro Kiefer (pedrokiefer) 2012-11-27 11:56:37.435-0600

JsSIP Console:
{noformat}
JsSIP | TRANSPORT | Sending WebSocket message:

MESSAGE sip:1111@172.20.31.134 SIP/2.0
Route: <sip:172.20.31.134:8088;transport=ws;lr>
Via: SIP/2.0/TCP 42.107.20.23;branch=z9hG4bK4369947
Max-Forwards: 69
To: sip:1111@172.20.31.134
From: sip:1236@172.20.31.134;tag=cbpmz73k95
Call-ID: az55yytkaq71ta7fd2t9
CSeq: 9439 MESSAGE
Authorization: Digest username="1236",realm="tecnosenior.com",nonce="2ca4080c",uri="sip:1111@172.20.31.134",response="c57c696f92891beb9e61eccae8320620",algorithm=MD5
Content-Type: text/plain
Supported: path, outbound, gruu
User-Agent: JsSIP 0.2.1
Content-Length: 4

qwer
{noformat}

Wireshark on the same machine as JsSIP:
{noformat}
No.     Time           Source                Destination           Protocol Length Info
   501 20.984410000   172.20.31.142         172.20.31.134         WebSocket 467    WebSocket Text [FIN] [MASKED]

Frame 501: 467 bytes on wire (3736 bits), 467 bytes captured (3736 bits) on interface 0
Ethernet II, Src: Apple_b0:c1:02 (00:1e:c2:b0:c1:02), Dst: CadmusCo_5a:01:55 (08:00:27:5a:01:55)
Internet Protocol Version 4, Src: 172.20.31.142 (172.20.31.142), Dst: 172.20.31.134 (172.20.31.134)
Transmission Control Protocol, Src Port: 53506 (53506), Dst Port: radan-http (8088), Seq: 8106, Ack: 5916, Len: 401
Hypertext Transfer Protocol
WebSocket
   1... .... = Fin: True
   .000 .... = Reserved: 0x00
   .... 0001 = Opcode: Text (1)
   1... .... = Mask: True
   .111 1110 = Payload length: 126 Extended Payload Length (16 bits)
   Extended Payload length (16 bits): 393
   Masking-Key: e3140db9
   Payload
       Text: ae515eeaa2534899907d7d83d2253c88a3253a8bcd263d97...
   Unmask Payload
0000   4d 45 53 53 41 47 45 20 73 69 70 3a 31 31 31 31  MESSAGE sip:1111
0010   40 31 37 32 2e 32 30 2e 33 31 2e 31 33 34 20 53  @172.20.31.134 S
0020   49 50 2f 32 2e 30 0d 0a 52 6f 75 74 65 3a 20 3c  IP/2.0..Route: <
0030   73 69 70 3a 31 37 32 2e 32 30 2e 33 31 2e 31 33  sip:172.20.31.13
0040   34 3a 38 30 38 38 3b 74 72 61 6e 73 70 6f 72 74  4:8088;transport
0050   3d 77 73 3b 6c 72 3e 0d 0a 56 69 61 3a 20 53 49  =ws;lr>..Via: SI
0060   50 2f 32 2e 30 2f 54 43 50 20 34 32 2e 31 30 37  P/2.0/TCP 42.107
0070   2e 32 30 2e 32 33 3b 62 72 61 6e 63 68 3d 7a 39  .20.23;branch=z9
0080   68 47 34 62 4b 35 38 37 33 35 37 31 0d 0a 4d 61  hG4bK5873571..Ma
0090   78 2d 46 6f 72 77 61 72 64 73 3a 20 36 39 0d 0a  x-Forwards: 69..
00a0   54 6f 3a 20 73 69 70 3a 31 31 31 31 40 31 37 32  To: sip:1111@172
00b0   2e 32 30 2e 33 31 2e 31 33 34 0d 0a 46 72 6f 6d  .20.31.134..From
00c0   3a 20 73 69 70 3a 31 32 33 36 40 31 37 32 2e 32  : sip:1236@172.2
00d0   30 2e 33 31 2e 31 33 34 3b 74 61 67 3d 63 62 70  0.31.134;tag=cbp
00e0   6d 7a 37 33 6b 39 35 0d 0a 43 61 6c 6c 2d 49 44  mz73k95..Call-ID
00f0   3a 20 61 7a 35 35 79 79 74 6b 61 71 37 31 74 61  : az55yytkaq71ta
0100   37 66 64 32 74 39 0d 0a 43 53 65 71 3a 20 39 34  7fd2t9..CSeq: 94
0110   33 38 20 4d 45 53 53 41 47 45 0d 0a 43 6f 6e 74  38 MESSAGE..Cont
0120   65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 70  ent-Type: text/p
0130   6c 61 69 6e 0d 0a 53 75 70 70 6f 72 74 65 64 3a  lain..Supported:
0140   20 70 61 74 68 2c 20 6f 75 74 62 6f 75 6e 64 2c   path, outbound,
0150   20 67 72 75 75 0d 0a 55 73 65 72 2d 41 67 65 6e   gruu..User-Agen
0160   74 3a 20 4a 73 53 49 50 20 30 2e 32 2e 31 0d 0a  t: JsSIP 0.2.1..
0170   43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20  Content-Length:
0180   34 0d 0a 0d 0a 71 77 65 72                       4....qwer
{noformat}
Asterisk SIP debug output:
{noformat}
<--- SIP read from WS:172.20.31.142:53506 --->
MESSAGE sip:1111@172.20.31.134 SIP/2.0
Route: <sip:172.20.31.134:8088;transport=ws;lr>
Via: SIP/2.0/TCP 42.107.20.23;branch=z9hG4bK5873571
Max-Forwards: 69
To: sip:1111@172.20.31.134
From: sip:1236@172.20.31.134;tag=cbpmz73k95
Call-ID: az55yytkaq71ta7fd2t9
CSeq: 9438 MESSAGE
Content-Type: text/plain
Supported: path, outbound, gruu
User-Agent: JsSIP 0.2.1
Content-Length: 4

qwe
<------------->
{noformat}

By: Iñaki Baz Castillo (ibc) 2012-11-27 16:21:52.156-0600

Probably the bug also exists when processing a SDP received in an INVITE over WebSocket, but SDP's usually end in CRLF so removing the last char is not so "important". Not sure about it however.

For sure this is a bug in the WebSocket layer. This issue does not occur when using other WebSocket capable SIP servers/proxies. And it's clear in the above wireshark capture that the web browser is sending a correct MESSAGE with body "qwer".

By: Pedro Kiefer (pedrokiefer) 2012-11-28 07:55:00.671-0600

I've added some debug to ast_websocket_read, and it's receiving all the bytes correctly, so it's probably something on chan_sip.

{noformat}
------
Length: 0x189, iter: 19
0000 4D 45 53 53 41 47 45 20 73 69 70 3A 31 31 31 31 MESSAGE sip:1111
0010 40 31 37 32 2E 32 30 2E 33 31 2E 31 33 34 20 53 @172.20.31.134 S
0020 49 50 2F 32 2E 30 0D 0A 52 6F 75 74 65 3A 20 3C IP/2.0..Route: <
0030 73 69 70 3A 31 37 32 2E 32 30 2E 33 31 2E 31 33 sip:172.20.31.13
0040 34 3A 38 30 38 38 3B 74 72 61 6E 73 70 6F 72 74 4:8088;transport
0050 3D 77 73 3B 6C 72 3E 0D 0A 56 69 61 3A 20 53 49 =ws;lr>..Via: SI
0060 50 2F 32 2E 30 2F 54 43 50 20 31 35 38 2E 37 32 P/2.0/TCP 158.72
0070 2E 35 33 2E 39 39 3B 62 72 61 6E 63 68 3D 7A 39 .53.99;branch=z9
0080 68 47 34 62 4B 35 31 39 38 33 34 35 0D 0A 4D 61 hG4bK5198345..Ma
0090 78 2D 46 6F 72 77 61 72 64 73 3A 20 36 39 0D 0A x-Forwards: 69..
00a0 54 6F 3A 20 73 69 70 3A 31 31 31 31 40 31 37 32 To: sip:1111@172
00b0 2E 32 30 2E 33 31 2E 31 33 34 0D 0A 46 72 6F 6D .20.31.134..From
00c0 3A 20 73 69 70 3A 31 32 33 36 40 31 37 32 2E 32 : sip:1236@172.2
00d0 30 2E 33 31 2E 31 33 34 3B 74 61 67 3D 62 63 65 0.31.134;tag=bce
00e0 34 74 6C 72 74 39 70 0D 0A 43 61 6C 6C 2D 49 44 4tlrt9p..Call-ID
00f0 3A 20 74 69 74 78 69 73 6E 71 6D 37 37 39 6B 64 : titxisnqm779kd
0100 6A 64 75 30 75 64 0D 0A 43 53 65 71 3A 20 38 35 jdu0ud..CSeq: 85
0110 37 31 20 4D 45 53 53 41 47 45 0D 0A 43 6F 6E 74 71 MESSAGE..Cont
0120 65 6E 74 2D 54 79 70 65 3A 20 74 65 78 74 2F 70 ent-Type: text/p
0130 6C 61 69 6E 0D 0A 53 75 70 70 6F 72 74 65 64 3A lain..Supported:
0140 20 70 61 74 68 2C 20 6F 75 74 62 6F 75 6E 64 2C  path, outbound,
0150 20 67 72 75 75 0D 0A 55 73 65 72 2D 41 67 65 6E  gruu..User-Agen
0160 74 3A 20 4A 73 53 49 50 20 30 2E 32 2E 31 0D 0A t: JsSIP 0.2.1..
0170 43 6F 6E 74 65 6E 74 2D 4C 65 6E 67 74 68 3A 20 Content-Length:
0180 34 0D 0A 0D 0A 61 73 64 66                      4....asdf      
------
{noformat}

By: Pedro Kiefer (pedrokiefer) 2012-11-28 10:30:22.313-0600

Dumping data on the end of ast_websocket_read gives me:
{noformat}
------
Length: 0x231, iter: 24
0000 4D 45 53 53 41 47 45 20 73 69 70 3A 31 31 31 31 MESSAGE sip:1111
0010 40 31 37 32 2E 32 30 2E 33 31 2E 31 33 34 20 53 @172.20.31.134 S
0020 49 50 2F 32 2E 30 0D 0A 52 6F 75 74 65 3A 20 3C IP/2.0..Route: <
0030 73 69 70 3A 31 37 32 2E 32 30 2E 33 31 2E 31 33 sip:172.20.31.13
0040 34 3A 38 30 38 38 3B 74 72 61 6E 73 70 6F 72 74 4:8088;transport
0050 3D 77 73 3B 6C 72 3E 0D 0A 56 69 61 3A 20 53 49 =ws;lr>..Via: SI
0060 50 2F 32 2E 30 2F 54 43 50 20 32 34 2E 31 30 39 P/2.0/TCP 24.109
0070 2E 32 38 2E 32 33 3B 62 72 61 6E 63 68 3D 7A 39 .28.23;branch=z9
0080 68 47 34 62 4B 34 34 31 31 33 32 38 0D 0A 4D 61 hG4bK4411328..Ma
0090 78 2D 46 6F 72 77 61 72 64 73 3A 20 36 39 0D 0A x-Forwards: 69..
00a0 54 6F 3A 20 73 69 70 3A 31 31 31 31 40 31 37 32 To: sip:1111@172
00b0 2E 32 30 2E 33 31 2E 31 33 34 0D 0A 46 72 6F 6D .20.31.134..From
00c0 3A 20 73 69 70 3A 31 32 33 36 40 31 37 32 2E 32 : sip:1236@172.2
00d0 30 2E 33 31 2E 31 33 34 3B 74 61 67 3D 6B 30 6D 0.31.134;tag=k0m
00e0 6D 74 77 31 31 79 6E 0D 0A 43 61 6C 6C 2D 49 44 mtw11yn..Call-ID
00f0 3A 20 64 6D 77 75 6A 31 6D 6A 6F 71 39 32 61 34 : dmwuj1mjoq92a4
0100 6A 38 75 6D 63 78 0D 0A 43 53 65 71 3A 20 34 39 j8umcx..CSeq: 49
0110 37 38 20 4D 45 53 53 41 47 45 0D 0A 41 75 74 68 78 MESSAGE..Auth
0120 6F 72 69 7A 61 74 69 6F 6E 3A 20 44 69 67 65 73 orization: Diges
0130 74 20 75 73 65 72 6E 61 6D 65 3D 22 31 32 33 36 t username="1236
0140 22 2C 72 65 61 6C 6D 3D 22 74 65 63 6E 6F 73 65 ",realm="tecnose
0150 6E 69 6F 72 2E 63 6F 6D 22 2C 6E 6F 6E 63 65 3D nior.com",nonce=
0160 22 35 34 64 62 63 62 33 37 22 2C 75 72 69 3D 22 "54dbcb37",uri="
0170 73 69 70 3A 31 31 31 31 40 31 37 32 2E 32 30 2E sip:1111@172.20.
0180 33 31 2E 31 33 34 22 2C 72 65 73 70 6F 6E 73 65 31.134",response
0190 3D 22 34 30 30 65 36 34 64 32 34 30 66 63 34 39 ="400e64d240fc49
01a0 30 66 34 30 62 30 63 65 35 63 64 64 39 63 39 61 0f40b0ce5cdd9c9a
01b0 62 38 22 2C 61 6C 67 6F 72 69 74 68 6D 3D 4D 44 b8",algorithm=MD
01c0 35 0D 0A 43 6F 6E 74 65 6E 74 2D 54 79 70 65 3A 5..Content-Type:
01d0 20 74 65 78 74 2F 70 6C 61 69 6E 0D 0A 53 75 70  text/plain..Sup
01e0 70 6F 72 74 65 64 3A 20 70 61 74 68 2C 20 6F 75 ported: path, ou
01f0 74 62 6F 75 6E 64 2C 20 67 72 75 75 0D 0A 55 73 tbound, gruu..Us
0200 65 72 2D 41 67 65 6E 74 3A 20 4A 73 53 49 50 20 er-Agent: JsSIP
0210 30 2E 32 2E 31 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 0.2.1..Content-L
0220 65 6E 67 74 68 3A 20 35 0D 0A 0D 0A 71 77 65 72 ength: 5....qwer
0230 74                                              t              
------
{noformat}

Doing the same thing on chan_sip, sip_websocket_callback function, right after copying the payload data to struct sip_request.data (using ast_str_create and ast_str_set). I've dumped it calling ast_str_buffer and ast_str_size. As you can notice the size is the same, but the last char is not 0x74 but 0x00.

{noformat}
******
Length: 0x231, iter: 24
0000 4D 45 53 53 41 47 45 20 73 69 70 3A 31 31 31 31 MESSAGE sip:1111
0010 40 31 37 32 2E 32 30 2E 33 31 2E 31 33 34 20 53 @172.20.31.134 S
0020 49 50 2F 32 2E 30 0D 0A 52 6F 75 74 65 3A 20 3C IP/2.0..Route: <
0030 73 69 70 3A 31 37 32 2E 32 30 2E 33 31 2E 31 33 sip:172.20.31.13
0040 34 3A 38 30 38 38 3B 74 72 61 6E 73 70 6F 72 74 4:8088;transport
0050 3D 77 73 3B 6C 72 3E 0D 0A 56 69 61 3A 20 53 49 =ws;lr>..Via: SI
0060 50 2F 32 2E 30 2F 54 43 50 20 32 34 2E 31 30 39 P/2.0/TCP 24.109
0070 2E 32 38 2E 32 33 3B 62 72 61 6E 63 68 3D 7A 39 .28.23;branch=z9
0080 68 47 34 62 4B 34 34 31 31 33 32 38 0D 0A 4D 61 hG4bK4411328..Ma
0090 78 2D 46 6F 72 77 61 72 64 73 3A 20 36 39 0D 0A x-Forwards: 69..
00a0 54 6F 3A 20 73 69 70 3A 31 31 31 31 40 31 37 32 To: sip:1111@172
00b0 2E 32 30 2E 33 31 2E 31 33 34 0D 0A 46 72 6F 6D .20.31.134..From
00c0 3A 20 73 69 70 3A 31 32 33 36 40 31 37 32 2E 32 : sip:1236@172.2
00d0 30 2E 33 31 2E 31 33 34 3B 74 61 67 3D 6B 30 6D 0.31.134;tag=k0m
00e0 6D 74 77 31 31 79 6E 0D 0A 43 61 6C 6C 2D 49 44 mtw11yn..Call-ID
00f0 3A 20 64 6D 77 75 6A 31 6D 6A 6F 71 39 32 61 34 : dmwuj1mjoq92a4
0100 6A 38 75 6D 63 78 0D 0A 43 53 65 71 3A 20 34 39 j8umcx..CSeq: 49
0110 37 38 20 4D 45 53 53 41 47 45 0D 0A 41 75 74 68 78 MESSAGE..Auth
0120 6F 72 69 7A 61 74 69 6F 6E 3A 20 44 69 67 65 73 orization: Diges
0130 74 20 75 73 65 72 6E 61 6D 65 3D 22 31 32 33 36 t username="1236
0140 22 2C 72 65 61 6C 6D 3D 22 74 65 63 6E 6F 73 65 ",realm="tecnose
0150 6E 69 6F 72 2E 63 6F 6D 22 2C 6E 6F 6E 63 65 3D nior.com",nonce=
0160 22 35 34 64 62 63 62 33 37 22 2C 75 72 69 3D 22 "54dbcb37",uri="
0170 73 69 70 3A 31 31 31 31 40 31 37 32 2E 32 30 2E sip:1111@172.20.
0180 33 31 2E 31 33 34 22 2C 72 65 73 70 6F 6E 73 65 31.134",response
0190 3D 22 34 30 30 65 36 34 64 32 34 30 66 63 34 39 ="400e64d240fc49
01a0 30 66 34 30 62 30 63 65 35 63 64 64 39 63 39 61 0f40b0ce5cdd9c9a
01b0 62 38 22 2C 61 6C 67 6F 72 69 74 68 6D 3D 4D 44 b8",algorithm=MD
01c0 35 0D 0A 43 6F 6E 74 65 6E 74 2D 54 79 70 65 3A 5..Content-Type:
01d0 20 74 65 78 74 2F 70 6C 61 69 6E 0D 0A 53 75 70  text/plain..Sup
01e0 70 6F 72 74 65 64 3A 20 70 61 74 68 2C 20 6F 75 ported: path, ou
01f0 74 62 6F 75 6E 64 2C 20 67 72 75 75 0D 0A 55 73 tbound, gruu..Us
0200 65 72 2D 41 67 65 6E 74 3A 20 4A 73 53 49 50 20 er-Agent: JsSIP
0210 30 2E 32 2E 31 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 0.2.1..Content-L
0220 65 6E 67 74 68 3A 20 35 0D 0A 0D 0A 71 77 65 72 ength: 5....qwer
0230 00                                              .              
******
{noformat}

By: Joshua C. Colp (jcolp) 2012-11-29 10:56:00.350-0600

Pedro - This fix is applicable to Asterisk 11 and not just trunk. Can you please commit it there as well?

By: Pedro Kiefer (pedrokiefer) 2012-11-29 10:58:13.651-0600

Joshua,
Sure, I'll do that in a moment.