Skip to content

Commit 5c1e247

Browse files
committed
Add check if assertion contains decrypted name id and decrypt it
Remove validation error when document contains a decrypted name id
1 parent bb2b61a commit 5c1e247

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/Saml2/Response.php

+22-19
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class Response
6161
*/
6262
public $encrypted = false;
6363

64+
/**
65+
* The response contains an encrypted nameId in the assertion.
66+
*
67+
* @var bool
68+
*/
69+
public $encryptedNameId = false;
70+
6471
/**
6572
* After validation, if it fail this var has the cause of the problem
6673
*
@@ -227,14 +234,11 @@ public function isValid($requestId = null)
227234
);
228235
}
229236

230-
if ($security['wantNameIdEncrypted']) {
231-
$encryptedIdNodes = $this->_queryAssertion('/saml:Subject/saml:EncryptedID/xenc:EncryptedData');
232-
if ($encryptedIdNodes->length != 1) {
233-
throw new ValidationError(
234-
"The NameID of the Response is not encrypted and the SP requires it",
235-
ValidationError::NO_ENCRYPTED_NAMEID
236-
);
237-
}
237+
if (!$this->encryptedNameId && $security['wantNameIdEncrypted']) {
238+
throw new ValidationError(
239+
"The NameID of the Response is not encrypted and the SP requires it",
240+
ValidationError::NO_ENCRYPTED_NAMEID
241+
);
238242
}
239243

240244
// Validate Conditions element exists
@@ -394,17 +398,6 @@ public function isValid($requestId = null)
394398
}
395399
}
396400

397-
// Detect case not supported
398-
if ($this->encrypted) {
399-
$encryptedIDNodes = Utils::query($this->decryptedDocument, '/samlp:Response/saml:Assertion/saml:Subject/saml:EncryptedID');
400-
if ($encryptedIDNodes->length > 0) {
401-
throw new ValidationError(
402-
'SAML Response that contains an encrypted Assertion with encrypted nameId is not supported.',
403-
ValidationError::NOT_SUPPORTED
404-
);
405-
}
406-
}
407-
408401
if (empty($signedElements) || (!$hasSignedResponse && !$hasSignedAssertion)) {
409402
throw new ValidationError(
410403
'No Signature found. SAML Response rejected',
@@ -1168,6 +1161,16 @@ protected function decryptAssertion(\DomNode $dom)
11681161
if ($check === false) {
11691162
throw new Exception('Error: string from decrypted assertion could not be loaded into a XML document');
11701163
}
1164+
1165+
// check if the decrypted assertion contains an encryptedID
1166+
$encryptedID = $decrypted->getElementsByTagName('EncryptedID')->item(0);
1167+
1168+
if($encryptedID) {
1169+
// decrypt the encryptedID
1170+
$this->encryptedNameId = true;
1171+
$this->decryptAssertion($encryptedID);
1172+
}
1173+
11711174
if ($encData->parentNode instanceof DOMDocument) {
11721175
return $decrypted;
11731176
} else {

0 commit comments

Comments
 (0)