From d5d8aa455ecea10efc828bfc478a3b86b2a3f83b Mon Sep 17 00:00:00 2001 From: 641i130 <46945263+641i130@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:36:07 -0500 Subject: [PATCH] One step away --- src/main.rs | 17 +++++++++++++++++ src/routes/card_routes.rs | 4 +--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1a5d63c..e10999b 100755 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,22 @@ macro_rules! resp { }; } +#[post("/basicinfo/")] +async fn basicinfo_e() -> HttpResponse { + // This function is technically decrypting the plaintext into cipher text for the client to + // encrypt to read it. It's very backwards, but this is how the game works. I hate it. + let mut key_file = File::open("private_key.pem").unwrap(); + let mut key_buffer = Vec::new(); + key_file.read_to_end(&mut key_buffer).unwrap(); + // Load the private key from the PEM data + let rsa = Rsa::private_key_from_pem(&key_buffer).unwrap(); + let plaintext = r#"{"result":200,"response":{"base_url":"http://data.nesys.jp/game","download_url":"http://data.nesys.jp/download","key":"01234567890123456789012345678901","iv":"0123456789012345","tenpo_index":1337}}"#; + let mut ciphertext = vec![0; rsa.size() as usize]; + rsa.private_encrypt(plaintext.as_bytes(), &mut ciphertext, Padding::PKCS1).unwrap(); + println!("{}",format!("RSA Public Encrypt").bold().red()); + println!("{}",format!("{}", plaintext).bold().yellow()); + HttpResponse::Ok().append_header(ContentType::octet_stream()).body(ciphertext) +} #[post("/basicinfo")] async fn basicinfo() -> HttpResponse { @@ -195,6 +211,7 @@ async fn main() -> std::io::Result<()> { .service(certify) .service(server_data) .service(basicinfo) + .service(basicinfo_e) .service(cardn) //.service(web::resource("/*").route(web::post().to(handle_post_request))) .route("{path:.*}",web::post().to(handle_post_request)) diff --git a/src/routes/card_routes.rs b/src/routes/card_routes.rs index 7aa0b78..edadd1e 100644 --- a/src/routes/card_routes.rs +++ b/src/routes/card_routes.rs @@ -2,6 +2,7 @@ use colored::Colorize; use actix_web::{web, HttpResponse, dev::Service, dev::ServiceRequest, dev::ServiceResponse, Error, Result, get, http::header::ContentType, post, App, HttpRequest, HttpServer}; // AES use crate::cry::aes::{aes_en, aes_dec}; +use serde::Deserialize; macro_rules! resp { ($str:expr) => { @@ -9,10 +10,7 @@ macro_rules! resp { HttpResponse::Ok().append_header(ContentType::octet_stream()).body($str) }; } - /////////////////////////////////////////////////////////////////////////////////////////// -use serde::Deserialize; - // Card Command Codes #[derive(Debug, Deserialize)]