示例#1
0
def add_subscriber(client, args):
    gsm = GSMSubscription()
    lte = LTESubscription()
    state = SubscriberState()

    if len(args.gsm_auth_tuple) != 0:
        gsm.state = GSMSubscription.ACTIVE
        for auth_tuple in args.gsm_auth_tuple:
            gsm.auth_tuples.append(bytes.fromhex(auth_tuple))

    if args.lte_auth_key is not None:
        lte.state = LTESubscription.ACTIVE
        lte.auth_key = bytes.fromhex(args.lte_auth_key)

    if args.lte_auth_next_seq is not None:
        state.lte_auth_next_seq = args.lte_auth_next_seq

    if args.lte_auth_opc is not None:
        lte.auth_opc = bytes.fromhex(args.lte_auth_opc)

    data = SubscriberData(
        sid=SIDUtils.to_pb(args.sid),
        gsm=gsm,
        lte=lte,
        state=state,
    )
    client.AddSubscriber(data)
示例#2
0
 def add_incomplete_sub(cls, sid: str):
     sub_db_sid = SIDUtils.to_pb(sid)
     lte = LTESubscription()
     lte.state = LTESubscription.ACTIVE
     state = SubscriberState()
     state.lte_auth_next_seq = 1
     subs_data = SubscriberData(sid=sub_db_sid, lte=lte, state=state)
     cls.subs[str(sub_db_sid)] = subs_data
示例#3
0
 def add_srsue(self):
     # Add for srsUE, add the hardcoded SubscriberData into the store when receiving request
     imsi = 'IMSI' + SRSUE_IMSI
     lte = LTESubscription()
     lte.state = LTESubscription.ACTIVE
     lte.auth_key = bytes.fromhex(SRSUE_KEY)
     #lte.auth_opc = bytes.fromhex(SRSUE_OPC)
     state = SubscriberState()
     state.lte_auth_next_seq = 1
     sub_data = SubscriberData(sid=SIDUtils.to_pb(imsi),
                               lte=lte,
                               state=state)
     self.add_subscriber(sub_data)
示例#4
0
    def add_sub(cls, sid: str, apn: str, ip: str, vlan: str = None,
                gw_ip=None, gw_mac=None):
        sub_db_sid = SIDUtils.to_pb(sid)
        lte = LTESubscription()
        lte.state = LTESubscription.ACTIVE
        state = SubscriberState()
        state.lte_auth_next_seq = 1
        non_3gpp = Non3GPPUserProfile()
        subs_data = SubscriberData(sid=sub_db_sid, lte=lte, state=state,
                                   non_3gpp=non_3gpp)

        cls.subs[str(sub_db_sid)] = subs_data
        cls.add_sub_ip(sid, apn, ip, vlan, gw_ip, gw_mac)
示例#5
0
    def _get_subscriberdb_data(sid):
        """
        Get subscriber data in protobuf format.

        Args:
            sid (str): string representation of the subscriber id
        Returns:
            subscriber_data (protos.subscriberdb_pb2.SubscriberData):
                full subscriber information for :sid: in protobuf format.
        """
        sub_db_sid = SIDUtils.to_pb(sid)
        lte = LTESubscription()
        lte.state = LTESubscription.ACTIVE
        lte.auth_key = bytes.fromhex(KEY)
        state = SubscriberState()
        state.lte_auth_next_seq = 1
        return SubscriberData(sid=sub_db_sid, lte=lte, state=state)
示例#6
0
def add_subscriber(client, args):
    gsm = GSMSubscription()
    lte = LTESubscription()
    state = SubscriberState()
    sub_network = CoreNetworkType()

    if len(args.gsm_auth_tuple) != 0:
        gsm.state = GSMSubscription.ACTIVE
        for auth_tuple in args.gsm_auth_tuple:
            gsm.auth_tuples.append(bytes.fromhex(auth_tuple))

    if args.lte_auth_key is not None:
        lte.state = LTESubscription.ACTIVE
        lte.auth_key = bytes.fromhex(args.lte_auth_key)

    if args.lte_auth_next_seq is not None:
        state.lte_auth_next_seq = args.lte_auth_next_seq

    if args.lte_auth_opc is not None:
        lte.auth_opc = bytes.fromhex(args.lte_auth_opc)

    if args.forbidden_network_types is not None:
        if (len(args.forbidden_network_types.split(",")) > 2):
            print("Forbidden Core Network Types are NT_5GC, NT_EPC")
            return
        for n in args.forbidden_network_types.split(","):
            if n == "NT_5GC":
                sub_network.forbidden_network_types.extend(
                    [CoreNetworkType.NT_5GC])
            elif n == "NT_EPC":
                sub_network.forbidden_network_types.extend(
                    [CoreNetworkType.NT_EPC])
            else:
                print(
                    "Invalid Network type, Forbidden Core Network Types are NT_5GC, NT_EPC"
                )
                return

    data = SubscriberData(
        sid=SIDUtils.to_pb(args.sid),
        gsm=gsm,
        lte=lte,
        state=state,
        sub_network=sub_network,
    )
    client.AddSubscriber(data)
示例#7
0
    def setUp(self):
        # Create sqlite3 database for testing
        self._tmpfile = tempfile.TemporaryDirectory()
        store = SqliteStore(self._tmpfile.name + '/')
        op = 16 * b'\x11'
        amf = b'\x80\x00'
        self._sub_profiles = {
            'superfast':
            SubscriberDB.SubscriptionProfile(max_ul_bit_rate=100000,
                                             max_dl_bit_rate=50000)
        }
        self._default_sub_profile = SubscriberDB.SubscriptionProfile(
            max_ul_bit_rate=10000, max_dl_bit_rate=5000)

        self._processor = processor.Processor(store, self._default_sub_profile,
                                              self._sub_profiles, op, amf)

        # Add some test users
        (rand, sres, gsm_key) = _dummy_auth_tuple()
        gsm = GSMSubscription(state=GSMSubscription.ACTIVE,
                              auth_tuples=[rand + sres + gsm_key])
        lte_key = 16 * b'\x00'
        lte = LTESubscription(state=LTESubscription.ACTIVE, auth_key=lte_key)
        lte_opc = LTESubscription(state=LTESubscription.ACTIVE,
                                  auth_key=lte_key,
                                  auth_opc=Milenage.generate_opc(lte_key, op))
        lte_opc_short = LTESubscription(state=LTESubscription.ACTIVE,
                                        auth_key=lte_key,
                                        auth_opc=b'\x00')
        state = SubscriberState(lte_auth_next_seq=1)
        sub1 = SubscriberData(sid=SIDUtils.to_pb('IMSI11111'),
                              gsm=gsm,
                              lte=lte,
                              state=state,
                              sub_profile='superfast')
        sub2 = SubscriberData(
            sid=SIDUtils.to_pb('IMSI22222'),  # No auth keys
            gsm=GSMSubscription(state=GSMSubscription.ACTIVE),
            lte=LTESubscription(state=LTESubscription.ACTIVE))
        sub3 = SubscriberData(
            sid=SIDUtils.to_pb('IMSI33333'))  # No subscribtion
        sub4 = SubscriberData(sid=SIDUtils.to_pb('IMSI44444'),
                              lte=lte_opc,
                              state=state)
        sub5 = SubscriberData(sid=SIDUtils.to_pb('IMSI55555'),
                              lte=lte_opc_short,
                              state=state)
        store.add_subscriber(sub1)
        store.add_subscriber(sub2)
        store.add_subscriber(sub3)
        store.add_subscriber(sub4)
        store.add_subscriber(sub5)
示例#8
0
    def setUp(self):
        # Create sqlite3 database for testing
        self._tmpfile = tempfile.TemporaryDirectory()
        store = SqliteStore(self._tmpfile.name + "/")
        op = 16 * b"\x11"
        amf = b"\x80\x00"
        sub_network = CoreNetworkType()
        self._sub_profiles = {
            "superfast":
            SubscriberDB.SubscriptionProfile(
                max_ul_bit_rate=100000,
                max_dl_bit_rate=50000,
            ),
        }
        self._default_sub_profile = SubscriberDB.SubscriptionProfile(
            max_ul_bit_rate=10000,
            max_dl_bit_rate=5000,
        )
        self._sub_network = sub_network

        self._processor = processor.Processor(
            store,
            self._default_sub_profile,
            self._sub_profiles,
            op,
            amf,
            self._sub_network,
        )

        # Add some test users
        (rand, sres, gsm_key) = _dummy_auth_tuple()
        gsm = GSMSubscription(
            state=GSMSubscription.ACTIVE,
            auth_tuples=[rand + sres + gsm_key],
        )
        lte_key = 16 * b"\x00"
        lte = LTESubscription(state=LTESubscription.ACTIVE, auth_key=lte_key)
        lte_opc = LTESubscription(
            state=LTESubscription.ACTIVE,
            auth_key=lte_key,
            auth_opc=Milenage.generate_opc(lte_key, op),
        )
        lte_opc_short = LTESubscription(
            state=LTESubscription.ACTIVE,
            auth_key=lte_key,
            auth_opc=b"\x00",
        )
        sub_network = CoreNetworkType(forbidden_network_types=[
            CoreNetworkType.NT_EPC, CoreNetworkType.NT_5GC
        ], )
        state = SubscriberState(lte_auth_next_seq=1)
        sub1 = SubscriberData(
            sid=SIDUtils.to_pb("IMSI11111"),
            gsm=gsm,
            lte=lte,
            state=state,
            sub_profile="superfast",
        )
        sub2 = SubscriberData(
            sid=SIDUtils.to_pb("IMSI22222"),  # No auth keys
            gsm=GSMSubscription(state=GSMSubscription.ACTIVE),
            lte=LTESubscription(state=LTESubscription.ACTIVE),
        )
        sub3 = SubscriberData(
            sid=SIDUtils.to_pb("IMSI33333"))  # No subscription
        sub4 = SubscriberData(sid=SIDUtils.to_pb("IMSI44444"),
                              lte=lte_opc,
                              state=state)
        sub5 = SubscriberData(
            sid=SIDUtils.to_pb("IMSI55555"),
            lte=lte_opc_short,
            state=state,
        )
        sub6 = SubscriberData(
            sid=SIDUtils.to_pb("IMSI66666"),
            sub_network=CoreNetworkType(),
        )
        store.add_subscriber(sub1)
        store.add_subscriber(sub2)
        store.add_subscriber(sub3)
        store.add_subscriber(sub4)
        store.add_subscriber(sub5)
        store.add_subscriber(sub6)