Skip to content
Snippets Groups Projects

Added support for multiple security contacts

Merged Davide Vaghetti requested to merge davide.vaghetti/edugain-contacts:master into master
1 file
+ 27
26
Compare changes
  • Side-by-side
  • Inline
+ 27
26
@@ -19,7 +19,7 @@ xml_req = requests.get('https://mds.edugain.org/edugain-v1.xml')
@@ -19,7 +19,7 @@ xml_req = requests.get('https://mds.edugain.org/edugain-v1.xml')
root = ET.fromstring(xml_req.content)
root = ET.fromstring(xml_req.content)
contacts = set()
contacts = set()
seen_doms = set()
seen_doms_mails = set()
ns = {
ns = {
'md': 'urn:oasis:names:tc:SAML:2.0:metadata',
'md': 'urn:oasis:names:tc:SAML:2.0:metadata',
@@ -33,36 +33,37 @@ ns = {
@@ -33,36 +33,37 @@ ns = {
entities = root.findall('./md:EntityDescriptor', ns)
entities = root.findall('./md:EntityDescriptor', ns)
for entity in entities:
for entity in entities:
 
sec_mails = set()
orgname = entity.find('./md:Organization/md:OrganizationDisplayName', ns).text.strip()
orgname = entity.find('./md:Organization/md:OrganizationDisplayName', ns).text.strip()
if not orgname:
if not orgname:
continue
continue
contact = entity.find('./md:ContactPerson[@remd:contactType="http://refeds.org/metadata/contactType/security"]', ns)
sec_contact_els = entity.findall('./md:ContactPerson[@remd:contactType="http://refeds.org/metadata/contactType/security"]', ns) + \
if contact is None:
entity.findall('./md:ContactPerson[@icmd:contactType="http://id.incommon.org/metadata/contactType/security"]', ns)
contact = entity.find(
for sec_contact_el in sec_contact_els:
'./md:ContactPerson[@icmd:contactType="http://id.incommon.org/metadata/contactType/security"]', ns)
mail_el = sec_contact_el.find('./md:EmailAddress', ns)
if contact is None:
name_el = sec_contact_el.find('./md:GivenName', ns)
continue
surname_el = sec_contact_el.find('./md:SurName', ns)
mail_el = contact.find('./md:EmailAddress', ns)
if mail_el is None:
if mail_el is None:
continue
continue
mail = strip_start(mail_el.text, 'mailto:')
name_el = contact.find('./md:GivenName', ns)
if name_el is not None:
surname_el = contact.find('./md:SurName', ns)
name = name_el.text.strip()
mail = strip_start(mail_el.text, 'mailto:')
if surname_el is not None:
if name_el is not None:
surname = surname_el.text.strip()
name = name_el.text.strip()
sec_mails.add('"{} {}" <{}>'.format(name, surname, mail))
if surname_el is not None:
else:
surname = surname_el.text.strip()
sec_mails.add('"{}" <{}>'.format(name, mail))
contact_txt = '"{} {}" <{}>'.format(name, surname, mail)
else:
else:
contact_txt = '"{}" <{}>'.format(name, mail)
sec_mails.add(mail)
else:
contact_txt = mail
doms = entity.findall('./md:IDPSSODescriptor/md:Extensions/shibmd:Scope[@regexp="false"]', ns)
doms = entity.findall('./md:IDPSSODescriptor/md:Extensions/shibmd:Scope[@regexp="false"]', ns)
for domain in doms:
doms_set = set()
domain_text = domain.text
for dom in doms:
if domain_text not in seen_doms:
doms_set.add(dom.text)
seen_doms.add(domain_text)
for domain in doms_set:
contacts.add('{},{},{}'.format(domain_text, contact_txt, orgname))
for mail in sec_mails:
 
if (domain,mail) not in seen_doms_mails:
 
seen_doms_mails.add((domain, mail))
 
contacts.add('{},{},{}'.format(domain, mail, orgname))
for contact in sorted(contacts):
for contact in sorted(contacts):
print(contact)
print(contact)
Loading