KerberosToken

BinarySecurityToken---KerberosToken

在WS-Security規範出現之前,針對Web Service或者其他的分佈式技術並不是沒有安全協議來保證它們的安全。只是這些協議一旦跨越了企業邊界往往會受到防火牆的影響,而不再起作用。在WS-Security中,並沒有拋棄這些現有的協議,而是將這些Binary的Security Token通過Encoding的方式集成到XML元素中,從而在Web Service中仍然能使用這些經典的安全協議,並利用SOAP消息穿越防火牆的特性,使它們適用於新的環境。這類Security Token在WS-Security中被稱爲BinarySecurityToken,目前僅支持Kerberos和X509v3 Certificate兩種,但是利用XML的高度擴展性,用戶可以定義自己的BinarySecurityToken。

下面是BinarySecurityToken的標準格式:
<wsse:BinarySecurityToken wsu:Id=...
        EncodingType=...
        ValueType=...>
      ...Binary Data ...
<wsse:BinarySecurityToken/>
其中EncodingType屬性指定將Binary數據Encoding到XML中的方法(常用Base64); ValueType屬性指定BinarySecurityToken的類型(比如KerberosV5); 元素內容則是經過Encoding的BinaryToken的內容。  

   
Note  Binary數據要嵌入XML時需要經過Encoding,因爲其中的某些內容可能不符合XML的語法。

    
KerberosToken

Kerberos協議非常適合用於保證企業內部的安全, 也是獲得Windows操作系統良好支持的一套安全協議, 理所當然它也成了WS-Security所支持的Security Token之一.
Kerberos協議的核心功能就是安全的完成了Client與Server之間的共享密鑰的發佈, 使得原本沒有聯繫的Client和Server能夠利用該密鑰保證消息的一致性和機密性, 並且實現相互間的身份鑑別. 

   
Note  有關Kerberos協議的原理請參考Kerberos簡介一文. 由於採用的是對稱密鑰技術, 使得Kerberos協議不具有抗否認性的功能.


WSE中目前也提供了對KerberosToken支持,下圖爲使用KerberosToken來保證消息安全的SOAP Envelop結構。
 
      

Kerberos協議是使用對稱密鑰技術的代表,消息的簽名和加密都依靠對稱密鑰, 所以其中用到的簽名算法必須是MAC(Message Authentication Code), 加密算法也必須是對稱加密算法(如AES).

以下是對應於上圖具體的SOAP Envelop:
<?xml version="1.0" encoding="utf-8"?>
<
SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope"
    xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
    xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
    <SOAP-ENV:Header>
        <wsse:Security
             xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/secext">
            <wsse:BinarySecurityToken
                   EncodingType="…#Base64Binary"
                   ValueType="…#Kerberosv5_AP_REQ"
                   wsu:Id="kerberosToken">
                     boIBxDCCAcCgAwIBBaEDAgEOogcD...
               </wsse:BinarySecurityToken>
            <ds:Signature>
                <ds:SignedInfo>
                    <ds:CanonicalizationMethod
                        Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                    <ds:SignatureMethod
                        Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1"/>
                    <ds:Reference URI="#DiscountRequest">
                        <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                        <ds:DigestValue>Fd3WSLg5yLsGMP4kPdU...</ds:DigestValue>
                    </ds:Reference>
                </ds:SignedInfo>
                <ds:SignatureValue>Fsd2h8SsxJwkDiXlJidm5P2k...</ds:SignatureValue>
                <ds:KeyInfo>
                          <wsse:SecurityTokenReference>
                                  <wsse:Reference URI="# kerberosToken "
                                     ValueType="…#Kerberosv5_AP_REQ">
                                  </wsse:Reference>
                          </wsse:SecurityTokenReference>
                   </ds:KeyInfo>
            </ds:Signature>
            <xenc:ReferenceList>
                    <xenc:DataReference URI="#DiscountResponse"/>
            </xenc:ReferenceList>
        </wsse:Security>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body wsu:Id="DiscountedBookingForPartnersResponse">
        <s:GetSpecialDiscountedBookingForPartnersResponse
            xmlns:s="http://www.MyHotel.com/partnerservice">
            <xenc:EncryptedData
                wsu:Id="DiscountResponse"
                type="http://www.w3.org/2001/04/xmlenc#Element">
                <xenc:EncryptionMethod
                    Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
                <ds:KeyInfo>
                          <wsse:SecurityTokenReference>
                                  <wsse:Reference URI="#kerberosToken"
                                    ValueType="…#Kerberosv5_AP_REQ">
                                  </wsse:Reference>
                          </wsse:SecurityTokenReference>
                   </ds:KeyInfo>
                <CipherData>
                <CipherValue>XD6sFa0DrWsHdehrHdhcW0x...</CipherValue>
                </CipherData>
            </xenc:EncryptedData>
        </s:GetSpecialDiscountedBookingForPartnersResponse>
    </SOAP-ENV:Body>
</
SOAP-ENV:Envelope>

以上的示例通過KerberosToken實現了用戶的身份鑑別,並利用Token中的Session Key簽名加密消息,從而保證消息的一致性和機密性。那麼如果KerberosToken通過首次的消息交換傳遞給了Service之後,是否每次仍有必要重複傳遞一遍呢?當我們利用Kerberos協議完成了密鑰的分配之後,能否通過一個約定的名稱的定位到之前的Session Key,從而繼續利用它來保證消息的安全性而不必重複的發送該KerberosToken。WS-Security協議中爲此定義了另一種在簽名和加密消息時引用KerberosToken的方法---KeyIdentity.

    
Note讀者可以將這裏的思路和WS-SecurityConversation協議做一番比較。
 

在完成了首次的KerberosToken的傳遞之後,在隨後的消息交換中可以通過如下的方式引用KerberosToken。

<?xml version="1.0" encoding="utf-8"?>
<
SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope"
   
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
   
xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
    <
SOAP-ENV:Header>
        <
wsse:Security  xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/secext">            
            <
ds:Signature>
                <
ds:SignedInfo>
                    <
ds:CanonicalizationMethod
                        Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                    <
ds:SignatureMethod
                        Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1"/>
                    <
ds:Reference URI="#DiscountRequest">
                        <
ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                        <
ds:DigestValue>Fd3WSLg5yLsGMP4kPdU...</ds:DigestValue>
                    </
ds:Reference>
                </
ds:SignedInfo>                           
                <
ds:SignatureValue>
                    Fsd2h8SsxJwkDiXlJidm5P2k...
                </
ds:SignatureValue>
              
  <ds:KeyInfo>
                          <
wsse:SecurityTokenReference
                             
wsse11:TokenType="…#Kerberosv5_AP_REQ">
                                 <
wsse:KeyIdentifier
                                  
ValueType="…#Kerberosv5APREQSHA1">
                                   GbsDt+WmD9XlnUUWbY/nhBveW8I=
                                 </
wsse:KeyIdentifier>
                          </
wsse:SecurityTokenReference>
                   </
ds:KeyInfo>
            </ds:Signature>
            <
xenc:ReferenceList>
                    <
xenc:DataReference URI="#DiscountResponse"/>
            </
xenc:ReferenceList>
        </
wsse:Security>
    </
SOAP-ENV:Header>
    <
SOAP-ENV:Body wsu:Id="DiscountedBookingForPartnersResponse">
        <
s:GetSpecialDiscountedBookingForPartnersResponse
            xmlns:s="http://www.MyHotel.com/partnerservice">
            <
xenc:EncryptedData
                wsu:Id="DiscountResponse"
               
type="http://www.w3.org/2001/04/xmlenc#Element">
                <
xenc:EncryptionMethod
                    Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
              
  <ds:KeyInfo>
                          <
wsse:SecurityTokenReference    
                            
wsse11:TokenType="…#Kerberosv5_AP_REQ">
                                 <
wsse:KeyIdentifier ValueType="…#Kerberosv5APREQSHA1">
                                     GbsDt+WmD9XlnUUWbY/nhBveW8I=
                                 </
wsse:KeyIdentifier> 
                          </
wsse:SecurityTokenReference>
                   </
ds:KeyInfo>
                <CipherData>
                     <
CipherValue>XD6sFa0DrWsHdehrHdhcW0x...</CipherValue>
                </
CipherData>
            </
xenc:EncryptedData>
        </
s:GetSpecialDiscountedBookingForPartnersResponse>
    </
SOAP-ENV:Body>
</
SOAP-ENV:Envelope>

  
Note在KeyIdentifier中並沒有使用一個簡單的名稱標識來引用之前的KerberosToken,而是通過之前KerberosToken的摘要( SHA(Encoding(KerberosToken)) )來標識的,此舉是爲了降低惡意攻擊者冒充KerberosToken擁有者的危險。


應用場景: 
由於使用KerberosToken具有SSO(Single Sign On)的功能,並且還可以獲得用戶和Service之間的相互信任,所以在企業內部廣爲採用。如銀行內部:
      


參考資料:
OASIS Kerberos Token Profile 1.1
Protect Your Web Services Through The Extensible Policy Framework In WSE 3.0


Kerberos簡介
 

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