-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathCanonicalizableElementTrait.php
More file actions
75 lines (66 loc) · 2.58 KB
/
Copy pathCanonicalizableElementTrait.php
File metadata and controls
75 lines (66 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
declare(strict_types=1);
namespace SimpleSAML\SAML2\XML;
use Dom;
use SimpleSAML\XMLSecurity\Assert\Assert;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\Exception\CanonicalizationFailedException;
use SimpleSAML\XMLSecurity\Exception\ReferenceValidationFailedException;
use SimpleSAML\XMLSecurity\XML\CanonicalizableElementTrait as BaseCanonicalizableElementTrait;
use SimpleSAML\XMLSecurity\XML\ds\Transforms;
/**
* A trait implementing the CanonicalizableElementInterface.
*
* @package simplesamlphp/xml-security
*/
trait CanonicalizableElementTrait
{
use BaseCanonicalizableElementTrait;
/**
* Process all transforms specified by a given Reference element.
*
* @param \SimpleSAML\XMLSecurity\XML\ds\Transforms $transforms The transforms to apply.
* @param \Dom\Element $data The data referenced.
*
* @return string The canonicalized data after applying all transforms specified by $ref.
*
* @see http://www.w3.org/TR/xmldsig-core/#sec-ReferenceProcessingModel
*/
public function processTransforms(
Transforms $transforms,
Dom\Element $data,
): string {
Assert::maxCount(
$transforms->getTransform(),
C::MAX_TRANSFORMS,
ReferenceValidationFailedException::class,
'Too many transforms.',
);
$canonicalMethod = C::C14N_EXCLUSIVE_WITHOUT_COMMENTS;
$arXPath = null;
$prefixList = null;
foreach ($transforms->getTransform() as $transform) {
$canonicalMethod = $transform->getAlgorithm()->getValue();
switch ($canonicalMethod) {
case C::XMLDSIG_ENVELOPED:
break;
case C::C14N_EXCLUSIVE_WITHOUT_COMMENTS:
case C::C14N_EXCLUSIVE_WITH_COMMENTS:
$inclusiveNamespaces = $transform->getInclusiveNamespaces();
if ($inclusiveNamespaces !== null) {
$prefixes = $inclusiveNamespaces->getPrefixes();
if ($prefixes !== null) {
$prefixList = array_map('strval', $prefixes->toArray());
}
}
break;
default:
throw new CanonicalizationFailedException(sprintf(
'Message rejected due to unsupported canonicalization transform; %s',
$canonicalMethod,
));
}
}
return $this->canonicalizeData($data, $canonicalMethod, $arXPath, $prefixList);
}
}