SIP 注册过程
2015-07-10 15:43
375 查看
SIP协议包含两种类型的消息,一种是请求行用于发出邀请,而另一种则是状态行,用于标明当前通信的状态。请求行和状态行军包含三部分,其中每一部分以空格隔开,不论是请求行还是状态行均以CRLF换行符结束。在请求行中,三部分内容分别为Method 请求URI和SIP版本号。如下例所示:
Request-Line: REGISTER sip:192.169.1.150 SIP/2.0
在这里方法是REGISTER,也就是注册。空格之后的sip:192.169.1.150则是请求到达的URI目的地址,SIP/2.0则是SIP的版本号。
Status-Line: SIP/2.0 407 Proxy Authentication Required
状态行的例子如上所示,第一个部分和请求行的解释一样被作为SIP的版本号,第二部分则是一个状态码,类似于浏览器访问出现的404;最后一个部分则是对第二部分状态码进行一个简单的解释。
在上面两种行消息之后是消息头部,消息头部的组成也是以文本字符进行编码的。同样的,消息头部的每一个字段都是以CRLF换行作为结尾符。而每一个字段的格式如下:
Via: SIP/2.0/UDP 192.169.1.147:39814;rport;branch=z9hG4bK80051
上面是定义SIP消息头部字段格式的一种示例,冒号前面的是字段的名称,这里表示消息传递出去经过的路径;而第二部分则是传递的使用到的协议——基于UDP的SIP(SIP也可以基于TCP进行实现),第三部分则是起始地址的IP地址和端口号。第四部分的rport告诉服务器,哪里来的消息从哪里发送回去——IP和端口号都不会改变。第五部分则是一个标志ID,标志ID的前七个字母类似于一个魔数用于区别其他的协议。
下面看一个完整的SIP用户和用户代理之间的鉴权认证过程。
Session Initiation Protocol (REGISTER)
Request-Line: REGISTER sip:192.169.1.150 SIP/2.0
Method: REGISTER
Request-URI: sip:192.169.1.150
[Resent Packet: False]
Message Header
Via: SIP/2.0/UDP 192.169.1.147:39814;rport;branch=z9hG4bK80051
Max-Forwards: 70
To: <sip:102@192.169.1.150>
SIP to address: sip:102@192.169.1.150
From: <sip:102@192.169.1.150>;tag=z9hG4bK17086172
SIP from address: sip:102@192.169.1.150
SIP from tag: z9hG4bK17086172
Call-ID: 281574552997@192.169.1.147
CSeq: 1 REGISTER
Sequence Number: 1
Method: REGISTER
Contact: <sip:102@192.169.1.147:39814;transport=udp>
Contact URI: sip:102@192.169.1.147:39814;transport=udp
Expires: 3600
User-Agent: Sipdroid/3.6 beta
Content-Length: 0
Session Initiation Protocol (407)
Status-Line: SIP/2.0 407 Proxy Authentication Required
Status-Code: 407
[Resent Packet: False]
[Request Frame: 1322]
[Response Time (ms): 0]
Message Header
Via: SIP/2.0/UDP 192.169.1.147:39814;branch=z9hG4bK80051;received=192.169.1.147;rport=39814
From: <sip:102@192.169.1.150>;tag=z9hG4bK17086172
SIP from address: sip:102@192.169.1.150
SIP from tag: z9hG4bK17086172
To: <sip:102@192.169.1.150>;tag=13d0075e
SIP to address: sip:102@192.169.1.150
SIP to tag: 13d0075e
CSeq: 1 REGISTER
Sequence Number: 1
Method: REGISTER
Call-ID: 281574552997@192.169.1.147
Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE
User-Agent: miniSIPServer V16.0.7 (100 clients) build 20150324
Proxy-Authenticate: Digest realm="myvoipapp.com",algorithm=MD5,nonce="328E3DAF06BC5374001D626160CB1C21",stale=FALSE
Authentication Scheme: Digest
Realm: "myvoipapp.com"
Algorithm: MD5
Nonce Value: "328E3DAF06BC5374001D626160CB1C21"
Stale Flag: FALSE
Content-Length: 0
Session Initiation Protocol (REGISTER)
Request-Line: REGISTER sip:192.169.1.150 SIP/2.0
Method: REGISTER
Request-URI: sip:192.169.1.150
[Resent Packet: False]
Message Header
Via: SIP/2.0/UDP 192.169.1.147:39814;rport;branch=z9hG4bK99109
Max-Forwards: 70
To: <sip:102@192.169.1.150>
SIP to address: sip:102@192.169.1.150
From: <sip:102@192.169.1.150>;tag=z9hG4bK17086172
SIP from address: sip:102@192.169.1.150
SIP from tag: z9hG4bK17086172
Call-ID: 281574552997@192.169.1.147
CSeq: 2 REGISTER
Sequence Number: 2
Method: REGISTER
Contact: <sip:102@192.169.1.147:39814;transport=udp>
Contact URI: sip:102@192.169.1.147:39814;transport=udp
Expires: 3600
User-Agent: Sipdroid/3.6 beta
Proxy-Authorization: Digest username="102", realm="myvoipapp.com", nonce="328E3DAF06BC5374001D626160CB1C21", uri="sip:192.169.1.150", algorithm=MD5, response="bdf9504e7f2e0d6c685e57f9eef22f43"
Authentication Scheme: Digest
Username: "102"
Realm: "myvoipapp.com"
Nonce Value: "328E3DAF06BC5374001D626160CB1C21"
Authentication URI: "sip:192.169.1.150"
Algorithm: MD5
Digest Authentication Response: "bdf9504e7f2e0d6c685e57f9eef22f43"
Content-Length: 0
Session Initiation Protocol (200)
Status-Line: SIP/2.0 200 OK
Status-Code: 200
[Resent Packet: False]
[Request Frame: 1324]
[Response Time (ms): 0]
Message Header
Via: SIP/2.0/UDP 192.169.1.147:39814;branch=z9hG4bK99109;received=192.169.1.147;rport=39814
From: <sip:102@192.169.1.150>;tag=z9hG4bK17086172
SIP from address: sip:102@192.169.1.150
SIP from tag: z9hG4bK17086172
To: <sip:102@192.169.1.150>;tag=55d70430
SIP to address: sip:102@192.169.1.150
SIP to tag: 55d70430
CSeq: 2 REGISTER
Sequence Number: 2
Method: REGISTER
Call-ID: 281574552997@192.169.1.147
Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE
User-Agent: miniSIPServer V16.0.7 (100 clients) build 20150324
Contact: <sip:102@192.169.1.147:39814;transport=udp>
Contact URI: sip:102@192.169.1.147:39814;transport=udp
Expires: 180
Content-Length: 0
Request-Line: REGISTER sip:192.169.1.150 SIP/2.0
在这里方法是REGISTER,也就是注册。空格之后的sip:192.169.1.150则是请求到达的URI目的地址,SIP/2.0则是SIP的版本号。
Status-Line: SIP/2.0 407 Proxy Authentication Required
状态行的例子如上所示,第一个部分和请求行的解释一样被作为SIP的版本号,第二部分则是一个状态码,类似于浏览器访问出现的404;最后一个部分则是对第二部分状态码进行一个简单的解释。
在上面两种行消息之后是消息头部,消息头部的组成也是以文本字符进行编码的。同样的,消息头部的每一个字段都是以CRLF换行作为结尾符。而每一个字段的格式如下:
Via: SIP/2.0/UDP 192.169.1.147:39814;rport;branch=z9hG4bK80051
上面是定义SIP消息头部字段格式的一种示例,冒号前面的是字段的名称,这里表示消息传递出去经过的路径;而第二部分则是传递的使用到的协议——基于UDP的SIP(SIP也可以基于TCP进行实现),第三部分则是起始地址的IP地址和端口号。第四部分的rport告诉服务器,哪里来的消息从哪里发送回去——IP和端口号都不会改变。第五部分则是一个标志ID,标志ID的前七个字母类似于一个魔数用于区别其他的协议。
下面看一个完整的SIP用户和用户代理之间的鉴权认证过程。
Session Initiation Protocol (REGISTER)
Request-Line: REGISTER sip:192.169.1.150 SIP/2.0
Method: REGISTER
Request-URI: sip:192.169.1.150
[Resent Packet: False]
Message Header
Via: SIP/2.0/UDP 192.169.1.147:39814;rport;branch=z9hG4bK80051
Max-Forwards: 70
To: <sip:102@192.169.1.150>
SIP to address: sip:102@192.169.1.150
From: <sip:102@192.169.1.150>;tag=z9hG4bK17086172
SIP from address: sip:102@192.169.1.150
SIP from tag: z9hG4bK17086172
Call-ID: 281574552997@192.169.1.147
CSeq: 1 REGISTER
Sequence Number: 1
Method: REGISTER
Contact: <sip:102@192.169.1.147:39814;transport=udp>
Contact URI: sip:102@192.169.1.147:39814;transport=udp
Expires: 3600
User-Agent: Sipdroid/3.6 beta
Content-Length: 0
Session Initiation Protocol (407)
Status-Line: SIP/2.0 407 Proxy Authentication Required
Status-Code: 407
[Resent Packet: False]
[Request Frame: 1322]
[Response Time (ms): 0]
Message Header
Via: SIP/2.0/UDP 192.169.1.147:39814;branch=z9hG4bK80051;received=192.169.1.147;rport=39814
From: <sip:102@192.169.1.150>;tag=z9hG4bK17086172
SIP from address: sip:102@192.169.1.150
SIP from tag: z9hG4bK17086172
To: <sip:102@192.169.1.150>;tag=13d0075e
SIP to address: sip:102@192.169.1.150
SIP to tag: 13d0075e
CSeq: 1 REGISTER
Sequence Number: 1
Method: REGISTER
Call-ID: 281574552997@192.169.1.147
Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE
User-Agent: miniSIPServer V16.0.7 (100 clients) build 20150324
Proxy-Authenticate: Digest realm="myvoipapp.com",algorithm=MD5,nonce="328E3DAF06BC5374001D626160CB1C21",stale=FALSE
Authentication Scheme: Digest
Realm: "myvoipapp.com"
Algorithm: MD5
Nonce Value: "328E3DAF06BC5374001D626160CB1C21"
Stale Flag: FALSE
Content-Length: 0
Session Initiation Protocol (REGISTER)
Request-Line: REGISTER sip:192.169.1.150 SIP/2.0
Method: REGISTER
Request-URI: sip:192.169.1.150
[Resent Packet: False]
Message Header
Via: SIP/2.0/UDP 192.169.1.147:39814;rport;branch=z9hG4bK99109
Max-Forwards: 70
To: <sip:102@192.169.1.150>
SIP to address: sip:102@192.169.1.150
From: <sip:102@192.169.1.150>;tag=z9hG4bK17086172
SIP from address: sip:102@192.169.1.150
SIP from tag: z9hG4bK17086172
Call-ID: 281574552997@192.169.1.147
CSeq: 2 REGISTER
Sequence Number: 2
Method: REGISTER
Contact: <sip:102@192.169.1.147:39814;transport=udp>
Contact URI: sip:102@192.169.1.147:39814;transport=udp
Expires: 3600
User-Agent: Sipdroid/3.6 beta
Proxy-Authorization: Digest username="102", realm="myvoipapp.com", nonce="328E3DAF06BC5374001D626160CB1C21", uri="sip:192.169.1.150", algorithm=MD5, response="bdf9504e7f2e0d6c685e57f9eef22f43"
Authentication Scheme: Digest
Username: "102"
Realm: "myvoipapp.com"
Nonce Value: "328E3DAF06BC5374001D626160CB1C21"
Authentication URI: "sip:192.169.1.150"
Algorithm: MD5
Digest Authentication Response: "bdf9504e7f2e0d6c685e57f9eef22f43"
Content-Length: 0
Session Initiation Protocol (200)
Status-Line: SIP/2.0 200 OK
Status-Code: 200
[Resent Packet: False]
[Request Frame: 1324]
[Response Time (ms): 0]
Message Header
Via: SIP/2.0/UDP 192.169.1.147:39814;branch=z9hG4bK99109;received=192.169.1.147;rport=39814
From: <sip:102@192.169.1.150>;tag=z9hG4bK17086172
SIP from address: sip:102@192.169.1.150
SIP from tag: z9hG4bK17086172
To: <sip:102@192.169.1.150>;tag=55d70430
SIP to address: sip:102@192.169.1.150
SIP to tag: 55d70430
CSeq: 2 REGISTER
Sequence Number: 2
Method: REGISTER
Call-ID: 281574552997@192.169.1.147
Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE
User-Agent: miniSIPServer V16.0.7 (100 clients) build 20150324
Contact: <sip:102@192.169.1.147:39814;transport=udp>
Contact URI: sip:102@192.169.1.147:39814;transport=udp
Expires: 180
Content-Length: 0
相关文章推荐
- MGCP以及SIP协议原理
- 更改LYNC SIP地址
- 基于JAVA的SIP代理PEERS的自动放音实现
- Asterisk 1.8.0版本发布beta3测试
- SIP Trunk / SIP中继图解
- elastix SIP Trunk 配置细节
- SIP Trunk / SIP 中继服务
- Asterisk 呼叫流程
- Clearwater IMS All-in-one环境搭建指导书
- Clearwater IMS All-in-one环境搭建指导书
- Difference between dialog and session in SIP?
- What is "inside dialog" and "outside dialog"
- DTMF 在FreeSWITCH中的传输方式
- SIP 协议消息应答代码解释详录(转)
- SIP中的PRACK
- ubuntu11.10安装openser1.3.2
- Options用法
- sip uri 与sips uri 的区别
- SIP代理服务器(一)
- Asterks(软交换)里配置两部简单的SIP软电话