Compare commits

...

11 Commits

Author SHA1 Message Date
Vivek Teega
4704375a4c Changes to accomodate new wallet.dat types. It ignores some of the new lines added in wallet.dat. Dumping the wallet works for now, other functions may have a problem 2018-08-10 18:55:45 +05:30
jackjack-jj
b52c955f8c Merge pull request #11 from gurnec/crypto-fixes
Fix wallet creation bugs related to crypto
2014-09-08 20:59:58 +02:00
Christopher Gurnee
7c847c18fa fix wallet creation bugs related to crypto
* fix encryption when using PyCrypto or SlowAES
 * use os.urandom wherever cryptographically secure rnd #s are required
2014-09-08 14:57:16 -04:00
jackjack-jj
069ef00443 Merge pull request #10 from dgnthr/master
Changed balance website to blockchain.
2014-09-08 16:00:43 +02:00
jackjack-jj
d44ac69b3e Merge pull request #8 from neldredge/master
With --testnet, look for testnet directory in the right place
2014-09-08 16:00:18 +02:00
jackjack-jj
1cc3ae55cc Update pywallet.py 2014-09-03 11:18:24 +02:00
jackjack-jj
5bf4b712f6 v2.2: Fix critical bug 2014-09-03 11:18:07 +02:00
Dominik G.
35d837efd9 Update pywallet.py
Change balance website to blockchain.
2014-07-04 12:18:36 +02:00
Nate Eldredge
7b3d93ca62 With --testnet, look for testnet directory in the right place 2014-03-01 21:14:37 -07:00
jackjack-jj
880662a31c Merge pull request #6 from Krellan/master
Allow bsddb3 for compatibility with Gentoo
2014-01-21 02:57:26 -08:00
Josh Lehan
cb6c3b4f0e Allow bsddb3 for compatibility with Gentoo
It is the same library, but unfortunately Gentoo renamed bsddb to bsddb3 when packaging it.
If bsddb is not found, try importing bsddb3 instead, before reporting error.
2014-01-21 01:54:53 -08:00

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-
pywversion="2.1.7"
pywversion="2.2"
never_update=False
#
@ -19,7 +19,10 @@ missing_dep = []
try:
from bsddb.db import *
except:
missing_dep.append('bsddb')
try:
from bsddb3.db import *
except:
missing_dep.append('bsddb')
import os, sys, time, re
pyw_filename = os.path.basename(__file__)
@ -76,7 +79,7 @@ private_hex_keys = []
passphrase = ""
global_merging_message = ["",""]
balance_site = 'http://jackjack.alwaysdata.net/balance/index.php?address'
balance_site = 'https://blockchain.info/q/addressbalance/'
aversions = {};
for i in range(256):
aversions[i] = "version %d" % i;
@ -739,7 +742,7 @@ class Crypter_pycrypto( object ):
self.chIV = iv[0:16]
def Encrypt(self, data):
return AES.new(self.chKey,AES.MODE_CBC,self.chIV).encrypt(data)[0:32]
return AES.new(self.chKey,AES.MODE_CBC,self.chIV).encrypt(append_PKCS7_padding(data))
def Decrypt(self, data):
return AES.new(self.chKey,AES.MODE_CBC,self.chIV).decrypt(data)[0:32]
@ -821,7 +824,7 @@ class Crypter_pure(object):
self.chIV = [ord(i) for i in iv]
def Encrypt(self, data):
mode, size, cypher = self.m.encrypt(data, self.cbc, self.chKey, self.sz, self.chIV)
mode, size, cypher = self.m.encrypt(append_PKCS7_padding(data), self.cbc, self.chKey, self.sz, self.chIV)
return ''.join(map(chr, cypher))
def Decrypt(self, data):
@ -2105,7 +2108,7 @@ def parse_wallet(db, item_callback):
d['comment'] = vds.read_string()
elif type == "bestblock":
d['nVersion'] = vds.read_int32()
d.update(parse_BlockLocator(vds))
#d.update(parse_BlockLocator(vds))
elif type == "ckey":
d['public_key'] = kds.read_bytes(kds.read_compact_size())
d['encrypted_private_key'] = vds.read_bytes(vds.read_compact_size())
@ -2243,10 +2246,10 @@ def merge_wallets(wadir, wa, wbdir, wb, wrdir, wr, passphrase_a, passphrase_b, p
if len(passphrase_r)>0:
NPP_salt=random_string(16).decode('hex')
NPP_salt=os.urandom(8)
NPP_rounds=int(50000+random.random()*20000)
NPP_method=0
NPP_MK=random_string(64).decode('hex')
NPP_MK=os.urandom(32)
crypter.SetKeyFromPassphrase(passphrase_r, NPP_salt, NPP_rounds, NPP_method)
NPP_EMK = crypter.Encrypt(NPP_MK)
@ -2469,7 +2472,7 @@ def read_wallet(json_db, db_env, walletfile, print_wallet, print_wallet_transact
addr = public_key_to_bc_address(d['public_key'])
compressed = d['public_key'][0] != '\04'
sec = SecretToASecret(PrivKeyToSecret(d['private_key']), compressed)
hexsec = ASecretToSecret(sec).encode('hex')[:32]
hexsec = ASecretToSecret(sec)[:32].encode('hex')
private_keys.append(sec)
addr_to_keys[addr]=[hexsec, d['public_key'].encode('hex')]
json_db['keys'].append({'addr' : addr, 'sec' : sec, 'hexsec' : hexsec, 'secret' : hexsec, 'pubkey':d['public_key'].encode('hex'), 'compressed':compressed, 'private':d['private_key'].encode('hex')})
@ -2496,7 +2499,7 @@ def read_wallet(json_db, db_env, walletfile, print_wallet, print_wallet_transact
json_db['acentry'] = (d['account'], d['nCreditDebit'], d['otherAccount'], time.ctime(d['nTime']), d['n'], d['comment'])
elif type == "bestblock":
json_db['bestblock'] = d['hashes'][0][::-1].encode('hex_codec')
print("ignored") #json_db['bestblock'] = d['hashes'][0][::-1].encode('hex_codec')
elif type == "ckey":
crypted=True
@ -2681,14 +2684,8 @@ def importprivkey(db, sec, label, reserve, keyishex, verbose=True, addrv=addrtyp
return True
def balance(site, address):
page=urllib.urlopen("%s=%s" % (site, address))
json_acc = json.loads(page.read().split("<end>")[0])
if json_acc['0'] == 0:
return "Invalid address"
elif json_acc['0'] == 2:
return "Never used"
else:
return json_acc['balance']
page=urllib.urlopen("%s%s" % (site, address))
return page.read()
def read_jsonfile(filename):
filin = open(filename, 'r')
@ -4883,10 +4880,10 @@ if __name__ == '__main__':
if passphraseRecov!="I don't want to put a password on the recovered wallet and I know what can be the consequences.":
db = open_wallet(db_env, recov_wallet_name, True)
NPP_salt=random_string(16).decode('hex')
NPP_salt=os.urandom(8)
NPP_rounds=int(50000+random.random()*20000)
NPP_method=0
NPP_MK=random_string(64).decode('hex')
NPP_MK=os.urandom(32)
crypter.SetKeyFromPassphrase(passphraseRecov, NPP_salt, NPP_rounds, NPP_method)
NPP_EMK = crypter.Encrypt(NPP_MK)
update_wallet(db, 'mkey', {
@ -4983,10 +4980,6 @@ if __name__ == '__main__':
parser.print_help()
exit(0)
if options.testnet:
db_dir += "/testnet"
addrtype = 111
if options.namecoin or options.otherversion is not None:
if options.datadir is None and options.keyinfo is None:
print("You must provide your wallet directory")
@ -5004,6 +4997,10 @@ if __name__ == '__main__':
db_dir = determine_db_dir()
if options.testnet:
db_dir += "/testnet3"
addrtype = 111
db_env = create_env(db_dir)
if options.multidelete is not None:
@ -5044,8 +5041,3 @@ if __name__ == '__main__':
print "Bad private key"
db.close()