Skip to content

Commit

Permalink
Rationalize algorithm blacklist code
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jul 29, 2024
1 parent 81681bb commit da4ca3b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 61 deletions.
25 changes: 25 additions & 0 deletions src/SAML2/XML/EncryptableElementTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML2\XML;

use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait as ParentEncryptableElementTrait;

/**
* Trait aggregating functionality for elements that are encrypted.
*
* @package simplesamlphp/saml2
*/
trait EncryptableElementTrait
{
use ParentEncryptableElementTrait;


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}
}
7 changes: 7 additions & 0 deletions src/SAML2/XML/SignableElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,11 @@ protected function doSign(DOMElement $xml): DOMElement
$this->signature = new Signature($signedInfo, new SignatureValue($signedData), $this->keyInfo);
return DOMDocumentFactory::fromString($canonicalDocument)->documentElement;
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}
}
8 changes: 8 additions & 0 deletions src/SAML2/XML/SignedElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SimpleSAML\SAML2\XML;

use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\XMLSecurity\Exception\ReferenceValidationFailedException;
use SimpleSAML\XMLSecurity\XML\ds\Signature;
use SimpleSAML\XMLSecurity\XML\SignedElementTrait as BaseSignedElementTrait;
Expand Down Expand Up @@ -47,4 +48,11 @@ protected function setSignature(Signature $signature): void

$this->signature = $signature;
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}
}
15 changes: 3 additions & 12 deletions src/SAML2/XML/md/AbstractSignedMdElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace SimpleSAML\SAML2\XML\md;

use DOMElement;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\XML\SignableElementTrait;
use SimpleSAML\SAML2\XML\SignedElementTrait;
use SimpleSAML\XMLSecurity\XML\SignableElementInterface;
Expand All @@ -23,7 +22,9 @@ abstract class AbstractSignedMdElement extends AbstractMdElement implements
SignedElementInterface
{
use SignableElementTrait;
use SignedElementTrait;
use SignedElementTrait {
SignedElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
}

/**
* The original signed XML
Expand Down Expand Up @@ -55,16 +56,6 @@ protected function setXML(DOMElement $xml): void
}


/**
* @return array|null
*/
public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}


/**
* @param \DOMElement|null $parent The EntityDescriptor we should append this SPSSODescriptor to.
* @return \DOMElement
Expand Down
10 changes: 1 addition & 9 deletions src/SAML2/XML/saml/AbstractBaseID.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\Utils;
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
use SimpleSAML\SAML2\XML\ExtensionPointInterface;
use SimpleSAML\SAML2\XML\ExtensionPointTrait;
use SimpleSAML\XML\Attribute as XMLAttribute;
Expand All @@ -17,7 +17,6 @@
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;

use function count;
use function explode;
Expand Down Expand Up @@ -147,13 +146,6 @@ public function toXML(DOMElement $parent = null): DOMElement
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}


public function getEncryptionBackend(): ?EncryptionBackend
{
// return the encryption backend you want to use,
Expand Down
15 changes: 5 additions & 10 deletions src/SAML2/XML/saml/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Assert\Assert as SAMLAssert;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
use SimpleSAML\SAML2\Utils\XPath;
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
use SimpleSAML\SAML2\XML\SignableElementTrait;
use SimpleSAML\SAML2\XML\SignedElementTrait;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
Expand All @@ -21,7 +21,6 @@
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
use SimpleSAML\XMLSecurity\XML\ds\Signature;
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
use SimpleSAML\XMLSecurity\XML\SignableElementInterface;
use SimpleSAML\XMLSecurity\XML\SignedElementInterface;

Expand All @@ -40,7 +39,10 @@ final class Assertion extends AbstractSamlElement implements
SignableElementInterface,
SignedElementInterface
{
use EncryptableElementTrait;
use EncryptableElementTrait {
EncryptableElementTrait::getBlacklistedAlgorithms insteadof SignedElementTrait;
EncryptableElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
}
use SignableElementTrait;
use SignedElementTrait;

Expand Down Expand Up @@ -220,13 +222,6 @@ protected function getOriginalXML(): DOMElement
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}


public function getEncryptionBackend(): ?EncryptionBackend
{
// return the encryption backend you want to use,
Expand Down
10 changes: 1 addition & 9 deletions src/SAML2/XML/saml/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Assert\Assert as SAMLAssert;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\XsNamespace as NS;
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;

/**
* Class representing SAML 2 Attribute.
Expand Down Expand Up @@ -112,13 +111,6 @@ public function getAttributeValues(): array
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}


public function getEncryptionBackend(): ?EncryptionBackend
{
// return the encryption backend you want to use,
Expand Down
10 changes: 1 addition & 9 deletions src/SAML2/XML/saml/NameID.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
namespace SimpleSAML\SAML2\XML\saml;

use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\Exception\ArrayValidationException;
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;

use function array_change_key_case;
use function array_filter;
Expand Down Expand Up @@ -77,13 +76,6 @@ public function __construct(
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}


public function getEncryptionBackend(): ?EncryptionBackend
{
// return the encryption backend you want to use,
Expand Down
15 changes: 3 additions & 12 deletions src/SAML2/XML/samlp/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Assert\Assert as SAMLAssert;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
use SimpleSAML\SAML2\Utils;
Expand All @@ -36,7 +35,9 @@ abstract class AbstractMessage extends AbstractSamlpElement implements SignableE
{
use ExtendableElementTrait;
use SignableElementTrait;
use SignedElementTrait;
use SignedElementTrait {
SignedElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
}


/**
Expand Down Expand Up @@ -210,16 +211,6 @@ protected function getOriginalXML(): DOMElement
}


/**
* @return string[]|null
*/
public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}


/**
* Convert this message to an unsigned XML document.
* This method does not sign the resulting XML document.
Expand Down

0 comments on commit da4ca3b

Please sign in to comment.