【问题标题】:Okta SAML SLO request AuthnFailed/Invalid SignatureOkta SAML SLO 请求 AuthnFailed/无效签名
【发布时间】:2018-03-26 04:24:49
【问题描述】:

我正在尝试在 PHP 中执行 SP 启动的 SAML 2.0 SLO,我的问题是:LogoutResponse 状态代码 AuthnFailed,因此没有 IdP 注销。根据 Okta (IdP) 仪表板,原因是无效签名。 我正在使用 robrichards/xmlseclibs 安全库和 POST 绑定。该请求在https://www.samltool.com/validate_logout_req.phphttp://php.net/manual/en/domdocument.schemavalidate.php 上验证。

这是我的美化要求:

<?xml version="1.0" encoding="utf-8"?>
<samlp:LogoutRequest
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
    ID="_logout_1_5ab86804b6057"
    Version="2.0"
    Destination="https://dev-680804.oktapreview.com/app/catalystitdev680000_xxxx_1/exkeb8o4nbMQ7xxxxxxx/slo/saml"
    IssueInstant="2018-03-26T16:24:52+13:00">
    <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">https://xxxxxxx/</saml: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>
                <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>5SXEPj5gyXWuf/BXfZ7QTVrUuJaF3Khh...</ds:DigestValue>
            </ds:Reference>
        </ds:SignedInfo>
        <ds:SignatureValue>TmAUPHY4rO...</ds:SignatureValue>
        <ds:KeyInfo>
            <ds:X509Data>
                <ds:X509Certificate>MIIFUzCCAzugAwIBAgI...</ds:X509Certificate>
            </ds:X509Data>
        </ds:KeyInfo>
    </ds:Signature>
    <saml:NameID xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">and...</saml:NameID>
    <samlp:SessionIndex>_authn_5ab8680105723</samlp:SessionIndex>
</samlp:LogoutRequest>

这就是我创建 pkey 和 crt 的方式:

#!/bin/bash

# https://github.com/mattermost/docs/blob/master/source/scripts/generate-certificates/gencert.md

umask 377

certname="${CRT_FILENAME:-"nzta-x509"}"
openssl x509 \
    -in <(
        openssl req \
            -days 3650 \
            -newkey rsa:4096 \
            -nodes \
            -keyout "${certname}.key" \
            -subj "/C=${CRT_C:-"NZ"}/L=${CRT_L:-"Wellington"}/O=${CRT_O:-"XXXX"}/OU=${CRT_OU:-"Sysadmins"}/CN=${CRT_CN:-"xxxx-xxxx"}"
        ) \
    -req \
    -signkey "${certname}.key" \
    -sha256 \
    -days 3650 \
    -out "${certname}.crt" \
    -extfile <(echo -e "basicConstraints=critical,CA:true,pathlen:0")

chmod 600 ${certname}.crt

我的想法不多了。如何获得更多错误上下文。 “无效签名”对我没有多大帮助......

【问题讨论】:

    标签: php saml-2.0 okta


    【解决方案1】:

    “无效签名”表示 LogoutRequest 未正确签名。典型的问题是:

    1. 签名散列算法。检查在 IdP 中为您的合作伙伴配置的签名哈希算法(例如:SHA256 或 MD5),您需要使用相同的算法对您的消息进行签名。
    2. 用于签署消息的私钥不正确。检查是否使用了正确的公私钥对,是否在 IdP 配置了关联证书,并且通过 LogoutRequest 发送相同的证书。
    3. 检查整个 LogoutRequest 消息是否已签名,而不仅仅是消息的几个元素。

    【讨论】:

      【解决方案2】:

      感谢时代精神。我找到了一个很好的工具:

      xmlsec1 --verify LogoutRequest.xml
      

      输出非常冗长,给了我很多东西要仔细阅读:

      func=xmlSecOpenSSLX509StoreVerify:file=x509vfy.c:line=360:obj=x509-store:subj=X509_verify_cert:error=4:crypto library function failed:subj=/C=NZ/L=Wellington/O=XXX/OU=Sysadmins/CN=xxx-xxx;err=18;msg=self signed certificate
      func=xmlSecOpenSSLX509StoreVerify:file=x509vfy.c:line=408:obj=x509-store:subj=unknown:error=71:certificate verification failed:err=18;msg=self signed certificate
      func=xmlSecKeysMngrGetKey:file=keys.c:line=1370:obj=unknown:subj=xmlSecKeysMngrFindKey:error=1:xmlsec library function failed: 
      func=xmlSecDSigCtxProcessKeyInfoNode:file=xmldsig.c:line=871:obj=unknown:subj=unknown:error=45:key is not found: 
      func=xmlSecDSigCtxProcessSignatureNode:file=xmldsig.c:line=565:obj=unknown:subj=xmlSecDSigCtxProcessKeyInfoNode:error=1:xmlsec library function failed: 
      func=xmlSecDSigCtxVerify:file=xmldsig.c:line=366:obj=unknown:subj=xmlSecDSigCtxSignatureProcessNode:error=1:xmlsec library function failed: 
      Error: signature failed 
      ERROR
      SignedInfo References (ok/all): 1/1
      Manifests References (ok/all): 0/0
      Error: failed to verify file "LogoutRequest.xml"
      

      【讨论】:

        【解决方案3】:

        将传输的 ds:X509Certificate 文本内容与 IDP 端配置的内容进行比较。我发现传输的版本包括换行符和白色速度字符,它们在字符串匹配中会失败。我删除了它们并验证了它。

        回复较晚,但希望这对某人有所帮助

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-08-19
          • 2016-01-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-02-26
          相关资源
          最近更新 更多