mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 06:47:56 +01:00
Modules renaming
This commit is contained in:
parent
f932ff8e7a
commit
10e4ff080c
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -739,6 +739,7 @@ dependencies = [
|
||||
"futures-test",
|
||||
"futures-util",
|
||||
"inventory",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"lmdb-rkv",
|
||||
"once_cell",
|
||||
|
@ -75,6 +75,7 @@ serde_dhall = { version = "0.10.1", default-features = false }
|
||||
serde_json = "1.0"
|
||||
|
||||
once_cell = "1.8"
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
rustls = "0.20"
|
||||
futures-rustls = "0.22"
|
||||
|
94
bffhd/capnp/authentication.rs
Normal file
94
bffhd/capnp/authentication.rs
Normal file
@ -0,0 +1,94 @@
|
||||
use std::io::Cursor;
|
||||
use capnp::capability::Promise;
|
||||
use capnp::Error;
|
||||
use capnp_rpc::pry;
|
||||
use rsasl::session::{Session, Step};
|
||||
|
||||
use api::auth::authentication::{
|
||||
Server,
|
||||
AbortParams,
|
||||
AbortResults,
|
||||
StepParams,
|
||||
StepResults,
|
||||
};
|
||||
use api::auth::response::{
|
||||
Reason,
|
||||
Action,
|
||||
};
|
||||
|
||||
pub struct Authentication {
|
||||
state: State,
|
||||
}
|
||||
|
||||
enum State {
|
||||
InvalidMechanism,
|
||||
Finished,
|
||||
Aborted,
|
||||
Running(Session)
|
||||
}
|
||||
|
||||
impl Server for Authentication {
|
||||
fn step(&mut self, params: StepParams, mut results: StepResults) -> Promise<(), Error> {
|
||||
use State::*;
|
||||
let new = match self.state {
|
||||
InvalidMechanism => {
|
||||
let builder = results.get();
|
||||
let mut b = builder.init_error();
|
||||
b.set_reason(Reason::BadMechanism);
|
||||
b.set_action(Action::Permanent);
|
||||
None
|
||||
},
|
||||
Finished => {
|
||||
let builder = results.get();
|
||||
let mut b = builder.init_error();
|
||||
b.set_reason(Reason::Finished);
|
||||
b.set_action(Action::Permanent);
|
||||
None
|
||||
},
|
||||
Aborted => {
|
||||
let builder = results.get();
|
||||
let mut b = builder.init_error();
|
||||
b.set_reason(Reason::Aborted);
|
||||
b.set_action(Action::Permanent);
|
||||
None
|
||||
},
|
||||
Running(ref mut session) => {
|
||||
// TODO: If null what happens?
|
||||
let data: &[u8] = pry!(pry!(params.get()).get_data());
|
||||
|
||||
let mut builder = results.get();
|
||||
let mut out = Cursor::new(Vec::new());
|
||||
match session.step(Some(data), &mut out) {
|
||||
Ok(Step::Done(data)) => {
|
||||
let mut b = builder.init_successful();
|
||||
let mut session_builder = b.init_session();
|
||||
let session = super::session::Session::new();
|
||||
session.build(&mut session_builder);
|
||||
Some(State::Finished)
|
||||
},
|
||||
Ok(Step::NeedsMore(data)) => {
|
||||
//builder.set_challenge(data.deref());
|
||||
None
|
||||
},
|
||||
Err(_) => {
|
||||
let mut b = builder.init_error();
|
||||
b.set_reason(Reason::Aborted);
|
||||
b.set_action(Action::Permanent);
|
||||
Some(State::Aborted)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(new) = new {
|
||||
std::mem::replace(&mut self.state, new);
|
||||
}
|
||||
|
||||
Promise::ok(())
|
||||
}
|
||||
|
||||
fn abort(&mut self, _: AbortParams, _: AbortResults) -> Promise<(), Error> {
|
||||
std::mem::replace(&mut self.state, State::Aborted);
|
||||
Promise::ok(())
|
||||
}
|
||||
}
|
@ -1,17 +1,12 @@
|
||||
use std::future::Future;
|
||||
use futures_util::future::FutureExt;
|
||||
use async_rustls::TlsStream;
|
||||
use capnp::capability::Promise;
|
||||
use capnp::Error;
|
||||
use capnp_rpc::rpc_twoparty_capnp::Side;
|
||||
use capnp_rpc::RpcSystem;
|
||||
use capnp_rpc::twoparty::VatNetwork;
|
||||
use smol::io::{AsyncRead, AsyncWrite};
|
||||
use futures_rustls::server::TlsStream;
|
||||
use futures_util::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::error::Result;
|
||||
|
||||
use api::bootstrap::{
|
||||
Client,
|
||||
Server,
|
||||
MechanismsParams,
|
||||
MechanismsResults,
|
||||
@ -33,19 +28,8 @@ impl APIHandler {
|
||||
pub fn handle<IO: 'static + Unpin + AsyncRead + AsyncWrite>(&mut self, stream: TlsStream<IO>)
|
||||
-> impl Future<Output = Result<()>>
|
||||
{
|
||||
let (mut reader, mut writer) = smol::io::split(stream);
|
||||
|
||||
let bootstrap = ApiSystem {};
|
||||
let rpc: Client = capnp_rpc::new_client(bootstrap);
|
||||
let network = VatNetwork::new(
|
||||
reader,
|
||||
writer,
|
||||
Side::Server,
|
||||
Default::default(),
|
||||
);
|
||||
let rpc_system = RpcSystem::new(Box::new(network), Some(rpc.client));
|
||||
|
||||
rpc_system.map(|r| r.map_err(Into::into))
|
||||
unimplemented!();
|
||||
futures_util::future::ready(Ok(()))
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use api::session::Builder;
|
||||
use crate::server::resources::Resources;
|
||||
use crate::server::users::Users;
|
||||
use crate::capnp::resources::Resources;
|
||||
use crate::capnp::users::Users;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Session {
|
@ -1,12 +1,12 @@
|
||||
use std::io;
|
||||
use std::fmt;
|
||||
use rsasl::SaslError;
|
||||
use rsasl::error::SessionError;
|
||||
use crate::db::DBError;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Shared error type
|
||||
pub enum Error {
|
||||
SASL(SaslError),
|
||||
SASL(SessionError),
|
||||
IO(io::Error),
|
||||
Boxed(Box<dyn std::error::Error>),
|
||||
Capnp(capnp::Error),
|
||||
@ -39,8 +39,8 @@ impl fmt::Display for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SaslError> for Error {
|
||||
fn from(e: SaslError) -> Error {
|
||||
impl From<SessionError> for Error {
|
||||
fn from(e: SessionError) -> Error {
|
||||
Error::SASL(e)
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ use async_channel as channel;
|
||||
use async_oneshot as oneshot;
|
||||
use futures_signals::signal::Signal;
|
||||
use futures_util::future::BoxFuture;
|
||||
use smol::future::FutureExt;
|
||||
use crate::resource::{Error, Update};
|
||||
use crate::resource::claim::{ResourceID, UserID};
|
||||
use crate::resource::state::State;
|
||||
@ -126,7 +125,7 @@ impl<S: Signal<Item=ResourceSink> + Unpin, I: Initiator + Unpin> Future for Init
|
||||
// If we've send an update to the resource in question we have error channel set, so
|
||||
// we poll that first to determine if the resource has acted on it yet.
|
||||
if let Some(ref mut errchan) = self.error_channel {
|
||||
match errchan.poll(cx) {
|
||||
match Pin::new(errchan).poll(cx) {
|
||||
// In case there's an ongoing
|
||||
Poll::Pending => return Poll::Pending,
|
||||
Poll::Ready(Ok(error)) => {
|
||||
@ -142,7 +141,7 @@ impl<S: Signal<Item=ResourceSink> + Unpin, I: Initiator + Unpin> Future for Init
|
||||
}
|
||||
|
||||
if let Some(ref mut init_fut) = self.initiator_future {
|
||||
match init_fut.poll(cx) {
|
||||
match init_fut.as_mut().poll(cx) {
|
||||
Poll::Pending => return Poll::Pending,
|
||||
Poll::Ready(Ok(())) => {},
|
||||
Poll::Ready(Err(_e)) => {
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
//! Diflouroborane
|
||||
//!
|
||||
//! This is the server component of the FabAccess project.
|
||||
//! This is the capnp component of the FabAccess project.
|
||||
//! The entry point of bffhd can be found in [bin/bffhd/main.rs](../bin/bffhd/main.rs)
|
||||
|
||||
/// Internal Databases build on top of LMDB, a mmap()'ed B-tree DB optimized for reads
|
||||
@ -29,6 +29,6 @@ pub mod initiators;
|
||||
|
||||
pub mod sensors;
|
||||
|
||||
pub mod server;
|
||||
pub mod capnp;
|
||||
|
||||
pub mod utils;
|
@ -1,221 +0,0 @@
|
||||
use api::utils::l10n_string;
|
||||
use crate::error;
|
||||
|
||||
use std::ops::Deref;
|
||||
use capnp::capability::Promise;
|
||||
use capnp::Error;
|
||||
use capnp_rpc::pry;
|
||||
|
||||
use rsasl::{rsasl_err_to_str, SASL, Session as SaslSession, Property, ReturnCode, RSASL, DiscardOnDrop, Mechanisms};
|
||||
use rsasl::session::Step::{Done, NeedsMore};
|
||||
|
||||
use api::auth::authentication::{
|
||||
Server,
|
||||
AbortParams,
|
||||
AbortResults,
|
||||
StepParams,
|
||||
StepResults,
|
||||
};
|
||||
use api::auth::response::{
|
||||
Reason,
|
||||
Action,
|
||||
};
|
||||
use crate::users::{UserDB, PassDB};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AuthenticationProvider {
|
||||
sasl: RSASL<AppData, SessionData>,
|
||||
}
|
||||
|
||||
impl AuthenticationProvider {
|
||||
pub fn new() -> error::Result<Self> {
|
||||
let sasl = SASL::new()?;
|
||||
Ok(Self { sasl })
|
||||
}
|
||||
|
||||
pub fn mechanisms(&self) -> error::Result<Mechanisms> {
|
||||
Ok(self.sasl.server_mech_list()?)
|
||||
}
|
||||
|
||||
pub fn try_start_session(&mut self, mechanism: &str) -> error::Result<Authentication> {
|
||||
let session = self.sasl.server_start(mechanism)?;
|
||||
Ok(Authentication {
|
||||
state: State::Running(session),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn bad_mechanism(&self) -> Authentication {
|
||||
Authentication {
|
||||
state: State::InvalidMechanism,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_session(&mut self, mechanism: &str) -> Authentication {
|
||||
self.try_start_session(mechanism)
|
||||
.unwrap_or_else(|_| self.bad_mechanism())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Callback;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct AppData {
|
||||
userdb: UserDB,
|
||||
passdb: PassDB,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SessionData;
|
||||
|
||||
impl rsasl::Callback<AppData, SessionData> for Callback {
|
||||
fn callback(sasl: &mut SASL<AppData, SessionData>,
|
||||
session: &mut SaslSession<SessionData>,
|
||||
prop: Property
|
||||
) -> Result<(), ReturnCode>
|
||||
{
|
||||
match prop {
|
||||
Property::GSASL_VALIDATE_SIMPLE => {
|
||||
// Access the authentication id, i.e. the username to check the password for
|
||||
let authcid = session
|
||||
.get_property(Property::GSASL_AUTHID)
|
||||
.ok_or(rsasl::GSASL_NO_AUTHID)
|
||||
.map_err(|_| rsasl::GSASL_NO_AUTHID)
|
||||
.and_then(|cstr| cstr.to_str()
|
||||
.map_err(|_| rsasl::GSASL_NO_AUTHID))?;
|
||||
|
||||
// Access the password itself
|
||||
let password = session
|
||||
.get_property(Property::GSASL_PASSWORD)
|
||||
.ok_or(rsasl::GSASL_NO_PASSWORD)
|
||||
.and_then(|cstr| cstr.to_str()
|
||||
.map_err(|_| rsasl::GSASL_NO_AUTHID))?;
|
||||
|
||||
let AppData { userdb: _, passdb } = sasl.retrieve_mut()
|
||||
.ok_or(rsasl::GSASL_NO_CALLBACK)?;
|
||||
|
||||
if let Ok(Some(Ok(true))) = passdb.verify_password(authcid, &password.as_bytes()) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(rsasl::GSASL_AUTHENTICATION_ERROR)
|
||||
}
|
||||
},
|
||||
_ => Err(rsasl::GSASL_NO_CALLBACK),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Authentication {
|
||||
state: State<SessionData>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum State<E> {
|
||||
InvalidMechanism,
|
||||
Finished,
|
||||
Aborted,
|
||||
Running(DiscardOnDrop<SaslSession<E>>)
|
||||
}
|
||||
|
||||
impl Server for Authentication {
|
||||
fn step(&mut self, params: StepParams, mut results: StepResults) -> Promise<(), Error> {
|
||||
use State::*;
|
||||
let new = match self.state {
|
||||
InvalidMechanism => {
|
||||
let builder = results.get();
|
||||
let mut b = builder.init_error();
|
||||
b.set_reason(Reason::BadMechanism);
|
||||
b.set_action(Action::Permanent);
|
||||
None
|
||||
},
|
||||
Finished => {
|
||||
let builder = results.get();
|
||||
let mut b = builder.init_error();
|
||||
b.set_reason(Reason::Finished);
|
||||
b.set_action(Action::Permanent);
|
||||
None
|
||||
},
|
||||
Aborted => {
|
||||
let builder = results.get();
|
||||
let mut b = builder.init_error();
|
||||
b.set_reason(Reason::Aborted);
|
||||
b.set_action(Action::Permanent);
|
||||
None
|
||||
},
|
||||
Running(ref mut session) => {
|
||||
// TODO: If null what happens?
|
||||
let data: &[u8] = pry!(pry!(params.get()).get_data());
|
||||
|
||||
let mut builder = results.get();
|
||||
match session.step(data) {
|
||||
Ok(Done(data)) => {
|
||||
let mut b = builder.init_successful();
|
||||
if !data.is_empty() {
|
||||
b.reborrow().set_additional_data(data.deref())
|
||||
}
|
||||
let mut session_builder = b.init_session();
|
||||
let session = super::session::Session::new();
|
||||
session.build(&mut session_builder);
|
||||
Some(State::Finished)
|
||||
},
|
||||
Ok(NeedsMore(data)) => {
|
||||
builder.set_challenge(data.deref());
|
||||
None
|
||||
},
|
||||
Err(_) => {
|
||||
let mut b = builder.init_error();
|
||||
b.set_reason(Reason::Aborted);
|
||||
b.set_action(Action::Permanent);
|
||||
Some(State::Aborted)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(new) = new {
|
||||
std::mem::replace(&mut self.state, new);
|
||||
}
|
||||
|
||||
Promise::ok(())
|
||||
}
|
||||
|
||||
fn abort(&mut self, _: AbortParams, _: AbortResults) -> Promise<(), Error> {
|
||||
std::mem::replace(&mut self.state, State::Aborted);
|
||||
Promise::ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
struct SaslE {
|
||||
e: ReturnCode,
|
||||
}
|
||||
|
||||
impl l10n_string::Server for SaslE {
|
||||
fn get(&mut self,
|
||||
params: l10n_string::GetParams,
|
||||
mut results: l10n_string::GetResults
|
||||
) -> Promise<(), Error>
|
||||
{
|
||||
let lang = pry!(pry!(params.get()).get_lang());
|
||||
if lang == "en" {
|
||||
let mut builder = results.get();
|
||||
builder.set_lang("en");
|
||||
builder.set_content(rsasl_err_to_str(self.e)
|
||||
.unwrap_or("Unknown gsasl error"));
|
||||
}
|
||||
|
||||
Promise::ok(())
|
||||
}
|
||||
|
||||
fn available(
|
||||
&mut self,
|
||||
_: l10n_string::AvailableParams,
|
||||
mut results: l10n_string::AvailableResults
|
||||
) -> Promise<(), Error> {
|
||||
let builder = results.get();
|
||||
let mut langs = builder.init_langs(1);
|
||||
langs.set(0, "en");
|
||||
Promise::ok(())
|
||||
}
|
||||
}
|
@ -150,7 +150,7 @@ fn main() -> Result<(), Error> {
|
||||
ex.spawn(init).detach();
|
||||
}
|
||||
|
||||
server::serve_api_connections(log.clone(), config, db, network, ex)
|
||||
capnp::serve_api_connections(log.clone(), config, db, network, ex)
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
//! Main differences between other executors are:
|
||||
//! * Uses SMP based execution scheme to exploit cache affinity on multiple cores and execution is
|
||||
//! equally distributed over the system resources, which means utilizing the all system.
|
||||
//! * Uses NUMA-aware allocation for scheduler's queues and exploit locality on server workloads.
|
||||
//! * Uses NUMA-aware allocation for scheduler's queues and exploit locality on capnp workloads.
|
||||
//! * Tailored for creating middleware and working with actor model like concurrency and distributed communication.
|
||||
//!
|
||||
//! **NOTE:** Bastion Executor is independent of it's framework implementation.
|
||||
|
Loading…
Reference in New Issue
Block a user