Spring SAML:为什么在SAML响应中可以对密钥信息进行加密?

时间:2018-07-02 21:21:29

标签: xml encryption saml saml-2.0 spring-saml

根据我的理解,如果idp要加密saml响应声明。 Idp将使用SP提供的加密公钥对其进行加密,而SP将使用私钥对其进行解密。

但这是我从idp获得的SAML响应的一部分

<EncryptedAssertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
   <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element">
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
         <e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#">
            <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
               <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            </e:EncryptionMethod>
            <KeyInfo>
               <ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                  <ds:X509IssuerSerial>
                     <ds:X509IssuerName>...</ds:X509IssuerName>
                     <ds:X509SerialNumber>1142467415</ds:X509SerialNumber>
                  </ds:X509IssuerSerial>
               </ds:X509Data>
            </KeyInfo>
            <e:CipherData>
               <e:CipherValue>...</e:CipherValue>
            </e:CipherData>
         </e:EncryptedKey>
      </KeyInfo>
      <xenc:CipherData>...</xenc:CipherData>
   </xenc:EncryptedData>
</EncryptedAssertion>

在查看源代码之后,SP的加密公共密钥(而不是用于加密/解密断言)用于加密/解密另一个密钥,而该密钥用于加密/解密断言(因此涉及2个密钥对而不是只是1)。

我看看org.opensaml.xml.encryption.Decrypter的源代码。

如果设置了字段解析器,则将使用cryptoUsingResolvedKey()。我认为这应该始终使用。

如果设置了encKeyResolver字段,则将使用cryptoUsingResolvedEncryptedKey()。

有两件事让我感到困惑:

    在spring saml扩展中的
  1. ,当populateDecrypter()时,resolver设置为null。为什么会这样?

  2. 使用已解析的加密密钥解密的目的是什么?为什么要使用2对密钥而不是只使用1对?

1 个答案:

答案 0 :(得分:1)

我想我知道为什么,涉及2个键的原因是为了提高速度。

公共/专用密钥(RSA等)用于加密/解密AES密钥,而AES密钥用于加密/解密实际消息。

由于AES比RSA快得多,并且AES比实际消息短得多。这比仅使用RSA密钥对实际消息进行加密/解密要快。

由于您需要AES密钥才能读取消息,并且需要RSA密钥才能读取AES密钥,因此安全性仍然受到保护。