SAML2.0

以下內(nèi)容來(lái)自https://en.wikipedia.org/wiki/SAML_2.0

SAML 2.0是用來(lái)在不同security domain間exchange authentication、authorization data的SAML標(biāo)準(zhǔn),其使用包含assertion的security tokens在SAML authority(IdP)和SAML consumer(SP)之間交換數(shù)據(jù),能夠?qū)崿F(xiàn)web-based cross-domain SSO.

SAML 2.0是2005年3月完成的,核心內(nèi)容包括SAML core、SAML bind、 SAML Profile、SAML metadata。

1. SAML 2.0 Assertions

SAML 2.0定義了三種不同類(lèi)型的assertion statement,assertion statement是由SAML authority創(chuàng)建,所有SAML-defined statement均與一個(gè)subject關(guān)聯(lián)(由<Subject>表示的元素),這三種類(lèi)型的assertion是:

a. Authentication assertion:assertion subject 在某一時(shí)刻以某種方式被authenticated

b. Attribute Assertion:assertion subject具備某一個(gè)屬性

c. Authorization Decision Assertion:允許assertion subject訪(fǎng)問(wèn)特定資源的請(qǐng)求被授權(quán)或拒絕。

一個(gè)重要的SAML assertion成為“bear” assertion,被用來(lái)實(shí)現(xiàn)Web browse SSO. 前綴saml:表示SAML V2.0 assertion命名空間。

SAML Assertion示例見(jiàn)https://en.wikipedia.org/wiki/SAML_2.0,包括下列內(nèi)容:

a. <saml:Issuer>: IdP的唯一標(biāo)識(shí)

b. <ds:Signature>: 對(duì)<saml:Assertion>元素的完整性保護(hù)(數(shù)字簽名)

c. <saml:Subject>: 標(biāo)識(shí)Authenticated subject

d. <saml:Conditions>: 給出assertion是valid的條件

e. <saml:AuthnStatement>: authentication相關(guān)信息

f. <saml:AttributeStatement>: 描述authenticated實(shí)體的屬性值。

2. SAML 2.0協(xié)議

SAML core中定義了下列協(xié)議:Assertion Query and Request protocol、Authentication Request Protocol、Artifact Resolution Protocol、Name Identifier Managerment Protocol、Single Logout Protocol、Name Identifier Mapping Protocols。這些協(xié)議中最重要的是Authentication Request Protocol。

Authentication Request Protocol

在SAML 1.1中, Web browser SSO profile是IdP-initiatied,即<samlp:Response>元素是IdP傳遞至SP(通過(guò)瀏覽器);在SAML 2.0中,整個(gè)流從SP開(kāi)始,SP首先發(fā)生authentication request給IdP,authentication request protocol是SAML 2.0的全新特征,一個(gè)典型的authentication request如下圖所示:


Artifact Resolution Protocol

SAML消息以值或者引用的方式從一個(gè)實(shí)體傳遞至另一個(gè)實(shí)體,SAML消息的引用成為artifact。artifact的接收者通過(guò)向artifact的簽發(fā)者發(fā)送<samlp:ArtifactResolve>來(lái)解引用。一個(gè)典型的artifact resolve如下圖所示,其請(qǐng)求AAQAAMh48/1oXIM+sDo7Dh2qMp1HM4IF5DaRNmDj6RdUmllwn9jJHyEgIi8=對(duì)應(yīng)的assertion。

3. SAML 2.0 binding

SAML 2.0支持的binding包括:SAML SOAP Binding、Reverse SOAP Bing、HTTP Redirect Binding、HTTP POST Binding、HTTP Artifact Binding、SAML URI Binding。

針對(duì)Web Browser SSO,HTTP Redirect Binding 和 HTTP POST Binding最為常用。

HTTP Redirect Binding

SAML protocol message可以直接包含在HTTP GET request的URL query中。實(shí)際中,URL長(zhǎng)度是受限制的,因此HTTP Redirect Binding針對(duì)短消息適用(如<samlp:AuthnRequest>),SAML傳遞的消息都會(huì)按壓縮、base64編碼、URL encode的順序處理。

HTTP POST Binding

下列體現(xiàn)了IdP和SP之間使用HTTP POST Binding的情形。首先SP對(duì)用戶(hù)瀏覽器的request進(jìn)行應(yīng)答,返回的文檔包含一個(gè)XHTML form,其中SAMLRequest的值為<samlp:AuthnRequest>的base64編碼值。


IdP的SSO service響應(yīng)如下,其中SAMLResponse的值為<samlp:Response>的base64編碼值。


為了實(shí)現(xiàn)form的自動(dòng)提交,可以在XHTML頁(yè)的任意位置加入如下JS語(yǔ)句:windows.onload = function(){document.forms[0].submit();} 當(dāng)然,前提是該頁(yè)面的第一個(gè)form包含上述SAMPResponse(包含form元素)。

HTTP Artifact Binding

HTTP Artifact Binding使用Artifact Resolution Protocol和SAML SOAP Binding(over HTTP)來(lái)解析SAML消息。假設(shè)一個(gè)SP希望發(fā)送一個(gè)<samlp:AuthnRequest>消息給一個(gè)IdP,SP使用HTTP redirect傳輸一個(gè)artifact給IdP,即https://idp.example.org/SAML2/SSO/Artifact?SAMLart=artifact,IdP通過(guò)back channel給SP發(fā)送<samlp:ArtifactResolve> request,SP返回<samlp:ArtifactResponse>, 該response中包含<samlp:AuthnRequest>消息的值。


當(dāng)然,http artifact binding中,信息流可以按照不同的方向進(jìn)行,如IdP發(fā)布artifact(這更為common)

Artifact Format

在SAML 2.0中,artifact包含三個(gè)元素2字節(jié)的typecode、2字節(jié)的EndpointIndex和任意長(zhǎng)度的Remaining Artifact.這三個(gè)信息鏈接在一起,使用Base64進(jìn)行編碼,構(gòu)成一個(gè)完整的artifact。

typecode唯一標(biāo)識(shí)artifact的格式,SAML2.0僅僅預(yù)定義了一種artifact(type 0x0004)。

EndpointIndex是對(duì)一個(gè)特定artifact resolution endpoint的reference。

RemainingArtifact,是由artifact的type定義的,是artifact的具體內(nèi)容。

0x0004類(lèi)型的artifact的定義如下,其實(shí)一個(gè)44字節(jié)的artifact(編碼前),sourceId是一個(gè)任意的字節(jié)序列(實(shí)際中是issuer的entityID的SHA-1值);messageHandle是一個(gè)隨機(jī)序列,是對(duì)SAML 消息的引用。

4. ?SAML 2.0 Profile

SAML 2.0中,Web Browser SSO仍然是主要用途,但是SAML 2.0還包含了下列詳盡的profile:

1. SSO Profiles: Web Browser SSO profile, Enhanced ?Client or Proxy (ECP) profile, Identity Provider Discovery Profile, Single Logout Profile, Name Identifier Management Profile;

2. Artifact Resolution Profile

3. Assertion Query/Request profile

4. Name ?Identifier Mapping Profile

5. SAML Attribute Profiles: Basic Attribute profile, X.500/LDAP attribute Profile, UUID Attribute Profile, DCE PAC Attribute Profile, XACML Attribute Profile。

Web Browser SSO profile

SP有4種binding的方式,IdP有3種,因此共有12中,這里我們選取3種介紹下:

1. SP redirect Request, IdP Post Response.

2. SP Post, IdP Post

3. SP Redirect Artifact, IdP Redirect Artifact

Identity Provider Discovery Profile

SAML 2.0 Identity Provider Discovery Profile引入了下列概念:Common Domain、Common Domain Cookie、Common Domain Cookie Writing Service、Common Domain Cookie Reading Service。

Common Domain解釋如下:uk.example.com和de.example.com的common domain是example.com

Common Domain Cookie是瀏覽器cookie(scoped to the common domain),對(duì)每個(gè)瀏覽器用戶(hù),該cookie存儲(chǔ)著最近訪(fǎng)問(wèn)的IdP歷史。

在一個(gè)成功的authentication后,IdP請(qǐng)求Common Domain Cookie Writing Service,將IdP的唯一標(biāo)識(shí)加入到common domain cookie中;在SP而言,在其接到一個(gè)unauthenticated request后,其調(diào)用Common Domain Cookie Reading Service來(lái)發(fā)現(xiàn)該用戶(hù)最近訪(fǎng)問(wèn)的IdP。

Assertion Query/Request Profile

Assertion Query/Request Profile是一個(gè)general profile,對(duì)應(yīng)下列SAML2.0元素的query:<samlp:AssertionIDRequest>, <samlp:SubjectQuery>,<samlp:AuthnQuery>, <samlp:AttributeQuery>, <samlp:AuthzDecisionQuery>。


SAML 2.0 Metadata

毫不夸張地說(shuō),metadata使得SAML能夠正常運(yùn)轉(zhuǎn),metadata有下列用途:

1. SP準(zhǔn)備傳輸<samlp:AuthnRequest>給IdP時(shí),SP如何知道IdP是真實(shí)的,不是evil IdP(企圖釣魚(yú)),為此,SP在發(fā)布authentication request前獲取metadata中的可信IdP列表;

2. 在上一個(gè)場(chǎng)景中,SP如何知道向user發(fā)送authentication request? SP從metadata中查看IdP預(yù)先分配的endpoint location(用于authentication的,IdP除了authentication還有其他功能)

3. ?IdP從SP處接收到<samlp:AuthnRequest>后,IdP如何知道SP是真實(shí)的,不是evil SP(企圖獲取用戶(hù)信息)?IdP在發(fā)布authentication response前獲取metadata中的可信SP列表。

4. 在前一個(gè)場(chǎng)景中,IdP如何加密SAML assertion,使得僅僅可信的SP能夠解密assertion?IdP使用metadata中的加密證書(shū)來(lái)加密assertion。

5. 緊接著上一場(chǎng)景,IdP如何知道給用戶(hù)發(fā)送authentication response的地址?IdP從metadata中查看可信SP的預(yù)先定義的endpoint location。

6. ?SP如何知道authentication response是來(lái)自于一個(gè)可信的IdP? SP使用metadata中IdP的公鑰驗(yàn)證assertion的簽名。

7. SP如何知道從可信IdP收到的artifact的resolve地址?SP從metadata查看IdP的artifact resolution service的預(yù)先分配的endpoint location。

metadata保證IdP和SP之間的安全transaction。

IdP metadata示例如下:


其中,entityID是實(shí)體的唯一標(biāo)志,validUntil給出了metadata的失效日期,ds:Signature包含數(shù)字簽名,md:Organization描述該實(shí)體對(duì)應(yīng)的企業(yè)信息,contactperson為技術(shù)聯(lián)系人,可以有多個(gè)技術(shù)聯(lián)系人。

SSO metadata示例如下:


其中,<md:KeyDescriptor use="signing">為IdP的公鑰信息(簽名用途);<md:ArtifactResolutionService>中的Binding屬性說(shuō)明artifact resolution中SAML SOAP binding使用的相關(guān)信息,其中的location是相應(yīng)的地址信息;其中的index屬性對(duì)應(yīng)SAML type 0x0004 artifact的EndpointIndex。<md:NameIDFormat>元素說(shuō)明SSO服務(wù)支持的SAML name identifier formats。 <md:SignleSignOnService>元素中的Binding屬性是SAML 2.0Binding 規(guī)范中定義的標(biāo)準(zhǔn)URI,Location是相應(yīng)的地址信息。<saml:Attribute>描述了IdP愿意assert的屬性。

SP metadata

示例如下:


Assertion Consumer Service Metadata

示例如下,其中<md:KeyDescriptor use="signing">和<md:KeyDescriptor use="encryption">分別為用于簽名驗(yàn)證、加密的公鑰信息。<md:AssertionConsumerService>元素中:index屬性是<samlp:AuthnRequest>元素中AssertionConsumerServiceIndex屬性的值;Binding屬性是SAML 2.0標(biāo)準(zhǔn)中各個(gè)Binding方式對(duì)應(yīng)的標(biāo)準(zhǔn)URL;中的Location是相應(yīng)的URI。


metadata Aggregates:通過(guò)<md:EntitiesDescriptor>將多個(gè)<md:EntityDescriptor>組合起來(lái)。



未完成的部分:

bear token

http://www.rfcreader.com/#rfc6750

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容