2022-01-21 20:37:48 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021 Citadel and contributors
|
2021-10-22 15:22:10 +00:00
|
|
|
#
|
2022-01-21 20:37:48 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2021-10-22 15:22:10 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
scriptDir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
nodeRoot = os.path.join(scriptDir, "..", "..")
|
|
|
|
|
|
|
|
def deriveEntropy(identifier: str):
|
|
|
|
seedFile = os.path.join(nodeRoot, "db", "citadel-seed", "seed")
|
2022-01-28 06:49:36 +00:00
|
|
|
alternativeSeedFile = os.path.join(nodeRoot, "..", "db", "citadel-seed", "seed")
|
2021-10-22 15:22:10 +00:00
|
|
|
if not os.path.isfile(seedFile):
|
2021-11-17 18:04:06 +00:00
|
|
|
if os.path.isfile(alternativeSeedFile):
|
2021-10-22 15:22:10 +00:00
|
|
|
seedFile = alternativeSeedFile
|
|
|
|
else:
|
|
|
|
print("No seed file found, exiting...")
|
|
|
|
exit(1)
|
|
|
|
with open(seedFile, "r") as f:
|
|
|
|
node_seed = f.read().strip()
|
|
|
|
entropy = subprocess.check_output(
|
|
|
|
'printf "%s" "{}" | openssl dgst -sha256 -binary -hmac "{}" | xxd -p | tr --delete "\n"'.format(identifier, node_seed), shell=True)
|
|
|
|
return entropy.decode("utf-8")
|