コード例 #1
0
def setup():
    global config
    config = uconfig.set_default_curve()

    global mock_kms 
    mock_kms = MockNetwork()

    global api
    api = ipfsapi.connect('127.0.0.1', 5001)
コード例 #2
0
def setup():
	# Setup pyUmbral
	global config
	config = uconfig.set_default_curve()

	global mock_kms
	mock_kms = MockNetwork()

	global r
	r = redis.Redis(host='localhost', port=6379, db=0)
コード例 #3
0
def setup():
    # Setup pyUmbral
    global config
    config = uconfig.set_default_curve()

    global mock_kms
    mock_kms = MockNetwork()
    global bob_privkey
    bob_privkey = keys.UmbralPrivateKey.gen_key()
    global bob_pubkey
    bob_pubkey = bob_privkey.get_pubkey()
コード例 #4
0
ファイル: chat.py プロジェクト: ivanpankov365/ChatNum
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)
コード例 #5
0
# 1. Setup pyUmbral
config.set_default_curve()


# 2. Generate Keys and setup mock network
alice_privkey = keys.UmbralPrivateKey.gen_key()
alice_pubkey = alice_privkey.get_pubkey()

alice_signing_privkey = keys.UmbralPrivateKey.gen_key()
alice_signing_pubkey = alice_signing_privkey.get_pubkey()
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)
コード例 #6
0
from flask import Flask, render_template, request, url_for, jsonify
import json
app = Flask(__name__)
# pyUmbral encryption script
# https://github.com/nucypher/pyUmbral
# invoked from nodejs server.
import sys

from nucypher import MockNetwork
from umbral import pre, keys, config

UNDEFINED_MESSAGE = "command undefined"

# Setup pyUmbral
config.set_default_curve()
mock_kms = MockNetwork()


def encrypt_and_save(file_content, file_name, key):
    # Convert to UTF-8 bytes if not already in bytes format.
    # if not isinstance(file_content, (bytes, bytearray)):
    #     file_content = str(file_content).encode('utf-8')

    # TODO: pass keys in as params.
    priv_key = keys.UmbralPrivateKey.gen_key()
    pub_key = priv_key.get_pubkey()

    # Encrypt file data with public key.
    ciphertext, capsule = pre.encrypt(pub_key, file_content)

    # Save file locally on the server.
コード例 #7
0
from umbral import pre, keys, config


import argparse
import sys
import os


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'))