signxml-references-modified 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. signxml-references-modified-1.0.0/LICENSE +201 -0
  2. signxml-references-modified-1.0.0/MANIFEST.in +2 -0
  3. signxml-references-modified-1.0.0/NOTICE +5 -0
  4. signxml-references-modified-1.0.0/PKG-INFO +287 -0
  5. signxml-references-modified-1.0.0/README.rst +258 -0
  6. signxml-references-modified-1.0.0/pyproject.toml +14 -0
  7. signxml-references-modified-1.0.0/setup.cfg +12 -0
  8. signxml-references-modified-1.0.0/setup.py +50 -0
  9. signxml-references-modified-1.0.0/signxml/__init__.py +13 -0
  10. signxml-references-modified-1.0.0/signxml/__pyinstaller/__init__.py +10 -0
  11. signxml-references-modified-1.0.0/signxml/__pyinstaller/hook-signxml.py +5 -0
  12. signxml-references-modified-1.0.0/signxml/algorithms.py +201 -0
  13. signxml-references-modified-1.0.0/signxml/exceptions.py +35 -0
  14. signxml-references-modified-1.0.0/signxml/processor.py +160 -0
  15. signxml-references-modified-1.0.0/signxml/py.typed +0 -0
  16. signxml-references-modified-1.0.0/signxml/schemas/__init__.py +0 -0
  17. signxml-references-modified-1.0.0/signxml/schemas/xmldsig-core-schema.xsd +318 -0
  18. signxml-references-modified-1.0.0/signxml/schemas/xmldsig1-schema.xsd +27 -0
  19. signxml-references-modified-1.0.0/signxml/schemas/xmldsig11-schema.xsd +144 -0
  20. signxml-references-modified-1.0.0/signxml/signer.py +470 -0
  21. signxml-references-modified-1.0.0/signxml/util/__init__.py +297 -0
  22. signxml-references-modified-1.0.0/signxml/verifier.py +628 -0
  23. signxml-references-modified-1.0.0/signxml/xades/__init__.py +34 -0
  24. signxml-references-modified-1.0.0/signxml/xades/schemas/XAdES.xsd +466 -0
  25. signxml-references-modified-1.0.0/signxml/xades/schemas/XAdES01903v132-201506.xsd +537 -0
  26. signxml-references-modified-1.0.0/signxml/xades/schemas/XAdES01903v132-201601.xsd +532 -0
  27. signxml-references-modified-1.0.0/signxml/xades/schemas/XAdES01903v141-201506.xsd +53 -0
  28. signxml-references-modified-1.0.0/signxml/xades/schemas/XAdES01903v141-201601.xsd +63 -0
  29. signxml-references-modified-1.0.0/signxml/xades/schemas/XAdESv141.xsd +15 -0
  30. signxml-references-modified-1.0.0/signxml/xades/schemas/__init__.py +0 -0
  31. signxml-references-modified-1.0.0/signxml/xades/xades.py +378 -0
  32. signxml-references-modified-1.0.0/signxml_references_modified.egg-info/PKG-INFO +287 -0
  33. signxml-references-modified-1.0.0/signxml_references_modified.egg-info/SOURCES.txt +37 -0
  34. signxml-references-modified-1.0.0/signxml_references_modified.egg-info/dependency_links.txt +1 -0
  35. signxml-references-modified-1.0.0/signxml_references_modified.egg-info/entry_points.txt +3 -0
  36. signxml-references-modified-1.0.0/signxml_references_modified.egg-info/requires.txt +11 -0
  37. signxml-references-modified-1.0.0/signxml_references_modified.egg-info/top_level.txt +1 -0
  38. signxml-references-modified-1.0.0/test/test.py +785 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ include signxml/schemas/*.xsd
2
+ include signxml/xades/schemas/*.xsd
@@ -0,0 +1,5 @@
1
+ SignXML is a free open source implementation of the XML Signature and XAdES standards. The SignXML project is staffed by
2
+ volunteers. If you are using this library in a for-profit project, please contribute to SignXML development and
3
+ maintenance using the "Sponsor" button on the SignXML GitHub project page, https://github.com/XML-Security/signxml. If
4
+ you are looking for support with your commercial XML Signature or XAdES based application, please donate and contact
5
+ SignXML developers using the issue tracker on the SignXML project page or the contact information listed in README.rst.
@@ -0,0 +1,287 @@
1
+ Metadata-Version: 2.1
2
+ Name: signxml-references-modified
3
+ Version: 1.0.0
4
+ Summary: Python XML Signature and XAdES library
5
+ Home-page: https://github.com/deisymo/signxml
6
+ Author: Andrey Kislyuk
7
+ Author-email: kislyuk@gmail.com
8
+ License: Apache Software License
9
+ Platform: MacOS X
10
+ Platform: Posix
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: MacOS :: MacOS X
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.7
24
+ Provides-Extra: tests
25
+ License-File: LICENSE
26
+ License-File: NOTICE
27
+
28
+ SignXML: XML Signature and XAdES in Python
29
+ ==========================================
30
+
31
+ *SignXML* is an implementation of the W3C `XML Signature <http://en.wikipedia.org/wiki/XML_Signature>`_ standard in
32
+ Python. This standard (also known as "XMLDSig") is used to provide payload security in `SAML 2.0
33
+ <http://en.wikipedia.org/wiki/SAML_2.0>`_, `XAdES <https://en.wikipedia.org/wiki/XAdES>`_, `EBICS
34
+ <https://en.wikipedia.org/wiki/Electronic_Banking_Internet_Communication_Standard>`_, and `WS-Security
35
+ <https://en.wikipedia.org/wiki/WS-Security>`_, among other uses. The standard is defined in the `W3C Recommendation
36
+ <https://www.w3.org/standards/types#REC>`_ `XML Signature Syntax and Processing Version 1.1
37
+ <http://www.w3.org/TR/xmldsig-core1/>`_. *SignXML* implements all of the required components of the Version 1.1
38
+ standard, and most recommended ones. Its features are:
39
+
40
+ * Use of a libxml2-based XML parser configured to defend against
41
+ `common XML attacks <https://docs.python.org/3/library/xml.html#xml-vulnerabilities>`_ when verifying signatures
42
+ * Extensions to allow signing with and verifying X.509 certificate chains, including hostname/CN validation
43
+ * Extensions to sign and verify `XAdES <https://en.wikipedia.org/wiki/XAdES>`_ signatures
44
+ * Support for exclusive XML canonicalization with inclusive prefixes (`InclusiveNamespaces PrefixList
45
+ <http://www.w3.org/TR/xml-exc-c14n/#def-InclusiveNamespaces-PrefixList>`_, required to verify signatures generated by
46
+ some SAML implementations)
47
+ * Modern Python compatibility (3.7-3.11+ and PyPy)
48
+ * Well-supported, portable, reliable dependencies: `lxml <https://github.com/lxml/lxml>`_ and
49
+ `cryptography <https://github.com/pyca/cryptography>`_
50
+ * Comprehensive testing (including the XMLDSig interoperability suite) and `continuous integration
51
+ <https://github.com/XML-Security/signxml/actions>`_
52
+ * Simple interface with useful, ergonomic, and secure defaults (no network calls, XSLT or XPath transforms)
53
+ * Compactness, readability, and extensibility
54
+
55
+ Installation
56
+ ------------
57
+ ::
58
+
59
+ pip install signxml
60
+
61
+ Synopsis
62
+ --------
63
+ SignXML uses the `lxml ElementTree API <https://lxml.de/tutorial.html>`_ to work with XML data.
64
+
65
+ .. code-block:: python
66
+
67
+ from lxml import etree
68
+ from signxml import XMLSigner, XMLVerifier
69
+
70
+ data_to_sign = "<Test/>"
71
+ cert = open("cert.pem").read()
72
+ key = open("privkey.pem").read()
73
+ root = etree.fromstring(data_to_sign)
74
+ signed_root = XMLSigner().sign(root, key=key, cert=cert)
75
+ verified_data = XMLVerifier().verify(signed_root).signed_xml
76
+
77
+ To make this example self-sufficient for test purposes:
78
+
79
+ - Generate a test certificate and key using
80
+ ``openssl req -x509 -nodes -subj "/CN=test" -days 1 -newkey rsa -keyout privkey.pem -out cert.pem``
81
+ (run ``apt-get install openssl``, ``yum install openssl``, or ``brew install openssl`` if the ``openssl`` executable
82
+ is not found).
83
+ - Pass the ``x509_cert=cert`` keyword argument to ``XMLVerifier.verify()``. (In production, ensure this is replaced with
84
+ the correct configuration for the trusted CA or certificate - this determines which signatures your application
85
+ trusts.)
86
+
87
+ .. _verifying-saml-assertions:
88
+
89
+ Verifying SAML assertions
90
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
91
+
92
+ Assuming ``metadata.xml`` contains SAML metadata for the assertion source:
93
+
94
+ .. code-block:: python
95
+
96
+ from lxml import etree
97
+ from base64 import b64decode
98
+ from signxml import XMLVerifier
99
+
100
+ with open("metadata.xml", "rb") as fh:
101
+ cert = etree.parse(fh).find("//ds:X509Certificate").text
102
+
103
+ assertion_data = XMLVerifier().verify(b64decode(assertion_body), x509_cert=cert).signed_xml
104
+
105
+ .. admonition:: Signing SAML assertions
106
+
107
+ The SAML assertion schema specifies a location for the enveloped XML signature (between ``<Issuer>`` and
108
+ ``<Subject>``). To sign a SAML assertion in a schema-compliant way, insert a signature placeholder tag at that location
109
+ before calling XMLSigner: ``<ds:Signature Id="placeholder"></ds:Signature>``.
110
+
111
+ .. admonition:: See what is signed
112
+
113
+ It is important to understand and follow the best practice rule of "See what is signed" when verifying XML
114
+ signatures. The gist of this rule is: if your application neglects to verify that the information it trusts is
115
+ what was actually signed, the attacker can supply a valid signature but point you to malicious data that wasn't signed
116
+ by that signature. Failure to follow this rule can lead to vulnerability against attacks like
117
+ `SAML signature wrapping <https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf>`_.
118
+
119
+ In SignXML, you can ensure that the information signed is what you expect to be signed by only trusting the
120
+ data returned by ``XMLVerifier.verify()``. The ``signed_xml`` attribute of the return value is the XML node or string
121
+ that was signed. We also recommend that you assert the expected location for the signature within the document:
122
+
123
+ .. code-block:: python
124
+
125
+ from signxml import XMLVerifier, SignatureConfiguration
126
+ config = SignatureConfiguration(location="./")
127
+ XMLVerifier(...).verify(..., expect_config=config)
128
+
129
+ **Recommended reading:** `W3C XML Signature Best Practices for Applications
130
+ <http://www.w3.org/TR/xmldsig-bestpractices/#practices-applications>`_, `On Breaking SAML: Be Whoever You Want to Be
131
+ <https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf>`_, `Duo Finds SAML Vulnerabilities
132
+ Affecting Multiple Implementations <https://duo.com/blog/duo-finds-saml-vulnerabilities-affecting-multiple-implementations>`_
133
+
134
+ .. admonition:: Establish trust
135
+
136
+ If you do not supply any keyword arguments to ``verify()``, the default behavior is to trust **any** valid XML
137
+ signature generated using a valid X.509 certificate trusted by your system's CA store. This means anyone can
138
+ get an SSL certificate and generate a signature that you will trust. To establish trust in the signer, use the
139
+ ``x509_cert`` argument to specify a certificate that was pre-shared out-of-band (e.g. via SAML metadata, as
140
+ shown in *Verifying SAML assertions*), or ``cert_subject_name`` to specify a
141
+ subject name that must be in the signing X.509 certificate given by the signature (verified as if it were a
142
+ domain name), or ``ca_pem_file`` to give a custom CA.
143
+
144
+ XML signature construction methods: enveloped, detached, enveloping
145
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146
+ The XML Signature specification defines three ways to compose a signature with the data being signed: enveloped,
147
+ detached, and enveloping signature. Enveloped is the default method. To specify the type of signature that you want to
148
+ generate, pass the ``method`` argument to ``sign()``:
149
+
150
+ .. code-block:: python
151
+
152
+ signed_root = XMLSigner(method=signxml.methods.detached).sign(root, key=key, cert=cert)
153
+ verified_data = XMLVerifier().verify(signed_root).signed_xml
154
+
155
+ For detached signatures, the code above will use the ``Id`` or ``ID`` attribute of ``root`` to generate a relative URI
156
+ (``<Reference URI="#value"``). You can also override the value of ``URI`` by passing a ``reference_uri`` argument to
157
+ ``sign()``. To verify a detached signature that refers to an external entity, pass a callable resolver in
158
+ ``XMLVerifier().verify(data, uri_resolver=...)``.
159
+
160
+ See the `API documentation <https://xml-security.github.io/signxml/#id5>`_ for more details.
161
+
162
+
163
+ XML representation details: Configuring namespace prefixes and whitespace
164
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165
+ Some applications require a particular namespace prefix configuration - for example, a number of applications assume
166
+ that the ``http://www.w3.org/2000/09/xmldsig#`` namespace is set as the default, unprefixed namespace instead of using
167
+ the customary ``ds:`` prefix. While in normal use namespace prefix naming is an insignificant representation detail,
168
+ it can be significant in some XML canonicalization and signature configurations. To configure the namespace prefix map
169
+ when generating a signature, set the ``XMLSigner.namespaces`` attribute:
170
+
171
+ .. code-block:: python
172
+
173
+ signer = signxml.XMLSigner(...)
174
+ signer.namespaces = {None: signxml.namespaces.ds}
175
+ signed_root = signer.sign(...)
176
+
177
+ Similarly, whitespace in the signed document is significant for XML canonicalization and signature purposes. Do not
178
+ pretty-print the XML after generating the signature, since this can unfortunately render the signature invalid.
179
+
180
+
181
+ XML parsing security and compatibility with ``xml.etree.ElementTree``
182
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
183
+ SignXML uses the `lxml <https://github.com/lxml/lxml>`_ ElementTree library, not the
184
+ `ElementTree from Python's standard library <https://docs.python.org/3.8/library/xml.etree.elementtree.html>`_,
185
+ to work with XML. lxml is used due to its superior resistance to XML attacks, as well as XML canonicalization and
186
+ namespace organization features. It is recommended that you pass XML string input directly to signxml before further
187
+ parsing, and use lxml to work with untrusted XML input in general. If you do pass ``xml.etree.ElementTree`` objects to
188
+ SignXML, you should be aware of differences in XML namespace handling between the two libraries. See the following
189
+ references for more information:
190
+
191
+ * `How do I use lxml safely as a web-service endpoint?
192
+ <https://lxml.de/FAQ.html#how-do-i-use-lxml-safely-as-a-web-service-endpoint>`_
193
+ * `ElementTree compatibility of lxml.etree <https://lxml.de/compatibility.html>`_
194
+ * `XML Signatures with Python ElementTree <https://technotes.shemyak.com/posts/xml-signatures-with-python-elementtree>`_
195
+
196
+
197
+ XAdES signatures
198
+ ~~~~~~~~~~~~~~~~
199
+ `XAdES ("XML Advanced Electronic Signatures") <https://en.wikipedia.org/wiki/XAdES>`_ is a standard for attaching
200
+ metadata to XML Signature objects. This standard is endorsed by the European Union as the implementation for its
201
+ `eSignature <https://ec.europa.eu/digital-building-blocks/wikis/display/DIGITAL/eSignature+Overview>`_ regulations.
202
+
203
+ SignXML supports signing and verifying documents using `XAdES <https://en.wikipedia.org/wiki/XAdES>`_ signatures:
204
+
205
+ .. code-block:: python
206
+
207
+ from signxml import DigestAlgorithm
208
+ from signxml.xades import (XAdESSigner, XAdESVerifier, XAdESVerifyResult,
209
+ XAdESSignaturePolicy, XAdESDataObjectFormat)
210
+ signature_policy = XAdESSignaturePolicy(
211
+ Identifier="MyPolicyIdentifier",
212
+ Description="Hello XAdES",
213
+ DigestMethod=DigestAlgorithm.SHA256,
214
+ DigestValue="Ohixl6upD6av8N7pEvDABhEL6hM=",
215
+ )
216
+ data_object_format = XAdESDataObjectFormat(
217
+ Description="My XAdES signature",
218
+ MimeType="text/xml",
219
+ )
220
+ signer = XAdESSigner(
221
+ signature_policy=signature_policy,
222
+ claimed_roles=["signer"],
223
+ data_object_format=data_object_format,
224
+ c14n_algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
225
+ )
226
+ signed_doc = signer.sign(doc, key=private_key, cert=certificate)
227
+
228
+ .. code-block:: python
229
+
230
+ verifier = XAdESVerifier()
231
+ verify_results = verifier.verify(
232
+ signed_doc, x509_cert=certificate, expect_references=3, expect_signature_policy=signature_policy
233
+ )
234
+ for verify_result in verify_results:
235
+ if isinstance(verify_result, XAdESVerifyResult):
236
+ verify_result.signed_properties # use this to access parsed XAdES properties
237
+
238
+ Authors
239
+ -------
240
+ * `Andrey Kislyuk <https://github.com/kislyuk>`_ and SignXML contributors.
241
+
242
+ Links
243
+ -----
244
+ * `Project home page (GitHub) <https://github.com/XML-Security/signxml>`_
245
+ * `Documentation <https://xml-security.github.io/signxml/>`_
246
+ * `Package distribution (PyPI) <https://pypi.python.org/pypi/signxml>`_
247
+ * `Change log <https://github.com/XML-Security/signxml/blob/master/Changes.rst>`_
248
+ * `List of W3C XML Signature standards and drafts <https://www.w3.org/TR/?title=xml%20signature>`_
249
+ * `W3C Recommendation: XML Signature Syntax and Processing Version 1.1 <http://www.w3.org/TR/xmldsig-core1>`_
250
+ * `W3C Working Group Note: XML Signature Best Practices <http://www.w3.org/TR/xmldsig-bestpractices/>`_
251
+ * `XML-Signature Interoperability <http://www.w3.org/Signature/2001/04/05-xmldsig-interop.html>`_
252
+ * `W3C Working Group Note: Test Cases for C14N 1.1 and XMLDSig Interoperability <http://www.w3.org/TR/xmldsig2ed-tests/>`_
253
+ * `W3C Working Group Note: XML Signature Syntax and Processing Version 2.0 <http://www.w3.org/TR/xmldsig-core2>`_
254
+ (This draft standard proposal was never finalized and is not in general use.)
255
+ * `Intelligence Community Technical Specification: Web Service Security Guidance for Use of XML Signature and XML
256
+ Encryption <https://github.com/XML-Security/signxml/blob/develop/docs/dni-guidance.pdf>`_
257
+ * `XMLSec: Related links <https://www.aleksey.com/xmlsec/related.html>`_
258
+ * `OWASP SAML Security Cheat Sheet <https://www.owasp.org/index.php/SAML_Security_Cheat_Sheet>`_
259
+ * `Okta Developer Docs: SAML <https://developer.okta.com/standards/SAML/>`_
260
+
261
+ Bugs
262
+ ~~~~
263
+ Please report bugs, issues, feature requests, etc. on `GitHub <https://github.com/XML-Security/signxml/issues>`_.
264
+
265
+ Versioning
266
+ ~~~~~~~~~~
267
+ This package follows the `Semantic Versioning 2.0.0 <http://semver.org/>`_ standard. To control changes, it is
268
+ recommended that application developers pin the package version and manage it using `pip-tools
269
+ <https://github.com/jazzband/pip-tools>`_ or similar. For library developers, pinning the major version is
270
+ recommended.
271
+
272
+ License
273
+ -------
274
+ Copyright 2014-2024, Andrey Kislyuk and SignXML contributors. Licensed under the terms of the
275
+ `Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>`_. Distribution of the LICENSE and NOTICE
276
+ files with source copies of this package and derivative works is **REQUIRED** as specified by the Apache License.
277
+
278
+ .. image:: https://github.com/XML-Security/signxml/workflows/Test%20suite/badge.svg
279
+ :target: https://github.com/XML-Security/signxml/actions
280
+ .. image:: https://codecov.io/github/XML-Security/signxml/coverage.svg?branch=master
281
+ :target: https://codecov.io/github/XML-Security/signxml?branch=master
282
+ .. image:: https://img.shields.io/pypi/v/signxml.svg
283
+ :target: https://pypi.python.org/pypi/signxml
284
+ .. image:: https://img.shields.io/pypi/l/signxml.svg
285
+ :target: https://pypi.python.org/pypi/signxml
286
+
287
+