我在尝试使用python saml和flask处理IdP启动的SAML2响应时遇到以下错误:
Signature validation failed. SAML Response rejected
我按照这个例子here。我的代码是:
^{pr2}$在SAML\u 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
,和wantAssertionsSigned
。断言是经过签名的(也许我们无法从您的示例中真正看出),但是消息(即响应作为一个整体)没有被签名。在你怎么知道?如果您的响应是签名的,它看起来更像下面的注释
ds:Signature
块(为了便于查看,我在其周围添加了一些空白行)。块包括消息的DigestValue,然后是该摘要的签名。它包括一个证书,您可以用它来解码签名并验证它是否与摘要匹配。在IdP用其私钥对响应进行签名,并向您发送证书。断言由IdP使用您的证书加密,允许您(而且只有您)解密它们(加密的断言是否签名?我不知道需要先解密。)
相关问题 更多 >
编程相关推荐