fix key stretching
This commit is contained in:
parent
5883aaf8ca
commit
d03e60b056
|
@ -215,6 +215,9 @@ class InvalidPassword(Exception):
|
|||
|
||||
|
||||
|
||||
WALLET_VERSION = 3 # bump this everytime the wallet format is modified
|
||||
|
||||
|
||||
class Wallet:
|
||||
def __init__(self, wallet_path):
|
||||
|
||||
|
@ -222,8 +225,7 @@ class Wallet:
|
|||
self.host = 'ecdsa.org'
|
||||
self.port = 50000
|
||||
self.fee = 0.005
|
||||
self.version = 2 # bump this everytime the wallet format is modified
|
||||
|
||||
self.version = WALLET_VERSION
|
||||
self.servers = ['ecdsa.org','electrum.novit.ro'] # list of default servers
|
||||
|
||||
# saved fields
|
||||
|
@ -286,8 +288,8 @@ class Wallet:
|
|||
def create_new_address(self, for_change, password):
|
||||
seed = self.pw_decode( self.seed, password)
|
||||
# strenghtening
|
||||
for i in range(100000):
|
||||
oldseed = seed
|
||||
for i in range(100000):
|
||||
seed = hashlib.sha512(seed + oldseed).digest()
|
||||
i = len( self.addresses ) - len(self.change_addresses) if not for_change else len(self.change_addresses)
|
||||
seed = Hash( "%d:%d:"%(i,for_change) + seed )
|
||||
|
@ -382,8 +384,8 @@ class Wallet:
|
|||
self.labels, self.addressbook) = sequence
|
||||
except:
|
||||
raise BaseException("version error.")
|
||||
if self.version == 1 and self.use_encryption:
|
||||
raise BaseException("version error: please upgrade your wallet first")
|
||||
if self.version != WALLET_VERSION:
|
||||
raise BaseException("Wallet version error. Please use the upgrade script.")
|
||||
self.update_tx_history()
|
||||
return True
|
||||
|
||||
|
|
|
@ -61,8 +61,13 @@ def show_seed_dialog(wallet, password, parent):
|
|||
|
||||
def init_wallet(wallet):
|
||||
|
||||
if not wallet.read():
|
||||
try:
|
||||
found = wallet.read()
|
||||
except BaseException, e:
|
||||
show_message(e.message)
|
||||
exit(1)
|
||||
|
||||
if not found:
|
||||
# ask if the user wants to create a new wallet, or recover from a seed.
|
||||
# if he wants to recover, and nothing is found, do not create wallet
|
||||
dialog = gtk.Dialog("electrum", parent=None,
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
import electrum, getpass, base64,ast,sys
|
||||
|
||||
|
||||
try:
|
||||
path = sys.argv[1]
|
||||
except:
|
||||
path = None
|
||||
wallet = electrum.Wallet(path)
|
||||
try:
|
||||
wallet.read()
|
||||
print "ok"
|
||||
except BaseException:
|
||||
def upgrade_wallet(wallet):
|
||||
if wallet.version == 1 and wallet.use_encryption:
|
||||
# version 1 used pycrypto for wallet encryption
|
||||
import Crypto
|
||||
|
@ -33,4 +25,30 @@ except BaseException:
|
|||
wallet.seed = wallet.pw_encode( seed, password)
|
||||
wallet.private_keys = wallet.pw_encode( repr( private_keys ), password)
|
||||
wallet.save()
|
||||
print "upgrade successful"
|
||||
print "upgraded to version 2"
|
||||
if wallet.version < 3:
|
||||
print """
|
||||
Your wallet is deprecated; its regeneration seed will not work with versions 0.31 and above.
|
||||
In order to upgrade, you need to create a new wallet (you may use your current seed), and to
|
||||
send your bitcoins to the new wallet, using a compatible version of Electrum ( http://ecdsa.org/electrum/Electrum-0.30.zip )
|
||||
|
||||
We apologize for the inconvenience. We try to keep this kind of upgrades as rare as possible.
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
path = sys.argv[1]
|
||||
except:
|
||||
path = None
|
||||
wallet = electrum.Wallet(path)
|
||||
try:
|
||||
found = wallet.read()
|
||||
if found:
|
||||
print wallet.path
|
||||
else:
|
||||
print "wallet not found."
|
||||
except BaseException:
|
||||
upgrade_wallet(wallet)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue