@@ -475,7 +475,7 @@ def __init__(self, sec_context, attribute_converters, entity_id,
475
475
else :
476
476
self .outstanding_queries = {}
477
477
self .context = "AuthnReq"
478
- self .came_from = ""
478
+ self .came_from = None
479
479
self .ava = None
480
480
self .assertion = None
481
481
self .assertions = []
@@ -507,7 +507,7 @@ def loads(self, xmldata, decode=True, origxml=None):
507
507
if self .asynchop :
508
508
if self .in_response_to in self .outstanding_queries :
509
509
self .came_from = self .outstanding_queries [self .in_response_to ]
510
- del self .outstanding_queries [self .in_response_to ]
510
+ # del self.outstanding_queries[self.in_response_to]
511
511
try :
512
512
if not self .check_subject_confirmation_in_response_to (
513
513
self .in_response_to ):
@@ -529,7 +529,7 @@ def loads(self, xmldata, decode=True, origxml=None):
529
529
530
530
def clear (self ):
531
531
self ._clear ()
532
- self .came_from = ""
532
+ self .came_from = None
533
533
self .ava = None
534
534
self .assertion = None
535
535
@@ -667,12 +667,12 @@ def _bearer_confirmed(self, data):
667
667
if not later_than (data .not_on_or_after , data .not_before ):
668
668
return False
669
669
670
- if self .asynchop and not self .came_from :
670
+ if self .asynchop and self .came_from is None :
671
671
if data .in_response_to :
672
672
if data .in_response_to in self .outstanding_queries :
673
673
self .came_from = self .outstanding_queries [
674
674
data .in_response_to ]
675
- del self .outstanding_queries [data .in_response_to ]
675
+ # del self.outstanding_queries[data.in_response_to]
676
676
elif self .allow_unsolicited :
677
677
pass
678
678
else :
@@ -744,7 +744,7 @@ def get_subject(self):
744
744
logger .info ("Subject NameID: %s" % self .name_id )
745
745
return self .name_id
746
746
747
- def _assertion (self , assertion ):
747
+ def _assertion (self , assertion , verified = False ):
748
748
"""
749
749
Check the assertion
750
750
:param assertion:
@@ -758,12 +758,13 @@ def _assertion(self, assertion):
758
758
else :
759
759
logger .debug ("signed" )
760
760
761
- try :
762
- self .sec .check_signature (assertion , class_name (assertion ),
763
- self .xmlstr )
764
- except Exception as exc :
765
- logger .error ("correctly_signed_response: %s" % exc )
766
- raise
761
+ if not verified :
762
+ try :
763
+ self .sec .check_signature (assertion , class_name (assertion ),
764
+ self .xmlstr )
765
+ except Exception as exc :
766
+ logger .error ("correctly_signed_response: %s" % exc )
767
+ raise
767
768
768
769
self .assertion = assertion
769
770
logger .debug ("assertion context: %s" % (self .context ,))
@@ -791,23 +792,23 @@ def _assertion(self, assertion):
791
792
if self .asynchop :
792
793
if self .allow_unsolicited :
793
794
pass
794
- elif not self .came_from :
795
+ elif self .came_from is None :
795
796
raise VerificationError ("Came from" )
796
797
return True
797
798
except Exception :
798
799
logger .exception ("get subject" )
799
800
raise
800
801
801
- def decrypt_assertions (self , encrypted_assertions , key_file = "" ):
802
+ def decrypt_assertions (self , encrypted_assertions , decr_txt ):
802
803
res = []
803
804
for encrypted_assertion in encrypted_assertions :
804
805
if encrypted_assertion .extension_elements :
805
806
assertions = extension_elements_to_elements (
806
807
encrypted_assertion .extension_elements , [saml , samlp ])
807
808
for assertion in assertions :
808
809
if assertion .signature :
809
- if not self .sec .verify_signature (
810
- "%s" % assertion , key_file ,
810
+ if not self .sec .check_signature (
811
+ assertion , origdoc = decr_txt ,
811
812
node_name = class_name (assertion )):
812
813
logger .error (
813
814
"Failed to verify signature on '%s'" % assertion )
@@ -826,21 +827,23 @@ def parse_assertion(self, key_file=""):
826
827
except AssertionError :
827
828
raise Exception ("No assertion part" )
828
829
830
+ res = []
829
831
if self .response .encrypted_assertion :
830
832
logger .debug ("***Encrypted assertion/-s***" )
831
833
decr_text = self .sec .decrypt (self .xmlstr , key_file )
832
834
resp = samlp .response_from_string (decr_text )
833
- res = self .decrypt_assertions (resp .encrypted_assertion , key_file )
835
+ res = self .decrypt_assertions (resp .encrypted_assertion , decr_text )
834
836
if self .response .assertion :
835
837
self .response .assertion .extend (res )
836
838
else :
837
839
self .response .assertion = res
838
840
self .response .encrypted_assertion = []
841
+ self .xmlstr = decr_text
839
842
840
843
if self .response .assertion :
841
844
logger .debug ("***Unencrypted assertion***" )
842
845
for assertion in self .response .assertion :
843
- if not self ._assertion (assertion ):
846
+ if not self ._assertion (assertion , assertion in res ):
844
847
return False
845
848
else :
846
849
self .assertions .append (assertion )
0 commit comments