From fa139208a2fefa57c99a591e8b0589bf72324f4a Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Sat, 8 Nov 2025 15:24:48 +0800 Subject: [PATCH] awa --- dns/src/gurt_server.rs | 4 ++-- dns/src/gurt_server/ca.rs | 8 ++++---- dns/src/gurt_server/routes.rs | 13 ++++--------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/dns/src/gurt_server.rs b/dns/src/gurt_server.rs index 412bef0..2bab031 100644 --- a/dns/src/gurt_server.rs +++ b/dns/src/gurt_server.rs @@ -19,12 +19,12 @@ impl warp::reject::Reject for CertificateError {} #[derive(Clone)] pub(crate) struct AppState { config: Config, - db: sqlx::PgPool, + db: sqlx::MySqlPool, jwt_secret: String, } impl AppState { - pub fn new(config: Config, db: sqlx::PgPool, jwt_secret: String) -> Self { + pub fn new(config: Config, db: sqlx::MySqlPool, jwt_secret: String) -> Self { Self { config, db, diff --git a/dns/src/gurt_server/ca.rs b/dns/src/gurt_server/ca.rs index 2ceca5b..e8df319 100644 --- a/dns/src/gurt_server/ca.rs +++ b/dns/src/gurt_server/ca.rs @@ -1,13 +1,13 @@ use crate::crypto; use anyhow::Result; -use sqlx::PgPool; +use sqlx::MySqlPool; pub struct CaCertificate { pub ca_cert_pem: String, pub ca_key_pem: String, } -pub async fn get_or_create_ca(db: &PgPool) -> Result { +pub async fn get_or_create_ca(db: &MySqlPool) -> Result { if let Some(ca_cert) = get_active_ca(db).await? { return Ok(ca_cert); } @@ -16,7 +16,7 @@ pub async fn get_or_create_ca(db: &PgPool) -> Result { let (ca_key_pem, ca_cert_pem) = crypto::generate_ca_cert()?; sqlx::query( - "INSERT INTO ca_certificates (ca_cert_pem, ca_key_pem, is_active) VALUES ($1, $2, TRUE)" + "INSERT INTO ca_certificates (ca_cert_pem, ca_key_pem, is_active) VALUES (?, ?, TRUE)" ) .bind(&ca_cert_pem) .bind(&ca_key_pem) @@ -31,7 +31,7 @@ pub async fn get_or_create_ca(db: &PgPool) -> Result { }) } -async fn get_active_ca(db: &PgPool) -> Result> { +async fn get_active_ca(db: &MySqlPool) -> Result> { let result: Option<(String, String)> = sqlx::query_as( "SELECT ca_cert_pem, ca_key_pem FROM ca_certificates WHERE is_active = TRUE ORDER BY created_at DESC LIMIT 1" ) diff --git a/dns/src/gurt_server/routes.rs b/dns/src/gurt_server/routes.rs index 18bae5e..8a9199d 100644 --- a/dns/src/gurt_server/routes.rs +++ b/dns/src/gurt_server/routes.rs @@ -972,7 +972,7 @@ pub(crate) async fn get_certificate( let token = path_parts[3]; let challenge: Option<(String, String, String, Option, chrono::DateTime)> = sqlx::query_as( - "SELECT domain, challenge_type, verification_data, csr_pem, expires_at FROM certificate_challenges WHERE token = $1" + "SELECT domain, challenge_type, verification_data, csr_pem, expires_at FROM certificate_challenges WHERE token = ?" ) .bind(token) .fetch_optional(&app_state.db) @@ -984,14 +984,9 @@ pub(crate) async fn get_certificate( None => return Ok(GurtResponse::not_found().with_string_body("Challenge not found")), }; - let csr_pem = match csr_pem { - Some(csr) => csr, - None => { - return Ok( - GurtResponse::bad_request().with_string_body("CSR not found for this challenge") - ) - } - }; + let csr_pem = csr_pem.ok_or_else(|| { + GurtResponse::bad_request().with_string_body("CSR not found for this challenge") + })?; if chrono::Utc::now() > expires_at { return Ok(GurtResponse::bad_request().with_string_body("Challenge expired"));