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


      最近在做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



  • 相关阅读:
    JavaScript 学习36.jQuery 获取和修改HTML 上海
    JavaScript 学习39.jQuery Ajax请求 上海
    低代码和人工智能助力疫情期间抗原自测信息自动化收集和处理
    使用Kafka时一定要注意防止消费速度过慢触发rebalance而导致的重复消费
    Cogview2:更快更好的文生图分层Transformer模型
    android root 更改system/app内容
    极钛星华pro1T智能话机(点评管家/美味不用等)型号p1A32 开启adb root等
    go CRUD
    delphi restfulWiRL
    delphi面向服务开发解决方案
  • 原文地址:https://www.cnblogs.com/zeolim/p/12899601.html
Copyright © 2020-2023  润新知