SignXML: XML Signature and XAdES in Python
==========================================
*SignXML* is an implementation of the W3C `XML Signature <http://en.wikipedia.org/wiki/XML_Signature>`_ standard in
Python. This standard (also known as "XMLDSig") is used to provide payload security in `SAML 2.0
<http://en.wikipedia.org/wiki/SAML_2.0>`_, `XAdES <https://en.wikipedia.org/wiki/XAdES>`_, and `WS-Security
<https://en.wikipedia.org/wiki/WS-Security>`_, among other uses. The standard is defined in the `W3C Recommendation
<https://www.w3.org/standards/types#REC>`_ `XML Signature Syntax and Processing Version 1.1
<http://www.w3.org/TR/xmldsig-core1/>`_. *SignXML* implements all of the required components of the Version 1.1
standard, and most recommended ones. Its features are:
* Use of a libxml2-based XML parser configured to defend against
`common XML attacks <https://docs.python.org/3/library/xml.html#xml-vulnerabilities>`_ when verifying signatures
* Extensions to allow signing with and verifying X.509 certificate chains, including hostname/CN validation
* Extensions to sign and verify `XAdES <https://en.wikipedia.org/wiki/XAdES>`_ signatures
* Support for exclusive XML canonicalization with inclusive prefixes (`InclusiveNamespaces PrefixList
<http://www.w3.org/TR/xml-exc-c14n/#def-InclusiveNamespaces-PrefixList>`_, required to verify signatures generated by
some SAML implementations)
* Modern Python compatibility (3.7-3.11+ and PyPy)
* Well-supported, portable, reliable dependencies: `lxml <https://github.com/lxml/lxml>`_,
`cryptography <https://github.com/pyca/cryptography>`_, `pyOpenSSL <https://github.com/pyca/pyopenssl>`_
* Comprehensive testing (including the XMLDSig interoperability suite) and `continuous integration
<https://github.com/XML-Security/signxml/actions>`_
* Simple interface with useful, ergonomic, and secure defaults (no network calls, XSLT or XPath transforms)
* Compactness, readability, and extensibility
Installation
------------
::
pip install signxml
Note: SignXML depends on `lxml <https://github.com/lxml/lxml>`_ and `cryptography
<https://github.com/pyca/cryptography>`_, which in turn depend on `OpenSSL <https://www.openssl.org/>`_, `LibXML
<http://xmlsoft.org/>`_, and Python tools to interface with them. You can install those as follows:
+--------------+----------------------------------------------------------------------------------------------------------------------+
| OS | Command |
+==============+======================================================================================================================+
| Ubuntu | ``apt-get install --no-install-recommends python3-pip python3-wheel python3-setuptools python3-openssl python3-lxml``|
+--------------+----------------------------------------------------------------------------------------------------------------------+
| Red Hat, | ``yum install python3-pip python3-pyOpenSSL python3-lxml`` |
| Amazon Linux,| |
| CentOS | |
+--------------+----------------------------------------------------------------------------------------------------------------------+
| Mac OS | Install `Homebrew <https://brew.sh>`_, then run ``brew install python``. |
+--------------+----------------------------------------------------------------------------------------------------------------------+
Synopsis
--------
SignXML uses the `lxml ElementTree API <https://lxml.de/tutorial.html>`_ to work with XML data.
.. code-block:: python
from lxml import etree
from signxml import XMLSigner, XMLVerifier
data_to_sign = "<Test/>"
cert = open("cert.pem").read()
key = open("privkey.pem").read()
root = etree.fromstring(data_to_sign)
signed_root = XMLSigner().sign(root, key=key, cert=cert)
verified_data = XMLVerifier().verify(signed_root).signed_xml
To make this example self-sufficient for test purposes:
- Generate a test certificate and key using
``openssl req -x509 -nodes -subj "/CN=test" -days 1 -newkey rsa -keyout privkey.pem -out cert.pem``
(run ``yum install openssl`` on Red Hat).
- Pass the ``x509_cert=cert`` keyword argument to ``XMLVerifier.verify()``. (In production, ensure this is replaced with
the correct configuration for the trusted CA or certificate - this determines which signatures your application trusts.)
.. _verifying-saml-assertions:
Verifying SAML assertions
~~~~~~~~~~~~~~~~~~~~~~~~~
Assuming ``metadata.xml`` contains SAML metadata for the assertion source:
.. code-block:: python
from lxml import etree
from base64 import b64decode
from signxml import XMLVerifier
with open("metadata.xml", "rb") as fh:
cert = etree.parse(fh).find("//ds:X509Certificate").text
assertion_data = XMLVerifier().verify(b64decode(assertion_body), x509_cert=cert).signed_xml
.. admonition:: Signing SAML assertions
The SAML assertion schema specifies a location for the enveloped XML signature (between ``<Issuer>`` and
``<Subject>``). To sign a SAML assertion in a schema-compliant way, insert a signature placeholder tag at that location
before calling XMLSigner: ``<ds:Signature Id="placeholder"></ds:Signature>``.
.. admonition:: See what is signed
It is important to understand and follow the best practice rule of "See what is signed" when verifying XML
signatures. The gist of this rule is: if your application neglects to verify that the information it trusts is
what was actually signed, the attacker can supply a valid signature but point you to malicious data that wasn't signed
by that signature. Failure to follow this rule can lead to vulnerability against attacks like
`SAML signature wrapping <https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf>`_.
In SignXML, you can ensure that the information signed is what you expect to be signed by only trusting the
data returned by the ``verify()`` method. The ``signed_xml`` attribute of the return value is the XML node or string that
was signed.
**Recommended reading:** `W3C XML Signature Best Practices for Applications
<http://www.w3.org/TR/xmldsig-bestpractices/#practices-applications>`_, `On Breaking SAML: Be Whoever You Want to Be
<https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf>`_, `Duo Finds SAML Vulnerabilities
Affecting Multiple Implementations <https://duo.com/blog/duo-finds-saml-vulnerabilities-affecting-multiple-implementations>`_
.. admonition:: Establish trust
If you do not supply any keyword arguments to ``verify()``, the default behavior is to trust **any** valid XML
signature generated using a valid X.509 certificate trusted by your system's CA store. This means anyone can
get an SSL certificate and generate a signature that you will trust. To establish trust in the signer, use the
``x509_cert`` argument to specify a certificate that was pre-shared out-of-band (e.g. via SAML metadata, as
shown in *Verifying SAML assertions*), or ``cert_subject_name`` to specify a
subject name that must be in the signing X.509 certificate given by the signature (verified as if it were a
domain name), or ``ca_pem_file``/``ca_path`` to give a custom CA.
XML signature construction methods: enveloped, detached, enveloping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The XML Signature specification defines three ways to compose a signature with the data being signed: enveloped,
detached, and enveloping signature. Enveloped is the default method. To specify the type of signature that you want to
generate, pass the ``method`` argument to ``sign()``:
.. code-block:: python
signed_root = XMLSigner(method=signxml.methods.detached).sign(root, key=key, cert=cert)
verified_data = XMLVerifier().verify(signed_root).signed_xml
For detached signatures, the code above will use the ``Id`` or ``ID`` attribute of ``root`` to generate a relative URI
(``<Reference URI="#value"``). You can also override the value of ``URI`` by passing a ``reference_uri`` argument to
``sign()``. To verify a detached signature that refers to an external entity, pass a callable resolver in
``XMLVerifier().verify(data, uri_resolver=...)``.
See the `API documentation <https://xml-security.github.io/signxml/#id5>`_ for more details.
XML representation details: Configuring namespace prefixes and whitespace
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Some applications require a particular namespace prefix configuration - for example, a number of applications assume
that the ``http://www.w3.org/2000/09/xmldsig#`` namespace is set as the default, unprefixed namespace instead of using
the customary ``ds:`` prefix. While in normal use namespace prefix naming is an insignificant representation detail,
it can be significant in some XML canonicalization and signature configurations. To configure the namespace prefix map
when generating a signature, set the ``XMLSigner.namespaces`` attribute:
.. code-block:: python
signer = signxml.XMLSigner(...)
signer.namespaces = {None: signxml.namespaces.ds}
signed_root = signer.sign(...)
Similarly, whitespace in the signed document is significant for XML canonicalization and signature purposes. Do not
pretty-print the XML after generating the signature, since this can unfortunately render the signature invalid.
XML parsing security and compatibility with ``xml.etree.ElementTree``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SignXML uses the `lxml <https://github.com/lxml/lxml>`_ ElementTree library, not the
`ElementTree from Python's standard library <https://docs.python.org/3.8/library/xml.etree.elementtree.html>`_,
to work with XML. lxml is used due to its superior resistance to XML attacks, as well as XML canonicalization and
namespace organization features. It is recommended that you pass XML string input directly to signxml before further
parsing, and use lxml to work with untrusted XML input in general. If you do pass ``xml.etree.ElementTree`` objects to
SignXML, you should be aware of differences in XML namespace handling between the two libraries. See the following
references for more information:
* `How do I use lxml safely as a web-service endpoint?
<https://lxml.de/FAQ.html#how-do-i-use-lxml-safely-as-a-web-service-endpoint>`_
* `ElementTree compatibility of lxml.etree <https://lxml.de/compatibility.html>`_
* `XML Signatures with Python ElementTree <https://technotes.shemyak.com/posts/xml-signatures-with-python-elementtree>`_
XAdES signatures
~~~~~~~~~~~~~~~~
`XAdES ("XML Advanced Electronic Signatures") <https://en.wikipedia.org/wiki/XAdES>`_ is a standard for attaching
metadata to XML Signature objects. This standard is endorsed by the European Union as the implementation for its
`eSignature <https://ec.europa.eu/digital-building-blocks/wikis/display/DIGITAL/eSignature+Overview>`_ regulations.
SignXML supports signing and verifying documents using `XAdES <https://en.wikipedia.org/wiki/XAdES>`_ signatures:
.. code-block:: python
from signxml import DigestAlgorithm
from signxml.xades import (XAdESSigner, XAdESVerifier, XAdESVerifyResult,
XAdESSignaturePolicy, XAdESDataObjectFormat)
signature_policy = XAdESSignaturePolicy(
Identifier="MyPolicyIdentifier",
Description="Hello XAdES",
DigestMethod=DigestAlgorithm.SHA256,
DigestValue="Ohixl6upD6av8N7pEvDABhEL6hM=",
)
data_object_format = XAdESDataObjectFormat(
Description="My XAdES signature",
MimeType="text/xml",
)
signer = XAdESSigner(
signature_policy=signature_policy,
claimed_roles=["signer"],
data_object_format=data_object_format,
c14n_algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
)
signed_doc = signer.sign(doc, key=private_key, cert=certificate)
.. code-block:: python
verifier = XAdESVerifier()
verify_results = verifier.verify(
signed_doc, x509_cert=certificate, expect_references=3, expect_signature_policy=signature_policy
)
for verify_result in verify_results:
if isinstance(verify_result, XAdESVerifyResult):
verify_result.signed_properties # use this to access parsed XAdES properties
Authors
-------
* `Andrey Kislyuk <https://github.com/kislyuk>`_ and SignXML contributors.
Links
-----
* `Project home page (GitHub) <https://github.com/XML-Security/signxml>`_
* `Documentation <https://xml-security.github.io/signxml/>`_
* `Package distribution (PyPI) <https://pypi.python.org/pypi/signxml>`_
* `Change log <https://github.com/XML-Security/signxml/blob/master/Changes.rst>`_
* `List of W3C XML Signature standards and drafts <https://www.w3.org/TR/?title=xml%20signature>`_
* `W3C Recommendation: XML Signature Syntax and Processing Version 1.1 <http://www.w3.org/TR/xmldsig-core1>`_
* `W3C Working Group Note: XML Signature Best Practices <http://www.w3.org/TR/xmldsig-bestpractices/>`_
* `XML-Signature Interoperability <http://www.w3.org/Signature/2001/04/05-xmldsig-interop.html>`_
* `W3C Working Group Note: Test Cases for C14N 1.1 and XMLDSig Interoperability <http://www.w3.org/TR/xmldsig2ed-tests/>`_
* `W3C Working Group Note: XML Signature Syntax and Processing Version 2.0 <http://www.w3.org/TR/xmldsig-core2>`_
(This draft standard proposal was never finalized and is not in general use.)
* `Intelligence Community Technical Specification: Web Service Security Guidance for Use of XML Signature and XML
Encryption <https://github.com/XML-Security/signxml/blob/develop/docs/dni-guidance.pdf>`_
* `XMLSec: Related links <https://www.aleksey.com/xmlsec/related.html>`_
* `OWASP SAML Security Cheat Sheet <https://www.owasp.org/index.php/SAML_Security_Cheat_Sheet>`_
* `Okta Developer Docs: SAML <https://developer.okta.com/standards/SAML/>`_
Bugs
~~~~
Please report bugs, issues, feature requests, etc. on `GitHub <https://github.com/XML-Security/signxml/issues>`_.
Versioning
~~~~~~~~~~
This package follows the `Semantic Versioning 2.0.0 <http://semver.org/>`_ standard. To control changes, it is
recommended that application developers pin the package version and manage it using `pip-tools
<https://github.com/jazzband/pip-tools>`_ or similar. For library developers, pinning the major version is
recommended.
License
-------
Copyright 2014-2023, Andrey Kislyuk and SignXML contributors. Licensed under the terms of the
`Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>`_. Distribution of the LICENSE and NOTICE
files with source copies of this package and derivative works is **REQUIRED** as specified by the Apache License.
.. image:: https://github.com/XML-Security/signxml/workflows/Test%20suite/badge.svg
:target: https://github.com/XML-Security/signxml/actions
.. image:: https://codecov.io/github/XML-Security/signxml/coverage.svg?branch=master
:target: https://codecov.io/github/XML-Security/signxml?branch=master
.. image:: https://img.shields.io/pypi/v/signxml.svg
:target: https://pypi.python.org/pypi/signxml
.. image:: https://img.shields.io/pypi/l/signxml.svg
:target: https://pypi.python.org/pypi/signxml
Raw data
{
"_id": null,
"home_page": "https://github.com/datastyx-dev/signxml.git",
"name": "custom-signxml",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Andrey Kislyuk",
"author_email": "dev@datastyx.com",
"download_url": "https://files.pythonhosted.org/packages/df/ad/2bcde49550e452069d3ecb76087f46fe67078e9a5acb2fdc45d06171df1e/custom_signxml-3.2.3.tar.gz",
"platform": "MacOS X",
"description": "SignXML: XML Signature and XAdES in Python\n==========================================\n\n*SignXML* is an implementation of the W3C `XML Signature <http://en.wikipedia.org/wiki/XML_Signature>`_ standard in\nPython. This standard (also known as \"XMLDSig\") is used to provide payload security in `SAML 2.0\n<http://en.wikipedia.org/wiki/SAML_2.0>`_, `XAdES <https://en.wikipedia.org/wiki/XAdES>`_, and `WS-Security\n<https://en.wikipedia.org/wiki/WS-Security>`_, among other uses. The standard is defined in the `W3C Recommendation\n<https://www.w3.org/standards/types#REC>`_ `XML Signature Syntax and Processing Version 1.1\n<http://www.w3.org/TR/xmldsig-core1/>`_. *SignXML* implements all of the required components of the Version 1.1\nstandard, and most recommended ones. Its features are:\n\n* Use of a libxml2-based XML parser configured to defend against\n `common XML attacks <https://docs.python.org/3/library/xml.html#xml-vulnerabilities>`_ when verifying signatures\n* Extensions to allow signing with and verifying X.509 certificate chains, including hostname/CN validation\n* Extensions to sign and verify `XAdES <https://en.wikipedia.org/wiki/XAdES>`_ signatures\n* Support for exclusive XML canonicalization with inclusive prefixes (`InclusiveNamespaces PrefixList\n <http://www.w3.org/TR/xml-exc-c14n/#def-InclusiveNamespaces-PrefixList>`_, required to verify signatures generated by\n some SAML implementations)\n* Modern Python compatibility (3.7-3.11+ and PyPy)\n* Well-supported, portable, reliable dependencies: `lxml <https://github.com/lxml/lxml>`_,\n `cryptography <https://github.com/pyca/cryptography>`_, `pyOpenSSL <https://github.com/pyca/pyopenssl>`_\n* Comprehensive testing (including the XMLDSig interoperability suite) and `continuous integration\n <https://github.com/XML-Security/signxml/actions>`_\n* Simple interface with useful, ergonomic, and secure defaults (no network calls, XSLT or XPath transforms)\n* Compactness, readability, and extensibility\n\nInstallation\n------------\n::\n\n pip install signxml\n\nNote: SignXML depends on `lxml <https://github.com/lxml/lxml>`_ and `cryptography\n<https://github.com/pyca/cryptography>`_, which in turn depend on `OpenSSL <https://www.openssl.org/>`_, `LibXML\n<http://xmlsoft.org/>`_, and Python tools to interface with them. You can install those as follows:\n\n+--------------+----------------------------------------------------------------------------------------------------------------------+\n| OS | Command |\n+==============+======================================================================================================================+\n| Ubuntu | ``apt-get install --no-install-recommends python3-pip python3-wheel python3-setuptools python3-openssl python3-lxml``|\n+--------------+----------------------------------------------------------------------------------------------------------------------+\n| Red Hat, | ``yum install python3-pip python3-pyOpenSSL python3-lxml`` |\n| Amazon Linux,| |\n| CentOS | |\n+--------------+----------------------------------------------------------------------------------------------------------------------+\n| Mac OS | Install `Homebrew <https://brew.sh>`_, then run ``brew install python``. |\n+--------------+----------------------------------------------------------------------------------------------------------------------+\n\nSynopsis\n--------\nSignXML uses the `lxml ElementTree API <https://lxml.de/tutorial.html>`_ to work with XML data.\n\n.. code-block:: python\n\n from lxml import etree\n from signxml import XMLSigner, XMLVerifier\n\n data_to_sign = \"<Test/>\"\n cert = open(\"cert.pem\").read()\n key = open(\"privkey.pem\").read()\n root = etree.fromstring(data_to_sign)\n signed_root = XMLSigner().sign(root, key=key, cert=cert)\n verified_data = XMLVerifier().verify(signed_root).signed_xml\n\nTo make this example self-sufficient for test purposes:\n\n- Generate a test certificate and key using\n ``openssl req -x509 -nodes -subj \"/CN=test\" -days 1 -newkey rsa -keyout privkey.pem -out cert.pem``\n (run ``yum install openssl`` on Red Hat).\n- Pass the ``x509_cert=cert`` keyword argument to ``XMLVerifier.verify()``. (In production, ensure this is replaced with\n the correct configuration for the trusted CA or certificate - this determines which signatures your application trusts.)\n\n.. _verifying-saml-assertions:\n\nVerifying SAML assertions\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nAssuming ``metadata.xml`` contains SAML metadata for the assertion source:\n\n.. code-block:: python\n\n from lxml import etree\n from base64 import b64decode\n from signxml import XMLVerifier\n\n with open(\"metadata.xml\", \"rb\") as fh:\n cert = etree.parse(fh).find(\"//ds:X509Certificate\").text\n\n assertion_data = XMLVerifier().verify(b64decode(assertion_body), x509_cert=cert).signed_xml\n\n.. admonition:: Signing SAML assertions\n\n The SAML assertion schema specifies a location for the enveloped XML signature (between ``<Issuer>`` and\n ``<Subject>``). To sign a SAML assertion in a schema-compliant way, insert a signature placeholder tag at that location\n before calling XMLSigner: ``<ds:Signature Id=\"placeholder\"></ds:Signature>``.\n\n.. admonition:: See what is signed\n\n It is important to understand and follow the best practice rule of \"See what is signed\" when verifying XML\n signatures. The gist of this rule is: if your application neglects to verify that the information it trusts is\n what was actually signed, the attacker can supply a valid signature but point you to malicious data that wasn't signed\n by that signature. Failure to follow this rule can lead to vulnerability against attacks like\n `SAML signature wrapping <https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf>`_.\n\n In SignXML, you can ensure that the information signed is what you expect to be signed by only trusting the\n data returned by the ``verify()`` method. The ``signed_xml`` attribute of the return value is the XML node or string that\n was signed.\n\n **Recommended reading:** `W3C XML Signature Best Practices for Applications\n <http://www.w3.org/TR/xmldsig-bestpractices/#practices-applications>`_, `On Breaking SAML: Be Whoever You Want to Be\n <https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf>`_, `Duo Finds SAML Vulnerabilities\n Affecting Multiple Implementations <https://duo.com/blog/duo-finds-saml-vulnerabilities-affecting-multiple-implementations>`_\n\n.. admonition:: Establish trust\n\n If you do not supply any keyword arguments to ``verify()``, the default behavior is to trust **any** valid XML\n signature generated using a valid X.509 certificate trusted by your system's CA store. This means anyone can\n get an SSL certificate and generate a signature that you will trust. To establish trust in the signer, use the\n ``x509_cert`` argument to specify a certificate that was pre-shared out-of-band (e.g. via SAML metadata, as\n shown in *Verifying SAML assertions*), or ``cert_subject_name`` to specify a\n subject name that must be in the signing X.509 certificate given by the signature (verified as if it were a\n domain name), or ``ca_pem_file``/``ca_path`` to give a custom CA.\n\nXML signature construction methods: enveloped, detached, enveloping\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nThe XML Signature specification defines three ways to compose a signature with the data being signed: enveloped,\ndetached, and enveloping signature. Enveloped is the default method. To specify the type of signature that you want to\ngenerate, pass the ``method`` argument to ``sign()``:\n\n.. code-block:: python\n\n signed_root = XMLSigner(method=signxml.methods.detached).sign(root, key=key, cert=cert)\n verified_data = XMLVerifier().verify(signed_root).signed_xml\n\nFor detached signatures, the code above will use the ``Id`` or ``ID`` attribute of ``root`` to generate a relative URI\n(``<Reference URI=\"#value\"``). You can also override the value of ``URI`` by passing a ``reference_uri`` argument to\n``sign()``. To verify a detached signature that refers to an external entity, pass a callable resolver in\n``XMLVerifier().verify(data, uri_resolver=...)``.\n\nSee the `API documentation <https://xml-security.github.io/signxml/#id5>`_ for more details.\n\n\nXML representation details: Configuring namespace prefixes and whitespace\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nSome applications require a particular namespace prefix configuration - for example, a number of applications assume\nthat the ``http://www.w3.org/2000/09/xmldsig#`` namespace is set as the default, unprefixed namespace instead of using\nthe customary ``ds:`` prefix. While in normal use namespace prefix naming is an insignificant representation detail,\nit can be significant in some XML canonicalization and signature configurations. To configure the namespace prefix map\nwhen generating a signature, set the ``XMLSigner.namespaces`` attribute:\n\n.. code-block:: python\n\n signer = signxml.XMLSigner(...)\n signer.namespaces = {None: signxml.namespaces.ds}\n signed_root = signer.sign(...)\n\nSimilarly, whitespace in the signed document is significant for XML canonicalization and signature purposes. Do not\npretty-print the XML after generating the signature, since this can unfortunately render the signature invalid.\n\n\nXML parsing security and compatibility with ``xml.etree.ElementTree``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nSignXML uses the `lxml <https://github.com/lxml/lxml>`_ ElementTree library, not the\n`ElementTree from Python's standard library <https://docs.python.org/3.8/library/xml.etree.elementtree.html>`_,\nto work with XML. lxml is used due to its superior resistance to XML attacks, as well as XML canonicalization and\nnamespace organization features. It is recommended that you pass XML string input directly to signxml before further\nparsing, and use lxml to work with untrusted XML input in general. If you do pass ``xml.etree.ElementTree`` objects to\nSignXML, you should be aware of differences in XML namespace handling between the two libraries. See the following\nreferences for more information:\n\n* `How do I use lxml safely as a web-service endpoint?\n <https://lxml.de/FAQ.html#how-do-i-use-lxml-safely-as-a-web-service-endpoint>`_\n* `ElementTree compatibility of lxml.etree <https://lxml.de/compatibility.html>`_\n* `XML Signatures with Python ElementTree <https://technotes.shemyak.com/posts/xml-signatures-with-python-elementtree>`_\n\n\nXAdES signatures\n~~~~~~~~~~~~~~~~\n`XAdES (\"XML Advanced Electronic Signatures\") <https://en.wikipedia.org/wiki/XAdES>`_ is a standard for attaching\nmetadata to XML Signature objects. This standard is endorsed by the European Union as the implementation for its\n`eSignature <https://ec.europa.eu/digital-building-blocks/wikis/display/DIGITAL/eSignature+Overview>`_ regulations.\n\nSignXML supports signing and verifying documents using `XAdES <https://en.wikipedia.org/wiki/XAdES>`_ signatures:\n\n.. code-block:: python\n\n from signxml import DigestAlgorithm\n from signxml.xades import (XAdESSigner, XAdESVerifier, XAdESVerifyResult,\n XAdESSignaturePolicy, XAdESDataObjectFormat)\n signature_policy = XAdESSignaturePolicy(\n Identifier=\"MyPolicyIdentifier\",\n Description=\"Hello XAdES\",\n DigestMethod=DigestAlgorithm.SHA256,\n DigestValue=\"Ohixl6upD6av8N7pEvDABhEL6hM=\",\n )\n data_object_format = XAdESDataObjectFormat(\n Description=\"My XAdES signature\",\n MimeType=\"text/xml\",\n )\n signer = XAdESSigner(\n signature_policy=signature_policy,\n claimed_roles=[\"signer\"],\n data_object_format=data_object_format,\n c14n_algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\",\n )\n signed_doc = signer.sign(doc, key=private_key, cert=certificate)\n\n.. code-block:: python\n\n verifier = XAdESVerifier()\n verify_results = verifier.verify(\n signed_doc, x509_cert=certificate, expect_references=3, expect_signature_policy=signature_policy\n )\n for verify_result in verify_results:\n if isinstance(verify_result, XAdESVerifyResult):\n verify_result.signed_properties # use this to access parsed XAdES properties\n\nAuthors\n-------\n* `Andrey Kislyuk <https://github.com/kislyuk>`_ and SignXML contributors.\n\nLinks\n-----\n* `Project home page (GitHub) <https://github.com/XML-Security/signxml>`_\n* `Documentation <https://xml-security.github.io/signxml/>`_\n* `Package distribution (PyPI) <https://pypi.python.org/pypi/signxml>`_\n* `Change log <https://github.com/XML-Security/signxml/blob/master/Changes.rst>`_\n* `List of W3C XML Signature standards and drafts <https://www.w3.org/TR/?title=xml%20signature>`_\n* `W3C Recommendation: XML Signature Syntax and Processing Version 1.1 <http://www.w3.org/TR/xmldsig-core1>`_\n* `W3C Working Group Note: XML Signature Best Practices <http://www.w3.org/TR/xmldsig-bestpractices/>`_\n* `XML-Signature Interoperability <http://www.w3.org/Signature/2001/04/05-xmldsig-interop.html>`_\n* `W3C Working Group Note: Test Cases for C14N 1.1 and XMLDSig Interoperability <http://www.w3.org/TR/xmldsig2ed-tests/>`_\n* `W3C Working Group Note: XML Signature Syntax and Processing Version 2.0 <http://www.w3.org/TR/xmldsig-core2>`_\n (This draft standard proposal was never finalized and is not in general use.)\n* `Intelligence Community Technical Specification: Web Service Security Guidance for Use of XML Signature and XML\n Encryption <https://github.com/XML-Security/signxml/blob/develop/docs/dni-guidance.pdf>`_\n* `XMLSec: Related links <https://www.aleksey.com/xmlsec/related.html>`_\n* `OWASP SAML Security Cheat Sheet <https://www.owasp.org/index.php/SAML_Security_Cheat_Sheet>`_\n* `Okta Developer Docs: SAML <https://developer.okta.com/standards/SAML/>`_\n\nBugs\n~~~~\nPlease report bugs, issues, feature requests, etc. on `GitHub <https://github.com/XML-Security/signxml/issues>`_.\n\nVersioning\n~~~~~~~~~~\nThis package follows the `Semantic Versioning 2.0.0 <http://semver.org/>`_ standard. To control changes, it is\nrecommended that application developers pin the package version and manage it using `pip-tools\n<https://github.com/jazzband/pip-tools>`_ or similar. For library developers, pinning the major version is\nrecommended.\n\nLicense\n-------\nCopyright 2014-2023, Andrey Kislyuk and SignXML contributors. Licensed under the terms of the\n`Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>`_. Distribution of the LICENSE and NOTICE\nfiles with source copies of this package and derivative works is **REQUIRED** as specified by the Apache License.\n\n.. image:: https://github.com/XML-Security/signxml/workflows/Test%20suite/badge.svg\n :target: https://github.com/XML-Security/signxml/actions\n.. image:: https://codecov.io/github/XML-Security/signxml/coverage.svg?branch=master\n :target: https://codecov.io/github/XML-Security/signxml?branch=master\n.. image:: https://img.shields.io/pypi/v/signxml.svg\n :target: https://pypi.python.org/pypi/signxml\n.. image:: https://img.shields.io/pypi/l/signxml.svg\n :target: https://pypi.python.org/pypi/signxml\n",
"bugtrack_url": null,
"license": "Apache Software License",
"summary": "Python XML Signature and XAdES library: Original work from Andrey Kislyuk, forked and targetted for pull request.",
"version": "3.2.3",
"project_urls": {
"Homepage": "https://github.com/datastyx-dev/signxml.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "96e7374d7fbb6246242c9869a956f7d23dd3b9d0b3000c04a74d6f9bc7812a55",
"md5": "d09a94bf216b2b32b2fda5023686a4d9",
"sha256": "5f91d65b0af3dae9495b2ce896de05a085bfd1101af773f9ce6ede45e01b8cfc"
},
"downloads": -1,
"filename": "custom_signxml-3.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d09a94bf216b2b32b2fda5023686a4d9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 59113,
"upload_time": "2024-06-18T14:32:37",
"upload_time_iso_8601": "2024-06-18T14:32:37.292630Z",
"url": "https://files.pythonhosted.org/packages/96/e7/374d7fbb6246242c9869a956f7d23dd3b9d0b3000c04a74d6f9bc7812a55/custom_signxml-3.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dfad2bcde49550e452069d3ecb76087f46fe67078e9a5acb2fdc45d06171df1e",
"md5": "0728fe70234e1a51bb5e751b9d1b212d",
"sha256": "fe8dc943c861780b0a24266c70841164e9c503188b8295cf0e1709f435290fdc"
},
"downloads": -1,
"filename": "custom_signxml-3.2.3.tar.gz",
"has_sig": false,
"md5_digest": "0728fe70234e1a51bb5e751b9d1b212d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 54977,
"upload_time": "2024-06-18T14:32:42",
"upload_time_iso_8601": "2024-06-18T14:32:42.088783Z",
"url": "https://files.pythonhosted.org/packages/df/ad/2bcde49550e452069d3ecb76087f46fe67078e9a5acb2fdc45d06171df1e/custom_signxml-3.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-18 14:32:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "datastyx-dev",
"github_project": "signxml",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "custom-signxml"
}