Example #1
0
async def main():
    s = settings.load("switch")
    s.configure("0a69c592", 40600, 0)

    chain = tls.load_certificate_chain("resources/fullchain.pem")
    key = tls.TLSPrivateKey.load("resources/privkey.pem", tls.TYPE_PEM)
    context = tls.TLSContext()
    context.set_certificate_chain(chain, key)

    async with eagle.serve("", 20001, context) as eagle_mgr:
        clients = ClientMgr()
        matchmaker = MatchMaker(clients, eagle_mgr)
        async with dashboard.serve("", 20002, context, clients, matchmaker):
            servers1 = [AuthenticationServer(s)]
            servers2 = [
                SecureConnectionServer(clients),
                MessageDeliveryServer(clients, matchmaker),
                MatchmakeRefereeServer(clients, matchmaker),
                MatchmakeExtensionServer(matchmaker),
                MatchMakingServerExt(matchmaker),
                MatchMakingServer(matchmaker),
                Ranking2Server(),
                UtilityServer()
            ]

            async with prudp.serve_transport(s, "", 20000,
                                             context) as transport:
                async with rmc.serve_prudp(s, servers1, transport, 1):
                    async with rmc.serve_prudp(s,
                                               servers2,
                                               transport,
                                               2,
                                               key=SERVER_KEY):
                        print("Server is running!")
                        await anyio.sleep(math.inf)
Example #2
0
async def main():
	s = settings.load("friends")
	s.configure(Friends.ACCESS_KEY, Friends.NEX_VERSION)
	
	async with backend.connect(s, "127.0.0.1", 1223) as be:
		async with be.login_guest() as client:
			pass
    def test_add(self):
        stream = streams.StreamOut(settings.default())
        stream.add(common.ResultRange())
        assert stream.get() == bytes.fromhex("000000000a000000")

        stream = streams.StreamOut(settings.load("switch"))
        stream.add(common.ResultRange())
        assert stream.get() == bytes.fromhex("0008000000000000000a000000")
    def test_pid(self):
        stream = streams.StreamOut(settings.default())
        stream.pid(12345)
        assert stream.get() == bytes.fromhex("39300000")

        stream = streams.StreamOut(settings.load("switch"))
        stream.pid(12345)
        assert stream.get() == bytes.fromhex("3930000000000000")
    def test_anydata(self):
        stream = streams.StreamOut(settings.default())
        stream.anydata(common.NullData())
        assert stream.get() == b"\x09\0NullData\0\x04\0\0\0\0\0\0\0"

        stream = streams.StreamOut(settings.load("switch"))
        stream.anydata(common.NullData())
        assert stream.get(
        ) == b"\x09\0NullData\0\x0E\0\0\0\x0A\0\0\0\0\0\0\0\0\0\0\0\0\0"
    def test_anydata(self):
        data = b"\x09\0NullData\0\x04\0\0\0\0\0\0\0"
        stream = streams.StreamIn(data, settings.default())
        assert isinstance(stream.anydata(), common.NullData)
        assert stream.eof()

        data = b"\x09\0NullData\0\x0E\0\0\0\x0A\0\0\0\0\0\0\0\0\0\0\0\0\0"
        stream = streams.StreamIn(data, settings.load("switch"))
        assert isinstance(stream.anydata(), common.NullData)
        assert stream.eof()
    def test_pid(self):
        data = bytes.fromhex("39300000")
        stream = streams.StreamIn(data, settings.default())
        assert stream.pid() == 12345
        assert stream.eof()

        data = bytes.fromhex("3930000000000000")
        stream = streams.StreamIn(data, settings.load("switch"))
        assert stream.pid() == 12345
        assert stream.eof()
Example #8
0
async def test_lite():
    s = settings.load("switch")

    async def handler(client):
        assert await client.recv() == b"ping"
        await client.send(b"pong")

    async with prudp.serve(handler, s, HOST, 12345):
        async with prudp.connect(s, HOST, 12345) as client:
            await client.send(b"ping")
            assert await client.recv() == b"pong"
    def test_extract(self):
        data = b"\0\0\0\0\x0a\0\0\0"
        stream = streams.StreamIn(data, settings.default())
        rr = stream.extract(common.ResultRange)
        assert rr.offset == 0
        assert rr.size == 10

        data = b"\0\x08\0\0\0\0\0\0\0\x0a\0\0\0"
        stream = streams.StreamIn(data, settings.load("switch"))
        rr = stream.extract(common.ResultRange)
        assert rr.offset == 0
        assert rr.size == 10
Example #10
0
async def test_v0_alt():
    s = settings.load("3ds")
    s["prudp_v0.signature_version"] = 1
    s["prudp_v0.flags_version"] = 0
    s["prudp_v0.checksum_version"] = 0

    async def handler(client):
        assert await client.recv() == b"ping"
        await client.send(b"pong")

    async with prudp.serve(handler, s, HOST, 12345):
        async with prudp.connect(s, HOST, 12345) as client:
            await client.send(b"ping")
            assert await client.recv() == b"pong"
Example #11
0
async def test_v0():
    s = settings.load("3ds")
    s["prudp.access_key"] = b"access key"

    async def handler(client):
        assert await client.recv() == b"ping"
        await client.send(b"pong")

    async with prudp.serve(handler, s, HOST, 12345):
        async with prudp.connect(s, HOST, 12345) as client:
            assert client.remote_address() == (HOST, 12345)

            await client.send(b"ping")
            assert await client.recv() == b"pong"
Example #12
0
async def main():
    client = nasc.NASCClient()
    client.set_title(Friends3DS.TITLE_ID_EUR, Friends3DS.LATEST_VERSION)
    client.set_device(SERIAL_NUMBER, MAC_ADDRESS, DEVICE_CERT, DEVICE_NAME)
    client.set_locale(REGION, LANGUAGE)
    client.set_user(PID, PID_HMAC)

    response = await client.login(Friends3DS.GAME_SERVER_ID)

    s = settings.load("friends")
    s.configure(Friends3DS.ACCESS_KEY, Friends3DS.NEX_VERSION)
    async with backend.connect(s, response.host, response.port) as be:
        async with be.login(str(PID), NEX_PASSWORD) as client:
            friends_client = friends.FriendsClientV1(client)
            await friends_client.update_comment("Hello World")
Example #13
0
async def main():
    s = settings.load("friends")
    s.configure(Friends.ACCESS_KEY, Friends.NEX_VERSION)

    auth_servers = [AuthenticationServer(s)]
    secure_servers = [FriendsServer()]

    server_key = derive_key(get_user_by_name(SECURE_SERVER))
    async with rmc.serve(s, auth_servers, "127.0.0.1", 1223):
        async with rmc.serve(s,
                             secure_servers,
                             "127.0.0.1",
                             1224,
                             key=server_key):
            await aioconsole.ainput("Press enter to exit...\n")
Example #14
0
async def main():
    keys = KeySet.load(PATH_KEYS)
    info = ProdInfo(keys, PATH_PRODINFO)

    with open(PATH_TICKET, "rb") as f:
        ticket = f.read()

    cert = info.get_tls_cert()
    pkey = info.get_tls_key()

    dauth = DAuthClient(keys)
    dauth.set_certificate(cert, pkey)
    dauth.set_system_version(SYSTEM_VERSION)
    response = await dauth.device_token(dauth.BAAS)
    device_token = response["device_auth_token"]

    aauth = AAuthClient()
    aauth.set_system_version(SYSTEM_VERSION)
    response = await aauth.auth_digital(SMM2.TITLE_ID, SMM2.LATEST_VERSION,
                                        device_token, ticket)
    app_token = response["application_auth_token"]

    baas = BAASClient()
    baas.set_system_version(SYSTEM_VERSION)

    response = await baas.authenticate(device_token)
    access_token = response["accessToken"]

    response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token,
                                app_token)
    user_id = int(response["user"]["id"], 16)
    id_token = response["idToken"]

    auth_info = authentication.AuthenticationInfo()
    auth_info.token = id_token
    auth_info.ngs_version = 4  #Switch
    auth_info.token_type = 2

    s = settings.load("switch")
    s.configure(SMM2.ACCESS_KEY, SMM2.NEX_VERSION, SMM2.CLIENT_VERSION)
    async with backend.connect(s, HOST, PORT) as be:
        async with be.login(str(user_id), auth_info=auth_info) as client:
            # Search for ninji courses
            store = datastore.DataStoreClientSMM2(client)

            param = datastore.SearchCoursesEventParam()
            courses = await store.search_courses_event(param)
            print("Found %i ninji courses.\n" % len(courses))

            # Print information about the oldest ninji course
            course = courses[-1]
            print("Name:", course.name)
            print("Description:", course.description)
            print("Start time:", course.upload_time)
            print("End time:", course.end_time)
            print()

            # Request ghost info
            param = datastore.GetEventCourseGhostParam()
            param.data_id = course.data_id
            param.time = 30000  # Request ghosts with a time around 30 seconds
            param.count = 1  # Only request a single ghost

            ghost = (await store.get_event_course_ghost(param))[0]

            # Request info about the ghost player
            param = datastore.GetUsersParam()
            param.pids = [ghost.pid]

            user = (await store.get_users(param)).users[0]
            print("Player:", user.name)
            print("Time: %i.%03i" % (ghost.time // 1000, ghost.time % 1000))
            print()

            # Download replay file
            header_info = await store.get_req_get_info_headers_info(
                ghost.replay_file.data_type)
            headers = {h.key: h.value for h in header_info.headers}
            response = await http.get(ghost.replay_file.url, headers=headers)
            response.raise_if_error()

            # Decompress and save replay file
            data = zlib.decompress(response.body)
            with open("replay.bin", "wb") as f:
                f.write(data)
Example #15
0
async def main():
    keys = KeySet.load(PATH_KEYS)
    info = ProdInfo(keys, PATH_PRODINFO)

    with open(PATH_TICKET, "rb") as f:
        ticket = f.read()

    cert = info.get_tls_cert()
    pkey = info.get_tls_key()

    dauth = DAuthClient(keys)
    dauth.set_certificate(cert, pkey)
    dauth.set_system_version(SYSTEM_VERSION)
    response = await dauth.device_token(dauth.BAAS)
    device_token = response["device_auth_token"]

    aauth = AAuthClient()
    aauth.set_system_version(SYSTEM_VERSION)
    response = await aauth.auth_digital(ACNH.TITLE_ID, ACNH.LATEST_VERSION,
                                        device_token, ticket)
    app_token = response["application_auth_token"]

    baas = BAASClient()
    baas.set_system_version(SYSTEM_VERSION)

    response = await baas.authenticate(device_token)
    access_token = response["accessToken"]

    response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token,
                                app_token)
    user_id = int(response["user"]["id"], 16)
    id_token = response["idToken"]

    auth_info = authentication.AuthenticationInfo()
    auth_info.token = id_token
    auth_info.ngs_version = 4  #Switch
    auth_info.token_type = 2

    s = settings.load("switch")
    s.configure(ACNH.ACCESS_KEY, ACNH.NEX_VERSION, ACNH.CLIENT_VERSION)
    async with backend.connect(s, HOST, PORT) as be:
        async with be.login(str(user_id), auth_info=auth_info) as client:
            mm = matchmaking.MatchmakeExtensionClient(client)

            param = matchmaking.MatchmakeSessionSearchCriteria()
            param.attribs = ["", "", "", "", "", ""]
            param.game_mode = "2"
            param.min_participants = "1"
            param.max_participants = "1,8"
            param.matchmake_system = "1"
            param.vacant_only = False
            param.exclude_locked = True
            param.exclude_non_host_pid = True
            param.selection_method = 0
            param.vacant_participants = 1
            param.exclude_user_password = True
            param.exclude_system_password = True
            param.refer_gid = 0
            param.codeword = CODE

            sessions = await mm.browse_matchmake_session_no_holder_no_result_range(
                param)
            if not sessions:
                print("\nNo island found for '%s'\n" % CODE)
            else:
                session = sessions[0]
                data = session.application_data
                print("\nFound island:")
                print("\tId:", session.id)
                print("\tActive players:", session.participation_count)
                print("\tIsland name:",
                      data[12:32].decode("utf16").rstrip("\0"))
                print("\tHost name:", data[40:60].decode("utf16").rstrip("\0"))
                print()
Example #16
0
async def main():
    nas = nnas.NNASClient()
    nas.set_device(DEVICE_ID, SERIAL_NUMBER, SYSTEM_VERSION)
    nas.set_title(Friends.TITLE_ID_EUR, Friends.LATEST_VERSION)
    nas.set_locale(REGION, COUNTRY, LANGUAGE)

    access_token = await nas.login(USERNAME, PASSWORD)
    nex_token = await nas.get_nex_token(access_token.token,
                                        Friends.GAME_SERVER_ID)

    pid = await nas.get_pid(USERNAME)
    mii = await nas.get_mii(pid)

    s = settings.load("friends")
    s.configure(Friends.ACCESS_KEY, Friends.NEX_VERSION)
    async with backend.connect(s, nex_token.host, nex_token.port) as be:
        async with be.login(str(nex_token.pid), nex_token.password) as client:
            nna_info = friends.NNAInfo()
            nna_info.principal_info.pid = pid
            nna_info.principal_info.nnid = USERNAME
            nna_info.principal_info.mii.name = mii.name
            nna_info.principal_info.mii.data = mii.data

            #NintendoPresenceV2 tells the server about your online status, which
            #game you're currently playing, etc. This will be shown to your friends
            #in their friend list (unless you disabled this feature).
            presence = friends.NintendoPresenceV2()

            friends_client = friends.FriendsClientV2(client)
            response = await friends_client.update_and_get_all_information(
                nna_info, presence, BIRTHDAY)

            if response.comment.text:
                print("Your status message: %s (last changed on %s)" %
                      (response.comment.text, response.comment.changed))
            else:
                print("You don't have a status message")

            if response.friends:
                print("Friends:")
                for friend in response.friends:
                    principal_info = friend.nna_info.principal_info
                    print("\tNNID:", principal_info.nnid)
                    print("\tName:", principal_info.mii.name)

                    presence = friend.presence
                    print("\tOnline:", ["No", "Yes"][presence.is_online])
                    if presence.game_key.title_id:
                        print("\tPlaying: %016X (v%i)" %
                              (presence.game_key.title_id,
                               presence.game_key.title_version))

                    if friend.comment.text:
                        print("\tStatus: %s (last changed on %s)" %
                              (friend.comment.text, friend.comment.changed))

                    print("\tFriend since:", friend.befriended)
                    print("\tLast online:", friend.last_online)
                    print("\t" + "-" * 40)
                print()
            else:
                print("You don't have any friends")

            if response.sent_requests:
                print("Friend requests sent:")
                print_requests(response.sent_requests)
            else:
                print("You haven't sent any friend requests")

            if response.received_requests:
                print("Friend requests received:")
                print_requests(response.received_requests)
            else:
                print("You haven't received any friend requests")

            if response.blacklist:
                print("Blacklist:")
                for item in response.blacklist:
                    principal_info = item.principal_info
                    print("\tWho: %s (%s)" %
                          (principal_info.nnid, principal_info.mii.name))
                    if item.game_key.title_id:
                        print("\tGame: %016X (%i)" %
                              (item.game_key.title_id,
                               item.game_key.title_version))
                    print("\tSince:", item.since)
                    print("\t" + "-" * 40)
            else:
                print("You haven't blacklisted any users")
async def main():
    keys = KeySet.load(PATH_KEYS)
    info = ProdInfo(keys, PATH_PRODINFO)

    with open(PATH_TICKET, "rb") as f:
        ticket = f.read()

    cert = info.get_tls_cert()
    pkey = info.get_tls_key()

    dauth = DAuthClient(keys)
    dauth.set_certificate(cert, pkey)
    dauth.set_system_version(SYSTEM_VERSION)
    response = await dauth.device_token(dauth.BAAS)
    device_token = response["device_auth_token"]

    aauth = AAuthClient()
    aauth.set_system_version(SYSTEM_VERSION)
    response = await aauth.auth_digital(SMM2.TITLE_ID, SMM2.LATEST_VERSION,
                                        device_token, ticket)
    app_token = response["application_auth_token"]

    baas = BAASClient()
    baas.set_system_version(SYSTEM_VERSION)

    response = await baas.authenticate(device_token)
    access_token = response["accessToken"]

    response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token,
                                app_token)
    user_id = int(response["user"]["id"], 16)
    id_token = response["idToken"]

    auth_info = authentication.AuthenticationInfo()
    auth_info.token = id_token
    auth_info.ngs_version = 4  #Switch
    auth_info.token_type = 2

    s = settings.load("switch")
    s.configure(SMM2.ACCESS_KEY, SMM2.NEX_VERSION, SMM2.CLIENT_VERSION)
    async with backend.connect(s, HOST, PORT) as be:
        async with be.login(str(user_id), auth_info=auth_info) as client:
            store = datastore.DataStoreClientSMM2(client)

            param = datastore.GetUserOrCourseParam()
            param.code = COURSE_ID
            param.course_option = datastore.CourseOption.ALL

            response = await store.get_user_or_course(param)
            course = response.course

            # Print information about the course
            print("Level info:")
            print("\tName:", course.name)
            print("\tDescription:", course.description)
            print("\tUploaded at:", course.upload_time)
            print("\tGame:", GameStyles[course.game_style])
            print("\tTheme:", CourseThemes[course.course_theme])
            print("\tDifficulty:", Difficulties[course.difficulty])
            print("\tFirst tag:", TagNames[course.tag1])
            print("\tSecond tag:", TagNames[course.tag2])
            print("\tWorld record:",
                  format_time(course.time_stats.world_record))
            print("\tNumber of comments:", course.comment_stats[0])

            # Request information about its uploader
            param = datastore.GetUsersParam()
            param.pids = [course.owner_id]

            response = await store.get_users(param)
            user = response.users[0]
            print("Uploader:")
            print("\tCode:", user.code)
            print("\tName:", user.name)
            print("\tCountry:", user.country)
            print("\tLast active:", user.last_active)

            # Download thumbnails
            await download_thumbnail(store, course.one_screen_thumbnail,
                                     "thumbnail_onescreen.jpg")
            await download_thumbnail(store, course.entire_thumbnail,
                                     "thumbnail_entire.jpg")

            # Download level file
            param = datastore.DataStorePrepareGetParam()
            param.data_id = course.data_id

            req_info = await store.prepare_get_object(param)
            response = await http.get(req_info.url)
            response.raise_if_error()
            with open("level.bin", "wb") as f:
                f.write(response.body)
async def main():
    keys = KeySet.load(PATH_KEYS)
    info = ProdInfo(keys, PATH_PRODINFO)

    with open(PATH_TICKET, "rb") as f:
        ticket = f.read()

    cert = info.get_tls_cert()
    pkey = info.get_tls_key()

    dauth = DAuthClient(keys)
    dauth.set_certificate(cert, pkey)
    dauth.set_system_version(SYSTEM_VERSION)
    response = await dauth.device_token(dauth.BAAS)
    device_token = response["device_auth_token"]

    aauth = AAuthClient()
    aauth.set_system_version(SYSTEM_VERSION)
    response = await aauth.auth_digital(GBG.TITLE_ID, GBG.LATEST_VERSION,
                                        device_token, ticket)
    app_token = response["application_auth_token"]

    baas = BAASClient()
    baas.set_system_version(SYSTEM_VERSION)

    response = await baas.authenticate(device_token)
    access_token = response["accessToken"]

    response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token,
                                app_token)
    user_id = int(response["user"]["id"], 16)
    id_token = response["idToken"]

    auth_info = authentication.AuthenticationInfo()
    auth_info.token = id_token
    auth_info.ngs_version = 4  #Switch
    auth_info.token_type = 2

    s = settings.load("switch")
    s.configure(GBG.ACCESS_KEY, GBG.NEX_VERSION, GBG.CLIENT_VERSION)
    async with backend.connect(s, HOST, PORT) as be:
        async with be.login(str(user_id), auth_info=auth_info) as client:
            store = datastore.DataStoreClient(client)

            # Request meta data
            param = datastore.DataStoreGetMetaParam()
            param.data_id = code_to_data_id(GAME_CODE)

            meta = await store.get_meta(param)
            print("Data id:", meta.data_id)
            print("Owner id:", meta.owner_id)
            print("Uploaded at:", meta.create_time)
            print("Expires at:", meta.expire_time)

            # Download game file
            result = await store.get_object_infos([meta.data_id])
            result.results[0].raise_if_error()

            info = result.infos[0]
            url = "https://" + info.url
            headers = {h.key: h.value for h in info.headers}
            response = await http.get(url, headers=headers)
            response.raise_if_error()
            with open("game.bin", "wb") as f:
                f.write(response.body)