Skip to content

Commit 7bcc2b7

Browse files
authored
Add missing dsig11-elements (#64)
* Add dsig11:DEREncodedKeyValue * Add dsig11:P * Add dsig11:A-element * Add dsig11:B-element * Add dsig11:Prime-element * Add Seed-element * Add dsig11:Order-element * Add K1-element * Add K2-element * Add K3-element * Add K-element * Add M-element * Add dsig11:GnB-element * Add dsig11:TnB-element * Add dsig11:PnB-element * Add dsig11:ValidationData-element * Add dsig11:Base-element * Add dsig11:PublicKey-element * Add dsig11:Curve-element * Add dsig11:FieldID-element * Add dsig11:NamedCurve-element * Add dsig11:CoFactor-element * Fix typo: s/xenc/dsig11 * Add dsig11:ECParameters-element * Add dsig11:ECKeyValue-element * Refactor ds:KeyValue * Fix Seed-element lowercase name * Refactor CoFactor-element to native integer * Refactor FieldIDType * Fix last minor issues
1 parent a7f2e09 commit 7bcc2b7

File tree

90 files changed

+3610
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3610
-66
lines changed

phpstan-baseline.neon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Call to an undefined static method SimpleSAML\\\\XML\\\\SerializableElementInterface\\:\\:getNameSpaceURI\\(\\)\\.$#"
5+
count: 1
6+
path: src/XML/ds/KeyValue.php
7+
8+
-
9+
message: "#^Call to an undefined static method SimpleSAML\\\\XML\\\\SerializableElementInterface\\:\\:getNameSpaceURI\\(\\)\\.$#"
10+
count: 1
11+
path: src/XML/dsig11/AbstractFieldIDType.php

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ parameters:
22
level: 6
33
paths:
44
- src
5+
includes:
6+
- phpstan-baseline.neon

src/Constants.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,12 @@ class Constants extends \SimpleSAML\XML\Constants
144144
*/
145145
public const NS_XDSIG = 'http://www.w3.org/2000/09/xmldsig#';
146146
public const NS_XDSIG11 = 'http://www.w3.org/2009/xmldsig11#';
147+
147148
public const XMLDSIG_ENVELOPED = 'http://www.w3.org/2000/09/xmldsig#enveloped-signature';
148149
public const XMLDSIG_MANIFEST = 'http://www.w3.org/2000/09/xmldsig#Manifest';
149150

151+
public const XMLDSIG11_DER_ENCODED_KEY_VALUE = 'https://www.w3.org/2009/xmldsig11#DEREncodedKeyValue';
152+
150153
public const NS_XENC = 'http://www.w3.org/2001/04/xmlenc#';
151154
public const NS_XENC11 = 'http://www.w3.org/2009/xmlenc11#';
152155
public const XMLENC_CONTENT = 'http://www.w3.org/2001/04/xmlenc#Content';

src/XML/ds/AbstractKeyInfoType.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use SimpleSAML\XMLSecurity\Assert\Assert;
1313
use SimpleSAML\XMLSecurity\Constants as C;
1414
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
15-
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
15+
use SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element;
16+
use SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue;
1617

1718
/**
1819
* Abstract class representing the KeyInfoType.
@@ -38,6 +39,7 @@ abstract class AbstractKeyInfoType extends AbstractDsElement
3839
* \SimpleSAML\XMLSecurity\XML\ds\PGPData|
3940
* \SimpleSAML\XMLSecurity\XML\ds\SPKIData|
4041
* \SimpleSAML\XMLSecurity\XML\ds\MgmtData|
42+
* \SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue|
4143
* \SimpleSAML\XML\SerializableElementInterface
4244
* )[] $info
4345
* @param string|null $Id
@@ -78,6 +80,14 @@ final public function __construct(
7880
],
7981
SchemaViolationException::class,
8082
);
83+
} elseif ($item instanceof AbstractDsig11Element) {
84+
Assert::isInstanceOfAny(
85+
$item,
86+
[
87+
DEREncodedKeyValue::class,
88+
],
89+
SchemaViolationException::class,
90+
);
8191
}
8292
}
8393
}

src/XML/ds/KeyInfo.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\SchemaValidatableElementInterface;
11-
use SimpleSAML\XML\SchemaValidatableElementTrait;
10+
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
11+
use SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue;
1212

1313
use function array_merge;
1414

@@ -44,6 +44,7 @@ public static function fromXML(DOMElement $xml): static
4444
$pgpData = PGPData::getChildrenOfClass($xml);
4545
$spkiData = SPKIData::getChildrenOfClass($xml);
4646
$mgmtData = MgmtData::getChildrenOfClass($xml);
47+
$derEncodedKeyValue = DEREncodedKeyValue::getChildrenOfClass($xml);
4748
$other = self::getChildElementsFromXML($xml);
4849

4950
$info = array_merge(
@@ -54,6 +55,7 @@ public static function fromXML(DOMElement $xml): static
5455
$pgpData,
5556
$spkiData,
5657
$mgmtData,
58+
$derEncodedKeyValue,
5759
$other,
5860
);
5961

src/XML/ds/KeyValue.php

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66

77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
9-
use SimpleSAML\XML\ElementInterface;
9+
use SimpleSAML\XML\Chunk;
1010
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1111
use SimpleSAML\XML\Exception\SchemaViolationException;
1212
use SimpleSAML\XML\Exception\TooManyElementsException;
1313
use SimpleSAML\XML\ExtendableElementTrait;
1414
use SimpleSAML\XML\SchemaValidatableElementInterface;
1515
use SimpleSAML\XML\SchemaValidatableElementTrait;
16+
use SimpleSAML\XML\SerializableElementInterface;
1617
use SimpleSAML\XML\XsNamespace as NS;
18+
use SimpleSAML\XMLSecurity\Constants as C;
19+
use SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue;
20+
21+
use function array_merge;
22+
use function array_pop;
1723

1824
/**
1925
* Class representing a ds:KeyValue element.
@@ -22,7 +28,11 @@
2228
*/
2329
final class KeyValue extends AbstractDsElement implements SchemaValidatableElementInterface
2430
{
25-
use ExtendableElementTrait;
31+
// We use our own getter instead of the trait's one, so we prevent their use by marking them private
32+
use ExtendableElementTrait {
33+
getElements as private;
34+
setElements as private;
35+
}
2636
use SchemaValidatableElementTrait;
2737

2838

@@ -33,33 +43,38 @@ final class KeyValue extends AbstractDsElement implements SchemaValidatableEleme
3343
/**
3444
* Initialize an KeyValue.
3545
*
36-
* @param \SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue|null $RSAKeyValue
37-
* @param \SimpleSAML\XML\SerializableElementInterface|null $element
46+
* @param \SimpleSAML\XML\SerializableElementInterface $keyValue
3847
*/
3948
final public function __construct(
40-
protected ?RSAKeyValue $RSAKeyValue,
41-
?ElementInterface $element = null,
49+
protected RSAKeyValue|DSAKeyValue|ECKeyValue|SerializableElementInterface $keyValue,
4250
) {
43-
Assert::false(
44-
is_null($RSAKeyValue) && is_null($element),
45-
'A <ds:KeyValue> requires either a RSAKeyValue or an element in namespace ##other',
46-
SchemaViolationException::class,
47-
);
48-
49-
if ($element !== null) {
50-
$this->setElements([$element]);
51+
if (
52+
!($keyValue instanceof RSAKeyValue
53+
|| $keyValue instanceof DSAKeyValue
54+
|| $keyValue instanceof ECKeyValue)
55+
) {
56+
Assert::true(
57+
(($keyValue instanceof Chunk) ? $keyValue->getNamespaceURI() : $keyValue::getNameSpaceURI())
58+
!== C::NS_XDSIG,
59+
'A <ds:KeyValue> requires either a RSAKeyValue, DSAKeyValue, ECKeyValue '
60+
. 'or an element in namespace ##other',
61+
SchemaViolationException::class,
62+
);
5163
}
5264
}
5365

5466

5567
/**
5668
* Collect the value of the RSAKeyValue-property
5769
*
58-
* @return \SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue|null
70+
* @return (\SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue|
71+
* \SimpleSAML\XMLSecurity\XML\ds\DSAKeyValue|
72+
* \SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue|
73+
* \SimpleSAML\XML\SerializableElementInterface)
5974
*/
60-
public function getRSAKeyValue(): ?RSAKeyValue
75+
public function getKeyValue(): RSAKeyValue|DSAKeyValue|ECKeyValue|SerializableElementInterface
6176
{
62-
return $this->RSAKeyValue;
77+
return $this->keyValue;
6378
}
6479

6580

@@ -77,23 +92,20 @@ public static function fromXML(DOMElement $xml): static
7792
Assert::same($xml->localName, 'KeyValue', InvalidDOMElementException::class);
7893
Assert::same($xml->namespaceURI, KeyValue::NS, InvalidDOMElementException::class);
7994

80-
$RSAKeyValue = RSAKeyValue::getChildrenOfClass($xml);
81-
Assert::maxCount(
82-
$RSAKeyValue,
83-
1,
84-
'A <ds:KeyValue> can contain exactly one <ds:RSAKeyValue>',
85-
TooManyElementsException::class,
95+
$keyValue = array_merge(
96+
RSAKeyValue::getChildrenOfClass($xml),
97+
DSAKeyValue::getChildrenOfClass($xml),
98+
self::getChildElementsFromXML($xml),
8699
);
87100

88-
$elements = self::getChildElementsFromXML($xml);
89-
Assert::maxCount(
90-
$elements,
101+
Assert::count(
102+
$keyValue,
91103
1,
92-
'A <ds:KeyValue> can contain exactly one element in namespace ##other',
104+
'A <ds:KeyValue> must contain exactly one child element',
93105
TooManyElementsException::class,
94106
);
95107

96-
return new static(array_pop($RSAKeyValue), array_pop($elements));
108+
return new static(array_pop($keyValue));
97109
}
98110

99111

@@ -107,13 +119,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
107119
{
108120
$e = $this->instantiateParentElement($parent);
109121

110-
$this->getRSAKeyValue()?->toXML($e);
111-
112-
foreach ($this->elements as $elt) {
113-
if (!$elt->isEmptyElement()) {
114-
$elt->toXML($e);
115-
}
116-
}
122+
$this->getKeyValue()->toXML($e);
117123

118124
return $e;
119125
}

src/XML/dsig11/A.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6+
7+
use SimpleSAML\XML\Base64ElementTrait;
8+
9+
/**
10+
* Class representing a dsig11:A element.
11+
*
12+
* @package simplesaml/xml-security
13+
*/
14+
final class A extends AbstractDsig11Element
15+
{
16+
use Base64ElementTrait;
17+
18+
19+
/**
20+
* Initialize a A element.
21+
*
22+
* @param string $value
23+
*/
24+
public function __construct(
25+
string $value,
26+
) {
27+
$this->setContent($value);
28+
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6+
7+
use DOMElement;
8+
9+
/**
10+
* Abstract class representing a dsig11:CharTwoFieldParamsType
11+
*
12+
* @package simplesaml/xml-security
13+
*/
14+
abstract class AbstractCharTwoFieldParamsType extends AbstractDsig11Element
15+
{
16+
/**
17+
* Initialize a CharTwoFieldParamsType element.
18+
*
19+
* @param \SimpleSAML\XMLSecurity\XML\dsig11\M $m
20+
*/
21+
public function __construct(
22+
protected M $m,
23+
) {
24+
}
25+
26+
27+
/**
28+
* Collect the value of the m-property
29+
*
30+
* @return \SimpleSAML\XMLSecurity\XML\dsig11\M
31+
*/
32+
public function getM(): M
33+
{
34+
return $this->m;
35+
}
36+
37+
38+
/**
39+
* Convert this CharTwoFieldParamsType element to XML.
40+
*
41+
* @param \DOMElement|null $parent The element we should append this CharTwoFieldParamsType element to.
42+
* @return \DOMElement
43+
*/
44+
public function toXML(?DOMElement $parent = null): DOMElement
45+
{
46+
$e = $this->instantiateParentElement($parent);
47+
$this->getM()->toXML($e);
48+
49+
return $e;
50+
}
51+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6+
7+
use DOMElement;
8+
9+
/**
10+
* Abstract class representing a dsig11:CurveType
11+
*
12+
* @package simplesaml/xml-security
13+
*/
14+
abstract class AbstractCurveType extends AbstractDsig11Element
15+
{
16+
/**
17+
* Initialize a CurveType element.
18+
*
19+
* @param \SimpleSAML\XMLSecurity\XML\dsig11\A $a
20+
* @param \SimpleSAML\XMLSecurity\XML\dsig11\B $b
21+
*/
22+
public function __construct(
23+
protected A $a,
24+
protected B $b,
25+
) {
26+
}
27+
28+
29+
/**
30+
* Collect the value of the a-property
31+
*
32+
* @return \SimpleSAML\XMLSecurity\XML\dsig11\A
33+
*/
34+
public function getA(): A
35+
{
36+
return $this->a;
37+
}
38+
39+
40+
/**
41+
* Collect the value of the b-property
42+
*
43+
* @return \SimpleSAML\XMLSecurity\XML\dsig11\B
44+
*/
45+
public function getB(): B
46+
{
47+
return $this->b;
48+
}
49+
50+
51+
/**
52+
* Convert this CurveType element to XML.
53+
*
54+
* @param \DOMElement|null $parent The element we should append this CurveType element to.
55+
* @return \DOMElement
56+
*/
57+
public function toXML(?DOMElement $parent = null): DOMElement
58+
{
59+
$e = $this->instantiateParentElement($parent);
60+
61+
$this->getA()->toXML($e);
62+
$this->getB()->toXML($e);
63+
64+
return $e;
65+
}
66+
}

0 commit comments

Comments
 (0)