Skip to content

Commit da4ca3b

Browse files
committed
Rationalize algorithm blacklist code
1 parent 81681bb commit da4ca3b

9 files changed

Lines changed: 54 additions & 61 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2\XML;
6+
7+
use SimpleSAML\SAML2\Compat\ContainerSingleton;
8+
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait as ParentEncryptableElementTrait;
9+
10+
/**
11+
* Trait aggregating functionality for elements that are encrypted.
12+
*
13+
* @package simplesamlphp/saml2
14+
*/
15+
trait EncryptableElementTrait
16+
{
17+
use ParentEncryptableElementTrait;
18+
19+
20+
public function getBlacklistedAlgorithms(): ?array
21+
{
22+
$container = ContainerSingleton::getInstance();
23+
return $container->getBlacklistedEncryptionAlgorithms();
24+
}
25+
}

src/SAML2/XML/SignableElementTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,11 @@ protected function doSign(DOMElement $xml): DOMElement
122122
$this->signature = new Signature($signedInfo, new SignatureValue($signedData), $this->keyInfo);
123123
return DOMDocumentFactory::fromString($canonicalDocument)->documentElement;
124124
}
125+
126+
127+
public function getBlacklistedAlgorithms(): ?array
128+
{
129+
$container = ContainerSingleton::getInstance();
130+
return $container->getBlacklistedEncryptionAlgorithms();
131+
}
125132
}

src/SAML2/XML/SignedElementTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SimpleSAML\SAML2\XML;
66

77
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\SAML2\Compat\ContainerSingleton;
89
use SimpleSAML\XMLSecurity\Exception\ReferenceValidationFailedException;
910
use SimpleSAML\XMLSecurity\XML\ds\Signature;
1011
use SimpleSAML\XMLSecurity\XML\SignedElementTrait as BaseSignedElementTrait;
@@ -47,4 +48,11 @@ protected function setSignature(Signature $signature): void
4748

4849
$this->signature = $signature;
4950
}
51+
52+
53+
public function getBlacklistedAlgorithms(): ?array
54+
{
55+
$container = ContainerSingleton::getInstance();
56+
return $container->getBlacklistedEncryptionAlgorithms();
57+
}
5058
}

src/SAML2/XML/md/AbstractSignedMdElement.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace SimpleSAML\SAML2\XML\md;
66

77
use DOMElement;
8-
use SimpleSAML\SAML2\Compat\ContainerSingleton;
98
use SimpleSAML\SAML2\XML\SignableElementTrait;
109
use SimpleSAML\SAML2\XML\SignedElementTrait;
1110
use SimpleSAML\XMLSecurity\XML\SignableElementInterface;
@@ -23,7 +22,9 @@ abstract class AbstractSignedMdElement extends AbstractMdElement implements
2322
SignedElementInterface
2423
{
2524
use SignableElementTrait;
26-
use SignedElementTrait;
25+
use SignedElementTrait {
26+
SignedElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
27+
}
2728

2829
/**
2930
* The original signed XML
@@ -55,16 +56,6 @@ protected function setXML(DOMElement $xml): void
5556
}
5657

5758

58-
/**
59-
* @return array|null
60-
*/
61-
public function getBlacklistedAlgorithms(): ?array
62-
{
63-
$container = ContainerSingleton::getInstance();
64-
return $container->getBlacklistedEncryptionAlgorithms();
65-
}
66-
67-
6859
/**
6960
* @param \DOMElement|null $parent The EntityDescriptor we should append this SPSSODescriptor to.
7061
* @return \DOMElement

src/SAML2/XML/saml/AbstractBaseID.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
9-
use SimpleSAML\SAML2\Compat\ContainerSingleton;
109
use SimpleSAML\SAML2\Constants as C;
1110
use SimpleSAML\SAML2\Utils;
11+
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
1212
use SimpleSAML\SAML2\XML\ExtensionPointInterface;
1313
use SimpleSAML\SAML2\XML\ExtensionPointTrait;
1414
use SimpleSAML\XML\Attribute as XMLAttribute;
@@ -17,7 +17,6 @@
1717
use SimpleSAML\XML\Exception\SchemaViolationException;
1818
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
1919
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
20-
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
2120

2221
use function count;
2322
use function explode;
@@ -147,13 +146,6 @@ public function toXML(DOMElement $parent = null): DOMElement
147146
}
148147

149148

150-
public function getBlacklistedAlgorithms(): ?array
151-
{
152-
$container = ContainerSingleton::getInstance();
153-
return $container->getBlacklistedEncryptionAlgorithms();
154-
}
155-
156-
157149
public function getEncryptionBackend(): ?EncryptionBackend
158150
{
159151
// return the encryption backend you want to use,

src/SAML2/XML/saml/Assertion.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
use DOMElement;
99
use SimpleSAML\Assert\Assert;
1010
use SimpleSAML\SAML2\Assert\Assert as SAMLAssert;
11-
use SimpleSAML\SAML2\Compat\ContainerSingleton;
1211
use SimpleSAML\SAML2\Constants as C;
1312
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
1413
use SimpleSAML\SAML2\Utils\XPath;
14+
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
1515
use SimpleSAML\SAML2\XML\SignableElementTrait;
1616
use SimpleSAML\SAML2\XML\SignedElementTrait;
1717
use SimpleSAML\XML\Exception\InvalidDOMElementException;
@@ -21,7 +21,6 @@
2121
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
2222
use SimpleSAML\XMLSecurity\XML\ds\Signature;
2323
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
24-
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
2524
use SimpleSAML\XMLSecurity\XML\SignableElementInterface;
2625
use SimpleSAML\XMLSecurity\XML\SignedElementInterface;
2726

@@ -40,7 +39,10 @@ final class Assertion extends AbstractSamlElement implements
4039
SignableElementInterface,
4140
SignedElementInterface
4241
{
43-
use EncryptableElementTrait;
42+
use EncryptableElementTrait {
43+
EncryptableElementTrait::getBlacklistedAlgorithms insteadof SignedElementTrait;
44+
EncryptableElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
45+
}
4446
use SignableElementTrait;
4547
use SignedElementTrait;
4648

@@ -220,13 +222,6 @@ protected function getOriginalXML(): DOMElement
220222
}
221223

222224

223-
public function getBlacklistedAlgorithms(): ?array
224-
{
225-
$container = ContainerSingleton::getInstance();
226-
return $container->getBlacklistedEncryptionAlgorithms();
227-
}
228-
229-
230225
public function getEncryptionBackend(): ?EncryptionBackend
231226
{
232227
// return the encryption backend you want to use,

src/SAML2/XML/saml/Attribute.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
99
use SimpleSAML\SAML2\Assert\Assert as SAMLAssert;
10-
use SimpleSAML\SAML2\Compat\ContainerSingleton;
1110
use SimpleSAML\SAML2\Constants as C;
11+
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
1212
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1313
use SimpleSAML\XML\ExtendableAttributesTrait;
1414
use SimpleSAML\XML\XsNamespace as NS;
1515
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
1616
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
17-
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
1817

1918
/**
2019
* Class representing SAML 2 Attribute.
@@ -112,13 +111,6 @@ public function getAttributeValues(): array
112111
}
113112

114113

115-
public function getBlacklistedAlgorithms(): ?array
116-
{
117-
$container = ContainerSingleton::getInstance();
118-
return $container->getBlacklistedEncryptionAlgorithms();
119-
}
120-
121-
122114
public function getEncryptionBackend(): ?EncryptionBackend
123115
{
124116
// return the encryption backend you want to use,

src/SAML2/XML/saml/NameID.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
namespace SimpleSAML\SAML2\XML\saml;
66

77
use SimpleSAML\Assert\Assert;
8-
use SimpleSAML\SAML2\Compat\ContainerSingleton;
98
use SimpleSAML\SAML2\Constants as C;
109
use SimpleSAML\SAML2\Exception\ArrayValidationException;
10+
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
1111
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
1212
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
13-
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
1413

1514
use function array_change_key_case;
1615
use function array_filter;
@@ -77,13 +76,6 @@ public function __construct(
7776
}
7877

7978

80-
public function getBlacklistedAlgorithms(): ?array
81-
{
82-
$container = ContainerSingleton::getInstance();
83-
return $container->getBlacklistedEncryptionAlgorithms();
84-
}
85-
86-
8779
public function getEncryptionBackend(): ?EncryptionBackend
8880
{
8981
// return the encryption backend you want to use,

src/SAML2/XML/samlp/AbstractMessage.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use DOMElement;
1010
use SimpleSAML\Assert\Assert;
1111
use SimpleSAML\SAML2\Assert\Assert as SAMLAssert;
12-
use SimpleSAML\SAML2\Compat\ContainerSingleton;
1312
use SimpleSAML\SAML2\Constants as C;
1413
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
1514
use SimpleSAML\SAML2\Utils;
@@ -36,7 +35,9 @@ abstract class AbstractMessage extends AbstractSamlpElement implements SignableE
3635
{
3736
use ExtendableElementTrait;
3837
use SignableElementTrait;
39-
use SignedElementTrait;
38+
use SignedElementTrait {
39+
SignedElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
40+
}
4041

4142

4243
/**
@@ -210,16 +211,6 @@ protected function getOriginalXML(): DOMElement
210211
}
211212

212213

213-
/**
214-
* @return string[]|null
215-
*/
216-
public function getBlacklistedAlgorithms(): ?array
217-
{
218-
$container = ContainerSingleton::getInstance();
219-
return $container->getBlacklistedEncryptionAlgorithms();
220-
}
221-
222-
223214
/**
224215
* Convert this message to an unsigned XML document.
225216
* This method does not sign the resulting XML document.

0 commit comments

Comments
 (0)