Skip to content

Commit

Permalink
Remove mfa in wallet (#858)
Browse files Browse the repository at this point in the history
* Remove MFA in Wallet

* cleanup

---------

Co-authored-by: Aleksander <[email protected]>
  • Loading branch information
moubctez and t-aleksander authored Nov 19, 2024
1 parent 70cbfea commit c4f6fd4
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 601 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions migrations/20241119105926_disable_wallet_mfa.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE wallet ADD COLUMN use_for_mfa boolean NOT NULL DEFAULT true;
2 changes: 1 addition & 1 deletion migrations/20241119105926_disable_wallet_mfa.up.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
UPDATE wallet SET use_for_mfa = false;
ALTER TABLE wallet DROP use_for_mfa;
13 changes: 2 additions & 11 deletions src/db/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ pub struct NewOpenIDClient {
pub enabled: bool,
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, ToSchema)]
pub struct WalletInfo {
pub address: String,
pub name: String,
pub chain_id: Id,
pub use_for_mfa: bool,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
Expand Down Expand Up @@ -217,7 +216,6 @@ impl UserDetails {
pub struct MFAInfo {
mfa_method: MFAMethod,
totp_available: bool,
web3_available: bool,
webauthn_available: bool,
email_available: bool,
}
Expand All @@ -227,7 +225,6 @@ impl MFAInfo {
query_as!(
Self,
"SELECT mfa_method \"mfa_method: _\", totp_enabled totp_available, email_mfa_enabled email_available, \
(SELECT count(*) > 0 FROM wallet WHERE user_id = $1 AND wallet.use_for_mfa) \"web3_available!\", \
(SELECT count(*) > 0 FROM webauthn WHERE user_id = $1) \"webauthn_available!\" \
FROM \"user\" WHERE \"user\".id = $1",
user.id
Expand All @@ -236,10 +233,7 @@ impl MFAInfo {

#[must_use]
pub fn mfa_available(&self) -> bool {
self.webauthn_available
|| self.totp_available
|| self.web3_available
|| self.email_available
self.webauthn_available || self.totp_available || self.email_available
}

#[must_use]
Expand All @@ -257,9 +251,6 @@ impl MFAInfo {
if self.webauthn_available {
methods.push(MFAMethod::Webauthn);
}
if self.web3_available {
methods.push(MFAMethod::Web3);
}
if self.totp_available {
methods.push(MFAMethod::OneTimePassword);
}
Expand Down
8 changes: 2 additions & 6 deletions src/db/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use totp_lite::{totp_custom, Sha1};
use super::{
device::{Device, UserDevice},
group::Group,
wallet::Wallet,
webauthn::WebAuthn,
MFAInfo, OAuth2AuthorizedAppInfo, SecurityKey, WalletInfo,
};
Expand Down Expand Up @@ -234,7 +233,6 @@ impl User<Id> {

/// Check if any of the multi-factor authentication methods is on.
/// - TOTP is enabled
/// - a [`Wallet`] flagged `use_for_mfa`
/// - a security key for Webauthn
async fn check_mfa_enabled<'e, E>(&self, executor: E) -> Result<bool, SqlxError>
where
Expand All @@ -246,9 +244,8 @@ impl User<Id> {
}

query_scalar!(
"SELECT totp_enabled OR email_mfa_enabled OR coalesce(bool_or(wallet.use_for_mfa), FALSE) \
"SELECT totp_enabled OR email_mfa_enabled \
OR count(webauthn.id) > 0 \"bool!\" FROM \"user\" \
LEFT JOIN wallet ON wallet.user_id = \"user\".id \
LEFT JOIN webauthn ON webauthn.user_id = \"user\".id \
WHERE \"user\".id = $1 GROUP BY totp_enabled, email_mfa_enabled;",
self.id
Expand Down Expand Up @@ -360,7 +357,6 @@ impl User<Id> {
)
.execute(pool)
.await?;
Wallet::disable_mfa_for_user(pool, self.id).await?;
WebAuthn::delete_all_for_user(pool, self.id).await?;

self.totp_secret = None;
Expand Down Expand Up @@ -727,7 +723,7 @@ impl User<Id> {
{
query_as!(
WalletInfo,
"SELECT address \"address!\", name, chain_id, use_for_mfa \
"SELECT address \"address!\", name, chain_id \
FROM wallet WHERE user_id = $1 AND validation_timestamp IS NOT NULL",
self.id
)
Expand Down
Loading

0 comments on commit c4f6fd4

Please sign in to comment.