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>

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