Finish up hooking frontend and backend for export config

This commit is contained in:
Shreya 2021-06-01 12:14:57 +05:30 committed by VakarisZ
parent 46408e6d32
commit f4b5d341cf
3 changed files with 14 additions and 5 deletions

View File

@ -11,7 +11,7 @@ from monkey_island.cc.services.utils.config_encryption import encrypt_config
class ConfigurationExport(flask_restful.Resource):
@jwt_required
def get(self):
return {"encrypted_config": self.config_to_return}
return {"to_export": self.config_to_return, "is_plaintext": self.is_plaintext}
@jwt_required
def post(self):
@ -21,8 +21,10 @@ class ConfigurationExport(flask_restful.Resource):
plaintext_config = ConfigService.get_config()
self.config_to_return = plaintext_config
self.is_plaintext = True
if should_encrypt:
password = data["password"]
self.config_to_return = encrypt_config(plaintext_config, password)
self.is_plaintext = False
return self.get()

View File

@ -15,6 +15,7 @@ def encrypt_config(config: Dict, password: str) -> str:
pyAesCrypt.encryptStream(
plaintext_config_stream, ciphertext_config_stream, password, BUFFER_SIZE
)
ciphertext_config_bytes = str(ciphertext_config_stream.getvalue())
return ciphertext_config_bytes

View File

@ -35,11 +35,17 @@ const ConfigExportModal = (props: Props) => {
}
)
.then(res => res.json())
.then(res => {
console.log(res);
const configAsBinary = new Blob([res['encrypted_config']]);
.then(res => {
let configToExport = res['to_export'];
if (res['is_plaintext'] === true) {
const configAsBinary = new Blob([configToExport], {type: 'text/plain;charset=utf-8'});
FileSaver.saveAs(configAsBinary, 'monkey.conf');
}
else {
const configAsBinary = new Blob([configToExport.slice(2, -1)]);
FileSaver.saveAs(configAsBinary, 'monkey.conf');
}
})
}