#include "hybrid/step/configuration/step_merge_tpk_privileges.h"
#include "hybrid/step/configuration/step_set_mainapp.h"
#include "hybrid/step/configuration/step_stash_tpk_config.h"
-#include "hybrid/step/encryption/step_encrypt_resources.h"
+#include "hybrid/step/encryption/step_encrypt_hybrid_resources.h"
#include "hybrid/step/pkgmgr/step_merge_xml.h"
#include "wgt/step/configuration/step_parse.h"
#include "wgt/step/configuration/step_set_old_signature_files_location.h"
AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
AddStep<wgt::security::StepCheckWgtNotificationCategory>();
AddStep<wgt::security::StepCheckWgtImePrivilege>();
- AddStep<hybrid::encryption::StepEncryptResources>();
+ AddStep<hybrid::encryption::StepEncryptHybridResources>();
AddStep<ci::security::StepRollbackInstallationSecurity>();
AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
AddStep<ci::filesystem::StepAcquireExternalStorage>(false);
AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
AddStep<wgt::security::StepCheckWgtNotificationCategory>();
AddStep<wgt::security::StepCheckWgtImePrivilege>();
- AddStep<hybrid::encryption::StepEncryptResources>();
+ AddStep<hybrid::encryption::StepEncryptHybridResources>();
AddStep<ci::configuration::StepParseManifest>(
ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
ci::configuration::StepParseManifest::StoreLocation::BACKUP);
AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
AddStep<wgt::security::StepCheckWgtNotificationCategory>();
AddStep<wgt::security::StepCheckWgtImePrivilege>();
- AddStep<hybrid::encryption::StepEncryptResources>();
+ AddStep<hybrid::encryption::StepEncryptHybridResources>();
AddStep<ci::configuration::StepBlockCrossUpdate>();
AddStep<ci::pkgmgr::StepKillApps>();
AddStep<ci::backup::StepBackupManifest>();
AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
AddStep<wgt::security::StepCheckWgtNotificationCategory>();
AddStep<wgt::security::StepCheckWgtImePrivilege>();
- AddStep<hybrid::encryption::StepEncryptResources>();
+ AddStep<hybrid::encryption::StepEncryptHybridResources>();
AddStep<ci::security::StepRollbackInstallationSecurity>();
AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
AddStep<ci::mount::StepMountInstall>();
AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
AddStep<wgt::security::StepCheckWgtNotificationCategory>();
AddStep<wgt::security::StepCheckWgtImePrivilege>();
- AddStep<hybrid::encryption::StepEncryptResources>();
+ AddStep<hybrid::encryption::StepEncryptHybridResources>();
AddStep<ci::configuration::StepParseManifest>(
ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
ci::configuration::StepParseManifest::StoreLocation::BACKUP);
AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
AddStep<wgt::security::StepCheckWgtNotificationCategory>();
AddStep<wgt::security::StepCheckWgtImePrivilege>();
- AddStep<hybrid::encryption::StepEncryptResources>();
+ AddStep<hybrid::encryption::StepEncryptHybridResources>();
AddStep<ci::configuration::StepSwitchReadonlyMode>();
AddStep<ci::configuration::StepParseManifest>(
ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
#include <string>
#include <memory>
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+namespace ci = common_installer;
+
namespace {
const std::size_t kEncryptionChunkMaxSize = 8_kB; // bytes
const std::set<std::string> encryptSet { ".html", ".htm", ".css", ".js"};
-FILE* OpenFile(const std::string& path, const std::string& mode) {
+FILE* OpenFile(const bf::path& path, const std::string& mode) {
FILE* result = nullptr;
do {
namespace wgt {
namespace encryption {
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
-
-common_installer::Step::Status StepEncryptResources::precheck() {
+ci::Step::Status StepEncryptResources::precheck() {
backend_data_ = static_cast<WgtBackendData*>(context_->backend_data.get());
if (!backend_data_) {
LOG(ERROR) << "no backend data";
- return common_installer::Step::Status::ERROR;
+ return ci::Step::Status::ERROR;
}
SetEncryptionRoot();
return Step::Status::INVALID_VALUE;
}
- return common_installer::Step::Status::OK;
+ return ci::Step::Status::OK;
}
-common_installer::Step::Status StepEncryptResources::process() {
+ci::Step::Status StepEncryptResources::process() {
if (!backend_data_->settings.get().encryption_enabled()) {
LOG(DEBUG) << "no encryption";
- return common_installer::Step::Status::OK;
+ return ci::Step::Status::OK;
}
LOG(DEBUG) << "Encrypting";
if (!Encrypt(input_)) {
LOG(ERROR) << "Error during encryption";
- return common_installer::Step::Status::ERROR;
+ return ci::Step::Status::ERROR;
}
- return common_installer::Step::Status::OK;
+ return ci::Step::Status::OK;
}
bool StepEncryptResources::Encrypt(const bf::path &src) {
for (bf::directory_iterator file(src);
file != bf::directory_iterator();
++file) {
- bs::error_code error_code;
+ bs::error_code error;
bf::path current(file->path());
- bool is_dir = bf::is_directory(current, error_code);
- if (error_code)
+ bool is_dir = bf::is_directory(current, error);
+ if (error) {
+ LOG(ERROR) << "Failed to check directory status: " << error.message();
return false;
+ }
if (is_dir) {
if (!Encrypt(current))
return false;
continue;
}
- bool is_sym = bf::is_symlink(symlink_status(current, error_code));
- if (error_code)
+ bool is_sym = bf::is_symlink(symlink_status(current, error));
+ if (error) {
+ LOG(ERROR) << "Failed to check symlink status: " << error.message();
return false;
+ }
if (is_sym)
continue;
}
bool StepEncryptResources::EncryptFile(const bf::path &src) {
- bf::path encFile(src.string() + ".enc");
struct stat info;
memset(&info, 0, sizeof(info));
- if (stat(src.string().c_str(), &info) != 0) {
- LOG(ERROR) << "Could not access file " << src.string();
+ if (stat(src.c_str(), &info) != 0) {
+ LOG(ERROR) << "Could not access file " << src;
return false;
}
const std::size_t fileSize = info.st_size;
- if (0 == fileSize) {
- LOG(ERROR) << src.string().c_str() << " size is 0, so encryption is skiped";
+ if (!fileSize) {
+ LOG(ERROR) << src << " size is 0, so encryption will be skipped";
return true;
}
- FILE *input = OpenFile(src.string().c_str(), "rb");
- if (input == nullptr) {
- LOG(ERROR) << "Cannot open file for encryption: " << src.string();
+ FILE *input = OpenFile(src, "rb");
+ if (!input) {
+ LOG(ERROR) << "Cannot open file for encryption: " << src;
return false;
}
- FILE *output = OpenFile(encFile.string().c_str(), "wb");
- if (output == nullptr) {
- LOG(ERROR) << "Cannot create encrypted file: " << encFile.string();
+ bf::path encFile(src.string() + ".enc");
+ FILE *output = OpenFile(encFile, "wb");
+ if (!output) {
+ LOG(ERROR) << "Cannot create encrypted file: " << encFile;
fclose(input);
return false;
}
- std::size_t chunkSize = (fileSize > kEncryptionChunkMaxSize
- ? kEncryptionChunkMaxSize : fileSize);
+ std::size_t chunkSize = (fileSize > kEncryptionChunkMaxSize ?
+ kEncryptionChunkMaxSize : fileSize);
std::unique_ptr<unsigned char[]> inChunk(new unsigned char[chunkSize]);
std::size_t bytesRead = 0;
do {
bytesRead = ReadBytes(inChunk.get(), chunkSize, input);
- if (0 != bytesRead) {
+ if (!bytesRead) {
unsigned char* encrypted_data = nullptr;
size_t encrypted_size = 0;
// TODO(p.sikorski) check if it is Preloaded
int ret;
- if (context_->request_mode.get()
- == common_installer::RequestMode::GLOBAL) {
+ if (context_->request_mode.get() == ci::RequestMode::GLOBAL) {
ret = wae_encrypt_global_web_application(
context_->pkgid.get().c_str(),
- context_->is_readonly_package.get() ?
- true : false,
+ context_->is_readonly_package.get() ? true : false,
inChunk.get(),
(size_t)bytesRead,
&encrypted_data,
fclose(input);
LOG(DEBUG) << "File encrypted successfully";
- if (0 != unlink(src.string().c_str())) {
+ if (!unlink(src.c_str()))
return false;
- }
LOG(DEBUG) << "Rename encrypted file";
- if (0 != std::rename(encFile.c_str(), src.string().c_str())) {
+ if (!std::rename(encFile.c_str(), src.c_str()))
return false;
- }
return true;
}