<s> from saml2 . md import AttributeProfile <EOL> from saml2 . sigver import security_context <EOL> from saml2 . config import Config <EOL> from saml2 . validate import valid_instance <EOL> from saml2 . time_util import in_a_while <EOL> from saml2 . extension import mdui <EOL> from saml2 . extension import idpdisc <EOL> from saml2 . extension import shibmd <EOL> from saml2 . extension import mdattr <EOL> from saml2 . saml import NAME_FORMAT_URI <EOL> from saml2 . saml import AttributeValue <EOL> from saml2 . saml import Attribute <EOL> from saml2 . attribute_converter import from_local_name <EOL> from saml2 import md , SAMLError <EOL> from saml2 import BINDING_HTTP_POST <EOL> from saml2 import BINDING_HTTP_REDIRECT <EOL> from saml2 import BINDING_SOAP <EOL> from saml2 import samlp <EOL> from saml2 import class_name <EOL> import xmldsig as ds <EOL> from saml2 . sigver import pre_signature_part <EOL> from saml2 . s_utils import factory <EOL> from saml2 . s_utils import rec_factory <EOL> from saml2 . s_utils import sid <EOL> __author__ = '<STR_LIT>' <EOL> NSPAIR = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> DEFAULTS = { <EOL> "<STR_LIT>" : "<STR_LIT:true>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> "<STR_LIT>" : "<STR_LIT:true>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> } <EOL> ORG_ATTR_TRANSL = { <EOL> "<STR_LIT>" : ( "<STR_LIT:name>" , md . OrganizationName ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , md . OrganizationDisplayName ) , <EOL> "<STR_LIT>" : ( "<STR_LIT:url>" , md . OrganizationURL ) <EOL> } <EOL> MDNS = '<STR_LIT>' <EOL> XMLNSXS = "<STR_LIT>" <EOL> def metadata_tostring_fix ( desc , nspair , xmlstring = "<STR_LIT>" ) : <EOL> if not xmlstring : <EOL> xmlstring = desc . to_string ( nspair ) <EOL> if "<STR_LIT>" in xmlstring and XMLNSXS not in xmlstring : <EOL> xmlstring = xmlstring . replace ( MDNS , MDNS + XMLNSXS ) <EOL> return xmlstring <EOL> def create_metadata_string ( configfile , config , valid , cert , keyfile , mid , name , <EOL> sign ) : <EOL> valid_for = <NUM_LIT:0> <EOL> nspair = { "<STR_LIT>" : "<STR_LIT>" } <EOL> if valid : <EOL> valid_for = int ( valid ) <EOL> eds = [ ] <EOL> if config is not None : <EOL> eds . append ( entity_descriptor ( config ) ) <EOL> else : <EOL> if configfile . endswith ( "<STR_LIT>" ) : <EOL> configfile = configfile [ : - <NUM_LIT:3> ] <EOL> config = Config ( ) . load_file ( configfile , metadata_construction = True ) <EOL> eds . append ( entity_descriptor ( config ) ) <EOL> conf = Config ( ) <EOL> conf . key_file = keyfile <EOL> conf . cert_file = cert <EOL> conf . debug = <NUM_LIT:1> <EOL> conf . xmlsec_binary = config . xmlsec_binary <EOL> secc = security_context ( conf ) <EOL> if mid : <EOL> desc = entities_descriptor ( eds , valid_for , name , mid , <EOL> sign , secc ) <EOL> valid_instance ( desc ) <EOL> return metadata_tostring_fix ( desc , nspair ) <EOL> else : <EOL> eid = eds [ <NUM_LIT:0> ] <EOL> if sign : <EOL> eid , xmldoc = sign_entity_descriptor ( eid , mid , secc ) <EOL> else : <EOL> xmldoc = None <EOL> valid_instance ( eid ) <EOL> xmldoc = metadata_tostring_fix ( eid , nspair , xmldoc ) <EOL> return xmldoc <EOL> def _localized_name ( val , klass ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> ( text , lang ) = val <EOL> return klass ( text = text , lang = lang ) <EOL> except ValueError : <EOL> return klass ( text = val , lang = "<STR_LIT>" ) <EOL> def do_organization_info ( ava ) : <EOL> """<STR_LIT>""" <EOL> if ava is None : <EOL> return None <EOL> org = md . Organization ( ) <EOL> for dkey , ( ckey , klass ) in ORG_ATTR_TRANSL . items ( ) : <EOL> if ckey not in ava : <EOL> continue <EOL> if isinstance ( ava [ ckey ] , basestring ) : <EOL> setattr ( org , dkey , [ _localized_name ( ava [ ckey ] , klass ) ] ) <EOL> elif isinstance ( ava [ ckey ] , list ) : <EOL> setattr ( org , dkey , <EOL> [ _localized_name ( n , klass ) for n in ava [ ckey ] ] ) <EOL> else : <EOL> setattr ( org , dkey , [ _localized_name ( ava [ ckey ] , klass ) ] ) <EOL> return org <EOL> def do_contact_person_info ( lava ) : <EOL> """<STR_LIT>""" <EOL> cps = [ ] <EOL> if lava is None : <EOL> return cps <EOL> contact_person = md . ContactPerson <EOL> for ava in lava : <EOL> cper = md . ContactPerson ( ) <EOL> for ( key , classpec ) in contact_person . c_children . values ( ) : <EOL> try : <EOL> value = ava [ key ] <EOL> data = [ ] <EOL> if isinstance ( classpec , list ) : <EOL> if isinstance ( value , basestring ) : <EOL> data = [ classpec [ <NUM_LIT:0> ] ( text = value ) ] <EOL> else : <EOL> for val in value : <EOL> data . append ( classpec [ <NUM_LIT:0> ] ( text = val ) ) <EOL> else : <EOL> data = classpec ( text = value ) <EOL> setattr ( cper , key , data ) <EOL> except KeyError : <EOL> pass <EOL> for ( prop , classpec , _ ) in contact_person . c_attributes . values ( ) : <EOL> try : <EOL> setattr ( cper , prop , ava [ prop ] ) <EOL> except KeyError : <EOL> pass <EOL> typ = getattr ( cper , "<STR_LIT>" ) <EOL> if not typ : <EOL> setattr ( cper , "<STR_LIT>" , "<STR_LIT>" ) <EOL> cps . append ( cper ) <EOL> return cps <EOL> def do_key_descriptor ( cert , use = "<STR_LIT>" ) : <EOL> if use == "<STR_LIT>" : <EOL> return [ <EOL> md . KeyDescriptor ( <EOL> key_info = ds . KeyInfo ( <EOL> x509_data = ds . X509Data ( <EOL> x509_certificate = ds . X509Certificate ( text = cert ) <EOL> ) <EOL> ) , <EOL> use = "<STR_LIT>" <EOL> ) , <EOL> md . KeyDescriptor ( <EOL> key_info = ds . KeyInfo ( <EOL> x509_data = ds . X509Data ( <EOL> x509_certificate = ds . X509Certificate ( text = cert ) <EOL> ) <EOL> ) , <EOL> use = "<STR_LIT>" <EOL> ) <EOL> ] <EOL> elif use in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> return md . KeyDescriptor ( <EOL> key_info = ds . KeyInfo ( <EOL> x509_data = ds . X509Data ( <EOL> x509_certificate = ds . X509Certificate ( text = cert ) <EOL> ) <EOL> ) , <EOL> use = use <EOL> ) <EOL> else : <EOL> return md . KeyDescriptor ( <EOL> key_info = ds . KeyInfo ( <EOL> x509_data = ds . X509Data ( <EOL> x509_certificate = ds . X509Certificate ( text = cert ) <EOL> ) <EOL> ) <EOL> ) <EOL> def do_requested_attribute ( attributes , acs , is_required = "<STR_LIT:false>" ) : <EOL> lista = [ ] <EOL> for attr in attributes : <EOL> attr = from_local_name ( acs , attr , NAME_FORMAT_URI ) <EOL> args = { } <EOL> for key in attr . keyswv ( ) : <EOL> args [ key ] = getattr ( attr , key ) <EOL> args [ "<STR_LIT>" ] = is_required <EOL> args [ "<STR_LIT>" ] = NAME_FORMAT_URI <EOL> lista . append ( md . RequestedAttribute ( ** args ) ) <EOL> return lista <EOL> def do_uiinfo ( _uiinfo ) : <EOL> uii = mdui . UIInfo ( ) <EOL> for attr in [ '<STR_LIT>' , '<STR_LIT:description>' , "<STR_LIT>" , <EOL> '<STR_LIT>' ] : <EOL> try : <EOL> val = _uiinfo [ attr ] <EOL> except KeyError : <EOL> continue <EOL> aclass = uii . child_class ( attr ) <EOL> inst = getattr ( uii , attr ) <EOL> if isinstance ( val , basestring ) : <EOL> ainst = aclass ( text = val ) <EOL> inst . append ( ainst ) <EOL> elif isinstance ( val , dict ) : <EOL> ainst = aclass ( ) <EOL> ainst . text = val [ "<STR_LIT:text>" ] <EOL> ainst . lang = val [ "<STR_LIT>" ] <EOL> inst . append ( ainst ) <EOL> else : <EOL> for value in val : <EOL> if isinstance ( value , basestring ) : <EOL> ainst = aclass ( text = value ) <EOL> inst . append ( ainst ) <EOL> elif isinstance ( value , dict ) : <EOL> ainst = aclass ( ) <EOL> ainst . text = value [ "<STR_LIT:text>" ] <EOL> ainst . lang = value [ "<STR_LIT>" ] <EOL> inst . append ( ainst ) <EOL> try : <EOL> _attr = "<STR_LIT>" <EOL> val = _uiinfo [ _attr ] <EOL> inst = getattr ( uii , _attr ) <EOL> if isinstance ( val , dict ) : <EOL> logo = mdui . Logo ( ) <EOL> for attr , value in val . items ( ) : <EOL> if attr in logo . keys ( ) : <EOL> setattr ( logo , attr , value ) <EOL> inst . append ( logo ) <EOL> elif isinstance ( val , list ) : <EOL> for logga in val : <EOL> if not isinstance ( logga , dict ) : <EOL> raise SAMLError ( "<STR_LIT>" ) <EOL> logo = mdui . Logo ( ) <EOL> for attr , value in logga . items ( ) : <EOL> if attr in logo . keys ( ) : <EOL> setattr ( logo , attr , value ) <EOL> inst . append ( logo ) <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> _attr = "<STR_LIT>" <EOL> val = _uiinfo [ _attr ] <EOL> inst = getattr ( uii , _attr ) <EOL> if isinstance ( val , list ) : <EOL> for value in val : <EOL> keyw = mdui . Keywords ( ) <EOL> if isinstance ( value , basestring ) : <EOL> keyw . text = value <EOL> elif isinstance ( value , dict ) : <EOL> keyw . text = "<STR_LIT:U+0020>" . join ( value [ "<STR_LIT:text>" ] ) <EOL> try : <EOL> keyw . lang = value [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> raise SAMLError ( "<STR_LIT>" ) <EOL> inst . append ( keyw ) <EOL> elif isinstance ( val , dict ) : <EOL> keyw = mdui . Keywords ( ) <EOL> keyw . text = "<STR_LIT:U+0020>" . join ( val [ "<STR_LIT:text>" ] ) <EOL> try : <EOL> keyw . lang = val [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> pass <EOL> inst . append ( keyw ) <EOL> else : <EOL> raise SAMLError ( "<STR_LIT>" ) <EOL> except KeyError : <EOL> pass <EOL> return uii <EOL> def do_idpdisc ( discovery_response ) : <EOL> return idpdisc . DiscoveryResponse ( index = "<STR_LIT:0>" , location = discovery_response , <EOL> binding = idpdisc . NAMESPACE ) <EOL> ENDPOINTS = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : ( md . ArtifactResolutionService , True ) , <EOL> "<STR_LIT>" : ( md . SingleLogoutService , False ) , <EOL> "<STR_LIT>" : ( md . ManageNameIDService , False ) , <EOL> "<STR_LIT>" : ( md . AssertionConsumerService , True ) , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : ( md . ArtifactResolutionService , True ) , <EOL> "<STR_LIT>" : ( md . SingleLogoutService , False ) , <EOL> "<STR_LIT>" : ( md . ManageNameIDService , False ) , <EOL> "<STR_LIT>" : ( md . SingleSignOnService , False ) , <EOL> "<STR_LIT>" : ( md . NameIDMappingService , False ) , <EOL> "<STR_LIT>" : ( md . AssertionIDRequestService , False ) , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : ( md . ArtifactResolutionService , True ) , <EOL> "<STR_LIT>" : ( md . SingleLogoutService , False ) , <EOL> "<STR_LIT>" : ( md . ManageNameIDService , False ) , <EOL> "<STR_LIT>" : ( md . AssertionIDRequestService , False ) , <EOL> "<STR_LIT>" : ( md . AttributeService , False ) <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : ( md . AuthzService , True ) <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : ( md . AuthnQueryService , True ) <EOL> } <EOL> } <EOL> ENDPOINT_EXT = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : ( idpdisc . DiscoveryResponse , True ) <EOL> } <EOL> } <EOL> DEFAULT_BINDING = { <EOL> "<STR_LIT>" : BINDING_HTTP_POST , <EOL> "<STR_LIT>" : BINDING_HTTP_REDIRECT , <EOL> "<STR_LIT>" : BINDING_HTTP_POST , <EOL> "<STR_LIT>" : BINDING_SOAP , <EOL> "<STR_LIT>" : BINDING_SOAP , <EOL> "<STR_LIT>" : BINDING_SOAP <EOL> } <EOL> def do_extensions ( mname , item ) : <EOL> try : <EOL> _mod = __import__ ( "<STR_LIT>" % mname , globals ( ) , locals ( ) , <EOL> mname ) <EOL> except ImportError : <EOL> return None <EOL> else : <EOL> res = [ ] <EOL> for _cname , ava in item . items ( ) : <EOL> cls = getattr ( _mod , _cname ) <EOL> res . append ( rec_factory ( cls , ** ava ) ) <EOL> return res <EOL> def _do_nameid_format ( cls , conf , typ ) : <EOL> namef = conf . getattr ( "<STR_LIT>" , typ ) <EOL> if namef : <EOL> if isinstance ( namef , basestring ) : <EOL> ids = [ md . NameIDFormat ( namef ) ] <EOL> else : <EOL> ids = [ md . NameIDFormat ( text = form ) for form in namef ] <EOL> setattr ( cls , "<STR_LIT>" , ids ) <EOL> def do_endpoints ( conf , endpoints ) : <EOL> service = { } <EOL> for endpoint , ( eclass , indexed ) in endpoints . items ( ) : <EOL> try : <EOL> servs = [ ] <EOL> i = <NUM_LIT:1> <EOL> for args in conf [ endpoint ] : <EOL> if isinstance ( args , basestring ) : <EOL> args = { "<STR_LIT:location>" : args , <EOL> "<STR_LIT>" : DEFAULT_BINDING [ endpoint ] } <EOL> elif isinstance ( args , tuple ) or isinstance ( args , list ) : <EOL> if len ( args ) == <NUM_LIT:2> : <EOL> args = { "<STR_LIT:location>" : args [ <NUM_LIT:0> ] , "<STR_LIT>" : args [ <NUM_LIT:1> ] } <EOL> elif len ( args ) == <NUM_LIT:3> : <EOL> args = { "<STR_LIT:location>" : args [ <NUM_LIT:0> ] , "<STR_LIT>" : args [ <NUM_LIT:1> ] , <EOL> "<STR_LIT:index>" : args [ <NUM_LIT:2> ] } <EOL> if indexed : <EOL> if "<STR_LIT:index>" not in args : <EOL> args [ "<STR_LIT:index>" ] = "<STR_LIT>" % i <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> try : <EOL> int ( args [ "<STR_LIT:index>" ] ) <EOL> except ValueError : <EOL> raise <EOL> else : <EOL> args [ "<STR_LIT:index>" ] = str ( args [ "<STR_LIT:index>" ] ) <EOL> servs . append ( factory ( eclass , ** args ) ) <EOL> service [ endpoint ] = servs <EOL> except KeyError : <EOL> pass <EOL> return service <EOL> DEFAULT = { <EOL> "<STR_LIT>" : "<STR_LIT:true>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> } <EOL> def do_attribute_consuming_service ( conf , spsso ) : <EOL> service_description = service_name = None <EOL> requested_attributes = [ ] <EOL> acs = conf . attribute_converters <EOL> req = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if req : <EOL> requested_attributes . extend ( do_requested_attribute ( req , acs , <EOL> is_required = "<STR_LIT:true>" ) ) <EOL> opt = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if opt : <EOL> requested_attributes . extend ( do_requested_attribute ( opt , acs ) ) <EOL> try : <EOL> if conf . description : <EOL> try : <EOL> ( text , lang ) = conf . description <EOL> except ValueError : <EOL> text = conf . description <EOL> lang = "<STR_LIT>" <EOL> service_description = [ md . ServiceDescription ( text = text , lang = lang ) ] <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> if conf . name : <EOL> try : <EOL> ( text , lang ) = conf . name <EOL> except ValueError : <EOL> text = conf . name <EOL> lang = "<STR_LIT>" <EOL> service_name = [ md . ServiceName ( text = text , lang = lang ) ] <EOL> except KeyError : <EOL> pass <EOL> if requested_attributes : <EOL> if not service_name : <EOL> service_name = [ md . ServiceName ( text = "<STR_LIT>" , lang = "<STR_LIT>" ) ] <EOL> ac_serv = md . AttributeConsumingService ( <EOL> index = "<STR_LIT:1>" , service_name = service_name , <EOL> requested_attribute = requested_attributes ) <EOL> if service_description : <EOL> ac_serv . service_description = service_description <EOL> spsso . attribute_consuming_service = [ ac_serv ] <EOL> def do_spsso_descriptor ( conf , cert = None ) : <EOL> spsso = md . SPSSODescriptor ( ) <EOL> spsso . protocol_support_enumeration = samlp . NAMESPACE <EOL> exts = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if exts : <EOL> if spsso . extensions is None : <EOL> spsso . extensions = md . Extensions ( ) <EOL> for key , val in exts . items ( ) : <EOL> _ext = do_extensions ( key , val ) <EOL> if _ext : <EOL> for _e in _ext : <EOL> spsso . extensions . add_extension_element ( _e ) <EOL> endps = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if endps : <EOL> for ( endpoint , instlist ) in do_endpoints ( endps , <EOL> ENDPOINTS [ "<STR_LIT>" ] ) . items ( ) : <EOL> setattr ( spsso , endpoint , instlist ) <EOL> ext = do_endpoints ( endps , ENDPOINT_EXT [ "<STR_LIT>" ] ) <EOL> if ext : <EOL> if spsso . extensions is None : <EOL> spsso . extensions = md . Extensions ( ) <EOL> for vals in ext . values ( ) : <EOL> for val in vals : <EOL> spsso . extensions . add_extension_element ( val ) <EOL> ui_info = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if ui_info : <EOL> if spsso . extensions is None : <EOL> spsso . extensions = md . Extensions ( ) <EOL> spsso . extensions . add_extension_element ( do_uiinfo ( ui_info ) ) <EOL> if cert : <EOL> encryption_type = conf . encryption_type <EOL> spsso . key_descriptor = do_key_descriptor ( cert , encryption_type ) <EOL> for key in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> try : <EOL> val = conf . getattr ( key , "<STR_LIT>" ) <EOL> if val is None : <EOL> setattr ( spsso , key , DEFAULT [ key ] ) <EOL> else : <EOL> strval = "<STR_LIT>" . format ( str ( val ) ) <EOL> setattr ( spsso , key , strval . lower ( ) ) <EOL> except KeyError : <EOL> setattr ( spsso , key , DEFAULTS [ key ] ) <EOL> do_attribute_consuming_service ( conf , spsso ) <EOL> _do_nameid_format ( spsso , conf , "<STR_LIT>" ) <EOL> return spsso <EOL> def do_idpsso_descriptor ( conf , cert = None ) : <EOL> idpsso = md . IDPSSODescriptor ( ) <EOL> idpsso . protocol_support_enumeration = samlp . NAMESPACE <EOL> endps = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if endps : <EOL> for ( endpoint , instlist ) in do_endpoints ( endps , <EOL> ENDPOINTS [ "<STR_LIT>" ] ) . items ( ) : <EOL> setattr ( idpsso , endpoint , instlist ) <EOL> _do_nameid_format ( idpsso , conf , "<STR_LIT>" ) <EOL> scopes = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if scopes : <EOL> if idpsso . extensions is None : <EOL> idpsso . extensions = md . Extensions ( ) <EOL> for scope in scopes : <EOL> mdscope = shibmd . Scope ( ) <EOL> mdscope . text = scope <EOL> mdscope . regexp = "<STR_LIT:false>" <EOL> idpsso . extensions . add_extension_element ( mdscope ) <EOL> ui_info = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if ui_info : <EOL> if idpsso . extensions is None : <EOL> idpsso . extensions = md . Extensions ( ) <EOL> idpsso . extensions . add_extension_element ( do_uiinfo ( ui_info ) ) <EOL> if cert : <EOL> idpsso . key_descriptor = do_key_descriptor ( cert ) <EOL> for key in [ "<STR_LIT>" ] : <EOL> try : <EOL> val = conf . getattr ( key , "<STR_LIT>" ) <EOL> if val is None : <EOL> setattr ( idpsso , key , DEFAULT [ key ] ) <EOL> else : <EOL> setattr ( idpsso , key , ( "<STR_LIT:%s>" % val ) . lower ( ) ) <EOL> except KeyError : <EOL> setattr ( idpsso , key , DEFAULTS [ key ] ) <EOL> return idpsso <EOL> def do_aa_descriptor ( conf , cert ) : <EOL> aad = md . AttributeAuthorityDescriptor ( ) <EOL> aad . protocol_support_enumeration = samlp . NAMESPACE <EOL> endps = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if endps : <EOL> for ( endpoint , instlist ) in do_endpoints ( endps , <EOL> ENDPOINTS [ "<STR_LIT>" ] ) . items ( ) : <EOL> setattr ( aad , endpoint , instlist ) <EOL> _do_nameid_format ( aad , conf , "<STR_LIT>" ) <EOL> if cert : <EOL> aad . key_descriptor = do_key_descriptor ( cert ) <EOL> attributes = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if attributes : <EOL> for attribute in attributes : <EOL> aad . attribute . append ( Attribute ( text = attribute ) ) <EOL> attribute_profiles = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if attribute_profiles : <EOL> for attribute_profile in attribute_profiles : <EOL> aad . attribute . append ( AttributeProfile ( text = attribute_profile ) ) <EOL> return aad <EOL> def do_aq_descriptor ( conf , cert ) : <EOL> aqs = md . AuthnAuthorityDescriptor ( ) <EOL> aqs . protocol_support_enumeration = samlp . NAMESPACE <EOL> endps = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if endps : <EOL> for ( endpoint , instlist ) in do_endpoints ( endps , <EOL> ENDPOINTS [ "<STR_LIT>" ] ) . items ( ) : <EOL> setattr ( aqs , endpoint , instlist ) <EOL> _do_nameid_format ( aqs , conf , "<STR_LIT>" ) <EOL> if cert : <EOL> aqs . key_descriptor = do_key_descriptor ( cert ) <EOL> return aqs <EOL> def do_pdp_descriptor ( conf , cert ) : <EOL> """<STR_LIT>""" <EOL> pdp = md . PDPDescriptor ( ) <EOL> pdp . protocol_support_enumeration = samlp . NAMESPACE <EOL> endps = conf . getattr ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if endps : <EOL> for ( endpoint , instlist ) in do_endpoints ( endps , <EOL> ENDPOINTS [ "<STR_LIT>" ] ) . items ( ) : <EOL> setattr ( pdp , endpoint , instlist ) <EOL> _do_nameid_format ( pdp , conf , "<STR_LIT>" ) <EOL> if cert : <EOL> pdp . key_descriptor = do_key_descriptor ( cert ) <EOL> return pdp <EOL> def entity_descriptor ( confd ) : <EOL> mycert = "<STR_LIT>" . join ( open ( confd . cert_file ) . readlines ( ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> entd = md . EntityDescriptor ( ) <EOL> entd . entity_id = confd . entityid <EOL> if confd . valid_for : <EOL> entd . valid_until = in_a_while ( hours = int ( confd . valid_for ) ) <EOL> if confd . organization is not None : <EOL> entd . organization = do_organization_info ( confd . organization ) <EOL> if confd . contact_person is not None : <EOL> entd . contact_person = do_contact_person_info ( confd . contact_person ) <EOL> if confd . entity_category : <EOL> entd . extensions = md . Extensions ( ) <EOL> ava = [ AttributeValue ( text = c ) for c in confd . entity_category ] <EOL> attr = Attribute ( attribute_value = ava , <EOL> name = "<STR_LIT>" ) <EOL> item = mdattr . EntityAttributes ( attribute = attr ) <EOL> entd . extensions . add_extension_element ( item ) <EOL> serves = confd . serves <EOL> if not serves : <EOL> raise SAMLError ( <EOL> '<STR_LIT>' ) <EOL> if "<STR_LIT>" in serves : <EOL> confd . context = "<STR_LIT>" <EOL> entd . spsso_descriptor = do_spsso_descriptor ( confd , mycert ) <EOL> if "<STR_LIT>" in serves : <EOL> confd . context = "<STR_LIT>" <EOL> entd . idpsso_descriptor = do_idpsso_descriptor ( confd , mycert ) <EOL> if "<STR_LIT>" in serves : <EOL> confd . context = "<STR_LIT>" <EOL> entd . attribute_authority_descriptor = do_aa_descriptor ( confd , mycert ) <EOL> if "<STR_LIT>" in serves : <EOL> confd . context = "<STR_LIT>" <EOL> entd . pdp_descriptor = do_pdp_descriptor ( confd , mycert ) <EOL> if "<STR_LIT>" in serves : <EOL> confd . context = "<STR_LIT>" <EOL> entd . authn_authority_descriptor = do_aq_descriptor ( confd , mycert ) <EOL> return entd <EOL> def entities_descriptor ( eds , valid_for , name , ident , sign , secc ) : <EOL> entities = md . EntitiesDescriptor ( entity_descriptor = eds ) <EOL> if valid_for : <EOL> entities . valid_until = in_a_while ( hours = valid_for ) <EOL> if name : <EOL> entities . name = name <EOL> if ident : <EOL> entities . id = ident <EOL> if sign : <EOL> if not ident : <EOL> ident = sid ( ) <EOL> if not secc . key_file : <EOL> raise SAMLError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> if not secc . my_cert : <EOL> raise SAMLError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> entities . signature = pre_signature_part ( ident , secc . my_cert , <NUM_LIT:1> ) <EOL> entities . id = ident <EOL> xmldoc = secc . sign_statement ( "<STR_LIT:%s>" % entities , class_name ( entities ) ) <EOL> entities = md . entities_descriptor_from_string ( xmldoc ) <EOL> else : <EOL> xmldoc = None <EOL> return entities , xmldoc <EOL> def sign_entity_descriptor ( edesc , ident , secc ) : <EOL> """<STR_LIT>""" <EOL> if not ident : <EOL> ident = sid ( ) <EOL> edesc . signature = pre_signature_part ( ident , secc . my_cert , <NUM_LIT:1> ) <EOL> edesc . id = ident <EOL> xmldoc = secc . sign_statement ( "<STR_LIT:%s>" % edesc , class_name ( edesc ) ) <EOL> edesc = md . entity_descriptor_from_string ( xmldoc ) <EOL> return edesc , xmldoc </s>
