Skip to content

Commit 556e279

Browse files
committed
Add some fixes to xmlseclibs. Extra protection verifying the Signature algorithm used on SignedInfo element, not only rely on verify / verifySignature methods
1 parent 68dd8a9 commit 556e279

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/Saml2/Utils.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,11 @@ public static function castKey(XMLSecurityKey $key, $algorithm, $type = 'public'
12061206
if ($key->type === $algorithm) {
12071207
return $key;
12081208
}
1209+
1210+
if (!OneLogin_Saml2_Utils::isSupportedSigningAlgorithm($algorithm)) {
1211+
throw new \Exception('Unsupported signing algorithm.');
1212+
}
1213+
12091214
$keyInfo = openssl_pkey_get_details($key->key);
12101215
if ($keyInfo === false) {
12111216
throw new Exception('Unable to get key details from XMLSecurityKey.');
@@ -1218,6 +1223,17 @@ public static function castKey(XMLSecurityKey $key, $algorithm, $type = 'public'
12181223
return $newKey;
12191224
}
12201225

1226+
public static function isSupportedSigningAlgorithm($algorithm)
1227+
{
1228+
return in_array($algorithm, array(
1229+
XMLSecurityKey::RSA_1_5,
1230+
XMLSecurityKey::RSA_SHA1,
1231+
XMLSecurityKey::RSA_SHA256,
1232+
XMLSecurityKey::RSA_SHA384,
1233+
XMLSecurityKey::RSA_SHA512
1234+
));
1235+
}
1236+
12211237
/**
12221238
* Adds signature key and senders certificate to an element (Message or Assertion).
12231239
*
@@ -1329,6 +1345,10 @@ public static function validateSign($xml, $cert = null, $fingerprint = null, $fi
13291345
throw new Exception('We have no idea about the key');
13301346
}
13311347

1348+
if (!OneLogin_Saml2_Utils::isSupportedSigningAlgorithm($objKey->type)) {
1349+
throw new \Exception('Unsupported signing algorithm.');
1350+
}
1351+
13321352
$objXMLSecDSig->canonicalizeSignedInfo();
13331353

13341354
try {

0 commit comments

Comments
 (0)