Skip to content

Commit a9037d2

Browse files
author
Alex Bublichenko
committed
Use extension_elements to extract KeyInfo
Instead of explicitly declaring `KeyInfo` as child of `SubjectConfirmationData`, use `extension_elements` to extract `KeyInfo` element(s).
1 parent 281d2e1 commit a9037d2

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/saml2/response.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,11 @@ def _bearer_confirmed(self, data):
722722
return True
723723

724724
def _holder_of_key_confirmed(self, data):
725-
if not data or not data.key_info:
725+
if not data or not data.extension_elements:
726726
return False
727727

728728
has_keyinfo = False
729-
key_info = data.key_info or ()
730-
for element in extension_elements_to_elements(key_info,
729+
for element in extension_elements_to_elements(data.extension_elements,
731730
[samlp, saml, xenc, ds]):
732731
if isinstance(element, ds.KeyInfo):
733732
has_keyinfo = True

src/saml2/saml.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,8 @@ class SubjectConfirmationDataType_(SamlBase):
482482
c_any = {"namespace": "##any", "processContents": "lax", "minOccurs": "0",
483483
"maxOccurs": "unbounded"}
484484
c_any_attribute = {"namespace": "##other", "processContents": "lax"}
485-
c_children['{http://www.w3.org/2000/09/xmldsig#}KeyInfo'] = ('key_info',
486-
[ds.KeyInfo])
487-
c_cardinality['key_info'] = {"min": 0, "max": 1}
488485

489486
def __init__(self,
490-
key_info=None,
491487
not_before=None,
492488
not_on_or_after=None,
493489
recipient=None,
@@ -500,7 +496,6 @@ def __init__(self,
500496
text=text,
501497
extension_elements=extension_elements,
502498
extension_attributes=extension_attributes)
503-
self.key_info = key_info
504499
self.not_before = not_before
505500
self.not_on_or_after = not_on_or_after
506501
self.recipient = recipient

tests/test_02_saml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,8 @@ def _assertBearer(self, sc):
886886
assert sc.subject_confirmation_data.recipient == "recipient"
887887
assert sc.subject_confirmation_data.in_response_to == "responseID"
888888
assert sc.subject_confirmation_data.address == "127.0.0.1"
889-
assert sc.subject_confirmation_data.key_info is None
889+
key_info = sc.subject_confirmation_data.extensions_as_elements(ds.KeyInfo.c_tag, ds)
890+
assert len(key_info) == 0
890891

891892
def testHolderOfKeyUsingTestData(self):
892893
"""Test subject_confirmation_from_string() using test data for 'holder-of-key' SubjectConfirmation"""
@@ -898,7 +899,7 @@ def testHolderOfKeyUsingTestData(self):
898899
assert sc.subject_confirmation_data.not_on_or_after == "2007-09-14T01:05:02Z"
899900
assert sc.subject_confirmation_data.recipient == "recipient"
900901
assert sc.subject_confirmation_data.in_response_to == "responseID"
901-
key_info = sc.subject_confirmation_data.key_info
902+
key_info = sc.subject_confirmation_data.extensions_as_elements(ds.KeyInfo.c_tag, ds)
902903
assert len(key_info) == 1
903904
assert len(key_info[0].x509_data) == 1
904905

tests/test_93_hok.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
from saml2 import xmldsig as ds
34
from saml2.response import authn_response, VerificationError
45
from saml2.config import config_factory
56

@@ -18,8 +19,10 @@ def test_valid_hok_response_is_parsed(self):
1819

1920
assert resp.get_subject() is not None
2021
assert len(resp.assertion.subject.subject_confirmation) == 2
21-
actual_hok_certs = [sc.subject_confirmation_data.key_info[0].x509_data[0].x509_certificate.text.strip()
22-
for sc in resp.assertion.subject.subject_confirmation]
22+
key_infos = [sc.subject_confirmation_data.extensions_as_elements(ds.KeyInfo.c_tag, ds)[0]
23+
for sc in resp.assertion.subject.subject_confirmation]
24+
actual_hok_certs = [key_info_element.x509_data[0].x509_certificate.text.strip()
25+
for key_info_element in key_infos]
2326
assert actual_hok_certs == self._expected_hok_certs()
2427

2528
def _expected_hok_certs(self):

0 commit comments

Comments
 (0)