diff --git a/src/main.rs b/src/main.rs index aa93919..866d216 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,9 +7,11 @@ use crate::sql::sql::initialize_db; use crate::sql::sql::print_users; use crate::util::crypto_helper::load_public_key; use crate::util::crypto_helper::load_secret_key; +use crate::util::logger::PrintType; use crate::util::logger::startup; use dotenv::dotenv; use once_cell::sync::Lazy; +use rustls::crypto::aws_lc_rs::default_provider; use std::env; static PRIVATE_KEY: Lazy = Lazy::new(|| env::var("PRIVATE_KEY").unwrap()); @@ -23,13 +25,20 @@ pub fn get_public_key() -> x448::PublicKey { #[tokio::main] async fn main() { + if let Err(_) = default_provider().install_default() { + println!("Error loading Provider"); + return; + } dotenv().ok(); startup(); log_in!("Incoming messages"); log_out!("Outgoing messages"); tokio::spawn(async move { - let _ = omikron_connection::start(9187).await; + match omikron_connection::start(9187).await { + Err(e) => log_err!(0, PrintType::General, "{:?}", e), + _ => {} + } }); log!("Started"); diff --git a/src/server/omikron_connection.rs b/src/server/omikron_connection.rs old mode 100755 new mode 100644 index 0a7fa87..0b200a8 --- a/src/server/omikron_connection.rs +++ b/src/server/omikron_connection.rs @@ -6,22 +6,14 @@ use crate::{ sql::{self, get_by_user_id, get_by_username, get_iota_by_id, get_omikron_by_id}, user_online_tracker::{self}, }, - util::{ - crypto_helper::encrypt, - file_util::{load_file_buf, load_file_vec}, - logger::PrintType, - }, + util::{crypto_helper::encrypt, file_util::load_file_vec, logger::PrintType}, }; use base64::{Engine as _, engine::general_purpose::STANDARD}; use dashmap::DashMap; use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; use epsilon_native::{Host, Receiver, Sender}; -use quinn::crypto::rustls::QuicServerConfig; -use quinn::{Endpoint, ServerConfig}; use rand::{Rng, distributions::Alphanumeric}; -use rustls::{ServerConfig as CryptoConfig, crypto::aws_lc_rs}; use std::{ - net::SocketAddr, sync::Arc, time::{Duration, Instant}, }; @@ -1090,12 +1082,6 @@ impl OmikronConnection { } } - fn arc_self(self: Arc) -> Arc { - // This is a bit of a hack - in practice you'd store the Arc in the struct - // or use weak references. For now, we rely on the caller having the Arc. - panic!("Use the Arc directly") - } - // Public API for external use pub async fn is_authenticated(self: Arc) -> bool { self.state.read().await.is_authenticated() @@ -1115,7 +1101,10 @@ impl OmikronConnection { // ============================================================================ pub async fn start(port: u16) -> Result<(), Box> { - let _ = aws_lc_rs::default_provider().install_default(); + let cert_pem = load_file_vec("certs", "cert.pem") + .map_err(|e| format!("Failed to load certificate: {}", e))?; + let key_pem = load_file_vec("certs", "key.pem") + .map_err(|e| format!("Failed to load private key: {}", e))?; let cert_pem = load_file_vec("certs", "cert.pem").expect("Error loading Pemfile");