def hide_config(options, salt, secret): """ @type options: optparse.Values, instance @param salt: @type salt: @param secret: @type secret: """ if salt and secret: datadir = get_data_dir(options) mempath = os.path.join(datadir, "memory.pickle") jsonpath = os.path.join(datadir, "memory.pickle.json") if os.path.exists(jsonpath): os.remove(jsonpath) if os.path.exists(mempath): read_and_encrypt_file(mempath, mempath + ".enc", secret) os.remove(mempath) hidden_name = "." + get_uuid(3) while hidden_name in os.listdir(options.dir): hidden_name = "." + get_uuid(3) encrypted_name = msgpack_encrypt_pyobject(secret, options.cryptobox) pickle_object(os.path.join(options.dir, hidden_name + ".cryptoboxfolder"), {"encrypted_name": encrypted_name, "salt": salt}) os.rename(options.dir, os.path.join(os.path.dirname(options.dir), hidden_name))
def hide_config(options, salt, secret): """ @type options: optparse.Values, instance @param salt: @type salt: @param secret: @type secret: """ if salt and secret: datadir = get_data_dir(options) mempath = os.path.join(datadir, "memory.pickle") jsonpath = os.path.join(datadir, "memory.pickle.json") if os.path.exists(jsonpath): os.remove(jsonpath) if os.path.exists(mempath): read_and_encrypt_file(mempath, mempath + ".enc", secret) os.remove(mempath) hidden_name = "." + get_uuid(3) while hidden_name in os.listdir(options.dir): hidden_name = "." + get_uuid(3) encrypted_name = msgpack_encrypt_pyobject(secret, options.cryptobox) pickle_object( os.path.join(options.dir, hidden_name + ".cryptoboxfolder"), { "encrypted_name": encrypted_name, "salt": salt }) os.rename(options.dir, os.path.join(os.path.dirname(options.dir), hidden_name))
def encrypt_new_blobs(secret, new_blobs): """ @type secret: str or unicode @type new_blobs: dict """ processed_files = 0 numfiles = len(new_blobs) for fhash in new_blobs: ensure_directory(new_blobs[fhash]["blobdir"]) update_progress(processed_files, numfiles, "encrypting: " + os.path.basename(new_blobs[fhash]["fpath"])) read_and_encrypt_file(new_blobs[fhash]["fpath"], new_blobs[fhash]["blobpath"], secret) processed_files += 1