xsd - OneLogin php saml - SAML 响应问题
问题描述
我已经使用 php-saml 集成了 OneLogin 以连接到我们的 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
标志设置回 true。
我已尝试针对该Validate XML with the XSD schema
工具运行响应,它以有效的 xml 形式返回。
打开 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
环境:
我的设置是具有 2 个 Windows 服务器和一个文件共享的负载平衡器。用户连接到 LB,运行 PHP 的网络服务器从文件共享(与网络服务器不在同一台服务器上)调用 onelogin PHP 文件。我提出这个问题的唯一原因是因为我想知道是否与schemaLocations
尝试读取.xsd
文件的方式有关。
更新:
我可能已经想通了,只是不是更好的解决方法。
OneLogin 文件中有一个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;
在此更改之前,架构文件将一直在查看此 xsd 的文件共享。
我不确定这是否是 libXML 无法读取这样的目录或其权限等的路径问题。
我希望将架构OneLogin
与 Web 服务器本身放在同一个文件夹中,而不必引用它们。
我可能在这里遗漏的路径中有什么突出的地方吗?
解决方案
推荐阅读
- java - 在 Springboot 中进行请求验证时,响应不符合预期
- javascript - IE 不支持箭头(=>)
- javascript - 角度日期和时间验证 MM/DD/YYY HH24MI
- javascript - 表单验证有效,但当用户输入错误答案时仍然提交
- python - Python Bleak 扫描广告并退出事件循环
- list - Haskell 将一个列表与测试用例相加
- docker - MAC M1 2020 处理器的等效 Docker Linux 命令
- c# - gRPC 使用 C# 连接到 Concordium 区块链 API
- openssl - 获取 OpenSSL 的 OpenSC PKCS11 引擎日志
- c++ - 非参数化构造函数的目的是什么?