From e99ba5c97e7f3fe2cfc2f66ed763d751c95c1b6f Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Mon, 8 Jul 2024 21:25:32 +0200 Subject: [PATCH] Fix bugs --- src/handlers/update/authenticate.rs | 25 +++++++++++++++---------- src/reader.rs | 4 +++- src/resolver.rs | 1 - 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/handlers/update/authenticate.rs b/src/handlers/update/authenticate.rs index 8715570..9bfe8e3 100644 --- a/src/handlers/update/authenticate.rs +++ b/src/handlers/update/authenticate.rs @@ -1,4 +1,5 @@ use diesel::PgConnection; +use reqwest::header::ACCEPT; use crate::{ config::Config, @@ -34,16 +35,20 @@ pub async fn authenticate( } async fn validate_ssh(username: &String, sig: &Sig) -> Result { - Ok(reqwest::get(format!( - "{}/users/keys/{}", - Config::get().zauth_url, - username - )) - .await? - .json::>() - .await? - .iter() - .any(|key| sig.verify_ssh(&key).is_ok_and(|b| b))) + let client = reqwest::Client::new(); + Ok(client + .get(format!( + "{}/users/{}/keys", + Config::get().zauth_url, + username + )) + .header(ACCEPT, "application/json") + .send() + .await? + .json::>() + .await? + .iter() + .any(|key| sig.verify_ssh(&key).is_ok_and(|b| b))) } async fn validate_dnskey( diff --git a/src/reader.rs b/src/reader.rs index fb831e0..749c82b 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -71,7 +71,9 @@ impl<'a> Reader<'a> { message: String::from("Seeking into the future is not allowed!!"), }) } else { - Ok(Reader::new(&self.buffer[position..self.position])) + let mut reader = Reader::new(&self.buffer[0..self.position]); + reader.position = position; + Ok(reader) } } } diff --git a/src/resolver.rs b/src/resolver.rs index fe26d75..e31f299 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -50,7 +50,6 @@ async fn get_response(bytes: &[u8]) -> Message { response } Err(e) => { - println!("{:#?}", message); eprintln!("{}", e.to_string()); message.set_response(e.rcode()); message