Exemplo n.º 1
0
 def test_aes_homomorphic(self):
     """Make sure AES is homomorphic."""
     payload = u'\u66f4\u7a33\u5b9a\u7684\u4ea4\u6613\u5e73\u53f0'
     password = u'secret'
     enc = pw_encode(payload, password)
     dec = pw_decode(enc, password)
     self.assertEqual(dec, payload)
Exemplo n.º 2
0
    def test_encryption(self):
        self.storage.write()
        wallet_data = json.load(open(self.wallet_path, "r"))
        self.assertTrue(wallet_data['use_encryption'])

        # retrieve the encrypted values from wallet storage
        enc_xprv_key = wallet_data['master_private_keys']['x/']
        enc_seed = wallet_data['seed']

        # the xprv key and seed should not be in plain text in the wallet storage
        self.assertNotEqual(self.seed_text, enc_seed)
        self.assertNotEqual(self.xprv_text, enc_xprv_key)

        # decoding the encrypted xprv key and seed should return the original values
        self.assertEqual(self.seed_text, pw_decode(enc_seed, self.password))
        self.assertEqual(self.xprv_text, pw_decode(enc_xprv_key, self.password))
        self.assertEqual(self.xprv_text, self.wallet.get_master_private_key('x/', self.password))
Exemplo n.º 3
0
 def get_private_key(self, sequence, wallet, password):
     for_change, i = sequence
     assert for_change == 0
     address = self.get_addresses(0)[i]
     pk = pw_decode(self.keypairs[address][1], password)
     # this checks the password
     if address != address_from_private_key(pk):
         raise InvalidPassword()
     return [pk]
Exemplo n.º 4
0
 def get_private_key(self, sequence, wallet, password):
     for_change, i = sequence
     assert for_change == 0
     address = self.get_addresses(0)[i]
     pk = pw_decode(self.keypairs[address][1], password)
     # this checks the password
     if address != address_from_private_key(pk):
         raise InvalidPassword()
     return [pk]
Exemplo n.º 5
0
    def test_encryption(self):
        self.storage.write()
        wallet_data = json.load(open(self.wallet_path, "r"))
        self.assertTrue(wallet_data['use_encryption'])

        # retrieve the encrypted values from wallet storage
        enc_xprv_key = wallet_data['master_private_keys']['x/']
        enc_seed = wallet_data['seed']

        # the xprv key and seed should not be in plain text in the wallet storage
        self.assertNotEqual(self.seed_text, enc_seed)
        self.assertNotEqual(self.xprv_text, enc_xprv_key)

        # decoding the encrypted xprv key and seed should return the original values
        self.assertEqual(self.seed_text, pw_decode(enc_seed, self.password))
        self.assertEqual(self.xprv_text, pw_decode(enc_xprv_key,
                                                   self.password))
        self.assertEqual(
            self.xprv_text,
            self.wallet.get_master_private_key('x/', self.password))
Exemplo n.º 6
0
 def test_aes_deencode_without_password(self):
     """When not passed a password, pw_decode is noop on the payload."""
     payload = u'\u66f4\u7a33\u5b9a\u7684\u4ea4\u6613\u5e73\u53f0'
     enc = pw_decode(payload, None)
     self.assertEqual(payload, enc)
Exemplo n.º 7
0
 def update_password(self, old_password, new_password):
     for k, v in self.keypairs.items():
         pubkey, a = v
         b = pw_decode(a, old_password)
         c = pw_encode(b, new_password)
         self.keypairs[k] = (pubkey, c)
Exemplo n.º 8
0
 def update_password(self, old_password, new_password):
     for k, v in self.keypairs.items():
         pubkey, a = v
         b = pw_decode(a, old_password)
         c = pw_encode(b, new_password)
         self.keypairs[k] = (pubkey, c)