Skip to content

Commit 5977734

Browse files
committed
Allow use of dsig11:X509Digest inside X509Data
1 parent 681093e commit 5977734

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/XML/ds/X509Data.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use SimpleSAML\XML\Constants as C;
1111
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1212
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
13+
use SimpleSAML\XMLSecurity\XML\dsig11\X509Digest;
1314

1415
/**
1516
* Class representing a ds:X509Data element.
@@ -24,15 +25,16 @@ final class X509Data extends AbstractDsElement
2425
* @param (\SimpleSAML\XML\Chunk|
2526
* \SimpleSAML\XMLSecurity\XML\ds\X509Certificate|
2627
* \SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial|
27-
* \SimpleSAML\XMLSecurity\XML\ds\X509SubjectName)[] $data
28+
* \SimpleSAML\XMLSecurity\XML\ds\X509SubjectName|
29+
* \SimpleSAML\XMLSecurity\XML\dsig11\X509Digest)[] $data
2830
*/
2931
public function __construct(
3032
protected array $data,
3133
) {
3234
Assert::maxCount($data, C::UNBOUNDED_LIMIT);
3335
Assert::allIsInstanceOfAny(
3436
$data,
35-
[Chunk::class, X509Certificate::class, X509IssuerSerial::class, X509SubjectName::class],
37+
[Chunk::class, X509Certificate::class, X509IssuerSerial::class, X509SubjectName::class, X509Digest::class],
3638
InvalidArgumentException::class,
3739
);
3840
}
@@ -44,7 +46,8 @@ public function __construct(
4446
* @return (\SimpleSAML\XML\Chunk|
4547
* \SimpleSAML\XMLSecurity\XML\ds\X509Certificate|
4648
* \SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial|
47-
* \SimpleSAML\XMLSecurity\XML\ds\X509SubjectName)[]
49+
* \SimpleSAML\XMLSecurity\XML\ds\X509SubjectName|
50+
* \SimpleSAML\XMLSecurity\XML\dsig11\X509Digest)[]
4851
*/
4952
public function getData(): array
5053
{
@@ -80,6 +83,7 @@ public static function fromXML(DOMElement $xml): static
8083
'X509Certificate' => X509Certificate::fromXML($n),
8184
'X509IssuerSerial' => X509IssuerSerial::fromXML($n),
8285
'X509SubjectName' => X509SubjectName::fromXML($n),
86+
'X509Digest' => X509Digest::fromXML($n),
8387
default => new Chunk($n),
8488
};
8589
}

tests/XML/ds/X509DataTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use SimpleSAML\XML\DOMDocumentFactory;
1111
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
1212
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13+
use SimpleSAML\XMLSecurity\Constants as C;
14+
use SimpleSAML\XMLSecurity\CryptoEncoding\PEM;
15+
use SimpleSAML\XMLSecurity\Key;
1316
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
1417
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
1518
use SimpleSAML\XMLSecurity\XML\ds\X509Certificate;
@@ -18,8 +21,11 @@
1821
use SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial;
1922
use SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber;
2023
use SimpleSAML\XMLSecurity\XML\ds\X509SubjectName;
24+
use SimpleSAML\XMLSecurity\XML\dsig11\X509Digest;
2125

26+
use function base64_encode;
2227
use function dirname;
28+
use function hex2bin;
2329
use function openssl_x509_parse;
2430
use function str_replace;
2531
use function strval;
@@ -42,6 +48,8 @@ final class X509DataTest extends TestCase
4248
/** @var array<string, mixed> */
4349
private static array $certData;
4450

51+
/** @var string */
52+
private static string $digest;
4553

4654
/**
4755
*/
@@ -78,6 +86,11 @@ public static function setUpBeforeClass(): void
7886
self::$certData = openssl_x509_parse(
7987
PEMCertificatesMock::getPlainCertificate(PEMCertificatesMock::SELFSIGNED_CERTIFICATE),
8088
);
89+
90+
$key = new Key\X509Certificate(PEM::fromString(PEMCertificatesMock::getPlainCertificate()));
91+
/** @var string $binary */
92+
$binary = hex2bin($key->getRawThumbprint(C::DIGEST_SHA256));
93+
self::$digest = base64_encode($binary);
8194
}
8295

8396

@@ -101,6 +114,7 @@ public function testMarshalling(): void
101114
new X509SerialNumber('2'),
102115
),
103116
new X509SubjectName(self::$certData['name']),
117+
new X509Digest(self::$digest, C::DIGEST_SHA256),
104118
new Chunk(DOMDocumentFactory::fromString(
105119
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">other</ssp:Chunk>',
106120
)->documentElement),

tests/resources/xml/ds_X509Data.xml

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<ds:X509SerialNumber>2</ds:X509SerialNumber>
77
</ds:X509IssuerSerial>
88
<ds:X509SubjectName>/CN=selfsigned.simplesamlphp.org/O=SimpleSAMLphp HQ/L=Honolulu/ST=Hawaii/C=US</ds:X509SubjectName>
9+
<dsig11:X509Digest xmlns:dsig11="http://www.w3.org/2009/xmldsig11#" Algorithm="http://www.w3.org/2001/04/xmlenc#sha256">6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE=</dsig11:X509Digest>
910
<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">other</ssp:Chunk>
1011
</ds:X509Data>

0 commit comments

Comments
 (0)