|
34 | 34 | from onelogin.saml2.constants import OneLogin_Saml2_Constants |
35 | 35 | from onelogin.saml2.errors import OneLogin_Saml2_Error |
36 | 36 |
|
| 37 | +if not globals().get('xmlsec_setup', False): |
| 38 | + xmlsec.initialize() |
| 39 | + globals()['xmlsec_setup'] = True |
| 40 | + |
37 | 41 |
|
38 | 42 | def print_xmlsec_errors(filename, line, func, error_object, error_subject, reason, msg): |
39 | 43 | """ |
@@ -626,8 +630,6 @@ def generate_name_id(value, sp_nq, sp_format, cert=None, debug=False, nq=None): |
626 | 630 | xml = name_id_container.toxml() |
627 | 631 | elem = fromstring(xml) |
628 | 632 |
|
629 | | - xmlsec.initialize() |
630 | | - |
631 | 633 | if debug: |
632 | 634 | xmlsec.set_error_callback(print_xmlsec_errors) |
633 | 635 |
|
@@ -735,8 +737,6 @@ def decrypt_element(encrypted_data, key, debug=False): |
735 | 737 | elif isinstance(encrypted_data, basestring): |
736 | 738 | encrypted_data = fromstring(str(encrypted_data)) |
737 | 739 |
|
738 | | - xmlsec.initialize() |
739 | | - |
740 | 740 | if debug: |
741 | 741 | xmlsec.set_error_callback(print_xmlsec_errors) |
742 | 742 |
|
@@ -810,8 +810,6 @@ def add_sign(xml, key, cert, debug=False, sign_algorithm=OneLogin_Saml2_Constant |
810 | 810 | else: |
811 | 811 | raise Exception('Error parsing xml string') |
812 | 812 |
|
813 | | - xmlsec.initialize() |
814 | | - |
815 | 813 | if debug: |
816 | 814 | xmlsec.set_error_callback(print_xmlsec_errors) |
817 | 815 |
|
@@ -916,8 +914,6 @@ def validate_sign(xml, cert=None, fingerprint=None, fingerprintalg='sha1', valid |
916 | 914 | else: |
917 | 915 | raise Exception('Error parsing xml string') |
918 | 916 |
|
919 | | - xmlsec.initialize() |
920 | | - |
921 | 917 | if debug: |
922 | 918 | xmlsec.set_error_callback(print_xmlsec_errors) |
923 | 919 |
|
@@ -981,8 +977,6 @@ def validate_metadata_sign(xml, cert=None, fingerprint=None, fingerprintalg='sha |
981 | 977 | else: |
982 | 978 | raise Exception('Error parsing xml string') |
983 | 979 |
|
984 | | - xmlsec.initialize() |
985 | | - |
986 | 980 | if debug: |
987 | 981 | xmlsec.set_error_callback(print_xmlsec_errors) |
988 | 982 |
|
@@ -1034,8 +1028,6 @@ def validate_node_sign(signature_node, elem, cert=None, fingerprint=None, finger |
1034 | 1028 | :type: bool |
1035 | 1029 | """ |
1036 | 1030 | try: |
1037 | | - xmlsec.initialize() |
1038 | | - |
1039 | 1031 | if debug: |
1040 | 1032 | xmlsec.set_error_callback(print_xmlsec_errors) |
1041 | 1033 |
|
@@ -1099,8 +1091,6 @@ def validate_binary_sign(signed_query, signature, cert=None, algorithm=OneLogin_ |
1099 | 1091 | :type: bool |
1100 | 1092 | """ |
1101 | 1093 | try: |
1102 | | - xmlsec.initialize() |
1103 | | - |
1104 | 1094 | if debug: |
1105 | 1095 | xmlsec.set_error_callback(print_xmlsec_errors) |
1106 | 1096 |
|
|
0 commit comments