Skip to content

Commit 0ab5f74

Browse files
committed
Begin XAdES documentation
1 parent cadfe8e commit 0ab5f74

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

README.rst

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ payload security in `SAML 2.0 <http://en.wikipedia.org/wiki/SAML_2.0>`_ and
1111
* Use of a libxml2-based XML parser configured to defend against
1212
`common XML attacks <https://docs.python.org/3/library/xml.html#xml-vulnerabilities>`_ when verifying signatures
1313
* Extensions to allow signing with and verifying X.509 certificate chains, including hostname/CN validation
14+
* Extensions to sign and verify `XAdES <https://en.wikipedia.org/wiki/XAdES>`_ signatures
1415
* Support for exclusive XML canonicalization with inclusive prefixes (`InclusiveNamespaces PrefixList
1516
<http://www.w3.org/TR/xml-exc-c14n/#def-InclusiveNamespaces-PrefixList>`_, required to verify signatures generated by
1617
some SAML implementations)
17-
* Modern Python compatibility (3.6-3.10+ and PyPy)
18+
* Modern Python compatibility (3.6-3.11+ and PyPy)
1819
* Well-supported, portable, reliable dependencies: `lxml <https://github.com/lxml/lxml>`_,
1920
`cryptography <https://github.com/pyca/cryptography>`_, `pyOpenSSL <https://github.com/pyca/pyopenssl>`_
2021
* Comprehensive testing (including the XMLDSig interoperability suite) and `continuous integration
@@ -167,6 +168,38 @@ references for more information:
167168
* `ElementTree compatibility of lxml.etree <https://lxml.de/compatibility.html>`_
168169
* `XML Signatures with Python ElementTree <https://technotes.shemyak.com/posts/xml-signatures-with-python-elementtree>`_
169170

171+
172+
XAdES signatures
173+
~~~~~~~~~~~~~~~~
174+
SignXML supports signing and verifying documents using `XAdES <https://en.wikipedia.org/wiki/XAdES>`_ signatures:
175+
176+
.. code-block:: python
177+
178+
from signxml.xades import XAdESSigner, XAdESVerifier, XAdESVerifyResult, digest_algorithms
179+
signature_policy = {
180+
"Identifier": "MyPolicyIdentifier",
181+
"Description": "Hello XAdES",
182+
"DigestMethod": digest_algorithms.SHA256,
183+
"DigestValue": "Ohixl6upD6av8N7pEvDABhEL6hM=",
184+
}
185+
signer = XAdESSigner(
186+
signature_policy=signature_policy,
187+
claimed_roles=["signer"],
188+
data_object_format={"Description": "My XAdES signature", "MimeType": "text/xml"},
189+
c14n_algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
190+
)
191+
signed_doc = signer.sign(doc, key=private_key, cert=certificate)
192+
193+
.. code-block:: python
194+
195+
verifier = XAdESVerifier()
196+
verify_results = verifier.verify(
197+
signed_doc, x509_cert=certificate, expect_references=3, expect_signature_policy=signature_policy
198+
)
199+
for verify_result in verify_results:
200+
if isinstance(verify_result, XAdESVerifyResult):
201+
verify_result.signed_properties # use this to access parsed XAdES properties
202+
170203
Authors
171204
-------
172205
* Andrey Kislyuk

0 commit comments

Comments
 (0)