1
0

add encryption version to channel backups

This commit is contained in:
ThomasV
2020-06-16 10:42:47 +02:00
parent cb4c8abe1c
commit 26ae6d68a3
6 changed files with 49 additions and 16 deletions

View File

@@ -67,6 +67,7 @@ from .address_synchronizer import TX_HEIGHT_LOCAL
from . import lnsweep
from .lnwatcher import LNWalletWatcher
from .crypto import pw_encode_bytes, pw_decode_bytes, PW_HASH_VERSION_LATEST
from .crypto import pw_encode_b64_with_version, pw_decode_b64_with_version
from .lnutil import ChannelBackupStorage
from .lnchannel import ChannelBackup
from .channel_db import UpdateStatus
@@ -1396,9 +1397,9 @@ class LNWallet(LNWorker):
xpub = self.wallet.get_fingerprint()
backup_bytes = self.create_channel_backup(channel_id).to_bytes()
assert backup_bytes == ChannelBackupStorage.from_bytes(backup_bytes).to_bytes(), "roundtrip failed"
encrypted = pw_encode_bytes(backup_bytes, xpub, version=PW_HASH_VERSION_LATEST)
assert backup_bytes == pw_decode_bytes(encrypted, xpub, version=PW_HASH_VERSION_LATEST), "encrypt failed"
return encrypted
encrypted = pw_encode_b64_with_version(backup_bytes, xpub)
assert backup_bytes == pw_decode_b64_with_version(encrypted, xpub), "encrypt failed"
return 'channel_backup:' + encrypted
class LNBackups(Logger):
@@ -1449,9 +1450,11 @@ class LNBackups(Logger):
self.lnwatcher.stop()
self.lnwatcher = None
def import_channel_backup(self, encrypted):
def import_channel_backup(self, data):
assert data.startswith('channel_backup:')
encrypted = data[15:]
xpub = self.wallet.get_fingerprint()
decrypted = pw_decode_bytes(encrypted, xpub, version=PW_HASH_VERSION_LATEST)
decrypted = pw_decode_b64_with_version(encrypted, xpub)
cb_storage = ChannelBackupStorage.from_bytes(decrypted)
channel_id = cb_storage.channel_id().hex()
d = self.db.get_dict("channel_backups")