Add authentication layer

This commit is contained in:
2024-06-29 14:43:56 +02:00
parent 738c53c8b9
commit e1739d9818
26 changed files with 1038 additions and 90 deletions

View File

@ -0,0 +1,2 @@
pub mod unsecure_pki_controller;
pub mod unsecure_server_controller;

View File

@ -0,0 +1,32 @@
use crate::app_config::AppConfig;
use crate::server::custom_error::HttpResult;
use actix_web::{web, HttpResponse};
#[derive(serde::Deserialize)]
pub struct ServeCRLPath {
file: String,
}
/// Serve PKI files (unsecure server)
pub async fn serve_pki_file(path: web::Path<ServeCRLPath>) -> HttpResult {
for f in std::fs::read_dir(AppConfig::get().pki_path())? {
let f = f?;
let file_name = f.file_name().to_string_lossy().to_string();
if !file_name.ends_with(".crl") && !file_name.ends_with(".pem") {
continue;
}
if file_name != path.file {
continue;
}
let crl = std::fs::read(f.path())?;
return Ok(HttpResponse::Ok()
.content_type("application/x-pem-file")
.body(crl));
}
Ok(HttpResponse::NotFound()
.content_type("text/plain")
.body("file not found!"))
}

View File

@ -0,0 +1,7 @@
use actix_web::HttpResponse;
pub async fn unsecure_home() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/plain")
.body("SolarEnergy unsecure central backend")
}