mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Implement proper jp authentication (gree)
This commit is contained in:
parent
f33e211dab
commit
b5138bfaaa
13 changed files with 381 additions and 42 deletions
170
Cargo.lock
generated
170
Cargo.lock
generated
|
@ -302,6 +302,12 @@ version = "0.21.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64ct"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
|
@ -350,6 +356,12 @@ version = "3.15.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a3b1be7772ee4501dba05acbe66bb1e8760f6a6c474a36035631638e4415f130"
|
checksum = "a3b1be7772ee4501dba05acbe66bb1e8760f6a6c474a36035631638e4415f130"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
|
@ -394,6 +406,12 @@ dependencies = [
|
||||||
"windows-targets 0.52.0",
|
"windows-targets 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const-oid"
|
||||||
|
version = "0.9.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "convert_case"
|
name = "convert_case"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -455,6 +473,17 @@ dependencies = [
|
||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "der"
|
||||||
|
version = "0.7.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0"
|
||||||
|
dependencies = [
|
||||||
|
"const-oid",
|
||||||
|
"pem-rfc7468",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deranged"
|
name = "deranged"
|
||||||
version = "0.3.11"
|
version = "0.3.11"
|
||||||
|
@ -484,6 +513,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block-buffer",
|
"block-buffer",
|
||||||
|
"const-oid",
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
@ -529,10 +559,12 @@ dependencies = [
|
||||||
"openssl",
|
"openssl",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"rsa",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"sha1",
|
"sha1",
|
||||||
"substring",
|
"substring",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -891,6 +923,9 @@ name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
dependencies = [
|
||||||
|
"spin",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
|
@ -898,6 +933,12 @@ version = "0.2.153"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libm"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libmath"
|
name = "libmath"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
|
@ -1014,12 +1055,49 @@ dependencies = [
|
||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-bigint-dig"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"lazy_static",
|
||||||
|
"libm",
|
||||||
|
"num-integer",
|
||||||
|
"num-iter",
|
||||||
|
"num-traits",
|
||||||
|
"rand 0.8.5",
|
||||||
|
"smallvec",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-conv"
|
name = "num-conv"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.46"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-iter"
|
||||||
|
version = "0.1.44"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.2.18"
|
version = "0.2.18"
|
||||||
|
@ -1027,6 +1105,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
|
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
|
"libm",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1127,6 +1206,15 @@ version = "1.0.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
|
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pem-rfc7468"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412"
|
||||||
|
dependencies = [
|
||||||
|
"base64ct",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.1"
|
version = "2.3.1"
|
||||||
|
@ -1145,6 +1233,27 @@ version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkcs1"
|
||||||
|
version = "0.7.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f"
|
||||||
|
dependencies = [
|
||||||
|
"der",
|
||||||
|
"pkcs8",
|
||||||
|
"spki",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkcs8"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7"
|
||||||
|
dependencies = [
|
||||||
|
"der",
|
||||||
|
"spki",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
|
@ -1336,6 +1445,26 @@ dependencies = [
|
||||||
"winreg",
|
"winreg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rsa"
|
||||||
|
version = "0.9.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc"
|
||||||
|
dependencies = [
|
||||||
|
"const-oid",
|
||||||
|
"digest",
|
||||||
|
"num-bigint-dig",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"pkcs1",
|
||||||
|
"pkcs8",
|
||||||
|
"rand_core 0.6.4",
|
||||||
|
"signature",
|
||||||
|
"spki",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rusqlite"
|
name = "rusqlite"
|
||||||
version = "0.30.0"
|
version = "0.30.0"
|
||||||
|
@ -1500,6 +1629,16 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signature"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
"rand_core 0.6.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.9"
|
version = "0.4.9"
|
||||||
|
@ -1525,6 +1664,22 @@ dependencies = [
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spin"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spki"
|
||||||
|
version = "0.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d"
|
||||||
|
dependencies = [
|
||||||
|
"base64ct",
|
||||||
|
"der",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "substring"
|
name = "substring"
|
||||||
version = "1.4.5"
|
version = "1.4.5"
|
||||||
|
@ -1777,6 +1932,15 @@ version = "2.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uuid"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "vcpkg"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
|
@ -2073,6 +2237,12 @@ dependencies = [
|
||||||
"syn 2.0.50",
|
"syn 2.0.50",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize"
|
||||||
|
version = "1.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd"
|
name = "zstd"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
|
|
@ -20,3 +20,5 @@ urlencoding = "2.1.3"
|
||||||
sha1 = "0.10.6"
|
sha1 = "0.10.6"
|
||||||
substring = "1.4.5"
|
substring = "1.4.5"
|
||||||
libmath = "0.1.4"
|
libmath = "0.1.4"
|
||||||
|
uuid = { version = "1.8.0", features = ["v4"] }
|
||||||
|
rsa = "0.9.6"
|
||||||
|
|
|
@ -5,8 +5,8 @@ use crate::router::global;
|
||||||
use actix_web::{HttpResponse, HttpRequest};
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
|
||||||
pub fn home(req: HttpRequest, _body: String) -> HttpResponse {
|
pub fn home(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let key = global::get_login(req.headers());
|
let key = global::get_login(req.headers(), &body);
|
||||||
let user = userdata::get_acc(&key);
|
let user = userdata::get_acc(&key);
|
||||||
|
|
||||||
let id = user["user"]["favorite_master_card_id"].as_i64().unwrap() / 10000;
|
let id = user["user"]["favorite_master_card_id"].as_i64().unwrap() / 10000;
|
||||||
|
|
|
@ -4,6 +4,7 @@ use actix_web::{
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
http::header::{HeaderValue, HeaderMap}
|
http::header::{HeaderValue, HeaderMap}
|
||||||
};
|
};
|
||||||
|
use crate::router::gree;
|
||||||
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};
|
||||||
|
|
||||||
|
@ -15,20 +16,23 @@ pub const ASSET_VERSION_JP: &str = "4c921d2443335e574a82e04ec9ea243c";
|
||||||
pub const ASSET_HASH_ANDROID_JP: &str = "67f8f261c16b3cca63e520a25aad6c1c";
|
pub const ASSET_HASH_ANDROID_JP: &str = "67f8f261c16b3cca63e520a25aad6c1c";
|
||||||
pub const ASSET_HASH_IOS_JP: &str = "b8975be8300013a168d061d3fdcd4a16";
|
pub const ASSET_HASH_IOS_JP: &str = "b8975be8300013a168d061d3fdcd4a16";
|
||||||
|
|
||||||
pub fn get_login(headers: &HeaderMap) -> String {
|
pub fn get_login(headers: &HeaderMap, body: &str) -> String {
|
||||||
let blank_header = HeaderValue::from_static("");
|
let blank_header = HeaderValue::from_static("");
|
||||||
|
|
||||||
let login = headers.get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
let login = headers.get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
let decoded = general_purpose::STANDARD.decode(login).unwrap_or(vec![]);
|
let decoded = general_purpose::STANDARD.decode(login).unwrap_or(vec![]);
|
||||||
let a6573cbe = String::from_utf8_lossy(&decoded);
|
match String::from_utf8(decoded) {
|
||||||
if a6573cbe.contains("-") {
|
Ok(a6573cbe) => {
|
||||||
let parts: Vec<&str> = a6573cbe.split('-').collect();
|
let parts: Vec<&str> = a6573cbe.split('-').collect();
|
||||||
let token = parts[1..parts.len() - 1].join("-");
|
let token = parts[1..parts.len() - 1].join("-");
|
||||||
return token.to_string();
|
return token.to_string();
|
||||||
}
|
},
|
||||||
//only jp should error?
|
Err(_) => {
|
||||||
let key = headers.get("aoharu-user-id").unwrap_or(&blank_header).to_str().unwrap_or("");
|
let rv = gree::get_uuid(headers, body);
|
||||||
key.to_string()
|
assert!(rv != String::new());
|
||||||
|
return rv;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timestamp() -> u64 {
|
pub fn timestamp() -> u64 {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::router::global;
|
use crate::router::global;
|
||||||
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue, http::header::ContentType};
|
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue, http::header::ContentType, http::header::HeaderMap};
|
||||||
use base64::{Engine as _, engine::general_purpose};
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use sha1::Sha1;
|
use sha1::Sha1;
|
||||||
|
@ -7,16 +7,180 @@ use substring::Substring;
|
||||||
use json::object;
|
use json::object;
|
||||||
use hmac::{Hmac, Mac};
|
use hmac::{Hmac, Mac};
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
use crate::encryption;
|
||||||
|
|
||||||
|
use rusqlite::{Connection, params, ToSql};
|
||||||
|
use std::sync::{Mutex, MutexGuard};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use openssl::pkey::PKey;
|
||||||
|
use openssl::rsa::Rsa;
|
||||||
|
use openssl::hash::MessageDigest;
|
||||||
|
use openssl::sign::Verifier;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref ENGINE: Mutex<Option<Connection>> = Mutex::new(None);
|
||||||
|
}
|
||||||
|
fn init(engine: &mut MutexGuard<'_, Option<Connection>>) {
|
||||||
|
let conn = Connection::open("gree.db").unwrap();
|
||||||
|
conn.execute("PRAGMA foreign_keys = ON;", ()).unwrap();
|
||||||
|
|
||||||
|
engine.replace(conn);
|
||||||
|
}
|
||||||
|
fn lock_and_exec(command: &str, args: &[&dyn ToSql]) {
|
||||||
|
loop {
|
||||||
|
match ENGINE.lock() {
|
||||||
|
Ok(mut result) => {
|
||||||
|
if result.is_none() {
|
||||||
|
init(&mut result);
|
||||||
|
}
|
||||||
|
let conn = result.as_ref().unwrap();
|
||||||
|
conn.execute(command, args).unwrap();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(15));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn lock_and_select(command: &str) -> Result<String, rusqlite::Error> {
|
||||||
|
loop {
|
||||||
|
match ENGINE.lock() {
|
||||||
|
Ok(mut result) => {
|
||||||
|
if result.is_none() {
|
||||||
|
init(&mut result);
|
||||||
|
}
|
||||||
|
let conn = result.as_ref().unwrap();
|
||||||
|
let mut stmt = conn.prepare(command).unwrap();
|
||||||
|
return stmt.query_row([], |row| row.get(0));
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(15));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn create_store(test_cmd: &str, table: &str, init_cmd: &str, init_args: &[&dyn ToSql]) {
|
||||||
|
loop {
|
||||||
|
match ENGINE.lock() {
|
||||||
|
Ok(mut result) => {
|
||||||
|
if result.is_none() {
|
||||||
|
init(&mut result);
|
||||||
|
}
|
||||||
|
let conn = result.as_ref().unwrap();
|
||||||
|
match conn.prepare(test_cmd) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_) => {
|
||||||
|
conn.execute(
|
||||||
|
table,
|
||||||
|
(),
|
||||||
|
).unwrap();
|
||||||
|
conn.execute(
|
||||||
|
init_cmd,
|
||||||
|
init_args
|
||||||
|
).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(15));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn get_new_uuid() -> String {
|
||||||
|
create_store("SELECT jsondata FROM uuids", "CREATE TABLE uuids (
|
||||||
|
jsondata TEXT NOT NULL
|
||||||
|
)", "INSERT INTO uuids (jsondata) VALUES (?1)", params!("[]"));
|
||||||
|
let id = format!("{}", Uuid::new_v4());
|
||||||
|
let mut existing_ids = json::parse(&lock_and_select("SELECT jsondata FROM uuids").unwrap()).unwrap();
|
||||||
|
if existing_ids.contains(id.clone()) {
|
||||||
|
return get_new_uuid();
|
||||||
|
}
|
||||||
|
existing_ids.push(id.clone()).unwrap();
|
||||||
|
lock_and_exec(
|
||||||
|
"UPDATE uuids SET jsondata=?1",
|
||||||
|
params!(json::stringify(existing_ids))
|
||||||
|
);
|
||||||
|
|
||||||
|
id
|
||||||
|
}
|
||||||
|
fn create_acc(cert: &str) -> String {
|
||||||
|
let uuid = get_new_uuid();
|
||||||
|
let user = userdata::get_acc(&uuid);
|
||||||
|
let user_id = user["user"]["id"].to_string();
|
||||||
|
lock_and_exec(
|
||||||
|
&format!("CREATE TABLE _{}_ (
|
||||||
|
cert TEXT NOT NULL,
|
||||||
|
uuid TEXT NOT NULL
|
||||||
|
)", user_id),
|
||||||
|
params!(),
|
||||||
|
);
|
||||||
|
|
||||||
|
lock_and_exec(
|
||||||
|
&format!("INSERT INTO _{}_ (cert, uuid) VALUES (?1, ?2)", user_id),
|
||||||
|
params!(cert, uuid)
|
||||||
|
);
|
||||||
|
|
||||||
|
uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify_signature(signature: &[u8], message: &[u8], public_key: &[u8]) -> bool {
|
||||||
|
let rsa_public_key = match Rsa::public_key_from_pem(public_key) {
|
||||||
|
Ok(key) => key,
|
||||||
|
Err(_) => return false,
|
||||||
|
};
|
||||||
|
let pkey = match PKey::from_rsa(rsa_public_key) {
|
||||||
|
Ok(pkey) => pkey,
|
||||||
|
Err(_) => return false,
|
||||||
|
};
|
||||||
|
let mut verifier = Verifier::new(MessageDigest::sha1(), &pkey).unwrap();
|
||||||
|
verifier.update(message).unwrap();
|
||||||
|
|
||||||
|
match verifier.verify(signature) {
|
||||||
|
Ok(_) => true,
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn get_uuid(headers: &HeaderMap, body: &str) -> String {
|
||||||
|
let body = encryption::decrypt_packet(&body).unwrap();
|
||||||
|
let blank_header = HeaderValue::from_static("");
|
||||||
|
let login = headers.get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
|
let uid = headers.get("aoharu-user-id").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
|
let version = headers.get("aoharu-client-version").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
|
let timestamp = headers.get("aoharu-timestamp").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
|
if uid == "" || login == "" || version == "" || timestamp == "" {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
let cert = lock_and_select(&format!("SELECT cert FROM _{}_", uid)).unwrap();
|
||||||
|
|
||||||
|
let data = format!("{}{}{}{}{}", uid, "sk1bdzb310n0s9tl", version, timestamp, body);
|
||||||
|
let encoded = general_purpose::STANDARD.encode(data.as_bytes());
|
||||||
|
|
||||||
|
let decoded = general_purpose::STANDARD.decode(login).unwrap_or(vec![]);
|
||||||
|
|
||||||
|
if verify_signature(&decoded, &encoded.as_bytes(), &cert.as_bytes()) {
|
||||||
|
return lock_and_select(&format!("SELECT uuid FROM _{}_", uid)).unwrap();
|
||||||
|
} else {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let body = json::parse(&body).unwrap();
|
||||||
|
let token = create_acc(&body["token"].to_string());
|
||||||
|
|
||||||
pub fn initialize(req: HttpRequest, _body: String) -> HttpResponse {
|
|
||||||
//println!("{}", body);
|
|
||||||
let app_id = "232610769078541";
|
let app_id = "232610769078541";
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
result: "OK",
|
result: "OK",
|
||||||
app_id: app_id,
|
app_id: app_id,
|
||||||
uuid: format!("{}{:x}", app_id, md5::compute((global::timestamp() * 1000).to_string()))
|
uuid: token
|
||||||
};
|
};
|
||||||
println!("{}", resp["uuid"].to_string());
|
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.insert_header(ContentType::json())
|
.insert_header(ContentType::json())
|
||||||
|
@ -29,7 +193,6 @@ pub fn initialize(req: HttpRequest, _body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn authorize(req: HttpRequest, _body: String) -> HttpResponse {
|
pub fn authorize(req: HttpRequest, _body: String) -> HttpResponse {
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
result: "OK"
|
result: "OK"
|
||||||
};
|
};
|
||||||
|
@ -44,7 +207,6 @@ pub fn authorize(req: HttpRequest, _body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn moderate_keyword(req: HttpRequest) -> HttpResponse {
|
pub fn moderate_keyword(req: HttpRequest) -> HttpResponse {
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
result: "OK",
|
result: "OK",
|
||||||
entry: {
|
entry: {
|
||||||
|
@ -63,7 +225,6 @@ pub fn moderate_keyword(req: HttpRequest) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uid(req: HttpRequest) -> HttpResponse {
|
pub fn uid(req: HttpRequest) -> HttpResponse {
|
||||||
let app_id = "232610769078541";
|
|
||||||
|
|
||||||
let mut uid = String::new();
|
let mut uid = String::new();
|
||||||
let blank_header = HeaderValue::from_static("");
|
let blank_header = HeaderValue::from_static("");
|
||||||
|
@ -75,10 +236,10 @@ pub fn uid(req: HttpRequest) -> HttpResponse {
|
||||||
uid = uid_str.to_string();
|
uid = uid_str.to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//println!("{}", auth_header);
|
//println!("{}", uid);
|
||||||
|
|
||||||
let key = uid.substring(app_id.len(), uid.len());
|
let user = userdata::get_acc(&uid);
|
||||||
let user = userdata::get_acc(&key);
|
//println!("{}", user["user"]["id"].to_string());
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
result: "OK",
|
result: "OK",
|
||||||
|
|
|
@ -6,8 +6,8 @@ use actix_web::{HttpResponse, HttpRequest};
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
|
||||||
pub fn preset(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn preset(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let mut user = userdata::get_acc_home(&key);
|
let mut user = userdata::get_acc_home(&key);
|
||||||
|
|
||||||
for (_i, data) in user["home"]["preset_setting"].members_mut().enumerate() {
|
for (_i, data) in user["home"]["preset_setting"].members_mut().enumerate() {
|
||||||
|
@ -26,7 +26,7 @@ pub fn preset(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn preset_get(req: HttpRequest) -> HttpResponse {
|
pub fn preset_get(req: HttpRequest) -> HttpResponse {
|
||||||
let key = global::get_login(req.headers());
|
let key = global::get_login(req.headers(), "");
|
||||||
let user = userdata::get_acc(&key);
|
let user = userdata::get_acc(&key);
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
|
@ -42,7 +42,10 @@ pub fn preset_get(req: HttpRequest) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn home(req: HttpRequest) -> HttpResponse {
|
pub fn home(req: HttpRequest) -> HttpResponse {
|
||||||
let key = global::get_login(req.headers());
|
for (name, value) in req.headers().iter() {
|
||||||
|
println!("{}: {}", name, value.to_str().unwrap());
|
||||||
|
}
|
||||||
|
let key = global::get_login(req.headers(), "");
|
||||||
let user = userdata::get_acc_home(&key);
|
let user = userdata::get_acc_home(&key);
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
|
|
|
@ -83,8 +83,8 @@ pub fn update_live_data(user: &mut JsonValue, data: &JsonValue) -> JsonValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn end(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn end(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let user2 = userdata::get_acc_home(&key);
|
let user2 = userdata::get_acc_home(&key);
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ use actix_web::{HttpResponse, HttpRequest};
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
|
||||||
//First time login handler
|
//First time login handler
|
||||||
pub fn dummy(req: HttpRequest, _body: String) -> HttpResponse {
|
pub fn dummy(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
//let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
//let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
let key = global::get_login(req.headers());
|
let key = global::get_login(req.headers(), &body);
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
user["user"]["last_login_time"] = global::timestamp().into();
|
user["user"]["last_login_time"] = global::timestamp().into();
|
||||||
|
@ -25,9 +25,9 @@ pub fn dummy(req: HttpRequest, _body: String) -> HttpResponse {
|
||||||
global::send(resp)
|
global::send(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bonus(req: HttpRequest, _body: String) -> HttpResponse {
|
pub fn bonus(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
//let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
//let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
let key = global::get_login(req.headers());
|
let key = global::get_login(req.headers(), &body);
|
||||||
let user = userdata::get_acc_home(&key);
|
let user = userdata::get_acc_home(&key);
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
|
|
|
@ -100,9 +100,9 @@ pub fn lottery(_req: HttpRequest) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
println!("lottery: {}", body);
|
println!("lottery: {}", body);
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
let user2 = userdata::get_acc(&key);
|
let user2 = userdata::get_acc(&key);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use json;
|
||||||
use json::object;
|
use json::object;
|
||||||
use crate::router::global;
|
use crate::router::global;
|
||||||
use actix_web::{HttpResponse, HttpRequest};
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
use crate::router::userdata;
|
//use crate::router::userdata;
|
||||||
|
|
||||||
pub fn mission(_req: HttpRequest) -> HttpResponse {
|
pub fn mission(_req: HttpRequest) -> HttpResponse {
|
||||||
//let key = global::get_login(req.headers());
|
//let key = global::get_login(req.headers());
|
||||||
|
|
|
@ -40,12 +40,13 @@ pub fn asset_hash(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn start(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
if body["asset_version"].to_string() != global::ASSET_VERSION && body["asset_version"].to_string() != global::ASSET_VERSION_JP {
|
if body["asset_version"].to_string() != global::ASSET_VERSION && body["asset_version"].to_string() != global::ASSET_VERSION_JP {
|
||||||
println!("Warning! Asset version is not what was expected. (Did the app update?)");
|
println!("Warning! Asset version is not what was expected. (Did the app update?)");
|
||||||
}
|
}
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
|
//println!("{} - {}", key, user["user"]["id"].to_string());
|
||||||
|
|
||||||
user["user"]["last_login_time"] = global::timestamp().into();
|
user["user"]["last_login_time"] = global::timestamp().into();
|
||||||
user["stamina"]["last_updated_time"] = global::timestamp().into();
|
user["stamina"]["last_updated_time"] = global::timestamp().into();
|
||||||
|
|
|
@ -6,8 +6,8 @@ use actix_web::{HttpResponse, HttpRequest};
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
|
||||||
pub fn tutorial(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn tutorial(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
user["tutorial_step"] = body["step"].clone();
|
user["tutorial_step"] = body["step"].clone();
|
||||||
|
|
|
@ -6,9 +6,8 @@ use actix_web::{HttpResponse, HttpRequest};
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
|
||||||
pub fn deck(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn deck(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
|
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
for (i, data) in user["deck_list"].members().enumerate() {
|
for (i, data) in user["deck_list"].members().enumerate() {
|
||||||
|
@ -35,8 +34,7 @@ pub fn deck(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user(req: HttpRequest) -> HttpResponse {
|
pub fn user(req: HttpRequest) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), "");
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let user = userdata::get_acc(&key);
|
let user = userdata::get_acc(&key);
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
|
@ -48,9 +46,9 @@ pub fn user(req: HttpRequest) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_post(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn user_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
|
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
let user_2 = userdata::get_acc_home(&key);
|
let user_2 = userdata::get_acc_home(&key);
|
||||||
|
|
||||||
|
@ -125,8 +123,8 @@ pub fn get_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_password(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn register_password(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
|
|
||||||
let user = userdata::get_acc(&key);
|
let user = userdata::get_acc(&key);
|
||||||
let code = uid_to_code(user["user"]["id"].to_string());
|
let code = uid_to_code(user["user"]["id"].to_string());
|
||||||
|
@ -212,9 +210,9 @@ pub fn migration(_req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
|
||||||
|
|
||||||
pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
|
|
||||||
let key = global::get_login(req.headers());
|
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
let mut user2 = userdata::get_acc_home(&key);
|
let mut user2 = userdata::get_acc_home(&key);
|
||||||
let ur = user["card_list"][user["card_list"].len() - 1]["master_card_id"].clone();
|
let ur = user["card_list"][user["card_list"].len() - 1]["master_card_id"].clone();
|
||||||
|
|
Loading…
Add table
Reference in a new issue