예제 #1
0
 def test_with_host(self, host_info):
     dst_addr = SCIONAddr.from_values(ISD_AS("1-1"),
                                      HostAddrIPv4("127.0.0.2"))
     src_addr = SCIONAddr.from_values(ISD_AS("1-1"),
                                      HostAddrIPv4("127.0.0.1"))
     connector = self._setup_connector()
     # Call
     ntools.eq_(connector._resolve_dst_addr(src_addr, dst_addr),
                host_info.return_value)
     # Tests
     ntools.assert_false(connector.get_service_info.called)
     host_info.assert_called_once_with([HostAddrIPv4("127.0.0.2")],
                                       SCION_UDP_EH_DATA_PORT)
예제 #2
0
def print_paths(s_isd_as, d_isd_as, connector):
    '''
    Print AS announced paths data from lib.app.sciond.
    :param paths: Array of PathInfo objects.
    '''
    flags = lib_sciond.PathRequestFlags(flush=False, sibra=False)
    try:
        paths = lib_sciond.get_paths(d_isd_as,
                                     flags=flags,
                                     connector=connector[s_isd_as])
    except (SCIONDResponseError) as err:
        logging.error("%s: %s" % (err.__class__.__name__, err))
        return
    i = 1
    # enumerate all paths
    for path in paths:
        logging.info("----------------- PATH %s" % i)
        logging.info("MTU: %s" % path.p.path.mtu)
        logging.info("IPV4: %s" % HostAddrIPv4(path.p.hostInfo.addrs.ipv4))
        logging.info("Port: %s" % path.p.hostInfo.port)
        logging.info("Hops: %i" % (len(path.p.path.interfaces) / 2))
        # enumerate path interfaces
        for interface in path.p.path.interfaces:
            isd_as = ISD_AS(interface.isdas)
            link = interface.ifID
            logging.info("%s (%s)" % (str(isd_as), link))

        i += 1
예제 #3
0
 def test(self, init, ipv4):
     inst = HostAddrIPv4("")
     # Call
     inst._parse("raw")
     # Tests
     ipv4.assert_called_once_with("raw")
     ntools.eq_(inst.addr, ipv4.return_value.ip)
예제 #4
0
def scion_server_socket(server_address, api_addr, isd_as):
    logging.info("Starting SCION test server application.")
    soc = ScionServerSocket(L4Proto.SSP, bytes(api_addr, 'ascii'))
    host = HostAddrIPv4(server_address[0])
    saddr = SCIONAddr.from_values(isd_as, host)
    soc.bind(server_address[1], saddr)
    soc.listen()
    return soc
예제 #5
0
def scion_server_socket(server_address, isd_as):
    logging.info("Starting SCION test server application.")
    sockdir = "/run/shm/sciond/%s.sock" % isd_as
    soc = ScionServerSocket(L4Proto.SSP, bytes(sockdir, 'ascii'))
    host = HostAddrIPv4(server_address[0])
    saddr = SCIONAddr.from_values(ISD_AS(isd_as), host)
    soc.bind(server_address[1], saddr)
    soc.listen()
    return soc
예제 #6
0
 def test_with_svc(self):
     dst_addr = SCIONAddr.from_values(ISD_AS("1-1"), SVCType.BS_A)
     src_addr = SCIONAddr.from_values(ISD_AS("1-1"),
                                      HostAddrIPv4("127.0.0.1"))
     connector = self._setup_connector(svc_info_desc=("bs", "bs1"))
     # Call
     ntools.eq_(connector._resolve_dst_addr(src_addr, dst_addr), "bs1")
     # Tests
     connector.get_service_info.assert_called_once_with(["bs"])
예제 #7
0
 def test_with_different_ases(self):
     dst_addr = SCIONAddr.from_values(ISD_AS("1-2"),
                                      HostAddrSVC(0, raw=False))
     src_addr = SCIONAddr.from_values(ISD_AS("1-1"),
                                      HostAddrIPv4("127.0.0.1"))
     connector = self._setup_connector(svc_info_desc=("bs", "bs1"))
     # Call
     ntools.eq_(connector._resolve_dst_addr(src_addr, dst_addr), None)
     # Tests
     ntools.assert_false(connector.get_service_info.called)
예제 #8
0
def get_json_interface_node(i):
    '''
    Create external AS interface node for graph direct bind
    '''
    return {
        "name": str(i.isd_as),
        "type": "interface",
        "icon": get_service_type_name("ISD_AS"),
        "group": get_grouping_index("ISD-AS"),
        "public addr": str(HostAddrIPv4(i.public[0][0])),
        "public port": i.public[0][1],
        "remote addr": str(HostAddrIPv4(i.remote[0][0])),
        "remote port": i.remote[0][1],
        "link_type": i.link_type,
        "bandwidth": i.bandwidth,
        "mtu": i.mtu,
        "overlay": i.overlay,
        "to_if_id": i.to_if_id,
    }
예제 #9
0
def get_json_interface(i):
    '''
    Create external AS interface node for graph
    '''
    addr = i.public[0][0]
    port = i.public[0][1]
    to_addr = i.remote[0][0]
    to_port = i.remote[0][1]
    return {
        "if_addr": str(HostAddrIPv4(addr)),
        "if_bandwidth": i.bandwidth,
        "if_id": i.if_id,
        "if_isd_as": str(i.isd_as),
        "if_link_type": i.link_type,
        "if_mtu": i.mtu,
        "if_name": i.name,
        "if_port": port,
        "if_to_addr": str(HostAddrIPv4(to_addr)),
        "if_to_if_id": i.to_if_id,
        "if_to_port": to_port,
    }
예제 #10
0
def get_json_server_node(label, name, addr, port):
    '''
    Create server node for graph
    '''
    return {
        "name": label,
        "type": "server",
        "icon": get_service_type_name(name),
        "group": get_grouping_index(name),
        "addr": str(HostAddrIPv4(addr)),
        "port": port
    }
예제 #11
0
def p_router_element(s, idx):
    '''
    Print InterfaceInfo object.
    :param s: InterfaceInfo object.
    :param idx: Index of interface (1-based).
    '''
    addr = s.p.hostInfo.addrs.ipv4
    port = s.p.hostInfo.port
    logging.info("----------------- %s ROUTER:" %
                 get_service_type_name(ServiceType.BR))
    logging.info("Address: %s" % HostAddrIPv4(addr))
    logging.info("Name: %s-%s" % (ServiceType.BR, idx))
    logging.info("Port: %s" % port)
    logging.info("Interface ID: %s" % s.p.ifID)
예제 #12
0
def p_server_element(s):
    '''
    Print ServiceInfo object.
    :param s: ServiceInfo object.
    '''
    sidx = 1
    for hi in s.p.hostInfos:
        addr = hi.addrs.ipv4
        port = hi.port
        logging.info("----------------- %s SERVER:" %
                     get_service_type_name(str(s.p.serviceType)))
        logging.info("Address: %s" % HostAddrIPv4(addr))
        logging.info("Name: %s-%s" % (s.p.serviceType, sidx))
        logging.info("Port: %s" % port)
        logging.info("TTL: %s" % s.p.ttl)
        sidx += 1
예제 #13
0
 def __init__(self, connection, address, conn_id, scion_mode, kbase,
              source_isd_as, target_isd_as):
     """
     Create a ConnectionHandler class to handle the incoming
     HTTP(S) request.
     :param connection: Socket object that belong to the incoming connection
     :type connection: socket
     :param address: Address of the connecting party.
     :type address: host, port
     """
     self.scion_mode = scion_mode
     self.socket_kbase = kbase
     isd_as = ISD_AS(target_isd_as)
     host = HostAddrIPv4(self.target_proxy[0])
     self.scion_target_proxy = SCIONAddr.from_values(isd_as, host)
     self.scion_target_port = self.target_proxy[1]
     self.isd_as = source_isd_as
     super().__init__(connection, address, conn_id)
예제 #14
0
def html_paths(s, paths):
    '''
    Formats multiple paths to nested html
    :param paths:
    '''
    i = 0
    # enumerate all paths
    for path in paths:
        list_add_head(s, i, "PATH", "black")
        indent_open(s)
        list_add(s, "MTU: %s" % path.p.path.mtu)
        list_add(s, "IPV4: %s" % HostAddrIPv4(path.p.hostInfo.addrs.ipv4))
        list_add(s, "Port: %s" % path.p.hostInfo.port)
        list_add(s, "Hops: %i" % (len(path.p.path.interfaces) / 2))
        # enumerate path interfaces
        for interface in path.p.path.interfaces:
            isd_as = ISD_AS(interface.isdas)
            link = interface.ifID
            list_add(s, "%s (%s)" % (str(isd_as), link))
        i += 1
        indent_close(s)
예제 #15
0
 def test_wrong_len(self, init, ipv4):
     inst = HostAddrIPv4("")
     ipv4.side_effect = ipaddress.AddressValueError
     # Call
     ntools.assert_raises(SCIONParseError, inst._parse, "raw")
예제 #16
0
 def ipv4(self):
     if self.p.addrs.ipv4:
         return HostAddrIPv4(self.p.addrs.ipv4)
     return None
예제 #17
0
def main():
    """
    Parse the command-line arguments and start the proxy server.
    """
    handle_signals()
    parser = argparse.ArgumentParser()
    parser.add_argument("--address",
                        help='IP address of the source SCION Proxy',
                        default='127.0.0.1')
    parser.add_argument("-p",
                        "--port",
                        help='Port number to run SCION Proxy on',
                        type=int,
                        default=DEFAULT_SERVER_PORT)
    parser.add_argument("-f",
                        "--forward",
                        help='Forwarding proxy mode',
                        action="store_true")
    parser.add_argument("-s",
                        "--scion",
                        help='Use SCION multi-path socket',
                        action="store_true")
    parser.add_argument(
        "--WARNING-insecure-kbase",
        dest="kbase",
        action="store_true",
        help='Enable SCION knowledge-base. %s' % KBASE_SECURITY_WARN,
    )
    parser.add_argument("-t",
                        "--topo",
                        help='Topology file SCION knowledge-base should use',
                        default='topology/Wide.topo')
    parser.add_argument("-l",
                        "--loc",
                        help='Locations file SCION knowledge-base should use',
                        default='topology/Wide.locations')
    parser.add_argument("--source_isd_as",
                        help='ISD-AS of the source SCION Proxy',
                        default='1-4')
    parser.add_argument("--target_isd_as",
                        help='ISD-AS of the target SCION Proxy',
                        default='3-3')
    parser.add_argument("--target_address",
                        help='IP address of the target SCION Proxy',
                        default='127.0.0.1')
    parser.add_argument("--target_port",
                        help='Port of the target SCION Proxy',
                        type=int,
                        default=9090)
    args = parser.parse_args()

    if args.forward:
        init_logging(LOG_BASE + "_forward",
                     file_level=logging.DEBUG,
                     console_level=logging.INFO)
        logging.info("Operating in forwarding (bridge) mode.")
        isd_as = ISD_AS(args.source_isd_as)
        host = HostAddrIPv4(args.address)
    else:
        init_logging(LOG_BASE,
                     file_level=logging.DEBUG,
                     console_level=logging.INFO)
        logging.info("Operating in normal proxy mode.")
        isd_as = ISD_AS(args.target_isd_as)
        host = HostAddrIPv4(args.target_address)

    # start sciond
    logging.info("Starting sciond for %s", isd_as)
    api_addr = SCIOND_API_SOCKDIR + "%s-%s.sock" % (isd_as[0], isd_as[1])
    sciond = start_sciond(host, api_addr, isd_as)

    kbase = None
    if args.scion:
        logging.info("SCION-socket mode is on.")
        if args.kbase:
            if args.forward:
                logging.warning(
                    "*** SCION-socket knowledge-base is enabled. %s ***",
                    KBASE_SECURITY_WARN)
                kbase = SocketKnowledgeBase(args.topo, args.loc,
                                            ISD_AS(args.source_isd_as),
                                            ISD_AS(args.target_isd_as))
            else:
                logging.info("SCION-socket knowledge-base is supported "
                             "only in forwarding mode.")

    if args.scion and not args.forward:
        logging.info("Starting the server with SCION multi-path socket.")
        soc = scion_server_socket((args.target_address, args.port), api_addr,
                                  ISD_AS(args.target_isd_as))
    else:
        logging.info("Starting the server with UNIX socket.")
        soc = unix_server_socket(args.port)

    worker = threading.Thread(target=serve_forever,
                              args=(soc, args.forward, args.scion, kbase,
                                    args.source_isd_as, args.target_isd_as,
                                    args.target_address, args.target_port),
                              daemon=True)
    worker.start()
    try:
        worker.join()
    finally:
        # Exit gracefully
        logging.info("Closing the socket.")
        soc.close()
        logging.info("Stopping sciond.")
        sciond.stop()