Skip to content

Commit 764a2a7

Browse files
committed
Strip element registry of any non top-level elements
1 parent 9401bac commit 764a2a7

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

src/XML/element.registry.php

+13-17
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,50 @@
77
'CanonicalizationMethod' => '\SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod',
88
'DigestMethod' => '\SimpleSAML\XMLSecurity\XML\ds\DigestMethod',
99
'DigestValue' => '\SimpleSAML\XMLSecurity\XML\ds\DigestValue',
10-
'Exponent' => '\SimpleSAML\XMLSecurity\XML\ds\Exponent',
10+
// 'DSAKeyValue' => '\SimpleSAML\XMLSecurity\XML\ds\DSAKeyValue',
1111
'KeyInfo' => '\SimpleSAML\XMLSecurity\XML\ds\KeyInfo',
1212
'KeyName' => '\SimpleSAML\XMLSecurity\XML\ds\KeyName',
1313
'KeyValue' => '\SimpleSAML\XMLSecurity\XML\ds\KeyValue',
1414
'Manifest' => '\SimpleSAML\XMLSecurity\XML\ds\Manifest',
15-
'Modulus' => '\SimpleSAML\XMLSecurity\XML\ds\Modulus',
15+
// 'MgmtData' => '\SimpleSAML\XMLSecurity\XML\ds\MgmtData',
1616
'Object' => '\SimpleSAML\XMLSecurity\XML\ds\DsObject',
17-
'RSAKeyValue' => '\SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue',
17+
// 'PGPData' => '\SimpleSAML\XMLSecurity\XML\ds\PGPData',
1818
'Reference' => '\SimpleSAML\XMLSecurity\XML\ds\Reference',
1919
'RetrievalMethod' => '\SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod',
20+
'RSAKeyValue' => '\SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue',
2021
'Signature' => '\SimpleSAML\XMLSecurity\XML\ds\Signature',
2122
'SignatureMethod' => '\SimpleSAML\XMLSecurity\XML\ds\SignatureMethod',
2223
'SignatureProperties' => '\SimpleSAML\XMLSecurity\XML\ds\SignatureProperties',
2324
'SignatureProperty' => '\SimpleSAML\XMLSecurity\XML\ds\SignatureProperty',
2425
'SignatureValue' => '\SimpleSAML\XMLSecurity\XML\ds\SignatureValue',
2526
'SignedInfo' => '\SimpleSAML\XMLSecurity\XML\ds\SignedInfo',
27+
// 'SPKIData' => '\SimpleSAML\XMLSecurity\XML\ds\SPKIData',
2628
'Transform' => '\SimpleSAML\XMLSecurity\XML\ds\Transform',
2729
'Transforms' => '\SimpleSAML\XMLSecurity\XML\ds\Transforms',
28-
'X509Certificate' => '\SimpleSAML\XMLSecurity\XML\ds\X509Certificate',
2930
'X509Data' => '\SimpleSAML\XMLSecurity\XML\ds\X509Data',
30-
'X509IssuerName' => '\SimpleSAML\XMLSecurity\XML\ds\X509IssuerName',
31-
'X509IssuerSerial' => '\SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial',
32-
'X509SerialNumber' => '\SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber',
33-
'X509SubjectName' => '\SimpleSAML\XMLSecurity\XML\ds\X509SubjectName',
34-
'XPath' => '\SimpleSAML\XMLSecurity\XML\ds\XPath',
3531
],
3632
'http://www.w3.org/2009/xmldsig11#' => [
33+
// 'DEREncodedKeyValue' => '\SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue',
34+
// 'ECKeyValue' => '\SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue',
35+
// 'GnB' => '\SimpleSAML\XMLSecurity\XML\dsig11\GnB',
3736
'KeyInfoReference' => '\SimpleSAML\XMLSecurity\XML\dsig11\KeyInfoReference',
37+
// 'PnB' => '\SimpleSAML\XMLSecurity\XML\dsig11\PnB',
38+
// 'Prime' => '\SimpleSAML\XMLSecurity\XML\dsig11\Prime',
39+
// 'TnB' => '\SimpleSAML\XMLSecurity\XML\dsig11\TnB',
3840
'X509Digest' => '\SimpleSAML\XMLSecurity\XML\dsig11\X509Digest',
3941
],
4042
'http://www.w3.org/2001/10/xml-exc-c14n#' => [
4143
'InclusiveNamespaces' => '\SimpleSAML\XMLSecurity\XML\ec\InclusiveNamespaces',
4244
],
4345
'http://www.w3.org/2001/04/xmlenc#' => [
44-
'CarriedKeyName' => '\SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName',
46+
// 'AgreementMethod' => '\SimpleSAML\XMLSecurity\XML\xenc\AgreementMethod',
4547
'CipherData' => '\SimpleSAML\XMLSecurity\XML\xenc\CipherData',
4648
'CipherReference' => '\SimpleSAML\XMLSecurity\XML\xenc\CipherReference',
47-
'CipherValue' => '\SimpleSAML\XMLSecurity\XML\xenc\CipherValue',
48-
'DataReference' => '\SimpleSAML\XMLSecurity\XML\xenc\DataReference',
49+
// 'DHKeyValue' => '\SimpleSAML\XMLSecurity\XML\xenc\DHKeyValue',
4950
'EncryptedData' => '\SimpleSAML\XMLSecurity\XML\xenc\EncryptedData',
5051
'EncryptedKey' => '\SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey',
51-
'EncryptionMethod' => '\SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod',
5252
'EncryptionProperties' => '\SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperties',
5353
'EncryptionProperty' => '\SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty',
54-
'KeyReference' => '\SimpleSAML\XMLSecurity\XML\xenc\KeyReference',
55-
'KeySize' => '\SimpleSAML\XMLSecurity\XML\xenc\KeySize',
56-
'OAEPparams' => '\SimpleSAML\XMLSecurity\XML\xenc\OAEPparams',
5754
'ReferenceList' => '\SimpleSAML\XMLSecurity\XML\xenc\ReferenceList',
58-
'Transforms' => '\SimpleSAML\XMLSecurity\XML\xenc\Transforms',
5955
],
6056
];

tests/XML/ds/KeyValueTest.php

+10-13
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
use DOMDocument;
88
use PHPUnit\Framework\Attributes\CoversClass;
99
use PHPUnit\Framework\TestCase;
10-
use SimpleSAML\XML\Chunk;
1110
use SimpleSAML\XML\DOMDocumentFactory;
1211
use SimpleSAML\XML\Exception\SchemaViolationException;
1312
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
1413
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
1514
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
1615
use SimpleSAML\XMLSecurity\XML\ds\KeyValue;
1716
use SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue;
18-
use SimpleSAML\XMLSecurity\XML\xenc\CipherValue;
17+
use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty;
1918

2019
use function dirname;
2120
use function strval;
@@ -39,8 +38,8 @@ final class KeyValueTest extends TestCase
3938
/** @var \DOMDocument $rsaKeyValue */
4039
protected static DOMDocument $rsaKeyValue;
4140

42-
/** @var \DOMDocument $cipherValue */
43-
protected static DOMDocument $cipherValue;
41+
/** @var \DOMDocument $encryptionProperty */
42+
protected static DOMDocument $encryptionProperty;
4443

4544

4645
/**
@@ -61,8 +60,8 @@ protected function setUp(): void
6160
dirname(__FILE__, 3) . '/resources/xml/ds_RSAKeyValue.xml',
6261
);
6362

64-
self::$cipherValue = DOMDocumentFactory::fromFile(
65-
dirname(__FILE__, 3) . '/resources/xml/xenc_CipherValue.xml',
63+
self::$encryptionProperty = DOMDocumentFactory::fromFile(
64+
dirname(__FILE__, 3) . '/resources/xml/xenc_EncryptionProperty.xml',
6665
);
6766
}
6867

@@ -91,18 +90,17 @@ public function testMarshalling(): void
9190
*/
9291
public function testMarshallingWithOtherElement(): void
9392
{
94-
$keyValue = new KeyValue(null, Chunk::fromXML(self::$cipherValue->documentElement));
93+
$keyValue = new KeyValue(null, EncryptionProperty::fromXML(self::$encryptionProperty->documentElement));
9594

9695
$elements = $keyValue->getElements();
9796
$this->assertEmpty($keyValue->getRSAKeyValue());
9897
$this->assertCount(1, $elements);
9998

10099
$element = reset($elements);
101-
$this->assertInstanceOf(Chunk::class, $element);
102-
$this->assertEquals($element->getXML()->textContent, '/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
100+
$this->assertInstanceOf(EncryptionProperty::class, $element);
103101

104102
$document = self::$empty;
105-
$document->documentElement->appendChild($document->importNode(self::$cipherValue->documentElement, true));
103+
$element->toXML($document->documentElement);
106104

107105
$this->assertXmlStringEqualsXmlString($document->saveXML($document->documentElement), strval($keyValue));
108106
}
@@ -126,7 +124,7 @@ public function testMarshallingEmpty(): void
126124
public function testUnmarshallingWithOtherElement(): void
127125
{
128126
$document = self::$empty;
129-
$document->documentElement->appendChild($document->importNode(self::$cipherValue->documentElement, true));
127+
$document->documentElement->appendChild($document->importNode(self::$encryptionProperty->documentElement, true));
130128

131129
$keyValue = KeyValue::fromXML($document->documentElement);
132130

@@ -135,8 +133,7 @@ public function testUnmarshallingWithOtherElement(): void
135133
$this->assertCount(1, $elements);
136134

137135
$element = reset($elements);
138-
$this->assertInstanceOf(CipherValue::class, $element);
139-
$this->assertEquals($element->getContent(), '/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
136+
$this->assertInstanceOf(EncryptionProperty::class, $element);
140137
}
141138

142139

0 commit comments

Comments
 (0)