totp debugging

This commit is contained in:
Graham McIntire 2026-01-28 17:37:54 -06:00
parent eeca341abf
commit 9353a24760
3 changed files with 44 additions and 0 deletions

24
check_totp_secret.sh Executable file
View file

@ -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}\")
"

View file

@ -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

10
watch_totp_enrollment.sh Executable file
View file

@ -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"