Ida/pbkdf2 #2
@ -66,10 +66,10 @@ class Hashes:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def from_pbkdf2(kdfparams=pbkdf2_kdfparams, passphrase=''):
|
def from_pbkdf2(kdfparams=pbkdf2_kdfparams, passphrase=''):
|
||||||
if kdfparams['prf'] == 'hmac-sha256':
|
if kdfparams['prf'] == 'hmac-sha256':
|
||||||
kdfparams['prf'].replace('sha256')
|
kdfparams['prf'].replace('hmac-sha256','sha256')
|
||||||
|
|
||||||
derived_key = hashlib.pbkdf2_hmac(
|
derived_key = hashlib.pbkdf2_hmac(
|
||||||
hash_name=kdfparams['prf'],
|
hash_name='sha256',
|
||||||
password=passphrase.encode('utf-8'),
|
password=passphrase.encode('utf-8'),
|
||||||
salt=bytes.fromhex(kdfparams['salt']),
|
salt=bytes.fromhex(kdfparams['salt']),
|
||||||
iterations=int(kdfparams['c']),
|
iterations=int(kdfparams['c']),
|
||||||
|
@ -16,14 +16,7 @@ from funga.eth.keystore.keyfile import (
|
|||||||
from_file,
|
from_file,
|
||||||
to_dict,
|
to_dict,
|
||||||
)
|
)
|
||||||
# from pathlib import Path
|
|
||||||
# import sys
|
|
||||||
# path_root = Path(__file__).parents[1]
|
|
||||||
# sys.path.append(str(path_root))
|
|
||||||
# from keystore.testkeyfile import (
|
|
||||||
# from_file,
|
|
||||||
# to_dict
|
|
||||||
# )
|
|
||||||
|
|
||||||
from funga.eth.encoding import (
|
from funga.eth.encoding import (
|
||||||
private_key_to_address,
|
private_key_to_address,
|
||||||
|
@ -81,12 +81,6 @@ class TestCli(unittest.TestCase):
|
|||||||
'f86c2a8504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef82466aa0b7c1bbf52f736ada30fe253c7484176f44d6fd097a9720dc85ae5bbc7f060e54a07afee2563b0cf6d00333df51cc62b0d13c63108b2bce54ce2ad24e26ce7b4f25')
|
'f86c2a8504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef82466aa0b7c1bbf52f736ada30fe253c7484176f44d6fd097a9720dc85ae5bbc7f060e54a07afee2563b0cf6d00333df51cc62b0d13c63108b2bce54ce2ad24e26ce7b4f25')
|
||||||
|
|
||||||
|
|
||||||
def test_pbkdf2(self):
|
|
||||||
keystore_filepath = os.path.join(data_dir, 'foo2.json')
|
|
||||||
address_hex = self.keystore.import_keystore_file(keystore_filepath)
|
|
||||||
logg.debug('getting {}'.format(address_hex))
|
|
||||||
pk = self.keystore.get(strip_0x(address_hex), '')
|
|
||||||
self.assertEqual(pk.lower(), 'a1De08A738F0bD3B261dC41d7E2102599bf648CA')
|
|
||||||
|
|
||||||
def test_sign_msg(self):
|
def test_sign_msg(self):
|
||||||
keystore_file = os.path.join(data_dir,
|
keystore_file = os.path.join(data_dir,
|
||||||
|
59
tests/test_pbkdf2.py
Normal file
59
tests/test_pbkdf2.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# standard imports
|
||||||
|
import unittest
|
||||||
|
import logging
|
||||||
|
import base64
|
||||||
|
import os
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
from hexathon import (
|
||||||
|
strip_0x,
|
||||||
|
add_0x,
|
||||||
|
)
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from funga.error import UnknownAccountError
|
||||||
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
|
from funga.eth.signer import EIP155Signer
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
script_dir = os.path.realpath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
class TestDict(unittest.TestCase):
|
||||||
|
address_hex = None
|
||||||
|
db = None
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.db = DictKeystore()
|
||||||
|
|
||||||
|
keystore_filepath = os.path.join(script_dir, 'testdata',
|
||||||
|
'UTC--2022-01-24T10-34-04Z--cc47ad90-71a0-7fbe-0224-63326e27263a')
|
||||||
|
|
||||||
|
address_hex = self.db.import_keystore_file(keystore_filepath, 'test')
|
||||||
|
self.address_hex = add_0x(address_hex)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_get_key(self):
|
||||||
|
logg.debug('getting {}'.format(strip_0x(self.address_hex)))
|
||||||
|
pk = self.db.get(strip_0x(self.address_hex), '')
|
||||||
|
|
||||||
|
self.assertEqual(self.address_hex.lower(), '0xb8df77e1b4fa142e83bf9706f66fd76ad2a564f8')
|
||||||
|
|
||||||
|
bogus_account = os.urandom(20).hex()
|
||||||
|
with self.assertRaises(UnknownAccountError):
|
||||||
|
self.db.get(bogus_account, '')
|
||||||
|
|
||||||
|
def test_sign_message(self):
|
||||||
|
s = EIP155Signer(self.db)
|
||||||
|
z = s.sign_ethereum_message(strip_0x(self.address_hex), b'foo')
|
||||||
|
logg.debug('zzz {}'.format(str(z)))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
1
tests/testdata/UTC--2022-01-24T10-34-04Z--cc47ad90-71a0-7fbe-0224-63326e27263a
vendored
Normal file
1
tests/testdata/UTC--2022-01-24T10-34-04Z--cc47ad90-71a0-7fbe-0224-63326e27263a
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"id":"cc47ad90-71a0-7fbe-0224-63326e27263a","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"7bff67c888a9878a88e8548a4598322d"},"ciphertext":"0cb0e3c69d224d0a645f2784b64f507e5aecdc7bb8a7ea31963d25e6b8020ccf","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"02f8b51b07a66a357c2d812952e6bee70fccc2e6a55e7cbd5c22d97d32fa8873"},"mac":"bb45aaabdb9fbbbde89631444ac39f8d76107381f16591799664274fd5d8c5bb"},"address":"b8df77e1b4fa142e83bf9706f66fd76ad2a564f8","name":"","meta":"{}"}
|
1
tests/testdata/foo2.json
vendored
1
tests/testdata/foo2.json
vendored
@ -1 +0,0 @@
|
|||||||
{"address": "a1De08A738F0bD3B261dC41d7E2102599bf648CA", "version": 3, "crypto": {"cipher": "aes-128-ctr", "ciphertext": "2240149943557906e6ee9bcb864d6148dce0c0d8245d1da8d466dcb39edcde6a", "cipherparams": {"iv": "a0c366fdfe86f21a4168b4f12059e7fa"}, "kdf": "pbkdf2", "kdfparams": {"c": 100000, "dklen": 32, "prf": "sha256", "salt": "73cb66c8cf0e60e36f7ec835a057638a17ed315cebb3b691574c32cfed827b6f"}, "mac": "6760ad0841da7976a41f134e021be450baa453efdec8fe5ba7790cfa79d0c14b"}, "id": "22e597ea-777e-11ec-be42-a8a7956d3851"}
|
|
Loading…
Reference in New Issue
Block a user