def main(m, n, filenames): files = [open(filename, 'w') for filename in filenames] config.set_default_curve() alice_privkey = keys.UmbralPrivateKey.gen_key() alice_pubkey = alice_privkey.get_pubkey() bob_privkey = keys.UmbralPrivateKey.gen_key() bob_pubkey = bob_privkey.get_pubkey() mock_kms = MockNetwork() sys.stderr.write('Server with PID %s is ready to pipe messages.\n' % os.getpid()) for line in sys.stdin: ciphertext, capsule = pre.encrypt(alice_pubkey, line.rstrip('\n').encode('utf8')) alice_kfrags = pre.split_rekey(alice_privkey, bob_pubkey, m, n) policy_id = mock_kms.grant(alice_kfrags) bob_cfrags = mock_kms.reencrypt(policy_id, capsule, m) bob_capsule = capsule for cfrag in bob_cfrags: bob_capsule.attach_cfrag(cfrag) decrypted = pre.decrypt(ciphertext, bob_capsule, bob_privkey, alice_pubkey) for file in files: file.write('%s\n' % decrypted.decode('utf8')) file.flush() mock_kms.revoke(policy_id)
alice_signer = Signer(alice_signing_privkey) bob_privkey = keys.UmbralPrivateKey.gen_key() bob_pubkey = bob_privkey.get_pubkey() mock_kms = MockNetwork() # 3. Encrypt some data plaintext = b'attack at dawn!' ciphertext, capsule = pre.encrypt(alice_pubkey, plaintext) # 4. Perform split-rekey and grant re-encryption policy alice_kfrags = pre.split_rekey(alice_privkey, alice_signer, bob_pubkey, 10, 20) assert len(alice_kfrags) == 20 policy_id = mock_kms.grant(alice_kfrags) assert type(policy_id) == str # 5. Perform re-encryption request bob_capsule = capsule bob_capsule.set_correctness_keys(alice_pubkey, bob_pubkey, alice_signing_pubkey) bob_cfrags = mock_kms.reencrypt(policy_id, bob_capsule, 10) assert len(bob_cfrags) == 10 # 6. Simulate capsule handoff, and set the correctness keys. # Correctness keys are used to prove that a cfrag is correct and not modified # by a proxy node in the network. They must be set to use the `decrypt` and # `attach_cfrag` funtions. for cfrag in bob_cfrags: bob_capsule.attach_cfrag(cfrag)
def main(m, n, fileNames):files = [open(fileName, 'w') for fileName in fileNames] config.set_default_curve() MDPrivateKey = keys.UmbralPrivateKey.gen_key() MDPublicKey = MDPrivateKey.get_pubkey() PacientPrivateKey = keys.UmbralPrivateKey.gen_key() PacientPublicKey = PacientPrivateKey.get_pubkey() mock_kms = MockNetwork() sys.stderr.write('Server is ready.\n' % os.getpid()) for line in sys.stdin: cipText, capsule = pre.encrypt(MDPublicKey, line.rstrip('\n').encode('utf8')) MDkfrags = pre.split_rekey(MDPrivateKey, PacientPrivateKey, m, n) policy_id = mock_kms.grant(MDkfrags) pacientCfrags = mock_kms.reencrypt(policy_id, capsule, m) pacientCapsule = capsule for cfrag in pacientCfrags: pacientCapsule.attach_cfrag(cfrag) decrypted = pre.decrypt(cipText, pacientCapsule, PacientPublicKey, MDPublicKey) for file in files: file.write('%s\n' % decrypted.decode('utf8')) file.flush() mock_kms.revoke(policy_id)