1
1
#!/usr/bin/env python
2
+ from saml2 .md import AttributeProfile , entity_descriptor_from_string
2
3
from saml2 .sigver import security_context
3
4
from saml2 .config import Config
4
5
from saml2 .validate import valid_instance
52
53
"organization_url" : ("url" , md .OrganizationURL )
53
54
}
54
55
56
+ MDNS = '"urn:oasis:names:tc:SAML:2.0:metadata"'
57
+ XMLNSXS = " xmlns:xs=\" http://www.w3.org/2001/XMLSchema\" "
55
58
56
- def metadata_tostring_fix ( desc , nspair ):
57
- MDNS = '"urn:oasis:names:tc:SAML:2.0:metadata"'
58
- XMLNSXS = " xmlns:xs= \" http://www.w3.org/2001/XMLSchema \" "
59
- xmlstring = desc .to_string (nspair )
59
+
60
+ def metadata_tostring_fix ( desc , nspair , xmlstring = "" ):
61
+ if not xmlstring :
62
+ xmlstring = desc .to_string (nspair )
60
63
if "\" xs:string\" " in xmlstring and XMLNSXS not in xmlstring :
61
64
xmlstring = xmlstring .replace (MDNS , MDNS + XMLNSXS )
62
65
return xmlstring
@@ -94,13 +97,15 @@ def create_metadata_string(configfile, config, valid, cert, keyfile, mid, name,
94
97
95
98
return metadata_tostring_fix (desc , nspair )
96
99
else :
97
- for eid in eds :
98
- if sign :
99
- desc = sign_entity_descriptor (eid , mid , secc )
100
- else :
101
- desc = eid
102
- valid_instance (desc )
103
- return metadata_tostring_fix (desc , nspair )
100
+ eid = eds [0 ]
101
+ if sign :
102
+ eid , xmldoc = sign_entity_descriptor (eid , mid , secc )
103
+ else :
104
+ xmldoc = None
105
+
106
+ valid_instance (eid )
107
+ xmldoc = metadata_tostring_fix (eid , nspair , xmldoc )
108
+ return xmldoc
104
109
105
110
106
111
def _localized_name (val , klass ):
@@ -598,6 +603,16 @@ def do_aa_descriptor(conf, cert):
598
603
if cert :
599
604
aad .key_descriptor = do_key_descriptor (cert )
600
605
606
+ attributes = conf .getattr ("attribute" , "aa" )
607
+ if attributes :
608
+ for attribute in attributes :
609
+ aad .attribute .append (Attribute (text = attribute ))
610
+
611
+ attribute_profiles = conf .getattr ("attribute_profile" , "aa" )
612
+ if attribute_profiles :
613
+ for attribute_profile in attribute_profiles :
614
+ aad .attribute .append (AttributeProfile (text = attribute_profile ))
615
+
601
616
return aad
602
617
603
618
@@ -712,14 +727,26 @@ def entities_descriptor(eds, valid_for, name, ident, sign, secc):
712
727
entities .id = ident
713
728
xmldoc = secc .sign_statement ("%s" % entities , class_name (entities ))
714
729
entities = md .entities_descriptor_from_string (xmldoc )
715
- return entities
730
+ else :
731
+ xmldoc = None
732
+
733
+ return entities , xmldoc
716
734
717
735
718
736
def sign_entity_descriptor (edesc , ident , secc ):
737
+ """
738
+
739
+ :param edesc: EntityDescriptor instance
740
+ :param ident: EntityDescriptor identifier
741
+ :param secc: Security context
742
+ :return: Tuple with EntityDescriptor instance and Signed XML document
743
+ """
744
+
719
745
if not ident :
720
746
ident = sid ()
721
747
722
748
edesc .signature = pre_signature_part (ident , secc .my_cert , 1 )
723
749
edesc .id = ident
724
750
xmldoc = secc .sign_statement ("%s" % edesc , class_name (edesc ))
725
- return md .entity_descriptor_from_string (xmldoc )
751
+ edesc = md .entity_descriptor_from_string (xmldoc )
752
+ return edesc , xmldoc
0 commit comments