I hate encryption
This commit is contained in:
24
src/encryption.rs
Normal file
24
src/encryption.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use openssl::symm::{Cipher, Crypter, Mode};
|
||||
use openssl::error::ErrorStack;
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
|
||||
const IV_LENGTH: usize = 16;
|
||||
const KEY: &str = "3559b435f24b297a79c68b9709ef2125";
|
||||
|
||||
pub fn decrypt_packet(base64_input: &str) -> Result<String, ErrorStack> {
|
||||
let base64_buffer = general_purpose::STANDARD.decode(base64_input).unwrap();
|
||||
|
||||
let decryption_iv = &base64_buffer[..IV_LENGTH];
|
||||
let ciphertext = &base64_buffer[IV_LENGTH..];
|
||||
|
||||
let cipher = Cipher::aes_256_cbc();
|
||||
let mut decrypter = Crypter::new(cipher, Mode::Decrypt, KEY.as_bytes(), Some(decryption_iv))?;
|
||||
|
||||
let mut decrypted_data = vec![0u8; ciphertext.len() + cipher.block_size()];
|
||||
let mut decrypted_len = decrypter.update(ciphertext, &mut decrypted_data)?;
|
||||
decrypted_len += decrypter.finalize(&mut decrypted_data[decrypted_len..])?;
|
||||
|
||||
decrypted_data.truncate(decrypted_len);
|
||||
|
||||
Ok(String::from_utf8(decrypted_data).unwrap())
|
||||
}
|
101
src/main.rs
Normal file
101
src/main.rs
Normal file
@ -0,0 +1,101 @@
|
||||
mod encryption;
|
||||
use actix_web::{
|
||||
// post,
|
||||
// get,
|
||||
HttpResponse,
|
||||
HttpRequest,
|
||||
http::header::HeaderMap,
|
||||
web,
|
||||
dev::Service
|
||||
};
|
||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||
|
||||
async fn make_post_request(url: &str, body: &str, headers: &HeaderMap) -> Result<String, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let mut response = client
|
||||
.post(url)
|
||||
.body(body.to_string());
|
||||
|
||||
for (name, value) in headers.iter() {
|
||||
if name == "Accept-Encoding" {continue;};
|
||||
if name == "host" {
|
||||
response = response.header("host", "api.app.lovelive-sif2.bushimo.jp");
|
||||
continue;
|
||||
};
|
||||
response = response.header(name, value.to_str().unwrap());
|
||||
}
|
||||
|
||||
let response_body = response.send().await?.text().await?;
|
||||
|
||||
Ok(response_body)
|
||||
}
|
||||
|
||||
async fn make_get_request(url: &str, headers: &HeaderMap) -> Result<String, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let mut response = client.get(url);
|
||||
for (name, value) in headers.iter() {
|
||||
if name == "Accept-Encoding" {continue;};
|
||||
if name == "host" {
|
||||
response = response.header("host", "api.app.lovelive-sif2.bushimo.jp");
|
||||
continue;
|
||||
};
|
||||
response = response.header(name, value.to_str().unwrap());
|
||||
}
|
||||
let response_body = response.send().await?.text().await?;
|
||||
Ok(response_body)
|
||||
}
|
||||
|
||||
async fn log_unknown_request(req: HttpRequest, body: String) -> HttpResponse {
|
||||
if body != String::new() {
|
||||
println!("req: {}", encryption::decrypt_packet(&body).unwrap_or(String::new()));
|
||||
let resp = make_post_request(&format!("https://api.app.lovelive-sif2.bushimo.jp{}", req.path()), &body, req.headers()).await.unwrap();
|
||||
|
||||
//println!("Unhandled request: {} {}", req.path(), body);
|
||||
println!("resp: {}", encryption::decrypt_packet(&resp).unwrap_or(String::new()));
|
||||
HttpResponse::Ok().body(resp)
|
||||
} else {
|
||||
let resp = make_get_request(&format!("https://api.app.lovelive-sif2.bushimo.jp{}", req.path()), req.headers()).await.unwrap();
|
||||
|
||||
//println!("Unhandled request: {} {}", req.path(), body);
|
||||
println!("resp: {}", encryption::decrypt_packet(&resp).unwrap_or(String::new()));
|
||||
HttpResponse::Ok().body(resp)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
use actix_web::{App, HttpServer};
|
||||
|
||||
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
|
||||
builder
|
||||
.set_private_key_file("key.pem", SslFiletype::PEM)
|
||||
.unwrap();
|
||||
builder.set_certificate_chain_file("cert.pem").unwrap();
|
||||
|
||||
let rv = HttpServer::new(|| App::new()
|
||||
.wrap_fn(|req, srv| {
|
||||
println!("Request: {}", req.path());
|
||||
srv.call(req)
|
||||
})
|
||||
.default_service(web::route().to(log_unknown_request)))
|
||||
.bind_openssl("0.0.0.0:8080", builder)?
|
||||
.run();
|
||||
println!("Server started: http://127.0.0.1:{}", 8080);
|
||||
rv.await
|
||||
}
|
||||
/*
|
||||
fn main() {
|
||||
let base64_input = "MX2tzmKTxY7EsV46rYFZuAfxeY0tPHuZ0etG15WsK1MAzs/U0WUXE4bJZINrEvCxqqUbvCYxhDtXp3HoeH/zDXtnW183aF/aYycmUW3aAF6zyio4/PJoqFl7EGET37ruotoQ9Teof2PXpXraF94diw==";
|
||||
match decrypt_packet(base64_input) {
|
||||
Ok(decrypted_json) => {
|
||||
// Process the decrypted JSON
|
||||
println!("Decrypted JSON: {}", decrypted_json);
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error decrypting packet: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
Reference in New Issue
Block a user