CryFS stores root blob key in config file!
This commit is contained in:
parent
30ac3ab3cb
commit
fcc22fe054
@ -1,3 +1,3 @@
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp impl/DirBlob.cpp)
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryConfig.cpp impl/DirBlob.cpp)
|
||||
|
||||
target_link_libraries(cryfs_lib)
|
||||
|
47
src/cryfs_lib/CryConfig.cpp
Normal file
47
src/cryfs_lib/CryConfig.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <cryfs_lib/CryConfig.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryConfig::CryConfig(const bf::path &configfile)
|
||||
:_configfile(configfile), _root_blob("") {
|
||||
if (bf::exists(_configfile)) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
void CryConfig::load() {
|
||||
ptree pt;
|
||||
read_json(_configfile.native(), pt);
|
||||
|
||||
_root_blob = pt.get("cryfs.rootblob", "");
|
||||
}
|
||||
|
||||
void CryConfig::save() const {
|
||||
ptree pt;
|
||||
|
||||
pt.put("cryfs.rootblob", _root_blob);
|
||||
|
||||
write_json(_configfile.native(), pt);
|
||||
}
|
||||
|
||||
const std::string &CryConfig::RootBlob() const {
|
||||
return _root_blob;
|
||||
}
|
||||
|
||||
void CryConfig::SetRootBlob(const std::string &value) {
|
||||
_root_blob = value;
|
||||
}
|
||||
|
||||
CryConfig::~CryConfig() {
|
||||
save();
|
||||
}
|
||||
|
||||
}
|
29
src/cryfs_lib/CryConfig.h
Normal file
29
src/cryfs_lib/CryConfig.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_CRYCONFIG_H_
|
||||
#define CRYFS_LIB_CRYCONFIG_H_
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class CryConfig {
|
||||
public:
|
||||
CryConfig(const boost::filesystem::path &configfile);
|
||||
virtual ~CryConfig();
|
||||
|
||||
const std::string &RootBlob() const;
|
||||
void SetRootBlob(const std::string &value);
|
||||
|
||||
private:
|
||||
boost::filesystem::path _configfile;
|
||||
|
||||
void load();
|
||||
void save() const;
|
||||
|
||||
std::string _root_blob;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -20,12 +20,19 @@ using blobstore::BlobStore;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryDevice::CryDevice(unique_ptr<BlobStore> blobStore)
|
||||
: _blob_store(std::move(blobStore)), _root_key() {
|
||||
CryDevice::CryDevice(unique_ptr<CryConfig> config, unique_ptr<BlobStore> blobStore)
|
||||
: _blob_store(std::move(blobStore)), _root_key(config->RootBlob()) {
|
||||
if (_root_key == "") {
|
||||
_root_key = CreateRootBlobAndReturnKey();
|
||||
config->SetRootBlob(_root_key);
|
||||
}
|
||||
}
|
||||
|
||||
string CryDevice::CreateRootBlobAndReturnKey() {
|
||||
auto rootBlob = _blob_store->create(DIR_BLOBSIZE);
|
||||
DirBlob rootDir(std::move(rootBlob.blob));
|
||||
rootDir.InitializeEmptyDir();
|
||||
_root_key = rootBlob.key;
|
||||
return rootBlob.key;
|
||||
}
|
||||
|
||||
CryDevice::~CryDevice() {
|
||||
|
@ -2,6 +2,8 @@
|
||||
#ifndef CRYFS_LIB_CRYDEVICE_H_
|
||||
#define CRYFS_LIB_CRYDEVICE_H_
|
||||
|
||||
#include "CryConfig.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <fspp/fs_interface/Device.h>
|
||||
|
||||
@ -17,7 +19,7 @@ class CryDevice: public fspp::Device {
|
||||
public:
|
||||
static constexpr size_t DIR_BLOBSIZE = 4096;
|
||||
|
||||
CryDevice(std::unique_ptr<blobstore::BlobStore> blobStore);
|
||||
CryDevice(std::unique_ptr<CryConfig> config, std::unique_ptr<blobstore::BlobStore> blobStore);
|
||||
virtual ~CryDevice();
|
||||
|
||||
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
||||
@ -25,12 +27,11 @@ public:
|
||||
blobstore::BlobWithKey CreateBlob(size_t size);
|
||||
|
||||
private:
|
||||
std::string CreateRootBlobAndReturnKey();
|
||||
std::unique_ptr<fspp::Node> Load(const bf::path &path) override;
|
||||
|
||||
std::unique_ptr<blobstore::BlobStore> _blob_store;
|
||||
|
||||
//TODO This takes a new root key each run, the filesystem won't survive restarting the daemon...
|
||||
// Find a way so that the next run will recognize the created root element.
|
||||
std::string _root_key;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryDevice);
|
||||
|
@ -19,7 +19,8 @@ int main (int argc, char *argv[])
|
||||
{
|
||||
printf("Version: %d\n", buildconfig::VERSION::MAJOR);
|
||||
auto blobStore = make_unique<OnDiskBlobStore>(bf::path("/home/heinzi/cryfstest/root"));
|
||||
cryfs::CryDevice device(std::move(blobStore));
|
||||
auto config = make_unique<cryfs::CryConfig>(bf::path("/home/heinzi/cryfstest/config.json"));
|
||||
cryfs::CryDevice device(std::move(config), std::move(blobStore));
|
||||
fspp::FilesystemImpl fsimpl(&device);
|
||||
fspp::fuse::Fuse fuse(&fsimpl);
|
||||
fuse.run(argc, argv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user