Skip to content

Commit

Permalink
Support for generating multiple vectors via API
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvsnetworking committed Nov 21, 2023
1 parent b87eba2 commit a74de0a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,25 @@ def Get_Vectors_AuC(self, auc_id, action, **kwargs):
self.Update_AuC(auc_id, sqn=key_data['sqn']+100)
return vector_dict

elif action == "2g3g":
rand, autn, xres, ck, ik = S6a_crypt.generate_maa_vector(key_data['ki'], key_data['opc'], key_data['amf'], key_data['sqn'], kwargs['plmn'])
vector_list = []
self.logTool.log(service='Database', level='debug', message="Generating " + str(kwargs['requested_vectors']) + " vectors for GSM use", redisClient=self.redisMessaging)
while kwargs['requested_vectors'] != 0:
self.logTool.log(service='Database', level='debug', message="RAND is: " + str(rand), redisClient=self.redisMessaging)
self.logTool.log(service='Database', level='debug', message="AUTN is: " + str(autn), redisClient=self.redisMessaging)

vector_dict['rand'] = binascii.hexlify(rand).decode("utf-8")
vector_dict['autn'] = binascii.hexlify(autn).decode("utf-8")
vector_dict['xres'] = binascii.hexlify(xres).decode("utf-8")
vector_dict['ck'] = binascii.hexlify(ck).decode("utf-8")
vector_dict['ik'] = binascii.hexlify(ik).decode("utf-8")

kwargs['requested_vectors'] = kwargs['requested_vectors'] - 1
vector_list.append(vector_dict)
self.Update_AuC(auc_id, sqn=key_data['sqn']+100)
return vector_list

elif action == "eap_aka":
rand, xres, autn, mac_a, ak = S6a_crypt.generate_eap_aka_vector(key_data['ki'], key_data['opc'], key_data['amf'], key_data['sqn'], kwargs['plmn'])
self.logTool.log(service='Database', level='debug', message="RAND is: " + str(rand), redisClient=self.redisMessaging)
Expand Down
17 changes: 17 additions & 0 deletions services/apiService.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,23 @@ def get(self, imsi, plmn):
print(E)
return handle_exception(E)

@ns_auc.route('/aka/vector_count/<string:vector_count>/imsi/<string:imsi>')
class PyHSS_AUC_Get_AKA_Vectors(Resource):
def get(self, imsi, vector_count):
'''Get AKA vectors for specified IMSI and PLMN'''
try:
#Get data from AuC
auc_data = databaseClient.Get_AuC(imsi=imsi)
print("Got AuC Data OK - Generating " + str(vector_count) + " Vectors")

plmn = diameterClient.EncodePLMN(mcc=config['hss']['MCC'], mnc=config['hss']['MNC'])
vector_dict = databaseClient.Get_Vectors_AuC(auc_data['auc_id'], action='2g3g', plmn=plmn, requested_vectors=int(vector_count))
print("Got Vectors: " + str(vector_dict))
return vector_dict, 200
except Exception as E:
print(E)
return handle_exception(E)

@ns_subscriber.route('/<string:subscriber_id>')
class PyHSS_SUBSCRIBER_Get(Resource):
def get(self, subscriber_id):
Expand Down

0 comments on commit a74de0a

Please sign in to comment.