码迷,mamicode.com
首页 > 其他好文 > 详细

[音视频]Sip交互基本流程分析

时间:2020-05-16 12:48:36      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:cal   视频   content   contact   ati   red   cse   shark   length   

  最近在做SIP相关,整理下文档

  • 搭建freeSwitch SipServer
  • Sip终端的互call
  • 看起来数据是在裸奔的,WireShark抓包分析之

注册到SIP服务器时序

技术图片

 

1.client向server发送注册请求
REGISTER sip:114.116.224.107 SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPjYqs3EqEoCHrmDM5TdFDI8zYraI3mhzFM
Max-Forwards: 70
From: <sip:1005@114.116.224.107>;tag=CB.XiNZfHrSBvnAuqwHiZRt8DxvMi0T3
To: <sip:1005@114.116.224.107>
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49088 REGISTER
Contact: <sip:1005@10.93.244.6:5060;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length:  0

2.server返回401, 并带上密钥
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.93.244.6:5060;rport=5060;branch=z9hG4bKPjYqs3EqEoCHrmDM5TdFDI8zYraI3mhzFM
From: <sip:1005@114.116.224.107>;tag=CB.XiNZfHrSBvnAuqwHiZRt8DxvMi0T3
To: <sip:1005@114.116.224.107>;tag=rBKvaNN2cSj4e
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49088 REGISTER
User-Agent: FreeSWITCH-mod_sofia/1.10.2-release+git~20191231T140119Z~f7bdd3845a~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
WWW-Authenticate: Digest realm="114.116.224.107", nonce="c8ba50d5-eab6-4a1f-9aa7-9f8c88f96c90", algorithm=MD5, qop="auth" 
Content-Length: 0

3.server收到401和密钥,通过密钥加密注册密码,然后返回给server
REGISTER sip:114.116.224.107 SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPjycbsvrhaCRSwvM1BReQaULqjhPZj4u6J
Max-Forwards: 70
From: <sip:1005@114.116.224.107>;tag=CB.XiNZfHrSBvnAuqwHiZRt8DxvMi0T3
To: <sip:1005@114.116.224.107>
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49089 REGISTER
Contact: <sip:1005@10.93.244.6:5060;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Authorization: Digest username="1005", realm="114.116.224.107", nonce="c8ba50d5-eab6-4a1f-9aa7-9f8c88f96c90", uri="sip:114.116.224.107", response="948801fddf1be64200dc700367d832ef", algorithm=MD5, cnonce="jpgf75GhmNhZoxjqHZfthlhqfD4PGasJ", qop=auth, nc=00000001 //验证信息
Content-Length:  0

4.server返回200 验证成功
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.93.244.6:5060;rport=5060;branch=z9hG4bKPjycbsvrhaCRSwvM1BReQaULqjhPZj4u6J
From: <sip:1005@114.116.224.107>;tag=CB.XiNZfHrSBvnAuqwHiZRt8DxvMi0T3
To: <sip:1005@114.116.224.107>;tag=SmcNcg65918pa
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49089 REGISTER
Contact: <sip:1005@10.93.244.6:5060;ob>;expires=300
Date: Sun, 30 Mar 2020 03:22:15 GMT
User-Agent: FreeSWITCH-mod_sofia/1.10.2-release+git~20191231T140119Z~f7bdd3845a~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Content-Length: 0

 

  技术图片

 

1.client向server发送注销请求,REGISTER,Expires被设置为0
REGISTER sip:114.116.224.107 SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPjCqeYwimKf9L52BQCayGkV9sGGrsXFLkW
Max-Forwards: 70
From: <sip:1005@114.116.224.107>;tag=DYA25izzkD4rNjstBnvJPfAv487vsRP7
To: <sip:1005@114.116.224.107>
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49090 REGISTER
Contact: <sip:1005@10.93.244.6:5060;ob>
Expires: 0
Content-Length:  0

2.server带回验证key
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.93.244.6:5060;rport=5060;branch=z9hG4bKPjCqeYwimKf9L52BQCayGkV9sGGrsXFLkW
From: <sip:1005@114.116.224.107>;tag=DYA25izzkD4rNjstBnvJPfAv487vsRP7
To: <sip:1005@114.116.224.107>;tag=y1aHNQtQUermm
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49090 REGISTER
User-Agent: FreeSWITCH-mod_sofia/1.10.2-release+git~20191231T140119Z~f7bdd3845a~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
WWW-Authenticate: Digest realm="114.116.224.107", nonce="6710e4ba-e19f-403e-a3d7-65e628211b81", algorithm=MD5, qop="auth"
Content-Length: 0

3.client加密认证信息再次发送REGISTER
REGISTER sip:114.116.224.107 SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPjX6W-c9Wzo.3-shnAIByzLiET6o2R1-hb
Max-Forwards: 70
From: <sip:1005@114.116.224.107>;tag=DYA25izzkD4rNjstBnvJPfAv487vsRP7
To: <sip:1005@114.116.224.107>
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49091 REGISTER
Contact: <sip:1005@10.93.244.6:5060;ob>
Expires: 0
Authorization: Digest username="1005", realm="114.116.224.107", nonce="6710e4ba-e19f-403e-a3d7-65e628211b81", uri="sip:114.116.224.107", response="4bffa0240ce67296e5401c13e4235939", algorithm=MD5, cnonce="jpgf75GhmNhZoxjqHZfthlhqfD4PGasJ", qop=auth, nc=00000001
Content-Length:  0

4.验证成功,注销完成
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.93.244.6:5060;rport=5060;branch=z9hG4bKPjX6W-c9Wzo.3-shnAIByzLiET6o2R1-hb
From: <sip:1005@114.116.224.107>;tag=DYA25izzkD4rNjstBnvJPfAv487vsRP7
To: <sip:1005@114.116.224.107>;tag=Za49pjBUrQe7F
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49091 REGISTER
Date: Sun, 30 Mar 2020 03:22:35 GMT
User-Agent: FreeSWITCH-mod_sofia/1.10.2-release+git~20191231T140119Z~f7bdd3845a~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Content-Length: 0

 

 技术图片

 

REGISTER
用于向SIP服务器注册身份
REGISTER sip:114.116.224.107 SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPjYqs3EqEoCHrmDM5TdFDI8zYraI3mhzFM
Max-Forwards: 70
From: <sip:1005@114.116.224.107>;tag=CB.XiNZfHrSBvnAuqwHiZRt8DxvMi0T3
To: <sip:1005@114.116.224.107>
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49088 REGISTER
Contact: <sip:1005@10.93.244.6:5060;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length:  0

用于注销 (Expires 为 0)

REGISTER sip:114.116.224.107 SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPjX6W-c9Wzo.3-shnAIByzLiET6o2R1-hb
Max-Forwards: 70
From: <sip:1005@114.116.224.107>;tag=DYA25izzkD4rNjstBnvJPfAv487vsRP7
To: <sip:1005@114.116.224.107>
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49091 REGISTER
Contact: <sip:1005@10.93.244.6:5060;ob>
Expires: 0
Authorization: Digest username="1005", realm="114.116.224.107", nonce="6710e4ba-e19f-403e-a3d7-65e628211b81", uri="sip:114.116.224.107", response="4bffa0240ce67296e5401c13e4235939", algorithm=MD5, cnonce="jpgf75GhmNhZoxjqHZfthlhqfD4PGasJ", qop=auth, nc=00000001
Content-Length:  0
INVITE
通话建立信令 带上SDP进行媒体协商
INVITE sip:1002@114.116.224.107:5060 SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPj7mkDH292jmm1y6Y2Jkws.gWRKW40d8Kp
Max-Forwards: 70
From: sip:1005@114.116.224.107;tag=mBuoO4GR7-AC-XUHv0cgzvX16MuG4Kng
To: sip:1002@114.116.224.107
Contact: <sip:1005@10.93.244.6:5060;ob>
Call-ID: IqTLNL8Gfdx09DOa8VUFb9XCMncifRav
CSeq: 13594 INVITE
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Supported: replaces, 100rel, timer, norefersub
Session-Expires: 1800
Min-SE: 90
Proxy-Authorization: Digest username="1005", realm="114.116.224.107", nonce="f1e24226-ce30-4829-9614-a766901286bb", uri="sip:1002@114.116.224.107:5060", response="4d7707bcc2decb57d9a11cce6b08529d", algorithm=MD5, cnonce="4vUxSXgyvi49AycztD.GDdu171ISBQlF", qop=auth, nc=00000001
Content-Type: application/sdp
Content-Length:   741
 
v=0
o=- 3794527338 3794527338 IN IP4 10.93.244.6
s=pjmedia
b=AS:117
t=0 0
a=X-nat:0
m=audio 4000 RTP/AVP 96 97 98 99 3 0 8 9 100 120 121 122 123
c=IN IP4 10.93.244.6
b=TIAS:96000
a=rtcp:4001 IN IP4 10.93.244.6
a=sendrecv
a=rtpmap:96 speex/16000
a=rtpmap:97 speex/8000
a=rtpmap:98 speex/32000
a=rtpmap:99 iLBC/8000
a=fmtp:99 mode=30
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:9 G722/8000
a=rtpmap:100 opus/48000/2
a=fmtp:100 useinbandfec=1
a=rtpmap:120 telephone-event/16000
a=fmtp:120 0-16
a=rtpmap:121 telephone-event/8000
a=fmtp:121 0-16
a=rtpmap:122 telephone-event/32000
a=fmtp:122 0-16
a=rtpmap:123 telephone-event/48000
a=fmtp:123 0-16
a=ssrc:731817971 cname:5cc7c43d3f24b061
SIP/2.0 401 Unauthorized
拒绝连接,注册服务器,转发服务器用401返回验证信息要求客户端验证
客户端拿到key后对密码加密进行注册
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.93.244.6:5060;rport=5060;branch=z9hG4bKPjYqs3EqEoCHrmDM5TdFDI8zYraI3mhzFM
From: <sip:1005@114.116.224.107>;tag=CB.XiNZfHrSBvnAuqwHiZRt8DxvMi0T3
To: <sip:1005@114.116.224.107>;tag=rBKvaNN2cSj4e
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49088 REGISTER
User-Agent: FreeSWITCH-mod_sofia/1.10.2-release+git~20191231T140119Z~f7bdd3845a~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
WWW-Authenticate: Digest realm="114.116.224.107", nonce="c8ba50d5-eab6-4a1f-9aa7-9f8c88f96c90", algorithm=MD5, qop="auth"
Content-Length: 0
SIP/2.0 407 Proxy Authentication Required
proxy只能用407,也是拒绝连接,同时带上验证信息,要求客户端进行验证
SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP 10.93.244.6:5060;rport=5060;branch=z9hG4bKPjeLCrGcm6YPo9ntRNCkJJXWY6wMdZBWTe
From: <sip:1005@114.116.224.107>;tag=mBuoO4GR7-AC-XUHv0cgzvX16MuG4Kng
To: <sip:1002@114.116.224.107>;tag=U6y6F67c4KNvH
Call-ID: IqTLNL8Gfdx09DOa8VUFb9XCMncifRav
CSeq: 13593 INVITE
User-Agent: FreeSWITCH-mod_sofia/1.10.2-release+git~20191231T140119Z~f7bdd3845a~64bit
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Proxy-Authenticate: Digest realm="114.116.224.107", nonce="f1e24226-ce30-4829-9614-a766901286bb", algorithm=MD5, qop="auth"
Content-Length: 0
ACK
确认收到对方信息
ACK sip:1002@114.116.224.107:5060 SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPjeLCrGcm6YPo9ntRNCkJJXWY6wMdZBWTe
Max-Forwards: 70
From: sip:1005@114.116.224.107;tag=mBuoO4GR7-AC-XUHv0cgzvX16MuG4Kng
To: sip:1002@114.116.224.107;tag=U6y6F67c4KNvH
Call-ID: IqTLNL8Gfdx09DOa8VUFb9XCMncifRav
CSeq: 13593 ACK
Content-Length:  0
200 OK
行动成功接受
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.93.244.6:5060;rport=5060;branch=z9hG4bKPjX6W-c9Wzo.3-shnAIByzLiET6o2R1-hb
From: <sip:1005@114.116.224.107>;tag=DYA25izzkD4rNjstBnvJPfAv487vsRP7
To: <sip:1005@114.116.224.107>;tag=Za49pjBUrQe7F
Call-ID: jRZZL9t5obumvLrRrpgTvs8NlbY9Ts2O
CSeq: 49091 REGISTER
Date: Sun, 30 Mar 2020 03:22:35 GMT
User-Agent: FreeSWITCH-mod_sofia/1.10.2-release+git~20191231T140119Z~f7bdd3845a~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Content-Length: 0
BYE
客户端A发送到服务器,服务器发送到客户端B,B收到后断开连接返回 200OK 服务器再发200OK到A
A断开连接
整个连接断开
BYE sip:1002@114.116.224.107:5060;transport=udp SIP/2.0
Via: SIP/2.0/UDP 10.93.244.6:5060;rport;branch=z9hG4bKPjEb-cfykgn.pipVqIPwpR9e0Vte4VW96I
Max-Forwards: 70
From: sip:1005@114.116.224.107;tag=mBuoO4GR7-AC-XUHv0cgzvX16MuG4Kng
To: sip:1002@114.116.224.107;tag=vFrZH1rg1vBFD
Call-ID: IqTLNL8Gfdx09DOa8VUFb9XCMncifRav
CSeq: 13595 BYE
Content-Length:  0



[音视频]Sip交互基本流程分析

标签:cal   视频   content   contact   ati   red   cse   shark   length   

原文地址:https://www.cnblogs.com/zeolim/p/12899601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!