Spring Security SAML - 无法验证签名

Posted

技术标签:

【中文标题】Spring Security SAML - 无法验证签名【英文标题】:Spring Security SAML - Failed to verify signature 【发布时间】:2012-08-17 00:30:51 【问题描述】:

我在 Tomcat 7 上使用 Spring Security SAML 2.0 示例 webapp,并对其进行了修改以尝试使其针对 Ping Identity 服务进行身份验证。 webapp 正在与服务对话,它正在发回一个断言,但在尝试验证签名时失败,如下面的调试输出所示:

- Attempting to verify signature and establish trust using KeyInfo-derived credentials
- Signature contained no KeyInfo element, could not resolve verification credentials
- Failed to verify signature and/or establish trust using any KeyInfo-derived credentials
- Attempting to verify signature using trusted credentials
- Failed to verify signature using either KeyInfo-derived or directly trusted credentials
- Validation of received assertion failed, assertion will be skipped
org.opensaml.xml.validation.ValidationException: Signature is not trusted or invalid

我了解它无法验证签名,并且 Ping Identity 管理员已为我提供了一个证书以供使用,但我不确定如何将其包含在应用程序中。我尝试使用 JDK 的 keytool 程序将其添加到示例应用程序附带的 JKS(密钥库)中,但似乎无法在其中找到它。我也尝试将它添加到服务提供商的元数据 xml 文件中,如下所示:

<md:KeyDescriptor use="signing">
    <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <ds:X509Data>
            <ds:X509Certificate>
                [Certificate is here...]
            </ds:X509Certificate>
        </ds:X509Data>
    </ds:KeyInfo>
</md:KeyDescriptor>

但它仍然返回相同的错误。

为了验证签名,我应该把证书放在一个特定的地方吗?总的来说,我对 SAML 和应用程序安全性比较陌生,所以如果我使用了错误的术语,我深表歉意。

【问题讨论】:

【参考方案1】:

终于搞定了。结果我错过了安全上下文文件中的一行配置,并且(看起来好像)服务提供商的元数据 XML 文件中不需要 X509 证书定义。

基本上我已经将我提供的公钥导入现有的 JKS(使用 keytool),但我没有告诉应用程序专门使用它。为了做到这一点,我必须进入安全上下文文件(在我的例子中是“securityContext.xml”)并将以下行添加到 SP 的元数据 xml 文件的 ExtendedMetadata bean 定义中:

<property name="signingKey" value="[alias of the provided key in the JKS goes here]"/>

因此修改后,ExtendedMetadataDelegate bean 定义如下所示:

<bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate">
  <constructor-arg>
    <bean class="org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider">
      <constructor-arg>
        <value type="java.io.File">classpath:security/[Path to SP metadata xml file].xml</value>
      </constructor-arg>
      <property name="parserPool" ref="parserPool" />
    </bean>
  </constructor-arg>
  <constructor-arg>
    <bean class="org.springframework.security.saml.metadata.ExtendedMetadata">
      <property name="alias" value="[SP alias goes here]" />
      <property name="signingKey" value="[alias of the provided key in the JKS goes here]"/>
    </bean>
  </constructor-arg>
</bean>

希望这对可能处于类似情况的任何人有所帮助。

【讨论】:

感谢您的洞察力。我正在尝试同样的事情,但不断遇到错误。我想知道你是如何处理 keyManager bean 的?我认为这个 bean 是必要的,它坚持提供私钥。这样做时,要导入 ADFS 的结果元数据中缺少公钥

以上是关于Spring Security SAML - 无法验证签名的主要内容,如果未能解决你的问题,请参考以下文章

Spring Security SAML 中的刷新会话

生成 SP 元数据时出现意外的堆栈跟踪表单 Spring-Security-SAML?

Spring Security SAML IdP 元数据证书和签名

带有 wso2 IS 的 Spring Security SAML

未抛出 Spring Security SAML DisabledException

Spring SAML 实现无法解析对 bean 的引用