@@ -61,6 +61,13 @@ class Response
61
61
*/
62
62
public $ encrypted = false ;
63
63
64
+ /**
65
+ * The response contains an encrypted nameId in the assertion.
66
+ *
67
+ * @var bool
68
+ */
69
+ public $ encryptedNameId = false ;
70
+
64
71
/**
65
72
* After validation, if it fail this var has the cause of the problem
66
73
*
@@ -227,14 +234,12 @@ public function isValid($requestId = null)
227
234
);
228
235
}
229
236
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
+ $ this ->encryptedNameId = $ this ->encryptedNameId || $ this ->_queryAssertion ('/saml:Subject/saml:EncryptedID/xenc:EncryptedData ' )->length > 0 ;
238
+ if (!$ this ->encryptedNameId && $ security ['wantNameIdEncrypted ' ]) {
239
+ throw new ValidationError (
240
+ "The NameID of the Response is not encrypted and the SP requires it " ,
241
+ ValidationError::NO_ENCRYPTED_NAMEID
242
+ );
238
243
}
239
244
240
245
// Validate Conditions element exists
@@ -394,17 +399,6 @@ public function isValid($requestId = null)
394
399
}
395
400
}
396
401
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
-
408
402
if (empty ($ signedElements ) || (!$ hasSignedResponse && !$ hasSignedAssertion )) {
409
403
throw new ValidationError (
410
404
'No Signature found. SAML Response rejected ' ,
@@ -1168,6 +1162,16 @@ protected function decryptAssertion(\DomNode $dom)
1168
1162
if ($ check === false ) {
1169
1163
throw new Exception ('Error: string from decrypted assertion could not be loaded into a XML document ' );
1170
1164
}
1165
+
1166
+ // check if the decrypted assertion contains an encryptedID
1167
+ $ encryptedID = $ decrypted ->getElementsByTagName ('EncryptedID ' )->item (0 );
1168
+
1169
+ if ($ encryptedID ) {
1170
+ // decrypt the encryptedID
1171
+ $ this ->encryptedNameId = true ;
1172
+ $ this ->decryptAssertion ($ encryptedID );
1173
+ }
1174
+
1171
1175
if ($ encData ->parentNode instanceof DOMDocument) {
1172
1176
return $ decrypted ;
1173
1177
} else {
0 commit comments