Skip to content

Commit 49fb3cd

Browse files
authored
Fixes to encryption optional (#2254)
The new feature from f99217b only worked if a signing cert was present. With no certs present, getPublicKeys threw an exception. Fixed the call from encryptAssertion to getPublicKeys to not require that a key be returned. Also fixed logic in getPublicKeys in Configuration.php. Previous logic would return an empty array if a use type was passed in but no keys of that type were found even if required was set to true. Thus, the encryptAssertion bug didn't appear until we had an SP with no certs at all rather than just one without an encryption cert.
1 parent ff5b76a commit 49fb3cd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

modules/saml/src/IdP/SAML2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ private static function encryptAssertion(
14361436
$key = new XMLSecurityKey($algo);
14371437
$key->loadKey($sharedKey);
14381438
} else {
1439-
$keys = $spMetadata->getPublicKeys('encryption', true);
1439+
$keys = $spMetadata->getPublicKeys('encryption');
14401440
if (!empty($keys)) {
14411441
$key = $keys[0];
14421442
switch ($key['type']) {

src/SimpleSAML/Configuration.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,9 @@ public function getPublicKeys(?string $use = null, bool $required = false, strin
14151415
}
14161416
$ret[] = $key;
14171417
}
1418-
return $ret;
1418+
if (!empty($ret)) {
1419+
return $ret;
1420+
}
14191421
} elseif ($this->hasValue($prefix . 'certData')) {
14201422
$certData = $this->getString($prefix . 'certData');
14211423
$certData = preg_replace('/\s+/', '', $certData);
@@ -1460,7 +1462,10 @@ public function getPublicKeys(?string $use = null, bool $required = false, strin
14601462
'X509Certificate' => $certData,
14611463
],
14621464
];
1463-
} elseif ($required === true) {
1465+
}
1466+
1467+
// If still here, we didn't find a certificate of the requested use
1468+
if ($required === true) {
14641469
throw new Error\Exception($this->location . ': Missing certificate in metadata.');
14651470
} else {
14661471
return [];

0 commit comments

Comments
 (0)