2008-01-07 09:09:04 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Author: Valient Gough <vgough@pobox.com>
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2012-10-03 07:12:17 +02:00
|
|
|
* Copyright (c) 2004-2012, Valient Gough
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
2013-10-20 00:35:26 +02:00
|
|
|
* option) any later version.
|
2008-01-07 09:09:04 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
2012-10-03 07:12:17 +02:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-01-07 09:09:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
// defines needed for RedHat 7.3...
|
|
|
|
#ifdef linux
|
2013-10-20 00:35:26 +02:00
|
|
|
#define _XOPEN_SOURCE 500 // make sure pwrite() is pulled in
|
2008-01-07 09:09:04 +01:00
|
|
|
#endif
|
2013-10-20 00:35:26 +02:00
|
|
|
#define _BSD_SOURCE // pick up setenv on RH7.3
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
#include "fs/encfs.h"
|
2013-03-05 07:29:58 +01:00
|
|
|
#include "fs/fsconfig.pb.h"
|
2013-01-29 04:07:54 +01:00
|
|
|
|
|
|
|
#include "base/autosprintf.h"
|
|
|
|
#include "base/config.h"
|
|
|
|
#include "base/ConfigReader.h"
|
|
|
|
#include "base/Error.h"
|
|
|
|
#include "base/i18n.h"
|
|
|
|
#include "base/XmlReader.h"
|
|
|
|
|
2013-03-05 07:36:32 +01:00
|
|
|
#include "cipher/CipherV1.h"
|
2013-01-29 04:07:54 +01:00
|
|
|
#include "cipher/MemoryPool.h"
|
|
|
|
#include "cipher/readpassphrase.h"
|
|
|
|
|
|
|
|
#include "fs/BlockNameIO.h"
|
|
|
|
#include "fs/Context.h"
|
|
|
|
#include "fs/DirNode.h"
|
|
|
|
#include "fs/FileUtils.h"
|
|
|
|
#include "fs/FSConfig.h"
|
|
|
|
#include "fs/NullNameIO.h"
|
|
|
|
#include "fs/StreamNameIO.h"
|
|
|
|
|
|
|
|
#include <glog/logging.h>
|
2008-01-07 09:09:04 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2008-05-19 06:08:58 +02:00
|
|
|
#include <cctype>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <cstring>
|
2008-01-07 09:09:04 +01:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
#include <google/protobuf/text_format.h>
|
|
|
|
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
2008-04-13 22:35:57 +02:00
|
|
|
|
2013-03-05 07:39:51 +01:00
|
|
|
using gnu::autosprintf;
|
|
|
|
using std::cout;
|
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
|
|
|
using std::map;
|
|
|
|
using std::string;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-03-05 07:29:58 +01:00
|
|
|
namespace encfs {
|
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
static const int DefaultBlockSize = 2048;
|
2008-01-13 00:13:49 +01:00
|
|
|
// The maximum length of text passwords. If longer are needed,
|
|
|
|
// use the extpass option, as extpass can return arbitrary length binary data.
|
2013-01-29 04:07:54 +01:00
|
|
|
static const int MaxPassBuf = 2048;
|
2008-01-13 00:13:49 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static const int NormalKDFDuration = 500; // 1/2 a second
|
|
|
|
static const int ParanoiaKDFDuration = 3000; // 3 seconds
|
2008-08-17 09:26:52 +02:00
|
|
|
|
2008-01-07 09:09:04 +01:00
|
|
|
// environment variable names for values encfs stores in the environment when
|
|
|
|
// calling an external password program.
|
|
|
|
static const char ENCFS_ENV_ROOTDIR[] = "encfs_root";
|
|
|
|
static const char ENCFS_ENV_STDOUT[] = "encfs_stdout";
|
|
|
|
static const char ENCFS_ENV_STDERR[] = "encfs_stderr";
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
const int V5Latest = 20040813; // fix MACFileIO block size issues
|
2013-01-29 04:07:54 +01:00
|
|
|
const int ProtoSubVersion = 20120902;
|
2012-04-26 04:34:15 +02:00
|
|
|
|
|
|
|
const char ConfigFileName[] = ".encfs.txt";
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
struct ConfigInfo {
|
2012-04-26 04:18:26 +02:00
|
|
|
ConfigType type;
|
2012-04-26 04:34:15 +02:00
|
|
|
const char *fileName;
|
2012-04-26 04:18:26 +02:00
|
|
|
const char *environmentOverride;
|
2013-10-20 00:35:26 +02:00
|
|
|
bool (*loadFunc)(const char *fileName, EncfsConfig &config, ConfigInfo *cfg);
|
2008-01-07 09:09:04 +01:00
|
|
|
} ConfigFileMapping[] = {
|
2013-10-20 00:35:26 +02:00
|
|
|
{Config_V7, ConfigFileName, "ENCFS_CONFIG", readProtoConfig},
|
|
|
|
{Config_V6, ".encfs6.xml", "ENCFS6_CONFIG", readV6Config},
|
|
|
|
// backward compatible support for older versions
|
|
|
|
{Config_V5, ".encfs5", "ENCFS5_CONFIG", readV5Config},
|
|
|
|
{Config_V4, ".encfs4", NULL, readV4Config},
|
|
|
|
// prehistoric - no longer support
|
|
|
|
{Config_V3, ".encfs3", NULL, NULL},
|
|
|
|
{Config_Prehistoric, ".encfs2", NULL, NULL},
|
|
|
|
{Config_Prehistoric, ".encfs", NULL, NULL},
|
|
|
|
{Config_None, NULL, NULL, NULL}};
|
|
|
|
|
|
|
|
EncFS_Root::EncFS_Root() {}
|
|
|
|
|
|
|
|
EncFS_Root::~EncFS_Root() {}
|
|
|
|
|
|
|
|
bool fileExists(const char *fileName) {
|
2012-04-26 04:18:26 +02:00
|
|
|
struct stat buf;
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!lstat(fileName, &buf)) {
|
2012-04-26 04:18:26 +02:00
|
|
|
return true;
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// XXX show perror?
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool isDirectory(const char *fileName) {
|
2012-04-26 04:18:26 +02:00
|
|
|
struct stat buf;
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!lstat(fileName, &buf)) {
|
|
|
|
return S_ISDIR(buf.st_mode);
|
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool isAbsolutePath(const char *fileName) {
|
|
|
|
if (fileName && fileName[0] != '\0' && fileName[0] == '/')
|
2012-04-26 04:18:26 +02:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
const char *lastPathElement(const char *name) {
|
|
|
|
const char *loc = strrchr(name, '/');
|
2012-04-26 04:18:26 +02:00
|
|
|
return loc ? loc + 1 : name;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
std::string parentDirectory(const std::string &path) {
|
|
|
|
size_t last = path.find_last_of('/');
|
|
|
|
if (last == string::npos)
|
2012-04-26 04:18:26 +02:00
|
|
|
return string("");
|
|
|
|
else
|
|
|
|
return path.substr(0, last);
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool userAllowMkdir(const char *path, mode_t mode) {
|
|
|
|
return userAllowMkdir(0, path, mode);
|
2010-12-07 10:14:17 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool userAllowMkdir(int promptno, const char *path, mode_t mode) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// TODO: can we internationalize the y/n names? Seems strange to prompt in
|
|
|
|
// their own language but then have to respond 'y' or 'n'.
|
|
|
|
// xgroup(setup)
|
2013-10-20 00:35:26 +02:00
|
|
|
cerr << autosprintf(_("The directory \"%s\" does not exist. "
|
|
|
|
"Should it be created? (y,n) "),
|
|
|
|
path);
|
2012-04-26 04:18:26 +02:00
|
|
|
char answer[10];
|
|
|
|
char *res;
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
switch (promptno) {
|
|
|
|
case 1:
|
|
|
|
cerr << endl << "$PROMPT$ create_root_dir" << endl;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
cerr << endl << "$PROMPT$ create_mount_point" << endl;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
res = fgets(answer, sizeof(answer), stdin);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (res != 0 && toupper(answer[0]) == 'Y') {
|
|
|
|
int result = mkdir(path, mode);
|
|
|
|
if (result < 0) {
|
|
|
|
perror(_("Unable to create directory: "));
|
2012-04-26 04:18:26 +02:00
|
|
|
return false;
|
2008-01-07 09:09:04 +01:00
|
|
|
} else
|
2012-04-26 04:18:26 +02:00
|
|
|
return true;
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// Directory not created, by user request
|
|
|
|
cerr << _("Directory not created.") << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
ConfigType readConfig_load(ConfigInfo *nm, const char *path,
|
|
|
|
EncfsConfig &config) {
|
|
|
|
if (nm->loadFunc) {
|
|
|
|
try {
|
|
|
|
if ((*nm->loadFunc)(path, config, nm)) return nm->type;
|
|
|
|
}
|
|
|
|
catch (Error &err) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(WARNING) << "readConfig failed: " << err.what();
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Found config file " << path << ", but failed to load";
|
2012-04-26 04:18:26 +02:00
|
|
|
return Config_None;
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// No load function - must be an unsupported type..
|
2012-04-26 04:34:15 +02:00
|
|
|
return Config_None;
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
ConfigType readConfig(const string &rootDir, EncfsConfig &config) {
|
2012-04-26 04:18:26 +02:00
|
|
|
ConfigInfo *nm = ConfigFileMapping;
|
2013-10-20 00:35:26 +02:00
|
|
|
while (nm->fileName) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// allow environment variable to override default config path
|
2013-10-20 00:35:26 +02:00
|
|
|
if (nm->environmentOverride != NULL) {
|
|
|
|
char *envFile = getenv(nm->environmentOverride);
|
|
|
|
if (envFile != NULL) return readConfig_load(nm, envFile, config);
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
// the standard place to look is in the root directory
|
|
|
|
string path = rootDir + nm->fileName;
|
2013-10-20 00:35:26 +02:00
|
|
|
if (fileExists(path.c_str()))
|
|
|
|
return readConfig_load(nm, path.c_str(), config);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
++nm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Config_None;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
// Read a boost::serialization config file using an Xml reader..
|
2013-10-20 00:35:26 +02:00
|
|
|
bool readV6Config(const char *configFile, EncfsConfig &cfg, ConfigInfo *info) {
|
2012-04-26 04:18:26 +02:00
|
|
|
(void)info;
|
2008-04-13 22:35:57 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
XmlReader rdr;
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!rdr.load(configFile)) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Failed to load config file " << configFile;
|
2012-04-26 04:34:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
XmlValuePtr serialization = rdr["boost_serialization"];
|
|
|
|
XmlValuePtr config = (*serialization)["cfg"];
|
2012-05-14 05:13:23 +02:00
|
|
|
if (!config) {
|
|
|
|
config = (*serialization)["config"];
|
|
|
|
}
|
|
|
|
if (!config) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Unable to find XML configuration in file " << configFile;
|
2012-05-14 05:13:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-26 08:43:01 +02:00
|
|
|
int version;
|
|
|
|
if (!config->read("version", &version) &&
|
|
|
|
!config->read("@version", &version)) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Unable to find version in config file";
|
2012-08-26 08:43:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-04-26 04:34:15 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
// version numbering was complicated by boost::archive
|
|
|
|
if (version == 20 || version >= 20100713) {
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "found new serialization format";
|
2012-04-26 04:34:15 +02:00
|
|
|
cfg.set_revision(version);
|
2013-10-20 00:35:26 +02:00
|
|
|
} else if (version == 26800) {
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "found 20080816 version";
|
2012-04-26 04:34:15 +02:00
|
|
|
cfg.set_revision(20080816);
|
2013-10-20 00:35:26 +02:00
|
|
|
} else if (version == 26797) {
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "found 20080813";
|
2012-04-26 04:34:15 +02:00
|
|
|
cfg.set_revision(20080813);
|
2013-10-20 00:35:26 +02:00
|
|
|
} else if (version < V5Latest) {
|
|
|
|
LOG(ERROR) << "Invalid version " << version << " - please fix config file";
|
|
|
|
} else {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(INFO) << "Boost <= 1.41 compatibility mode";
|
2012-04-26 04:34:15 +02:00
|
|
|
cfg.set_revision(version);
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "subVersion = " << cfg.revision();
|
2012-04-26 04:34:15 +02:00
|
|
|
|
2012-08-26 08:43:01 +02:00
|
|
|
config->read("creator", cfg.mutable_creator());
|
|
|
|
config->read("cipherAlg", cfg.mutable_cipher());
|
|
|
|
config->read("nameAlg", cfg.mutable_naming());
|
2012-04-26 04:34:15 +02:00
|
|
|
|
|
|
|
//(*config)["keySize"] >> cfg.keySize;
|
|
|
|
int blockSize, blockMacBytes, blockMacRandBytes;
|
|
|
|
bool uniqueIv, chainedNameIv, externalIv, allowHoles;
|
|
|
|
|
2012-08-26 08:43:01 +02:00
|
|
|
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);
|
2012-04-26 04:34:15 +02:00
|
|
|
|
|
|
|
cfg.set_block_size(blockSize);
|
|
|
|
cfg.set_unique_iv(uniqueIv);
|
|
|
|
cfg.set_chained_iv(chainedNameIv);
|
|
|
|
cfg.set_external_iv(externalIv);
|
|
|
|
cfg.set_block_mac_bytes(blockMacBytes);
|
|
|
|
cfg.set_block_mac_rand_bytes(blockMacRandBytes);
|
|
|
|
cfg.set_allow_holes(allowHoles);
|
|
|
|
|
2012-08-20 07:05:16 +02:00
|
|
|
EncryptedKey *encryptedKey = cfg.mutable_key();
|
2012-04-26 04:34:15 +02:00
|
|
|
int encodedSize;
|
2012-08-26 08:43:01 +02:00
|
|
|
config->read("encodedKeySize", &encodedSize);
|
2012-04-26 04:34:15 +02:00
|
|
|
unsigned char *key = new unsigned char[encodedSize];
|
2012-08-26 08:43:01 +02:00
|
|
|
config->readB64("encodedKeyData", key, encodedSize);
|
2012-08-20 07:05:16 +02:00
|
|
|
encryptedKey->set_ciphertext(key, encodedSize);
|
2012-04-26 04:34:15 +02:00
|
|
|
delete[] key;
|
2013-10-20 00:35:26 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
int keySize;
|
2012-08-26 08:43:01 +02:00
|
|
|
config->read("keySize", &keySize);
|
2013-10-20 00:35:26 +02:00
|
|
|
encryptedKey->set_size(keySize / 8); // save as size in bytes
|
2012-04-26 04:34:15 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (cfg.revision() >= 20080816) {
|
2012-04-26 04:34:15 +02:00
|
|
|
int saltLen;
|
2012-08-26 08:43:01 +02:00
|
|
|
config->read("saltLen", &saltLen);
|
2012-04-26 04:34:15 +02:00
|
|
|
unsigned char *salt = new unsigned char[saltLen];
|
2012-08-26 08:43:01 +02:00
|
|
|
config->readB64("saltData", salt, saltLen);
|
2012-08-20 07:05:16 +02:00
|
|
|
encryptedKey->set_salt(salt, saltLen);
|
2012-04-26 04:34:15 +02:00
|
|
|
delete[] salt;
|
|
|
|
|
|
|
|
int kdfIterations, desiredKDFDuration;
|
2012-08-26 08:43:01 +02:00
|
|
|
config->read("kdfIterations", &kdfIterations);
|
|
|
|
config->read("desiredKDFDuration", &desiredKDFDuration);
|
2012-08-20 07:05:16 +02:00
|
|
|
encryptedKey->set_kdf_iterations(kdfIterations);
|
|
|
|
encryptedKey->set_kdf_duration(desiredKDFDuration);
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-08-20 07:05:16 +02:00
|
|
|
encryptedKey->clear_salt();
|
|
|
|
encryptedKey->set_kdf_iterations(16);
|
|
|
|
encryptedKey->clear_kdf_duration();
|
2012-04-26 04:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2008-04-13 22:35:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
// Read a v5 archive, which is a proprietary binary format.
|
2013-10-20 00:35:26 +02:00
|
|
|
bool readV5Config(const char *configFile, EncfsConfig &config, ConfigInfo *) {
|
2012-04-26 04:18:26 +02:00
|
|
|
bool ok = false;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// use Config to parse the file and query it..
|
|
|
|
ConfigReader cfgRdr;
|
2013-10-20 00:35:26 +02:00
|
|
|
if (cfgRdr.load(configFile)) {
|
|
|
|
try {
|
2012-04-26 04:34:15 +02:00
|
|
|
config.set_revision(cfgRdr["subVersion"].readInt(0));
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.revision() > V5Latest) {
|
2012-04-26 04:18:26 +02:00
|
|
|
/* config file specifies a version outside our supported
|
|
|
|
range.. */
|
2013-10-20 00:35:26 +02:00
|
|
|
LOG(ERROR)
|
|
|
|
<< "Config subversion " << config.revision()
|
|
|
|
<< " found, but this version of encfs only supports up to version "
|
|
|
|
<< V5Latest;
|
2012-04-26 04:18:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.revision() < V5Latest) {
|
|
|
|
LOG(ERROR)
|
|
|
|
<< "This version of EncFS doesn't support "
|
|
|
|
<< "filesystems created with EncFS releases before 2004-08-13";
|
2012-04-26 04:18:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
cfgRdr["creator"] >> (*config.mutable_creator());
|
|
|
|
cfgRdr["cipher"] >> (*config.mutable_cipher());
|
|
|
|
cfgRdr["naming"] >> (*config.mutable_naming());
|
|
|
|
|
|
|
|
int blockSize;
|
|
|
|
cfgRdr["blockSize"] >> blockSize;
|
|
|
|
config.set_block_size(blockSize);
|
|
|
|
|
2012-08-20 07:05:16 +02:00
|
|
|
EncryptedKey *encryptedKey = config.mutable_key();
|
2012-04-26 04:34:15 +02:00
|
|
|
int keySize;
|
|
|
|
cfgRdr["keySize"] >> keySize;
|
2012-08-20 07:05:16 +02:00
|
|
|
encryptedKey->set_size(keySize / 8);
|
|
|
|
cfgRdr["keyData"] >> (*encryptedKey->mutable_ciphertext());
|
2012-04-26 04:34:15 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
config.set_unique_iv(cfgRdr["uniqueIV"].readBool(false));
|
|
|
|
config.set_chained_iv(cfgRdr["chainedIV"].readBool(false));
|
|
|
|
config.set_external_iv(cfgRdr["externalIV"].readBool(false));
|
|
|
|
config.set_block_mac_bytes(cfgRdr["blockMACBytes"].readInt(0));
|
|
|
|
config.set_block_mac_rand_bytes(cfgRdr["blockMACRandBytes"].readInt(0));
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
ok = true;
|
2013-10-20 00:35:26 +02:00
|
|
|
}
|
|
|
|
catch (Error &err) {
|
|
|
|
LOG(WARNING) << "Error parsing data in config file " << configFile << "; "
|
|
|
|
<< err.what();
|
2012-04-26 04:18:26 +02:00
|
|
|
ok = false;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
return ok;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool readV4Config(const char *configFile, EncfsConfig &config, ConfigInfo *) {
|
2012-04-26 04:18:26 +02:00
|
|
|
bool ok = false;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// use Config to parse the file and query it..
|
|
|
|
ConfigReader cfgRdr;
|
2013-10-20 00:35:26 +02:00
|
|
|
if (cfgRdr.load(configFile)) {
|
|
|
|
try {
|
2012-04-26 04:34:15 +02:00
|
|
|
cfgRdr["cipher"] >> (*config.mutable_cipher());
|
|
|
|
int blockSize;
|
|
|
|
cfgRdr["blockSize"] >> blockSize;
|
|
|
|
config.set_block_size(blockSize);
|
|
|
|
|
2012-08-20 07:05:16 +02:00
|
|
|
EncryptedKey *key = config.mutable_key();
|
|
|
|
cfgRdr["keyData"] >> (*key->mutable_ciphertext());
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
// fill in default for V4
|
2013-10-20 00:35:26 +02:00
|
|
|
config.mutable_naming()->MergeFrom(
|
|
|
|
makeInterface("nameio/stream", 1, 0, 0));
|
|
|
|
config.set_creator("EncFS 1.0.x");
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
ok = true;
|
2013-10-20 00:35:26 +02:00
|
|
|
}
|
|
|
|
catch (Error &err) {
|
|
|
|
LOG(WARNING) << "Error parsing config file " << configFile << ": "
|
|
|
|
<< err.what();
|
2012-04-26 04:18:26 +02:00
|
|
|
ok = false;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
return ok;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool writeTextConfig(const char *fileName, const EncfsConfig &cfg) {
|
|
|
|
int fd = ::open(fileName, O_RDWR | O_CREAT, 0640);
|
|
|
|
if (fd < 0) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Unable to open or create file " << fileName;
|
2012-04-26 04:34:15 +02:00
|
|
|
return false;
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
google::protobuf::io::FileOutputStream fos(fd);
|
|
|
|
google::protobuf::TextFormat::Print(cfg, &fos);
|
2008-04-13 22:35:57 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
fos.Close();
|
2012-04-26 04:18:26 +02:00
|
|
|
return true;
|
2008-04-13 22:35:57 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool saveConfig(const string &rootDir, const EncfsConfig &config) {
|
2012-04-26 04:34:15 +02:00
|
|
|
bool ok = false;
|
2008-08-23 08:33:24 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
ConfigInfo *nm = ConfigFileMapping;
|
2013-10-20 00:35:26 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
// TODO(vgough): remove old config after saving a new one?
|
|
|
|
string path = rootDir + ConfigFileName;
|
2013-10-20 00:35:26 +02:00
|
|
|
if (nm->environmentOverride != NULL) {
|
2012-04-26 04:34:15 +02:00
|
|
|
// use environment file if specified..
|
2013-10-20 00:35:26 +02:00
|
|
|
const char *envFile = getenv(nm->environmentOverride);
|
|
|
|
if (envFile != NULL) path.assign(envFile);
|
2012-04-26 04:34:15 +02:00
|
|
|
}
|
2008-08-23 08:33:24 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
try {
|
|
|
|
const_cast<EncfsConfig &>(config).set_writer("EncFS " VERSION);
|
|
|
|
ok = writeTextConfig(path.c_str(), config);
|
|
|
|
}
|
|
|
|
catch (Error &err) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(WARNING) << "saveConfig failed: " << err.what();
|
2012-04-26 04:34:15 +02:00
|
|
|
ok = false;
|
|
|
|
}
|
2008-08-23 08:33:24 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
return ok;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool readProtoConfig(const char *fileName, EncfsConfig &config,
|
|
|
|
struct ConfigInfo *) {
|
|
|
|
int fd = ::open(fileName, O_RDONLY, 0640);
|
|
|
|
if (fd < 0) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Unable to open file " << fileName;
|
2012-04-26 04:34:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
google::protobuf::io::FileInputStream fis(fd);
|
|
|
|
google::protobuf::TextFormat::Parse(&fis, &config);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
return true;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static CipherV1::CipherAlgorithm findCipherAlgorithm(const char *name,
|
|
|
|
int keySize) {
|
|
|
|
for (auto &it : CipherV1::GetAlgorithmList()) {
|
|
|
|
if (!strcmp(name, it.name.c_str()) && it.keyLength.allowed(keySize)) {
|
2013-03-05 07:36:32 +01:00
|
|
|
return it;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-03-05 07:36:32 +01:00
|
|
|
CipherV1::CipherAlgorithm result;
|
2012-04-26 04:18:26 +02:00
|
|
|
return result;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static CipherV1::CipherAlgorithm selectCipherAlgorithm() {
|
|
|
|
for (;;) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// figure out what cipher they want to use..
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("The following cipher algorithms are available:") << "\n";
|
2013-03-05 07:36:32 +01:00
|
|
|
int optNum = 0;
|
|
|
|
auto algorithms = CipherV1::GetAlgorithmList();
|
2013-10-20 00:35:26 +02:00
|
|
|
for (auto &it : algorithms) {
|
|
|
|
cout << ++optNum << ". " << it.name << " : "
|
|
|
|
<< gettext(it.description.c_str()) << "\n";
|
|
|
|
if (it.keyLength.min() == it.keyLength.max()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// shown after algorithm name and description.
|
|
|
|
// xgroup(setup)
|
2013-10-20 00:35:26 +02:00
|
|
|
cout << autosprintf(_(" -- key length %i bits"), it.keyLength.min())
|
|
|
|
<< "\n";
|
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << autosprintf(
|
2013-10-20 00:35:26 +02:00
|
|
|
// shown after algorithm name and description.
|
|
|
|
// xgroup(setup)
|
|
|
|
_(" -- Supports key lengths of %i to %i bits"),
|
|
|
|
it.keyLength.min(), it.keyLength.max()) << "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (it.blockSize.min() == it.blockSize.max()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << autosprintf(
|
2013-10-20 00:35:26 +02:00
|
|
|
// shown after algorithm name and description.
|
|
|
|
// xgroup(setup)
|
|
|
|
_(" -- block size %i bytes"), it.blockSize.min()) << "\n";
|
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << autosprintf(
|
2013-10-20 00:35:26 +02:00
|
|
|
// shown after algorithm name and description.
|
|
|
|
// xgroup(setup)
|
|
|
|
_(" -- Supports block sizes of %i to %i bytes"),
|
|
|
|
it.blockSize.min(), it.blockSize.max()) << "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << "\n" << _("Enter the number corresponding to your choice: ");
|
|
|
|
char answer[10];
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
|
|
|
int cipherNum = (res == 0 ? 0 : atoi(answer));
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << "\n";
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (cipherNum < 1 || cipherNum > (int)algorithms.size()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
cerr << _("Invalid selection.") << "\n";
|
|
|
|
continue;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-03-05 07:36:32 +01:00
|
|
|
CipherV1::CipherAlgorithm alg;
|
2013-10-20 00:35:26 +02:00
|
|
|
for (auto &it : algorithms) {
|
|
|
|
if (!--cipherNum) {
|
2013-03-05 07:36:32 +01:00
|
|
|
alg = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
// xgroup(setup)
|
2013-10-20 00:35:26 +02:00
|
|
|
cout << autosprintf(_("Selected algorithm \"%s\""), alg.name.c_str())
|
|
|
|
<< "\n\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
return alg;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static Interface selectNameCoding(const CipherV1::CipherAlgorithm &alg) {
|
|
|
|
for (;;) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// figure out what cipher they want to use..
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("The following filename encoding algorithms are available:")
|
2013-10-20 00:35:26 +02:00
|
|
|
<< "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
NameIO::AlgorithmList algorithms = NameIO::GetAlgorithmList();
|
|
|
|
NameIO::AlgorithmList::const_iterator it;
|
|
|
|
int optNum = 1;
|
2013-01-29 04:07:54 +01:00
|
|
|
map<int, NameIO::AlgorithmList::const_iterator> algMap;
|
2013-10-20 00:35:26 +02:00
|
|
|
for (it = algorithms.begin(); it != algorithms.end(); ++it) {
|
|
|
|
cout << optNum << ". " << it->name << " : "
|
|
|
|
<< gettext(it->description.c_str()) << "\n";
|
2013-01-29 04:07:54 +01:00
|
|
|
algMap[optNum++] = it;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// xgroup(setup)
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << "\n" << _("Enter the number corresponding to your choice: ");
|
2008-01-07 09:09:04 +01:00
|
|
|
char answer[10];
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
|
|
|
int algNum = (res == 0 ? 0 : atoi(answer));
|
2008-01-07 09:09:04 +01:00
|
|
|
cout << "\n";
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (algNum < 1 || algNum >= optNum) {
|
2012-04-26 04:18:26 +02:00
|
|
|
cerr << _("Invalid selection.") << "\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
it = algMap[algNum];
|
2008-01-07 09:09:04 +01:00
|
|
|
|
|
|
|
// xgroup(setup)
|
2013-10-20 00:35:26 +02:00
|
|
|
cout << autosprintf(_("Selected algorithm \"%s\""), it->name.c_str())
|
|
|
|
<< "\"\n\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
return it->iface;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-06-18 07:54:58 +02:00
|
|
|
static int selectKDFDuration() {
|
2013-10-20 00:35:26 +02:00
|
|
|
cout << autosprintf(
|
|
|
|
_("Select desired KDF duration in milliseconds.\n"
|
|
|
|
"The default is 500 (half a second): "));
|
2013-06-18 07:54:58 +02:00
|
|
|
|
|
|
|
char answer[10];
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
|
|
|
int duration = (res == 0 ? 0 : atoi(answer));
|
2013-06-18 07:54:58 +02:00
|
|
|
cout << "\n";
|
|
|
|
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static int selectKeySize(const CipherV1::CipherAlgorithm &alg) {
|
|
|
|
if (alg.keyLength.min() == alg.keyLength.max()) {
|
|
|
|
cout << autosprintf(_("Using key size of %i bits"), alg.keyLength.min())
|
|
|
|
<< "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
return alg.keyLength.min();
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
cout
|
|
|
|
<< autosprintf(
|
|
|
|
// xgroup(setup)
|
|
|
|
_("Please select a key size in bits. The cipher you have chosen\n"
|
|
|
|
"supports sizes from %i to %i bits in increments of %i bits.\n"
|
|
|
|
"For example: "),
|
|
|
|
alg.keyLength.min(), alg.keyLength.max(), alg.keyLength.inc())
|
|
|
|
<< "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
int numAvail =
|
|
|
|
(alg.keyLength.max() - alg.keyLength.min()) / alg.keyLength.inc();
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (numAvail < 5) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// show them all
|
2013-10-20 00:35:26 +02:00
|
|
|
for (int i = 0; i <= numAvail; ++i) {
|
|
|
|
if (i) cout << ", ";
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << alg.keyLength.min() + i * alg.keyLength.inc();
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// partial
|
2013-10-20 00:35:26 +02:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
if (i) cout << ", ";
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << alg.keyLength.min() + i * alg.keyLength.inc();
|
|
|
|
}
|
|
|
|
cout << " ... " << alg.keyLength.max() - alg.keyLength.inc();
|
|
|
|
cout << ", " << alg.keyLength.max();
|
|
|
|
}
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << "\n" << _("Selected key size: ");
|
|
|
|
|
|
|
|
char answer[10];
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
|
|
|
int keySize = (res == 0 ? 0 : atoi(answer));
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << "\n";
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
keySize = alg.keyLength.closest(keySize);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << autosprintf(_("Using key size of %i bits"), keySize) << "\n\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
return keySize;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static int selectBlockSize(const CipherV1::CipherAlgorithm &alg) {
|
|
|
|
if (alg.blockSize.min() == alg.blockSize.max()) {
|
2008-01-07 09:09:04 +01:00
|
|
|
cout << autosprintf(
|
2013-10-20 00:35:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
_("Using filesystem block size of %i bytes"),
|
|
|
|
alg.blockSize.min()) << "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
return alg.blockSize.min();
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << autosprintf(
|
2013-10-20 00:35:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
_("Select a block size in bytes. The cipher you have chosen\n"
|
|
|
|
"supports sizes from %i to %i bytes in increments of %i.\n"
|
|
|
|
"Or just hit enter for the default (%i bytes)\n"),
|
|
|
|
alg.blockSize.min(), alg.blockSize.max(), alg.blockSize.inc(),
|
|
|
|
DefaultBlockSize);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << "\n" << _("filesystem block size: ");
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
int blockSize = DefaultBlockSize;
|
|
|
|
char answer[10];
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << "\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (res != 0 && atoi(answer) >= alg.blockSize.min()) blockSize = atoi(answer);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
blockSize = alg.blockSize.closest(blockSize);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
2013-10-20 00:35:26 +02:00
|
|
|
cout << autosprintf(_("Using filesystem block size of %i bytes"), blockSize)
|
|
|
|
<< "\n\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
return blockSize;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static bool boolDefaultNo(const char *prompt) {
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << prompt << "\n";
|
|
|
|
cout << _("The default here is No.\n"
|
2013-10-20 00:35:26 +02:00
|
|
|
"Any response that does not begin with 'y' will mean No: ");
|
2008-04-11 10:37:19 +02:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
char answer[10];
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << "\n";
|
2008-04-11 10:37:19 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (res != 0 && tolower(answer[0]) == 'y')
|
2012-04-26 04:18:26 +02:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2008-04-11 10:37:19 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static void selectBlockMAC(int *macBytes, int *macRandBytes) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
bool addMAC = boolDefaultNo(
|
|
|
|
_("Enable block authentication code headers\n"
|
|
|
|
"on every block in a file? This adds about 12 bytes per block\n"
|
|
|
|
"to the storage requirements for a file, and significantly affects\n"
|
|
|
|
"performance but it also means [almost] any modifications or errors\n"
|
|
|
|
"within a block will be caught and will cause a read error."));
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (addMAC)
|
2012-04-26 04:18:26 +02:00
|
|
|
*macBytes = 8;
|
|
|
|
else
|
|
|
|
*macBytes = 0;
|
|
|
|
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Add random bytes to each block header?\n"
|
2013-10-20 00:35:26 +02:00
|
|
|
"This adds a performance penalty, but ensures that blocks\n"
|
|
|
|
"have different authentication codes. Note that you can\n"
|
|
|
|
"have the same benefits by enabling per-file initialization\n"
|
|
|
|
"vectors, which does not come with as great of performance\n"
|
|
|
|
"penalty. \n"
|
|
|
|
"Select a number of bytes, from 0 (no random bytes) to 8: ");
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
char answer[10];
|
|
|
|
int randSize = 0;
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << "\n";
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
randSize = (res == 0 ? 0 : atoi(answer));
|
|
|
|
if (randSize < 0) randSize = 0;
|
|
|
|
if (randSize > 8) randSize = 8;
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
*macRandBytes = randSize;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static bool boolDefaultYes(const char *prompt) {
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << prompt << "\n";
|
|
|
|
cout << _("The default here is Yes.\n"
|
2013-10-20 00:35:26 +02:00
|
|
|
"Any response that does not begin with 'n' will mean Yes: ");
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
char answer[10];
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << "\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (res != 0 && tolower(answer[0]) == 'n')
|
2012-04-26 04:18:26 +02:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
2008-04-11 10:37:19 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static bool selectUniqueIV() {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
return boolDefaultYes(
|
|
|
|
_("Enable per-file initialization vectors?\n"
|
|
|
|
"This adds about 8 bytes per file to the storage requirements.\n"
|
|
|
|
"It should not affect performance except possibly with applications\n"
|
|
|
|
"which rely on block-aligned file io for performance."));
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static bool selectChainedIV() {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
return boolDefaultYes(
|
|
|
|
_("Enable filename initialization vector chaining?\n"
|
|
|
|
"This makes filename encoding dependent on the complete path, \n"
|
2013-06-18 08:03:16 +02:00
|
|
|
"rather than encoding each path element individually."));
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static bool selectExternalChainedIV() {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
return boolDefaultNo(
|
|
|
|
_("Enable filename to IV header chaining?\n"
|
|
|
|
"This makes file data encoding dependent on the complete file path.\n"
|
|
|
|
"If a file is renamed, it will not decode sucessfully unless it\n"
|
|
|
|
"was renamed by encfs with the proper key.\n"
|
|
|
|
"If this option is enabled, then hard links will not be supported\n"
|
|
|
|
"in the filesystem."));
|
2008-04-11 10:37:19 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
static bool selectZeroBlockPassThrough() {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
return boolDefaultYes(
|
|
|
|
_("Enable file-hole pass-through?\n"
|
|
|
|
"This avoids writing encrypted blocks when file holes are created."));
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
RootPtr createConfig(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts) {
|
2012-04-26 04:18:26 +02:00
|
|
|
const std::string rootDir = opts->rootDir;
|
|
|
|
bool enableIdleTracking = opts->idleTracking;
|
|
|
|
bool forceDecode = opts->forceDecode;
|
|
|
|
const std::string passwordProgram = opts->passwordProgram;
|
|
|
|
bool useStdin = opts->useStdin;
|
|
|
|
bool reverseEncryption = opts->reverseEncryption;
|
|
|
|
ConfigMode configMode = opts->configMode;
|
|
|
|
bool annotate = opts->annotate;
|
|
|
|
|
|
|
|
RootPtr rootInfo;
|
|
|
|
|
|
|
|
// creating new volume key.. should check that is what the user is
|
|
|
|
// expecting...
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Creating new encrypted volume.") << endl;
|
|
|
|
|
|
|
|
char answer[10] = {0};
|
2013-10-20 00:35:26 +02:00
|
|
|
if (configMode == Config_Prompt) {
|
2008-01-07 09:09:04 +01:00
|
|
|
// xgroup(setup)
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << _("Please choose from one of the following options:\n"
|
2013-10-20 00:35:26 +02:00
|
|
|
" enter \"x\" for expert configuration mode,\n"
|
|
|
|
" enter \"p\" for pre-configured paranoia mode,\n"
|
|
|
|
" anything else, or an empty line will select standard mode.\n"
|
|
|
|
"?> ");
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (annotate) cerr << "$PROMPT$ config_option" << endl;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets(answer, sizeof(answer), stdin);
|
2012-04-26 04:18:26 +02:00
|
|
|
(void)res;
|
|
|
|
cout << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
int keySize = 0;
|
|
|
|
int blockSize = 0;
|
2013-03-05 07:36:32 +01:00
|
|
|
CipherV1::CipherAlgorithm alg;
|
2012-04-26 04:18:26 +02:00
|
|
|
Interface nameIOIface;
|
|
|
|
int blockMACBytes = 0;
|
|
|
|
int blockMACRandBytes = 0;
|
|
|
|
bool uniqueIV = false;
|
|
|
|
bool chainedIV = false;
|
|
|
|
bool externalIV = false;
|
|
|
|
bool allowHoles = true;
|
|
|
|
long desiredKDFDuration = NormalKDFDuration;
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (reverseEncryption) {
|
2012-04-26 04:18:26 +02:00
|
|
|
uniqueIV = false;
|
|
|
|
chainedIV = false;
|
|
|
|
externalIV = false;
|
|
|
|
blockMACBytes = 0;
|
|
|
|
blockMACRandBytes = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (configMode == Config_Paranoia || answer[0] == 'p') {
|
|
|
|
if (reverseEncryption) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Paranoia configuration not supported for --reverse";
|
2012-04-26 04:18:26 +02:00
|
|
|
return rootInfo;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Paranoia configuration selected.") << "\n";
|
|
|
|
// look for AES with 256 bit key..
|
|
|
|
// Use block filename encryption mode.
|
|
|
|
// Enable per-block HMAC headers at substantial performance penalty..
|
|
|
|
// Enable per-file initialization vector headers.
|
|
|
|
// Enable filename initialization vector chaning
|
|
|
|
keySize = 256;
|
|
|
|
blockSize = DefaultBlockSize;
|
2013-03-05 07:36:32 +01:00
|
|
|
alg = findCipherAlgorithm("AES", keySize);
|
2012-04-26 04:18:26 +02:00
|
|
|
nameIOIface = BlockNameIO::CurrentInterface();
|
|
|
|
blockMACBytes = 8;
|
2013-10-20 00:35:26 +02:00
|
|
|
blockMACRandBytes = 0; // using uniqueIV, so this isn't necessary
|
2012-04-26 04:18:26 +02:00
|
|
|
uniqueIV = true;
|
|
|
|
chainedIV = true;
|
|
|
|
externalIV = true;
|
|
|
|
desiredKDFDuration = ParanoiaKDFDuration;
|
2013-10-20 00:35:26 +02:00
|
|
|
} else if (configMode == Config_Standard || answer[0] != 'x') {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Standard configuration selected.") << "\n";
|
|
|
|
// AES w/ 192 bit key, block name encoding, per-file initialization
|
|
|
|
// vectors are all standard.
|
|
|
|
keySize = 192;
|
|
|
|
blockSize = DefaultBlockSize;
|
|
|
|
alg = findCipherAlgorithm("AES", keySize);
|
|
|
|
blockMACBytes = 0;
|
|
|
|
externalIV = false;
|
|
|
|
nameIOIface = BlockNameIO::CurrentInterface();
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (reverseEncryption) {
|
|
|
|
cout << _("--reverse specified, not using unique/chained IV") << "\n";
|
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
uniqueIV = true;
|
|
|
|
chainedIV = true;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-08-16 18:39:31 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (answer[0] == 'x' || alg.name.empty()) {
|
|
|
|
if (answer[0] != 'x') {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Sorry, unable to locate cipher for predefined "
|
2013-10-20 00:35:26 +02:00
|
|
|
"configuration...\n"
|
|
|
|
"Falling through to Manual configuration mode.");
|
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Manual configuration mode selected.");
|
2010-12-07 10:14:17 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << endl;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// query user for settings..
|
|
|
|
alg = selectCipherAlgorithm();
|
2013-10-20 00:35:26 +02:00
|
|
|
keySize = selectKeySize(alg);
|
|
|
|
blockSize = selectBlockSize(alg);
|
|
|
|
nameIOIface = selectNameCoding(alg);
|
|
|
|
if (reverseEncryption) {
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << _("--reverse specified, not using unique/chained IV") << "\n";
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
chainedIV = selectChainedIV();
|
|
|
|
uniqueIV = selectUniqueIV();
|
2013-10-20 00:35:26 +02:00
|
|
|
if (chainedIV && uniqueIV)
|
2012-04-26 04:18:26 +02:00
|
|
|
externalIV = selectExternalChainedIV();
|
2013-10-20 00:35:26 +02:00
|
|
|
else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("External chained IV disabled, as both 'IV chaining'\n"
|
2013-10-20 00:35:26 +02:00
|
|
|
"and 'unique IV' features are required for this option.")
|
|
|
|
<< "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
externalIV = false;
|
|
|
|
}
|
|
|
|
selectBlockMAC(&blockMACBytes, &blockMACRandBytes);
|
|
|
|
allowHoles = selectZeroBlockPassThrough();
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2013-06-18 07:54:58 +02:00
|
|
|
desiredKDFDuration = selectKDFDuration();
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
shared_ptr<CipherV1> cipher = CipherV1::New(alg.iface, keySize);
|
|
|
|
if (!cipher) {
|
|
|
|
LOG(ERROR) << "Unable to instanciate cipher " << alg.name << ", key size "
|
|
|
|
<< keySize << ", block size " << blockSize;
|
2012-04-26 04:18:26 +02:00
|
|
|
return rootInfo;
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
|
|
|
VLOG(1) << "Using cipher " << alg.name << ", key size " << keySize
|
|
|
|
<< ", block size " << blockSize;
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
EncfsConfig config;
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
config.mutable_cipher()->MergeFrom(cipher->interface());
|
|
|
|
config.set_block_size(blockSize);
|
|
|
|
config.mutable_naming()->MergeFrom(nameIOIface);
|
|
|
|
config.set_creator("EncFS " VERSION);
|
|
|
|
config.set_revision(ProtoSubVersion);
|
|
|
|
config.set_block_mac_bytes(blockMACBytes);
|
|
|
|
config.set_block_mac_rand_bytes(blockMACRandBytes);
|
|
|
|
config.set_unique_iv(uniqueIV);
|
|
|
|
config.set_chained_iv(chainedIV);
|
|
|
|
config.set_external_iv(externalIV);
|
|
|
|
config.set_allow_holes(allowHoles);
|
2012-04-26 04:34:15 +02:00
|
|
|
|
2012-08-20 07:05:16 +02:00
|
|
|
EncryptedKey *key = config.mutable_key();
|
|
|
|
key->clear_salt();
|
2013-10-20 00:35:26 +02:00
|
|
|
key->clear_kdf_iterations(); // filled in by keying function
|
|
|
|
key->set_kdf_duration(desiredKDFDuration);
|
2012-08-22 06:56:28 +02:00
|
|
|
key->set_size(keySize / 8);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
cout << "\n";
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Configuration finished. The filesystem to be created has\n"
|
2013-10-20 00:35:26 +02:00
|
|
|
"the following properties:") << endl;
|
|
|
|
showFSInfo(config);
|
|
|
|
|
|
|
|
if (config.external_iv()) {
|
|
|
|
cout << _("-------------------------- WARNING --------------------------\n")
|
|
|
|
<< _("The external initialization-vector chaining option has been\n"
|
|
|
|
"enabled. This option disables the use of hard links on the\n"
|
|
|
|
"filesystem. Without hard links, some programs may not work.\n"
|
|
|
|
"The programs 'mutt' and 'procmail' are known to fail. For\n"
|
|
|
|
"more information, please see the encfs mailing list.\n"
|
|
|
|
"If you would like to choose another configuration setting,\n"
|
|
|
|
"please press CTRL-C now to abort and start over.") << endl;
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Now you will need to enter a password for your filesystem.\n"
|
2013-10-20 00:35:26 +02:00
|
|
|
"You will need to remember this password, as there is absolutely\n"
|
|
|
|
"no recovery mechanism. However, the password can be changed\n"
|
|
|
|
"later using encfsctl.\n\n");
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
int encodedKeySize = cipher->encodedKeySize();
|
2013-10-20 00:35:26 +02:00
|
|
|
unsigned char *encodedKey = new unsigned char[encodedKeySize];
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
CipherKey volumeKey = cipher->newRandomKey();
|
|
|
|
|
|
|
|
// get user key and use it to encode volume key
|
|
|
|
CipherKey userKey;
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "useStdin: " << useStdin;
|
2013-10-20 00:35:26 +02:00
|
|
|
if (useStdin) {
|
|
|
|
if (annotate) cerr << "$PROMPT$ new_passwd" << endl;
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
userKey = getNewUserKey(config, useStdin, passwordProgram, rootDir);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
cipher->setKey(userKey);
|
|
|
|
cipher->writeKey(volumeKey, encodedKey);
|
2012-04-26 04:18:26 +02:00
|
|
|
userKey.reset();
|
|
|
|
|
2012-08-20 07:05:16 +02:00
|
|
|
key->set_ciphertext(encodedKey, encodedKeySize);
|
2012-04-26 04:18:26 +02:00
|
|
|
delete[] encodedKey;
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!volumeKey.valid()) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Failure generating new volume key! "
|
2013-10-20 00:35:26 +02:00
|
|
|
<< "Please report this error.";
|
2012-04-26 04:18:26 +02:00
|
|
|
return rootInfo;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
cipher->setKey(volumeKey);
|
|
|
|
if (!saveConfig(rootDir, config)) return rootInfo;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// fill in config struct
|
2013-10-20 00:35:26 +02:00
|
|
|
shared_ptr<NameIO> nameCoder = NameIO::New(config.naming(), cipher);
|
|
|
|
if (!nameCoder) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(WARNING) << "Name coding interface not supported";
|
2013-10-20 00:35:26 +02:00
|
|
|
cout << _("The filename encoding interface requested is not available")
|
|
|
|
<< endl;
|
2008-01-07 09:09:04 +01:00
|
|
|
return rootInfo;
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
nameCoder->setChainedNameIV(config.chained_iv());
|
|
|
|
nameCoder->setReverseEncryption(reverseEncryption);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
FSConfigPtr fsConfig(new FSConfig);
|
2012-04-26 04:18:26 +02:00
|
|
|
fsConfig->cipher = cipher;
|
|
|
|
fsConfig->key = volumeKey;
|
|
|
|
fsConfig->nameCoding = nameCoder;
|
2012-08-22 06:46:36 +02:00
|
|
|
fsConfig->config = shared_ptr<EncfsConfig>(new EncfsConfig(config));
|
2012-04-26 04:18:26 +02:00
|
|
|
fsConfig->forceDecode = forceDecode;
|
|
|
|
fsConfig->reverseEncryption = reverseEncryption;
|
|
|
|
fsConfig->idleTracking = enableIdleTracking;
|
|
|
|
fsConfig->opts = opts;
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
rootInfo = RootPtr(new EncFS_Root);
|
2012-04-26 04:18:26 +02:00
|
|
|
rootInfo->cipher = cipher;
|
|
|
|
rootInfo->volumeKey = volumeKey;
|
2013-10-20 00:35:26 +02:00
|
|
|
rootInfo->root = shared_ptr<DirNode>(new DirNode(ctx, rootDir, fsConfig));
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
return rootInfo;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
void showFSInfo(const EncfsConfig &config) {
|
|
|
|
shared_ptr<CipherV1> cipher =
|
|
|
|
CipherV1::New(config.cipher(), config.key().size());
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
cout << autosprintf(
|
2013-10-20 00:35:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
_("Filesystem cipher: \"%s\", version %i:%i:%i"),
|
|
|
|
config.cipher().name().c_str(), config.cipher().major(),
|
|
|
|
config.cipher().minor(), config.cipher().age());
|
2012-04-26 04:18:26 +02:00
|
|
|
// check if we support this interface..
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!cipher)
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << _(" (NOT supported)\n");
|
2013-10-20 00:35:26 +02:00
|
|
|
else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// if we're using a newer interface, show the version number
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.cipher() != cipher->interface()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
Interface iface = cipher->interface();
|
|
|
|
// xgroup(diag)
|
2013-10-20 00:35:26 +02:00
|
|
|
cout << autosprintf(_(" (using %i:%i:%i)\n"), iface.major(),
|
|
|
|
iface.minor(), iface.age());
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
|
|
|
cout << "\n";
|
2008-08-17 09:26:52 +02:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << autosprintf(_("Filename encoding: \"%s\", version %i:%i:%i"),
|
2013-10-20 00:35:26 +02:00
|
|
|
config.naming().name().c_str(), config.naming().major(),
|
|
|
|
config.naming().minor(), config.naming().age());
|
|
|
|
|
|
|
|
if (!cipher) {
|
|
|
|
cout << "\n";
|
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// check if we support the filename encoding interface..
|
2013-10-20 00:35:26 +02:00
|
|
|
shared_ptr<NameIO> nameCoder = NameIO::New(config.naming(), cipher);
|
|
|
|
if (!nameCoder) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _(" (NOT supported)\n");
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// if we're using a newer interface, show the version number
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.naming() != nameCoder->interface()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
Interface iface = nameCoder->interface();
|
2013-10-20 00:35:26 +02:00
|
|
|
cout << autosprintf(_(" (using %i:%i:%i)\n"), iface.major(),
|
|
|
|
iface.minor(), iface.age());
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
|
|
|
cout << "\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2012-08-20 07:05:16 +02:00
|
|
|
const EncryptedKey &key = config.key();
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
2012-08-20 07:05:16 +02:00
|
|
|
cout << autosprintf(_("Key Size: %i bits"), 8 * key.size());
|
2012-04-26 04:34:15 +02:00
|
|
|
cipher = getCipher(config);
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!cipher) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _(" (NOT supported)\n");
|
|
|
|
} else
|
|
|
|
cout << "\n";
|
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
if (key.kdf_iterations() > 0 && key.salt().size() > 0) {
|
|
|
|
cout << autosprintf(_("Using PBKDF2, with %i iterations"),
|
|
|
|
key.kdf_iterations()) << "\n";
|
|
|
|
cout << autosprintf(_("Salt Size: %i bits"), 8 * (int)key.salt().size())
|
|
|
|
<< "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.block_mac_bytes() || config.block_mac_rand_bytes()) {
|
|
|
|
if (config.revision() < V5Latest) {
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << autosprintf(
|
2013-10-20 00:35:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
_("Block Size: %i bytes + %i byte MAC header"),
|
|
|
|
config.block_size(),
|
|
|
|
config.block_mac_bytes() + config.block_mac_rand_bytes())
|
|
|
|
<< endl;
|
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// new version stores the header as part of that block size..
|
|
|
|
cout << autosprintf(
|
2013-10-20 00:35:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
_("Block Size: %i bytes, including %i byte MAC header"),
|
|
|
|
config.block_size(),
|
|
|
|
config.block_mac_bytes() + config.block_mac_rand_bytes())
|
|
|
|
<< endl;
|
2008-04-11 10:37:19 +02:00
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
2012-04-26 04:34:15 +02:00
|
|
|
cout << autosprintf(_("Block Size: %i bytes"), config.block_size());
|
2008-01-07 09:09:04 +01:00
|
|
|
cout << "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.unique_iv()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("Each file contains 8 byte header with unique IV data.\n");
|
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.chained_iv()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("Filenames encoded using IV chaining mode.\n");
|
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.external_iv()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("File data IV is chained to filename IV.\n");
|
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
if (config.allow_holes()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("File holes passed through to ciphertext.\n");
|
|
|
|
}
|
|
|
|
cout << "\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
shared_ptr<CipherV1> getCipher(const EncfsConfig &config) {
|
2012-08-20 07:05:16 +02:00
|
|
|
return getCipher(config.cipher(), 8 * config.key().size());
|
2008-08-17 09:26:52 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
shared_ptr<CipherV1> getCipher(const Interface &iface, int keySize) {
|
|
|
|
return CipherV1::New(iface, keySize);
|
2008-08-23 08:33:24 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
CipherKey makeNewKey(EncfsConfig &config, const char *password, int passwdLen) {
|
2012-04-26 04:34:15 +02:00
|
|
|
CipherKey userKey;
|
2013-03-05 07:36:32 +01:00
|
|
|
shared_ptr<CipherV1> cipher = getCipher(config);
|
|
|
|
|
|
|
|
EncryptedKey *key = config.mutable_key();
|
2008-08-23 08:33:24 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
unsigned char salt[20];
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!cipher->pseudoRandomize(salt, sizeof(salt))) {
|
2012-04-26 04:34:15 +02:00
|
|
|
cout << _("Error creating salt\n");
|
|
|
|
return userKey;
|
|
|
|
}
|
2012-08-20 07:05:16 +02:00
|
|
|
key->set_salt(salt, sizeof(salt));
|
2008-08-23 08:33:24 +02:00
|
|
|
|
2012-08-20 07:05:16 +02:00
|
|
|
int iterations = key->kdf_iterations();
|
2013-10-20 00:35:26 +02:00
|
|
|
userKey = cipher->newKey(password, passwdLen, &iterations,
|
|
|
|
key->kdf_duration(), salt, sizeof(salt));
|
2012-08-20 07:05:16 +02:00
|
|
|
key->set_kdf_iterations(iterations);
|
2008-08-23 08:33:24 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
return userKey;
|
2008-08-23 08:33:24 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
CipherKey decryptKey(const EncfsConfig &config, const char *password,
|
|
|
|
int passwdLen) {
|
2012-08-20 07:05:16 +02:00
|
|
|
const EncryptedKey &key = config.key();
|
2012-04-26 04:18:26 +02:00
|
|
|
CipherKey userKey;
|
2013-03-05 07:36:32 +01:00
|
|
|
shared_ptr<CipherV1> cipher = getCipher(config.cipher(), 8 * key.size());
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!key.salt().empty()) {
|
2012-08-20 07:05:16 +02:00
|
|
|
int iterations = key.kdf_iterations();
|
2013-10-20 00:35:26 +02:00
|
|
|
userKey =
|
|
|
|
cipher->newKey(password, passwdLen, &iterations, key.kdf_duration(),
|
|
|
|
(const byte *)key.salt().data(), key.salt().size());
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (iterations != key.kdf_iterations()) {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Error in KDF, iteration mismatch";
|
2012-04-26 04:18:26 +02:00
|
|
|
return userKey;
|
2008-08-17 09:26:52 +02:00
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2012-04-26 04:34:15 +02:00
|
|
|
// old KDF, no salt..
|
2013-10-20 00:35:26 +02:00
|
|
|
userKey = cipher->newKey(password, passwdLen);
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-08-17 09:26:52 +02:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
return userKey;
|
2008-08-17 09:26:52 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
// Doesn't use SecureMem, since we don't know how much will be read.
|
|
|
|
// Besides, password is being produced by another program.
|
2013-10-20 00:35:26 +02:00
|
|
|
std::string readPassword(int FD) {
|
2012-04-26 04:34:15 +02:00
|
|
|
SecureMem *buf = new SecureMem(1024);
|
2012-04-26 04:18:26 +02:00
|
|
|
string result;
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
while (1) {
|
2013-03-06 09:02:23 +01:00
|
|
|
ssize_t rdSize = recv(FD, buf->data(), buf->size(), 0);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (rdSize > 0) {
|
|
|
|
result.append((char *)buf->data(), rdSize);
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// chop off trailing "\n" if present..
|
|
|
|
// This is done so that we can use standard programs like ssh-askpass
|
|
|
|
// without modification, as it returns trailing newline..
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!result.empty() && result[result.length() - 1] == '\n')
|
|
|
|
result.resize(result.length() - 1);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
delete buf;
|
2012-04-26 04:18:26 +02:00
|
|
|
return result;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
SecureMem *passwordFromProgram(const std::string &passProg,
|
2013-10-20 00:35:26 +02:00
|
|
|
const std::string &rootDir) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// have a child process run the command and get the result back to us.
|
|
|
|
int fds[2], pid;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = socketpair(PF_UNIX, SOCK_STREAM, 0, fds);
|
2013-10-20 00:35:26 +02:00
|
|
|
if (res == -1) {
|
2012-04-26 04:18:26 +02:00
|
|
|
perror(_("Internal error: socketpair() failed"));
|
2012-04-26 04:34:15 +02:00
|
|
|
return NULL;
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "getUserKey: fds = " << fds[0] << ", " << fds[1];
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
pid = fork();
|
2013-10-20 00:35:26 +02:00
|
|
|
if (pid == -1) {
|
2012-04-26 04:18:26 +02:00
|
|
|
perror(_("Internal error: fork() failed"));
|
|
|
|
close(fds[0]);
|
|
|
|
close(fds[1]);
|
2012-04-26 04:34:15 +02:00
|
|
|
return NULL;
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (pid == 0) {
|
2012-04-26 04:18:26 +02:00
|
|
|
const char *argv[4];
|
|
|
|
argv[0] = "/bin/sh";
|
|
|
|
argv[1] = "-c";
|
|
|
|
argv[2] = passProg.c_str();
|
|
|
|
argv[3] = 0;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// child process.. run the command and send output to fds[0]
|
2013-10-20 00:35:26 +02:00
|
|
|
close(fds[1]); // we don't use the other half..
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// make a copy of stdout and stderr descriptors, and set an environment
|
|
|
|
// variable telling where to find them, in case a child wants it..
|
2013-10-20 00:35:26 +02:00
|
|
|
int stdOutCopy = dup(STDOUT_FILENO);
|
|
|
|
int stdErrCopy = dup(STDERR_FILENO);
|
2012-04-26 04:18:26 +02:00
|
|
|
// replace STDOUT with our socket, which we'll used to receive the
|
|
|
|
// password..
|
2013-10-20 00:35:26 +02:00
|
|
|
dup2(fds[0], STDOUT_FILENO);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// ensure that STDOUT_FILENO and stdout/stderr are not closed on exec..
|
2013-10-20 00:35:26 +02:00
|
|
|
fcntl(STDOUT_FILENO, F_SETFD, 0); // don't close on exec..
|
2012-04-26 04:18:26 +02:00
|
|
|
fcntl(stdOutCopy, F_SETFD, 0);
|
|
|
|
fcntl(stdErrCopy, F_SETFD, 0);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
char tmpBuf[8];
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
setenv(ENCFS_ENV_ROOTDIR, rootDir.c_str(), 1);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
snprintf(tmpBuf, sizeof(tmpBuf) - 1, "%i", stdOutCopy);
|
2012-04-26 04:18:26 +02:00
|
|
|
setenv(ENCFS_ENV_STDOUT, tmpBuf, 1);
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
snprintf(tmpBuf, sizeof(tmpBuf) - 1, "%i", stdErrCopy);
|
2012-04-26 04:18:26 +02:00
|
|
|
setenv(ENCFS_ENV_STDERR, tmpBuf, 1);
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
execvp(argv[0], (char * const *)argv); // returns only on error..
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
perror(_("Internal error: failed to exec program"));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fds[0]);
|
|
|
|
string password = readPassword(fds[1]);
|
|
|
|
close(fds[1]);
|
|
|
|
|
|
|
|
waitpid(pid, NULL, 0);
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
SecureMem *result = new SecureMem(password.length() + 1);
|
|
|
|
if (result) strncpy((char *)result->data(), password.c_str(), result->size());
|
2012-04-26 04:34:15 +02:00
|
|
|
password.assign(password.length(), '\0');
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
return result;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
SecureMem *passwordFromStdin() {
|
2012-04-26 04:34:15 +02:00
|
|
|
SecureMem *buf = new SecureMem(MaxPassBuf);
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = fgets((char *)buf->data(), buf->size(), stdin);
|
|
|
|
if (res) {
|
2012-04-26 04:34:15 +02:00
|
|
|
// Kill the trailing newline.
|
2013-03-06 09:02:23 +01:00
|
|
|
int last = strnlen((char *)buf->data(), buf->size());
|
2013-10-20 00:35:26 +02:00
|
|
|
if (last > 0 && buf->data()[last - 1] == '\n') buf->data()[last - 1] = '\0';
|
2012-04-26 04:34:15 +02:00
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
SecureMem *passwordFromPrompt() {
|
2012-04-26 04:34:15 +02:00
|
|
|
SecureMem *buf = new SecureMem(MaxPassBuf);
|
|
|
|
|
|
|
|
// xgroup(common)
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res = readpassphrase(_("EncFS Password: "), (char *)buf->data(),
|
|
|
|
buf->size() - 1, RPP_ECHO_OFF);
|
|
|
|
if (!res) {
|
2012-04-26 04:34:15 +02:00
|
|
|
delete buf;
|
|
|
|
buf = NULL;
|
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
SecureMem *passwordFromPrompts() {
|
2012-04-26 04:34:15 +02:00
|
|
|
SecureMem *buf = new SecureMem(MaxPassBuf);
|
|
|
|
SecureMem *buf2 = new SecureMem(MaxPassBuf);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
do {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(common)
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res1 = readpassphrase(_("New Encfs Password: "), (char *)buf->data(),
|
|
|
|
buf->size() - 1, RPP_ECHO_OFF);
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(common)
|
2013-10-20 00:35:26 +02:00
|
|
|
char *res2 =
|
|
|
|
readpassphrase(_("Verify Encfs Password: "), (char *)buf2->data(),
|
|
|
|
buf2->size() - 1, RPP_ECHO_OFF);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (res1 && res2 &&
|
|
|
|
!strncmp((char *)buf->data(), (char *)buf2->data(), MaxPassBuf)) {
|
|
|
|
break;
|
|
|
|
} else {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(common) -- probably not common, but group with the others
|
|
|
|
cerr << _("Passwords did not match, please try again\n");
|
|
|
|
}
|
2013-10-20 00:35:26 +02:00
|
|
|
} while (1);
|
2012-04-26 04:34:15 +02:00
|
|
|
|
|
|
|
delete buf2;
|
|
|
|
return buf;
|
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
CipherKey getUserKey(const EncfsConfig &config, bool useStdin) {
|
2012-04-26 04:34:15 +02:00
|
|
|
CipherKey userKey;
|
|
|
|
SecureMem *password;
|
|
|
|
|
|
|
|
if (useStdin)
|
|
|
|
password = passwordFromStdin();
|
|
|
|
else
|
|
|
|
password = passwordFromPrompt();
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (password) {
|
|
|
|
userKey = decryptKey(config, (char *)password->data(),
|
|
|
|
strlen((char *)password->data()));
|
2012-04-26 04:34:15 +02:00
|
|
|
delete password;
|
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
return userKey;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
CipherKey getUserKey(const EncfsConfig &config, const std::string &passProg,
|
|
|
|
const std::string &rootDir) {
|
2012-04-26 04:34:15 +02:00
|
|
|
CipherKey result;
|
|
|
|
SecureMem *password = passwordFromProgram(passProg, rootDir);
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (password) {
|
|
|
|
result = decryptKey(config, (char *)password->data(),
|
|
|
|
strlen((char *)password->data()));
|
2012-04-26 04:34:15 +02:00
|
|
|
delete password;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
CipherKey getNewUserKey(EncfsConfig &config, bool useStdin,
|
|
|
|
const std::string &passProg,
|
|
|
|
const std::string &rootDir) {
|
2012-04-26 04:34:15 +02:00
|
|
|
CipherKey result;
|
|
|
|
SecureMem *password;
|
|
|
|
|
|
|
|
if (useStdin)
|
|
|
|
password = passwordFromStdin();
|
|
|
|
else if (!passProg.empty())
|
|
|
|
password = passwordFromProgram(passProg, rootDir);
|
|
|
|
else
|
|
|
|
password = passwordFromPrompts();
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (password) {
|
|
|
|
result = makeNewKey(config, (char *)password->data(),
|
|
|
|
strlen((char *)password->data()));
|
2012-04-26 04:34:15 +02:00
|
|
|
delete password;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
RootPtr initFS(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts) {
|
2012-04-26 04:18:26 +02:00
|
|
|
RootPtr rootInfo;
|
2012-04-26 04:34:15 +02:00
|
|
|
EncfsConfig config;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (readConfig(opts->rootDir, config) != Config_None) {
|
|
|
|
if (opts->reverseEncryption) {
|
|
|
|
if (config.block_mac_bytes() != 0 || config.block_mac_rand_bytes() != 0 ||
|
|
|
|
config.unique_iv() || config.external_iv() || config.chained_iv()) {
|
|
|
|
cout
|
|
|
|
<< _("The configuration loaded is not compatible with --reverse\n");
|
2012-04-26 04:18:26 +02:00
|
|
|
return rootInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// first, instanciate the cipher.
|
2013-03-05 07:36:32 +01:00
|
|
|
shared_ptr<CipherV1> cipher = getCipher(config);
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!cipher) {
|
2013-01-29 04:07:54 +01:00
|
|
|
Interface iface = config.cipher();
|
2013-10-20 00:35:26 +02:00
|
|
|
LOG(ERROR) << "Unable to find cipher " << iface.name() << ", version "
|
|
|
|
<< iface.major() << ":" << iface.minor() << ":" << iface.age();
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("The requested cipher interface is not available\n");
|
|
|
|
return rootInfo;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (opts->delayMount) {
|
|
|
|
rootInfo = RootPtr(new EncFS_Root);
|
2013-10-03 07:10:23 +02:00
|
|
|
rootInfo->cipher = cipher;
|
|
|
|
rootInfo->root = shared_ptr<DirNode>();
|
|
|
|
return rootInfo;
|
|
|
|
}
|
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// get user key
|
|
|
|
CipherKey userKey;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (opts->passwordProgram.empty()) {
|
|
|
|
if (opts->annotate) cerr << "$PROMPT$ passwd" << endl;
|
|
|
|
userKey = getUserKey(config, opts->useStdin);
|
2008-01-07 09:09:04 +01:00
|
|
|
} else
|
2013-10-20 00:35:26 +02:00
|
|
|
userKey = getUserKey(config, opts->passwordProgram, opts->rootDir);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!userKey.valid()) return rootInfo;
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
cipher->setKey(userKey);
|
2013-03-05 07:36:32 +01:00
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "cipher encoded key size = " << cipher->encodedKeySize();
|
2012-04-26 04:18:26 +02:00
|
|
|
// decode volume key..
|
2013-10-20 00:35:26 +02:00
|
|
|
CipherKey volumeKey =
|
|
|
|
cipher->readKey((const unsigned char *)config.key().ciphertext().data(),
|
|
|
|
opts->checkKey);
|
2012-04-26 04:18:26 +02:00
|
|
|
userKey.reset();
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (!volumeKey.valid()) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("Error decoding volume key, password incorrect\n");
|
|
|
|
return rootInfo;
|
|
|
|
}
|
|
|
|
|
2013-03-05 07:36:32 +01:00
|
|
|
cipher->setKey(volumeKey);
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
shared_ptr<NameIO> nameCoder = NameIO::New(config.naming(), cipher);
|
|
|
|
if (!nameCoder) {
|
2013-01-29 04:07:54 +01:00
|
|
|
Interface iface = config.naming();
|
|
|
|
LOG(ERROR) << "Unable to find nameio interface " << iface.name()
|
2013-10-20 00:35:26 +02:00
|
|
|
<< ", version " << iface.major() << ":" << iface.minor() << ":"
|
|
|
|
<< iface.age();
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("The requested filename coding interface is "
|
2013-10-20 00:35:26 +02:00
|
|
|
"not available\n");
|
2012-04-26 04:18:26 +02:00
|
|
|
return rootInfo;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
nameCoder->setChainedNameIV(config.chained_iv());
|
|
|
|
nameCoder->setReverseEncryption(opts->reverseEncryption);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
FSConfigPtr fsConfig(new FSConfig);
|
2012-04-26 04:18:26 +02:00
|
|
|
fsConfig->cipher = cipher;
|
|
|
|
fsConfig->key = volumeKey;
|
|
|
|
fsConfig->nameCoding = nameCoder;
|
2012-08-22 06:46:36 +02:00
|
|
|
fsConfig->config = shared_ptr<EncfsConfig>(new EncfsConfig(config));
|
2012-04-26 04:18:26 +02:00
|
|
|
fsConfig->forceDecode = opts->forceDecode;
|
|
|
|
fsConfig->reverseEncryption = opts->reverseEncryption;
|
|
|
|
fsConfig->opts = opts;
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
rootInfo = RootPtr(new EncFS_Root);
|
2012-04-26 04:18:26 +02:00
|
|
|
rootInfo->cipher = cipher;
|
|
|
|
rootInfo->volumeKey = volumeKey;
|
2013-10-20 00:35:26 +02:00
|
|
|
rootInfo->root =
|
|
|
|
shared_ptr<DirNode>(new DirNode(ctx, opts->rootDir, fsConfig));
|
|
|
|
} else {
|
|
|
|
if (opts->createIfNotFound) {
|
2012-04-26 04:18:26 +02:00
|
|
|
// creating a new encrypted filesystem
|
2013-10-20 00:35:26 +02:00
|
|
|
rootInfo = createConfig(ctx, opts);
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rootInfo;
|
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
int remountFS(EncFS_Context *ctx) {
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "Attempting to reinitialize filesystem";
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
RootPtr rootInfo = initFS(ctx, ctx->opts);
|
|
|
|
if (rootInfo) {
|
2012-04-26 04:18:26 +02:00
|
|
|
ctx->setRoot(rootInfo->root);
|
|
|
|
return 0;
|
2013-10-20 00:35:26 +02:00
|
|
|
} else {
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(WARNING) << "Remount failed";
|
2012-04-26 04:18:26 +02:00
|
|
|
return -EACCES;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-03-05 07:29:58 +01:00
|
|
|
} // namespace encfs
|