sudo: zeroize pass on every [ask_sudo()] call

This commit is contained in:
hinto-janaiyo 2022-12-07 20:34:21 -05:00
parent 06f19043ed
commit 82918d4106
No known key found for this signature in database
GPG key ID: B1C5A64B80691E45
2 changed files with 16 additions and 7 deletions

View file

@ -435,13 +435,15 @@ impl ErrorState {
// Instead of creating a whole new screen and system, this (ab)uses ErrorState // Instead of creating a whole new screen and system, this (ab)uses ErrorState
// to ask for the [sudo] when starting XMRig. Yes, yes I know, it's called "ErrorState" // to ask for the [sudo] when starting XMRig. Yes, yes I know, it's called "ErrorState"
// but rewriting the UI code and button stuff might be worse. // but rewriting the UI code and button stuff might be worse.
pub fn ask_sudo(&mut self) { // It also resets the current [SudoState]
pub fn ask_sudo(&mut self, state: &Arc<Mutex<SudoState>>) {
*self = Self { *self = Self {
error: true, error: true,
msg: String::new(), msg: String::new(),
ferris: ErrorFerris::Sudo, ferris: ErrorFerris::Sudo,
buttons: ErrorButtons::Sudo, buttons: ErrorButtons::Sudo,
} };
SudoState::reset(&state)
} }
} }
@ -1150,10 +1152,10 @@ impl eframe::App for App {
let width = (ui.available_width()/3.0)-5.0; let width = (ui.available_width()/3.0)-5.0;
if self.xmrig.lock().unwrap().is_alive() { if self.xmrig.lock().unwrap().is_alive() {
if ui.add_sized([width, height], Button::new("")).on_hover_text("Restart XMRig").clicked() { if ui.add_sized([width, height], Button::new("")).on_hover_text("Restart XMRig").clicked() {
self.error_state.ask_sudo(); self.error_state.ask_sudo(&self.sudo);
} }
if ui.add_sized([width, height], Button::new("")).on_hover_text("Stop XMRig").clicked() { if ui.add_sized([width, height], Button::new("")).on_hover_text("Stop XMRig").clicked() {
self.error_state.ask_sudo(); self.error_state.ask_sudo(&self.sudo);
} }
ui.add_enabled_ui(false, |ui| { ui.add_enabled_ui(false, |ui| {
ui.add_sized([width, height], Button::new("")).on_hover_text("Start XMRig"); ui.add_sized([width, height], Button::new("")).on_hover_text("Start XMRig");
@ -1164,7 +1166,7 @@ impl eframe::App for App {
ui.add_sized([width, height], Button::new("")).on_hover_text("Stop XMRig"); ui.add_sized([width, height], Button::new("")).on_hover_text("Stop XMRig");
}); });
if ui.add_sized([width, height], Button::new("")).on_hover_text("Start XMRig").clicked() { if ui.add_sized([width, height], Button::new("")).on_hover_text("Start XMRig").clicked() {
self.error_state.ask_sudo(); self.error_state.ask_sudo(&self.sudo);
} }
} }
}); });

View file

@ -51,10 +51,17 @@ impl SudoState {
} }
} }
// Resets the state.
pub fn reset(state: &Arc<Mutex<Self>>) {
Self::wipe(&state);
let mut state = state.lock().unwrap();
state.testing = false;
state.success = false;
}
// Swaps the pass with another 256-capacity String, // Swaps the pass with another 256-capacity String,
// zeroizes the old and drops it. // zeroizes the old and drops it.
pub fn wipe(state: &Arc<Mutex<Self>>) { pub fn wipe(state: &Arc<Mutex<Self>>) {
info!("Sudo | Wiping password with zeros and dropping from memory...");
let mut new = String::with_capacity(256); let mut new = String::with_capacity(256);
let mut state = state.lock().unwrap(); let mut state = state.lock().unwrap();
// new is now == old, and vice-versa. // new is now == old, and vice-versa.
@ -62,7 +69,7 @@ impl SudoState {
// we're wiping & dropping the old pass here. // we're wiping & dropping the old pass here.
new.zeroize(); new.zeroize();
std::mem::drop(new); std::mem::drop(new);
info!("Sudo ... Password Wipe OK"); info!("Sudo | Password wipe with 0's ... OK");
} }
// Spawns a thread and tests sudo with the provided password. // Spawns a thread and tests sudo with the provided password.