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/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/ds/KeyValue.php b/src/XML/ds/KeyValue.php index 7fba8cc6..01d85e53 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| + * \SimpleSAML\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/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/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/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/AbstractECKeyValueType.php b/src/XML/dsig11/AbstractECKeyValueType.php new file mode 100644 index 00000000..13a65fea --- /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/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/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/AbstractFieldIDType.php b/src/XML/dsig11/AbstractFieldIDType.php new file mode 100644 index 00000000..cc15ede9 --- /dev/null +++ b/src/XML/dsig11/AbstractFieldIDType.php @@ -0,0 +1,86 @@ +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 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 getFieldId(): Prime|TnB|PnB|GnB|SerializableElementInterface + { + return $this->fieldId; + } + + + /** + * 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->getFieldId()->toXML($e); + + return $e; + } +} 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/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/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/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/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/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/src/XML/dsig11/CoFactor.php b/src/XML/dsig11/CoFactor.php new file mode 100644 index 00000000..c1741c6e --- /dev/null +++ b/src/XML/dsig11/CoFactor.php @@ -0,0 +1,73 @@ +value; + } + + + /** + * 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->getValue()); + + 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/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/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/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/src/XML/dsig11/FieldID.php b/src/XML/dsig11/FieldID.php new file mode 100644 index 00000000..0b431c71 --- /dev/null +++ b/src/XML/dsig11/FieldID.php @@ -0,0 +1,56 @@ +localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); + + $fieldId = array_merge( + Prime::getChildrenOfClass($xml), + TnB::getChildrenOfClass($xml), + PnB::getChildrenOfClass($xml), + GnB::getChildrenOfClass($xml), + self::getChildElementsFromXML($xml), + ); + + Assert::count( + $fieldId, + 1, + 'A must contain exactly one child element', + TooManyElementsException::class, + ); + + return new static( + array_pop($fieldId), + ); + } +} 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/src/XML/dsig11/K.php b/src/XML/dsig11/K.php new file mode 100644 index 00000000..7bf3cac6 --- /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/src/XML/dsig11/K1.php b/src/XML/dsig11/K1.php new file mode 100644 index 00000000..51364a78 --- /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/src/XML/dsig11/K2.php b/src/XML/dsig11/K2.php new file mode 100644 index 00000000..8cb56613 --- /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/src/XML/dsig11/K3.php b/src/XML/dsig11/K3.php new file mode 100644 index 00000000..9cf92713 --- /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/src/XML/dsig11/M.php b/src/XML/dsig11/M.php new file mode 100644 index 00000000..ec429082 --- /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/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/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/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/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/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/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/src/XML/dsig11/Seed.php b/src/XML/dsig11/Seed.php new file mode 100644 index 00000000..fda47836 --- /dev/null +++ b/src/XML/dsig11/Seed.php @@ -0,0 +1,32 @@ +setContent($value); + } +} 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/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/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/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); 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/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/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/XML/dsig11/CoFactorTest.php b/tests/XML/dsig11/CoFactorTest.php new file mode 100644 index 00000000..4c698aad --- /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/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/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/XML/dsig11/ECKeyValueTest.php b/tests/XML/dsig11/ECKeyValueTest.php new file mode 100644 index 00000000..516af023 --- /dev/null +++ b/tests/XML/dsig11/ECKeyValueTest.php @@ -0,0 +1,107 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($ecKeyValue), + ); + } +} diff --git a/tests/XML/dsig11/ECParametersTest.php b/tests/XML/dsig11/ECParametersTest.php new file mode 100644 index 00000000..7cc5e540 --- /dev/null +++ b/tests/XML/dsig11/ECParametersTest.php @@ -0,0 +1,93 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($ecParameters), + ); + } +} diff --git a/tests/XML/dsig11/FieldIDTest.php b/tests/XML/dsig11/FieldIDTest.php new file mode 100644 index 00000000..35cf08f3 --- /dev/null +++ b/tests/XML/dsig11/FieldIDTest.php @@ -0,0 +1,59 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($fieldId), + ); + } +} 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/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/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/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/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/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/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/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/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/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/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/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/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/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/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_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= 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= 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= 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 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= + 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= diff --git a/tests/resources/xml/dsig11_ECKeyValue.xml b/tests/resources/xml/dsig11_ECKeyValue.xml new file mode 100644 index 00000000..b99609cb --- /dev/null +++ b/tests/resources/xml/dsig11_ECKeyValue.xml @@ -0,0 +1,23 @@ + + + + + 1024 + 128 + 256 + 512 + + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 128 + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + diff --git a/tests/resources/xml/dsig11_ECParameters.xml b/tests/resources/xml/dsig11_ECParameters.xml new file mode 100644 index 00000000..97c00181 --- /dev/null +++ b/tests/resources/xml/dsig11_ECParameters.xml @@ -0,0 +1,18 @@ + + + + 1024 + 64 + + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + 128 + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + diff --git a/tests/resources/xml/dsig11_FieldID.xml b/tests/resources/xml/dsig11_FieldID.xml new file mode 100644 index 00000000..ac8f688d --- /dev/null +++ b/tests/resources/xml/dsig11_FieldID.xml @@ -0,0 +1,5 @@ + + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + + 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 + 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 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 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 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 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 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 @@ + 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= 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= 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 + 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= + 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= diff --git a/tests/resources/xml/dsig11_Seed.xml b/tests/resources/xml/dsig11_Seed.xml new file mode 100644 index 00000000..2c4a864d --- /dev/null +++ b/tests/resources/xml/dsig11_Seed.xml @@ -0,0 +1 @@ +6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= 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 + diff --git a/tests/resources/xml/dsig11_ValidationData.xml b/tests/resources/xml/dsig11_ValidationData.xml new file mode 100644 index 00000000..c1723176 --- /dev/null +++ b/tests/resources/xml/dsig11_ValidationData.xml @@ -0,0 +1,3 @@ + + 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= +