diff --git a/check_totp_secret.sh b/check_totp_secret.sh new file mode 100755 index 00000000..7469ebd9 --- /dev/null +++ b/check_totp_secret.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Check TOTP secret generation + +echo "=== TOTP Secret Generation Test ===" +echo "" + +kubectl exec -n towerops deployment/towerops -- bin/towerops rpc " +# Generate a test secret +secret = NimbleTOTP.secret() +IO.puts(\"Generated secret: #{secret}\") +IO.puts(\"Secret length: #{String.length(secret)} characters\") +IO.puts(\"Secret bytes: #{byte_size(secret)} bytes\") +IO.puts(\"Valid Base32?: #{String.match?(secret, ~r/^[A-Z2-7]+$/)}\") + +# Try to generate a code with it +current_time = System.system_time(:second) +code = NimbleTOTP.verification_code(secret, time: current_time) +IO.puts(\"\") +IO.puts(\"Test verification code: #{code}\") + +# Check if the code can be verified +valid = NimbleTOTP.valid?(secret, code, time: current_time) +IO.puts(\"Code validates: #{valid}\") +" diff --git a/lib/towerops_web/live/account_live/totp_enrollment.ex b/lib/towerops_web/live/account_live/totp_enrollment.ex index f9347b92..1d74061e 100644 --- a/lib/towerops_web/live/account_live/totp_enrollment.ex +++ b/lib/towerops_web/live/account_live/totp_enrollment.ex @@ -35,12 +35,22 @@ defmodule ToweropsWeb.AccountLive.TotpEnrollment do @impl true def handle_event("verify_code", %{"code" => code}, socket) do + require Logger + user = socket.assigns.current_scope.user secret = socket.assigns.secret + Logger.info("TOTP enrollment verification attempt", + user_email: user.email, + provided_code: code, + secret_length: byte_size(secret) + ) + if Accounts.verify_totp(secret, code) do + Logger.info("TOTP enrollment successful", user_email: user.email) handle_valid_code(socket, user, secret) else + Logger.warning("TOTP enrollment verification failed", user_email: user.email) {:noreply, assign(socket, :error, "Invalid code. Please try again.")} end end diff --git a/watch_totp_enrollment.sh b/watch_totp_enrollment.sh new file mode 100755 index 00000000..f8c3b980 --- /dev/null +++ b/watch_totp_enrollment.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Watch for TOTP enrollment in real-time + +echo "=== Watching for TOTP Enrollment Activity ===" +echo "Visit https://towerops.net/users/settings/totp-enrollment and scan the QR code" +echo "" +echo "Monitoring production logs for TOTP activity..." +echo "" + +kubectl logs -n towerops deployment/towerops -f --tail=0 | grep --line-buffered "TOTP"