Skip to content
Snippets Groups Projects
Commit 8c298b0f authored by Martin van Es's avatar Martin van Es
Browse files

First commit

parent fd33fc8a
Branches
No related tags found
No related merge requests found
# created by virtualenv automatically
bin/
lib/
pyvenv.cfg
meta.crt
meta.key
*.xml
# alternate-mdx # alternate-mdx
Alternate MDX research project Alternate MDX research project
\ No newline at end of file
## Usage
- Create python virtualenv
- Activate virtualenv (```. bin/activate```)
- ```pip install -r requirements.txt```
- Create (self-signed) metadata signing cert (```meta.crt/meta.key```)
- Create output directory (```mkdir output```)
- Download metadata file(s)
- Run ```./mdsigner <metadata file(s)>```
\ No newline at end of file
#!/usr/bin/env python
import sys
import copy
from concurrent.futures import ThreadPoolExecutor
from lxml import etree as ET
from signxml import XMLSigner, XMLVerifier
import hashlib
# import traceback
# Find all IdP's in edugain metadata
idps = []
success = 0
failed = 0
maxthreads = 8
cert = open("meta.crt").read()
key = open("meta.key").read()
def sign(xml, name):
global success, failed, cert
# print("Signer")
try:
sha1 = hashlib.sha1()
sha1.update(name.encode('utf-8'))
sha1d = sha1.hexdigest()
signed = XMLSigner().sign(xml, key=key, cert=cert)
out = ET.tostring(signed, pretty_print=True).decode()
# XMLVerifier().verify(out, x509_cert=cert)
with open(f'output/{sha1d}.xml', 'w') as f:
f.write(out)
success += 1
except Exception as e:
print(name)
print(f" {e}")
# traceback.print_exc()
failed += 1
with ThreadPoolExecutor(max_workers=maxthreads) as executor:
for mdfile in sys.argv[1:]:
tree = ET.ElementTree(file=mdfile)
root = tree.getroot()
ns = copy.deepcopy(root.nsmap)
ns['xml'] = 'http://www.w3.org/XML/1998/namespace'
for idp in root.findall('md:EntityDescriptor', ns):
entityID = idp.attrib.get('entityID', 'none')
if entityID not in idps:
idps.append(entityID)
executor.submit(sign, idp, entityID)
print(f"Succeeded: {success}")
print(f"Failed: {failed}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment