Skip to content

Commit 4e71669

Browse files
committed
Split the setting check methods. Now 1 method for IdP settings and other for SP settings
1 parent 5fcfacd commit 4e71669

File tree

2 files changed

+64
-18
lines changed

2 files changed

+64
-18
lines changed

lib/Saml2/Settings.php

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,34 @@ public function checkSettings($settings)
369369
{
370370
assert('is_array($settings)');
371371

372-
$errors = array ();
373372
if (!is_array($settings) || empty($settings)) {
374-
$errors[] = 'invalid_syntax';
375-
return $errors;
373+
$errors = array('invalid_syntax');
374+
} else {
375+
$idpErrors = $this->checkIdPSettings($settings);
376+
$spErrors = $this->checkSPSettings($settings);
377+
$errors = array_merge($idpErrors, $spErrors);
378+
}
379+
380+
return $errors;
381+
}
382+
383+
/**
384+
* Checks the IdP settings info.
385+
*
386+
* @param array $settings Array with settings data
387+
*
388+
* @return array $errors Errors found on the IdP settings data
389+
*/
390+
public function checkIdPSettings($settings)
391+
{
392+
assert('is_array($settings)');
393+
394+
if (!is_array($settings) || empty($settings)) {
395+
return array('invalid_syntax');
376396
}
377397

398+
$errors = array();
399+
378400
if (!isset($settings['idp']) || empty($settings['idp'])) {
379401
$errors[] = 'idp_not_found';
380402
} else {
@@ -401,6 +423,44 @@ public function checkSettings($settings)
401423
}
402424
}
403425

426+
if (isset($settings['security'])) {
427+
$security = $settings['security'];
428+
}
429+
430+
$existsX509 = isset($settings['idp']) && isset($settings['idp']['x509cert']) && !empty($settings['idp']['x509cert']);
431+
$existsFingerprint = isset($settings['idp']) && isset($settings['idp']['certFingerprint']) && !empty($settings['idp']['certFingerprint']);
432+
if (((isset($security['wantAssertionsSigned']) && $security['wantAssertionsSigned'] == true)
433+
|| (isset($security['wantMessagesSigned']) && $security['wantMessagesSigned'] == true))
434+
&& !($existsX509 || $existsFingerprint)
435+
) {
436+
$errors[] = 'idp_cert_or_fingerprint_not_found_and_required';
437+
}
438+
if ((isset($security['nameIdEncrypted']) && $security['nameIdEncrypted'] == true)
439+
&& !($existsX509)
440+
) {
441+
$errors[] = 'idp_cert_not_found_and_required';
442+
}
443+
444+
return $errors;
445+
}
446+
447+
/**
448+
* Checks the SP settings info.
449+
*
450+
* @param array $settings Array with settings data
451+
*
452+
* @return array $errors Errors found on the SP settings data
453+
*/
454+
public function checkSPSettings($settings)
455+
{
456+
assert('is_array($settings)');
457+
458+
if (!is_array($settings) || empty($settings)) {
459+
return array('invalid_syntax');
460+
}
461+
462+
$errors = array();
463+
404464
if (!isset($settings['sp']) || empty($settings['sp'])) {
405465
$errors[] = 'sp_not_found';
406466
} else {
@@ -447,20 +507,6 @@ public function checkSettings($settings)
447507
) {
448508
$errors[] = 'sp_certs_not_found_and_required';
449509
}
450-
451-
$existsX509 = isset($settings['idp']) && isset($settings['idp']['x509cert']) && !empty($settings['idp']['x509cert']);
452-
$existsFingerprint = isset($settings['idp']) && isset($settings['idp']['certFingerprint']) && !empty($settings['idp']['certFingerprint']);
453-
if (((isset($security['wantAssertionsSigned']) && $security['wantAssertionsSigned'] == true)
454-
|| (isset($security['wantMessagesSigned']) && $security['wantMessagesSigned'] == true))
455-
&& !($existsX509 || $existsFingerprint)
456-
) {
457-
$errors[] = 'idp_cert_or_fingerprint_not_found_and_required';
458-
}
459-
if ((isset($security['nameIdEncrypted']) && $security['nameIdEncrypted'] == true)
460-
&& !($existsX509)
461-
) {
462-
$errors[] = 'idp_cert_not_found_and_required';
463-
}
464510
}
465511

466512
if (isset($settings['contactPerson'])) {

lib/Saml2/Utils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ public static function validateSign ($xml, $cert = null, $fingerprint = null, $f
998998
if ($referenceElem->getAttribute('URI') == '') {
999999
$referenceElem->setAttribute('URI', '#'.$signatureElem->parentNode->getAttribute('ID'));
10001000
}
1001-
}
1001+
}
10021002
}
10031003
} catch (Exception $e) {
10041004
continue;

0 commit comments

Comments
 (0)