-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenc.cpp
More file actions
executable file
·107 lines (79 loc) · 3.31 KB
/
enc.cpp
File metadata and controls
executable file
·107 lines (79 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/******************************************************************************
Copyright 2024
File: enc.cpp
Author: NetRay
Date: May 1 2024
Flags: --atomic | --silent | --backup
Description: This is a utility tool used to encrypt/decrypt data.
******************************************************************************/
#include "../include/SysEnc.cpp"
int main(int argc, char **argv)
{
#if defined(__SYSTEM_ENCRYPTION_FF__)
using namespace System;
// Instance Declaration
Crypto Encryptor;
*Crypto::with_backup = false;
try
{
// prepare env variables(verbosity, atomicity, backup)
Encryptor.CliSetExeMode(argc, argv);
// Set Recovery key
const String_t recovery_key = Crypto::SetRecoveryKey();
if (recovery_key.empty()) [[unlikely]]
throw std::runtime_error("No Recovery Key Supplied!");
// Set the target to encrypt
const String_t set_target = Crypto::SetTargetPath();
if (set_target.empty()) [[unlikely]]
throw std::runtime_error("Target path is empty!!");
std::cout << "Scheduling path '" << set_target.c_str() << "' for Full Encryption...\n";
if (!Crypto::Approve()) [[unlikely]]
{
std::cout << "Ok, aborting!\n";
return EXIT_SUCCESS;
}
// register/store target
Crypto::RegisterTargetPath(std::move(set_target));
// get target
const std::optional<String_t> use_target = Crypto::GetTargetPath();
// verifying target value, if target was not registered, then stop
if (!use_target.has_value()) [[unlikely]]
throw std::runtime_error("no valid target path found!");
std::cout << "Using Target Path: " << use_target.value() << std::endl;
// Collect Resources
const std::vector<String_t> aggregation_stack = Crypto::DirectoryAggregation(std::move(use_target.value()));
if (aggregation_stack.empty()) [[unlikely]]
{
throw std::runtime_error("Nothing To Encrypt!");
}
// ask to create backup if no CLI arg for backup related was found
if (*Crypto::with_backup == 0)
*Crypto::with_backup = Crypto::Want2CreateBackup() ? 2 : 0;
if (*Crypto::with_backup >= 1)
{
if (!Crypto::CreateBackup(std::move(use_target.value()))) [[unlikely]]
{
throw std::runtime_error("Backup Operation Failed.. aborting..");
}
std::cout << "Backup Create Successfully!\n";
}
// Prepare Secure Key Block
const std::optional<CryptoPP::SecByteBlock> ParseKey = Crypto::RecoveryKeyIntersect(std::move(recovery_key));
if (!ParseKey.has_value()) [[unlikely]]
throw std::runtime_error("Error Intersection Recovery Key");
// Encrypt File Content
for (const String_t &resource : aggregation_stack)
if (!Crypto::EncryptFile(std::move(resource.c_str()), ParseKey.value())) [[unlikely]]
throw std::runtime_error("Cannot encrypt file");
}
catch (const std::runtime_error &_e)
{
Crypto::LogError("Error: ", _e.what(), '\n');
}
catch (const std::exception &_e)
{
Crypto::LogError("Error: ", _e.what(), '\n');
}
#endif
return EXIT_SUCCESS;
};