Skip to content

Instantly share code, notes, and snippets.

@markcallen
Last active June 8, 2018 14:39
Show Gist options
  • Select an option

  • Save markcallen/6e027b694a6fe0a3a01413b68616fdc9 to your computer and use it in GitHub Desktop.

Select an option

Save markcallen/6e027b694a6fe0a3a01413b68616fdc9 to your computer and use it in GitHub Desktop.
Get the encryption certificate from an ADFS metadata file
import sys
from xml.etree import cElementTree as ET
x509s = []
def read_in():
return ET.fromstring(sys.stdin.read())
def main():
xml = read_in()
for e in xml.findall(".//*[@use='signing']"):
for x509 in e.iter("{http://www.w3.org/2000/09/xmldsig#}X509Certificate"):
x509s.append(x509.text)
for x in range(1, len(x509s)):
if x509s[x] != x509s[x-1]:
raise ValueError("x509 encryption certificates are not the same")
print x509s[0]
if __name__ == '__main__':
main()
@markcallen
Copy link
Copy Markdown
Author

Takes the xml file from standard in

python getcert.py < federated.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment