add basic dialog authentication

This commit is contained in:
Andrew Houts 2021-02-27 18:29:47 -06:00 committed by Ryan Leckey
parent c9197916fb
commit 22e11e59a0
2 changed files with 38 additions and 1 deletions

View File

@ -8,11 +8,13 @@ use sqlx_core::{Error, Result};
use crate::MySqlDatabaseError;
mod caching_sha2;
mod dialog;
mod native;
mod rsa;
mod sha256;
pub(crate) use self::caching_sha2::CachingSha2AuthPlugin;
pub(crate) use self::dialog::DialogAuthPlugin;
pub(crate) use self::native::NativeAuthPlugin;
pub(crate) use self::sha256::Sha256AuthPlugin;
@ -39,6 +41,7 @@ impl dyn AuthPlugin {
_ if s == CachingSha2AuthPlugin.name() => Ok(Box::new(CachingSha2AuthPlugin)),
_ if s == Sha256AuthPlugin.name() => Ok(Box::new(Sha256AuthPlugin)),
_ if s == NativeAuthPlugin.name() => Ok(Box::new(NativeAuthPlugin)),
_ if s == DialogAuthPlugin.name() => Ok(Box::new(DialogAuthPlugin)),
_ => Err(MySqlDatabaseError::new(
2059,
@ -63,7 +66,8 @@ fn err_msg(plugin: &'static str, message: &str) -> Error {
MySqlDatabaseError::new(
2061,
&format!("Authentication plugin '{}' reported error: {}", plugin, message),
).into()
)
.into()
}
fn err<E>(plugin: &'static str, error: &E) -> Error

View File

@ -0,0 +1,33 @@
use bytes::buf::Chain;
use bytes::Bytes;
use sqlx_core::{Error, Result};
use std::borrow::Cow;
/// Dialog authentication implementation
///
/// https://mariadb.com/kb/en/authentication-plugin-pam/#dialog
///
#[derive(Debug)]
pub(crate) struct DialogAuthPlugin;
impl super::AuthPlugin for DialogAuthPlugin {
fn name(&self) -> &'static str {
"dialog"
}
fn invoke(&self, _nonce: &Chain<Bytes, Bytes>, password: &str) -> Vec<u8> {
password.as_bytes().to_vec()
}
fn handle(
&self,
_data: Bytes,
_nonce: &Chain<Bytes, Bytes>,
_password: &str,
) -> Result<Option<Vec<u8>>> {
Err(Error::ConnectOptions {
message: Cow::Borrowed("interactive dialog authentication is currently not supported"),
source: None,
})
}
}