Added AES and structured stuff for BasicInfo

This commit is contained in:
caret 2023-05-29 00:54:35 -05:00
parent fdd36fc42e
commit 59ff696184
2 changed files with 61 additions and 9 deletions

View File

@ -14,4 +14,7 @@ mime = "0.3.16"
openssl = "0.10.52"
rustls = "0.20.8"
rustls-pemfile = "1.0.2"
serde = {version = "1.0.152", features = ["derive"]}
aes = "0.8.2"
cfb-mode = "0.8.2"
serde = {version="1.0.163",features = ['derive']}
serde_json = {version = "1.0.96", features = ['std']}

View File

@ -5,13 +5,25 @@
#![allow(dead_code)]
#![allow(unused_imports)]
use actix_web::{get, http::header::ContentType, post, web, App, HttpRequest, HttpResponse, HttpServer};
use aes::cipher::{AsyncStreamCipher, KeyIvInit};
use log::{debug, error, info, log_enabled, Level};
use rustls::{Certificate, PrivateKey, ServerConfig};
use rustls_pemfile::{certs, pkcs8_private_keys};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::fs::File;
use std::io::BufReader;
type Aes128CfbEnc = cfb_mode::Encryptor<aes::Aes128>;
struct BasicInfo {
BaseUrl: String,
DownloadUrl: String,
Key: String,
Iv: String,
TenpoIndex: u8,
}
#[macro_export]
macro_rules! resp {
($str:expr) => {
@ -19,6 +31,24 @@ 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 {
resp!("")
@ -67,28 +97,47 @@ x-img=https://static.wikia.nocookie.net/houkai-star-rail/images/1/18/Character_M
x-ranking=http://10.3.0.53/ranking/ranking.php
ticket=9251859b560b33b031516d05c2ef3c28"
);
HttpResponse::Ok().append_header(ContentType(mime::TEXT_PLAIN)).append_header(ContentType(mime::TEXT_PLAIN)).body(res)
resp!(res)
}
#[get("/server/data.php")]
async fn server_data() -> HttpResponse {
HttpResponse::Ok().append_header(ContentType(mime::TEXT_PLAIN)).body("count=0\nnexttime=0\n")
resp!("count=0\nnexttime=0\n")
}
#[post("/basicinfo")]
async fn basicinfo() -> HttpResponse {
HttpResponse::Ok().append_header(ContentType(mime::TEXT_PLAIN)).body("Harder to do")
// Encrypt or something first...
// Very possible PGP is needed I think/? or aes portion ... idk
resp!("Harder to do")
}
async fn index(req: actix_web::HttpRequest) -> HttpResponse {
println!("~");
//println!("Method: {:?}", req.method());
//println!("Host: {:?}", req.head().uri.host());
//println!("Path: {:?}", req.path());
println!("---");
println!("Method: {:?}", req.method());
println!("Host: {:?}", req.head().uri.host());
println!("Path: {:?}", req.path());
dbg!(&req);
HttpResponse::Ok().append_header(ContentType(mime::TEXT_PLAIN)).body("shit")
}
fn _aes_encrypt(_plaintext: String) {
// Create an instance of your JSON object
let data: MyData = MyData { name: "Alice".to_string(), age: 30 };
let plaintext: String = serde_json::to_string(&data).unwrap();
dbg!(&plaintext);
// 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);
// Print
print_valid_chars!(ciphertext.iter());
}
fn load_rustls_config() -> rustls::ServerConfig {
// init server config builder with safe defaults
let config = ServerConfig::builder().with_safe_defaults().with_no_client_auth();