mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
udpated hmac code signing - stil not working I guess
This commit is contained in:
parent
338dbc1d92
commit
52b4478f22
|
@ -919,16 +919,17 @@ class DATA:
|
||||||
|
|
||||||
# check if hmac signing enabled
|
# check if hmac signing enabled
|
||||||
if TNC.enable_hmac:
|
if TNC.enable_hmac:
|
||||||
hmac_digest = hmac.new(TNC.hmac_salt, data_frame, hashlib.sha256).digest()[:4]
|
|
||||||
# now check if we have valid hmac signature
|
# now check if we have valid hmac signature
|
||||||
if hmac_digest == data_frame_crc_received:
|
salt_found = helpers.search_hmac_salt(self.dxcallsign, self.mycallsign, data_frame_crc, token_iters=100)
|
||||||
|
if salt_found:
|
||||||
# hmac digest received
|
# hmac digest received
|
||||||
self.arq_process_received_data_frame(data_frame, snr, signed=True)
|
self.arq_process_received_data_frame(data_frame, snr, signed=True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# hmac signature wrong
|
# hmac signature wrong
|
||||||
self.arq_process_received_data_frame(data_frame, snr, signed=False)
|
self.arq_process_received_data_frame(data_frame, snr, signed=False)
|
||||||
|
elif data_frame_crc == data_frame_crc_received:
|
||||||
|
self.arq_process_received_data_frame(data_frame, snr, signed=False)
|
||||||
else:
|
else:
|
||||||
self.send_data_to_socket_queue(
|
self.send_data_to_socket_queue(
|
||||||
freedata="tnc-message",
|
freedata="tnc-message",
|
||||||
|
@ -1289,7 +1290,7 @@ class DATA:
|
||||||
tempbuffer = []
|
tempbuffer = []
|
||||||
self.rpt_request_buffer = []
|
self.rpt_request_buffer = []
|
||||||
# Append data frames with n_frames_per_burst to tempbuffer
|
# Append data frames with n_frames_per_burst to tempbuffer
|
||||||
for n_frame in range(0, n_frames_per_burst):
|
for n_frame in range(n_frames_per_burst):
|
||||||
arqheader = bytearray()
|
arqheader = bytearray()
|
||||||
arqheader[:1] = bytes([FR_TYPE.BURST_01.value + n_frame])
|
arqheader[:1] = bytes([FR_TYPE.BURST_01.value + n_frame])
|
||||||
#####arqheader[:1] = bytes([FR_TYPE.BURST_01.value])
|
#####arqheader[:1] = bytes([FR_TYPE.BURST_01.value])
|
||||||
|
@ -1663,7 +1664,7 @@ class DATA:
|
||||||
print(self.rpt_request_buffer)
|
print(self.rpt_request_buffer)
|
||||||
|
|
||||||
tempbuffer_rptframes = []
|
tempbuffer_rptframes = []
|
||||||
for i in range(0, len(missing_area)):
|
for i in range(len(missing_area)):
|
||||||
print(missing_area[i])
|
print(missing_area[i])
|
||||||
missing_frames_buffer_position = missing_area[i] - 1
|
missing_frames_buffer_position = missing_area[i] - 1
|
||||||
tempbuffer_rptframes.append(self.rpt_request_buffer[missing_frames_buffer_position])
|
tempbuffer_rptframes.append(self.rpt_request_buffer[missing_frames_buffer_position])
|
||||||
|
@ -2134,7 +2135,7 @@ class DATA:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
arq_transmit
|
|
||||||
def arq_open_data_channel(
|
def arq_open_data_channel(
|
||||||
self, mycallsign
|
self, mycallsign
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
|
@ -13,6 +13,8 @@ import structlog
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import threading
|
import threading
|
||||||
import mesh
|
import mesh
|
||||||
|
import hashlib
|
||||||
|
import hmac
|
||||||
|
|
||||||
log = structlog.get_logger("helpers")
|
log = structlog.get_logger("helpers")
|
||||||
|
|
||||||
|
@ -494,7 +496,7 @@ 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_{int(time.time())}_{dxcallsign}_{mycallsign}.txt"
|
filename = f"freedata_hmac_tokens_{dxcallsign}_{mycallsign}.txt"
|
||||||
try:
|
try:
|
||||||
with open(filename, "w") as file:
|
with open(filename, "w") as file:
|
||||||
line = file.readlines()
|
line = file.readlines()
|
||||||
|
@ -503,6 +505,25 @@ def get_hmac_salt(dxcallsign: bytes, mycallsign: bytes):
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def search_hmac_salt(dxcallsign: bytes, mycallsign: bytes, search_token, data_frame, token_iters):
|
||||||
|
try:
|
||||||
|
filename = f"freedata_hmac_tokens_{dxcallsign}_{mycallsign}.txt"
|
||||||
|
with open(filename, "w") as file:
|
||||||
|
token_list = file.readlines()
|
||||||
|
|
||||||
|
token_iters = min(token_iters, len(token_list))
|
||||||
|
for _ in range(1, token_iters + 1):
|
||||||
|
key = token_list[len(token_list) - _][:-1]
|
||||||
|
search_digest = hmac.new(key, data_frame, hashlib.sha256).digest()[:4]
|
||||||
|
if search_token == search_digest:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def delete_last_line_from_hmac_list(filename):
|
def delete_last_line_from_hmac_list(filename):
|
||||||
try:
|
try:
|
||||||
linearray = []
|
linearray = []
|
||||||
|
|
|
@ -17,9 +17,9 @@ def create_hmac_salts(dxcallsign: str, mycallsign: str, num_tokens: int = 10000)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Create and write random strings to a file
|
# Create and write random strings to a file
|
||||||
with open(f"freedata_hmac_tokens_{int(time.time())}_{dxcallsign}_{mycallsign}.txt", "w") as file:
|
with open(f"freedata_hmac_tokens_{dxcallsign}_{mycallsign}.txt", "w") as file:
|
||||||
for _ in range(num_tokens):
|
for _ in range(num_tokens):
|
||||||
random_str = np.random.bytes(16).hex()
|
random_str = np.random.bytes(4).hex()
|
||||||
file.write(random_str + '\n')
|
file.write(random_str + '\n')
|
||||||
except Exception:
|
except Exception:
|
||||||
print("error creating hmac file")
|
print("error creating hmac file")
|
||||||
|
|
Loading…
Reference in a new issue