예제 #1
0
    def packet_login_encryption_request(self, buff):
        p_server_id = buff.unpack_string()

        # 1.7.x
        if self.protocol_version <= 5:
            unpack_array = lambda b: b.read(b.unpack('h'))
        # 1.8.x
        else:
            unpack_array = lambda b: b.read(b.unpack_varint(max_bits=16))

        p_public_key = unpack_array(buff)
        p_verify_token = unpack_array(buff)

        if not self.factory.profile.online:
            raise ProtocolError("Can't log into online-mode server while using"
                                " offline profile")

        self.shared_secret = crypto.make_shared_secret()
        self.public_key = crypto.import_public_key(p_public_key)
        self.verify_token = p_verify_token

        # make digest
        digest = crypto.make_digest(
            p_server_id.encode('ascii'),
            self.shared_secret,
            p_public_key)

        # do auth
        deferred = self.factory.profile.join(digest)
        deferred.addCallbacks(self.auth_ok, self.auth_failed)
예제 #2
0
파일: client.py 프로젝트: barneygale/quarry
    def packet_login_encryption_request(self, buff):
        p_server_id = buff.unpack_string()

        # 1.7.x
        if self.protocol_version <= 5:
            unpack_array = lambda b: b.read(b.unpack('h'))
        # 1.8.x
        else:
            unpack_array = lambda b: b.read(b.unpack_varint(max_bits=16))

        p_public_key = unpack_array(buff)
        p_verify_token = unpack_array(buff)

        if not self.factory.profile.online:
            raise ProtocolError("Can't log into online-mode server while using"
                                " offline profile")

        self.shared_secret = crypto.make_shared_secret()
        self.public_key = crypto.import_public_key(p_public_key)
        self.verify_token = p_verify_token

        # make digest
        digest = crypto.make_digest(
            p_server_id.encode('ascii'),
            self.shared_secret,
            p_public_key)

        # do auth
        deferred = self.factory.profile.join(digest)
        deferred.addCallbacks(self.auth_ok, self.auth_failed)
예제 #3
0
    async def decode_login_encryption_response(cls, msg: ClientMessage) ->...:
        # 1.7.x
        if msg.protocol_version <= 5:
            unpack_array = lambda b: b.read(b.unpack('h'))
        else:
            unpack_array = lambda b: b.read(b.unpack_varint(max_bits=16))

        buffer = msg.buffer
        p_shared_secret = unpack_array(buffer)
        p_shared_verify = unpack_array(buffer)
        shared_secret = decrypt_secret(ServerCore.keypair, p_shared_secret)
        shared_verify = decrypt_secret(ServerCore.keypair, p_shared_verify)

        if shared_verify != msg.conn.verify_token:
            msg.close_connection("Invalid verify token!")

        msg.conn.cipher.enable(shared_secret)

        digest = make_digest(msg.conn.server_id.encode("ascii"), shared_secret,
                             ServerCore.pubkey)

        url = ("https://sessionserver.mojang.com/session/minecraft/hasJoined" +
               f"?username={msg.conn.display_name}&serverId={digest}")
        if ServerCore.options["prevent-proxy-connections"]:
            url += f"&ip={msg.conn.client.server_hostname}"

        async with ClientSession() as session:
            async with session.get(url,
                                   timeout=ServerCore.auth_timeout) as resp:
                data = await resp.json()
                msg.conn.uuid = UUID(data["id"])

        cls.update_protocol(msg, "play")
        return PlayerRegistry.add_player(msg.conn)
예제 #4
0
파일: server.py 프로젝트: barneygale/quarry
    def packet_login_encryption_response(self, buff):
        if self.login_expecting != 1:
            raise ProtocolError("Out-of-order login")

        # 1.7.x
        if self.protocol_version <= 5:
            unpack_array = lambda b: b.read(b.unpack('h'))
        # 1.8.x
        else:
            unpack_array = lambda b: b.read(b.unpack_varint(max_bits=16))

        p_shared_secret = unpack_array(buff)
        p_verify_token = unpack_array(buff)

        shared_secret = crypto.decrypt_secret(
            self.factory.keypair,
            p_shared_secret)

        verify_token = crypto.decrypt_secret(
            self.factory.keypair,
            p_verify_token)

        self.login_expecting = None

        if verify_token != self.verify_token:
            raise ProtocolError("Verify token incorrect")

        # enable encryption
        self.cipher.enable(shared_secret)
        self.logger.debug("Encryption enabled")

        # make digest
        digest = crypto.make_digest(
            self.server_id.encode('ascii'),
            shared_secret,
            self.factory.public_key)

        # do auth
        remote_host = None
        if self.factory.prevent_proxy_connections:
            remote_host = self.remote_addr.host
        deferred = auth.has_joined(
            self.factory.auth_timeout,
            digest,
            self.display_name,
            remote_host)
        deferred.addCallbacks(self.auth_ok, self.auth_failed)
예제 #5
0
파일: server.py 프로젝트: vcokltfre/quarry
    def packet_login_encryption_response(self, buff):
        if self.login_expecting != 1:
            raise ProtocolError("Out-of-order login")

        # 1.7.x
        if self.protocol_version <= 5:
            unpack_array = lambda b: b.read(b.unpack('h'))
        # 1.8.x
        else:
            unpack_array = lambda b: b.read(b.unpack_varint(max_bits=16))

        p_shared_secret = unpack_array(buff)
        p_verify_token = unpack_array(buff)

        shared_secret = crypto.decrypt_secret(self.factory.keypair,
                                              p_shared_secret)

        verify_token = crypto.decrypt_secret(self.factory.keypair,
                                             p_verify_token)

        self.login_expecting = None

        if verify_token != self.verify_token:
            raise ProtocolError("Verify token incorrect")

        # enable encryption
        self.cipher.enable(shared_secret)
        self.logger.debug("Encryption enabled")

        # make digest
        digest = crypto.make_digest(self.server_id.encode('ascii'),
                                    shared_secret, self.factory.public_key)

        # do auth
        remote_host = None
        if self.factory.prevent_proxy_connections:
            remote_host = self.remote_addr.host
        deferred = auth.has_joined(self.factory.auth_timeout, digest,
                                   self.display_name, remote_host)
        deferred.addCallbacks(self.auth_ok, self.auth_failed)