Skip to content

Instantly share code, notes, and snippets.

@markwallsgrove
Created February 24, 2017 12:19
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 markwallsgrove/94169332da50592e3f4a8e2195b07d01 to your computer and use it in GitHub Desktop.
Save markwallsgrove/94169332da50592e3f4a8e2195b07d01 to your computer and use it in GitHub Desktop.
Summarise SSL signature hash type used by providers within SAML federation
#!/usr/bin/python2.7
import lxml.etree as etree
from cryptography import x509
from cryptography.hazmat.backends import default_backend
def chunkstring(string, length):
return (string[0+i:length+i] for i in range(0, len(string), length))
def main():
with open('fed.xml', 'r') as myfile:
data = myfile.read().replace('\n', '')
hashes = {}
root = etree.fromstring(data)
for x in root.xpath("//*[local-name() = 'X509Certificate']"):
text = x.text.replace("\n", "").replace(" ", "").replace("\t", "")
text = "\n".join(chunkstring(text, 64))
certText = "\n".join(["-----BEGIN CERTIFICATE-----", text, '-----END CERTIFICATE-----'])
cert = x509.load_pem_x509_certificate(certText, default_backend())
certName = cert.signature_hash_algorithm.name
if certName not in hashes:
hashes[certName] = 0
hashes[certName] += 1
print hashes
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment