feat(reception): add strict anti-capture expiration to dynamic QR and fix Buenos Aires timezone display (v3.8.49)
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import Any
|
||||
from database import db, get_db, engine, SessionLocal, session
|
||||
from config.config import Config
|
||||
|
||||
__version__ = "3.8.48"
|
||||
__version__ = "3.8.49"
|
||||
|
||||
class DummyContext:
|
||||
def __enter__(self):
|
||||
|
||||
@@ -82,6 +82,33 @@ class QRSecurityService:
|
||||
if clean_normalized.startswith("UNICABA:QR:"):
|
||||
clean_normalized = clean_normalized[len("UNICABA:QR:"):].strip()
|
||||
|
||||
# 1. Intentar validar como JWT criptográfico institucional primero
|
||||
if clean_normalized.count(".") == 2:
|
||||
try:
|
||||
payload = jwt.decode(
|
||||
clean_normalized,
|
||||
cls._get_secret(),
|
||||
algorithms=["HS256"],
|
||||
options={"verify_exp": True}
|
||||
)
|
||||
if payload.get("type") != cls.QR_TOKEN_TYPE:
|
||||
return None, "DENEGADO", "El token no corresponde a una credencial institucional válida."
|
||||
|
||||
user_id = payload.get("sub")
|
||||
user = User.query.get(int(user_id)) if user_id else None
|
||||
if not user:
|
||||
return None, "DENEGADO", "Usuario no encontrado en la base de datos."
|
||||
|
||||
if not user.is_active:
|
||||
return user, "RESTRINGIDO", "La cuenta del usuario se encuentra inactiva o suspendida."
|
||||
|
||||
return user, "AUTORIZADO", "Credencial institucional válida y activa."
|
||||
except jwt.ExpiredSignatureError:
|
||||
return None, "DENEGADO", "La credencial digital ha expirado (anti-captura activo). Renueve el código en la pantalla del usuario."
|
||||
except jwt.PyJWTError as e:
|
||||
return None, "DENEGADO", f"Firma criptográfica inválida: {str(e)}"
|
||||
|
||||
# 2. Formatos fallback (cuando no es un JWT):
|
||||
# A. Intentar extraer patrón institucional UNICABA:USR:<id>
|
||||
usr_match = re.search(r"USR:(\d+)", clean_normalized)
|
||||
if usr_match:
|
||||
@@ -107,32 +134,6 @@ class QRSecurityService:
|
||||
return user_by_dni, "RESTRINGIDO", "Usuario inactivo en el sistema institucional."
|
||||
return user_by_dni, "AUTORIZADO", f"Identificación validada por documento de identidad (DNI {doc})."
|
||||
|
||||
# C. Intentar validar como JWT institucional
|
||||
if clean_normalized.count(".") == 2:
|
||||
try:
|
||||
payload = jwt.decode(
|
||||
clean_normalized,
|
||||
cls._get_secret(),
|
||||
algorithms=["HS256"],
|
||||
options={"verify_exp": True}
|
||||
)
|
||||
if payload.get("type") != cls.QR_TOKEN_TYPE:
|
||||
return None, "DENEGADO", "El token no corresponde a una credencial institucional válida."
|
||||
|
||||
user_id = payload.get("sub")
|
||||
user = User.query.get(int(user_id)) if user_id else None
|
||||
if not user:
|
||||
return None, "DENEGADO", "Usuario no encontrado en la base de datos."
|
||||
|
||||
if not user.is_active:
|
||||
return user, "RESTRINGIDO", "La cuenta del usuario se encuentra inactiva o suspendida."
|
||||
|
||||
return user, "AUTORIZADO", "Credencial institucional válida y activa."
|
||||
except jwt.ExpiredSignatureError:
|
||||
return None, "DENEGADO", "La credencial digital ha expirado. El alumno debe abrir su app para renovarla."
|
||||
except jwt.PyJWTError as e:
|
||||
return None, "DENEGADO", f"Firma criptográfica inválida: {str(e)}"
|
||||
|
||||
# D. Fallback: Lectura de pistola óptica o documento directo (ej: 'DNI:12345678' o '12345678')
|
||||
doc_num = clean_normalized
|
||||
if doc_num.upper().startswith("DNI:"):
|
||||
|
||||
Reference in New Issue
Block a user