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
|
|
|
|
* 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
|
|
|
|
#define _XOPEN_SOURCE 500 // make sure pwrite() is pulled in
|
|
|
|
#endif
|
|
|
|
#define _BSD_SOURCE // pick up setenv on RH7.3
|
|
|
|
|
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
|
|
|
|
2008-01-07 09:09:04 +01:00
|
|
|
using namespace std;
|
|
|
|
using namespace gnu;
|
|
|
|
|
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
|
|
|
|
2008-08-17 09:26:52 +02:00
|
|
|
static const int NormalKDFDuration = 500; // 1/2 a second
|
|
|
|
static const int ParanoiaKDFDuration = 3000; // 3 seconds
|
|
|
|
|
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";
|
|
|
|
|
2012-08-22 06:46:36 +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";
|
|
|
|
|
2008-01-07 09:09:04 +01: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;
|
|
|
|
bool (*loadFunc)(const char *fileName,
|
2012-04-26 04:34:15 +02:00
|
|
|
EncfsConfig &config, ConfigInfo *cfg);
|
2008-01-07 09:09:04 +01:00
|
|
|
} ConfigFileMapping[] = {
|
2012-04-26 04:34:15 +02:00
|
|
|
{Config_V7, ConfigFileName, "ENCFS_CONFIG", readProtoConfig },
|
|
|
|
{Config_V6, ".encfs6.xml", "ENCFS6_CONFIG", readV6Config },
|
2012-04-26 04:18:26 +02:00
|
|
|
// backward compatible support for older versions
|
2012-04-26 04:34:15 +02:00
|
|
|
{Config_V5, ".encfs5", "ENCFS5_CONFIG", readV5Config },
|
2012-08-22 06:46:36 +02:00
|
|
|
{Config_V4, ".encfs4", NULL, readV4Config },
|
2012-04-26 04:34:15 +02:00
|
|
|
// prehistoric - no longer support
|
|
|
|
{Config_V3, ".encfs3", NULL, NULL },
|
|
|
|
{Config_Prehistoric, ".encfs2", NULL, NULL },
|
|
|
|
{Config_Prehistoric, ".encfs", NULL, NULL },
|
|
|
|
{Config_None, NULL, NULL, NULL } };
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2008-01-07 09:09:04 +01:00
|
|
|
EncFS_Root::EncFS_Root()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EncFS_Root::~EncFS_Root()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool fileExists( const char * fileName )
|
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
struct stat buf;
|
|
|
|
if(!lstat( fileName, &buf ))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// XXX show perror?
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isDirectory( const char *fileName )
|
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
struct stat buf;
|
|
|
|
if( !lstat( fileName, &buf ))
|
|
|
|
{
|
|
|
|
return S_ISDIR( buf.st_mode );
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isAbsolutePath( const char *fileName )
|
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
if(fileName && fileName[0] != '\0' && fileName[0] == '/')
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *lastPathElement( const char *name )
|
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
const char *loc = strrchr( name, '/' );
|
|
|
|
return loc ? loc + 1 : name;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string parentDirectory( const std::string &path )
|
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
size_t last = path.find_last_of( '/' );
|
|
|
|
if(last == string::npos)
|
|
|
|
return string("");
|
|
|
|
else
|
|
|
|
return path.substr(0, last);
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2010-12-07 10:14:17 +01:00
|
|
|
bool userAllowMkdir(const char *path, mode_t mode )
|
|
|
|
{
|
|
|
|
return userAllowMkdir(0, path, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool userAllowMkdir(int promptno, const char *path, mode_t mode )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
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)
|
|
|
|
cerr << autosprintf( _("The directory \"%s\" does not exist. Should it be created? (y,n) "), path );
|
|
|
|
char answer[10];
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
switch (promptno)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
cerr << endl << "$PROMPT$ create_root_dir" << endl;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
cerr << endl << "$PROMPT$ create_mount_point" << endl;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = fgets( answer, sizeof(answer), stdin );
|
|
|
|
|
|
|
|
if(res != 0 && toupper(answer[0]) == 'Y')
|
|
|
|
{
|
|
|
|
int result = mkdir( path, mode );
|
|
|
|
if(result < 0)
|
2010-12-07 10:14:17 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
perror( _("Unable to create directory: ") );
|
|
|
|
return false;
|
2008-01-07 09:09:04 +01:00
|
|
|
} else
|
2012-04-26 04:18:26 +02:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// Directory not created, by user request
|
|
|
|
cerr << _("Directory not created.") << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigType readConfig_load( ConfigInfo *nm, const char *path,
|
2012-04-26 04:34:15 +02:00
|
|
|
EncfsConfig &config )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
if( nm->loadFunc )
|
|
|
|
{
|
|
|
|
try
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
if( (*nm->loadFunc)( path, config, nm ))
|
|
|
|
return nm->type;
|
2013-01-29 04:07:54 +01:00
|
|
|
} catch( Error &err )
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
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;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
ConfigType readConfig( const string &rootDir, EncfsConfig &config )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
ConfigInfo *nm = ConfigFileMapping;
|
|
|
|
while(nm->fileName)
|
|
|
|
{
|
|
|
|
// allow environment variable to override default config path
|
|
|
|
if( nm->environmentOverride != NULL )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
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;
|
|
|
|
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..
|
2010-08-30 08:32:05 +02:00
|
|
|
bool readV6Config( const char *configFile,
|
2012-04-26 04:34:15 +02:00
|
|
|
EncfsConfig &cfg, ConfigInfo *info)
|
2008-04-13 22:35:57 +02:00
|
|
|
{
|
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;
|
|
|
|
if (!rdr.load(configFile))
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
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
|
|
|
|
|
|
|
// 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);
|
|
|
|
} 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);
|
|
|
|
} 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);
|
2012-08-22 06:46:36 +02:00
|
|
|
} else if (version < V5Latest)
|
2012-04-26 04:34:15 +02:00
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Invalid version " << version
|
|
|
|
<< " - please fix config file";
|
2012-04-26 04:18:26 +02:00
|
|
|
} 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;
|
|
|
|
|
|
|
|
int keySize;
|
2012-08-26 08:43:01 +02:00
|
|
|
config->read("keySize", &keySize);
|
2012-08-20 07:05:16 +02:00
|
|
|
encryptedKey->set_size(keySize / 8); // save as size in bytes
|
2012-04-26 04:34:15 +02:00
|
|
|
|
|
|
|
if(cfg.revision() >= 20080816)
|
|
|
|
{
|
|
|
|
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);
|
2012-04-26 04:34:15 +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.
|
2010-08-30 08:32:05 +02:00
|
|
|
bool readV5Config( const char *configFile,
|
2012-04-26 04:34:15 +02:00
|
|
|
EncfsConfig &config, ConfigInfo *)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
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;
|
|
|
|
if(cfgRdr.load( configFile ))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-04-26 04:34:15 +02:00
|
|
|
config.set_revision(cfgRdr["subVersion"].readInt(0));
|
2012-08-22 06:46:36 +02:00
|
|
|
if(config.revision() > V5Latest)
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
/* config file specifies a version outside our supported
|
|
|
|
range.. */
|
2013-01-29 04:07:54 +01: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;
|
|
|
|
}
|
2012-08-22 06:46:36 +02:00
|
|
|
if( config.revision() < V5Latest )
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
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
|
|
|
|
|
|
|
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-01-29 04:07:54 +01:00
|
|
|
} catch( Error &err)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-08-30 08:32:05 +02:00
|
|
|
bool readV4Config( const char *configFile,
|
2012-04-26 04:34:15 +02:00
|
|
|
EncfsConfig &config, ConfigInfo *)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
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;
|
|
|
|
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
|
2012-04-26 04:34:15 +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-01-29 04:07:54 +01:00
|
|
|
} catch( Error &err)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
bool writeTextConfig( const char *fileName, const EncfsConfig &cfg )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:34:15 +02:00
|
|
|
int fd = ::open( fileName, O_RDWR | O_CREAT, 0640 );
|
|
|
|
if (fd < 0)
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
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
|
|
|
|
2012-04-26 04:34:15 +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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
bool saveConfig( const string &rootDir, const EncfsConfig &config )
|
2008-08-23 08:33:24 +02:00
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
// TODO(vgough): remove old config after saving a new one?
|
|
|
|
string path = rootDir + ConfigFileName;
|
|
|
|
if( nm->environmentOverride != NULL )
|
|
|
|
{
|
|
|
|
// use environment file if specified..
|
|
|
|
const char *envFile = getenv( nm->environmentOverride );
|
|
|
|
if( envFile != NULL )
|
|
|
|
path.assign( envFile );
|
|
|
|
}
|
2008-08-23 08:33:24 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
try
|
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
const_cast<EncfsConfig &>(config).set_writer("EncFS " VERSION );
|
2012-04-26 04:34:15 +02:00
|
|
|
ok = writeTextConfig( path.c_str(), config );
|
2013-01-29 04:07:54 +01:00
|
|
|
} catch( Error &err )
|
2012-04-26 04:34:15 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
bool readProtoConfig( const char *fileName, EncfsConfig &config,
|
|
|
|
struct ConfigInfo *)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:34:15 +02:00
|
|
|
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
|
|
|
|
2012-04-26 04:34:15 +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
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2013-03-05 07:36:32 +01:00
|
|
|
CipherV1::CipherAlgorithm findCipherAlgorithm(const char *name,
|
2012-04-26 04:18:26 +02:00
|
|
|
int keySize )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2013-03-05 07:36:32 +01:00
|
|
|
for (auto &it : CipherV1::GetAlgorithmList())
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
2013-03-05 07:36:32 +01:00
|
|
|
if( !strcmp( name, it.name.c_str() )
|
|
|
|
&& it.keyLength.allowed( keySize ))
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2013-03-05 07:36:32 +01:00
|
|
|
CipherV1::CipherAlgorithm selectCipherAlgorithm()
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
// 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();
|
|
|
|
for (auto &it : algorithms)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2013-03-05 07:36:32 +01:00
|
|
|
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)
|
|
|
|
cout << autosprintf(_(" -- key length %i bits")
|
2013-03-05 07:36:32 +01:00
|
|
|
, it.keyLength.min()) << "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
cout << autosprintf(
|
|
|
|
// shown after algorithm name and description.
|
|
|
|
// xgroup(setup)
|
|
|
|
_(" -- Supports key lengths of %i to %i bits"),
|
2013-03-05 07:36:32 +01:00
|
|
|
it.keyLength.min(), it.keyLength.max()) << "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 07:36:32 +01:00
|
|
|
if(it.blockSize.min() == it.blockSize.max())
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
cout << autosprintf(
|
|
|
|
// shown after algorithm name and description.
|
|
|
|
// xgroup(setup)
|
2013-03-05 07:36:32 +01:00
|
|
|
_(" -- block size %i bytes"), it.blockSize.min())
|
2012-04-26 04:18:26 +02:00
|
|
|
<< "\n";
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
cout << autosprintf(
|
|
|
|
// shown after algorithm name and description.
|
|
|
|
// xgroup(setup)
|
|
|
|
_(" -- Supports block sizes of %i to %i bytes"),
|
2013-03-05 07:36:32 +01:00
|
|
|
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];
|
|
|
|
char *res = fgets( answer, sizeof(answer), stdin );
|
|
|
|
int cipherNum = (res == 0 ? 0 : atoi( answer ));
|
|
|
|
cout << "\n";
|
|
|
|
|
|
|
|
if( cipherNum < 1 || cipherNum > (int)algorithms.size() )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
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;
|
|
|
|
for (auto &it : algorithms)
|
|
|
|
{
|
|
|
|
if (!--cipherNum)
|
|
|
|
{
|
|
|
|
alg = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << autosprintf(_("Selected algorithm \"%s\""), alg.name.c_str())
|
|
|
|
<< "\n\n";
|
|
|
|
|
|
|
|
return alg;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2013-03-05 07:36:32 +01:00
|
|
|
Interface selectNameCoding(const CipherV1::CipherAlgorithm &alg)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
// figure out what cipher they want to use..
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("The following filename encoding algorithms are available:")
|
|
|
|
<< "\n";
|
|
|
|
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;
|
|
|
|
for(it = algorithms.begin(); it != algorithms.end(); ++it)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
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];
|
2010-06-15 08:21:38 +02:00
|
|
|
char *res = fgets( answer, sizeof(answer), stdin );
|
2012-04-26 04:18:26 +02:00
|
|
|
int algNum = (res == 0 ? 0 : atoi( answer ));
|
2008-01-07 09:09:04 +01:00
|
|
|
cout << "\n";
|
|
|
|
|
2013-01-29 04:07:54 +01: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)
|
2012-04-26 04:18: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
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2013-03-05 07:36:32 +01:00
|
|
|
int selectKeySize( const CipherV1::CipherAlgorithm &alg )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
if(alg.keyLength.min() == alg.keyLength.max())
|
|
|
|
{
|
|
|
|
cout << autosprintf(_("Using key size of %i bits"),
|
|
|
|
alg.keyLength.min()) << "\n";
|
|
|
|
return alg.keyLength.min();
|
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
int numAvail = (alg.keyLength.max() - alg.keyLength.min())
|
|
|
|
/ alg.keyLength.inc();
|
|
|
|
|
|
|
|
if(numAvail < 5)
|
|
|
|
{
|
|
|
|
// show them all
|
|
|
|
for(int i=0; i<=numAvail; ++i)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
if(i)
|
|
|
|
cout << ", ";
|
|
|
|
cout << alg.keyLength.min() + i * alg.keyLength.inc();
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
// partial
|
|
|
|
for(int i=0; i<3; ++i)
|
|
|
|
{
|
|
|
|
if(i)
|
|
|
|
cout << ", ";
|
|
|
|
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];
|
|
|
|
char *res = fgets( answer, sizeof(answer), stdin );
|
|
|
|
int keySize = (res == 0 ? 0 : atoi( answer ));
|
|
|
|
cout << "\n";
|
|
|
|
|
|
|
|
keySize = alg.keyLength.closest( keySize );
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2013-03-05 07:36:32 +01:00
|
|
|
int selectBlockSize( const CipherV1::CipherAlgorithm &alg )
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
if(alg.blockSize.min() == alg.blockSize.max())
|
|
|
|
{
|
2008-01-07 09:09:04 +01:00
|
|
|
cout << autosprintf(
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
_("Using filesystem block size of %i bytes"),
|
|
|
|
alg.blockSize.min()) << "\n";
|
|
|
|
return alg.blockSize.min();
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << autosprintf(
|
|
|
|
// 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];
|
|
|
|
char *res = fgets( answer, sizeof(answer), stdin );
|
|
|
|
cout << "\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if( res != 0 && atoi( answer ) >= alg.blockSize.min() )
|
|
|
|
blockSize = atoi( answer );
|
|
|
|
|
|
|
|
blockSize = alg.blockSize.closest( blockSize );
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << autosprintf(_("Using filesystem block size of %i bytes"),
|
|
|
|
blockSize) << "\n\n";
|
|
|
|
|
|
|
|
return blockSize;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2008-04-11 10:37:19 +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"
|
|
|
|
"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];
|
|
|
|
char *res = fgets( answer, sizeof(answer), stdin );
|
|
|
|
cout << "\n";
|
2008-04-11 10:37:19 +02:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if(res != 0 && tolower(answer[0]) == 'y')
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2008-04-11 10:37:19 +02:00
|
|
|
}
|
|
|
|
|
2008-01-07 09:09:04 +01: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."));
|
|
|
|
|
|
|
|
if(addMAC)
|
|
|
|
*macBytes = 8;
|
|
|
|
else
|
|
|
|
*macBytes = 0;
|
|
|
|
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Add random bytes to each block header?\n"
|
|
|
|
"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: ");
|
|
|
|
|
|
|
|
char answer[10];
|
|
|
|
int randSize = 0;
|
|
|
|
char *res = fgets( answer, sizeof(answer), stdin );
|
|
|
|
cout << "\n";
|
|
|
|
|
|
|
|
randSize = (res == 0 ? 0 : atoi( answer ));
|
|
|
|
if(randSize < 0)
|
|
|
|
randSize = 0;
|
|
|
|
if(randSize > 8)
|
|
|
|
randSize = 8;
|
|
|
|
|
|
|
|
*macRandBytes = randSize;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2008-04-11 10:37:19 +02:00
|
|
|
static
|
|
|
|
bool boolDefaultYes(const char *prompt)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << prompt << "\n";
|
|
|
|
cout << _("The default here is Yes.\n"
|
|
|
|
"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];
|
|
|
|
char *res = fgets( answer, sizeof(answer), stdin );
|
|
|
|
cout << "\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if(res != 0 && tolower(answer[0]) == 'n')
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
2008-04-11 10:37:19 +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
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
"rather then encoding each path element individually."));
|
2008-01-07 09:09:04 +01: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
|
|
|
|
2008-04-11 10:37:19 +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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
RootPtr createConfig( EncFS_Context *ctx,
|
2012-04-26 04:18:26 +02:00
|
|
|
const shared_ptr<EncFS_Opts> &opts )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
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};
|
|
|
|
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"
|
|
|
|
" 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
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if (annotate)
|
|
|
|
cerr << "$PROMPT$ config_option" << endl;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
char *res = fgets( answer, sizeof(answer), stdin );
|
|
|
|
(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;
|
|
|
|
|
|
|
|
if (reverseEncryption)
|
|
|
|
{
|
|
|
|
uniqueIV = false;
|
|
|
|
chainedIV = false;
|
|
|
|
externalIV = false;
|
|
|
|
blockMACBytes = 0;
|
|
|
|
blockMACRandBytes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(configMode == Config_Paranoia || answer[0] == 'p')
|
|
|
|
{
|
2008-01-07 09:09:04 +01:00
|
|
|
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;
|
|
|
|
blockMACRandBytes = 0; // using uniqueIV, so this isn't necessary
|
|
|
|
uniqueIV = true;
|
|
|
|
chainedIV = true;
|
|
|
|
externalIV = true;
|
|
|
|
desiredKDFDuration = ParanoiaKDFDuration;
|
|
|
|
} else if(configMode == Config_Standard || answer[0] != 'x')
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if (reverseEncryption)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << _("--reverse specified, not using unique/chained IV")
|
|
|
|
<< "\n";
|
2008-01-07 09:09:04 +01:00
|
|
|
} 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
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if(answer[0] == 'x' || alg.name.empty())
|
|
|
|
{
|
|
|
|
if(answer[0] != 'x')
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Sorry, unable to locate cipher for predefined "
|
|
|
|
"configuration...\n"
|
|
|
|
"Falling through to Manual configuration mode.");
|
|
|
|
} else
|
2010-12-07 10:14:17 +01:00
|
|
|
{
|
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();
|
|
|
|
keySize = selectKeySize( alg );
|
|
|
|
blockSize = selectBlockSize( alg );
|
2013-01-29 04:07:54 +01:00
|
|
|
nameIOIface = selectNameCoding( alg );
|
2012-04-26 04:18:26 +02:00
|
|
|
if (reverseEncryption)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << _("--reverse specified, not using unique/chained IV") << "\n";
|
|
|
|
} else
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
chainedIV = selectChainedIV();
|
|
|
|
uniqueIV = selectUniqueIV();
|
|
|
|
if(chainedIV && uniqueIV)
|
|
|
|
externalIV = selectExternalChainedIV();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("External chained IV disabled, as both 'IV chaining'\n"
|
|
|
|
"and 'unique IV' features are required for this option.")
|
|
|
|
<< "\n";
|
|
|
|
externalIV = false;
|
|
|
|
}
|
|
|
|
selectBlockMAC(&blockMACBytes, &blockMACRandBytes);
|
|
|
|
allowHoles = selectZeroBlockPassThrough();
|
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
|
|
|
shared_ptr<CipherV1> cipher = CipherV1::New( alg.iface, keySize );
|
2012-04-26 04:18:26 +02:00
|
|
|
if(!cipher)
|
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Unable to instanciate cipher " << alg.name
|
|
|
|
<< ", key size " << keySize << ", block size " << blockSize;
|
2012-04-26 04:18:26 +02:00
|
|
|
return rootInfo;
|
|
|
|
} else
|
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
config.mutable_cipher()->MergeFrom( cipher->interface() );
|
|
|
|
config.set_block_size( blockSize );
|
|
|
|
config.mutable_naming()->MergeFrom( nameIOIface );
|
|
|
|
config.set_creator( "EncFS " VERSION );
|
2012-08-22 06:46:36 +02:00
|
|
|
config.set_revision( ProtoSubVersion );
|
2012-04-26 04:34:15 +02:00
|
|
|
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-08-20 07:05:16 +02:00
|
|
|
EncryptedKey *key = config.mutable_key();
|
|
|
|
key->clear_salt();
|
|
|
|
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"
|
|
|
|
"the following properties:") << endl;
|
|
|
|
showFSInfo( config );
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
if( config.external_iv() )
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// xgroup(setup)
|
|
|
|
cout << _("Now you will need to enter a password for your filesystem.\n"
|
|
|
|
"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");
|
|
|
|
|
|
|
|
int encodedKeySize = cipher->encodedKeySize();
|
|
|
|
unsigned char *encodedKey = new unsigned char[ encodedKeySize ];
|
|
|
|
|
|
|
|
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;
|
2012-04-26 04:18:26 +02:00
|
|
|
if(useStdin)
|
|
|
|
{
|
|
|
|
if (annotate)
|
|
|
|
cerr << "$PROMPT$ new_passwd" << endl;
|
|
|
|
}
|
2012-04-26 04:34:15 +02:00
|
|
|
userKey = getNewUserKey( config, useStdin, passwordProgram, rootDir );
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-03-05 07:36:32 +01: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-03-05 07:36:32 +01:00
|
|
|
if(!volumeKey.valid())
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(ERROR) << "Failure generating new volume key! "
|
|
|
|
<< "Please report this error.";
|
2012-04-26 04:18:26 +02:00
|
|
|
return rootInfo;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-03-05 07:36:32 +01:00
|
|
|
cipher->setKey( volumeKey );
|
2012-04-26 04:34:15 +02:00
|
|
|
if(!saveConfig( rootDir, config ))
|
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
|
|
|
// fill in config struct
|
2013-03-05 07:36:32 +01:00
|
|
|
shared_ptr<NameIO> nameCoder = NameIO::New( config.naming(), cipher );
|
2012-04-26 04:18:26 +02:00
|
|
|
if(!nameCoder)
|
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
LOG(WARNING) << "Name coding interface not supported";
|
2012-04-26 04:18: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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
nameCoder->setChainedNameIV( config.chained_iv() );
|
2012-04-26 04:18:26 +02:00
|
|
|
nameCoder->setReverseEncryption( reverseEncryption );
|
|
|
|
|
|
|
|
FSConfigPtr fsConfig (new FSConfig);
|
|
|
|
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;
|
|
|
|
|
|
|
|
rootInfo = RootPtr( new EncFS_Root );
|
|
|
|
rootInfo->cipher = cipher;
|
|
|
|
rootInfo->volumeKey = volumeKey;
|
|
|
|
rootInfo->root = shared_ptr<DirNode>(
|
|
|
|
new DirNode( ctx, rootDir, fsConfig ));
|
|
|
|
|
|
|
|
return rootInfo;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
void showFSInfo( const EncfsConfig &config )
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2013-03-05 07:36:32 +01:00
|
|
|
shared_ptr<CipherV1> cipher = CipherV1::New( config.cipher(), -1 );
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
cout << autosprintf(
|
|
|
|
// xgroup(diag)
|
|
|
|
_("Filesystem cipher: \"%s\", version %i:%i:%i"),
|
2012-04-26 04:34:15 +02:00
|
|
|
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..
|
|
|
|
if(!cipher)
|
|
|
|
cout << _(" (NOT supported)\n");
|
|
|
|
else
|
2008-08-17 09:26:52 +02:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
// if we're using a newer interface, show the version number
|
2012-04-26 04:34:15 +02:00
|
|
|
if( config.cipher() != cipher->interface() )
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
Interface iface = cipher->interface();
|
|
|
|
// xgroup(diag)
|
|
|
|
cout << autosprintf(_(" (using %i:%i:%i)\n"),
|
2012-04-26 04:34:15 +02:00
|
|
|
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"),
|
|
|
|
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-03-05 07:36:32 +01:00
|
|
|
shared_ptr<NameIO> nameCoder = NameIO::New( config.naming(), cipher );
|
2012-04-26 04:18:26 +02:00
|
|
|
if(!nameCoder)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _(" (NOT supported)\n");
|
2008-01-07 09:09:04 +01:00
|
|
|
} else
|
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
// if we're using a newer interface, show the version number
|
2012-04-26 04:34:15 +02:00
|
|
|
if( config.naming() != nameCoder->interface() )
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
Interface iface = nameCoder->interface();
|
|
|
|
cout << autosprintf(_(" (using %i:%i:%i)\n"),
|
2012-04-26 04:34:15 +02:00
|
|
|
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);
|
2012-04-26 04:18:26 +02:00
|
|
|
if(!cipher)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _(" (NOT supported)\n");
|
|
|
|
} else
|
|
|
|
cout << "\n";
|
|
|
|
}
|
2012-08-20 07:05:16 +02:00
|
|
|
if(key.kdf_iterations() > 0 && key.salt().size() > 0)
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
cout << autosprintf(_("Using PBKDF2, with %i iterations"),
|
2012-08-20 07:05:16 +02:00
|
|
|
key.kdf_iterations()) << "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << autosprintf(_("Salt Size: %i bits"),
|
2012-08-20 07:05:16 +02:00
|
|
|
8*(int)key.salt().size()) << "\n";
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
2012-04-26 04:34:15 +02:00
|
|
|
if(config.block_mac_bytes() || config.block_mac_rand_bytes())
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
2012-08-22 06:46:36 +02:00
|
|
|
if(config.revision() < V5Latest)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
cout << autosprintf(
|
|
|
|
// xgroup(diag)
|
|
|
|
_("Block Size: %i bytes + %i byte MAC header"),
|
2012-04-26 04:34:15 +02:00
|
|
|
config.block_size(),
|
|
|
|
config.block_mac_bytes() + config.block_mac_rand_bytes()) << endl;
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
2008-04-11 10:37:19 +02:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
// new version stores the header as part of that block size..
|
|
|
|
cout << autosprintf(
|
|
|
|
// xgroup(diag)
|
|
|
|
_("Block Size: %i bytes, including %i byte MAC header"),
|
2012-04-26 04:34:15 +02:00
|
|
|
config.block_size(),
|
|
|
|
config.block_mac_bytes() + config.block_mac_rand_bytes()) << endl;
|
2008-04-11 10:37:19 +02:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +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");
|
|
|
|
}
|
2012-04-26 04:34:15 +02:00
|
|
|
if(config.chained_iv())
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("Filenames encoded using IV chaining mode.\n");
|
|
|
|
}
|
2012-04-26 04:34:15 +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");
|
|
|
|
}
|
2012-04-26 04:34:15 +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-03-05 07:36:32 +01:00
|
|
|
shared_ptr<CipherV1> getCipher(const EncfsConfig &config)
|
2008-08-17 09:26:52 +02:00
|
|
|
{
|
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-03-05 07:36:32 +01:00
|
|
|
shared_ptr<CipherV1> getCipher(const Interface &iface, int keySize)
|
2008-08-23 08:33:24 +02:00
|
|
|
{
|
2013-03-05 07:36:32 +01:00
|
|
|
return CipherV1::New( iface, keySize );
|
2008-08-23 08:33:24 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
CipherKey makeNewKey(EncfsConfig &config, const char *password, int passwdLen)
|
2008-08-23 08:33:24 +02:00
|
|
|
{
|
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-03-05 07:36:32 +01: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-03-05 07:36:32 +01: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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
CipherKey decryptKey(const EncfsConfig &config, const char *password, int passwdLen)
|
2008-08-17 09:26:52 +02:00
|
|
|
{
|
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
|
|
|
|
2012-08-20 07:05:16 +02:00
|
|
|
if(!key.salt().empty())
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
2012-08-20 07:05:16 +02:00
|
|
|
int iterations = key.kdf_iterations();
|
2013-03-05 07:36:32 +01: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-01-29 04:07:54 +01:00
|
|
|
if (iterations != key.kdf_iterations())
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
|
|
|
{
|
2012-04-26 04:34:15 +02:00
|
|
|
// old KDF, no salt..
|
2012-04-26 04:18:26 +02:00
|
|
|
userKey = cipher->newKey( password, passwdLen );
|
|
|
|
}
|
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.
|
2008-01-07 09:09:04 +01: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;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2012-04-26 04:34:15 +02:00
|
|
|
ssize_t rdSize = recv(FD, buf->data, buf->size, 0);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if(rdSize > 0)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2013-03-05 07:32:27 +01:00
|
|
|
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..
|
|
|
|
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,
|
|
|
|
const std::string &rootDir)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
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);
|
|
|
|
if(res == -1)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
if(pid == -1)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if(pid == 0)
|
|
|
|
{
|
|
|
|
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]
|
|
|
|
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..
|
|
|
|
int stdOutCopy = dup( STDOUT_FILENO );
|
|
|
|
int stdErrCopy = dup( STDERR_FILENO );
|
|
|
|
// replace STDOUT with our socket, which we'll used to receive the
|
|
|
|
// password..
|
|
|
|
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..
|
|
|
|
fcntl(STDOUT_FILENO, F_SETFD, 0); // don't close on exec..
|
|
|
|
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
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
snprintf(tmpBuf, sizeof(tmpBuf)-1, "%i", stdOutCopy);
|
|
|
|
setenv(ENCFS_ENV_STDOUT, tmpBuf, 1);
|
|
|
|
|
|
|
|
snprintf(tmpBuf, sizeof(tmpBuf)-1, "%i", stdErrCopy);
|
|
|
|
setenv(ENCFS_ENV_STDERR, tmpBuf, 1);
|
|
|
|
|
|
|
|
execvp( argv[0], (char * const *)argv ); // returns only on error..
|
|
|
|
|
|
|
|
perror(_("Internal error: failed to exec program"));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fds[0]);
|
|
|
|
string password = readPassword(fds[1]);
|
|
|
|
close(fds[1]);
|
|
|
|
|
|
|
|
waitpid(pid, NULL, 0);
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
SecureMem *result = new SecureMem(password.length()+1);
|
|
|
|
if (result)
|
2013-03-05 07:32:27 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
SecureMem *passwordFromStdin()
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:34:15 +02:00
|
|
|
SecureMem *buf = new SecureMem(MaxPassBuf);
|
|
|
|
|
2013-03-05 07:32:27 +01:00
|
|
|
char *res = fgets( (char *)buf->data, buf->size, stdin );
|
2012-04-26 04:34:15 +02:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
// Kill the trailing newline.
|
2013-03-05 07:32:27 +01:00
|
|
|
int last = strnlen((char *)buf->data, buf->size);
|
2012-04-26 04:34:15 +02:00
|
|
|
if (last > 0 && buf->data[last-1] == '\n')
|
|
|
|
buf->data[ last-1 ] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
SecureMem *passwordFromPrompt()
|
|
|
|
{
|
|
|
|
SecureMem *buf = new SecureMem(MaxPassBuf);
|
|
|
|
|
|
|
|
// xgroup(common)
|
|
|
|
char *res = readpassphrase( _("EncFS Password: "),
|
2013-03-05 07:32:27 +01:00
|
|
|
(char *)buf->data, buf->size-1, RPP_ECHO_OFF );
|
2012-04-26 04:34:15 +02:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
delete buf;
|
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
SecureMem *passwordFromPrompts()
|
|
|
|
{
|
|
|
|
SecureMem *buf = new SecureMem(MaxPassBuf);
|
|
|
|
SecureMem *buf2 = new SecureMem(MaxPassBuf);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// xgroup(common)
|
2012-04-26 04:34:15 +02:00
|
|
|
char *res1 = readpassphrase(_("New Encfs Password: "),
|
2013-03-05 07:32:27 +01:00
|
|
|
(char *)buf->data, buf->size-1, RPP_ECHO_OFF);
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(common)
|
2012-04-26 04:34:15 +02:00
|
|
|
char *res2 = readpassphrase(_("Verify Encfs Password: "),
|
2013-03-05 07:32:27 +01:00
|
|
|
(char *)buf2->data, buf2->size-1, RPP_ECHO_OFF);
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-03-05 07:32:27 +01:00
|
|
|
if(res1 && res2
|
|
|
|
&& !strncmp((char*)buf->data, (char*)buf2->data, MaxPassBuf))
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
2012-04-26 04:34:15 +02:00
|
|
|
break;
|
2012-04-26 04:18:26 +02:00
|
|
|
} else
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
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");
|
|
|
|
}
|
2012-04-26 04:34:15 +02:00
|
|
|
} while(1);
|
|
|
|
|
|
|
|
delete buf2;
|
|
|
|
return buf;
|
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
CipherKey getUserKey(const EncfsConfig &config, bool useStdin)
|
|
|
|
{
|
|
|
|
CipherKey userKey;
|
|
|
|
SecureMem *password;
|
|
|
|
|
|
|
|
if (useStdin)
|
|
|
|
password = passwordFromStdin();
|
|
|
|
else
|
|
|
|
password = passwordFromPrompt();
|
|
|
|
|
|
|
|
if (password)
|
|
|
|
{
|
2013-03-05 07:32:27 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
CipherKey getUserKey( const EncfsConfig &config, const std::string &passProg,
|
|
|
|
const std::string &rootDir )
|
|
|
|
{
|
|
|
|
CipherKey result;
|
|
|
|
SecureMem *password = passwordFromProgram(passProg, rootDir);
|
|
|
|
|
|
|
|
if (password)
|
|
|
|
{
|
2013-03-05 07:32:27 +01:00
|
|
|
result = decryptKey(config, (char*)password->data,
|
|
|
|
strlen((char*)password->data));
|
2012-04-26 04:34:15 +02:00
|
|
|
delete password;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CipherKey getNewUserKey(EncfsConfig &config,
|
|
|
|
bool useStdin, const std::string &passProg,
|
|
|
|
const std::string &rootDir)
|
|
|
|
{
|
|
|
|
CipherKey result;
|
|
|
|
SecureMem *password;
|
|
|
|
|
|
|
|
if (useStdin)
|
|
|
|
password = passwordFromStdin();
|
|
|
|
else if (!passProg.empty())
|
|
|
|
password = passwordFromProgram(passProg, rootDir);
|
|
|
|
else
|
|
|
|
password = passwordFromPrompts();
|
|
|
|
|
|
|
|
if (password)
|
|
|
|
{
|
2013-03-05 07:32:27 +01:00
|
|
|
result = makeNewKey(config, (char*)password->data,
|
|
|
|
strlen((char*)password->data));
|
2012-04-26 04:34:15 +02:00
|
|
|
delete password;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-01-07 09:09:04 +01: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
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if(readConfig( opts->rootDir, config ) != Config_None)
|
|
|
|
{
|
|
|
|
if(opts->reverseEncryption)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:34:15 +02:00
|
|
|
if (config.block_mac_bytes() != 0 || config.block_mac_rand_bytes() != 0
|
|
|
|
|| config.unique_iv() || config.external_iv()
|
|
|
|
|| config.chained_iv() )
|
2012-04-26 04:18:26 +02:00
|
|
|
{
|
|
|
|
cout << _("The configuration loaded is not compatible with --reverse\n");
|
|
|
|
return rootInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// first, instanciate the cipher.
|
2013-03-05 07:36:32 +01:00
|
|
|
shared_ptr<CipherV1> cipher = getCipher(config);
|
2012-04-26 04:18:26 +02:00
|
|
|
if(!cipher)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
Interface iface = config.cipher();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
// get user key
|
|
|
|
CipherKey userKey;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:18:26 +02:00
|
|
|
if(opts->passwordProgram.empty())
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
if (opts->annotate)
|
|
|
|
cerr << "$PROMPT$ passwd" << endl;
|
2012-04-26 04:34:15 +02:00
|
|
|
userKey = getUserKey( config, opts->useStdin );
|
2008-01-07 09:09:04 +01:00
|
|
|
} else
|
2012-04-26 04:34:15 +02:00
|
|
|
userKey = getUserKey( config, opts->passwordProgram, opts->rootDir );
|
2012-04-26 04:18:26 +02:00
|
|
|
|
2013-03-05 07:36:32 +01:00
|
|
|
if(!userKey.valid())
|
2012-04-26 04:18:26 +02:00
|
|
|
return rootInfo;
|
|
|
|
|
2013-03-05 07:36:32 +01:00
|
|
|
cipher->setKey(userKey);
|
|
|
|
|
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..
|
|
|
|
CipherKey volumeKey = cipher->readKey(
|
2013-03-05 07:36:32 +01:00
|
|
|
(const unsigned char *)config.key().ciphertext().data(), opts->checkKey);
|
2012-04-26 04:18:26 +02:00
|
|
|
userKey.reset();
|
|
|
|
|
2013-03-05 07:36:32 +01: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);
|
|
|
|
|
|
|
|
shared_ptr<NameIO> nameCoder = NameIO::New( config.naming(), cipher );
|
2012-04-26 04:18:26 +02:00
|
|
|
if(!nameCoder)
|
|
|
|
{
|
2013-01-29 04:07:54 +01:00
|
|
|
Interface iface = config.naming();
|
|
|
|
LOG(ERROR) << "Unable to find nameio interface " << iface.name()
|
|
|
|
<< ", version " << iface.major()
|
|
|
|
<< ":" << iface.minor() << ":" << iface.age();
|
2012-04-26 04:18:26 +02:00
|
|
|
// xgroup(diag)
|
|
|
|
cout << _("The requested filename coding interface is "
|
|
|
|
"not available\n");
|
|
|
|
return rootInfo;
|
|
|
|
}
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
nameCoder->setChainedNameIV( config.chained_iv() );
|
2012-04-26 04:18:26 +02:00
|
|
|
nameCoder->setReverseEncryption( opts->reverseEncryption );
|
|
|
|
|
|
|
|
FSConfigPtr fsConfig( new FSConfig );
|
|
|
|
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;
|
|
|
|
|
|
|
|
rootInfo = RootPtr( new EncFS_Root );
|
|
|
|
rootInfo->cipher = cipher;
|
|
|
|
rootInfo->volumeKey = volumeKey;
|
|
|
|
rootInfo->root = shared_ptr<DirNode>(
|
|
|
|
new DirNode( ctx, opts->rootDir, fsConfig ));
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if(opts->createIfNotFound)
|
2008-01-07 09:09:04 +01:00
|
|
|
{
|
2012-04-26 04:18:26 +02:00
|
|
|
// creating a new encrypted filesystem
|
2012-04-26 04:34:15 +02:00
|
|
|
rootInfo = createConfig( ctx, opts );
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
2012-04-26 04:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rootInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
RootPtr rootInfo = initFS( ctx, ctx->opts );
|
|
|
|
if(rootInfo)
|
|
|
|
{
|
|
|
|
ctx->setRoot(rootInfo->root);
|
|
|
|
return 0;
|
|
|
|
} 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
|