Port to rsasl2

Closes #45
This commit is contained in:
Nadja Reitzenstein 2022-03-02 17:20:28 +01:00
parent 4306b5b691
commit e130e59651
5 changed files with 191 additions and 250 deletions

308
Cargo.lock generated
View File

@ -23,15 +23,6 @@ dependencies = [
"pretty",
]
[[package]]
name = "aho-corasick"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
]
[[package]]
name = "annotate-snippets"
version = "0.9.1"
@ -164,7 +155,7 @@ checksum = "83137067e3a2a6a06d67168e49e68a0957d215410473a740cea95a2425c0b7c6"
dependencies = [
"async-io",
"blocking",
"cfg-if 1.0.0",
"cfg-if",
"event-listener",
"futures-lite",
"libc",
@ -239,30 +230,6 @@ dependencies = [
"serde",
]
[[package]]
name = "bindgen"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b13ce559e6433d360c26305643803cb52cfbabbc2b9c47ce04a58493dfb443"
dependencies = [
"bitflags",
"cexpr",
"cfg-if 0.1.10",
"clang-sys",
"clap",
"env_logger",
"lazy_static",
"lazycell",
"log",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"which",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@ -301,6 +268,15 @@ dependencies = [
"generic-array 0.14.5",
]
[[package]]
name = "block-buffer"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
dependencies = [
"generic-array 0.14.5",
]
[[package]]
name = "block-padding"
version = "0.1.5"
@ -396,38 +372,12 @@ version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cexpr"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clang-sys"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "clap"
version = "2.34.0"
@ -473,7 +423,7 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"crossbeam-utils",
]
@ -483,10 +433,20 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"lazy_static",
]
[[package]]
name = "crypto-common"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
dependencies = [
"generic-array 0.14.5",
"typenum",
]
[[package]]
name = "dhall"
version = "0.11.0"
@ -508,7 +468,7 @@ dependencies = [
"quote",
"serde",
"serde_cbor",
"sha2",
"sha2 0.9.9",
"url",
]
@ -587,13 +547,24 @@ dependencies = [
"generic-array 0.14.5",
]
[[package]]
name = "digest"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [
"block-buffer 0.10.2",
"crypto-common",
"subtle",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"dirs-sys-next",
]
@ -641,19 +612,6 @@ dependencies = [
"stable_deref_trait",
]
[[package]]
name = "env_logger"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "event-listener"
version = "2.5.2"
@ -903,26 +861,11 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "gsasl-sys"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd377f206007e661591b4c6a6ba9907a75ae24e2a9ef40f3d0750a1db6bd5dbd"
dependencies = [
"bindgen",
]
[[package]]
name = "half"
version = "1.8.2"
@ -950,6 +893,15 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest 0.10.3",
]
[[package]]
name = "home"
version = "0.5.3"
@ -970,15 +922,6 @@ dependencies = [
"itoa",
]
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
dependencies = [
"quick-error",
]
[[package]]
name = "idna"
version = "0.2.3"
@ -1006,7 +949,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@ -1039,12 +982,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "lexical-core"
version = "0.7.6"
@ -1053,7 +990,7 @@ checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec 0.5.2",
"bitflags",
"cfg-if 1.0.0",
"cfg-if",
"ryu",
"static_assertions",
]
@ -1065,13 +1002,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
[[package]]
name = "libloading"
version = "0.7.3"
name = "linkme"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
checksum = "edd4ad156b9934dc21cad96fd17278a7cb6f30a5657a9d976cd7b71d6d49c02c"
dependencies = [
"cfg-if 1.0.0",
"winapi",
"linkme-impl",
]
[[package]]
name = "linkme-impl"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73fd9dc7072de7168cbdaba9125e8f742cd3a965aa12bde994b4611a174488d8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1103,7 +1050,7 @@ version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@ -1118,6 +1065,15 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "md-5"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582"
dependencies = [
"digest 0.10.3",
]
[[package]]
name = "memchr"
version = "2.4.1"
@ -1240,10 +1196,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
[[package]]
name = "peeking_take_while"
version = "0.1.2"
name = "pbkdf2"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7"
dependencies = [
"digest 0.10.3",
]
[[package]]
name = "percent-encoding"
@ -1313,7 +1272,7 @@ checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d"
dependencies = [
"maplit",
"pest",
"sha-1",
"sha-1 0.8.2",
]
[[package]]
@ -1360,7 +1319,7 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"libc",
"log",
"wepoll-ffi",
@ -1439,12 +1398,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.15"
@ -1503,23 +1456,6 @@ dependencies = [
"redox_syscall",
]
[[package]]
name = "regex"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "remove_dir_all"
version = "0.5.3"
@ -1546,13 +1482,21 @@ dependencies = [
[[package]]
name = "rsasl"
version = "1.4.2"
version = "2.0.0-preview2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00658df565e044eeb2d0358bf370eb597c7089daf7d5021aa142b91f2524f641"
checksum = "2adcc7fb89ad42cf35d527905a11232c02fa030f7b6983b8c9880c385da2ae8e"
dependencies = [
"discard",
"gsasl-sys",
"base64",
"digest 0.10.3",
"hmac",
"libc",
"linkme",
"md-5",
"pbkdf2",
"rand",
"sha-1 0.10.0",
"sha2 0.10.2",
"stringprep",
]
[[package]]
@ -1586,12 +1530,6 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustls"
version = "0.19.1"
@ -1711,6 +1649,17 @@ dependencies = [
"opaque-debug 0.2.3",
]
[[package]]
name = "sha-1"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
dependencies = [
"cfg-if",
"cpufeatures",
"digest 0.10.3",
]
[[package]]
name = "sha2"
version = "0.9.9"
@ -1718,17 +1667,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"digest 0.9.0",
"opaque-debug 0.3.0",
]
[[package]]
name = "shlex"
version = "0.1.1"
name = "sha2"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
dependencies = [
"cfg-if",
"cpufeatures",
"digest 0.10.3",
]
[[package]]
name = "signal-hook"
@ -1832,12 +1786,28 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "stringprep"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1"
dependencies = [
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "subtle"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.86"
@ -1872,7 +1842,7 @@ version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"fastrand",
"libc",
"redox_syscall",
@ -1891,15 +1861,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@ -2133,7 +2094,7 @@ version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"wasm-bindgen-macro",
]
@ -2210,15 +2171,6 @@ dependencies = [
"cc",
]
[[package]]
name = "which"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724"
dependencies = [
"libc",
]
[[package]]
name = "winapi"
version = "0.3.9"

View File

@ -47,7 +47,7 @@ uuid = { version = "0.8.2", features = ["serde", "v4"] }
clap = "2.33.3"
# TODO update this if bindgen breaks (again)
rsasl = "1.4.0"
rsasl = "2.0.0-preview2"
#rsasl = { path = "../../rsasl" }
rumqttc = { version = "0.10", features = ["url"] }

View File

@ -212,7 +212,7 @@
-- Actors need to be connected to machines to be useful. A machine can be connected to multiple actors, but one
-- actor can only be connected to one machine.
actor_connections = [
{ machine = "Testmachine", actor = "DoorControl1" },
{ machine = "Testmachine", actor = "Shelly1234" },
{ machine = "Another", actor = "Bash" },
{ machine = "Yetmore", actor = "Bash2" },
{ machine = "Yetmore", actor = "FailBash"}
@ -221,14 +221,14 @@
-- Initiators are configured almost the same way as Actors, refer to actor documentation for more details
-- The below '{=}' is what you need if you want to define *no* initiators at all and only use the API with apps
-- to let people use machines.
-- initiators = {=},
initiators = {=},
-- The "Dummy" initiator will try to use and return a machine as the given user every few seconds. It's good to
-- test your system but will spam your log so is disabled by default.
initiators = { Initiator = { module = "Dummy", params = { uid = "Testuser" } } },
--initiators = { Initiator = { module = "Dummy", params = { uid = "Testuser" } } },
-- Linking up machines to initiators. Similar to actors a machine can have several initiators assigned but an
-- initiator can only be assigned to one machine.
-- The below is once again how you have to define *no* initiators.
--init_connections = [] : List { machine : Text, initiator : Text }
init_connections = [{ machine = "Testmachine", initiator = "Initiator" }]
init_connections = [] : List { machine : Text, initiator : Text }
--init_connections = [{ machine = "Testmachine", initiator = "Initiator" }]
}

View File

@ -6,23 +6,21 @@
use std::sync::Arc;
use std::rc::Rc;
use std::cell::RefCell;
use std::io::Cursor;
use slog::Logger;
use rsasl::{
SASL,
RSASL,
Property,
Session as SaslSession,
ReturnCode,
Callback,
Step,
};
use serde::{Serialize, Deserialize};
use capnp::capability::{Promise};
use rsasl::callback::Callback;
use rsasl::error::SessionError;
use rsasl::mechname::Mechname;
use rsasl::property::{AuthId, Password};
use rsasl::SASL;
use rsasl::session::Step;
use rsasl::validate::{Validation, validations};
use crate::api::Session;
@ -39,42 +37,35 @@ pub struct SessionData {
authz: Option<User>,
}
struct CB;
impl Callback<AppData, SessionData> for CB {
fn callback(sasl: &mut SASL<AppData, SessionData>,
session: &mut SaslSession<SessionData>,
prop: Property
) -> Result<(), ReturnCode>
{
let ret = match prop {
Property::GSASL_VALIDATE_SIMPLE => {
// FIXME: get_property and retrieve_mut can't be used interleaved but that's
// technically safe.
let authid: &str = session
.get_property(Property::GSASL_AUTHID)
.ok_or(ReturnCode::GSASL_NO_AUTHID)
.and_then(|a| match a.to_str() {
Ok(s) => Ok(s),
Err(_) => Err(ReturnCode::GSASL_SASLPREP_ERROR),
})?;
let pass = session.get_property(Property::GSASL_PASSWORD)
.ok_or(ReturnCode::GSASL_NO_PASSWORD)?;
if let Some(appdata) = sasl.retrieve_mut() {
if let Ok(Some(user)) = appdata.userdb.login(authid, pass.to_bytes()) {
session.retrieve_mut().unwrap().authz.replace(user);
return Ok(());
struct CB {
userdb: Arc<UserDB>,
}
impl CB {
pub fn new(userdb: Arc<UserDB>) -> Self {
Self { userdb }
}
}
impl Callback for CB {
fn validate(&self, session: &mut rsasl::session::SessionData, validation: Validation, _mechanism: &Mechname) -> Result<(), SessionError> {
let ret = match validation {
validations::SIMPLE => {
let authid = session
.get_property::<AuthId>()
.ok_or(SessionError::no_property::<AuthId>())?;
let pass = session.get_property::<Password>()
.ok_or(SessionError::no_property::<Password>())?;
if let Some(opt) = self.userdb.login(authid.as_ref(), pass.as_bytes()).unwrap() {
return Ok(())
}
ReturnCode::GSASL_AUTHENTICATION_ERROR
SessionError::AuthenticationFailure
}
p => {
println!("Callback called with property {:?}", p);
ReturnCode::GSASL_NO_CALLBACK
_ => {
SessionError::no_validate(validation)
}
};
Err(ret)
@ -82,22 +73,19 @@ impl Callback<AppData, SessionData> for CB {
}
pub struct Auth {
pub ctx: RSASL<AppData, SessionData>,
pub ctx: SASL,
session: Rc<RefCell<Option<Session>>>,
userdb: Arc<UserDB>,
access: Arc<AccessDB>,
log: Logger,
}
impl Auth {
pub fn new(log: Logger, dbs: Databases, session: Rc<RefCell<Option<Session>>>) -> Self {
let mut ctx = SASL::new().unwrap();
let mut ctx = SASL::new();
ctx.install_callback(Arc::new(CB::new(dbs.userdb.clone())));
let appdata = Box::new(AppData { userdb: dbs.userdb.clone() });
ctx.store(appdata);
ctx.install_callback::<CB>();
Self { log, ctx, session, access: dbs.access.clone() }
Self { log, ctx, session, userdb: dbs.userdb.clone(), access: dbs.access.clone() }
}
}
@ -147,6 +135,8 @@ impl authentication_system::Server for Auth {
})
}
let mech = Mechname::new(mech.as_bytes()).unwrap();
let mut session = match self.ctx.server_start(mech) {
Ok(s) => s,
Err(e) =>
@ -156,7 +146,7 @@ impl authentication_system::Server for Auth {
}),
};
session.store(Box::new(SessionData { authz: None }));
let mut out = Cursor::new(Vec::new());
// If the client has provided initial data go use that
use request::initial_response::Which;
@ -169,24 +159,24 @@ impl authentication_system::Server for Auth {
Ok(Which::None(_)) => {
// FIXME: Actually this needs to indicate NO data instead of SOME data of 0 length
session.step(&[])
session.step(Option::<&[u8]>::None, &mut out)
}
Ok(Which::Initial(data)) => {
session.step(pry!(data))
session.step(Some(pry!(data)), &mut out)
}
};
// The step may either return an error, a success or the need for more data
// TODO: Set the session user. Needs a lookup though <.>
use response::Result as Resres;
match step_res {
Ok(Step::Done(b)) => {
let user = session
.retrieve_mut()
.get_property::<AuthId>()
.and_then(|data| {
data.authz.take()
self.userdb.get_user(data.as_str()).unwrap()
})
.expect("Authentication returned OK but didn't set user id");
.expect("Authentication returned OK but the given AuthId is invalid");
let perms = pry!(self.access.collect_permrules(&user.data)
.map_err(|e| capnp::Error::failed(format!("AccessDB lookup failed: {}", e))));
@ -199,26 +189,26 @@ impl authentication_system::Server for Auth {
)));
let mut outcome = pry!(res.get().get_response()).init_outcome();
outcome.reborrow().set_result(Resres::Successful);
if b.len() != 0 {
outcome.init_additional_data().set_additional(&b);
outcome.reborrow().set_result(response::Result::Successful);
if let Some(data) = b {
outcome.init_additional_data().set_additional(&out.get_ref());
}
Promise::ok(())
},
Ok(Step::NeedsMore(b)) => {
pry!(res.get().get_response()).set_challence(&b);
if b.is_some() {
pry!(res.get().get_response()).set_challence(&out.get_ref());
}
Promise::ok(())
}
// TODO: This should really be an outcome because this is failed auth just as much atm.
Err(e) => {
let mut outcome = pry!(res.get().get_response()).init_outcome();
outcome.reborrow().set_result(Resres::Failed);
outcome.reborrow().set_result(response::Result::InvalidCredentials);
let text = format!("{}", e);
outcome.set_help_text(&text);
Promise::ok(())
}
}
}
}

View File

@ -3,10 +3,9 @@ use std::fmt;
use toml;
use serde_dhall;
use rsasl::SaslError;
// SpawnError is a somewhat ambigous name, `use as` to make it futures::SpawnError instead.
use futures::task as futures_task;
use rsasl::error::SessionError;
use crate::network;
@ -16,7 +15,7 @@ pub enum Error {
TomlDe(toml::de::Error),
TomlSer(toml::ser::Error),
Dhall(serde_dhall::Error),
SASL(SaslError),
SASL(SessionError),
IO(io::Error),
Boxed(Box<dyn std::error::Error>),
Capnp(capnp::Error),
@ -95,8 +94,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)
}
}