From 21fe97fa163b7bd36911e51f5ac684ac827275ff Mon Sep 17 00:00:00 2001 From: James Edington Date: Tue, 15 Mar 2022 12:56:27 -0500 Subject: [PATCH] Saner TOTP provisioning A user's e-mail address may be fluid, and the site "instance name" may be strange or change regularly. There's no reason to use these over the user's stable ID and the site's stable hostname for TOTP parameters. Even if the system is built to TOLERATE changes (as it is -- I tested it), it seems much more elegant to have these para- meters as stable identifiers. --- lib/pleroma/mfa/totp.ex | 2 +- .../web/pleroma_api/controllers/two_factor_authentication_controller.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/mfa/totp.ex b/lib/pleroma/mfa/totp.ex index f33e3a379..4bc3607fa 100644 --- a/lib/pleroma/mfa/totp.ex +++ b/lib/pleroma/mfa/totp.ex @@ -34,7 +34,7 @@ defmodule Pleroma.MFA.TOTP do defp default_digits, do: Config.get(@config_ns ++ [:digits]) defp default_issuer, - do: Config.get(@config_ns ++ [:issuer], Config.get([:instance, :name])) + do: Config.get(@config_ns ++ [:issuer], Config.get([:instance, :host])) @doc "Creates a random Base 32 encoded string" def generate_secret do diff --git a/lib/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller.ex b/lib/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller.ex index 3940ad581..28998453a 100644 --- a/lib/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller.ex @@ -41,7 +41,7 @@ defmodule Pleroma.Web.PleromaAPI.TwoFactorAuthenticationController do def setup(%{assigns: %{user: user}} = conn, %{"method" => "totp"} = _params) do with {:ok, user} <- MFA.setup_totp(user), %{secret: secret} = _ <- user.multi_factor_authentication_settings.totp do - provisioning_uri = TOTP.provisioning_uri(secret, "#{user.email}") + provisioning_uri = TOTP.provisioning_uri(secret, "#{user.ap_id}") json(conn, %{provisioning_uri: provisioning_uri, key: secret}) else