Beispiel #1
0
 def read_wallet_file_data(self, filename):
     self.path = None
     self.index_cache = [[0, 0]] * self.max_mix_depth
     path = os.path.join('wallets', filename)
     if not os.path.isfile(path):
         if get_network() == 'testnet':
             debug(
                 'filename interpreted as seed, only available in testnet because this probably has lower entropy'
             )
             return filename
         else:
             raise IOError('wallet file not found')
     self.path = path
     fd = open(path, 'r')
     walletfile = fd.read()
     fd.close()
     walletdata = json.loads(walletfile)
     if walletdata['network'] != get_network():
         print 'wallet network(%s) does not match joinmarket configured network(%s)' % (
             walletdata['network'], get_network())
         sys.exit(0)
     if 'index_cache' in walletdata:
         self.index_cache = walletdata['index_cache']
     decrypted = False
     while not decrypted:
         password = getpass.getpass('Enter wallet decryption passphrase: ')
         password_key = btc.bin_dbl_sha256(password)
         encrypted_seed = walletdata['encrypted_seed']
         try:
             decrypted_seed = slowaes.decryptData(
                 password_key, encrypted_seed.decode('hex')).encode('hex')
             #there is a small probability of getting a valid PKCS7 padding
             #by chance from a wrong password; sanity check the seed length
             if len(decrypted_seed) == 32:
                 decrypted = True
             else:
                 raise ValueError
         except ValueError:
             print 'Incorrect password'
             decrypted = False
     if self.storepassword:
         self.password_key = password_key
         self.walletdata = walletdata
     if 'imported_keys' in walletdata:
         for epk_m in walletdata['imported_keys']:
             privkey = slowaes.decryptData(
                 password_key,
                 epk_m['encrypted_privkey'].decode('hex')).encode('hex')
             privkey = btc.encode_privkey(privkey, 'hex_compressed')
             if epk_m['mixdepth'] not in self.imported_privkeys:
                 self.imported_privkeys[epk_m['mixdepth']] = []
             self.addr_cache[btc.privtoaddr(privkey, get_p2pk_vbyte())] = (
                 epk_m['mixdepth'], -1,
                 len(self.imported_privkeys[epk_m['mixdepth']]))
             self.imported_privkeys[epk_m['mixdepth']].append(privkey)
     return decrypted_seed
Beispiel #2
0
	def read_wallet_file_data(self, filename):
		self.path = None
		self.index_cache = [[0, 0]]*self.max_mix_depth
		path = os.path.join('wallets', filename)
		if not os.path.isfile(path):
			if get_network() == 'testnet':
				debug('filename interpreted as seed, only available in testnet because this probably has lower entropy')
				return filename
			else:
				raise IOError('wallet file not found')
		self.path = path
		fd = open(path, 'r')
		walletfile = fd.read()
		fd.close()
		walletdata = json.loads(walletfile)
		if walletdata['network'] != get_network():
			print 'wallet network(%s) does not match joinmarket configured network(%s)' % (
				walletdata['network'], get_network())
			sys.exit(0)
		if 'index_cache' in walletdata:
			self.index_cache = walletdata['index_cache']
		decrypted = False
		while not decrypted:
			password = getpass.getpass('Enter wallet decryption passphrase: ')
			password_key = btc.bin_dbl_sha256(password)
			encrypted_seed = walletdata['encrypted_seed']
			try:
				decrypted_seed = slowaes.decryptData(password_key, encrypted_seed
					.decode('hex')).encode('hex')
				#there is a small probability of getting a valid PKCS7 padding
				#by chance from a wrong password; sanity check the seed length
				if len(decrypted_seed) == 32:
					decrypted = True
				else:
					raise ValueError
			except ValueError:
				print 'Incorrect password'
				decrypted = False
		if self.storepassword:
			self.password_key = password_key
			self.walletdata = walletdata
		if 'imported_keys' in walletdata:
			for epk_m in walletdata['imported_keys']:
				privkey = slowaes.decryptData(password_key, epk_m['encrypted_privkey']
					.decode('hex')).encode('hex')
				privkey = btc.encode_privkey(privkey, 'hex_compressed')
				if epk_m['mixdepth'] not in self.imported_privkeys:
					self.imported_privkeys[epk_m['mixdepth']] = []
				self.addr_cache[btc.privtoaddr(privkey, get_p2pk_vbyte())] = (epk_m['mixdepth'],
					-1, len(self.imported_privkeys[epk_m['mixdepth']]))
				self.imported_privkeys[epk_m['mixdepth']].append(privkey)
		return decrypted_seed
Beispiel #3
0
	def get_seed(self, seedarg):
		self.path = None
		self.index_cache = [[0, 0]]*self.max_mix_depth
		path = os.path.join('wallets', seedarg)
		if not os.path.isfile(path):
			if get_network() == 'testnet':
				debug('seedarg interpreted as seed, only available in testnet because this probably has lower entropy')
				return seedarg
			else:
				raise IOError('wallet file not found')
		#debug('seedarg interpreted as wallet file name')
		self.path = path
		fd = open(path, 'r')
		walletfile = fd.read()
		fd.close()
		walletdata = json.loads(walletfile)
		if walletdata['network'] != get_network():
			print 'wallet network(%s) does not match joinmarket configured network(%s)' % (
				walletdata['network'], get_network())
			sys.exit(0)
		if 'index_cache' in walletdata:
			self.index_cache = walletdata['index_cache']
		decrypted = False
		while not decrypted:
			password = getpass.getpass('Enter wallet decryption passphrase: ')
			password_key = btc.bin_dbl_sha256(password)
			encrypted_seed = walletdata['encrypted_seed']
			try:
				decrypted_seed = slowaes.decryptData(password_key, encrypted_seed
					.decode('hex')).encode('hex')
				decrypted = True
			except ValueError:
				print 'Incorrect password'
				decrypted = False
		return decrypted_seed
Beispiel #4
0
	def get_seed(self, seedarg):
		self.path = None
		self.index_cache = [[0, 0]]*self.max_mix_depth
		path = os.path.join('wallets', seedarg)
		if not os.path.isfile(path):
			if get_network() == 'testnet':
				debug('seedarg interpreted as seed, only available in testnet because this probably has lower entropy')
				return seedarg
			else:
				raise IOError('wallet file not found')
		#debug('seedarg interpreted as wallet file name')
		self.path = path
		fd = open(path, 'r')
		walletfile = fd.read()
		fd.close()
		walletdata = json.loads(walletfile)
		if walletdata['network'] != get_network():
			print 'wallet network(%s) does not match joinmarket configured network(%s)' % (
				walletdata['network'], get_network())
			sys.exit(0)
		if 'index_cache' in walletdata:
			self.index_cache = walletdata['index_cache']
		decrypted = False
		while not decrypted:
			password = getpass.getpass('Enter wallet decryption passphrase: ')
			password_key = btc.bin_dbl_sha256(password)
			encrypted_seed = walletdata['encrypted_seed']
			try:
				decrypted_seed = slowaes.decryptData(password_key, encrypted_seed
					.decode('hex')).encode('hex')
				decrypted = True
			except ValueError:
				print 'Incorrect password'
				decrypted = False
		return decrypted_seed
Beispiel #5
0
 def get_seed(self, seedarg):
     self.path = None
     self.index_cache = [[0, 0]] * self.max_mix_depth
     path = os.path.join("wallets", seedarg)
     if not os.path.isfile(path):
         if get_network() == "testnet":
             debug("seedarg interpreted as seed, only available in testnet because this probably has lower entropy")
             return seedarg
         else:
             raise IOError("wallet file not found")
             # debug('seedarg interpreted as wallet file name')
     self.path = path
     fd = open(path, "r")
     walletfile = fd.read()
     fd.close()
     walletdata = json.loads(walletfile)
     if walletdata["network"] != get_network():
         print "wallet network(%s) does not match joinmarket configured network(%s)" % (
             walletdata["network"],
             get_network(),
         )
         sys.exit(0)
     if "index_cache" in walletdata:
         self.index_cache = walletdata["index_cache"]
     decrypted = False
     while not decrypted:
         password = getpass.getpass("Enter wallet decryption passphrase: ")
         password_key = btc.bin_dbl_sha256(password)
         encrypted_seed = walletdata["encrypted_seed"]
         try:
             decrypted_seed = slowaes.decryptData(password_key, encrypted_seed.decode("hex")).encode("hex")
             # there is a small probability of getting a valid PKCS7 padding
             # by chance from a wrong password; sanity check the seed length
             if len(decrypted_seed) == 32:
                 decrypted = True
             else:
                 raise ValueError
         except ValueError:
             print "Incorrect password"
             decrypted = False
     return decrypted_seed
Beispiel #6
0
 def decrypt(self, enc):
     return slowaes.decryptData(self.key, enc)