Esempio n. 1
0
def run(args):
    """Download a chunk of data from a file"""

    uid = str(args["uid"])
    drive_uid = str(args["drive_uid"])
    file_uid = str(args["file_uid"])
    chunk_idx = int(args["chunk_index"])
    secret = str(args["secret"])

    drive = DriveInfo(drive_uid=drive_uid)

    try:
        (data, meta, num_chunks) = drive.download_chunk(file_uid=file_uid,
                                                        downloader_uid=uid,
                                                        chunk_index=chunk_idx,
                                                        secret=secret)
    except IndexError:
        data = None
        meta = None
        num_chunks = None

    response = {}

    if data is not None:
        response["chunk"] = bytes_to_string(data)
        data = None

    if meta is not None:
        response["meta"] = json.dumps(meta)

    if num_chunks is not None:
        response["num_chunks"] = int(num_chunks)

    return response
Esempio n. 2
0
# The passphrase to unlock the key - VERY SECRET!!!
data["pass_phrase"] = sys.argv[2]

# Make sure that this is the correct password...
privkey = PrivateKey.read(sys.argv[1], sys.argv[2])

# The region for this tenancy
data["region"] = "eu-frankfurt-1"

secret_config["LOGIN"] = data

## Now create the bucket info so we know where the bucket is
## that will store all data related to logging into accounts

data = {}
data[
    "compartment"] = "ocid1.compartment.oc1..aaaaaaaat33j7w74mdyjenwoinyeawztxe7ri6qkfbm5oihqb5zteamvbpzq"
data["bucket"] = "acquire_compute"

secret_config["BUCKET"] = data

secret_config["PASSWORD"] = sys.argv[2]

config_data = bytes_to_string(
    config_key.encrypt(json.dumps(secret_config).encode("utf-8")))
secret_key = json.dumps(config_key.to_data(sys.argv[3]))

os.system("fn config app compute SECRET_CONFIG '%s'" % config_data)
os.system("fn config app compute SECRET_KEY '%s'" % secret_key)
def test_pack_unpack_args_returnvals():
    privkey = get_private_key("testing")
    pubkey = privkey.public_key()

    args = {"message": "Hello, this is a message",
            "status": 0,
            "long": [random.random() for _ in range(2)]}

    func = "test_function"

    packed = pack_arguments(function=func, args=args)

    crypted = pubkey.encrypt(packed)

    uncrypted = privkey.decrypt(crypted)

    (f, unpacked, keys) = unpack_arguments(args=uncrypted)

    print(keys)

    assert(args == unpacked)
    assert(f == func)

    packed = pack_arguments(function=func, args=args,
                            key=pubkey, response_key=pubkey,
                            public_cert=pubkey)

    data = json.loads(packed.decode("utf-8"))

    assert(data["encrypted"])
    assert(data["fingerprint"] == privkey.fingerprint())

    payload = privkey.decrypt(string_to_bytes(data["data"]))
    payload = json.loads(payload)

    assert(payload["sign_with_service_key"] == privkey.fingerprint())
    assert(payload["encryption_public_key"] == bytes_to_string(pubkey.bytes()))
    assert(payload["payload"] == args)

    (f, unpacked, keys) = unpack_arguments(function=func, args=packed,
                                           key=privkey)

    message = {"message": "OK"}

    return_value = create_return_value(message)

    packed_result = pack_return_value(function=func,
                                      payload=return_value, key=keys,
                                      private_cert=privkey)

    result = json.loads(packed_result.decode("utf-8"))

    assert(result["fingerprint"] == privkey.fingerprint())
    assert(result["encrypted"])
    data = string_to_bytes(result["data"])
    sig = string_to_bytes(result["signature"])

    pubkey.verify(signature=sig, message=data)

    data = json.loads(privkey.decrypt(data))

    assert(data["payload"]["return"] == message)

    result = unpack_return_value(return_value=packed_result,
                                 key=privkey, public_cert=pubkey)

    assert(result == message)

    try:
        return_value = create_return_value(_foo())
    except Exception as e:
        return_value = create_return_value(e)

    packed_result = pack_return_value(function=func,
                                      payload=return_value, key=keys,
                                      private_cert=privkey)

    with pytest.raises(PermissionError):
        result = unpack_return_value(function=func, return_value=packed_result,
                                     key=privkey, public_cert=pubkey)
Esempio n. 4
0
        config["credentials"]["key"] = key
        config["credentials"]["fingerprint"] = fingerprint
        print("\n****\nPlease make sure you upload %s to OCI\n****\n" % pubkey)

    unique_salt = str(fingerprint)

else:
    raise TypeError("Cannot recognise the type of service that "
                    "is being configured. This should be either "
                    "gcp or oci")

# now save the configuration to disk
d = {}
d["key"] = service_key.to_data(passphrase=password)
d["salt"] = service_salt
d["config"] = bytes_to_string(service_key.encrypt(json.dumps(config)))
with open(service_file, "w") as FILE:
    FILE.write(json.dumps(d))

# package all of the config data into a dictionary
data = {}

login = {}

login["service_type"] = service_type
login["bucket"] = bucket

if provider == "gcp":
    login["credentials"] = key
    login["project"] = project
    login["unique_suffix"] = unique_suffix