|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML11\XML; |
|
6
|
|
|
|
|
7
|
|
|
use SimpleSAML\Assert\Assert; |
|
8
|
|
|
use SimpleSAML\SAML11\Compat\ContainerSingleton; |
|
9
|
|
|
use SimpleSAML\XMLSecurity\Exception\ReferenceValidationFailedException; |
|
10
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\Signature; |
|
11
|
|
|
use SimpleSAML\XMLSecurity\XML\SignedElementTrait as BaseSignedElementTrait; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Helper trait for processing signed elements. |
|
15
|
|
|
* |
|
16
|
|
|
* @package simplesamlphp/saml11 |
|
17
|
|
|
*/ |
|
18
|
|
|
trait SignedElementTrait |
|
19
|
|
|
{ |
|
20
|
|
|
use BaseSignedElementTrait; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Initialize a signed element from XML. |
|
25
|
|
|
* |
|
26
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Signature $signature The ds:Signature object |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function setSignature(Signature $signature): void |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Signatures MUST contain a single <ds:Reference> containing a same-document reference to the ID |
|
32
|
|
|
* attribute value of the root element of the assertion or protocol message being signed. For example, if the |
|
33
|
|
|
* ID attribute value is "foo", then the URI attribute in the <ds:Reference> element MUST be "#foo". |
|
34
|
|
|
*/ |
|
35
|
|
|
|
|
36
|
|
|
$references = $signature->getSignedInfo()->getReferences(); |
|
37
|
|
|
Assert::count($references, 1, "A signature needs to have exactly one Reference, %d found."); |
|
38
|
|
|
|
|
39
|
|
|
$reference = array_pop($references); |
|
40
|
|
|
Assert::notNull($reference->getURI(), "URI attribute not found.", ReferenceValidationFailedException::class); |
|
41
|
|
|
Assert::validURI($reference->getURI(), ReferenceValidationFailedException::class); |
|
42
|
|
|
Assert::startsWith( |
|
43
|
|
|
$reference->getURI(), |
|
44
|
|
|
'#', |
|
45
|
|
|
"Reference must contain a same-document reference to the ID-attribute of the root element.", |
|
46
|
|
|
ReferenceValidationFailedException::class, |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$this->signature = $signature; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
public function getBlacklistedAlgorithms(): ?array |
|
54
|
|
|
{ |
|
55
|
|
|
$container = ContainerSingleton::getInstance(); |
|
56
|
|
|
return $container->getBlacklistedEncryptionAlgorithms(); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|