Adapt to new EncryptedBlockStore
This commit is contained in:
parent
89a9f1e3d2
commit
22323a0a03
@ -7,13 +7,12 @@
|
|||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
|
|
||||||
using boost::property_tree::ptree;
|
using boost::property_tree::ptree;
|
||||||
using blockstore::encrypted::EncryptionKey;
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
CryConfig::CryConfig(const bf::path &configfile)
|
CryConfig::CryConfig(const bf::path &configfile)
|
||||||
:_configfile(configfile), _rootBlob(""), _encKey(EncryptionKey::CreateRandom()) {
|
:_configfile(configfile), _rootBlob(""), _encKey("") {
|
||||||
if (bf::exists(_configfile)) {
|
if (bf::exists(_configfile)) {
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
@ -24,18 +23,14 @@ void CryConfig::load() {
|
|||||||
read_json(_configfile.native(), pt);
|
read_json(_configfile.native(), pt);
|
||||||
|
|
||||||
_rootBlob = pt.get("cryfs.rootblob", "");
|
_rootBlob = pt.get("cryfs.rootblob", "");
|
||||||
|
_encKey = pt.get("cryfs.key", "");
|
||||||
string key = pt.get("cryfs.key", "");
|
|
||||||
if (key != "") {
|
|
||||||
_encKey = EncryptionKey::FromString(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryConfig::save() const {
|
void CryConfig::save() const {
|
||||||
ptree pt;
|
ptree pt;
|
||||||
|
|
||||||
pt.put("cryfs.rootblob", _rootBlob);
|
pt.put("cryfs.rootblob", _rootBlob);
|
||||||
pt.put("cryfs.key", _encKey.ToString());
|
pt.put("cryfs.key", _encKey);
|
||||||
|
|
||||||
write_json(_configfile.native(), pt);
|
write_json(_configfile.native(), pt);
|
||||||
}
|
}
|
||||||
@ -48,10 +43,14 @@ void CryConfig::SetRootBlob(const std::string &value) {
|
|||||||
_rootBlob = value;
|
_rootBlob = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blockstore::encrypted::EncryptionKey &CryConfig::EncryptionKey() const {
|
const string &CryConfig::EncryptionKey() const {
|
||||||
return _encKey;
|
return _encKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CryConfig::SetEncryptionKey(const std::string &value) {
|
||||||
|
_encKey = value;
|
||||||
|
}
|
||||||
|
|
||||||
CryConfig::~CryConfig() {
|
CryConfig::~CryConfig() {
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
#include "messmer/cpp-utils/macros.h"
|
#include "messmer/cpp-utils/macros.h"
|
||||||
#include "messmer/blockstore/implementations/encrypted/EncryptionKey.h"
|
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
@ -17,7 +16,8 @@ public:
|
|||||||
const std::string &RootBlob() const;
|
const std::string &RootBlob() const;
|
||||||
void SetRootBlob(const std::string &value);
|
void SetRootBlob(const std::string &value);
|
||||||
|
|
||||||
const blockstore::encrypted::EncryptionKey &EncryptionKey() const;
|
const std::string &EncryptionKey() const;
|
||||||
|
void SetEncryptionKey(const std::string &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::filesystem::path _configfile;
|
boost::filesystem::path _configfile;
|
||||||
@ -26,7 +26,7 @@ private:
|
|||||||
void save() const;
|
void save() const;
|
||||||
|
|
||||||
std::string _rootBlob;
|
std::string _rootBlob;
|
||||||
blockstore::encrypted::EncryptionKey _encKey;
|
std::string _encKey;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CryConfig);
|
DISALLOW_COPY_AND_ASSIGN(CryConfig);
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <messmer/blockstore/implementations/caching/CachingBlockStore.h>
|
#include <messmer/blockstore/implementations/caching/CachingBlockStore.h>
|
||||||
|
#include <messmer/blockstore/implementations/encrypted/ciphers/AES256_CFB.h>
|
||||||
#include "impl/DirBlob.h"
|
#include "impl/DirBlob.h"
|
||||||
#include "CryDevice.h"
|
#include "CryDevice.h"
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ using fspp::fuse::FuseErrnoException;
|
|||||||
using blockstore::BlockStore;
|
using blockstore::BlockStore;
|
||||||
using blockstore::Key;
|
using blockstore::Key;
|
||||||
using blockstore::encrypted::EncryptedBlockStore;
|
using blockstore::encrypted::EncryptedBlockStore;
|
||||||
|
using blockstore::encrypted::AES256_CFB;
|
||||||
using blobstore::onblocks::BlobStoreOnBlocks;
|
using blobstore::onblocks::BlobStoreOnBlocks;
|
||||||
using blobstore::onblocks::BlobOnBlocks;
|
using blobstore::onblocks::BlobOnBlocks;
|
||||||
using blockstore::caching::CachingBlockStore;
|
using blockstore::caching::CachingBlockStore;
|
||||||
@ -31,20 +33,29 @@ namespace cryfs {
|
|||||||
constexpr uint32_t CryDevice::BLOCKSIZE_BYTES;
|
constexpr uint32_t CryDevice::BLOCKSIZE_BYTES;
|
||||||
|
|
||||||
CryDevice::CryDevice(unique_ptr<CryConfig> config, unique_ptr<BlockStore> blockStore)
|
CryDevice::CryDevice(unique_ptr<CryConfig> config, unique_ptr<BlockStore> blockStore)
|
||||||
: _blobStore(make_unique<BlobStoreOnBlocks>(make_unique<CachingBlockStore>(make_unique<EncryptedBlockStore>(std::move(blockStore), config->EncryptionKey())), BLOCKSIZE_BYTES)), _rootKey(GetOrCreateRootKey(config.get())) {
|
: _blobStore(make_unique<BlobStoreOnBlocks>(make_unique<CachingBlockStore>(make_unique<EncryptedBlockStore<Cipher>>(std::move(blockStore), GetOrCreateEncryptionKey(config.get()))), BLOCKSIZE_BYTES)), _rootKey(GetOrCreateRootKey(config.get())) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Key CryDevice::GetOrCreateRootKey(CryConfig *config) {
|
Key CryDevice::GetOrCreateRootKey(CryConfig *config) {
|
||||||
string root_key = config->RootBlob();
|
string root_key = config->RootBlob();
|
||||||
if (root_key == "") {
|
if (root_key == "") {
|
||||||
auto key = CreateRootBlobAndReturnKey();
|
auto new_key = CreateRootBlobAndReturnKey();
|
||||||
config->SetRootBlob(key.ToString());
|
config->SetRootBlob(new_key.ToString());
|
||||||
return key;
|
return new_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Key::FromString(root_key);
|
return Key::FromString(root_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CryDevice::Cipher::EncryptionKey CryDevice::GetOrCreateEncryptionKey(CryConfig *config) {
|
||||||
|
string encryption_key = config->EncryptionKey();
|
||||||
|
if (encryption_key == "") {
|
||||||
|
auto new_key = Cipher::EncryptionKey::CreateRandom();
|
||||||
|
config->SetEncryptionKey(new_key.ToString());
|
||||||
|
return new_key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Key CryDevice::CreateRootBlobAndReturnKey() {
|
Key CryDevice::CreateRootBlobAndReturnKey() {
|
||||||
auto rootBlob = _blobStore->create();
|
auto rootBlob = _blobStore->create();
|
||||||
Key rootBlobKey = rootBlob->key();
|
Key rootBlobKey = rootBlob->key();
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "CryConfig.h"
|
#include "CryConfig.h"
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <messmer/blockstore/implementations/encrypted/ciphers/AES256_CFB.h>
|
||||||
#include <messmer/fspp/fs_interface/Device.h>
|
#include <messmer/fspp/fs_interface/Device.h>
|
||||||
|
|
||||||
#include "messmer/cpp-utils/macros.h"
|
#include "messmer/cpp-utils/macros.h"
|
||||||
@ -20,6 +21,8 @@ class CryDevice: public fspp::Device {
|
|||||||
public:
|
public:
|
||||||
static constexpr uint32_t BLOCKSIZE_BYTES = 32 * 1024;
|
static constexpr uint32_t BLOCKSIZE_BYTES = 32 * 1024;
|
||||||
|
|
||||||
|
using Cipher = blockstore::encrypted::AES256_CFB;
|
||||||
|
|
||||||
CryDevice(std::unique_ptr<CryConfig> config, std::unique_ptr<blockstore::BlockStore> blockStore);
|
CryDevice(std::unique_ptr<CryConfig> config, std::unique_ptr<blockstore::BlockStore> blockStore);
|
||||||
virtual ~CryDevice();
|
virtual ~CryDevice();
|
||||||
|
|
||||||
@ -35,6 +38,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
blockstore::Key GetOrCreateRootKey(CryConfig *config);
|
blockstore::Key GetOrCreateRootKey(CryConfig *config);
|
||||||
|
Cipher::EncryptionKey GetOrCreateEncryptionKey(CryConfig *config);
|
||||||
blockstore::Key CreateRootBlobAndReturnKey();
|
blockstore::Key CreateRootBlobAndReturnKey();
|
||||||
|
|
||||||
std::unique_ptr<blobstore::BlobStore> _blobStore;
|
std::unique_ptr<blobstore::BlobStore> _blobStore;
|
||||||
|
Loading…
Reference in New Issue
Block a user