pull/146/head
Chip Senkbeil 2 years ago
parent 55dc58888b
commit 66d184daa3
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -5,13 +5,6 @@ use std::io;
/// Interface for a handler of authentication requests
#[async_trait]
pub trait AuthHandler {
/// Callback when authentication is beginning, providing available authentication methods and
/// returning selected authentication methods to pursue
async fn on_initialization(
&mut self,
initalizaton: Initialization,
) -> io::Result<InitializationResponse>;
/// Callback when a challenge is received, returning answers to the given questions.
async fn on_challenge(&mut self, challenge: Challenge) -> io::Result<ChallengeResponse>;
@ -22,6 +15,17 @@ pub trait AuthHandler {
verification: Verification,
) -> io::Result<VerificationResponse>;
/// Callback when authentication is beginning, providing available authentication methods and
/// returning selected authentication methods to pursue
async fn on_initialization(
&mut self,
initialization: Initialization,
) -> io::Result<InitializationResponse> {
Ok(InitializationResponse {
methods: initialization.methods,
})
}
/// Callback when authentication starts for a specific method
#[allow(unused_variables)]
async fn on_start_method(&mut self, start_method: StartMethod) -> io::Result<()> {

@ -82,7 +82,7 @@ impl AuthenticationMethod for StaticKeyAuthenticationMethod {
return Err(x.into_io_permission_denied());
} else if response.answers.len() > 1 {
authenticator
.error(Error::error("more than one answer, picking first"))
.error(Error::non_fatal("more than one answer, picking first"))
.await?;
}

@ -1,7 +1,7 @@
use super::MethodType;
use derive_more::{Display, Error, From};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
/// Represents messages from an authenticator that act as initiators such as providing
/// a challenge, verifying information, presenting information, or highlighting an error
@ -31,10 +31,10 @@ pub enum Authentication {
}
/// Represents the beginning of the authentication procedure
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Initialization {
/// Available methods to use for authentication
pub methods: Vec<MethodType>,
pub methods: HashSet<MethodType>,
}
/// Represents the start of authentication for some method
@ -81,7 +81,7 @@ pub enum AuthenticationResponse {
/// Represents a response to initialization to specify which authentication methods to pursue
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct InitializationResponse {
pub methods: Vec<MethodType>,
pub methods: HashSet<MethodType>,
}
/// Represents the answers to a previously-asked challenge associated with authentication
@ -159,7 +159,7 @@ impl Error {
}
/// Creates a non-fatal error
pub fn error(text: impl Into<String>) -> Self {
pub fn non_fatal(text: impl Into<String>) -> Self {
Self {
kind: ErrorKind::Error,
text: text.into(),

@ -9,6 +9,9 @@ pub struct ServerConfig {
/// Supported authentication methods
pub authentication_methods: Vec<MethodType>,
/// If true, authentication type "none" is allowed, meaning that no authentication is required
pub allow_none_authentication: bool,
/// Rules for how a server will shutdown automatically
pub shutdown: Shutdown,
}
@ -17,6 +20,7 @@ impl Default for ServerConfig {
fn default() -> Self {
Self {
authentication_methods: vec![MethodType::None],
allow_none_authentication: true,
shutdown: Shutdown::default(),
}
}

@ -425,6 +425,7 @@ mod tests {
let server = ServerExt::start(
TestServer(ServerConfig {
shutdown: Shutdown::Lonely(Duration::from_millis(100)),
..Default::default()
}),
listener,
)
@ -451,6 +452,7 @@ mod tests {
let server = ServerExt::start(
TestServer(ServerConfig {
shutdown: Shutdown::Lonely(Duration::from_millis(100)),
..Default::default()
}),
listener,
)
@ -479,6 +481,7 @@ mod tests {
let server = ServerExt::start(
TestServer(ServerConfig {
shutdown: Shutdown::Lonely(Duration::from_millis(100)),
..Default::default()
}),
listener,
)
@ -503,6 +506,7 @@ mod tests {
let server = ServerExt::start(
TestServer(ServerConfig {
shutdown: Shutdown::After(Duration::from_millis(100)),
..Default::default()
}),
listener,
)
@ -521,6 +525,7 @@ mod tests {
let server = ServerExt::start(
TestServer(ServerConfig {
shutdown: Shutdown::After(Duration::from_millis(100)),
..Default::default()
}),
listener,
)
@ -539,6 +544,7 @@ mod tests {
let server = ServerExt::start(
TestServer(ServerConfig {
shutdown: Shutdown::Never,
..Default::default()
}),
listener,
)

Loading…
Cancel
Save