首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SAML断言中的SAML 2.0摘要值计算

SAML断言中的SAML 2.0摘要值计算
EN

Stack Overflow用户
提问于 2021-09-20 10:23:36
回答 1查看 712关注 0票数 0

我想知道在SAML 2响应中有digestValue时是如何计算AttributeStatement的。在SAML响应中没有任何“SAML 2:AttributeStatement”时,我可以计算并获得相同的digestValue:

删除ds:签名segment

  • Canonicalizing XML payload

  • Applying SHA-256以计算摘要值的
  1. (如我在IDP部件上配置的那样)

但是,当我在IDP侧配置为在响应中添加“saml2 2:AttributeStatement”和一个属性时,无论是否保留“saml2 2:AttributeStatement”,我都不能再计算IDP返回给我的相同的摘要值。

我该怎么做才能算出正确的数值?我在用OKTA的IDP。

我在SAML响应中的SAML断言如下:

代码语言:javascript
复制
<saml2:Assertion ID="id2725281198079267683856882"
                     IssueInstant="2021-09-20T07:18:33.051Z"
                     Version="2.0"
    xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
                     >
    <saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
        xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
                      >http://www.okta.com/exk1mv3c9ke9u3tz25d7
    </saml2:Issuer>
    <ds:Signature
        xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <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="#id2725281198079267683856882">
                <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#">
                        <ec:InclusiveNamespaces PrefixList="xs"
                            xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
                                                    />
                        </ds:Transform>
                    </ds:Transforms>
                    <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                    <ds:DigestValue>uHowdunaQ+0tDsHrEGgJFUWwd23L08Qubp9HFS2In2Q=</ds:DigestValue>
                </ds:Reference>
            </ds:SignedInfo>
            <ds:SignatureValue>S9YQNf7t...</ds:SignatureValue>
            <ds:KeyInfo>
                <ds:X509Data>
                    <ds:X509Certificate>MIIDq...
                    </ds:X509Data>
                </ds:KeyInfo>
            </ds:Signature>
            <saml2:Subject
                xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
                <saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">allen.li@gmail.com</saml2:NameID>
                <saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
                    <saml2:SubjectConfirmationData InResponseTo="a3b3ff8jicf316993316069j03bdjfj"
                                               NotOnOrAfter="2021-09-20T07:23:33.051Z"
                                               Recipient="http://localhost:8080/saml/SSO"
                                               />
                </saml2:SubjectConfirmation>
            </saml2:Subject>
            <saml2:Conditions NotBefore="2021-09-20T07:13:33.051Z"
                          NotOnOrAfter="2021-09-20T07:23:33.051Z"
                xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
                          >
                <saml2:AudienceRestriction>
                    <saml2:Audience>http://localhost:8080/saml/metadata</saml2:Audience>
                </saml2:AudienceRestriction>
            </saml2:Conditions>
            <saml2:AuthnStatement AuthnInstant="2021-09-20T07:18:33.051Z"
                              SessionIndex="a3b3ff8jicf316993316069j03bdjfj"
                xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
                              >
                <saml2:AuthnContext>
                    <saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml2:AuthnContextClassRef>
                </saml2:AuthnContext>
            </saml2:AuthnStatement>
            <saml2:AttributeStatement
                xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
                <saml2:Attribute Name="email"
                             NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
                             >
                    <saml2:AttributeValue
                        xmlns:xs="http://www.w3.org/2001/XMLSchema"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                      xsi:type="xs:string"
                                      >allen.li@gmail.com
                    </saml2:AttributeValue>
                </saml2:Attribute>
            </saml2:AttributeStatement>
        </saml2:Assertion> 
EN

回答 1

Stack Overflow用户

发布于 2021-09-27 03:29:22

问题解决了。在执行规范化操作与Java org.apache.xml.security.c14n.Canonicalizer.getInstance(String).提供的内容之间存在着差距。在Java实现中,他们删除了名称空间xmlns:xs="http://www.w3.org/2001/XMLSchema",但是OKTA保留了它,在我在规范化的SAML断言中添加了这个名称空间并计算了摘要值之后,我得到了与OKTA相同的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69252831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档