fix: another player see your skin!
This commit is contained in:
@ -4,15 +4,29 @@ router = APIRouter(tags=["Meta"])
|
|||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
def api_root():
|
def api_root():
|
||||||
return {
|
# Читаем публичный ключ из файла
|
||||||
"meta": {
|
public_key_path = "app/keys/public_key.pem"
|
||||||
"serverName": "Your Auth Server",
|
|
||||||
"implementationName": "FastAPI",
|
try:
|
||||||
"implementationVersion": "1.0.0",
|
with open(public_key_path, "r") as f:
|
||||||
"links": {
|
public_key = f.read().strip()
|
||||||
"homepage": "https://your-server.com"
|
|
||||||
|
return {
|
||||||
|
"meta": {
|
||||||
|
"serverName": "Popa Auth Server",
|
||||||
|
"implementationName": "FastAPI",
|
||||||
|
"implementationVersion": "1.0.0",
|
||||||
|
"links": {
|
||||||
|
"homepage": "https://popa-popa.ru"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
"skinDomains": ["147.78.65.214"],
|
||||||
"skinDomains": ["147.78.65.214"],
|
"capeDomains": ["147.78.65.214"],
|
||||||
"capeDomains": ["147.78.65.214"]
|
# Важно - возвращаем ключ как есть, без дополнительной обработки
|
||||||
}
|
"signaturePublickey": public_key
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
return {
|
||||||
|
"error": str(e),
|
||||||
|
"traceback": str(e)
|
||||||
|
}
|
||||||
|
@ -108,7 +108,7 @@ class AuthService:
|
|||||||
|
|
||||||
textures = {
|
textures = {
|
||||||
"timestamp": int(datetime.now().timestamp() * 1000),
|
"timestamp": int(datetime.now().timestamp() * 1000),
|
||||||
"profileId": user["uuid"], # UUID с дефисами
|
"profileId": user["uuid"].replace("-", ""),
|
||||||
"profileName": user["username"],
|
"profileName": user["username"],
|
||||||
"textures": {}
|
"textures": {}
|
||||||
}
|
}
|
||||||
@ -124,29 +124,67 @@ class AuthService:
|
|||||||
|
|
||||||
textures_json = json.dumps(textures).encode()
|
textures_json = json.dumps(textures).encode()
|
||||||
base64_textures = base64.b64encode(textures_json).decode()
|
base64_textures = base64.b64encode(textures_json).decode()
|
||||||
|
|
||||||
# Подписываем текстуры
|
|
||||||
with open("private_key.pem", "rb") as key_file:
|
|
||||||
private_key = serialization.load_pem_private_key(
|
|
||||||
key_file.read(),
|
|
||||||
password=None
|
|
||||||
)
|
|
||||||
|
|
||||||
signature = private_key.sign(
|
try:
|
||||||
textures_json,
|
# Подписываем текстуры
|
||||||
padding.PKCS1v15(),
|
private_key_path = "app/keys/private_key.pem"
|
||||||
hashes.SHA1()
|
with open(private_key_path, "rb") as key_file:
|
||||||
)
|
private_key = serialization.load_pem_private_key(
|
||||||
|
key_file.read(),
|
||||||
|
password=None
|
||||||
|
)
|
||||||
|
|
||||||
|
signature = private_key.sign(
|
||||||
|
base64.b64encode(textures_json),
|
||||||
|
padding.PKCS1v15(),
|
||||||
|
hashes.SHA1()
|
||||||
|
)
|
||||||
|
|
||||||
|
signature_base64 = base64.b64encode(signature).decode()
|
||||||
|
|
||||||
|
return {
|
||||||
|
"id": user["uuid"].replace("-", ""),
|
||||||
|
"name": user["username"],
|
||||||
|
"properties": [{
|
||||||
|
"name": "textures",
|
||||||
|
"value": base64_textures,
|
||||||
|
"signature": signature_base64
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error signing textures: {e}")
|
||||||
|
# В случае ошибки возвращаем текстуры без подписи
|
||||||
|
return {
|
||||||
|
"id": user["uuid"].replace("-", ""),
|
||||||
|
"name": user["username"],
|
||||||
|
"properties": [{
|
||||||
|
"name": "textures",
|
||||||
|
"value": base64_textures
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
return JSONResponse({
|
# # Подписываем текстуры
|
||||||
"id": user["uuid"].replace("-", ""), # Уберите дефисы
|
# with open("private_key.pem", "rb") as key_file:
|
||||||
"name": user["username"],
|
# private_key = serialization.load_pem_private_key(
|
||||||
"properties": [{
|
# key_file.read(),
|
||||||
"name": "textures",
|
# password=None
|
||||||
"value": base64_textures,
|
# )
|
||||||
"signature": base64.b64encode(signature).decode()
|
|
||||||
}]
|
# signature = private_key.sign(
|
||||||
})
|
# textures_json,
|
||||||
|
# padding.PKCS1v15(),
|
||||||
|
# hashes.SHA1()
|
||||||
|
# )
|
||||||
|
|
||||||
|
# return JSONResponse({
|
||||||
|
# "id": user["uuid"].replace("-", ""), # Уберите дефисы
|
||||||
|
# "name": user["username"],
|
||||||
|
# "properties": [{
|
||||||
|
# "name": "textures",
|
||||||
|
# "value": base64_textures,
|
||||||
|
# # "signature": base64.b64encode(signature).decode()
|
||||||
|
# }]
|
||||||
|
# })
|
||||||
|
|
||||||
async def join_server(self, request_data: dict):
|
async def join_server(self, request_data: dict):
|
||||||
access_token = request_data.get("accessToken")
|
access_token = request_data.get("accessToken")
|
||||||
@ -186,24 +224,59 @@ class AuthService:
|
|||||||
if not session:
|
if not session:
|
||||||
raise HTTPException(status_code=403, detail="Not joined this server")
|
raise HTTPException(status_code=403, detail="Not joined this server")
|
||||||
|
|
||||||
textures = {}
|
textures = {
|
||||||
if user.get("skin_url"):
|
"timestamp": int(datetime.now().timestamp() * 1000),
|
||||||
textures["SKIN"] = {"url": user["skin_url"]}
|
"profileId": user["uuid"].replace("-", ""),
|
||||||
if user.get("cloak_url"):
|
"profileName": user["username"],
|
||||||
textures["CAPE"] = {"url": user["cloak_url"]}
|
"textures": {}
|
||||||
|
|
||||||
textures_value = base64.b64encode(json.dumps({
|
|
||||||
"timestamp": int(datetime.now().timestamp()),
|
|
||||||
"profileId": user["uuid"].replace("-", ""), # UUID без дефисов
|
|
||||||
"profileName": username,
|
|
||||||
"textures": textures
|
|
||||||
}).encode()).decode()
|
|
||||||
|
|
||||||
return {
|
|
||||||
"id": user["uuid"].replace("-", ""), # UUID без дефисов
|
|
||||||
"name": username,
|
|
||||||
"properties": [{
|
|
||||||
"name": "textures",
|
|
||||||
"value": textures_value
|
|
||||||
}] if textures else []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.get("skin_url"):
|
||||||
|
textures["textures"]["SKIN"] = {
|
||||||
|
"url": user["skin_url"],
|
||||||
|
"metadata": {"model": user.get("skin_model", "classic")}
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.get("cloak_url"):
|
||||||
|
textures["textures"]["CAPE"] = {"url": user["cloak_url"]}
|
||||||
|
|
||||||
|
textures_json = json.dumps(textures).encode()
|
||||||
|
base64_textures = base64.b64encode(textures_json).decode()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Подписываем текстуры
|
||||||
|
private_key_path = "app/keys/private_key.pem"
|
||||||
|
with open(private_key_path, "rb") as key_file:
|
||||||
|
private_key = serialization.load_pem_private_key(
|
||||||
|
key_file.read(),
|
||||||
|
password=None
|
||||||
|
)
|
||||||
|
|
||||||
|
signature = private_key.sign(
|
||||||
|
base64.b64encode(textures_json),
|
||||||
|
padding.PKCS1v15(),
|
||||||
|
hashes.SHA1()
|
||||||
|
)
|
||||||
|
|
||||||
|
signature_base64 = base64.b64encode(signature).decode()
|
||||||
|
|
||||||
|
return {
|
||||||
|
"id": user["uuid"].replace("-", ""),
|
||||||
|
"name": user["username"],
|
||||||
|
"properties": [{
|
||||||
|
"name": "textures",
|
||||||
|
"value": base64_textures,
|
||||||
|
"signature": signature_base64
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error signing textures: {e}")
|
||||||
|
# В случае ошибки возвращаем текстуры без подписи
|
||||||
|
return {
|
||||||
|
"id": user["uuid"].replace("-", ""),
|
||||||
|
"name": user["username"],
|
||||||
|
"properties": [{
|
||||||
|
"name": "textures",
|
||||||
|
"value": base64_textures
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 738 B |
Reference in New Issue
Block a user