Created
June 29, 2020 12:40
-
-
Save FrankSpierings/a3361fe2e3d7467e0e1adbff38ccaae2 to your computer and use it in GitHub Desktop.
If SAML Raider won't re-sign the requests....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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