我遇到了一個問題,即Spring SAML集成爲我的IdP生成正確的元數據文件。我獲得了新的SHA256 SSL證書。我已經完成了所有的步驟來創建適當的keyStore,並且我的Spring安全配置文件都已經設置好了。我從字面上看似98%的方式,但是在生成的元數據文件中缺少一件事,我無法爲我的生活找出爲什麼它沒有設置。設置ExtendedMetadata'signingAlgorithm'字段
這裏是我的MetadataGeneratorFilter ExtendedMetadata配置:
<bean id="metadataGeneratorFilter" class="org.springframework.security.saml.metadata.MetadataGeneratorFilter">
<constructor-arg>
<bean class="org.springframework.security.saml.metadata.MetadataGenerator">
<property name="entityId" value="urn:myentityidhere"/>
<property name="entityBaseURL" value="https://${saml.url}"/>
<property name="extendedMetadata">
<bean class="org.springframework.security.saml.metadata.ExtendedMetadata">
<property name="signMetadata" value="true"/>
<property name="signingAlgorithm" value="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<property name="alias" value="ceo"/>
<property name="signingKey" value="${saml.sp.alias}"/>
<property name="encryptionKey" value="${saml.sp.alias}"/>
</bean>
</property>
</bean>
</constructor-arg>
當我運行我的應用程序,並轉到/ SAML /元數據URI讓Spring生成的元數據文件,我需要發送到我的IdP,SHA256算法在SignatureMethod上得到了正確設置,但子DigestMethod標籤的算法值仍然設置爲SHA1,當我需要將SHA256和DigestValue一起設置爲SHA256值而不是SHA1值時。
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<ds:Reference URI="#urn_myentityidhere">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>xxxxxxx</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
有人可以指導我如何/我需要設置將DigestMethod算法值設置爲256也是什麼?我想,因爲它是SignedInfo標記的子元素,它將繼承Extendedmetadata配置中的signingAlgorithm值,但事實並非如此。
任何幫助將非常感激。非常感謝。
的解決方案 - 萬一有人關心
所以,一天的價值挖掘後,我決定只實現這個自己。我通過添加字段,digestMethodAlgorithm延長ExtendedMetadata類和加入適當的吸氣/ setter方法:
/**
* Algorithm used for creation of digest method of this entity. At the moment only used for metadata signatures.
* Only valid for local entities.
*/
private String digestMethodAlgorithm;
/**
* Returns digest method algorithm value
* @return String
*/
public String getDigestMethodAlgorithm()
{
return digestMethodAlgorithm;
}
/**
* Sets the digest method algorithm to use when signing the SAML messages.
* This can be used, for example, when a strong algorithm is required (e.g. SHA 256 instead of SHA 128).
* If this property is null, then the {@link org.opensaml.xml.Configuration} default algorithm will be used instead.
*
* Value only applies to local entities.
*
* At the moment the value is only used for signatures on metadata.
*
* Typical values are:
* http://www.w3.org/2001/04/xmlenc#sha1
* http://www.w3.org/2001/04/xmlenc#sha256
* http://www.w3.org/2001/04/xmlenc#sha384
* http://www.w3.org/2001/04/xmlenc#sha512
* http://www.w3.org/2001/04/xmlenc#ripemd160
*
* @param digestMethodAlgorithm The new digest method algorithm to use
* @see org.opensaml.xml.signature.SignatureConstants
*/
public void setDigestMethodAlgorithm(String digestMethodAlgorithm)
{
this.digestMethodAlgorithm = digestMethodAlgorithm;
}
然後我修改從我的上述彈簧安全配置,以包括該新bean屬性在我MetadataGenerator配置進行設置:
<bean id="metadataGeneratorFilter" class="org.springframework.security.saml.metadata.MetadataGeneratorFilter">
<constructor-arg>
<bean class="org.springframework.security.saml.metadata.MetadataGenerator">
<property name="entityId" value="urn:myentityidhere"/>
<property name="entityBaseURL" value="https://${saml.url}"/>
<property name="extendedMetadata">
<bean class="org.springframework.security.saml.metadata.ExtendedMetadata">
<property name="signMetadata" value="true"/>
<property name="signingAlgorithm" value="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<property name="digestMethodAlgorithm" value="http://www.w3.org/2001/04/xmlenc#sha256"/>
<property name="alias" value="ceo"/>
<property name="signingKey" value="${saml.sp.alias}"/>
<property name="encryptionKey" value="${saml.sp.alias}"/>
</bean>
</property>
</bean>
</constructor-arg>
然後,我也不得不提出兩個更改SAMLUtil類。在getSignadataAsString中,在isSignMetadata()if-子句中,我提取了由上述配置設置的digestMethodAlgorithm的注入值,然後進一步修改了marshallAndSignMessage方法以接受一個新的輸入參數,我進一步使用它來獲取DigestMethod算法集合。
內SAMLUtil.getMetaDataAsString的,線572
...
String digestMethodAlgorithm = extendedMetadata.getDigestMethodAlgorithm();
element = SAMLUtil.marshallAndSignMessage(descriptor, credential, signingAlgorithm, digestMethodAlgorithm, keyGenerator);
...
內SAMLUtil.marshallAndSignMessage,線437之後,我添加/更改如下:
...
BasicSecurityConfiguration secConfig = null;
if (digestMethodAlgorithm != null)
{
secConfig = (BasicSecurityConfiguration) Configuration.getGlobalSecurityConfiguration();
secConfig.setSignatureReferenceDigestMethod(digestMethodAlgorithm);
}
try {
SecurityHelper.prepareSignatureParams(signature, signingCredential, secConfig, keyInfoGenerator);
} catch (org.opensaml.xml.security.SecurityException e) {
throw new MessageEncodingException("Error preparing signature for signing", e);
}
...
我重新編譯了整個春天SAML通過Gradle,spring-security-saml-1.0.0.RELEASE,將新jar從build/libs目錄複製到我的項目中,部署webapp,將瀏覽器指向/ saml/metadata併成功獲取元數據文件meta的正確SHA256簽名部分數據文件。
我會看看我能做些什麼來實現這個項目的git repo,因爲我不想失去這個能力,因爲這個項目將來會發布。以前從來沒有爲這樣的開源項目做過貢獻。
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<ds:Reference URI="#urn_myentityidhere">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue>xxxxxx</ds:DigestValue>
</ds:Reference>
你使用了哪個spring-security-saml2-core版本?我不能使你的建議... – nuvio 2016-07-29 07:01:24
這是使用'org.springframework.security.extensions:spring-security-saml2-core:1.0.1.RELEASE' with'org.opensaml:opensaml:2.6.4' 。 – 2016-07-29 13:12:30