TJAuth
一个认证模组,可使用外部认证服务器来验证白名单和密码。
此模组专为 tjmtr 服务器设计,可与 Tianji_Center 完美配合使用。
如何配置和使用?
认证服务器
使用本目录中的 ExampleAuthServer.py 进行测试。
记得安装 Python 和 Flask。
示例服务器包含清晰的注释和函数名,以说明何时通过验证、何时拒绝。
运行命令:python ExampleAuthServer.py
重要提示:必须使用 POST 方法和 application/json 格式,因为该模组是为此设计的。
加密密钥
在服务器根目录下的 config/tjauth/keys 文件夹中创建 private.pem 和 public.pem。
生成私钥的命令:openssl genrsa -out private.pem 2048
生成公钥的命令:openssl rsa -in private.pem -pubout -out public.pem
记得安装 openssl,并且必须先私钥后公钥的顺序生成。
重要提示:请记得先生成密钥;模组不会自动生成它们。
配置文件
配置文件位于 config/tjauth/config.json,首次启动时会自动生成。
whitelist_check_url:白名单认证 URL。
auth_server_url:密码认证 URL。
server_key:用于服务器进行身份验证的校验密钥。如果不需要,可以填入任意值(但不能留空)。
auth_timeout_seconds:认证超时时间,决定了客户端在不活动多久后会被踢出。如果在此时间内客户端未输入密码,将被踢出。此外,如果服务器响应超过此时间,认证也会超时。
此模组的工作原理?
概述:它主要请求外部服务器验证是否有资格加入世界,以及密码认证是否正确。请求中使用的 UUID 与启动客户端时使用的 UUID 相同。
注意:服务器和客户端都必须安装此模组。目前(v1.0.0),仅支持 Fabric 1.19.2。
- 允许外部服务器认证,配置灵活
- 使用客户端启动时的实际 UUID,从而区分拥有相同用户名的离线玩家
- 包含未完成认证时的禁止机制,防止意外操作游戏
- 显示密码输入界面,并在认证完成前保持可见
- 通过连接请求数据包阻止不受支持的客户端(例如未安装此模组的客户端)
连接阶段
当客户端连接到服务器时,服务器将请求客户端发送用于启动客户端的 UUID 和用户名。
如果客户端未安装此模组,将无法接受服务器的请求,被视为不兼容客户端并被踢出。
服务器收到客户端的 UUID 和用户名后,会请求外部服务器验证玩家是否被允许加入世界。如果允许,则客户端获准加入世界;如果不允许,则被踢出。
加入世界后
加入世界后,客户端立即显示输入密码的界面。
密码使用 RSA2048 加密发送给服务器。服务器随后将其发送给外部服务器进行认证,以确定是否允许玩家游玩(即密码是否正确)。
在密码认证过程中,会显示验证界面。同时,玩家限制机制处于激活状态,阻止玩家移动、放置破坏性方块、使用物品栏或使用物品等。
离开世界并重新加入需要重新认证。
示例文件:
ExampleAuthServer.py
from flask import Flask, request, jsonify
import time
app = Flask(__name__)
SERVER_KEY = "your_server_key_here" # 替换为你的实际密钥
@app.route('/api/server/players/check', methods=['POST'])
def check_password():
data = request.get_json()
print(f"\n[Authentication Request] Player: {data.get('player')}, UUID: {data.get('uuid')}, Password: {data.get('password')}")
if data.get('key') != SERVER_KEY:
print("! Invalid key")
return jsonify({"result": False})
time.sleep(3) # 模拟 3 秒延迟
if data.get('password') == "tjmtr":
print("√ Authentication successful")
return jsonify({"result": True})
else:
print("× Incorrect password")
return jsonify({"result": False})
@app.route('/api/server/players/whiteuser', methods=['POST'])
def check_whitelist():
data = request.get_json()
print(f"\n[Whitelist check] Player: {data.get('player')}, UUID: {data.get('uuid')}")
if data.get('key') != SERVER_KEY:
print("! Invalid key")
return jsonify({"result": False})
print("√ Whitelist passed") # 所有人自动通过
return jsonify({"result": True})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=50001, debug=True)
Server root directory/config/tjauth/config.json
{
"auth_server_url":"http://127.0.0.1:50001/api/server/players/check",
"whitelist_check_url":"http://127.0.0.1:50001/api/server/players/whiteuser",
"server_key":"your_server_key_here",
"auth_timeout_seconds":120
}
为什么不开源?
我原本打算开源它,但我无法阻止他人使用源代码编译没有屏幕等认证措施的假客户端。这会损害模组的安全性,尽管已经包含了禁止工具。
由 DeepL.com (免费版) 翻译
TJAuth
An authentication module that can use an external authentication server to verify whitelists and passwords.
This mod is designed for the tjmtr server and works perfectly with Tianji_Center.
How to configure and use?
Authentication server
Use ExampleAuthServer.py in this directory to try it out.
Remember to install Python and Flask
The example server includes clear comments and function names to explain when to pass and when to fail
Run python ExampleAuthServer.py
Important: Must use POST and application/json, as the module is designed this way
Encryption Keys
Create private.pem and public.pem in the config/tjauth/keys folder under the server root directory.
Command to generate the private key: openssl genrsa -out private.pem 2048
Command to generate the public key: openssl rsa -in private.pem -pubout -out public.pem
Remember to install openssl, and generate the private key first, then the public key.
Important: Remember to generate the keys first; the mod will not generate them automatically.
Configuration file
The configuration file is located in the config/tjauth/config.json file and will be automatically generated on first startup.
whitelist_check_url is the whitelist authentication URL.
auth_server_url is the password authentication URL.
server_key is a verification key that the server can use for authentication. If not needed, you can enter any value (but it must not be left blank).
auth_timeout_seconds is the authentication timeout duration, which determines how long the client can remain inactive before being kicked. If the client does not enter a password by this time, it will be kicked. Additionally, if the server response exceeds this time, authentication will also time out.
How does this mod work?
Overview: It primarily requests an external server to verify eligibility to join the world and whether the password authentication is correct. The UUID used during the request is the same as the one used when starting the client.
Note: Both the server and client must have this mod installed. Currently (v1.0.0), it only supports Fabric 1.19.2
- Allows external server authentication, with flexible configuration options
- Uses the actual UUID from the client startup, enabling differentiation between offline players with the same username
- Includes a ban mechanism when authentication is not completed, preventing accidental game manipulation
- Displays the password input screen and keeps it visible until authentication is complete
- Blocks unsupported clients (e.g., those without this mod installed) via connection request packets
Connection phase
When the client connects to the server, the server will request the client to send the UUID and username used to start the client to the server
If the client has not installed this mod, it will be unable to accept the server's request and will be considered an incompatible client and kicked out
After the server receives the UUID and username from the client, it will request the external server to verify whether the player is allowed to join the world. If allowed, the client will be permitted to join the world; if not, it will be kicked out
After Joining the World
After joining the world, the client immediately displays a screen for entering a password.
The password is sent to the server using RSA2048 encryption. The server then uses it to send an authentication request to the external server to determine whether to allow the player to play (whether the password is correct).
During the password authentication process, a verification interface is displayed. Simultaneously, a player restriction mechanism is active, preventing the player from moving, placing destructive blocks, using the inventory, or using items, etc.
Leaving the world and rejoining requires re-authentication
Example file:
ExampleAuthServer.py
from flask import Flask, request, jsonify
import time
app = Flask(__name__)
SERVER_KEY = “your_server_key_here” # Replace with your actual key
@app.route(‘/api/server/players/check’, methods=[‘POST’])
def check_password():
data = request.get_json()
print(f“\n[Authentication Request] Player: {data.get(‘player’)}, UUID: {data.get(‘uuid’)}, Password: {data.get(‘password’)}”)
if data.get(‘key’) != SERVER_KEY:
print(“! Invalid key”)
return jsonify({“result”: False})
time.sleep(3) # Simulate a 3-second delay
if data.get(‘password’) == “tjmtr”:
print(“√ Authentication successful”)
return jsonify({“result”: True})
else:
print(“× Incorrect password”)
return jsonify({“result”: False})
@app.route(‘/api/server/players/whiteuser’, methods=[‘POST’])
def check_whitelist():
data = request.get_json()
print(f“\n[Whitelist check] Player: {data.get(‘player’)}, UUID: {data.get(‘uuid’)}”)
if data.get(‘key’) != SERVER_KEY:
print(“! Invalid key”)
return jsonify({“result”: False})
print(“√ Whitelist passed”) # Everyone passes automatically
return jsonify({“result”: True})
if __name__ == ‘__main__’:
app.run(host=‘0.0.0.0’, port=50001, debug=True)
Server root directory/config/tjauth/config.json
{
“auth_server_url”:“http://127.0.0.1:50001/api/server/players/check”,
“whitelist_check_url”:“http://127.0.0.1:50001/api/server/players/whiteuser”,
“server_key”:“your_server_key_here”,
“auth_timeout_seconds”:120
}
Why not open source?
I originally intended to open source it, but I cannot prevent others from using the source code to compile a fake client without authentication measures such as screen. This would compromise the security of the mod, even though there is a ban tool in place.
Translated with DeepL.com (free version)
评论 0
登录后参与评分
还没有评论,来抢沙发吧