|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\xenc; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
|
10
|
|
|
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; |
|
11
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
|
12
|
|
|
use SimpleSAML\XMLSecurity\Utils\XPath; |
|
13
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; |
|
14
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptedType; |
|
15
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; |
|
16
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\CipherData; |
|
17
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\CipherValue; |
|
18
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\EncryptedData; |
|
19
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey; |
|
20
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod; |
|
21
|
|
|
|
|
22
|
|
|
use function dirname; |
|
23
|
|
|
use function strval; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\EncryptedDataTest |
|
27
|
|
|
* |
|
28
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement |
|
29
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptedType |
|
30
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\EncryptedData |
|
31
|
|
|
* |
|
32
|
|
|
* @package simplesamlphp/xml-security |
|
33
|
|
|
*/ |
|
34
|
|
|
#[CoversClass(AbstractXencElement::class)] |
|
35
|
|
|
#[CoversClass(AbstractEncryptedType::class)] |
|
36
|
|
|
#[CoversClass(EncryptedData::class)] |
|
37
|
|
|
final class EncryptedDataTest extends TestCase |
|
38
|
|
|
{ |
|
39
|
|
|
use SchemaValidationTestTrait; |
|
40
|
|
|
use SerializableElementTestTrait; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function setUpBeforeClass(): void |
|
45
|
|
|
{ |
|
46
|
|
|
self::$testedClass = EncryptedData::class; |
|
47
|
|
|
|
|
48
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
|
49
|
|
|
dirname(__FILE__, 3) . '/resources/xml/xenc_EncryptedData.xml', |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
// marshalling |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testMarshalling(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$encryptedData = new EncryptedData( |
|
62
|
|
|
new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), |
|
63
|
|
|
'MyID', |
|
64
|
|
|
'http://www.w3.org/2001/04/xmlenc#Element', |
|
65
|
|
|
'text/plain', |
|
66
|
|
|
'urn:x-simplesamlphp:encoding', |
|
67
|
|
|
new EncryptionMethod('http://www.w3.org/2001/04/xmlenc#aes128-cbc'), |
|
68
|
|
|
new KeyInfo( |
|
69
|
|
|
[ |
|
70
|
|
|
new EncryptedKey( |
|
71
|
|
|
new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), |
|
72
|
|
|
null, |
|
73
|
|
|
null, |
|
74
|
|
|
null, |
|
75
|
|
|
null, |
|
76
|
|
|
null, |
|
77
|
|
|
null, |
|
78
|
|
|
new EncryptionMethod('http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'), |
|
79
|
|
|
), |
|
80
|
|
|
], |
|
81
|
|
|
), |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertEquals( |
|
85
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
|
86
|
|
|
strval($encryptedData), |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testMarshallingElementOrdering(): void |
|
94
|
|
|
{ |
|
95
|
|
|
$encryptedData = new EncryptedData( |
|
96
|
|
|
new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), |
|
97
|
|
|
'MyID', |
|
98
|
|
|
'http://www.w3.org/2001/04/xmlenc#Element', |
|
99
|
|
|
'text/plain', |
|
100
|
|
|
'urn:x-simplesamlphp:encoding', |
|
101
|
|
|
new EncryptionMethod('http://www.w3.org/2001/04/xmlenc#aes128-cbc'), |
|
102
|
|
|
new KeyInfo( |
|
103
|
|
|
[ |
|
104
|
|
|
new EncryptedKey( |
|
105
|
|
|
new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), |
|
106
|
|
|
null, |
|
107
|
|
|
null, |
|
108
|
|
|
null, |
|
109
|
|
|
null, |
|
110
|
|
|
null, |
|
111
|
|
|
null, |
|
112
|
|
|
new EncryptionMethod('http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'), |
|
113
|
|
|
), |
|
114
|
|
|
], |
|
115
|
|
|
), |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
$encryptedDataElement = $encryptedData->toXML(); |
|
119
|
|
|
$xpCache = XPath::getXPath($encryptedDataElement); |
|
120
|
|
|
|
|
121
|
|
|
// Test for an EncryptionMethod |
|
122
|
|
|
$encryptedDataElements = XPath::xpQuery($encryptedDataElement, './xenc:EncryptionMethod', $xpCache); |
|
123
|
|
|
$this->assertCount(1, $encryptedDataElements); |
|
124
|
|
|
|
|
125
|
|
|
// Test ordering of EncryptedData contents |
|
126
|
|
|
/** @var \DOMElement[] $encryptedDataElements */ |
|
127
|
|
|
$encryptedDataElements = XPath::xpQuery( |
|
128
|
|
|
$encryptedDataElement, |
|
129
|
|
|
'./xenc:EncryptionMethod/following-sibling::*', |
|
130
|
|
|
$xpCache, |
|
131
|
|
|
); |
|
132
|
|
|
$this->assertCount(2, $encryptedDataElements); |
|
133
|
|
|
$this->assertEquals('ds:KeyInfo', $encryptedDataElements[0]->tagName); |
|
134
|
|
|
$this->assertEquals('xenc:CipherData', $encryptedDataElements[1]->tagName); |
|
135
|
|
|
|
|
136
|
|
|
// EncryptionProperties is currently not supported |
|
137
|
|
|
//$this->assertEquals('xenc:EncryptionProperties', $encryptedDataElements[2]->tagName); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|