dbus: use challenge-response authentication
This commit is contained in:
parent
2f4543912b
commit
3d7dc1161f
4 changed files with 9 additions and 19 deletions
|
|
@ -98,6 +98,8 @@ pub enum DbusError {
|
||||||
ReadError(#[source] IoUringError),
|
ReadError(#[source] IoUringError),
|
||||||
#[error("timeout")]
|
#[error("timeout")]
|
||||||
IoUringError(#[source] Box<IoUringError>),
|
IoUringError(#[source] Box<IoUringError>),
|
||||||
|
#[error("Server did not send auth challenge")]
|
||||||
|
NoChallenge,
|
||||||
#[error("Server did not accept our authentication")]
|
#[error("Server did not accept our authentication")]
|
||||||
Auth,
|
Auth,
|
||||||
#[error("Array length is not a multiple of the element size")]
|
#[error("Array length is not a multiple of the element size")]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
dbus::{DbusError, DbusSocket, incoming::handle_incoming, outgoing::handle_outgoing},
|
dbus::{DbusError, DbusSocket, incoming::handle_incoming, outgoing::handle_outgoing},
|
||||||
utils::{buf::Buf, errorfmt::ErrorFmt, hex},
|
utils::{buf::Buf, errorfmt::ErrorFmt},
|
||||||
},
|
},
|
||||||
std::{ops::Deref, rc::Rc},
|
std::{ops::Deref, rc::Rc},
|
||||||
};
|
};
|
||||||
|
|
@ -52,16 +52,20 @@ impl Auth {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_auth(&mut self) -> Result<(), DbusError> {
|
async fn handle_auth(&mut self) -> Result<(), DbusError> {
|
||||||
let uid = hex::to_hex(&uapi::getuid().to_string());
|
|
||||||
let mut out_buf = Buf::new(128);
|
let mut out_buf = Buf::new(128);
|
||||||
{
|
{
|
||||||
let buf = out_buf
|
let buf = out_buf
|
||||||
.write_fmt(format_args!("\0AUTH EXTERNAL {}\r\n", uid))
|
.write_fmt(format_args!("\0AUTH EXTERNAL\r\nDATA\r\n"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.write_buf(buf).await?;
|
self.write_buf(buf).await?;
|
||||||
}
|
}
|
||||||
let line = self.readline().await?;
|
let line = self.readline().await?;
|
||||||
let (cmd, _) = line_to_cmd(&line);
|
let (cmd, _) = line_to_cmd(&line);
|
||||||
|
if cmd != "DATA" {
|
||||||
|
return Err(DbusError::NoChallenge);
|
||||||
|
}
|
||||||
|
let line = self.readline().await?;
|
||||||
|
let (cmd, _) = line_to_cmd(&line);
|
||||||
if cmd != "OK" {
|
if cmd != "OK" {
|
||||||
return Err(DbusError::Auth);
|
return Err(DbusError::Auth);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ pub mod free_list;
|
||||||
pub mod geometric_decay;
|
pub mod geometric_decay;
|
||||||
pub mod gfx_api_ext;
|
pub mod gfx_api_ext;
|
||||||
pub mod hash_map_ext;
|
pub mod hash_map_ext;
|
||||||
pub mod hex;
|
|
||||||
pub mod line_logger;
|
pub mod line_logger;
|
||||||
pub mod linkedlist;
|
pub mod linkedlist;
|
||||||
pub mod log_on_drop;
|
pub mod log_on_drop;
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
pub fn to_hex(b: &str) -> String {
|
|
||||||
let mut s = String::with_capacity(b.len() * 2);
|
|
||||||
for &b in b.as_bytes() {
|
|
||||||
s.push(nibble_to_hex(b >> 4) as char);
|
|
||||||
s.push(nibble_to_hex(b & 7) as char);
|
|
||||||
}
|
|
||||||
s
|
|
||||||
}
|
|
||||||
|
|
||||||
fn nibble_to_hex(n: u8) -> u8 {
|
|
||||||
match n {
|
|
||||||
n @ 0..=9 => b'0' + n,
|
|
||||||
n => b'a' + n,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue