Short-circuit Authentication of incoming game results

Attempt to resolve requests to an IP address, and then save that with each worker. A worker can compare against the IP address of his last request, and use that comparison to skip the password hashing steps
This commit is contained in:
Andrew Grant committed 2021-07-02 10:24:17 -04:00
1 parent f97e45b07d
commit 7b9b6f05e5
2 files changed
+27

No files matched your search

+1
View File
@@ -54,6 +54,7 @@ class Machine(Model):
threads = IntegerField(default=0) threads = IntegerField(default=0)
mnps = FloatField(default=0.00) mnps = FloatField(default=0.00)
updated = DateTimeField(auto_now=True) updated = DateTimeField(auto_now=True)
lastaddr = CharField(max_length=64, default='None')
workload = ForeignKey('Test', PROTECT, related_name='workload', default=1) workload = ForeignKey('Test', PROTECT, related_name='workload', default=1)
def __str__(self): def __str__(self):
+26
View File
@@ -31,6 +31,7 @@ from OpenBench.models import *
from django.contrib.auth.models import User from django.contrib.auth.models import User
from OpenSite.settings import MEDIA_ROOT from OpenSite.settings import MEDIA_ROOT
from ipware import get_client_ip
from wsgiref.util import FileWrapper from wsgiref.util import FileWrapper
from django.db.models import F from django.db.models import F
from django.http import HttpResponse, FileResponse from django.http import HttpResponse, FileResponse
@@ -82,6 +83,25 @@ def authenticate(request, requireEnabled=False):
return user return user
def fastAuthenticate(request):
try:
# Try to compare the saved IP address of the machine
client_ip, _ = get_client_ip(request)
machine = Machine.objects.get(id=int(request.POST['machineid']))
# Authenticate via IP comparisons, and update lastaddr
if client_ip and machine.lastaddr == str(client_ip):
return User.objects.get(username=request.POST['username']), machine
if client_ip: machine.lastaddr = str(client_ip); machine.save()
raise UnableToAuthenticate()
except Exception as err:
print(err)
raise UnableToAuthenticate()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# ADMINISTRATIVE VIEWS # # ADMINISTRATIVE VIEWS #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -734,6 +754,12 @@ def clientSubmitError(request):
@not_minified_response @not_minified_response
def clientSubmitResults(request): def clientSubmitResults(request):
try:
# Authenticate using saved IP addresses
user, machine = fastAuthenticate(request)
except UnableToAuthenticate:
# Verify the User's credentials # Verify the User's credentials
try: user = authenticate(request, True) try: user = authenticate(request, True)
except UnableToAuthenticate: return HttpResponse('Bad Credentials') except UnableToAuthenticate: return HttpResponse('Bad Credentials')