mirror of
https://gitlab.com/fabinfra/fabaccess/sute.git
synced 2025-03-12 14:41:52 +01:00
Complete a full PLAIN authentication round and report the result
This commit is contained in:
parent
5a4f8cc0ec
commit
4a9dd734f8
23
src/app.rs
23
src/app.rs
@ -10,7 +10,7 @@ use futures_signals::signal::{Mutable, Signal, MutableSignalCloned, MutableLockM
|
||||
use termion::event::Key;
|
||||
|
||||
use crate::input::Inputs;
|
||||
use crate::schema::API;
|
||||
use crate::schema::{API, Authentication};
|
||||
use crate::commands::{CommandParser, Commands};
|
||||
|
||||
use smol::future::FutureExt;
|
||||
@ -62,22 +62,28 @@ impl<'a, S: Unpin> Sute<'a, S> {
|
||||
}
|
||||
|
||||
fn run_cmd(&mut self, cmdline: String) {
|
||||
let mut words = cmdline.split_ascii_whitespace().map(|s| s.to_string());
|
||||
let words = cmdline.split_ascii_whitespace().map(|s| s.to_string());
|
||||
match self.cmds.parse(words) {
|
||||
Ok(matches) => {
|
||||
match matches.subcommand() {
|
||||
Some(("quit", _)) => self.state.lock_mut().running = false,
|
||||
Some(("authenticate", m)) => {
|
||||
let u = m.value_of("user");
|
||||
let p = m.value_of("pass");
|
||||
if u.is_none() || p.is_none() {
|
||||
error!(self.log, "authenticate <user> <pass>");
|
||||
} else {
|
||||
if let Some(mut api) = self.api.clone() {
|
||||
let log2 = self.log.clone();
|
||||
info!(self.log, "Going for an auth trip");
|
||||
|
||||
let u = u.unwrap().to_string();
|
||||
let p = p.unwrap().to_string();
|
||||
|
||||
let f = api.authentication().then(move |mut auth| {
|
||||
info!(log2, "Hey, an auth step!");
|
||||
auth.mechanisms().map(move |mechs| {
|
||||
info!(log2, "Oh yeah about `authenticate` of yours:");
|
||||
for mech in mechs {
|
||||
info!(log2, "Mech: {}", mech);
|
||||
}
|
||||
auth.authenticate(u, p).then(move |res| {
|
||||
info!(log2, "Authentication result: {}", res);
|
||||
futures::future::ready(())
|
||||
})
|
||||
});
|
||||
let old_f = self.future.replace(Box::pin(f));
|
||||
@ -88,6 +94,7 @@ impl<'a, S: Unpin> Sute<'a, S> {
|
||||
error!(self.log, "No connection, can't authenticate!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Some((s, m)) => info!(self.log, "Got Command {} with params {:?}", s, m),
|
||||
None => error!(self.log, "No command provided."),
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ impl<'help> CommandParser<'help> {
|
||||
.subcommand(App::new("authenticate")
|
||||
.arg(Arg::new("user")
|
||||
.takes_value(true))
|
||||
.arg(Arg::new("password")
|
||||
.arg(Arg::new("pass")
|
||||
.takes_value(true))
|
||||
)
|
||||
,
|
||||
|
@ -31,4 +31,27 @@ impl Authentication {
|
||||
tmp.get_mechs().unwrap().iter().map(|x| x.unwrap().to_string()).collect()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn authenticate(&mut self, username: String, password: String) -> impl Future<Output=bool> {
|
||||
let mut req = self.inner.start_request();
|
||||
let mut builder = req.get().init_request();
|
||||
builder.set_mechanism("PLAIN");
|
||||
let mut init_data = builder.init_initial_response();
|
||||
init_data.set_initial(format!("\0{}\0{}", username, password).as_ref());
|
||||
let response = req.send().promise;
|
||||
response.map(|res| {
|
||||
let res = res.unwrap();
|
||||
let tmp = res.get().unwrap().get_response().unwrap();
|
||||
match tmp.which().unwrap() {
|
||||
super::auth_capnp::response::Which::Challence(_) => false,
|
||||
super::auth_capnp::response::Which::Outcome(outcome) => {
|
||||
if outcome.get_result().unwrap() == super::auth_capnp::response::Result::Successful {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user