SIP Call Flow - Registration

Session Initiation Protocol (SIP) registration 注册的过程是将 IP 地址和当前用户的公共用户ID(Public user ID:SIP URI  (uniform resource identifier)) 绑定的过程。

SIP (Session Initiation Protocol) 绑定的过程

  • UE 发送 Register 到 P-CSCF
  • I-CSCF 选择对应的S-CSCF
  • S-CSCF到HSS (Home Subscriber Server) 下载用户鉴权数据
  • UE和P-CSCF开启安全机制
  • UE和网络(S-CSCF)相互认证
  • UE 和P-CSCF间建立 IP Security(IPSec)连接
  • UE和P-CSCF间开启SIP 压缩
  • UE学习到S-CSCF的路由
  • S-CSCF学习到UE的路由
  • S-CSCF从HSS下载当前用户的profile
  • UE确定进入注册状态
  • P-CSCF确定当前用户进入注册状态

SIP Registe Flow

pic_01


手机发现P-CSCF
当是手机建立PDP Context时会将P-CSCF的IP地址告诉手机。

第一次 Register交互
UE Abc 发送Register 通过P-CSCF转发到 S-CSCF,图中的 Register (1)-(3)

pic_02


消息解析

[Method]/[Request-URI]
REGISTER sip:home1.fr SIP/2.0
(提供服务的domian name), SIP 2.0
[Via]
(1) SIP/2.0/UDP [5555::1:2:3:4];branch=0uetb
(2) SIP/2.0/UDP sip:pcscf1.visited1.fi;branch=0pctb
(3) SIP/2.0/UDP sip:icscf1.home1.fr;branch=0ictb 
它是在传输过(Transport)程中使用的一个header,用来指示Response将会被发到哪里。Via的构成中包含了协议名和版本及传输的协议(SIP/2.0/UDP),Via中必须包含一个branch参数,它用来标识由这个请求所创建的事务
(Transaction) 。在消息转发的过程中,会将路由信息添加到Register的Via中。
[Route]
sip:[5555::a:f:f:e];lr 
强制请求信息经过指定的代理进行发送。
[Max-Forwards]
70
在SIP消息中用来限制代理或网关对消息转发的次数,它的范围是(0-255)。
所以在转发的过程中它的值分别是70,69,68.
[From]
<sip:[email protected]>;tag=pohja
对这次注册负责的人的地址。tag是与Call-ID一起使用来标识Dialog的。 因为是发起一个请求,所以只有From有tag参数, To并没带tag 参数。
[To]
包含将要被注册的地址
[Contact]
<sip:[5555::1:2:3:4]>;expires=600000
保存着将要绑定的地址和超时时间,单位是秒
[Call-ID]
apb03a0s09dkjdfglkj49111 
Call-ID用来标识一个Dialog,UAC到特定的Register中,注册消息中的Call-ID是一样的。否则在注册的Server端,它无法检测是否有乱序的Register消息。
[CSeq]
25 REGISTER
用来保证Register 请求的消息顺序,手机必须对有相同Call-ID的Register 消息中的CSeq进行递增。

这里关于Dialog 和 Transaction(Via:branch和Call-ID),REGISTER Request从UE发出到达 S-CSCF经历了两次转发,但他们属于同一个Dialog,
所以使用的Call-ID是一样的,但从传输的角度来看,从UE到P-CSCF,P-CSCF到I-CSCF,以及I-CSCF到S-CSCF,他们经历的传输过程是不一样的
所以使用了一个 Via:branch 来区分不同的传输的过程。

pic_03


当完成第一次 Register过程后,S-CSCF要求手机进行认证,发起第二次Register过程。
在第二个Register消息中 Call-ID会更新为新的ID,表示它与第一个Register已经不是同一个Dialog了。

S-CSCF收到的Register 消息
REGISTER sip:home1.fr SIP/2.0
Via: SIP/2.0/UDP sip:icscf1.home1.fr;branch=3ictb
Via: SIP/2.0/UDP sip:pcscf1.visited1.fi;branch=2pctb
Via: SIP/2.0/UDP [5555::a:b:c:d];branch=1uetb
Route: sip:scscf1.home1.fr;lr
Max-Forwards: 68
From: <sip:[email protected]>;tag=ulkomaa
Contact: <sip:[5555::1:2:3:4]>;expires=600000
Call-ID: apb03a0s09dkjdfglkj49222 
CSeq: 47 REGISTER
Content-Length: 0

如果S-CSCF鉴权成功,它会将User ID [email protected] 与 Contact <5555::a:b:c:d> 绑定在一起,绑定期限为600000秒。

S-CSCF 返回 200 OK 消息
SIP/2.0 200 OK
Via: SIP/2.0/UDP icscf1.home1.fr;branch=3ictb
Via: SIP/2.0/UDP pcscf1.visited1.fi;branch=2pctb
Via: SIP/2.0/UDP [5555::1:2:3:4]:1357;branch=1uetb
From: <sip:[email protected]>;tag=ulkomaa
To: <sip:[email protected]>;tag=kotimaa
Contact: <sip:[5555::a:b:c:d]>;expires=600000
Call-ID: apb03a0s09dkjdfglkj49222
CSeq: 47 REGISTER
Content-Length: 0


SIP Register 的鉴权过程 (Authentication

在UE 注册到网络的过程中鉴权分为两个部分
-    UE和网络间的鉴权
-    UE和P-CSCF间的鉴权 (IPSec)

IMS 鉴权主要是基于  shared secret 和一个 sequence number (SQN),分别保存在HSS(Home Subscriber Server) 和 手机卡中。
HSS并不直接和手机通信,所以S-CSCF会从HSS下载手机相关的鉴权参数 Authentication Vector (AV) :
  • a random challenge (RAND);
  • the expected result (XRES);
  • the network authentication token (AUTN);
  • the Integrity Key (IK); and
  • the Ciphering Key (CK).

这些参数使S-CSCF在不知道 shared secret 和 SQN的情况下进行鉴权。


pic_04



为了触发鉴权的过程,S-CSCF会对UE的第一个Register返回 401 Unauthorized(包含 RAND, the AUTN, the IK and the CK),要求UE进行鉴权。
在P-CSCF中,它会去掉401中的 IK和CK,并将401发给手机。IK用来在接下来的过程中在UE和P-CSCF间建立完整性保护的。

S-CSCF  --->  P-CSCF
SIP/2.0 401 Unauthorized
WWW-Authenticate: Digest realm="home1.fr",
        nonce=A34Cm+Fva37UYWpGNB34JP, algorithm=AKAv1-MD5,
        ik="0123456789abcdeedcba9876543210",
        ck="9876543210abcdeedcba0123456789"

P-CSCF删除了 ik 和 ck

P-CSCF  --->  UE
SIP/2.0 401 Unauthorized
WWW-Authenticate: Digest realm="home1.fr",
        nonce=A34Cm+Fva37UYWpGNB34JP, algorithm=AKAv1-MD5

UE对于鉴权的响应

  • verifies the AUTN : 根据 share secret 和 SQN 手机验证网络是否是合法的。
  • calculates the result (RES): 根据 shared secret 和收到的 RAND 计算 RES
  • calculates the IK:计算后在 P-CSCF 和 UE 见使用

计算完成后UE发送第二个Register到S-CSCF,S-CSCF会比较 手机计算的RES 和从HSS得到的XRES,来判断手机是否合法。

UE  --->  P-CSCF
REGISTER sip:home1.fr SIP/2.0
Authorization: Digest username="[email protected]",
        realm="home1.fr",
        nonce=A34Cm+Fva37UYWpGNB34JP,
        algorithm=AKAv1-MD5,
        uri="sip:home1.fr",
        response="6629fae49393a05397450978507c4ef1"

P-CSCF  --->  S-CSCF
REGISTER sip:home1.fr SIP/2.0
Authorization: Digest username="[email protected]",
        realm="home1.fr",
        nonce=A34Cm+Fva37UYWpGNB34JP,
        algorithm=AKAv1-MD5,
        uri="sip:home1.fr",
        response="6629fae49393a05397450978507c4ef1",
        integrity-protected="yes"

到这里鉴权成功。


SIP (Session Initiation Protocol) SUBSCRIBE

Subscribe的作用:
  • 手机向网络侧订阅资源
  • 请求资源的版本信息
  • 当资源信息发送变化时,网络通知手机

信令过程

pic_05


pic_06


[Method]/[Request-URI]
SUBSCRIBE sip:[email protected] SIP/2.0   
这里Request-URI是订阅目标的ID。
[Via]
(1) SIP/2.0/UDP [5555::1:2:3:4];branch=04uetb          
(2) Via: SIP/2.0/UDP pcscf1.visited1.fi   
它是在传输过(Transport)程中使用的一个header,用来指示Response将会被发到哪里。Via的构成中包含了协议名和版本及传输的协议(SIP/2.0/UDP),Via中包含一个branch参数,它用来标识由这个请求所创建的事务
(Transaction) 。在消息转发的过程中,会将路由信息添加到Register的Via中。
[Route]
<sip:[5555::a:b:c:d]:7531;lr>
强制请求信息经过指定的代理进行发送。
[From]
<sip:[email protected]>;tag=pohja
对这次订阅负责的人的地址。tag是与Call-ID一起使用来标识Dialog的。 因为是发起一个请求,所以只有From有tag参数, To并没带tag 参数。
[To]
订阅的目标地址
[P-Preferred-Identity]
rfc3455
"abc" <sip:[email protected]>
P-Preferred-Identity头域被用在用户端末和受信任的代理之间,用来传输用户信息。在信任域之间发送消息,代理服务器收到了P-Preferred-Identity,该值作为服务器可参考值,可在被插入后续的P-Asserted-Identity包头域中,P-Preferred-Identity值。
[P-Asserted-Identity]
rfc3455
<sip:pcscf1.visited1.fi>
P-Asserted- Identity,即确认的公有身份,当这个消息被路由到被叫的时候,被叫可以通过读取P-Asserted-Identity中的信息,来显示主叫的公有身份
[Event] (rfc3265/3680)
reg
Event package name=reg,表示希望Notifier返回关于 Registration的信息
[Contact]
<sip:[5555::1:2:3:4]:1357>
保存着绑定的地址
[Expires]
600000
标识了订阅的时间。
[Accept]
application/reginfo+xml 
标识了消息内容的格式。


S-CSCF --> UE 返回  NOTIFY
NOTIFY sip:[5555::1:2:3:4]:1357;comp=sigcomp SIP/2.0
Via: SIP/2.0/UDP scscf1.home1.fr;branch=nosctb
Via: SIP/2.0/UDP pcscf1.visited1.fi:7531;branch=nopctb
From: "abc" <sip:[email protected]>;tag=peruna
To: "abc" <sip:[email protected]>;tag=sipuli
Subscription-State: active;expires=599999
Event: reg
Content-Type: application/reginfo+xml
Contact: <sip:scscf1.home1.fr>
Content-Length: (...)

<?xml version="1.0"?>
<reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="1" state="partial">
<registration aor="sip:[email protected]" id="a1" state="active">
<contact id="15" state="active" event="registered">
sip:[5555::1:2:3:4]
</contact>
<contact id="20" state="active" event="registered">
sip:[5555::171:171:172:173]
</contact>
</registration>
</reginfo>


S-CSCF --> UE 返回  NOTIFY
NOTIFY sip:[5555::1:2:3:4]:1357;comp=sigcomp SIP/2.0
Via: SIP/2.0/UDP scscf1.home1.fr;branch=nosctb
Via: SIP/2.0/UDP pcscf1.visited1.fi:7531;branch=nopctb
From: "abc" <sip:[email protected]>;tag=peruna
To: "abc" <sip:[email protected]>;tag=sipuli
Subscription-State: active;expires=599999
Event: reg
Content-Type: application/reginfo+xml
Contact: <sip:scscf1.home1.fr>
Content-Length: (...)

<?xml version="1.0"?>
<reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="1" state="partial">
<registration aor="sip:[email protected]" id="a1" state="active">
<contact id="15" state="active" event="registered">
sip:[5555::1:2:3:4]
</contact>
<contact id="20" state="active" event="registered">
sip:[5555::171:171:172:173]
</contact>
</registration>
</reginfo>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章