electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit d03e60b0565ed79961685d6d0df81883b0bcdf31
parent 5883aaf8ca2f79bf694d11ac6b63f5defd2a2c38
Author: thomasv <thomasv@gitorious>
Date:   Tue,  6 Dec 2011 15:40:04 +0100

fix key stretching

Diffstat:
Mclient/electrum.py | 12+++++++-----
Mclient/gui.py | 7++++++-
Mclient/upgrade.py | 38++++++++++++++++++++++++++++----------
3 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/client/electrum.py b/client/electrum.py @@ -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 + oldseed = seed for i in range(100000): - oldseed = seed 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 diff --git a/client/gui.py b/client/gui.py @@ -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, diff --git a/client/upgrade.py b/client/upgrade.py @@ -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) + +