From 46c6abbda8e020b86f8156cec2fdc6b5f7275612 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 3 Jun 2025 23:55:08 +0200 Subject: [PATCH 01/30] Add dsig11:DEREncodedKeyValue --- src/Constants.php | 3 + src/XML/ds/AbstractKeyInfoType.php | 12 ++- src/XML/ds/KeyInfo.php | 6 +- src/XML/dsig11/DEREncodedKeyValue.php | 91 +++++++++++++++++++ src/XML/element.registry.php | 2 +- tests/XML/dsig11/DEREncodedKeyValueTest.php | 60 ++++++++++++ .../xml/dsig11_DEREncodedKeyValue.xml | 1 + 7 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 src/XML/dsig11/DEREncodedKeyValue.php create mode 100644 tests/XML/dsig11/DEREncodedKeyValueTest.php create mode 100644 tests/resources/xml/dsig11_DEREncodedKeyValue.xml diff --git a/src/Constants.php b/src/Constants.php index 402d43e5..0e0565b4 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -144,9 +144,12 @@ class Constants extends \SimpleSAML\XML\Constants */ public const NS_XDSIG = 'http://www.w3.org/2000/09/xmldsig#'; public const NS_XDSIG11 = 'http://www.w3.org/2009/xmldsig11#'; + public const XMLDSIG_ENVELOPED = 'http://www.w3.org/2000/09/xmldsig#enveloped-signature'; public const XMLDSIG_MANIFEST = 'http://www.w3.org/2000/09/xmldsig#Manifest'; + public const XMLDSIG11_DER_ENCODED_KEY_VALUE = 'https://www.w3.org/2009/xmldsig11#DEREncodedKeyValue'; + public const NS_XENC = 'http://www.w3.org/2001/04/xmlenc#'; public const NS_XENC11 = 'http://www.w3.org/2009/xmlenc11#'; public const XMLENC_CONTENT = 'http://www.w3.org/2001/04/xmlenc#Content'; diff --git a/src/XML/ds/AbstractKeyInfoType.php b/src/XML/ds/AbstractKeyInfoType.php index dadff6fc..205869ac 100644 --- a/src/XML/ds/AbstractKeyInfoType.php +++ b/src/XML/ds/AbstractKeyInfoType.php @@ -12,7 +12,8 @@ use SimpleSAML\XMLSecurity\Assert\Assert; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; +use SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element; +use SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue; /** * Abstract class representing the KeyInfoType. @@ -38,6 +39,7 @@ abstract class AbstractKeyInfoType extends AbstractDsElement * \SimpleSAML\XMLSecurity\XML\ds\PGPData| * \SimpleSAML\XMLSecurity\XML\ds\SPKIData| * \SimpleSAML\XMLSecurity\XML\ds\MgmtData| + * \SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue| * \SimpleSAML\XML\SerializableElementInterface * )[] $info * @param string|null $Id @@ -78,6 +80,14 @@ final public function __construct( ], SchemaViolationException::class, ); + } elseif ($item instanceof AbstractDsig11Element) { + Assert::isInstanceOfAny( + $item, + [ + DEREncodedKeyValue::class, + ], + SchemaViolationException::class, + ); } } } diff --git a/src/XML/ds/KeyInfo.php b/src/XML/ds/KeyInfo.php index 01cb7c13..b64ecd0c 100644 --- a/src/XML/ds/KeyInfo.php +++ b/src/XML/ds/KeyInfo.php @@ -7,8 +7,8 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue; use function array_merge; @@ -44,6 +44,7 @@ public static function fromXML(DOMElement $xml): static $pgpData = PGPData::getChildrenOfClass($xml); $spkiData = SPKIData::getChildrenOfClass($xml); $mgmtData = MgmtData::getChildrenOfClass($xml); + $derEncodedKeyValue = DEREncodedKeyValue::getChildrenOfClass($xml); $other = self::getChildElementsFromXML($xml); $info = array_merge( @@ -54,6 +55,7 @@ public static function fromXML(DOMElement $xml): static $pgpData, $spkiData, $mgmtData, + $derEncodedKeyValue, $other, ); diff --git a/src/XML/dsig11/DEREncodedKeyValue.php b/src/XML/dsig11/DEREncodedKeyValue.php new file mode 100644 index 00000000..f3bbe1c2 --- /dev/null +++ b/src/XML/dsig11/DEREncodedKeyValue.php @@ -0,0 +1,91 @@ +setContent($value); + } + + + /** + * Collect the value of the Id-property + * + * @return string|null + */ + public function getId(): ?string + { + return $this->Id; + } + + + /** + * Convert XML into a DEREncodedKeyValue + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + return new static( + $xml->textContent, + self::getOptionalAttribute($xml, 'Id', null), + ); + } + + + /** + * Convert this DEREncodedKeyValue element to XML. + * + * @param \DOMElement|null $parent The element we should append this DEREncodedKeyValue element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = $this->getContent(); + + if ($this->getId() !== null) { + $e->setAttribute('Id', $this->getId()); + } + + return $e; + } +} diff --git a/src/XML/element.registry.php b/src/XML/element.registry.php index 82e5b59d..495adbd6 100644 --- a/src/XML/element.registry.php +++ b/src/XML/element.registry.php @@ -30,7 +30,7 @@ 'X509Data' => '\SimpleSAML\XMLSecurity\XML\ds\X509Data', ], 'http://www.w3.org/2009/xmldsig11#' => [ -// 'DEREncodedKeyValue' => '\SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue', + 'DEREncodedKeyValue' => '\SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue', // 'ECKeyValue' => '\SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue', // 'GnB' => '\SimpleSAML\XMLSecurity\XML\dsig11\GnB', 'KeyInfoReference' => '\SimpleSAML\XMLSecurity\XML\dsig11\KeyInfoReference', diff --git a/tests/XML/dsig11/DEREncodedKeyValueTest.php b/tests/XML/dsig11/DEREncodedKeyValueTest.php new file mode 100644 index 00000000..2a5d260f --- /dev/null +++ b/tests/XML/dsig11/DEREncodedKeyValueTest.php @@ -0,0 +1,60 @@ +assertEquals( + XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), + strval($derEncodedKeyValue), + ); + } +} diff --git a/tests/resources/xml/dsig11_DEREncodedKeyValue.xml b/tests/resources/xml/dsig11_DEREncodedKeyValue.xml new file mode 100644 index 00000000..b3da335d --- /dev/null +++ b/tests/resources/xml/dsig11_DEREncodedKeyValue.xml @@ -0,0 +1 @@ +MGYwHwYIKoUDBwEBAQEwEwYHKoUDAgIkAAYIKoUDBwEBAgIDQwAEQLrf0MNTFKvSj6pHRwtsQBdyu07oB36PZ+duQ9rOZhWXQ+acH/dP4uLxdJhZq/Z30cDGD+KND4NZjp+UZWlzWK0= From 90b1e4d9c45e7415b51c97a6292f40765945a66f Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Wed, 4 Jun 2025 08:49:22 +0200 Subject: [PATCH 02/30] Add dsig11:P --- src/XML/dsig11/P.php | 29 +++++++++++++++++ tests/XML/dsig11/PTest.php | 53 ++++++++++++++++++++++++++++++++ tests/resources/xml/dsig11_P.xml | 1 + 3 files changed, 83 insertions(+) create mode 100644 src/XML/dsig11/P.php create mode 100644 tests/XML/dsig11/PTest.php create mode 100644 tests/resources/xml/dsig11_P.xml diff --git a/src/XML/dsig11/P.php b/src/XML/dsig11/P.php new file mode 100644 index 00000000..ea807ea2 --- /dev/null +++ b/src/XML/dsig11/P.php @@ -0,0 +1,29 @@ +setContent($value); + } +} diff --git a/tests/XML/dsig11/PTest.php b/tests/XML/dsig11/PTest.php new file mode 100644 index 00000000..e8d6ff34 --- /dev/null +++ b/tests/XML/dsig11/PTest.php @@ -0,0 +1,53 @@ +assertEquals( + XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), + strval($p), + ); + } +} diff --git a/tests/resources/xml/dsig11_P.xml b/tests/resources/xml/dsig11_P.xml new file mode 100644 index 00000000..46e2f189 --- /dev/null +++ b/tests/resources/xml/dsig11_P.xml @@ -0,0 +1 @@ +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= From 5dd916276003b7a5891e8190aeb1471e65e978f3 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Wed, 4 Jun 2025 08:57:35 +0200 Subject: [PATCH 03/30] Add dsig11:A-element --- src/XML/dsig11/A.php | 29 +++++++++++++++++ tests/XML/dsig11/ATest.php | 53 ++++++++++++++++++++++++++++++++ tests/resources/xml/dsig11_A.xml | 1 + 3 files changed, 83 insertions(+) create mode 100644 src/XML/dsig11/A.php create mode 100644 tests/XML/dsig11/ATest.php create mode 100644 tests/resources/xml/dsig11_A.xml diff --git a/src/XML/dsig11/A.php b/src/XML/dsig11/A.php new file mode 100644 index 00000000..19957519 --- /dev/null +++ b/src/XML/dsig11/A.php @@ -0,0 +1,29 @@ +setContent($value); + } +} diff --git a/tests/XML/dsig11/ATest.php b/tests/XML/dsig11/ATest.php new file mode 100644 index 00000000..b8f68c03 --- /dev/null +++ b/tests/XML/dsig11/ATest.php @@ -0,0 +1,53 @@ +assertEquals( + XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), + strval($a), + ); + } +} diff --git a/tests/resources/xml/dsig11_A.xml b/tests/resources/xml/dsig11_A.xml new file mode 100644 index 00000000..c288036c --- /dev/null +++ b/tests/resources/xml/dsig11_A.xml @@ -0,0 +1 @@ +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= From 2defdd115ecba1fab02ec0708d901b0826a88723 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Wed, 4 Jun 2025 08:57:57 +0200 Subject: [PATCH 04/30] Add dsig11:B-element --- src/XML/dsig11/B.php | 29 +++++++++++++++++ tests/XML/dsig11/BTest.php | 53 ++++++++++++++++++++++++++++++++ tests/resources/xml/dsig11_B.xml | 1 + 3 files changed, 83 insertions(+) create mode 100644 src/XML/dsig11/B.php create mode 100644 tests/XML/dsig11/BTest.php create mode 100644 tests/resources/xml/dsig11_B.xml diff --git a/src/XML/dsig11/B.php b/src/XML/dsig11/B.php new file mode 100644 index 00000000..38c39c4e --- /dev/null +++ b/src/XML/dsig11/B.php @@ -0,0 +1,29 @@ +setContent($value); + } +} diff --git a/tests/XML/dsig11/BTest.php b/tests/XML/dsig11/BTest.php new file mode 100644 index 00000000..5d5374e8 --- /dev/null +++ b/tests/XML/dsig11/BTest.php @@ -0,0 +1,53 @@ +assertEquals( + XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), + strval($b), + ); + } +} diff --git a/tests/resources/xml/dsig11_B.xml b/tests/resources/xml/dsig11_B.xml new file mode 100644 index 00000000..33b7cc61 --- /dev/null +++ b/tests/resources/xml/dsig11_B.xml @@ -0,0 +1 @@ +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= From f5d3678f5d5591d4b3980f77fedfcc48bec796fe Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Wed, 4 Jun 2025 23:30:42 +0200 Subject: [PATCH 05/30] Add dsig11:Prime-element --- .../dsig11/AbstractPrimeFieldParamsType.php | 51 ++++++++++++++++ src/XML/dsig11/Prime.php | 48 +++++++++++++++ tests/XML/dsig11/PrimeTest.php | 59 +++++++++++++++++++ tests/resources/xml/dsig11_Prime.xml | 3 + 4 files changed, 161 insertions(+) create mode 100644 src/XML/dsig11/AbstractPrimeFieldParamsType.php create mode 100644 src/XML/dsig11/Prime.php create mode 100644 tests/XML/dsig11/PrimeTest.php create mode 100644 tests/resources/xml/dsig11_Prime.xml diff --git a/src/XML/dsig11/AbstractPrimeFieldParamsType.php b/src/XML/dsig11/AbstractPrimeFieldParamsType.php new file mode 100644 index 00000000..8a1ac69b --- /dev/null +++ b/src/XML/dsig11/AbstractPrimeFieldParamsType.php @@ -0,0 +1,51 @@ +p; + } + + + /** + * Convert this PrimeFieldParamsType element to XML. + * + * @param \DOMElement|null $parent The element we should append this PrimeFieldParamsType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $this->getP()->toXML($e); + + return $e; + } +} diff --git a/src/XML/dsig11/Prime.php b/src/XML/dsig11/Prime.php new file mode 100644 index 00000000..ec5b0af0 --- /dev/null +++ b/src/XML/dsig11/Prime.php @@ -0,0 +1,48 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $p = P::getChildrenOfClass($xml); + Assert::minCount($p, 1, MissingElementException::class); + Assert::maxCount($p, 1, TooManyElementsException::class); + + return new static( + array_pop($p), + ); + } +} diff --git a/tests/XML/dsig11/PrimeTest.php b/tests/XML/dsig11/PrimeTest.php new file mode 100644 index 00000000..8658daa0 --- /dev/null +++ b/tests/XML/dsig11/PrimeTest.php @@ -0,0 +1,59 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($prime), + ); + } +} diff --git a/tests/resources/xml/dsig11_Prime.xml b/tests/resources/xml/dsig11_Prime.xml new file mode 100644 index 00000000..f9f8ef69 --- /dev/null +++ b/tests/resources/xml/dsig11_Prime.xml @@ -0,0 +1,3 @@ + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + From a4353f0c8ffef0bf0e9e171a422b95b26577e801 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 5 Jun 2025 00:17:34 +0200 Subject: [PATCH 06/30] Add Seed-element --- src/XML/dsig11/Seed.php | 29 ++++++++++++++++ tests/XML/dsig11/SeedTest.php | 53 +++++++++++++++++++++++++++++ tests/resources/xml/dsig11_Seed.xml | 1 + 3 files changed, 83 insertions(+) create mode 100644 src/XML/dsig11/Seed.php create mode 100644 tests/XML/dsig11/SeedTest.php create mode 100644 tests/resources/xml/dsig11_Seed.xml diff --git a/src/XML/dsig11/Seed.php b/src/XML/dsig11/Seed.php new file mode 100644 index 00000000..b1f51a38 --- /dev/null +++ b/src/XML/dsig11/Seed.php @@ -0,0 +1,29 @@ +setContent($value); + } +} diff --git a/tests/XML/dsig11/SeedTest.php b/tests/XML/dsig11/SeedTest.php new file mode 100644 index 00000000..28c13f01 --- /dev/null +++ b/tests/XML/dsig11/SeedTest.php @@ -0,0 +1,53 @@ +assertEquals( + XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), + strval($seed), + ); + } +} diff --git a/tests/resources/xml/dsig11_Seed.xml b/tests/resources/xml/dsig11_Seed.xml new file mode 100644 index 00000000..c6c2f9a7 --- /dev/null +++ b/tests/resources/xml/dsig11_Seed.xml @@ -0,0 +1 @@ +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= From aa3fc5e3cc86df11b9c8149d2761e616107bf14c Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 5 Jun 2025 00:22:58 +0200 Subject: [PATCH 07/30] Add dsig11:Order-element --- src/XML/dsig11/Order.php | 29 +++++++++++++++ tests/XML/dsig11/OrderTest.php | 53 ++++++++++++++++++++++++++++ tests/resources/xml/dsig11_Order.xml | 1 + 3 files changed, 83 insertions(+) create mode 100644 src/XML/dsig11/Order.php create mode 100644 tests/XML/dsig11/OrderTest.php create mode 100644 tests/resources/xml/dsig11_Order.xml diff --git a/src/XML/dsig11/Order.php b/src/XML/dsig11/Order.php new file mode 100644 index 00000000..d803acec --- /dev/null +++ b/src/XML/dsig11/Order.php @@ -0,0 +1,29 @@ +setContent($value); + } +} diff --git a/tests/XML/dsig11/OrderTest.php b/tests/XML/dsig11/OrderTest.php new file mode 100644 index 00000000..89a21600 --- /dev/null +++ b/tests/XML/dsig11/OrderTest.php @@ -0,0 +1,53 @@ +assertEquals( + XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), + strval($order), + ); + } +} diff --git a/tests/resources/xml/dsig11_Order.xml b/tests/resources/xml/dsig11_Order.xml new file mode 100644 index 00000000..503de2c8 --- /dev/null +++ b/tests/resources/xml/dsig11_Order.xml @@ -0,0 +1 @@ +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= From bf5fa29dee284a98e2703bf87aaca59b34019575 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 5 Jun 2025 20:22:59 +0200 Subject: [PATCH 08/30] Add K1-element --- src/XML/dsig11/K1.php | 70 +++++++++++++++++++++++++++++++ tests/XML/dsig11/K1Test.php | 52 +++++++++++++++++++++++ tests/resources/xml/dsig11_K1.xml | 1 + 3 files changed, 123 insertions(+) create mode 100644 src/XML/dsig11/K1.php create mode 100644 tests/XML/dsig11/K1Test.php create mode 100644 tests/resources/xml/dsig11_K1.xml diff --git a/src/XML/dsig11/K1.php b/src/XML/dsig11/K1.php new file mode 100644 index 00000000..fa454e11 --- /dev/null +++ b/src/XML/dsig11/K1.php @@ -0,0 +1,70 @@ +k1; + } + + + /** + * Convert XML into a class instance + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + Assert::numeric($xml->textContent); + + return new static(intval($xml->textContent)); + } + + + /** + * Convert this element to XML. + * + * @param \DOMElement|null $parent The element we should append this element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = strval($this->getK1()); + + return $e; + } +} diff --git a/tests/XML/dsig11/K1Test.php b/tests/XML/dsig11/K1Test.php new file mode 100644 index 00000000..374f778f --- /dev/null +++ b/tests/XML/dsig11/K1Test.php @@ -0,0 +1,52 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($k1), + ); + } +} diff --git a/tests/resources/xml/dsig11_K1.xml b/tests/resources/xml/dsig11_K1.xml new file mode 100644 index 00000000..20234633 --- /dev/null +++ b/tests/resources/xml/dsig11_K1.xml @@ -0,0 +1 @@ +128 From 46d6292be00ebfcb7d639739757f5638b4206b9d Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 5 Jun 2025 22:44:31 +0200 Subject: [PATCH 09/30] Add K2-element --- src/XML/dsig11/K2.php | 70 +++++++++++++++++++++++++++++++ tests/XML/dsig11/K2Test.php | 52 +++++++++++++++++++++++ tests/resources/xml/dsig11_K2.xml | 1 + 3 files changed, 123 insertions(+) create mode 100644 src/XML/dsig11/K2.php create mode 100644 tests/XML/dsig11/K2Test.php create mode 100644 tests/resources/xml/dsig11_K2.xml diff --git a/src/XML/dsig11/K2.php b/src/XML/dsig11/K2.php new file mode 100644 index 00000000..dc322df2 --- /dev/null +++ b/src/XML/dsig11/K2.php @@ -0,0 +1,70 @@ +k2; + } + + + /** + * Convert XML into a class instance + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + Assert::numeric($xml->textContent); + + return new static(intval($xml->textContent)); + } + + + /** + * Convert this element to XML. + * + * @param \DOMElement|null $parent The element we should append this element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = strval($this->getK2()); + + return $e; + } +} diff --git a/tests/XML/dsig11/K2Test.php b/tests/XML/dsig11/K2Test.php new file mode 100644 index 00000000..9a164636 --- /dev/null +++ b/tests/XML/dsig11/K2Test.php @@ -0,0 +1,52 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($k2), + ); + } +} diff --git a/tests/resources/xml/dsig11_K2.xml b/tests/resources/xml/dsig11_K2.xml new file mode 100644 index 00000000..4b91babf --- /dev/null +++ b/tests/resources/xml/dsig11_K2.xml @@ -0,0 +1 @@ +256 From f7031c271220ce77c6a380a1a02b3473b5040c3b Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 5 Jun 2025 22:46:46 +0200 Subject: [PATCH 10/30] Add K3-element --- src/XML/dsig11/K3.php | 70 +++++++++++++++++++++++++++++++ tests/XML/dsig11/K3Test.php | 52 +++++++++++++++++++++++ tests/resources/xml/dsig11_K3.xml | 1 + 3 files changed, 123 insertions(+) create mode 100644 src/XML/dsig11/K3.php create mode 100644 tests/XML/dsig11/K3Test.php create mode 100644 tests/resources/xml/dsig11_K3.xml diff --git a/src/XML/dsig11/K3.php b/src/XML/dsig11/K3.php new file mode 100644 index 00000000..0af4b99e --- /dev/null +++ b/src/XML/dsig11/K3.php @@ -0,0 +1,70 @@ +k3; + } + + + /** + * Convert XML into a class instance + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + Assert::numeric($xml->textContent); + + return new static(intval($xml->textContent)); + } + + + /** + * Convert this element to XML. + * + * @param \DOMElement|null $parent The element we should append this element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = strval($this->getK3()); + + return $e; + } +} diff --git a/tests/XML/dsig11/K3Test.php b/tests/XML/dsig11/K3Test.php new file mode 100644 index 00000000..90f05962 --- /dev/null +++ b/tests/XML/dsig11/K3Test.php @@ -0,0 +1,52 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($k3), + ); + } +} diff --git a/tests/resources/xml/dsig11_K3.xml b/tests/resources/xml/dsig11_K3.xml new file mode 100644 index 00000000..f3864abd --- /dev/null +++ b/tests/resources/xml/dsig11_K3.xml @@ -0,0 +1 @@ +512 From fd2b2338ee5b6b0f989315572cfdc12075c83f14 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 5 Jun 2025 22:49:07 +0200 Subject: [PATCH 11/30] Add K-element --- src/XML/dsig11/K.php | 70 ++++++++++++++++++++++++++++++++ tests/XML/dsig11/KTest.php | 52 ++++++++++++++++++++++++ tests/resources/xml/dsig11_K.xml | 1 + 3 files changed, 123 insertions(+) create mode 100644 src/XML/dsig11/K.php create mode 100644 tests/XML/dsig11/KTest.php create mode 100644 tests/resources/xml/dsig11_K.xml diff --git a/src/XML/dsig11/K.php b/src/XML/dsig11/K.php new file mode 100644 index 00000000..038ffd25 --- /dev/null +++ b/src/XML/dsig11/K.php @@ -0,0 +1,70 @@ +k; + } + + + /** + * Convert XML into a class instance + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + Assert::numeric($xml->textContent); + + return new static(intval($xml->textContent)); + } + + + /** + * Convert this element to XML. + * + * @param \DOMElement|null $parent The element we should append this element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = strval($this->getK()); + + return $e; + } +} diff --git a/tests/XML/dsig11/KTest.php b/tests/XML/dsig11/KTest.php new file mode 100644 index 00000000..a92700ed --- /dev/null +++ b/tests/XML/dsig11/KTest.php @@ -0,0 +1,52 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($k), + ); + } +} diff --git a/tests/resources/xml/dsig11_K.xml b/tests/resources/xml/dsig11_K.xml new file mode 100644 index 00000000..46398e80 --- /dev/null +++ b/tests/resources/xml/dsig11_K.xml @@ -0,0 +1 @@ +64 From 1c78a6d0fe79f257482418e379621c8dc1c9ff59 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 5 Jun 2025 22:51:27 +0200 Subject: [PATCH 12/30] Add M-element --- src/XML/dsig11/M.php | 70 ++++++++++++++++++++++++++++++++ tests/XML/dsig11/MTest.php | 52 ++++++++++++++++++++++++ tests/resources/xml/dsig11_M.xml | 1 + 3 files changed, 123 insertions(+) create mode 100644 src/XML/dsig11/M.php create mode 100644 tests/XML/dsig11/MTest.php create mode 100644 tests/resources/xml/dsig11_M.xml diff --git a/src/XML/dsig11/M.php b/src/XML/dsig11/M.php new file mode 100644 index 00000000..2f4e90a1 --- /dev/null +++ b/src/XML/dsig11/M.php @@ -0,0 +1,70 @@ +m; + } + + + /** + * Convert XML into a class instance + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + Assert::numeric($xml->textContent); + + return new static(intval($xml->textContent)); + } + + + /** + * Convert this element to XML. + * + * @param \DOMElement|null $parent The element we should append this element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = strval($this->getM()); + + return $e; + } +} diff --git a/tests/XML/dsig11/MTest.php b/tests/XML/dsig11/MTest.php new file mode 100644 index 00000000..255537d2 --- /dev/null +++ b/tests/XML/dsig11/MTest.php @@ -0,0 +1,52 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($m), + ); + } +} diff --git a/tests/resources/xml/dsig11_M.xml b/tests/resources/xml/dsig11_M.xml new file mode 100644 index 00000000..3210f1e2 --- /dev/null +++ b/tests/resources/xml/dsig11_M.xml @@ -0,0 +1 @@ +1024 From c4569bbfa8e88117c2b3cd51f315c615dbb83eb5 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 8 Jun 2025 21:34:06 +0200 Subject: [PATCH 13/30] Add dsig11:GnB-element --- .../dsig11/AbstractCharTwoFieldParamsType.php | 51 ++++++++++++++++ src/XML/dsig11/GnB.php | 48 +++++++++++++++ tests/XML/dsig11/GnBTest.php | 59 +++++++++++++++++++ tests/resources/xml/dsig11_GnB.xml | 3 + 4 files changed, 161 insertions(+) create mode 100644 src/XML/dsig11/AbstractCharTwoFieldParamsType.php create mode 100644 src/XML/dsig11/GnB.php create mode 100644 tests/XML/dsig11/GnBTest.php create mode 100644 tests/resources/xml/dsig11_GnB.xml diff --git a/src/XML/dsig11/AbstractCharTwoFieldParamsType.php b/src/XML/dsig11/AbstractCharTwoFieldParamsType.php new file mode 100644 index 00000000..cb3edacb --- /dev/null +++ b/src/XML/dsig11/AbstractCharTwoFieldParamsType.php @@ -0,0 +1,51 @@ +m; + } + + + /** + * Convert this CharTwoFieldParamsType element to XML. + * + * @param \DOMElement|null $parent The element we should append this CharTwoFieldParamsType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $this->getM()->toXML($e); + + return $e; + } +} diff --git a/src/XML/dsig11/GnB.php b/src/XML/dsig11/GnB.php new file mode 100644 index 00000000..196fe47e --- /dev/null +++ b/src/XML/dsig11/GnB.php @@ -0,0 +1,48 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $m = M::getChildrenOfClass($xml); + Assert::minCount($m, 1, MissingElementException::class); + Assert::maxCount($m, 1, TooManyElementsException::class); + + return new static( + array_pop($m), + ); + } +} diff --git a/tests/XML/dsig11/GnBTest.php b/tests/XML/dsig11/GnBTest.php new file mode 100644 index 00000000..347beaf3 --- /dev/null +++ b/tests/XML/dsig11/GnBTest.php @@ -0,0 +1,59 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($gnb), + ); + } +} diff --git a/tests/resources/xml/dsig11_GnB.xml b/tests/resources/xml/dsig11_GnB.xml new file mode 100644 index 00000000..251e9b9a --- /dev/null +++ b/tests/resources/xml/dsig11_GnB.xml @@ -0,0 +1,3 @@ + + 1024 + From 87390d1109fe9d0e5e757757887a0be7dd85db96 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 8 Jun 2025 21:58:05 +0200 Subject: [PATCH 14/30] Add dsig11:TnB-element --- src/XML/dsig11/AbstractTnBFieldParamsType.php | 54 +++++++++++++ src/XML/dsig11/TnB.php | 53 ++++++++++++ tests/XML/dsig11/TnBTest.php | 81 +++++++++++++++++++ tests/resources/xml/dsig11_TnB.xml | 4 + 4 files changed, 192 insertions(+) create mode 100644 src/XML/dsig11/AbstractTnBFieldParamsType.php create mode 100644 src/XML/dsig11/TnB.php create mode 100644 tests/XML/dsig11/TnBTest.php create mode 100644 tests/resources/xml/dsig11_TnB.xml diff --git a/src/XML/dsig11/AbstractTnBFieldParamsType.php b/src/XML/dsig11/AbstractTnBFieldParamsType.php new file mode 100644 index 00000000..11171478 --- /dev/null +++ b/src/XML/dsig11/AbstractTnBFieldParamsType.php @@ -0,0 +1,54 @@ +k; + } + + + /** + * Convert this TnBFieldParamsType element to XML. + * + * @param \DOMElement|null $parent The element we should append this TnBFieldParamsType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = parent::toXML($parent); + $this->getK()->toXML($e); + + return $e; + } +} diff --git a/src/XML/dsig11/TnB.php b/src/XML/dsig11/TnB.php new file mode 100644 index 00000000..7f4b2e9c --- /dev/null +++ b/src/XML/dsig11/TnB.php @@ -0,0 +1,53 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $k = K::getChildrenOfClass($xml); + Assert::minCount($k, 1, MissingElementException::class); + Assert::maxCount($k, 1, TooManyElementsException::class); + + $m = M::getChildrenOfClass($xml); + Assert::minCount($m, 1, MissingElementException::class); + Assert::maxCount($m, 1, TooManyElementsException::class); + + return new static( + array_pop($m), + array_pop($k), + ); + } +} diff --git a/tests/XML/dsig11/TnBTest.php b/tests/XML/dsig11/TnBTest.php new file mode 100644 index 00000000..d47179ff --- /dev/null +++ b/tests/XML/dsig11/TnBTest.php @@ -0,0 +1,81 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($tnb), + ); + } + + + /** + */ + public function testMarshallingElementOrder(): void + { + $m = new M(1024); + $k = new K(64); + $tnb = new TnB($m, $k); + + $tnbElement = $tnb->toXML(); + /** @var \DOMElement[] $children */ + $children = $tnbElement->childNodes; + + $this->assertEquals('dsig11:M', $children[0]->tagName); + $this->assertEquals('dsig11:K', $children[1]->tagName); + } +} diff --git a/tests/resources/xml/dsig11_TnB.xml b/tests/resources/xml/dsig11_TnB.xml new file mode 100644 index 00000000..abcef386 --- /dev/null +++ b/tests/resources/xml/dsig11_TnB.xml @@ -0,0 +1,4 @@ + + 1024 + 64 + From 0fdf0efac86af109b2c863a329add664275fe44f Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 8 Jun 2025 22:13:57 +0200 Subject: [PATCH 15/30] Add dsig11:PnB-element --- src/XML/dsig11/AbstractPnBFieldParamsType.php | 82 +++++++++++++++++ src/XML/dsig11/PnB.php | 63 +++++++++++++ tests/XML/dsig11/PnBTest.php | 91 +++++++++++++++++++ tests/resources/xml/dsig11_PnB.xml | 6 ++ 4 files changed, 242 insertions(+) create mode 100644 src/XML/dsig11/AbstractPnBFieldParamsType.php create mode 100644 src/XML/dsig11/PnB.php create mode 100644 tests/XML/dsig11/PnBTest.php create mode 100644 tests/resources/xml/dsig11_PnB.xml diff --git a/src/XML/dsig11/AbstractPnBFieldParamsType.php b/src/XML/dsig11/AbstractPnBFieldParamsType.php new file mode 100644 index 00000000..e0d1dede --- /dev/null +++ b/src/XML/dsig11/AbstractPnBFieldParamsType.php @@ -0,0 +1,82 @@ +k1; + } + + + /** + * Collect the value of the k2-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\K2 + */ + public function getK2(): K2 + { + return $this->k2; + } + + + /** + * Collect the value of the k3-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\K3 + */ + public function getK3(): K3 + { + return $this->k3; + } + + + /** + * Convert this PnBFieldParamsType element to XML. + * + * @param \DOMElement|null $parent The element we should append this PnBFieldParamsType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = parent::toXML($parent); + $this->getK1()->toXML($e); + $this->getK2()->toXML($e); + $this->getK3()->toXML($e); + + return $e; + } +} diff --git a/src/XML/dsig11/PnB.php b/src/XML/dsig11/PnB.php new file mode 100644 index 00000000..71894e2f --- /dev/null +++ b/src/XML/dsig11/PnB.php @@ -0,0 +1,63 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $k1 = K1::getChildrenOfClass($xml); + Assert::minCount($k1, 1, MissingElementException::class); + Assert::maxCount($k1, 1, TooManyElementsException::class); + + $k2 = K2::getChildrenOfClass($xml); + Assert::minCount($k2, 1, MissingElementException::class); + Assert::maxCount($k2, 1, TooManyElementsException::class); + + $k3 = K3::getChildrenOfClass($xml); + Assert::minCount($k3, 1, MissingElementException::class); + Assert::maxCount($k3, 1, TooManyElementsException::class); + + $m = M::getChildrenOfClass($xml); + Assert::minCount($m, 1, MissingElementException::class); + Assert::maxCount($m, 1, TooManyElementsException::class); + + return new static( + array_pop($m), + array_pop($k1), + array_pop($k2), + array_pop($k3), + ); + } +} diff --git a/tests/XML/dsig11/PnBTest.php b/tests/XML/dsig11/PnBTest.php new file mode 100644 index 00000000..9bd20c22 --- /dev/null +++ b/tests/XML/dsig11/PnBTest.php @@ -0,0 +1,91 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($pnb), + ); + } + + + /** + */ + public function testMarshallingElementOrder(): void + { + $m = new M(1024); + $k1 = new K1(128); + $k2 = new K2(256); + $k3 = new K3(512); + $pnb = new PnB($m, $k1, $k2, $k3); + + $pnbElement = $pnb->toXML(); + /** @var \DOMElement[] $children */ + $children = $pnbElement->childNodes; + + $this->assertEquals('dsig11:M', $children[0]->tagName); + $this->assertEquals('dsig11:K1', $children[1]->tagName); + $this->assertEquals('dsig11:K2', $children[2]->tagName); + $this->assertEquals('dsig11:K3', $children[3]->tagName); + } +} diff --git a/tests/resources/xml/dsig11_PnB.xml b/tests/resources/xml/dsig11_PnB.xml new file mode 100644 index 00000000..84e2c88d --- /dev/null +++ b/tests/resources/xml/dsig11_PnB.xml @@ -0,0 +1,6 @@ + + 1024 + 128 + 256 + 512 + From 61ef931173c0ad9948ced9200eedee94bc5eaa06 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 8 Jun 2025 22:42:28 +0200 Subject: [PATCH 16/30] Add dsig11:ValidationData-element --- .../dsig11/AbstractECValidationDataType.php | 69 +++++++++++++++++++ src/XML/dsig11/ValidationData.php | 49 +++++++++++++ tests/XML/dsig11/ValidationDataTest.php | 57 +++++++++++++++ tests/resources/xml/dsig11_ValidationData.xml | 3 + 4 files changed, 178 insertions(+) create mode 100644 src/XML/dsig11/AbstractECValidationDataType.php create mode 100644 src/XML/dsig11/ValidationData.php create mode 100644 tests/XML/dsig11/ValidationDataTest.php create mode 100644 tests/resources/xml/dsig11_ValidationData.xml diff --git a/src/XML/dsig11/AbstractECValidationDataType.php b/src/XML/dsig11/AbstractECValidationDataType.php new file mode 100644 index 00000000..95d65db2 --- /dev/null +++ b/src/XML/dsig11/AbstractECValidationDataType.php @@ -0,0 +1,69 @@ +seed; + } + + + /** + * Collect the value of the hashAlgorithm-property + * + * @return string + */ + public function getHashAlgorithm(): string + { + return $this->hashAlgorithm; + } + + + /** + * Convert this ECValidationDataType element to XML. + * + * @param \DOMElement|null $parent The element we should append this ECValidationDataType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->setAttribute('hashAlgorithm', $this->getHashAlgorithm()); + + $this->getSeed()->toXML($e); + + return $e; + } +} diff --git a/src/XML/dsig11/ValidationData.php b/src/XML/dsig11/ValidationData.php new file mode 100644 index 00000000..20cf4c0a --- /dev/null +++ b/src/XML/dsig11/ValidationData.php @@ -0,0 +1,49 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $seed = Seed::getChildrenOfClass($xml); + Assert::minCount($seed, 1, MissingElementException::class); + Assert::maxCount($seed, 1, TooManyElementsException::class); + + return new static( + array_pop($seed), + self::getAttribute($xml, 'hashAlgorithm'), + ); + } +} diff --git a/tests/XML/dsig11/ValidationDataTest.php b/tests/XML/dsig11/ValidationDataTest.php new file mode 100644 index 00000000..6932fc23 --- /dev/null +++ b/tests/XML/dsig11/ValidationDataTest.php @@ -0,0 +1,57 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($validationData), + ); + } +} diff --git a/tests/resources/xml/dsig11_ValidationData.xml b/tests/resources/xml/dsig11_ValidationData.xml new file mode 100644 index 00000000..0caa6d5c --- /dev/null +++ b/tests/resources/xml/dsig11_ValidationData.xml @@ -0,0 +1,3 @@ + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + From 17100db6117b3f81b7b7cebb7371629286c7b40c Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 8 Jun 2025 22:48:20 +0200 Subject: [PATCH 17/30] Add dsig11:Base-element --- src/XML/dsig11/Base.php | 29 ++++++++++++++++ tests/XML/dsig11/BaseTest.php | 53 +++++++++++++++++++++++++++++ tests/resources/xml/dsig11_Base.xml | 1 + 3 files changed, 83 insertions(+) create mode 100644 src/XML/dsig11/Base.php create mode 100644 tests/XML/dsig11/BaseTest.php create mode 100644 tests/resources/xml/dsig11_Base.xml diff --git a/src/XML/dsig11/Base.php b/src/XML/dsig11/Base.php new file mode 100644 index 00000000..15bf664f --- /dev/null +++ b/src/XML/dsig11/Base.php @@ -0,0 +1,29 @@ +setContent($value); + } +} diff --git a/tests/XML/dsig11/BaseTest.php b/tests/XML/dsig11/BaseTest.php new file mode 100644 index 00000000..29d2977e --- /dev/null +++ b/tests/XML/dsig11/BaseTest.php @@ -0,0 +1,53 @@ +assertEquals( + XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), + strval($base), + ); + } +} diff --git a/tests/resources/xml/dsig11_Base.xml b/tests/resources/xml/dsig11_Base.xml new file mode 100644 index 00000000..a4f1bf3d --- /dev/null +++ b/tests/resources/xml/dsig11_Base.xml @@ -0,0 +1 @@ +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= From 1ee6229d233df298b136a8e75783e4d8be7a0d03 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 8 Jun 2025 22:56:46 +0200 Subject: [PATCH 18/30] Add dsig11:PublicKey-element --- src/XML/dsig11/PublicKey.php | 29 +++++++++++++ tests/XML/dsig11/PublicKeyTest.php | 53 ++++++++++++++++++++++++ tests/resources/xml/dsig11_PublicKey.xml | 1 + 3 files changed, 83 insertions(+) create mode 100644 src/XML/dsig11/PublicKey.php create mode 100644 tests/XML/dsig11/PublicKeyTest.php create mode 100644 tests/resources/xml/dsig11_PublicKey.xml diff --git a/src/XML/dsig11/PublicKey.php b/src/XML/dsig11/PublicKey.php new file mode 100644 index 00000000..bf8bf1a5 --- /dev/null +++ b/src/XML/dsig11/PublicKey.php @@ -0,0 +1,29 @@ +setContent($value); + } +} diff --git a/tests/XML/dsig11/PublicKeyTest.php b/tests/XML/dsig11/PublicKeyTest.php new file mode 100644 index 00000000..ca5dd32d --- /dev/null +++ b/tests/XML/dsig11/PublicKeyTest.php @@ -0,0 +1,53 @@ +assertEquals( + XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), + strval($publicKey), + ); + } +} diff --git a/tests/resources/xml/dsig11_PublicKey.xml b/tests/resources/xml/dsig11_PublicKey.xml new file mode 100644 index 00000000..feebd65b --- /dev/null +++ b/tests/resources/xml/dsig11_PublicKey.xml @@ -0,0 +1 @@ +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= From e2614718a258fc92677bc7627ae0abdef42cd59e Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 8 Jun 2025 23:16:52 +0200 Subject: [PATCH 19/30] Add dsig11:Curve-element --- src/XML/dsig11/AbstractCurveType.php | 66 ++++++++++++++++++++++++++++ src/XML/dsig11/Curve.php | 49 +++++++++++++++++++++ tests/XML/dsig11/CurveTest.php | 58 ++++++++++++++++++++++++ tests/resources/xml/dsig11_Curve.xml | 4 ++ 4 files changed, 177 insertions(+) create mode 100644 src/XML/dsig11/AbstractCurveType.php create mode 100644 src/XML/dsig11/Curve.php create mode 100644 tests/XML/dsig11/CurveTest.php create mode 100644 tests/resources/xml/dsig11_Curve.xml diff --git a/src/XML/dsig11/AbstractCurveType.php b/src/XML/dsig11/AbstractCurveType.php new file mode 100644 index 00000000..b298a5b9 --- /dev/null +++ b/src/XML/dsig11/AbstractCurveType.php @@ -0,0 +1,66 @@ +a; + } + + + /** + * Collect the value of the b-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\B + */ + public function getB(): B + { + return $this->b; + } + + + /** + * Convert this CurveType element to XML. + * + * @param \DOMElement|null $parent The element we should append this CurveType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + + $this->getA()->toXML($e); + $this->getB()->toXML($e); + + return $e; + } +} diff --git a/src/XML/dsig11/Curve.php b/src/XML/dsig11/Curve.php new file mode 100644 index 00000000..8879754f --- /dev/null +++ b/src/XML/dsig11/Curve.php @@ -0,0 +1,49 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + + $a = A::getChildrenOfClass($xml); + Assert::minCount($a, 1, MissingElementException::class); + Assert::maxCount($a, 1, TooManyElementsException::class); + + $b = B::getChildrenOfClass($xml); + Assert::minCount($b, 1, MissingElementException::class); + Assert::maxCount($b, 1, TooManyElementsException::class); + + return new static( + array_pop($a), + array_pop($b), + ); + } +} diff --git a/tests/XML/dsig11/CurveTest.php b/tests/XML/dsig11/CurveTest.php new file mode 100644 index 00000000..0914cb37 --- /dev/null +++ b/tests/XML/dsig11/CurveTest.php @@ -0,0 +1,58 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($curve), + ); + } +} diff --git a/tests/resources/xml/dsig11_Curve.xml b/tests/resources/xml/dsig11_Curve.xml new file mode 100644 index 00000000..9bd1142e --- /dev/null +++ b/tests/resources/xml/dsig11_Curve.xml @@ -0,0 +1,4 @@ + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + From fe6e748f14ef6552ce9878c4cc5c9e5e239790a8 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 8 Jun 2025 23:51:34 +0200 Subject: [PATCH 20/30] Add dsig11:FieldID-element --- src/XML/dsig11/AbstractFieldIDType.php | 109 +++++++++++++++++++++++++ src/XML/dsig11/FieldID.php | 62 ++++++++++++++ tests/XML/dsig11/FieldIDTest.php | 83 +++++++++++++++++++ tests/resources/xml/dsig11_FieldID.xml | 19 +++++ 4 files changed, 273 insertions(+) create mode 100644 src/XML/dsig11/AbstractFieldIDType.php create mode 100644 src/XML/dsig11/FieldID.php create mode 100644 tests/XML/dsig11/FieldIDTest.php create mode 100644 tests/resources/xml/dsig11_FieldID.xml diff --git a/src/XML/dsig11/AbstractFieldIDType.php b/src/XML/dsig11/AbstractFieldIDType.php new file mode 100644 index 00000000..0e0bc154 --- /dev/null +++ b/src/XML/dsig11/AbstractFieldIDType.php @@ -0,0 +1,109 @@ + $children + */ + public function __construct( + protected Prime $prime, + protected TnB $tnb, + protected PnB $pnb, + protected GnB $gnb, + array $children, + ) { + $this->setElements($children); + } + + + /** + * Collect the value of the prime-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\Prime + */ + public function getPrime(): Prime + { + return $this->prime; + } + + + /** + * Collect the value of the tnb-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\TnB + */ + public function getTnB(): TnB + { + return $this->tnb; + } + + + /** + * Collect the value of the pnb-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\PnB + */ + public function getPnB(): PnB + { + return $this->pnb; + } + + + /** + * Collect the value of the gnb-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\GnB + */ + public function getGnB(): GnB + { + return $this->gnb; + } + + + /** + * Convert this FieldIDType element to XML. + * + * @param \DOMElement|null $parent The element we should append this FieldIDType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + + $this->getPrime()->toXML($e); + $this->getTnB()->toXML($e); + $this->getPnB()->toXML($e); + $this->getGnB()->toXML($e); + + foreach ($this->getElements() as $elt) { + $elt->toXML($e); + } + + return $e; + } +} diff --git a/src/XML/dsig11/FieldID.php b/src/XML/dsig11/FieldID.php new file mode 100644 index 00000000..25025234 --- /dev/null +++ b/src/XML/dsig11/FieldID.php @@ -0,0 +1,62 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $prime = Prime::getChildrenOfClass($xml); + Assert::minCount($prime, 1, MissingElementException::class); + Assert::maxCount($prime, 1, TooManyElementsException::class); + + $tnb = TnB::getChildrenOfClass($xml); + Assert::minCount($tnb, 1, MissingElementException::class); + Assert::maxCount($tnb, 1, TooManyElementsException::class); + + $pnb = PnB::getChildrenOfClass($xml); + Assert::minCount($pnb, 1, MissingElementException::class); + Assert::maxCount($pnb, 1, TooManyElementsException::class); + + $gnb = GnB::getChildrenOfClass($xml); + Assert::minCount($gnb, 1, MissingElementException::class); + Assert::maxCount($gnb, 1, TooManyElementsException::class); + + return new static( + array_pop($prime), + array_pop($tnb), + array_pop($pnb), + array_pop($gnb), + self::getChildElementsFromXML($xml), + ); + } +} diff --git a/tests/XML/dsig11/FieldIDTest.php b/tests/XML/dsig11/FieldIDTest.php new file mode 100644 index 00000000..7b72eca2 --- /dev/null +++ b/tests/XML/dsig11/FieldIDTest.php @@ -0,0 +1,83 @@ +some', + )->documentElement); + + $fieldId = new FieldID($prime, $tnb, $pnb, $gnb, [$chunk]); + + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($fieldId), + ); + } +} diff --git a/tests/resources/xml/dsig11_FieldID.xml b/tests/resources/xml/dsig11_FieldID.xml new file mode 100644 index 00000000..2503395d --- /dev/null +++ b/tests/resources/xml/dsig11_FieldID.xml @@ -0,0 +1,19 @@ + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + + 1024 + 64 + + + 1024 + 128 + 256 + 512 + + + 1024 + + some + From 486e5ec68e42d63efff805080aabd97713e2f606 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 00:36:33 +0200 Subject: [PATCH 21/30] Add dsig11:NamedCurve-element --- src/XML/dsig11/AbstractNamedCurveType.php | 54 +++++++++++++++++++++++ src/XML/dsig11/NamedCurve.php | 36 +++++++++++++++ tests/XML/dsig11/NamedCurveTest.php | 54 +++++++++++++++++++++++ tests/resources/xml/dsig11_NamedCurve.xml | 1 + 4 files changed, 145 insertions(+) create mode 100644 src/XML/dsig11/AbstractNamedCurveType.php create mode 100644 src/XML/dsig11/NamedCurve.php create mode 100644 tests/XML/dsig11/NamedCurveTest.php create mode 100644 tests/resources/xml/dsig11_NamedCurve.xml diff --git a/src/XML/dsig11/AbstractNamedCurveType.php b/src/XML/dsig11/AbstractNamedCurveType.php new file mode 100644 index 00000000..a01ab586 --- /dev/null +++ b/src/XML/dsig11/AbstractNamedCurveType.php @@ -0,0 +1,54 @@ +URI; + } + + + /** + * Convert this NamedCurveType element to XML. + * + * @param \DOMElement|null $parent The element we should append this NamedCurveType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->setAttribute('URI', $this->getURI()); + + return $e; + } +} diff --git a/src/XML/dsig11/NamedCurve.php b/src/XML/dsig11/NamedCurve.php new file mode 100644 index 00000000..fdf23490 --- /dev/null +++ b/src/XML/dsig11/NamedCurve.php @@ -0,0 +1,36 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + return new static( + self::getAttribute($xml, 'URI'), + ); + } +} diff --git a/tests/XML/dsig11/NamedCurveTest.php b/tests/XML/dsig11/NamedCurveTest.php new file mode 100644 index 00000000..eb63b12a --- /dev/null +++ b/tests/XML/dsig11/NamedCurveTest.php @@ -0,0 +1,54 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($namedCurve), + ); + } +} diff --git a/tests/resources/xml/dsig11_NamedCurve.xml b/tests/resources/xml/dsig11_NamedCurve.xml new file mode 100644 index 00000000..94fb1416 --- /dev/null +++ b/tests/resources/xml/dsig11_NamedCurve.xml @@ -0,0 +1 @@ + From 3c3129cb0ffb8546e270947e884e16271a070b7a Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 00:57:06 +0200 Subject: [PATCH 22/30] Add dsig11:CoFactor-element --- src/XML/dsig11/CoFactor.php | 29 ++++++++++++++ tests/XML/dsig11/CoFactorTest.php | 52 +++++++++++++++++++++++++ tests/resources/xml/dsig11_CoFactor.xml | 1 + 3 files changed, 82 insertions(+) create mode 100644 src/XML/dsig11/CoFactor.php create mode 100644 tests/XML/dsig11/CoFactorTest.php create mode 100644 tests/resources/xml/dsig11_CoFactor.xml diff --git a/src/XML/dsig11/CoFactor.php b/src/XML/dsig11/CoFactor.php new file mode 100644 index 00000000..d1671019 --- /dev/null +++ b/src/XML/dsig11/CoFactor.php @@ -0,0 +1,29 @@ +setContent($value); + } +} diff --git a/tests/XML/dsig11/CoFactorTest.php b/tests/XML/dsig11/CoFactorTest.php new file mode 100644 index 00000000..e13dcf72 --- /dev/null +++ b/tests/XML/dsig11/CoFactorTest.php @@ -0,0 +1,52 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($coFactor), + ); + } +} diff --git a/tests/resources/xml/dsig11_CoFactor.xml b/tests/resources/xml/dsig11_CoFactor.xml new file mode 100644 index 00000000..27655534 --- /dev/null +++ b/tests/resources/xml/dsig11_CoFactor.xml @@ -0,0 +1 @@ +128 From f441612603c02805c4314accc99903445191ad2b Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 10:05:42 +0200 Subject: [PATCH 23/30] Fix typo: s/xenc/dsig11 --- src/XML/dsig11/K.php | 2 +- src/XML/dsig11/K1.php | 2 +- src/XML/dsig11/K2.php | 2 +- src/XML/dsig11/K3.php | 2 +- src/XML/dsig11/M.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/XML/dsig11/K.php b/src/XML/dsig11/K.php index 038ffd25..7bf3cac6 100644 --- a/src/XML/dsig11/K.php +++ b/src/XML/dsig11/K.php @@ -10,7 +10,7 @@ use SimpleSAML\XML\Exception\SchemaViolationException; /** - * Class representing a xenc:K element. + * Class representing a dsig11:K element. * * @package simplesaml/xml-security */ diff --git a/src/XML/dsig11/K1.php b/src/XML/dsig11/K1.php index fa454e11..51364a78 100644 --- a/src/XML/dsig11/K1.php +++ b/src/XML/dsig11/K1.php @@ -10,7 +10,7 @@ use SimpleSAML\XML\Exception\SchemaViolationException; /** - * Class representing a xenc:K1 element. + * Class representing a dsig11:K1 element. * * @package simplesaml/xml-security */ diff --git a/src/XML/dsig11/K2.php b/src/XML/dsig11/K2.php index dc322df2..8cb56613 100644 --- a/src/XML/dsig11/K2.php +++ b/src/XML/dsig11/K2.php @@ -10,7 +10,7 @@ use SimpleSAML\XML\Exception\SchemaViolationException; /** - * Class representing a xenc:K2 element. + * Class representing a dsig11:K2 element. * * @package simplesaml/xml-security */ diff --git a/src/XML/dsig11/K3.php b/src/XML/dsig11/K3.php index 0af4b99e..9cf92713 100644 --- a/src/XML/dsig11/K3.php +++ b/src/XML/dsig11/K3.php @@ -10,7 +10,7 @@ use SimpleSAML\XML\Exception\SchemaViolationException; /** - * Class representing a xenc:K3 element. + * Class representing a dsig11:K3 element. * * @package simplesaml/xml-security */ diff --git a/src/XML/dsig11/M.php b/src/XML/dsig11/M.php index 2f4e90a1..ec429082 100644 --- a/src/XML/dsig11/M.php +++ b/src/XML/dsig11/M.php @@ -10,7 +10,7 @@ use SimpleSAML\XML\Exception\SchemaViolationException; /** - * Class representing a xenc:M element. + * Class representing a dsig11:M element. * * @package simplesaml/xml-security */ From 184b271cef962f7a1f92233fa3206ac5ccfdb118 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 16:38:59 +0200 Subject: [PATCH 24/30] Add dsig11:ECParameters-element --- src/XML/dsig11/AbstractECParametersType.php | 122 ++++++++++++++++++++ src/XML/dsig11/ECParameters.php | 67 +++++++++++ tests/XML/dsig11/ECParametersTest.php | 115 ++++++++++++++++++ tests/resources/xml/dsig11_ECParameters.xml | 31 +++++ 4 files changed, 335 insertions(+) create mode 100644 src/XML/dsig11/AbstractECParametersType.php create mode 100644 src/XML/dsig11/ECParameters.php create mode 100644 tests/XML/dsig11/ECParametersTest.php create mode 100644 tests/resources/xml/dsig11_ECParameters.xml diff --git a/src/XML/dsig11/AbstractECParametersType.php b/src/XML/dsig11/AbstractECParametersType.php new file mode 100644 index 00000000..b35ca34f --- /dev/null +++ b/src/XML/dsig11/AbstractECParametersType.php @@ -0,0 +1,122 @@ +fieldId; + } + + + /** + * Collect the value of the curve-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\Curve + */ + public function getCurve(): Curve + { + return $this->curve; + } + + + /** + * Collect the value of the base-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\Base + */ + public function getBase(): Base + { + return $this->base; + } + + + /** + * Collect the value of the order-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\Order + */ + public function getOrder(): Order + { + return $this->order; + } + + + /** + * Collect the value of the coFactor-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\CoFactor|null + */ + public function getCoFactor(): ?CoFactor + { + return $this->coFactor; + } + + + /** + * Collect the value of the validationData-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\ValidationData|null + */ + public function getValidationData(): ?ValidationData + { + return $this->validationData; + } + + + /** + * Convert this ECParametersType element to XML. + * + * @param \DOMElement|null $parent The element we should append this ECParametersType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + + $this->getFieldId()->toXML($e); + $this->getCurve()->toXML($e); + $this->getBase()->toXML($e); + $this->getOrder()->toXML($e); + $this->getCoFactor()?->toXML($e); + $this->getValidationData()?->toXML($e); + + return $e; + } +} diff --git a/src/XML/dsig11/ECParameters.php b/src/XML/dsig11/ECParameters.php new file mode 100644 index 00000000..dee70308 --- /dev/null +++ b/src/XML/dsig11/ECParameters.php @@ -0,0 +1,67 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $fieldId = FieldID::getChildrenOfClass($xml); + Assert::minCount($fieldId, 1, MissingElementException::class); + Assert::maxCount($fieldId, 1, TooManyElementsException::class); + + $curve = Curve::getChildrenOfClass($xml); + Assert::minCount($curve, 1, MissingElementException::class); + Assert::maxCount($curve, 1, TooManyElementsException::class); + + $base = Base::getChildrenOfClass($xml); + Assert::minCount($base, 1, MissingElementException::class); + Assert::maxCount($base, 1, TooManyElementsException::class); + + $order = Order::getChildrenOfClass($xml); + Assert::minCount($order, 1, MissingElementException::class); + Assert::maxCount($order, 1, TooManyElementsException::class); + + $coFactor = CoFactor::getChildrenOfClass($xml); + Assert::maxCount($coFactor, 1, TooManyElementsException::class); + + $validationData = ValidationData::getChildrenOfClass($xml); + Assert::maxCount($validationData, 1, TooManyElementsException::class); + + return new static( + array_pop($fieldId), + array_pop($curve), + array_pop($base), + array_pop($order), + array_pop($coFactor), + array_pop($validationData), + ); + } +} diff --git a/tests/XML/dsig11/ECParametersTest.php b/tests/XML/dsig11/ECParametersTest.php new file mode 100644 index 00000000..e476464e --- /dev/null +++ b/tests/XML/dsig11/ECParametersTest.php @@ -0,0 +1,115 @@ +some', + )->documentElement); + + $fieldId = new FieldID($prime, $tnb, $pnb, $gnb, [$chunk]); + + // Build Curve + $a = new A('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + $b = new B('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + $curve = new Curve($a, $b); + + // Build Base + $base = new Base('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + + // Build Order + $order = new Order('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + + // Build CoFactor + $coFactor = new CoFactor('128'); + + // Build ValidationData + $seed = new Seed('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + $validationData = new ValidationData($seed, C::DIGEST_SHA1); + + // Build ECParameters + $ecParameters = new ECParameters($fieldId, $curve, $base, $order, $coFactor, $validationData); + + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($ecParameters), + ); + } +} diff --git a/tests/resources/xml/dsig11_ECParameters.xml b/tests/resources/xml/dsig11_ECParameters.xml new file mode 100644 index 00000000..6c61f459 --- /dev/null +++ b/tests/resources/xml/dsig11_ECParameters.xml @@ -0,0 +1,31 @@ + + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + + 1024 + 64 + + + 1024 + 128 + 256 + 512 + + + 1024 + + some + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 128 + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + From 1942074f7dee63fa37fa5d4d62e7a027942c3f39 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 16:53:01 +0200 Subject: [PATCH 25/30] Add dsig11:ECKeyValue-element --- src/XML/dsig11/AbstractECKeyValueType.php | 106 ++++++++++++++++++ src/XML/dsig11/ECKeyValue.php | 57 ++++++++++ tests/XML/dsig11/ECKeyValueTest.php | 125 ++++++++++++++++++++++ tests/resources/xml/dsig11_ECKeyValue.xml | 34 ++++++ 4 files changed, 322 insertions(+) create mode 100644 src/XML/dsig11/AbstractECKeyValueType.php create mode 100644 src/XML/dsig11/ECKeyValue.php create mode 100644 tests/XML/dsig11/ECKeyValueTest.php create mode 100644 tests/resources/xml/dsig11_ECKeyValue.xml diff --git a/src/XML/dsig11/AbstractECKeyValueType.php b/src/XML/dsig11/AbstractECKeyValueType.php new file mode 100644 index 00000000..31f09018 --- /dev/null +++ b/src/XML/dsig11/AbstractECKeyValueType.php @@ -0,0 +1,106 @@ +ecParameters; + } + + + /** + * Collect the value of the namedCurve-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\NamedCurve|null + */ + public function getNamedCurve(): ?NamedCurve + { + return $this->namedCurve; + } + + + /** + * Collect the value of the publicKey-property + * + * @return \SimpleSAML\XMLSecurity\XML\dsig11\PublicKey + */ + public function getPublicKey(): PublicKey + { + return $this->publicKey; + } + + + /** + * Collect the value of the id-property + * + * @return string|null + */ + public function getId(): string + { + return $this->id; + } + + + /** + * Convert this ECKeyValueType element to XML. + * + * @param \DOMElement|null $parent The element we should append this ECKeyValueType element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + + if ($this->getId() !== null) { + $e->setAttribute('Id', $this->getId()); + } + + $this->getECParameters()?->toXML($e); + $this->getNamedCurve()?->toXML($e); + $this->getPublicKey()->toXML($e); + + return $e; + } +} diff --git a/src/XML/dsig11/ECKeyValue.php b/src/XML/dsig11/ECKeyValue.php new file mode 100644 index 00000000..c4d78437 --- /dev/null +++ b/src/XML/dsig11/ECKeyValue.php @@ -0,0 +1,57 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $publicKey = PublicKey::getChildrenOfClass($xml); + Assert::minCount($publicKey, 1, MissingElementException::class); + Assert::maxCount($publicKey, 1, TooManyElementsException::class); + + $ecParameters = ECParameters::getChildrenOfClass($xml); + Assert::maxCount($ecParameters, 1, TooManyElementsException::class); + + $namedCurve = NamedCurve::getChildrenOfClass($xml); + Assert::maxCount($namedCurve, 1, TooManyElementsException::class); + + return new static( + array_pop($publicKey), + self::getOptionalAttribute($xml, 'Id', null), + array_pop($ecParameters), + array_pop($namedCurve), + ); + } +} diff --git a/tests/XML/dsig11/ECKeyValueTest.php b/tests/XML/dsig11/ECKeyValueTest.php new file mode 100644 index 00000000..65ccb80f --- /dev/null +++ b/tests/XML/dsig11/ECKeyValueTest.php @@ -0,0 +1,125 @@ +some', + )->documentElement); + + $fieldId = new FieldID($prime, $tnb, $pnb, $gnb, [$chunk]); + + // Build Curve + $a = new A('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + $b = new B('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + $curve = new Curve($a, $b); + + // Build Base + $base = new Base('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + + // Build Order + $order = new Order('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + + // Build CoFactor + $coFactor = new CoFactor('128'); + + // Build ValidationData + $seed = new Seed('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + $validationData = new ValidationData($seed, C::DIGEST_SHA1); + + // Build ECParameters + $ecParameters = new ECParameters($fieldId, $curve, $base, $order, $coFactor, $validationData); + + // Build PublicKey + $publicKey = new PublicKey('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); + + // Build ECKeyValue + $ecKeyValue = new ECKeyValue($publicKey, 'phpunit', $ecParameters); + + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($ecKeyValue), + ); + } +} diff --git a/tests/resources/xml/dsig11_ECKeyValue.xml b/tests/resources/xml/dsig11_ECKeyValue.xml new file mode 100644 index 00000000..4377465e --- /dev/null +++ b/tests/resources/xml/dsig11_ECKeyValue.xml @@ -0,0 +1,34 @@ + + + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + + 1024 + 64 + + + 1024 + 128 + 256 + 512 + + + 1024 + + some + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 128 + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + From a03a79047f0cc171604db58f026e27d0a819f912 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 16:23:22 +0200 Subject: [PATCH 26/30] Refactor ds:KeyValue --- src/XML/ds/KeyValue.php | 76 +++++++++++++++++++---------------- tests/XML/ds/KeyValueTest.php | 32 +++------------ 2 files changed, 46 insertions(+), 62 deletions(-) diff --git a/src/XML/ds/KeyValue.php b/src/XML/ds/KeyValue.php index 7fba8cc6..b59d90ef 100644 --- a/src/XML/ds/KeyValue.php +++ b/src/XML/ds/KeyValue.php @@ -6,14 +6,20 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\ElementInterface; +use SimpleSAML\XML\Chunk; use SimpleSAML\XML\Exception\InvalidDOMElementException; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Exception\TooManyElementsException; use SimpleSAML\XML\ExtendableElementTrait; use SimpleSAML\XML\SchemaValidatableElementInterface; use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\SerializableElementInterface; use SimpleSAML\XML\XsNamespace as NS; +use SimpleSAML\XMLSecurity\Constants as C; +use SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue; + +use function array_merge; +use function array_pop; /** * Class representing a ds:KeyValue element. @@ -22,7 +28,11 @@ */ final class KeyValue extends AbstractDsElement implements SchemaValidatableElementInterface { - use ExtendableElementTrait; + // We use our own getter instead of the trait's one, so we prevent their use by marking them private + use ExtendableElementTrait { + getElements as private; + setElements as private; + } use SchemaValidatableElementTrait; @@ -33,21 +43,23 @@ final class KeyValue extends AbstractDsElement implements SchemaValidatableEleme /** * Initialize an KeyValue. * - * @param \SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue|null $RSAKeyValue - * @param \SimpleSAML\XML\SerializableElementInterface|null $element + * @param \SimpleSAML\XML\SerializableElementInterface $keyValue */ final public function __construct( - protected ?RSAKeyValue $RSAKeyValue, - ?ElementInterface $element = null, + protected RSAKeyValue|DSAKeyValue|ECKeyValue|SerializableElementInterface $keyValue, ) { - Assert::false( - is_null($RSAKeyValue) && is_null($element), - 'A requires either a RSAKeyValue or an element in namespace ##other', - SchemaViolationException::class, - ); - - if ($element !== null) { - $this->setElements([$element]); + if ( + !($keyValue instanceof RSAKeyValue + || $keyValue instanceof DSAKeyValue + || $keyValue instanceof ECKeyValue) + ) { + Assert::true( + (($keyValue instanceof Chunk) ? $keyValue->getNamespaceURI() : $keyValue::getNameSpaceURI()) + !== C::NS_XDSIG, + 'A requires either a RSAKeyValue, DSAKeyValue, ECKeyValue ' + . 'or an element in namespace ##other', + SchemaViolationException::class, + ); } } @@ -55,11 +67,14 @@ final public function __construct( /** * Collect the value of the RSAKeyValue-property * - * @return \SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue|null + * @return \SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue| + * \SimpleSAML\XMLSecurity\XML\ds\DSAKeyValue| + * \SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue| + * \SimpeSAML\XML\SerializableElementInterface */ - public function getRSAKeyValue(): ?RSAKeyValue + public function getKeyValue(): RSAKeyValue|DSAKeyValue|ECKeyValue|SerializableElementInterface { - return $this->RSAKeyValue; + return $this->keyValue; } @@ -77,23 +92,20 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'KeyValue', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, KeyValue::NS, InvalidDOMElementException::class); - $RSAKeyValue = RSAKeyValue::getChildrenOfClass($xml); - Assert::maxCount( - $RSAKeyValue, - 1, - 'A can contain exactly one ', - TooManyElementsException::class, + $keyValue = array_merge( + RSAKeyValue::getChildrenOfClass($xml), + DSAKeyValue::getChildrenOfClass($xml), + self::getChildElementsFromXML($xml), ); - $elements = self::getChildElementsFromXML($xml); - Assert::maxCount( - $elements, + Assert::count( + $keyValue, 1, - 'A can contain exactly one element in namespace ##other', + 'A must contain exactly one child element', TooManyElementsException::class, ); - return new static(array_pop($RSAKeyValue), array_pop($elements)); + return new static(array_pop($keyValue)); } @@ -107,13 +119,7 @@ public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $this->getRSAKeyValue()?->toXML($e); - - foreach ($this->elements as $elt) { - if (!$elt->isEmptyElement()) { - $elt->toXML($e); - } - } + $this->getKeyValue()->toXML($e); return $e; } diff --git a/tests/XML/ds/KeyValueTest.php b/tests/XML/ds/KeyValueTest.php index da3f9695..0c9f1cfc 100644 --- a/tests/XML/ds/KeyValueTest.php +++ b/tests/XML/ds/KeyValueTest.php @@ -70,9 +70,8 @@ public function testMarshalling(): void { $keyValue = new KeyValue(RSAKeyValue::fromXML(self::$rsaKeyValue->documentElement)); - $rsaKeyValue = $keyValue->getRSAKeyValue(); + $rsaKeyValue = $keyValue->getKeyValue(); $this->assertInstanceOf(RSAKeyValue::class, $rsaKeyValue); - $this->assertEmpty($keyValue->getElements()); $this->assertEquals($rsaKeyValue->getModulus()->getContent(), 'dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='); $this->assertEquals($rsaKeyValue->getExponent()->getContent(), 'dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='); @@ -88,13 +87,9 @@ public function testMarshalling(): void */ public function testMarshallingWithOtherElement(): void { - $keyValue = new KeyValue(null, EncryptionProperty::fromXML(self::$encryptionProperty->documentElement)); + $keyValue = new KeyValue(EncryptionProperty::fromXML(self::$encryptionProperty->documentElement)); - $elements = $keyValue->getElements(); - $this->assertEmpty($keyValue->getRSAKeyValue()); - $this->assertCount(1, $elements); - - $element = reset($elements); + $element = $keyValue->getKeyValue(); $this->assertInstanceOf(EncryptionProperty::class, $element); $document = self::$empty; @@ -104,19 +99,6 @@ public function testMarshallingWithOtherElement(): void } - /** - */ - public function testMarshallingEmpty(): void - { - $this->expectException(SchemaViolationException::class); - $this->expectExceptionMessage( - 'A requires either a RSAKeyValue or an element in namespace ##other', - ); - - new KeyValue(null, null); - } - - /** */ public function testUnmarshallingWithOtherElement(): void @@ -128,11 +110,7 @@ public function testUnmarshallingWithOtherElement(): void $keyValue = KeyValue::fromXML($document->documentElement); - $elements = $keyValue->getElements(); - $this->assertNull($keyValue->getRSAKeyValue()); - $this->assertCount(1, $elements); - - $element = reset($elements); + $element = $keyValue->getKeyValue(); $this->assertInstanceOf(EncryptionProperty::class, $element); } @@ -145,7 +123,7 @@ public function testUnmarshallingEmpty(): void $this->expectException(SchemaViolationException::class); $this->expectExceptionMessage( - 'A requires either a RSAKeyValue or an element in namespace ##other', + 'A must contain exactly one child element', ); KeyValue::fromXML($document->documentElement); From 8e80e7723f239f5eb8200ac540b21c9f2424e914 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 17:05:31 +0200 Subject: [PATCH 27/30] Fix Seed-element lowercase name --- src/XML/dsig11/Seed.php | 3 +++ tests/resources/xml/dsig11_ECKeyValue.xml | 2 +- tests/resources/xml/dsig11_ECParameters.xml | 2 +- tests/resources/xml/dsig11_Seed.xml | 2 +- tests/resources/xml/dsig11_ValidationData.xml | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/XML/dsig11/Seed.php b/src/XML/dsig11/Seed.php index b1f51a38..fda47836 100644 --- a/src/XML/dsig11/Seed.php +++ b/src/XML/dsig11/Seed.php @@ -15,6 +15,9 @@ final class Seed extends AbstractDsig11Element { use Base64ElementTrait; + /** @var string */ + public const LOCALNAME = 'seed'; + /** * Initialize a Seed element. diff --git a/tests/resources/xml/dsig11_ECKeyValue.xml b/tests/resources/xml/dsig11_ECKeyValue.xml index 4377465e..b6ba3caa 100644 --- a/tests/resources/xml/dsig11_ECKeyValue.xml +++ b/tests/resources/xml/dsig11_ECKeyValue.xml @@ -27,7 +27,7 @@ 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= 128 - 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= diff --git a/tests/resources/xml/dsig11_ECParameters.xml b/tests/resources/xml/dsig11_ECParameters.xml index 6c61f459..89e8ddc4 100644 --- a/tests/resources/xml/dsig11_ECParameters.xml +++ b/tests/resources/xml/dsig11_ECParameters.xml @@ -26,6 +26,6 @@ 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= 128 - 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= diff --git a/tests/resources/xml/dsig11_Seed.xml b/tests/resources/xml/dsig11_Seed.xml index c6c2f9a7..2c4a864d 100644 --- a/tests/resources/xml/dsig11_Seed.xml +++ b/tests/resources/xml/dsig11_Seed.xml @@ -1 +1 @@ -6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= diff --git a/tests/resources/xml/dsig11_ValidationData.xml b/tests/resources/xml/dsig11_ValidationData.xml index 0caa6d5c..c1723176 100644 --- a/tests/resources/xml/dsig11_ValidationData.xml +++ b/tests/resources/xml/dsig11_ValidationData.xml @@ -1,3 +1,3 @@ - 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= From 77461faea171193c6af9bf373c2d96cc473becfd Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 17:11:58 +0200 Subject: [PATCH 28/30] Refactor CoFactor-element to native integer --- src/XML/dsig11/CoFactor.php | 60 +++++++++++++++++++++++---- tests/XML/dsig11/CoFactorTest.php | 2 +- tests/XML/dsig11/ECKeyValueTest.php | 2 +- tests/XML/dsig11/ECParametersTest.php | 2 +- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/XML/dsig11/CoFactor.php b/src/XML/dsig11/CoFactor.php index d1671019..c1741c6e 100644 --- a/src/XML/dsig11/CoFactor.php +++ b/src/XML/dsig11/CoFactor.php @@ -4,7 +4,13 @@ namespace SimpleSAML\XMLSecurity\XML\dsig11; -use SimpleSAML\XML\IntegerElementTrait; +use DOMElement; +use SimpleSAML\Assert\Assert; +use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Exception\SchemaViolationException; + +use function intval; +use function strval; /** * Class representing a dsig11:CoFactor element. @@ -13,17 +19,55 @@ */ final class CoFactor extends AbstractDsig11Element { - use IntegerElementTrait; + /** + * @param int $value + */ + public function __construct( + protected int $value, + ) { + Assert::positiveInteger($value, SchemaViolationException::class); + } + + + /** + * @return int + */ + public function getValue(): int + { + return $this->value; + } /** - * Initialize a CoFactor element. + * Convert XML into a class instance * - * @param string $value + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong */ - public function __construct( - string $value, - ) { - $this->setContent($value); + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + Assert::numeric($xml->textContent); + + return new static(intval($xml->textContent)); + } + + + /** + * Convert this element to XML. + * + * @param \DOMElement|null $parent The element we should append this element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = strval($this->getValue()); + + return $e; } } diff --git a/tests/XML/dsig11/CoFactorTest.php b/tests/XML/dsig11/CoFactorTest.php index e13dcf72..4c698aad 100644 --- a/tests/XML/dsig11/CoFactorTest.php +++ b/tests/XML/dsig11/CoFactorTest.php @@ -42,7 +42,7 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $coFactor = new CoFactor('128'); + $coFactor = new CoFactor(128); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/dsig11/ECKeyValueTest.php b/tests/XML/dsig11/ECKeyValueTest.php index 65ccb80f..26866421 100644 --- a/tests/XML/dsig11/ECKeyValueTest.php +++ b/tests/XML/dsig11/ECKeyValueTest.php @@ -102,7 +102,7 @@ public function testMarshalling(): void $order = new Order('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); // Build CoFactor - $coFactor = new CoFactor('128'); + $coFactor = new CoFactor(128); // Build ValidationData $seed = new Seed('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); diff --git a/tests/XML/dsig11/ECParametersTest.php b/tests/XML/dsig11/ECParametersTest.php index e476464e..6db2411f 100644 --- a/tests/XML/dsig11/ECParametersTest.php +++ b/tests/XML/dsig11/ECParametersTest.php @@ -98,7 +98,7 @@ public function testMarshalling(): void $order = new Order('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); // Build CoFactor - $coFactor = new CoFactor('128'); + $coFactor = new CoFactor(128); // Build ValidationData $seed = new Seed('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); From 47ff852644e1198830e37c4915bb91b1a0089861 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 17:28:11 +0200 Subject: [PATCH 29/30] Refactor FieldIDType --- src/XML/dsig11/AbstractECKeyValueType.php | 2 +- src/XML/dsig11/AbstractFieldIDType.php | 89 ++++++++------------- src/XML/dsig11/FieldID.php | 34 ++++---- tests/XML/dsig11/ECKeyValueTest.php | 20 +---- tests/XML/dsig11/ECParametersTest.php | 24 +----- tests/XML/dsig11/FieldIDTest.php | 26 +----- tests/resources/xml/dsig11_ECKeyValue.xml | 11 --- tests/resources/xml/dsig11_ECParameters.xml | 13 --- tests/resources/xml/dsig11_FieldID.xml | 14 ---- 9 files changed, 51 insertions(+), 182 deletions(-) diff --git a/src/XML/dsig11/AbstractECKeyValueType.php b/src/XML/dsig11/AbstractECKeyValueType.php index 31f09018..aa1b624a 100644 --- a/src/XML/dsig11/AbstractECKeyValueType.php +++ b/src/XML/dsig11/AbstractECKeyValueType.php @@ -27,7 +27,7 @@ public function __construct( protected PublicKey $publicKey, protected ?string $id = null, protected ?ECParameters $ecParameters = null, - protected ?NamedCurve $ecParamOrNamedCurve = null, + protected ?NamedCurve $namedCurve = null, ) { Assert::validNCName($id, SchemaViolationException::class); Assert::oneOf( diff --git a/src/XML/dsig11/AbstractFieldIDType.php b/src/XML/dsig11/AbstractFieldIDType.php index 0e0bc154..cbbfd943 100644 --- a/src/XML/dsig11/AbstractFieldIDType.php +++ b/src/XML/dsig11/AbstractFieldIDType.php @@ -5,7 +5,12 @@ namespace SimpleSAML\XMLSecurity\XML\dsig11; use DOMElement; +use SimpleSAML\Assert\Assert; +use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Constants as C; +use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\ExtendableElementTrait; +use SimpleSAML\XML\SerializableElementInterface; use SimpleSAML\XML\XsNamespace as NS; /** @@ -15,7 +20,11 @@ */ abstract class AbstractFieldIDType extends AbstractDsig11Element { - use ExtendableElementTrait; + // We use our own getter instead of the trait's one, so we prevent their use by marking them private + use ExtendableElementTrait { + getElements as private; + setElements as private; + } /** @var \SimpleSAML\XML\XsNamespace */ public const XS_ANY_ELT_NAMESPACE = NS::OTHER; @@ -24,64 +33,39 @@ abstract class AbstractFieldIDType extends AbstractDsig11Element /** * Initialize a FieldIDType element. * - * @param \SimpleSAML\XMLSecurity\XML\dsig11\Prime $prime - * @param \SimpleSAML\XMLSecurity\XML\dsig11\TnB $tnb - * @param \SimpleSAML\XMLSecurity\XML\dsig11\PnB $pnb - * @param \SimpleSAML\XMLSecurity\XML\dsig11\GnB $gnb - * @param array<\SimpleSAML\XML\SerializableElementInterface> $children + * @param \SimpleSAML\XML\SerializableElementInterface $fieldId */ public function __construct( - protected Prime $prime, - protected TnB $tnb, - protected PnB $pnb, - protected GnB $gnb, - array $children, + protected Prime|TnB|PnB|GnB|SerializableElementInterface $fieldId, ) { - $this->setElements($children); + if ( + !($fieldId instanceof Prime + || $fieldId instanceof TnB + || $fieldId instanceof PnB + || $fieldId instanceof GnB) + ) { + Assert::true( + (($fieldId instanceof Chunk) ? $fieldId->getNamespaceURI() : $fieldId::getNameSpaceURI()) + !== C::NS_XDSIG11, + 'A requires either a Prime, TnB, PnB, GnB or an element in namespace ##other', + SchemaViolationException::class, + ); + } } /** - * Collect the value of the prime-property + * Collect the value of the fieldId-property * * @return \SimpleSAML\XMLSecurity\XML\dsig11\Prime + * \SimpleSAML\XMLSecurity\XML\dsig11\TnB + * \SimpleSAML\XMLSecurity\XML\dsig11\PnB + * \SimpleSAML\XMLSecurity\XML\dsig11\GnB + * \SimpleSAML\XML\SerializableElementInterface */ - public function getPrime(): Prime + public function getFieldId(): Prime|TnB|PnB|GnB|SerializableElementInterface { - return $this->prime; - } - - - /** - * Collect the value of the tnb-property - * - * @return \SimpleSAML\XMLSecurity\XML\dsig11\TnB - */ - public function getTnB(): TnB - { - return $this->tnb; - } - - - /** - * Collect the value of the pnb-property - * - * @return \SimpleSAML\XMLSecurity\XML\dsig11\PnB - */ - public function getPnB(): PnB - { - return $this->pnb; - } - - - /** - * Collect the value of the gnb-property - * - * @return \SimpleSAML\XMLSecurity\XML\dsig11\GnB - */ - public function getGnB(): GnB - { - return $this->gnb; + return $this->fieldId; } @@ -95,14 +79,7 @@ public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $this->getPrime()->toXML($e); - $this->getTnB()->toXML($e); - $this->getPnB()->toXML($e); - $this->getGnB()->toXML($e); - - foreach ($this->getElements() as $elt) { - $elt->toXML($e); - } + $this->getFieldId()->toXML($e); return $e; } diff --git a/src/XML/dsig11/FieldID.php b/src/XML/dsig11/FieldID.php index 25025234..0b431c71 100644 --- a/src/XML/dsig11/FieldID.php +++ b/src/XML/dsig11/FieldID.php @@ -7,7 +7,6 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; use SimpleSAML\XML\Exception\TooManyElementsException; use SimpleSAML\XML\SchemaValidatableElementInterface; use SimpleSAML\XML\SchemaValidatableElementTrait; @@ -35,28 +34,23 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); - $prime = Prime::getChildrenOfClass($xml); - Assert::minCount($prime, 1, MissingElementException::class); - Assert::maxCount($prime, 1, TooManyElementsException::class); - - $tnb = TnB::getChildrenOfClass($xml); - Assert::minCount($tnb, 1, MissingElementException::class); - Assert::maxCount($tnb, 1, TooManyElementsException::class); - - $pnb = PnB::getChildrenOfClass($xml); - Assert::minCount($pnb, 1, MissingElementException::class); - Assert::maxCount($pnb, 1, TooManyElementsException::class); + $fieldId = array_merge( + Prime::getChildrenOfClass($xml), + TnB::getChildrenOfClass($xml), + PnB::getChildrenOfClass($xml), + GnB::getChildrenOfClass($xml), + self::getChildElementsFromXML($xml), + ); - $gnb = GnB::getChildrenOfClass($xml); - Assert::minCount($gnb, 1, MissingElementException::class); - Assert::maxCount($gnb, 1, TooManyElementsException::class); + Assert::count( + $fieldId, + 1, + 'A must contain exactly one child element', + TooManyElementsException::class, + ); return new static( - array_pop($prime), - array_pop($tnb), - array_pop($pnb), - array_pop($gnb), - self::getChildElementsFromXML($xml), + array_pop($fieldId), ); } } diff --git a/tests/XML/dsig11/ECKeyValueTest.php b/tests/XML/dsig11/ECKeyValueTest.php index 26866421..516af023 100644 --- a/tests/XML/dsig11/ECKeyValueTest.php +++ b/tests/XML/dsig11/ECKeyValueTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; @@ -21,19 +20,14 @@ use SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue; use SimpleSAML\XMLSecurity\XML\dsig11\ECParameters; use SimpleSAML\XMLSecurity\XML\dsig11\FieldID; -use SimpleSAML\XMLSecurity\XML\dsig11\GnB; -use SimpleSAML\XMLSecurity\XML\dsig11\K; use SimpleSAML\XMLSecurity\XML\dsig11\K1; use SimpleSAML\XMLSecurity\XML\dsig11\K2; use SimpleSAML\XMLSecurity\XML\dsig11\K3; use SimpleSAML\XMLSecurity\XML\dsig11\M; use SimpleSAML\XMLSecurity\XML\dsig11\Order; -use SimpleSAML\XMLSecurity\XML\dsig11\P; use SimpleSAML\XMLSecurity\XML\dsig11\PnB; -use SimpleSAML\XMLSecurity\XML\dsig11\Prime; use SimpleSAML\XMLSecurity\XML\dsig11\PublicKey; use SimpleSAML\XMLSecurity\XML\dsig11\Seed; -use SimpleSAML\XMLSecurity\XML\dsig11\TnB; use SimpleSAML\XMLSecurity\XML\dsig11\ValidationData; use function dirname; @@ -70,25 +64,13 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { // Build FieldID - $p = new P('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); - $prime = new Prime($p); - $m = new M(1024); - $k = new K(64); - $tnb = new TnB($m, $k); - $k1 = new K1(128); $k2 = new K2(256); $k3 = new K3(512); $pnb = new PnB($m, $k1, $k2, $k3); - $gnb = new GnB($m); - - $chunk = new Chunk(DOMDocumentFactory::fromString( - 'some', - )->documentElement); - - $fieldId = new FieldID($prime, $tnb, $pnb, $gnb, [$chunk]); + $fieldId = new FieldID($pnb); // Build Curve $a = new A('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); diff --git a/tests/XML/dsig11/ECParametersTest.php b/tests/XML/dsig11/ECParametersTest.php index 6db2411f..7cc5e540 100644 --- a/tests/XML/dsig11/ECParametersTest.php +++ b/tests/XML/dsig11/ECParametersTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Constants as C; @@ -19,16 +18,9 @@ use SimpleSAML\XMLSecurity\XML\dsig11\Curve; use SimpleSAML\XMLSecurity\XML\dsig11\ECParameters; use SimpleSAML\XMLSecurity\XML\dsig11\FieldID; -use SimpleSAML\XMLSecurity\XML\dsig11\GnB; use SimpleSAML\XMLSecurity\XML\dsig11\K; -use SimpleSAML\XMLSecurity\XML\dsig11\K1; -use SimpleSAML\XMLSecurity\XML\dsig11\K2; -use SimpleSAML\XMLSecurity\XML\dsig11\K3; use SimpleSAML\XMLSecurity\XML\dsig11\M; use SimpleSAML\XMLSecurity\XML\dsig11\Order; -use SimpleSAML\XMLSecurity\XML\dsig11\P; -use SimpleSAML\XMLSecurity\XML\dsig11\PnB; -use SimpleSAML\XMLSecurity\XML\dsig11\Prime; use SimpleSAML\XMLSecurity\XML\dsig11\Seed; use SimpleSAML\XMLSecurity\XML\dsig11\TnB; use SimpleSAML\XMLSecurity\XML\dsig11\ValidationData; @@ -66,25 +58,11 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { // Build FieldID - $p = new P('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); - $prime = new Prime($p); - $m = new M(1024); $k = new K(64); $tnb = new TnB($m, $k); - $k1 = new K1(128); - $k2 = new K2(256); - $k3 = new K3(512); - $pnb = new PnB($m, $k1, $k2, $k3); - - $gnb = new GnB($m); - - $chunk = new Chunk(DOMDocumentFactory::fromString( - 'some', - )->documentElement); - - $fieldId = new FieldID($prime, $tnb, $pnb, $gnb, [$chunk]); + $fieldId = new FieldID($tnb); // Build Curve $a = new A('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); diff --git a/tests/XML/dsig11/FieldIDTest.php b/tests/XML/dsig11/FieldIDTest.php index 7b72eca2..35cf08f3 100644 --- a/tests/XML/dsig11/FieldIDTest.php +++ b/tests/XML/dsig11/FieldIDTest.php @@ -6,22 +6,13 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element; use SimpleSAML\XMLSecurity\XML\dsig11\AbstractFieldIDType; use SimpleSAML\XMLSecurity\XML\dsig11\FieldID; -use SimpleSAML\XMLSecurity\XML\dsig11\GnB; -use SimpleSAML\XMLSecurity\XML\dsig11\K; -use SimpleSAML\XMLSecurity\XML\dsig11\K1; -use SimpleSAML\XMLSecurity\XML\dsig11\K2; -use SimpleSAML\XMLSecurity\XML\dsig11\K3; -use SimpleSAML\XMLSecurity\XML\dsig11\M; use SimpleSAML\XMLSecurity\XML\dsig11\P; -use SimpleSAML\XMLSecurity\XML\dsig11\PnB; use SimpleSAML\XMLSecurity\XML\dsig11\Prime; -use SimpleSAML\XMLSecurity\XML\dsig11\TnB; use function dirname; use function strval; @@ -58,22 +49,7 @@ public function testMarshalling(): void $p = new P('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); $prime = new Prime($p); - $m = new M(1024); - $k = new K(64); - $tnb = new TnB($m, $k); - - $k1 = new K1(128); - $k2 = new K2(256); - $k3 = new K3(512); - $pnb = new PnB($m, $k1, $k2, $k3); - - $gnb = new GnB($m); - - $chunk = new Chunk(DOMDocumentFactory::fromString( - 'some', - )->documentElement); - - $fieldId = new FieldID($prime, $tnb, $pnb, $gnb, [$chunk]); + $fieldId = new FieldID($prime); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/resources/xml/dsig11_ECKeyValue.xml b/tests/resources/xml/dsig11_ECKeyValue.xml index b6ba3caa..b99609cb 100644 --- a/tests/resources/xml/dsig11_ECKeyValue.xml +++ b/tests/resources/xml/dsig11_ECKeyValue.xml @@ -1,23 +1,12 @@ - - 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= - - - 1024 - 64 - 1024 128 256 512 - - 1024 - - some 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= diff --git a/tests/resources/xml/dsig11_ECParameters.xml b/tests/resources/xml/dsig11_ECParameters.xml index 89e8ddc4..97c00181 100644 --- a/tests/resources/xml/dsig11_ECParameters.xml +++ b/tests/resources/xml/dsig11_ECParameters.xml @@ -1,22 +1,9 @@ - - 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= - 1024 64 - - 1024 - 128 - 256 - 512 - - - 1024 - - some 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= diff --git a/tests/resources/xml/dsig11_FieldID.xml b/tests/resources/xml/dsig11_FieldID.xml index 2503395d..ac8f688d 100644 --- a/tests/resources/xml/dsig11_FieldID.xml +++ b/tests/resources/xml/dsig11_FieldID.xml @@ -2,18 +2,4 @@ 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= - - 1024 - 64 - - - 1024 - 128 - 256 - 512 - - - 1024 - - some From 82423d96aef67ea4ad0d6d964aa976700a4abe58 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 9 Jun 2025 17:53:36 +0200 Subject: [PATCH 30/30] Fix last minor issues --- phpstan-baseline.neon | 11 +++++++++++ phpstan.neon | 2 ++ src/XML/ds/KeyValue.php | 4 ++-- src/XML/dsig11/AbstractECKeyValueType.php | 2 +- src/XML/dsig11/AbstractFieldIDType.php | 12 ++++++------ 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 phpstan-baseline.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 00000000..d869f67e --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,11 @@ +parameters: + ignoreErrors: + - + message: "#^Call to an undefined static method SimpleSAML\\\\XML\\\\SerializableElementInterface\\:\\:getNameSpaceURI\\(\\)\\.$#" + count: 1 + path: src/XML/ds/KeyValue.php + + - + message: "#^Call to an undefined static method SimpleSAML\\\\XML\\\\SerializableElementInterface\\:\\:getNameSpaceURI\\(\\)\\.$#" + count: 1 + path: src/XML/dsig11/AbstractFieldIDType.php diff --git a/phpstan.neon b/phpstan.neon index db37782f..e266e4a4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,3 +2,5 @@ parameters: level: 6 paths: - src +includes: + - phpstan-baseline.neon diff --git a/src/XML/ds/KeyValue.php b/src/XML/ds/KeyValue.php index b59d90ef..01d85e53 100644 --- a/src/XML/ds/KeyValue.php +++ b/src/XML/ds/KeyValue.php @@ -67,10 +67,10 @@ final public function __construct( /** * Collect the value of the RSAKeyValue-property * - * @return \SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue| + * @return (\SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue| * \SimpleSAML\XMLSecurity\XML\ds\DSAKeyValue| * \SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue| - * \SimpeSAML\XML\SerializableElementInterface + * \SimpleSAML\XML\SerializableElementInterface) */ public function getKeyValue(): RSAKeyValue|DSAKeyValue|ECKeyValue|SerializableElementInterface { diff --git a/src/XML/dsig11/AbstractECKeyValueType.php b/src/XML/dsig11/AbstractECKeyValueType.php index aa1b624a..13a65fea 100644 --- a/src/XML/dsig11/AbstractECKeyValueType.php +++ b/src/XML/dsig11/AbstractECKeyValueType.php @@ -77,7 +77,7 @@ public function getPublicKey(): PublicKey * * @return string|null */ - public function getId(): string + public function getId(): ?string { return $this->id; } diff --git a/src/XML/dsig11/AbstractFieldIDType.php b/src/XML/dsig11/AbstractFieldIDType.php index cbbfd943..cc15ede9 100644 --- a/src/XML/dsig11/AbstractFieldIDType.php +++ b/src/XML/dsig11/AbstractFieldIDType.php @@ -7,11 +7,11 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\Constants as C; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\ExtendableElementTrait; use SimpleSAML\XML\SerializableElementInterface; use SimpleSAML\XML\XsNamespace as NS; +use SimpleSAML\XMLSecurity\Constants as C; /** * Abstract class representing a dsig11:FieldIDType @@ -57,11 +57,11 @@ public function __construct( /** * Collect the value of the fieldId-property * - * @return \SimpleSAML\XMLSecurity\XML\dsig11\Prime - * \SimpleSAML\XMLSecurity\XML\dsig11\TnB - * \SimpleSAML\XMLSecurity\XML\dsig11\PnB - * \SimpleSAML\XMLSecurity\XML\dsig11\GnB - * \SimpleSAML\XML\SerializableElementInterface + * @return (\SimpleSAML\XMLSecurity\XML\dsig11\Prime| + * \SimpleSAML\XMLSecurity\XML\dsig11\TnB| + * \SimpleSAML\XMLSecurity\XML\dsig11\PnB| + * \SimpleSAML\XMLSecurity\XML\dsig11\GnB| + * \SimpleSAML\XML\SerializableElementInterface) */ public function getFieldId(): Prime|TnB|PnB|GnB|SerializableElementInterface {