Skip to content

Commit

Permalink
keystore: fail sooner if unsupported version
Browse files Browse the repository at this point in the history
follow-up #4937
  • Loading branch information
SomberNight committed Dec 18, 2018
1 parent fa389a4 commit 8f5f0e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions electrum/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

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 _


Expand Down Expand Up @@ -123,7 +123,7 @@ def DecodeAES_bytes(secret: bytes, ciphertext: bytes) -> bytes:
assert PW_HASH_VERSION_LATEST in SUPPORTED_PW_HASH_VERSIONS


class UnexpectedPasswordHashVersion(InvalidPassword):
class UnexpectedPasswordHashVersion(InvalidPassword, WalletFileException):
def __init__(self, version):
self.version = version

Expand All @@ -134,7 +134,7 @@ def __str__(self):
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

Expand Down
5 changes: 4 additions & 1 deletion electrum/keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions electrum/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ def convert_version_18(self):
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
Expand Down

0 comments on commit 8f5f0e4

Please sign in to comment.