2.7.3.2 元素<EncryptedAttribute>
本博客采用知识共享署名 4.0 国际许可协议进行许可
<EncryptedAttribute>元素以加密的方式表示SAML属性,符合XML加密语法和处理规范[XMLEnc]中的定义。<EncryptedAttribute>元素包含下列元素:
<xenc:EncryptedData> [必须]
加密的内容和相关的加密详情,符合XML加密语法和处理规范[XMLEnc]中的定义。Type
属性应该存在,如果存在的话,必须包含http://www.w3.org/2001/04/xmlenc#Element
这个值。加密的内容必须包含一个AttributeType
类型的或者派生自该类型的元素。
<xenc:EncryptedKey> [零个或多个]
封装的解密密钥,符合[XMLEnc]中的描述。每一个封装的密钥都应该包含一个Recipient
属性,该属性指定了当前密钥是为了哪个实体而加密的。Recipient
属性的值应该是具有SAML名称标识符的系统实体的URI标识符,如第8.3.6节所定义。
当明文的值通过中间人传递时,可以使用加密属性来保护明文的机密性。
下列的schema片段定义了<EncryptedAttribute>元素:
<element name="EncryptedAttribute" type="saml:EncryptedElementType"/>
以下为译者(义臻)的详细解析
假设现在有一个Attribute
片段如下:
<?xml version="1.0" encoding="UTF-8"?>
<saml2:Attribute Name="username" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">yizhen</saml2:AttributeValue>
</saml2:Attribute>
把上面的Attribute
片段生成EncryptedAttribute
片段的过程是怎样的呢?
首先,生成一个对称的数据密钥(Plain Data Key),用此密钥加密明文。然后,把PDK密钥用接收方的公钥(Key Encrpyted Key)加密。最后,把加密后的数据密钥(Cipher Data Key)和密文一起传输给接受方。
这里描述的是简化过程,实际在处理过程中要遵守[XMLEnc]规范。
使用上述过程可以得到如下EncryptedAttribute
片段:
<?xml version="1.0" encoding="UTF-8"?>
<saml2:EncryptedAttribute xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
<xenc:EncryptedData Id="_907295ebd08f6193095d96ac29b3fcaa" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:RetrievalMethod Type="http://www.w3.org/2001/04/xmlenc#EncryptedKey" URI="#_50e9bca286838bce5dbcf1b182792251"/>
</ds:KeyInfo>
<xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:CipherValue>qZnoGrIH9efoLjuuI9hpwH7zIe0OOfvY1UvrKJ8+rBZYLoWCFmTg22kvXvtcR1C7CxA2II9U72aMsU3hyJngN232Psn6tRK4GyUBn8FKHM043yOxv5vLGOQzoG10Al0A5W9opeGbhU6lbO7Du6mPFn/DI59uaxSFKHbgqnvFEq/it1LIR8TmXUUFTYnUbpUfTGCqBFmmAmkhUGp3paC3sO8rH3n22oaMxLGdt51tEtOx/GXwA7nqIBebmNbEAkKpT7PHZGyY0u2UyXFTIqbk2pHtwUP5vhiWSrbsgXquEzpIDmPk6SJUiKNnZF2gizOeDOCKCcSQqMDpCurkSUzNPGJ2c4YaXuWBkiLfmMJLUmPD3pKZXVo/Xtmy/E8nuK/CI5QX9UccQcye+QGrGt5e6w==</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
<xenc:EncryptedKey Id="_50e9bca286838bce5dbcf1b182792251" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/>
<xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:CipherValue>Q1ckXc0CCb1WjZwBW/61Y40SgqssdJcS3M0FULp71DVhM3c3yGBLw/cYpwcF5cSSzx4blNU8JroHP6MVjqWYBiQWZaYWG5QHsNeN8HJ6O8OzrYxAN7xc+MGuHdyTdrWTEzbwRwde63ZlNyja2mYHKAUsHTqj5eu3ZqKDS9x2EG4=</xenc:CipherValue>
</xenc:CipherData>
<xenc:ReferenceList>
<xenc:DataReference URI="#_907295ebd08f6193095d96ac29b3fcaa"/>
</xenc:ReferenceList>
</xenc:EncryptedKey>
</saml2:EncryptedAttribute>
接收方在收到此密文后,可以先使用自己的私钥解密出数据密钥,再使用数据密钥解密出原始的明文信息,此处不再赘述。源码参考地址。
Last updated
Was this helpful?