歡迎轉載,請注明作者:石韌
http://blog.csdn.net/stonerme/article/details/53409732
第二章 ZigBee3.0協定棧的Standard Security
2.1 Standard Security
Standard Security是所有的ZigBee應用規範都使用的安全模型,包括ZigBee3.0。它也是EmberZnet協定棧中唯一支援的安全模型。
Standard Security分别使用Network Key和Link Key在網絡層和APS層加密資料。APS層安全允許Trust Center來安全傳輸Network Key給加入節點或拒絕節點加入,并且它允許應用來增加可選的安全加密消息。網絡層安全用來保證所有的ZigBee網絡中發送消息的安全性。Standard Security不包括MAC層的通信(比如association,資料請求polling,MAC ACKs)。
2.2 Use of Keys in Standard Security
Standard Security定義了不同類型的Keys,使用不同的方式來保證資料的安全。所有的Keys都是用128位對稱密鑰(AES-128)來解密和加密資料包。
2.2.1 Network Key
Network Key用來保證網絡層的安全傳輸。所有Standard Security網絡中的裝置都會對Network Key進行備份。Trust Center可以周期性的更新Network Key。Trust Center通過兩種方式進行更新:廣播更新或單點傳播更新。在廣播更新的情況下,Trust Center首先廣播新的Network Key,此時使用舊的Network Key來對廣播消息進行加密。在單點傳播更新的情況下,Trust Center發送新的Network Key給每一個裝置,此時使用Trust Center Link Key來對其進行加密。當新的Network Key發送給各網絡節點之後,Trust Center再發送一條轉換指令告訴所有的裝置轉換為新的Network Key。新Network Key對應一個序列碼,這個序列碼在舊的Network Key 序列碼基礎上加1。
2.2.2 Trust Center Link Key
Trust Center Link Key用于兩個節點(其中有一個節點是Trust center)之間的端到端的安全通信。在以下情況下使用Trust Center Link Key:
• 當節點初次加入網絡時,需加密傳輸Network Key到加入節點。
• 當Network Key更新時,有些節點因未接收到新的Network Key,是以需要Rejoin。此時,Trust Center使用Trust Center Link Key加密 Network Key發送給該重新入網節點。
• 路由器向發送給Trust Center,或從Trust Center接收APS安全消息時,需要使用Trust Center Link Key。比如路由器發送節點加入或Rejoin的更新給Trust Center時,或由Trust Center發送到路由器以執行一些安全功能的指令時, 需要使用Trust Center Link Key。
• 啟用APS加密的應用程式單點傳播消息,其中發送或接收裝置是Trust Center。
由Trust Center決定如何管理Trust Center Link Key的選項。它可以為每個裝置選擇唯一的密鑰
(從裝置的IEEE位址導出的密鑰),或者對于所有的裝置采用相同的全局密鑰。
2.2.3 Installation Code Keys
ZigBee 3.0支援Installation Code Key,在之前隻用于Smart Energy Network(智能能源網絡),Smart Energy Network必須使用install code。現在所有ZigBee 3.0認證裝置都需要支援install code,但是由Trust center決定是否在網絡中使用。
Install code用來預配置Trust Center Link Key,其用于加入ZigBee網絡時對Network Key的傳輸進行加密。在進入網絡時,加入裝置和Trust Center都必須知道這個唯一的密鑰,是以install code用于在兩端導出密鑰。Install code可以是6,8,12或16位元組的任意值,再末尾加上這些位元組的16位CRC(最低有效位元組優先)。Install code用作Matyas-Meyer-Oseas(MMO)Hash散列函數的輸入,其散列長度等于128位。該AES-MMO哈希函數的128位(16位元組)結果就是用作該裝置的預配置Trust Center Link Key的值,并且Trust Center可以安裝密鑰表條目(該密鑰和加入裝置的EUI64),其然後允許在加入網絡期間成功地進行認證,加入裝置可以成功地接收和解密Network Key。作為此過程的一部分,Install code和加入裝置的EUI64必須在帶外傳送(目标ZigBee之外網絡,因為新節點尚未加入)到網絡的Trust Center,以允許建立正确的Link key表條目。
2.2.4 Application Link Keys
Application Link Key與Trust Center Link Key不同,它不是必須的,屬于可選的一種安全機制。Application Link Key用于網絡中兩個都不是Trust Center的裝置之間的APS級加密。裝置不會與Trust Center之間使用Application Link Key。Application Link Key可以通過以下兩種方式建立:
• 由應用程式手動配置,指定與目标裝置關聯的Application Link Key。
• 通過請求Trust Center生成Application Link Key并将其發送到兩個裝置。
Ember Stack支援兩種請求Application Link Key的方法。
第一個是ZigBee标準方法,其中一個裝置通過聯系Trust Center向另一個裝置請求Application Link Key。然後Trust Center立即響應并将随機生成的Application Link Key發送回請求裝置和另一個裝置。這種做法的缺點是:隻有一個裝置請求密鑰,而另一個裝置可能正在休眠,離線,或沒有足夠的容量來儲存新的Application Link Key。
第二種方法,如下圖所示,不是ZigBee标準方法,由Ember Stack在第一種方法上進行改進,是以其不相容第三方裝置。它還要求網絡中的所有Ember裝置都配置為使用此方法,包括Trust Center。這種方法更加可靠,因為它有助于確定夥伴裝置線上,是以能夠接收Application Link Key。在這種情況下,裝置A向Trust Center發送與裝置B的Link Key請求(這個請求是使用裝置A的Trust Center Link Key進行APS層的加密)消息。Trust Center接收到該請求之後,在一定的時間内(由Trust Center應用程式定義這個時間的長短),在此期間,裝置B向Trust Center發送與裝置A的Link Key請求(這個請求是使用裝置B的Trust Center Link Key進行APS層加密)消息。如果發生這種情況,Trust Center生成随機Application Link Key并将其發送給兩個裝置。要求兩個裝置都發送Link Key請求大大減少了裝置接收不到Application Link Key的情況。

• EmberZNet PRO支援用于存儲Application Link Key的可配置表。
2.3 Joining a Network
裝置加入ZigBee Standard Security網絡時,首先向父節點發送MAC關聯請求。 如果關聯成功,則裝置處于已加入但未認證狀态,此時它不具有Network Key。父節點給裝置發送MAC關聯成功的響應之後,再向Trust Center發送更新裝置消息,訓示新節點希望加入ZigBee網絡。 然後由Trust Center決定是否允許裝置加入。 如果不允許裝置加入,則向父節點發送移除裝置(Remove device)請求。 如果允許該裝置加入,Trust Center則向父節點發送Network Key,Trust Center的行為取決于裝置是否具有預配置的Trust Center Link Key。
2.3.1 Preconfigured Link Keys
Trust Center規定了如何處理新裝置和确定裝置是否應該具有Preconfigured Link Key。 如果新裝置沒有Preconfigured Link Key,它将無法加入網絡。
Trust Center可以選擇該密鑰是Default global Link Key(ZigBeeAlliance09)還是installation code。下圖說明了使用Preconfigured Link Key的加入網絡的過程。
為了允許裝置加入到網絡,Trust Center發送Network Key(使用Preconfigured Link Key加密)給父節點。ZigBee 3.0和所有ZigBee應用程式配置檔案需要Preconfigured Link Key才能加入。
2.3.2 Decision for Using Well-Known Key or Installation Code
Trust Center是使用Well-Known Key還是Installation Code,取決于易用性和安全性之間的平衡。使用Well-Known Key使裝置能夠更容易地加入網絡,而無需大量的使用者互動。然而,Well-Known Key加密Network Key提供了一個脆弱的時刻,直到該Well-Known Key被替換為新的密鑰。使用Installation Code為Network Key到裝置的初始交換提供了安全性,代價是使用者和Trust Center之間增加了互動。使用者必須以某種方式将密鑰從裝置傳輸到Trust Center。這是通過ZigBee網絡之外的機制來完成,例如從列出加入裝置上的代碼的标簽将代碼輸入到Trust Center GUI中;在加入裝置上運作的主應用程式。在網絡上運作的主要應用程式将幫助決定是否易于使用與更好的安全性誰更重要。
2.3.3 Requesting a New Link Key after Joining
ZigBee 3.0裝置成功加入網絡後,裝置需要請求更新的Trust Center Link Key以替換它們現有的Preconfigured Link Key。 即使使用Installation code的裝置,也将替換成新的Trust Center Link Key。 下圖說明了ZigBee 3.0裝置如何更新Trust Center Link Key。
隻有在Trust Center和加入裝置都支援ZigBee 3.0的情況下,才能更新Trust Center Link Key。 如果其中一個不是ZigBee 3.0裝置,則保留原始的Preconfigured Link Key。
2.4 Network Key Updates
加密網絡層的所有傳輸。在網絡中的任何裝置的Frame Counter到達0x80000000最大值之前,Trust Center應該更新Network Key。由于Trust Center不可能在任何給定時間知道網絡中的每個裝置的Frame Counter的值,是以依賴于特定Frame Counter門檻值的方法來更新Network Key是不實際的。是以,推薦采用Trust Center定期更新Network Key,以減小Network Key被洩露的風險。這有助于確定已離開ZigBee安全網絡的裝置無法Rejoin。
• 更新Network Key可以使用廣播或單點傳播兩種方式,由Trust Center決定使用哪種機制。
2.4.1 Broadcast Network Key Update
當采用廣播的方式對密鑰更新時,使用目前Network key加密消息。 收到廣播的裝置不立即使用該Network Key,而是先存儲它。 之後Trust Center廣播密鑰切換指令,以通知所有節點開始使用新密鑰。Trust Center在發送切換指令之前應該允許足夠的時間(大約9秒)來保證新密鑰的廣播到整個網絡。 此外Trust Center必須記住,睡眠終端裝置可能會錯過初始廣播,除非他們頻繁輪詢父節點。廣播機制非常簡單,因為它不需要知道網絡上所有裝置的身份。 它也隻涉及發送兩個消息,更新的密鑰消息和切換消息。
2.4.2 Unicast Network Key Update
當采用單點傳播的方式對密鑰更新時,Trust Center将向網絡上的每個裝置發送單獨的密鑰更新。 Trust Center必須維護網絡上所有授權裝置的清單,以便執行此操作。更新消息使用每個裝置的特定Trust Center Link Key單點傳播具有APS加密的消息到每個裝置。 然後由Trust Center廣播切換指令,告知所有節點開始使用新密鑰。
2.4.3 Missing a Network Key Update
任何裝置可能會錯過密鑰更新,比如它處于睡眠,斷電或者長時間掉網的狀态。 如果發生這種情況,裝置可以嘗試執行Trust Center Rejoin操作。 然後由Trust Center決定是否允許節點傳回到網絡上。
EmberZNet PRO協定棧可以檢測接收的加密資料包是否使用較新的Network Key。如果檢測到,它将自動執行Trust Center Rejoin到目前網絡以嘗試擷取最新的Network Key。
2.5 Network Rejoin
Rejoin是指節點重新連接配接到其先前所在的網絡的一種方式。在以下幾種不同的情況下需要進行Rejoin:
• 移動或睡眠的裝置,可能無法再與其父節點通信。
• 錯過Network Key更新,并需要更新Network Key副本的裝置。
• 錯過PAN ID更新并需要發現網絡的新PAN ID的裝置。
當裝置嘗試Rejoin網絡時,它可能有,也可能沒有目前網絡的Network Key。如果沒有正确的Network Key,裝置的Rejoin請求會被附近的路由器忽略。
是以,當Rejoin時,裝置有兩個選擇:Secure Rejoin或Trust Center Rejoin。注意,這些Rejoin的情況都不需要在目标網絡中的任何裝置上設定MAC允許關聯(也稱為“允許加入”)标志。路由器/協調器裝置将始終接受NWK層Rejoin指令,該指令是Trust Center Rejoin或使用Network Key的Secure Rejoin。對于Trust Center Rejoin的情況,Trust Center的責任是在收到通知後授權或拒絕裝置的重新連接配接。
2.5.1 Secured Rejoining
Secured Rejoin的情況是更簡單一些,試圖重新加入網絡的裝置應當首先嘗試這個方法。 如果它具有目前Network Key,則裝置将能夠在很快地重新加入網絡。 當睡眠或移動終端裝置與其父節點失去聯系時,才需要進行Secured Rejoin。
如下圖所示,裝置發送用其Network Key副本加密的Rejoin請求給父節點。 如果路由器在附近并且使用相同的Network Key,則父節點将Rejoin響應發送回該裝置。 裝置處于成功加入網絡中并處于驗證狀态。 父節點通知Trust Center該裝置Rejoin,但Trust Center不得采取進一步的操作。
如果裝置嘗試Secured Rejoin失敗,并且裝置使用Standard Security性,則應用程式可以嘗試Unsecured Rejoin。
2.5.2 Trust Center Rejoin
當相鄰裝置已經切換到新的Network Key并且不再使用與Rejoin裝置相同的Network Key時,就需要進行Trust Center Rejoin。要成功地在Trust Center Rejoin,裝置必須有一個Trust Center Link Key。裝置發送未加密的Rejoin請求給父節點。附近的路由器(父節點)接受未加密的Rejoin請求并且發送響應到該裝置,允許它轉換到加入和未認證的狀态。
如下圖所示,Rejoin裝置的父節點向Trust Center發送更新裝置消息,通知它有不安全的Rejoin。Trust Center有兩個選擇:拒絕或接受Rejoin。如果它接受Rejoin,則它必須向裝置發送更新的Network Key。但是,它使用該裝置的Trust Center Link Key保護此消息。該消息(在網絡層和APS層均被加密)被發送到Rejoin裝置的父節點。然後,父節點中繼此消息(隻進行APS層加密而不進行網絡層加密)到Rejoin裝置。一旦它具有Network Key,它将處于加入和認證狀态,即可以在網絡上再次通信。
備注:
Trust Center決定是否允許Trust Center Rejoin,必須考慮加入裝置是否使用Global Trust Center Link Key。如果Trust Center隻有裝置的Global Trust Center Link Key(例如ZigBeeAlliance09密鑰),則它應該忽略Rejoin請求。衆所周知,Global Trust Center Link Key是不安全的,是以不應該用于傳送重要的資料(Network Key),在Rejoin期間,Global Trust Center Link Key應該隻用于初始加入,甚至應該隻允許短暫的時間。
Pre-ZigBee 3.0網絡在加入後不會立即更新Link Key,是以強烈建議拒絕任何使用Global Trust Center Link Key來進行Rejoin操作。智能能源網絡不受此特定問題的限制,因為他們在加入後立即更新Link Key。
是以,智能能源網絡可接受Trust Center Rejoin。
建議拒絕Trust Center Rejoin而不是明确拒絕Trust Center Rejoin是必要的保持與ZigBee 3.0之前的裝置的相容性。 Pre-ZigBee 3.0裝置可以嘗試Trust Center Rejoin而不考慮是否先前已經獲得了更新的Link Key。如果進行明确拒絕,則裝置可能完全脫離網絡,靜默拒絕将允許裝置稍後嘗試Secured Rejoin并成功。
Trust Center的行為将最終決定Trust Center Rejoin的安全性。這可以通過控制在SOC上的emberTrustCenterJoinHandler()回調,在NCP上通過配置EZSP_TRUST_CENTER_POLICY的ezspSetPolicy()API。要忽略SOC裝置上的Trust Center Rejoin,emberTrustCenterJoinHandler()必須傳回EMBER_NO_ACTION。要忽略NCP上的Trust Center Rejoin,主機必須将EZSP_TRUST_CENTER_POLICY設定為EZSP_IGNORE_TRUST_CENTER_REJOINS。
如果終端裝置隻有一個Global Trust Center Link Key,建議将其限制為隻執行Secured Rejoin。然而,如上所述, Trust Center的行為最終保證網絡的安全。
歡迎轉載,請注明作者:石韌
http://blog.csdn.net/stonerme/article/details/53409732