From 22e11e59a0ab1f41855b9dc6de24e9a0ea87c0c6 Mon Sep 17 00:00:00 2001 From: Andrew Houts Date: Sat, 27 Feb 2021 18:29:47 -0600 Subject: [PATCH] add basic dialog authentication --- sqlx-mysql/src/protocol/auth_plugin.rs | 6 +++- sqlx-mysql/src/protocol/auth_plugin/dialog.rs | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 sqlx-mysql/src/protocol/auth_plugin/dialog.rs diff --git a/sqlx-mysql/src/protocol/auth_plugin.rs b/sqlx-mysql/src/protocol/auth_plugin.rs index 5c4b5364..498712f9 100644 --- a/sqlx-mysql/src/protocol/auth_plugin.rs +++ b/sqlx-mysql/src/protocol/auth_plugin.rs @@ -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(plugin: &'static str, error: &E) -> Error diff --git a/sqlx-mysql/src/protocol/auth_plugin/dialog.rs b/sqlx-mysql/src/protocol/auth_plugin/dialog.rs new file mode 100644 index 00000000..f38a160c --- /dev/null +++ b/sqlx-mysql/src/protocol/auth_plugin/dialog.rs @@ -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, password: &str) -> Vec { + password.as_bytes().to_vec() + } + + fn handle( + &self, + _data: Bytes, + _nonce: &Chain, + _password: &str, + ) -> Result>> { + Err(Error::ConnectOptions { + message: Cow::Borrowed("interactive dialog authentication is currently not supported"), + source: None, + }) + } +}