From 215cf67984345cc2999f8c705a13b162559b00fe Mon Sep 17 00:00:00 2001 From: Veselin Penev Date: Sun, 12 Nov 2023 21:36:56 +0100 Subject: [PATCH] several bug fixes (#191) --- CHANGELOG.txt | 10 +++ Makefile | 2 +- bitdust/stream/message_peddler.py | 2 +- bitdust/supplier/customer_space.py | 2 +- bitdust/system/deploy.py | 5 +- bitdust/userid/id_server.py | 6 +- bitdust/userid/id_url.py | 2 + .../Bismuth/bismuthclient/bismuthclient.py | 36 +++++------ .../Bismuth/bismuthclient/bismuthcrypto.py | 62 +++++++++---------- .../bismuthclient/bismuthmultiwallet.py | 40 ++++++------ bitdust_forks/Bismuth/config.txt | 33 ---------- 11 files changed, 93 insertions(+), 107 deletions(-) delete mode 100644 bitdust_forks/Bismuth/config.txt diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e2e3fd2..09b5d04 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,16 @@ Change Log ========== +2023-11-12 Veselin Penev [penev.veselin@gmail.com](mailto:penev.veselin@gmail.com) + +* bug fix in bitdust/system/deploy.py related to python3.11 +* IDURL fix in bitdust/supplier/customer_space.py +* bug fix in butdust/userid/id_url.py +* disabled un-used Bismuth crypto methods +* Bump twisted from 22.4.0 to 23.8.0 + + + 2023-10-24 Veselin Penev [penev.veselin@gmail.com](mailto:penev.veselin@gmail.com) * removed bitdust_forks/Bismuth/wallet/ diff --git a/Makefile b/Makefile index 8c7c0ed..df1ecf4 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,7 @@ regress_run: PYTHON_VERSION=$(REGRESSION_PY_VER) _PAUSE_BEFORE=0 make --no-print-directory -C regress/ run_all regress_run_parallel: - PYTHON_VERSION=$(REGRESSION_PY_VER) _PAUSE_BEFORE=0 make --no-print-directory -j 3 -C regress/ run_parallel + PYTHON_VERSION=$(REGRESSION_PY_VER) _PAUSE_BEFORE=0 make --no-print-directory -j 1 -C regress/ run_parallel regress_run_log: PYTHON_VERSION=$(REGRESSION_PY_VER) make --no-print-directory -C regress/ run_all_log diff --git a/bitdust/stream/message_peddler.py b/bitdust/stream/message_peddler.py index e2ed882..6066f63 100644 --- a/bitdust/stream/message_peddler.py +++ b/bitdust/stream/message_peddler.py @@ -1877,7 +1877,7 @@ def _on_queue_keeper_connect_failed(self, err, consumer_id, producer_id, group_k try: evt, args, kwargs = err.value.args except: - lg.exc() + lg.exc(msg=repr(err)) return None if _Debug: lg.args(_DebugLevel, event=evt, args=args, kwargs=kwargs) diff --git a/bitdust/supplier/customer_space.py b/bitdust/supplier/customer_space.py index 2906309..f30b652 100644 --- a/bitdust/supplier/customer_space.py +++ b/bitdust/supplier/customer_space.py @@ -193,7 +193,7 @@ def verify_ownership(newpacket, raise_exception=False): if _Debug: lg.args(_DebugLevel, owner_id=owner_id, creator_id=creator_id, customer_id=packet_owner_id, key_registered=packet_key_id_registered) if newpacket.Command == commands.Data(): - if owner_idurl == creator_idurl: + if id_url.is_the_same(owner_idurl, creator_idurl): if contactsdb.is_customer(creator_idurl): if _Debug: lg.dbg(_DebugLevel, 'OK, scenario 1: customer is sending own data to own supplier') diff --git a/bitdust/system/deploy.py b/bitdust/system/deploy.py index 3f8fb60..3a87833 100644 --- a/bitdust/system/deploy.py +++ b/bitdust/system/deploy.py @@ -281,7 +281,10 @@ def run(args): python_exe = current_python make_venv_cmd = '{} -m virtualenv --system-site-packages {}'.format(python_exe, venv_path) if on_mac: - make_venv_cmd = '{} -m virtualenv --clear --always-copy {}'.format(current_python, venv_path) + if sys.version_info >= (3, 11): + make_venv_cmd = '{} -m venv --clear --copies {}'.format(current_python, venv_path) + else: + make_venv_cmd = '{} -m virtualenv --clear --always-copy {}'.format(current_python, venv_path) print_text('\n***** Executing "{}"'.format(make_venv_cmd)) status = os.system(make_venv_cmd) diff --git a/bitdust/userid/id_server.py b/bitdust/userid/id_server.py index 231d03b..a78e7d5 100644 --- a/bitdust/userid/id_server.py +++ b/bitdust/userid/id_server.py @@ -244,10 +244,14 @@ def _save_identity(self, inputfilename): lg.warn('input file too small - ignoring') tmpfile.erase('idsrv', inputfilename, 'input file too small') return + if not newxml.startswith(''): + lg.warn('input file is not an XML - ignoring') + tmpfile.erase('idsrv', inputfilename, 'input file is not an XML') + return try: newidentity = identity.identity(xmlsrc=newxml) except: - lg.warn('input file is wrong - ignoring ') + lg.warn('input file is wrong - ignoring') tmpfile.erase('idsrv', inputfilename, 'input file is wrong') return tmpfile.erase('idsrv', inputfilename, 'id received') diff --git a/bitdust/userid/id_url.py b/bitdust/userid/id_url.py index 2732fe7..075b0f0 100644 --- a/bitdust/userid/id_url.py +++ b/bitdust/userid/id_url.py @@ -101,6 +101,8 @@ def init(): for_cleanup = [] for one_user_dir in os.listdir(_IdentityHistoryDir): one_user_dir_path = os.path.join(_IdentityHistoryDir, one_user_dir) + if not os.path.isdir(one_user_dir_path): + continue one_user_identity_files = [] for one_filename in os.listdir(one_user_dir_path): try: diff --git a/bitdust_forks/Bismuth/bismuthclient/bismuthclient.py b/bitdust_forks/Bismuth/bismuthclient/bismuthclient.py index 3857b94..bf6fff5 100644 --- a/bitdust_forks/Bismuth/bismuthclient/bismuthclient.py +++ b/bitdust_forks/Bismuth/bismuthclient/bismuthclient.py @@ -429,24 +429,24 @@ def load_wallet(self, wallet_file='wallet.der'): self.clear_cache() self.address = self._wallet.address - def load_multi_wallet(self, wallet_file='wallet.json'): - """ - Tries to load the wallet file - - :param wallet_file: string, a wallet.json file - """ - # TODO: Refactor - self.wallet_file = None - self.address = None - self._wallet = None - self._wallet = BismuthMultiWallet(wallet_file, verbose=self.verbose) - if len(self._wallet._data["addresses"]) == 0: - # Create a first address by default - self._wallet.new_address(label="default") - self.wallet_file = wallet_file - if self.address != self._wallet.address: - self.clear_cache() - self.address = self._wallet.address + # def load_multi_wallet(self, wallet_file='wallet.json'): + # """ + # Tries to load the wallet file + # + # :param wallet_file: string, a wallet.json file + # """ + # # TODO: Refactor + # self.wallet_file = None + # self.address = None + # self._wallet = None + # self._wallet = BismuthMultiWallet(wallet_file, verbose=self.verbose) + # if len(self._wallet._data["addresses"]) == 0: + # # Create a first address by default + # self._wallet.new_address(label="default") + # self.wallet_file = wallet_file + # if self.address != self._wallet.address: + # self.clear_cache() + # self.address = self._wallet.address def set_address(self, address: str=''): if not type(self._wallet) == BismuthMultiWallet: diff --git a/bitdust_forks/Bismuth/bismuthclient/bismuthcrypto.py b/bitdust_forks/Bismuth/bismuthclient/bismuthcrypto.py index 275bbca..335a894 100644 --- a/bitdust_forks/Bismuth/bismuthclient/bismuthcrypto.py +++ b/bitdust_forks/Bismuth/bismuthclient/bismuthcrypto.py @@ -199,37 +199,37 @@ def keys_new(keyfile): return True -def keys_gen(password: str='', salt: str='', count=10000, verbose=False): - """ - Optionnally deterministic RSA Key generation from password and salt. To be used by tests only atm. - :param password: - :param salt: - :param count: - :param verbose: - :return: - """ - if password: - def my_rand(n): - # kluge: use PBKDF2 with count=1 and incrementing salt as deterministic PRNG - my_rand.counter += 1 - return PBKDF2(master_key, "my_rand:%d" % my_rand.counter, dkLen=n, count=1) - if verbose: - print("Generating master key") - master_key = PBKDF2(password, salt, count=count) - my_rand.counter = 0 - if verbose: - print("Generating RSA key") - key = RSA.generate(4096, randfunc=my_rand) - else: - if verbose: - print("Generating RSA key") - key = RSA.generate(4096) - # public_key = key.publickey() - private_key_readable = key.exportKey().decode("utf-8") - public_key_readable = key.publickey().exportKey().decode("utf-8") - address = hashlib.sha224(public_key_readable.encode("utf-8")).hexdigest() # hashed public key - # export to single file - return {'private_key': private_key_readable, 'public_key': public_key_readable, 'address': address} +# def keys_gen(password: str='', salt: str='', count=10000, verbose=False): +# """ +# Optionnally deterministic RSA Key generation from password and salt. To be used by tests only atm. +# :param password: +# :param salt: +# :param count: +# :param verbose: +# :return: +# """ +# if password: +# def my_rand(n): +# # kluge: use PBKDF2 with count=1 and incrementing salt as deterministic PRNG +# my_rand.counter += 1 +# return PBKDF2(master_key, "my_rand:%d" % my_rand.counter, dkLen=n, count=1) +# if verbose: +# print("Generating master key") +# master_key = PBKDF2(password, salt, count=count) +# my_rand.counter = 0 +# if verbose: +# print("Generating RSA key") +# key = RSA.generate(4096, randfunc=my_rand) +# else: +# if verbose: +# print("Generating RSA key") +# key = RSA.generate(4096) +# # public_key = key.publickey() +# private_key_readable = key.exportKey().decode("utf-8") +# public_key_readable = key.publickey().exportKey().decode("utf-8") +# address = hashlib.sha224(public_key_readable.encode("utf-8")).hexdigest() # hashed public key +# # export to single file +# return {'private_key': private_key_readable, 'public_key': public_key_readable, 'address': address} def keys_save(private_key_readable, public_key_readable, address, file): diff --git a/bitdust_forks/Bismuth/bismuthclient/bismuthmultiwallet.py b/bitdust_forks/Bismuth/bismuthclient/bismuthmultiwallet.py index c2932e7..a0d2682 100644 --- a/bitdust_forks/Bismuth/bismuthclient/bismuthmultiwallet.py +++ b/bitdust_forks/Bismuth/bismuthclient/bismuthmultiwallet.py @@ -235,26 +235,26 @@ def new(self, wallet_file='wallet.der'): return True """ - def new_address(self, label: str='', password: str='', salt: str='', type="RSA"): - """ - Add a new address to the wallet (and save it) - """ - if type != "RSA": - raise RuntimeError("Only RSA is available for now") - if self._infos['encrypted'] and self._locked: - raise RuntimeError("Wallet must be unlocked") - keys = bismuthcrypto.keys_gen(password=password, salt=salt) - keys['label'] = label - keys['timestamp'] = int(time()) - self._addresses.append(keys) - if self._infos['encrypted']: - content = json.dumps(keys) - encrypted = b64encode(encrypt(self._master_password, content, level=1)).decode('utf-8') - self._data['addresses'].append(encrypted) - else: - print('1') - self._data['addresses'].append(keys) - self.save() + # def new_address(self, label: str='', password: str='', salt: str='', type="RSA"): + # """ + # Add a new address to the wallet (and save it) + # """ + # if type != "RSA": + # raise RuntimeError("Only RSA is available for now") + # if self._infos['encrypted'] and self._locked: + # raise RuntimeError("Wallet must be unlocked") + # keys = bismuthcrypto.keys_gen(password=password, salt=salt) + # keys['label'] = label + # keys['timestamp'] = int(time()) + # self._addresses.append(keys) + # if self._infos['encrypted']: + # content = json.dumps(keys) + # encrypted = b64encode(encrypt(self._master_password, content, level=1)).decode('utf-8') + # self._data['addresses'].append(encrypted) + # else: + # print('1') + # self._data['addresses'].append(keys) + # self.save() def set_label(self, address:str ='', label: str=''): """ diff --git a/bitdust_forks/Bismuth/config.txt b/bitdust_forks/Bismuth/config.txt deleted file mode 100644 index f26f1ba..0000000 --- a/bitdust_forks/Bismuth/config.txt +++ /dev/null @@ -1,33 +0,0 @@ -port=5658 -verify=False -version=mainnet0021 -version_allow=mainnet0020,mainnet0021,mainnet0022 -thread_limit=64 -rebuild_db=True -debug=False -debug_level=DEBUG -purge=True -pause=6 -hyper_path=static/hyper.db -hyper_recompress=True -full_ledger=True -ledger_path=static/ledger.db -ban_threshold=30 -tor=False -allowed=127.0.0.1,192.168.0.1,any -ram=False -node_ip=127.0.0.1 -light_ip={"127.0.0.1": "5658", "185.204.2.109": "5658"} -reveal_address=True -accept_peers=True -banlist=127.1.2.3 -whitelist=127.0.0.1 -nodes_ban_reset=5 -mempool_allowed=1aae2cfe5d01acc8d7cbc90fcf8bb715ca24927504d0d8071c0979c7 -terminal_output=False -gui_scaling=adapt -mempool_ram=False -egress=True -trace_db_calls=False -heavy3_path=./heavy3a.bin -# mempool_ram_conf=False