-use bcrypt::hash;
+use bcrypt::{hash, verify};
use regex::Regex;
use std::{env, net::TcpListener, process::exit, thread};
--help: print this help message
--ip: set the IP address to bind the server to
--port: set the port for the server
- --token: token used to authenticate"
+ --token: bcrypt hash used to authenticate
+ --insecure: allows for raw text to be passed as a passphrase, which is hashed by bcrypt"
);
exit(0);
}
+ let insecure_context = args.iter().any(|i| i == "--insecure");
+
for item in args {
if item.contains("--ip=") {
conf.ip = item.replace("--ip=", "");
exit(-1);
});
} else if item.contains("--token=") {
+ let hash = if insecure_context {
+ let hash = hash(item.replace("--token=", ""), 10).unwrap();
+ println!("[!] Insecure mode: Raw text hashed as {}", &hash);
+ hash
+ } else {
+ let hash = item.replace("--token=", "");
+ match verify("", &hash) {
+ Ok(_) => hash,
+ Err(x) => {
+ println!("{}", x);
+ exit(-1);
+ }
+ }
+ };
unsafe {
- env::set_var("token", hash(item.replace("--token=", ""), 10).unwrap());
+ env::set_var("token", hash);
}
}
}