mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Push (not working?) gree code
This commit is contained in:
parent
5bf5b8333d
commit
36077a0b69
6 changed files with 120 additions and 1 deletions
42
Cargo.lock
generated
42
Cargo.lock
generated
|
@ -485,6 +485,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block-buffer",
|
"block-buffer",
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -520,12 +521,17 @@ dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"chrono",
|
"chrono",
|
||||||
"hex",
|
"hex",
|
||||||
|
"hmac",
|
||||||
"json",
|
"json",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"md5",
|
||||||
"openssl",
|
"openssl",
|
||||||
"rand",
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
|
"sha1",
|
||||||
|
"substring",
|
||||||
|
"urlencoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -711,6 +717,15 @@ version = "0.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hmac"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
|
@ -926,6 +941,12 @@ version = "0.4.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "md5"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.7.1"
|
version = "2.7.1"
|
||||||
|
@ -1441,6 +1462,21 @@ dependencies = [
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "substring"
|
||||||
|
version = "1.4.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "42ee6433ecef213b2e72f587ef64a2f5943e7cd16fbd82dbe8bc07486c534c86"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
|
@ -1672,6 +1708,12 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "urlencoding"
|
||||||
|
version = "2.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "vcpkg"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
|
|
|
@ -14,3 +14,8 @@ rand = "0.8.5"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
chrono = "0.4.31"
|
chrono = "0.4.31"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
|
hmac = "0.12.1"
|
||||||
|
md5 = "0.7.0"
|
||||||
|
urlencoding = "2.1.3"
|
||||||
|
sha1 = "0.10.6"
|
||||||
|
substring = "1.4.5"
|
||||||
|
|
|
@ -9,6 +9,9 @@ use actix_web::{
|
||||||
dev::Service
|
dev::Service
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[post("/v1.0/auth/initialize")]
|
||||||
|
async fn gree_init(req: HttpRequest, body: String) -> HttpResponse { router::gree::initialize(req, body) }
|
||||||
|
|
||||||
#[post("/api/debug/error")]
|
#[post("/api/debug/error")]
|
||||||
async fn debug_error(req: HttpRequest, body: String) -> HttpResponse { router::debug::error(req, body) }
|
async fn debug_error(req: HttpRequest, body: String) -> HttpResponse { router::debug::error(req, body) }
|
||||||
|
|
||||||
|
@ -122,6 +125,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
println!("Request: {}", req.path());
|
println!("Request: {}", req.path());
|
||||||
srv.call(req)
|
srv.call(req)
|
||||||
})
|
})
|
||||||
|
.service(gree_init)
|
||||||
.service(debug_error)
|
.service(debug_error)
|
||||||
.service(login_bonus)
|
.service(login_bonus)
|
||||||
.service(reward)
|
.service(reward)
|
||||||
|
|
|
@ -15,3 +15,4 @@ pub mod chat;
|
||||||
pub mod story;
|
pub mod story;
|
||||||
pub mod notice;
|
pub mod notice;
|
||||||
pub mod debug;
|
pub mod debug;
|
||||||
|
pub mod gree;
|
||||||
|
|
|
@ -7,7 +7,6 @@ use actix_web::{
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use base64::{Engine as _, engine::general_purpose};
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
|
|
||||||
//different between ios and android?
|
|
||||||
pub const ASSET_VERSION: &str = "13177023d4b7ad41ff52af4cefba5c55";
|
pub const ASSET_VERSION: &str = "13177023d4b7ad41ff52af4cefba5c55";
|
||||||
pub const ASSET_HASH: &str = "6a6f3be1da2c3734386a1832e251451a";
|
pub const ASSET_HASH: &str = "6a6f3be1da2c3734386a1832e251451a";
|
||||||
|
|
||||||
|
|
68
src/router/gree.rs
Normal file
68
src/router/gree.rs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
use crate::router::global;
|
||||||
|
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue, http::header::ContentType};
|
||||||
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use sha1::Sha1;
|
||||||
|
use substring::Substring;
|
||||||
|
|
||||||
|
pub fn initialize(req: HttpRequest, _body: String) -> HttpResponse {
|
||||||
|
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("{\"result\": \"OK\"}")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
use hmac::{Hmac, Mac};
|
||||||
|
|
||||||
|
|
||||||
|
fn gree_authorize(req: &HttpRequest) -> String {
|
||||||
|
type HmacSha1 = Hmac<Sha1>;
|
||||||
|
|
||||||
|
let blank_header = HeaderValue::from_static("");
|
||||||
|
let auth_header = req.headers().get("Authorization").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
|
if auth_header == "" {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
let auth_header = auth_header.substring(6, auth_header.len());
|
||||||
|
|
||||||
|
let auth_list: Vec<&str> = auth_header.split(',').collect();
|
||||||
|
let mut header_data = HashMap::new();
|
||||||
|
|
||||||
|
for auth_data in auth_list {
|
||||||
|
let data: Vec<&str> = auth_data.split('=').collect();
|
||||||
|
if data.len() == 2 {
|
||||||
|
header_data.insert(data[0].to_string(), data[1][1..(data[1].len() - 1)].to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let current_url = format!("http://127.0.0.1:8080{}", req.path());
|
||||||
|
let nonce = format!("{:x}", md5::compute((global::timestamp() * 1000).to_string()));
|
||||||
|
let timestamp = global::timestamp().to_string();
|
||||||
|
let method = "HMAC-SHA1";
|
||||||
|
let validate_data = format!("{}&{}&{}",
|
||||||
|
"POST",
|
||||||
|
urlencoding::encode(¤t_url),
|
||||||
|
urlencoding::encode(&format!("oauth_body_hash={}&oauth_consumer_key={}&oauth_nonce={}&oauth_signature_method={}&oauth_timestamp={}&oauth_version=1.0",
|
||||||
|
header_data.get("oauth_body_hash").unwrap_or(&String::new()),
|
||||||
|
header_data.get("oauth_consumer_key").unwrap_or(&String::new()),
|
||||||
|
nonce,
|
||||||
|
method,
|
||||||
|
timestamp)));
|
||||||
|
let mut hasher = HmacSha1::new_from_slice(&hex::decode("6438663638653238346566646636306262616563326432323563306366643432").unwrap()).unwrap();
|
||||||
|
hasher.update(validate_data.as_bytes());
|
||||||
|
let signature = general_purpose::STANDARD.encode(hasher.finalize().into_bytes());
|
||||||
|
|
||||||
|
format!("OAuth oauth_version=\"1.0\",oauth_nonce=\"{}\",oauth_timestamp=\"{}\",oauth_consumer_key=\"{}\",oauth_body_hash=\"{}\",oauth_signature_method=\"{}\",oauth_signature=\"{}\"",
|
||||||
|
nonce,
|
||||||
|
timestamp,
|
||||||
|
header_data.get("oauth_consumer_key").unwrap_or(&String::new()),
|
||||||
|
header_data.get("oauth_body_hash").unwrap_or(&String::new()),
|
||||||
|
method,
|
||||||
|
urlencoding::encode(&signature))
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue