Remove need for ssl

This commit is contained in:
Ethan O'Brien
2024-02-22 17:17:12 -06:00
parent 163f5956a1
commit 410aae9bd1
3 changed files with 4 additions and 92 deletions

View File

@ -8,7 +8,6 @@ use actix_web::{
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();
@ -19,7 +18,7 @@ async fn make_post_request(url: &str, body: &str, headers: &HeaderMap) -> Result
for (name, value) in headers.iter() {
if name == "Accept-Encoding" {continue;};
if name == "host" {
response = response.header("host", "api.app.lovelive-sif2.bushimo.jp");
response = response.header("host", "api-sif2.lovelive-sif2.com");
continue;
};
response = response.header(name, value.to_str().unwrap());
@ -48,13 +47,13 @@ async fn make_get_request(url: &str, headers: &HeaderMap) -> Result<String, reqw
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();
let resp = make_post_request(&format!("https://api-sif2.lovelive-sif2.com{}", 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();
let resp = make_get_request(&format!("https://api-sif2.lovelive-sif2.com{}", req.path()), req.headers()).await.unwrap();
//println!("Unhandled request: {} {}", req.path(), body);
println!("resp: {}", encryption::decrypt_packet(&resp).unwrap_or(String::new()));
@ -67,19 +66,13 @@ async fn log_unknown_request(req: HttpRequest, body: String) -> HttpResponse {
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)?
.bind(("0.0.0.0", 8080))?
.run();
println!("Server started: http://127.0.0.1:{}", 8080);
rv.await