mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 19:02:34 +01:00
autotest: make hlrauc.py able to run standalone
For testing purposes, it is useful to run hlrauc.py by itself not including it from another python script like autotests do. Better error checking was also added as testing can result in badly formatted data.
This commit is contained in:
parent
98a5d2b9be
commit
32907c10df
@ -1,6 +1,8 @@
|
|||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
import sys
|
||||||
|
import signal
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
|
|
||||||
class AuthCenter:
|
class AuthCenter:
|
||||||
@ -13,7 +15,7 @@ class AuthCenter:
|
|||||||
self._read_config(config_file)
|
self._read_config(config_file)
|
||||||
self._socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
self._socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||||
self._socket.setblocking(0)
|
self._socket.setblocking(0)
|
||||||
if os.path.isfile(sock_path):
|
if os.path.exists(sock_path):
|
||||||
os.unlink(sock_path)
|
os.unlink(sock_path)
|
||||||
self._socket.bind(sock_path)
|
self._socket.bind(sock_path)
|
||||||
|
|
||||||
@ -48,7 +50,12 @@ class AuthCenter:
|
|||||||
if data[:12] == "SIM-REQ-AUTH":
|
if data[:12] == "SIM-REQ-AUTH":
|
||||||
# SIM requests just return the stored values for the IMSI
|
# SIM requests just return the stored values for the IMSI
|
||||||
imsi, num_chals = data[13:].split(' ')
|
imsi, num_chals = data[13:].split(' ')
|
||||||
data = self._database[imsi]
|
if not imsi or not num_chals:
|
||||||
|
return "ERROR"
|
||||||
|
|
||||||
|
data = self._database.get(imsi, None)
|
||||||
|
if not data:
|
||||||
|
return "ERROR"
|
||||||
|
|
||||||
response = "SIM-RESP-AUTH %s" % imsi
|
response = "SIM-RESP-AUTH %s" % imsi
|
||||||
response += (' ' + data)*int(num_chals)
|
response += (' ' + data)*int(num_chals)
|
||||||
@ -57,7 +64,13 @@ class AuthCenter:
|
|||||||
elif data[:12] == "AKA-REQ-AUTH":
|
elif data[:12] == "AKA-REQ-AUTH":
|
||||||
# AKA requests must compute the milenage parameters for the IMSI
|
# AKA requests must compute the milenage parameters for the IMSI
|
||||||
imsi = data.split(' ')[1]
|
imsi = data.split(' ')[1]
|
||||||
data = self._database[imsi]
|
data = self._database.get(imsi, None)
|
||||||
|
if not data:
|
||||||
|
return "ERROR"
|
||||||
|
|
||||||
|
# make sure this is an AKA entry
|
||||||
|
if len(data.split(':')) < 4:
|
||||||
|
return "ERROR"
|
||||||
|
|
||||||
k, opc, amf, sqn = data.split(':')
|
k, opc, amf, sqn = data.split(':')
|
||||||
|
|
||||||
@ -172,3 +185,22 @@ class AuthCenter:
|
|||||||
self._rxhandle.shutdown = True
|
self._rxhandle.shutdown = True
|
||||||
self._rxhandle.join()
|
self._rxhandle.join()
|
||||||
self._socket.close()
|
self._socket.close()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
'''
|
||||||
|
This will run in a stand-alone mode for testing
|
||||||
|
'''
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
print('Usage: ./hlrauc.py <sock_path> <config>')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
hlrauc = AuthCenter(sys.argv[1], sys.argv[2])
|
||||||
|
|
||||||
|
def signal_handler(signal, frame):
|
||||||
|
print('Exiting...')
|
||||||
|
hlrauc.stop()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
|
signal.pause()
|
||||||
|
Loading…
Reference in New Issue
Block a user