From 5c420184ac4ac19e73653a5399fa6cede583753a Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Wed, 3 Apr 2024 13:09:27 -0500 Subject: [PATCH] More gree stuff --- src/main.rs | 8 ++++++ src/router/gree.rs | 61 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0802653..9b8e309 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,12 @@ use actix_web::{ #[post("/v1.0/auth/initialize")] async fn gree_init(req: HttpRequest, body: String) -> HttpResponse { router::gree::initialize(req, body) } +#[get("/v1.0/auth/x_uid")] +async fn gree_uid(req: HttpRequest) -> HttpResponse { router::gree::uid(req) } + +#[post("/v1.0/auth/authorize")] +async fn gree_authorize(req: HttpRequest, body: String) -> HttpResponse { router::gree::authorize(req, body) } + #[post("/api/debug/error")] async fn debug_error(req: HttpRequest, body: String) -> HttpResponse { router::debug::error(req, body) } @@ -137,6 +143,8 @@ async fn main() -> std::io::Result<()> { .service(preset) .service(preset_get) .service(gree_init) + .service(gree_uid) + .service(gree_authorize) .service(debug_error) .service(login_bonus) .service(reward) diff --git a/src/router/gree.rs b/src/router/gree.rs index efc501d..6d96991 100644 --- a/src/router/gree.rs +++ b/src/router/gree.rs @@ -4,8 +4,19 @@ use base64::{Engine as _, engine::general_purpose}; use std::collections::HashMap; use sha1::Sha1; use substring::Substring; +use json::object; +use hmac::{Hmac, Mac}; +use crate::router::userdata; pub fn initialize(req: HttpRequest, _body: String) -> HttpResponse { + let app_id = "232610769078541"; + let resp = object!{ + result: "OK", + app_id: app_id, + uuid: format!("{}{:x}", app_id, md5::compute((global::timestamp() * 1000).to_string())) + }; + println!("{}", resp["uuid"].to_string()); + HttpResponse::Ok() .insert_header(ContentType::json()) .insert_header(("Expires", "-1")) @@ -13,11 +24,55 @@ pub fn initialize(req: HttpRequest, _body: String) -> HttpResponse { .insert_header(("Cache-Control", "must-revalidate, no-cache, no-store, private")) .insert_header(("Vary", "Authorization,Accept-Encoding")) .insert_header(("X-GREE-Authorization", gree_authorize(&req))) - .body("{\"result\": \"OK\"}") - + .body(json::stringify(resp)) } -use hmac::{Hmac, Mac}; +pub fn authorize(req: HttpRequest, _body: String) -> HttpResponse { + let resp = object!{ + result: "OK" + }; + HttpResponse::Ok() + .insert_header(ContentType::json()) + .insert_header(("Expires", "-1")) + .insert_header(("Pragma", "no-cache")) + .insert_header(("Cache-Control", "must-revalidate, no-cache, no-store, private")) + .insert_header(("Vary", "Authorization,Accept-Encoding")) + .insert_header(("X-GREE-Authorization", gree_authorize(&req))) + .body(json::stringify(resp)) +} + +pub fn uid(req: HttpRequest) -> HttpResponse { + let app_id = "232610769078541"; + + let mut uid = String::new(); + let blank_header = HeaderValue::from_static(""); + let auth_header = req.headers().get("Authorization").unwrap_or(&blank_header).to_str().unwrap_or(""); + let uid_data: Vec<&str> = auth_header.split(",xoauth_requestor_id=\"").collect(); + if let Some(uid_data2) = uid_data.get(1) { + let uid_data2: Vec<&str> = uid_data2.split('"').collect(); + if let Some(uid_str) = uid_data2.get(0) { + uid = uid_str.to_string(); + } + } + + let key = uid.substring(app_id.len(), uid.len()); + let user = userdata::get_acc(&key); + + let resp = object!{ + result: "OK", + x_app_id: "100900301", + x_uid: user["user"]["id"].to_string() + }; + + HttpResponse::Ok() + .insert_header(ContentType::json()) + .insert_header(("Expires", "-1")) + .insert_header(("Pragma", "no-cache")) + .insert_header(("Cache-Control", "must-revalidate, no-cache, no-store, private")) + .insert_header(("Vary", "Authorization,Accept-Encoding")) + .insert_header(("X-GREE-Authorization", gree_authorize(&req))) + .body(json::stringify(resp)) +} fn gree_authorize(req: &HttpRequest) -> String {