简体   繁体   English

如何使用PHP解码来自idP的加密SAML响应?

[英]How to decode encrypted SAML response from idP with PHP?

First time trying to implement SAML as an SP. 第一次尝试将SAML实施为SP。 We decided to try using SimpleSAMLphp with our bespoke MVC framework as we figured it would save us time. 我们决定尝试在定制的MVC框架中使用SimpleSAMLphp,因为我们认为这样做可以节省时间。

Problem that I have is that I end up in an infinite loop or the attributes are empty. 我遇到的问题是我陷入无限循环或属性为空。

I have configured my metadata and tested it from the authenticate interface in SimpleSAMLphp. 我已经配置了元数据,并从SimpleSAMLphp中的authenticate接口对其进行了测试。 The idP has a post-back URL set that is different to where we begin, so: idP的回发URL集与我们开始时的URL集不同,因此:

  • User hits domain.com/sso We create new instance of SimpleSAML_Auth_Simple('our-configured-sp') 用户点击domain.com/sso我们创建了SimpleSAML_Auth_Simple('our-configured-sp')新实例
  • Call $as->requireAuth() 调用$as->requireAuth()
  • Client is redirected to idP 客户端被重定向到idP
  • idP redirects user back to domain.com/sso/saml idP将用户重定向回domain.com/sso/saml

If we do this, we have to create a new instance using the same code ( $as = new SimpleSAML_Auth_Simple('our-configured-sp') , for example) and when we do $as->getAttributes() it is an empty array. 如果执行此操作,则必须使用相同的代码(例如$as = new SimpleSAML_Auth_Simple('our-configured-sp')创建一个新实例),当我们执行$as->getAttributes()时,该实例为空数组。 We're using the phpsession store.type but when I look at the cookies on the domain I see only PHPSESSID and SimpleSAMLAuthToken 我们正在使用phpsession store.type但是当我查看域上的cookie时,我只会看到PHPSESSIDSimpleSAMLAuthToken

So we tried putting it all into one method. 因此,我们尝试将所有内容整合为一种方法。 As above, only you begin on domain.com/sso/saml except this time the loop keeps going over and over. 如上所述,只有您从domain.com/sso/saml开始,除了这次循环不断重复。 The user hits our domain, is redirected to the idP, then redirected back to us, then back to the idP, for ever. 用户点击我们的域,重定向到idP,然后重定向回我们,然后再重定向回idP,直到永远。

Eventually I gave up. 最终我放弃了。 I can get the response in $_POST['SAMLResponse'] and I can base64_decode() it to see what it says. 我可以在$_POST['SAMLResponse']获得响应,并且可以base64_decode()来查看其内容。 I put it into a SimpleXMLElement object and was able to work with it. 我将其放入SimpleXMLElement对象中并能够使用它。 The problem is that the data is encrypted, and now I'm stuck trying to decrypt it. 问题在于数据是加密的,现在我被困在尝试对其解密。

I have data in these nodes but don't know what to do with it: 我在这些节点中有数据,但不知道该如何处理:

  • samlp:Response->saml:EncryptedAssertion->EncryptedData->KeyInfo->EncryptedKey->X509Data->X509Certificate samlp:响应-> saml:EncryptedAssertion-> EncryptedData-> KeyInfo-> EncryptedKey-> X509Data-> X509Certificate
  • samlp:Response->saml:EncryptedAssertion->EncryptedData->KeyInfo->EncryptedKey->CipherData->CipherValue samlp:响应-> saml:EncryptedAssertion-> EncryptedData-> KeyInfo-> EncryptedKey-> CipherData-> CipherValue
  • samlp:Response->saml:EncryptedAssertion->EncryptedData->CipherData->CipherValue samlp:响应-> saml:EncryptedAssertion-> EncryptedData-> CipherData-> CipherValue

I don't know how to use each of these, though I can verify that the X509Certificate is the public key to match my private key. 尽管可以验证X509Certificate是与我的私钥匹配的公钥,但我不知道如何使用它们。 I've tried decoding various values using different keys (or what I thought were keys) to no avail. 我尝试使用不同的键(或我认为是键)对各种值进行解码都无济于事。

  • samlp:Response->saml:EncryptedAssertion->EncryptedData->KeyInfo->EncryptedKey->EncryptionMethod suggests RSA1_5 samlp:响应-> saml:EncryptedAssertion-> EncryptedData-> KeyInfo-> EncryptedKey-> EncryptionMethod建议使用RSA1_5
  • samlp:Response->saml:EncryptedAssertion->EncryptedData->EncryptionMethod suggests AES256-CBC (I've been trying mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, "cbc", $iv); though I can't actually work out what I'm supposed to put into $key or $data ) samlp:Response-> saml:EncryptedAssertion-> EncryptedData-> EncryptionMethod建议使用AES256-CBC (我一直在尝试mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, "cbc", $iv);尽管我实际上mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, "cbc", $iv);我应该放入$key$data

Ideally I'd like to get it working completely within SimpleSAMLphp, but I honestly have no idea what the problem is so I don't know how to sort it. 理想情况下,我想使其完全在SimpleSAMLphp中运行,但是老实说,我不知道问题出在什么地方,所以我不知道如何对其进行排序。 Metadata looks like this: 元数据看起来像这样:

$metadata = array(
    'https://partner.com' => array(
        'SingleSignOnService' => 'https://partner.com/sso/response',
        'SingleLogoutService' => 'https://partner.com/sso/slo',
        'assertion.encryption' => true,
        'certificate' => partner.cer'
    )
);

Authsources has this: Authsources具有以下功能:

$config = array(
    'our-configured-sp' => array(
        'saml:SP',
        'privatekey' => 'my.private.pem',
        'certificate' => 'my.public.cert',
        'idp' => 'https://partner.com',
        'baseurlpath' => 'simplesaml/',
    )
);

Any help? 有什么帮助吗? Preferably to get the whole thing working with SimpleSAMLphp, but if not I'd take a little guidance on how to decrypt the file. 最好是使整个事情与SimpleSAMLphp一起使用,但是如果没有,我将对如何解密文件采取一些指导。

Thanks everyone 感谢大家

Please check the One Login SAML php library, It is well documented and coded. 请检查一个登录 SAML php库,该文件已被很好地记录和编码。 You can easily use it to processResponse and the getAttributes do what you want. 您可以轻松地使用它来处理response和getAttributes做您想要的事情。

I know the question is old, But it may help someone still looking for the same. 我知道这个问题很旧,但这可能会帮助仍在寻找相同问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM