From 1fce78304f222525b63cff66d740d9f66c52a168 Mon Sep 17 00:00:00 2001 From: axtloss Date: Thu, 28 Jul 2022 22:24:56 +0200 Subject: [PATCH] Make jade automatically has the password when used this only affects using it from the terminal --- README.md | 8 +++----- src/functions/users.rs | 25 +++++++++++++++++++++++-- src/internal/config.rs | 1 + src/main.rs | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ccfcaf4..72ddd7f 100755 --- a/README.md +++ b/README.md @@ -68,18 +68,16 @@ jade networking getcryst.al --ipv6 ### configure users ```sh # make a new user called nonRootHaver, without sudo and easytohack as the password -# jade uses prehashed passwords for user creation, so you'll have to calculate the hash of the password -jade users newUser nonRootHaver $(openssl passwd -6 easytohack) +jade users newUser nonRootHaver easytohack # make a user called rootHaver, with sudo and omgsosuperhardtohack as the password -jade users newUser rootHaver $(openssl passwd -6 omgsuperhardtohack) --sudoer +jade users newUser rootHaver omgsuperhardtohack --sudoer ``` ### set root password ```sh # set the root password to 'muchSecurity,veryHardToHack' -# the same hashing thing goes for root passwords -jade users rootPass $(openssl passwd -6 muchSecurity,veryHardToHack) +jade users rootPass muchSecurity,veryHardToHack ``` ### install a desktop environment diff --git a/src/functions/users.rs b/src/functions/users.rs index aa7231b..d9a59a3 100755 --- a/src/functions/users.rs +++ b/src/functions/users.rs @@ -1,7 +1,15 @@ use crate::internal::exec::*; use crate::internal::*; +use std::process::Command; -pub fn new_user(username: &str, hasroot: bool, password: &str) { +pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: bool) { + if do_hash_pass { + let hashed_pass = &*hash_pass(password).stdout; + let password = match std::str::from_utf8(hashed_pass) { + Ok(v) => v, + Err(e) => panic!("Failed to hash password, invalid UTF-8 sequence {}", e), + }; + } exec_eval( exec_chroot( "useradd", @@ -10,7 +18,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) { String::from("-s"), String::from("/bin/bash"), String::from("-p"), - String::from(password), + String::from(password).replace("\n", ""), String::from(username), ], ), @@ -39,6 +47,19 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) { } } +pub fn hash_pass(password: &str) -> std::process::Output { + let output = Command::new("openssl") + .args([ + "passwd", + "-1", + password + ]) + .output() + .expect("Failed to hash password"); + return output; + +} + pub fn root_pass(root_pass: &str) { exec_eval( exec_chroot( diff --git a/src/internal/config.rs b/src/internal/config.rs index bdf217a..868d3cb 100755 --- a/src/internal/config.rs +++ b/src/internal/config.rs @@ -142,6 +142,7 @@ pub fn read_config(configpath: PathBuf) { config.users[i].name.as_str(), config.users[i].hasroot, config.users[i].password.as_str(), + false, ); println!("---------"); } diff --git a/src/main.rs b/src/main.rs index adee0c8..9a630af 100755 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ fn main() { } Command::Users { subcommand } => match subcommand { UsersSubcommand::NewUser(args) => { - users::new_user(&args.username, args.hasroot, &args.password); + users::new_user(&args.username, args.hasroot, &args.password, true); } UsersSubcommand::RootPass { password } => { users::root_pass(&password);