Minimal XML signature and verification, intended for use with SAML2
Maintained. Last release 10 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install minisignxmlminisignxml
Python library to sign and verify XML documents.
This library, on purpose, only supports a limited part of the xmldsig specification. It is mainly aimed at allowing SAML documents to be signed and verified.
Supported features:
- Simple API.
- Only support enveloped signatures (
http://www.w3.org/2000/09/xmldsig#enveloped-signature) - Require and only support exclusive XML canonincalization without comments (
http://www.w3.org/2001/10/xml-exc-c14n#) - Support SHA-256 (default) and SHA-1 (for compatibility, not recommended) for signing and digest (
https://www.w3.org/2000/09/xmldsig#sha1,https://www.w3.org/2000/09/xmldsig#rsa-sha1,http://www.w3.org/2001/04/xmlenc#sha256,http://www.w3.org/2001/04/xmldsig-more#rsa-sha256) - Only support X509 certificates and RSA private keys
- Uses
lxmlfor XML handling andcryptographyfor cryptography. - Only supports a single signature, with a single reference in a document.
- Support certificate rollover by providing multiple certificates when verifying a document.
minisignxml performs no IO and you have to manage and load the keys/certificates yourself.
API
Signing
minisignxml.sign.sign
def sign(
*,
element: Element,
private_key: RSAPrivateKey,
certificate: Certificate,
config: SigningConfig = SigningConfig.default(),
index: int = 0,
attribute: str = "ID"
) -> bytes:
Signs the given lxml.etree._Element with the given cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey private key, embedding the cryptography.x509.Certificate in the signature. Use minisignxml.config.SigningConfig to control the hash algorithms uses (default is SHA-256). The index controls at which index the signature element is appended to the element.
If the element passed in does not have an attribute matching attribute, an exception is raised. It is the callers responsibility to ensure the value of the attribute of the is unique for the whole document.