@@ -38,8 +38,8 @@ def __init__(self, settings, response):
3838 :param response: The base64 encoded, XML string containing the samlp:Response
3939 :type response: string
4040 """
41- self .__settings = settings
42- self .__error = None
41+ self ._settings = settings
42+ self ._error = None
4343 self .response = self .__class__ .decode_response (response )
4444 self .document = fromstring (self .response )
4545 self .decrypted_document = None
@@ -68,8 +68,8 @@ def is_valid(self, request_data, response_id=None):
6868
6969 return self .validate_response (request_data , response_id )
7070 except Exception as err :
71- self .__error = err .__str__ ()
72- debug = self .__settings .is_debug_active ()
71+ self ._error = err .__str__ ()
72+ debug = self ._settings .is_debug_active ()
7373 if debug :
7474 print err .__str__ ()
7575 return False
@@ -103,7 +103,7 @@ def get_audiences(self):
103103 """
104104 audiences = []
105105
106- audience_nodes = self .__query_assertion ('/saml:Conditions/saml:AudienceRestriction/saml:Audience' )
106+ audience_nodes = self ._query_assertion ('/saml:Conditions/saml:AudienceRestriction/saml:Audience' )
107107 for audience_node in audience_nodes :
108108 audiences .append (audience_node .text )
109109 return audiences
@@ -117,11 +117,11 @@ def get_issuers(self):
117117 """
118118 issuers = []
119119
120- message_issuer_nodes = self .__query ('/samlp:Response/saml:Issuer' )
120+ message_issuer_nodes = self ._query ('/samlp:Response/saml:Issuer' )
121121 if message_issuer_nodes :
122122 issuers .append (message_issuer_nodes [0 ].text )
123123
124- assertion_issuer_nodes = self .__query_assertion ('/saml:Issuer' )
124+ assertion_issuer_nodes = self ._query_assertion ('/saml:Issuer' )
125125 if assertion_issuer_nodes :
126126 issuers .append (assertion_issuer_nodes [0 ].text )
127127
@@ -135,13 +135,13 @@ def get_nameid_data(self):
135135 :rtype: dict
136136 """
137137 nameid = None
138- encrypted_id_data_nodes = self .__query_assertion ('/saml:Subject/saml:EncryptedID/xenc:EncryptedData' )
138+ encrypted_id_data_nodes = self ._query_assertion ('/saml:Subject/saml:EncryptedID/xenc:EncryptedData' )
139139 if encrypted_id_data_nodes :
140140 encrypted_data = encrypted_id_data_nodes [0 ]
141- key = self .__settings .get_sp_key ()
141+ key = self ._settings .get_sp_key ()
142142 nameid = OneLogin_Saml2_Utils .decrypt_element (encrypted_data , key )
143143 else :
144- nameid_nodes = self .__query_assertion ('/saml:Subject/saml:NameID' )
144+ nameid_nodes = self ._query_assertion ('/saml:Subject/saml:NameID' )
145145 if nameid_nodes :
146146 nameid = nameid_nodes [0 ]
147147 if nameid is None :
@@ -173,7 +173,7 @@ def get_session_not_on_or_after(self):
173173 :rtype: time|None
174174 """
175175 not_on_or_after = None
176- authn_statement_nodes = self .__query_assertion ('/saml:AuthnStatement[@SessionNotOnOrAfter]' )
176+ authn_statement_nodes = self ._query_assertion ('/saml:AuthnStatement[@SessionNotOnOrAfter]' )
177177 if authn_statement_nodes :
178178 not_on_or_after = OneLogin_Saml2_Utils .parse_SAML_to_time (authn_statement_nodes [0 ].get ('SessionNotOnOrAfter' ))
179179 return not_on_or_after
@@ -189,7 +189,7 @@ def get_session_index(self):
189189 :rtype: string|None
190190 """
191191 session_index = None
192- authn_statement_nodes = self .__query_assertion ('/saml:AuthnStatement[@SessionIndex]' )
192+ authn_statement_nodes = self ._query_assertion ('/saml:AuthnStatement[@SessionIndex]' )
193193 if authn_statement_nodes :
194194 session_index = authn_statement_nodes [0 ].get ('SessionIndex' )
195195 return session_index
@@ -200,7 +200,7 @@ def get_attributes(self):
200200 EncryptedAttributes are not supported
201201 """
202202 attributes = {}
203- attribute_nodes = self .__query_assertion ('/saml:AttributeStatement/saml:Attribute' )
203+ attribute_nodes = self ._query_assertion ('/saml:AttributeStatement/saml:Attribute' )
204204 for attribute_node in attribute_nodes :
205205 attr_name = attribute_node .get ('Name' )
206206 values = []
@@ -216,8 +216,8 @@ def validate_num_assertions(self):
216216 :returns: True if only 1 assertion encrypted or not
217217 :rtype: bool
218218 """
219- encrypted_assertion_nodes = self .__query ('/samlp:Response/saml:EncryptedAssertion' )
220- assertion_nodes = self .__query ('/samlp:Response/saml:Assertion' )
219+ encrypted_assertion_nodes = self ._query ('/samlp:Response/saml:EncryptedAssertion' )
220+ assertion_nodes = self ._query ('/samlp:Response/saml:Assertion' )
221221 return (len (encrypted_assertion_nodes ) + len (assertion_nodes )) == 1
222222
223223 def validate_timestamps (self ):
@@ -227,7 +227,7 @@ def validate_timestamps(self):
227227 :returns: True if the condition is valid, False otherwise
228228 :rtype: bool
229229 """
230- conditions_nodes = self .__query_assertion ('/saml:Conditions' )
230+ conditions_nodes = self ._query_assertion ('/saml:Conditions' )
231231
232232 for conditions_node in conditions_nodes :
233233 nb_attr = conditions_node .get ('NotBefore' )
@@ -238,7 +238,7 @@ def validate_timestamps(self):
238238 return False
239239 return True
240240
241- def __query_assertion (self , xpath_expr ):
241+ def _query_assertion (self , xpath_expr ):
242242 """
243243 Extracts nodes that match the query from the Assertion
244244
@@ -254,12 +254,12 @@ def __query_assertion(self, xpath_expr):
254254 assertion_expr = '/saml:Assertion'
255255 signature_expr = '/ds:Signature/ds:SignedInfo/ds:Reference'
256256 signed_assertion_query = '/samlp:Response' + assertion_expr + signature_expr
257- assertion_reference_nodes = self .__query (signed_assertion_query )
257+ assertion_reference_nodes = self ._query (signed_assertion_query )
258258
259259 if not assertion_reference_nodes :
260260 # Check if the message is signed
261261 signed_message_query = '/samlp:Response' + signature_expr
262- message_reference_nodes = self .__query (signed_message_query )
262+ message_reference_nodes = self ._query (signed_message_query )
263263 if message_reference_nodes :
264264 message_id = message_reference_nodes [0 ].get ('URI' )
265265 final_query = "/samlp:Response[@ID='%s']/" % message_id [1 :]
@@ -270,9 +270,9 @@ def __query_assertion(self, xpath_expr):
270270 assertion_id = assertion_reference_nodes [0 ].get ('URI' )
271271 final_query = '/samlp:Response' + assertion_expr + "[@ID='%s']" % assertion_id [1 :]
272272 final_query += xpath_expr
273- return self .__query (final_query )
273+ return self ._query (final_query )
274274
275- def __query (self , query ):
275+ def _query (self , query ):
276276 """
277277 Extracts nodes that match the query from the Response
278278
@@ -288,7 +288,7 @@ def __query(self, query):
288288 document = self .document
289289 return OneLogin_Saml2_Utils .query (document , query )
290290
291- def __decrypt_assertion (self , dom ):
291+ def _decrypt_assertion (self , dom ):
292292 """
293293 Decrypts the Assertion
294294
@@ -298,7 +298,7 @@ def __decrypt_assertion(self, dom):
298298 :returns: Decrypted Assertion
299299 :rtype: Element
300300 """
301- key = self .__settings .get_sp_key ()
301+ key = self ._settings .get_sp_key ()
302302
303303 if not key :
304304 raise Exception ('No private key available, check settings' )
@@ -315,7 +315,7 @@ def get_error(self):
315315 """
316316 After execute a validation process, if fails this method returns the cause
317317 """
318- return self .__error
318+ return self ._error
319319
320320
321321class OneLogin_Saml2_Response_Post (OneLogin_Saml2_Response ):
@@ -331,16 +331,13 @@ def __init__(self, settings, response):
331331 :type response: string
332332 """
333333 OneLogin_Saml2_Response .__init__ (self , settings , response )
334- # Reset these given the meaning of double underscore in Python.
335- self .__settings = settings
336- self .__error = None
337334
338335 # Quick check for the presence of EncryptedAssertion
339- encrypted_assertion_nodes = self .__query ('/samlp:Response/saml:EncryptedAssertion' )
336+ encrypted_assertion_nodes = self ._query ('/samlp:Response/saml:EncryptedAssertion' )
340337 if encrypted_assertion_nodes :
341338 decrypted_document = deepcopy (self .document )
342339 self .encrypted = True
343- self .decrypted_document = self .__decrypt_assertion (decrypted_document )
340+ self .decrypted_document = self ._decrypt_assertion (decrypted_document )
344341
345342 @staticmethod
346343 def decode_response (response ):
@@ -366,24 +363,24 @@ def validate_response(self, request_data, request_id=None):
366363 :returns: True if the SAML Response is valid, False if not
367364 :rtype: bool
368365 """
369- self .__error = None
370- idp_data = self .__settings .get_idp_data ()
366+ self ._error = None
367+ idp_data = self ._settings .get_idp_data ()
371368 idp_entity_id = idp_data .get ('entityId' , '' )
372- sp_data = self .__settings .get_sp_data ()
369+ sp_data = self ._settings .get_sp_data ()
373370 sp_entity_id = sp_data .get ('entityId' , '' )
374371
375- sign_nodes = self .__query ('//ds:Signature' )
372+ sign_nodes = self ._query ('//ds:Signature' )
376373
377374 signed_elements = []
378375 for sign_node in sign_nodes :
379376 signed_elements .append (sign_node .getparent ().tag )
380377
381- if self .__settings .is_strict ():
382- res = OneLogin_Saml2_Utils .validate_xml (etree .tostring (self .document ), 'saml-schema-protocol-2.0.xsd' , self .__settings .is_debug_active ())
378+ if self ._settings .is_strict ():
379+ res = OneLogin_Saml2_Utils .validate_xml (etree .tostring (self .document ), 'saml-schema-protocol-2.0.xsd' , self ._settings .is_debug_active ())
383380 if not isinstance (res , Document ):
384381 raise Exception ('Invalid SAML Response. Not match the saml-schema-protocol-2.0.xsd' )
385382
386- security = self .__settings .get_security_data ()
383+ security = self ._settings .get_security_data ()
387384 current_url = OneLogin_Saml2_Utils .get_self_url_no_query (request_data )
388385
389386 # Check if the InResponseTo of the Response matchs the ID of the AuthNRequest (requestId) if provided
@@ -396,20 +393,20 @@ def validate_response(self, request_data, request_id=None):
396393 raise Exception ('The assertion of the Response is not encrypted and the SP require it' )
397394
398395 if security .get ('wantNameIdEncrypted' , False ):
399- encrypted_nameid_nodes = self .__query_assertion ('/saml:Subject/saml:EncryptedID/xenc:EncryptedData' )
396+ encrypted_nameid_nodes = self ._query_assertion ('/saml:Subject/saml:EncryptedID/xenc:EncryptedData' )
400397 if len (encrypted_nameid_nodes ) == 0 :
401398 raise Exception ('The NameID of the Response is not encrypted and the SP require it' )
402399
403400 # Checks that there is at least one AttributeStatement
404- attribute_statement_nodes = self .__query_assertion ('/saml:AttributeStatement' )
401+ attribute_statement_nodes = self ._query_assertion ('/saml:AttributeStatement' )
405402 if not attribute_statement_nodes :
406403 raise Exception ('There is no AttributeStatement on the Response' )
407404
408405 # Validates Asserion timestamps
409406 if not self .validate_timestamps ():
410407 raise Exception ('Timing issues (please check your clock settings)' )
411408
412- encrypted_attributes_nodes = self .__query_assertion ('/saml:AttributeStatement/saml:EncryptedAttribute' )
409+ encrypted_attributes_nodes = self ._query_assertion ('/saml:AttributeStatement/saml:EncryptedAttribute' )
413410 if encrypted_attributes_nodes :
414411 raise Exception ('There is an EncryptedAttribute in the Response and this SP not support them' )
415412
@@ -441,7 +438,7 @@ def validate_response(self, request_data, request_id=None):
441438
442439 # Checks the SubjectConfirmation, at least one SubjectConfirmation must be valid
443440 any_subject_confirmation = False
444- subject_confirmation_nodes = self .__query_assertion ('/saml:Subject/saml:SubjectConfirmation' )
441+ subject_confirmation_nodes = self ._query_assertion ('/saml:Subject/saml:SubjectConfirmation' )
445442
446443 for scn in subject_confirmation_nodes :
447444 method = scn .get ('Method' , None )
@@ -513,9 +510,6 @@ def __init__(self, settings, response):
513510 :type response: string
514511 """
515512 OneLogin_Saml2_Response .__init__ (self , settings , response )
516- # Reset these given the meaning of double underscore in Python.
517- self .__settings = settings
518- self .__error = None
519513
520514 @staticmethod
521515 def decode_response (response ):
@@ -541,17 +535,17 @@ def validate_response(self, request_data, request_id=None):
541535 :returns: True if the SAML Response is valid, False if not
542536 :rtype: bool
543537 """
544- self .__error = None
545- idp_data = self .__settings .get_idp_data ()
538+ self ._error = None
539+ idp_data = self ._settings .get_idp_data ()
546540 idp_entity_id = idp_data ['entityId' ]
547541 get_data = request_data ['get_data' ]
548542
549- if self .__settings .is_strict ():
550- res = OneLogin_Saml2_Utils .validate_xml (self .document , 'saml-schema-protocol-2.0.xsd' , self .__settings .is_debug_active ())
543+ if self ._settings .is_strict ():
544+ res = OneLogin_Saml2_Utils .validate_xml (self .document , 'saml-schema-protocol-2.0.xsd' , self ._settings .is_debug_active ())
551545 if not isinstance (res , Document ):
552546 raise Exception ('Invalid SAML Logout Request. Not match the saml-schema-protocol-2.0.xsd' )
553547
554- security = self .__settings .get_security_data ()
548+ security = self ._settings .get_security_data ()
555549
556550 # Check if the InResponseTo of the Logout Response matchs the ID of the Logout Request (requestId) if provided
557551 if request_id is not None and self .document .documentElement .hasAttribute ('InResponseTo' ):
@@ -595,6 +589,12 @@ def validate_response(self, request_data, request_id=None):
595589 raise Exception ('In order to validate the sign on the Logout Response, the x509cert of the IdP is required' )
596590 cert = idp_data ['x509cert' ]
597591
592+ print '////////////'
593+ print cert
594+ print get_data
595+ print signed_query
596+ print '////////////'
597+
598598 if not OneLogin_Saml2_Utils .validate_binary_sign (signed_query , b64decode (get_data ['Signature' ]), cert ):
599599 raise Exception ('Signature validation failed. Logout Response rejected' )
600600
0 commit comments