1
0

During wallet creation, do not write seed on disk before it is encrypted

This commit is contained in:
thomasv
2013-12-13 17:30:34 +01:00
parent 60b6fd399d
commit f045490597
7 changed files with 115 additions and 97 deletions

View File

@@ -108,7 +108,7 @@ class OldAccount(Account):
master_private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 )
master_public_key = master_private_key.get_verifying_key().to_string()
if master_public_key != self.mpk:
print_error('invalid password (mpk)')
print_error('invalid password (mpk)', self.mpk.encode('hex'), master_public_key.encode('hex'))
raise Exception('Invalid password')
return True

View File

@@ -340,10 +340,14 @@ class Wallet:
# self.seed = seed
def save_seed(self):
def save_seed(self, password):
if password:
self.seed = pw_encode( self.seed, password)
self.use_encryption = True
self.storage.put('seed', self.seed, True)
self.storage.put('seed_version', self.seed_version, True)
self.create_accounts()
self.storage.put('use_encryption', self.use_encryption,True)
self.create_accounts(password)
def create_watching_only_wallet(self, params):
@@ -366,29 +370,31 @@ class Wallet:
self.create_account('1','Main account')
def create_accounts(self):
def create_accounts(self, password):
seed = pw_decode(self.seed, password)
if self.seed_version == 4:
mpk = OldAccount.mpk_from_seed(self.seed)
mpk = OldAccount.mpk_from_seed(seed)
self.create_old_account(mpk)
else:
# create default account
self.create_master_keys('1')
self.create_master_keys('1', password)
self.create_account('1','Main account')
def create_master_keys(self, account_type):
def create_master_keys(self, account_type, password):
master_k, master_c, master_K, master_cK = bip32_init(self.get_seed(None))
if account_type == '1':
k0, c0, K0, cK0 = bip32_private_derivation(master_k, master_c, "m/", "m/0'/")
self.master_public_keys["m/0'/"] = (c0, K0, cK0)
self.master_private_keys["m/0'/"] = k0
self.master_private_keys["m/0'/"] = pw_encode(k0, password)
elif account_type == '2of2':
k1, c1, K1, cK1 = bip32_private_derivation(master_k, master_c, "m/", "m/1'/")
k2, c2, K2, cK2 = bip32_private_derivation(master_k, master_c, "m/", "m/2'/")
self.master_public_keys["m/1'/"] = (c1, K1, cK1)
self.master_public_keys["m/2'/"] = (c2, K2, cK2)
self.master_private_keys["m/1'/"] = k1
self.master_private_keys["m/2'/"] = k2
self.master_private_keys["m/1'/"] = pw_encode(k1, password)
self.master_private_keys["m/2'/"] = pw_encode(k2, password)
elif account_type == '2of3':
k3, c3, K3, cK3 = bip32_private_derivation(master_k, master_c, "m/", "m/3'/")
k4, c4, K4, cK4 = bip32_private_derivation(master_k, master_c, "m/", "m/4'/")
@@ -396,9 +402,9 @@ class Wallet:
self.master_public_keys["m/3'/"] = (c3, K3, cK3)
self.master_public_keys["m/4'/"] = (c4, K4, cK4)
self.master_public_keys["m/5'/"] = (c5, K5, cK5)
self.master_private_keys["m/3'/"] = k3
self.master_private_keys["m/4'/"] = k4
self.master_private_keys["m/5'/"] = k5
self.master_private_keys["m/3'/"] = pw_encode(k3, password)
self.master_private_keys["m/4'/"] = pw_encode(k4, password)
self.master_private_keys["m/5'/"] = pw_encode(k5, password)
self.storage.put('master_public_keys', self.master_public_keys, True)
self.storage.put('master_private_keys', self.master_private_keys, True)