Ejemplo n.º 1
0
    def yang(self, nonce="", output=None):
        if not output:
            output = self.device.get(filter=(
                'xpath',
                f'/system-integrity-oper-data/location/integrity[nonce={nonce}][request="choice-trust-chain"]'
            )).data_xml

        log.debug(minidom.parseString(output).toprettyxml())

        root = ET.fromstring(output)
        system_integrity_oper_data = Common.retrieve_xml_child(
            root=root, key='system-integrity-oper-data')
        ret_dict = {}
        name = None
        for parent in system_integrity_oper_data:
            for child in parent:
                if child.tag.endswith('slot'):
                    slot = int(child.text)
                    slot_dict = ret_dict.setdefault('slot', {})
                    slot_id = slot_dict.setdefault(slot, {})
                elif child.tag.endswith('fru'):
                    ret_dict.update({'fru': child.text})
                elif child.tag.endswith('chassis'):
                    ret_dict.update({'chassis': child.text})
                elif child.tag.endswith('bay'):
                    ret_dict.update({'bay': child.text})
                elif child.tag.endswith('node'):
                    ret_dict.update({'node': child.text})
                elif child.tag.endswith('integrity'):
                    for sub_child in child:
                        if sub_child.tag.endswith('trust-chain'):
                            for sub_child1 in sub_child:
                                if sub_child1.tag.endswith('trust-chain'):
                                    for sub_child2 in sub_child1:
                                        if sub_child2.tag.endswith('name'):
                                            name = sub_child2.text.replace(
                                                " ", "_").lower()
                                        elif name and sub_child2.tag.endswith(
                                                'value'):
                                            slot_id.update(
                                                {name: sub_child2.text})
                                            name = None
                                elif sub_child1.tag.endswith('signature'):
                                    for sub_child2 in sub_child1:
                                        sign_dict = slot_id.setdefault(
                                            'signature', {})
                                        if sub_child2.tag.endswith(
                                                'signature'):
                                            sign_dict.update(
                                                {'value': sub_child2.text})
                                        elif sub_child2.tag.endswith(
                                                'version'):
                                            sign_dict.update({
                                                'version':
                                                int(sub_child2.text)
                                            })
        return ret_dict
Ejemplo n.º 2
0
 def yang(self, nonce="", output=None):
     if not output:
         output = self.device.get(filter=(
             'xpath',
             f'/system-integrity-oper-data/location/integrity[nonce={nonce}][request="choice-measurement"]'
         )).data_xml
     log.info(minidom.parseString(output).toprettyxml())
     root = ET.fromstring(output)
     system_integrity_oper_data = Common.retrieve_xml_child(
         root=root, key='system-integrity-oper-data')
     ret_dict = {}
     name = None
     version = None
     for parent in system_integrity_oper_data:
         for child in parent:
             if child.tag.endswith('slot'):
                 slot = int(child.text)
                 slot_dict = ret_dict.setdefault('slot', {})
                 slot_id = slot_dict.setdefault(slot, {})
             elif child.tag.endswith('fru'):
                 ret_dict.update({'fru': child.text})
             elif child.tag.endswith('chassis'):
                 ret_dict.update({'chassis': child.text})
             elif child.tag.endswith('bay'):
                 ret_dict.update({'bay': child.text})
             elif child.tag.endswith('node'):
                 ret_dict.update({'node': child.text})
             elif child.tag.endswith('integrity'):
                 for sub_child in child:
                     if sub_child.tag.endswith('measurement'):
                         for sub_child1 in sub_child:
                             if sub_child1.tag.endswith('boot-loader'):
                                 for sub_child2 in sub_child1:
                                     boot_hash_dict = slot_id.setdefault(
                                         'boot_hashes', {})
                                     if sub_child2.tag.endswith('version'):
                                         version = sub_child2.text
                                     elif version and sub_child2.tag.endswith(
                                             'hash'):
                                         boot_hash_dict.update(
                                             {version: sub_child2.text})
                             elif sub_child1.tag.endswith('platform'):
                                 slot_id.update(
                                     {'platform': sub_child1.text})
                             elif sub_child1.tag.endswith(
                                     'operating-system'):
                                 for sub_child2 in sub_child1:
                                     os_dict = slot_id.setdefault('os', {})
                                     if sub_child2.tag.endswith('version'):
                                         os_dict.update(
                                             {'version': sub_child2.text})
                                     elif sub_child2.tag.endswith(
                                             'package-integrity'):
                                         for sub_child3 in sub_child2:
                                             os_dict1 = slot_id.setdefault('os', {}). \
                                                             setdefault('hashes', {})
                                             if sub_child3.tag.endswith(
                                                     'name'):
                                                 name = sub_child3.text
                                             elif name and sub_child3.tag.endswith(
                                                     'hash'):
                                                 os_dict1.update({
                                                     name:
                                                     sub_child3.text
                                                 })
                             elif sub_child1.tag.endswith('register'):
                                 for sub_child2 in sub_child1:
                                     regs_dict = slot_id.setdefault(
                                         'registers', {})
                                     if sub_child2.tag.endswith('index'):
                                         name = 'PCR{}'.format(
                                             sub_child2.text)
                                     elif sub_child2.tag.endswith(
                                             'pcr-content'):
                                         regs_dict.update(
                                             {name: sub_child2.text})
                                         name = None
                             elif sub_child1.tag.endswith('signature'):
                                 for sub_child2 in sub_child1:
                                     sign_dict = slot_id.setdefault(
                                         'signature', {})
                                     if sub_child2.tag.endswith(
                                             'signature'):
                                         sign_dict.update(
                                             {'value': sub_child2.text})
                                     elif sub_child2.tag.endswith(
                                             'version'):
                                         sign_dict.update({
                                             'version':
                                             int(sub_child2.text)
                                         })
     return ret_dict