mirror of
https://github.com/vgough/encfs.git
synced 2024-11-21 23:43:26 +01:00
reworked encfs6 read support to better handle variants
git-svn-id: http://encfs.googlecode.com/svn/trunk@88 db9cf616-1c43-0410-9cb8-a902689de0d6
This commit is contained in:
parent
a3a676c7d0
commit
22e29faea1
@ -280,14 +280,17 @@ bool readV6Config( const char *configFile,
|
||||
return false;
|
||||
}
|
||||
|
||||
int version = 0;
|
||||
(*config)["@version"] >> version;
|
||||
int version;
|
||||
if (!config->read("version", &version) &&
|
||||
!config->read("@version", &version)) {
|
||||
rError("Unable to find version in config file");
|
||||
return false;
|
||||
}
|
||||
|
||||
// version numbering was complicated by boost::archive
|
||||
if (version == 20 || version >= 20100713)
|
||||
{
|
||||
rInfo("found new serialization format");
|
||||
(*config)["version"] >> version;
|
||||
cfg.set_revision(version);
|
||||
} else if (version == 26800)
|
||||
{
|
||||
@ -307,21 +310,21 @@ bool readV6Config( const char *configFile,
|
||||
}
|
||||
rInfo("subVersion = %i", cfg.revision());
|
||||
|
||||
(*config)["creator"] >> (*cfg.mutable_creator());
|
||||
(*config)["cipherAlg"] >> (*cfg.mutable_cipher());
|
||||
(*config)["nameAlg"] >> (*cfg.mutable_naming());
|
||||
config->read("creator", cfg.mutable_creator());
|
||||
config->read("cipherAlg", cfg.mutable_cipher());
|
||||
config->read("nameAlg", cfg.mutable_naming());
|
||||
|
||||
//(*config)["keySize"] >> cfg.keySize;
|
||||
int blockSize, blockMacBytes, blockMacRandBytes;
|
||||
bool uniqueIv, chainedNameIv, externalIv, allowHoles;
|
||||
|
||||
(*config)["blockSize"] >> blockSize;
|
||||
(*config)["uniqueIV"] >> uniqueIv;
|
||||
(*config)["chainedNameIV"] >> chainedNameIv;
|
||||
(*config)["externalIVChaining"] >> externalIv;
|
||||
(*config)["blockMACBytes"] >> blockMacBytes;
|
||||
(*config)["blockMACRandBytes"] >> blockMacRandBytes;
|
||||
(*config)["allowHoles"] >> allowHoles;
|
||||
config->read("blockSize", &blockSize);
|
||||
config->read("uniqueIV", &uniqueIv);
|
||||
config->read("chainedNameIV", &chainedNameIv);
|
||||
config->read("externalIVChaining", &externalIv);
|
||||
config->read("blockMACBytes", &blockMacBytes);
|
||||
config->read("blockMACRandBytes", &blockMacRandBytes);
|
||||
config->read("allowHoles", &allowHoles);
|
||||
|
||||
cfg.set_block_size(blockSize);
|
||||
cfg.set_unique_iv(uniqueIv);
|
||||
@ -333,28 +336,28 @@ bool readV6Config( const char *configFile,
|
||||
|
||||
EncryptedKey *encryptedKey = cfg.mutable_key();
|
||||
int encodedSize;
|
||||
(*config)["encodedKeySize"] >> encodedSize;
|
||||
config->read("encodedKeySize", &encodedSize);
|
||||
unsigned char *key = new unsigned char[encodedSize];
|
||||
(*config)["encodedKeyData"]->readB64Data(key, encodedSize);
|
||||
config->readB64("encodedKeyData", key, encodedSize);
|
||||
encryptedKey->set_ciphertext(key, encodedSize);
|
||||
delete[] key;
|
||||
|
||||
int keySize;
|
||||
(*config)["keySize"] >> keySize;
|
||||
config->read("keySize", &keySize);
|
||||
encryptedKey->set_size(keySize / 8); // save as size in bytes
|
||||
|
||||
if(cfg.revision() >= 20080816)
|
||||
{
|
||||
int saltLen;
|
||||
(*config)["saltLen"] >> saltLen;
|
||||
config->read("saltLen", &saltLen);
|
||||
unsigned char *salt = new unsigned char[saltLen];
|
||||
(*config)["saltData"]->readB64Data(salt, saltLen);
|
||||
config->readB64("saltData", salt, saltLen);
|
||||
encryptedKey->set_salt(salt, saltLen);
|
||||
delete[] salt;
|
||||
|
||||
int kdfIterations, desiredKDFDuration;
|
||||
(*config)["kdfIterations"] >> kdfIterations;
|
||||
(*config)["desiredKDFDuration"] >> desiredKDFDuration;
|
||||
config->read("kdfIterations", &kdfIterations);
|
||||
config->read("desiredKDFDuration", &desiredKDFDuration);
|
||||
encryptedKey->set_kdf_iterations(kdfIterations);
|
||||
encryptedKey->set_kdf_duration(desiredKDFDuration);
|
||||
} else
|
||||
|
@ -66,17 +66,6 @@ const ConfigVar & operator >> (const ConfigVar &src, Interface &iface)
|
||||
return src;
|
||||
}
|
||||
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &src, Interface &iface)
|
||||
{
|
||||
(*src)["name"] >> *iface.mutable_name();
|
||||
int major, minor;
|
||||
(*src)["major"] >> major;
|
||||
(*src)["minor"] >> minor;
|
||||
iface.set_major(major);
|
||||
iface.set_minor(minor);
|
||||
return src;
|
||||
}
|
||||
|
||||
bool operator != (const Interface &a, const Interface &b)
|
||||
{
|
||||
if (a.major() != b.major())
|
||||
|
@ -19,7 +19,6 @@
|
||||
#define _Interface_incl_
|
||||
|
||||
#include <string>
|
||||
#include "XmlReader.h"
|
||||
#include "config.pb.h"
|
||||
|
||||
// check if A implements the interface described by B.
|
||||
@ -33,7 +32,6 @@ Interface makeInterface( const char *name, int major, int minor, int age );
|
||||
// Reae operation
|
||||
class ConfigVar;
|
||||
const ConfigVar & operator >> (const ConfigVar &, Interface &);
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &, Interface &);
|
||||
|
||||
bool operator != (const Interface &a, const Interface &b);
|
||||
|
||||
|
@ -19,9 +19,6 @@
|
||||
*/
|
||||
|
||||
#include "XmlReader.h"
|
||||
#include "base64.h"
|
||||
|
||||
#include <rlog/rlog.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -38,6 +35,10 @@
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/buffer.h>
|
||||
|
||||
#include <rlog/rlog.h>
|
||||
#include "base64.h"
|
||||
#include "Interface.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace rlog;
|
||||
|
||||
@ -47,48 +48,72 @@ XmlValue::~XmlValue()
|
||||
|
||||
XmlValuePtr XmlValue::operator[] (const char *path) const
|
||||
{
|
||||
return this->find(path);
|
||||
return find(path);
|
||||
}
|
||||
|
||||
XmlValuePtr XmlValue::find(const char *name) const
|
||||
XmlValuePtr XmlValue::find(const char *path) const
|
||||
{
|
||||
rError("in XmlValue::operator[%s]", name);
|
||||
return XmlValuePtr(new XmlValue());
|
||||
rError("in XmlValue::find(%s)", path);
|
||||
return XmlValuePtr();
|
||||
}
|
||||
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, std::string &out)
|
||||
bool XmlValue::read(const char *path, std::string *out) const
|
||||
{
|
||||
out = ptr->text();
|
||||
return ptr;
|
||||
XmlValuePtr value = find(path);
|
||||
if (!value)
|
||||
return false;
|
||||
|
||||
*out = value->text();
|
||||
return true;
|
||||
}
|
||||
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, int &out)
|
||||
bool XmlValue::read(const char *path, int *out) const
|
||||
{
|
||||
out = atoi(ptr->text().c_str());
|
||||
return ptr;
|
||||
XmlValuePtr value = find(path);
|
||||
if (!value)
|
||||
return false;
|
||||
|
||||
*out = atoi(value->text().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, long &out)
|
||||
bool XmlValue::read(const char *path, long *out) const
|
||||
{
|
||||
out = atol(ptr->text().c_str());
|
||||
return ptr;
|
||||
XmlValuePtr value = find(path);
|
||||
if (!value)
|
||||
return false;
|
||||
|
||||
*out = atol(value->text().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, double &out)
|
||||
bool XmlValue::read(const char *path, double *out) const
|
||||
{
|
||||
out = atof(ptr->text().c_str());
|
||||
return ptr;
|
||||
XmlValuePtr value = find(path);
|
||||
if (!value)
|
||||
return false;
|
||||
|
||||
*out = atof(value->text().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, bool &out)
|
||||
bool XmlValue::read(const char *path, bool *out) const
|
||||
{
|
||||
out = atoi(ptr->text().c_str());
|
||||
return ptr;
|
||||
XmlValuePtr value = find(path);
|
||||
if (!value)
|
||||
return false;
|
||||
|
||||
*out = atoi(value->text().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool XmlValue::readB64Data(unsigned char *data, int length) const
|
||||
bool XmlValue::readB64(const char *path, unsigned char *data, int length) const
|
||||
{
|
||||
std::string s = value;
|
||||
XmlValuePtr value = find(path);
|
||||
if (!value)
|
||||
return false;
|
||||
|
||||
std::string s = value->text();
|
||||
s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
|
||||
|
||||
BIO *b64 = BIO_new(BIO_f_base64());
|
||||
@ -110,9 +135,31 @@ bool XmlValue::readB64Data(unsigned char *data, int length) const
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string safeValueForNode(TiXmlElement *element)
|
||||
bool XmlValue::read(const char *path, Interface *out) const
|
||||
{
|
||||
XmlValuePtr node = find(path);
|
||||
if (!node)
|
||||
return false;
|
||||
|
||||
int major, minor;
|
||||
bool ok = node->read("name", out->mutable_name())
|
||||
&& node->read("major", &major)
|
||||
&& node->read("minor", &minor);
|
||||
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
out->set_major(major);
|
||||
out->set_minor(minor);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string safeValueForNode(const TiXmlElement *element)
|
||||
{
|
||||
std::string value;
|
||||
if (element == NULL)
|
||||
return value;
|
||||
|
||||
const TiXmlNode *child = element->FirstChild();
|
||||
if (child)
|
||||
{
|
||||
@ -126,9 +173,9 @@ std::string safeValueForNode(TiXmlElement *element)
|
||||
|
||||
class XmlNode : virtual public XmlValue
|
||||
{
|
||||
TiXmlElement *element;
|
||||
const TiXmlElement *element;
|
||||
public:
|
||||
XmlNode(TiXmlElement *element_)
|
||||
XmlNode(const TiXmlElement *element_)
|
||||
: XmlValue(safeValueForNode(element_))
|
||||
, element(element_)
|
||||
{
|
||||
@ -142,10 +189,18 @@ public:
|
||||
{
|
||||
if (name[0] == '@')
|
||||
{
|
||||
return XmlValuePtr(new XmlValue(element->Attribute(name+1)));
|
||||
const char *value = element->Attribute(name+1);
|
||||
if (value)
|
||||
return XmlValuePtr(new XmlValue(value));
|
||||
else
|
||||
return XmlValuePtr();
|
||||
} else
|
||||
{
|
||||
return XmlValuePtr(new XmlNode(element->FirstChild(name)->ToElement()));
|
||||
const TiXmlElement *el = element->FirstChildElement(name);
|
||||
if (el)
|
||||
return XmlValuePtr(new XmlNode(el));
|
||||
else
|
||||
return XmlValuePtr();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -27,6 +27,8 @@
|
||||
class XmlValue;
|
||||
typedef shared_ptr<XmlValue> XmlValuePtr;
|
||||
|
||||
class Interface;
|
||||
|
||||
class XmlValue
|
||||
{
|
||||
std::string value;
|
||||
@ -43,23 +45,25 @@ public:
|
||||
|
||||
XmlValuePtr operator[] (const char *path) const;
|
||||
|
||||
bool readB64Data(unsigned char *data, int length) const;
|
||||
|
||||
const std::string &text() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
bool read(const char *path, std::string *out) const;
|
||||
bool readB64(const char *path, unsigned char *out, int length) const;
|
||||
|
||||
bool read(const char *path, int *out) const;
|
||||
bool read(const char *path, long *out) const;
|
||||
bool read(const char *path, double *out) const;
|
||||
bool read(const char *path, bool *out) const;
|
||||
|
||||
bool read(const char *path, Interface *out) const;
|
||||
|
||||
protected:
|
||||
virtual XmlValuePtr find(const char *name) const;
|
||||
};
|
||||
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, std::string &outStr);
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, int &out);
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, long &out);
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, double &out);
|
||||
const XmlValuePtr & operator >> (const XmlValuePtr &ptr, bool &out);
|
||||
|
||||
class XmlReader
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user