Beispiel #1
0
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))
Beispiel #2
0
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))
Beispiel #3
0
 def test_object_encryption(self):
     """
     test_object_encryption
     """
     self.do_wait_for_tasks = False
     mydict = {"hello": "world"}
     encrypted_obj = msgpack_encrypt_pyobject("kjhfsd98", mydict)
     mydict2, secret = msgpack_decrypt_pyobject("kjhfsd98", encrypted_obj)
     self.assertEqual(mydict, mydict2)