fixed filenames

This commit is contained in:
DJ2LS 2023-08-07 20:28:19 +02:00
parent 467c6af913
commit 1bdf070dfe
5 changed files with 29 additions and 24 deletions

View file

@ -496,9 +496,10 @@ def bool_to_string(state):
def get_hmac_salt(dxcallsign: bytes, mycallsign: bytes):
filename = f"freedata_hmac_tokens_{dxcallsign}_{mycallsign}.txt"
filename = f"freedata_hmac_STATION_{dxcallsign.decode('utf-8')}_REMOTE_{mycallsign.decode('utf-8')}.txt"
print(f"looking for file {filename}")
try:
with open(filename, "w") as file:
with open(filename, "r") as file:
line = file.readlines()
hmac_salt = line[-1]
return hmac_salt if delete_last_line_from_hmac_list(filename, -1) else False
@ -507,7 +508,7 @@ def get_hmac_salt(dxcallsign: bytes, mycallsign: bytes):
def search_hmac_salt(dxcallsign: bytes, mycallsign: bytes, search_token, data_frame, token_iters):
try:
filename = f"freedata_hmac_tokens_{dxcallsign}_{mycallsign}.txt"
filename = f"freedata_hmac_STATION_{dxcallsign.decode('utf-8')}_REMOTE_{mycallsign.decode('utf-8')}.txt"
with open(filename, "w") as file:
token_list = file.readlines()

View file

@ -256,8 +256,8 @@ if __name__ == "__main__":
PARSER.add_argument(
"--hmac",
dest="hmac_salt",
type=str,
default="False",
action="store_true",
default=True,
help="Enable and set hmac message salt",
)
@ -315,12 +315,8 @@ if __name__ == "__main__":
TCIParam.port = ARGS.tci_port
ModemParam.tx_delay = ARGS.tx_delay
MeshParam.enable_protocol = ARGS.enable_mesh
if ARGS.hmac_salt not in ["False"]:
TNC.hmac_salt = ARGS.hmac_salt
TNC.enable_hmac = False
else:
TNC.hmac_salt = ''
TNC.enable_hmac = False
TNC.enable_hmac = False
except Exception as e:
log.error("[DMN] Error reading config file", exception=e)

View file

@ -782,8 +782,11 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
binarydata = base64.b64decode(base64data)
# check if hmac hash is provided
try:
print("looking for hmac salt...")
hmac_salt = helpers.get_hmac_salt(dxcallsign, mycallsign)
print(f" ... {hmac_salt}")
except Exception:
print("no hmac salt found...")
hmac_salt = ''
DATA_QUEUE_TRANSMIT.put(
["ARQ_RAW", binarydata, arq_uuid, mycallsign, dxcallsign, attempts, hmac_salt]

View file

@ -144,7 +144,6 @@ class TNC:
heard_stations = []
listen: bool = True
enable_hmac: bool = False
hmac_salt: str = ''
# ------------

30
tools/create_hmac_tokes.py Normal file → Executable file
View file

@ -1,7 +1,5 @@
import argparse
import numpy as np
import time
def create_hmac_salts(dxcallsign: str, mycallsign: str, num_tokens: int = 10000):
"""
@ -16,22 +14,30 @@ def create_hmac_salts(dxcallsign: str, mycallsign: str, num_tokens: int = 10000)
bool
"""
try:
token_array = []
for _ in range(num_tokens):
token_array.append(np.random.bytes(4).hex())
# Create and write random strings to a file
with open(f"freedata_hmac_tokens_{dxcallsign}_{mycallsign}.txt", "w") as file:
for _ in range(num_tokens):
random_str = np.random.bytes(4).hex()
file.write(random_str + '\n')
with open(f"freedata_hmac_STATION_{mycallsign}_REMOTE_{dxcallsign}.txt", "w") as file:
for _ in range(len(token_array)):
file.write(token_array[_] + '\n')
except Exception:
print("error creating hmac file")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='FreeDATA token generator')
parser = argparse.ArgumentParser(description='FreeDATA token generator')
parser.add_argument('--dxcallsign', dest="dxcallsign", default='AA0AA', help="Select the destination callsign", type=str)
parser.add_argument('--mycallsign', dest="mycallsign", default='AA0AA', help="Select the own callsign", type=str)
parser.add_argument('--tokens', dest="tokens", default='10000', help="Amount of tokens to create", type=int)
parser.add_argument('--dxcallsign', dest="dxcallsign", default='AA0AA', help="Select the destination callsign", type=str)
parser.add_argument('--mycallsign', dest="mycallsign", default='AA0AA', help="Select the own callsign", type=str)
parser.add_argument('--tokens', dest="tokens", default='10000', help="Amount of tokens to create", type=int)
args = parser.parse_args()
args = parser.parse_args()
create_hmac_salts(args.dxcallsign, args.mycallsign, int(args.tokens))
create_hmac_salts(args.dxcallsign, args.mycallsign, int(args.tokens))