From 609f1cfaef2f9f9cbc1b739c606fae2189e2258b Mon Sep 17 00:00:00 2001 From: chapeau Date: Wed, 24 Apr 2024 19:12:56 +0200 Subject: [PATCH] Fix bug in prod --- radius/api/views.py | 19 +++++++++++-------- re2o/aes_field.py | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/radius/api/views.py b/radius/api/views.py index 9d18c7dd..55d9e55f 100644 --- a/radius/api/views.py +++ b/radius/api/views.py @@ -22,6 +22,7 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from django.db.models import Q +from django.db import DataError from django.http import HttpResponse from django.forms import ValidationError from django.contrib.auth.decorators import login_required @@ -61,9 +62,11 @@ def authorize(request, nas_id, username): """ # get the Nas object which made the request (if exists) - nas_interface = Interface.objects.filter( - Q(domain__name=nas_id) | Q(ipv4__ipv4=nas_id) - ).first() + try: + nas_interface = Interface.objects.filter(Q(ipv4__ipv4=nas_id)).first() + except DataError: + nas_interface = Interface.objects.filter(Q(domain__name=nas_id)).first() + nas_type = None if nas_interface: nas_type = Nas.objects.filter(nas_type=nas_interface.machine_type).first() @@ -130,11 +133,11 @@ def post_auth(request, nas_id, nas_port, user_mac, username): """ # get the Nas object which made the request (if exists) - nas_interface = ( - Interface.objects.prefetch_related("machine__switch__stack") - .filter(Q(domain__name=nas_id) | Q(ipv4__ipv4=nas_id)) - .first() - ) + try: + nas_interface = Interface.objects.prefetch_related("machine__switch__stack").filter(Q(ipv4__ipv4=nas_id)).first() + except DataError: + nas_interface = Interface.objects.prefetch_related("machine__switch__stack").filter(Q(domain__name=nas_id)).first() + nas_type = None if nas_interface: nas_type = Nas.objects.filter(nas_type=nas_interface.machine_type).first() diff --git a/re2o/aes_field.py b/re2o/aes_field.py index 3c847c69..eb5e2bd5 100644 --- a/re2o/aes_field.py +++ b/re2o/aes_field.py @@ -49,7 +49,7 @@ def genstring(length=16, chars=string.printable): def encrypt(key, secret): """ AES Encrypt a secret with the key `key` """ - obj = AES.new(key) + obj = AES.new(key, AES.MODE_ECB) datalength = len(secret) + len(EOD) if datalength < 16: saltlength = 16 - datalength @@ -61,7 +61,7 @@ def encrypt(key, secret): def decrypt(key, secret): """ AES Decrypt a secret with the key `key` """ - obj = AES.new(key) + obj = AES.new(key, AES.MODE_ECB) uncrypted_secret = obj.decrypt(secret) return uncrypted_secret.split(EOD_asbyte)[0]