mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
fixed filenames
This commit is contained in:
parent
467c6af913
commit
1bdf070dfe
|
@ -496,9 +496,10 @@ def bool_to_string(state):
|
||||||
|
|
||||||
|
|
||||||
def get_hmac_salt(dxcallsign: bytes, mycallsign: bytes):
|
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:
|
try:
|
||||||
with open(filename, "w") as file:
|
with open(filename, "r") as file:
|
||||||
line = file.readlines()
|
line = file.readlines()
|
||||||
hmac_salt = line[-1]
|
hmac_salt = line[-1]
|
||||||
return hmac_salt if delete_last_line_from_hmac_list(filename, -1) else False
|
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):
|
def search_hmac_salt(dxcallsign: bytes, mycallsign: bytes, search_token, data_frame, token_iters):
|
||||||
try:
|
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:
|
with open(filename, "w") as file:
|
||||||
token_list = file.readlines()
|
token_list = file.readlines()
|
||||||
|
|
||||||
|
|
12
tnc/main.py
12
tnc/main.py
|
@ -256,8 +256,8 @@ if __name__ == "__main__":
|
||||||
PARSER.add_argument(
|
PARSER.add_argument(
|
||||||
"--hmac",
|
"--hmac",
|
||||||
dest="hmac_salt",
|
dest="hmac_salt",
|
||||||
type=str,
|
action="store_true",
|
||||||
default="False",
|
default=True,
|
||||||
help="Enable and set hmac message salt",
|
help="Enable and set hmac message salt",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -315,12 +315,8 @@ if __name__ == "__main__":
|
||||||
TCIParam.port = ARGS.tci_port
|
TCIParam.port = ARGS.tci_port
|
||||||
ModemParam.tx_delay = ARGS.tx_delay
|
ModemParam.tx_delay = ARGS.tx_delay
|
||||||
MeshParam.enable_protocol = ARGS.enable_mesh
|
MeshParam.enable_protocol = ARGS.enable_mesh
|
||||||
if ARGS.hmac_salt not in ["False"]:
|
TNC.enable_hmac = False
|
||||||
TNC.hmac_salt = ARGS.hmac_salt
|
|
||||||
TNC.enable_hmac = False
|
|
||||||
else:
|
|
||||||
TNC.hmac_salt = ''
|
|
||||||
TNC.enable_hmac = False
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("[DMN] Error reading config file", exception=e)
|
log.error("[DMN] Error reading config file", exception=e)
|
||||||
|
|
|
@ -782,8 +782,11 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
binarydata = base64.b64decode(base64data)
|
binarydata = base64.b64decode(base64data)
|
||||||
# check if hmac hash is provided
|
# check if hmac hash is provided
|
||||||
try:
|
try:
|
||||||
|
print("looking for hmac salt...")
|
||||||
hmac_salt = helpers.get_hmac_salt(dxcallsign, mycallsign)
|
hmac_salt = helpers.get_hmac_salt(dxcallsign, mycallsign)
|
||||||
|
print(f" ... {hmac_salt}")
|
||||||
except Exception:
|
except Exception:
|
||||||
|
print("no hmac salt found...")
|
||||||
hmac_salt = ''
|
hmac_salt = ''
|
||||||
DATA_QUEUE_TRANSMIT.put(
|
DATA_QUEUE_TRANSMIT.put(
|
||||||
["ARQ_RAW", binarydata, arq_uuid, mycallsign, dxcallsign, attempts, hmac_salt]
|
["ARQ_RAW", binarydata, arq_uuid, mycallsign, dxcallsign, attempts, hmac_salt]
|
||||||
|
|
|
@ -144,7 +144,6 @@ class TNC:
|
||||||
heard_stations = []
|
heard_stations = []
|
||||||
listen: bool = True
|
listen: bool = True
|
||||||
enable_hmac: bool = False
|
enable_hmac: bool = False
|
||||||
hmac_salt: str = ''
|
|
||||||
|
|
||||||
# ------------
|
# ------------
|
||||||
|
|
||||||
|
|
30
tools/create_hmac_tokes.py
Normal file → Executable file
30
tools/create_hmac_tokes.py
Normal file → Executable file
|
@ -1,7 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
def create_hmac_salts(dxcallsign: str, mycallsign: str, num_tokens: int = 10000):
|
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
|
bool
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
token_array = []
|
||||||
|
for _ in range(num_tokens):
|
||||||
|
token_array.append(np.random.bytes(4).hex())
|
||||||
|
|
||||||
# Create and write random strings to a file
|
# Create and write random strings to a file
|
||||||
with open(f"freedata_hmac_tokens_{dxcallsign}_{mycallsign}.txt", "w") as file:
|
with open(f"freedata_hmac_STATION_{mycallsign}_REMOTE_{dxcallsign}.txt", "w") as file:
|
||||||
for _ in range(num_tokens):
|
for _ in range(len(token_array)):
|
||||||
random_str = np.random.bytes(4).hex()
|
file.write(token_array[_] + '\n')
|
||||||
file.write(random_str + '\n')
|
|
||||||
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
print("error creating hmac file")
|
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('--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('--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('--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))
|
|
Loading…
Reference in a new issue