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 b203434
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 55 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();
}
}
7 changes: 7 additions & 0 deletions src/SAML2/XML/SignedElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ protected function setSignature(Signature $signature): void

$this->signature = $signature;
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
return $container->getBlacklistedEncryptionAlgorithms();
}
}
14 changes: 3 additions & 11 deletions src/SAML2/XML/md/AbstractSignedMdElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 +57,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
9 changes: 1 addition & 8 deletions src/SAML2/XML/saml/AbstractBaseID.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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 +18,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 +147,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
14 changes: 5 additions & 9 deletions src/SAML2/XML/saml/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 +22,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 +40,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 +223,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
9 changes: 1 addition & 8 deletions src/SAML2/XML/saml/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
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 +112,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
9 changes: 1 addition & 8 deletions src/SAML2/XML/saml/NameID.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
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 +77,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
14 changes: 3 additions & 11 deletions src/SAML2/XML/samlp/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 +212,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 b203434

Please sign in to comment.