v1.2.0 + v1.3.0: Localization, About dialog, TOTP/2FA, stability improvements
v1.2.0: - GUI localization (EN/RU/ZH) with language switcher and persistent selection - About dialog (ⓘ) with app info, features, quick start guide - core/i18n.py — internationalization module with t() function - All GUI components translated via t() keys v1.3.0: - TOTP/2FA tab — Google Authenticator compatible codes with live 30s countdown, one-click copy, per-server secret management - core/totp.py — TOTP module (pyotp, RFC 6238) - core/logger.py — rotating file logger (5MB, 3 backups) - Stronger Fernet encryption key with automatic migration from old key - Thread-safe server store with locks, atomic writes, auto-restore on corruption - Parallel status checks via ThreadPoolExecutor (up to 10 concurrent) - SSH client: explicit channel cleanup, Unix key permissions - Server dialog: port validation (1-65535), TOTP secret field - Language change preserves active tab and server selection - pyotp dependency added Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
39
core/totp.py
Normal file
39
core/totp.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""
|
||||
TOTP module — Google Authenticator compatible 2FA codes.
|
||||
Uses pyotp (RFC 6238).
|
||||
"""
|
||||
|
||||
import time
|
||||
import pyotp
|
||||
|
||||
|
||||
def generate_secret(length: int = 32) -> str:
|
||||
"""Generate a new random TOTP secret (base32-encoded)."""
|
||||
return pyotp.random_base32(length=length)
|
||||
|
||||
|
||||
def get_code(secret: str) -> str:
|
||||
"""Get current 6-digit TOTP code."""
|
||||
return pyotp.TOTP(secret).now()
|
||||
|
||||
|
||||
def get_code_with_timer(secret: str) -> dict:
|
||||
"""Get current code with timing info for GUI display."""
|
||||
totp = pyotp.TOTP(secret)
|
||||
now = time.time()
|
||||
remaining = 30 - (int(now) % 30)
|
||||
return {
|
||||
"code": totp.now(),
|
||||
"remaining": remaining,
|
||||
"progress": remaining / 30.0,
|
||||
}
|
||||
|
||||
|
||||
def verify_code(secret: str, code: str) -> bool:
|
||||
"""Verify a TOTP code (with +/- 1 period tolerance)."""
|
||||
return pyotp.TOTP(secret).verify(code, valid_window=1)
|
||||
|
||||
|
||||
def format_secret_uri(secret: str, account: str, issuer: str = "ServerManager") -> str:
|
||||
"""Generate otpauth:// URI for QR code / authenticator apps."""
|
||||
return pyotp.TOTP(secret).provisioning_uri(name=account, issuer_name=issuer)
|
||||
Reference in New Issue
Block a user