第一步:UAC --> UAS
UAC向UAS发送注册信息:
Request-Line: REGISTER sip:192.168.35.165:5060 SIP/2.0
Method: REGISTER
Request-URI: sip:192.168.35.165:5060
Via: SIP/2.0/UDP 192.168.35.165:5080;rport;branch=z9hG4bK648439518
From: <sip:34020000001320000003@340200000>;tag=1492484359
To: <sip:34020000001320000003@340200000>
Call-ID: 445511141
CSeq: 1 REGISTER
Contact: <sip:34020000001320000003@192.168.35.165:5080;line=030bf7a750f46d9>
Authorization: Capability, algorithm="H:MD5"
Max-Forwards: 70
User-Agent: eXosip/4.1.0
Expires: 3600
Content-Length: 0
字段说明:
请求起始行: 表示UAC向IP地址为192.168.35.165的服务器发起注册,SIP版本号为2.0
From字段: 指明该REGISTER请求消息由UAS(IP地址:192.168.35.165)控制的UAC发起的。
To字段: 指明REGISTER请求接收方的地址。此时REGISTER请求的接收方为IP地址为192.168.35.165的UAS。(这个值和To头域的值相同,除非这个请求是第三方发起的注册请求。)
Call-ID字段: UAC发出的给某个注册服务器(registrar)的所有注册请求都应该有相同的Call-ID头域值。如果相同的客户端用了不同的Call-ID值,注册服务器(registrar)就不能检测是否一个REGISTER请求由于延时的关系导致了故障。
Cseq字段: Cseq值保证了REGISTER请求的正确顺序。一个UA为每一个具备相同的Call-ID的REGISTER请求顺序递增这个Cseq字段。
Contact字段: 在REGISTER请求中的Contact字段指明用户可达位置。
Expires字段: 表示该登记生存期为3600s。
Content-Length字段:表明此请求消息消息体的长度为空,即此消息不带会话描述。
第二步,UAS–>UAC
UAS返回401 Unauthorized(无权限)响应,表明要求对UAC进行用户认证,并且通过WWW-Authenticate字段携带UAS支持的认证方式,产生本次认证的nonce
Status-Line: SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.35.165:5080;rport=5080;branch=z9hG4bK648439518
From: <sip:34020000001320000003@340200000>;tag=1492484359
To: <sip:34020000001320000003@340200000>;tag=2251663018
Call-ID: 445511141
CSeq: 1 REGISTER
User-Agent: eXosip/4.0.0
WWW-Authenticate: Digest realm="34020000",algorithm=MD5,nonce="1616570703"
Date: 2021-03-24T15:25:03.253
Content-Length: 0
第三步,UAC–>UAS
UAC重新向UAS发起注册请求,携带WWW-Authorization字段
Request-Line: REGISTER sip:192.168.35.165:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.35.165:5080;rport;branch=z9hG4bK2907048769
From: <sip:34020000001320000003@340200000>;tag=1492484359
To: <sip:34020000001320000003@340200000>
Call-ID: 445511141
CSeq: 2 REGISTER
Contact: <sip:34020000001320000003@192.168.35.165:5080;line=030bf7a750f46d9>
Authorization: Digest username="34020000001320000003", realm="34020000", nonce="1616570703", uri="sip:192.168.35.165:5060", response="9c75261f524d20d385f1371c7a077505", algorithm=MD5
Max-Forwards: 70
User-Agent: eXosip/4.1.0
Expires: 3600
Content-Length: 0
第四步,UAS–>UAC
UAS收到UAC的注册请求,首先检查NONCE的正确性,如果和在401 Unauthorized响应中产生的NONCE相同,则通过。否则,直接返回失败。然后,UAS会根据NONCE、用户名、密码(服务器端可以根据本地用户信息获取用户的密码)、URI等采用和终端相同的算法生成
RESPONSE,并且对此RESPONSE和请求消息中的RESPONSE进行比较,如果二者一致则用户认证成功,否则认证失败。此时,UAS返回200 OK响应消息,表明终端认证成功。
Status-Line: SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.35.165:5080;rport=5080;branch=z9hG4bK2907048769
From: <sip:34020000001320000003@340200000>;tag=1492484359
To: <sip:34020000001320000003@340200000>;tag=4139998294
Call-ID: 445511141
CSeq: 2 REGISTER
User-Agent: eXosip/4.0.0
Date: 2021-03-24T15:25:03.259
Content-Length: 0
第五步、UAC发送请求消息
多了一个messagebody
Request-Line: MESSAGE sip:34020000001320000003@192.168.35.165:5080 SIP/2.0
Via: SIP/2.0/UDP 192.168.35.165:5060;rport;branch=z9hG4bK772385439
From: <sip:34020000002000000001@169.254.71.29:5060>;tag=1289075555
To: <sip:34020000001320000003@192.168.35.165:5080>
Call-ID: 540150356
CSeq: 20 MESSAGE
Content-Type: application/MANSCDP+xml
Max-Forwards: 70
User-Agent: eXosip/4.0.0
Date: 2021-03-24T15:25:03.263
Content-Length: 125
Message Body:
<?xml version="1.0"?>\r\n
<Query>\r\n
<CmdType>Catalog</CmdType>\r\n
<SN>1</SN>\r\n
<DeviceID>34020000001320000003</DeviceID>\r\n
</Query>\r\n
第六步、UAS发送确认消息
Status-Line: SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.35.165:5060;rport=5060;branch=z9hG4bK772385439
From: <sip:34020000002000000001@169.254.71.29:5060>;tag=1289075555
To: <sip:34020000001320000003@192.168.35.165:5080>;tag=1051246918
Call-ID: 540150356
CSeq: 20 MESSAGE
User-Agent: eXosip/4.1.0
Content-Length: 0
ps:
1.messagehead详解
2.服务器端参数设置:
3.客户端参数配置: