void Container::extract_file(const path& relative_path) { send_callback(INFORMATION, EXTRACT_FILE, relative_path.raw_std_str()); if (file_exists(relative_path.str())) { std::string location(relative_path.str()); std::string filename(relative_path.get_filename()); std::string folder(relative_path.get_folderpath_unsecure()); container_handle::file_node fnode = handle_.get_filenode(relative_path); if (fnode.p == folder) { switch (algo_) { case AES: helper_extract_file<CryptoPP::AES>(fnode, (*volume_).drive_letter); break; case SERPENT: helper_extract_file<CryptoPP::Serpent>(fnode, (*volume_).drive_letter); break; case TWOFISH: helper_extract_file<CryptoPP::Twofish>(fnode, (*volume_).drive_letter); break; } } } //THROW }
Container::Container(const path& location, const std::string& pw, VirtualDisk_Impl::volume_handle* volume, encryption_algorithm algo) : volume_(volume), passphrase_(pw.begin(), pw.end()), seed_(32), is_syncing(false), container_open_(false), has_callback_(false) { using namespace CryptoPP; SHA256 shafunc; StringSource(pw.data(), true, new HashFilter(shafunc, new StringSink(pw_))); container_name_ = location.get_filename(); container_name_.erase(container_name_.find_first_of('.'), container_name_.size()); path_ = location; location.create_folderpath(); algo_ = algo; if (enhanced_passphrase_.size()) { std::vector<byte> tmp(std::begin(pw), std::end(pw)); tmp.insert(std::end(tmp), std::begin(enhanced_passphrase_), std::end(enhanced_passphrase_)); std::swap(tmp, enhanced_passphrase_); } else { for (byte b : pw) { enhanced_passphrase_.push_back(b); } } }
void Container::init(const path& location, const std::string& pw, encryption_algorithm algo) { using namespace CryptoPP; send_callback(VERBOSE, INIT_CONTAINER, location.std_str()); SHA256 shafunc; StringSource(pw.data(), true, new HashFilter(shafunc, new StringSink(pw_))); if (enhanced_passphrase_.size()) { std::vector<byte> tmp(std::begin(pw), std::end(pw)); tmp.insert(std::end(tmp), std::begin(enhanced_passphrase_), std::end(enhanced_passphrase_)); std::swap(tmp, enhanced_passphrase_); } else { for (byte b : pw) { enhanced_passphrase_.push_back(b); } } container_name_ = location.get_filename(); container_name_.erase(container_name_.find_first_of('.'), container_name_.size()); path_ = location; //fehler filename muss noch raus aus dem string location.create_folderpath(); algo_ = algo; }
void Container::add_file(const path& src, const std::string& rootfolder) { if (!validate()) { if (has_callback_) send_callback(CONFLICT, MISSING_ENC_FILES); else throw(std::logic_error("severe: synchronization with cloud incomplete!")); return; } std::string location = src.str(); std::string file_name = src.get_filename(); using namespace CryptoPP; /*std::string crc; if (!secure_crc(location, crc)) { return; }*/ std::string hash; if (!secure_hash(location, hash)) { return; } auto folderstart = location.find(rootfolder); auto folderend = location.find(src.get_filename()); path relativepath(std::string(location.begin() + folderstart, location.begin() + (folderend - 1))); path tmp = relativepath.append_filename(file_name); container_handle::file_node fnode = handle_.get_filenode(tmp); if (fnode.p == relativepath) { update_file(src.get_filename(), relativepath, src); return; } if (FileSystem::file_exists(location)) { send_callback(INFORMATION, ADD_FILE, src.std_str()); auto size = FileSystem::file_size(location); if (size >= 0) { path store_path; if (!handle_.where_to_store(size, store_path)) { return; } CloudManager& manager = CloudManager::instance(); std::string location_name = manager.get_location_name(store_path.raw_str()); container_handle::file_node file; file.filename = src.get_filename(); file.size = size; file.p = relativepath.std_str(); //file.crc = crc; file.hash = hash; std::string key; std::string iv; std::string hashname; bool ret = false; //file verschluesseln hier switch (algo_) { case AES: ret = helper_add_file<CryptoPP::AES>(src, store_path, iv, hashname); break; case SERPENT: ret = helper_add_file<CryptoPP::Serpent>(src, store_path, iv, hashname); break; case TWOFISH: ret = helper_add_file<CryptoPP::Twofish>(src, store_path, iv, hashname); break; default: return; } if (!ret) { handle_.update_memusage_location(location_name, -size); return; } container_handle::block_node block_node; block_node.id = 1; block_node.location = location_name; block_node.hash = hash; //block_node.crc = crc; block_node.filename = hashname; file.blocks.push_back(block_node); handle_.add_file_node(file); save(); } } #ifdef TDEBUG handle_.dump(std::string("C:\\Users\\Kai\\Desktop\\new_test.xml")); #endif }