Get rid of default crypto key; use random one at startup
This commit is contained in:
parent
ccbb058e9d
commit
949a42ad34
11
conn.py
11
conn.py
@ -149,6 +149,12 @@ class Connection(metaclass=Singleton):
|
||||
logging.info(f"Starting hidden service: %s" % BP['onion_addr'])
|
||||
asyncio.create_task(TOR.start_tunnel())
|
||||
|
||||
h = STATUS.hsm
|
||||
if ('summary' in h) and h.summary and not BP.get('priv_over_ux') and not BP.get('summary'):
|
||||
logging.info("Captured CC's summary of the policy")
|
||||
BP['summary'] = h.summary
|
||||
BP.save()
|
||||
|
||||
STATUS.reset_pending_auth()
|
||||
STATUS.notify_watchers()
|
||||
|
||||
@ -195,11 +201,6 @@ class Connection(metaclass=Singleton):
|
||||
# won't be required
|
||||
STATUS.local_code = None
|
||||
|
||||
if ('summary' in h) and h.summary and not BP.get('priv_over_ux') and not BP.get('summary'):
|
||||
logging.info("Captured CC's summary of the policy")
|
||||
BP['summary'] = h.summary
|
||||
BP.save()
|
||||
|
||||
# has it just transitioned into HSM mode?
|
||||
if STATUS.connected and STATUS.hsm.active and not b4:
|
||||
await self.activated_hsm()
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
# Data Files
|
||||
|
||||
- this directory will hold data files for the Bunker
|
||||
- they are encrypted with a private key held in the "storage locker" of the Coldcard
|
||||
- contents include Tor hidden service private key and settings
|
||||
- they are encrypted with a private key held in the "storage locker" of a Coldcard
|
||||
- contents include Tor hidden service private key and settings for Bunker
|
||||
- filename based on key
|
||||
- default key maps to `bp-1850f665aa1e22c0.dat`
|
||||
- you may see unused junk accumulate in this directory; those are random keys that
|
||||
never got saved as a policy file for any Coldcard
|
||||
|
||||
@ -115,12 +115,9 @@ it reads the storage locker and uses the NaCl private key (32 bytes)
|
||||
to select and open the corresponding Bunker settings file. Therefore,
|
||||
each Coldcard has it's own settings for the Bunker.
|
||||
|
||||
Before a Coldcard is connected, or before the policy is saved for
|
||||
the first time, the settings are held with a fixed key, and end up
|
||||
in file: `data/bp-1850f665aa1e22c0.dat` based on that key. At the
|
||||
point where you upload a new policy to a Coldcard, a new key is
|
||||
picked and added to the policy file. Data on disk at that point is
|
||||
re-encrypted and moved over.
|
||||
In setup mode, bunker settings are effectively not saved until
|
||||
the NaCL secret is saved into the policy of a Coldcard and saved
|
||||
there.
|
||||
|
||||
|
||||
#### Other Notes
|
||||
|
||||
19
persist.py
19
persist.py
@ -39,10 +39,6 @@ class Settings(metaclass=Singleton):
|
||||
# path to data files
|
||||
DATA_FILES = './data'
|
||||
|
||||
# used during secret/when we don't have a key yet
|
||||
# - maps to data/bp-1850f665aa1e22c0.dat
|
||||
PLACEHOLDER_KEY = b'ab'*16
|
||||
|
||||
# endpoint to use for sending txn; we assume it's Explora protocol (Blockstream.info)
|
||||
EXPLORA = 'http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion'
|
||||
|
||||
@ -111,12 +107,13 @@ class BunkerPersistance(WatchableMixin, dict, metaclass=Singleton):
|
||||
|
||||
def __init__(self):
|
||||
super(BunkerPersistance, self).__init__()
|
||||
self.key = None
|
||||
self.filename = None
|
||||
self.set_defaults()
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
self.open(settings.PLACEHOLDER_KEY)
|
||||
self.clear()
|
||||
self.set_secret(os.urandom(32))
|
||||
self.set_defaults()
|
||||
|
||||
def set_defaults(self):
|
||||
# defaults here
|
||||
@ -135,11 +132,6 @@ class BunkerPersistance(WatchableMixin, dict, metaclass=Singleton):
|
||||
bn = 'bp-%s.dat' % sha256(sha256(b'salty' + self.key).digest()).hexdigest()[-16:].lower()
|
||||
self.filename = os.path.join(settings.DATA_FILES, bn)
|
||||
|
||||
@staticmethod
|
||||
def new_secret():
|
||||
# rotate key
|
||||
return os.urandom(32)
|
||||
|
||||
def open(self, key):
|
||||
# Given a private key (via storage locker) open a Nacl secret box
|
||||
# and use that for the data.
|
||||
@ -182,8 +174,5 @@ class BunkerPersistance(WatchableMixin, dict, metaclass=Singleton):
|
||||
except:
|
||||
pass
|
||||
|
||||
def is_default_secret(self):
|
||||
return self.key == settings.PLACEHOLDER_KEY
|
||||
|
||||
|
||||
# EOF
|
||||
|
||||
@ -129,13 +129,8 @@ def update_sl(proposed):
|
||||
xk = None
|
||||
|
||||
if not xk:
|
||||
if not BP.key or BP.is_default_secret():
|
||||
# pick a new key
|
||||
logging.info("Making new secret for holding Bunker settings")
|
||||
xk = BP.new_secret()
|
||||
else:
|
||||
# keep using same key
|
||||
xk = BP.key
|
||||
# capture settings key
|
||||
xk = BP.key
|
||||
|
||||
assert len(xk) == 32
|
||||
proposed['set_sl'] = b64encode(b'Bunk' + xk).decode('ascii')
|
||||
|
||||
@ -480,9 +480,10 @@ async def ws_api_handler(ses, send_json, req, orig_request): # handle_api
|
||||
|
||||
if not BP['tor_enabled']:
|
||||
await TOR.stop_tunnel()
|
||||
elif BP.get('onion_pk') and not (STATUS.force_local_mode or STATUS.setup_mode):
|
||||
# connect/reconnect
|
||||
await TOR.start_tunnel()
|
||||
elif BP.get('onion_pk') and not (STATUS.force_local_mode or STATUS.setup_mode) \
|
||||
and TOR.get_current_addr() != BP.get('onion_addr'):
|
||||
# disconnect/reconnect
|
||||
await TOR.start_tunnel()
|
||||
|
||||
elif action == 'sign_message':
|
||||
# sign a short text message
|
||||
|
||||
Loading…
Reference in New Issue
Block a user