Skip to content

Commit a982e8c

Browse files
committed
Merge branch 'mukulagrawal-master'
2 parents f1b3f93 + b22e48a commit a982e8c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/onelogin/saml2/response.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,25 @@ def __decrypt_assertion(self, dom):
449449
if encrypted_assertion_nodes:
450450
encrypted_data_nodes = OneLogin_Saml2_Utils.query(encrypted_assertion_nodes[0], '//saml:EncryptedAssertion/xenc:EncryptedData')
451451
if encrypted_data_nodes:
452+
keyinfo = OneLogin_Saml2_Utils.query(encrypted_assertion_nodes[0], '//saml:EncryptedAssertion/xenc:EncryptedData/ds:KeyInfo')
453+
if not keyinfo:
454+
raise Exception('No KeyInfo present, invalid Assertion')
455+
keyinfo = keyinfo[0]
456+
children = keyinfo.getchildren()
457+
if not children:
458+
raise Exception('No child to KeyInfo, invalid Assertion')
459+
for child in children:
460+
if 'RetrievalMethod' in child.tag:
461+
if child.attrib['Type'] != 'http://www.w3.org/2001/04/xmlenc#EncryptedKey':
462+
raise Exception('Unsupported Retrieval Method found')
463+
uri = child.attrib['URI']
464+
if not uri.startswith('#'):
465+
break
466+
uri = uri.split('#')[1]
467+
encrypted_key = OneLogin_Saml2_Utils.query(encrypted_assertion_nodes[0], './xenc:EncryptedKey[@Id="'+uri +'"]')
468+
if encrypted_key:
469+
keyinfo.append(encrypted_key[0])
470+
452471
encrypted_data = encrypted_data_nodes[0]
453472
OneLogin_Saml2_Utils.decrypt_element(encrypted_data, key)
454473
return dom

0 commit comments

Comments
 (0)