示例#1
0
def test_securexgboost_encryption(keys, data_paths):
    plaintext, encrypted, decrypted = data_paths

    mc2.encrypt_data(
        plaintext,
        encrypted,
        enc_format="securexgboost",
    )

    mc2.decrypt_data(encrypted, decrypted, enc_format="securexgboost")

    assert filecmp.cmp(plaintext, decrypted)
示例#2
0
def test_opaque_encryption(keys, data_paths, schema):
    plaintext, encrypted, decrypted = data_paths

    mc2.encrypt_data(
        plaintext,
        encrypted,
        schema_file=schema,
        enc_format="opaque",
    )

    mc2.decrypt_data(encrypted, decrypted, enc_format="opaque")

    # Remove first line (header) from original file,
    # as the decrypted copy doesn't have it
    with open(plaintext, "r") as f:
        original = f.readlines()[1:]

    with open(decrypted, "r") as f:
        copy = f.readlines()

    assert original == copy
示例#3
0
    # Remote path to results (a list)
    remote_results = config["cloud"]["results"]

    # Path to local results
    local_results_dir = config["local"]["results"]

    # TODO: upload data to multiple machines
    if args.command == "upload":
        encrypted_data = [d + ".enc" for d in data]
        print("Encrypting and uploading data...")

        for i in range(len(data)):
            # Encrypt data
            if args.xgb:
                mc2.encrypt_data(data[i], encrypted_data[i], None,
                                 "securexgboost")
            elif args.sql:
                if schemas is None:
                    raise Exception(
                        "Please specify a schema when uploading data for Opaque SQL"
                    )
                mc2.encrypt_data(data[i], encrypted_data[i], schemas[i],
                                 "opaque")
            else:
                raise Exception("Specified format not supported")

            # Transfer data
            filename = os.path.basename(encrypted_data[i])
            remote_path = os.path.join(remote_data, filename)
            mc2.upload_file(encrypted_data[i], remote_path)
            print("Uploaded data to {}".format(remote_path))
示例#4
0
        schemas = config_upload.get("schemas", [])

        if config_upload.get("storage") == "blob":
            use_azure = True
        else:
            use_azure = False

        encrypted_data = [d + ".enc" for d in data]

        print("Encrypting and uploading data...")

        dst_dir = config_upload.get("dst", "")
        for i in range(len(data)):
            # Encrypt data
            if enc_format == "xgb":
                mc2.encrypt_data(data[i], encrypted_data[i], None, "xgb")
            elif enc_format == "sql":
                if schemas is None:
                    raise Exception(
                        "Please specify a schema when uploading data for Opaque SQL"
                    )
                # Remove temporary files from a previous run
                if os.path.exists(encrypted_data[i]):
                    if os.path.isdir(encrypted_data[i]):
                        shutil.rmtree(encrypted_data[i])
                    else:
                        os.remove(encrypted_data[i])

                mc2.encrypt_data(data[i], encrypted_data[i], schemas[i], "sql")
            else:
                raise Exception(