bugfix and bulletproof

This commit is contained in:
emdee 2022-10-07 04:41:54 +00:00
parent a871c2a681
commit 3ab429628a

View file

@ -241,16 +241,15 @@ def lProcessGroups(state, index, length, result, label="GROUPS"):
""" """
global sENC global sENC
lIN = [] lIN = []
i = 0
if not msgpack: if not msgpack:
LOG.warn(f"process_chunk Groups = NO msgpack bytes={length}") LOG.warn(f"process_chunk Groups = NO msgpack bytes={length}")
return [] return []
try: try:
groups = msgpack.loads(result, raw=True) groups = msgpack.loads(result, raw=True)
LOG.info(f"{label} {len(groups)} groups") LOG.info(f"{label} {len(groups)} groups")
i = 0
for group in groups: for group in groups:
assert len(group) == 7, group assert len(group) == 7, group
i += 1
state_values, \ state_values, \
state_bin, \ state_bin, \
@ -260,76 +259,105 @@ def lProcessGroups(state, index, length, result, label="GROUPS"):
self_info, \ self_info, \
saved_peers, = group saved_peers, = group
assert len(state_values) == 8, state_values if state_values is None:
manually_disconnected, \ LOG.warn(f"lProcessGroups #{i} state_values is None")
group_name_len, \ else:
privacy_state, \ assert len(state_values) == 8, state_values
maxpeers, \ manually_disconnected, \
password_length, \ group_name_len, \
version, \ privacy_state, \
topic_lock, \ maxpeers, \
voice_state = state_values password_length, \
LOG.info(f"lProcessGroups #{i} version={version}") version, \
dBINS = {"Version": version, topic_lock, \
"Privacy_state": privacy_state} voice_state = state_values
lIN += [{"State_values": dBINS}] LOG.info(f"lProcessGroups #{i} version={version}")
dBINS = {"Version": version,
"Privacy_state": privacy_state}
lIN += [{"State_values": dBINS}]
assert len(state_bin) == 5, state_bin if state_bin is None:
shared_state_sig, \ LOG.warn(f"lProcessGroups #{i} state_bin is None")
founder_public_key, \ else:
group_name_len, \ assert len(state_bin) == 5, state_bin
password_length, \ shared_state_sig, \
mod_list_hash = state_bin founder_public_key, \
LOG.info(f"lProcessGroups #{i} founder_public_key={bin_to_hex(founder_public_key)}") group_name_len, \
dBINS = {"Founder_public_key": bin_to_hex(founder_public_key)} password_length, \
lIN += [{"State_bin": dBINS}] mod_list_hash = state_bin
LOG.info(f"lProcessGroups #{i} founder_public_key={bin_to_hex(founder_public_key)}")
dBINS = {"Founder_public_key": bin_to_hex(founder_public_key)}
lIN += [{"State_bin": dBINS}]
assert len(topic_info) == 6, topic_info if topic_info is None:
topic_info_topic = str(topic_info[3], sENC) LOG.warn(f"lProcessGroups #{i} topic_info is None")
LOG.info(f"lProcessGroups #{i} topic_info_topic={topic_info_topic}") else:
dBINS = {"topic_info_topic": topic_info_topic} assert len(topic_info) == 6, topic_info
lIN += [{"Topic_info": dBINS}] topic_info_topic = str(topic_info[3], sENC)
LOG.info(f"lProcessGroups #{i} topic_info_topic={topic_info_topic}")
dBINS = {"topic_info_topic": topic_info_topic}
lIN += [{"Topic_info": dBINS}]
assert len(mod_list) == 2, mod_list if mod_list is None:
num_moderators = mod_list[0] LOG.warn(f"lProcessGroups #{i} mod_list is None")
LOG.info(f"lProcessGroups #{i} num moderators={mod_list[0]}") else:
#define CRYPTO_SIGN_PUBLIC_KEY_SIZE 32 assert len(mod_list) == 2, mod_list
mods = mod_list[1] num_moderators = mod_list[0]
assert len(mods) % 32 == 0, len(mods) LOG.info(f"lProcessGroups #{i} num moderators={mod_list[0]}")
assert len(mods) == num_moderators * 32, len(mods) #define CRYPTO_SIGN_PUBLIC_KEY_SIZE 32
lMODS = [] lMODS = []
for j in range(num_moderators): if not num_moderators:
mod = mods[j*32:j*32 + 32] LOG.warn(f"lProcessGroups #{i} num_moderators is 0")
LOG.info(f"lProcessGroups group#{i} mod#{j} sig_pk={bin_to_hex(mod)}") else:
lMODS += [{"Sig_pk": bin_to_hex(mod)}] mods = mod_list[1]
lIN += [{"Moderators": lMODS}] assert len(mods) % 32 == 0, len(mods)
assert len(mods) == num_moderators * 32, len(mods)
for j in range(num_moderators):
mod = mods[j*32:j*32 + 32]
LOG.info(f"lProcessGroups group#{i} mod#{j} sig_pk={bin_to_hex(mod)}")
lMODS += [{"Sig_pk": bin_to_hex(mod)}]
lIN += [{"Moderators": lMODS}]
assert len(keys) == 4, keys if keys is None:
LOG.debug(f"lProcessGroups #{i} {repr(list(map(len, keys)))}") LOG.warn(f"lProcessGroups #{i} keys is None")
chat_public_key, \ else:
chat_secret_key, \ assert len(keys) == 4, keys
self_public_key, \ LOG.debug(f"lProcessGroups #{i} {repr(list(map(len, keys)))}")
self_secret_key = keys chat_public_key, \
LOG.info(f"lProcessGroups #{i} chat_public_key={bin_to_hex(chat_public_key)}") chat_secret_key, \
lIN[0].update({"Chat_public_key": bin_to_hex(chat_public_key)}) self_public_key, \
if int(bin_to_hex(chat_secret_key), 16) != 0: self_secret_key = keys
# 192 * b'0' LOG.info(f"lProcessGroups #{i} chat_public_key={bin_to_hex(chat_public_key)}")
LOG.info(f"lProcessGroups #{i} chat_secret_key={bin_to_hex(chat_secret_key)}") lIN[0].update({"Chat_public_key": bin_to_hex(chat_public_key)})
lIN[0].update({"Chat_secret_key": bin_to_hex(chat_secret_key)}) if int(bin_to_hex(chat_secret_key), 16) != 0:
# 192 * b'0'
LOG.info(f"lProcessGroups #{i} chat_secret_key={bin_to_hex(chat_secret_key)}")
lIN[0].update({"Chat_secret_key": bin_to_hex(chat_secret_key)})
LOG.info(f"lProcessGroups #{i} self_public_key={bin_to_hex(self_public_key)}") LOG.info(f"lProcessGroups #{i} self_public_key={bin_to_hex(self_public_key)}")
lIN[0].update({"Self_public_key": bin_to_hex(self_public_key)}) lIN[0].update({"Self_public_key": bin_to_hex(self_public_key)})
LOG.info(f"lProcessGroups #{i} self_secret_key={bin_to_hex(self_secret_key)}") LOG.info(f"lProcessGroups #{i} self_secret_key={bin_to_hex(self_secret_key)}")
lIN[0].update({"Self_secret_key": bin_to_hex(self_secret_key)}) lIN[0].update({"Self_secret_key": bin_to_hex(self_secret_key)})
assert len(self_info) == 4, self_info if self_info is None:
self_nick_len, self_role, self_status, self_nick = self_info LOG.warn(f"lProcessGroups #{i} self_info is None")
self_nick = str(self_nick, sENC) else:
LOG.info(f"lProcessGroups #{i} self_nick={self_nick}") assert len(self_info) == 4, self_info
dBINS = {"Self_nick": self_nick} self_nick_len, self_role, self_status, self_nick = self_info
lIN += [{"Self_info": dBINS}] self_nick = str(self_nick, sENC)
dBINS = {"Self_nick": self_nick,
"Self_role": self_role,
"Self_status": self_status,
"Self_info": self_info,
}
LOG.info(f"lProcessGroups #{i} {repr(dBINS)}")
lIN += [dBINS]
assert len(saved_peers) == 2, saved_peers if saved_peers is None:
LOG.warn(f"lProcessGroups #{i} saved_peers is None")
else:
assert len(saved_peers) == 2, saved_peers
i += 1
except Exception as e: except Exception as e:
LOG.warn(f"process_chunk Groups #{i} error={e}") LOG.warn(f"process_chunk Groups #{i} error={e}")
@ -381,9 +409,9 @@ The Node Info data structure contains a Transport Protocol, a Socket
"Ip": ipaddr, "Ip": ipaddr,
"Port": port, "Port": port,
"Pk": pk}] "Pk": pk}]
relay += 1
delta += total delta += total
length -= total length -= total
relay += 1
return lIN return lIN
def lProcessDHTnodes(state, index, length, result, label="DHTnode"): def lProcessDHTnodes(state, index, length, result, label="DHTnode"):
@ -427,9 +455,9 @@ def lProcessDHTnodes(state, index, length, result, label="DHTnode"):
"Port": port, "Port": port,
"Pk": pk}] "Pk": pk}]
offset += subtotal offset += subtotal
relay += 1
delta += total delta += total
length -= total length -= total
relay += 1
return lIN return lIN
def process_chunk(index, state, oArgs=None): def process_chunk(index, state, oArgs=None):