Пример #1
0
def create_as_obj(all_ases, as_credentials):
    as_objs = {}
    for _as in all_ases:
        isd_as = ISD_AS(_as)
        as_crd = as_credentials[_as]
        as_obj = AS_Object()
        as_obj.isd_id = isd_as.isd_str()
        as_obj.as_id = isd_as.as_str()
        # TRC/Cert
        trc_name = 'ISD%s-V1.trc' % isd_as.isd_str()
        cert_name = 'ISD%s-AS%s-V1.crt' % (isd_as.isd_str(), isd_as.as_file_fmt())
        as_obj.trc = json.dumps(as_crd['certs'][trc_name])
        as_obj.certificate = json.dumps(as_crd['certs'][cert_name])
        # Keys
        keys = {}
        keys['sig_key'] = as_crd['keys']['as-sig.seed']
        keys['enc_key'] = as_crd['keys']['as-decrypt.key']
        keys['master0_as_key'] = as_crd['keys']['master0.key']
        keys['master1_as_key'] = as_crd['keys']['master1.key']
        as_obj.keys = keys
        # Core keys
        if 'core-sig.seed' in as_crd['keys']:
            core_keys = {}
            core_keys['core_sig_key'] = as_crd['keys']['core-sig.seed']
            core_keys['online_key'] = as_crd['keys']['online-root.seed']
            core_keys['offline_key'] = as_crd['keys']['offline-root.seed']
            as_obj.core_keys = core_keys
        as_objs[_as] = as_obj

    return as_objs
Пример #2
0
 def get_neighbors(self):
     """
     : return: Nested dictionary with intra and inter isd neighbor dictionaries
     """
     intra_dict = {}
     inter_dict = {}
     border_routers = self.topology["BorderRouters"]
     for br in border_routers:
         if_id = self.get_neighbor_IA_interface(br)['interface']
         n_IA = ISD_AS(self.get_neighbor_IA_interface(br)['IA'])
         n_isd = n_IA.isd_str()
         n_as = n_IA.as_file_fmt()
         if n_isd == self.ISD:
             intra_isd_neighbor = \
                 {'n_as': n_as, 'br-ip': border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["Addr"],
                     'br-port': border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["OverlayPort"],
                  'remote-ip': border_routers[br]["Interfaces"][if_id]["RemoteOverlay"]["Addr"], 'remote-port':
                     border_routers[br]["Interfaces"][if_id]["RemoteOverlay"]["OverlayPort"]}
             intra_dict[if_id] = intra_isd_neighbor
         else:
             inter_isd_neighbor = \
                 {'n_isd': n_isd, 'n_as': n_as, 'br-ip': border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["Addr"],
                     'br-port': border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["OverlayPort"],
                  'remote-ip': border_routers[br]["Interfaces"][if_id]["RemoteOverlay"]["Addr"], 'remote-port':
                     border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["OverlayPort"]}
             inter_dict[if_id] = inter_isd_neighbor
     return {'intra': intra_dict, 'inter': inter_dict}
Пример #3
0
 def get_neighbors(self):
     """
     : return: Nested dictionary with intra and inter isd neighbor dictionaries
     """
     intra_dict = {}
     inter_dict = {}
     border_routers = self.topology["BorderRouters"]
     for br in border_routers:
         if_id = self.get_neighbor_IA_interface(br)['interface']
         n_IA = ISD_AS(self.get_neighbor_IA_interface(br)['IA'])
         n_isd = n_IA.isd_str()
         n_as = n_IA.as_file_fmt()
         if n_isd == self.ISD:
             intra_isd_neighbor = \
                 {'n_as': n_as, 'br-ip': border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["Addr"],
                     'br-port': border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["OverlayPort"],
                  'remote-ip': border_routers[br]["Interfaces"][if_id]["RemoteOverlay"]["Addr"], 'remote-port':
                     border_routers[br]["Interfaces"][if_id]["RemoteOverlay"]["OverlayPort"]}
             intra_dict[if_id] = intra_isd_neighbor
         else:
             inter_isd_neighbor = \
                 {'n_isd': n_isd, 'n_as': n_as, 'br-ip': border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["Addr"],
                     'br-port': border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["OverlayPort"],
                  'remote-ip': border_routers[br]["Interfaces"][if_id]["RemoteOverlay"]["Addr"], 'remote-port':
                     border_routers[br]["Interfaces"][if_id]["PublicOverlay"]["OverlayPort"]}
             inter_dict[if_id] = inter_isd_neighbor
     return {'intra': intra_dict, 'inter': inter_dict}
Пример #4
0
def deploy_gen(src_path, deploy_plan):
    """Copy gen folder to remote machines """
    for target_addr, ases in deploy_plan.items():
        print("[INF] ======== Deploying new gen folder =========")
        print("Target: %s" % target_addr)
        # initialize gen folder
        init_remote_dir(target_addr, TARGET_PATH)
        # deploy general things such as dispatcher and overlay config
        dispatcher_path = os.path.join(src_path, 'dispatcher')
        overlay_path = os.path.join(src_path, 'overlay')
        target_path = '%s:%s/.' % (target_addr, TARGET_PATH)
        copy_remote(dispatcher_path, target_path)
        copy_remote(overlay_path, target_path)
        for as_ in ases:
            isd_as = ISD_AS(as_)
            as_path = 'ISD%s/AS%s' % (isd_as.isd_str(), isd_as.as_file_fmt())
            target_path = os.path.join(TARGET_PATH, as_path)
            as_path = os.path.join(src_path, as_path, '*')
            init_remote_dir(target_addr, target_path)
            target_path = '%s:%s' % (target_addr, target_path)
            copy_remote(as_path, target_path)
Пример #5
0
 def test(self):
     inst = ISD_AS()
     inst.isd_str = create_mock_full()
     inst.as_str = create_mock_full()
     # Call
     ntools.eq_(str(inst), "%s-%s" % (inst.isd_str.return_value, inst.as_str.return_value))
Пример #6
0
 def _check(self, isd, s):
     inst = ISD_AS()
     inst._isd = isd
     # Call
     ntools.eq_(inst.isd_str(), s)
Пример #7
0
def index(request):
    '''
    Main index handler for index.html for main visualization page.
    Validates parameters, request scion data, returns formatted response.
    :param request: HTML request object containing url parameters.
    '''
    p = {}  # return param dictionary
    p['tab'] = set_param(request, 'tab', 'tab-pathtopo')
    p['data'] = set_param(request, 'data', 'sdapi')
    p['addr'] = set_param(request, 'addr', '')
    p['src'] = set_param(request, 'src', '')
    p['dst'] = set_param(request, 'dst', '')
    p['mp'] = set_param(request, 'mp', '5')
    p['err'] = ''
    if (p['src'] == '' and p['dst'] == ''):
        # use endhost gen/ia if no host specified
        if (p['src'] == ''):
            ia_file = "%s/%s/ia" % (SCION_ROOT, GEN_PATH)
            try:
                with open(ia_file, 'r') as fin:
                    # load and reformat
                    p['src'] = str(ISD_AS(fin.read().strip()))
            except (FileNotFoundError) as err:
                logging.warning("%s: %s" % (err.__class__.__name__, err))
        return fmt_err(request, p)
    s_isd_as = ISD_AS(p['src'])
    d_isd_as = ISD_AS(p['dst'])
    p['src'], p['dst'] = str(s_isd_as), str(d_isd_as)  # reformat
    csegs = dsegs = usegs = []
    paths = ''
    logging.info("Requesting sciond data from %s to %s" % (s_isd_as, d_isd_as))
    conf_dir = "%s/%s/ISD%s/AS%s/endhost" % (
        SCION_ROOT, GEN_PATH, s_isd_as.isd_str(), s_isd_as.as_file_fmt())
    sock_file = get_default_sciond_path(s_isd_as)
    if not pathlib.Path(sock_file).exists():
        sock_file = get_default_sciond_path(None)
    try:
        if (p['data'] == 'sdapi'):
            connector[s_isd_as] = lib_sciond.init(sock_file)
            logging.info(connector[s_isd_as]._api_addr)
            try:  # test if sciond is already running for this AS
                logging.info("Testing sciond at %s" % sock_file)
                lib_sciond.get_as_info(connector=connector[s_isd_as])
            except (SCIONDResponseError) as err:
                p['err'] = "%s: %s" % (err.__class__.__name__, err)
                return fmt_err(request, p)
            except (SCIONDConnectionError, FileNotFoundError) as err:
                logging.warning("%s: %s" % (err.__class__.__name__, err))
                # need to launch sciond, wait for uptime
                launch_sciond(sock_file, conf_dir, p['addr'], s_isd_as)

            if (p['dst'] != ''):  # PATHS
                try:
                    # get paths and keep segments
                    flags = lib_sciond.PathRequestFlags(flush=False,
                                                        sibra=False)
                    paths = lib_sciond.get_paths(d_isd_as,
                                                 max_paths=int(p['mp']),
                                                 flags=flags,
                                                 connector=connector[s_isd_as])
                    csegs = lib_sciond.get_segtype_hops(
                        PST.CORE, connector=connector[s_isd_as])
                    dsegs = lib_sciond.get_segtype_hops(
                        PST.DOWN, connector=connector[s_isd_as])
                    usegs = lib_sciond.get_segtype_hops(
                        PST.UP, connector=connector[s_isd_as])
                    # refresh old segments for next call
                    flags = lib_sciond.PathRequestFlags(flush=True,
                                                        sibra=False)
                    lib_sciond.get_paths(d_isd_as,
                                         max_paths=int(p['mp']),
                                         flags=flags,
                                         connector=connector[s_isd_as])
                except (SCIONDResponseError, SCIONDConnectionError,
                        AttributeError) as err:
                    # AttributeError handles backward-compatability
                    logging.error("%s: %s" % (err.__class__.__name__, err))
                    p['err'] = str(err)
            p['json_as_topo'] = json.dumps(
                get_json_as_topology_sciond(connector[s_isd_as], paths))
            p['json_trc'] = ("TRC information for sciond not yet implemented.")
            p['json_crt'] = (
                "Certificate information for sciond not yet implemented.")
        elif (p['data'] == 'file'):
            t = Topology.from_file(os.path.join(conf_dir, TOPO_FILE))
            topo = organize_topo(t)
            p['json_as_topo'] = json.dumps(get_json_as_topology(t, topo))
            p['json_trc'] = html_jsonfile(findCerts(conf_dir, ".trc"))
            p['json_crt'] = html_jsonfile(findCerts(conf_dir, ".crt"))
        p['path_info'] = get_as_view_html(paths, csegs, usegs, dsegs)
        p['json_path_topo'] = json.dumps(
            get_json_path_segs(paths, csegs, usegs, dsegs))
        p['json_seg_topo'] = json.dumps(
            get_json_all_segments(csegs, usegs, dsegs))
        p['json_paths'] = json.dumps(get_json_paths(paths))
    except (SCIONBaseError) as err:
        p['err'] = "%s: %s" % (err.__class__.__name__, err)
        return fmt_err(request, p)
    return render(request, 'asviz/index.html', p)