以下内容来自https://en.wikipedia.org/wiki/SAML_2.0
SAML 2.0是用来在不同security domain间exchange authentication、authorization data的SAML标准,其使用包含assertion的security tokens在SAML authority(IdP)和SAML consumer(SP)之间交换数据,能够实现web-based cross-domain SSO.
SAML 2.0是2005年3月完成的,核心内容包括SAML core、SAML bind、 SAML Profile、SAML metadata。
1. SAML 2.0 Assertions
SAML 2.0定义了三种不同类型的assertion statement,assertion statement是由SAML authority创建,所有SAML-defined statement均与一个subject关联(由<Subject>表示的元素),这三种类型的assertion是:
a. Authentication assertion:assertion subject 在某一时刻以某种方式被authenticated
b. Attribute Assertion:assertion subject具备某一个属性
c. Authorization Decision Assertion:允许assertion subject访问特定资源的请求被授权或拒绝。
一个重要的SAML assertion成为“bear” assertion,被用来实现Web browse SSO. 前缀saml:表示SAML V2.0 assertion命名空间。
SAML Assertion示例见https://en.wikipedia.org/wiki/SAML_2.0,包括下列内容:
a. <saml:Issuer>: IdP的唯一标识
b. <ds:Signature>: 对<saml:Assertion>元素的完整性保护(数字签名)
c. <saml:Subject>: 标识Authenticated subject
d. <saml:Conditions>: 给出assertion是valid的条件
e. <saml:AuthnStatement>: authentication相关信息
f. <saml:AttributeStatement>: 描述authenticated实体的属性值。
2. SAML 2.0协议
SAML core中定义了下列协议:Assertion Query and Request protocol、Authentication Request Protocol、Artifact Resolution Protocol、Name Identifier Managerment Protocol、Single Logout Protocol、Name Identifier Mapping Protocols。这些协议中最重要的是Authentication Request Protocol。
Authentication Request Protocol
在SAML 1.1中, Web browser SSO profile是IdP-initiatied,即<samlp:Response>元素是IdP传递至SP(通过浏览器);在SAML 2.0中,整个流从SP开始,SP首先发生authentication request给IdP,authentication request protocol是SAML 2.0的全新特征,一个典型的authentication request如下图所示:
Artifact Resolution Protocol
SAML消息以值或者引用的方式从一个实体传递至另一个实体,SAML消息的引用成为artifact。artifact的接收者通过向artifact的签发者发送<samlp:ArtifactResolve>来解引用。一个典型的artifact resolve如下图所示,其请求AAQAAMh48/1oXIM+sDo7Dh2qMp1HM4IF5DaRNmDj6RdUmllwn9jJHyEgIi8=对应的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。
针对Web Browser SSO,HTTP Redirect Binding 和 HTTP POST Binding最为常用。
HTTP Redirect Binding
SAML protocol message可以直接包含在HTTP GET request的URL query中。实际中,URL长度是受限制的,因此HTTP Redirect Binding针对短消息适用(如<samlp:AuthnRequest>),SAML传递的消息都会按压缩、base64编码、URL encode的顺序处理。
HTTP POST Binding
下列体现了IdP和SP之间使用HTTP POST Binding的情形。首先SP对用户浏览器的request进行应答,返回的文档包含一个XHTML form,其中SAMLRequest的值为<samlp:AuthnRequest>的base64编码值。
IdP的SSO service响应如下,其中SAMLResponse的值为<samlp:Response>的base64编码值。
为了实现form的自动提交,可以在XHTML页的任意位置加入如下JS语句:windows.onload = function(){document.forms[0].submit();} 当然,前提是该页面的第一个form包含上述SAMPResponse(包含form元素)。
HTTP Artifact Binding
HTTP Artifact Binding使用Artifact Resolution Protocol和SAML SOAP Binding(over HTTP)来解析SAML消息。假设一个SP希望发送一个<samlp:AuthnRequest>消息给一个IdP,SP使用HTTP redirect传输一个artifact给IdP,即https://idp.example.org/SAML2/SSO/Artifact?SAMLart=artifact,IdP通过back channel给SP发送<samlp:ArtifactResolve> request,SP返回<samlp:ArtifactResponse>, 该response中包含<samlp:AuthnRequest>消息的值。
当然,http artifact binding中,信息流可以按照不同的方向进行,如IdP发布artifact(这更为common)
Artifact Format
在SAML 2.0中,artifact包含三个元素2字节的typecode、2字节的EndpointIndex和任意长度的Remaining Artifact.这三个信息链接在一起,使用Base64进行编码,构成一个完整的artifact。
typecode唯一标识artifact的格式,SAML2.0仅仅预定义了一种artifact(type 0x0004)。
EndpointIndex是对一个特定artifact resolution endpoint的reference。
RemainingArtifact,是由artifact的type定义的,是artifact的具体内容。
0x0004类型的artifact的定义如下,其实一个44字节的artifact(编码前),sourceId是一个任意的字节序列(实际中是issuer的entityID的SHA-1值);messageHandle是一个随机序列,是对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),对每个浏览器用户,该cookie存储着最近访问的IdP历史。
在一个成功的authentication后,IdP请求Common Domain Cookie Writing Service,将IdP的唯一标识加入到common domain cookie中;在SP而言,在其接到一个unauthenticated request后,其调用Common Domain Cookie Reading Service来发现该用户最近访问的IdP。
Assertion Query/Request Profile
Assertion Query/Request Profile是一个general profile,对应下列SAML2.0元素的query:<samlp:AssertionIDRequest>, <samlp:SubjectQuery>,<samlp:AuthnQuery>, <samlp:AttributeQuery>, <samlp:AuthzDecisionQuery>。
SAML 2.0 Metadata
毫不夸张地说,metadata使得SAML能够正常运转,metadata有下列用途:
1. SP准备传输<samlp:AuthnRequest>给IdP时,SP如何知道IdP是真实的,不是evil IdP(企图钓鱼),为此,SP在发布authentication request前获取metadata中的可信IdP列表;
2. 在上一个场景中,SP如何知道向user发送authentication request? SP从metadata中查看IdP预先分配的endpoint location(用于authentication的,IdP除了authentication还有其他功能)
3. IdP从SP处接收到<samlp:AuthnRequest>后,IdP如何知道SP是真实的,不是evil SP(企图获取用户信息)?IdP在发布authentication response前获取metadata中的可信SP列表。
4. 在前一个场景中,IdP如何加密SAML assertion,使得仅仅可信的SP能够解密assertion?IdP使用metadata中的加密证书来加密assertion。
5. 紧接着上一场景,IdP如何知道给用户发送authentication response的地址?IdP从metadata中查看可信SP的预先定义的endpoint location。
6. SP如何知道authentication response是来自于一个可信的IdP? SP使用metadata中IdP的公钥验证assertion的签名。
7. SP如何知道从可信IdP收到的artifact的resolve地址?SP从metadata查看IdP的artifact resolution service的预先分配的endpoint location。
metadata保证IdP和SP之间的安全transaction。
IdP metadata示例如下:
其中,entityID是实体的唯一标志,validUntil给出了metadata的失效日期,ds:Signature包含数字签名,md:Organization描述该实体对应的企业信息,contactperson为技术联系人,可以有多个技术联系人。
SSO metadata示例如下:
其中,<md:KeyDescriptor use="signing">为IdP的公钥信息(签名用途);<md:ArtifactResolutionService>中的Binding属性说明artifact resolution中SAML SOAP binding使用的相关信息,其中的location是相应的地址信息;其中的index属性对应SAML type 0x0004 artifact的EndpointIndex。<md:NameIDFormat>元素说明SSO服务支持的SAML name identifier formats。 <md:SignleSignOnService>元素中的Binding属性是SAML 2.0Binding 规范中定义的标准URI,Location是相应的地址信息。<saml:Attribute>描述了IdP愿意assert的属性。
SP metadata
示例如下:
Assertion Consumer Service Metadata
示例如下,其中<md:KeyDescriptor use="signing">和<md:KeyDescriptor use="encryption">分别为用于签名验证、加密的公钥信息。<md:AssertionConsumerService>元素中:index属性是<samlp:AuthnRequest>元素中AssertionConsumerServiceIndex属性的值;Binding属性是SAML 2.0标准中各个Binding方式对应的标准URL;中的Location是相应的URI。
metadata Aggregates:通过<md:EntitiesDescriptor>将多个<md:EntityDescriptor>组合起来。
未完成的部分:
bear token
http://www.rfcreader.com/#rfc6750