channel migration better handles missing or invalid certificates

This commit is contained in:
Lex Berezhny 2019-06-23 12:55:24 -04:00
parent 8a5bb239c5
commit d0e1468acd
3 changed files with 18 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import lbry.wallet
from lbry.conf import Config from lbry.conf import Config
from lbry.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty from lbry.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty
from lbry.wallet import LbryWalletManager from lbry.wallet import LbryWalletManager
from lbry.wallet.account import Account
from lbry.extras.daemon.Components import Component, WalletComponent from lbry.extras.daemon.Components import Component, WalletComponent
from lbry.extras.daemon.Components import ( from lbry.extras.daemon.Components import (
DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT,
@ -63,6 +64,8 @@ class CommandTestCase(IntegrationTestCase):
VERBOSITY = logging.WARN VERBOSITY = logging.WARN
blob_lru_cache_size = 0 blob_lru_cache_size = 0
account: Account
async def asyncSetUp(self): async def asyncSetUp(self):
await super().asyncSetUp() await super().asyncSetUp()

View file

@ -53,6 +53,10 @@ class Account(BaseAccount):
return return
channel_keys = {} channel_keys = {}
for private_key_pem in self.channel_keys.values(): for private_key_pem in self.channel_keys.values():
if not isinstance(private_key_pem, str):
continue
if "-----BEGIN EC PRIVATE KEY-----" not in private_key_pem:
continue
private_key = ecdsa.SigningKey.from_pem(private_key_pem, hashfunc=sha256) private_key = ecdsa.SigningKey.from_pem(private_key_pem, hashfunc=sha256)
public_key_der = private_key.get_verifying_key().to_der() public_key_der = private_key.get_verifying_key().to_der()
channel_keys[self.ledger.public_key_to_address(public_key_der)] = private_key_pem channel_keys[self.ledger.public_key_to_address(public_key_der)] = private_key_pem

View file

@ -54,3 +54,14 @@ class AccountManagement(CommandTestCase):
# list specific account # list specific account
response = await self.daemon.jsonrpc_account_list(account_id, include_claims=True) response = await self.daemon.jsonrpc_account_list(account_id, include_claims=True)
self.assertEqual(response['name'], 'recreated account') self.assertEqual(response['name'], 'recreated account')
async def test_wallet_migration(self):
# null certificates should get deleted
await self.channel_create('@foo1')
await self.channel_create('@foo2')
await self.channel_create('@foo3')
keys = list(self.account.channel_keys.keys())
self.account.channel_keys[keys[0]] = None
self.account.channel_keys[keys[1]] = "some invalid junk"
await self.account.maybe_migrate_certificates()
self.assertEqual(list(self.account.channel_keys.keys()), [keys[2]])