Skip to content

Commit cb9d587

Browse files
committed
Fix xmlsec issue. Merge branch 'coolbootscoder-master'
2 parents 3c77f55 + e9165c8 commit cb9d587

2 files changed

Lines changed: 5 additions & 19 deletions

File tree

src/onelogin/saml2/auth.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
from base64 import b64encode
1515
from urllib import quote_plus
1616

17-
import dm.xmlsec.binding as xmlsec
18-
1917
from onelogin.saml2.settings import OneLogin_Saml2_Settings
2018
from onelogin.saml2.response import OneLogin_Saml2_Response
2119
from onelogin.saml2.errors import OneLogin_Saml2_Error
2220
from onelogin.saml2.logout_response import OneLogin_Saml2_Logout_Response
2321
from onelogin.saml2.constants import OneLogin_Saml2_Constants
24-
from onelogin.saml2.utils import OneLogin_Saml2_Utils
22+
from onelogin.saml2.utils import OneLogin_Saml2_Utils, xmlsec
2523
from onelogin.saml2.logout_request import OneLogin_Saml2_Logout_Request
2624
from onelogin.saml2.authn_request import OneLogin_Saml2_Authn_Request
2725

@@ -433,8 +431,6 @@ def __build_signature(self, saml_data, relay_state, saml_type, sign_algorithm=On
433431
OneLogin_Saml2_Error.SP_CERTS_NOT_FOUND
434432
)
435433

436-
xmlsec.initialize()
437-
438434
dsig_ctx = xmlsec.DSigCtx()
439435
dsig_ctx.signKey = xmlsec.Key.loadMemory(key, xmlsec.KeyDataFormatPem, None)
440436

src/onelogin/saml2/utils.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
from onelogin.saml2.constants import OneLogin_Saml2_Constants
3535
from onelogin.saml2.errors import OneLogin_Saml2_Error
3636

37+
if not globals().get('xmlsec_setup', False):
38+
xmlsec.initialize()
39+
globals()['xmlsec_setup'] = True
40+
3741

3842
def print_xmlsec_errors(filename, line, func, error_object, error_subject, reason, msg):
3943
"""
@@ -626,8 +630,6 @@ def generate_name_id(value, sp_nq, sp_format, cert=None, debug=False, nq=None):
626630
xml = name_id_container.toxml()
627631
elem = fromstring(xml)
628632

629-
xmlsec.initialize()
630-
631633
if debug:
632634
xmlsec.set_error_callback(print_xmlsec_errors)
633635

@@ -735,8 +737,6 @@ def decrypt_element(encrypted_data, key, debug=False):
735737
elif isinstance(encrypted_data, basestring):
736738
encrypted_data = fromstring(str(encrypted_data))
737739

738-
xmlsec.initialize()
739-
740740
if debug:
741741
xmlsec.set_error_callback(print_xmlsec_errors)
742742

@@ -810,8 +810,6 @@ def add_sign(xml, key, cert, debug=False, sign_algorithm=OneLogin_Saml2_Constant
810810
else:
811811
raise Exception('Error parsing xml string')
812812

813-
xmlsec.initialize()
814-
815813
if debug:
816814
xmlsec.set_error_callback(print_xmlsec_errors)
817815

@@ -916,8 +914,6 @@ def validate_sign(xml, cert=None, fingerprint=None, fingerprintalg='sha1', valid
916914
else:
917915
raise Exception('Error parsing xml string')
918916

919-
xmlsec.initialize()
920-
921917
if debug:
922918
xmlsec.set_error_callback(print_xmlsec_errors)
923919

@@ -981,8 +977,6 @@ def validate_metadata_sign(xml, cert=None, fingerprint=None, fingerprintalg='sha
981977
else:
982978
raise Exception('Error parsing xml string')
983979

984-
xmlsec.initialize()
985-
986980
if debug:
987981
xmlsec.set_error_callback(print_xmlsec_errors)
988982

@@ -1034,8 +1028,6 @@ def validate_node_sign(signature_node, elem, cert=None, fingerprint=None, finger
10341028
:type: bool
10351029
"""
10361030
try:
1037-
xmlsec.initialize()
1038-
10391031
if debug:
10401032
xmlsec.set_error_callback(print_xmlsec_errors)
10411033

@@ -1099,8 +1091,6 @@ def validate_binary_sign(signed_query, signature, cert=None, algorithm=OneLogin_
10991091
:type: bool
11001092
"""
11011093
try:
1102-
xmlsec.initialize()
1103-
11041094
if debug:
11051095
xmlsec.set_error_callback(print_xmlsec_errors)
11061096

0 commit comments

Comments
 (0)