Browse Source

keystore: fail sooner if unsupported version

follow-up #4937
3.3.3.1
SomberNight 6 years ago
parent
commit
8f5f0e46aa
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 6
      electrum/crypto.py
  2. 5
      electrum/keystore.py
  3. 5
      electrum/storage.py

6
electrum/crypto.py

@ -31,7 +31,7 @@ from typing import Union
import pyaes
from .util import assert_bytes, InvalidPassword, to_bytes, to_string
from .util import assert_bytes, InvalidPassword, to_bytes, to_string, WalletFileException
from .i18n import _
@ -123,7 +123,7 @@ assert PW_HASH_VERSION_LATEST in KNOWN_PW_HASH_VERSIONS
assert PW_HASH_VERSION_LATEST in SUPPORTED_PW_HASH_VERSIONS
class UnexpectedPasswordHashVersion(InvalidPassword):
class UnexpectedPasswordHashVersion(InvalidPassword, WalletFileException):
def __init__(self, version):
self.version = version
@ -134,7 +134,7 @@ class UnexpectedPasswordHashVersion(InvalidPassword):
instruction=_('You are most likely using an outdated version of Electrum. Please update.'))
class UnsupportedPasswordHashVersion(InvalidPassword):
class UnsupportedPasswordHashVersion(InvalidPassword, WalletFileException):
def __init__(self, version):
self.version = version

5
electrum/keystore.py

@ -35,7 +35,8 @@ from .bip32 import (bip32_public_derivation, deserialize_xpub, CKD_pub,
bip32_private_key, bip32_derivation, BIP32_PRIME,
is_xpub, is_xprv)
from .ecc import string_to_number, number_to_string
from .crypto import (pw_decode, pw_encode, sha256d, PW_HASH_VERSION_LATEST)
from .crypto import (pw_decode, pw_encode, sha256d, PW_HASH_VERSION_LATEST,
SUPPORTED_PW_HASH_VERSIONS, UnsupportedPasswordHashVersion)
from .util import (PrintError, InvalidPassword, hfu, WalletFileException,
BitcoinException, bh2u, bfh, print_error, inv_dict)
from .mnemonic import Mnemonic, load_wordlist
@ -95,6 +96,8 @@ class Software_KeyStore(KeyStore):
def __init__(self, d):
KeyStore.__init__(self)
self.pw_hash_version = d.get('pw_hash_version', 1)
if self.pw_hash_version not in SUPPORTED_PW_HASH_VERSIONS:
raise UnsupportedPasswordHashVersion(self.pw_hash_version)
def may_have_password(self):
return not self.is_watching_only()

5
electrum/storage.py

@ -575,6 +575,11 @@ class WalletStorage(JsonDB):
self.put('verified_tx3', None)
self.put('seed_version', 18)
# def convert_version_19(self):
# TODO for "next" upgrade:
# - move "pw_hash_version" from keystore to storage
# pass
def convert_imported(self):
if not self._is_upgrade_method_needed(0, 13):
return

Loading…
Cancel
Save