Setting the ExtendedMetadata 'signingAlgorithm' field

血红的双手。 提交于 2019-11-28 23:38:30

Things seem to have changed since the @VladimírSchäfer answer; it did not work for us with AD FS 2.0 and SHA-256. We had to add an extra setting to get it to work (see code, below).

The problem appears to be in OpenSAML's xmltooling library, specifically the org.opensaml.xml.security.BasicSecurityConfiguration.getSignatureAlgorithmURI(Credential) method - instead of just using the signature algorithm of the certificate (in our case, SHA256withRSA), it gets the key of the certificate, then looks at the algorithm of that key and uses a map of registered URIs to look up a signature URI. If they'd just have a map of JCA signature algorithms to URIs, instead of key algorithms to URIs, it would all be fine.

The workaround is to register the correct signature algorithm URI with BasicSecurityConfiguration during Spring wiring, overwriting the (undesirable) URI http://www.w3.org/2000/09/xmldsig#rsa-sha1 that's already present with http://www.w3.org/2001/04/xmldsig-more#rsa-sha256.

We also had to remove the setSignatureReferenceDigestMethod() call, or importing metadata into AD FS would fail.

import org.opensaml.Configuration;
import org.opensaml.xml.security.BasicSecurityConfiguration;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.security.saml.SAMLBootstrap;

public class CustomSamlBootstrap extends SAMLBootstrap {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
super.postProcessBeanFactory(beanFactory); BasicSecurityConfiguration config = (BasicSecurityConfiguration) Configuration.getGlobalSecurityConfiguration(); config.registerSignatureAlgorithmURI("RSA", "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"); } }

You can configure digest method for computation of digital signatures by making the following call during Spring SAML initialization:

// Use SHA-256 signatures for RSA keys
BasicSecurityConfiguration config = (BasicSecurityConfiguration) Configuration.getGlobalSecurityConfiguration();
config.setSignatureReferenceDigestMethod(SignatureConstants.ALGO_ID_DIGEST_SHA256);

For example extend the default org.springframework.security.saml.SAMLBootstrap and add the code to the overriden postProcessBeanFactory method after call to super:

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    super.postProcessBeanFactory(beanFactory);
    BasicSecurityConfiguration config = (BasicSecurityConfiguration) Configuration.getGlobalSecurityConfiguration();
    config.setSignatureReferenceDigestMethod(SignatureConstants.ALGO_ID_DIGEST_SHA256);
}

This change affects both signatures in generated metadata and signatures in generated SAML messages.

pramod

After making the changes in SAMLBootstrap for global security config , I ran into below exception :

org.apache.xml.security.signature.XMLSignatureException: The requested algorithm SHA256withRSA does not exist. Original Message was: SHA256withRSA MessageDigest not available at org.apache.xml.security.algorithms.MessageDigestAlgorithm.getDigestInstance(Unknown Source) at org.apache.xml.security.algorithms.MessageDigestAlgorithm.getInstance(Unknown Source) at org.apache.xml.security.signature.Reference.(Unknown Source) at org.apache.xml.security.signature.Manifest.addDocument(Unknown Source) at org.apache.xml.security.signature.XMLSignature.addDocument(Unknown Source)

After further investigation found that the Apache XML Security xmlsec-1.4.3.jar does not support the underlying SHA256withRSA algorithm.

Resolution : Use xmlsec-2.0.2.jar from https://mvnrepository.com/artifact/org.apache.santuario/xmlsec/2.0.2

This new jar resolved the issue .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!