Skip to content

Commit cc8a717

Browse files
committed
Support multiple encrypted keys as required by i.e. saml:EncryptedElementType
1 parent 251933f commit cc8a717

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/XML/EncryptedElementInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function hasDecryptionKey(): bool;
3636
/**
3737
* Get the encrypted key used to encrypt the current element.
3838
*
39-
* @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey
39+
* @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey[]
4040
*/
41-
public function getEncryptedKey(): EncryptedKey;
41+
public function getEncryptedKey(): array;
4242

4343
/**
4444
* Get the EncryptedData object.

src/XML/EncryptedElementTrait.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
*/
2828
trait EncryptedElementTrait
2929
{
30-
/** @var \SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey|null */
31-
protected ?EncryptedKey $encryptedKey = null;
30+
/** @var \SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey[] */
31+
protected array $encryptedKey = [];
3232

3333

3434
/**
@@ -46,7 +46,7 @@ public function __construct(
4646

4747
foreach ($keyInfo->getInfo() as $info) {
4848
if ($info instanceof EncryptedKey) {
49-
$this->encryptedKey = $info;
49+
$this->encryptedKey[] = $info;
5050
break;
5151
}
5252
}
@@ -60,16 +60,16 @@ public function __construct(
6060
*/
6161
public function hasDecryptionKey(): bool
6262
{
63-
return $this->encryptedKey !== null;
63+
return !empty($this->encryptedKey);
6464
}
6565

6666

6767
/**
6868
* Get the encrypted key used to encrypt the current element.
6969
*
70-
* @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey
70+
* @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey[]
7171
*/
72-
public function getEncryptedKey(): EncryptedKey
72+
public function getEncryptedKey(): array
7373
{
7474
return $this->encryptedKey;
7575
}
@@ -120,7 +120,7 @@ protected function decryptData(EncryptionAlgorithmInterface $decryptor): string
120120

121121
if (in_array($decryptor->getAlgorithmId(), C::$KEY_TRANSPORT_ALGORITHMS)) {
122122
// the decryptor uses a key transport algorithm, check if we have a session key
123-
if ($this->hasDecryptionKey() === null) {
123+
if (!$this->hasDecryptionKey()) {
124124
throw new RuntimeException('Cannot use a key transport algorithm to decrypt an object.');
125125
}
126126

@@ -129,7 +129,9 @@ protected function decryptData(EncryptionAlgorithmInterface $decryptor): string
129129
}
130130

131131
$encryptedKey = $this->getEncryptedKey();
132-
$decryptionKey = $encryptedKey->decrypt($decryptor);
132+
Assert::count($encryptedKey, 1, RuntimeException::class);
133+
134+
$decryptionKey = $encryptedKey[0]->decrypt($decryptor);
133135

134136
$factory = new EncryptionAlgorithmFactory(
135137
$this->getBlacklistedAlgorithms() ?? EncryptionAlgorithmFactory::DEFAULT_BLACKLIST,

0 commit comments

Comments
 (0)