代码之家  ›  专栏  ›  技术社区  ›  SBB

OneLogin php saml-saml响应问题

  •  0
  • SBB  · 技术社区  · 7 年前

    我已经使用php saml集成了一个登录名来连接我们的idp服务。在我们的登台环境中,我们使用的设置一切正常。

    但是,在我们的生产环境中使用这些相同的文件时,我遇到了一个问题。

    问题是SAML响应没有用 saml-schema-protocol-2.0.xsd 架构,正在对此抛出错误。

    $settingsInfo = array(
        'strict' => true,
        'debug' => false,
        'sp' => array(
            'entityId' => 'website',
            'assertionConsumerService' => array(
                'url' => "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
                'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
            ) ,
            'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
            'x509cert' => file_get_contents('tool-sso.pem', FILE_USE_INCLUDE_PATH) ,
            'privateKey' => file_get_contents('tool-sso.key', FILE_USE_INCLUDE_PATH) ,
        ) ,
        'idp' => array(
            'entityId' => 'https://sso.example.com',
            'singleSignOnService' => array(
                'url' => 'https://sso.example.com/idp/SSO.saml2',
                'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
            ) ,
            'singleLogoutService' => array(
                'url' => 'https://sso.example.com/idp/SSO.saml2',
                'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
            ) ,
            'x509cert' => file_get_contents('sso.pem', FILE_USE_INCLUDE_PATH)
        ) ,
        'compress' => array(
            'requests' => true,
            'responses' => true
        ) ,
        'security' => array(
            'authnRequestsSigned' => true,
            'signatureAlgorithm' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
        )
    );
    

    但是,如果我将以下行添加到安全设置中,它就可以正常工作:

    'wantXMLValidation' => false

    这使我认为我们从idp得到的SAML响应在某种程度上不是由 xsd .

    wantXMLValidation=true 失败?是因为SAML响应中缺少/附加/不正确的数据,还是因为我们如何发送数据的问题?

    我试图排除idp是这里的问题,但为了保持我们的登台和生产环境的同步,我想得到 wantXMLValidation 标志设回真。

    Validate XML with the XSD schema tool 它返回为有效的xml。

        Warning: DOMDocument::schemaValidate(): Invalid Schema in \\fileshare\root\resources\Classes\OneLogin\src\Saml2\Utils.php on line 135 failed to load external entity "/fileshare/root/resources/Classes/OneLogin/src/Saml2/schemas/xmldsig-core-schema.xsd" Element '{http://www.w3.org/2001/XMLSchema}import': Failed to locate a schema at location '/fileshare/root/resources/Classes/OneLogin/src/Saml2/schemas/xmldsig-core-schema.xsd'. Skipping the import. failed to load external entity "/fileshare/root/resources/Classes/OneLogin/src/Saml2/schemas/xenc-schema.xsd" Element '{http://www.w3.org/2001/XMLSchema}import': Failed to locate a schema at location '/fileshare/root/resources/Classes/OneLogin/src/Saml2/schemas/xenc-schema.xsd'. Skipping the import. Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref': The QName value '{http://www.w3.org/2001/04/xmlenc#}EncryptedData' does not resolve to a(n) element declaration. Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref': The QName value '{http://www.w3.org/2001/04/xmlenc#}EncryptedKey' does not resolve to a(n) element declaration. Invalid SAML Response. Not match the saml-schema-protocol-2.0.xsd
    invalid_response
    
    OneLogin\Saml2\Auth Object
    (
        [_settings:OneLogin\Saml2\Auth:private] => OneLogin\Saml2\Settings Object
    

    环境:

    我的安装程序是一个带有两个windows服务器和一个文件共享的负载平衡器。用户连接到LB,运行PHP的web服务器从文件共享调用onelogin PHP文件(与web服务器不在同一服务器上)。我提出这个问题的唯一原因是我想知道是否与 schemaLocations 正在尝试阅读 .xsd 文件夹。

    我可能已经想好了,只是不是一个更好的方法来解决它。

    Utils.php 打电话 validateXML 加载它将SAML响应与之进行比较的架构文件。在尝试了一个错误之后,我将模式文件直接移动到web服务器,而不是文件共享。在移动它们并对这些模式文件的位置进行硬编码之后,问题就解决了。

    public static function validateXML($xml, $schema, $debug = false)
        {
            assert(is_string($xml) || $xml instanceof DOMDocument);
            assert(is_string($schema));
    
            libxml_clear_errors();
            libxml_use_internal_errors(true);
    
            if ($xml instanceof DOMDocument) {
                $dom = $xml;
            } else {
                $dom = new DOMDocument;
                $dom = self::loadXML($dom, $xml);
                if (!$dom) {
                    return 'unloaded_xml';
                }
            }
    
            //$schemaFile = __DIR__ . '/schemas/' . $schema;
            $schemaFile = 'file://C:\inetpub\wwwroot\config\schemas\\'. $schema;
    

    我不确定这是否是libXML无法读取这样一个目录的路径问题,或者它的权限等。

    我希望模式与 OneLogin

    我的路有什么特别的地方我可能会错过?

    0 回复  |  直到 7 年前