示例#1
0
文件: parse.py 项目: skanct/pyFF
    def parse(self, resource, content):
        info = dict()
        info['Description'] = "eIDAS MetadataServiceList from {}".format(resource.url)
        t = parse_xml(StringIO(content.encode('utf8')))
        t.xinclude()
        relt = root(t)
        info['Version'] = relt.get('Version', '0')
        info['IssueDate'] = relt.get('IssueDate')
        info['IssuerName'] = first_text(relt, "{%s}IssuerName" % NS['ser'])
        info['SchemeIdentifier'] = first_text(relt, "{%s}SchemeIdentifier" % NS['ser'])
        info['SchemeTerritory'] = first_text(relt, "{%s}SchemeTerritory" % NS['ser'])
        for mdl in relt.iter("{%s}MetadataList" % NS['ser']):
            for ml in mdl.iter("{%s}MetadataLocation" % NS['ser']):
                location = ml.get('Location')
                if location:
                    certs = CertDict(ml)
                    fingerprints = certs.keys()
                    fp = None
                    if len(fingerprints) > 0:
                        fp = fingerprints[0]

                    ep = ml.find("{%s}Endpoint" % NS['ser'])
                    if ep is not None and fp is not None:
                        log.debug("MetadataServiceList[{}]: {} verified by {}".format(info['SchemeTerritory'],
                                  location, fp))
                        resource.add_child(location,
                                           verify=fp,
                                           eidas_territory=mdl.get('Territory'),
                                           eidas_endpoint_type=ep.get('EndpointType'))

        log.debug("Done parsing eIDAS MetadataServiceList")
        resource.last_seen = datetime.now
        resource.expire_time = None
        return info
示例#2
0
    def parse(self, resource, content):
        info = dict()
        info['Description'] = "eIDAS MetadataServiceList"
        t = parse_xml(unicode_stream(content))
        t.xinclude()
        relt = root(t)
        info['Version'] = relt.get('Version', '0')
        info['IssueDate'] = relt.get('IssueDate')
        info['NextUpdate'] = relt.get('NextUpdate')
        resource.expire_time = iso2datetime(relt.get('NextUpdate'))
        info['Expiration Time'] = str(resource.expire_time)
        info['IssuerName'] = first_text(relt, "{%s}IssuerName" % NS['ser'])
        info['SchemeIdentifier'] = first_text(
            relt, "{%s}SchemeIdentifier" % NS['ser'])
        info['SchemeTerritory'] = first_text(relt,
                                             "{%s}SchemeTerritory" % NS['ser'])
        for mdl in relt.iter("{%s}MetadataList" % NS['ser']):
            for ml in mdl.iter("{%s}MetadataLocation" % NS['ser']):
                location = ml.get('Location')
                if location:
                    certs = CertDict(ml)
                    fingerprints = list(certs.keys())
                    fp = None
                    if len(fingerprints) > 0:
                        fp = fingerprints[0]

                    ep = ml.find("{%s}Endpoint" % NS['ser'])
                    if ep is not None and fp is not None:
                        args = dict(country_code=mdl.get('Territory'),
                                    hide_from_discovery=strtobool(
                                        ep.get('HideFromDiscovery', 'false')))
                        log.debug("MDSL[{}]: {} verified by {} for country {}".
                                  format(info['SchemeTerritory'], location, fp,
                                         args.get('country_code')))
                        r = resource.add_child(location, verify=fp)

                        # this is specific post-processing for MDSL files
                        def _update_entities(_t, **kwargs):
                            _country_code = kwargs.get('country_code')
                            _hide_from_discovery = kwargs.get(
                                'hide_from_discovery')
                            for e in iter_entities(_t):
                                if _country_code:
                                    set_nodecountry(e, _country_code)
                                if bool(_hide_from_discovery) and is_idp(e):
                                    set_entity_attributes(
                                        e, {
                                            ATTRS['entity-category']:
                                            'http://refeds.org/category/hide-from-discovery'
                                        })
                            return _t

                        r.add_via(Lambda(_update_entities, **args))

        log.debug("Done parsing eIDAS MetadataServiceList")
        resource.last_seen = datetime.now()
        resource.expire_time = None
        return info
示例#3
0
文件: parse.py 项目: skanct/pyFF
 def parse(self, resource, content):
     info = dict()
     info['Description'] = "XRD links from {}".format(resource.url)
     t = parse_xml(StringIO(content.encode('utf8')))
     relt = root(t)
     for xrd in t.iter("{%s}XRD" % NS['xrd']):
         for link in xrd.findall(".//{%s}Link[@rel='%s']" % (NS['xrd'], NS['md'])):
             link_href = link.get("href")
             certs = CertDict(link)
             fingerprints = certs.keys()
             fp = None
             if len(fingerprints) > 0:
                 fp = fingerprints[0]
             log.debug("XRD: {} verified by {}".format(link_href, fp))
             resource.add_child(link_href, verify=fp)
     resource.last_seen = datetime.now
     resource.expire_time = None
     return info
示例#4
0
    def parse(self, resource: Resource, content: str) -> ParserInfo:
        info = ParserInfo(description='XRD links', expiration_time='never expires')
        t = parse_xml(unicode_stream(content))

        relt = root(t)
        for xrd in t.iter("{%s}XRD" % NS['xrd']):
            for link in xrd.findall(".//{%s}Link[@rel='%s']" % (NS['xrd'], NS['md'])):
                link_href = link.get("href")
                certs = CertDict(link)
                fingerprints = list(certs.keys())
                fp = None
                if len(fingerprints) > 0:
                    fp = fingerprints[0]
                log.debug("XRD: {} verified by {}".format(link_href, fp))
                child_opts = resource.opts.copy(update={'alias': None})
                resource.add_child(link_href, child_opts)
        resource.last_seen = utc_now().replace(microsecond=0)
        resource.expire_time = None
        resource.never_expires = True
        return info
示例#5
0
    def parse(self, resource, content):
        info = dict()
        info['Description'] = "XRD links"
        info['Expiration Time'] = 'never expires'
        t = parse_xml(unicode_stream(content))

        relt = root(t)
        for xrd in t.iter("{%s}XRD" % NS['xrd']):
            for link in xrd.findall(".//{%s}Link[@rel='%s']" %
                                    (NS['xrd'], NS['md'])):
                link_href = link.get("href")
                certs = CertDict(link)
                fingerprints = list(certs.keys())
                fp = None
                if len(fingerprints) > 0:
                    fp = fingerprints[0]
                log.debug("XRD: {} verified by {}".format(link_href, fp))
                resource.add_child(link_href, verify=fp)
        resource.last_seen = datetime.now()
        resource.expire_time = None
        resource.never_expires = True
        return info
示例#6
0
    def parse(self, resource: Resource, content: str) -> EidasMDParserInfo:
        info = EidasMDParserInfo(description='eIDAS MetadataServiceList',
                                 expiration_time='None')
        t = parse_xml(unicode_stream(content))
        if config.xinclude:
            t.xinclude()
        relt = root(t)
        info.version = relt.get('Version', '0')
        info.issue_date = relt.get('IssueDate')
        info.next_update = relt.get('NextUpdate')
        if isinstance(info.next_update, str):
            resource.expire_time = iso2datetime(info.next_update)
        elif config.respect_cache_duration:
            duration = duration2timedelta(config.default_cache_duration)
            if not duration:
                # TODO: what is the right action here?
                raise ValueError(
                    f'Invalid default cache duration: {config.default_cache_duration}'
                )
            info.next_update = utc_now().replace(microsecond=0) + duration
            resource.expire_time = info.next_update

        info.expiration_time = 'None' if not resource.expire_time else resource.expire_time.isoformat(
        )
        info.issuer_name = first_text(relt, "{%s}IssuerName" % NS['ser'])
        info.scheme_identifier = first_text(relt,
                                            "{%s}SchemeIdentifier" % NS['ser'])
        info.scheme_territory = first_text(relt,
                                           "{%s}SchemeTerritory" % NS['ser'])
        for mdl in relt.iter("{%s}MetadataList" % NS['ser']):
            for ml in mdl.iter("{%s}MetadataLocation" % NS['ser']):
                location = ml.get('Location')
                if location:
                    certs = CertDict(ml)
                    fingerprints = list(certs.keys())
                    fp = None
                    if len(fingerprints) > 0:
                        fp = fingerprints[0]

                    ep = ml.find("{%s}Endpoint" % NS['ser'])
                    if ep is not None and fp is not None:
                        args = dict(
                            country_code=mdl.get('Territory'),
                            hide_from_discovery=strtobool(
                                ep.get('HideFromDiscovery', 'false')),
                        )
                        log.debug("MDSL[{}]: {} verified by {} for country {}".
                                  format(info.scheme_territory, location, fp,
                                         args.get('country_code')))
                        child_opts = resource.opts.copy(update={'alias': None})
                        child_opts.verify = fp
                        r = resource.add_child(location, child_opts)

                        # this is specific post-processing for MDSL files
                        def _update_entities(_t, **kwargs):
                            _country_code = kwargs.get('country_code')
                            _hide_from_discovery = kwargs.get(
                                'hide_from_discovery')
                            for e in iter_entities(_t):
                                if _country_code:
                                    set_nodecountry(e, _country_code)
                                if bool(_hide_from_discovery) and is_idp(e):
                                    set_entity_attributes(
                                        e, {
                                            ATTRS['entity-category']:
                                            'http://refeds.org/category/hide-from-discovery'
                                        })
                            return _t

                        r.add_via(Lambda(_update_entities, **args))

        log.debug("Done parsing eIDAS MetadataServiceList")
        resource.last_seen = utc_now().replace(microsecond=0)
        resource.expire_time = None
        return info