1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SAML2\XML\saml; |
6
|
|
|
|
7
|
|
|
use RobRichards\XMLSecLibs\XMLSecurityKey; |
8
|
|
|
use SAML2\Compat\ContainerSingleton; |
9
|
|
|
use SAML2\Constants; |
10
|
|
|
use SAML2\XML\EncryptedElementInterface; |
11
|
|
|
use SAML2\XML\EncryptedElementTrait; |
12
|
|
|
use SAML2\Exception\InvalidArgumentException; |
13
|
|
|
use SAML2\Utils; |
14
|
|
|
use SAML2\XML\AbstractXMLElement; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class representing an encrypted identifier. |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/saml2 |
20
|
|
|
*/ |
21
|
|
|
class EncryptedID extends AbstractSamlElement implements EncryptedElementInterface |
22
|
|
|
{ |
23
|
|
|
use EncryptedElementTrait; |
|
|
|
|
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
* |
29
|
|
|
* @return IdentifierInterface |
30
|
|
|
* @throws \Exception |
31
|
|
|
* |
32
|
|
|
* @psalm-suppress MismatchingDocblockReturnType |
33
|
|
|
* @psalm-suppress ImplementedReturnTypeMismatch |
34
|
|
|
*/ |
35
|
|
|
public function decrypt(XMLSecurityKey $key, array $blacklist = []): AbstractXMLElement |
36
|
|
|
{ |
37
|
|
|
$xml = Utils::decryptElement($this->encryptedData->toXML(), $key, $blacklist); |
38
|
|
|
$id = implode(':', [$xml->namespaceURI, $xml->localName]); |
39
|
|
|
switch ($id) { |
40
|
|
|
case NameID::NS . ':NameID': |
41
|
|
|
return NameID::fromXML($xml); |
42
|
|
|
case Issuer::NS . 'Issuer': |
43
|
|
|
return Issuer::fromXML($xml); |
44
|
|
|
case BaseID::NS . ':BaseID': |
45
|
|
|
$xsiType = $xml->getAttributeNS(Constants::NS_XSI, 'type'); |
46
|
|
|
$container = ContainerSingleton::getInstance(); |
47
|
|
|
$handler = $container->getIdentifierHandler($xsiType); |
48
|
|
|
if ($handler !== null) { |
49
|
|
|
return $handler::fromXML($xml); |
50
|
|
|
} |
51
|
|
|
return BaseID::fromXML($xml); |
52
|
|
|
} |
53
|
|
|
throw new InvalidArgumentException('Unknown or unsupported encrypted identifier.'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|