mirror of https://github.com/nucypher/nucypher.git
Fixed kfrag test by rebuilding kfrag.
parent
e0c50d473c
commit
6eeb8ee546
|
@ -1,5 +1,7 @@
|
|||
import umbral
|
||||
from nkms.crypto import api
|
||||
from tests.utilities import EVENT_LOOP, MockNetworkyStuff
|
||||
from umbral.fragments import KFrag
|
||||
|
||||
|
||||
def test_bob_can_follow_treasure_map(enacted_policy, ursulas, alice, bob):
|
||||
|
@ -66,9 +68,11 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_policy, alice,
|
|||
# OK, so cool - Bob has his cFrag! Let's make sure everything went properly. First, we'll show that it is in fact
|
||||
# the correct cFrag (ie, that Ursula performed reencryption properly).
|
||||
ursula = networky_stuff.get_ursula_by_id(work_order.ursula_id)
|
||||
the_kfrag = ursula.keystore.get_kfrag(work_order.kfrag_hrac)
|
||||
the_correct_cfrag = api.ecies_reencrypt(the_kfrag, the_pfrag.encrypted_key)
|
||||
assert the_cfrag == the_correct_cfrag # It's the correct cfrag!
|
||||
kfrag_bytes = ursula.keystore.get_policy_contract(
|
||||
work_order.kfrag_hrac.hex().encode()).k_frag
|
||||
the_kfrag = KFrag.from_bytes(kfrag_bytes)
|
||||
the_correct_cfrag = umbral.umbral.reencrypt(the_kfrag, capsule)
|
||||
assert bytes(the_cfrag) == bytes(the_correct_cfrag) # It's the correct cfrag!
|
||||
|
||||
# Now we'll show that Ursula saved the correct WorkOrder.
|
||||
work_orders_from_bob = ursula.work_orders(bob=bob)
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
import unittest
|
||||
from nacl.utils import EncryptedMessage
|
||||
from nkms.crypto import api
|
||||
|
||||
|
||||
class TestInternal(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.pre = umbral.PRE()
|
||||
self.privkey_a = self.pre.gen_priv()
|
||||
self.privkey_a_bytes = ec.serialize(self.privkey_a)[1:]
|
||||
|
||||
self.privkey_b = self.pre.gen_priv()
|
||||
self.privkey_b_bytes = ec.serialize(self.privkey_b)[1:]
|
||||
|
||||
self.pubkey_a = self.pre.priv2pub(self.privkey_a)
|
||||
self.pubkey_b = self.pre.priv2pub(self.privkey_b)
|
||||
|
||||
self.pubkey_a_bytes = ec.serialize(self.pubkey_a)[1:]
|
||||
self.pubkey_b_bytes = ec.serialize(self.pubkey_b)[1:]
|
||||
|
||||
def test_ecies_gen_ephemeral_key(self):
|
||||
result_data = _internal._ecies_gen_ephemeral_key(
|
||||
self.pubkey_a)
|
||||
self.assertEqual(tuple, type(result_data))
|
||||
self.assertEqual(2, len(result_data))
|
||||
|
||||
eph_privkey, enc_data = result_data
|
||||
|
||||
self.assertEqual(bytes, type(eph_privkey))
|
||||
self.assertEqual(32, len(eph_privkey))
|
||||
|
||||
self.assertEqual(tuple, type(enc_data))
|
||||
self.assertEqual(2, len(enc_data))
|
||||
|
||||
enc_symm_key, enc_eph_key = enc_data
|
||||
|
||||
self.assertEqual(umbral.EncryptedKey, type(enc_symm_key))
|
||||
self.assertEqual(EncryptedMessage, type(enc_eph_key))
|
||||
self.assertNotEqual(eph_privkey, enc_eph_key)
|
||||
|
||||
dec_symm_key = api.ecies_decapsulate(self.privkey_a, enc_symm_key)
|
||||
|
||||
self.assertEqual(bytes, type(dec_symm_key))
|
||||
self.assertEqual(32, len(dec_symm_key))
|
||||
|
||||
dec_eph_key = api.symm_decrypt(dec_symm_key, enc_eph_key)
|
||||
|
||||
self.assertEqual(bytes, type(dec_eph_key))
|
||||
self.assertEqual(32, len(dec_eph_key))
|
||||
self.assertEqual(eph_privkey, dec_eph_key)
|
Loading…
Reference in New Issue