From 8ff3d9dac2c5976b64dc6a8f49802410c7f3f335 Mon Sep 17 00:00:00 2001 From: caret Date: Thu, 1 Jun 2023 23:07:53 -0500 Subject: [PATCH] cert issues still --- Cargo.toml | 2 + certs/install.ps1 | 18 ++++++++ priv.pem | 28 ++++++++++++ src/main.rs | 106 ++++++++++++++++++++++++---------------------- 4 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 certs/install.ps1 create mode 100644 priv.pem diff --git a/Cargo.toml b/Cargo.toml index 6fb9b16..865f3a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,5 @@ aes = "0.8.2" cfb-mode = "0.8.2" serde = {version="1.0.163",features = ['derive']} serde_json = {version = "1.0.96", features = ['std']} +#rsa = "0.9.2" +rand = "0.8.5" diff --git a/certs/install.ps1 b/certs/install.ps1 new file mode 100644 index 0000000..c4c4c37 --- /dev/null +++ b/certs/install.ps1 @@ -0,0 +1,18 @@ +$certPath = "C:\Path\to\Certificates" # Specify the path where your .crt certificates are located + +$certFiles = Get-ChildItem -Path $certPath -Filter *.crt + +$certStore = Get-Item -Path "Cert:\LocalMachine\Root" + +foreach ($certFile in $certFiles) { + $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 + $cert.Import($certFile.FullName) + + if (!$certStore.Contains($cert)) { + $certStore.Add($cert) + Write-Host "Certificate $($cert.Subject) imported successfully." + } else { + Write-Host "Certificate $($cert.Subject) already exists in the store." + } +} + diff --git a/priv.pem b/priv.pem new file mode 100644 index 0000000..6b819ec --- /dev/null +++ b/priv.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDLrefJsODZ3SXk +SblFOzHRAnhaG5PgPCvMkP9J08Ns6i1cTkGJXJx83Fx9dVJrvhK+pOHJCzgpqxnI +r81Yk3pfKLs1CCHbEphzd5WPxvwxKSHPljvrfV2xwtBFH2wOJN/b6NHy6Z3pT2in +9m5xo5T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4LTXrXhbsDsdZqpAoGBAJtX +/EU/UYeHY7MTceLesV0Dg5Hj2HQyLZMDGsFQeZBYpYPmuo9NdiR/LGSwRj6GsFdc +lXv1yxgqkIuD1/+mV78JWn259xavliXQsrSpIV74YEpuGoF8b1WbzRCcUU/6zo+l +PRiRMAl4gWCpQwSzmVGSnj1RJ3rmFZWfh2e/CB41AoGBAMKnczJq3cqd2Rzm6N+Q +0uZgVjN+GKEZX+KGZd535tPnZ9NqHxbYXcpu/XzbykRHwqmH9CbW0C/+JnOHqGT9 ++qbmf/FcIAHHSA3HDXOyGM1lHUXUcPfGhPJ1GD3IBqNeNWjY0aSAYxR2pRX3Bb+4 +AIlPFSOu7jYSw5+prAXZxmm7 +-----END PRIVATE KEY----- diff --git a/src/main.rs b/src/main.rs index 4b9ad94..7385e72 100755 --- a/src/main.rs +++ b/src/main.rs @@ -13,40 +13,46 @@ use rustls_pemfile::{certs, pkcs8_private_keys}; use serde::{Deserialize, Serialize}; use std::fs::File; use std::io::BufReader; +use std::io::Read; +use openssl::rsa::{Padding, Rsa}; type Aes128CfbEnc = cfb_mode::Encryptor; -#[derive(Serialize, Deserialize)] -struct BasicInfo { - BaseUrl: String, - DownloadUrl: String, - Key: String, - Iv: String, - TenpoIndex: u16, -} +//use rsa::pkcs8::DecodePublicKey; +//use rsa::{Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey}; #[post("/basicinfo")] async fn basicinfo() -> HttpResponse { - // Encrypt or something first... - // Very possible PGP is needed I think/? or aes portion ... idk - let data: BasicInfo = BasicInfo { - BaseUrl: "http://10.3.0.53/game/info".to_string(), - DownloadUrl: "http://10.3.0.53/download".to_string(), - Key: "0123456789012345".to_string(), - Iv: "0123456789012345".to_string(), - TenpoIndex: 1337u16, - }; - let plaintext: String = serde_json::to_string(&data).unwrap(); + /* + let pem = "-----BEGIN PUBLIC KEY----- + MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy63nybDg2d0l5Em5RTsx + 0QJ4WhuT4DwrzJD/SdPDbOotXE5BiVycfNxcfXVSa74SvqThyQs4KasZyK/NWJN6 + Xyi7NQgh2xKYc3eVj8b8MSkhz5Y7631dscLQRR9sDiTf2+jR8umd6U9op/ZucaOU + zaEcyHalryeeRwD8q7mtlBccL+5dSVVWuPaJ/Oh4Oivk4qNunYHygQ/iw2vBgN3f + 6tB1yiKlUe0T51FS1yJcavWilp2JA6XGEhh0OmFJX6wf5vPu9heTXGqnriClinXn + XV1zUPDaa0udD8n2OV9NphozqD7TT4pE68G65Xz/iLAaEudSg7f1Shu+VFtt/cF4 + NwIDAQAB + -----END PUBLIC KEY-----"; + */ + let mut key_file = File::open("priv.pem").unwrap(); - // Crypto constants - let key: &[u8] = "0123456789012345".as_bytes(); - let iv: &[u8] = "0123456789012345".as_bytes(); + let mut key_buffer = Vec::new(); + key_file.read_to_end(&mut key_buffer).unwrap(); - // Encrypt - let mut ciphertext = plaintext.as_bytes().to_vec(); - Aes128CfbEnc::new(key.into(), iv.into()).encrypt(&mut ciphertext); + // Load the private key from the PEM data + let rsa = Rsa::private_key_from_pem(&key_buffer).unwrap(); - print_valid_chars!(ciphertext.iter()); + let plaintext = r#" + {'result':200,'response':{'base_url':'http://10.3.0.53/game/info','download_url':'http://10.3.0.53/download','key':'01234567890123456789012345678901','iv':'0123456789012345','tenpo_index':1337}} + "#; + let mut ciphertext = vec![0; rsa.size() as usize]; + rsa.public_encrypt(plaintext.as_bytes(), &mut ciphertext, Padding::PKCS1).unwrap(); + + println!("{:?}", String::from_utf8_lossy(&ciphertext)); + + //let mut rng = rand::thread_rng(); + //let pub_key = RsaPublicKey::from_public_key_pem(pem).unwrap(); + //let ciphertext = pub_key.encrypt(&mut rng, Pkcs1v15Encrypt, &plaintext.as_bytes()).expect("failed to encrypt"); HttpResponse::Ok().append_header(ContentType::octet_stream()).body(ciphertext) } @@ -57,26 +63,9 @@ macro_rules! resp { }; } -#[macro_export] -macro_rules! print_valid_chars { - ($slice:expr) => {{ - print!("{{{{"); - let mut valid_chars = String::new(); - for &byte in $slice { - if let Ok(chr) = std::str::from_utf8(&[byte]) { - if chr.is_ascii() && &byte >= &32 { - valid_chars.push_str(chr); - } - } else { - valid_chars.push_str("."); - } - } - println!("{}}}}}", valid_chars); - }}; -} - -#[get("/alive/303807/Alive.txt")] -async fn alive() -> HttpResponse { +#[get("/alive/{id}/Alive.txt")] +async fn alive(id: web::Path) -> HttpResponse { + println!("/alive/{}/Alive.txt", id); resp!("") } @@ -109,7 +98,22 @@ async fn cursel() -> HttpResponse { async fn gameinfo() -> HttpResponse { resp!("0\n3\n301000,test1\n302000,test2\n303000,test3\n") } +#[post("/game/info")] +async fn game_info() -> HttpResponse { + // JSON type that is AES encrypted + let plaintext = r#"{"result":200,"response":{"base_url":"http://10.3.0.53/game/next","information":[],"event_information":[],"encore_expiration_date":"2033-05-27"}}"#; + // Crypto constants + let key: &[u8] = "0123456789012345".as_bytes(); + let iv: &[u8] = "0123456789012345".as_bytes(); + + // Encrypt + let mut ciphertext = plaintext.as_bytes().to_vec(); + Aes128CfbEnc::new(key.into(), iv.into()).encrypt(&mut ciphertext); + + //println!("{:?}", String::from_utf8_lossy(&ciphertext)); + HttpResponse::Ok().append_header(ContentType::octet_stream()).body(ciphertext) +} #[get("/server/certify.php")] async fn certify() -> HttpResponse { let res = format!( @@ -119,7 +123,7 @@ name=LLServer pref=nesys addr=Local x-next-time=15 -x-img=https://static.wikia.nocookie.net/houkai-star-rail/images/1/18/Character_March_7th_Splash_Art.png +x-img=http://10.3.0.53/test.png x-ranking=http://10.3.0.53/ranking/ranking.php ticket=9251859b560b33b031516d05c2ef3c28" ); @@ -136,7 +140,7 @@ async fn index(req: actix_web::HttpRequest) -> HttpResponse { println!("Method: {:?}", req.method()); println!("Host: {:?}", req.head().uri.host()); println!("Path: {:?}", req.path()); - dbg!(&req); + //dbg!(&req); HttpResponse::Ok().append_header(ContentType(mime::TEXT_PLAIN)).body("shit") } @@ -163,9 +167,10 @@ fn load_rustls_config() -> rustls::ServerConfig { #[actix_web::main] async fn main() -> std::io::Result<()> { - env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + //env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug")); let config = load_rustls_config(); info!("Certificates loaded."); + println!("Started!"); HttpServer::new(|| { App::new() .service(alive) @@ -175,13 +180,14 @@ async fn main() -> std::io::Result<()> { .service(fire_alert) .service(cursel) .service(gameinfo) + .service(game_info) .service(certify) .service(server_data) .service(basicinfo) .route("{path:.*}", web::get().to(index)) }) - .bind("127.0.0.1:80")? - .bind("127.0.0.1:5107")? + .bind("0.0.0.0:80")? + .bind("0.0.0.0:5107")? .bind_rustls("0.0.0.0:443", config)? .run() .await