获得;签名验证失败。SAML回应被拒绝“拒绝”;将python saml与烧瓶一起使用
在尝试使用python saml和flask处理IdP启动的SAML2响应时,我遇到以下错误:获得;签名验证失败。SAML回应被拒绝“拒绝”;将python saml与烧瓶一起使用,python,flask,saml-2.0,Python,Flask,Saml 2.0,在尝试使用python saml和flask处理IdP启动的SAML2响应时,我遇到以下错误: Signature validation failed. SAML Response rejected 我正在学习这个例子。我的代码是: url_data = urlparse(request.url) req = { "https": "on", "http_host": request.host, "server_port": url_data.port, "sc
Signature validation failed. SAML Response rejected
我正在学习这个例子。我的代码是:
url_data = urlparse(request.url)
req = {
"https": "on",
"http_host": request.host,
"server_port": url_data.port,
"script_name": request.path,
"get_data": request.args.copy(),
"post_data": request.form.copy()
}
auth = OneLogin_Saml2_Auth(req, custom_base_path=app.config['SAML_PATH'])
auth.process_response()
在SAML_PATH中,我的settings.json文件中有以下内容:
{
"strict": false,
"debug": true,
"sp": {
"entityId": "[spEntityId]",
"assertionConsumerService": {
"url": "[acsUrl]",
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
},
"NameIDFormat": "urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified",
"x509cert": "[x509cert]",
"privateKey": "[privateKey]"
},
"idp": {
"entityId": "[idpEntityId]",
"singleSignOnService": {
"url": "http://dummy.com/saml2",
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
},
"singleLogoutService": {
"url": "http://dummy.com/saml2",
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
},
"x509cert": "[x509cert]"
},
"security": {
"nameIdEncrypted": false,
"authnRequestsSigned": false,
"logoutRequestSigned": false,
"logoutResponseSigned": false,
"signMetadata": false,
"wantMessagesSigned": true,
"wantAssertionsSigned": true,
"wantNameIdEncrypted": false,
"requestedAuthnContext": false
}
}
如您所见,我为IdP singleSignOnService和singleLogoutService URL使用了虚拟值。我认为在我的案例中不需要它们,因为我只需要处理SAML响应。我还为SP和IdP使用了相同的x509cert。响应具有签名消息和加密断言:
<?xml version="1.0" encoding="UTF-8"?>
<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" Destination="[Destination]" ID="[ID]" IssueInstant="2015-11-30T15:35:02.702Z" Version="2.0">
<saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
[Issuer]
</saml2:Issuer>
<saml2p:Status>
<saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</saml2p:Status>
<saml2:EncryptedAssertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="[ID]" Type="http://www.w3.org/2001/04/xmlenc#Element">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" />
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<xenc:EncryptedKey Id="[ID]" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" />
<xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:CipherValue>
[CipherValue]
</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedKey>
</ds:KeyInfo>
<xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:CipherValue>
[CipherValue]
</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</saml2:EncryptedAssertion>
</saml2p:Response>
[发行人]
[密码值]
[密码值]
我已验证x509cert和privateKey是否正确。我是SAML2新手,所以我希望它是简单的:)提前谢谢 您上面提供的响应未签名,但您已请求对该响应进行签名,因此您的软件拒绝该响应
您的配置显示wantMessagesSigned
,和WANTASERTIONSSIGNED
。断言是经过签名的(也许——我们实际上无法从您的示例中看出),但是消息(即,作为一个整体的响应)没有经过签名
你怎么知道?如果您的响应是签名的,那么它看起来更像下面的内容——请注意ds:Signature
块(我在其周围添加了一些空行,以便更容易查看)。该块包括消息的摘要值,然后是该摘要的签名。它包括一个证书,您可以用它来解码签名并验证它是否与摘要匹配
IdP使用其私钥对响应进行签名,并向您发送证书。IdP使用您的证书对断言进行加密,允许您(并且只有您)解密它们(加密的断言是否已签名?我不知道--需要先解密它们。)
[发行人]
...
[摘要价值]
[签名]
[证书]
[密码值]
[密码值]
您找到解决方案了吗?我有一个类似的问题。我的问题是通过让IdP在签名中包含KeyInfo元素来解决的。这是python saml当前所需的:
<?xml version="1.0" encoding="UTF-8"?>
<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" Destination="[Destination]" ID="[ID]" IssueInstant="2015-11-30T15:35:02.702Z" Version="2.0">
<saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
[Issuer]
</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-cl14n#"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<ds:Reference URI="#[ID]">
<ds:Transforms>
...
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www/s3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue>[DigestValue]</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
[Signature]
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
[Certificate]
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<saml2p:Status>
<saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</saml2p:Status>
<saml2:EncryptedAssertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="[ID]" Type="http://www.w3.org/2001/04/xmlenc#Element">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" />
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<xenc:EncryptedKey Id="[ID]" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" />
<xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:CipherValue>
[CipherValue]
</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedKey>
</ds:KeyInfo>
<xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:CipherValue>
[CipherValue]
</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</saml2:EncryptedAssertion>