From 75d7e29f6e354f7c10ccd7c3c34ddca717cecd1a Mon Sep 17 00:00:00 2001 From: DIKER0K Date: Sun, 20 Jul 2025 09:12:37 +0500 Subject: [PATCH] fix: another player see your skin! --- app/api/meta.py | 36 ++-- private_key.pem => app/keys/private_key.pem | 0 public_key.pem => app/keys/public_key.pem | 0 app/services/auth.py | 157 +++++++++++++----- ...e_5a522894-02be-4221-be1c-09ec1ff50665.png | Bin 0 -> 738 bytes 5 files changed, 140 insertions(+), 53 deletions(-) rename private_key.pem => app/keys/private_key.pem (100%) rename public_key.pem => app/keys/public_key.pem (100%) create mode 100644 app/static/capes_store/store_cape_5a522894-02be-4221-be1c-09ec1ff50665.png diff --git a/app/api/meta.py b/app/api/meta.py index 2e16373..8a3710e 100644 --- a/app/api/meta.py +++ b/app/api/meta.py @@ -4,15 +4,29 @@ router = APIRouter(tags=["Meta"]) @router.get("/") def api_root(): - return { - "meta": { - "serverName": "Your Auth Server", - "implementationName": "FastAPI", - "implementationVersion": "1.0.0", - "links": { - "homepage": "https://your-server.com" + # Читаем публичный ключ из файла + public_key_path = "app/keys/public_key.pem" + + try: + with open(public_key_path, "r") as f: + public_key = f.read().strip() + + return { + "meta": { + "serverName": "Popa Auth Server", + "implementationName": "FastAPI", + "implementationVersion": "1.0.0", + "links": { + "homepage": "https://popa-popa.ru" + } }, - }, - "skinDomains": ["147.78.65.214"], - "capeDomains": ["147.78.65.214"] - } + "skinDomains": ["147.78.65.214"], + "capeDomains": ["147.78.65.214"], + # Важно - возвращаем ключ как есть, без дополнительной обработки + "signaturePublickey": public_key + } + except Exception as e: + return { + "error": str(e), + "traceback": str(e) + } diff --git a/private_key.pem b/app/keys/private_key.pem similarity index 100% rename from private_key.pem rename to app/keys/private_key.pem diff --git a/public_key.pem b/app/keys/public_key.pem similarity index 100% rename from public_key.pem rename to app/keys/public_key.pem diff --git a/app/services/auth.py b/app/services/auth.py index e6543f5..2faf691 100644 --- a/app/services/auth.py +++ b/app/services/auth.py @@ -108,7 +108,7 @@ class AuthService: textures = { "timestamp": int(datetime.now().timestamp() * 1000), - "profileId": user["uuid"], # UUID с дефисами + "profileId": user["uuid"].replace("-", ""), "profileName": user["username"], "textures": {} } @@ -124,29 +124,67 @@ class AuthService: textures_json = json.dumps(textures).encode() 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( - textures_json, - padding.PKCS1v15(), - hashes.SHA1() - ) + 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 + }] + } - return JSONResponse({ - "id": user["uuid"].replace("-", ""), # Уберите дефисы - "name": user["username"], - "properties": [{ - "name": "textures", - "value": base64_textures, - "signature": base64.b64encode(signature).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( + # 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): access_token = request_data.get("accessToken") @@ -186,24 +224,59 @@ class AuthService: if not session: raise HTTPException(status_code=403, detail="Not joined this server") - textures = {} - if user.get("skin_url"): - textures["SKIN"] = {"url": user["skin_url"]} - if user.get("cloak_url"): - textures["CAPE"] = {"url": user["cloak_url"]} - - 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 [] + textures = { + "timestamp": int(datetime.now().timestamp() * 1000), + "profileId": user["uuid"].replace("-", ""), + "profileName": user["username"], + "textures": {} } + + 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 + }] + } diff --git a/app/static/capes_store/store_cape_5a522894-02be-4221-be1c-09ec1ff50665.png b/app/static/capes_store/store_cape_5a522894-02be-4221-be1c-09ec1ff50665.png new file mode 100644 index 0000000000000000000000000000000000000000..9ef45747c05da53044fb25cc5a59977352b2d3ab GIT binary patch literal 738 zcmV<80v-K{P)(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fdMgRZ+R8UM* zMF0Q*s;a8{`Ty?x{Ko0+p~%;s$K#*J;G~?z8Mpr>oBbZ1|0J6HKZN5rh}}Pg-(FFR zEi#5HEPyL4ekv(_DJ6I(A95ufY$O(F9|&3-1x^zHIFtjnZ2$lO0(4SNQvd_+nw)|F z00II@L_t(|+U=CVmYXmPMVXfvk1PvFJJ1aN|NpFIyEzSqIqgQ7jW2OzR_{t+hPSuR z6IetzQ~q78gAHE@G=o-LE^e@)C2s4s-M741mgVy+>;&%jZM)rW*{jwb%Q>f*SH`+q9OrQksI^?zLJ?pav9b?@CQ9n?lvvZ3GnT|AW~C6lDG>VkCe) z?NCnRleIw75CHyQklK2bWHo`*`uCm)dH*Lm)!?Mt=3_O1(!M7q!r$HN)pn^m*a#$e zXnrx!EaWUji>52J*a$%JEbN7-2DijUli1A!JTl~kQwDjpa>PhL^SuX&aLWeLIWQ8) z2!opd#(bTGC%{aA*$Y^}wSSDjQ*;4=;TDnB6?93`qeMU-HM1dFXUHold9I>2x}sPN!qQZ?a=> UPS5tSwEzGB07*qoM6N<$f{kWI6aWAK literal 0 HcmV?d00001