9

我在 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 和应用程序安全性比较陌生,所以如果我使用了错误的术语,我深表歉意。

4

1 回答 1

9

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

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

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

因此,在此修改之后,ExtendedMetadataDelegatebean 定义如下所示:

<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>

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

于 2012-08-23T15:21:18.960 回答