commit 8f5f0e46aac97c923c5ca826177781389d6a5486
parent fa389a4e06efa2bd369ad1d9c879d54efe2816af
Author: SomberNight <somber.night@protonmail.com>
Date: Tue, 18 Dec 2018 19:57:58 +0100
keystore: fail sooner if unsupported version
follow-up #4937
Diffstat:
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/electrum/crypto.py b/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
diff --git a/electrum/keystore.py b/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()
diff --git a/electrum/storage.py b/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