forked from p15670423/monkey
Finish up hooking frontend and backend for export config
This commit is contained in:
parent
46408e6d32
commit
f4b5d341cf
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -36,10 +36,16 @@ const ConfigExportModal = (props: Props) => {
|
|||
)
|
||||
.then(res => res.json())
|
||||
.then(res => {
|
||||
console.log(res);
|
||||
const configAsBinary = new Blob([res['encrypted_config']]);
|
||||
|
||||
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');
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue